Author: angela
Date: Tue Oct 30 11:46:35 2012
New Revision: 1403671
URL: http://svn.apache.org/viewvc?rev=1403671&view=rev
Log:
OAK-250 : Enforce jcr constraints for 'protected' items
- consistently exclude protected items from the validation
- isProtected renamed to isProtectedProperty and added isProtectedNode in
addition
- the code in the isProtected method is basically duplicting code that was
formerly present in Node/PropertyImpl and
NodeTypeImpl.... and the check for protected residual definitions was
missing.
- in addition the SNS-hack for the node type definitions now requires another
hack in order to be able
to determine the real name of the node (without the trailing index)...
*speurk*
- added even more TODOs and FIXME comments in particular for the private
EffectiveNodeType class that
is present in the TypeValidator.
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/EffectiveNodeTypeProvider.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/NodeTypeImpl.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeValidator.java
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/EffectiveNodeTypeProvider.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/EffectiveNodeTypeProvider.java?rev=1403671&r1=1403670&r2=1403671&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/EffectiveNodeTypeProvider.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/EffectiveNodeTypeProvider.java
Tue Oct 30 11:46:35 2012
@@ -22,6 +22,8 @@ import javax.jcr.nodetype.NodeType;
/**
* EffectiveNodeTypeProvider... TODO
+ *
+ * FIXME: see also TypeValidator which has it's own private EffectiveNodeType
class.
*/
public interface EffectiveNodeTypeProvider {
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/NodeTypeImpl.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/NodeTypeImpl.java?rev=1403671&r1=1403670&r2=1403671&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/NodeTypeImpl.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/NodeTypeImpl.java
Tue Oct 30 11:46:35 2012
@@ -400,10 +400,11 @@ class NodeTypeImpl implements NodeType {
@Override
public boolean canAddChildNode(String childNodeName) {
+ // FIXME: properly calculate matching definition
for (NodeDefinition definition : getChildNodeDefinitions()) {
String name = definition.getName();
if (matches(childNodeName, name) || "*".equals(name)) {
- return definition.getDefaultPrimaryType() != null;
+ return !definition.isProtected() &&
definition.getDefaultPrimaryType() != null;
}
}
return false;
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeValidator.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeValidator.java?rev=1403671&r1=1403670&r2=1403671&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeValidator.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeValidator.java
Tue Oct 30 11:46:35 2012
@@ -239,6 +239,7 @@ class TypeValidator implements Validator
return types;
}
+ // FIXME: the same is also required on JCR level. probably keeping that in
1 single location would be preferable.
private EffectiveNodeType getEffectiveNodeType(Tree tree) throws
RepositoryException {
return new EffectiveNodeType(getPrimaryType(tree),
getMixinTypes(tree));
}
@@ -251,7 +252,7 @@ class TypeValidator implements Validator
}
public void checkSetProperty(PropertyState property) throws
ConstraintViolationException {
- if (isProtected(property.getName())) {
+ if (isProtectedProperty(property.getName())) {
return;
}
if (property.isArray()) {
@@ -266,6 +267,9 @@ class TypeValidator implements Validator
private void checkSetProperty(final String propertyName, List<Value>
values)
throws ConstraintViolationException {
+ if (isProtectedProperty(propertyName)) {
+ return;
+ }
Value[] valueArray = values.toArray(new Value[values.size()]);
for (NodeType nodeType : allTypes) {
if (nodeType.canSetProperty(propertyName, valueArray)) {
@@ -276,6 +280,9 @@ class TypeValidator implements Validator
}
private void checkSetProperty(final String propertyName, Value value)
throws ConstraintViolationException {
+ if (isProtectedProperty(propertyName)) {
+ return;
+ }
for (NodeType nodeType : allTypes) {
if (nodeType.canSetProperty(propertyName, value)) {
return;
@@ -285,7 +292,7 @@ class TypeValidator implements Validator
}
public void checkRemoveProperty(PropertyState property) throws
ConstraintViolationException {
- if (isProtected(property.getName())) {
+ if (isProtectedProperty(property.getName())) {
return;
}
final String name = property.getName();
@@ -298,6 +305,9 @@ class TypeValidator implements Validator
}
public void checkRemoveNode(final String name) throws
ConstraintViolationException {
+ if (isProtectedNode(name)) {
+ return;
+ }
for (NodeType nodeType : allTypes) {
if (nodeType.canRemoveNode(name)) {
return;
@@ -307,6 +317,9 @@ class TypeValidator implements Validator
}
public void canAddChildNode(final String name) throws
ConstraintViolationException {
+ if (isProtectedNode(name)) {
+ return;
+ }
for (NodeType nodeType : allTypes) {
if (nodeType.canAddChildNode(name)) {
return;
@@ -316,6 +329,9 @@ class TypeValidator implements Validator
}
public void checkAddChildNode(final String name, final String ntName)
throws ConstraintViolationException {
+ if (isProtectedNode(name)) {
+ return;
+ }
for (NodeType nodeType : allTypes) {
if (nodeType.canAddChildNode(name, ntName)) {
return;
@@ -343,7 +359,8 @@ class TypeValidator implements Validator
}
}
- private boolean isProtected(String propertyName) {
+ private boolean isProtectedProperty(String propertyName) {
+ // FIXME: duplicated code. we should use one common way to
determine a matching definition (DefinitionProvider)
for (NodeType nodeType : allTypes) {
for (PropertyDefinition pd :
nodeType.getPropertyDefinitions()) {
if (propertyName.equals(pd.getName()) && pd.isProtected())
{
@@ -351,6 +368,40 @@ class TypeValidator implements Validator
}
}
}
+ for (NodeType nodeType : allTypes) {
+ for (PropertyDefinition pd :
nodeType.getPropertyDefinitions()) {
+ if ("*".equals(pd.getName()) && pd.isProtected()) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ private boolean isProtectedNode(String nodeName) {
+ // FIXME: ugly hack to workaround sns-hack that was used to map
sns-item definitions with node types.
+ String nameToCheck = nodeName;
+ if (nodeName.startsWith("jcr:childNodeDefinition") &&
!nodeName.equals("jcr:childNodeDefinition")) {
+ nameToCheck = nodeName.substring(0,
"jcr:childNodeDefinition".length());
+ }
+ if (nodeName.startsWith("jcr:propertyDefinition") &&
!nodeName.equals("jcr:propertyDefinition")) {
+ nameToCheck = nodeName.substring(0,
"jcr:propertyDefinition".length());
+ }
+ // FIXME: duplicated code. we should use one common way to
determine a matching definition (DefinitionProvider)
+ for (NodeType nodeType : allTypes) {
+ for (NodeDefinition nd : nodeType.getChildNodeDefinitions()) {
+ if (nameToCheck.equals(nd.getName()) && nd.isProtected()) {
+ return true;
+ }
+ }
+ }
+ for (NodeType nodeType : allTypes) {
+ for (NodeDefinition nd : nodeType.getChildNodeDefinitions()) {
+ if ("*".equals(nd.getName()) && nd.isProtected()) {
+ return true;
+ }
+ }
+ }
return false;
}