You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by st...@apache.org on 2004/06/30 16:39:37 UTC
cvs commit: jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/nodetype EffectiveNodeType.java NodeTypeConflictException.java NodeTypeDef.java NodeTypeRegistry.java
stefan 2004/06/30 07:39:37
Modified: proposals/jcrri/src/org/apache/slide/jcr/core/nodetype
EffectiveNodeType.java
NodeTypeConflictException.java NodeTypeDef.java
NodeTypeRegistry.java
Log:
jcrri
Revision Changes Path
1.5 +3 -33 jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/nodetype/EffectiveNodeType.java
Index: EffectiveNodeType.java
===================================================================
RCS file: /home/cvs/jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/nodetype/EffectiveNodeType.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- EffectiveNodeType.java 29 Jun 2004 17:11:47 -0000 1.4
+++ EffectiveNodeType.java 30 Jun 2004 14:39:37 -0000 1.5
@@ -26,11 +26,9 @@
import org.apache.log4j.Logger;
import org.apache.slide.jcr.core.InternalValue;
import org.apache.slide.jcr.core.QName;
-import org.apache.slide.jcr.core.NamespaceResolver;
import javax.jcr.RepositoryException;
import javax.jcr.ValueFormatException;
-import javax.jcr.Node;
import javax.jcr.nodetype.ConstraintViolationException;
import javax.jcr.nodetype.NoSuchNodeTypeException;
import java.util.ArrayList;
@@ -105,7 +103,7 @@
* @throws NodeTypeConflictException
* @throws NoSuchNodeTypeException
*/
- static EffectiveNodeType create(NodeTypeRegistry ntReg, NodeTypeDef ntd)
+ public static EffectiveNodeType create(NodeTypeRegistry ntReg, NodeTypeDef ntd)
throws NodeTypeConflictException, NoSuchNodeTypeException {
// create empty effective node type instance
EffectiveNodeType ent = new EffectiveNodeType(ntReg);
@@ -145,34 +143,6 @@
}
// we're done
- return ent;
- }
-
- /**
- * Factory method: creates an effective node type representation of an
- * node that itself represents a node type. While all referenced node types must
- * exist (i.e. must be registered), the definition itself is not required to
- * be registered.
- * @param ntReg
- * @param node
- * @param nsResolver namespace resolver used to convert from <code>String</code>
- * values to qualified names required.
- * @return A new 'empty' effective node type instance.
- * @throws NoSuchNodeTypeException if any of the referenced node types does not exist.
- * @throws RepositoryException if the given <code>node</code> does not represent
- * a node type or if the creation fails due to a conflict.
- */
- public static EffectiveNodeType create(NodeTypeRegistry ntReg, Node node, NamespaceResolver nsResolver)
- throws NoSuchNodeTypeException, RepositoryException {
- EffectiveNodeType ent = null;
- try {
- NodeTypeDef ntd = new NodeTypeDef(node, nsResolver);
- ent = create(ntReg, ntd);
- } catch (InvalidConstraintException e) {
- throw new RepositoryException(e.getMessage());
- } catch (NodeTypeConflictException e) {
- throw new RepositoryException(e.getMessage());
- }
return ent;
}
1.4 +3 -3 jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/nodetype/NodeTypeConflictException.java
Index: NodeTypeConflictException.java
===================================================================
RCS file: /home/cvs/jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/nodetype/NodeTypeConflictException.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- NodeTypeConflictException.java 22 Jun 2004 18:03:07 -0000 1.3
+++ NodeTypeConflictException.java 30 Jun 2004 14:39:37 -0000 1.4
@@ -31,7 +31,7 @@
* @author Stefan Guggisberg
* @version $Revision$, $Date$
*/
-class NodeTypeConflictException extends BaseException {
+public class NodeTypeConflictException extends BaseException {
/**
* Constructs a new instance of this class.
*/
1.5 +9 -97 jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/nodetype/NodeTypeDef.java
Index: NodeTypeDef.java
===================================================================
RCS file: /home/cvs/jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/nodetype/NodeTypeDef.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- NodeTypeDef.java 29 Jun 2004 17:11:47 -0000 1.4
+++ NodeTypeDef.java 30 Jun 2004 14:39:37 -0000 1.5
@@ -23,9 +23,11 @@
*/
package org.apache.slide.jcr.core.nodetype;
-import org.apache.slide.jcr.core.*;
-import javax.jcr.*;
-import java.util.*;
+import org.apache.slide.jcr.core.QName;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
/**
* A <code>NodeTypeDef</code> holds the definition of a nodetype.
@@ -56,24 +58,6 @@
orderableChildNodes = false;
}
- /**
- * Package private constructor.
- */
- NodeTypeDef(Node node, NamespaceResolver nsResolver)
- throws RepositoryException, InvalidConstraintException {
- this();
- if (!node.isNodeType("nt:nodeType")) {
- throw new RepositoryException("Node of type 'nt:nodeType' expected.");
- }
- QName ntName = QName.fromJCRName(node.getProperty("jcr:nodeTypeName").getString(), nsResolver);
- setName(ntName);
- setMixin(node.getProperty("jcr:isMixin").getBoolean());
- setOrderableChildNodes(node.getProperty("jcr:orderableChildNodes").getBoolean());
- setSupertypes(node.getProperty("jcr:supertypes"), nsResolver);
- setChildNodeDefs(node.getNodes("jcr:childNodeDef"), ntName, nsResolver);
- setPropertyDefs(node.getNodes("jcr:propertyDef"), ntName, nsResolver);
- }
-
public Object clone() throws CloneNotSupportedException {
// create a shallow copy
NodeTypeDef clone = (NodeTypeDef) super.clone();
@@ -134,6 +118,7 @@
/**
* Sets the mixin flag.
+ *
* @param mixin flag
*/
public void setMixin(boolean mixin) {
@@ -142,6 +127,7 @@
/**
* Sets the orderableChildNodes flag.
+ *
* @param orderableChildNodes flag
*/
public void setOrderableChildNodes(boolean orderableChildNodes) {
@@ -226,79 +212,5 @@
*/
public ChildNodeDef[] getChildNodeDefs() {
return nodeDefs;
- }
-
- //---------------< private methods for building definition from node >------
- /**
- * Retrieve the supertypes defined with the nodetype node.<br>
- * NOTE: If the 'jcr:supertype' property has no value and the nodetype is
- * a primary nodetype 'nt:base' is set as default value as required for
- * custom nodetypes by the specification.
- * @param supertypeProp
- * @param nsResolver
- * @throws RepositoryException
- * @see NodeTypeRegistry#NT_BASE
- */
- private void setSupertypes(Property supertypeProp, NamespaceResolver nsResolver)
- throws RepositoryException {
-
- ArrayList sList = new ArrayList();
- if (supertypeProp.hasValue()) {
- Value[] values = supertypeProp.getValues();
- for (int i = 0; i < values.length; i++) {
- String stName = values[i].getString();
- // ignore base, will automatically be added if no supertypes
- if (stName.equals(NodeTypeRegistry.NT_BASE.toJCRName(nsResolver))) {
- continue;
- }
- sList.add(QName.fromJCRName(stName, nsResolver));
- }
- }
- if (sList.size()==0 && !isMixin()) {
- sList.add(NodeTypeRegistry.NT_BASE);
- }
- setSupertypes((QName[])sList.toArray(new QName[sList.size()]));
- }
-
- /**
- * @param it
- * @param ntName
- * @param nsResolver
- * @throws RepositoryException
- */
- private void setChildNodeDefs(NodeIterator it, QName ntName, NamespaceResolver nsResolver)
- throws RepositoryException {
-
- if (it == null) {
- return;
- }
- ArrayList l = new ArrayList();
- while (it.hasNext()) {
- Node childNode = it.nextNode();
- ChildNodeDef childDef = new ChildNodeDef(childNode, ntName, nsResolver);
- l.add(childDef);
- }
- setChildNodeDefs((ChildNodeDef[])l.toArray(new ChildNodeDef[l.size()]));
- }
-
- /**
- * @param it
- * @param ntName
- * @param nsResolver
- * @throws RepositoryException
- */
- private void setPropertyDefs(NodeIterator it, QName ntName, NamespaceResolver nsResolver)
- throws RepositoryException, InvalidConstraintException {
-
- if (it == null) {
- return;
- }
- ArrayList l = new ArrayList();
- while (it.hasNext()) {
- Node propNode = it.nextNode();
- PropDef propDef = new PropDef(propNode, ntName, nsResolver);
- l.add(propDef);
- }
- setPropertyDefs((PropDef[])l.toArray(new PropDef[l.size()]));
}
}
1.5 +17 -57 jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/nodetype/NodeTypeRegistry.java
Index: NodeTypeRegistry.java
===================================================================
RCS file: /home/cvs/jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/nodetype/NodeTypeRegistry.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- NodeTypeRegistry.java 29 Jun 2004 17:11:47 -0000 1.4
+++ NodeTypeRegistry.java 30 Jun 2004 14:39:37 -0000 1.5
@@ -1,6 +1,6 @@
/*
* $Id$
- *
+ *
* Copyright 2002-2004 Day Management AG, Switzerland.
*
* Licensed under the Day RI License, Version 2.0 (the "License"),
@@ -31,7 +31,6 @@
import org.apache.slide.jcr.fs.FileSystemException;
import org.apache.slide.jcr.fs.FileSystemResource;
-import javax.jcr.Node;
import javax.jcr.PropertyType;
import javax.jcr.RepositoryException;
import javax.jcr.nodetype.ConstraintViolationException;
@@ -58,13 +57,17 @@
// nt:base
public static final QName NT_BASE =
new QName(NamespaceRegistryImpl.NS_NT_URI, "base");
-
+ // nt:hierarchyNode
+ public static final QName NT_HIERARCHYNODE =
+ new QName(NamespaceRegistryImpl.NS_NT_URI, "hierarchyNode");
// mix:referenceable
public static final QName MIX_REFERENCEABLE =
new QName(NamespaceRegistryImpl.NS_MIX_URI, "referenceable");
- private static final String DEFAULT_NODETYPES_RESOURCE_PATH =
- "org/apache/slide/jcr/core/nodetype/nodetypes.xml";
+ private static final String BUILTIN_NODETYPES_RESOURCE_PATH =
+ "org/apache/slide/jcr/core/nodetype/builtin_nodetypes.xml";
+
+ private static final String CUSTOM_NODETYPES_RESOURCE_NAME = "custom_nodetypes.xml";
// file system where node type registrations are persisted
private final FileSystem ntStore;
@@ -119,7 +122,7 @@
throws RepositoryException {
this.nsReg = nsReg;
this.ntStore = ntStore;
- customNodeTypesResource = new FileSystemResource(this.ntStore, "custom_nodetypes.xml");
+ customNodeTypesResource = new FileSystemResource(this.ntStore, CUSTOM_NODETYPES_RESOURCE_NAME);
try {
// make sure path to resource exists
if (!customNodeTypesResource.exists()) {
@@ -138,15 +141,15 @@
builtInNTDefs = new NodeTypeDefStore();
InputStream in = null;
try {
- in = getClass().getClassLoader().getResourceAsStream(DEFAULT_NODETYPES_RESOURCE_PATH);
+ in = getClass().getClassLoader().getResourceAsStream(BUILTIN_NODETYPES_RESOURCE_PATH);
builtInNTDefs.load(in);
internalRegister(builtInNTDefs.all());
} catch (IOException ioe) {
- String error = "internal error: failed to read built-in node type definitions stored in " + DEFAULT_NODETYPES_RESOURCE_PATH;
+ String error = "internal error: failed to read built-in node type definitions stored in " + BUILTIN_NODETYPES_RESOURCE_PATH;
log.error(error);
throw new RepositoryException(error);
} catch (InvalidNodeTypeDefException intde) {
- String error = "internal error: invalid built-in node type definition stored in " + DEFAULT_NODETYPES_RESOURCE_PATH;
+ String error = "internal error: invalid built-in node type definition stored in " + BUILTIN_NODETYPES_RESOURCE_PATH;
log.error(error);
throw new RepositoryException(error);
} finally {
@@ -202,10 +205,11 @@
* <p/>
* Note that in the case an exception is thrown, some node types might have
* been nevertheless successfully registered.
- * @see #registerNodeType
+ *
* @param ntDefs collection of <code>NodeTypeDef</code> objects
* @throws InvalidNodeTypeDefException
* @throws RepositoryException
+ * @see #registerNodeType
*/
synchronized private void internalRegister(Collection ntDefs)
throws InvalidNodeTypeDefException, RepositoryException {
@@ -782,7 +786,7 @@
* node type constraints in the same child-node definition</li>
* </ul>
*
- * @param ntd the definition of the new node type
+ * @param ntd the definition of the new node type
* @return an <code>EffectiveNodeType</code> instance
* @throws InvalidNodeTypeDefException
* @throws RepositoryException
@@ -812,27 +816,6 @@
}
/**
- * todo move to separate helper class outside of ri
- *
- * Register the node type defined by the given {@link Node}.
- *
- * @param node <code>Node</coding> defining the node type to be registered.
- * @return an <code>EffectiveNodeType</code> instance
- * @throws InvalidNodeTypeDefException
- * @throws RepositoryException if the registration fails.
- * @see #registerNodeType(NodeTypeDef)
- */
- synchronized public EffectiveNodeType registerNodeType(Node node)
- throws InvalidNodeTypeDefException, RepositoryException {
- try {
- return registerNodeType(new NodeTypeDef(node, nsReg));
- } catch (InvalidConstraintException e) {
- throw new InvalidNodeTypeDefException(e.getMessage());
- }
- }
-
- /**
- *
* @param name
* @throws NoSuchNodeTypeException
* @throws RepositoryException
@@ -885,7 +868,6 @@
}
/**
- *
* @param ntd
* @return
* @throws NoSuchNodeTypeException
@@ -918,28 +900,6 @@
* - what else?
*/
throw new RepositoryException("not yet implemented");
- }
-
- /**
- * todo move to separate helper class outside of ri
- *
- * Permanently unregister the node type that is defined by the given <code>Node</code>.
- *
- * @param node Node object holding the definition of the node type to be unregistered.
- * @throws NoSuchNodeTypeException
- * @throws RepositoryException if unregistering the node type failed.
- */
- synchronized public void unregisterNodeType(Node node)
- throws NoSuchNodeTypeException, RepositoryException {
- try {
- NodeTypeDef ntd = new NodeTypeDef(node, nsReg);
- // if updating the resource succeeded, unregister the node type
- unregisterNodeType(ntd.getName());
- } catch (InvalidConstraintException ice) {
- String msg = "Failed to unregister node type '" + node.getPath() + "'";
- log.error(msg, ice);
- throw new RepositoryException(msg, ice);
- }
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: slide-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-dev-help@jakarta.apache.org