You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by an...@apache.org on 2012/12/12 18:02:11 UTC
svn commit: r1420832 - in
/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype:
EffectiveNodeTypeImpl.java ReadOnlyNodeTypeManager.java
Author: angela
Date: Wed Dec 12 17:02:10 2012
New Revision: 1420832
URL: http://svn.apache.org/viewvc?rev=1420832&view=rev
Log:
OAK-494 : Cleanup ReadOnlyNodeTypeManager (Work in Progress)
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/EffectiveNodeTypeImpl.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ReadOnlyNodeTypeManager.java
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/EffectiveNodeTypeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/EffectiveNodeTypeImpl.java?rev=1420832&r1=1420831&r2=1420832&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/EffectiveNodeTypeImpl.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/EffectiveNodeTypeImpl.java Wed Dec 12 17:02:10 2012
@@ -18,12 +18,15 @@ package org.apache.jackrabbit.oak.plugin
import java.util.ArrayList;
import java.util.Collection;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
import javax.annotation.Nullable;
import javax.jcr.RepositoryException;
import javax.jcr.Value;
import javax.jcr.nodetype.ConstraintViolationException;
import javax.jcr.nodetype.ItemDefinition;
+import javax.jcr.nodetype.NoSuchNodeTypeException;
import javax.jcr.nodetype.NodeDefinition;
import javax.jcr.nodetype.NodeType;
import javax.jcr.nodetype.PropertyDefinition;
@@ -33,23 +36,39 @@ import com.google.common.collect.Iterabl
import org.apache.jackrabbit.oak.api.PropertyState;
import org.apache.jackrabbit.oak.api.Tree;
import org.apache.jackrabbit.oak.plugins.value.ValueFactoryImpl;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* EffectiveNodeTypeImpl...
*
* TODO implementation needs optimization
- * FIXME: add validation of the effective node type
*/
class EffectiveNodeTypeImpl implements EffectiveNodeType {
+ private static final Logger log = LoggerFactory.getLogger(EffectiveNodeTypeImpl.class);
+
private final Collection<NodeType> nodeTypes;
private final ReadOnlyNodeTypeManager ntMgr;
- EffectiveNodeTypeImpl(Collection<NodeType> nodeTypes, ReadOnlyNodeTypeManager ntMgr) {
+ private EffectiveNodeTypeImpl(Collection<NodeType> nodeTypes, ReadOnlyNodeTypeManager ntMgr) {
this.nodeTypes = nodeTypes;
this.ntMgr = ntMgr;
}
+ static EffectiveNodeType create(Collection<NodeType> nodeTypes, ReadOnlyNodeTypeManager ntMgr) throws ConstraintViolationException {
+ if (!isValid(nodeTypes)) {
+ throw new ConstraintViolationException("Invalid effective node type");
+ }
+ return new EffectiveNodeTypeImpl(nodeTypes, ntMgr);
+ }
+
+ private static boolean isValid(Collection<NodeType> nodeTypes) {
+ // FIXME: add validation
+ return true;
+ }
+
+ //---------------------------------------------=----< EffectiveNodeType >---
@Override
public Iterable<NodeType> getAllNodeTypes() {
return nodeTypes;
@@ -77,7 +96,25 @@ class EffectiveNodeTypeImpl implements E
@Override
public boolean supportsMixin(String mixin) {
- // TODO: add implementation (-> OAK-505)
+ if (includesNodeType(mixin)) {
+ return true;
+ }
+
+ NodeType mixinType = null;
+ try {
+ mixinType = ntMgr.internalGetNodeType(mixin);
+ if (!mixinType.isMixin() || mixinType.isAbstract()) {
+ return false;
+ }
+ } catch (NoSuchNodeTypeException e) {
+ log.debug("Unknown mixin type " + mixin);
+ }
+
+ if (mixinType != null) {
+ Set<NodeType> newTypes = new HashSet<NodeType>(nodeTypes);
+ newTypes.add(mixinType);
+ return isValid(newTypes);
+ }
return false;
}
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ReadOnlyNodeTypeManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ReadOnlyNodeTypeManager.java?rev=1420832&r1=1420831&r2=1420832&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ReadOnlyNodeTypeManager.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ReadOnlyNodeTypeManager.java Wed Dec 12 17:02:10 2012
@@ -400,8 +400,9 @@ public abstract class ReadOnlyNodeTypeMa
return getPropertyDefinition(getEffectiveNodeType(queue), propertyName, isMultiple, type, exactTypeMatch);
}
- //------------------------------------------------------------< private >---
- private NodeTypeImpl internalGetNodeType(String oakName) throws NoSuchNodeTypeException {
+ //-----------------------------------------------------------< internal >---
+
+ NodeTypeImpl internalGetNodeType(String oakName) throws NoSuchNodeTypeException {
Tree types = getTypes();
if (types != null) {
Tree type = types.getChild(oakName);
@@ -412,7 +413,9 @@ public abstract class ReadOnlyNodeTypeMa
throw new NoSuchNodeTypeException(getNamePathMapper().getJcrName(oakName));
}
- private EffectiveNodeType getEffectiveNodeType(Queue<NodeType> queue) {
+ //------------------------------------------------------------< private >---
+
+ private EffectiveNodeType getEffectiveNodeType(Queue<NodeType> queue) throws ConstraintViolationException {
Map<String, NodeType> types = Maps.newHashMap();
while (!queue.isEmpty()) {
NodeType type = queue.remove();
@@ -422,7 +425,7 @@ public abstract class ReadOnlyNodeTypeMa
queue.addAll(Arrays.asList(type.getDeclaredSupertypes()));
}
}
- return new EffectiveNodeTypeImpl(types.values(), this);
+ return EffectiveNodeTypeImpl.create(types.values(), this);
}
/**