http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/75b0d8ee/juneau-core/juneau-marshall-rdf/.classpath ---------------------------------------------------------------------- diff --git a/juneau-core/juneau-marshall-rdf/.classpath b/juneau-core/juneau-marshall-rdf/.classpath new file mode 100644 index 0000000..49432dc --- /dev/null +++ b/juneau-core/juneau-marshall-rdf/.classpath @@ -0,0 +1,31 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="src" output="target/classes" path="src/main/java"> + <attributes> + <attribute name="optional" value="true"/> + <attribute name="maven.pomderived" value="true"/> + </attributes> + </classpathentry> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"> + <attributes> + <attribute name="maven.pomderived" value="true"/> + </attributes> + </classpathentry> + <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"> + <attributes> + <attribute name="maven.pomderived" value="true"/> + </attributes> + </classpathentry> + <classpathentry kind="src" output="target/test-classes" path="src/test/java"> + <attributes> + <attribute name="optional" value="true"/> + <attribute name="maven.pomderived" value="true"/> + </attributes> + </classpathentry> + <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> + <attributes> + <attribute name="maven.pomderived" value="true"/> + </attributes> + </classpathentry> + <classpathentry kind="output" path="target/classes"/> +</classpath>
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/75b0d8ee/juneau-core/juneau-marshall-rdf/.gitignore ---------------------------------------------------------------------- diff --git a/juneau-core/juneau-marshall-rdf/.gitignore b/juneau-core/juneau-marshall-rdf/.gitignore new file mode 100644 index 0000000..d274d47 --- /dev/null +++ b/juneau-core/juneau-marshall-rdf/.gitignore @@ -0,0 +1,3 @@ +/target/ +/.settings/ +/.DS_Store http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/75b0d8ee/juneau-core/juneau-marshall-rdf/.project ---------------------------------------------------------------------- diff --git a/juneau-core/juneau-marshall-rdf/.project b/juneau-core/juneau-marshall-rdf/.project new file mode 100644 index 0000000..9922e3d --- /dev/null +++ b/juneau-core/juneau-marshall-rdf/.project @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>juneau-marshall-rdf</name> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>edu.umd.cs.findbugs.plugin.eclipse.findbugsBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.m2e.core.maven2Builder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.m2e.core.maven2Nature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + <nature>edu.umd.cs.findbugs.plugin.eclipse.findbugsNature</nature> + </natures> +</projectDescription> http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/75b0d8ee/juneau-core/juneau-marshall-rdf/pom.xml ---------------------------------------------------------------------- diff --git a/juneau-core/juneau-marshall-rdf/pom.xml b/juneau-core/juneau-marshall-rdf/pom.xml new file mode 100644 index 0000000..62490a4 --- /dev/null +++ b/juneau-core/juneau-marshall-rdf/pom.xml @@ -0,0 +1,108 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + *************************************************************************************************************************** + * 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. * + *************************************************************************************************************************** +--> +<project + xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.juneau</groupId> + <artifactId>juneau-core</artifactId> + <version>6.3.2-incubating-SNAPSHOT</version> + </parent> + + <artifactId>juneau-marshall-rdf</artifactId> + <name>Apache Juneau Marshal RDF</name> + <description>Addition to the marshall API for RDF support.</description> + <packaging>bundle</packaging> + + <dependencies> + <dependency> + <groupId>org.apache.juneau</groupId> + <artifactId>juneau-marshall</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.apache.jena</groupId> + <artifactId>jena-core</artifactId> + <optional>true</optional> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + </dependency> + </dependencies> + + <properties> + <!-- Skip javadoc generation since we generate them in the aggregate pom --> + <maven.javadoc.skip>true</maven.javadoc.skip> + </properties> + + <build> + <plugins> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <version>3.2.0</version> + <extensions>true</extensions> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <includes> + <include>**/*Test.class</include> + </includes> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-source-plugin</artifactId> + <executions> + <execution> + <id>attach-sources</id> + <phase>verify</phase> + <goals> + <goal>jar-no-fork</goal> + </goals> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.jacoco</groupId> + <artifactId>jacoco-maven-plugin</artifactId> + <version>0.7.2.201409121644</version> + <executions> + <execution> + <id>default-prepare-agent</id> + <goals> + <goal>prepare-agent</goal> + </goals> + </execution> + <execution> + <id>default-report</id> + <phase>prepare-package</phase> + <goals> + <goal>report</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> +</project> http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/75b0d8ee/juneau-core/juneau-marshall-rdf/src/main/java/org/apache/juneau/jena/Constants.java ---------------------------------------------------------------------- diff --git a/juneau-core/juneau-marshall-rdf/src/main/java/org/apache/juneau/jena/Constants.java b/juneau-core/juneau-marshall-rdf/src/main/java/org/apache/juneau/jena/Constants.java new file mode 100644 index 0000000..2920b5d --- /dev/null +++ b/juneau-core/juneau-marshall-rdf/src/main/java/org/apache/juneau/jena/Constants.java @@ -0,0 +1,99 @@ +// *************************************************************************************************************************** +// * 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 org.apache.juneau.serializer.*; + +/** + * Constants used by the {@link RdfSerializer} and {@link RdfParser} classes. + */ +public final class Constants { + + //-------------------------------------------------------------------------------- + // Built-in Jena languages. + //-------------------------------------------------------------------------------- + + /** Jena language support: <js>"RDF/XML"</js>.*/ + public static final String LANG_RDF_XML = "RDF/XML"; + + /** Jena language support: <js>"RDF/XML-ABBREV"</js>.*/ + public static final String LANG_RDF_XML_ABBREV = "RDF/XML-ABBREV"; + + /** Jena language support: <js>"N-TRIPLE"</js>.*/ + public static final String LANG_NTRIPLE = "N-TRIPLE"; + + /** Jena language support: <js>"TURTLE"</js>.*/ + public static final String LANG_TURTLE = "TURTLE"; + + /** Jena language support: <js>"N3"</js>.*/ + public static final String LANG_N3 = "N3"; + + + //-------------------------------------------------------------------------------- + // Built-in Juneau properties. + //-------------------------------------------------------------------------------- + + /** + * RDF property identifier <js>"items"</js>. + * + * <p> + * For resources that are collections, this property identifies the RDF Sequence container for the items in the + * collection. + */ + public static final String RDF_juneauNs_ITEMS = "items"; + + /** + * RDF property identifier <js>"root"</js>. + * + * <p> + * Property added to root nodes to help identify them as root elements during parsing. + * + * <p> + * Added if {@link RdfSerializerContext#RDF_addRootProperty} setting is enabled. + */ + public static final String RDF_juneauNs_ROOT = "root"; + + /** + * RDF property identifier <js>"class"</js>. + * + * <p> + * Property added to bean resources to identify the class type. + * + * <p> + * Added if {@link SerializerContext#SERIALIZER_addBeanTypeProperties} setting is enabled. + */ + public static final String RDF_juneauNs_TYPE = "_type"; + + /** + * RDF property identifier <js>"value"</js>. + * + * <p> + * Property added to nodes to identify a simple value. + */ + public static final String RDF_juneauNs_VALUE = "value"; + + /** + * RDF resource that identifies a <jk>null</jk> value. + */ + public static final String RDF_NIL = "http://www.w3.org/1999/02/22-rdf-syntax-ns#nil"; + + /** + * RDF resource that identifies a <code>Seq</code> value. + */ + public static final String RDF_SEQ = "http://www.w3.org/1999/02/22-rdf-syntax-ns#Seq"; + + /** + * RDF resource that identifies a <code>Bag</code> value. + */ + public static final String RDF_BAG = "http://www.w3.org/1999/02/22-rdf-syntax-ns#Bag"; +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/75b0d8ee/juneau-core/juneau-marshall-rdf/src/main/java/org/apache/juneau/jena/RdfBeanMeta.java ---------------------------------------------------------------------- diff --git a/juneau-core/juneau-marshall-rdf/src/main/java/org/apache/juneau/jena/RdfBeanMeta.java b/juneau-core/juneau-marshall-rdf/src/main/java/org/apache/juneau/jena/RdfBeanMeta.java new file mode 100644 index 0000000..b929db3 --- /dev/null +++ b/juneau-core/juneau-marshall-rdf/src/main/java/org/apache/juneau/jena/RdfBeanMeta.java @@ -0,0 +1,63 @@ +// *************************************************************************************************************************** +// * 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 org.apache.juneau.*; +import org.apache.juneau.jena.annotation.*; + +/** + * Metadata on beans specific to the RDF serializers and parsers pulled from the {@link Rdf @Rdf} annotation on the + * class. + */ +public class RdfBeanMeta extends BeanMetaExtended { + + // RDF related fields + private final BeanPropertyMeta beanUriProperty; // Bean property that identifies the URI of the bean. + + /** + * Constructor. + * + * @param beanMeta The metadata on the bean that this metadata applies to. + */ + public RdfBeanMeta(BeanMeta<?> beanMeta) { + super(beanMeta); + + BeanPropertyMeta t_beanUriProperty = null; + for (BeanPropertyMeta p : beanMeta.getPropertyMetas()) { + RdfBeanPropertyMeta bpm = p.getExtendedMeta(RdfBeanPropertyMeta.class); + if (bpm.isBeanUri()) + t_beanUriProperty = p; + } + + this.beanUriProperty = t_beanUriProperty; + } + + /** + * Returns <jk>true</jk> if one of the properties on this bean is annotated with {@link Rdf#beanUri()} as + * <jk>true</jk> + * + * @return <jk>true</jk> if there is a URI property associated with this bean. + */ + public boolean hasBeanUri() { + return beanUriProperty != null; + } + + /** + * Returns the bean property marked as the URI for the bean (annotated with {@link Rdf#beanUri()} as <jk>true</jk>). + * + * @return The URI property, or <jk>null</jk> if no URI property exists on this bean. + */ + public BeanPropertyMeta getBeanUriProperty() { + return beanUriProperty; + } +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/75b0d8ee/juneau-core/juneau-marshall-rdf/src/main/java/org/apache/juneau/jena/RdfBeanPropertyMeta.java ---------------------------------------------------------------------- diff --git a/juneau-core/juneau-marshall-rdf/src/main/java/org/apache/juneau/jena/RdfBeanPropertyMeta.java b/juneau-core/juneau-marshall-rdf/src/main/java/org/apache/juneau/jena/RdfBeanPropertyMeta.java new file mode 100644 index 0000000..b226607 --- /dev/null +++ b/juneau-core/juneau-marshall-rdf/src/main/java/org/apache/juneau/jena/RdfBeanPropertyMeta.java @@ -0,0 +1,95 @@ +// *************************************************************************************************************************** +// * 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.RdfCollectionFormat.*; + +import java.util.*; + +import org.apache.juneau.*; +import org.apache.juneau.jena.annotation.*; +import org.apache.juneau.xml.*; + +/** + * Metadata on bean properties specific to the RDF serializers and parsers pulled from the {@link Rdf @Rdf} annotation + * on the bean property. + */ +public class RdfBeanPropertyMeta extends BeanPropertyMetaExtended { + + private RdfCollectionFormat collectionFormat = DEFAULT; + private Namespace namespace = null; + private boolean isBeanUri; + + /** + * Constructor. + * + * @param bpm The metadata of the bean property of this additional metadata. + */ + public RdfBeanPropertyMeta(BeanPropertyMeta bpm) { + super(bpm); + + List<Rdf> rdfs = bpm.findAnnotations(Rdf.class); + List<RdfSchema> schemas = bpm.findAnnotations(RdfSchema.class); + + for (Rdf rdf : rdfs) { + if (collectionFormat == DEFAULT) + collectionFormat = rdf.collectionFormat(); + if (rdf.beanUri()) + isBeanUri = true; + } + + namespace = RdfUtils.findNamespace(rdfs, schemas); + } + + /** + * Returns the RDF collection format of this property from the {@link Rdf#collectionFormat} annotation on this bean + * property. + * + * @return The RDF collection format, or {@link RdfCollectionFormat#DEFAULT} if annotation not specified. + */ + protected RdfCollectionFormat getCollectionFormat() { + return collectionFormat; + } + + /** + * Returns the RDF namespace associated with this bean property. + * + * <p> + * Namespace is determined in the following order: + * <ol> + * <li>{@link Rdf#prefix()} annotation defined on bean property field. + * <li>{@link Rdf#prefix()} annotation defined on bean getter. + * <li>{@link Rdf#prefix()} annotation defined on bean setter. + * <li>{@link Rdf#prefix()} annotation defined on bean. + * <li>{@link Rdf#prefix()} annotation defined on bean package. + * <li>{@link Rdf#prefix()} annotation defined on bean superclasses. + * <li>{@link Rdf#prefix()} annotation defined on bean superclass packages. + * <li>{@link Rdf#prefix()} annotation defined on bean interfaces. + * <li>{@link Rdf#prefix()} annotation defined on bean interface packages. + * </ol> + * + * @return The namespace associated with this bean property, or <jk>null</jk> if no namespace is associated with it. + */ + public Namespace getNamespace() { + return namespace; + } + + /** + * Returns <jk>true</jk> if this bean property is marked with {@link Rdf#beanUri()} as <jk>true</jk>. + * + * @return <jk>true</jk> if this bean property is marked with {@link Rdf#beanUri()} as <jk>true</jk>. + */ + public boolean isBeanUri() { + return isBeanUri; + } +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/75b0d8ee/juneau-core/juneau-marshall-rdf/src/main/java/org/apache/juneau/jena/RdfClassMeta.java ---------------------------------------------------------------------- diff --git a/juneau-core/juneau-marshall-rdf/src/main/java/org/apache/juneau/jena/RdfClassMeta.java b/juneau-core/juneau-marshall-rdf/src/main/java/org/apache/juneau/jena/RdfClassMeta.java new file mode 100644 index 0000000..76d1e35 --- /dev/null +++ b/juneau-core/juneau-marshall-rdf/src/main/java/org/apache/juneau/jena/RdfClassMeta.java @@ -0,0 +1,89 @@ +// *************************************************************************************************************************** +// * 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 java.util.*; + +import org.apache.juneau.*; +import org.apache.juneau.internal.*; +import org.apache.juneau.jena.annotation.*; +import org.apache.juneau.xml.*; + +/** + * Metadata on classes specific to the RDF serializers and parsers pulled from the {@link Rdf @Rdf} annotation on the + * class. + */ +public class RdfClassMeta extends ClassMetaExtended { + + private final Rdf rdf; + private final RdfCollectionFormat collectionFormat; + private final Namespace namespace; + + /** + * Constructor. + * + * @param cm The class that this annotation is defined on. + */ + public RdfClassMeta(ClassMeta<?> cm) { + super(cm); + Class<?> c = getInnerClass(); + this.rdf = ReflectionUtils.getAnnotation(Rdf.class, c); + if (rdf != null) { + collectionFormat = rdf.collectionFormat(); + } else { + collectionFormat = RdfCollectionFormat.DEFAULT; + } + List<Rdf> rdfs = ReflectionUtils.findAnnotations(Rdf.class, c); + List<RdfSchema> schemas = ReflectionUtils.findAnnotations(RdfSchema.class, c); + this.namespace = RdfUtils.findNamespace(rdfs, schemas); + } + + /** + * Returns the {@link Rdf} annotation defined on the class. + * + * @return The value of the {@link Rdf} annotation, or <jk>null</jk> if annotation is not specified. + */ + protected Rdf getAnnotation() { + return rdf; + } + + /** + * Returns the {@link Rdf#collectionFormat()} annotation defined on the class. + * + * @return The value of the {@link Rdf#collectionFormat()} annotation, or <jk>null</jk> if annotation is not + * specified. + */ + protected RdfCollectionFormat getCollectionFormat() { + return collectionFormat; + } + + /** + * Returns the RDF namespace associated with this class. + * + * <p> + * Namespace is determined in the following order: + * <ol> + * <li>{@link Rdf#prefix()} annotation defined on class. + * <li>{@link Rdf#prefix()} annotation defined on package. + * <li>{@link Rdf#prefix()} annotation defined on superclasses. + * <li>{@link Rdf#prefix()} annotation defined on superclass packages. + * <li>{@link Rdf#prefix()} annotation defined on interfaces. + * <li>{@link Rdf#prefix()} annotation defined on interface packages. + * </ol> + * + * @return The namespace associated with this class, or <jk>null</jk> if no namespace is associated with it. + */ + protected Namespace getNamespace() { + return namespace; + } +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/75b0d8ee/juneau-core/juneau-marshall-rdf/src/main/java/org/apache/juneau/jena/RdfCollectionFormat.java ---------------------------------------------------------------------- diff --git a/juneau-core/juneau-marshall-rdf/src/main/java/org/apache/juneau/jena/RdfCollectionFormat.java b/juneau-core/juneau-marshall-rdf/src/main/java/org/apache/juneau/jena/RdfCollectionFormat.java new file mode 100644 index 0000000..2ff1370 --- /dev/null +++ b/juneau-core/juneau-marshall-rdf/src/main/java/org/apache/juneau/jena/RdfCollectionFormat.java @@ -0,0 +1,55 @@ +// *************************************************************************************************************************** +// * 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 org.apache.juneau.jena.annotation.*; + +/** + * Used in conjunction with the {@link Rdf#collectionFormat() @Rdf.collectionFormat()} annotation to fine-tune how + * classes, beans, and bean properties are serialized, particularly collections. + */ +public enum RdfCollectionFormat { + + /** + * Default formatting (default). + * + * <p> + * Inherit formatting from parent class or parent package. + * If no formatting specified at any level, default is {@link #SEQ}. + */ + DEFAULT, + + /** + * Causes collections and arrays to be rendered as RDF sequences. + */ + SEQ, + + /** + * Causes collections and arrays to be rendered as RDF bags. + */ + BAG, + + /** + * Causes collections and arrays to be rendered as RDF lists. + */ + LIST, + + /** + * Causes collections and arrays to be rendered as multi-valued RDF properties instead of sequences. + * + * <p> + * Note that enabling this setting will cause order of elements in the collection to be lost. + */ + MULTI_VALUED; + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/75b0d8ee/juneau-core/juneau-marshall-rdf/src/main/java/org/apache/juneau/jena/RdfCommonContext.java ---------------------------------------------------------------------- diff --git a/juneau-core/juneau-marshall-rdf/src/main/java/org/apache/juneau/jena/RdfCommonContext.java b/juneau-core/juneau-marshall-rdf/src/main/java/org/apache/juneau/jena/RdfCommonContext.java new file mode 100644 index 0000000..ae65e23 --- /dev/null +++ b/juneau-core/juneau-marshall-rdf/src/main/java/org/apache/juneau/jena/RdfCommonContext.java @@ -0,0 +1,646 @@ +// *************************************************************************************************************************** +// * 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 java.util.*; + +import org.apache.juneau.jena.annotation.*; +import org.apache.juneau.utils.*; +import org.apache.juneau.xml.*; +import org.apache.juneau.xml.annotation.*; + +/** + * Configurable properties common to both the {@link RdfSerializer} and {@link RdfParser} classes. + */ +public interface RdfCommonContext { + + /** + * Maps RDF writer names to property prefixes that apply to them. + */ + final static Map<String,String> LANG_PROP_MAP = new AMap<String,String>() + .append("RDF/XML","rdfXml.") + .append("RDF/XML-ABBREV","rdfXml.") + .append("N3","n3.") + .append("N3-PP","n3.") + .append("N3-PLAIN","n3.") + .append("N3-TRIPLES","n3.") + .append("TURTLE","n3.") + .append("N-TRIPLE","ntriple."); + + /** + * <b>Configuration property:</b> RDF language. + * + * <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> + */ + public static final String RDF_language = "Rdf.language"; + + /** + * <b>Configuration property:</b> XML namespace for Juneau properties. + * + * <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> + */ + public static final String RDF_juneauNs = "Rdf.juneauNs"; + + /** + * <b>Configuration property:</b> Default XML namespace for bean properties. + * + * <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> + */ + public static final String RDF_juneauBpNs = "Rdf.juneauBpNs"; + + /** + * <b>Configuration property:</b> Reuse XML namespaces when RDF namespaces not specified. + * + * <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}. + */ + public static final String RDF_useXmlNamespaces = "Rdf.useXmlNamespaces"; + + /** + * <b>Configuration property:</b> RDF/XML property: <code>iri_rules</code>. + * + * <ul> + * <li><b>Name:</b> <js>"Rdf.jena.rdfXml.iri-rules"</js> + * <li><b>Data type:</b> <code>String</code> + * <li><b>Default:</b> <js>"lax"</js> + * </ul> + * + * <p> + * Set the engine for checking and resolving. + * + * <p> + * Possible values: + * <ul class='spaced-list'> + * <li> + * <js>"lax"</js> - The rules for RDF URI references only, which does permit spaces although the use of spaces + * is not good practice. + * <li> + * <js>"strict"</js> - Sets the IRI engine with rules for valid IRIs, XLink and RDF; it does not permit spaces + * in IRIs. + * <li> + * <js>"iri"</js> - Sets the IRI engine to IRI + * (<a class="doclink" href="http://www.ietf.org/rfc/rfc3986.txt">RFC 3986</a>, + * <a class="doclink" href="http://www.ietf.org/rfc/rfc3987.txt">RFC 3987</a>). + * </ul> + */ + public static final String RDF_arp_iriRules = "Rdf.jena.rdfXml.iri-rules"; + + /** + * <b>Configuration property:</b> RDF/XML ARP property: <code>error-mode</code>. + * + * <ul> + * <li><b>Name:</b> <js>"Rdf.jena.rdfXml.error-mode"</js> + * <li><b>Data type:</b> <code>String</code> + * <li><b>Default:</b> <js>"lax"</js> + * </ul> + * + * <p> + * This allows a coarse-grained approach to control of error handling. + * + * <p> + * Possible values: + * <ul> + * <li><js>"default"</js> + * <li><js>"lax"</js> + * <li><js>"strict"</js> + * <li><js>"strict-ignore"</js> + * <li><js>"strict-warning"</js> + * <li><js>"strict-error"</js> + * <li><js>"strict-fatal"</js> + * </ul> + * + * <p> + * See also: + * <ul class='spaced-list'> + * <li> + * <a class="doclink" href="http://jena.sourceforge.net/javadoc/com/hp/hpl/jena/rdf/arp/ARPOptions.html#setDefaultErrorMode()">ARPOptions.setDefaultErrorMode()</a> + * <li> + * <a class="doclink" href="http://jena.sourceforge.net/javadoc/com/hp/hpl/jena/rdf/arp/ARPOptions.html#setLaxErrorMode()">ARPOptions.setLaxErrorMode()</a> + * <li> + * <a class="doclink" href="http://jena.sourceforge.net/javadoc/com/hp/hpl/jena/rdf/arp/ARPOptions.html#setStrictErrorMode()">ARPOptions.setStrictErrorMode()</a> + * <li> + * <a class="doclink" href="http://jena.sourceforge.net/javadoc/com/hp/hpl/jena/rdf/arp/ARPOptions.html#setStrictErrorMode(int)">ARPOptions.setStrictErrorMode(int)</a> + * </ul> + */ + public static final String RDF_arp_errorMode = "Rdf.jena.rdfXml.error-mode"; + + /** + * <b>Configuration property:</b> RDF/XML ARP property: <code>embedding</code>. + * + * <ul> + * <li><b>Name:</b> <js>"Rdf.jena.rdfXml.embedding"</js> + * <li><b>Data type:</b> <code>Boolean</code> + * <li><b>Default:</b> <jk>false</jk> + * </ul> + * + * <p> + * Sets ARP to look for RDF embedded within an enclosing XML document. + * + * <p> + * See also: + * <ul class='spaced-list'> + * <li> + * <a class="doclink" href="http://jena.sourceforge.net/javadoc/com/hp/hpl/jena/rdf/arp/ARPOptions.html#setEmbedding(boolean)">ARPOptions.setEmbedding(boolean)</a> + * </ul> + */ + public static final String RDF_arp_embedding = "Rdf.jena.rdfXml.embedding"; + + /** + * <b>Configuration property:</b> RDF/XML ARP property: <code>ERR_xxx</code>. + * + * <ul> + * <li><b>Name:</b> <js>"Rdf.jena.rdfXml.ERR_"</js> + * <li><b>Data type:</b> <code>String</code> + * </ul> + * + * <p> + * Provides fine-grained control over detected error conditions. + * + * <p> + * Possible values: + * <ul> + * <li><js>"EM_IGNORE"</js> + * <li><js>"EM_WARNING"</js> + * <li><js>"EM_ERROR"</js> + * <li><js>"EM_FATAL"</js> + * </ul> + * + * <p> + * See also: + * <ul class='spaced-list'> + * <li> + * <a class="doclink" href="http://jena.sourceforge.net/javadoc/com/hp/hpl/jena/rdf/arp/ARPErrorNumbers.html">ARPErrorNumbers</a> + * <li> + * <a class="doclink" href="http://jena.sourceforge.net/javadoc/com/hp/hpl/jena/rdf/arp/ARPOptions.html#setErrorMode(int,%20int)">ARPOptions.setErrorMode(int, int)</a> + * </ul> + */ + public static final String RDF_arp_err_ = "Rdf.jena.rdfXml.ERR_"; + + /** + * <b>Configuration property:</b> RDF/XML ARP property: <code>WARN_xxx</code>. + * + * <ul> + * <li><b>Name:</b> <js>"Rdf.jena.rdfXml.WARN_"</js> + * <li><b>Data type:</b> <code>String</code> + * </ul> + * + * <p> + * See {@link #RDF_arp_err_} for details. + */ + public static final String RDF_arp_warn_ = "Rdf.jena.rdfXml.WARN_"; + + /** + * RDF/XML ARP property: <code>IGN_xxx</code>. + * + * <ul> + * <li><b>Name:</b> <js>"Rdf.jena.rdfXml.IGN_"</js> + * <li><b>Data type:</b> <code>String</code> + * </ul> + * + * <p> + * See {@link #RDF_arp_err_} for details. + */ + public static final String RDF_arp_ign_ = "Rdf.jena.rdfXml.IGN_"; + + /** + * <b>Configuration property:</b> RDF/XML property: <code>xmlbase</code>. + * + * <ul> + * <li><b>Name:</b> <js>"Rdf.jena.rdfXml.xmlbase"</js> + * <li><b>Data type:</b> <code>String</code> + * <li><b>Default:</b> <jk>null</jk> + * </ul> + * + * <p> + * The value to be included for an <xa>xml:base</xa> attribute on the root element in the file. + */ + public static final String RDF_rdfxml_xmlBase = "Rdf.jena.rdfXml.xmlbase"; + + /** + * <b>Configuration property:</b> RDF/XML property: <code>longId</code>. + * + * <ul> + * <li><b>Name:</b> <js>"Rdf.jena.rdfXml.longId"</js> + * <li><b>Data type:</b> <code>Boolean</code> + * <li><b>Default:</b> <jk>false</jk> + * </ul> + * + * <p> + * Whether to use long ID's for anon resources. + * Short ID's are easier to read, but can run out of memory on very large models. + */ + public static final String RDF_rdfxml_longId = "Rdf.jena.rdfXml.longId"; + + /** + * <b>Configuration property:</b> RDF/XML property: <code>allowBadURIs</code>. + * + * <ul> + * <li><b>Name:</b> <js>"Rdf.jena.rdfXml.allowBadURIs"</js> + * <li><b>Data type:</b> <code>Boolean</code> + * <li><b>Default:</b> <jk>false</jk> + * </ul> + * + * <p> + * URIs in the graph are, by default, checked prior to serialization. + */ + public static final String RDF_rdfxml_allowBadUris = "Rdf.jena.rdfXml.allowBadURIs"; + + /** + * <b>Configuration property:</b> RDF/XML property: <code>relativeURIs</code>. + * + * <ul> + * <li><b>Name:</b> <js>"Rdf.jena.rdfXml.relativeURIs"</js> + * <li><b>Data type:</b> <code>String</code> + * <li><b>Default:</b> <js>"same-document, absolute, relative, parent"</js> + * </ul> + * + * <p> + * What sort of relative URIs should be used. + * + * <p> + * A comma separate list of options: + * <ul class='spaced-list'> + * <li> + * <js>"same-document"</js> - Same-document references (e.g. <js>""</js> or <js>"#foo"</js>) + * <li> + * <js>"network"</js> - Network paths (e.g. <js>"//example.org/foo"</js> omitting the URI scheme) + * <li> + * <js>"absolute"</js> - Absolute paths (e.g. <js>"/foo"</js> omitting the scheme and authority) + * <li> + * <js>"relative"</js> - Relative path not beginning in <js>"../"</js> + * <li> + * <js>"parent"</js> - Relative path beginning in <js>"../"</js> + * <li> + * <js>"grandparent"</js> - Relative path beginning in <js>"../../"</js> + * </ul> + * + * <p> + * The default value is <js>"same-document, absolute, relative, parent"</js>. + * To switch off relative URIs use the value <js>""</js>. + * Relative URIs of any of these types are output where possible if and only if the option has been specified. + */ + public static final String RDF_rdfxml_relativeUris = "Rdf.jena.rdfXml.relativeURIs"; + + /** + * <b>Configuration property:</b> RDF/XML property: <code>showXmlDeclaration</code>. + * + * <ul> + * <li><b>Name:</b> <js>"Rdf.jena.rdfXml.showXmlDeclaration"</js> + * <li><b>Data type:</b> <code>String</code> + * <li><b>Default:</b> <js>"default"</js> + * </ul> + * + * <p> + * Possible values: + * <ul class='spaced-list'> + * <li> + * <js>"true"</js> - Add XML Declaration to the output. + * <li> + * <js>"false"</js> - Don't add XML Declaration to the output. + * <li> + * <js>"default"</js> - Only add an XML Declaration when asked to write to an <code>OutputStreamWriter</code> + * that uses some encoding other than <code>UTF-8</code> or <code>UTF-16</code>. + * In this case the encoding is shown in the XML declaration. + * </ul> + */ + public static final String RDF_rdfxml_showXmlDeclaration = "Rdf.jena.rdfXml.showXmlDeclaration"; + + /** + * <b>Configuration property:</b> RDF/XML property: <code>showDoctypeDeclaration</code>. + * + * <ul> + * <li><b>Name:</b> <js>"Rdf.jena.rdfXml.showDoctypeDeclaration"</js> + * <li><b>Data type:</b> <code>Boolean</code> + * <li><b>Default:</b> <jk>true</jk> + * </ul> + * + * <p> + * If true, an XML doctype declaration is included in the output. + * This declaration includes a <code>!ENTITY</code> declaration for each prefix mapping in the model, and any + * attribute value that starts with the URI of that mapping is written as starting with the corresponding entity + * invocation. + */ + public static final String RDF_rdfxml_showDoctypeDeclaration = "Rdf.jena.rdfXml.showDoctypeDeclaration"; + + /** + * <b>Configuration property:</b> RDF/XML property: <code>tab</code>. + * + * <ul> + * <li><b>Name:</b> <js>"Rdf.jena.rdfXml.tab"</js> + * <li><b>Data type:</b> <code>Integer</code> + * <li><b>Default:</b> <code>2</code> + * </ul> + * + * <p> + * The number of spaces with which to indent XML child elements. + */ + public static final String RDF_rdfxml_tab = "Rdf.jena.rdfXml.tab"; + + /** + * <b>Configuration property:</b> RDF/XML property: <code>attributeQuoteChar</code>. + * + * <ul> + * <li><b>Name:</b> <js>"Rdf.jena.rdfXml.attributeQuoteChar"</js> + * <li><b>Data type:</b> <code>Character</code> + * <li><b>Default:</b> <js>'"'</js> + * </ul> + * + * <p> + * The XML attribute quote character. + */ + public static final String RDF_rdfxml_attributeQuoteChar = "Rdf.jena.rdfXml.attributeQuoteChar"; + + /** + * <b>Configuration property:</b> RDF/XML property: <code>blockRules</code>. + * + * <ul> + * <li><b>Name:</b> <js>"Rdf.jena.rdfXml.blockRules"</js> + * <li><b>Data type:</b> <code>String</code> + * <li><b>Default:</b> <js>""</js> + * </ul> + * + * <p> + * A list of <code>Resource</code> or a <code>String</code> being a comma separated list of fragment IDs from + * <a class="doclink" href="http://www.w3.org/TR/rdf-syntax-grammar">RDF Syntax Grammar</a> indicating grammar + * rules that will not be used. + */ + public static final String RDF_rdfxml_blockRules = "Rdf.jena.rdfXml.blockRules"; + + /** + * <b>Configuration property:</b> N3/Turtle property: <code>minGap</code>. + * + * <ul> + * <li><b>Name:</b> <js>"Rdf.jena.n3.minGap"</js> + * <li><b>Data type:</b> <code>Integer</code> + * <li><b>Default:</b> <code>1</code> + * </ul> + * + * <p> + * Minimum gap between items on a line. + */ + public static final String RDF_n3_minGap = "Rdf.jena.n3.minGap"; + + /** + * <b>Configuration property:</b> N3/Turtle property: <code>objectLists</code>. + * + * <ul> + * <li><b>Name:</b> <js>"Rdf.jena.n3.objectLists"</js> + * <li><b>Data type:</b> <code>Boolean</code> + * <li><b>Default:</b> <jk>true</jk> + * </ul> + * + * <p> + * Print object lists as comma separated lists. + */ + public static final String RDF_n3_objectLists = "Rdf.jena.n3.objectLists"; + + /** + * <b>Configuration property:</b> N3/Turtle property: <code>subjectColumn</code>. + * + * <ul> + * <li><b>Name:</b> <js>"Rdf.jena.n3.subjectColumn"</js> + * <li><b>Data type:</b> <code>Integer</code> + * <li><b>Default:</b> indentProperty + * </ul> + * + * <p> + * If the subject is shorter than this value, the first property may go on the same line. + */ + public static final String RDF_n3_subjectColumn = "Rdf.jena.n3.subjectColumn"; + + /** + * <b>Configuration property:</b> N3/Turtle property: <code>propertyColumn</code>. + * + * <ul> + * <li><b>Name:</b> <js>"Rdf.jena.n3.propertyColumn"</js> + * <li><b>Data type:</b> <code>Integer</code> + * <li><b>Default:</b> <code>8</code> + * </ul> + * + * <p> + * Width of the property column. + */ + public static final String RDF_n3_propertyColumn = "Rdf.jena.n3.propertyColumn"; + + /** + * <b>Configuration property:</b> N3/Turtle property: <code>indentProperty</code>. + * + * <ul> + * <li><b>Name:</b> <js>"Rdf.jena.n3.indentProperty"</js> + * <li><b>Data type:</b> <code>Integer</code> + * <li><b>Default:</b> <code>6</code> + * </ul> + * + * <p> + * Width to indent properties. + */ + public static final String RDF_n3_indentProperty = "Rdf.jena.n3.indentProperty"; + + /** + * <b>Configuration property:</b> N3/Turtle property: <code>widePropertyLen</code>. + * + * <ul> + * <li><b>Name:</b> <js>"Rdf.jena.n3.widePropertyLen"</js> + * <li><b>Data type:</b> <code>Integer</code> + * <li><b>Default:</b> <code>20</code> + * </ul> + * + * <p> + * Width of the property column. + * Must be longer than <code>propertyColumn</code>. + */ + public static final String RDF_n3_widePropertyLen = "Rdf.jena.n3.widePropertyLen"; + + /** + * <b>Configuration property:</b> N3/Turtle property: <code>abbrevBaseURI</code>. + * + * <ul> + * <li><b>Name:</b> <js>"Rdf.jena.n3.abbrevBaseURI"</js> + * <li><b>Data type:</b> <code>Boolean</code> + * <li><b>Default:</b> <jk>true</jk> + * </ul> + * + * <p> + * Control whether to use abbreviations <code><></code> or <code><#></code>. + */ + public static final String RDF_n3_abbrevBaseUri = "Rdf.jena.n3.abbrevBaseURI"; + + /** + * <b>Configuration property:</b> N3/Turtle property: <code>usePropertySymbols</code>. + * + * <ul> + * <li><b>Name:</b> <js>"Rdf.jena.n3.usePropertySymbols"</js> + * <li><b>Data type:</b> <code>Boolean</code> + * <li><b>Default:</b> <jk>true</jk> + * </ul> + * + * <p> + * Control whether to use <code>a</code>, <code>=</code> and <code>=></code> in output + */ + public static final String RDF_n3_usePropertySymbols = "Rdf.jena.n3.usePropertySymbols"; + + /** + * <b>Configuration property:</b> N3/Turtle property: <code>useTripleQuotedStrings</code>. + * + * <ul> + * <li><b>Name:</b> <js>"Rdf.jena.n3.useTripleQuotedStrings"</js> + * <li><b>Data type:</b> <code>Boolean</code> + * <li><b>Default:</b> <jk>true</jk> + * </ul> + * + * <p> + * Allow the use of <code>"""</code> to delimit long strings. + */ + public static final String RDF_n3_useTripleQuotedStrings = "Rdf.jena.n3.useTripleQuotedStrings"; + + /** + * <b>Configuration property:</b> N3/Turtle property: <code>useDoubles</code>. + * + * <ul> + * <li><b>Name:</b> <js>"Rdf.jena.n3.useDoubles"</js> + * <li><b>Data type:</b> <code>Boolean</code> + * <li><b>Default:</b> <jk>true</jk> + * </ul> + * + * <p> + * Allow the use doubles as <code>123.456</code>. + */ + public static final String RDF_n3_useDoubles = "Rdf.jena.n3.useDoubles"; + + /** + * <b>Configuration property:</b> RDF format for representing collections and arrays. + * + * <ul> + * <li><b>Name:</b> <js>"Rdf.collectionFormat"</js> + * <li><b>Data type:</b> <code>String</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> + * + * <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> + */ + public static final String RDF_collectionFormat = "Rdf.collectionFormat"; + + /** + * <b>Configuration property:</b> Collections should be serialized and parsed as loose collections. + * + * <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> + */ + public static final String RDF_looseCollections = "Rdf.looseCollections"; +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/75b0d8ee/juneau-core/juneau-marshall-rdf/src/main/java/org/apache/juneau/jena/RdfParser.java ---------------------------------------------------------------------- diff --git a/juneau-core/juneau-marshall-rdf/src/main/java/org/apache/juneau/jena/RdfParser.java b/juneau-core/juneau-marshall-rdf/src/main/java/org/apache/juneau/jena/RdfParser.java new file mode 100644 index 0000000..a94c123 --- /dev/null +++ b/juneau-core/juneau-marshall-rdf/src/main/java/org/apache/juneau/jena/RdfParser.java @@ -0,0 +1,137 @@ +// *************************************************************************************************************************** +// * 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.Constants.*; +import static org.apache.juneau.jena.RdfCommonContext.*; + +import org.apache.juneau.*; +import org.apache.juneau.parser.*; + +/** + * Parses RDF into POJOs. + * + * <h5 class='section'>Configurable properties:</h5> + * + * Refer to <a class="doclink" href="package-summary.html#ParserConfigurableProperties">Configurable Properties</a> + * for the entire list of configurable properties. + * + * <h6 class='topic'>Behavior-specific subclasses</h6> + * + * The following direct subclasses are provided for language-specific parsers: + * <ul class='spaced-list'> + * <li> + * {@link RdfParser.Xml} - RDF/XML and RDF/XML-ABBREV. + * <li> + * {@link RdfParser.NTriple} - N-TRIPLE. + * <li> + * {@link RdfParser.Turtle} - TURTLE. + * <li> + * {@link RdfParser.N3} - N3. + * </ul> + * + * <h5 class='section'>Additional information:</h5> + * + * See <a class="doclink" href="package-summary.html#TOC">RDF Overview</a> for an overview of RDF support in Juneau. + */ +public class RdfParser extends ReaderParser { + + /** Default XML parser, all default settings.*/ + public static final RdfParser DEFAULT_XML = new Xml(PropertyStore.create()); + + /** Default Turtle parser, all default settings.*/ + public static final RdfParser DEFAULT_TURTLE = new Turtle(PropertyStore.create()); + + /** Default N-Triple parser, all default settings.*/ + public static final RdfParser DEFAULT_NTRIPLE = new NTriple(PropertyStore.create()); + + /** Default N3 parser, all default settings.*/ + public static final RdfParser DEFAULT_N3 = new N3(PropertyStore.create()); + + + /** Consumes RDF/XML input */ + public static class Xml extends RdfParser { + + /** + * Constructor. + * + * @param propertyStore The property store containing all the settings for this object. + */ + public Xml(PropertyStore propertyStore) { + super(propertyStore.copy().append(RDF_language, LANG_RDF_XML), "text/xml+rdf"); + } + } + + /** Consumes N-Triple input */ + public static class NTriple extends RdfParser { + + /** + * Constructor. + * + * @param propertyStore The property store containing all the settings for this object. + */ + public NTriple(PropertyStore propertyStore) { + super(propertyStore.copy().append(RDF_language, LANG_NTRIPLE), "text/n-triple"); + } + } + + /** Consumes Turtle input */ + public static class Turtle extends RdfParser { + + /** + * Constructor. + * + * @param propertyStore The property store containing all the settings for this object. + */ + public Turtle(PropertyStore propertyStore) { + super(propertyStore.copy().append(RDF_language, LANG_TURTLE), "text/turtle"); + } + } + + /** Consumes N3 input */ + public static class N3 extends RdfParser { + + /** + * Constructor. + * + * @param propertyStore The property store containing all the settings for this object. + */ + public N3(PropertyStore propertyStore) { + super(propertyStore.copy().append(RDF_language, LANG_N3), "text/n3"); + } + } + + + private final RdfParserContext ctx; + + /** + * Constructor. + * + * @param propertyStore The property store containing all the settings for this object. + * @param consumes The list of media types that this parser consumes (e.g. <js>"application/json"</js>). + */ + public RdfParser(PropertyStore propertyStore, String...consumes) { + super(propertyStore, consumes); + this.ctx = createContext(RdfParserContext.class); + } + + @Override /* CoreObject */ + public RdfParserBuilder builder() { + return new RdfParserBuilder(propertyStore); + } + + @Override /* Parser */ + public ReaderParserSession createSession(ParserSessionArgs args) { + return new RdfParserSession(ctx, args); + } +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/75b0d8ee/juneau-core/juneau-marshall-rdf/src/main/java/org/apache/juneau/jena/RdfParserBuilder.java ---------------------------------------------------------------------- diff --git a/juneau-core/juneau-marshall-rdf/src/main/java/org/apache/juneau/jena/RdfParserBuilder.java b/juneau-core/juneau-marshall-rdf/src/main/java/org/apache/juneau/jena/RdfParserBuilder.java new file mode 100644 index 0000000..095d45a --- /dev/null +++ b/juneau-core/juneau-marshall-rdf/src/main/java/org/apache/juneau/jena/RdfParserBuilder.java @@ -0,0 +1,765 @@ +// *************************************************************************************************************************** +// * 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.RdfParserContext.*; + +import java.util.*; + +import org.apache.juneau.*; +import org.apache.juneau.http.*; +import org.apache.juneau.jena.annotation.*; +import org.apache.juneau.parser.*; +import org.apache.juneau.xml.*; +import org.apache.juneau.xml.annotation.*; + +/** + * Builder class for building instances of RDF parsers. + */ +public class RdfParserBuilder extends ParserBuilder { + + /** + * Constructor, default settings. + */ + public RdfParserBuilder() { + super(); + } + + /** + * Constructor. + * + * @param propertyStore The initial configuration settings for this builder. + */ + public RdfParserBuilder(PropertyStore propertyStore) { + super(propertyStore); + } + + @Override /* CoreObjectBuilder */ + public RdfParser build() { + return new RdfParser(propertyStore, "text/xml+rdf"); + } + + + //-------------------------------------------------------------------------------- + // Properties + //-------------------------------------------------------------------------------- + + /** + * <b>Configuration property:</b> Trim whitespace from text elements. + * + * <ul> + * <li><b>Name:</b> <js>"RdfParser.trimWhitespace"</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> + * If <jk>true</jk>, whitespace in text elements will be automatically trimmed. + * + * <h5 class='section'>Notes:</h5> + * <ul> + * <li>This is equivalent to calling <code>property(<jsf>RDF_trimWhitespace</jsf>, value)</code>. + * </ul> + * + * @param value The new value for this property. + * @return This object (for method chaining). + * @see RdfParserContext#RDF_trimWhitespace + */ + public RdfParserBuilder trimWhitespace(boolean value) { + return property(RDF_trimWhitespace, value); + } + + /** + * <b>Configuration property:</b> RDF language. + * + * <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> + * + * <h5 class='section'>Notes:</h5> + * <ul> + * <li>This is equivalent to calling <code>property(<jsf>RDF_language</jsf>, value)</code>. + * </ul> + * + * @param value The new value for this property. + * @return This object (for method chaining). + * @see RdfParserContext#RDF_language + */ + public RdfParserBuilder 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 RdfParserBuilder 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 RdfParserBuilder 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 RdfParserBuilder ntriple() { + return language(Constants.LANG_NTRIPLE); + } + + /** + * Shortcut for calling <code>language(<jsf>LANG_N3</jsf>)</code> + * + * @return This object (for method chaining). + */ + public RdfParserBuilder n3() { + return language(Constants.LANG_N3); + } + + /** + * Shortcut for calling <code>language(<jsf>LANG_TURTLE</jsf>)</code> + * + * @return This object (for method chaining). + */ + public RdfParserBuilder turtle() { + return language(Constants.LANG_TURTLE); + } + + /** + * <b>Configuration property:</b> XML namespace for Juneau properties. + * + * <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> + * + * <h5 class='section'>Notes:</h5> + * <ul> + * <li>This is equivalent to calling <code>property(<jsf>RDF_juneauNs</jsf>, value)</code>. + * </ul> + * + * @param value The new value for this property. + * @return This object (for method chaining). + * @see RdfParserContext#RDF_juneauNs + */ + public RdfParserBuilder juneauNs(Namespace value) { + return property(RDF_juneauNs, value); + } + + /** + * <b>Configuration property:</b> Default XML namespace for bean properties. + * + * <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> + * + * <h5 class='section'>Notes:</h5> + * <ul> + * <li>This is equivalent to calling <code>property(<jsf>RDF_juneauBpNs</jsf>, value)</code>. + * </ul> + * + * @param value The new value for this property. + * @return This object (for method chaining). + * @see RdfParserContext#RDF_juneauBpNs + */ + public RdfParserBuilder juneauBpNs(Namespace value) { + return property(RDF_juneauBpNs, value); + } + + /** + * <b>Configuration property:</b> Reuse XML namespaces when RDF namespaces not specified. + * + * <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 parsers. + * Otherwise, namespaces will be defined using {@link RdfNs} and {@link Rdf}. + * + * <h5 class='section'>Notes:</h5> + * <ul> + * <li>This is equivalent to calling <code>property(<jsf>RDF_useXmlNamespaces</jsf>, value)</code>. + * </ul> + * + * @param value The new value for this property. + * @return This object (for method chaining). + * @see RdfParserContext#RDF_useXmlNamespaces + */ + public RdfParserBuilder useXmlNamespaces(boolean value) { + return property(RDF_useXmlNamespaces, value); + } + + /** + * <b>Configuration property:</b> RDF format for representing collections and arrays. + * + * <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> + * + * <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> + * + * <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 RdfParserBuilder collectionFormat(RdfCollectionFormat value) { + return property(RDF_collectionFormat, value); + } + + /** + * <b>Configuration property:</b> Collections should be serialized and parsed as loose collections. + * + * <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> + * + * <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 RdfParserBuilder looseCollections(boolean value) { + return property(RDF_looseCollections, value); + } + + @Override /* ParserBuilder */ + public RdfParserBuilder trimStrings(boolean value) { + super.trimStrings(value); + return this; + } + + @Override /* ParserBuilder */ + public RdfParserBuilder strict(boolean value) { + super.strict(value); + return this; + } + + @Override /* ParserBuilder */ + public RdfParserBuilder strict() { + super.strict(); + return this; + } + + @Override /* ParserBuilder */ + public RdfParserBuilder inputStreamCharset(String value) { + super.inputStreamCharset(value); + return this; + } + + @Override /* ParserBuilder */ + public RdfParserBuilder fileCharset(String value) { + super.fileCharset(value); + return this; + } + + @Override /* ParserBuilder */ + public RdfParserBuilder listener(Class<? extends ParserListener> value) { + super.listener(value); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfParserBuilder beansRequireDefaultConstructor(boolean value) { + super.beansRequireDefaultConstructor(value); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfParserBuilder beansRequireSerializable(boolean value) { + super.beansRequireSerializable(value); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfParserBuilder beansRequireSettersForGetters(boolean value) { + super.beansRequireSettersForGetters(value); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfParserBuilder beansRequireSomeProperties(boolean value) { + super.beansRequireSomeProperties(value); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfParserBuilder beanMapPutReturnsOldValue(boolean value) { + super.beanMapPutReturnsOldValue(value); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfParserBuilder beanConstructorVisibility(Visibility value) { + super.beanConstructorVisibility(value); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfParserBuilder beanClassVisibility(Visibility value) { + super.beanClassVisibility(value); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfParserBuilder beanFieldVisibility(Visibility value) { + super.beanFieldVisibility(value); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfParserBuilder methodVisibility(Visibility value) { + super.methodVisibility(value); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfParserBuilder useJavaBeanIntrospector(boolean value) { + super.useJavaBeanIntrospector(value); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfParserBuilder useInterfaceProxies(boolean value) { + super.useInterfaceProxies(value); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfParserBuilder ignoreUnknownBeanProperties(boolean value) { + super.ignoreUnknownBeanProperties(value); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfParserBuilder ignoreUnknownNullBeanProperties(boolean value) { + super.ignoreUnknownNullBeanProperties(value); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfParserBuilder ignorePropertiesWithoutSetters(boolean value) { + super.ignorePropertiesWithoutSetters(value); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfParserBuilder ignoreInvocationExceptionsOnGetters(boolean value) { + super.ignoreInvocationExceptionsOnGetters(value); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfParserBuilder ignoreInvocationExceptionsOnSetters(boolean value) { + super.ignoreInvocationExceptionsOnSetters(value); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfParserBuilder sortProperties(boolean value) { + super.sortProperties(value); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfParserBuilder notBeanPackages(String...values) { + super.notBeanPackages(values); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfParserBuilder notBeanPackages(Collection<String> values) { + super.notBeanPackages(values); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfParserBuilder setNotBeanPackages(String...values) { + super.setNotBeanPackages(values); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfParserBuilder setNotBeanPackages(Collection<String> values) { + super.setNotBeanPackages(values); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfParserBuilder removeNotBeanPackages(String...values) { + super.removeNotBeanPackages(values); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfParserBuilder removeNotBeanPackages(Collection<String> values) { + super.removeNotBeanPackages(values); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfParserBuilder notBeanClasses(Class<?>...values) { + super.notBeanClasses(values); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfParserBuilder notBeanClasses(Collection<Class<?>> values) { + super.notBeanClasses(values); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfParserBuilder setNotBeanClasses(Class<?>...values) { + super.setNotBeanClasses(values); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfParserBuilder setNotBeanClasses(Collection<Class<?>> values) { + super.setNotBeanClasses(values); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfParserBuilder removeNotBeanClasses(Class<?>...values) { + super.removeNotBeanClasses(values); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfParserBuilder removeNotBeanClasses(Collection<Class<?>> values) { + super.removeNotBeanClasses(values); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfParserBuilder beanFilters(Class<?>...values) { + super.beanFilters(values); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfParserBuilder beanFilters(Collection<Class<?>> values) { + super.beanFilters(values); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfParserBuilder setBeanFilters(Class<?>...values) { + super.setBeanFilters(values); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfParserBuilder setBeanFilters(Collection<Class<?>> values) { + super.setBeanFilters(values); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfParserBuilder removeBeanFilters(Class<?>...values) { + super.removeBeanFilters(values); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfParserBuilder removeBeanFilters(Collection<Class<?>> values) { + super.removeBeanFilters(values); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfParserBuilder pojoSwaps(Class<?>...values) { + super.pojoSwaps(values); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfParserBuilder pojoSwaps(Collection<Class<?>> values) { + super.pojoSwaps(values); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfParserBuilder setPojoSwaps(Class<?>...values) { + super.setPojoSwaps(values); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfParserBuilder setPojoSwaps(Collection<Class<?>> values) { + super.setPojoSwaps(values); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfParserBuilder removePojoSwaps(Class<?>...values) { + super.removePojoSwaps(values); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfParserBuilder removePojoSwaps(Collection<Class<?>> values) { + super.removePojoSwaps(values); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfParserBuilder implClasses(Map<Class<?>,Class<?>> values) { + super.implClasses(values); + return this; + } + + @Override /* CoreObjectBuilder */ + public <T> RdfParserBuilder implClass(Class<T> interfaceClass, Class<? extends T> implClass) { + super.implClass(interfaceClass, implClass); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfParserBuilder beanDictionary(Class<?>...values) { + super.beanDictionary(values); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfParserBuilder beanDictionary(Collection<Class<?>> values) { + super.beanDictionary(values); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfParserBuilder setBeanDictionary(Class<?>...values) { + super.setBeanDictionary(values); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfParserBuilder setBeanDictionary(Collection<Class<?>> values) { + super.setBeanDictionary(values); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfParserBuilder removeFromBeanDictionary(Class<?>...values) { + super.removeFromBeanDictionary(values); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfParserBuilder removeFromBeanDictionary(Collection<Class<?>> values) { + super.removeFromBeanDictionary(values); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfParserBuilder beanTypePropertyName(String value) { + super.beanTypePropertyName(value); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfParserBuilder defaultParser(Class<?> value) { + super.defaultParser(value); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfParserBuilder locale(Locale value) { + super.locale(value); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfParserBuilder timeZone(TimeZone value) { + super.timeZone(value); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfParserBuilder mediaType(MediaType value) { + super.mediaType(value); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfParserBuilder debug() { + super.debug(); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfParserBuilder property(String name, Object value) { + super.property(name, value); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfParserBuilder properties(Map<String,Object> properties) { + super.properties(properties); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfParserBuilder addToProperty(String name, Object value) { + super.addToProperty(name, value); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfParserBuilder putToProperty(String name, Object key, Object value) { + super.putToProperty(name, key, value); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfParserBuilder putToProperty(String name, Object value) { + super.putToProperty(name, value); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfParserBuilder removeFromProperty(String name, Object value) { + super.removeFromProperty(name, value); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfParserBuilder classLoader(ClassLoader classLoader) { + super.classLoader(classLoader); + return this; + } + + @Override /* CoreObjectBuilder */ + public RdfParserBuilder 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/75b0d8ee/juneau-core/juneau-marshall-rdf/src/main/java/org/apache/juneau/jena/RdfParserContext.java ---------------------------------------------------------------------- diff --git a/juneau-core/juneau-marshall-rdf/src/main/java/org/apache/juneau/jena/RdfParserContext.java b/juneau-core/juneau-marshall-rdf/src/main/java/org/apache/juneau/jena/RdfParserContext.java new file mode 100644 index 0000000..42833c4 --- /dev/null +++ b/juneau-core/juneau-marshall-rdf/src/main/java/org/apache/juneau/jena/RdfParserContext.java @@ -0,0 +1,104 @@ +// *************************************************************************************************************************** +// * 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 java.util.*; + +import org.apache.juneau.*; +import org.apache.juneau.parser.*; +import org.apache.juneau.xml.*; + +/** + * Configurable properties on the {@link RdfParser} class. + * + * <p> + * Context properties are set by calling {@link PropertyStore#setProperty(String, Object)} on the property store + * passed into the constructor. + * + * <p> + * See {@link PropertyStore} for more information about context properties. + * + * <h6 class='topic' id='ConfigProperties'>Configurable properties inherited by the RDF parsers</h6> + * <ul class='doctree'> + * <li class='jc'> + * <a class="doclink" href="../BeanContext.html#ConfigProperties">BeanContext</a> + * - Properties associated with handling beans on serializers and parsers. + * <ul> + * <li class='jc'> + * <a class="doclink" href="../parser/ParserContext.html#ConfigProperties">ParserContext</a> + * - Configurable properties common to all parsers. + * <ul> + * <li class='jic'> + * <a class="doclink" href="RdfCommonContext.html#ConfigProperties">RdfCommonContext</a> + * - Configurable properties common to the RDF serializers and parsers. + * </ul> + * </li> + * </ul> + * </li> + * </ul> + */ +public final class RdfParserContext extends ParserContext implements RdfCommonContext { + + /** + * <b>Configuration property:</b> Trim whitespace from text elements. + * + * <ul> + * <li><b>Name:</b> <js>"RdfParser.trimWhitespace"</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> + * If <jk>true</jk>, whitespace in text elements will be automatically trimmed. + */ + public static final String RDF_trimWhitespace = "RdfParser.trimWhitespace"; + + final boolean trimWhitespace, looseCollections; + final String rdfLanguage; + final Namespace juneauNs, juneauBpNs; + final RdfCollectionFormat collectionFormat; + final Map<String,Object> jenaSettings = new HashMap<String,Object>(); + + /** + * Constructor. + * + * <p> + * Typically only called from {@link PropertyStore#getContext(Class)}. + * + * @param ps The property store that created this context. + */ + public RdfParserContext(PropertyStore ps) { + super(ps); + trimWhitespace = ps.getProperty(RDF_trimWhitespace, boolean.class, false); + looseCollections = ps.getProperty(RDF_looseCollections, boolean.class, false); + 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("j", "http://www.apache.org/juneaubp/")); + collectionFormat = ps.getProperty(RDF_collectionFormat, RdfCollectionFormat.class, RdfCollectionFormat.DEFAULT); + } + + @Override /* Context */ + public ObjectMap asMap() { + return super.asMap() + .append("RdfParserContext", new ObjectMap() + .append("trimWhitespace", trimWhitespace) + .append("looseCollections", looseCollections) + .append("rdfLanguage", rdfLanguage) + .append("juneauNs", juneauNs) + .append("juneauBpNs", juneauBpNs) + .append("collectionFormat", collectionFormat) + ); + } +} +
