Modified: websites/staging/marmotta/trunk/content/sesame.html
==============================================================================
--- websites/staging/marmotta/trunk/content/sesame.html (original)
+++ websites/staging/marmotta/trunk/content/sesame.html Thu Apr 25 13:05:59 2013
@@ -378,28 +378,37 @@ public interface ConceptFacade extends F
 
 <div class="source">
 <pre>Resource concept = null;
-RepositoryConnection conn = ...
+URI context = null;
+// a valid uri
+String skosURI = &quot;http://&lt;host&gt;/resource/concept1&quot;;
+String contextURI = &quot;http://&lt;host&gt;/context/default&quot;;
+RepositoryConnection conn = ... // obtain a connection
 try {
         conn.begin();
+        // obtain the Facading helper 
         Facading facading = FacadingFactory.createFacading(conn);
-        Literal object = conn.getValueFactory().createLiteral(identifier);
-        URI prop = 
conn.getValueFactory().createURI(Namespace.DCTERMS.identifier);
-        if (object != null &amp;&amp; prop != null) {
-                RepositoryResult&lt;Statement&gt; statements = 
conn.getStatements(null, prop, object, true, context);
-                while (statements.hasNext()) {
-                        Statement stmt = statements.next();
-                        if ( stmt.getObject().equals(object)) {
-                                concept = stmt.getSubject();
-                                break;
-                        }
-                }
-                statements.close();
-        }           
+        // create or use an resource uri of a skos:Concept
+        concept = conn.getValueFactory().createURI(skosURI);
+        context = conn.getValueFactory().createURI(contextURI);
+
+        // create a facade of the skos:Concept by providing the resource, the 
requested type and (optional) the context
+        ConceptFacade facade = facading.createFacade(concept, 
ConceptFacade.class, context);
+        // manage the resource via getter/setter methods
+        fadade.setPrefLabel(&quot;new label&quot;);
+        facade.addAltLabel(&quot;new alternate label&quot;);
+        // 
+        // at this point, the resource 
&quot;http://&lt;host&gt;/resource/concept1&quot; 
+        // - is created if not yet present
+        // - has a triple: rdf:Type 
&lt;http://www.w3.org/2004/02/skos/core#Concept&gt;
+        // - has a triple: skos:prefLabel &quot;new label&quot;
+        // - has a triple: skos:altLabel &quot;new alternate label&quot;
+        //
+        // return the resource uri of the facade, e.g. the concept resource's 
uri;
+        return resource.getDelegate();
 } finally {
         conn.commit();
         conn.close();
 }
-return concept;
 </pre></div></div>
                   </div>
           </div>


Reply via email to