Renamed jaxb support classes
This commit is contained in:
parent
b67d5c5363
commit
ceab91eb5d
|
@ -34,7 +34,7 @@ import org.apache.commons.lang3.Validate;
|
|||
|
||||
import net.forwardfire.tpquery.config.TPQConfig;
|
||||
import net.forwardfire.tpquery.model.TPQuerySet;
|
||||
import net.forwardfire.tpquery.model.TPQuerySetXMLMarshaller;
|
||||
import net.forwardfire.tpquery.model.ModelXMLMarshaller;
|
||||
import net.forwardfire.tpquery.statement.TPQStatementMarshaller;
|
||||
|
||||
/**
|
||||
|
@ -48,7 +48,7 @@ public class TPQConfigBuilder<T> {
|
|||
|
||||
private final TPQConfig storeConfig;
|
||||
private final Supplier<T> resultBuilder;
|
||||
private final TPQuerySetXMLMarshaller xmlDriver;
|
||||
private final ModelXMLMarshaller xmlDriver;
|
||||
private final TPQStatementMarshaller statementMarshaller;
|
||||
|
||||
/**
|
||||
|
@ -62,7 +62,7 @@ public class TPQConfigBuilder<T> {
|
|||
Validate.notNull(resultBuilder,"Can't build with null builder.");
|
||||
this.storeConfig = storeConfig;
|
||||
this.resultBuilder = resultBuilder;
|
||||
this.xmlDriver = new TPQuerySetXMLMarshaller();
|
||||
this.xmlDriver = new ModelXMLMarshaller();
|
||||
this.statementMarshaller = new TPQStatementMarshaller();
|
||||
}
|
||||
|
||||
|
|
|
@ -30,8 +30,9 @@ import javax.xml.bind.annotation.XmlElement;
|
|||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import net.forwardfire.tpquery.model.AbstractXMLMarshaller.Attribute;
|
||||
import net.forwardfire.tpquery.model.AbstractXMLMarshaller.Element;
|
||||
import net.forwardfire.tpquery.model.ModelXMLInfoSet.Attribute;
|
||||
import net.forwardfire.tpquery.model.ModelXMLInfoSet.Element;
|
||||
import net.forwardfire.tpquery.model.ModelXMLInfoSet.Meta;
|
||||
|
||||
/**
|
||||
* AbstractTPQueryNode has the shared properties of an query(set) node.
|
||||
|
@ -58,7 +59,7 @@ public abstract class AbstractTPQueryNode {
|
|||
/**
|
||||
* @return the name
|
||||
*/
|
||||
@XmlAttribute(name=Attribute.NAME,required=AbstractXMLMarshaller.Meta.REQUIRED)
|
||||
@XmlAttribute(name=Attribute.NAME,required=Meta.REQUIRED)
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
|
|
@ -23,16 +23,16 @@
|
|||
package net.forwardfire.tpquery.model;
|
||||
|
||||
/**
|
||||
* AbstractXMLMarshaller has all jaxb meta info.
|
||||
* ModelXMLInfoSet has all jaxb model info.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jan 16, 2015
|
||||
*/
|
||||
abstract class AbstractXMLMarshaller {
|
||||
class ModelXMLInfoSet {
|
||||
|
||||
protected static final String XML_ENCODING = "UTF-8";
|
||||
|
||||
protected AbstractXMLMarshaller() {
|
||||
protected ModelXMLInfoSet() {
|
||||
}
|
||||
|
||||
protected static class Meta {
|
|
@ -33,29 +33,29 @@ import javax.xml.bind.Unmarshaller;
|
|||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
/**
|
||||
* Jaxb marshaller of the query sets.
|
||||
* Jaxb model marshaller of the query sets.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @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.
|
||||
* @throws JAXBException When context could not be build.
|
||||
*/
|
||||
public TPQuerySetXMLMarshaller() throws JAXBException {
|
||||
public ModelXMLMarshaller() throws JAXBException {
|
||||
this(JAXBContext.newInstance(TPQuerySet.class));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a query set xml marshaller.
|
||||
* @param querySetContext The jaxb query set context.
|
||||
* @param jaxbContext The jaxb query set context.
|
||||
*/
|
||||
public TPQuerySetXMLMarshaller(JAXBContext querySetContext) {
|
||||
this.querySetContext = Validate.notNull(querySetContext,"querySetContext is null.");
|
||||
public ModelXMLMarshaller(JAXBContext jaxbContext) {
|
||||
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(output,"OutputStream is null.");
|
||||
|
||||
Marshaller marshaller = querySetContext.createMarshaller();
|
||||
Marshaller marshaller = jaxbContext.createMarshaller();
|
||||
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
|
||||
marshaller.setProperty(Marshaller.JAXB_ENCODING, XML_ENCODING);
|
||||
marshaller.marshal(querySet, output);
|
||||
|
@ -83,7 +83,7 @@ public class TPQuerySetXMLMarshaller extends AbstractXMLMarshaller {
|
|||
public TPQuerySet unmarshal(InputStream input) throws JAXBException {
|
||||
Validate.notNull(input,"InputStream is null.");
|
||||
|
||||
Unmarshaller unmarshaller = querySetContext.createUnmarshaller();
|
||||
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
|
||||
return (TPQuerySet) unmarshaller.unmarshal(input);
|
||||
}
|
||||
}
|
|
@ -30,7 +30,8 @@ import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
|
|||
|
||||
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.TPQStatementMarshallerAdapter;
|
||||
|
||||
|
@ -65,7 +66,7 @@ public final class TPQuery extends AbstractTPQueryNode {
|
|||
/**
|
||||
* @return the queryParts
|
||||
*/
|
||||
@XmlElement(name=Element.QUERY_PART,required=AbstractXMLMarshaller.Meta.REQUIRED)
|
||||
@XmlElement(name=Element.QUERY_PART,required=Meta.REQUIRED)
|
||||
@XmlJavaTypeAdapter(TPQStatementMarshallerAdapter.class)
|
||||
public List<TPQStatement> getQueryParts() {
|
||||
return queryParts;
|
||||
|
|
|
@ -24,7 +24,8 @@ package net.forwardfire.tpquery.model;
|
|||
|
||||
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.
|
||||
|
@ -57,7 +58,7 @@ public final class TPQueryHint {
|
|||
/**
|
||||
* @return the name
|
||||
*/
|
||||
@XmlAttribute(name=Attribute.NAME,required=AbstractXMLMarshaller.Meta.REQUIRED)
|
||||
@XmlAttribute(name=Attribute.NAME,required=Meta.REQUIRED)
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
@ -72,7 +73,7 @@ public final class TPQueryHint {
|
|||
/**
|
||||
* @return the value
|
||||
*/
|
||||
@XmlAttribute(name=Attribute.VALUE,required=AbstractXMLMarshaller.Meta.REQUIRED)
|
||||
@XmlAttribute(name=Attribute.VALUE,required=Meta.REQUIRED)
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
|
|
@ -24,7 +24,8 @@ package net.forwardfire.tpquery.model;
|
|||
|
||||
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.
|
||||
|
@ -59,7 +60,7 @@ public final class TPQueryParameter {
|
|||
/**
|
||||
* @return the name
|
||||
*/
|
||||
@XmlAttribute(name=Attribute.NAME,required=AbstractXMLMarshaller.Meta.REQUIRED)
|
||||
@XmlAttribute(name=Attribute.NAME,required=Meta.REQUIRED)
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
@ -103,7 +104,7 @@ public final class TPQueryParameter {
|
|||
/**
|
||||
* @return the valueType
|
||||
*/
|
||||
@XmlAttribute(name=Attribute.VALUE_TYPE,required=AbstractXMLMarshaller.Meta.REQUIRED)
|
||||
@XmlAttribute(name=Attribute.VALUE_TYPE,required=Meta.REQUIRED)
|
||||
public String getValueType() {
|
||||
return valueType;
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ import java.util.List;
|
|||
import javax.xml.bind.annotation.XmlElement;
|
||||
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.
|
||||
|
|
|
@ -16,14 +16,14 @@ import net.forwardfire.tpquery.TPQManager;
|
|||
import net.forwardfire.tpquery.model.TPQuery;
|
||||
import net.forwardfire.tpquery.model.TPQueryParameter;
|
||||
import net.forwardfire.tpquery.model.TPQuerySet;
|
||||
import net.forwardfire.tpquery.model.AbstractXMLMarshaller;
|
||||
import net.forwardfire.tpquery.model.TPQuerySetXMLMarshaller;
|
||||
import net.forwardfire.tpquery.model.ModelXMLInfoSet;
|
||||
import net.forwardfire.tpquery.model.ModelXMLMarshaller;
|
||||
import net.forwardfire.tpquery.statement.TPQStatementPartInclude;
|
||||
import net.forwardfire.tpquery.statement.TPQStatementPartParameter;
|
||||
import net.forwardfire.tpquery.statement.TPQStatementPartText;
|
||||
import net.forwardfire.tpquery.store.executor.TPQExecutorStatement;
|
||||
|
||||
public class XMLMarshallerTest {
|
||||
public class ModelXMLMarshallerTest {
|
||||
|
||||
private TPQuerySet createTest() throws Exception {
|
||||
|
||||
|
@ -77,7 +77,7 @@ public class XMLMarshallerTest {
|
|||
@Test
|
||||
public void testRoundTrip() throws Exception {
|
||||
TPQuerySet qs = createTest();
|
||||
TPQuerySetXMLMarshaller xmlDriver = new TPQuerySetXMLMarshaller();
|
||||
ModelXMLMarshaller xmlDriver = new ModelXMLMarshaller();
|
||||
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream(4096);
|
||||
xmlDriver.marshal(qs, out);
|
||||
|
@ -91,9 +91,9 @@ public class XMLMarshallerTest {
|
|||
|
||||
@Test
|
||||
public void testXMLMarshallerClasses() throws Exception {
|
||||
assertNotNull(new AbstractXMLMarshaller.Meta());
|
||||
assertNotNull(new AbstractXMLMarshaller.Element());
|
||||
assertNotNull(new AbstractXMLMarshaller.Attribute());
|
||||
assertNotNull(new ModelXMLInfoSet.Meta());
|
||||
assertNotNull(new ModelXMLInfoSet.Element());
|
||||
assertNotNull(new ModelXMLInfoSet.Attribute());
|
||||
}
|
||||
|
||||
@Test
|
Loading…
Reference in a new issue