| <!-- |
| /*************************************************************************************************************************** |
| * 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. |
| ***************************************************************************************************************************/ |
| --> |
| |
| Root Property |
| |
| <p> |
| For all RDF languages, the POJO objects get broken down into simple triplets. |
| Unfortunately, for tree-structured data like the POJOs shown above, this causes the root node of the tree |
| to become lost. |
| There is no easy way to identify that <c>person/1</c> is the root node in our tree once in triplet |
| form, and in some cases it's impossible. |
| </p> |
| <p> |
| By default, the {@link oaj.jena.RdfParser} class handles this by scanning all the nodes and |
| identifying the nodes without incoming references. |
| However, this is inefficient, especially for large models. |
| And in cases where the root node is referenced by another node in the model by URL, it's not possible to |
| locate the root at all. |
| </p> |
| <p> |
| To resolve this issue, the property {@link oaj.jena.RdfSerializer#RDF_addRootProperty} |
| was introduced. |
| When enabled, this adds a special <c>root</c> attribute to the root node to make it easy to locate |
| by the parser. |
| </p> |
| <p> |
| To enable, set the <jsf>RDF_addRootProperty</jsf> property to <jk>true</jk> on the serializer: |
| </p> |
| <p class='bpcode w800'> |
| <jc>// Create a new serializer.</jc> |
| RdfSerializer s = RdfSerializer.<jsm>create</jsm>() |
| .xmlabbrev() |
| .set(RdfProperties.<jsf>RDF_rdfxml_tab</jsf>, 3), |
| .addRootProperty(<jk>true</jk>) |
| .build(); |
| </p> |
| <p> |
| Now when we rerun the sample code, we'll see the added <c>root</c> attribute on the root resource. |
| </p> |
| <p class='bpcode w800'> |
| <xt><rdf:RDF</xt> |
| <xa>xmlns:rdf</xa>=<xs>"http://www.w3.org/1999/02/22-rdf-syntax-ns#"</xs> |
| <xa>xmlns:j</xa>=<xs>"http://www.apache.org/juneau/"</xs> |
| <xa>xmlns:jp</xa>=<xs>"http://www.apache.org/juneaubp/"</xs> |
| <xa>xmlns:per</xa>=<xs>"http://www.apache.org/person/"</xs> |
| <xa>xmlns:mail</xa>=<xs>"http://www.apache.org/mail/"</xs> |
| <xa>xmlns:addr</xa>=<xs>"http://www.apache.org/address/"</xs><xt>></xt> |
| <xt><rdf:Description <xa>rdf:about</xa>=<xs>"http://sample/addressBook/person/1"</xs>></xt> |
| <b><xt><j:root></xt>true<xt></j:root></xt></b> |
| <xt><per:addressBookUri</xt> <xa>rdf:resource</xa>=<xs>"http://sample/addressBook"</xs><xt>/></xt> |
| <xt><per:id></xt>1<xt></per:id></xt> |
| <xt><per:name></xt>John Smith<xt></per:name></xt> |
| <xt><per:addresses></xt> |
| <xt><rdf:Seq></xt> |
| <xt><rdf:li></xt> |
| <xt><rdf:Description <xa>rdf:about</xa>=<xs>"http://sample/addressBook/address/1"</xs>></xt> |
| <xt><addr:personUri <xa>rdf:resource</xa>=<xs>"http://sample/addressBook/person/1"</xs>/></xt> |
| <xt><addr:id></xt>1<xt></addr:id></xt> |
| <xt><mail:street></xt>100 Main Street<xt></mail:street></xt> |
| <xt><mail:city></xt>Anywhereville<xt></mail:city></xt> |
| <xt><mail:state></xt>NY<xt></mail:state></xt> |
| <xt><mail:zip></xt>12345<xt></mail:zip></xt> |
| <xt><addr:isCurrent></xt>true<xt></addr:isCurrent></xt> |
| <xt></rdf:Description></xt> |
| <xt></rdf:li></xt> |
| <xt></rdf:Seq></xt> |
| <xt></per:addresses></xt> |
| <xt></rdf:Description></xt> |
| <xt></rdf:RDF></xt> |
| </p> |