You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by st...@apache.org on 2007/11/21 17:51:35 UTC
svn commit: r597142 -
/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/
Author: stefan
Date: Wed Nov 21 08:51:34 2007
New Revision: 597142
URL: http://svn.apache.org/viewvc?rev=597142&view=rev
Log:
JCR-1104: JSR 283 support
work in (slow) progress...
Added:
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/AbstractItemDefinitionTemplate.java
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeDefinitionTemplateImpl.java
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/PropertyDefinitionTemplateImpl.java
Modified:
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/ItemDefinitionImpl.java
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeDefinitionImpl.java
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeImpl.java
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeManagerImpl.java
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeTemplateImpl.java
Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/AbstractItemDefinitionTemplate.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/AbstractItemDefinitionTemplate.java?rev=597142&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/AbstractItemDefinitionTemplate.java (added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/AbstractItemDefinitionTemplate.java Wed Nov 21 08:51:34 2007
@@ -0,0 +1,143 @@
+/*
+ * 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.core.nodetype;
+
+import javax.jcr.Value;
+import javax.jcr.nodetype.ItemDefinition;
+import javax.jcr.nodetype.NodeType;
+
+/**
+ * <code>AbstractItemDefinitionTemplate</code> serves as base class for
+ * <code>NodeDefinitionTemplateImpl</code> and
+ * <code>PropertyDefinitionTemplateImpl</code>.
+ */
+abstract class AbstractItemDefinitionTemplate implements ItemDefinition {
+
+ private String name;
+ private boolean autoCreated;
+ private boolean mandatory;
+ private int opv;
+ private boolean protectedStatus;
+
+ /**
+ * Package private constructor
+ */
+ AbstractItemDefinitionTemplate() {
+ }
+
+ /**
+ * Package private constructor
+ *
+ * @param def
+ */
+ AbstractItemDefinitionTemplate(ItemDefinition def) {
+ name = def.getName();
+ autoCreated = def.isAutoCreated();
+ mandatory = def.isMandatory();
+ opv = def.getOnParentVersion();
+ protectedStatus = def.isProtected();
+ }
+
+ //-----------------------------------------------< ItemDefinition setters >
+ /**
+ * Sets the name of the child item.
+ *
+ * @param name a <code>String</code>.
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * Sets the auto-create status of the child item.
+ *
+ * @param autoCreated a <code>boolean</code>.
+ */
+ public void setAutoCreated(boolean autoCreated) {
+ this.autoCreated = autoCreated;
+ }
+
+ /**
+ * Sets the mandatory status of the child item.
+ *
+ * @param mandatory a <code>boolean</code>.
+ */
+ public void setMandatory(boolean mandatory) {
+ this.mandatory = mandatory;
+ }
+
+ /**
+ * Sets the on-parent-version status of the child item.
+ *
+ * @param opv an <code>int</code> constant member of <code>OnParentVersionAction</code>.
+ */
+ public void setOnParentVersion(int opv) {
+ this.opv = opv;
+ }
+
+ /**
+ * Sets the protected status of the child item.
+ *
+ * @param protectedStatus a <code>boolean</code>.
+ */
+ public void setProtected(boolean protectedStatus) {
+ this.protectedStatus = protectedStatus;
+ }
+
+ //-------------------------------------------------------< ItemDefinition >
+ /**
+ * {@inheritDoc}
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public NodeType getDeclaringNodeType() {
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isAutoCreated() {
+ return autoCreated;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isMandatory() {
+ return mandatory;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getOnParentVersion() {
+ return opv;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isProtected() {
+ return protectedStatus;
+ }
+}
\ No newline at end of file
Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/ItemDefinitionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/ItemDefinitionImpl.java?rev=597142&r1=597141&r2=597142&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/ItemDefinitionImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/ItemDefinitionImpl.java Wed Nov 21 08:51:34 2007
@@ -98,6 +98,9 @@
* {@inheritDoc}
*/
public NodeType getDeclaringNodeType() {
+ if (ntMgr == null) {
+ return null;
+ }
try {
return ntMgr.getNodeType(itemDef.getDeclaringNodeType());
} catch (NoSuchNodeTypeException e) {
Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeDefinitionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeDefinitionImpl.java?rev=597142&r1=597141&r2=597142&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeDefinitionImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeDefinitionImpl.java Wed Nov 21 08:51:34 2007
@@ -140,10 +140,9 @@
}
return names;
}
- } catch (NamespaceException npde) {
+ } catch (NamespaceException e) {
// should never get here
- log.error("encountered unregistered namespace in node type name",
- npde);
+ log.error("encountered unregistered namespace in node type name", e);
return new String[0];
}
}
@@ -172,10 +171,9 @@
try {
return resolver.getJCRName(ntName);
- } catch (NamespaceException npde) {
+ } catch (NamespaceException e) {
// should never get here
- log.error("encountered unregistered namespace in node type name",
- npde);
+ log.error("encountered unregistered namespace in node type name", e);
// not correct, but an acceptable fallback
return ntName.toString();
}
Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeDefinitionTemplateImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeDefinitionTemplateImpl.java?rev=597142&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeDefinitionTemplateImpl.java (added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeDefinitionTemplateImpl.java Wed Nov 21 08:51:34 2007
@@ -0,0 +1,125 @@
+/*
+ * 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.core.nodetype;
+
+import org.apache.jackrabbit.core.nodetype.jsr283.NodeDefinitionTemplate;
+import org.apache.jackrabbit.name.NameConstants;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.nodetype.NodeDefinition;
+import javax.jcr.nodetype.NodeType;
+
+/**
+ * A <code>NodeDefinitionTemplateImpl</code> ...
+ */
+class NodeDefinitionTemplateImpl
+ extends AbstractItemDefinitionTemplate
+ implements NodeDefinitionTemplate {
+
+ private NodeType[] requiredPrimaryTypes;
+ private String[] requiredPrimaryTypeNames;
+ private String defaultPrimaryTypeName;
+ private boolean allowSameNameSiblings;
+
+ /**
+ * Package private constructor
+ *
+ * @param ntMgr
+ * @throws RepositoryException
+ */
+ NodeDefinitionTemplateImpl(NodeTypeManagerImpl ntMgr) throws RepositoryException {
+ requiredPrimaryTypes = new NodeType[] {ntMgr.getNodeType(NameConstants.NT_BASE)};
+ requiredPrimaryTypeNames = new String[] {requiredPrimaryTypes[0].getName()};
+ }
+
+ /**
+ * Package private constructor
+ *
+ * @param def
+ */
+ NodeDefinitionTemplateImpl(NodeDefinition def) {
+ super(def);
+ requiredPrimaryTypes = def.getRequiredPrimaryTypes();
+ // FIXME temporary workaround until JSR 283 has been finalized
+ requiredPrimaryTypeNames = new String[requiredPrimaryTypes.length];
+ for (int i = 0; i < requiredPrimaryTypes.length; i++) {
+ requiredPrimaryTypeNames[i] = requiredPrimaryTypes[i].getName();
+ }
+ defaultPrimaryTypeName =
+ def.getDefaultPrimaryType() == null ? null : def.getDefaultPrimaryType().getName();
+ allowSameNameSiblings = def.allowsSameNameSiblings();
+ }
+
+ //-----------------------------------------------< NodeDefinitionTemplate >
+ /**
+ * {@inheritDoc}
+ */
+ public void setRequiredPrimaryTypes(String[] requiredPrimaryTypeNames) {
+ this.requiredPrimaryTypeNames = requiredPrimaryTypeNames;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setDefaultPrimaryType(String defaultPrimaryType) {
+ this.defaultPrimaryTypeName = defaultPrimaryType;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setSameNameSiblings(boolean allowSameNameSiblings) {
+ this.allowSameNameSiblings = allowSameNameSiblings;
+ }
+
+ //-------------------------------------------------------< NodeDefinition >
+ /**
+ * {@inheritDoc}
+ */
+ public NodeType[] getRequiredPrimaryTypes() {
+ return requiredPrimaryTypes;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String[] getRequiredPrimaryTypeNames() {
+ return requiredPrimaryTypeNames;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public NodeType getDefaultPrimaryType() {
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getDefaultPrimaryTypeName() {
+ return defaultPrimaryTypeName;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+
+ public boolean allowsSameNameSiblings() {
+ return allowSameNameSiblings;
+ }
+}
Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeImpl.java?rev=597142&r1=597141&r2=597142&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeImpl.java Wed Nov 21 08:51:34 2007
@@ -16,20 +16,21 @@
*/
package org.apache.jackrabbit.core.nodetype;
-import org.apache.jackrabbit.core.data.DataStore;
-import org.apache.jackrabbit.core.value.InternalValue;
import org.apache.jackrabbit.conversion.NameException;
import org.apache.jackrabbit.conversion.NamePathResolver;
+import org.apache.jackrabbit.core.data.DataStore;
+import org.apache.jackrabbit.core.nodetype.jsr283.NodeTypeDefinition;
+import org.apache.jackrabbit.core.value.InternalValue;
import org.apache.jackrabbit.spi.Name;
-import org.apache.jackrabbit.value.ValueHelper;
import org.apache.jackrabbit.value.ValueFactoryImpl;
+import org.apache.jackrabbit.value.ValueHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import javax.jcr.NamespaceException;
import javax.jcr.PropertyType;
import javax.jcr.RepositoryException;
import javax.jcr.Value;
-import javax.jcr.NamespaceException;
import javax.jcr.nodetype.ConstraintViolationException;
import javax.jcr.nodetype.NoSuchNodeTypeException;
import javax.jcr.nodetype.NodeDefinition;
@@ -41,7 +42,7 @@
/**
* A <code>NodeTypeImpl</code> ...
*/
-public class NodeTypeImpl implements NodeType {
+public class NodeTypeImpl implements NodeType, NodeTypeDefinition {
private static Logger log = LoggerFactory.getLogger(NodeTypeImpl.class);
@@ -210,7 +211,7 @@
return (NodeType[]) inherited.toArray(new NodeType[inherited.size()]);
}
- //-------------------------------------------------------------< NodeType >
+ //---------------------------------------------------< NodeTypeDefinition >
/**
* {@inheritDoc}
*/
@@ -225,6 +226,67 @@
}
/**
+ * Returns the names of the supertypes actually declared in this node type.
+ * <p/>
+ * In implementations that support node type registration, if this
+ * <code>NodeTypeDefinition</code> object is actually a newly-created empty
+ * <code>NodeTypeTemplate</code>, then this method will return an array
+ * containing a single string indicating the node type
+ * <code>nt:base</code>.
+ *
+ * @return an array of <code>String</code>s
+ * @since JCR 2.0
+ */
+ public String[] getDeclaredSupertypeNames() {
+ Name[] ntNames = ntd.getSupertypes();
+ String[] supertypes = new String[ntNames.length];
+ for (int i = 0; i < ntNames.length; i++) {
+ try {
+ supertypes[i] = resolver.getJCRName(ntd.getName());
+ } catch (NamespaceException e) {
+ // should never get here
+ log.error("encountered unregistered namespace in node type name", e);
+ supertypes[i] = ntd.getName().toString();
+ }
+ }
+ return supertypes;
+ }
+
+ /**
+ * Returns <code>true</code> if this is an abstract node type; returns
+ * <code>false</code> otherwise.
+ * <p/>
+ * An abstract node type is one that cannot be assigned as the primary or
+ * mixin type of a node but can be used in the definitions of other node
+ * types as a superclass.
+ * <p/>
+ * In implementations that support node type registration, if this
+ * <code>NodeTypeDefinition</code> object is actually a newly-created empty
+ * <code>NodeTypeTemplate</code>, then this method will return
+ * <code>false</code>.
+ *
+ * @return a <code>boolean</code>
+ * @since JCR 2.0
+ */
+ public boolean isAbstract() {
+ return ntd.isAbstract();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isMixin() {
+ return ntd.isMixin();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean hasOrderableChildNodes() {
+ return ntd.hasOrderableChildNodes();
+ }
+
+ /**
* {@inheritDoc}
*/
public String getPrimaryItemName() {
@@ -245,13 +307,37 @@
/**
* {@inheritDoc}
*/
- public boolean isMixin() {
- return ntd.isMixin();
+ public NodeType[] getDeclaredSupertypes() {
+ Name[] ntNames = ntd.getSupertypes();
+ NodeType[] supertypes = new NodeType[ntNames.length];
+ for (int i = 0; i < ntNames.length; i++) {
+ try {
+ supertypes[i] = ntMgr.getNodeType(ntNames[i]);
+ } catch (NoSuchNodeTypeException e) {
+ // should never get here
+ log.error("undefined supertype", e);
+ return new NodeType[0];
+ }
+ }
+ return supertypes;
}
/**
* {@inheritDoc}
*/
+ public NodeDefinition[] getDeclaredChildNodeDefinitions() {
+ NodeDef[] cnda = ntd.getChildNodeDefs();
+ NodeDefinition[] nodeDefs = new NodeDefinition[cnda.length];
+ for (int i = 0; i < cnda.length; i++) {
+ nodeDefs[i] = ntMgr.getNodeDefinition(cnda[i].getId());
+ }
+ return nodeDefs;
+ }
+
+ //-------------------------------------------------------------< NodeType >
+ /**
+ * {@inheritDoc}
+ */
public boolean isNodeType(String nodeTypeName) {
Name ntName;
try {
@@ -269,13 +355,6 @@
/**
* {@inheritDoc}
*/
- public boolean hasOrderableChildNodes() {
- return ntd.hasOrderableChildNodes();
- }
-
- /**
- * {@inheritDoc}
- */
public NodeType[] getSupertypes() {
Name[] ntNames = ent.getInheritedNodeTypes();
NodeType[] supertypes = new NodeType[ntNames.length];
@@ -313,36 +392,6 @@
propDefs[i] = ntMgr.getPropertyDefinition(pda[i].getId());
}
return propDefs;
- }
-
- /**
- * {@inheritDoc}
- */
- public NodeType[] getDeclaredSupertypes() {
- Name[] ntNames = ntd.getSupertypes();
- NodeType[] supertypes = new NodeType[ntNames.length];
- for (int i = 0; i < ntNames.length; i++) {
- try {
- supertypes[i] = ntMgr.getNodeType(ntNames[i]);
- } catch (NoSuchNodeTypeException e) {
- // should never get here
- log.error("undefined supertype", e);
- return new NodeType[0];
- }
- }
- return supertypes;
- }
-
- /**
- * {@inheritDoc}
- */
- public NodeDefinition[] getDeclaredChildNodeDefinitions() {
- NodeDef[] cnda = ntd.getChildNodeDefs();
- NodeDefinition[] nodeDefs = new NodeDefinition[cnda.length];
- for (int i = 0; i < cnda.length; i++) {
- nodeDefs[i] = ntMgr.getNodeDefinition(cnda[i].getId());
- }
- return nodeDefs;
}
/**
Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeManagerImpl.java?rev=597142&r1=597141&r2=597142&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeManagerImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeManagerImpl.java Wed Nov 21 08:51:34 2007
@@ -17,35 +17,46 @@
package org.apache.jackrabbit.core.nodetype;
import org.apache.commons.collections.map.ReferenceMap;
+import org.apache.jackrabbit.api.JackrabbitNodeTypeManager;
import org.apache.jackrabbit.conversion.NameException;
-import org.apache.jackrabbit.spi.Name;
import org.apache.jackrabbit.conversion.NamePathResolver;
-import org.apache.jackrabbit.util.IteratorHelper;
-import org.apache.jackrabbit.namespace.NamespaceMapping;
-import org.apache.jackrabbit.namespace.NamespaceResolver;
-import org.apache.jackrabbit.api.JackrabbitNodeTypeManager;
import org.apache.jackrabbit.core.NamespaceRegistryImpl;
import org.apache.jackrabbit.core.data.DataStore;
import org.apache.jackrabbit.core.nodetype.compact.CompactNodeTypeDefReader;
import org.apache.jackrabbit.core.nodetype.compact.ParseException;
+import org.apache.jackrabbit.core.nodetype.jsr283.InvalidNodeTypeDefinitionException;
+import org.apache.jackrabbit.core.nodetype.jsr283.NodeDefinitionTemplate;
+import org.apache.jackrabbit.core.nodetype.jsr283.NodeTypeDefinition;
+import org.apache.jackrabbit.core.nodetype.jsr283.NodeTypeExistsException;
+import org.apache.jackrabbit.core.nodetype.jsr283.NodeTypeTemplate;
+import org.apache.jackrabbit.core.nodetype.jsr283.PropertyDefinitionTemplate;
import org.apache.jackrabbit.core.nodetype.xml.NodeTypeReader;
import org.apache.jackrabbit.core.util.Dumpable;
+import org.apache.jackrabbit.core.value.InternalValue;
+import org.apache.jackrabbit.namespace.NamespaceMapping;
+import org.apache.jackrabbit.namespace.NamespaceResolver;
+import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.util.IteratorHelper;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
+import javax.jcr.NamespaceException;
import javax.jcr.RepositoryException;
import javax.jcr.UnsupportedRepositoryOperationException;
-import javax.jcr.NamespaceException;
+import javax.jcr.Value;
+import javax.jcr.ValueFormatException;
import javax.jcr.nodetype.NoSuchNodeTypeException;
+import javax.jcr.nodetype.NodeDefinition;
import javax.jcr.nodetype.NodeType;
import javax.jcr.nodetype.NodeTypeIterator;
-
+import javax.jcr.nodetype.PropertyDefinition;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
@@ -291,7 +302,7 @@
ArrayList nodeTypes = new ArrayList();
// register new node types
- nodeTypes.addAll(Arrays.asList(registerNodeTypes(newNodeTypeDefs)));
+ nodeTypes.addAll(registerNodeTypes(newNodeTypeDefs));
// reregister already existing node types
for (Iterator iter = registeredNodeTypeDefs.iterator(); iter.hasNext();) {
@@ -301,7 +312,8 @@
}
return (NodeType[]) nodeTypes.toArray(new NodeType[nodeTypes.size()]);
} else {
- return registerNodeTypes(nodeTypeDefs);
+ Collection types = registerNodeTypes(nodeTypeDefs);
+ return (NodeType[]) types.toArray(new NodeType[types.size()]);
}
} catch (InvalidNodeTypeDefException e) {
@@ -430,14 +442,14 @@
/**
* Internal helper method for registering a list of node type definitions.
- * Returns an array containing the registered node types.
+ * Returns a collection containing the registered node types.
*
* @param defs a collection of <code>NodeTypeDef<code> objects
* @returns registered node types
* @throws InvalidNodeTypeDefException
* @throws RepositoryException
*/
- private NodeType[] registerNodeTypes(List defs)
+ private Collection registerNodeTypes(List defs)
throws InvalidNodeTypeDefException, RepositoryException {
ntReg.registerNodeTypes(defs);
@@ -451,7 +463,7 @@
// ignore
}
}
- return (NodeType[]) types.toArray(new NodeType[types.size()]);
+ return types;
}
/**
@@ -505,6 +517,444 @@
} catch (NameException e) {
throw new RepositoryException("Invalid name: " + name, e);
}
+ }
+
+ //--------------------------------------------------< new JSR 283 methods >
+ /**
+ * Returns an empty <code>NodeTypeTemplate</code> which can then be used to
+ * define a node type and passed to
+ * <code>NodeTypeManager.registerNodeType</code>.
+ * <p/>
+ * Throws an <code>UnsupportedRepositoryOperationException</code> if this
+ * implementation does not support node type registration.
+ * @return A <code>NodeTypeTemplate</code>.
+ * @throws UnsupportedRepositoryOperationException if this implementation
+ * does not support node type registration.
+ * @throws RepositoryException if another error occurs.
+ * @since JCR 2.0
+ */
+ public NodeTypeTemplate createNodeTypeTemplate()
+ throws UnsupportedRepositoryOperationException, RepositoryException {
+ return new NodeTypeTemplateImpl();
+ }
+
+ /**
+ * Returns a <code>NodeTypeTemplate</code> holding the specified node type
+ * definition. This template can then be altered and passed to
+ * <code>NodeTypeManager.registerNodeType</code>.
+ * <p/>
+ * Throws an <code>UnsupportedRepositoryOperationException</code> if this
+ * implementation does not support node type registration.
+ *
+ * @param ntd a <code>NodeTypeDefinition</code>.
+ * @return A <code>NodeTypeTemplate</code>.
+ * @throws UnsupportedRepositoryOperationException if this implementation
+ * does not support node type registration.
+ * @throws RepositoryException if another error occurs.
+ * @since JCR 2.0
+ */
+ public NodeTypeTemplate createNodeTypeTemplate(NodeTypeDefinition ntd)
+ throws UnsupportedRepositoryOperationException, RepositoryException {
+ return new NodeTypeTemplateImpl(ntd);
+ }
+
+ /**
+ * Returns an empty <code>NodeDefinitionTemplate</code> which can then be
+ * used to create a child node definition and attached to a
+ * <code>NodeTypeTemplate</code>.
+ * <p/>
+ * Throws an <code>UnsupportedRepositoryOperationException</code> if this
+ * implementation does not support node type registration.
+ *
+ * @return A <code>NodeDefinitionTemplate</code>.
+ * @throws UnsupportedRepositoryOperationException if this implementation
+ * does not support node type registration.
+ * @throws RepositoryException if another error occurs.
+ * @since JCR 2.0
+ */
+ public NodeDefinitionTemplate createNodeDefinitionTemplate()
+ throws UnsupportedRepositoryOperationException, RepositoryException {
+ return new NodeDefinitionTemplateImpl(this);
+ }
+
+ /**
+ * Returns an empty <code>PropertyDefinitionTemplate</code> which can then
+ * be used to create a property definition and attached to a
+ * <code>NodeTypeTemplate</code>.
+ * <p/>
+ * Throws an <code>UnsupportedRepositoryOperationException</code> if this
+ * implementation does not support node type registration.
+ *
+ * @return A <code>PropertyDefinitionTemplate</code>.
+ * @throws UnsupportedRepositoryOperationException if this implementation
+ * does not support node type registration.
+ * @throws RepositoryException if another error occurs.
+ * @since JCR 2.0
+ */
+ public PropertyDefinitionTemplate createPropertyDefinitionTemplate()
+ throws UnsupportedRepositoryOperationException, RepositoryException {
+ return new PropertyDefinitionTemplateImpl();
+ }
+
+ /**
+ * Registers a new node type or updates an existing node type using the
+ * specified definition and returns the resulting <code>NodeType</code>
+ * object.
+ * <p/>
+ * Typically, the object passed to this method will be a
+ * <code>NodeTypeTemplate</code> (a subclass of
+ * <code>NodeTypeDefinition</code>) acquired from
+ * <code>NodeTypeManager.createNodeTypeTemplate</code> and then filled-in
+ * with definition information.
+ * <p/>
+ * Throws an <code>InvalidNodeTypeDefinitionException</code> if the
+ * <code>NodeTypeDefinition</code> is invalid.
+ * <p/>
+ * Throws a <code>NodeTypeExistsException</code> if <code>allowUpdate</code>
+ * is <code>false</code> and the <code>NodeTypeDefinition</code> specifies a
+ * node type name that is already registered.
+ * <p/>
+ * Throws an <code>UnsupportedRepositoryOperationException</code> if this
+ * implementation does not support node type registration.
+ *
+ * @param ntd an <code>NodeTypeDefinition</code>.
+ * @param allowUpdate a boolean
+ * @return the registered node type
+ * @throws InvalidNodeTypeDefinitionException if the
+ * <code>NodeTypeDefinition</code> is invalid.
+ * @throws NodeTypeExistsException if <code>allowUpdate</code> is
+ * <code>false</code> and the <code>NodeTypeDefinition</code> specifies a
+ * node type name that is already registered.
+ * @throws UnsupportedRepositoryOperationException if this implementation
+ * does not support node type registration.
+ * @throws RepositoryException if another error occurs.
+ * @since JCR 2.0
+ */
+ public NodeType registerNodeType(NodeTypeDefinition ntd, boolean allowUpdate)
+ throws InvalidNodeTypeDefinitionException, NodeTypeExistsException,
+ UnsupportedRepositoryOperationException, RepositoryException {
+ HashSet defs = new HashSet();
+ defs.add(ntd);
+ return (NodeType) registerNodeTypes(defs, allowUpdate).next();
+ }
+
+ /**
+ * Registers or updates the specified <code>Collection</code> of
+ * <code>NodeTypeDefinition</code> objects. This method is used to register
+ * or update a set of node types with mutual dependencies. Returns an
+ * iterator over the resulting <code>NodeType</code> objects.
+ * <p/>
+ * The effect of the method is "all or nothing"; if an error occurs, no node
+ * types are registered or updated.
+ * <p/>
+ * Throws an <code>InvalidNodeTypeDefinitionException</code> if a
+ * <code>NodeTypeDefinition</code> within the <code>Collection</code> is
+ * invalid or if the <code>Collection</code> contains an object of a type
+ * other than <code>NodeTypeDefinition</code>.
+ * <p/>
+ * Throws a <code>NodeTypeExistsException</code> if <code>allowUpdate</code>
+ * is <code>false</code> and a <code>NodeTypeDefinition</code> within the
+ * <code>Collection</code> specifies a node type name that is already
+ * registered.
+ * <p/>
+ * Throws an <code>UnsupportedRepositoryOperationException</code> if this
+ * implementation does not support node type registration.
+ *
+ * @param definitions a collection of <code>NodeTypeDefinition</code>s
+ * @param allowUpdate a boolean
+ * @return the registered node types.
+ * @throws InvalidNodeTypeDefinitionException if a
+ * <code>NodeTypeDefinition</code> within the <code>Collection</code> is
+ * invalid or if the <code>Collection</code> contains an object of a type
+ * other than <code>NodeTypeDefinition</code>.
+ * @throws NodeTypeExistsException if <code>allowUpdate</code> is
+ * <code>false</code> and a <code>NodeTypeDefinition</code> within the
+ * <code>Collection</code> specifies a node type name that is already
+ * registered.
+ * @throws UnsupportedRepositoryOperationException if this implementation
+ * does not support node type registration.
+ * @throws RepositoryException if another error occurs.
+ * @since JCR 2.0
+ */
+ public NodeTypeIterator registerNodeTypes(Collection definitions,
+ boolean allowUpdate)
+ throws InvalidNodeTypeDefinitionException, NodeTypeExistsException,
+ UnsupportedRepositoryOperationException, RepositoryException {
+ // split the node types into new and already registered node types.
+ // this way we can register new node types together with already
+ // registered node types which make circular dependencies possible
+ List addedDefs = new ArrayList();
+ List modifiedDefs = new ArrayList();
+ for (Iterator iter = definitions.iterator(); iter.hasNext();) {
+ NodeTypeDefinition definition = (NodeTypeDefinition) iter.next();
+ // convert to NodeTypeDef
+ NodeTypeDef def = toNodeTypeDef(definition);
+ if (ntReg.isRegistered(def.getName())) {
+ if (allowUpdate) {
+ modifiedDefs.add(def);
+ } else {
+ throw new NodeTypeExistsException(definition.getName());
+ }
+ } else {
+ addedDefs.add(def);
+ }
+ }
+
+ try {
+ ArrayList result = new ArrayList();
+
+ // register new node types
+ Collection registeredDefs = registerNodeTypes(addedDefs);
+ for (Iterator iter = registeredDefs.iterator(); iter.hasNext();) {
+ NodeTypeDef nodeTypeDef = (NodeTypeDef) iter.next();
+ result.add(getNodeType(nodeTypeDef.getName()));
+ }
+
+ // reregister already existing node types
+ for (Iterator iter = modifiedDefs.iterator(); iter.hasNext();) {
+ NodeTypeDef nodeTypeDef = (NodeTypeDef) iter.next();
+ ntReg.reregisterNodeType(nodeTypeDef);
+ result.add(getNodeType(nodeTypeDef.getName()));
+ }
+ return new IteratorHelper(result);
+ } catch (InvalidNodeTypeDefException e) {
+ throw new InvalidNodeTypeDefinitionException(e.getMessage());
+ }
+ }
+
+ /**
+ * Unregisters the specified node type.
+ * <p/>
+ * Throws a <code>NoSuchNodeTypeException</code> if no registered node type
+ * exists with the specified name.
+ *
+ * @param name a <code>String</code>.
+ * @throws UnsupportedRepositoryOperationException if this implementation
+ * does not support node type registration.
+ * @throws NoSuchNodeTypeException if no registered node type exists with
+ * the specified name.
+ * @throws RepositoryException if another error occurs.
+ * @since JCR 2.0
+ */
+ public void unregisterNodeType(String name)
+ throws UnsupportedRepositoryOperationException,
+ NoSuchNodeTypeException, RepositoryException {
+ unregisterNodeTypes(new String[] {name});
+ }
+
+ /**
+ * Unregisters the specified set of node types. Used to unregister a set of node types with mutual dependencies.
+ * <p/>
+ * Throws a <code>NoSuchNodeTypeException</code> if one of the names listed is not a registered node type.
+ * <p/>
+ * Throws an <code>UnsupportedRepositoryOperationException</code> if this implementation does not support node type registration.
+ *
+ * @param names a <code>String</code> array
+ * @throws UnsupportedRepositoryOperationException if this implementation does not support node type registration.
+ * @throws NoSuchNodeTypeException if one of the names listed is not a registered node type.
+ * @throws RepositoryException if another error occurs.
+ * @since JCR 2.0
+ */
+ public void unregisterNodeTypes(String[] names)
+ throws UnsupportedRepositoryOperationException,
+ NoSuchNodeTypeException, RepositoryException {
+ HashSet ntNames = new HashSet();
+ for (int i = 0; i < names.length; i++) {
+ try {
+ ntNames.add(resolver.getQName(names[i]));
+ } catch (NamespaceException e) {
+ throw new RepositoryException("Invalid name: " + names[i], e);
+ } catch (NameException e) {
+ throw new RepositoryException("Invalid name: " + names[i], e);
+ }
+ }
+ getNodeTypeRegistry().unregisterNodeTypes(ntNames);
+ }
+
+ /**
+ * Internal helper method for converting a <code>NodeTypeDefinition</code>
+ * (using prefixed JCR names) to a <code>NodeTypeDef</code> (using
+ * namespace-qualified names).
+ *
+ * @param definition
+ * @return a <code>NodeTypeDef</code>
+ * @throws InvalidNodeTypeDefinitionException
+ * @throws RepositoryException
+ */
+ private NodeTypeDef toNodeTypeDef(NodeTypeDefinition definition)
+ throws InvalidNodeTypeDefinitionException, RepositoryException {
+ NodeTypeDef def = new NodeTypeDef();
+
+ // name
+ String name = definition.getName();
+ if (name == null) {
+ throw new InvalidNodeTypeDefinitionException("No node type name specified");
+ }
+ try {
+ def.setName(resolver.getQName(name));
+ } catch (NamespaceException e) {
+ throw new InvalidNodeTypeDefinitionException("Invalid name: " + name, e);
+ } catch (NameException e) {
+ throw new InvalidNodeTypeDefinitionException("Invalid name: " + name, e);
+ }
+
+ // supertypes
+ String[] names = definition.getDeclaredSupertypeNames();
+ Name[] qnames = new Name[names.length];
+ for (int i = 0; i < names.length; i++) {
+ try {
+ qnames[i] = resolver.getQName(names[i]);
+ } catch (NamespaceException e) {
+ throw new InvalidNodeTypeDefinitionException("Invalid supertype name: " + names[i], e);
+ } catch (NameException e) {
+ throw new InvalidNodeTypeDefinitionException("Invalid supertype name: " + names[i], e);
+ }
+ }
+ def.setSupertypes(qnames);
+
+ // primary item
+ name = definition.getPrimaryItemName();
+ if (name != null) {
+ try {
+ def.setPrimaryItemName(resolver.getQName(name));
+ } catch (NamespaceException e) {
+ throw new InvalidNodeTypeDefinitionException("Invalid primary item name: " + name, e);
+ } catch (NameException e) {
+ throw new InvalidNodeTypeDefinitionException("Invalid primary item name: " + name, e);
+ }
+ }
+
+ // misc. flags
+ def.setMixin(definition.isMixin());
+ def.setAbstract(definition.isAbstract());
+ def.setOrderableChildNodes(definition.hasOrderableChildNodes());
+
+ // child nodes
+ NodeDefinition[] ndefs = definition.getDeclaredChildNodeDefinitions();
+ if (ndefs != null) {
+ NodeDef[] qndefs = new NodeDef[ndefs.length];
+ for (int i = 0; i < ndefs.length; i++) {
+ NodeDefImpl qndef = new NodeDefImpl();
+ // name
+ name = ndefs[i].getName();
+ if (name != null) {
+ if (name.equals("*")) {
+ qndef.setName(ItemDef.ANY_NAME);
+ } else {
+ try {
+ qndef.setName(resolver.getQName(name));
+ } catch (NamespaceException e) {
+ throw new InvalidNodeTypeDefinitionException("Invalid node name: " + name, e);
+ } catch (NameException e) {
+ throw new InvalidNodeTypeDefinitionException("Invalid node name: " + name, e);
+ }
+ }
+ }
+ // default primary type
+ //name = ndefs[i].getDefaultPrimaryTypeName();
+ // FIXME when JCR 2.0 API has been finalized
+ name = ((NodeDefinitionTemplateImpl) ndefs[i]).getDefaultPrimaryTypeName();
+ if (name != null) {
+ try {
+ qndef.setDefaultPrimaryType(resolver.getQName(name));
+ } catch (NamespaceException e) {
+ throw new InvalidNodeTypeDefinitionException("Invalid default primary type: " + name, e);
+ } catch (NameException e) {
+ throw new InvalidNodeTypeDefinitionException("Invalid default primary type: " + name, e);
+ }
+ }
+ // required primary types
+ //names = ndefs[i].getRequiredPrimaryTypeNames();
+ // FIXME when JCR 2.0 API has been finalized
+ names = ((NodeDefinitionTemplateImpl) ndefs[i]).getRequiredPrimaryTypeNames();
+ qnames = new Name[names.length];
+ for (int j = 0; i < names.length; j++) {
+ try {
+ qnames[i] = resolver.getQName(names[i]);
+ } catch (NamespaceException e) {
+ throw new InvalidNodeTypeDefinitionException("Invalid required primary type: " + names[i], e);
+ } catch (NameException e) {
+ throw new InvalidNodeTypeDefinitionException("Invalid required primary type: " + names[i], e);
+ }
+ }
+ qndef.setRequiredPrimaryTypes(qnames);
+
+ // misc. flags/attributes
+ qndef.setAutoCreated(ndefs[i].isAutoCreated());
+ qndef.setMandatory(ndefs[i].isMandatory());
+ qndef.setProtected(ndefs[i].isProtected());
+ qndef.setOnParentVersion(ndefs[i].getOnParentVersion());
+ qndef.setAllowsSameNameSiblings(ndefs[i].allowsSameNameSiblings());
+
+ qndefs[i] = qndef;
+ }
+ def.setChildNodeDefs(qndefs);
+ }
+
+ // properties
+ PropertyDefinition[] pdefs = definition.getDeclaredPropertyDefinitions();
+ if (pdefs != null) {
+ PropDef[] qpdefs = new PropDef[pdefs.length];
+ for (int i = 0; i < pdefs.length; i++) {
+ PropDefImpl qpdef = new PropDefImpl();
+ // name
+ name = pdefs[i].getName();
+ if (name != null) {
+ if (name.equals("*")) {
+ qpdef.setName(ItemDef.ANY_NAME);
+ } else {
+ try {
+ qpdef.setName(resolver.getQName(name));
+ } catch (NamespaceException e) {
+ throw new InvalidNodeTypeDefinitionException("Invalid property name: " + name, e);
+ } catch (NameException e) {
+ throw new InvalidNodeTypeDefinitionException("Invalid property name: " + name, e);
+ }
+ }
+ }
+ // misc. flags/attributes
+ int type = pdefs[i].getRequiredType();
+ qpdef.setRequiredType(type);
+ qpdef.setAutoCreated(pdefs[i].isAutoCreated());
+ qpdef.setMandatory(pdefs[i].isMandatory());
+ qpdef.setProtected(pdefs[i].isProtected());
+ qpdef.setOnParentVersion(pdefs[i].getOnParentVersion());
+ qpdef.setMultiple(pdefs[i].isMultiple());
+ // value constraints
+ String[] constraints = pdefs[i].getValueConstraints();
+ if (constraints != null) {
+ ValueConstraint[] qconstraints = new ValueConstraint[constraints.length];
+ for (int j = 0; j < constraints.length; j++) {
+ try {
+ qconstraints[j] = ValueConstraint.create(type, constraints[i], resolver);
+ } catch (InvalidConstraintException e) {
+ throw new InvalidNodeTypeDefinitionException(
+ "Invalid value constraint " + constraints[i], e);
+ }
+ }
+ qpdef.setValueConstraints(qconstraints);
+ }
+ // default values
+ Value[] values = pdefs[i].getDefaultValues();
+ if (values != null) {
+ InternalValue[] qvalues = new InternalValue[values.length];
+ for (int j = 0; j < values.length; j++) {
+ try {
+ qvalues[j] = InternalValue.create(values[i], resolver);
+ } catch (ValueFormatException e) {
+ throw new InvalidNodeTypeDefinitionException(
+ "Invalid default value format", e);
+ }
+ }
+ qpdef.setDefaultValues(qvalues);
+ }
+
+ qpdefs[i] = qpdef;
+ }
+ def.setPropertyDefs(qpdefs);
+ }
+
+ return def;
}
//-------------------------------------------------------------< Dumpable >
Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeTemplateImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeTemplateImpl.java?rev=597142&r1=597141&r2=597142&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeTemplateImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeTemplateImpl.java Wed Nov 21 08:51:34 2007
@@ -18,12 +18,14 @@
import org.apache.commons.collections.list.TypedList;
import org.apache.jackrabbit.core.nodetype.jsr283.NodeDefinitionTemplate;
+import org.apache.jackrabbit.core.nodetype.jsr283.NodeTypeDefinition;
import org.apache.jackrabbit.core.nodetype.jsr283.NodeTypeTemplate;
import org.apache.jackrabbit.core.nodetype.jsr283.PropertyDefinitionTemplate;
import javax.jcr.nodetype.NodeDefinition;
import javax.jcr.nodetype.PropertyDefinition;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
/**
@@ -31,7 +33,6 @@
*/
public class NodeTypeTemplateImpl implements NodeTypeTemplate {
-
private String name;
private String[] superTypeNames;
private String primaryItemName;
@@ -42,13 +43,35 @@
private List propertyDefinitionTemplates;
/**
- * Default constructor
+ * Package private constructor
*/
- public NodeTypeTemplateImpl() {
+ NodeTypeTemplateImpl() {
nodeDefinitionTemplates = TypedList.decorate(
new ArrayList(), NodeDefinitionTemplate.class);
propertyDefinitionTemplates = TypedList.decorate(
new ArrayList(), PropertyDefinitionTemplate.class);
+ }
+
+ /**
+ * Package private constructor
+ *
+ * @param def
+ */
+ NodeTypeTemplateImpl(NodeTypeDefinition def) {
+ name = def.getName();
+ superTypeNames = def.getDeclaredSupertypeNames();
+ primaryItemName = def.getPrimaryItemName();
+ abstractStatus = def.isAbstract();
+ mixin = def.isMixin();
+ orderableChildNodes = def.hasOrderableChildNodes();
+ NodeDefinition[] nodeDefs = def.getDeclaredChildNodeDefinitions();
+ for (int i = 0; i < nodeDefs.length; i++) {
+ nodeDefinitionTemplates.add(new NodeDefinitionTemplateImpl(nodeDefs[i])) ;
+ }
+ PropertyDefinition[] propDefs = def.getDeclaredPropertyDefinitions();
+ for (int i = 0; i < propDefs.length; i++) {
+ propertyDefinitionTemplates.add(new PropertyDefinitionTemplateImpl(propDefs[i]));
+ }
}
//-----------------------------------------------------< NodeTypeTemplate >
Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/PropertyDefinitionTemplateImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/PropertyDefinitionTemplateImpl.java?rev=597142&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/PropertyDefinitionTemplateImpl.java (added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/PropertyDefinitionTemplateImpl.java Wed Nov 21 08:51:34 2007
@@ -0,0 +1,114 @@
+/*
+ * 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.core.nodetype;
+
+import org.apache.jackrabbit.core.nodetype.jsr283.PropertyDefinitionTemplate;
+
+import javax.jcr.PropertyType;
+import javax.jcr.Value;
+import javax.jcr.nodetype.PropertyDefinition;
+
+/**
+ * A <code>PropertyDefinitionTemplateImpl</code> ...
+ */
+class PropertyDefinitionTemplateImpl
+ extends AbstractItemDefinitionTemplate
+ implements PropertyDefinitionTemplate {
+
+ private int type;
+ private String[] constraints;
+ private Value[] defaultValues;
+ private boolean multiple;
+
+ /**
+ * Package private constructor
+ */
+ PropertyDefinitionTemplateImpl() {
+ type = PropertyType.STRING;
+ }
+
+ /**
+ * Package private constructor
+ *
+ * @param def
+ */
+ PropertyDefinitionTemplateImpl(PropertyDefinition def) {
+ super(def);
+ type = def.getRequiredType();
+ constraints = def.getValueConstraints();
+ defaultValues = def.getDefaultValues();
+ multiple = def.isMultiple();
+ }
+
+ //-------------------------------------------< PropertyDefinitionTemplate >
+ /**
+ * {@inheritDoc}
+ */
+ public void setRequiredType(int type) {
+ this.type = type;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setValueConstarints(String[] constraints) {
+ this.constraints = constraints;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setDefaultValues(Value[] defaultValues) {
+ this.defaultValues = defaultValues;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setMultiple(boolean multiple) {
+ this.multiple = multiple;
+ }
+
+ //---------------------------------------------------< PropertyDefinition >
+ /**
+ * {@inheritDoc}
+ */
+ public int getRequiredType() {
+ return type;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String[] getValueConstraints() {
+ return constraints;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Value[] getDefaultValues() {
+ return defaultValues;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isMultiple() {
+ return multiple;
+ }
+}