http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/95e832e1/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfSerializer.java ---------------------------------------------------------------------- diff --git a/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfSerializer.java b/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfSerializer.java index c856512..4de1963 100644 --- a/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfSerializer.java +++ b/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfSerializer.java @@ -14,7 +14,6 @@ package org.apache.juneau.jena; import static org.apache.juneau.jena.Constants.*; import static org.apache.juneau.jena.RdfCommonContext.*; -import static org.apache.juneau.jena.RdfSerializerContext.*; import java.lang.reflect.*; import java.util.*; @@ -22,11 +21,9 @@ import java.util.*; import org.apache.juneau.*; import org.apache.juneau.annotation.*; import org.apache.juneau.internal.*; -import org.apache.juneau.jena.annotation.*; import org.apache.juneau.serializer.*; import org.apache.juneau.transform.*; import org.apache.juneau.xml.*; -import org.apache.juneau.xml.annotation.*; import com.hp.hpl.jena.rdf.model.*; @@ -58,67 +55,128 @@ import com.hp.hpl.jena.rdf.model.*; public class RdfSerializer extends WriterSerializer { /** Default RDF/XML serializer, all default settings.*/ - public static final RdfSerializer DEFAULT_XML = new RdfSerializer.Xml().lock(); + public static final RdfSerializer DEFAULT_XML = new Xml(PropertyStore.create()); /** Default Abbreviated RDF/XML serializer, all default settings.*/ - public static final RdfSerializer DEFAULT_XMLABBREV = new RdfSerializer.XmlAbbrev().lock(); + public static final RdfSerializer DEFAULT_XMLABBREV = new XmlAbbrev(PropertyStore.create()); /** Default Turtle serializer, all default settings.*/ - public static final RdfSerializer DEFAULT_TURTLE = new RdfSerializer.Turtle().lock(); + public static final RdfSerializer DEFAULT_TURTLE = new Turtle(PropertyStore.create()); /** Default N-Triple serializer, all default settings.*/ - public static final RdfSerializer DEFAULT_NTRIPLE = new RdfSerializer.NTriple().lock(); + public static final RdfSerializer DEFAULT_NTRIPLE = new NTriple(PropertyStore.create()); /** Default N3 serializer, all default settings.*/ - public static final RdfSerializer DEFAULT_N3 = new RdfSerializer.N3().lock(); + public static final RdfSerializer DEFAULT_N3 = new N3(PropertyStore.create()); /** Produces RDF/XML output */ @Produces("text/xml+rdf") public static class Xml extends RdfSerializer { - /** Constructor */ - public Xml() { - setLanguage(LANG_RDF_XML); + + /** + * Constructor. + * @param propertyStore The property store containing all the settings for this object. + */ + public Xml(PropertyStore propertyStore) { + super(propertyStore); + } + + @Override /* CoreObject */ + protected ObjectMap getOverrideProperties() { + return super.getOverrideProperties().append(RDF_language, LANG_RDF_XML); } } /** Produces Abbreviated RDF/XML output */ @Produces(value="text/xml+rdf+abbrev", contentType="text/xml+rdf") public static class XmlAbbrev extends RdfSerializer { - /** Constructor */ - public XmlAbbrev() { - setLanguage(LANG_RDF_XML_ABBREV); + + /** + * Constructor. + * @param propertyStore The property store containing all the settings for this object. + */ + public XmlAbbrev(PropertyStore propertyStore) { + super(propertyStore); + } + + @Override /* CoreObject */ + protected ObjectMap getOverrideProperties() { + return super.getOverrideProperties().append(RDF_language, LANG_RDF_XML_ABBREV); } } /** Produces N-Triple output */ @Produces("text/n-triple") public static class NTriple extends RdfSerializer { - /** Constructor */ - public NTriple() { - setLanguage(LANG_NTRIPLE); + + /** + * Constructor. + * @param propertyStore The property store containing all the settings for this object. + */ + public NTriple(PropertyStore propertyStore) { + super(propertyStore); + } + + @Override /* CoreObject */ + protected ObjectMap getOverrideProperties() { + return super.getOverrideProperties().append(RDF_language, LANG_NTRIPLE); } } /** Produces Turtle output */ @Produces("text/turtle") public static class Turtle extends RdfSerializer { - /** Constructor */ - public Turtle() { - setLanguage(LANG_TURTLE); + + /** + * Constructor. + * @param propertyStore The property store containing all the settings for this object. + */ + public Turtle(PropertyStore propertyStore) { + super(propertyStore); + } + + @Override /* CoreObject */ + protected ObjectMap getOverrideProperties() { + return super.getOverrideProperties().append(RDF_language, LANG_TURTLE); } } /** Produces N3 output */ @Produces("text/n3") public static class N3 extends RdfSerializer { - /** Constructor */ - public N3() { - setLanguage(LANG_N3); + + /** + * Constructor. + * @param propertyStore The property store containing all the settings for this object. + */ + public N3(PropertyStore propertyStore) { + super(propertyStore); + } + + @Override /* CoreObject */ + protected ObjectMap getOverrideProperties() { + return super.getOverrideProperties().append(RDF_language, LANG_N3); } } + private final RdfSerializerContext ctx; + + /** + * Constructor. + * @param propertyStore The property store containing all the settings for this object. + */ + public RdfSerializer(PropertyStore propertyStore) { + super(propertyStore); + this.ctx = createContext(RdfSerializerContext.class); + } + + @Override /* CoreObject */ + public RdfSerializerBuilder builder() { + return new RdfSerializerBuilder(propertyStore); + } + @Override /* Serializer */ protected void doSerialize(SerializerSession session, Object o) throws Exception { @@ -392,819 +450,6 @@ public class RdfSerializer extends WriterSerializer { @Override /* Serializer */ public RdfSerializerSession createSession(Object output, ObjectMap op, Method javaMethod, Locale locale, TimeZone timeZone, MediaType mediaType) { - return new RdfSerializerSession(getContext(RdfSerializerContext.class), op, output, javaMethod, locale, timeZone, mediaType); - } - - - //-------------------------------------------------------------------------------- - // Properties - //-------------------------------------------------------------------------------- - - /** - * <b>Configuration property:</b> RDF language. - * <p> - * <ul> - * <li><b>Name:</b> <js>"Rdf.language"</js> - * <li><b>Data type:</b> <code>String</code> - * <li><b>Default:</b> <js>"RDF/XML-ABBREV"</js> - * </ul> - * <p> - * Can be any of the following: - * <ul class='spaced-list'> - * <li><js>"RDF/XML"</js> - * <li><js>"RDF/XML-ABBREV"</js> - * <li><js>"N-TRIPLE"</js> - * <li><js>"N3"</js> - General name for the N3 writer. - * Will make a decision on exactly which writer to use (pretty writer, plain writer or simple writer) when created. - * Default is the pretty writer but can be overridden with system property <code>com.hp.hpl.jena.n3.N3JenaWriter.writer</code>. - * <li><js>"N3-PP"</js> - Name of the N3 pretty writer. - * The pretty writer uses a frame-like layout, with prefixing, clustering like properties and embedding one-referenced bNodes. - * <li><js>"N3-PLAIN"</js> - Name of the N3 plain writer. - * The plain writer writes records by subject. - * <li><js>"N3-TRIPLES"</js> - Name of the N3 triples writer. - * This writer writes one line per statement, like N-Triples, but does N3-style prefixing. - * <li><js>"TURTLE"</js> - Turtle writer. - * http://www.dajobe.org/2004/01/turtle/ - * </ul> - * <p> - * <h5 class='section'>Notes:</h5> - * <ul> - * <li>This is equivalent to calling <code>setProperty(<jsf>RDF_language</jsf>, value)</code>. - * <li>This introduces a slight performance penalty. - * </ul> - * - * @param value The new value for this property. - * @return This object (for method chaining). - * @throws LockedException If {@link #lock()} was called on this class. - * @see RdfCommonContext#RDF_language - */ - public RdfSerializer setLanguage(String value) throws LockedException { - return setProperty(RDF_language, value); - } - - /** - * <b>Configuration property:</b> XML namespace for Juneau properties. - * <p> - * <ul> - * <li><b>Name:</b> <js>"Rdf.juneauNs"</js> - * <li><b>Data type:</b> {@link Namespace} - * <li><b>Default:</b> <code>{j:<js>'http://www.apache.org/juneau/'</js>}</code> - * </ul> - * <p> - * <h5 class='section'>Notes:</h5> - * <ul> - * <li>This is equivalent to calling <code>setProperty(<jsf>RDF_juneauNs</jsf>, value)</code>. - * <li>This introduces a slight performance penalty. - * </ul> - * - * @param value The new value for this property. - * @return This object (for method chaining). - * @throws LockedException If {@link #lock()} was called on this class. - * @see RdfSerializerContext#RDF_juneauNs - */ - public RdfSerializer setJuneauNs(Namespace value) throws LockedException { - return setProperty(RDF_juneauNs, value); - } - - /** - * <b>Configuration property:</b> Default XML namespace for bean properties. - * <p> - * <ul> - * <li><b>Name:</b> <js>"Rdf.juneauBpNs"</js> - * <li><b>Data type:</b> {@link Namespace} - * <li><b>Default:</b> <code>{j:<js>'http://www.apache.org/juneaubp/'</js>}</code> - * </ul> - * <p> - * <h5 class='section'>Notes:</h5> - * <ul> - * <li>This is equivalent to calling <code>setProperty(<jsf>RDF_juneauBpNs</jsf>, value)</code>. - * <li>This introduces a slight performance penalty. - * </ul> - * - * @param value The new value for this property. - * @return This object (for method chaining). - * @throws LockedException If {@link #lock()} was called on this class. - * @see RdfSerializerContext#RDF_juneauBpNs - */ - public RdfSerializer setJuneauBpNs(Namespace value) throws LockedException { - return setProperty(RDF_juneauBpNs, value); - } - - /** - * <b>Configuration property:</b> Reuse XML namespaces when RDF namespaces not specified. - * <p> - * <ul> - * <li><b>Name:</b> <js>"Rdf.useXmlNamespaces"</js> - * <li><b>Data type:</b> <code>Boolean</code> - * <li><b>Default:</b> <jk>true</jk> - * </ul> - * <p> - * When specified, namespaces defined using {@link XmlNs} and {@link Xml} will be inherited by the RDF serializers. - * Otherwise, namespaces will be defined using {@link RdfNs} and {@link Rdf}. - * <p> - * <h5 class='section'>Notes:</h5> - * <ul> - * <li>This is equivalent to calling <code>setProperty(<jsf>RDF_useXmlNamespaces</jsf>, value)</code>. - * <li>This introduces a slight performance penalty. - * </ul> - * - * @param value The new value for this property. - * @return This object (for method chaining). - * @throws LockedException If {@link #lock()} was called on this class. - * @see SerializerContext#SERIALIZER_sortMaps - */ - public RdfSerializer setUseXmlNamespaces(boolean value) throws LockedException { - return setProperty(RDF_useXmlNamespaces, value); - } - - /** - * <b>Configuration property:</b> Add XSI data types to non-<code>String</code> literals. - * <p> - * <ul> - * <li><b>Name:</b> <js>"RdfSerializer.addLiteralTypes"</js> - * <li><b>Data type:</b> <code>Boolean</code> - * <li><b>Default:</b> <jk>false</jk> - * <li><b>Session-overridable:</b> <jk>true</jk> - * </ul> - * <p> - * <h5 class='section'>Notes:</h5> - * <ul> - * <li>This is equivalent to calling <code>setProperty(<jsf>RDF_addLiteralTypes</jsf>, value)</code>. - * <li>This introduces a slight performance penalty. - * </ul> - * - * @param value The new value for this property. - * @return This object (for method chaining). - * @throws LockedException If {@link #lock()} was called on this class. - * @see RdfSerializerContext#RDF_addLiteralTypes - */ - public RdfSerializer setAddLiteralTypes(boolean value) throws LockedException { - return setProperty(RDF_addLiteralTypes, value); - } - - /** - * <b>Configuration property:</b> Add RDF root identifier property to root node. - * <p> - * <ul> - * <li><b>Name:</b> <js>"RdfSerializer.addRootProperty"</js> - * <li><b>Data type:</b> <code>Boolean</code> - * <li><b>Default:</b> <jk>false</jk> - * <li><b>Session-overridable:</b> <jk>true</jk> - * </ul> - * <p> - * When enabled an RDF property <code>http://www.apache.org/juneau/root</code> is added with a value of <js>"true"</js> - * to identify the root node in the graph. - * This helps locate the root node during parsing. - * <p> - * If disabled, the parser has to search through the model to find any resources without - * incoming predicates to identify root notes, which can introduce a considerable performance - * degradation. - * <p> - * <h5 class='section'>Notes:</h5> - * <ul> - * <li>This is equivalent to calling <code>setProperty(<jsf>RDF_addRootProperty</jsf>, value)</code>. - * <li>This introduces a slight performance penalty. - * </ul> - * - * @param value The new value for this property. - * @return This object (for method chaining). - * @throws LockedException If {@link #lock()} was called on this class. - * @see RdfSerializerContext#RDF_addRootProperty - */ - public RdfSerializer setAddRootProperty(boolean value) throws LockedException { - return setProperty(RDF_addRootProperty, value); - } - - /** - * <b>Configuration property:</b> Auto-detect namespace usage. - * <p> - * <ul> - * <li><b>Name:</b> <js>"RdfSerializer.autoDetectNamespaces"</js> - * <li><b>Data type:</b> <code>Boolean</code> - * <li><b>Default:</b> <jk>true</jk> - * <li><b>Session-overridable:</b> <jk>true</jk> - * </ul> - * <p> - * Detect namespace usage before serialization. - * <p> - * If enabled, then the data structure will first be crawled looking for - * namespaces that will be encountered before the root element is - * serialized. - * <p> - * <h5 class='section'>Notes:</h5> - * <ul> - * <li>This is equivalent to calling <code>setProperty(<jsf>RDF_autoDetectNamespaces</jsf>, value)</code>. - * <li>This introduces a slight performance penalty. - * </ul> - * - * @param value The new value for this property. - * @return This object (for method chaining). - * @throws LockedException If {@link #lock()} was called on this class. - * @see RdfSerializerContext#RDF_autoDetectNamespaces - */ - public RdfSerializer setAutoDetectNamespaces(boolean value) throws LockedException { - return setProperty(RDF_autoDetectNamespaces, value); - } - - /** - * <b>Configuration property:</b> Default namespaces. - * <p> - * <ul> - * <li><b>Name:</b> <js>"RdfSerializer.namespaces.list"</js> - * <li><b>Data type:</b> <code>List<{@link Namespace}></code> - * <li><b>Default:</b> empty list - * <li><b>Session-overridable:</b> <jk>true</jk> - * </ul> - * <p> - * The default list of namespaces associated with this serializer. - * <p> - * <h5 class='section'>Notes:</h5> - * <ul> - * <li>This is equivalent to calling <code>setProperty(<jsf>RDF_namespaces</jsf>, values)</code>. - * <li>This introduces a slight performance penalty. - * </ul> - * - * @param values The new value for this property. - * @return This object (for method chaining). - * @throws LockedException If {@link #lock()} was called on this class. - * @see RdfSerializerContext#RDF_namespaces - */ - public RdfSerializer setNamespaces(Namespace...values) throws LockedException { - return setProperty(RDF_namespaces, values); - } - - /** - * <b>Configuration property:</b> RDF format for representing collections and arrays. - * <p> - * <ul> - * <li><b>Name:</b> <js>"Rdf.collectionFormat"</js> - * <li><b>Data type:</b> <code>RdfCollectionFormat</code> - * <li><b>Default:</b> <js>"DEFAULT"</js> - * </ul> - * <p> - * Possible values: - * <ul class='spaced-list'> - * <li><js>"DEFAULT"</js> - Default format. The default is an RDF Sequence container. - * <li><js>"SEQ"</js> - RDF Sequence container. - * <li><js>"BAG"</js> - RDF Bag container. - * <li><js>"LIST"</js> - RDF List container. - * <li><js>"MULTI_VALUED"</js> - Multi-valued properties. - * </ul> - * <p> - * <h5 class='section'>Notes:</h5> - * <ul> - * <li>If you use <js>"BAG"</js> or <js>"MULTI_VALUED"</js>, the order of the elements in the collection will get lost. - * </ul> - * <p> - * <h5 class='section'>Notes:</h5> - * <ul> - * <li>This is equivalent to calling <code>setProperty(<jsf>RDF_collectionFormat</jsf>, value)</code>. - * <li>This introduces a slight performance penalty. - * </ul> - * - * @param value The new value for this property. - * @return This object (for method chaining). - * @throws LockedException If {@link #lock()} was called on this class. - * @see RdfCommonContext#RDF_collectionFormat - */ - public RdfSerializer setCollectionFormat(RdfCollectionFormat value) throws LockedException { - return setProperty(RDF_collectionFormat, value); - } - - /** - * <b>Configuration property:</b> Collections should be serialized and parsed as loose collections. - * <p> - * <ul> - * <li><b>Name:</b> <js>"Rdf.looseCollections"</js> - * <li><b>Data type:</b> <code>Boolean</code> - * <li><b>Default:</b> <jk>false</jk> - * </ul> - * <p> - * When specified, collections of resources are handled as loose collections of resources in RDF instead of - * resources that are children of an RDF collection (e.g. Sequence, Bag). - * <p> - * Note that this setting is specialized for RDF syntax, and is incompatible with the concept of - * losslessly representing POJO models, since the tree structure of these POJO models are lost - * when serialized as loose collections. - * <p> - * This setting is typically only useful if the beans being parsed into do not have a bean property - * annotated with {@link Rdf#beanUri @Rdf(beanUri=true)}. - * - * <h5 class='section'>Example:</h5> - * <p class='bcode'> - * WriterSerializer s = <jk>new</jk> RdfSerializer.XmlAbbrev().setLooseCollections(<jk>true</jk>); - * ReaderParser p = <jk>new</jk> RdfParser.Xml().setLooseCollections(<jk>true</jk>); - * - * List<MyBean> l = createListOfMyBeans(); - * - * <jc>// Serialize to RDF/XML as loose resources</jc> - * String rdfXml = s.serialize(l); - * - * <jc>// Parse back into a Java collection</jc> - * l = p.parse(rdfXml, LinkedList.<jk>class</jk>, MyBean.<jk>class</jk>); - * - * MyBean[] b = createArrayOfMyBeans(); - * - * <jc>// Serialize to RDF/XML as loose resources</jc> - * String rdfXml = s.serialize(b); - * - * <jc>// Parse back into a bean array</jc> - * b = p.parse(rdfXml, MyBean[].<jk>class</jk>); - * </p> - * <p> - * <h5 class='section'>Notes:</h5> - * <ul> - * <li>This is equivalent to calling <code>setProperty(<jsf>RDF_looseCollections</jsf>, value)</code>. - * </ul> - * - * @param value The new value for this property. - * @return This object (for method chaining). - * @throws LockedException If {@link #lock()} was called on this class. - * @see RdfCommonContext#RDF_looseCollections - */ - public RdfSerializer setLooseCollections(boolean value) throws LockedException { - return setProperty(RDF_looseCollections, value); - } - - @Override /* Serializer */ - public RdfSerializer setMaxDepth(int value) throws LockedException { - super.setMaxDepth(value); - return this; - } - - @Override /* Serializer */ - public RdfSerializer setInitialDepth(int value) throws LockedException { - super.setInitialDepth(value); - return this; - } - - @Override /* Serializer */ - public RdfSerializer setDetectRecursions(boolean value) throws LockedException { - super.setDetectRecursions(value); - return this; - } - - @Override /* Serializer */ - public RdfSerializer setIgnoreRecursions(boolean value) throws LockedException { - super.setIgnoreRecursions(value); - return this; - } - - @Override /* Serializer */ - public RdfSerializer setUseWhitespace(boolean value) throws LockedException { - super.setUseWhitespace(value); - return this; - } - - @Override /* Serializer */ - public RdfSerializer setAddBeanTypeProperties(boolean value) throws LockedException { - super.setAddBeanTypeProperties(value); - return this; - } - - @Override /* Serializer */ - public RdfSerializer setQuoteChar(char value) throws LockedException { - super.setQuoteChar(value); - return this; - } - - @Override /* Serializer */ - public RdfSerializer setTrimNullProperties(boolean value) throws LockedException { - super.setTrimNullProperties(value); - return this; - } - - @Override /* Serializer */ - public RdfSerializer setTrimEmptyCollections(boolean value) throws LockedException { - super.setTrimEmptyCollections(value); - return this; - } - - @Override /* Serializer */ - public RdfSerializer setTrimEmptyMaps(boolean value) throws LockedException { - super.setTrimEmptyMaps(value); - return this; - } - - @Override /* Serializer */ - public RdfSerializer setTrimStrings(boolean value) throws LockedException { - super.setTrimStrings(value); - return this; - } - - @Override /* Serializer */ - public RdfSerializer setRelativeUriBase(String value) throws LockedException { - super.setRelativeUriBase(value); - return this; - } - - @Override /* Serializer */ - public RdfSerializer setAbsolutePathUriBase(String value) throws LockedException { - super.setAbsolutePathUriBase(value); - return this; - } - - @Override /* Serializer */ - public RdfSerializer setSortCollections(boolean value) throws LockedException { - super.setSortCollections(value); - return this; - } - - @Override /* Serializer */ - public RdfSerializer setSortMaps(boolean value) throws LockedException { - super.setSortMaps(value); - return this; - } - - @Override /* CoreApi */ - public RdfSerializer setBeansRequireDefaultConstructor(boolean value) throws LockedException { - super.setBeansRequireDefaultConstructor(value); - return this; - } - - @Override /* CoreApi */ - public RdfSerializer setBeansRequireSerializable(boolean value) throws LockedException { - super.setBeansRequireSerializable(value); - return this; - } - - @Override /* CoreApi */ - public RdfSerializer setBeansRequireSettersForGetters(boolean value) throws LockedException { - super.setBeansRequireSettersForGetters(value); - return this; - } - - @Override /* CoreApi */ - public RdfSerializer setBeansRequireSomeProperties(boolean value) throws LockedException { - super.setBeansRequireSomeProperties(value); - return this; - } - - @Override /* CoreApi */ - public RdfSerializer setBeanMapPutReturnsOldValue(boolean value) throws LockedException { - super.setBeanMapPutReturnsOldValue(value); - return this; - } - - @Override /* CoreApi */ - public RdfSerializer setBeanConstructorVisibility(Visibility value) throws LockedException { - super.setBeanConstructorVisibility(value); - return this; - } - - @Override /* CoreApi */ - public RdfSerializer setBeanClassVisibility(Visibility value) throws LockedException { - super.setBeanClassVisibility(value); - return this; - } - - @Override /* CoreApi */ - public RdfSerializer setBeanFieldVisibility(Visibility value) throws LockedException { - super.setBeanFieldVisibility(value); - return this; - } - - @Override /* CoreApi */ - public RdfSerializer setMethodVisibility(Visibility value) throws LockedException { - super.setMethodVisibility(value); - return this; - } - - @Override /* CoreApi */ - public RdfSerializer setUseJavaBeanIntrospector(boolean value) throws LockedException { - super.setUseJavaBeanIntrospector(value); - return this; - } - - @Override /* CoreApi */ - public RdfSerializer setUseInterfaceProxies(boolean value) throws LockedException { - super.setUseInterfaceProxies(value); - return this; - } - - @Override /* CoreApi */ - public RdfSerializer setIgnoreUnknownBeanProperties(boolean value) throws LockedException { - super.setIgnoreUnknownBeanProperties(value); - return this; - } - - @Override /* CoreApi */ - public RdfSerializer setIgnoreUnknownNullBeanProperties(boolean value) throws LockedException { - super.setIgnoreUnknownNullBeanProperties(value); - return this; - } - - @Override /* CoreApi */ - public RdfSerializer setIgnorePropertiesWithoutSetters(boolean value) throws LockedException { - super.setIgnorePropertiesWithoutSetters(value); - return this; - } - - @Override /* CoreApi */ - public RdfSerializer setIgnoreInvocationExceptionsOnGetters(boolean value) throws LockedException { - super.setIgnoreInvocationExceptionsOnGetters(value); - return this; - } - - @Override /* CoreApi */ - public RdfSerializer setIgnoreInvocationExceptionsOnSetters(boolean value) throws LockedException { - super.setIgnoreInvocationExceptionsOnSetters(value); - return this; - } - - @Override /* CoreApi */ - public RdfSerializer setSortProperties(boolean value) throws LockedException { - super.setSortProperties(value); - return this; - } - - @Override /* CoreApi */ - public RdfSerializer setNotBeanPackages(String...values) throws LockedException { - super.setNotBeanPackages(values); - return this; - } - - @Override /* CoreApi */ - public RdfSerializer setNotBeanPackages(Collection<String> values) throws LockedException { - super.setNotBeanPackages(values); - return this; - } - - @Override /* CoreApi */ - public RdfSerializer addNotBeanPackages(String...values) throws LockedException { - super.addNotBeanPackages(values); - return this; - } - - @Override /* CoreApi */ - public RdfSerializer addNotBeanPackages(Collection<String> values) throws LockedException { - super.addNotBeanPackages(values); - return this; - } - - @Override /* CoreApi */ - public RdfSerializer removeNotBeanPackages(String...values) throws LockedException { - super.removeNotBeanPackages(values); - return this; - } - - @Override /* CoreApi */ - public RdfSerializer removeNotBeanPackages(Collection<String> values) throws LockedException { - super.removeNotBeanPackages(values); - return this; - } - - @Override /* CoreApi */ - public RdfSerializer setNotBeanClasses(Class<?>...values) throws LockedException { - super.setNotBeanClasses(values); - return this; - } - - @Override /* CoreApi */ - public RdfSerializer setNotBeanClasses(Collection<Class<?>> values) throws LockedException { - super.setNotBeanClasses(values); - return this; - } - - @Override /* CoreApi */ - public RdfSerializer addNotBeanClasses(Class<?>...values) throws LockedException { - super.addNotBeanClasses(values); - return this; - } - - @Override /* CoreApi */ - public RdfSerializer addNotBeanClasses(Collection<Class<?>> values) throws LockedException { - super.addNotBeanClasses(values); - return this; - } - - @Override /* CoreApi */ - public RdfSerializer removeNotBeanClasses(Class<?>...values) throws LockedException { - super.removeNotBeanClasses(values); - return this; - } - - @Override /* CoreApi */ - public RdfSerializer removeNotBeanClasses(Collection<Class<?>> values) throws LockedException { - super.removeNotBeanClasses(values); - return this; - } - - @Override /* CoreApi */ - public RdfSerializer setBeanFilters(Class<?>...values) throws LockedException { - super.setBeanFilters(values); - return this; - } - - @Override /* CoreApi */ - public RdfSerializer setBeanFilters(Collection<Class<?>> values) throws LockedException { - super.setBeanFilters(values); - return this; - } - - @Override /* CoreApi */ - public RdfSerializer addBeanFilters(Class<?>...values) throws LockedException { - super.addBeanFilters(values); - return this; - } - - @Override /* CoreApi */ - public RdfSerializer addBeanFilters(Collection<Class<?>> values) throws LockedException { - super.addBeanFilters(values); - return this; - } - - @Override /* CoreApi */ - public RdfSerializer removeBeanFilters(Class<?>...values) throws LockedException { - super.removeBeanFilters(values); - return this; - } - - @Override /* CoreApi */ - public RdfSerializer removeBeanFilters(Collection<Class<?>> values) throws LockedException { - super.removeBeanFilters(values); - return this; - } - - @Override /* CoreApi */ - public RdfSerializer setPojoSwaps(Class<?>...values) throws LockedException { - super.setPojoSwaps(values); - return this; - } - - @Override /* CoreApi */ - public RdfSerializer setPojoSwaps(Collection<Class<?>> values) throws LockedException { - super.setPojoSwaps(values); - return this; - } - - @Override /* CoreApi */ - public RdfSerializer addPojoSwaps(Class<?>...values) throws LockedException { - super.addPojoSwaps(values); - return this; - } - - @Override /* CoreApi */ - public RdfSerializer addPojoSwaps(Collection<Class<?>> values) throws LockedException { - super.addPojoSwaps(values); - return this; - } - - @Override /* CoreApi */ - public RdfSerializer removePojoSwaps(Class<?>...values) throws LockedException { - super.removePojoSwaps(values); - return this; - } - - @Override /* CoreApi */ - public RdfSerializer removePojoSwaps(Collection<Class<?>> values) throws LockedException { - super.removePojoSwaps(values); - return this; - } - - @Override /* CoreApi */ - public RdfSerializer setImplClasses(Map<Class<?>,Class<?>> values) throws LockedException { - super.setImplClasses(values); - return this; - } - - @Override /* CoreApi */ - public <T> CoreApi addImplClass(Class<T> interfaceClass, Class<? extends T> implClass) throws LockedException { - super.addImplClass(interfaceClass, implClass); - return this; - } - - @Override /* CoreApi */ - public RdfSerializer setBeanDictionary(Class<?>...values) throws LockedException { - super.setBeanDictionary(values); - return this; - } - - @Override /* CoreApi */ - public RdfSerializer setBeanDictionary(Collection<Class<?>> values) throws LockedException { - super.setBeanDictionary(values); - return this; - } - - @Override /* CoreApi */ - public RdfSerializer addToBeanDictionary(Class<?>...values) throws LockedException { - super.addToBeanDictionary(values); - return this; - } - - @Override /* CoreApi */ - public RdfSerializer addToBeanDictionary(Collection<Class<?>> values) throws LockedException { - super.addToBeanDictionary(values); - return this; - } - - @Override /* CoreApi */ - public RdfSerializer removeFromBeanDictionary(Class<?>...values) throws LockedException { - super.removeFromBeanDictionary(values); - return this; - } - - @Override /* CoreApi */ - public RdfSerializer removeFromBeanDictionary(Collection<Class<?>> values) throws LockedException { - super.removeFromBeanDictionary(values); - return this; - } - - @Override /* CoreApi */ - public RdfSerializer setBeanTypePropertyName(String value) throws LockedException { - super.setBeanTypePropertyName(value); - return this; - } - - @Override /* CoreApi */ - public RdfSerializer setDefaultParser(Class<?> value) throws LockedException { - super.setDefaultParser(value); - return this; - } - - @Override /* CoreApi */ - public RdfSerializer setLocale(Locale value) throws LockedException { - super.setLocale(value); - return this; - } - - @Override /* CoreApi */ - public RdfSerializer setTimeZone(TimeZone value) throws LockedException { - super.setTimeZone(value); - return this; - } - - @Override /* CoreApi */ - public RdfSerializer setMediaType(MediaType value) throws LockedException { - super.setMediaType(value); - return this; - } - - @Override /* CoreApi */ - public RdfSerializer setDebug(boolean value) throws LockedException { - super.setDebug(value); - return this; - } - - @Override /* CoreApi */ - public RdfSerializer setProperty(String name, Object value) throws LockedException { - super.setProperty(name, value); - return this; - } - - @Override /* CoreApi */ - public RdfSerializer setProperties(ObjectMap properties) throws LockedException { - super.setProperties(properties); - return this; - } - - @Override /* CoreApi */ - public RdfSerializer addToProperty(String name, Object value) throws LockedException { - super.addToProperty(name, value); - return this; - } - - @Override /* CoreApi */ - public RdfSerializer putToProperty(String name, Object key, Object value) throws LockedException { - super.putToProperty(name, key, value); - return this; - } - - @Override /* CoreApi */ - public RdfSerializer putToProperty(String name, Object value) throws LockedException { - super.putToProperty(name, value); - return this; - } - - @Override /* CoreApi */ - public RdfSerializer removeFromProperty(String name, Object value) throws LockedException { - super.removeFromProperty(name, value); - return this; - } - - - //-------------------------------------------------------------------------------- - // Overridden methods - //-------------------------------------------------------------------------------- - - @Override /* CoreApi */ - public RdfSerializer setClassLoader(ClassLoader classLoader) throws LockedException { - super.setClassLoader(classLoader); - return this; - } - - @Override /* Lockable */ - public RdfSerializer lock() { - super.lock(); - return this; - } - - @Override /* Lockable */ - public RdfSerializer clone() { - try { - return (RdfSerializer)super.clone(); - } catch (CloneNotSupportedException e) { - throw new RuntimeException(e); // Shouldn't happen - } + return new RdfSerializerSession(ctx, op, output, javaMethod, locale, timeZone, mediaType); } }
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/95e832e1/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfSerializerBuilder.java ---------------------------------------------------------------------- diff --git a/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfSerializerBuilder.java b/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfSerializerBuilder.java new file mode 100644 index 0000000..6b150ad --- /dev/null +++ b/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfSerializerBuilder.java @@ -0,0 +1,890 @@ +// *************************************************************************************************************************** +// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * +// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * +// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * +// * with the License. You may obtain a copy of the License at * +// * * +// * http://www.apache.org/licenses/LICENSE-2.0 * +// * * +// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * +// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * +// * specific language governing permissions and limitations under the License. * +// *************************************************************************************************************************** +package org.apache.juneau.jena; + +import static org.apache.juneau.jena.RdfCommonContext.*; +import static org.apache.juneau.jena.RdfSerializerContext.*; + +import java.util.*; + +import org.apache.juneau.*; +import org.apache.juneau.jena.annotation.*; +import org.apache.juneau.serializer.*; +import org.apache.juneau.xml.*; +import org.apache.juneau.xml.annotation.*; + +/** + * Builder class for building instances of RDF serializers. + */ +public class RdfSerializerBuilder extends SerializerBuilder { + + /** + * Constructor, default settings. + */ + public RdfSerializerBuilder() { + super(); + } + + /** + * Constructor. + * @param propertyStore The initial configuration settings for this builder. + */ + public RdfSerializerBuilder(PropertyStore propertyStore) { + super(propertyStore); + } + + @Override /* CoreObjectBuilder */ + public RdfSerializer build() { + return new RdfSerializer(propertyStore); + } + + + //-------------------------------------------------------------------------------- + // Properties + //-------------------------------------------------------------------------------- + + /** + * <b>Configuration property:</b> RDF language. + * <p> + * <ul> + * <li><b>Name:</b> <js>"Rdf.language"</js> + * <li><b>Data type:</b> <code>String</code> + * <li><b>Default:</b> <js>"RDF/XML-ABBREV"</js> + * </ul> + * <p> + * Can be any of the following: + * <ul class='spaced-list'> + * <li><js>"RDF/XML"</js> + * <li><js>"RDF/XML-ABBREV"</js> + * <li><js>"N-TRIPLE"</js> + * <li><js>"N3"</js> - General name for the N3 writer. + * Will make a decision on exactly which writer to use (pretty writer, plain writer or simple writer) when created. + * Default is the pretty writer but can be overridden with system property <code>com.hp.hpl.jena.n3.N3JenaWriter.writer</code>. + * <li><js>"N3-PP"</js> - Name of the N3 pretty writer. + * The pretty writer uses a frame-like layout, with prefixing, clustering like properties and embedding one-referenced bNodes. + * <li><js>"N3-PLAIN"</js> - Name of the N3 plain writer. + * The plain writer writes records by subject. + * <li><js>"N3-TRIPLES"</js> - Name of the N3 triples writer. + * This writer writes one line per statement, like N-Triples, but does N3-style prefixing. + * <li><js>"TURTLE"</js> - Turtle writer. + * http://www.dajobe.org/2004/01/turtle/ + * </ul> + * <p> + * <h5 class='section'>Notes:</h5> + * <ul> + * <li>This is equivalent to calling <code>property(<jsf>RDF_language</jsf>, value)</code>. + * <li>This introduces a slight performance penalty. + * </ul> + * + * @param value The new value for this property. + * @return This object (for method chaining). + * @see RdfCommonContext#RDF_language + */ + public RdfSerializerBuilder language(String value) { + return property(RDF_language, value); + } + + /** + * Shortcut for calling <code>language(<jsf>LANG_RDF_XML</jsf>)</code> + * @return This object (for method chaining). + */ + public RdfSerializerBuilder xml() { + return language(Constants.LANG_RDF_XML); + } + + /** + * Shortcut for calling <code>language(<jsf>LANG_RDF_XML_ABBREV</jsf>)</code> + * @return This object (for method chaining). + */ + public RdfSerializerBuilder xmlabbrev() { + return language(Constants.LANG_RDF_XML_ABBREV); + } + + /** + * Shortcut for calling <code>language(<jsf>LANG_NTRIPLE</jsf>)</code> + * @return This object (for method chaining). + */ + public RdfSerializerBuilder ntriple() { + return language(Constants.LANG_NTRIPLE); + } + + /** + * Shortcut for calling <code>language(<jsf>LANG_N3</jsf>)</code> + * @return This object (for method chaining). + */ + public RdfSerializerBuilder n3() { + return language(Constants.LANG_N3); + } + + /** + * Shortcut for calling <code>language(<jsf>LANG_TURTLE</jsf>)</code> + * @return This object (for method chaining). + */ + public RdfSerializerBuilder turtle() { + return language(Constants.LANG_TURTLE); + } + + /** + * <b>Configuration property:</b> XML namespace for Juneau properties. + * <p> + * <ul> + * <li><b>Name:</b> <js>"Rdf.juneauNs"</js> + * <li><b>Data type:</b> {@link Namespace} + * <li><b>Default:</b> <code>{j:<js>'http://www.apache.org/juneau/'</js>}</code> + * </ul> + * <p> + * <h5 class='section'>Notes:</h5> + * <ul> + * <li>This is equivalent to calling <code>property(<jsf>RDF_juneauNs</jsf>, value)</code>. + * <li>This introduces a slight performance penalty. + * </ul> + * + * @param value The new value for this property. + * @return This object (for method chaining). + * @see RdfSerializerContext#RDF_juneauNs + */ + public RdfSerializerBuilder juneauNs(Namespace value) { + return property(RDF_juneauNs, value); + } + + /** + * <b>Configuration property:</b> Default XML namespace for bean properties. + * <p> + * <ul> + * <li><b>Name:</b> <js>"Rdf.juneauBpNs"</js> + * <li><b>Data type:</b> {@link Namespace} + * <li><b>Default:</b> <code>{j:<js>'http://www.apache.org/juneaubp/'</js>}</code> + * </ul> + * <p> + * <h5 class='section'>Notes:</h5> + * <ul> + * <li>This is equivalent to calling <code>property(<jsf>RDF_juneauBpNs</jsf>, value)</code>. + * <li>This introduces a slight performance penalty. + * </ul> + * + * @param value The new value for this property. + * @return This object (for method chaining). + * @see RdfSerializerContext#RDF_juneauBpNs + */ + public RdfSerializerBuilder juneauBpNs(Namespace value) { + return property(RDF_juneauBpNs, value); + } + + /** + * <b>Configuration property:</b> Reuse XML namespaces when RDF namespaces not specified. + * <p> + * <ul> + * <li><b>Name:</b> <js>"Rdf.useXmlNamespaces"</js> + * <li><b>Data type:</b> <code>Boolean</code> + * <li><b>Default:</b> <jk>true</jk> + * </ul> + * <p> + * When specified, namespaces defined using {@link XmlNs} and {@link Xml} will be inherited by the RDF serializers. + * Otherwise, namespaces will be defined using {@link RdfNs} and {@link Rdf}. + * <p> + * <h5 class='section'>Notes:</h5> + * <ul> + * <li>This is equivalent to calling <code>property(<jsf>RDF_useXmlNamespaces</jsf>, value)</code>. + * <li>This introduces a slight performance penalty. + * </ul> + * + * @param value The new value for this property. + * @return This object (for method chaining). + * @see SerializerContext#SERIALIZER_sortMaps + */ + public RdfSerializerBuilder useXmlNamespaces(boolean value) { + return property(RDF_useXmlNamespaces, value); + } + + /** + * <b>Configuration property:</b> Add XSI data types to non-<code>String</code> literals. + * <p> + * <ul> + * <li><b>Name:</b> <js>"RdfSerializer.addLiteralTypes"</js> + * <li><b>Data type:</b> <code>Boolean</code> + * <li><b>Default:</b> <jk>false</jk> + * <li><b>Session-overridable:</b> <jk>true</jk> + * </ul> + * <p> + * <h5 class='section'>Notes:</h5> + * <ul> + * <li>This is equivalent to calling <code>property(<jsf>RDF_addLiteralTypes</jsf>, value)</code>. + * <li>This introduces a slight performance penalty. + * </ul> + * + * @param value The new value for this property. + * @return This object (for method chaining). + * @see RdfSerializerContext#RDF_addLiteralTypes + */ + public RdfSerializerBuilder addLiteralTypes(boolean value) { + return property(RDF_addLiteralTypes, value); + } + + /** + * <b>Configuration property:</b> Add RDF root identifier property to root node. + * <p> + * <ul> + * <li><b>Name:</b> <js>"RdfSerializer.addRootProperty"</js> + * <li><b>Data type:</b> <code>Boolean</code> + * <li><b>Default:</b> <jk>false</jk> + * <li><b>Session-overridable:</b> <jk>true</jk> + * </ul> + * <p> + * When enabled an RDF property <code>http://www.apache.org/juneau/root</code> is added with a value of <js>"true"</js> + * to identify the root node in the graph. + * This helps locate the root node during parsing. + * <p> + * If disabled, the parser has to search through the model to find any resources without + * incoming predicates to identify root notes, which can introduce a considerable performance + * degradation. + * <p> + * <h5 class='section'>Notes:</h5> + * <ul> + * <li>This is equivalent to calling <code>property(<jsf>RDF_addRootProperty</jsf>, value)</code>. + * <li>This introduces a slight performance penalty. + * </ul> + * + * @param value The new value for this property. + * @return This object (for method chaining). + * @see RdfSerializerContext#RDF_addRootProperty + */ + public RdfSerializerBuilder addRootProperty(boolean value) { + return property(RDF_addRootProperty, value); + } + + /** + * <b>Configuration property:</b> Auto-detect namespace usage. + * <p> + * <ul> + * <li><b>Name:</b> <js>"RdfSerializer.autoDetectNamespaces"</js> + * <li><b>Data type:</b> <code>Boolean</code> + * <li><b>Default:</b> <jk>true</jk> + * <li><b>Session-overridable:</b> <jk>true</jk> + * </ul> + * <p> + * Detect namespace usage before serialization. + * <p> + * If enabled, then the data structure will first be crawled looking for + * namespaces that will be encountered before the root element is + * serialized. + * <p> + * <h5 class='section'>Notes:</h5> + * <ul> + * <li>This is equivalent to calling <code>property(<jsf>RDF_autoDetectNamespaces</jsf>, value)</code>. + * <li>This introduces a slight performance penalty. + * </ul> + * + * @param value The new value for this property. + * @return This object (for method chaining). + * @see RdfSerializerContext#RDF_autoDetectNamespaces + */ + public RdfSerializerBuilder autoDetectNamespaces(boolean value) { + return property(RDF_autoDetectNamespaces, value); + } + + /** + * <b>Configuration property:</b> Default namespaces. + * <p> + * <ul> + * <li><b>Name:</b> <js>"RdfSerializer.namespaces.list"</js> + * <li><b>Data type:</b> <code>List<{@link Namespace}></code> + * <li><b>Default:</b> empty list + * <li><b>Session-overridable:</b> <jk>true</jk> + * </ul> + * <p> + * The default list of namespaces associated with this serializer. + * <p> + * <h5 class='section'>Notes:</h5> + * <ul> + * <li>This is equivalent to calling <code>property(<jsf>RDF_namespaces</jsf>, values)</code>. + * <li>This introduces a slight performance penalty. + * </ul> + * + * @param values The new value for this property. + * @return This object (for method chaining). + * @see RdfSerializerContext#RDF_namespaces + */ + public RdfSerializerBuilder namespaces(Namespace...values) { + return property(RDF_namespaces, values); + } + + /** + * <b>Configuration property:</b> RDF format for representing collections and arrays. + * <p> + * <ul> + * <li><b>Name:</b> <js>"Rdf.collectionFormat"</js> + * <li><b>Data type:</b> <code>RdfCollectionFormat</code> + * <li><b>Default:</b> <js>"DEFAULT"</js> + * </ul> + * <p> + * Possible values: + * <ul class='spaced-list'> + * <li><js>"DEFAULT"</js> - Default format. The default is an RDF Sequence container. + * <li><js>"SEQ"</js> - RDF Sequence container. + * <li><js>"BAG"</js> - RDF Bag container. + * <li><js>"LIST"</js> - RDF List container. + * <li><js>"MULTI_VALUED"</js> - Multi-valued properties. + * </ul> + * <p> + * <h5 class='section'>Notes:</h5> + * <ul> + * <li>If you use <js>"BAG"</js> or <js>"MULTI_VALUED"</js>, the order of the elements in the collection will get lost. + * </ul> + * <p> + * <h5 class='section'>Notes:</h5> + * <ul> + * <li>This is equivalent to calling <code>property(<jsf>RDF_collectionFormat</jsf>, value)</code>. + * <li>This introduces a slight performance penalty. + * </ul> + * + * @param value The new value for this property. + * @return This object (for method chaining). + * @see RdfCommonContext#RDF_collectionFormat + */ + public RdfSerializerBuilder collectionFormat(RdfCollectionFormat value) { + return property(RDF_collectionFormat, value); + } + + /** + * <b>Configuration property:</b> Collections should be serialized and parsed as loose collections. + * <p> + * <ul> + * <li><b>Name:</b> <js>"Rdf.looseCollections"</js> + * <li><b>Data type:</b> <code>Boolean</code> + * <li><b>Default:</b> <jk>false</jk> + * </ul> + * <p> + * When specified, collections of resources are handled as loose collections of resources in RDF instead of + * resources that are children of an RDF collection (e.g. Sequence, Bag). + * <p> + * Note that this setting is specialized for RDF syntax, and is incompatible with the concept of + * losslessly representing POJO models, since the tree structure of these POJO models are lost + * when serialized as loose collections. + * <p> + * This setting is typically only useful if the beans being parsed into do not have a bean property + * annotated with {@link Rdf#beanUri @Rdf(beanUri=true)}. + * + * <h5 class='section'>Example:</h5> + * <p class='bcode'> + * WriterSerializer s = <jk>new</jk> RdfSerializerBuilder().xmlabbrev().looseCollections(<jk>true</jk>).build(); + * ReaderParser p = <jk>new</jk> RdfParserBuilder().xml().looseCollections(<jk>true</jk>).build(); + * + * List<MyBean> l = createListOfMyBeans(); + * + * <jc>// Serialize to RDF/XML as loose resources</jc> + * String rdfXml = s.serialize(l); + * + * <jc>// Parse back into a Java collection</jc> + * l = p.parse(rdfXml, LinkedList.<jk>class</jk>, MyBean.<jk>class</jk>); + * + * MyBean[] b = createArrayOfMyBeans(); + * + * <jc>// Serialize to RDF/XML as loose resources</jc> + * String rdfXml = s.serialize(b); + * + * <jc>// Parse back into a bean array</jc> + * b = p.parse(rdfXml, MyBean[].<jk>class</jk>); + * </p> + * <p> + * <h5 class='section'>Notes:</h5> + * <ul> + * <li>This is equivalent to calling <code>property(<jsf>RDF_looseCollections</jsf>, value)</code>. + * </ul> + * + * @param value The new value for this property. + * @return This object (for method chaining). + * @see RdfCommonContext#RDF_looseCollections + */ + public RdfSerializerBuilder looseCollections(boolean value) { + return property(RDF_looseCollections, value); + } + + @Override /* SerializerBuilder */ + public RdfSerializerBuilder maxDepth(int value) { + super.maxDepth(value); + return this; + } + + @Override /* SerializerBuilder */ + public RdfSerializerBuilder initialDepth(int value) { + super.initialDepth(value); + return this; + } + + @Override /* SerializerBuilder */ + public RdfSerializerBuilder detectRecursions(boolean value) { + super.detectRecursions(value); + return this; + } + + @Override /* SerializerBuilder */ + public RdfSerializerBuilder ignoreRecursions(boolean value) { + super.ignoreRecursions(value); + return this; + } + + @Override /* SerializerBuilder */ + public RdfSerializerBuilder useWhitespace(boolean value) { + super.useWhitespace(value); + return this; + } + + @Override /* SerializerBuilder */ + public RdfSerializerBuilder ws() { + super.ws(); + return this; + } + + @Override /* SerializerBuilder */ + public RdfSerializerBuilder addBeanTypeProperties(boolean value) { + super.addBeanTypeProperties(value); + return this; + } + + @Override /* SerializerBuilder */ + public RdfSerializerBuilder quoteChar(char value) { + super.quoteChar(value); + return this; + } + + @Override /* SerializerBuilder */ + public RdfSerializerBuilder sq() { + super.sq(); + return this; + } + + @Override /* SerializerBuilder */ + public RdfSerializerBuilder trimNullProperties(boolean value) { + super.trimNullProperties(value); + return this; + } + + @Override /* SerializerBuilder */ + public RdfSerializerBuilder trimEmptyCollections(boolean value) { + super.trimEmptyCollections(value); + return this; + } + + @Override /* SerializerBuilder */ + public RdfSerializerBuilder trimEmptyMaps(boolean value) { + super.trimEmptyMaps(value); + return this; + } + + @Override /* SerializerBuilder */ + public RdfSerializerBuilder trimStrings(boolean value) { + super.trimStrings(value); + return this; + } + + @Override /* SerializerBuilder */ + public RdfSerializerBuilder relativeUriBase(String value) { + super.relativeUriBase(value); + return this; + } + + @Override /* SerializerBuilder */ + public RdfSerializerBuilder absolutePathUriBase(String value) { + super.absolutePathUriBase(value); + return this; + } + + @Override /* SerializerBuilder */ + public RdfSerializerBuilder sortCollections(boolean value) { + super.sortCollections(value); + return this; + } + + @Override /* SerializerBuilder */ + public RdfSerializerBuilder sortMaps(boolean value) { + super.sortMaps(value); + return this; + } + @Override /* CoreObjectBuilder */ + public RdfSerializerBuilder beansRequireDefaultConstructor(boolean value) { + super.beansRequireDefaultConstructor(value); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfSerializerBuilder beansRequireSerializable(boolean value) { + super.beansRequireSerializable(value); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfSerializerBuilder beansRequireSettersForGetters(boolean value) { + super.beansRequireSettersForGetters(value); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfSerializerBuilder beansRequireSomeProperties(boolean value) { + super.beansRequireSomeProperties(value); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfSerializerBuilder beanMapPutReturnsOldValue(boolean value) { + super.beanMapPutReturnsOldValue(value); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfSerializerBuilder beanConstructorVisibility(Visibility value) { + super.beanConstructorVisibility(value); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfSerializerBuilder beanClassVisibility(Visibility value) { + super.beanClassVisibility(value); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfSerializerBuilder beanFieldVisibility(Visibility value) { + super.beanFieldVisibility(value); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfSerializerBuilder methodVisibility(Visibility value) { + super.methodVisibility(value); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfSerializerBuilder useJavaBeanIntrospector(boolean value) { + super.useJavaBeanIntrospector(value); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfSerializerBuilder useInterfaceProxies(boolean value) { + super.useInterfaceProxies(value); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfSerializerBuilder ignoreUnknownBeanProperties(boolean value) { + super.ignoreUnknownBeanProperties(value); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfSerializerBuilder ignoreUnknownNullBeanProperties(boolean value) { + super.ignoreUnknownNullBeanProperties(value); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfSerializerBuilder ignorePropertiesWithoutSetters(boolean value) { + super.ignorePropertiesWithoutSetters(value); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfSerializerBuilder ignoreInvocationExceptionsOnGetters(boolean value) { + super.ignoreInvocationExceptionsOnGetters(value); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfSerializerBuilder ignoreInvocationExceptionsOnSetters(boolean value) { + super.ignoreInvocationExceptionsOnSetters(value); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfSerializerBuilder sortProperties(boolean value) { + super.sortProperties(value); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfSerializerBuilder notBeanPackages(String...values) { + super.notBeanPackages(values); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfSerializerBuilder notBeanPackages(Collection<String> values) { + super.notBeanPackages(values); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfSerializerBuilder setNotBeanPackages(String...values) { + super.setNotBeanPackages(values); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfSerializerBuilder setNotBeanPackages(Collection<String> values) { + super.setNotBeanPackages(values); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfSerializerBuilder removeNotBeanPackages(String...values) { + super.removeNotBeanPackages(values); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfSerializerBuilder removeNotBeanPackages(Collection<String> values) { + super.removeNotBeanPackages(values); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfSerializerBuilder notBeanClasses(Class<?>...values) { + super.notBeanClasses(values); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfSerializerBuilder notBeanClasses(Collection<Class<?>> values) { + super.notBeanClasses(values); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfSerializerBuilder setNotBeanClasses(Class<?>...values) { + super.setNotBeanClasses(values); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfSerializerBuilder setNotBeanClasses(Collection<Class<?>> values) { + super.setNotBeanClasses(values); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfSerializerBuilder removeNotBeanClasses(Class<?>...values) { + super.removeNotBeanClasses(values); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfSerializerBuilder removeNotBeanClasses(Collection<Class<?>> values) { + super.removeNotBeanClasses(values); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfSerializerBuilder beanFilters(Class<?>...values) { + super.beanFilters(values); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfSerializerBuilder beanFilters(Collection<Class<?>> values) { + super.beanFilters(values); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfSerializerBuilder setBeanFilters(Class<?>...values) { + super.setBeanFilters(values); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfSerializerBuilder setBeanFilters(Collection<Class<?>> values) { + super.setBeanFilters(values); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfSerializerBuilder removeBeanFilters(Class<?>...values) { + super.removeBeanFilters(values); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfSerializerBuilder removeBeanFilters(Collection<Class<?>> values) { + super.removeBeanFilters(values); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfSerializerBuilder pojoSwaps(Class<?>...values) { + super.pojoSwaps(values); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfSerializerBuilder pojoSwaps(Collection<Class<?>> values) { + super.pojoSwaps(values); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfSerializerBuilder setPojoSwaps(Class<?>...values) { + super.setPojoSwaps(values); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfSerializerBuilder setPojoSwaps(Collection<Class<?>> values) { + super.setPojoSwaps(values); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfSerializerBuilder removePojoSwaps(Class<?>...values) { + super.removePojoSwaps(values); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfSerializerBuilder removePojoSwaps(Collection<Class<?>> values) { + super.removePojoSwaps(values); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfSerializerBuilder implClasses(Map<Class<?>,Class<?>> values) { + super.implClasses(values); + return this; + } + + @Override /* CoreObjectBuilder */ + public <T> RdfSerializerBuilder implClass(Class<T> interfaceClass, Class<? extends T> implClass) { + super.implClass(interfaceClass, implClass); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfSerializerBuilder beanDictionary(Class<?>...values) { + super.beanDictionary(values); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfSerializerBuilder beanDictionary(Collection<Class<?>> values) { + super.beanDictionary(values); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfSerializerBuilder setBeanDictionary(Class<?>...values) { + super.setBeanDictionary(values); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfSerializerBuilder setBeanDictionary(Collection<Class<?>> values) { + super.setBeanDictionary(values); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfSerializerBuilder removeFromBeanDictionary(Class<?>...values) { + super.removeFromBeanDictionary(values); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfSerializerBuilder removeFromBeanDictionary(Collection<Class<?>> values) { + super.removeFromBeanDictionary(values); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfSerializerBuilder beanTypePropertyName(String value) { + super.beanTypePropertyName(value); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfSerializerBuilder defaultParser(Class<?> value) { + super.defaultParser(value); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfSerializerBuilder locale(Locale value) { + super.locale(value); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfSerializerBuilder timeZone(TimeZone value) { + super.timeZone(value); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfSerializerBuilder mediaType(MediaType value) { + super.mediaType(value); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfSerializerBuilder debug(boolean value) { + super.debug(value); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfSerializerBuilder property(String name, Object value) { + super.property(name, value); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfSerializerBuilder properties(Map<String,Object> properties) { + super.properties(properties); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfSerializerBuilder addToProperty(String name, Object value) { + super.addToProperty(name, value); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfSerializerBuilder putToProperty(String name, Object key, Object value) { + super.putToProperty(name, key, value); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfSerializerBuilder putToProperty(String name, Object value) { + super.putToProperty(name, value); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfSerializerBuilder removeFromProperty(String name, Object value) { + super.removeFromProperty(name, value); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfSerializerBuilder classLoader(ClassLoader classLoader) { + super.classLoader(classLoader); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfSerializerBuilder apply(PropertyStore copyFrom) { + super.apply(copyFrom); + return this; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/95e832e1/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfSerializerContext.java ---------------------------------------------------------------------- diff --git a/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfSerializerContext.java b/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfSerializerContext.java index 8c91057..5c3b680 100644 --- a/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfSerializerContext.java +++ b/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfSerializerContext.java @@ -21,10 +21,10 @@ import org.apache.juneau.xml.*; /** * Configurable properties on the {@link RdfSerializer} class. * <p> - * Context properties are set by calling {@link ContextFactory#setProperty(String, Object)} on the context factory - * returned {@link CoreApi#getContextFactory()}. + * Context properties are set by calling {@link PropertyStore#setProperty(String, Object)} on the property store + * passed into the constructor. * <p> - * See {@link ContextFactory} for more information about context properties. + * See {@link PropertyStore} for more information about context properties. * * <h6 class='topic' id='ConfigProperties'>Configurable properties inherited by the RDF serializers</h6> * <ul class='javahierarchy'> @@ -140,23 +140,23 @@ public final class RdfSerializerContext extends SerializerContext implements Rdf /** * Constructor. * <p> - * Typically only called from {@link ContextFactory#getContext(Class)}. + * Typically only called from {@link PropertyStore#getContext(Class)}. * - * @param cf The factory that created this context. + * @param ps The property store that created this context. */ - public RdfSerializerContext(ContextFactory cf) { - super(cf); - addLiteralTypes = cf.getProperty(RDF_addLiteralTypes, boolean.class, false); - addRootProperty = cf.getProperty(RDF_addRootProperty, boolean.class, false); - useXmlNamespaces = cf.getProperty(RDF_useXmlNamespaces, boolean.class, true); - looseCollections = cf.getProperty(RDF_looseCollections, boolean.class, false); - autoDetectNamespaces = cf.getProperty(RDF_autoDetectNamespaces, boolean.class, true); - rdfLanguage = cf.getProperty(RDF_language, String.class, "RDF/XML-ABBREV"); - juneauNs = cf.getProperty(RDF_juneauNs, Namespace.class, new Namespace("j", "http://www.apache.org/juneau/")); - juneauBpNs = cf.getProperty(RDF_juneauBpNs, Namespace.class, new Namespace("jp", "http://www.apache.org/juneaubp/")); - collectionFormat = cf.getProperty(RDF_collectionFormat, RdfCollectionFormat.class, RdfCollectionFormat.DEFAULT); - namespaces = cf.getProperty(RDF_namespaces, Namespace[].class, new Namespace[0]); - addBeanTypeProperties = cf.getProperty(RDF_addBeanTypeProperties, boolean.class, cf.getProperty(SERIALIZER_addBeanTypeProperties, boolean.class, true)); + public RdfSerializerContext(PropertyStore ps) { + super(ps); + addLiteralTypes = ps.getProperty(RDF_addLiteralTypes, boolean.class, false); + addRootProperty = ps.getProperty(RDF_addRootProperty, boolean.class, false); + useXmlNamespaces = ps.getProperty(RDF_useXmlNamespaces, boolean.class, true); + looseCollections = ps.getProperty(RDF_looseCollections, boolean.class, false); + autoDetectNamespaces = ps.getProperty(RDF_autoDetectNamespaces, boolean.class, true); + rdfLanguage = ps.getProperty(RDF_language, String.class, "RDF/XML-ABBREV"); + juneauNs = ps.getProperty(RDF_juneauNs, Namespace.class, new Namespace("j", "http://www.apache.org/juneau/")); + juneauBpNs = ps.getProperty(RDF_juneauBpNs, Namespace.class, new Namespace("jp", "http://www.apache.org/juneaubp/")); + collectionFormat = ps.getProperty(RDF_collectionFormat, RdfCollectionFormat.class, RdfCollectionFormat.DEFAULT); + namespaces = ps.getProperty(RDF_namespaces, Namespace[].class, new Namespace[0]); + addBeanTypeProperties = ps.getProperty(RDF_addBeanTypeProperties, boolean.class, ps.getProperty(SERIALIZER_addBeanTypeProperties, boolean.class, true)); } @Override /* Context */ http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/95e832e1/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfSerializerSession.java ---------------------------------------------------------------------- diff --git a/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfSerializerSession.java b/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfSerializerSession.java index c44951a..b2e63d9 100644 --- a/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfSerializerSession.java +++ b/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfSerializerSession.java @@ -57,7 +57,7 @@ public final class RdfSerializerSession extends SerializerSession { * @param output The output object. See {@link JsonSerializerSession#getWriter()} for valid class types. * @param op The override properties. * These override any context properties defined in the context. - * @param javaMethod The java method that called this parser, usually the method in a REST servlet. + * @param javaMethod The java method that called this serializer, usually the method in a REST servlet. * @param locale The session locale. * If <jk>null</jk>, then the locale defined on the context is used. * @param timeZone The session timezone. http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/95e832e1/juneau-core-rdf/src/main/java/org/apache/juneau/jena/package.html ---------------------------------------------------------------------- diff --git a/juneau-core-rdf/src/main/java/org/apache/juneau/jena/package.html b/juneau-core-rdf/src/main/java/org/apache/juneau/jena/package.html index d5b446d..c29250c 100644 --- a/juneau-core-rdf/src/main/java/org/apache/juneau/jena/package.html +++ b/juneau-core-rdf/src/main/java/org/apache/juneau/jena/package.html @@ -238,7 +238,7 @@ </p> <p class='bcode'> <jc>// Create a new serializer with readable output.</jc> - RdfSerializer s = <jk>new</jk> RdfSerializer.XmlAbbrev().setProperty(RdfProperties.<jsf>RDF_rdfxml_tab</jsf>, 3); + RdfSerializer s = <jk>new</jk> RdfSerializerBuilder().xmlabbrev().property(RdfProperties.<jsf>RDF_rdfxml_tab</jsf>, 3).build(); <jc>// Create our bean.</jc> Person p = <jk>new</jk> Person(1, <js>"John Smith"</js>); @@ -251,7 +251,7 @@ </p> <p class='bcode'> <jc>// Create a new serializer with readable output by cloning an existing serializer.</jc> - RdfSerializer s = RdfSerializer.<jsf>DEFAULT_XMLABBREV</jsf>.clone().setProperty(RdfProperties.<jsf>RDF_rdfxml_tab</jsf>, 3); + RdfSerializer s = RdfSerializer.<jsf>DEFAULT_XMLABBREV</jsf>.builder().property(RdfProperties.<jsf>RDF_rdfxml_tab</jsf>, 3).build(); </p> <p> This code produces the following output: @@ -344,10 +344,12 @@ </p> <p class='bcode'> <jc>// Create a new serializer, but manually specify the namespaces.</jc> - RdfSerializer s = <jk>new</jk> RdfSerializer.XmlAbbrev() - .setProperty(RdfProperties.<jsf>RDF_rdfxml_tab</jsf>, 3) - .setProperty(XmlSerializerContext.<jsf>XML_autoDetectNamespaces</jsf>, <jk>false</jk>) - .setProperty(XmlSerializerContext.<jsf>XML_namespaces</jsf>, <js>"{per:'http://www.apache.org/person/'}"</js>); + RdfSerializer s = <jk>new</jk> RdfSerializerBuilder() + .xmlabbrev() + .property(RdfProperties.<jsf>RDF_rdfxml_tab</jsf>, 3) + .autoDetectNamespaces(<jk>false</jk>) + .namespaces(<js>"{per:'http://www.apache.org/person/'}"</js>) + .build(); </p> <p> This code change will produce the same output as before, but will perform slightly better since it doesn't have to crawl the POJO tree before serializing the result. @@ -440,10 +442,12 @@ </p> <p class='bcode'> <jc>// Create a new serializer with readable output.</jc> - RdfSerializer s = <jk>new</jk> RdfSerializer.XmlAbbrev() - .setProperty(RdfProperties.<jsf>RDF_rdfxml_tab</jsf>, 3); - .setProperty(SerializerContext.<jsf>SERIALIZER_relativeUriBase</jsf>, <js>"http://myhost/sample"</js>); - .setProperty(SerializerContext.<jsf>SERIALIZER_absolutePathUriBase</jsf>, <js>"http://myhost"</js>); + RdfSerializer s = <jk>new</jk> RdfSerializerBuilder() + .xmlabbrev() + .property(RdfProperties.<jsf>RDF_rdfxml_tab</jsf>, 3); + .relativeUriBase(<js>"http://myhost/sample"</js>); + .absolutePathUriBase(<js>"http://myhost"</js>) + .build(); <jc>// Create our bean.</jc> Person p = <jk>new</jk> Person(1, <js>"John Smith"</js>, <js>"person/1"</js>, <js>"/"</js>); @@ -559,7 +563,7 @@ </p> <p class='bcode'> <jc>// Create a new serializer (revert back to namespace autodetection).</jc> - RdfSerializer s = <jk>new</jk> RdfSerializer.XmlAbbrev().setProperty(RdfProperties.<jsf>RDF_rdfxml_tab</jsf>, 3); + RdfSerializer s = <jk>new</jk> RdfSerializerBuilder().xmlabbrev().property(RdfProperties.<jsf>RDF_rdfxml_tab</jsf>, 3).build(); <jc>// Create our bean.</jc> Person p = <jk>new</jk> Person(1, <js>"John Smith"</js>, <js>"http://sample/addressBook/person/1"</js>, <js>"http://sample/addressBook"</js>, <js>"Aug 12, 1946"</js>); @@ -635,9 +639,11 @@ </p> <p class='bcode'> <jc>// Create a new serializer.</jc> - RdfSerializer s = <jk>new</jk> RdfSerializer.XmlAbbrev() - .setProperty(RdfProperties.<jsf>RDF_rdfxml_tab</jsf>, 3), - .setProperty(RdfSerializerContext.<jsf>RDF_addRootProperty</jsf>, <jk>true</jk>); + RdfSerializer s = <jk>new</jk> RdfSerializerBuilder() + .xmlabbrev() + .property(RdfProperties.<jsf>RDF_rdfxml_tab</jsf>, 3), + .addRootProperty(<jk>true</jk>) + .build(); </p> <p> Now when we rerun the sample code, we'll see the added <code>root</code> attribute on the root resource. @@ -689,9 +695,11 @@ </p> <p class='bcode'> <jc>// Create a new serializer (revert back to namespace autodetection).</jc> - RdfSerializer s = <jk>new</jk> RdfSerializer.XmlAbbrev() - .setProperty(RdfProperties.<jsf>RDF_rdfxml_tab</jsf>, 3), - .setProperty(RdfSerializerContext.<jsf>RDF_addLiteralTypes</jsf>, <jk>true</jk>); + RdfSerializer s = <jk>new</jk> RdfSerializerBuilder() + .xmlabbrev() + .property(RdfProperties.<jsf>RDF_rdfxml_tab</jsf>, 3), + .addLiteralTypes(<jk>true</jk>) + .build(); </p> <p> Now when we rerun the sample code, we'll see the added <code>root</code> attribute on the root resource. @@ -809,9 +817,11 @@ </p> <p class='bcode'> <jc>// Create a new serializer with readable output.</jc> - RdfSerializer s = <jk>new</jk> RdfSerializer.XmlAbbrev() - .setProperty(RdfProperties.<jsf>RDF_rdfxml_tab</jsf>, 3) - .setProperty(RdfSerializerContext.<jsf>RDF_addRootProperty</jsf>, <jk>true</jk>); + RdfSerializer s = <jk>new</jk> RdfSerializerBuilder() + .xmlabbrev() + .property(RdfProperties.<jsf>RDF_rdfxml_tab</jsf>, 3) + .addRootProperty(<jk>true</jk>) + .build(); <jc>// Create our bean.</jc> Person p = <jk>new</jk> Person(1, <js>"John Smith"</js>, <js>"http://sample/addressBook/person/1"</js>, <js>"http://sample/addressBook"</js>, <js>"Aug 12, 1946"</js>); @@ -1361,7 +1371,7 @@ </p> <p class='bcode'> <jc>// Create a client to handle RDF/XML requests and responses.</jc> - RestClient client = <jk>new</jk> RestClient(RdfSerializer.XmlAbbrev.<jk>class</jk>, RdfParser.Xml.<jk>class</jk>); + RestClient client = <jk>new</jk> RestClientBuilder(RdfSerializer.XmlAbbrev.<jk>class</jk>, RdfParser.Xml.<jk>class</jk>).build(); </p> <p> The client handles all content negotiation based on the registered serializers and parsers. http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/95e832e1/juneau-core-test/src/test/java/org/apache/juneau/BeanConfigTest.java ---------------------------------------------------------------------- diff --git a/juneau-core-test/src/test/java/org/apache/juneau/BeanConfigTest.java b/juneau-core-test/src/test/java/org/apache/juneau/BeanConfigTest.java index 3757598..b55b98e 100755 --- a/juneau-core-test/src/test/java/org/apache/juneau/BeanConfigTest.java +++ b/juneau-core-test/src/test/java/org/apache/juneau/BeanConfigTest.java @@ -457,7 +457,7 @@ public class BeanConfigTest { //==================================================================================================== @Test public void testProxyHandler() throws Exception { - BeanSession session = ContextFactory.create().getBeanContext().createSession(); + BeanSession session = PropertyStore.create().getBeanContext().createSession(); A f1 = (A) Proxy.newProxyInstance(this.getClass() .getClassLoader(), new Class[] { A.class }, @@ -564,153 +564,153 @@ public class BeanConfigTest { //==================================================================================================== @Test public void testClassMetaCaching() throws Exception { - Parser p1, p2; + ParserBuilder p1, p2; - p1 = new JsonParser(); - p2 = new JsonParser(); + p1 = new JsonParserBuilder(); + p2 = new JsonParserBuilder(); assertSameCache(p1, p2); - p1.setBeansRequireDefaultConstructor(true); + p1.beansRequireDefaultConstructor(true); assertDifferentCache(p1, p2); - p2.setBeansRequireDefaultConstructor(true); + p2.beansRequireDefaultConstructor(true); assertSameCache(p1, p2); - p1.setBeansRequireSerializable(true); + p1.beansRequireSerializable(true); assertDifferentCache(p1, p2); - p2.setBeansRequireSerializable(true); + p2.beansRequireSerializable(true); assertSameCache(p1, p2); - p1.setBeansRequireSettersForGetters(true); + p1.beansRequireSettersForGetters(true); assertDifferentCache(p1, p2); - p2.setBeansRequireSettersForGetters(true); + p2.beansRequireSettersForGetters(true); assertSameCache(p1, p2); - p1.setBeansRequireSomeProperties(false); + p1.beansRequireSomeProperties(false); assertDifferentCache(p1, p2); - p2.setBeansRequireSomeProperties(false); + p2.beansRequireSomeProperties(false); assertSameCache(p1, p2); - p1.setBeanMapPutReturnsOldValue(true); + p1.beanMapPutReturnsOldValue(true); assertDifferentCache(p1, p2); - p2.setBeanMapPutReturnsOldValue(true); + p2.beanMapPutReturnsOldValue(true); assertSameCache(p1, p2); - p1.setBeanConstructorVisibility(Visibility.DEFAULT); + p1.beanConstructorVisibility(Visibility.DEFAULT); assertDifferentCache(p1, p2); - p2.setBeanConstructorVisibility(Visibility.DEFAULT); + p2.beanConstructorVisibility(Visibility.DEFAULT); assertSameCache(p1, p2); - p1.setBeanConstructorVisibility(Visibility.NONE); + p1.beanConstructorVisibility(Visibility.NONE); assertDifferentCache(p1, p2); - p2.setBeanConstructorVisibility(Visibility.NONE); + p2.beanConstructorVisibility(Visibility.NONE); assertSameCache(p1, p2); - p1.setBeanConstructorVisibility(Visibility.PRIVATE); + p1.beanConstructorVisibility(Visibility.PRIVATE); assertDifferentCache(p1, p2); - p2.setBeanConstructorVisibility(Visibility.PRIVATE); + p2.beanConstructorVisibility(Visibility.PRIVATE); assertSameCache(p1, p2); - p1.setBeanConstructorVisibility(Visibility.PROTECTED); + p1.beanConstructorVisibility(Visibility.PROTECTED); assertDifferentCache(p1, p2); - p2.setBeanConstructorVisibility(Visibility.PROTECTED); + p2.beanConstructorVisibility(Visibility.PROTECTED); assertSameCache(p1, p2); - p1.setBeanClassVisibility(Visibility.DEFAULT); + p1.beanClassVisibility(Visibility.DEFAULT); assertDifferentCache(p1, p2); - p2.setBeanClassVisibility(Visibility.DEFAULT); + p2.beanClassVisibility(Visibility.DEFAULT); assertSameCache(p1, p2); - p1.setBeanClassVisibility(Visibility.NONE); + p1.beanClassVisibility(Visibility.NONE); assertDifferentCache(p1, p2); - p2.setBeanClassVisibility(Visibility.NONE); + p2.beanClassVisibility(Visibility.NONE); assertSameCache(p1, p2); - p1.setBeanClassVisibility(Visibility.PRIVATE); + p1.beanClassVisibility(Visibility.PRIVATE); assertDifferentCache(p1, p2); - p2.setBeanClassVisibility(Visibility.PRIVATE); + p2.beanClassVisibility(Visibility.PRIVATE); assertSameCache(p1, p2); - p1.setBeanClassVisibility(Visibility.PROTECTED); + p1.beanClassVisibility(Visibility.PROTECTED); assertDifferentCache(p1, p2); - p2.setBeanClassVisibility(Visibility.PROTECTED); + p2.beanClassVisibility(Visibility.PROTECTED); assertSameCache(p1, p2); - p1.setBeanFieldVisibility(Visibility.DEFAULT); + p1.beanFieldVisibility(Visibility.DEFAULT); assertDifferentCache(p1, p2); - p2.setBeanFieldVisibility(Visibility.DEFAULT); + p2.beanFieldVisibility(Visibility.DEFAULT); assertSameCache(p1, p2); - p1.setBeanFieldVisibility(Visibility.NONE); + p1.beanFieldVisibility(Visibility.NONE); assertDifferentCache(p1, p2); - p2.setBeanFieldVisibility(Visibility.NONE); + p2.beanFieldVisibility(Visibility.NONE); assertSameCache(p1, p2); - p1.setBeanFieldVisibility(Visibility.PRIVATE); + p1.beanFieldVisibility(Visibility.PRIVATE); assertDifferentCache(p1, p2); - p2.setBeanFieldVisibility(Visibility.PRIVATE); + p2.beanFieldVisibility(Visibility.PRIVATE); assertSameCache(p1, p2); - p1.setBeanFieldVisibility(Visibility.PROTECTED); + p1.beanFieldVisibility(Visibility.PROTECTED); assertDifferentCache(p1, p2); - p2.setBeanFieldVisibility(Visibility.PROTECTED); + p2.beanFieldVisibility(Visibility.PROTECTED); assertSameCache(p1, p2); - p1.setMethodVisibility(Visibility.DEFAULT); + p1.methodVisibility(Visibility.DEFAULT); assertDifferentCache(p1, p2); - p2.setMethodVisibility(Visibility.DEFAULT); + p2.methodVisibility(Visibility.DEFAULT); assertSameCache(p1, p2); - p1.setMethodVisibility(Visibility.NONE); + p1.methodVisibility(Visibility.NONE); assertDifferentCache(p1, p2); - p2.setMethodVisibility(Visibility.NONE); + p2.methodVisibility(Visibility.NONE); assertSameCache(p1, p2); - p1.setMethodVisibility(Visibility.PRIVATE); + p1.methodVisibility(Visibility.PRIVATE); assertDifferentCache(p1, p2); - p2.setMethodVisibility(Visibility.PRIVATE); + p2.methodVisibility(Visibility.PRIVATE); assertSameCache(p1, p2); - p1.setMethodVisibility(Visibility.PROTECTED); + p1.methodVisibility(Visibility.PROTECTED); assertDifferentCache(p1, p2); - p2.setMethodVisibility(Visibility.PROTECTED); + p2.methodVisibility(Visibility.PROTECTED); assertSameCache(p1, p2); - p1.setUseJavaBeanIntrospector(true); + p1.useJavaBeanIntrospector(true); assertDifferentCache(p1, p2); - p2.setUseJavaBeanIntrospector(true); + p2.useJavaBeanIntrospector(true); assertSameCache(p1, p2); - p1.setUseInterfaceProxies(false); + p1.useInterfaceProxies(false); assertDifferentCache(p1, p2); - p2.setUseInterfaceProxies(false); + p2.useInterfaceProxies(false); assertSameCache(p1, p2); - p1.setIgnoreUnknownBeanProperties(true); + p1.ignoreUnknownBeanProperties(true); assertDifferentCache(p1, p2); - p2.setIgnoreUnknownBeanProperties(true); + p2.ignoreUnknownBeanProperties(true); assertSameCache(p1, p2); - p1.setIgnoreUnknownNullBeanProperties(false); + p1.ignoreUnknownNullBeanProperties(false); assertDifferentCache(p1, p2); - p2.setIgnoreUnknownNullBeanProperties(false); + p2.ignoreUnknownNullBeanProperties(false); assertSameCache(p1, p2); - p1.setIgnorePropertiesWithoutSetters(false); + p1.ignorePropertiesWithoutSetters(false); assertDifferentCache(p1, p2); - p2.setIgnorePropertiesWithoutSetters(false); + p2.ignorePropertiesWithoutSetters(false); assertSameCache(p1, p2); - p1.setIgnoreInvocationExceptionsOnGetters(true); + p1.ignoreInvocationExceptionsOnGetters(true); assertDifferentCache(p1, p2); - p2.setIgnoreInvocationExceptionsOnGetters(true); + p2.ignoreInvocationExceptionsOnGetters(true); assertSameCache(p1, p2); - p1.setIgnoreInvocationExceptionsOnSetters(true); + p1.ignoreInvocationExceptionsOnSetters(true); assertDifferentCache(p1, p2); - p2.setIgnoreInvocationExceptionsOnSetters(true); + p2.ignoreInvocationExceptionsOnSetters(true); assertSameCache(p1, p2); - p1.addNotBeanPackages("foo"); + p1.notBeanPackages("foo"); assertDifferentCache(p1, p2); - p2.addNotBeanPackages("foo"); + p2.notBeanPackages("foo"); assertSameCache(p1, p2); - p1.addNotBeanPackages("bar"); + p1.notBeanPackages("bar"); assertDifferentCache(p1, p2); - p2.addNotBeanPackages("bar"); + p2.notBeanPackages("bar"); assertSameCache(p1, p2); - p1.addNotBeanPackages("baz"); - p1.addNotBeanPackages("bing"); + p1.notBeanPackages("baz"); + p1.notBeanPackages("bing"); assertDifferentCache(p1, p2); - p2.addNotBeanPackages("bing"); - p2.addNotBeanPackages("baz"); + p2.notBeanPackages("bing"); + p2.notBeanPackages("baz"); assertSameCache(p1, p2); p1.removeNotBeanPackages("bar"); @@ -718,22 +718,22 @@ public class BeanConfigTest { p2.removeNotBeanPackages("bar"); assertSameCache(p1, p2); - p1.addPojoSwaps(DummyPojoSwapA.class); + p1.pojoSwaps(DummyPojoSwapA.class); assertDifferentCache(p1, p2); - p2.addPojoSwaps(DummyPojoSwapA.class); + p2.pojoSwaps(DummyPojoSwapA.class); assertSameCache(p1, p2); - p1.addPojoSwaps(DummyPojoSwapB.class,DummyPojoSwapC.class); // Order of filters is important! - p2.addPojoSwaps(DummyPojoSwapC.class,DummyPojoSwapB.class); + p1.pojoSwaps(DummyPojoSwapB.class,DummyPojoSwapC.class); // Order of filters is important! + p2.pojoSwaps(DummyPojoSwapC.class,DummyPojoSwapB.class); assertDifferentCache(p1, p2); - p1 = new JsonParser(); - p2 = new JsonParser(); - p1.addBeanFilters(DummyBeanFilterA.class); + p1 = new JsonParserBuilder(); + p2 = new JsonParserBuilder(); + p1.beanFilters(DummyBeanFilterA.class); assertDifferentCache(p1, p2); - p2.addBeanFilters(DummyBeanFilterA.class); + p2.beanFilters(DummyBeanFilterA.class); assertSameCache(p1, p2); - p1.addBeanFilters(DummyBeanFilterB.class,DummyBeanFilterC.class); // Order of filters is important! - p2.addBeanFilters(DummyBeanFilterC.class,DummyBeanFilterB.class); + p1.beanFilters(DummyBeanFilterB.class,DummyBeanFilterC.class); // Order of filters is important! + p2.beanFilters(DummyBeanFilterC.class,DummyBeanFilterB.class); assertDifferentCache(p1, p2); } @@ -757,12 +757,14 @@ public class BeanConfigTest { } public static class C {} - private void assertSameCache(Parser p1, Parser p2) { + private void assertSameCache(ParserBuilder p1b, ParserBuilder p2b) { + Parser p1 = p1b.build(), p2 = p2b.build(); assertTrue(p1.getBeanContext().hasSameCache(p2.getBeanContext())); assertTrue(p1.getBeanContext().hashCode() == p2.getBeanContext().hashCode()); } - private void assertDifferentCache(Parser p1, Parser p2) { + private void assertDifferentCache(ParserBuilder p1b, ParserBuilder p2b) { + Parser p1 = p1b.build(), p2 = p2b.build(); assertFalse(p1.getBeanContext().hasSameCache(p2.getBeanContext())); assertFalse(p1.getBeanContext().hashCode() == p2.getBeanContext().hashCode()); } http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/95e832e1/juneau-core-test/src/test/java/org/apache/juneau/BeanFilterTest.java ---------------------------------------------------------------------- diff --git a/juneau-core-test/src/test/java/org/apache/juneau/BeanFilterTest.java b/juneau-core-test/src/test/java/org/apache/juneau/BeanFilterTest.java index 8116344..8b6f383 100755 --- a/juneau-core-test/src/test/java/org/apache/juneau/BeanFilterTest.java +++ b/juneau-core-test/src/test/java/org/apache/juneau/BeanFilterTest.java @@ -89,7 +89,7 @@ public class BeanFilterTest { //==================================================================================================== @Test public void testParentClassFilter() throws Exception { - JsonSerializer s = new JsonSerializer.Simple().addBeanFilters(C1.class); + JsonSerializer s = new JsonSerializerBuilder().simple().beanFilters(C1.class).build(); C1 c1 = new C2(); String r = s.serialize(c1); @@ -114,7 +114,7 @@ public class BeanFilterTest { //==================================================================================================== @Test public void testParentClassFilter2() throws Exception { - JsonSerializer s = new JsonSerializer.Simple().addBeanFilters(D1.class); + JsonSerializer s = new JsonSerializerBuilder().simple().beanFilters(D1.class).build(); D1 d1 = new D2(); String r = s.serialize(d1);
