PodamFactoryImpl: Support for XML Datatype instantiation.
Thank you for Podam. I use it in production to generate samples requests for web service APIs. These POJOs often contain XmlGregorianCalendar properties. Here is a patch for PodamFactoryImpl to return values when instantiation requires the use of the XML Datatype factory.
- Here are the imports ...
import java.util.GregorianCalendar;
import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.Duration;
import javax.xml.datatype.XMLGregorianCalendar;
- A helper method to get a static instance of the XML DatatypeFactory...
// A factory to create objects that map XML to/from Java.
private static DatatypeFactory xmlDatatypeFactory;
public static DatatypeFactory getXmlDatatypeFactory()
{
if ( xmlDatatypeFactory == null )
{
try
{
xmlDatatypeFactory = DatatypeFactory.newInstance();
}
catch (DatatypeConfigurationException e)
{
throw new RuntimeException("Podam factory cannot create XML factory.", e);
}
}
return xmlDatatypeFactory;
}
- In the
createNewInstanceForClassWithoutConstructors(...)method, within the test for 'no constructors' and after the loop to find a 'getInstance()' method, add this code...
// Did we find a getInstance() method to create the return value?
if ( retValue == null )
{
// No return value, so far.
// Can we use an XML DatatypeFactory to create an instance?
if ( XMLGregorianCalendar.class.isAssignableFrom(clazz) )
{
retValue = getXmlDatatypeFactory().newXMLGregorianCalendar(new GregorianCalendar());
}
else if ( Duration.class.isAssignableFrom(clazz) )
{
List<Annotation> annotations = new ArrayList<Annotation>();
getLongValueWithinRange(annotations, null);
retValue = getXmlDatatypeFactory().newDuration(0L);
}
}
And a suggestion: Change the log.info(...) in PodamFactoryImpl to log.debug(...). This would allow my SysAdmin to set the log level to INFO instead of WARN without a flood of details from this class, IMHO.
Most of logging framework allow setting logging level per package. For example, Logback: http://stackoverflow.com/questions/5924089/how-to-configure-logback-to-skip-logging-messages-from-org-package-with-all-le And Log4J: http://stackoverflow.com/questions/5297686/log4j-package-specific-logging Which logging framework do you use?
Thanks Daniil, that is good advice! I code to slf4j and deploy to containers that are configured for either logback or log4j. Consistent with your advice, I have configured log4j.logger.uk.co.jemos.podam=WARN. That works but an improvement might be to limit INFO messages to life cycle events (start/stop and configuration settings) and push the more verbose messages down to DEBUG or TRACE. By the time a framework hits prod, the cool dev-centric stuff becomes less important while admin stuff like 'did the framework start and how is it configured' becomes the focus. Using INFO is a way to log the life-cycle events without the verbosity of 'per instance' logic flow. In any case, this is not an issue, only a suggestion.
Could please you report logging as a separate new issue?
I just noticed that pull request https://github.com/mtedone/podam/pull/39 addresses excessive logging and use of slf4j to abstract the logging framework.
Fixed in PODAM 4.5.0.
Released to Maven central
On 3 Jan 2015, at 17:53, Daniil Ivanov [email protected] wrote:
Fixed in PODAM 4.5.0.
— Reply to this email directly or view it on GitHub https://github.com/mtedone/podam/issues/69#issuecomment-68603207.
Closing.
Apparently XMLGregorianCalendar manufacturing test doesn't work properly.
Fixed in PODAM 5.2.0.