Author: reto
Date: Mon May 10 06:43:23 2010
New Revision: 942669

URL: http://svn.apache.org/viewvc?rev=942669&view=rev
Log:
CLEREZZA-211: simplifies as-method usage

Modified:
    
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/RichGraphNode.scala
    
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/RichGraphNodeTest.scala

Modified: 
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/RichGraphNode.scala
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/RichGraphNode.scala?rev=942669&r1=942668&r2=942669&view=diff
==============================================================================
--- 
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/RichGraphNode.scala
 (original)
+++ 
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/RichGraphNode.scala
 Mon May 10 06:43:23 2010
@@ -22,6 +22,7 @@ import rdf.utils.GraphNode
 import rdf.core.{UriRef, Resource, Literal, TypedLiteral, LiteralFactory}
 import java.util.Iterator
 import _root_.scala.collection.jcl.Conversions
+import _root_.scala.reflect.Manifest
 
 class RichGraphNode(node: GraphNode) extends GraphNode(node.getNode, 
node.getGraph) {
     /**
@@ -39,22 +40,22 @@ class RichGraphNode(node: GraphNode) ext
     }
 
     /**
-    * returns a List with the elements of the rdf:List represented by this node
-    */
+        * returns a List with the elements of the rdf:List represented by this 
node
+        */
     def !! = (for (listElem <- Conversions.convertList(node.asList)) yield {
-       new RichGraphNode(new GraphNode(listElem, node.getGraph))
-    }).toList
+                       new RichGraphNode(new GraphNode(listElem, 
node.getGraph))
+               }).toList
 
     /**
-    * returns the specified index from the rdf:List represenetd by this node
-    */
+        * returns the specified index from the rdf:List represenetd by this 
node
+        */
     def %!!(index: Int) = new RichGraphNode(new 
GraphNode(node.asList.get(index),
                                                           node.getGraph))
 
        /**
-       * returns the lexical form of literals, the unicode-string for UriRef 
for
-       * BNodes the value returned by toString
-       */
+        * returns the lexical form of literals, the unicode-string for UriRef 
for
+        * BNodes the value returned by toString
+        */
        def * = {
                val wrappedNode = node.getNode();
                if (wrappedNode.isInstanceOf[Literal]) {
@@ -68,10 +69,17 @@ class RichGraphNode(node: GraphNode) ext
                }
        }
 
-        def as[T](clazz : Class[T]) : T= {
-                LiteralFactory.getInstance().createObject(clazz,
-                        node.getNode().asInstanceOf[TypedLiteral])
-        }
+       private def asClass[T](clazz : Class[T]) : T= {
+               LiteralFactory.getInstance().createObject(clazz,
+                                                                               
                  node.getNode().asInstanceOf[TypedLiteral])
+       }
+
+       /**
+        * returns the literal represenetd by this node as instance of the 
spcified type
+        */
+       def as[T](implicit m: Manifest[T]): T = {
+               asClass(m.erasure.asInstanceOf[Class[T]])
+       }
 
     /**
      * Operator syntax shortcut to get the <code>Resource</code> wrapped by 
this

Modified: 
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/RichGraphNodeTest.scala
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/RichGraphNodeTest.scala?rev=942669&r1=942668&r2=942669&view=diff
==============================================================================
--- 
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/RichGraphNodeTest.scala
 (original)
+++ 
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/RichGraphNodeTest.scala
 Mon May 10 06:43:23 2010
@@ -117,7 +117,7 @@ class RichGraphNodeTest {
                val dateLiteral = new TypedLiteralImpl("2009-01-01T01:33:58Z",
                                        new 
UriRef("http://www.w3.org/2001/XMLSchema#dateTime";))
                val node = new GraphNode(dateLiteral, new SimpleMGraph())
-               Assert.assertNotNull(node.as(classOf[java.util.Date]))
+               Assert.assertNotNull(node.as[java.util.Date])
        }
 
 }


Reply via email to