jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1363412 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type: ItemDefinitionImpl.java NodeDefinitionImpl.java PropertyDefinitionImpl.java
Date Thu, 19 Jul 2012 16:20:25 GMT
Author: jukka
Date: Thu Jul 19 16:20:24 2012
New Revision: 1363412

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

Add ItemDefinition classes based on in-content type information

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

Added: 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=1363412&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/ItemDefinitionImpl.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/ItemDefinitionImpl.java
Thu Jul 19 16:20:24 2012
@@ -0,0 +1,157 @@
+/*
+ * 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 static javax.jcr.version.OnParentVersionAction.ACTIONNAME_ABORT;
+import static javax.jcr.version.OnParentVersionAction.ACTIONNAME_COMPUTE;
+import static javax.jcr.version.OnParentVersionAction.ACTIONNAME_COPY;
+import static javax.jcr.version.OnParentVersionAction.ACTIONNAME_IGNORE;
+import static javax.jcr.version.OnParentVersionAction.ACTIONNAME_INITIALIZE;
+import static javax.jcr.version.OnParentVersionAction.ACTIONNAME_VERSION;
+
+import java.util.List;
+
+import javax.jcr.nodetype.ItemDefinition;
+import javax.jcr.nodetype.NodeType;
+import javax.jcr.version.OnParentVersionAction;
+
+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;
+
+/**
+ * <pre>
+ * [nt:{propertyDefinition,childNodeDefinition}]
+ * - jcr:name (NAME) protected 
+ * - jcr:autoCreated (BOOLEAN) protected mandatory
+ * - jcr:mandatory (BOOLEAN) protected mandatory
+ * - jcr:onParentVersion (STRING) protected mandatory
+ *     < 'COPY', 'VERSION', 'INITIALIZE', 'COMPUTE', 'IGNORE', 'ABORT'
+ * - jcr:protected (BOOLEAN) protected mandatory
+ *   ...
+ * </pre>
+ */
+
+class ItemDefinitionImpl implements ItemDefinition {
+
+    private final NodeType type;
+
+    private final NameMapper mapper;
+
+    private final Tree tree;
+
+    protected ItemDefinitionImpl(
+            NodeType type, NameMapper mapper, Tree tree) {
+        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;
+    }
+
+    @Override
+    public NodeType getDeclaringNodeType() {
+        return type;
+    }
+
+    @Override
+    public String getName() {
+        return getName("jcr:name", "*");
+    }
+
+    @Override
+    public boolean isAutoCreated() {
+        return getBoolean("jcr:autoCreated", false);
+    }
+
+    @Override
+    public boolean isMandatory() {
+        return getBoolean("jcr:mandatory", false);
+    }
+
+    @Override
+    public int getOnParentVersion() {
+        String opv = getString("jcr:onParentVersion", ACTIONNAME_COPY);
+        if (ACTIONNAME_ABORT.equalsIgnoreCase(opv)) {
+            return OnParentVersionAction.ABORT;
+        } else if (ACTIONNAME_COMPUTE.equalsIgnoreCase(opv)) {
+            return OnParentVersionAction.COMPUTE;
+        } else if (ACTIONNAME_IGNORE.equalsIgnoreCase(opv)) {
+            return OnParentVersionAction.IGNORE;
+        } else if (ACTIONNAME_INITIALIZE.equalsIgnoreCase(opv)) {
+            return OnParentVersionAction.INITIALIZE;
+        } else if (ACTIONNAME_VERSION.equalsIgnoreCase(opv)) {
+            return OnParentVersionAction.VERSION;
+        } else {
+            return OnParentVersionAction.COPY;
+        }
+    }
+
+    @Override
+    public boolean isProtected() {
+        return getBoolean("jcr:protected", false);
+    }
+
+}

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

Added: 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=1363412&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeDefinitionImpl.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeDefinitionImpl.java
Thu Jul 19 16:20:24 2012
@@ -0,0 +1,99 @@
+/*
+ * 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 javax.jcr.RepositoryException;
+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;
+
+/**
+ * <pre>
+ * [nt:childNodeDefinition]
+ *   ...
+ * - jcr:requiredPrimaryTypes (NAME) = 'nt:base' protected mandatory multiple
+ * - jcr:defaultPrimaryType (NAME) protected
+ * - jcr:sameNameSiblings (BOOLEAN) protected mandatory
+ * </pre>
+ */
+class NodeDefinitionImpl extends ItemDefinitionImpl implements NodeDefinition {
+
+    private static final Logger log =
+            LoggerFactory.getLogger(NodeDefinitionImpl.class);
+
+    private final NodeTypeManager manager;
+
+    protected NodeDefinitionImpl(
+            NodeTypeManager manager,
+            NodeType type, NameMapper mapper, Tree tree) {
+        super(type, mapper, tree);
+        this.manager = manager;
+    }
+
+    @Override
+    public String[] getRequiredPrimaryTypeNames() {
+        return getNames("requiredPrimaryTypes", "nt:base");
+    }
+
+    @Override
+    public NodeType[] getRequiredPrimaryTypes() {
+        String[] names = getRequiredPrimaryTypeNames();
+        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 required primary type "
+                        + names[i] + " of node " + getName(), e);
+            }
+        }
+        return types.toArray(new NodeType[types.size()]);
+    }
+
+    @Override
+    public String getDefaultPrimaryTypeName() {
+        return getName("jcr:defaultPrimaryTypeName", null);
+    }
+
+    @Override
+    public NodeType getDefaultPrimaryType() {
+        String name = getDefaultPrimaryTypeName();
+        if (name != null) {
+            try {
+                return manager.getNodeType(name);
+            } catch (RepositoryException e) {
+                log.warn("Unable to access default primary type "
+                        + name + " of node " + getName(), e);
+            }
+        }
+        return null;
+    }
+
+    @Override
+    public boolean allowsSameNameSiblings() {
+        return getBoolean("jcr:sameNameSiblings", false);
+    }
+
+}

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

Added: 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=1363412&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/PropertyDefinitionImpl.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/PropertyDefinitionImpl.java
Thu Jul 19 16:20:24 2012
@@ -0,0 +1,133 @@
+/*
+ * 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 static javax.jcr.PropertyType.TYPENAME_UNDEFINED;
+
+import javax.jcr.PropertyType;
+import javax.jcr.Value;
+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]
+ *   ...
+ * - jcr:requiredType (STRING) protected mandatory
+ *   < 'STRING', 'URI', 'BINARY', 'LONG', 'DOUBLE',
+ *     'DECIMAL', 'BOOLEAN', 'DATE', 'NAME', 'PATH',
+ *     'REFERENCE', 'WEAKREFERENCE', 'UNDEFINED'
+ * - jcr:valueConstraints (STRING) protected multiple
+ * - jcr:defaultValues (UNDEFINED) protected multiple
+ * - jcr:multiple (BOOLEAN) protected mandatory
+ * - jcr:availableQueryOperators (NAME) protected mandatory multiple
+ * - jcr:isFullTextSearchable (BOOLEAN) protected mandatory
+ * - jcr:isQueryOrderable (BOOLEAN) protected mandatory
+ * </pre>
+ */
+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);
+    }
+
+    @Override
+    public int getRequiredType() {
+        String type = getString("jcr:requiredType", TYPENAME_UNDEFINED);
+        if (PropertyType.TYPENAME_BINARY.equalsIgnoreCase(type)) {
+            return PropertyType.BINARY;
+        } else if (PropertyType.TYPENAME_BOOLEAN.equalsIgnoreCase(type)) {
+            return PropertyType.BOOLEAN;
+        } else if (PropertyType.TYPENAME_DATE.equalsIgnoreCase(type)) {
+            return PropertyType.DATE;
+        } else if (PropertyType.TYPENAME_DECIMAL.equalsIgnoreCase(type)) {
+            return PropertyType.DECIMAL;
+        } else if (PropertyType.TYPENAME_DOUBLE.equalsIgnoreCase(type)) {
+            return PropertyType.DOUBLE;
+        } else if (PropertyType.TYPENAME_LONG.equalsIgnoreCase(type)) {
+            return PropertyType.LONG;
+        } else if (PropertyType.TYPENAME_NAME.equalsIgnoreCase(type)) {
+            return PropertyType.NAME;
+        } else if (PropertyType.TYPENAME_PATH.equalsIgnoreCase(type)) {
+            return PropertyType.PATH;
+        } else if (PropertyType.TYPENAME_REFERENCE.equalsIgnoreCase(type)) {
+            return PropertyType.REFERENCE;
+        } else if (PropertyType.TYPENAME_STRING.equalsIgnoreCase(type)) {
+            return PropertyType.STRING;
+        } else if (PropertyType.TYPENAME_URI.equalsIgnoreCase(type)) {
+            return PropertyType.URI;
+        } else if (PropertyType.TYPENAME_WEAKREFERENCE.equalsIgnoreCase(type)) {
+            return PropertyType.WEAKREFERENCE;
+        } else {
+            return PropertyType.UNDEFINED;
+        }
+    }
+
+    @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;
+    }
+
+    @Override
+    public Value[] getDefaultValues() {
+        return new Value[0]; // TODO
+    }
+
+    @Override
+    public boolean isMultiple() {
+        return getBoolean("jcr:multiple", false);
+    }
+
+    @Override
+    public String[] getAvailableQueryOperators() {
+        return getStrings("jcr:availableQueryOperators", DEFAULT_QOPS.clone());
+    }
+
+    @Override
+    public boolean isFullTextSearchable() {
+        return getBoolean("jcr:isFullTextSearchable", true);
+    }
+
+    @Override
+    public boolean isQueryOrderable() {
+        return getBoolean("jcr:isQueryOrderable", true);
+    }
+
+}

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



Mime
View raw message