Author: fmeschbe
Date: Mon Jan 21 06:10:31 2008
New Revision: 613895

URL: http://svn.apache.org/viewvc?rev=613895&view=rev
Log:
SLING-154 Added more scriptable mappings:
   - Completed getters for ScriptableNode
   - Created ScriptableProperty to map properties
   - Added getters for child nodes (node.children) and
     properties (node.properties) to ScriptableNode

Added:
    
incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/wrapper/ScriptableItemMap.java
    
incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/wrapper/ScriptableProperty.java
Modified:
    
incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/RhinoJavaScriptEngineFactory.java
    
incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/helper/SlingWrapFactory.java
    
incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/wrapper/ScriptableNode.java

Modified: 
incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/RhinoJavaScriptEngineFactory.java
URL: 
http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/RhinoJavaScriptEngineFactory.java?rev=613895&r1=613894&r2=613895&view=diff
==============================================================================
--- 
incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/RhinoJavaScriptEngineFactory.java
 (original)
+++ 
incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/RhinoJavaScriptEngineFactory.java
 Mon Jan 21 06:10:31 2008
@@ -22,11 +22,13 @@
 
 import org.apache.sling.scripting.api.AbstractScriptEngineFactory;
 import org.apache.sling.scripting.javascript.helper.SlingContextFactory;
+import org.apache.sling.scripting.javascript.helper.SlingWrapFactory;
+import org.apache.sling.scripting.javascript.wrapper.ScriptableItemMap;
 import org.apache.sling.scripting.javascript.wrapper.ScriptableNode;
 import org.apache.sling.scripting.javascript.wrapper.ScriptablePrintWriter;
+import org.apache.sling.scripting.javascript.wrapper.ScriptableProperty;
 import org.apache.sling.scripting.javascript.wrapper.ScriptableResource;
 import org.mozilla.javascript.Context;
-import org.mozilla.javascript.ContextFactory;
 import org.mozilla.javascript.Scriptable;
 import org.mozilla.javascript.ScriptableObject;
 
@@ -39,15 +41,20 @@
 
     public final static String ESP_SCRIPT_EXTENSION = "esp";
 
+    private static final Class<?>[] WRAPPER_CLASSES = {
+        ScriptableResource.class, ScriptableNode.class,
+        ScriptableProperty.class, ScriptableItemMap.class,
+        ScriptablePrintWriter.class };
+
     private final String languageVersion;
 
     private Scriptable rootScope;
 
     public RhinoJavaScriptEngineFactory() {
-        
+
         // initialize the Rhino Context Factory
         SlingContextFactory.setup();
-        
+
         Context cx = Context.enter();
         setEngineName(getEngineName() + " (" + cx.getImplementationVersion()
             + ")");
@@ -78,12 +85,17 @@
             final Context rhinoContext = Context.enter();
             rootScope = rhinoContext.initStandardObjects();
 
-            try {
-                ScriptableObject.defineClass(rootScope, 
ScriptableResource.class);
-                ScriptableObject.defineClass(rootScope, ScriptableNode.class);
-                ScriptableObject.defineClass(rootScope, 
ScriptablePrintWriter.class);
-            } catch (Throwable t) {
-                // TODO: log
+            for (Class<?> clazz : WRAPPER_CLASSES) {
+                try {
+                    ScriptableObject.defineClass(rootScope, clazz);
+
+                    Scriptable hostObject = (Scriptable) clazz.newInstance();
+                    SlingWrapFactory.INSTANCE.registerWrapper(clazz,
+                        hostObject.getClassName());
+
+                } catch (Throwable t) {
+                    // TODO: log
+                }
             }
         }
 

Modified: 
incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/helper/SlingWrapFactory.java
URL: 
http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/helper/SlingWrapFactory.java?rev=613895&r1=613894&r2=613895&view=diff
==============================================================================
--- 
incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/helper/SlingWrapFactory.java
 (original)
+++ 
incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/helper/SlingWrapFactory.java
 Mon Jan 21 06:10:31 2008
@@ -18,14 +18,9 @@
  */
 package org.apache.sling.scripting.javascript.helper;
 
-import java.io.PrintWriter;
+import java.util.HashMap;
+import java.util.Map;
 
-import javax.jcr.Node;
-
-import org.apache.sling.api.resource.Resource;
-import org.apache.sling.scripting.javascript.wrapper.ScriptableNode;
-import org.apache.sling.scripting.javascript.wrapper.ScriptablePrintWriter;
-import org.apache.sling.scripting.javascript.wrapper.ScriptableResource;
 import org.mozilla.javascript.Context;
 import org.mozilla.javascript.Scriptable;
 import org.mozilla.javascript.WrapFactory;
@@ -34,10 +29,12 @@
 
 public class SlingWrapFactory extends WrapFactory {
 
+    public static final SlingWrapFactory INSTANCE = new SlingWrapFactory();
+
     /** default log */
     private final Logger log = LoggerFactory.getLogger(getClass());
 
-    public static final WrapFactory INSTANCE = new SlingWrapFactory();
+    private Map<Class<?>, String> wrappers = new HashMap<Class<?>, String>();
 
     /**
      * @param cx the current Context for this thread
@@ -52,14 +49,14 @@
             Object javaObject, Class staticType) {
 
         try {
-            if (javaObject instanceof Resource) {
-                return cx.newObject(scope, ScriptableResource.CLASSNAME,
-                    new Object[] { javaObject });
-            } else if (javaObject instanceof Node) {
-                return cx.newObject(scope, ScriptableNode.CLASSNAME,
-                    new Object[] { javaObject });
-            } else if (javaObject instanceof PrintWriter) {
-                return cx.newObject(scope, ScriptablePrintWriter.CLASSNAME,
+            String hostObjectName = getHostObjectName(staticType);
+
+            if (hostObjectName == null) {
+                hostObjectName = getHostObjectName(javaObject.getClass());
+            }
+
+            if (hostObjectName != null) {
+                return cx.newObject(scope, hostObjectName,
                     new Object[] { javaObject });
             }
         } catch (Exception e) {
@@ -69,4 +66,28 @@
         return super.wrapAsJavaObject(cx, scope, javaObject, staticType);
     }
 
+    private String getHostObjectName(Class<?> javaClass) {
+        String hostObjectName = wrappers.get(javaClass);
+        if (hostObjectName == null) {
+            hostObjectName = getHostObjectName(javaClass.getSuperclass());
+
+            if (hostObjectName == null) {
+                Class<?>[] javaInterfaces = javaClass.getInterfaces();
+                for (int i = 0; i < javaInterfaces.length
+                    && hostObjectName == null; i++) {
+                    hostObjectName = getHostObjectName(javaClass);
+                }
+            }
+        }
+
+        return hostObjectName;
+    }
+
+    public void registerWrapper(Class<?> javaClass, String hostObjectName) {
+        wrappers.put(javaClass, hostObjectName);
+    }
+
+    public void unregisterWrapper(Class<?> javaClass) {
+        wrappers.remove(javaClass);
+    }
 }

Added: 
incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/wrapper/ScriptableItemMap.java
URL: 
http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/wrapper/ScriptableItemMap.java?rev=613895&view=auto
==============================================================================
--- 
incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/wrapper/ScriptableItemMap.java
 (added)
+++ 
incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/wrapper/ScriptableItemMap.java
 Mon Jan 21 06:10:31 2008
@@ -0,0 +1,117 @@
+/*
+ * 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.
+ */
+package org.apache.sling.scripting.javascript.wrapper;
+
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import javax.jcr.Item;
+import javax.jcr.RepositoryException;
+
+import org.mozilla.javascript.ScriptRuntime;
+import org.mozilla.javascript.Scriptable;
+import org.mozilla.javascript.ScriptableObject;
+import org.mozilla.javascript.Undefined;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ScriptableItemMap extends ScriptableObject {
+
+    public static final String CLASSNAME = "ItemMap";
+
+    /** default log */
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    private Map<String, Item> items = new LinkedHashMap<String, Item>();
+
+    public ScriptableItemMap() {
+        // prevent modification, seal the object
+        sealObject();
+    }
+
+    public ScriptableItemMap(Iterator<?> itemIterator) {
+        while (itemIterator.hasNext()) {
+            Item item = (Item) itemIterator.next();
+            try {
+                items.put(item.getName(), item);
+            } catch (RepositoryException re) {
+                log.error("ScriptableItemMap<init>: Cannot get name of item "
+                    + item, re);
+            }
+        }
+
+        // prevent modification, seal the object
+        sealObject();
+    }
+
+    @Override
+    public String getClassName() {
+        return CLASSNAME;
+    }
+
+    @Override
+    public boolean has(int index, Scriptable start) {
+        return getItem(index) != null;
+    }
+
+    @Override
+    public boolean has(String name, Scriptable start) {
+        return items.containsKey(name);
+    }
+
+    @Override
+    public Object get(int index, Scriptable start) {
+        Item item = getItem(index);
+        if (item != null) {
+            return ScriptRuntime.toObject(this, item);
+        }
+
+        return Undefined.instance;
+    }
+
+    @Override
+    public Object get(String name, Scriptable start) {
+        Item item = items.get(name);
+        if (item != null) {
+            return ScriptRuntime.toObject(this, item);
+        }
+
+        return Undefined.instance;
+    }
+
+    @Override
+    public Object[] getIds() {
+        return items.keySet().toArray();
+    }
+
+    private Item getItem(int index) {
+        if (index < 0 || index >= items.size()) {
+            return null;
+        }
+
+        Iterator<Item> itemsIter = items.values().iterator();
+        while (itemsIter.hasNext() && index > 0) {
+            itemsIter.next();
+            index--;
+        }
+
+        return itemsIter.hasNext() ? itemsIter.next() : null;
+    }
+}

Modified: 
incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/wrapper/ScriptableNode.java
URL: 
http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/wrapper/ScriptableNode.java?rev=613895&r1=613894&r2=613895&view=diff
==============================================================================
--- 
incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/wrapper/ScriptableNode.java
 (original)
+++ 
incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/wrapper/ScriptableNode.java
 Mon Jan 21 06:10:31 2008
@@ -16,160 +16,224 @@
  */
 package org.apache.sling.scripting.javascript.wrapper;
 
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
+import java.util.Collections;
+import java.util.Iterator;
 
 import javax.jcr.Node;
-import javax.jcr.NodeIterator;
-import javax.jcr.Property;
-import javax.jcr.PropertyIterator;
-import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
-import javax.jcr.Value;
-import javax.jcr.ValueFormatException;
+import javax.jcr.nodetype.NodeType;
 
-import org.mozilla.javascript.NativeArray;
 import org.mozilla.javascript.ScriptRuntime;
-import org.mozilla.javascript.Scriptable;
 import org.mozilla.javascript.ScriptableObject;
 import org.mozilla.javascript.Undefined;
 import org.mozilla.javascript.Wrapper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 /**
- * A wrapper for JCR nodes that exposes all properties and child nodes
- * as properties of a Javascript object.
+ * A wrapper for JCR nodes that exposes all properties and child nodes as
+ * properties of a Javascript object.
  */
 public class ScriptableNode extends ScriptableObject implements Wrapper {
 
     public static final String CLASSNAME = "Node";
 
-       private Node node;
+    /** default log */
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    private Node node;
 
-       public ScriptableNode() {
-       }
+    public ScriptableNode() {
+    }
 
-       public ScriptableNode(Node item) {
-               super();
-               this.node = item;
-       }
+    public ScriptableNode(Node item) {
+        super();
+        this.node = item;
+    }
 
     public void jsConstructor(Object res) {
         this.node = (Node) res;
     }
 
-       public String getClassName() {
-               return CLASSNAME;
-       }
-
-       /**
-        * Gets the value of a (Javascript) property. If there is a single 
single-value
-        * JCR property of this node, return its string value. If there are 
multiple properties
-        * of the same name or child nodes of the same name, return an array.
-        */
-       @Override
-       public Object get(String name, Scriptable start) {
-               List<Scriptable> items = new ArrayList<Scriptable>();
-
-               // add all matching nodes
-               try {
-                       NodeIterator it = node.getNodes(name);
-                       while (it.hasNext()) {
-                               items.add(new ScriptableNode(it.nextNode()));
-                       }
-               } catch (RepositoryException e) {}
-
-               // add all matching properies
-               try {
-                       PropertyIterator it = node.getProperties(name);
-                       while (it.hasNext()) {
-                               Property prop = it.nextProperty();
-                               int type = prop.getType();
-                               if (prop.getDefinition().isMultiple()) {
-                                       Value[] values = prop.getValues();
-                                       for (int i=0;i<values.length;i++) {
-                                               items.add(wrap(values[i], 
type));
-                                       }
-                               } else {
-                                       if (type==PropertyType.REFERENCE) {
-                                               items.add(new 
ScriptableNode(prop.getNode()));
-                                       } else {
-                                               items.add(wrap(prop.getValue(), 
type));
-                                       }
-                               }
-                       }
-               } catch (RepositoryException e) {}
-
-               if (items.size()==0) {
-                       return Undefined.instance;
-               } else if (items.size()==1) {
-                       return items.iterator().next();
-               } else {
-                       //TODO: add write support
-                       NativeArray result = new NativeArray(items.toArray());
-               ScriptRuntime.setObjectProtoAndParent(result, this);
-               return result;
-               }
-       }
-
-       private Scriptable wrap(Value value, int type) throws 
ValueFormatException, IllegalStateException, RepositoryException {
-           Object valObj;
-               if (type==PropertyType.BINARY) {
-                       valObj = value.getBoolean();
-               } else if (type==PropertyType.DOUBLE) {
-                   valObj = value.getDouble();
-               } else if (type==PropertyType.LONG) {
-                   valObj = value.getLong();
-               } else {
-                   valObj = value.getString();
-               }
-
-               return ScriptRuntime.toObject(this, valObj);
-       }
-
-       @Override
-       public Object[] getIds() {
-               Collection<String> ids = new ArrayList<String>();
-               try {
-                       PropertyIterator pit = node.getProperties();
-                       while (pit.hasNext()) {
-                               ids.add(pit.nextProperty().getName());
-                       }
-               } catch (RepositoryException e) {
-                       //do nothing, just do not list properties
-               }
-               try {
-                       NodeIterator nit = node.getNodes();
-                       while (nit.hasNext()) {
-                               ids.add(nit.nextNode().getName());
-                       }
-               } catch (RepositoryException e) {
-                       //do nothing, just do not list child nodes
-               }
-               return ids.toArray();
-       }
-
-       @Override
-       public boolean has(String name, Scriptable start) {
-               try {
-                       return node.hasProperty(name) || node.hasNode(name);
-               } catch (RepositoryException e) {
-                       return false;
-               }
-       }
-
-       @Override
-       public Object getDefaultValue(Class typeHint) {
-               try {
-                       return node.getPath();
-               } catch (RepositoryException e) {
-                       return null;
-               }
-       }
-
-       //---------- Wrapper interface 
--------------------------------------------
-       
-       // returns the wrapped node
-       public Object unwrap() {
-           return node;
-       }
+    public String getClassName() {
+        return CLASSNAME;
+    }
+
+    public ScriptableItemMap jsGet_children() {
+        try {
+            return new ScriptableItemMap(node.getNodes());
+        } catch (RepositoryException re) {
+            log.warn("Cannot get children of " + jsGet_path(), re);
+            return new ScriptableItemMap();
+        }
+    }
+
+    public ScriptableItemMap jsGet_properties() {
+        try {
+            return new ScriptableItemMap(node.getProperties());
+        } catch (RepositoryException re) {
+            log.warn("Cannot get children of " + jsGet_path(), re);
+            return new ScriptableItemMap();
+        }
+    }
+
+    public Object jsGet_primaryItem() {
+        try {
+            return ScriptRuntime.toObject(this, node.getPrimaryItem());
+        } catch (RepositoryException re) {
+            return Undefined.instance;
+        }
+    }
+
+    public String jsGet_UUID() {
+        try {
+            return node.getUUID();
+        } catch (RepositoryException re) {
+            return "";
+        }
+    }
+
+    public int jsGet_index() {
+        try {
+            return node.getIndex();
+        } catch (RepositoryException re) {
+            return 1;
+        }
+    }
+
+    public Iterator<?> jsGet_references() {
+        try {
+            return node.getReferences();
+        } catch (RepositoryException re) {
+            return Collections.EMPTY_LIST.iterator();
+        }
+    }
+
+    public Object jsGet_primaryNodeType() {
+        try {
+            return node.getPrimaryNodeType();
+        } catch (RepositoryException re) {
+            return Undefined.instance;
+        }
+    }
+
+    public NodeType[] jsGet_mixinNodeTypes() {
+        try {
+            return node.getMixinNodeTypes();
+        } catch (RepositoryException re) {
+            return new NodeType[0];
+        }
+    }
+
+    public Object jsGet_definition() {
+        try {
+            return node.getDefinition();
+        } catch (RepositoryException re) {
+            return Undefined.instance;
+        }
+    }
+
+    public boolean jsGet_checkedOut() {
+        try {
+            return node.isCheckedOut();
+        } catch (RepositoryException re) {
+            return false;
+        }
+    }
+
+    public Object jsGet_versionHistory() {
+        try {
+            return node.getVersionHistory();
+        } catch (RepositoryException re) {
+            return Undefined.instance;
+        }
+    }
+
+    public Object jsGet_baseVersion() {
+        try {
+            return node.getBaseVersion();
+        } catch (RepositoryException re) {
+            return Undefined.instance;
+        }
+    }
+
+    public Object jsGet_lock() {
+        try {
+            return node.getLock();
+        } catch (RepositoryException re) {
+            return Undefined.instance;
+        }
+    }
+
+    public boolean jsGet_locked() {
+        try {
+            return node.isLocked();
+        } catch (RepositoryException re) {
+            return false;
+        }
+    }
+
+    public Object jsGet_session() {
+        try {
+            return node.getSession();
+        } catch (RepositoryException re) {
+            return Undefined.instance;
+        }
+    }
+
+    public String jsGet_path() {
+        try {
+            return node.getPath();
+        } catch (RepositoryException e) {
+            return node.toString();
+        }
+    }
+
+    public String jsGet_name() {
+        try {
+            return node.getName();
+        } catch (RepositoryException e) {
+            return node.toString();
+        }
+    }
+
+    public Object jsGet_parent() {
+        try {
+            return ScriptRuntime.toObject(this, node.getParent());
+        } catch (RepositoryException re) {
+            return Undefined.instance;
+        }
+    }
+
+    public int jsGet_depth() {
+        try {
+            return node.getDepth();
+        } catch (RepositoryException re) {
+            return -1;
+        }
+    }
+
+    public boolean jsGet_new() {
+        return node.isNew();
+    }
+
+    public boolean jsGet_modified() {
+        return node.isModified();
+    }
+
+    @Override
+    public Object getDefaultValue(Class typeHint) {
+        try {
+            return node.getPath();
+        } catch (RepositoryException e) {
+            return super.getDefaultValue(typeHint);
+        }
+    }
+
+    // ---------- Wrapper interface 
--------------------------------------------
+
+    // returns the wrapped node
+    public Object unwrap() {
+        return node;
+    }
 }

Added: 
incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/wrapper/ScriptableProperty.java
URL: 
http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/wrapper/ScriptableProperty.java?rev=613895&view=auto
==============================================================================
--- 
incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/wrapper/ScriptableProperty.java
 (added)
+++ 
incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/wrapper/ScriptableProperty.java
 Mon Jan 21 06:10:31 2008
@@ -0,0 +1,225 @@
+/*
+ * 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.
+ */
+package org.apache.sling.scripting.javascript.wrapper;
+
+import java.io.InputStream;
+import java.util.Calendar;
+
+import javax.jcr.Node;
+import javax.jcr.Property;
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+import javax.jcr.ValueFormatException;
+import javax.jcr.nodetype.PropertyDefinition;
+
+import org.mozilla.javascript.ScriptRuntime;
+import org.mozilla.javascript.ScriptableObject;
+import org.mozilla.javascript.Undefined;
+import org.mozilla.javascript.Wrapper;
+
+public class ScriptableProperty extends ScriptableObject implements Wrapper {
+
+    public static final String CLASSNAME = "Property";
+    
+    private Property property;
+    
+    public ScriptableProperty() {
+    }
+    
+    public ScriptableProperty(Property property) {
+        this.property = property;
+    }
+    
+    public void jsConstructor(Object res) {
+        this.property = (Property) res;
+    }
+
+    @Override
+    public String getClassName() {
+        return CLASSNAME;
+    }
+
+    public Object jsGet_value() {
+        try {
+            return property.getValue();
+        } catch (RepositoryException re) {
+            return Undefined.instance;
+        }
+    }
+
+    public Object jsGet_values() {
+        try {
+            return property.getValues();
+        } catch (RepositoryException re) {
+            return Undefined.instance;
+        }
+    }
+
+    public Object jsGet_string() {
+        try {
+            return property.getString();
+        } catch (RepositoryException re) {
+            return Undefined.instance;
+        }
+    }
+
+    public Object jsGet_stream() {
+        try {
+            return property.getStream();
+        } catch (RepositoryException re) {
+            return Undefined.instance;
+        }
+    }
+
+    public Object jsGet_long() {
+        try {
+            return property.getLong();
+        } catch (RepositoryException re) {
+            return Undefined.instance;
+        }
+    }
+
+    public Object jsGet_double() {
+        try {
+            return property.getDouble();
+        } catch (RepositoryException re) {
+            return Undefined.instance;
+        }
+    }
+
+    public Object jsGet_date() {
+        try {
+            return property.getDate();
+        } catch (RepositoryException re) {
+            return Undefined.instance;
+        }
+    }
+
+    public Object jsGet_boolean() {
+        try {
+            return property.getBoolean();
+        } catch (RepositoryException re) {
+            return Undefined.instance;
+        }
+    }
+
+    public Object jsGet_node() {
+        try {
+            return ScriptRuntime.toObject(this, property.getValue());
+        } catch (RepositoryException re) {
+            return Undefined.instance;
+        }
+    }
+
+    public Object jsGet_length() {
+        try {
+            return property.getLength();
+        } catch (RepositoryException re) {
+            return Undefined.instance;
+        }
+    }
+
+    public long[] jsGet_lengths() {
+        try {
+            return property.getLengths();
+        } catch (RepositoryException re) {
+            return new long[0];
+        }
+    }
+
+    public Object jsGet_definition() {
+        try {
+            return property.getDefinition();
+        } catch (RepositoryException re) {
+            return Undefined.instance;
+        }
+    }
+
+    public int getType() {
+        try {
+            return property.getType();
+        } catch (RepositoryException re) {
+            return PropertyType.UNDEFINED;
+        }
+    }
+
+    public Object jsGet_session() {
+        try {
+            return property.getSession();
+        } catch (RepositoryException re) {
+            return Undefined.instance;
+        }
+    }
+
+    public String jsGet_path() {
+        try {
+            return property.getPath();
+        } catch (RepositoryException e) {
+            return property.toString();
+        }
+    }
+
+    public String jsGet_name() {
+        try {
+            return property.getName();
+        } catch (RepositoryException e) {
+            return property.toString();
+        }
+    }
+
+    public Object jsGet_parent() {
+        try {
+            return ScriptRuntime.toObject(this, property.getParent());
+        } catch (RepositoryException re) {
+            return Undefined.instance;
+        }
+    }
+
+    public int jsGet_depth() {
+        try {
+            return property.getDepth();
+        } catch (RepositoryException re) {
+            return -1;
+        }
+    }
+
+    public boolean jsGet_new() {
+        return property.isNew();
+    }
+
+    public boolean jsGet_modified() {
+        return property.isModified();
+    }
+
+    @Override
+    public Object getDefaultValue(Class typeHint) {
+        try {
+            return property.getPath();
+        } catch (RepositoryException e) {
+            return super.getDefaultValue(typeHint);
+        }
+    }
+
+    //---------- Wrapper interface --------------------------------------------
+    
+    public Object unwrap() {
+        return property;
+    }
+}


Reply via email to