diff --git a/declarative/annotations/pom.xml b/declarative/annotations/pom.xml new file mode 100644 index 000000000..0a405c7c7 --- /dev/null +++ b/declarative/annotations/pom.xml @@ -0,0 +1,30 @@ + + + 4.0.0 + + com.inrupt.rdf + inrupt-rdf-wrapping-declarative + 1.0.1-SNAPSHOT + + + inrupt-rdf-wrapping-declarative-annotations + Inrupt RDF Wrapping Declarative - Annotations + + + 1.8 + 1.8 + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + org.jacoco + jacoco-maven-plugin + + + + diff --git a/declarative/annotations/src/main/java/com/inrupt/rdf/wrapping/declarative/annotations/Dataset.java b/declarative/annotations/src/main/java/com/inrupt/rdf/wrapping/declarative/annotations/Dataset.java new file mode 100644 index 000000000..9003b1491 --- /dev/null +++ b/declarative/annotations/src/main/java/com/inrupt/rdf/wrapping/declarative/annotations/Dataset.java @@ -0,0 +1,34 @@ +/* + * Copyright Inrupt Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the + * Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +package com.inrupt.rdf.wrapping.declarative.annotations; + +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.CLASS; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +@Target(TYPE) +@Retention(CLASS) +@Documented +public @interface Dataset { +} diff --git a/declarative/annotations/src/main/java/com/inrupt/rdf/wrapping/declarative/annotations/Graph.java b/declarative/annotations/src/main/java/com/inrupt/rdf/wrapping/declarative/annotations/Graph.java new file mode 100644 index 000000000..62a893e49 --- /dev/null +++ b/declarative/annotations/src/main/java/com/inrupt/rdf/wrapping/declarative/annotations/Graph.java @@ -0,0 +1,34 @@ +/* + * Copyright Inrupt Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the + * Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +package com.inrupt.rdf.wrapping.declarative.annotations; + +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.CLASS; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +@Target(TYPE) +@Retention(CLASS) +@Documented +public @interface Graph { +} diff --git a/declarative/annotations/src/main/java/com/inrupt/rdf/wrapping/declarative/annotations/Resource.java b/declarative/annotations/src/main/java/com/inrupt/rdf/wrapping/declarative/annotations/Resource.java new file mode 100644 index 000000000..c7b2ca60e --- /dev/null +++ b/declarative/annotations/src/main/java/com/inrupt/rdf/wrapping/declarative/annotations/Resource.java @@ -0,0 +1,34 @@ +/* + * Copyright Inrupt Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the + * Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +package com.inrupt.rdf.wrapping.declarative.annotations; + +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.CLASS; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +@Target(TYPE) +@Retention(CLASS) +@Documented +public @interface Resource { +} diff --git a/declarative/pom.xml b/declarative/pom.xml new file mode 100644 index 000000000..0f46267e3 --- /dev/null +++ b/declarative/pom.xml @@ -0,0 +1,32 @@ + + + 4.0.0 + + com.inrupt.rdf + inrupt-rdf-wrapping + 1.0.1-SNAPSHOT + + + inrupt-rdf-wrapping-declarative + Inrupt RDF Wrapping Declarative + pom + + + annotations + processor + test + template + + + + + + org.apache.maven.plugins + maven-deploy-plugin + + true + + + + + diff --git a/declarative/processor/pom.xml b/declarative/processor/pom.xml new file mode 100644 index 000000000..442c3b455 --- /dev/null +++ b/declarative/processor/pom.xml @@ -0,0 +1,71 @@ + + + 4.0.0 + + com.inrupt.rdf + inrupt-rdf-wrapping-declarative + 1.0.1-SNAPSHOT + + + inrupt-rdf-wrapping-declarative-processor + Inrupt RDF Wrapping Declarative - Processor + + + + + + 1.8 + 1.8 + + 3.0.1.Final + + + + + com.inrupt.rdf + inrupt-rdf-wrapping-declarative-annotations + ${project.version} + + + + org.jboss.logmanager + jboss-logmanager + ${jboss.logmanager.version} + + + + org.junit.jupiter + junit-jupiter-api + test + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + default-compile + compile + + compile + + + -proc:none + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + org.jacoco + jacoco-maven-plugin + + + + diff --git a/declarative/processor/src/main/java/com/inrupt/rdf/wrapping/declarative/processor/Processor.java b/declarative/processor/src/main/java/com/inrupt/rdf/wrapping/declarative/processor/Processor.java new file mode 100644 index 000000000..6ae1bd13f --- /dev/null +++ b/declarative/processor/src/main/java/com/inrupt/rdf/wrapping/declarative/processor/Processor.java @@ -0,0 +1,51 @@ +/* + * Copyright Inrupt Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the + * Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +package com.inrupt.rdf.wrapping.declarative.processor; + +import java.util.Set; + +import javax.annotation.processing.AbstractProcessor; +import javax.annotation.processing.RoundEnvironment; +import javax.annotation.processing.SupportedAnnotationTypes; +import javax.annotation.processing.SupportedSourceVersion; +import javax.lang.model.SourceVersion; +import javax.lang.model.element.Element; +import javax.lang.model.element.TypeElement; + +import org.jboss.logging.Logger; + +@SupportedAnnotationTypes("com.inrupt.rdf.wrapping.declarative.annotations.*") +@SupportedSourceVersion(SourceVersion.RELEASE_8) +public class Processor extends AbstractProcessor { + private static final Logger LOG = Logger.getLogger(Processor.class); + + @Override + public boolean process(final Set annotations, final RoundEnvironment roundEnv) { + LOG.infov("annotations {0}", annotations); + + for (TypeElement annotation : annotations) { + final Set annotatedElements = roundEnv.getElementsAnnotatedWith(annotation); + LOG.infov("annotatedElements {0}", annotatedElements); + } + + return true; + } +} diff --git a/declarative/processor/src/main/resources/META-INF/services/javax.annotation.processing.Processor b/declarative/processor/src/main/resources/META-INF/services/javax.annotation.processing.Processor new file mode 100644 index 000000000..63e203cdb --- /dev/null +++ b/declarative/processor/src/main/resources/META-INF/services/javax.annotation.processing.Processor @@ -0,0 +1 @@ +com.inrupt.rdf.wrapping.declarative.processor.Processor diff --git a/declarative/template/pom.xml b/declarative/template/pom.xml new file mode 100644 index 000000000..ce9de407d --- /dev/null +++ b/declarative/template/pom.xml @@ -0,0 +1,35 @@ + + + 4.0.0 + + com.inrupt.rdf + inrupt-rdf-wrapping-declarative + 1.0.1-SNAPSHOT + + + inrupt-rdf-wrapping-declarative-template + Inrupt RDF Wrapping Declarative - Template + + Examples of wrapper interfaces and the implementations the Processor should generate from them + + + + 17 + 17 + + + + + com.inrupt.rdf + inrupt-rdf-wrapping-jena + ${project.version} + + + + org.junit.jupiter + junit-jupiter + test + + + diff --git a/declarative/template/src/main/java/com/inrupt/rdf/wrapping/declarative/template/ExampleDataset.java b/declarative/template/src/main/java/com/inrupt/rdf/wrapping/declarative/template/ExampleDataset.java new file mode 100644 index 000000000..82e41a0c5 --- /dev/null +++ b/declarative/template/src/main/java/com/inrupt/rdf/wrapping/declarative/template/ExampleDataset.java @@ -0,0 +1,33 @@ +/* + * Copyright Inrupt Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the + * Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +package com.inrupt.rdf.wrapping.declarative.template; + +import org.apache.jena.query.Dataset; + +// @Dataset +public interface ExampleDataset { + static ExampleDataset wrap(final Dataset original) { + return Manager.wrap(ExampleDataset.class, original); + } + + // @DefaultGraph + ExampleGraph getGraph(); +} diff --git a/declarative/template/src/main/java/com/inrupt/rdf/wrapping/declarative/template/ExampleDataset_$impl.java b/declarative/template/src/main/java/com/inrupt/rdf/wrapping/declarative/template/ExampleDataset_$impl.java new file mode 100644 index 000000000..586b6640c --- /dev/null +++ b/declarative/template/src/main/java/com/inrupt/rdf/wrapping/declarative/template/ExampleDataset_$impl.java @@ -0,0 +1,52 @@ +/* + * Copyright Inrupt Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the + * Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +package com.inrupt.rdf.wrapping.declarative.template; + +import javax.annotation.processing.Generated; + +import org.apache.jena.query.Dataset; +import org.apache.jena.sparql.core.DatasetGraph; +import org.apache.jena.sparql.core.DatasetGraphFactory; +import org.apache.jena.sparql.core.DatasetImpl; + +/** + * Warning this class consists of generated code. + */ +@Generated(value = "TODO: FQCN of generator", date = "TODO: Generation date") +public class ExampleDataset_$impl extends DatasetImpl implements ExampleDataset { + + protected ExampleDataset_$impl(final DatasetGraph original) { + super(original); + } + + public static ExampleDataset wrap(final Dataset original) { + return new ExampleDataset_$impl(original.asDatasetGraph()); + } + + public static ExampleDataset create() { + return new ExampleDataset_$impl(DatasetGraphFactory.create()); + } + + @Override + public ExampleGraph getGraph() { + return ExampleGraph.wrap(getDefaultModel()); + } +} diff --git a/declarative/template/src/main/java/com/inrupt/rdf/wrapping/declarative/template/ExampleGraph.java b/declarative/template/src/main/java/com/inrupt/rdf/wrapping/declarative/template/ExampleGraph.java new file mode 100644 index 000000000..534360337 --- /dev/null +++ b/declarative/template/src/main/java/com/inrupt/rdf/wrapping/declarative/template/ExampleGraph.java @@ -0,0 +1,33 @@ +/* + * Copyright Inrupt Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the + * Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +package com.inrupt.rdf.wrapping.declarative.template; + +import org.apache.jena.rdf.model.Model; + +// @Graph +public interface ExampleGraph { + static ExampleGraph wrap(final Model original) { + return Manager.wrap(ExampleGraph.class, original); + } + + // @FirstSubjectOf(RDF.type, "urn:example:C") + ExampleNode1 getResource(); +} diff --git a/declarative/template/src/main/java/com/inrupt/rdf/wrapping/declarative/template/ExampleGraph_$impl.java b/declarative/template/src/main/java/com/inrupt/rdf/wrapping/declarative/template/ExampleGraph_$impl.java new file mode 100644 index 000000000..3bff32501 --- /dev/null +++ b/declarative/template/src/main/java/com/inrupt/rdf/wrapping/declarative/template/ExampleGraph_$impl.java @@ -0,0 +1,61 @@ +/* + * Copyright Inrupt Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the + * Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +package com.inrupt.rdf.wrapping.declarative.template; + +import javax.annotation.processing.Generated; + +import org.apache.jena.graph.Graph; +import org.apache.jena.rdf.model.Model; +import org.apache.jena.rdf.model.ResourceFactory; +import org.apache.jena.rdf.model.impl.ModelCom; +import org.apache.jena.sparql.graph.GraphFactory; +import org.apache.jena.vocabulary.RDF; + +/** + * Warning this class consists of generated code. + */ +@Generated(value = "TODO: FQCN of generator", date = "TODO: Generation date") +public class ExampleGraph_$impl extends ModelCom implements ExampleGraph { + protected ExampleGraph_$impl(final Graph base) { + super(base); + + getPersonality() + .add(ExampleNode1_$impl.class, ExampleNode1_$impl.factory) + .add(ExampleNode2_$impl.class, ExampleNode2_$impl.factory); + } + + public static ExampleGraph wrap(final Model original) { + return new ExampleGraph_$impl(original.getGraph()); + } + + public static ExampleGraph create() { + return new ExampleGraph_$impl(GraphFactory.createDefaultGraph()); + } + + @Override + public ExampleNode1 getResource() { + return listResourcesWithProperty( + RDF.type, + ResourceFactory.createResource("urn:example:C")) + .nextResource() + .as(ExampleNode1_$impl.class); + } +} diff --git a/declarative/template/src/main/java/com/inrupt/rdf/wrapping/declarative/template/ExampleNode1.java b/declarative/template/src/main/java/com/inrupt/rdf/wrapping/declarative/template/ExampleNode1.java new file mode 100644 index 000000000..b84325c35 --- /dev/null +++ b/declarative/template/src/main/java/com/inrupt/rdf/wrapping/declarative/template/ExampleNode1.java @@ -0,0 +1,7 @@ +package com.inrupt.rdf.wrapping.declarative.template; + +// @Resource +public interface ExampleNode1 { + // @Property(predicate = "urn:example:p1", type = PropertyMappingTypes.anyOrNull, mapping = ValueMappingTypes.as) + ExampleNode2 getP1(); +} diff --git a/declarative/template/src/main/java/com/inrupt/rdf/wrapping/declarative/template/ExampleNode1_$impl.java b/declarative/template/src/main/java/com/inrupt/rdf/wrapping/declarative/template/ExampleNode1_$impl.java new file mode 100644 index 000000000..9564cb17e --- /dev/null +++ b/declarative/template/src/main/java/com/inrupt/rdf/wrapping/declarative/template/ExampleNode1_$impl.java @@ -0,0 +1,53 @@ +/* + * Copyright Inrupt Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the + * Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +package com.inrupt.rdf.wrapping.declarative.template; + +import static org.apache.jena.rdf.model.ResourceFactory.*; + +import com.inrupt.rdf.wrapping.jena.UriOrBlankFactory; +import com.inrupt.rdf.wrapping.jena.ValueMappings; +import com.inrupt.rdf.wrapping.jena.WrapperResource; + +import javax.annotation.processing.Generated; + +import org.apache.jena.enhanced.EnhGraph; +import org.apache.jena.enhanced.Implementation; +import org.apache.jena.graph.Node; +import org.apache.jena.rdf.model.ResourceFactory; + +/** + * Warning this class consists of generated code. + */ +@Generated(value = "TODO: FQCN of generator", date = "TODO: Generation date") +public class ExampleNode1_$impl extends WrapperResource implements ExampleNode1 { + static final Implementation factory = new UriOrBlankFactory(ExampleNode1_$impl::new); + + protected ExampleNode1_$impl(Node node, EnhGraph model) { + super(node, model); + } + + @Override + public ExampleNode2 getP1() { + return anyOrNull( + createProperty("urn:example:p1"), + ValueMappings.as(ExampleNode2_$impl.class)); + } +} diff --git a/declarative/template/src/main/java/com/inrupt/rdf/wrapping/declarative/template/ExampleNode2.java b/declarative/template/src/main/java/com/inrupt/rdf/wrapping/declarative/template/ExampleNode2.java new file mode 100644 index 000000000..c8af94dff --- /dev/null +++ b/declarative/template/src/main/java/com/inrupt/rdf/wrapping/declarative/template/ExampleNode2.java @@ -0,0 +1,27 @@ +/* + * Copyright Inrupt Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the + * Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +package com.inrupt.rdf.wrapping.declarative.template; + +// @Resource +public interface ExampleNode2 { + // @Property(predicate = "urn:example:p2", type = PropertyMappingTypes.anyOrNull, mapping = ValueMappingTypes.literalAsString) + String getP2(); +} diff --git a/declarative/template/src/main/java/com/inrupt/rdf/wrapping/declarative/template/ExampleNode2_$impl.java b/declarative/template/src/main/java/com/inrupt/rdf/wrapping/declarative/template/ExampleNode2_$impl.java new file mode 100644 index 000000000..10b045ab8 --- /dev/null +++ b/declarative/template/src/main/java/com/inrupt/rdf/wrapping/declarative/template/ExampleNode2_$impl.java @@ -0,0 +1,53 @@ +/* + * Copyright Inrupt Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the + * Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +package com.inrupt.rdf.wrapping.declarative.template; + +import static org.apache.jena.rdf.model.ResourceFactory.*; + +import com.inrupt.rdf.wrapping.jena.UriOrBlankFactory; +import com.inrupt.rdf.wrapping.jena.ValueMappings; +import com.inrupt.rdf.wrapping.jena.WrapperResource; + +import javax.annotation.processing.Generated; + +import org.apache.jena.enhanced.EnhGraph; +import org.apache.jena.enhanced.Implementation; +import org.apache.jena.graph.Node; +import org.apache.jena.rdf.model.ResourceFactory; + +/** + * Warning this class consists of generated code. + */ +@Generated(value = "TODO: FQCN of generator", date = "TODO: Generation date") +public class ExampleNode2_$impl extends WrapperResource implements ExampleNode2 { + static final Implementation factory = new UriOrBlankFactory(ExampleNode2_$impl::new); + + protected ExampleNode2_$impl(Node node, EnhGraph model) { + super(node, model); + } + + @Override + public String getP2() { + return anyOrNull( + createProperty("urn:example:p2"), + ValueMappings::literalAsString); + } +} diff --git a/declarative/template/src/main/java/com/inrupt/rdf/wrapping/declarative/template/Manager.java b/declarative/template/src/main/java/com/inrupt/rdf/wrapping/declarative/template/Manager.java new file mode 100644 index 000000000..d225d2d3a --- /dev/null +++ b/declarative/template/src/main/java/com/inrupt/rdf/wrapping/declarative/template/Manager.java @@ -0,0 +1,79 @@ +/* + * Copyright Inrupt Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the + * Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +package com.inrupt.rdf.wrapping.declarative.template; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import org.apache.jena.query.Dataset; +import org.apache.jena.rdf.model.Model; + +/** + * A utility class that aids wrapper interfaces to find generated implementations + */ +// TODO: Move to processor module +// TODO: Should this be SPI? +public final class Manager { + private Manager() { + } + + public static T wrap(final Class type, final Model original) { + return wrap(type, original, Model.class); + } + + public static T wrap(final Class type, final Dataset original) { + return wrap(type, original, Dataset.class); + } + + private static T wrap(final Class type, final Object original, Class xtype) { + final ClassLoader classLoader = type.getClassLoader(); + final String implTypeName = type.getName() + "_$impl"; + + Class implClass; + try { + implClass = Class.forName(implTypeName, true, classLoader).asSubclass(type); + } catch (ClassNotFoundException e) { + throw new RuntimeException("implementation not found", e); + } catch (ClassCastException e) { + // TODO: probably not needed as it's generated, match on $impl + throw new RuntimeException("implementation type mismatch", e); + } + + + final Method wrapMethod; + try { + wrapMethod = implClass.getMethod("wrap", xtype); + } catch (NoSuchMethodException e) { + throw new RuntimeException("wrap method not found", e); + } + + try { + return type.cast(wrapMethod.invoke(null, original)); + } catch (IllegalAccessException e) { + throw new RuntimeException("wrap method inaccessible", e); + } catch (InvocationTargetException e) { + throw new RuntimeException("wrap method threw exception", e); + } catch (ClassCastException e) { + // TODO: probably not needed as it's generated, match on $impl + throw new RuntimeException("wrap method return type mismatch", e); + } + } +} diff --git a/declarative/template/src/main/java/com/inrupt/rdf/wrapping/declarative/template/package-info.java b/declarative/template/src/main/java/com/inrupt/rdf/wrapping/declarative/template/package-info.java new file mode 100644 index 000000000..cb90dd82b --- /dev/null +++ b/declarative/template/src/main/java/com/inrupt/rdf/wrapping/declarative/template/package-info.java @@ -0,0 +1,25 @@ +/* + * Copyright Inrupt Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the + * Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/** + * Examples of wrapper interfaces and the implementations the Processor should generate from them + */ +package com.inrupt.rdf.wrapping.declarative.template; diff --git a/declarative/template/src/test/java/com/inrupt/rdf/wrapping/declarative/template/ExampleGraphTest.java b/declarative/template/src/test/java/com/inrupt/rdf/wrapping/declarative/template/ExampleGraphTest.java new file mode 100644 index 000000000..5578d7613 --- /dev/null +++ b/declarative/template/src/test/java/com/inrupt/rdf/wrapping/declarative/template/ExampleGraphTest.java @@ -0,0 +1,60 @@ +/* + * Copyright Inrupt Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the + * Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +package com.inrupt.rdf.wrapping.declarative.template; + +import com.github.jsonldjava.shaded.com.google.common.base.Charsets; + +import org.apache.commons.io.IOUtils; +import org.apache.jena.query.Dataset; +import org.apache.jena.query.DatasetFactory; +import org.apache.jena.riot.Lang; +import org.apache.jena.riot.RDFDataMgr; +import org.junit.jupiter.api.Test; + +class ExampleGraphTest { + @Test + void test() { + final Dataset dataset = datasetFrom(""" + PREFIX : + + [ + a :C ; + :p1 [ + :p2 "XXX" ; + ] ; + ] . + """); + + final var wrap = ExampleDataset.wrap(dataset); + final var graph = wrap.getGraph(); + final var resource = graph.getResource(); + final var p1 = resource.getP1(); + final var p2 = p1.getP2(); + + System.out.println(p2); + } + + private static Dataset datasetFrom(final String rdf) { + final var dataset = DatasetFactory.create(); + RDFDataMgr.read(dataset, IOUtils.toInputStream(rdf, Charsets.UTF_8), Lang.TRIG); + return dataset; + } +} diff --git a/declarative/test/pom.xml b/declarative/test/pom.xml new file mode 100644 index 000000000..5939a9bbb --- /dev/null +++ b/declarative/test/pom.xml @@ -0,0 +1,49 @@ + + + 4.0.0 + + com.inrupt.rdf + inrupt-rdf-wrapping-declarative + 1.0.1-SNAPSHOT + + + inrupt-rdf-wrapping-declarative-test + Inrupt RDF Wrapping Declarative - Test + + + + + + 1.8 + 1.8 + + + + + com.inrupt.rdf + inrupt-rdf-wrapping-declarative-processor + ${project.version} + provided + true + + + + org.junit.jupiter + junit-jupiter-api + test + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + org.jacoco + jacoco-maven-plugin + + + + diff --git a/declarative/test/src/main/java/com/inrupt/rdf/wrapping/declarative/test/X.java b/declarative/test/src/main/java/com/inrupt/rdf/wrapping/declarative/test/X.java new file mode 100644 index 000000000..cec990e5e --- /dev/null +++ b/declarative/test/src/main/java/com/inrupt/rdf/wrapping/declarative/test/X.java @@ -0,0 +1,35 @@ +/* + * Copyright Inrupt Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the + * Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +package com.inrupt.rdf.wrapping.declarative.test; + +import com.inrupt.rdf.wrapping.declarative.annotations.Dataset; +import com.inrupt.rdf.wrapping.declarative.annotations.Graph; +import com.inrupt.rdf.wrapping.declarative.annotations.Resource; + +@Dataset +public interface X { + @Graph + interface Y { + @Resource + interface Z { + } + } +} diff --git a/pom.xml b/pom.xml index f208c50c2..f6d06805f 100644 --- a/pom.xml +++ b/pom.xml @@ -68,6 +68,7 @@ jena rdf4j reports + declarative