juneau-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] jamesbognar closed pull request #34: Adding more samples on rdf serializer and adding clear comments
Date Thu, 13 Dec 2018 13:21:16 GMT
jamesbognar closed pull request #34: Adding more samples on rdf serializer and adding clear
comments
URL: https://github.com/apache/juneau/pull/34
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/juneau-examples/juneau-examples-core/src/main/java/org/apache/juneau/examples/core/rdf/RdfComplexExample.java
b/juneau-examples/juneau-examples-core/src/main/java/org/apache/juneau/examples/core/rdf/RdfComplexExample.java
index 05b5a4692..551520039 100644
--- a/juneau-examples/juneau-examples-core/src/main/java/org/apache/juneau/examples/core/rdf/RdfComplexExample.java
+++ b/juneau-examples/juneau-examples-core/src/main/java/org/apache/juneau/examples/core/rdf/RdfComplexExample.java
@@ -14,6 +14,7 @@
 
 import org.apache.juneau.examples.core.pojo.*;
 import org.apache.juneau.jena.RdfSerializer;
+import org.apache.juneau.jena.RdfXmlAbbrevSerializer;
 import org.apache.juneau.jena.RdfXmlSerializer;
 
 import java.util.ArrayList;
@@ -46,8 +47,58 @@ public static void main(String[] args) throws Exception {
         PojoComplex pojoc = new PojoComplex("pojo", new Pojo("1.0", "name0"), values);
 
         // this creates an RDF serializer with the default XML structure
+        /**Produces
+         * <rdf:RDF
+         * xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+         * xmlns:j="http://www.apache.org/juneau/"
+         * xmlns:jp="http://www.apache.org/juneaubp/" >
+         * <rdf:Description rdf:nodeID="A0">
+         * <jp:name>name1</jp:name>
+         * <jp:id>1.1</jp:id>
+         * </rdf:Description>
+         * <rdf:Description rdf:nodeID="A1">
+         * <jp:innerPojo rdf:nodeID="A2"/>
+         * <jp:values rdf:nodeID="A3"/>
+         * <jp:id>pojo</jp:id>
+         * </rdf:Description>
+         * <rdf:Description rdf:nodeID="A3">
+         * <jp:setOne rdf:nodeID="A4"/>
+         * <jp:setTwo rdf:nodeID="A5"/>
+         * </rdf:Description>
+         * <rdf:Description rdf:nodeID="A6">
+         * <jp:name>name2</jp:name>
+         * <jp:id>1.1</jp:id>
+         * </rdf:Description>
+         * <rdf:Description rdf:nodeID="A2">
+         * <jp:name>name0</jp:name>
+         * <jp:id>1.0</jp:id>
+         * </rdf:Description>
+         * <rdf:Description rdf:nodeID="A7">
+         * <jp:name>name2</jp:name>
+         * <jp:id>1.2</jp:id>
+         * </rdf:Description>
+         * <rdf:Description rdf:nodeID="A4">
+         * <rdf:_2 rdf:nodeID="A6"/>
+         * <rdf:_1 rdf:nodeID="A0"/>
+         * <rdf:type rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#Seq"/>
+         * </rdf:Description>
+         * <rdf:Description rdf:nodeID="A5">
+         * <rdf:_2 rdf:nodeID="A7"/>
+         * <rdf:_1 rdf:nodeID="A8"/>
+         * <rdf:type rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#Seq"/>
+         * </rdf:Description>
+         * <rdf:Description rdf:nodeID="A8">
+         * <jp:name>name1</jp:name>
+         * <jp:id>1.2</jp:id>
+         * </rdf:Description>
+         * </rdf:RDF>
+         */
         RdfSerializer rdfSerializer = RdfXmlSerializer.DEFAULT;
         // This will show the final output from the bean
         System.out.println(rdfSerializer.serialize(pojoc));
+
+        //Usage of RdfXmlAbbrevSerializer.
+        String rdfXml = RdfXmlAbbrevSerializer.DEFAULT.serialize(pojoc);
+        System.out.println(rdfXml);
     }
 }
diff --git a/juneau-examples/juneau-examples-core/src/main/java/org/apache/juneau/examples/core/rdf/RdfExample.java
b/juneau-examples/juneau-examples-core/src/main/java/org/apache/juneau/examples/core/rdf/RdfExample.java
index 2838cf1c1..9090a39f5 100644
--- a/juneau-examples/juneau-examples-core/src/main/java/org/apache/juneau/examples/core/rdf/RdfExample.java
+++ b/juneau-examples/juneau-examples-core/src/main/java/org/apache/juneau/examples/core/rdf/RdfExample.java
@@ -35,8 +35,82 @@
 	public static void main(String[] args) throws Exception {
 		Pojo pojo = new Pojo("rdf","This is RDF format.");
 		// this creates an RDF serializer with the default XML structure
+		/**Produces
+		 * <rdf:RDF
+		 * xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+		 * xmlns:j="http://www.apache.org/juneau/"
+		 * xmlns:jp="http://www.apache.org/juneaubp/" >
+		 * <rdf:Description rdf:nodeID="A0">
+		 * <jp:name>This is RDF format.</jp:name>
+		 * <jp:id>rdf</jp:id>
+		 * </rdf:Description>
+		 * </rdf:RDF>
+		 */
 		RdfSerializer rdfSerializer = RdfXmlSerializer.DEFAULT;
 		// This will show the final output from the bean
 		System.out.println(rdfSerializer.serialize(pojo));
+
+		/**Produces
+		 * <rdf:RDF
+		 * xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+		 * xmlns:j="http://www.apache.org/juneau/"
+		 * xmlns:jp="http://www.apache.org/juneaubp/">
+		 * <rdf:Description>
+		 * <jp:name>This is RDF format.</jp:name>
+		 * <jp:id>rdf</jp:id>
+		 * </rdf:Description>
+		 * </rdf:RDF>
+		 */
+		String rdfXml = RdfXmlAbbrevSerializer.DEFAULT.serialize(pojo);
+		System.out.println(rdfXml);
+
+		// Deserialize back to Pojo instance type.
+		Pojo xmlAbParsed = RdfXmlParser.DEFAULT.parse(rdfXml,Pojo.class);
+		assert xmlAbParsed.getClass().equals(pojo.getClass());
+		assert xmlAbParsed.getId().equals(pojo.getId());
+
+		/**Produces
+		 * @prefix jp:      <http://www.apache.org/juneaubp/> .
+		 * @prefix j:       <http://www.apache.org/juneau/> .
+		 *
+		 * []    jp:id   "rdf" ;
+		 * jp:name "This is RDF format." .
+		 */
+		String rdfN3 = N3Serializer.DEFAULT.serialize(pojo);
+		System.out.println(rdfN3);
+
+		// Deserialize back to Pojo instance type.
+		Pojo n3parsed = N3Parser.DEFAULT.parse(rdfN3,Pojo.class);
+		assert n3parsed.getClass().equals(pojo.getClass());
+		assert n3parsed.getId().equals(pojo.getId());
+
+		/**Produces
+		 *_:A5ecded4fX3aX167a62fdefeX3aXX2dX7ffc <http://www.apache.org/juneaubp/name> "This
is RDF format." .
+		 *_:A5ecded4fX3aX167a62fdefeX3aXX2dX7ffc <http://www.apache.org/juneaubp/id> "rdf"
.
+		 */
+		String rdfNTriple = NTripleSerializer.DEFAULT.serialize(pojo);
+		System.out.println(rdfNTriple);
+
+		// Deserialize back to Pojo instance type.
+		Pojo nTripleparsed = NTripleParser.DEFAULT.parse(rdfNTriple,Pojo.class);
+		assert nTripleparsed.getClass().equals(pojo.getClass());
+		assert nTripleparsed.getId().equals(pojo.getId());
+
+		/**
+		 * @prefix jp:      <http://www.apache.org/juneaubp/> .
+		 * @prefix j:       <http://www.apache.org/juneau/> .
+		 *
+		 * []    jp:id   "rdf" ;
+		 * jp:name "This is RDF format." .
+		 */
+		String rdfTurtle = TurtleSerializer.DEFAULT.serialize(pojo);
+		System.out.println(rdfTurtle);
+
+		// Deserialize back to Pojo instance type.
+		Pojo turtleparsed = TurtleParser.DEFAULT.parse(rdfTurtle,Pojo.class);
+		assert turtleparsed.getClass().equals(pojo.getClass());
+		assert turtleparsed.getId().equals(pojo.getId());
+
+		
 	}
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message