http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e4dfdf81/juneau-core-test/src/test/java/org/apache/juneau/xml/xml1b/T6.java ---------------------------------------------------------------------- diff --git a/juneau-core-test/src/test/java/org/apache/juneau/xml/xml1b/T6.java b/juneau-core-test/src/test/java/org/apache/juneau/xml/xml1b/T6.java new file mode 100755 index 0000000..c34126c --- /dev/null +++ b/juneau-core-test/src/test/java/org/apache/juneau/xml/xml1b/T6.java @@ -0,0 +1,38 @@ +// *************************************************************************************************************************** +// * 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.xml.xml1b; + +import org.apache.juneau.annotation.*; +import org.apache.juneau.xml.annotation.*; + +@Xml(prefix="foo",namespace="http://foo") +@Bean(sort=true) +@SuppressWarnings("javadoc") +public class T6 { + + public int f1 = 1; + + @Xml(prefix="bar",namespace="http://bar") public int f2 = 2; + + private int f3 = 3; + public int getF3() { return f3; } + public void setF3(int f3) { this.f3 = f3; } + + private int f4 = 4; + @Xml(prefix="baz",namespace="http://baz") public int getF4() { return f4; } + public void setF4(int f4) { this.f4 = f4; } + + public boolean equals(T6 x) { + return x.f1 == f1 && x.f2 == f2 && x.f3 == f3 && x.f4 == f4; + } +}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e4dfdf81/juneau-core-test/src/test/java/org/apache/juneau/xml/xml1b/T7.java ---------------------------------------------------------------------- diff --git a/juneau-core-test/src/test/java/org/apache/juneau/xml/xml1b/T7.java b/juneau-core-test/src/test/java/org/apache/juneau/xml/xml1b/T7.java new file mode 100755 index 0000000..f2960aa --- /dev/null +++ b/juneau-core-test/src/test/java/org/apache/juneau/xml/xml1b/T7.java @@ -0,0 +1,37 @@ +// *************************************************************************************************************************** +// * 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.xml.xml1b; + +import org.apache.juneau.annotation.*; +import org.apache.juneau.xml.annotation.*; + +@Bean(sort=true) +@SuppressWarnings("javadoc") +public class T7 { + + @BeanProperty(name="g1") public int f1 = 1; + + @Xml(prefix="bar",namespace="http://bar") @BeanProperty(name="g2") public int f2 = 2; + + private int f3 = 3; + @BeanProperty(name="g3") public int getF3() { return f3; } + @BeanProperty(name="g3") public void setF3(int f3) { this.f3 = f3; } + + private int f4 = 4; + @BeanProperty(name="g4") @Xml(prefix="baz",namespace="http://baz") public int getF4() { return f4; } + @BeanProperty(name="g4") public void setF4(int f4) { this.f4 = f4; } + + public boolean equals(T7 x) { + return x.f1 == f1 && x.f2 == f2 && x.f3 == f3 && x.f4 == f4; + } +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e4dfdf81/juneau-core-test/src/test/java/org/apache/juneau/xml/xml1b/package-info.java ---------------------------------------------------------------------- diff --git a/juneau-core-test/src/test/java/org/apache/juneau/xml/xml1b/package-info.java b/juneau-core-test/src/test/java/org/apache/juneau/xml/xml1b/package-info.java new file mode 100755 index 0000000..306db1b --- /dev/null +++ b/juneau-core-test/src/test/java/org/apache/juneau/xml/xml1b/package-info.java @@ -0,0 +1,16 @@ +// *************************************************************************************************************************** +// * 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. * +// *************************************************************************************************************************** +@XmlSchema(prefix="p1",namespace="http://p1") +package org.apache.juneau.xml.xml1b; +import org.apache.juneau.xml.annotation.*; + http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e4dfdf81/juneau-core-test/src/test/java/org/apache/juneau/xml/xml1c/T8.java ---------------------------------------------------------------------- diff --git a/juneau-core-test/src/test/java/org/apache/juneau/xml/xml1c/T8.java b/juneau-core-test/src/test/java/org/apache/juneau/xml/xml1c/T8.java new file mode 100755 index 0000000..0c383eb --- /dev/null +++ b/juneau-core-test/src/test/java/org/apache/juneau/xml/xml1c/T8.java @@ -0,0 +1,33 @@ +// *************************************************************************************************************************** +// * 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.xml.xml1c; + +import org.apache.juneau.xml.annotation.*; + +@Xml(prefix="p2") +@SuppressWarnings("javadoc") +public class T8 { + + public int f1 = 1; + + @Xml(prefix="p1") public int f2 = 2; + + @Xml(prefix="c1") public int f3 = 3; + + @Xml(prefix="f1") + public int f4 = 4; + + public boolean equals(T8 x) { + return x.f1 == f1 && x.f2 == f2 && x.f3 == f3 && x.f4 == f4; + } +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e4dfdf81/juneau-core-test/src/test/java/org/apache/juneau/xml/xml1c/T9.java ---------------------------------------------------------------------- diff --git a/juneau-core-test/src/test/java/org/apache/juneau/xml/xml1c/T9.java b/juneau-core-test/src/test/java/org/apache/juneau/xml/xml1c/T9.java new file mode 100755 index 0000000..7009626 --- /dev/null +++ b/juneau-core-test/src/test/java/org/apache/juneau/xml/xml1c/T9.java @@ -0,0 +1,23 @@ +// *************************************************************************************************************************** +// * 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.xml.xml1c; + +@SuppressWarnings("javadoc") +public class T9 { + + public int f1 = 1; + + public boolean equals(T9 x) { + return x.f1 == f1; + } +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e4dfdf81/juneau-core-test/src/test/java/org/apache/juneau/xml/xml1c/package-info.java ---------------------------------------------------------------------- diff --git a/juneau-core-test/src/test/java/org/apache/juneau/xml/xml1c/package-info.java b/juneau-core-test/src/test/java/org/apache/juneau/xml/xml1c/package-info.java new file mode 100755 index 0000000..e054388 --- /dev/null +++ b/juneau-core-test/src/test/java/org/apache/juneau/xml/xml1c/package-info.java @@ -0,0 +1,25 @@ +// *************************************************************************************************************************** +// * 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. * +// *************************************************************************************************************************** +@XmlSchema( + prefix="p1", + xmlNs={ + @XmlNs(prefix="p1",namespaceURI="http://p1"), + @XmlNs(prefix="p2",namespaceURI="http://p2"), + @XmlNs(prefix="p3",namespaceURI="http://p3(unused)"), + @XmlNs(prefix="c1",namespaceURI="http://c1"), + @XmlNs(prefix="f1",namespaceURI="http://f1") + } +) +package org.apache.juneau.xml.xml1c; +import org.apache.juneau.xml.annotation.*; + http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e4dfdf81/juneau-core/pom.xml ---------------------------------------------------------------------- diff --git a/juneau-core/pom.xml b/juneau-core/pom.xml index 1e517cd..741250d 100644 --- a/juneau-core/pom.xml +++ b/juneau-core/pom.xml @@ -29,15 +29,6 @@ </parent> <dependencies> - <dependency> - <groupId>org.apache.jena</groupId> - <artifactId>jena-core</artifactId> - <optional>true</optional> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - </dependency> </dependencies> <properties> http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e4dfdf81/juneau-core/src/main/java/org/apache/juneau/BeanSession.java ---------------------------------------------------------------------- diff --git a/juneau-core/src/main/java/org/apache/juneau/BeanSession.java b/juneau-core/src/main/java/org/apache/juneau/BeanSession.java index e22f028..9d2e5fe 100644 --- a/juneau-core/src/main/java/org/apache/juneau/BeanSession.java +++ b/juneau-core/src/main/java/org/apache/juneau/BeanSession.java @@ -22,11 +22,10 @@ import java.util.concurrent.atomic.*; import org.apache.juneau.internal.*; import org.apache.juneau.json.*; +import org.apache.juneau.parser.*; import org.apache.juneau.serializer.*; import org.apache.juneau.transform.*; -import com.hp.hpl.jena.reasoner.rulesys.Rule.*; - /** * Session object that lives for the duration of a single use of {@link Serializer} or {@link Parser}. * <p> http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e4dfdf81/juneau-core/src/main/java/org/apache/juneau/jena/Constants.java ---------------------------------------------------------------------- diff --git a/juneau-core/src/main/java/org/apache/juneau/jena/Constants.java b/juneau-core/src/main/java/org/apache/juneau/jena/Constants.java deleted file mode 100644 index 1e4d8ea..0000000 --- a/juneau-core/src/main/java/org/apache/juneau/jena/Constants.java +++ /dev/null @@ -1,93 +0,0 @@ -// *************************************************************************************************************************** -// * 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_CLASS = "class"; - - /** - * 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/e4dfdf81/juneau-core/src/main/java/org/apache/juneau/jena/RdfBeanMeta.java ---------------------------------------------------------------------- diff --git a/juneau-core/src/main/java/org/apache/juneau/jena/RdfBeanMeta.java b/juneau-core/src/main/java/org/apache/juneau/jena/RdfBeanMeta.java deleted file mode 100644 index 1923ac3..0000000 --- a/juneau-core/src/main/java/org/apache/juneau/jena/RdfBeanMeta.java +++ /dev/null @@ -1,61 +0,0 @@ -// *************************************************************************************************************************** -// * 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/e4dfdf81/juneau-core/src/main/java/org/apache/juneau/jena/RdfBeanPropertyMeta.java ---------------------------------------------------------------------- diff --git a/juneau-core/src/main/java/org/apache/juneau/jena/RdfBeanPropertyMeta.java b/juneau-core/src/main/java/org/apache/juneau/jena/RdfBeanPropertyMeta.java deleted file mode 100644 index 9dedfb4..0000000 --- a/juneau-core/src/main/java/org/apache/juneau/jena/RdfBeanPropertyMeta.java +++ /dev/null @@ -1,93 +0,0 @@ -// *************************************************************************************************************************** -// * 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/e4dfdf81/juneau-core/src/main/java/org/apache/juneau/jena/RdfClassMeta.java ---------------------------------------------------------------------- diff --git a/juneau-core/src/main/java/org/apache/juneau/jena/RdfClassMeta.java b/juneau-core/src/main/java/org/apache/juneau/jena/RdfClassMeta.java deleted file mode 100644 index 44331ad..0000000 --- a/juneau-core/src/main/java/org/apache/juneau/jena/RdfClassMeta.java +++ /dev/null @@ -1,87 +0,0 @@ -// *************************************************************************************************************************** -// * 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/e4dfdf81/juneau-core/src/main/java/org/apache/juneau/jena/RdfCollectionFormat.java ---------------------------------------------------------------------- diff --git a/juneau-core/src/main/java/org/apache/juneau/jena/RdfCollectionFormat.java b/juneau-core/src/main/java/org/apache/juneau/jena/RdfCollectionFormat.java deleted file mode 100644 index 70984b2..0000000 --- a/juneau-core/src/main/java/org/apache/juneau/jena/RdfCollectionFormat.java +++ /dev/null @@ -1,53 +0,0 @@ -// *************************************************************************************************************************** -// * 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/e4dfdf81/juneau-core/src/main/java/org/apache/juneau/jena/RdfCommonContext.java ---------------------------------------------------------------------- diff --git a/juneau-core/src/main/java/org/apache/juneau/jena/RdfCommonContext.java b/juneau-core/src/main/java/org/apache/juneau/jena/RdfCommonContext.java deleted file mode 100644 index bd99d10..0000000 --- a/juneau-core/src/main/java/org/apache/juneau/jena/RdfCommonContext.java +++ /dev/null @@ -1,753 +0,0 @@ -// *************************************************************************************************************************** -// * 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.xml.*; -import org.apache.juneau.xml.annotation.*; - -/** - * Configurable properties common to both the {@link RdfSerializer} and {@link RdfParser} classes. - * - * <h6 class='topic' id='ConfigProperties'>Configurable properties common to the RDF serializers and parsers</h6> - * <table class='styled' style='border-collapse: collapse;'> - * <tr><th>Setting name</th><th>Description</th><th>Data type</th><th>Default value</th></tr> - * <tr> - * <td>{@link #RDF_language}</td> - * <td>RDF language.</td> - * <td><code>String</code></td> - * <td><js>"RDF/XML-ABBREV"</js></td> - * </tr> - * <tr> - * <td>{@link #RDF_juneauNs}</td> - * <td>XML namespace for Juneau properties.</td> - * <td>{@link Namespace}</td> - * <td><code>{j:<js>'http://www.apache.org/juneau/'</js>}</code></td> - * </tr> - * <tr> - * <td>{@link #RDF_juneauBpNs}</td> - * <td>Default XML namespace for bean properties.</td> - * <td>{@link Namespace}</td> - * <td><code>{j:<js>'http://www.apache.org/juneaubp/'</js>}</code></td> - * </tr> - * <tr> - * <td>{@link #RDF_useXmlNamespaces}</td> - * <td>Reuse XML namespaces when RDF namespaces not specified.</td> - * <td><code>Boolean</code></td> - * <td><jk>true</jk></td> - * </tr> - * <tr> - * <td>{@link #RDF_arp_iriRules}</td> - * <td>RDF/XML property: <code>iri_rules</code>.</td> - * <td><code>String</code></td> - * <td><js>"lax"</js></td> - * </tr> - * <tr> - * <td>{@link #RDF_arp_errorMode}</td> - * <td>RDF/XML ARP property: <code>error-mode</code>.</td> - * <td><code>String</code></td> - * <td><js>"lax"</js></td> - * </tr> - * <tr> - * <td>{@link #RDF_arp_embedding}</td> - * <td>RDF/XML ARP property: <code>embedding</code>.</td> - * <td><code>Boolean</code></td> - * <td><jk>false</jk></td> - * </tr> - * <tr> - * <td>{@link #RDF_arp_err_}</td> - * <td>RDF/XML ARP property: <code>ERR_xxx</code>.</td> - * <td><code>String</code></td> - * <td></td> - * </tr> - * <tr> - * <td>{@link #RDF_arp_warn_}</td> - * <td>RDF/XML ARP property: <code>WARN_xxx</code>.</td> - * <td><code>String</code></td> - * <td></td> - * </tr> - * <tr> - * <td>{@link #RDF_arp_ign_}</td> - * <td>RDF/XML ARP property: <code>IGN_xxx</code>.</td> - * <td><code>String</code></td> - * <td></td> - * </tr> - * <tr> - * <td>{@link #RDF_rdfxml_xmlBase}</td> - * <td>RDF/XML property: <code>xmlbase</code>.</td> - * <td><code>String</code></td> - * <td><jk>null</jk></td> - * </tr> - * <tr> - * <td>{@link #RDF_rdfxml_longId}</td> - * <td>RDF/XML property: <code>longId</code>.</td> - * <td><code>Boolean</code></td> - * <td><jk>false</jk></td> - * </tr> - * <tr> - * <td>{@link #RDF_rdfxml_allowBadUris}</td> - * <td>RDF/XML property: <code>allowBadURIs</code>.</td> - * <td><code>Boolean</code></td> - * <td><jk>false</jk></td> - * </tr> - * <tr> - * <td>{@link #RDF_rdfxml_relativeUris}</td> - * <td>RDF/XML property: <code>relativeURIs</code>.</td> - * <td><code>String</code></td> - * <td><js>"same-document, absolute, relative, parent"</js></td> - * </tr> - * <tr> - * <td>{@link #RDF_rdfxml_showXmlDeclaration}</td> - * <td>RDF/XML property: <code>showXmlDeclaration</code>.</td> - * <td><code>String</code></td> - * <td><js>"default"</js></td> - * </tr> - * <tr> - * <td>{@link #RDF_rdfxml_showDoctypeDeclaration}</td> - * <td>RDF/XML property: <code>showDoctypeDeclaration</code>.</td> - * <td><code>Boolean</code></td> - * <td><jk>true</jk></td> - * </tr> - * <tr> - * <td>{@link #RDF_rdfxml_tab}</td> - * <td>RDF/XML property: <code>tab</code>.</td> - * <td><code>Integer</code></td> - * <td><code>2</code></td> - * </tr> - * <tr> - * <td>{@link #RDF_rdfxml_attributeQuoteChar}</td> - * <td>RDF/XML property: <code>attributeQuoteChar</code>.</td> - * <td><code>Character</code></td> - * <td><js>'"'</js></td> - * </tr> - * <tr> - * <td>{@link #RDF_rdfxml_blockRules}</td> - * <td>RDF/XML property: <code>blockRules</code>.</td> - * <td><code>String</code></td> - * <td><js>""</js></td> - * </tr> - * <tr> - * <td>{@link #RDF_n3_minGap}</td> - * <td>N3/Turtle property: <code>minGap</code>.</td> - * <td><code>Integer</code></td> - * <td><code>1</code></td> - * </tr> - * <tr> - * <td>{@link #RDF_n3_objectLists}</td> - * <td>N3/Turtle property: <code>objectLists</code>.</td> - * <td><code>Boolean</code></td> - * <td><jk>true</jk></td> - * </tr> - * <tr> - * <td>{@link #RDF_n3_subjectColumn}</td> - * <td>N3/Turtle property: <code>subjectColumn</code>.</td> - * <td>code>Integer</code></td> - * <td>indent column</td> - * </tr> - * <tr> - * <td>{@link #RDF_n3_propertyColumn}</td> - * <td>N3/Turtle property: <code>propertyColumn</code>.</td> - * <td><code>Integer</code></td> - * <td><code>8</code></td> - * </tr> - * <tr> - * <td>{@link #RDF_n3_indentProperty}</td> - * <td>N3/Turtle property: <code>indentProperty</code>.</td> - * <td><code>Integer</code></td> - * <td><code>6</code></td> - * </tr> - * <tr> - * <td>{@link #RDF_n3_widePropertyLen}</td> - * <td>N3/Turtle property: <code>widePropertyLen</code>.</td> - * <td><code>Integer</code></td> - * <td><code>20</code></td> - * </tr> - * <tr> - * <td>{@link #RDF_n3_abbrevBaseUri}</td> - * <td>N3/Turtle property: <code>abbrevBaseURI</code>.</td> - * <td><code>Boolean</code></td> - * <td><jk>true</jk></td> - * </tr> - * <tr> - * <td>{@link #RDF_n3_usePropertySymbols}</td> - * <td>N3/Turtle property: <code>usePropertySymbols</code>.</td> - * <td><code>Boolean</code></td> - * <td><jk>true</jk></td> - * </tr> - * <tr> - * <td>{@link #RDF_n3_useTripleQuotedStrings}</td> - * <td>N3/Turtle property: <code>useTripleQuotedStrings</code>.</td> - * <td><code>Boolean</code></td> - * <td><jk>true</jk></td> - * </tr> - * <tr> - * <td>{@link #RDF_n3_useDoubles}</td> - * <td>N3/Turtle property: <code>useDoubles</code>.</td> - * <td><code>Boolean</code></td> - * <td><jk>true</jk></td> - * </tr> - * <tr> - * <td>{@link #RDF_collectionFormat}</td> - * <td>RDF format for representing collections and arrays.</td> - * <td><code>String</code></td> - * <td><js>"DEFAULT"</js></td> - * </tr> - * <tr> - * <td>{@link #RDF_looseCollections}</td> - * <td>Collections should be serialized and parsed as loose collections.</td> - * <td><code>Boolean</code></td> - * <td><jk>false</jk></td> - * </tr> - * </table> - */ -@SuppressWarnings("serial") -public interface RdfCommonContext { - - /** - * Maps RDF writer names to property prefixes that apply to them. - */ - final static Map<String,String> LANG_PROP_MAP = new HashMap<String,String>() {{ - put("RDF/XML","rdfXml."); - put("RDF/XML-ABBREV","rdfXml."); - put("N3","n3."); - put("N3-PP","n3."); - put("N3-PLAIN","n3."); - put("N3-TRIPLES","n3."); - put("TURTLE","n3."); - put("N-TRIPLE","ntriple."); - }}; - - /** - * <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> - */ - public static final String RDF_language = "Rdf.language"; - - /** - * <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> - */ - public static final String RDF_juneauNs = "Rdf.juneauNs"; - - /** - * <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> - */ - public static final String RDF_juneauBpNs = "Rdf.juneauBpNs"; - - /** - * <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}. - */ - public static final String RDF_useXmlNamespaces = "Rdf.useXmlNamespaces"; - - /** - * <b>Configuration property:</b> RDF/XML property: <code>iri_rules</code>. - * <p> - * <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 href='http://www.ietf.org/rfc/rfc3986.txt'>RFC 3986</a>, <a 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>. - * <p> - * <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 href='http://jena.sourceforge.net/javadoc/com/hp/hpl/jena/rdf/arp/ARPOptions.html#setDefaultErrorMode()'>ARPOptions.setDefaultErrorMode()</a> - * <li><a href='http://jena.sourceforge.net/javadoc/com/hp/hpl/jena/rdf/arp/ARPOptions.html#setLaxErrorMode()'>ARPOptions.setLaxErrorMode()</a> - * <li><a href='http://jena.sourceforge.net/javadoc/com/hp/hpl/jena/rdf/arp/ARPOptions.html#setStrictErrorMode()'>ARPOptions.setStrictErrorMode()</a> - * <li><a 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>. - * <p> - * <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 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>. - * <p> - * <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 href='http://jena.sourceforge.net/javadoc/com/hp/hpl/jena/rdf/arp/ARPErrorNumbers.html'>ARPErrorNumbers</a> - * <li><a 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>. - * <p> - * <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>. - * <p> - * <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>. - * <p> - * <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>. - * <p> - * <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>. - * <p> - * <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>. - * <p> - * <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 begining in <js>"../"</js> - * <li><js>"parent"</js> - Relative path begining in <js>"../"</js> - * <li><js>"grandparent"</js> - Relative path begining 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>. - * <p> - * <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>. - * <p> - * <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>. - * <p> - * <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>. - * <p> - * <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>. - * <p> - * <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 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>. - * <p> - * <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>. - * <p> - * <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>. - * <p> - * <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>. - * <p> - * <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>. - * <p> - * <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>. - * <p> - * <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>. - * <p> - * <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>. - * <p> - * <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>. - * <p> - * <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>. - * <p> - * <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. - * <p> - * <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> - * </p> - * <p> - * Important Note: If you use <js>"BAG"</js> or <js>"MULTI_VALUED"</js>, the order of the elements - * in the collection will get lost. - */ - public static final String RDF_collectionFormat = "Rdf.collectionFormat"; - - /** - * <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)}. - * - * <h6 class='topic'>Example:</h6> - * <p class='bcode'> - * WriterSerializer s = <jk>new</jk> RdfSerializer.XmlAbbrev().setProperty(<jsf>RDF_looseCollection</jsf>, <jk>true</jk>); - * ReaderParser p = <jk>new</jk> RdfParser.Xml().setProperty(<jsf>RDF_looseCollection</jsf>, <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.parseCollection(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/e4dfdf81/juneau-core/src/main/java/org/apache/juneau/jena/RdfParser.java ---------------------------------------------------------------------- diff --git a/juneau-core/src/main/java/org/apache/juneau/jena/RdfParser.java b/juneau-core/src/main/java/org/apache/juneau/jena/RdfParser.java deleted file mode 100644 index 604d98a..0000000 --- a/juneau-core/src/main/java/org/apache/juneau/jena/RdfParser.java +++ /dev/null @@ -1,502 +0,0 @@ -// *************************************************************************************************************************** -// * 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.internal.StringUtils.*; -import static org.apache.juneau.jena.Constants.*; -import static org.apache.juneau.jena.RdfCommonContext.*; - -import java.lang.reflect.*; -import java.util.*; - -import org.apache.juneau.*; -import org.apache.juneau.annotation.*; -import org.apache.juneau.parser.*; -import org.apache.juneau.transform.*; - -import com.hp.hpl.jena.rdf.model.*; -import com.hp.hpl.jena.util.iterator.*; - -/** - * Parses RDF into POJOs. - * - * <h6 class='topic'>Configurable properties</h6> - * <p> - * 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> - * <p> - * 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> - * - * <h6 class='topic'>Additional Information</h6> - * <p> - * See <a class='doclink' href='package-summary.html#TOC'>RDF Overview</a> for an overview of RDF support in Juneau. - */ -@Consumes(value="text/xml+rdf") -public class RdfParser extends ReaderParser { - - /** Default XML parser, all default settings.*/ - public static final RdfParser DEFAULT_XML = new RdfParser.Xml().lock(); - - /** Default Turtle parser, all default settings.*/ - public static final RdfParser DEFAULT_TURTLE = new RdfParser.Turtle().lock(); - - /** Default N-Triple parser, all default settings.*/ - public static final RdfParser DEFAULT_NTRIPLE = new RdfParser.NTriple().lock(); - - /** Default N3 parser, all default settings.*/ - public static final RdfParser DEFAULT_N3 = new RdfParser.N3().lock(); - - - /** Consumes RDF/XML input */ - @Consumes("text/xml+rdf") - public static class Xml extends RdfParser { - /** Constructor */ - public Xml() { - setProperty(RDF_language, LANG_RDF_XML); - } - } - - /** Consumes N-Triple input */ - @Consumes(value="text/n-triple") - public static class NTriple extends RdfParser { - /** Constructor */ - public NTriple() { - setProperty(RDF_language, LANG_NTRIPLE); - } - } - - /** Consumes Turtle input */ - @Consumes(value="text/turtle") - public static class Turtle extends RdfParser { - /** Constructor */ - public Turtle() { - setProperty(RDF_language, LANG_TURTLE); - } - } - - /** Consumes N3 input */ - @Consumes(value="text/n3") - public static class N3 extends RdfParser { - /** Constructor */ - public N3() { - setProperty(RDF_language, LANG_N3); - } - } - - - @SuppressWarnings({"unchecked", "rawtypes"}) - @Override /* ReaderParser */ - protected <T> T doParse(ParserSession session, ClassMeta<T> type) throws Exception { - - RdfParserSession s = (RdfParserSession)session; - - type = session.normalizeClassMeta(type); - - Model model = s.getModel(); - RDFReader r = s.getRdfReader(); - r.read(model, session.getReader(), null); - - List<Resource> roots = getRoots(s, model); - - // Special case where we're parsing a loose collection of resources. - if (s.isLooseCollections() && type.isCollectionOrArray()) { - Collection c = null; - if (type.isArray()) - c = new ArrayList(); - else - c = (type.canCreateNewInstance(session.getOuter()) ? (Collection<?>)type.newInstance(session.getOuter()) : new ObjectList(session)); - for (Resource resource : roots) - c.add(parseAnything(s, type.getElementType(), resource, session.getOuter())); - - if (type.isArray()) - return (T)session.toArray(type, c); - return (T)c; - } - - if (roots.isEmpty()) - return null; - if (roots.size() > 1) - throw new ParseException(session, "Too many root nodes found in model: {0}", roots.size()); - Resource resource = roots.get(0); - - return parseAnything(s, type, resource, session.getOuter()); - } - - /* - * Finds the roots in the model using either the "root" property to identify it, - * or by resorting to scanning the model for all nodes with no incoming predicates. - */ - private List<Resource> getRoots(RdfParserSession session, Model m) { - List<Resource> l = new LinkedList<Resource>(); - - // First try to find the root using the "http://www.apache.org/juneau/root" property. - Property root = m.createProperty(session.getJuneauNsUri(), RDF_juneauNs_ROOT); - for (ResIterator i = m.listResourcesWithProperty(root); i.hasNext();) - l.add(i.next()); - - if (! l.isEmpty()) - return l; - - // Otherwise, we need to find all resources that aren't objects. - // We want to explicitly ignore statements where the subject - // and object are the same node. - Set<RDFNode> objects = new HashSet<RDFNode>(); - for (StmtIterator i = m.listStatements(); i.hasNext();) { - Statement st = i.next(); - RDFNode subject = st.getSubject(); - RDFNode object = st.getObject(); - if (object.isResource() && ! object.equals(subject)) - objects.add(object); - } - for (ResIterator i = m.listSubjects(); i.hasNext();) { - Resource r = i.next(); - if (! objects.contains(r)) - l.add(r); - } - return l; - } - - private <T> BeanMap<T> parseIntoBeanMap(RdfParserSession session, Resource r2, BeanMap<T> m) throws Exception { - BeanMeta<T> bm = m.getMeta(); - RdfBeanMeta rbm = bm.getExtendedMeta(RdfBeanMeta.class); - if (rbm.hasBeanUri() && r2.getURI() != null) - rbm.getBeanUriProperty().set(m, r2.getURI()); - Property subTypeIdProperty = null; - BeanPropertyMeta stp = bm.getSubTypeProperty(); - if (stp != null) { - subTypeIdProperty = session.getProperty(stp.getName()); - Statement st = r2.getProperty(subTypeIdProperty); - if (st == null) - throw new ParseException(session, "Could not find subtype ID property for bean of type ''{0}''", m.getClassMeta()); - String subTypeId = st.getLiteral().getString(); - stp.set(m, subTypeId); - } - for (StmtIterator i = r2.listProperties(); i.hasNext();) { - Statement st = i.next(); - Property p = st.getPredicate(); - if (p.equals(subTypeIdProperty)) - continue; - String key = session.decodeString(p.getLocalName()); - BeanPropertyMeta pMeta = m.getPropertyMeta(key); - session.setCurrentProperty(pMeta); - if (pMeta != null) { - RDFNode o = st.getObject(); - ClassMeta<?> cm = pMeta.getClassMeta(); - if (cm.isCollectionOrArray() && isMultiValuedCollections(session, pMeta)) { - ClassMeta<?> et = cm.getElementType(); - Object value = parseAnything(session, et, o, m.getBean(false)); - setName(et, value, key); - pMeta.add(m, value); - } else { - Object value = parseAnything(session, cm, o, m.getBean(false)); - setName(cm, value, key); - pMeta.set(m, value); - } - } else if (! (p.equals(session.getRootProperty()) || p.equals(session.getClassProperty()) || p.equals(subTypeIdProperty))) { - if (bm.isSubTyped()) { - RDFNode o = st.getObject(); - Object value = parseAnything(session, object(), o, m.getBean(false)); - m.put(key, value); - } else { - onUnknownProperty(session, key, m, -1, -1); - } - } - session.setCurrentProperty(null); - } - return m; - } - - private boolean isMultiValuedCollections(RdfParserSession session, BeanPropertyMeta pMeta) { - if (pMeta != null && pMeta.getExtendedMeta(RdfBeanPropertyMeta.class).getCollectionFormat() != RdfCollectionFormat.DEFAULT) - return pMeta.getExtendedMeta(RdfBeanPropertyMeta.class).getCollectionFormat() == RdfCollectionFormat.MULTI_VALUED; - return session.getCollectionFormat() == RdfCollectionFormat.MULTI_VALUED; - } - - @SuppressWarnings({ "unchecked", "rawtypes" }) - private <T> T parseAnything(RdfParserSession session, ClassMeta<T> eType, RDFNode n, Object outer) throws Exception { - - if (eType == null) - eType = (ClassMeta<T>)object(); - PojoSwap<T,Object> transform = (PojoSwap<T,Object>)eType.getPojoSwap(); - ClassMeta<?> sType = eType.getSerializedClassMeta(); - session.setCurrentClass(sType); - - if (! sType.canCreateNewInstance(outer)) { - if (n.isResource()) { - Statement st = n.asResource().getProperty(session.getClassProperty()); - if (st != null) { - String c = st.getLiteral().getString(); - sType = eType = (ClassMeta<T>)session.getClassMetaFromString(c); - } - } - } - - Object o = null; - if (n.isResource() && n.asResource().getURI() != null && n.asResource().getURI().equals(RDF_NIL)) { - // Do nothing. Leave o == null. - } else if (sType.isObject()) { - if (n.isLiteral()) { - o = n.asLiteral().getValue(); - if (o instanceof String) { - o = session.decodeString(o); - } - } - else if (n.isResource()) { - Resource r = n.asResource(); - if (session.wasAlreadyProcessed(r)) - o = r.getURI(); - else if (r.getProperty(session.getValueProperty()) != null) { - o = parseAnything(session, object(), n.asResource().getProperty(session.getValueProperty()).getObject(), outer); - } else if (isSeq(session, r)) { - o = new ObjectList(session); - parseIntoCollection(session, r.as(Seq.class), (Collection)o, sType.getElementType()); - } else if (isBag(session, r)) { - o = new ObjectList(session); - parseIntoCollection(session, r.as(Bag.class), (Collection)o, sType.getElementType()); - } else if (r.canAs(RDFList.class)) { - o = new ObjectList(session); - parseIntoCollection(session, r.as(RDFList.class), (Collection)o, sType.getElementType()); - } else { - // If it has a URI and no child properties, we interpret this as an - // external resource, and convert it to just a URL. - String uri = r.getURI(); - if (uri != null && ! r.listProperties().hasNext()) { - o = r.getURI(); - } else { - o = new ObjectMap(session); - parseIntoMap(session, r, (Map)o, null, null); - } - } - } else { - throw new ParseException(session, "Unrecognized node type ''{0}'' for object", n); - } - } else if (sType.isBoolean()) { - o = session.convertToType(getValue(session, n, outer), boolean.class); - } else if (sType.isCharSequence()) { - o = session.decodeString(getValue(session, n, outer)); - } else if (sType.isChar()) { - o = session.decodeString(getValue(session, n, outer)).charAt(0); - } else if (sType.isNumber()) { - o = parseNumber(getValue(session, n, outer).toString(), (Class<? extends Number>)sType.getInnerClass()); - } else if (sType.isMap()) { - Resource r = n.asResource(); - if (session.wasAlreadyProcessed(r)) - return null; - Map m = (sType.canCreateNewInstance(outer) ? (Map)sType.newInstance(outer) : new ObjectMap(session)); - o = parseIntoMap(session, r, m, eType.getKeyType(), eType.getValueType()); - } else if (sType.isCollectionOrArray()) { - if (sType.isArray()) - o = new ArrayList(); - else - o = (sType.canCreateNewInstance(outer) ? (Collection<?>)sType.newInstance(outer) : new ObjectList(session)); - Resource r = n.asResource(); - if (session.wasAlreadyProcessed(r)) - return null; - if (isSeq(session, r)) { - parseIntoCollection(session, r.as(Seq.class), (Collection)o, sType.getElementType()); - } else if (isBag(session, r)) { - parseIntoCollection(session, r.as(Bag.class), (Collection)o, sType.getElementType()); - } else if (r.canAs(RDFList.class)) { - parseIntoCollection(session, r.as(RDFList.class), (Collection)o, sType.getElementType()); - } else { - throw new ParseException("Unrecognized node type ''{0}'' for collection", n); - } - if (sType.isArray()) - o = session.toArray(sType, (Collection)o); - } else if (sType.canCreateNewInstanceFromObjectMap(outer)) { - Resource r = n.asResource(); - if (session.wasAlreadyProcessed(r)) - return null; - Map m = new ObjectMap(session); - parseIntoMap(session, r, m, eType.getKeyType(), eType.getValueType()); - o = sType.newInstanceFromObjectMap(outer, (ObjectMap)m); - } else if (sType.canCreateNewBean(outer)) { - Resource r = n.asResource(); - if (session.wasAlreadyProcessed(r)) - return null; - BeanMap<?> bm = session.newBeanMap(outer, sType.getInnerClass()); - o = parseIntoBeanMap(session, r, bm).getBean(); - } else if (sType.isUri() && n.isResource()) { - o = sType.newInstanceFromString(outer, session.decodeString(n.asResource().getURI())); - } else if (sType.canCreateNewInstanceFromString(outer)) { - o = sType.newInstanceFromString(outer, session.decodeString(getValue(session, n, outer))); - } else if (sType.canCreateNewInstanceFromNumber(outer)) { - o = sType.newInstanceFromNumber(session, outer, parseNumber(getValue(session, n, outer).toString(), sType.getNewInstanceFromNumberClass())); - } else { - throw new ParseException("Class ''{0}'' could not be instantiated. Reason: ''{1}''", sType.getInnerClass().getName(), sType.getNotABeanReason()); - } - - if (transform != null && o != null) - o = transform.unswap(session, o, eType); - - if (outer != null) - setParent(eType, o, outer); - - return (T)o; - } - - private boolean isSeq(RdfParserSession session, RDFNode n) { - if (n.isResource()) { - Statement st = n.asResource().getProperty(session.getTypeProperty()); - if (st != null) - return RDF_SEQ.equals(st.getResource().getURI()); - } - return false; - } - - private boolean isBag(RdfParserSession session, RDFNode n) { - if (n.isResource()) { - Statement st = n.asResource().getProperty(session.getTypeProperty()); - if (st != null) - return RDF_BAG.equals(st.getResource().getURI()); - } - return false; - } - - private Object getValue(RdfParserSession session, RDFNode n, Object outer) throws Exception { - if (n.isLiteral()) - return n.asLiteral().getValue(); - if (n.isResource()) { - Statement st = n.asResource().getProperty(session.getValueProperty()); - if (st != null) { - n = st.getObject(); - if (n.isLiteral()) - return n.asLiteral().getValue(); - return parseAnything(session, object(), st.getObject(), outer); - } - } - throw new ParseException(session, "Unknown value type for node ''{0}''", n); - } - - private <K,V> Map<K,V> parseIntoMap(RdfParserSession session, Resource r, Map<K,V> m, ClassMeta<K> keyType, ClassMeta<V> valueType) throws Exception { - // Add URI as "uri" to generic maps. - if (r.getURI() != null) { - K uri = convertAttrToType(session, m, "uri", keyType); - V value = convertAttrToType(session, m, r.getURI(), valueType); - m.put(uri, value); - } - for (StmtIterator i = r.listProperties(); i.hasNext();) { - Statement st = i.next(); - Property p = st.getPredicate(); - String key = p.getLocalName(); - if (! (key.equals("root") && p.getURI().equals(session.getJuneauNsUri()))) { - key = session.decodeString(key); - RDFNode o = st.getObject(); - K key2 = convertAttrToType(session, m, key, keyType); - V value = parseAnything(session, valueType, o, m); - setName(valueType, value, key); - m.put(key2, value); - } - - } - // TODO Auto-generated method stub - return m; - } - - private <E> Collection<E> parseIntoCollection(RdfParserSession session, Container c, Collection<E> l, ClassMeta<E> et) throws Exception { - for (NodeIterator ni = c.iterator(); ni.hasNext();) { - E e = parseAnything(session, et, ni.next(), l); - l.add(e); - } - return l; - } - - private <E> Collection<E> parseIntoCollection(RdfParserSession session, RDFList list, Collection<E> l, ClassMeta<E> et) throws Exception { - for (ExtendedIterator<RDFNode> ni = list.iterator(); ni.hasNext();) { - E e = parseAnything(session, et, ni.next(), l); - l.add(e); - } - return l; - } - - //-------------------------------------------------------------------------------- - // Overridden methods - //-------------------------------------------------------------------------------- - - @Override /* Parser */ - public RdfParserSession createSession(Object input, ObjectMap op, Method javaMethod, Object outer, Locale locale, TimeZone timeZone) { - return new RdfParserSession(getContext(RdfParserContext.class), op, input, javaMethod, outer, locale, timeZone); - } - - @Override /* CoreApi */ - public RdfParser setProperty(String property, Object value) throws LockedException { - super.setProperty(property, value); - return this; - } - - @Override /* CoreApi */ - public RdfParser setProperties(ObjectMap properties) throws LockedException { - super.setProperties(properties); - return this; - } - - @Override /* CoreApi */ - public RdfParser addNotBeanClasses(Class<?>...classes) throws LockedException { - super.addNotBeanClasses(classes); - return this; - } - - @Override /* CoreApi */ - public RdfParser addBeanFilters(Class<?>...classes) throws LockedException { - super.addBeanFilters(classes); - return this; - } - - @Override /* CoreApi */ - public RdfParser addPojoSwaps(Class<?>...classes) throws LockedException { - super.addPojoSwaps(classes); - return this; - } - - @Override /* CoreApi */ - public RdfParser addToDictionary(Class<?>...classes) throws LockedException { - super.addToDictionary(classes); - return this; - } - - @Override /* CoreApi */ - public <T> RdfParser addImplClass(Class<T> interfaceClass, Class<? extends T> implClass) throws LockedException { - super.addImplClass(interfaceClass, implClass); - return this; - } - - @Override /* CoreApi */ - public RdfParser setClassLoader(ClassLoader classLoader) throws LockedException { - super.setClassLoader(classLoader); - return this; - } - - @Override /* Lockable */ - public RdfParser lock() { - super.lock(); - return this; - } - - @Override /* Lockable */ - public RdfParser clone() { - try { - RdfParser c = (RdfParser)super.clone(); - return c; - } catch (CloneNotSupportedException e) { - throw new RuntimeException(e); // Shouldn't happen - } - } -}
