jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1363447 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type: ItemDefinitionImpl.java NodeDefinitionImpl.java NodeTypeImpl.java NodeUtil.java PropertyDefinitionImpl.java
Date Thu, 19 Jul 2012 18:05:53 GMT
Author: jukka
Date: Thu Jul 19 18:05:52 2012
New Revision: 1363447

URL: http://svn.apache.org/viewvc?rev=1363447&view=rev
Log:
OAK-66: JCR Node Type Management

Add a content-based NodeType implementation.
Refactor NodeUtil out of ItemDefinitionImpl.

Added:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeTypeImpl.java
  (with props)
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeUtil.java
  (with props)
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/ItemDefinitionImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeDefinitionImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/PropertyDefinitionImpl.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/ItemDefinitionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/ItemDefinitionImpl.java?rev=1363447&r1=1363446&r2=1363447&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/ItemDefinitionImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/ItemDefinitionImpl.java
Thu Jul 19 18:05:52 2012
@@ -51,64 +51,11 @@ class ItemDefinitionImpl implements Item
 
     private final NodeType type;
 
-    private final NameMapper mapper;
+    protected final NodeUtil node;
 
-    private final Tree tree;
-
-    protected ItemDefinitionImpl(
-            NodeType type, NameMapper mapper, Tree tree) {
+    protected ItemDefinitionImpl(NodeType type, NodeUtil node) {
         this.type = type;
-        this.mapper = mapper;
-        this.tree = tree;
-    }
-
-    protected boolean getBoolean(String name, boolean defaultValue) {
-        PropertyState property = tree.getProperty(name);
-        if (property != null && !property.isArray()) {
-            return property.getValue().getBoolean();
-        } else {
-            return defaultValue;
-        }
-    }
-
-    protected String getString(String name, String defaultValue) {
-        PropertyState property = tree.getProperty(name);
-        if (property != null && !property.isArray()) {
-            return property.getValue().getString();
-        } else {
-            return defaultValue;
-        }
-    }
-
-    protected String[] getStrings(String name, String[] defaultValues) {
-        PropertyState property = tree.getProperty(name);
-        if (property != null) {
-            List<CoreValue> values = property.getValues();
-            String[] strings = new String[values.size()];
-            for (int i = 0; i < strings.length; i++) {
-                strings[i] = values.get(i).getString();
-            }
-            return strings;
-        } else {
-            return defaultValues;
-        }
-    }
-
-    protected String getName(String name, String defaultValue) {
-        PropertyState property = tree.getProperty(name);
-        if (property != null && !property.isArray()) {
-            return mapper.getJcrName(property.getValue().getString());
-        } else {
-            return defaultValue;
-        }
-    }
-
-    protected String[] getNames(String name, String... defaultValues) {
-        String[] strings = getStrings(name, defaultValues);
-        for (int i = 0; i < strings.length; i++) {
-            strings[i] = mapper.getJcrName(strings[i]);
-        }
-        return strings;
+        this.node = node;
     }
 
     @Override
@@ -118,22 +65,22 @@ class ItemDefinitionImpl implements Item
 
     @Override
     public String getName() {
-        return getName("jcr:name", "*");
+        return node.getName("jcr:name", "*");
     }
 
     @Override
     public boolean isAutoCreated() {
-        return getBoolean("jcr:autoCreated", false);
+        return node.getBoolean("jcr:autoCreated");
     }
 
     @Override
     public boolean isMandatory() {
-        return getBoolean("jcr:mandatory", false);
+        return node.getBoolean("jcr:mandatory");
     }
 
     @Override
     public int getOnParentVersion() {
-        String opv = getString("jcr:onParentVersion", ACTIONNAME_COPY);
+        String opv = node.getString("jcr:onParentVersion", ACTIONNAME_COPY);
         if (ACTIONNAME_ABORT.equalsIgnoreCase(opv)) {
             return OnParentVersionAction.ABORT;
         } else if (ACTIONNAME_COMPUTE.equalsIgnoreCase(opv)) {
@@ -151,7 +98,7 @@ class ItemDefinitionImpl implements Item
 
     @Override
     public boolean isProtected() {
-        return getBoolean("jcr:protected", false);
+        return node.getBoolean("jcr:protected");
     }
 
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeDefinitionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeDefinitionImpl.java?rev=1363447&r1=1363446&r2=1363447&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeDefinitionImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeDefinitionImpl.java
Thu Jul 19 18:05:52 2012
@@ -24,8 +24,6 @@ import javax.jcr.nodetype.NodeDefinition
 import javax.jcr.nodetype.NodeType;
 import javax.jcr.nodetype.NodeTypeManager;
 
-import org.apache.jackrabbit.oak.api.Tree;
-import org.apache.jackrabbit.oak.namepath.NameMapper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -46,15 +44,14 @@ class NodeDefinitionImpl extends ItemDef
     private final NodeTypeManager manager;
 
     protected NodeDefinitionImpl(
-            NodeTypeManager manager,
-            NodeType type, NameMapper mapper, Tree tree) {
-        super(type, mapper, tree);
+            NodeTypeManager manager, NodeType type, NodeUtil node) {
+        super(type, node);
         this.manager = manager;
     }
 
     @Override
     public String[] getRequiredPrimaryTypeNames() {
-        return getNames("requiredPrimaryTypes", "nt:base");
+        return node.getNames("requiredPrimaryTypes", "nt:base");
     }
 
     @Override
@@ -74,7 +71,7 @@ class NodeDefinitionImpl extends ItemDef
 
     @Override
     public String getDefaultPrimaryTypeName() {
-        return getName("jcr:defaultPrimaryTypeName", null);
+        return node.getName("jcr:defaultPrimaryTypeName", null);
     }
 
     @Override
@@ -93,7 +90,7 @@ class NodeDefinitionImpl extends ItemDef
 
     @Override
     public boolean allowsSameNameSiblings() {
-        return getBoolean("jcr:sameNameSiblings", false);
+        return node.getBoolean("jcr:sameNameSiblings");
     }
 
 }

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeTypeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeTypeImpl.java?rev=1363447&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeTypeImpl.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeTypeImpl.java
Thu Jul 19 18:05:52 2012
@@ -0,0 +1,339 @@
+/*
+ * 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.jackrabbit.oak.plugins.type;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Queue;
+import java.util.Set;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+import javax.jcr.nodetype.NoSuchNodeTypeException;
+import javax.jcr.nodetype.NodeDefinition;
+import javax.jcr.nodetype.NodeType;
+import javax.jcr.nodetype.NodeTypeIterator;
+import javax.jcr.nodetype.NodeTypeManager;
+import javax.jcr.nodetype.PropertyDefinition;
+
+import org.apache.jackrabbit.commons.iterator.NodeTypeIteratorAdapter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * <pre>
+ * [nt:nodeType]
+ * - jcr:nodeTypeName (NAME) protected mandatory
+ * - jcr:supertypes (NAME) protected multiple
+ * - jcr:isAbstract (BOOLEAN) protected mandatory
+ * - jcr:isQueryable (BOOLEAN) protected mandatory
+ * - jcr:isMixin (BOOLEAN) protected mandatory
+ * - jcr:hasOrderableChildNodes (BOOLEAN) protected mandatory
+ * - jcr:primaryItemName (NAME) protected
+ * + jcr:propertyDefinition (nt:propertyDefinition) = nt:propertyDefinition protected sns
+ * + jcr:childNodeDefinition (nt:childNodeDefinition) = nt:childNodeDefinition protected
sns
+ * </pre>
+ */
+class NodeTypeImpl implements NodeType {
+
+    private static final Logger log =
+            LoggerFactory.getLogger(NodeTypeImpl.class);
+
+    private final NodeTypeManager manager;
+
+    private final NodeUtil node;
+
+    public NodeTypeImpl(NodeTypeManager manager, NodeUtil node) {
+        this.manager = manager;
+        this.node = node;
+    }
+
+    @Override
+    public String getName() {
+        String name = node.getName("jcr:nodeTypeName");
+        if (name == null) {
+            name = node.getName();
+        }
+        return name;
+    }
+
+    @Override
+    public String[] getDeclaredSupertypeNames() {
+        return node.getNames("jcr:supertypes");
+    }
+
+    @Override
+    public boolean isAbstract() {
+        return node.getBoolean("jcr:isAbstract");
+    }
+
+    @Override
+    public boolean isMixin() {
+        return node.getBoolean("jcr:isMixin");
+    }
+
+    @Override
+    public boolean hasOrderableChildNodes() {
+        return node.getBoolean("jcr:hasOrderableChildNodes");
+    }
+
+    @Override
+    public boolean isQueryable() {
+        return node.getBoolean("jcr:isQueryable");
+    }
+
+    @Override
+    public String getPrimaryItemName() {
+        return node.getName("jcr:primaryItemName");
+    }
+
+    @Override
+    public PropertyDefinition[] getDeclaredPropertyDefinitions() {
+        NodeUtil[] nodes = node.getNodes("jcr:propertyDefinition");
+        PropertyDefinition[] definitions = new PropertyDefinition[nodes.length];
+        for (int i = 0; i < nodes.length; i++) {
+            definitions[i] = new PropertyDefinitionImpl(this, nodes[i]);
+        }
+        return definitions;
+    }
+
+    @Override
+    public NodeDefinition[] getDeclaredChildNodeDefinitions() {
+        NodeUtil[] nodes = node.getNodes("jcr:childNodeDefinition");
+        NodeDefinition[] definitions = new NodeDefinition[nodes.length];
+        for (int i = 0; i < nodes.length; i++) {
+            definitions[i] = new NodeDefinitionImpl(manager, this, nodes[i]);
+        }
+        return definitions;
+    }
+
+    @Override
+    public NodeType[] getSupertypes() {
+        try {
+            Collection<NodeType> types = new ArrayList<NodeType>();
+            Set<String> added = new HashSet<String>();
+            Queue<String> queue = new LinkedList<String>(Arrays.asList(
+                    getDeclaredSupertypeNames()));
+            while (!queue.isEmpty()) {
+                String name = queue.remove();
+                if (added.add(name)) {
+                    NodeType type = manager.getNodeType(name);
+                    types.add(type);
+                    queue.addAll(Arrays.asList(type.getDeclaredSupertypeNames()));
+                }
+            }
+            return types.toArray(new NodeType[types.size()]);
+        } catch (RepositoryException e) {
+            throw new IllegalStateException("Inconsistent node type: " + this, e);
+        }
+    }
+
+    @Override
+    public NodeType[] getDeclaredSupertypes() {
+        String[] names = getDeclaredSupertypeNames();
+        List<NodeType> types = new ArrayList<NodeType>(names.length);
+        for (int i = 0; i < names.length; i++) {
+            try {
+                types.add(manager.getNodeType(names[i]));
+            } catch (RepositoryException e) {
+                log.warn("Unable to access declared supertype "
+                        + names[i] + " of " + getName(), e);
+            }
+        }
+        return types.toArray(new NodeType[types.size()]);
+    }
+
+    @Override
+    public NodeTypeIterator getSubtypes() {
+        Collection<NodeType> types = new ArrayList<NodeType>();
+        try {
+            NodeTypeIterator iterator = manager.getAllNodeTypes();
+            while (iterator.hasNext()) {
+                NodeType type = iterator.nextNodeType();
+                if (type.isNodeType(getName()) && !isNodeType(type.getName())) {
+                    types.add(type);
+                }
+            }
+        } catch (RepositoryException e) {
+            log.warn("Unable to access subtypes of " + getName(), e);
+        }
+        return new NodeTypeIteratorAdapter(types);
+    }
+
+    @Override
+    public NodeTypeIterator getDeclaredSubtypes() {
+        Collection<NodeType> types = new ArrayList<NodeType>();
+        try {
+            NodeTypeIterator iterator = manager.getAllNodeTypes();
+            while (iterator.hasNext()) {
+                NodeType type = iterator.nextNodeType();
+                String name = type.getName();
+                if (type.isNodeType(getName()) && !isNodeType(name)) {
+                    List<String> declaredSuperTypeNames = Arrays.asList(type.getDeclaredSupertypeNames());
+                    if (declaredSuperTypeNames.contains(name)) {
+                        types.add(type);
+                    }
+                }
+            }
+        } catch (RepositoryException e) {
+            log.warn("Unable to access declared subtypes of " + getName(), e);
+        }
+        return new NodeTypeIteratorAdapter(types);
+    }
+
+    @Override
+    public boolean isNodeType(String nodeTypeName) {
+        if (nodeTypeName.equals(getName())) {
+            return true;
+        }
+
+        for (NodeType type : getDeclaredSupertypes()) {
+            if (type.isNodeType(nodeTypeName)) {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
+    @Override
+    public PropertyDefinition[] getPropertyDefinitions() {
+        Collection<PropertyDefinition> definitions =
+                new ArrayList<PropertyDefinition>();
+        for (NodeType type : getSupertypes()) {
+            definitions.addAll(Arrays.asList(
+                    type.getDeclaredPropertyDefinitions()));
+        }
+        definitions.addAll(Arrays.asList(getDeclaredPropertyDefinitions()));
+        return definitions.toArray(new PropertyDefinition[definitions.size()]);
+    }
+
+    @Override
+    public NodeDefinition[] getChildNodeDefinitions() {
+        Collection<NodeDefinition> definitions =
+                new ArrayList<NodeDefinition>();
+        for (NodeType type : getSupertypes()) {
+            definitions.addAll(Arrays.asList(
+                    type.getDeclaredChildNodeDefinitions()));
+        }
+        definitions.addAll(Arrays.asList(getDeclaredChildNodeDefinitions()));
+        return definitions.toArray(new NodeDefinition[definitions.size()]);
+    }
+
+    @Override
+    public boolean canSetProperty(String propertyName, Value value) {
+        for (PropertyDefinition definition : getPropertyDefinitions()) {
+            String name = definition.getName();
+            if ((propertyName.equals(name) && !definition.isProtected())
+                    || "*".equals(name)) {
+                if (!definition.isMultiple()) {
+                    // TODO: Check value type, constraints, etc.
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+
+    @Override
+    public boolean canSetProperty(String propertyName, Value[] values) {
+        for (PropertyDefinition definition : getPropertyDefinitions()) {
+            String name = definition.getName();
+            if ((propertyName.equals(name) && !definition.isProtected())
+                    || "*".equals(name)) {
+                if (definition.isMultiple()) {
+                    // TODO: Check value type, constraints, etc.
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+
+    @Override
+    public boolean canAddChildNode(String childNodeName) {
+        for (NodeDefinition definition : getChildNodeDefinitions()) {
+            String name = definition.getName();
+            if ((childNodeName.equals(name) && !definition.isProtected())
+                    || "*".equals(name)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    @Override
+    public boolean canAddChildNode(String childNodeName, String nodeTypeName) {
+        NodeType type;
+        try {
+            type = manager.getNodeType(nodeTypeName);
+        } catch (NoSuchNodeTypeException e) {
+            return false;
+        } catch (RepositoryException e) {
+            log.warn("Unable to access node type " + nodeTypeName, e);
+            return false;
+        }
+        for (NodeDefinition definition : getChildNodeDefinitions()) {
+            String name = definition.getName();
+            if ((childNodeName.equals(name) && !definition.isProtected())
+                    || "*".equals(name)) {
+                for (String required : definition.getRequiredPrimaryTypeNames()) {
+                    if (type.isNodeType(required)) {
+                        return true;
+                    }
+                }
+            }
+        }
+        return false;
+    }
+
+    @Override
+    public boolean canRemoveItem(String itemName) {
+        return canRemoveNode(itemName) || canRemoveProperty(itemName);
+    }
+
+    @Override
+    public boolean canRemoveNode(String nodeName) {
+        for (PropertyDefinition definition : getPropertyDefinitions()) {
+            String name = definition.getName();
+            if (nodeName.equals(name)) {
+                if (definition.isMandatory() || definition.isProtected()) {
+                    return false;
+                }
+            }
+        }
+        return true;
+    }
+
+    @Override
+    public boolean canRemoveProperty(String propertyName) {
+        for (PropertyDefinition definition : getPropertyDefinitions()) {
+            String name = definition.getName();
+            if (propertyName.equals(name)) {
+                if (definition.isMandatory() || definition.isProtected()) {
+                    return false;
+                }
+            }
+        }
+        return true;
+    }
+
+}

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeTypeImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeUtil.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeUtil.java?rev=1363447&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeUtil.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeUtil.java
Thu Jul 19 18:05:52 2012
@@ -0,0 +1,109 @@
+/*
+ * 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.jackrabbit.oak.plugins.type;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.jackrabbit.oak.api.CoreValue;
+import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.api.Tree;
+import org.apache.jackrabbit.oak.namepath.NameMapper;
+
+/**
+ * Utility class for accessing typed content of a node.
+ */
+class NodeUtil {
+
+    private final NameMapper mapper;
+
+    private final Tree tree;
+
+    public NodeUtil(NameMapper mapper, Tree tree) {
+        this.mapper = mapper;
+        this.tree = tree;
+    }
+
+    public String getName() {
+        return mapper.getJcrName(tree.getName());
+    }
+
+    public boolean getBoolean(String name) {
+        PropertyState property = tree.getProperty(name);
+        return property != null && !property.isArray()
+                && property.getValue().getBoolean();
+    }
+
+    public String getString(String name, String defaultValue) {
+        PropertyState property = tree.getProperty(name);
+        if (property != null && !property.isArray()) {
+            return property.getValue().getString();
+        } else {
+            return defaultValue;
+        }
+    }
+
+    public String[] getStrings(String name) {
+        PropertyState property = tree.getProperty(name);
+        if (property == null) {
+            return null;
+        }
+
+        List<CoreValue> values = property.getValues();
+        String[] strings = new String[values.size()];
+        for (int i = 0; i < strings.length; i++) {
+            strings[i] = values.get(i).getString();
+        }
+        return strings;
+    }
+
+    public String getName(String name) {
+        return getName(name, null);
+    }
+
+    public String getName(String name, String defaultValue) {
+        PropertyState property = tree.getProperty(name);
+        if (property != null && !property.isArray()) {
+            return mapper.getJcrName(property.getValue().getString());
+        } else {
+            return defaultValue;
+        }
+    }
+
+    public String[] getNames(String name, String... defaultValues) {
+        String[] strings = getStrings(name);
+        if (strings == null) {
+            strings = defaultValues;
+        }
+        for (int i = 0; i < strings.length; i++) {
+            strings[i] = mapper.getJcrName(strings[i]);
+        }
+        return strings;
+    }
+
+    public NodeUtil[] getNodes(String name) {
+        List<NodeUtil> nodes = new ArrayList<NodeUtil>();
+        Tree child = tree.getChild(name);
+        if (child != null) {
+            for (Tree tree : child.getChildren()) {
+                nodes.add(new NodeUtil(mapper, tree));
+            }
+        }
+        return nodes.toArray(new NodeUtil[nodes.size()]);
+    }
+
+}

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeUtil.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/PropertyDefinitionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/PropertyDefinitionImpl.java?rev=1363447&r1=1363446&r2=1363447&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/PropertyDefinitionImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/PropertyDefinitionImpl.java
Thu Jul 19 18:05:52 2012
@@ -24,9 +24,6 @@ import javax.jcr.nodetype.NodeType;
 import javax.jcr.nodetype.PropertyDefinition;
 import javax.jcr.query.qom.QueryObjectModelConstants;
 
-import org.apache.jackrabbit.oak.api.Tree;
-import org.apache.jackrabbit.oak.namepath.NameMapper;
-
 /**
  * <pre>
  * [nt:propertyDefinition]
@@ -46,22 +43,13 @@ import org.apache.jackrabbit.oak.namepat
 class PropertyDefinitionImpl extends ItemDefinitionImpl
         implements PropertyDefinition {
 
-    private static String[] DEFAULT_QOPS = new String[] {
-        QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO,
-        QueryObjectModelConstants.JCR_OPERATOR_NOT_EQUAL_TO,
-        QueryObjectModelConstants.JCR_OPERATOR_GREATER_THAN,
-        QueryObjectModelConstants.JCR_OPERATOR_GREATER_THAN_OR_EQUAL_TO,
-        QueryObjectModelConstants.JCR_OPERATOR_LESS_THAN,
-        QueryObjectModelConstants.JCR_OPERATOR_LESS_THAN_OR_EQUAL_TO,
-        QueryObjectModelConstants.JCR_OPERATOR_LIKE };
-
-    public PropertyDefinitionImpl(NodeType type, NameMapper mapper, Tree tree) {
-        super(type, mapper, tree);
+    public PropertyDefinitionImpl(NodeType type, NodeUtil node) {
+        super(type, node);
     }
 
     @Override
     public int getRequiredType() {
-        String type = getString("jcr:requiredType", TYPENAME_UNDEFINED);
+        String type = node.getString("jcr:requiredType", TYPENAME_UNDEFINED);
         if (PropertyType.TYPENAME_BINARY.equalsIgnoreCase(type)) {
             return PropertyType.BINARY;
         } else if (PropertyType.TYPENAME_BOOLEAN.equalsIgnoreCase(type)) {
@@ -93,16 +81,8 @@ class PropertyDefinitionImpl extends Ite
 
     @Override
     public String[] getValueConstraints() {
-        String[] constraints = getStrings("jcr:valueConstraints", null);
-        if (constraints != null) {
-            int type = getRequiredType();
-            if (type == PropertyType.NAME || type == PropertyType.PATH) {
-                for (int i = 0; i < constraints.length; i++) {
-                    // TODO: namespace mapping
-                }
-            }
-        }
-        return constraints;
+        // TODO: namespace mapping?
+        return node.getStrings("jcr:valueConstraints");
     }
 
     @Override
@@ -112,22 +92,33 @@ class PropertyDefinitionImpl extends Ite
 
     @Override
     public boolean isMultiple() {
-        return getBoolean("jcr:multiple", false);
+        return node.getBoolean("jcr:multiple");
     }
 
     @Override
     public String[] getAvailableQueryOperators() {
-        return getStrings("jcr:availableQueryOperators", DEFAULT_QOPS.clone());
+        String[] ops = node.getStrings("jcr:availableQueryOperators");
+        if (ops == null) {
+            ops = new String[] {
+                    QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO,
+                    QueryObjectModelConstants.JCR_OPERATOR_NOT_EQUAL_TO,
+                    QueryObjectModelConstants.JCR_OPERATOR_GREATER_THAN,
+                    QueryObjectModelConstants.JCR_OPERATOR_GREATER_THAN_OR_EQUAL_TO,
+                    QueryObjectModelConstants.JCR_OPERATOR_LESS_THAN,
+                    QueryObjectModelConstants.JCR_OPERATOR_LESS_THAN_OR_EQUAL_TO,
+                    QueryObjectModelConstants.JCR_OPERATOR_LIKE };
+        }
+        return ops;
     }
 
     @Override
     public boolean isFullTextSearchable() {
-        return getBoolean("jcr:isFullTextSearchable", true);
+        return node.getBoolean("jcr:isFullTextSearchable");
     }
 
     @Override
     public boolean isQueryOrderable() {
-        return getBoolean("jcr:isQueryOrderable", true);
+        return node.getBoolean("jcr:isQueryOrderable");
     }
 
 }



Mime
View raw message