You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by md...@apache.org on 2011/09/01 13:52:13 UTC
svn commit: r1164026 [6/11] - in
/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi:
./ config/ hierarchy/ lock/ nodetype/ observation/ operation/ query/
security/ state/ util/ version/ xml/
Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/DefinitionValidator.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/DefinitionValidator.java?rev=1164026&r1=1164025&r2=1164026&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/DefinitionValidator.java (original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/DefinitionValidator.java Thu Sep 1 11:52:08 2011
@@ -47,8 +47,7 @@ import java.util.Iterator;
* <code>DefinitionValidator</code>...
*/
class DefinitionValidator {
-
- private static Logger log = LoggerFactory.getLogger(DefinitionValidator.class);
+ private static final Logger log = LoggerFactory.getLogger(DefinitionValidator.class);
private final EffectiveNodeTypeProvider entProvider;
private final NamespaceRegistry nsRegistry;
@@ -69,8 +68,8 @@ class DefinitionValidator {
* @throws RepositoryException
*/
public Map<QNodeTypeDefinition, EffectiveNodeType> validateNodeTypeDefs(Collection<QNodeTypeDefinition> ntDefs,
- Map<Name, QNodeTypeDefinition> validatedDefs)
- throws InvalidNodeTypeDefinitionException, RepositoryException {
+ Map<Name, QNodeTypeDefinition> validatedDefs) throws RepositoryException {
+
// tmp. map containing names/defs of validated nodetypes
Map<Name, QNodeTypeDefinition> tmpMap = new HashMap<Name, QNodeTypeDefinition>(validatedDefs);
for (QNodeTypeDefinition ntd : ntDefs) {
@@ -83,15 +82,14 @@ class DefinitionValidator {
// iterate over definitions until there are no more definitions with
// unresolved (i.e. unregistered) dependencies or an error occurs;
-
- int count = -1; // number of validated nt's per iteration
- while (list.size() > 0 && count != 0) {
+ int count = -1; // number of validated nt per iteration
+ while (!list.isEmpty() && count != 0) {
count = 0;
Iterator<QNodeTypeDefinition> iterator = list.iterator();
while (iterator.hasNext()) {
QNodeTypeDefinition ntd = iterator.next();
// check if definition has unresolved dependencies
- /* Note: don't compared to 'registered' nodetypes since registr. is performed later on */
+ // Note: don't compared to 'registered' nodetypes since registration is performed later on
Collection<Name> dependencies = ntd.getDependencies();
if (tmpMap.keySet().containsAll(dependencies)) {
EffectiveNodeType ent = validateNodeTypeDef(ntd, tmpMap);
@@ -103,13 +101,12 @@ class DefinitionValidator {
}
}
}
- if (list.size() > 0) {
- StringBuffer msg = new StringBuffer();
+ if (!list.isEmpty()) {
+ StringBuilder msg = new StringBuilder();
msg.append("the following node types could not be registered because of unresolvable dependencies: ");
- Iterator<QNodeTypeDefinition> iterator = list.iterator();
- while (iterator.hasNext()) {
- msg.append(iterator.next().getName());
- msg.append(" ");
+ for (QNodeTypeDefinition aList : list) {
+ msg.append(aList.getName());
+ msg.append(' ');
}
log.error(msg.toString());
throw new InvalidNodeTypeDefinitionException(msg.toString());
@@ -128,15 +125,12 @@ class DefinitionValidator {
* @throws RepositoryException
*/
public EffectiveNodeType validateNodeTypeDef(QNodeTypeDefinition ntDef, Map<Name, QNodeTypeDefinition> validatedDefs)
- throws InvalidNodeTypeDefinitionException, RepositoryException {
- /**
- * the effective (i.e. merged and resolved) node type resulting from
- * the specified node type definition;
- * the effective node type will finally be created after the definition
- * has been verified and checked for conflicts etc.; in some cases it
- * will be created already at an earlier stage during the validation
- * of child node definitions
- */
+ throws RepositoryException {
+
+ // the effective (i.e. merged and resolved) node type resulting from the specified node
+ // type definition; the effective node type will finally be created after the definition
+ // has been verified and checked for conflicts etc.; in some cases it will be created
+ // already at an earlier stage during the validation of child node definitions
EffectiveNodeType ent = null;
Name name = ntDef.getName();
@@ -150,46 +144,37 @@ class DefinitionValidator {
// validate supertypes
Name[] supertypes = ntDef.getSupertypes();
if (supertypes.length > 0) {
- for (int i = 0; i < supertypes.length; i++) {
- checkNamespace(supertypes[i]);
- /**
- * simple check for infinite recursion
- * (won't trap recursion on a deeper inheritance level)
- */
- if (name.equals(supertypes[i])) {
+ for (Name supertype : supertypes) {
+ checkNamespace(supertype);
+
+ // simple check for infinite recursion (won't trap recursion on a deeper inheritance level)
+ if (name.equals(supertype)) {
String msg = "[" + name + "] invalid supertype: "
- + supertypes[i] + " (infinite recursion))";
+ + supertype + " (infinite recursion))";
log.debug(msg);
throw new InvalidNodeTypeDefinitionException(msg);
}
- /* compare to given nt-name set and not to registered nodetypes */
- if (!validatedDefs.containsKey(supertypes[i])) {
- String msg = "[" + name + "] invalid supertype: " + supertypes[i];
+
+ // compare to given nt-name set and not to registered nodetypes
+ if (!validatedDefs.containsKey(supertype)) {
+ String msg = "[" + name + "] invalid supertype: " + supertype;
log.debug(msg);
throw new InvalidNodeTypeDefinitionException(msg);
}
}
- /**
- * check for circularity in inheritance chain
- * ('a' extends 'b' extends 'a')
- */
+ // check for circularity in inheritance chain
+ // ('a' extends 'b' extends 'a')
Stack<Name> inheritanceChain = new Stack<Name>();
inheritanceChain.push(name);
checkForCircularInheritance(supertypes, inheritanceChain, validatedDefs);
}
- /**
- * note that infinite recursion through inheritance is automatically
- * being checked by the following call to getEffectiveNodeType()
- * as it's impossible to register a node type definition which
- * references a supertype that isn't registered yet...
- */
-
- /**
- * build effective (i.e. merged and resolved) node type from supertypes
- * and check for conflicts
- */
+ // note that infinite recursion through inheritance is automatically being checked by the following
+ // call to getEffectiveNodeType() as it's impossible to register a node type definition which
+ // references a supertype that isn't registered yet...
+
+ // build effective (i.e. merged and resolved) node type from supertypes and check for conflicts
if (supertypes.length > 0) {
try {
EffectiveNodeType est = entProvider.getEffectiveNodeType(supertypes, validatedDefs);
@@ -224,57 +209,50 @@ class DefinitionValidator {
// validate property definitions
QPropertyDefinition[] pda = ntDef.getPropertyDefs();
- for (int i = 0; i < pda.length; i++) {
- QPropertyDefinition pd = pda[i];
- /**
- * sanity check:
- * make sure declaring node type matches name of node type definition
- */
+ for (QPropertyDefinition pd : pda) {
+ // sanity check: make sure declaring node type matches name of node type definition
if (!name.equals(pd.getDeclaringNodeType())) {
- String msg = "[" + name + "#" + pd.getName() + "] invalid declaring node type specified";
+ String msg = "[" + name + '#' + pd.getName() + "] invalid declaring node type specified";
log.debug(msg);
throw new InvalidNodeTypeDefinitionException(msg);
}
checkNamespace(pd.getName());
+
// check that auto-created properties specify a name
if (pd.definesResidual() && pd.isAutoCreated()) {
- String msg = "[" + name + "#" + pd.getName() + "] auto-created properties must specify a name";
+ String msg = "[" + name + '#' + pd.getName() + "] auto-created properties must specify a name";
log.debug(msg);
throw new InvalidNodeTypeDefinitionException(msg);
}
+
// check that auto-created properties specify a type
if (pd.getRequiredType() == PropertyType.UNDEFINED && pd.isAutoCreated()) {
- String msg = "[" + name + "#" + pd.getName() + "] auto-created properties must specify a type";
+ String msg = "[" + name + '#' + pd.getName() + "] auto-created properties must specify a type";
log.debug(msg);
throw new InvalidNodeTypeDefinitionException(msg);
}
- /* check default values:
- * make sure type of value is consistent with required property type
- * Note: default internal values are built from the required type,
- * thus check for match with pd.getRequiredType is redundant.
- */
+
+ // check default values: make sure type of value is consistent with required property type
+ // Note: default internal values are built from the required type, thus check for match with
+ // pd.getRequiredType is redundant.
QValue[] defVals = pd.getDefaultValues();
- /* check that default values satisfy value constraints.
- * Note however, that no check is performed if autocreated property-
- * definitions define a default value. JSR170 does not require this.
- */
+ // check that default values satisfy value constraints. Note however, that no check is performed
+ // if autocreated property- definitions define a default value. JSR170 does not require this.
ValueConstraint.checkValueConstraints(pd, defVals);
- /* ReferenceConstraint:
- * the specified node type must be registered, with one notable
- * exception: the node type just being registered
- */
+ // ReferenceConstraint: the specified node type must be registered, with one notable
+ // exception: the node type just being registered
QValueConstraint[] constraints = pd.getValueConstraints();
if (constraints != null && constraints.length > 0) {
if (pd.getRequiredType() == PropertyType.REFERENCE) {
for (QValueConstraint constraint : constraints) {
- // TODO improve. don't rely on a specific factory impl
+ // TODO improve. Don't rely on a specific factory implementation
Name ntName = NameFactoryImpl.getInstance().create(constraint.getString());
- /* compare to given ntd map and not registered nts only */
+ // compare to given ntd map and not registered nts only
if (!name.equals(ntName) && !validatedDefs.containsKey(ntName)) {
- String msg = "[" + name + "#" + pd.getName()
+ String msg = "[" + name + '#' + pd.getName()
+ "] invalid REFERENCE value constraint '"
+ ntName + "' (unknown node type)";
log.debug(msg);
@@ -287,11 +265,10 @@ class DefinitionValidator {
// validate child-node definitions
QNodeDefinition[] cnda = ntDef.getChildNodeDefs();
- for (int i = 0; i < cnda.length; i++) {
- QNodeDefinition cnd = cnda[i];
- /* make sure declaring node type matches name of node type definition */
+ for (QNodeDefinition cnd : cnda) {
+ // make sure declaring node type matches name of node type definition
if (!name.equals(cnd.getDeclaringNodeType())) {
- String msg = "[" + name + "#" + cnd.getName()
+ String msg = "[" + name + '#' + cnd.getName()
+ "] invalid declaring node type specified";
log.debug(msg);
throw new InvalidNodeTypeDefinitionException(msg);
@@ -299,7 +276,7 @@ class DefinitionValidator {
checkNamespace(cnd.getName());
// check that auto-created child-nodes specify a name
if (cnd.definesResidual() && cnd.isAutoCreated()) {
- String msg = "[" + name + "#" + cnd.getName()
+ String msg = "[" + name + '#' + cnd.getName()
+ "] auto-created child-nodes must specify a name";
log.debug(msg);
throw new InvalidNodeTypeDefinitionException(msg);
@@ -307,7 +284,7 @@ class DefinitionValidator {
// check that auto-created child-nodes specify a default primary type
if (cnd.getDefaultPrimaryType() == null
&& cnd.isAutoCreated()) {
- String msg = "[" + name + "#" + cnd.getName()
+ String msg = "[" + name + '#' + cnd.getName()
+ "] auto-created child-nodes must specify a default primary type";
log.debug(msg);
throw new InvalidNodeTypeDefinitionException(msg);
@@ -322,49 +299,44 @@ class DefinitionValidator {
if (name.equals(dpt)) {
referenceToSelf = true;
}
- /**
- * the default primary type must be registered, with one notable
- * exception: the node type just being registered
- */
+
+ // the default primary type must be registered, with one notable
+ // exception: the node type just being registered
if (!name.equals(dpt) && !validatedDefs.containsKey(dpt)) {
- String msg = "[" + name + "#" + cnd.getName()
- + "] invalid default primary type '" + dpt + "'";
+ String msg = "[" + name + '#' + cnd.getName()
+ + "] invalid default primary type '" + dpt + '\'';
log.debug(msg);
throw new InvalidNodeTypeDefinitionException(msg);
}
- /**
- * build effective (i.e. merged and resolved) node type from
- * default primary type and check for conflicts
- */
+
+ // build effective (i.e. merged and resolved) node type from
+ // default primary type and check for conflicts
try {
- if (!referenceToSelf) {
- defaultENT = entProvider.getEffectiveNodeType(new Name[] {dpt}, validatedDefs);
- } else {
- /**
- * the default primary type is identical with the node
- * type just being registered; we have to instantiate it
- * 'manually'
- */
+ if (referenceToSelf) {
+ // the default primary type is identical with the node type just being registered;
+ // we have to instantiate it 'manually'
ent = entProvider.getEffectiveNodeType(ntDef, validatedDefs);
defaultENT = ent;
+ } else {
+ defaultENT = entProvider.getEffectiveNodeType(new Name[]{dpt}, validatedDefs);
}
if (cnd.isAutoCreated()) {
- /**
- * check for circularity through default primary types
- * of auto-created child nodes (node type 'a' defines
- * auto-created child node with default primary type 'a')
- */
+ // check for circularity through default primary types
+ // of auto-created child nodes (node type 'a' defines
+ // auto-created child node with default primary type 'a')
Stack<Name> definingNTs = new Stack<Name>();
definingNTs.push(name);
checkForCircularNodeAutoCreation(defaultENT, definingNTs, validatedDefs);
}
- } catch (ConstraintViolationException e) {
- String msg = "[" + name + "#" + cnd.getName()
+ }
+ catch (ConstraintViolationException e) {
+ String msg = "[" + name + '#' + cnd.getName()
+ "] failed to validate default primary type";
log.debug(msg);
throw new InvalidNodeTypeDefinitionException(msg, e);
- } catch (NoSuchNodeTypeException e) {
- String msg = "[" + name + "#" + cnd.getName()
+ }
+ catch (NoSuchNodeTypeException e) {
+ String msg = "[" + name + '#' + cnd.getName()
+ "] failed to validate default primary type";
log.debug(msg);
throw new InvalidNodeTypeDefinitionException(msg, e);
@@ -374,62 +346,54 @@ class DefinitionValidator {
// check required primary types
Name[] reqTypes = cnd.getRequiredPrimaryTypes();
if (reqTypes != null && reqTypes.length > 0) {
- for (int n = 0; n < reqTypes.length; n++) {
- Name rpt = reqTypes[n];
+ for (Name rpt : reqTypes) {
checkNamespace(rpt);
referenceToSelf = false;
- /**
- * check if this node type specifies itself as required
- * primary type
- */
+ // check if this node type specifies itself as required primary type
if (name.equals(rpt)) {
referenceToSelf = true;
}
- /**
- * the required primary type must be registered, with one
- * notable exception: the node type just being registered
- */
+
+ // the required primary type must be registered, with one
+ // notable exception: the node type just being registered
if (!name.equals(rpt) && !validatedDefs.containsKey(rpt)) {
- String msg = "[" + name + "#" + cnd.getName()
+ String msg = "[" + name + '#' + cnd.getName()
+ "] invalid required primary type: " + rpt;
log.debug(msg);
throw new InvalidNodeTypeDefinitionException(msg);
}
- /**
- * check if default primary type satisfies the required
- * primary type constraint
- */
+
+ // check if default primary type satisfies the required
+ // primary type constraint
if (defaultENT != null && !defaultENT.includesNodeType(rpt)) {
- String msg = "[" + name + "#" + cnd.getName()
+ String msg = "[" + name + '#' + cnd.getName()
+ "] default primary type does not satisfy required primary type constraint "
+ rpt;
log.debug(msg);
throw new InvalidNodeTypeDefinitionException(msg);
}
- /**
- * build effective (i.e. merged and resolved) node type from
- * required primary type constraint and check for conflicts
- */
+
+ // build effective (i.e. merged and resolved) node type from
+ // required primary type constraint and check for conflicts
try {
- if (!referenceToSelf) {
- entProvider.getEffectiveNodeType(new Name[] {rpt}, validatedDefs);
- } else {
- /**
- * the required primary type is identical with the
- * node type just being registered; we have to
- * instantiate it 'manually'
- */
+ if (referenceToSelf) {
+ // the required primary type is identical with the node type just being
+ // registered; we have to instantiate it 'manually'
if (ent == null) {
ent = entProvider.getEffectiveNodeType(ntDef, validatedDefs);
}
+ } else {
+ entProvider.getEffectiveNodeType(new Name[]{rpt}, validatedDefs);
}
- } catch (ConstraintViolationException e) {
- String msg = "[" + name + "#" + cnd.getName()
+ }
+ catch (ConstraintViolationException e) {
+ String msg = "[" + name + '#' + cnd.getName()
+ "] failed to validate required primary type constraint";
log.debug(msg);
throw new InvalidNodeTypeDefinitionException(msg, e);
- } catch (NoSuchNodeTypeException e) {
- String msg = "[" + name + "#" + cnd.getName()
+ }
+ catch (NoSuchNodeTypeException e) {
+ String msg = "[" + name + '#' + cnd.getName()
+ "] failed to validate required primary type constraint";
log.debug(msg);
throw new InvalidNodeTypeDefinitionException(msg, e);
@@ -438,11 +402,8 @@ class DefinitionValidator {
}
}
- /**
- * now build effective (i.e. merged and resolved) node type from
- * this node type definition; this will potentially detect more
- * conflicts or problems
- */
+ // now build effective (i.e. merged and resolved) node type from this node type definition;
+ // this will potentially detect more conflicts or problems
if (ent == null) {
try {
ent = entProvider.getEffectiveNodeType(ntDef, validatedDefs);
@@ -460,20 +421,19 @@ class DefinitionValidator {
}
/**
- *
* @param supertypes
* @param inheritanceChain
* @param ntdMap
* @throws InvalidNodeTypeDefinitionException
* @throws RepositoryException
*/
- private void checkForCircularInheritance(Name[] supertypes, Stack<Name> inheritanceChain, Map<Name, QNodeTypeDefinition> ntdMap)
- throws InvalidNodeTypeDefinitionException, RepositoryException {
- for (int i = 0; i < supertypes.length; i++) {
- Name stName = supertypes[i];
+ private static void checkForCircularInheritance(Name[] supertypes, Stack<Name> inheritanceChain,
+ Map<Name, QNodeTypeDefinition> ntdMap) throws RepositoryException {
+
+ for (Name stName : supertypes) {
int pos = inheritanceChain.lastIndexOf(stName);
if (pos >= 0) {
- StringBuffer buf = new StringBuffer();
+ StringBuilder buf = new StringBuilder();
for (int j = 0; j < inheritanceChain.size(); j++) {
if (j == pos) {
buf.append("--> ");
@@ -508,16 +468,16 @@ class DefinitionValidator {
* @throws InvalidNodeTypeDefinitionException
*/
private void checkForCircularNodeAutoCreation(EffectiveNodeType childNodeENT,
- Stack<Name> definingParentNTs, Map<Name, QNodeTypeDefinition> ntdMap)
- throws InvalidNodeTypeDefinitionException {
+ Stack<Name> definingParentNTs, Map<Name, QNodeTypeDefinition> ntdMap)
+ throws InvalidNodeTypeDefinitionException {
+
// check for circularity through default node types of auto-created child nodes
// (node type 'a' defines auto-created child node with default node type 'a')
Name[] childNodeNTs = childNodeENT.getAllNodeTypes();
- for (int i = 0; i < childNodeNTs.length; i++) {
- Name nt = childNodeNTs[i];
+ for (Name nt : childNodeNTs) {
int pos = definingParentNTs.lastIndexOf(nt);
if (pos >= 0) {
- StringBuffer buf = new StringBuffer();
+ StringBuilder buf = new StringBuilder();
for (int j = 0; j < definingParentNTs.size(); j++) {
if (j == pos) {
buf.append("--> ");
@@ -530,28 +490,30 @@ class DefinitionValidator {
buf.append("node type ");
buf.append(nt);
throw new InvalidNodeTypeDefinitionException("circular node auto-creation detected: "
- + buf.toString());
+ + buf.toString());
}
}
QNodeDefinition[] nodeDefs = childNodeENT.getAutoCreateQNodeDefinitions();
- for (int i = 0; i < nodeDefs.length; i++) {
- Name dnt = nodeDefs[i].getDefaultPrimaryType();
- Name definingNT = nodeDefs[i].getDeclaringNodeType();
+ for (QNodeDefinition nodeDef : nodeDefs) {
+ Name dnt = nodeDef.getDefaultPrimaryType();
+ Name definingNT = nodeDef.getDeclaringNodeType();
try {
if (dnt != null) {
// check recursively
definingParentNTs.push(definingNT);
- EffectiveNodeType ent = entProvider.getEffectiveNodeType(new Name[] {dnt}, ntdMap);
+ EffectiveNodeType ent = entProvider.getEffectiveNodeType(new Name[]{dnt}, ntdMap);
checkForCircularNodeAutoCreation(ent, definingParentNTs, ntdMap);
definingParentNTs.pop();
}
- } catch (NoSuchNodeTypeException e) {
- String msg = definingNT + " defines invalid default node type for child node " + nodeDefs[i].getName();
+ }
+ catch (NoSuchNodeTypeException e) {
+ String msg = definingNT + " defines invalid default node type for child node " + nodeDef.getName();
log.debug(msg);
throw new InvalidNodeTypeDefinitionException(msg, e);
- } catch (ConstraintViolationException e) {
- String msg = definingNT + " defines invalid default node type for child node " + nodeDefs[i].getName();
+ }
+ catch (ConstraintViolationException e) {
+ String msg = definingNT + " defines invalid default node type for child node " + nodeDef.getName();
log.debug(msg);
throw new InvalidNodeTypeDefinitionException(msg, e);
}
Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeType.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeType.java?rev=1164026&r1=1164025&r2=1164026&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeType.java (original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeType.java Thu Sep 1 11:52:08 2011
@@ -29,11 +29,11 @@ import javax.jcr.nodetype.NoSuchNodeType
*/
public interface EffectiveNodeType {
- public Name[] getAllNodeTypes();
+ Name[] getAllNodeTypes();
- public Name[] getInheritedNodeTypes();
+ Name[] getInheritedNodeTypes();
- public Name[] getMergedNodeTypes();
+ Name[] getMergedNodeTypes();
/**
* Determines whether this effective node type representation includes
@@ -43,7 +43,7 @@ public interface EffectiveNodeType {
* @return <code>true</code> if the given node type is included, otherwise
* <code>false</code>
*/
- public boolean includesNodeType(Name nodeTypeName);
+ boolean includesNodeType(Name nodeTypeName);
/**
* Determines whether this effective node type supports adding
@@ -52,7 +52,7 @@ public interface EffectiveNodeType {
* @return <code>true</code> if the mixin type is supported, otherwise
* <code>false</code>
*/
- public boolean supportsMixin(Name mixin);
+ boolean supportsMixin(Name mixin);
/**
* Determines whether this effective node type representation includes
@@ -62,34 +62,34 @@ public interface EffectiveNodeType {
* @return <code>true</code> if all of the given node types are included,
* otherwise <code>false</code>
*/
- public boolean includesNodeTypes(Name[] nodeTypeNames);
+ boolean includesNodeTypes(Name[] nodeTypeNames);
- public QNodeDefinition[] getAllQNodeDefinitions();
+ QNodeDefinition[] getAllQNodeDefinitions();
- public QPropertyDefinition[] getAllQPropertyDefinitions();
+ QPropertyDefinition[] getAllQPropertyDefinitions();
- public QNodeDefinition[] getAutoCreateQNodeDefinitions();
+ QNodeDefinition[] getAutoCreateQNodeDefinitions();
- public QPropertyDefinition[] getAutoCreateQPropertyDefinitions();
+ QPropertyDefinition[] getAutoCreateQPropertyDefinitions();
- public QNodeDefinition[] getMandatoryQNodeDefinitions();
+ QNodeDefinition[] getMandatoryQNodeDefinitions();
- public QPropertyDefinition[] getMandatoryQPropertyDefinitions();
+ QPropertyDefinition[] getMandatoryQPropertyDefinitions();
- public QNodeDefinition[] getNamedQNodeDefinitions(Name name);
+ QNodeDefinition[] getNamedQNodeDefinitions(Name name);
- public QPropertyDefinition[] getNamedQPropertyDefinitions(Name name);
+ QPropertyDefinition[] getNamedQPropertyDefinitions(Name name);
- public QNodeDefinition[] getUnnamedQNodeDefinitions();
+ QNodeDefinition[] getUnnamedQNodeDefinitions();
- public QPropertyDefinition[] getUnnamedQPropertyDefinitions();
+ QPropertyDefinition[] getUnnamedQPropertyDefinitions();
/**
* @param name
* @param definitionProvider
* @throws ConstraintViolationException
*/
- public void checkAddNodeConstraints(Name name, ItemDefinitionProvider definitionProvider)
+ void checkAddNodeConstraints(Name name, ItemDefinitionProvider definitionProvider)
throws ConstraintViolationException;
/**
@@ -97,7 +97,7 @@ public interface EffectiveNodeType {
* @param nodeTypeDefinition
*@param definitionProvider @throws ConstraintViolationException @throws NoSuchNodeTypeException
*/
- public void checkAddNodeConstraints(Name name, QNodeTypeDefinition nodeTypeDefinition, ItemDefinitionProvider definitionProvider)
+ void checkAddNodeConstraints(Name name, QNodeTypeDefinition nodeTypeDefinition, ItemDefinitionProvider definitionProvider)
throws ConstraintViolationException, NoSuchNodeTypeException;
/**
@@ -106,7 +106,7 @@ public interface EffectiveNodeType {
* @deprecated Use {@link #hasRemoveNodeConstraint(Name)} and
* {@link #hasRemovePropertyConstraint(Name)} respectively.
*/
- public void checkRemoveItemConstraints(Name name) throws ConstraintViolationException;
+ void checkRemoveItemConstraints(Name name) throws ConstraintViolationException;
/**
* Returns <code>true</code> if a single node definition matching the
@@ -116,7 +116,7 @@ public interface EffectiveNodeType {
* @return <code>true</code> if a single node definition matching the
* specified <code>nodeName</code> is either mandatory or protected.
*/
- public boolean hasRemoveNodeConstraint(Name nodeName);
+ boolean hasRemoveNodeConstraint(Name nodeName);
/**
* Returns <code>true</code> if a single property definition matching the
@@ -126,5 +126,5 @@ public interface EffectiveNodeType {
* @return <code>true</code> if a single property definition matching the
* specified <code>propertyName</code> is either mandatory or protected.
*/
- public boolean hasRemovePropertyConstraint(Name propertyName);
+ boolean hasRemovePropertyConstraint(Name propertyName);
}
Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeTypeCache.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeTypeCache.java?rev=1164026&r1=1164025&r2=1164026&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeTypeCache.java (original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeTypeCache.java Thu Sep 1 11:52:08 2011
@@ -75,7 +75,7 @@ public interface EffectiveNodeTypeCache
* <code>true</code>. If an already cached effective node type matches the
* key it is returned.
*
- * @param key the key for which the subkey is to be searched
+ * @param key the key for which the sub-key is to be searched
* @return the best key or <code>null</code> if no key could be found.
*/
Key findBest(Key key);
Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeTypeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeTypeImpl.java?rev=1164026&r1=1164025&r2=1164026&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeTypeImpl.java (original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeTypeImpl.java Thu Sep 1 11:52:08 2011
@@ -16,8 +16,19 @@
*/
package org.apache.jackrabbit.jcr2spi.nodetype;
+import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.QItemDefinition;
+import org.apache.jackrabbit.spi.QNodeDefinition;
+import org.apache.jackrabbit.spi.QNodeTypeDefinition;
+import org.apache.jackrabbit.spi.QPropertyDefinition;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.jcr.nodetype.ConstraintViolationException;
+import javax.jcr.nodetype.NoSuchNodeTypeException;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -25,17 +36,6 @@ import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
-import javax.jcr.nodetype.ConstraintViolationException;
-import javax.jcr.nodetype.NoSuchNodeTypeException;
-
-import org.apache.jackrabbit.spi.Name;
-import org.apache.jackrabbit.spi.QItemDefinition;
-import org.apache.jackrabbit.spi.QNodeDefinition;
-import org.apache.jackrabbit.spi.QNodeTypeDefinition;
-import org.apache.jackrabbit.spi.QPropertyDefinition;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
/**
* An <code>EffectiveNodeType</code> represents one or more
* <code>NodeType</code>s as one 'effective' node type where inheritance
@@ -44,28 +44,30 @@ import org.slf4j.LoggerFactory;
* Instances of <code>EffectiveNodeType</code> are immutable.
*/
public class EffectiveNodeTypeImpl implements Cloneable, EffectiveNodeType {
- private static Logger log = LoggerFactory.getLogger(EffectiveNodeTypeImpl.class);
+ private static final Logger log = LoggerFactory.getLogger(EffectiveNodeTypeImpl.class);
- // list of explicitly aggregated {i.e. merged) node types
+ /** list of explicitly aggregated {i.e. merged) node types */
private final TreeSet<Name> mergedNodeTypes = new TreeSet<Name>();
- // list of implicitly aggregated {through inheritance) node types
+
+ /** list of implicitly aggregated {through inheritance) node types */
private final TreeSet<Name> inheritedNodeTypes = new TreeSet<Name>();
- // list of all either explicitly (through aggregation) or implicitly
- // (through inheritance) included node types.
+
+ /** list of all either explicitly (through aggregation) or implicitly (through inheritance) included node types. */
private final TreeSet<Name> allNodeTypes = new TreeSet<Name>();
- // map of named item definitions (maps name to list of definitions)
+
+ /** map of named item definitions (maps name to list of definitions) */
private final Map<Name, List<QItemDefinition>> namedItemDefs = new HashMap<Name, List<QItemDefinition>>();
- // list of unnamed item definitions (i.e. residual definitions)
+
+ /** list of unnamed item definitions (i.e. residual definitions) */
private final List<QItemDefinition> unnamedItemDefs = new ArrayList<QItemDefinition>();
- // (optional) set of additional mixins supported on node type
+
+ /** (optional) set of additional mixins supported on node type */
private Set<Name> supportedMixins;
- /**
- * constructor.
- */
- EffectiveNodeTypeImpl(TreeSet<Name> mergedNodeTypes, TreeSet<Name> inheritedNodeTypes,
- TreeSet<Name> allNodeTypes, Map<Name, List<QItemDefinition>> namedItemDefs,
- List<QItemDefinition> unnamedItemDefs, Set<Name> supportedMixins) {
+ EffectiveNodeTypeImpl(TreeSet<Name> mergedNodeTypes, TreeSet<Name> inheritedNodeTypes, TreeSet<Name> allNodeTypes,
+ Map<Name, List<QItemDefinition>> namedItemDefs, List<QItemDefinition> unnamedItemDefs,
+ Set<Name> supportedMixins) {
+
this.mergedNodeTypes.addAll(mergedNodeTypes);
this.inheritedNodeTypes.addAll(inheritedNodeTypes);
this.allNodeTypes.addAll(allNodeTypes);
@@ -81,273 +83,241 @@ public class EffectiveNodeTypeImpl imple
}
//--------------------------------------------------< EffectiveNodeType >---
- /**
- * @see EffectiveNodeType#getInheritedNodeTypes()
- */
+
+ @Override
public Name[] getInheritedNodeTypes() {
return inheritedNodeTypes.toArray(new Name[inheritedNodeTypes.size()]);
}
- /**
- * @see EffectiveNodeType#getAllNodeTypes()
- */
+ @Override
public Name[] getAllNodeTypes() {
return allNodeTypes.toArray(new Name[allNodeTypes.size()]);
}
- /**
- * @see EffectiveNodeType#getMergedNodeTypes()
- */
+ @Override
public Name[] getMergedNodeTypes() {
return mergedNodeTypes.toArray(new Name[mergedNodeTypes.size()]);
}
- /**
- * @see EffectiveNodeType#getAllQNodeDefinitions()
- */
+ @Override
public QNodeDefinition[] getAllQNodeDefinitions() {
- if (namedItemDefs.size() == 0 && unnamedItemDefs.size() == 0) {
+ if (namedItemDefs.isEmpty() && unnamedItemDefs.isEmpty()) {
return QNodeDefinition.EMPTY_ARRAY;
}
- ArrayList<QItemDefinition> defs = new ArrayList<QItemDefinition>(namedItemDefs.size() + unnamedItemDefs.size());
+ ArrayList<QNodeDefinition> defs = new ArrayList<QNodeDefinition>(namedItemDefs.size() + unnamedItemDefs.size());
for (QItemDefinition qDef : unnamedItemDefs) {
if (qDef.definesNode()) {
- defs.add(qDef);
+ defs.add((QNodeDefinition) qDef);
}
}
for (List<QItemDefinition> list : namedItemDefs.values()) {
for (QItemDefinition qDef : list) {
if (qDef.definesNode()) {
- defs.add(qDef);
+ defs.add((QNodeDefinition) qDef);
}
}
}
- if (defs.size() == 0) {
+ if (defs.isEmpty()) {
return QNodeDefinition.EMPTY_ARRAY;
}
return defs.toArray(new QNodeDefinition[defs.size()]);
}
- /**
- * @see EffectiveNodeType#getAllQPropertyDefinitions()
- */
+ @Override
public QPropertyDefinition[] getAllQPropertyDefinitions() {
- if (namedItemDefs.size() == 0 && unnamedItemDefs.size() == 0) {
+ if (namedItemDefs.isEmpty() && unnamedItemDefs.isEmpty()) {
return QPropertyDefinition.EMPTY_ARRAY;
}
- ArrayList<QItemDefinition> defs = new ArrayList<QItemDefinition>(namedItemDefs.size() + unnamedItemDefs.size());
+ ArrayList<QPropertyDefinition> defs = new ArrayList<QPropertyDefinition>(namedItemDefs.size() + unnamedItemDefs.size());
for (QItemDefinition qDef : unnamedItemDefs) {
if (!qDef.definesNode()) {
- defs.add(qDef);
+ defs.add((QPropertyDefinition) qDef);
}
}
for (List<QItemDefinition> list : namedItemDefs.values()) {
for (QItemDefinition qDef : list) {
if (!qDef.definesNode()) {
- defs.add(qDef);
+ defs.add((QPropertyDefinition) qDef);
}
}
}
- if (defs.size() == 0) {
+ if (defs.isEmpty()) {
return QPropertyDefinition.EMPTY_ARRAY;
}
return defs.toArray(new QPropertyDefinition[defs.size()]);
}
- /**
- * @see EffectiveNodeType#getAutoCreateQNodeDefinitions()
- */
+ @Override
public QNodeDefinition[] getAutoCreateQNodeDefinitions() {
// since auto-create items must have a name,
// we're only searching the named item definitions
- if (namedItemDefs.size() == 0) {
+ if (namedItemDefs.isEmpty()) {
return QNodeDefinition.EMPTY_ARRAY;
}
- ArrayList<QItemDefinition> defs = new ArrayList<QItemDefinition>(namedItemDefs.size());
+ ArrayList<QNodeDefinition> defs = new ArrayList<QNodeDefinition>(namedItemDefs.size());
for (List<QItemDefinition> list : namedItemDefs.values()) {
for (QItemDefinition qDef : list) {
if (qDef.definesNode() && qDef.isAutoCreated()) {
- defs.add(qDef);
+ defs.add((QNodeDefinition) qDef);
}
}
}
- if (defs.size() == 0) {
+ if (defs.isEmpty()) {
return QNodeDefinition.EMPTY_ARRAY;
}
return defs.toArray(new QNodeDefinition[defs.size()]);
}
- /**
- * @see EffectiveNodeType#getAutoCreateQPropertyDefinitions()
- */
+ @Override
public QPropertyDefinition[] getAutoCreateQPropertyDefinitions() {
// since auto-create items must have a name,
// we're only searching the named item definitions
- if (namedItemDefs.size() == 0) {
+ if (namedItemDefs.isEmpty()) {
return QPropertyDefinition.EMPTY_ARRAY;
}
- ArrayList<QItemDefinition> defs = new ArrayList<QItemDefinition>(namedItemDefs.size());
+ ArrayList<QPropertyDefinition> defs = new ArrayList<QPropertyDefinition>(namedItemDefs.size());
for (List<QItemDefinition> list : namedItemDefs.values()) {
for (QItemDefinition qDef : list) {
if (!qDef.definesNode() && qDef.isAutoCreated()) {
- defs.add(qDef);
+ defs.add((QPropertyDefinition) qDef);
}
}
}
- if (defs.size() == 0) {
+ if (defs.isEmpty()) {
return QPropertyDefinition.EMPTY_ARRAY;
}
return defs.toArray(new QPropertyDefinition[defs.size()]);
}
- /**
- * @see EffectiveNodeType#getMandatoryQPropertyDefinitions()
- */
+ @Override
public QPropertyDefinition[] getMandatoryQPropertyDefinitions() {
// since mandatory items must have a name,
// we're only searching the named item definitions
- if (namedItemDefs.size() == 0) {
+ if (namedItemDefs.isEmpty()) {
return QPropertyDefinition.EMPTY_ARRAY;
}
- ArrayList<QItemDefinition> defs = new ArrayList<QItemDefinition>(namedItemDefs.size());
+ ArrayList<QPropertyDefinition> defs = new ArrayList<QPropertyDefinition>(namedItemDefs.size());
for (List<QItemDefinition> list : namedItemDefs.values()) {
for (QItemDefinition qDef : list) {
if (!qDef.definesNode() && qDef.isMandatory()) {
- defs.add(qDef);
+ defs.add((QPropertyDefinition) qDef);
}
}
}
- if (defs.size() == 0) {
+ if (defs.isEmpty()) {
return QPropertyDefinition.EMPTY_ARRAY;
}
return defs.toArray(new QPropertyDefinition[defs.size()]);
}
- /**
- * @see EffectiveNodeType#getMandatoryQNodeDefinitions()
- */
+ @Override
public QNodeDefinition[] getMandatoryQNodeDefinitions() {
// since mandatory items must have a name,
// we're only searching the named item definitions
- if (namedItemDefs.size() == 0) {
+ if (namedItemDefs.isEmpty()) {
return QNodeDefinition.EMPTY_ARRAY;
}
- ArrayList<QItemDefinition> defs = new ArrayList<QItemDefinition>(namedItemDefs.size());
+ ArrayList<QNodeDefinition> defs = new ArrayList<QNodeDefinition>(namedItemDefs.size());
for (List<QItemDefinition> list : namedItemDefs.values()) {
for (QItemDefinition qDef : list) {
if (qDef.definesNode() && qDef.isMandatory()) {
- defs.add(qDef);
+ defs.add((QNodeDefinition) qDef);
}
}
}
- if (defs.size() == 0) {
+ if (defs.isEmpty()) {
return QNodeDefinition.EMPTY_ARRAY;
}
return defs.toArray(new QNodeDefinition[defs.size()]);
}
- /**
- * @see EffectiveNodeType#getNamedQNodeDefinitions(Name)
- */
+ @Override
public QNodeDefinition[] getNamedQNodeDefinitions(Name name) {
List<QItemDefinition> list = namedItemDefs.get(name);
- if (list == null || list.size() == 0) {
+ if (list == null || list.isEmpty()) {
return QNodeDefinition.EMPTY_ARRAY;
}
- ArrayList<QItemDefinition> defs = new ArrayList<QItemDefinition>(list.size());
+ ArrayList<QNodeDefinition> defs = new ArrayList<QNodeDefinition>(list.size());
for (QItemDefinition qDef : list) {
if (qDef.definesNode()) {
- defs.add(qDef);
+ defs.add((QNodeDefinition) qDef);
}
}
- if (defs.size() == 0) {
+ if (defs.isEmpty()) {
return QNodeDefinition.EMPTY_ARRAY;
}
return defs.toArray(new QNodeDefinition[defs.size()]);
}
- /**
- * @see EffectiveNodeType#getUnnamedQNodeDefinitions()
- */
+ @Override
public QNodeDefinition[] getUnnamedQNodeDefinitions() {
- if (unnamedItemDefs.size() == 0) {
+ if (unnamedItemDefs.isEmpty()) {
return QNodeDefinition.EMPTY_ARRAY;
}
- ArrayList<QItemDefinition> defs = new ArrayList<QItemDefinition>(unnamedItemDefs.size());
+ ArrayList<QNodeDefinition> defs = new ArrayList<QNodeDefinition>(unnamedItemDefs.size());
for (QItemDefinition qDef : unnamedItemDefs) {
if (qDef.definesNode()) {
- defs.add(qDef);
+ defs.add((QNodeDefinition) qDef);
}
}
- if (defs.size() == 0) {
+ if (defs.isEmpty()) {
return QNodeDefinition.EMPTY_ARRAY;
}
return defs.toArray(new QNodeDefinition[defs.size()]);
}
- /**
- * @see EffectiveNodeType#getNamedQPropertyDefinitions(Name)
- */
+ @Override
public QPropertyDefinition[] getNamedQPropertyDefinitions(Name name) {
List<QItemDefinition> list = namedItemDefs.get(name);
- if (list == null || list.size() == 0) {
+ if (list == null || list.isEmpty()) {
return QPropertyDefinition.EMPTY_ARRAY;
}
- ArrayList<QItemDefinition> defs = new ArrayList<QItemDefinition>(list.size());
+ ArrayList<QPropertyDefinition> defs = new ArrayList<QPropertyDefinition>(list.size());
for (QItemDefinition qDef : list) {
if (!qDef.definesNode()) {
- defs.add(qDef);
+ defs.add((QPropertyDefinition) qDef);
}
}
- if (defs.size() == 0) {
+ if (defs.isEmpty()) {
return QPropertyDefinition.EMPTY_ARRAY;
}
return defs.toArray(new QPropertyDefinition[defs.size()]);
}
- /**
- * @see EffectiveNodeType#getUnnamedQPropertyDefinitions()
- */
+ @Override
public QPropertyDefinition[] getUnnamedQPropertyDefinitions() {
- if (unnamedItemDefs.size() == 0) {
+ if (unnamedItemDefs.isEmpty()) {
return QPropertyDefinition.EMPTY_ARRAY;
}
- ArrayList<QItemDefinition> defs = new ArrayList<QItemDefinition>(unnamedItemDefs.size());
+ ArrayList<QPropertyDefinition> defs = new ArrayList<QPropertyDefinition>(unnamedItemDefs.size());
for (QItemDefinition qDef : unnamedItemDefs) {
if (!qDef.definesNode()) {
- defs.add(qDef);
+ defs.add((QPropertyDefinition) qDef);
}
}
- if (defs.size() == 0) {
+ if (defs.isEmpty()) {
return QPropertyDefinition.EMPTY_ARRAY;
}
return defs.toArray(new QPropertyDefinition[defs.size()]);
}
+ @Override
public boolean includesNodeType(Name nodeTypeName) {
return allNodeTypes.contains(nodeTypeName);
}
+ @Override
public boolean includesNodeTypes(Name[] nodeTypeNames) {
return allNodeTypes.containsAll(Arrays.asList(nodeTypeNames));
}
- /**
- * @see EffectiveNodeType#supportsMixin(Name)
- */
+ @Override
public boolean supportsMixin(Name mixin) {
- if (supportedMixins == null) {
- return true;
- }
- else {
- return supportedMixins.contains(mixin);
- }
+ return supportedMixins == null || supportedMixins.contains(mixin);
}
- /**
- * @see EffectiveNodeType#checkAddNodeConstraints(Name, ItemDefinitionProvider)
- */
+ @Override
public void checkAddNodeConstraints(Name name, ItemDefinitionProvider definitionProvider)
throws ConstraintViolationException {
try {
@@ -359,16 +329,16 @@ public class EffectiveNodeTypeImpl imple
}
}
- /**
- * @see EffectiveNodeType#checkAddNodeConstraints(org.apache.jackrabbit.spi.Name,QNodeTypeDefinition, ItemDefinitionProvider)
- */
- public void checkAddNodeConstraints(Name name, QNodeTypeDefinition nodeTypeDefinition, ItemDefinitionProvider definitionProvider)
+ @Override
+ public void checkAddNodeConstraints(Name name, QNodeTypeDefinition nodeTypeDefinition,
+ ItemDefinitionProvider definitionProvider)
+
throws ConstraintViolationException, NoSuchNodeTypeException {
if (nodeTypeDefinition.isAbstract()) {
throw new ConstraintViolationException("not allowed to add node " + name + ": " + nodeTypeDefinition.getName() + " is abstract and cannot be used as primary node type.");
}
if (nodeTypeDefinition.isMixin()) {
- throw new ConstraintViolationException("not allowed to add node " + name + ":" + nodeTypeDefinition.getName() + " is a mixin and cannot be used as primary node type.");
+ throw new ConstraintViolationException("not allowed to add node " + name + ':' + nodeTypeDefinition.getName() + " is a mixin and cannot be used as primary node type.");
}
QNodeDefinition nd = definitionProvider.getQNodeDefinition(this, name, nodeTypeDefinition.getName());
if (nd.isProtected()) {
@@ -379,37 +349,30 @@ public class EffectiveNodeTypeImpl imple
}
}
- /**
- * @see EffectiveNodeType#checkRemoveItemConstraints(Name)
- */
+ @Override
public void checkRemoveItemConstraints(Name name) throws ConstraintViolationException {
- /**
- * as there might be multiple definitions with the same name and we
- * don't know which one is applicable, we check all of them
- */
+ // as there might be multiple definitions with the same name and we
+ // don't know which one is applicable, we check all of them
QItemDefinition[] defs = getNamedItemDefs(name);
- if (hasRemoveConstaint(defs)) {
+ if (hasRemoveConstraint(defs)) {
throw new ConstraintViolationException("can't remove mandatory or protected item");
}
}
- /**
- * @see EffectiveNodeType#hasRemoveNodeConstraint(Name)
- */
+ @Override
public boolean hasRemoveNodeConstraint(Name nodeName) {
QNodeDefinition[] defs = getNamedQNodeDefinitions(nodeName);
- return hasRemoveConstaint(defs);
+ return hasRemoveConstraint(defs);
}
- /**
- * @see EffectiveNodeType#hasRemovePropertyConstraint(Name)
- */
+ @Override
public boolean hasRemovePropertyConstraint(Name propertyName) {
QPropertyDefinition[] defs = getNamedQPropertyDefinitions(propertyName);
- return hasRemoveConstaint(defs);
+ return hasRemoveConstraint(defs);
}
//---------------------------------------------< impl. specific methods >---
+
/**
* Loop over the specified definitions and return <code>true</code> as soon
* as the first mandatory or protected definition is encountered.
@@ -417,18 +380,16 @@ public class EffectiveNodeTypeImpl imple
* @param defs
* @return <code>true</code> if a mandatory or protected definition is present.
*/
- private static boolean hasRemoveConstaint(QItemDefinition[] defs) {
- /**
- * as there might be multiple definitions with the same name that may be
- * applicable, return true as soon as the first mandatory or protected
- * definition is encountered.
- */
+ private static boolean hasRemoveConstraint(QItemDefinition[] defs) {
+ // as there might be multiple definitions with the same name that may be
+ // applicable, return true as soon as the first mandatory or protected
+ // definition is encountered.
if (defs != null) {
- for (int i = 0; i < defs.length; i++) {
- if (defs[i].isMandatory()) {
+ for (QItemDefinition def : defs) {
+ if (def.isMandatory()) {
return true;
}
- if (defs[i].isProtected()) {
+ if (def.isProtected()) {
return true;
}
}
@@ -437,14 +398,14 @@ public class EffectiveNodeTypeImpl imple
}
private QItemDefinition[] getNamedItemDefs() {
- if (namedItemDefs.size() == 0) {
+ if (namedItemDefs.isEmpty()) {
return QItemDefinition.EMPTY_ARRAY;
}
ArrayList<QItemDefinition> defs = new ArrayList<QItemDefinition>(namedItemDefs.size());
for (List<QItemDefinition> list : namedItemDefs.values()) {
defs.addAll(list);
}
- if (defs.size() == 0) {
+ if (defs.isEmpty()) {
return QItemDefinition.EMPTY_ARRAY;
}
return defs.toArray(new QItemDefinition[defs.size()]);
@@ -452,14 +413,14 @@ public class EffectiveNodeTypeImpl imple
private QItemDefinition[] getNamedItemDefs(Name name) {
List<QItemDefinition> list = namedItemDefs.get(name);
- if (list == null || list.size() == 0) {
+ if (list == null || list.isEmpty()) {
return QNodeDefinition.EMPTY_ARRAY;
}
return list.toArray(new QItemDefinition[list.size()]);
}
private QItemDefinition[] getUnnamedItemDefs() {
- if (unnamedItemDefs.size() == 0) {
+ if (unnamedItemDefs.isEmpty()) {
return QItemDefinition.EMPTY_ARRAY;
}
return unnamedItemDefs.toArray(new QItemDefinition[unnamedItemDefs.size()]);
@@ -473,8 +434,7 @@ public class EffectiveNodeTypeImpl imple
* @return
* @throws ConstraintViolationException
*/
- EffectiveNodeTypeImpl merge(EffectiveNodeTypeImpl other)
- throws ConstraintViolationException {
+ EffectiveNodeTypeImpl merge(EffectiveNodeTypeImpl other) throws ConstraintViolationException {
// create a clone of this instance and perform the merge on
// the 'clone' to avoid a potentially inconsistent state
// of this instance if an exception is thrown during
@@ -501,10 +461,10 @@ public class EffectiveNodeTypeImpl imple
throws ConstraintViolationException {
Name[] nta = other.getAllNodeTypes();
int includedCount = 0;
- for (int i = 0; i < nta.length; i++) {
- if (includesNodeType(nta[i])) {
+ for (Name aNta : nta) {
+ if (includesNodeType(aNta)) {
// redundant node type
- log.debug("node type '" + nta[i] + "' is already contained.");
+ log.debug("node type '" + aNta + "' is already contained.");
includedCount++;
}
}
@@ -515,8 +475,7 @@ public class EffectiveNodeTypeImpl imple
// named item definitions
QItemDefinition[] defs = other.getNamedItemDefs();
- for (int i = 0; i < defs.length; i++) {
- QItemDefinition qDef = defs[i];
+ for (QItemDefinition qDef : defs) {
if (includesNodeType(qDef.getDeclaringNodeType())) {
// ignore redundant definitions
continue;
@@ -524,10 +483,9 @@ public class EffectiveNodeTypeImpl imple
Name name = qDef.getName();
List<QItemDefinition> existingDefs = namedItemDefs.get(name);
if (existingDefs != null) {
- if (existingDefs.size() > 0) {
+ if (!existingDefs.isEmpty()) {
// there already exists at least one definition with that name
- for (int j = 0; j < existingDefs.size(); j++) {
- QItemDefinition qItemDef = existingDefs.get(j);
+ for (QItemDefinition qItemDef : existingDefs) {
// make sure none of them is auto-create
if (qDef.isAutoCreated() || qItemDef.isAutoCreated()) {
// conflict
@@ -542,7 +500,18 @@ public class EffectiveNodeTypeImpl imple
}
// check ambiguous definitions
if (qDef.definesNode() == qItemDef.definesNode()) {
- if (!qDef.definesNode()) {
+ if (qDef.definesNode()) {
+ // child node definition
+ // conflict
+ String msg = "The child node definition for '"
+ + name + "' in node type '"
+ + qDef.getDeclaringNodeType()
+ + "' conflicts with the one of node type '"
+ + qItemDef.getDeclaringNodeType()
+ + "': ambiguous child node definition. name must differ.";
+ log.debug(msg);
+ throw new ConstraintViolationException(msg);
+ } else {
// property definition
QPropertyDefinition pd = (QPropertyDefinition) qDef;
QPropertyDefinition epd = (QPropertyDefinition) qItemDef;
@@ -561,17 +530,6 @@ public class EffectiveNodeTypeImpl imple
log.debug(msg);
throw new ConstraintViolationException(msg);
}
- } else {
- // child node definition
- // conflict
- String msg = "The child node definition for '"
- + name + "' in node type '"
- + qDef.getDeclaringNodeType()
- + "' conflicts with the one of node type '"
- + qItemDef.getDeclaringNodeType()
- + "': ambiguous child node definition. name must differ.";
- log.debug(msg);
- throw new ConstraintViolationException(msg);
}
}
}
@@ -585,8 +543,7 @@ public class EffectiveNodeTypeImpl imple
// residual item definitions
defs = other.getUnnamedItemDefs();
- for (int i = 0; i < defs.length; i++) {
- QItemDefinition qDef = defs[i];
+ for (QItemDefinition qDef : defs) {
if (includesNodeType(qDef.getDeclaringNodeType())) {
// ignore redundant definitions
continue;
@@ -594,7 +551,25 @@ public class EffectiveNodeTypeImpl imple
for (QItemDefinition existing : unnamedItemDefs) {
// compare with existing definition
if (qDef.definesNode() == existing.definesNode()) {
- if (!qDef.definesNode()) {
+ if (qDef.definesNode()) {
+ // child node definition
+ QNodeDefinition nd = (QNodeDefinition) qDef;
+ QNodeDefinition end = (QNodeDefinition) existing;
+ // compare required & default primary types
+ if (Arrays.equals(nd.getRequiredPrimaryTypes(), end.getRequiredPrimaryTypes())
+ && (nd.getDefaultPrimaryType() == null
+ ? end.getDefaultPrimaryType() == null
+ : nd.getDefaultPrimaryType().equals(end.getDefaultPrimaryType()))) {
+ // conflict
+ String msg = "A child node definition in node type '"
+ + qDef.getDeclaringNodeType()
+ + "' conflicts with node type '"
+ + existing.getDeclaringNodeType()
+ + "': ambiguous residual child node definition";
+ log.debug(msg);
+ throw new ConstraintViolationException(msg);
+ }
+ } else {
// property definition
QPropertyDefinition pd = (QPropertyDefinition) qDef;
QPropertyDefinition epd = (QPropertyDefinition) existing;
@@ -613,67 +588,37 @@ public class EffectiveNodeTypeImpl imple
log.debug(msg);
throw new ConstraintViolationException(msg);
}
- } else {
- // child node definition
- QNodeDefinition nd = (QNodeDefinition) qDef;
- QNodeDefinition end = (QNodeDefinition) existing;
- // compare required & default primary types
- if (Arrays.equals(nd.getRequiredPrimaryTypes(), end.getRequiredPrimaryTypes())
- && (nd.getDefaultPrimaryType() == null
- ? end.getDefaultPrimaryType() == null
- : nd.getDefaultPrimaryType().equals(end.getDefaultPrimaryType()))) {
- // conflict
- String msg = "A child node definition in node type '"
- + qDef.getDeclaringNodeType()
- + "' conflicts with node type '"
- + existing.getDeclaringNodeType()
- + "': ambiguous residual child node definition";
- log.debug(msg);
- throw new ConstraintViolationException(msg);
- }
}
}
}
unnamedItemDefs.add(qDef);
}
- for (int i = 0; i < nta.length; i++) {
- allNodeTypes.add(nta[i]);
- }
+ Collections.addAll(allNodeTypes, nta);
if (supertype) {
// implicit merge as result of inheritance
// add other merged node types as supertypes
nta = other.getMergedNodeTypes();
- for (int i = 0; i < nta.length; i++) {
- inheritedNodeTypes.add(nta[i]);
- }
+ Collections.addAll(inheritedNodeTypes, nta);
// add supertypes of other merged node types as supertypes
nta = other.getInheritedNodeTypes();
- for (int i = 0; i < nta.length; i++) {
- inheritedNodeTypes.add(nta[i]);
- }
+ Collections.addAll(inheritedNodeTypes, nta);
} else {
// explicit merge
// merge with other merged node types
nta = other.getMergedNodeTypes();
- for (int i = 0; i < nta.length; i++) {
- mergedNodeTypes.add(nta[i]);
- }
+ Collections.addAll(mergedNodeTypes, nta);
// add supertypes of other merged node types as supertypes
nta = other.getInheritedNodeTypes();
- for (int i = 0; i < nta.length; i++) {
- inheritedNodeTypes.add(nta[i]);
- }
+ Collections.addAll(inheritedNodeTypes, nta);
}
}
@Override
- protected Object clone() {
- EffectiveNodeTypeImpl clone = new EffectiveNodeTypeImpl(mergedNodeTypes,
- inheritedNodeTypes, allNodeTypes, namedItemDefs, unnamedItemDefs,
- supportedMixins);
- return clone;
+ protected final Object clone() {
+ return new EffectiveNodeTypeImpl(mergedNodeTypes, inheritedNodeTypes, allNodeTypes, namedItemDefs,
+ unnamedItemDefs, supportedMixins);
}
}
Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeTypeProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeTypeProvider.java?rev=1164026&r1=1164025&r2=1164026&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeTypeProvider.java (original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeTypeProvider.java Thu Sep 1 11:52:08 2011
@@ -36,8 +36,7 @@ public interface EffectiveNodeTypeProvid
* @return
* @throws NoSuchNodeTypeException
*/
- public EffectiveNodeType getEffectiveNodeType(Name ntName)
- throws NoSuchNodeTypeException;
+ EffectiveNodeType getEffectiveNodeType(Name ntName) throws NoSuchNodeTypeException;
/**
* Build the <code>EffectiveNodeType</code> from the given array of
@@ -48,7 +47,7 @@ public interface EffectiveNodeTypeProvid
* @throws ConstraintViolationException
* @throws NoSuchNodeTypeException
*/
- public EffectiveNodeType getEffectiveNodeType(Name[] ntNames)
+ EffectiveNodeType getEffectiveNodeType(Name[] ntNames)
throws ConstraintViolationException, NoSuchNodeTypeException;
/**
@@ -58,7 +57,7 @@ public interface EffectiveNodeTypeProvid
* @throws ConstraintViolationException
* @throws NoSuchNodeTypeException
*/
- public EffectiveNodeType getEffectiveNodeType(Name[] ntNames, Map<Name, QNodeTypeDefinition> ntdMap)
+ EffectiveNodeType getEffectiveNodeType(Name[] ntNames, Map<Name, QNodeTypeDefinition> ntdMap)
throws ConstraintViolationException, NoSuchNodeTypeException;
/**
@@ -73,7 +72,6 @@ public interface EffectiveNodeTypeProvid
* @throws ConstraintViolationException
* @throws NoSuchNodeTypeException
*/
- public EffectiveNodeType getEffectiveNodeType(QNodeTypeDefinition ntd,
- Map<Name, QNodeTypeDefinition> ntdMap)
+ EffectiveNodeType getEffectiveNodeType(QNodeTypeDefinition ntd, Map<Name, QNodeTypeDefinition> ntdMap)
throws ConstraintViolationException, NoSuchNodeTypeException;
}
Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/ItemDefinitionProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/ItemDefinitionProvider.java?rev=1164026&r1=1164025&r2=1164026&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/ItemDefinitionProvider.java (original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/ItemDefinitionProvider.java Thu Sep 1 11:52:08 2011
@@ -38,7 +38,7 @@ public interface ItemDefinitionProvider
* @return the <code>QNodeDefinition</code> for the root node.
* @throws RepositoryException
*/
- public QNodeDefinition getRootNodeDefinition() throws RepositoryException;
+ QNodeDefinition getRootNodeDefinition() throws RepositoryException;
/**
* Returns the <code>QNodeDefinition</code> for the specified node state.
@@ -50,9 +50,8 @@ public interface ItemDefinitionProvider
* @return the <code>QNodeDefinition</code> for the specified node state.
* @throws RepositoryException
*/
- public QNodeDefinition getQNodeDefinition(Name[] parentNodeTypeNames,
- Name nodeName, Name ntName,
- NodeId nodeId) throws RepositoryException;
+ QNodeDefinition getQNodeDefinition(Name[] parentNodeTypeNames, Name nodeName, Name ntName, NodeId nodeId)
+ throws RepositoryException;
/**
* Returns the applicable child node definition for a child node with the
@@ -66,8 +65,7 @@ public interface ItemDefinitionProvider
* @throws ConstraintViolationException if no applicable child node definition
* could be found
*/
- public QNodeDefinition getQNodeDefinition(Name[] parentNodeTypeNames,
- Name name, Name nodeTypeName)
+ QNodeDefinition getQNodeDefinition(Name[] parentNodeTypeNames, Name name, Name nodeTypeName)
throws NoSuchNodeTypeException, ConstraintViolationException;
/**
@@ -82,33 +80,23 @@ public interface ItemDefinitionProvider
* @throws ConstraintViolationException if no applicable child node definition
* could be found
*/
- public QNodeDefinition getQNodeDefinition(EffectiveNodeType ent,
- Name name, Name nodeTypeName)
+ QNodeDefinition getQNodeDefinition(EffectiveNodeType ent, Name name, Name nodeTypeName)
throws NoSuchNodeTypeException, ConstraintViolationException;
/**
- * Returns the <code>QPropertyDefinition</code> for the specified property state.
- * @param propertyState
- * @return the <code>QPropertyDefinition</code> for the specified property state.
- * @throws RepositoryException
- */
- /**
* Returns the <code>QPropertyDefinition</code> for the specified parameters.
*
* @param parentNodeTypeNames
* @param propertyName
- * @param propertType
+ * @param propertyType
* @param isMultiValued
* @param propertyId Used to retrieve the definition from the persistent
* layer if it cannot be determined from the information present.
* @return
* @throws RepositoryException
*/
- public QPropertyDefinition getQPropertyDefinition(Name[] parentNodeTypeNames,
- Name propertyName,
- int propertType,
- boolean isMultiValued,
- PropertyId propertyId) throws RepositoryException;
+ QPropertyDefinition getQPropertyDefinition(Name[] parentNodeTypeNames, Name propertyName, int propertyType,
+ boolean isMultiValued, PropertyId propertyId) throws RepositoryException;
/**
* Returns the applicable property definition for a property with the
@@ -126,9 +114,7 @@ public interface ItemDefinitionProvider
* @throws ConstraintViolationException if no applicable property definition
* could be found
*/
- public QPropertyDefinition getQPropertyDefinition(Name ntName,
- Name propName, int type,
- boolean multiValued)
+ QPropertyDefinition getQPropertyDefinition(Name ntName, Name propName, int type, boolean multiValued)
throws ConstraintViolationException, NoSuchNodeTypeException;
/**
@@ -149,9 +135,7 @@ public interface ItemDefinitionProvider
* @throws ConstraintViolationException if no applicable property definition
* could be found.
*/
- public QPropertyDefinition getQPropertyDefinition(Name[] parentNodeTypeNames,
- Name name, int type,
- boolean multiValued)
+ QPropertyDefinition getQPropertyDefinition(Name[] parentNodeTypeNames, Name name, int type, boolean multiValued)
throws ConstraintViolationException, NoSuchNodeTypeException;
/**
@@ -176,7 +160,6 @@ public interface ItemDefinitionProvider
* @throws ConstraintViolationException if no applicable property definition
* could be found
*/
- public QPropertyDefinition getQPropertyDefinition(Name[] parentNodeTypeNames,
- Name name, int type)
+ QPropertyDefinition getQPropertyDefinition(Name[] parentNodeTypeNames, Name name, int type)
throws ConstraintViolationException, NoSuchNodeTypeException;
}