Renamed jaxb support classes

This commit is contained in:
Willem 2015-12-27 16:11:57 +01:00
parent b67d5c5363
commit ceab91eb5d
9 changed files with 38 additions and 34 deletions

View file

@ -34,7 +34,7 @@ import org.apache.commons.lang3.Validate;
import net.forwardfire.tpquery.config.TPQConfig; import net.forwardfire.tpquery.config.TPQConfig;
import net.forwardfire.tpquery.model.TPQuerySet; import net.forwardfire.tpquery.model.TPQuerySet;
import net.forwardfire.tpquery.model.TPQuerySetXMLMarshaller; import net.forwardfire.tpquery.model.ModelXMLMarshaller;
import net.forwardfire.tpquery.statement.TPQStatementMarshaller; import net.forwardfire.tpquery.statement.TPQStatementMarshaller;
/** /**
@ -48,7 +48,7 @@ public class TPQConfigBuilder<T> {
private final TPQConfig storeConfig; private final TPQConfig storeConfig;
private final Supplier<T> resultBuilder; private final Supplier<T> resultBuilder;
private final TPQuerySetXMLMarshaller xmlDriver; private final ModelXMLMarshaller xmlDriver;
private final TPQStatementMarshaller statementMarshaller; private final TPQStatementMarshaller statementMarshaller;
/** /**
@ -62,7 +62,7 @@ public class TPQConfigBuilder<T> {
Validate.notNull(resultBuilder,"Can't build with null builder."); Validate.notNull(resultBuilder,"Can't build with null builder.");
this.storeConfig = storeConfig; this.storeConfig = storeConfig;
this.resultBuilder = resultBuilder; this.resultBuilder = resultBuilder;
this.xmlDriver = new TPQuerySetXMLMarshaller(); this.xmlDriver = new ModelXMLMarshaller();
this.statementMarshaller = new TPQStatementMarshaller(); this.statementMarshaller = new TPQStatementMarshaller();
} }

View file

@ -30,8 +30,9 @@ import javax.xml.bind.annotation.XmlElement;
import org.apache.commons.lang3.Validate; import org.apache.commons.lang3.Validate;
import net.forwardfire.tpquery.model.AbstractXMLMarshaller.Attribute; import net.forwardfire.tpquery.model.ModelXMLInfoSet.Attribute;
import net.forwardfire.tpquery.model.AbstractXMLMarshaller.Element; import net.forwardfire.tpquery.model.ModelXMLInfoSet.Element;
import net.forwardfire.tpquery.model.ModelXMLInfoSet.Meta;
/** /**
* AbstractTPQueryNode has the shared properties of an query(set) node. * AbstractTPQueryNode has the shared properties of an query(set) node.
@ -58,7 +59,7 @@ public abstract class AbstractTPQueryNode {
/** /**
* @return the name * @return the name
*/ */
@XmlAttribute(name=Attribute.NAME,required=AbstractXMLMarshaller.Meta.REQUIRED) @XmlAttribute(name=Attribute.NAME,required=Meta.REQUIRED)
public String getName() { public String getName() {
return name; return name;
} }

View file

@ -23,16 +23,16 @@
package net.forwardfire.tpquery.model; package net.forwardfire.tpquery.model;
/** /**
* AbstractXMLMarshaller has all jaxb meta info. * ModelXMLInfoSet has all jaxb model info.
* *
* @author Willem Cazander * @author Willem Cazander
* @version 1.0 Jan 16, 2015 * @version 1.0 Jan 16, 2015
*/ */
abstract class AbstractXMLMarshaller { class ModelXMLInfoSet {
protected static final String XML_ENCODING = "UTF-8"; protected static final String XML_ENCODING = "UTF-8";
protected AbstractXMLMarshaller() { protected ModelXMLInfoSet() {
} }
protected static class Meta { protected static class Meta {

View file

@ -33,29 +33,29 @@ import javax.xml.bind.Unmarshaller;
import org.apache.commons.lang3.Validate; import org.apache.commons.lang3.Validate;
/** /**
* Jaxb marshaller of the query sets. * Jaxb model marshaller of the query sets.
* *
* @author Willem Cazander * @author Willem Cazander
* @version 1.0 Jan 14, 2015 * @version 1.0 Jan 14, 2015
*/ */
public class TPQuerySetXMLMarshaller extends AbstractXMLMarshaller { public class ModelXMLMarshaller extends ModelXMLInfoSet {
private final JAXBContext querySetContext; private final JAXBContext jaxbContext;
/** /**
* Creates a query set xml marshaller. * Creates a query set xml marshaller.
* @throws JAXBException When context could not be build. * @throws JAXBException When context could not be build.
*/ */
public TPQuerySetXMLMarshaller() throws JAXBException { public ModelXMLMarshaller() throws JAXBException {
this(JAXBContext.newInstance(TPQuerySet.class)); this(JAXBContext.newInstance(TPQuerySet.class));
} }
/** /**
* Creates a query set xml marshaller. * Creates a query set xml marshaller.
* @param querySetContext The jaxb query set context. * @param jaxbContext The jaxb query set context.
*/ */
public TPQuerySetXMLMarshaller(JAXBContext querySetContext) { public ModelXMLMarshaller(JAXBContext jaxbContext) {
this.querySetContext = Validate.notNull(querySetContext,"querySetContext is null."); this.jaxbContext = Validate.notNull(jaxbContext,"jaxbContext is null.");
} }
/** /**
@ -68,7 +68,7 @@ public class TPQuerySetXMLMarshaller extends AbstractXMLMarshaller {
Validate.notNull(querySet,"querySet is null."); Validate.notNull(querySet,"querySet is null.");
Validate.notNull(output,"OutputStream is null."); Validate.notNull(output,"OutputStream is null.");
Marshaller marshaller = querySetContext.createMarshaller(); Marshaller marshaller = jaxbContext.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.setProperty(Marshaller.JAXB_ENCODING, XML_ENCODING); marshaller.setProperty(Marshaller.JAXB_ENCODING, XML_ENCODING);
marshaller.marshal(querySet, output); marshaller.marshal(querySet, output);
@ -83,7 +83,7 @@ public class TPQuerySetXMLMarshaller extends AbstractXMLMarshaller {
public TPQuerySet unmarshal(InputStream input) throws JAXBException { public TPQuerySet unmarshal(InputStream input) throws JAXBException {
Validate.notNull(input,"InputStream is null."); Validate.notNull(input,"InputStream is null.");
Unmarshaller unmarshaller = querySetContext.createUnmarshaller(); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
return (TPQuerySet) unmarshaller.unmarshal(input); return (TPQuerySet) unmarshaller.unmarshal(input);
} }
} }

View file

@ -30,7 +30,8 @@ import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import org.apache.commons.lang3.Validate; import org.apache.commons.lang3.Validate;
import net.forwardfire.tpquery.model.AbstractXMLMarshaller.Element; import net.forwardfire.tpquery.model.ModelXMLInfoSet.Element;
import net.forwardfire.tpquery.model.ModelXMLInfoSet.Meta;
import net.forwardfire.tpquery.statement.TPQStatement; import net.forwardfire.tpquery.statement.TPQStatement;
import net.forwardfire.tpquery.statement.TPQStatementMarshallerAdapter; import net.forwardfire.tpquery.statement.TPQStatementMarshallerAdapter;
@ -65,7 +66,7 @@ public final class TPQuery extends AbstractTPQueryNode {
/** /**
* @return the queryParts * @return the queryParts
*/ */
@XmlElement(name=Element.QUERY_PART,required=AbstractXMLMarshaller.Meta.REQUIRED) @XmlElement(name=Element.QUERY_PART,required=Meta.REQUIRED)
@XmlJavaTypeAdapter(TPQStatementMarshallerAdapter.class) @XmlJavaTypeAdapter(TPQStatementMarshallerAdapter.class)
public List<TPQStatement> getQueryParts() { public List<TPQStatement> getQueryParts() {
return queryParts; return queryParts;

View file

@ -24,7 +24,8 @@ package net.forwardfire.tpquery.model;
import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlAttribute;
import net.forwardfire.tpquery.model.AbstractXMLMarshaller.Attribute; import net.forwardfire.tpquery.model.ModelXMLInfoSet.Attribute;
import net.forwardfire.tpquery.model.ModelXMLInfoSet.Meta;
/** /**
* Query hint are optional hint. * Query hint are optional hint.
@ -57,7 +58,7 @@ public final class TPQueryHint {
/** /**
* @return the name * @return the name
*/ */
@XmlAttribute(name=Attribute.NAME,required=AbstractXMLMarshaller.Meta.REQUIRED) @XmlAttribute(name=Attribute.NAME,required=Meta.REQUIRED)
public String getName() { public String getName() {
return name; return name;
} }
@ -72,7 +73,7 @@ public final class TPQueryHint {
/** /**
* @return the value * @return the value
*/ */
@XmlAttribute(name=Attribute.VALUE,required=AbstractXMLMarshaller.Meta.REQUIRED) @XmlAttribute(name=Attribute.VALUE,required=Meta.REQUIRED)
public String getValue() { public String getValue() {
return value; return value;
} }

View file

@ -24,7 +24,8 @@ package net.forwardfire.tpquery.model;
import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlAttribute;
import net.forwardfire.tpquery.model.AbstractXMLMarshaller.Attribute; import net.forwardfire.tpquery.model.ModelXMLInfoSet.Attribute;
import net.forwardfire.tpquery.model.ModelXMLInfoSet.Meta;
/** /**
* Defines the query parameter. * Defines the query parameter.
@ -59,7 +60,7 @@ public final class TPQueryParameter {
/** /**
* @return the name * @return the name
*/ */
@XmlAttribute(name=Attribute.NAME,required=AbstractXMLMarshaller.Meta.REQUIRED) @XmlAttribute(name=Attribute.NAME,required=Meta.REQUIRED)
public String getName() { public String getName() {
return name; return name;
} }
@ -103,7 +104,7 @@ public final class TPQueryParameter {
/** /**
* @return the valueType * @return the valueType
*/ */
@XmlAttribute(name=Attribute.VALUE_TYPE,required=AbstractXMLMarshaller.Meta.REQUIRED) @XmlAttribute(name=Attribute.VALUE_TYPE,required=Meta.REQUIRED)
public String getValueType() { public String getValueType() {
return valueType; return valueType;
} }

View file

@ -28,7 +28,7 @@ import java.util.List;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import net.forwardfire.tpquery.model.AbstractXMLMarshaller.Element; import net.forwardfire.tpquery.model.ModelXMLInfoSet.Element;
/** /**
* Query sets is an tree node which holds more query sets and queries. * Query sets is an tree node which holds more query sets and queries.

View file

@ -16,14 +16,14 @@ import net.forwardfire.tpquery.TPQManager;
import net.forwardfire.tpquery.model.TPQuery; import net.forwardfire.tpquery.model.TPQuery;
import net.forwardfire.tpquery.model.TPQueryParameter; import net.forwardfire.tpquery.model.TPQueryParameter;
import net.forwardfire.tpquery.model.TPQuerySet; import net.forwardfire.tpquery.model.TPQuerySet;
import net.forwardfire.tpquery.model.AbstractXMLMarshaller; import net.forwardfire.tpquery.model.ModelXMLInfoSet;
import net.forwardfire.tpquery.model.TPQuerySetXMLMarshaller; import net.forwardfire.tpquery.model.ModelXMLMarshaller;
import net.forwardfire.tpquery.statement.TPQStatementPartInclude; import net.forwardfire.tpquery.statement.TPQStatementPartInclude;
import net.forwardfire.tpquery.statement.TPQStatementPartParameter; import net.forwardfire.tpquery.statement.TPQStatementPartParameter;
import net.forwardfire.tpquery.statement.TPQStatementPartText; import net.forwardfire.tpquery.statement.TPQStatementPartText;
import net.forwardfire.tpquery.store.executor.TPQExecutorStatement; import net.forwardfire.tpquery.store.executor.TPQExecutorStatement;
public class XMLMarshallerTest { public class ModelXMLMarshallerTest {
private TPQuerySet createTest() throws Exception { private TPQuerySet createTest() throws Exception {
@ -77,7 +77,7 @@ public class XMLMarshallerTest {
@Test @Test
public void testRoundTrip() throws Exception { public void testRoundTrip() throws Exception {
TPQuerySet qs = createTest(); TPQuerySet qs = createTest();
TPQuerySetXMLMarshaller xmlDriver = new TPQuerySetXMLMarshaller(); ModelXMLMarshaller xmlDriver = new ModelXMLMarshaller();
ByteArrayOutputStream out = new ByteArrayOutputStream(4096); ByteArrayOutputStream out = new ByteArrayOutputStream(4096);
xmlDriver.marshal(qs, out); xmlDriver.marshal(qs, out);
@ -91,9 +91,9 @@ public class XMLMarshallerTest {
@Test @Test
public void testXMLMarshallerClasses() throws Exception { public void testXMLMarshallerClasses() throws Exception {
assertNotNull(new AbstractXMLMarshaller.Meta()); assertNotNull(new ModelXMLInfoSet.Meta());
assertNotNull(new AbstractXMLMarshaller.Element()); assertNotNull(new ModelXMLInfoSet.Element());
assertNotNull(new AbstractXMLMarshaller.Attribute()); assertNotNull(new ModelXMLInfoSet.Attribute());
} }
@Test @Test