All Downloads are FREE. Search and download functionalities are using the official Maven repository.

hm.binkley.xml.fuzzy.ftl Maven / Gradle / Ivy

There is a newer version: 6
Show newest version
package ${package};

/**
 * {@code ${simpleName}Factory} creates new instances of the {@code ${simpleName}} interface.
 * 

* Instance creation extracts and converts values from an XML node, saving the typed results to * {@code final} fields. Implemnted methods return the field values. The instances are * immutable. */ @javax.annotation.Generated(value="${generator}", date="${date}") public final class ${simpleName}Factory implements ${simpleName} { <#list methods as method> private final ${method.returnType} ${method.simpleName}; /** * Creates a new {@code ${simpleName} for the given XML node. *

* If XML parsing or field conversion fails, attaches a suppressed exception describing the * field and XPath. * * @param node the XML node, never missing * * @return the new {@code ${simpleName}, never missing * @throws java.lang.Exception if XML parsing or field conversion fails */ public static ${simpleName} of(@javax.annotation.Nonnull final org.w3c.dom.Node node) throws java.lang.Exception { return new ${simpleName}Factory(node); } private ${simpleName}Factory(final org.w3c.dom.Node node) throws java.lang.Exception { <#list methods as method> try { final String $value = hm.binkley.xml.XMLFuzzyProcessor.evaluate(node, "${method.xpath}"); if ("".equals($value)) <#if method.nullable> this.${method.simpleName} = null; <#else> throw new java.lang.NullPointerException(); else <#if "java.lang.String" == method.returnType> this.${method.simpleName} = $value; <#else> this.${method.simpleName} = ${method.converter}($value); } catch (final java.lang.Exception $e) { $e.addSuppressed(new java.lang.Exception(java.lang.String.format("%s: %s", "${simpleName}::${method.simpleName}", "${method.xpath}"))); throw $e; } } <#list methods as method> <#if !method.nullable> @javax.annotation.Nonnull @Override public ${method.returnType} ${method.simpleName}() { return ${method.simpleName}; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy