You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by md...@apache.org on 2012/08/31 22:08:04 UTC
svn commit: r1379573 -
/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeTypeManagerImpl.java
Author: mduerig
Date: Fri Aug 31 20:08:04 2012
New Revision: 1379573
URL: http://svn.apache.org/viewvc?rev=1379573&view=rev
Log:
OAK-66: JCR Node Type Management
TODO avoid unbounded recursive auto creation. See 3.7.2.3.5 Chained Auto-creation
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeTypeManagerImpl.java
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeTypeManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeTypeManagerImpl.java?rev=1379573&r1=1379572&r2=1379573&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeTypeManagerImpl.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeTypeManagerImpl.java Fri Aug 31 20:08:04 2012
@@ -40,7 +40,6 @@ import javax.security.auth.Subject;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
-import org.apache.jackrabbit.JcrConstants;
import org.apache.jackrabbit.commons.cnd.CompactNodeTypeDefReader;
import org.apache.jackrabbit.commons.iterator.NodeTypeIteratorAdapter;
import org.apache.jackrabbit.oak.api.CommitFailedException;
@@ -54,6 +53,31 @@ import org.apache.jackrabbit.oak.namepat
import org.apache.jackrabbit.oak.spi.security.principal.AdminPrincipal;
import org.apache.jackrabbit.oak.util.NodeUtil;
+import static org.apache.jackrabbit.JcrConstants.JCR_AUTOCREATED;
+import static org.apache.jackrabbit.JcrConstants.JCR_CHILDNODEDEFINITION;
+import static org.apache.jackrabbit.JcrConstants.JCR_DEFAULTPRIMARYTYPE;
+import static org.apache.jackrabbit.JcrConstants.JCR_DEFAULTVALUES;
+import static org.apache.jackrabbit.JcrConstants.JCR_HASORDERABLECHILDNODES;
+import static org.apache.jackrabbit.JcrConstants.JCR_ISMIXIN;
+import static org.apache.jackrabbit.JcrConstants.JCR_MANDATORY;
+import static org.apache.jackrabbit.JcrConstants.JCR_MULTIPLE;
+import static org.apache.jackrabbit.JcrConstants.JCR_NAME;
+import static org.apache.jackrabbit.JcrConstants.JCR_NODETYPENAME;
+import static org.apache.jackrabbit.JcrConstants.JCR_ONPARENTVERSION;
+import static org.apache.jackrabbit.JcrConstants.JCR_PRIMARYITEMNAME;
+import static org.apache.jackrabbit.JcrConstants.JCR_PRIMARYTYPE;
+import static org.apache.jackrabbit.JcrConstants.JCR_PROPERTYDEFINITION;
+import static org.apache.jackrabbit.JcrConstants.JCR_PROTECTED;
+import static org.apache.jackrabbit.JcrConstants.JCR_REQUIREDPRIMARYTYPES;
+import static org.apache.jackrabbit.JcrConstants.JCR_REQUIREDTYPE;
+import static org.apache.jackrabbit.JcrConstants.JCR_SAMENAMESIBLINGS;
+import static org.apache.jackrabbit.JcrConstants.JCR_SUPERTYPES;
+import static org.apache.jackrabbit.JcrConstants.JCR_SYSTEM;
+import static org.apache.jackrabbit.JcrConstants.JCR_VALUECONSTRAINTS;
+import static org.apache.jackrabbit.JcrConstants.NT_BASE;
+import static org.apache.jackrabbit.JcrConstants.NT_CHILDNODEDEFINITION;
+import static org.apache.jackrabbit.JcrConstants.NT_NODETYPE;
+import static org.apache.jackrabbit.JcrConstants.NT_PROPERTYDEFINITION;
import static org.apache.jackrabbit.oak.plugins.type.NodeTypeConstants.JCR_AVAILABLE_QUERY_OPERATORS;
import static org.apache.jackrabbit.oak.plugins.type.NodeTypeConstants.JCR_IS_ABSTRACT;
import static org.apache.jackrabbit.oak.plugins.type.NodeTypeConstants.JCR_IS_FULLTEXT_SEARCHABLE;
@@ -104,12 +128,12 @@ public class NodeTypeManagerImpl extends
}
for (NodeTypeTemplate template : templates.values()) {
if (!template.isMixin()
- && !JcrConstants.NT_BASE.equals(template.getName())) {
+ && !NT_BASE.equals(template.getName())) {
String[] supertypes =
template.getDeclaredSupertypeNames();
if (supertypes.length == 0) {
template.setDeclaredSuperTypeNames(
- new String[] {JcrConstants.NT_BASE});
+ new String[] {NT_BASE});
} else {
// Check whether we need to add the implicit "nt:base" supertype
boolean needsNtBase = true;
@@ -120,7 +144,7 @@ public class NodeTypeManagerImpl extends
}
if (needsNtBase) {
String[] withBase = new String[supertypes.length + 1];
- withBase[0] = JcrConstants.NT_BASE;
+ withBase[0] = NT_BASE;
System.arraycopy(supertypes, 0, withBase, 1, supertypes.length);
template.setDeclaredSuperTypeNames(withBase);
}
@@ -214,27 +238,27 @@ public class NodeTypeManagerImpl extends
type = types.addChild(oakName);
NodeUtil node = new NodeUtil(type, getCoreValueFactory(), mapper);
- node.setName(JcrConstants.JCR_PRIMARYTYPE, JcrConstants.NT_NODETYPE);
- node.setName(JcrConstants.JCR_NODETYPENAME, jcrName);
- node.setNames(JcrConstants.JCR_SUPERTYPES, ntd.getDeclaredSupertypeNames());
+ node.setName(JCR_PRIMARYTYPE, NT_NODETYPE);
+ node.setName(JCR_NODETYPENAME, jcrName);
+ node.setNames(JCR_SUPERTYPES, ntd.getDeclaredSupertypeNames());
node.setBoolean(JCR_IS_ABSTRACT, ntd.isAbstract());
node.setBoolean(JCR_IS_QUERYABLE, ntd.isQueryable());
- node.setBoolean(JcrConstants.JCR_ISMIXIN, ntd.isMixin());
- node.setBoolean(JcrConstants.JCR_HASORDERABLECHILDNODES, ntd.hasOrderableChildNodes());
+ node.setBoolean(JCR_ISMIXIN, ntd.isMixin());
+ node.setBoolean(JCR_HASORDERABLECHILDNODES, ntd.hasOrderableChildNodes());
String primaryItemName = ntd.getPrimaryItemName();
if (primaryItemName != null) {
- node.setName(JcrConstants.JCR_PRIMARYITEMNAME, primaryItemName);
+ node.setName(JCR_PRIMARYITEMNAME, primaryItemName);
}
int pdn = 1;
for (PropertyDefinition pd : ntd.getDeclaredPropertyDefinitions()) {
- NodeUtil def = node.addChild(JcrConstants.JCR_PROPERTYDEFINITION + pdn++, JcrConstants.NT_PROPERTYDEFINITION);
+ NodeUtil def = node.addChild(JCR_PROPERTYDEFINITION + pdn++, NT_PROPERTYDEFINITION);
internalRegisterPropertyDefinition(def, pd);
}
int ndn = 1;
for (NodeDefinition nd : ntd.getDeclaredChildNodeDefinitions()) {
- NodeUtil def = node.addChild(JcrConstants.JCR_CHILDNODEDEFINITION + ndn++, JcrConstants.NT_CHILDNODEDEFINITION);
+ NodeUtil def = node.addChild(JCR_CHILDNODEDEFINITION + ndn++, NT_CHILDNODEDEFINITION);
internalRegisterNodeDefinition(def, nd);
}
@@ -245,13 +269,15 @@ public class NodeTypeManagerImpl extends
NodeUtil node, ItemDefinition def) {
String name = def.getName();
if (!"*".equals(name)) {
- node.setName(JcrConstants.JCR_NAME, name);
+ node.setName(JCR_NAME, name);
}
- node.setBoolean(JcrConstants.JCR_AUTOCREATED, def.isAutoCreated());
- node.setBoolean(JcrConstants.JCR_MANDATORY, def.isMandatory());
- node.setBoolean(JcrConstants.JCR_PROTECTED, def.isProtected());
+
+ // TODO avoid unbounded recursive auto creation. See 3.7.2.3.5 Chained Auto-creation
+ node.setBoolean(JCR_AUTOCREATED, def.isAutoCreated());
+ node.setBoolean(JCR_MANDATORY, def.isMandatory());
+ node.setBoolean(JCR_PROTECTED, def.isProtected());
node.setString(
- JcrConstants.JCR_ONPARENTVERSION,
+ JCR_ONPARENTVERSION,
OnParentVersionAction.nameFromValue(def.getOnParentVersion()));
}
@@ -260,43 +286,43 @@ public class NodeTypeManagerImpl extends
internalRegisterItemDefinition(node, def);
node.setString(
- JcrConstants.JCR_REQUIREDTYPE,
+ JCR_REQUIREDTYPE,
PropertyType.nameFromValue(def.getRequiredType()));
- node.setBoolean(JcrConstants.JCR_MULTIPLE, def.isMultiple());
+ node.setBoolean(JCR_MULTIPLE, def.isMultiple());
node.setBoolean(JCR_IS_FULLTEXT_SEARCHABLE, def.isFullTextSearchable());
node.setBoolean(JCR_IS_QUERY_ORDERABLE, def.isQueryOrderable());
node.setStrings(JCR_AVAILABLE_QUERY_OPERATORS, def.getAvailableQueryOperators());
String[] constraints = def.getValueConstraints();
if (constraints != null) {
- node.setStrings(JcrConstants.JCR_VALUECONSTRAINTS, constraints);
+ node.setStrings(JCR_VALUECONSTRAINTS, constraints);
}
Value[] values = def.getDefaultValues();
if (values != null) {
- node.setValues(JcrConstants.JCR_DEFAULTVALUES, values);
+ node.setValues(JCR_DEFAULTVALUES, values);
}
}
private static void internalRegisterNodeDefinition(NodeUtil node, NodeDefinition def) {
internalRegisterItemDefinition(node, def);
- node.setBoolean(JcrConstants.JCR_SAMENAMESIBLINGS, def.allowsSameNameSiblings());
+ node.setBoolean(JCR_SAMENAMESIBLINGS, def.allowsSameNameSiblings());
node.setNames(
- JcrConstants.JCR_REQUIREDPRIMARYTYPES,
+ JCR_REQUIREDPRIMARYTYPES,
def.getRequiredPrimaryTypeNames());
String defaultPrimaryType = def.getDefaultPrimaryTypeName();
if (defaultPrimaryType != null) {
- node.setName(JcrConstants.JCR_DEFAULTPRIMARYTYPE, defaultPrimaryType);
+ node.setName(JCR_DEFAULTPRIMARYTYPE, defaultPrimaryType);
}
}
private static Tree getOrCreateNodeTypes(Root root) {
Tree types = root.getTree(NODE_TYPES_PATH);
if (types == null) {
- Tree system = root.getTree('/' + JcrConstants.JCR_SYSTEM);
+ Tree system = root.getTree('/' + JCR_SYSTEM);
if (system == null) {
- system = root.getTree("/").addChild(JcrConstants.JCR_SYSTEM);
+ system = root.getTree("/").addChild(JCR_SYSTEM);
}
types = system.addChild(JCR_NODE_TYPES);
}