incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r600491 - /incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/ScriptableResource.java
Date Mon, 03 Dec 2007 11:33:31 GMT
Author: fmeschbe
Date: Mon Dec  3 03:33:30 2007
New Revision: 600491

URL: http://svn.apache.org/viewvc?rev=600491&view=rev
Log:
SLING-109 Support Resource adapter

Modified:
    incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/ScriptableResource.java

Modified: incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/ScriptableResource.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/ScriptableResource.java?rev=600491&r1=600490&r2=600491&view=diff
==============================================================================
--- incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/ScriptableResource.java
(original)
+++ incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/ScriptableResource.java
Mon Dec  3 03:33:30 2007
@@ -16,8 +16,8 @@
  */
 package org.apache.sling.scripting.javascript;
 
-import org.apache.sling.api.resource.NodeProvider;
-import org.apache.sling.api.resource.ObjectProvider;
+import javax.jcr.Node;
+
 import org.apache.sling.api.resource.Resource;
 import org.mozilla.javascript.Context;
 import org.mozilla.javascript.ScriptableObject;
@@ -44,15 +44,14 @@
     }
 
     public Object jsFunction_getObject() {
-        if (resource instanceof ObjectProvider) {
-            return ((ObjectProvider) resource).getObject();
-        }
-        return Undefined.instance;
+        Object object = resource.adaptTo(Object.class);
+        return (object != null) ? object : Undefined.instance;
     }
 
     public Object jsFunction_getNode() {
-        if (resource instanceof NodeProvider) {
-            return new ScriptableNode(((NodeProvider) resource).getNode());
+        Node node = resource.adaptTo(Node.class);
+        if (node != null) {
+            return new ScriptableNode(node);
         }
         return Undefined.instance;
     }
@@ -81,9 +80,13 @@
     public Object jsFunction_getMetadata() {
         return resource.getResourceMetadata();
     }
-
+    
     public Object jsGet_meta() {
         return resource.getResourceMetadata();
+    }
+
+    public Object jsFunction_adaptTo(Class<?> type) {
+        return resource.adaptTo(type);
     }
 
     @Override



Mime
View raw message