Author: pnedonosko
Date: 2010-05-21 08:21:59 -0400 (Fri, 21 May 2010)
New Revision: 2430
Added:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/value/ValueConstraintsValidator.java
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/core/nodetype/NodeTypeData.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/ItemImpl.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/NodeImpl.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/PropertyImpl.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/WorkspaceImpl.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/ItemDefinitionImpl.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/NodeDefinitionImpl.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/NodeTypeDataManagerImpl.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/NodeTypeDefinitionImpl.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/NodeTypeImpl.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/NodeTypeManagerImpl.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/PropertyDefinitionImpl.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/NodeTypeDataValidator.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/PropertyDefinitionComparator.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/value/ValueConstraintsMatcher.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/value/ValueFactoryImpl.java
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/nodetypes/TestValueConstraints.java
Log:
EXOJCR-668 default values format validation added on NT registration
EXOJCR-740 constraint ranges support added; BOOLEAN constraint support added
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/core/nodetype/NodeTypeData.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/core/nodetype/NodeTypeData.java 2010-05-21
10:28:31 UTC (rev 2429)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/core/nodetype/NodeTypeData.java 2010-05-21
12:21:59 UTC (rev 2430)
@@ -25,17 +25,12 @@
/**
* @author <a href="mailto:Sergey.Kabashnyuk@exoplatform.org">Sergey
Kabashnyuk</a>
- * @version $Id: exo-jboss-codetemplates.xml 34360 2009-07-22 23:58:59Z ksm $
+ * @version $Id$
*
*/
public interface NodeTypeData
{
-// /**
-// * @return the isAbstract
-// */
-// public boolean isAbstract();
-
/**
*
* @return
@@ -91,13 +86,4 @@
* @throws NodeTypeReadException
*/
public boolean isMixin();
-
-// /**
-// *
-// * @return
-// * @throws RepositoryException
-// * @throws NodeTypeReadException
-// */
-// public boolean isQueryable();
-
}
\ No newline at end of file
Property changes on:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/core/nodetype/NodeTypeData.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/ItemImpl.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/ItemImpl.java 2010-05-21
10:28:31 UTC (rev 2429)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/ItemImpl.java 2010-05-21
12:21:59 UTC (rev 2430)
@@ -74,7 +74,7 @@
* Created by The eXo Platform SAS.
*
* @author Gennady Azarenkov
- * @version $Id: ItemImpl.java 14590 2008-05-22 08:51:29Z pnedonosko $
+ * @version $Id$
*/
public abstract class ItemImpl implements Item
{
@@ -459,7 +459,9 @@
}
if (defs == null || defs.getAnyDefinition() == null)
+ {
throw new RepositoryException("Property definition '" +
propertyName.getAsString() + "' is not found.");
+ }
PropertyDefinitionData def = defs.getDefinition(isMultiValue);
if (def != null && def.isProtected())
@@ -941,9 +943,8 @@
}
private void checkValueConstraints(PropertyDefinitionData def, List<ValueData>
newValues, int type)
- throws ConstraintViolationException, RepositoryException
+ throws RepositoryException
{
-
ValueConstraintsMatcher constraints =
new ValueConstraintsMatcher(def.getValueConstraints(),
session.getLocationFactory(), session
.getTransientNodesManager(), session.getWorkspace().getNodeTypesHolder());
Property changes on:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/ItemImpl.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/NodeImpl.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/NodeImpl.java 2010-05-21
10:28:31 UTC (rev 2429)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/NodeImpl.java 2010-05-21
12:21:59 UTC (rev 2430)
@@ -788,7 +788,7 @@
new InternalQName[]{requiredName}, null, true);
this.nodeDefinition =
new NodeDefinitionImpl(ntData, nodeTypesHolder, nodeTypeManager,
sysLocFactory, session
- .getValueFactory());
+ .getValueFactory(), session.getTransientNodesManager());
}
}
else
@@ -815,7 +815,7 @@
nodeDefinition =
new NodeDefinitionImpl(definition, nodeTypesHolder, nodeTypeManager,
sysLocFactory, session
- .getValueFactory());
+ .getValueFactory(), session.getTransientNodesManager());
}
}
@@ -1935,9 +1935,9 @@
public void setPermissions(Map permissions) throws RepositoryException,
AccessDeniedException,
AccessControlException
{
-
+
checkValid();
-
+
if (!isNodeType(Constants.EXO_PRIVILEGEABLE))
{
throw new AccessControlException("Node is not exo:privilegeable " +
getPath());
@@ -1967,7 +1967,7 @@
aces.add(ace);
}
}
-
+
AccessControlList acl = new AccessControlList(getACL().getOwner(), aces);
setACL(acl);
updatePermissions(acl);
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/PropertyImpl.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/PropertyImpl.java 2010-05-21
10:28:31 UTC (rev 2429)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/PropertyImpl.java 2010-05-21
12:21:59 UTC (rev 2430)
@@ -337,8 +337,7 @@
return new PropertyDefinitionImpl(propertyDef,
session.getWorkspace().getNodeTypesHolder(),
(ExtendedNodeTypeManager)session.getWorkspace().getNodeTypeManager(),
session.getSystemLocationFactory(),
- session.getValueFactory());
-
+ session.getValueFactory(), session.getTransientNodesManager());
}
/**
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/WorkspaceImpl.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/WorkspaceImpl.java 2010-05-21
10:28:31 UTC (rev 2429)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/WorkspaceImpl.java 2010-05-21
12:21:59 UTC (rev 2430)
@@ -275,7 +275,8 @@
public NodeTypeManager getNodeTypeManager() throws RepositoryException
{
// incl Session mapping
- return new NodeTypeManagerImpl(session.getLocationFactory(),
session.getValueFactory(), nodeTypeManager);
+ return new NodeTypeManagerImpl(session.getLocationFactory(),
session.getValueFactory(), nodeTypeManager, session
+ .getTransientNodesManager());
}
/**
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/ItemDefinitionImpl.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/ItemDefinitionImpl.java 2010-05-21
10:28:31 UTC (rev 2429)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/ItemDefinitionImpl.java 2010-05-21
12:21:59 UTC (rev 2430)
@@ -21,6 +21,7 @@
import org.exoplatform.services.jcr.core.nodetype.ExtendedNodeTypeManager;
import org.exoplatform.services.jcr.core.nodetype.ItemDefinitionData;
import org.exoplatform.services.jcr.core.nodetype.NodeTypeDataManager;
+import org.exoplatform.services.jcr.dataflow.ItemDataConsumer;
import org.exoplatform.services.jcr.datamodel.InternalQName;
import org.exoplatform.services.jcr.impl.Constants;
import org.exoplatform.services.jcr.impl.core.LocationFactory;
@@ -51,6 +52,8 @@
protected final ExtendedNodeTypeManager nodeTypeManager;
protected final ValueFactory valueFactory;
+
+ protected final ItemDataConsumer dataManager;
private final ItemDefinitionData itemDefinitionData;
@@ -63,14 +66,14 @@
* @param protectedItem
*/
public ItemDefinitionImpl(ItemDefinitionData itemDefinitionData, NodeTypeDataManager
nodeTypeDataManager,
- ExtendedNodeTypeManager nodeTypeManager, LocationFactory locationFactory,
ValueFactory valueFactory)
+ ExtendedNodeTypeManager nodeTypeManager, LocationFactory locationFactory,
ValueFactory valueFactory, ItemDataConsumer dataManager)
{
-
this.itemDefinitionData = itemDefinitionData;
this.nodeTypeDataManager = nodeTypeDataManager;
this.nodeTypeManager = nodeTypeManager;
this.locationFactory = locationFactory;
this.valueFactory = valueFactory;
+ this.dataManager = dataManager;
}
/**
@@ -78,9 +81,8 @@
*/
public NodeType getDeclaringNodeType()
{
-
return new
NodeTypeImpl(nodeTypeDataManager.getNodeType(itemDefinitionData.getDeclaringNodeType()),
- nodeTypeDataManager, nodeTypeManager, locationFactory, valueFactory);
+ nodeTypeDataManager, nodeTypeManager, locationFactory, valueFactory,
dataManager);
}
/**
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/NodeDefinitionImpl.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/NodeDefinitionImpl.java 2010-05-21
10:28:31 UTC (rev 2429)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/NodeDefinitionImpl.java 2010-05-21
12:21:59 UTC (rev 2430)
@@ -22,6 +22,7 @@
import org.exoplatform.services.jcr.core.nodetype.NodeDefinitionData;
import org.exoplatform.services.jcr.core.nodetype.NodeTypeData;
import org.exoplatform.services.jcr.core.nodetype.NodeTypeDataManager;
+import org.exoplatform.services.jcr.dataflow.ItemDataConsumer;
import org.exoplatform.services.jcr.datamodel.InternalQName;
import org.exoplatform.services.jcr.impl.core.LocationFactory;
import org.exoplatform.services.log.ExoLogger;
@@ -55,11 +56,11 @@
* @param valueFactory
*/
public NodeDefinitionImpl(NodeDefinitionData nodeDefinitionData, NodeTypeDataManager
nodeTypeDataManager,
- ExtendedNodeTypeManager nodeTypeManager, LocationFactory locationFactory,
ValueFactory valueFactory)
+ ExtendedNodeTypeManager nodeTypeManager, LocationFactory locationFactory,
ValueFactory valueFactory,
+ ItemDataConsumer dataManager)
{
- super(nodeDefinitionData, nodeTypeDataManager, nodeTypeManager, locationFactory,
valueFactory);
+ super(nodeDefinitionData, nodeTypeDataManager, nodeTypeManager, locationFactory,
valueFactory, dataManager);
this.nodeDefinitionData = nodeDefinitionData;
-
}
/**
@@ -85,7 +86,7 @@
if (nodeDefinitionData.getDefaultPrimaryType() == null)
return null;
return new
NodeTypeImpl(nodeTypeDataManager.getNodeType(nodeDefinitionData.getDefaultPrimaryType()),
- nodeTypeDataManager, nodeTypeManager, locationFactory, valueFactory);
+ nodeTypeDataManager, nodeTypeManager, locationFactory, valueFactory,
dataManager);
}
/**
@@ -162,7 +163,9 @@
LOG.error("NODE TYPE NOT FOUND " +
requiredPrimaryTypes[i].getAsString());
}
else
- result[i] = new NodeTypeImpl(ntData, nodeTypeDataManager, nodeTypeManager,
locationFactory, valueFactory);
+ result[i] =
+ new NodeTypeImpl(ntData, nodeTypeDataManager, nodeTypeManager,
locationFactory, valueFactory,
+ dataManager);
}
return result;
}
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/NodeTypeDataManagerImpl.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/NodeTypeDataManagerImpl.java 2010-05-21
10:28:31 UTC (rev 2429)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/NodeTypeDataManagerImpl.java 2010-05-21
12:21:59 UTC (rev 2430)
@@ -100,6 +100,10 @@
protected final NodeTypeRepository nodeTypeRepository;
+ protected final NodeTypeConverter nodeTypeConverter;
+
+ protected final NodeTypeDataValidator nodeTypeDataValidator;
+
/**
* Listeners (soft references)
*/
@@ -109,37 +113,21 @@
private boolean started = false;
- public NodeTypeDataManagerImpl(final RepositoryEntry config, final LocationFactory
locationFactory,
- final NamespaceRegistry namespaceRegistry, final NodeTypeDataPersister persister,
- final ItemDataConsumer dataManager, final RepositoryIndexSearcherHolder
indexSearcherHolder)
- throws RepositoryException
- {
-
- this.namespaceRegistry = namespaceRegistry;
-
- this.locationFactory = locationFactory;
- this.dataManager = dataManager;
- this.indexSearcherHolder = indexSearcherHolder;
-
- this.valueFactory = new ValueFactoryImpl(locationFactory);
- this.accessControlPolicy = config.getAccessControl();
-
- this.nodeTypeRepository = new InmemoryNodeTypeRepository(persister);
- this.listeners = Collections.synchronizedMap(new
WeakHashMap<NodeTypeManagerListener, NodeTypeManagerListener>());
- this.buildInNodeTypesNames = new HashSet<InternalQName>();
- }
-
/**
- * @param accessControlPolicy
- * @param locationFactory
- * @param namespaceRegistry
- * @param persister
- * @throws RepositoryException
+ * NodeTypeDataManagerImpl constructor.
+ *
+ * @param accessControlPolicy String
+ * @param locationFactory LocationFactory
+ * @param namespaceRegistry NamespaceRegistry
+ * @param persister NodeTypeDataPersister
+ * @param dataManager ItemDataConsumer
+ * @param indexSearcherHolder RepositoryIndexSearcherHolder
+ * @param nodeTypeRepository NodeTypeRepository
*/
public NodeTypeDataManagerImpl(final String accessControlPolicy, final LocationFactory
locationFactory,
final NamespaceRegistry namespaceRegistry, final NodeTypeDataPersister persister,
final ItemDataConsumer dataManager, final RepositoryIndexSearcherHolder
indexSearcherHolder,
- final NodeTypeRepository nodeTypeRepository) throws RepositoryException
+ final NodeTypeRepository nodeTypeRepository)
{
this.namespaceRegistry = namespaceRegistry;
@@ -153,9 +141,30 @@
this.nodeTypeRepository = nodeTypeRepository;
this.listeners = Collections.synchronizedMap(new
WeakHashMap<NodeTypeManagerListener, NodeTypeManagerListener>());
this.buildInNodeTypesNames = new HashSet<InternalQName>();
+
+ this.nodeTypeConverter = new NodeTypeConverter(this.locationFactory,
this.accessControlPolicy);
+ this.nodeTypeDataValidator = new NodeTypeDataValidator(this.locationFactory,
this.nodeTypeRepository);
}
/**
+ * Constructor for in-container use.
+ *
+ * @param config RepositoryEntry
+ * @param locationFactory LocationFactory
+ * @param namespaceRegistry NamespaceRegistry
+ * @param persister NodeTypeDataPersister
+ * @param dataManager ItemDataConsumer
+ * @param indexSearcherHolder RepositoryIndexSearcherHolder
+ */
+ public NodeTypeDataManagerImpl(final RepositoryEntry config, final LocationFactory
locationFactory,
+ final NamespaceRegistry namespaceRegistry, final NodeTypeDataPersister persister,
+ final ItemDataConsumer dataManager, final RepositoryIndexSearcherHolder
indexSearcherHolder)
+ {
+ this(config.getAccessControl(), locationFactory, namespaceRegistry, persister,
dataManager, indexSearcherHolder,
+ new InmemoryNodeTypeRepository(persister));
+ }
+
+ /**
* Add a <code>NodeTypeRegistryListener</code>
*
* @param listener the new listener to be informed on (un)registration of node
@@ -580,9 +589,6 @@
public List<NodeTypeData> registerNodeTypes(final InputStream is, final int
alreadyExistsBehaviour,
final String contentType) throws RepositoryException
{
-
- final NodeTypeConverter nodeTypeConverter = new
NodeTypeConverter(this.locationFactory, this.accessControlPolicy);
- final NodeTypeDataValidator nodeTypeDataValidator = new
NodeTypeDataValidator(this.nodeTypeRepository);
NodeTypeDataPersister serializer = null;
if (contentType.equalsIgnoreCase(TEXT_XML))
{
@@ -611,9 +617,6 @@
public List<NodeTypeData> registerNodeTypes(final List<NodeTypeValue>
ntvalues, final int alreadyExistsBehaviour)
throws RepositoryException
{
-
- final NodeTypeConverter nodeTypeConverter = new
NodeTypeConverter(this.locationFactory, this.accessControlPolicy);
- final NodeTypeDataValidator nodeTypeDataValidator = new
NodeTypeDataValidator(this.nodeTypeRepository);
// convert to Node data.
final List<NodeTypeData> nodeTypes =
nodeTypeConverter.convertFromValueToData(ntvalues);
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/NodeTypeDefinitionImpl.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/NodeTypeDefinitionImpl.java 2010-05-21
10:28:31 UTC (rev 2429)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/NodeTypeDefinitionImpl.java 2010-05-21
12:21:59 UTC (rev 2430)
@@ -21,6 +21,7 @@
import org.exoplatform.services.jcr.core.nodetype.ExtendedNodeTypeManager;
import org.exoplatform.services.jcr.core.nodetype.NodeTypeData;
import org.exoplatform.services.jcr.core.nodetype.NodeTypeDataManager;
+import org.exoplatform.services.jcr.dataflow.ItemDataConsumer;
import org.exoplatform.services.jcr.impl.core.LocationFactory;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
@@ -53,6 +54,8 @@
protected final ValueFactory valueFactory;
+ protected final ItemDataConsumer dataManager;
+
/**
* @param name
* @param declaredChildNodeDefinitions
@@ -64,7 +67,8 @@
* @param primaryItemName
*/
public NodeTypeDefinitionImpl(NodeTypeData nodeTypeData, NodeTypeDataManager
nodeTypeDataManager,
- ExtendedNodeTypeManager nodeTypeManager, LocationFactory locationFactory,
ValueFactory valueFactory)
+ ExtendedNodeTypeManager nodeTypeManager, LocationFactory locationFactory,
ValueFactory valueFactory,
+ ItemDataConsumer dataManager)
{
super();
this.nodeTypeData = nodeTypeData;
@@ -72,7 +76,7 @@
this.nodeTypeManager = nodeTypeManager;
this.locationFactory = locationFactory;
this.valueFactory = valueFactory;
-
+ this.dataManager = dataManager;
}
/**
@@ -118,7 +122,7 @@
{
result[i] =
new NodeDefinitionImpl(nodeTypeData.getDeclaredChildNodeDefinitions()[i],
nodeTypeDataManager,
- nodeTypeManager, locationFactory, valueFactory);
+ nodeTypeManager, locationFactory, valueFactory, dataManager);
}
return result;
}
@@ -133,7 +137,7 @@
{
result[i] =
new PropertyDefinitionImpl(nodeTypeData.getDeclaredPropertyDefinitions()[i],
nodeTypeDataManager,
- nodeTypeManager, locationFactory, valueFactory);
+ nodeTypeManager, locationFactory, valueFactory, dataManager);
}
return result;
}
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/NodeTypeImpl.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/NodeTypeImpl.java 2010-05-21
10:28:31 UTC (rev 2429)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/NodeTypeImpl.java 2010-05-21
12:21:59 UTC (rev 2430)
@@ -24,10 +24,12 @@
import org.exoplatform.services.jcr.core.nodetype.NodeTypeDataManager;
import org.exoplatform.services.jcr.core.nodetype.PropertyDefinitionData;
import org.exoplatform.services.jcr.core.nodetype.PropertyDefinitionDatas;
+import org.exoplatform.services.jcr.dataflow.ItemDataConsumer;
import org.exoplatform.services.jcr.datamodel.InternalQName;
import org.exoplatform.services.jcr.impl.Constants;
import org.exoplatform.services.jcr.impl.core.LocationFactory;
-import
org.exoplatform.services.jcr.impl.core.nodetype.registration.NodeTypeReadException;
+import org.exoplatform.services.jcr.impl.core.value.BaseValue;
+import org.exoplatform.services.jcr.impl.core.value.ValueConstraintsMatcher;
import org.exoplatform.services.jcr.impl.util.JCRDateFormat;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
@@ -66,19 +68,20 @@
protected static final Log LOG =
ExoLogger.getLogger("exo.jcr.component.core.NodeTypeImpl");
/**
- * @param nodeTypeData
- * @param nodeTypeDataManager
- * @param nodeTypeManager
- * @param locationFactory
- * @param valueFactory
- * @throws RepositoryException
- * @throws NodeTypeReadException
+ * NodeTypeImpl contructor.
+ *
+ * @param nodeTypeData NodeTypeData
+ * @param nodeTypeDataManager NodeTypeDataManager
+ * @param nodeTypeManager ExtendedNodeTypeManager
+ * @param locationFactory LocationFactory
+ * @param valueFactory ValueFactory
+ * @param dataManager ItemDataConsumer
*/
public NodeTypeImpl(NodeTypeData nodeTypeData, NodeTypeDataManager
nodeTypeDataManager,
- ExtendedNodeTypeManager nodeTypeManager, LocationFactory locationFactory,
ValueFactory valueFactory)
+ ExtendedNodeTypeManager nodeTypeManager, LocationFactory locationFactory,
ValueFactory valueFactory,
+ ItemDataConsumer dataManager)
{
- super(nodeTypeData, nodeTypeDataManager, nodeTypeManager, locationFactory,
valueFactory);
-
+ super(nodeTypeData, nodeTypeDataManager, nodeTypeManager, locationFactory,
valueFactory, dataManager);
}
/**
@@ -86,7 +89,6 @@
*/
public boolean canAddChildNode(String childNodeName)
{
-
try
{
InternalQName cname =
locationFactory.parseJCRName(childNodeName).getInternalName();
@@ -169,14 +171,20 @@
if (pd != null)
{
if (pd.isProtected())
+ {
// can set (edit)
return false;
+ }
else if (value != null)
+ {
// can set (add or edit)
return canSetPropertyForType(pd.getRequiredType(), value,
pd.getValueConstraints());
+ }
else
+ {
// can remove
return !pd.isMandatory();
+ }
}
}
return false;
@@ -202,8 +210,10 @@
if (pd != null)
{
if (pd.isProtected())
+ {
// can set (edit)
return false;
+ }
else if (values != null)
{
// can set (add or edit)
@@ -211,16 +221,22 @@
for (Value value : values)
{
if (canSetPropertyForType(pd.getRequiredType(), value,
pd.getValueConstraints()))
+ {
res++;
+ }
}
return res == values.length;
}
else
+ {
// can remove
return !pd.isMandatory();
+ }
}
else
+ {
return false;
+ }
}
catch (RepositoryException e)
{
@@ -240,7 +256,9 @@
for (int i = 0; i < nodeDefs.length; i++)
{
NodeDefinitionData cnd = nodeDefs[i];
- ndefs[i] = new NodeDefinitionImpl(cnd, nodeTypeDataManager, nodeTypeManager,
locationFactory, valueFactory);
+ ndefs[i] =
+ new NodeDefinitionImpl(cnd, nodeTypeDataManager, nodeTypeManager,
locationFactory, valueFactory,
+ dataManager);
}
return ndefs;
@@ -256,7 +274,9 @@
for (int i = 0; i < cndefs.length; i++)
{
NodeDefinitionData cnd = cndefs[i];
- ndefs[i] = new NodeDefinitionImpl(cnd, nodeTypeDataManager, nodeTypeManager,
locationFactory, valueFactory);
+ ndefs[i] =
+ new NodeDefinitionImpl(cnd, nodeTypeDataManager, nodeTypeManager,
locationFactory, valueFactory,
+ dataManager);
}
return ndefs;
@@ -281,7 +301,8 @@
{
NodeTypeData superNodeTypeData = nodeTypeDataManager.getNodeType(snames[i]);
supers[i] =
- new NodeTypeImpl(superNodeTypeData, nodeTypeDataManager, nodeTypeManager,
locationFactory, valueFactory);
+ new NodeTypeImpl(superNodeTypeData, nodeTypeDataManager, nodeTypeManager,
locationFactory, valueFactory,
+ dataManager);
}
return supers;
@@ -421,35 +442,35 @@
*
* @param requiredType - type.
* @param value - value.
- * @param constrains - constrains.
+ * @param constraints - constraints.
* @return a boolean.
*/
- private boolean canSetPropertyForType(int requiredType, Value value, String[]
constrains)
+ private boolean canSetPropertyForType(int requiredType, Value value, String[]
constraints)
{
if (requiredType == value.getType())
{
- return checkValueConstraints(constrains, value);
+ return checkValueConstraints(requiredType, constraints, value);
}
else if (requiredType == PropertyType.BINARY
&& (value.getType() == PropertyType.STRING || value.getType() ==
PropertyType.DATE
|| value.getType() == PropertyType.LONG || value.getType() ==
PropertyType.DOUBLE
|| value.getType() == PropertyType.NAME || value.getType() ==
PropertyType.PATH || value.getType() == PropertyType.BOOLEAN))
{
- return checkValueConstraints(constrains, value);
+ return checkValueConstraints(requiredType, constraints, value);
}
else if (requiredType == PropertyType.BOOLEAN)
{
if (value.getType() == PropertyType.STRING)
{
- return checkValueConstraints(constrains, value);
+ return checkValueConstraints(requiredType, constraints, value);
}
else if (value.getType() == PropertyType.BINARY)
{
try
{
return isCharsetString(value.getString(), Constants.DEFAULT_ENCODING)
- && checkValueConstraints(constrains, value);
+ && checkValueConstraints(requiredType, constraints, value);
}
catch (Exception e)
{
@@ -477,7 +498,7 @@
}
else if (value.getType() == PropertyType.DOUBLE || value.getType() ==
PropertyType.LONG)
{
- return checkValueConstraints(constrains, value);
+ return checkValueConstraints(requiredType, constraints, value);
}
else
{
@@ -486,7 +507,7 @@
// try parse...
JCRDateFormat.parse(likeDataString);
// validate
- return checkValueConstraints(constrains, value);
+ return checkValueConstraints(requiredType, constraints, value);
}
catch (Exception e)
{
@@ -513,14 +534,14 @@
}
else if (value.getType() == PropertyType.LONG)
{
- return checkValueConstraints(constrains, value);
+ return checkValueConstraints(requiredType, constraints, value);
}
else
{
return false;
}
Double doubleValue = new Double(likeDoubleString);
- return doubleValue != null && checkValueConstraints(constrains,
value);
+ return doubleValue != null && checkValueConstraints(requiredType,
constraints, value);
}
catch (Exception e)
{
@@ -554,7 +575,7 @@
return false;
}
Long longValue = new Long(likeLongString);
- return longValue != null && checkValueConstraints(constrains,
value);
+ return longValue != null && checkValueConstraints(requiredType,
constraints, value);
}
catch (Exception e)
{
@@ -591,11 +612,11 @@
// Path is relative
// TRUE if it is one element long
// and has no index
- return checkValueConstraints(constrains, value);
+ return checkValueConstraints(requiredType, constraints, value);
}
else if (pathString.startsWith("/") &&
pathString.lastIndexOf("/") < 1 && pathString.indexOf("[")
< 0)
{
- return checkValueConstraints(constrains, value);
+ return checkValueConstraints(requiredType, constraints, value);
}
else
{
@@ -609,7 +630,7 @@
try
{
Value nameValue = valueFactory.createValue(likeNameString, requiredType);
- return nameValue != null && checkValueConstraints(constrains,
value);
+ return nameValue != null && checkValueConstraints(requiredType,
constraints, value);
}
catch (Exception e)
{
@@ -636,7 +657,7 @@
}
else if (value.getType() == PropertyType.NAME)
{
- return checkValueConstraints(constrains, value);
+ return checkValueConstraints(requiredType, constraints, value);
}
else
{
@@ -645,7 +666,7 @@
try
{
Value nameValue = valueFactory.createValue(likeNameString, requiredType);
- return nameValue != null && checkValueConstraints(constrains,
value);
+ return nameValue != null && checkValueConstraints(requiredType,
constraints, value);
}
catch (Exception e)
{
@@ -676,7 +697,7 @@
{
return false;
}
- return likeStringString != null && checkValueConstraints(constrains,
value);
+ return likeStringString != null &&
checkValueConstraints(requiredType, constraints, value);
}
catch (Exception e)
{
@@ -685,7 +706,7 @@
}
else if (requiredType == PropertyType.UNDEFINED)
{
- return checkValueConstraints(constrains, value);
+ return checkValueConstraints(requiredType, constraints, value);
}
else
{
@@ -696,34 +717,47 @@
/**
* Check value constrains.
*
+ * @param requiredType int
* @param constraints - string constrains.
* @param value - value to check.
* @return result of check.
*/
- private boolean checkValueConstraints(String[] constraints, Value value)
+ private boolean checkValueConstraints(int requiredType, String[] constraints, Value
value)
{
+ ValueConstraintsMatcher constrMatcher =
+ new ValueConstraintsMatcher(constraints, locationFactory, dataManager,
nodeTypeDataManager);
- if (constraints != null && constraints.length > 0)
+ try
{
- for (int i = 0; i < constraints.length; i++)
- {
- try
- {
- if (constraints[i].equals(value.getString()))
- {
- return true;
- }
- }
- catch (RepositoryException e)
- {
- LOG.error("Can't get value's string value " + e, e);
- }
- }
+ return constrMatcher.match(((BaseValue)value).getInternalData(), requiredType);
}
- else
- return true;
+ catch (RepositoryException e1)
+ {
+ return false;
+ }
- return false;
+ // TODO old code
+ // if (constraints != null && constraints.length > 0)
+ // {
+ // for (int i = 0; i < constraints.length; i++)
+ // {
+ // try
+ // {
+ // if (constraints[i].equals(value.getString()))
+ // {
+ // return true;
+ // }
+ // }
+ // catch (RepositoryException e)
+ // {
+ // LOG.error("Can't get value's string value " + e,
e);
+ // }
+ // }
+ // }
+ // else
+ // return true;
+ //
+ // return false;
}
private String getCharsetString(String source, String charSetName)
@@ -764,7 +798,8 @@
for (int i = 0; i < pdefs.length; i++)
{
propertyDefinitions[i] =
- new PropertyDefinitionImpl(pdefs[i], nodeTypeDataManager, nodeTypeManager,
locationFactory, valueFactory);
+ new PropertyDefinitionImpl(pdefs[i], nodeTypeDataManager, nodeTypeManager,
locationFactory, valueFactory,
+ dataManager);
}
return propertyDefinitions;
}
@@ -781,30 +816,4 @@
return false;
}
}
-
- /**
- * @param nodeTypeData
- * @return
- * @throws NoSuchNodeTypeException
- * @throws RepositoryException
- */
- private NodeDefinition makeNodeDefinition(NodeDefinitionData nodeTypeData) throws
NoSuchNodeTypeException,
- RepositoryException
- {
- InternalQName[] rnames = nodeTypeData.getRequiredPrimaryTypes();
- NodeType[] rnts = new NodeType[rnames.length];
- for (int j = 0; j < rnames.length; j++)
- {
- rnts[j] = nodeTypeManager.findNodeType(rnames[j]);
- }
-
- String name =
- locationFactory
- .createJCRName(nodeTypeData.getName() != null ? nodeTypeData.getName() :
Constants.JCR_ANY_NAME)
- .getAsString();
- NodeType defType =
- nodeTypeData.getDefaultPrimaryType() != null ?
nodeTypeManager.findNodeType(nodeTypeData
- .getDefaultPrimaryType()) : null;
- return new NodeDefinitionImpl(nodeTypeData, nodeTypeDataManager, nodeTypeManager,
locationFactory, valueFactory);
- }
}
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/NodeTypeManagerImpl.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/NodeTypeManagerImpl.java 2010-05-21
10:28:31 UTC (rev 2429)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/NodeTypeManagerImpl.java 2010-05-21
12:21:59 UTC (rev 2430)
@@ -26,6 +26,7 @@
import org.exoplatform.services.jcr.core.nodetype.NodeTypeValue;
import org.exoplatform.services.jcr.core.nodetype.PropertyDefinitionData;
import org.exoplatform.services.jcr.core.nodetype.PropertyDefinitionValue;
+import org.exoplatform.services.jcr.dataflow.ItemDataConsumer;
import org.exoplatform.services.jcr.datamodel.InternalQName;
import org.exoplatform.services.jcr.impl.Constants;
import org.exoplatform.services.jcr.impl.core.LocationFactory;
@@ -53,8 +54,7 @@
* Created by The eXo Platform SAS.
*
* @author <a href="mailto:geaz@users.sourceforge.net">Gennady Azarenkov
</a>
- * @version $Id: NodeTypeManagerImpl.java 13986 2008-05-08 10:48:43Z pnedonosko
- * $
+ * @version $Id: NodeTypeManagerImpl.java 13986 2008-05-08 10:48:43Z pnedonosko$
*/
public class NodeTypeManagerImpl implements ExtendedNodeTypeManager
{
@@ -68,14 +68,16 @@
protected final LocationFactory locationFactory;
protected final NodeTypeDataManager typesManager;
+
+ protected final ItemDataConsumer dataManager;
public NodeTypeManagerImpl(LocationFactory locationFactory, ValueFactoryImpl
valueFactory,
- NodeTypeDataManager typesManager)
+ NodeTypeDataManager typesManager, ItemDataConsumer dataManager)
{
this.valueFactory = valueFactory;
this.locationFactory = locationFactory;
this.typesManager = typesManager;
-
+ this.dataManager = dataManager;
}
// JSR-170 stuff ================================
@@ -85,8 +87,9 @@
NodeTypeData ntdata = typesManager.getNodeType(nodeTypeName);
if (ntdata != null)
- return new NodeTypeImpl(ntdata, typesManager, this, locationFactory,
valueFactory);
-
+ {
+ return new NodeTypeImpl(ntdata, typesManager, this, locationFactory,
valueFactory, dataManager);
+ }
throw new NoSuchNodeTypeException("Nodetype not found " +
nodeTypeName.getAsString());
}
@@ -99,8 +102,9 @@
List<NodeTypeData> allNts = typesManager.getAllNodeTypes();
for (NodeTypeData ntdata : allNts)
- ec.add(new NodeTypeImpl(ntdata, typesManager, this, locationFactory,
valueFactory));
-
+ {
+ ec.add(new NodeTypeImpl(ntdata, typesManager, this, locationFactory,
valueFactory, dataManager));
+ }
return ec;
}
@@ -120,8 +124,9 @@
for (NodeTypeData nodeTypeData : allNodeTypes)
{
if (nodeTypeData.isMixin())
- ec.add(new NodeTypeImpl(nodeTypeData, typesManager, this, locationFactory,
valueFactory));
-
+ {
+ ec.add(new NodeTypeImpl(nodeTypeData, typesManager, this, locationFactory,
valueFactory, dataManager));
+ }
}
return ec;
}
@@ -133,8 +138,9 @@
{
NodeTypeData ntdata =
typesManager.getNodeType(locationFactory.parseJCRName(nodeTypeName).getInternalName());
if (ntdata != null)
- return new NodeTypeImpl(ntdata, typesManager, this, locationFactory,
valueFactory);
-
+ {
+ return new NodeTypeImpl(ntdata, typesManager, this, locationFactory,
valueFactory, dataManager);
+ }
throw new NoSuchNodeTypeException("Nodetype not found " + nodeTypeName);
}
@@ -193,7 +199,6 @@
}
throw new NoSuchNodeTypeException("Nodetype not found " + nodeTypeName);
-
}
/**
@@ -210,7 +215,9 @@
{
NodeType type = allTypes.nextNodeType();
if (!type.isMixin())
+ {
ec.add(type);
+ }
}
return ec;
}
@@ -245,12 +252,12 @@
public NodeTypeIterator registerNodeTypes(List<NodeTypeValue> values, int
alreadyExistsBehaviour)
throws UnsupportedRepositoryOperationException, RepositoryException
{
-
Collection<NodeTypeData> nts = typesManager.registerNodeTypes(values,
alreadyExistsBehaviour);
EntityCollection types = new EntityCollection();
for (NodeTypeData ntdata : nts)
- types.add(new NodeTypeImpl(ntdata, typesManager, this, locationFactory,
valueFactory));
-
+ {
+ types.add(new NodeTypeImpl(ntdata, typesManager, this, locationFactory,
valueFactory, dataManager));
+ }
return types;
}
@@ -262,12 +269,12 @@
public NodeTypeIterator registerNodeTypes(InputStream xml, int alreadyExistsBehaviour,
String contentType)
throws RepositoryException
{
-
Collection<NodeTypeData> nts = typesManager.registerNodeTypes(xml,
alreadyExistsBehaviour, contentType);
EntityCollection types = new EntityCollection();
for (NodeTypeData ntdata : nts)
- types.add(new NodeTypeImpl(ntdata, typesManager, this, locationFactory,
valueFactory));
-
+ {
+ types.add(new NodeTypeImpl(ntdata, typesManager, this, locationFactory,
valueFactory, dataManager));
+ }
return types;
}
@@ -285,8 +292,9 @@
typesManager.registerNodeTypes(xml, alreadyExistsBehaviour,
NodeTypeDataManager.TEXT_XML);
EntityCollection types = new EntityCollection();
for (NodeTypeData ntdata : nts)
- types.add(new NodeTypeImpl(ntdata, typesManager, this, locationFactory,
valueFactory));
-
+ {
+ types.add(new NodeTypeImpl(ntdata, typesManager, this, locationFactory,
valueFactory, dataManager));
+ }
return types;
}
@@ -298,7 +306,9 @@
{
InternalQName nodeTypeName = locationFactory.parseJCRName(name).getInternalName();
if (typesManager.getNodeType(nodeTypeName) == null)
+ {
throw new NoSuchNodeTypeException(name);
+ }
typesManager.unregisterNodeType(nodeTypeName);
}
@@ -312,7 +322,6 @@
{
unregisterNodeType(names[i]);
}
-
}
private NodeDefinitionValue convert(NodeDefinitionData data) throws
RepositoryException
Property changes on:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/NodeTypeManagerImpl.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/PropertyDefinitionImpl.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/PropertyDefinitionImpl.java 2010-05-21
10:28:31 UTC (rev 2429)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/PropertyDefinitionImpl.java 2010-05-21
12:21:59 UTC (rev 2430)
@@ -21,6 +21,7 @@
import org.exoplatform.services.jcr.core.nodetype.ExtendedNodeTypeManager;
import org.exoplatform.services.jcr.core.nodetype.NodeTypeDataManager;
import org.exoplatform.services.jcr.core.nodetype.PropertyDefinitionData;
+import org.exoplatform.services.jcr.dataflow.ItemDataConsumer;
import org.exoplatform.services.jcr.impl.core.LocationFactory;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
@@ -53,12 +54,13 @@
* @param nodeTypeManager
* @param locationFactory
* @param valueFactory
+ * @param dataManager
*/
public PropertyDefinitionImpl(PropertyDefinitionData propertyDefinitionData,
NodeTypeDataManager nodeTypeDataManager, ExtendedNodeTypeManager nodeTypeManager,
- LocationFactory locationFactory, ValueFactory valueFactory)
+ LocationFactory locationFactory, ValueFactory valueFactory, ItemDataConsumer
dataManager)
{
- super(propertyDefinitionData, nodeTypeDataManager, nodeTypeManager,
locationFactory, valueFactory);
+ super(propertyDefinitionData, nodeTypeDataManager, nodeTypeManager,
locationFactory, valueFactory, dataManager);
this.propertyDefinitionData = propertyDefinitionData;
}
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/NodeTypeDataValidator.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/NodeTypeDataValidator.java 2010-05-21
10:28:31 UTC (rev 2429)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/NodeTypeDataValidator.java 2010-05-21
12:21:59 UTC (rev 2430)
@@ -20,37 +20,97 @@
import org.exoplatform.services.jcr.core.nodetype.NodeDefinitionData;
import org.exoplatform.services.jcr.core.nodetype.NodeTypeData;
+import org.exoplatform.services.jcr.core.nodetype.PropertyDefinitionData;
import org.exoplatform.services.jcr.datamodel.InternalQName;
+import org.exoplatform.services.jcr.datamodel.ValueData;
import org.exoplatform.services.jcr.impl.Constants;
+import org.exoplatform.services.jcr.impl.core.LocationFactory;
import org.exoplatform.services.jcr.impl.core.nodetype.NodeTypeRepository;
+import org.exoplatform.services.jcr.impl.core.value.ValueConstraintsValidator;
+import org.exoplatform.services.jcr.impl.core.value.ValueFactoryImpl;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
+import java.io.InputStream;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
+import javax.jcr.PropertyType;
import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+import javax.jcr.ValueFormatException;
/**
* Created by The eXo Platform SAS.
*
* @author <a href="mailto:Sergey.Kabashnyuk@gmail.com">Sergey
Kabashnyuk</a>
- * @version $Id: $
+ * @version $Id$
*/
public class NodeTypeDataValidator
{
/**
* Class logger.
*/
- private final Log log =
ExoLogger.getLogger("exo.jcr.component.core.NodeTypeDataValidator");
+ private final static Log LOG =
ExoLogger.getLogger("exo.jcr.component.core.NodeTypeDataValidator");
protected final NodeTypeRepository hierarchy;
- public NodeTypeDataValidator(NodeTypeRepository hierarchy)
+ protected final ValueFactoryImpl valueFactory;
+
+ protected class ValidatorValueFactory extends ValueFactoryImpl
{
- super();
+ ValidatorValueFactory(LocationFactory locationFactory)
+ {
+ super(locationFactory);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Value createValue(String value, int type) throws ValueFormatException
+ {
+ if (type == PropertyType.BINARY)
+ {
+ LOG.warn("Not supported Value type: BINARY");
+ return null;
+ }
+
+ return super.createValue(value, type);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Value createValue(InputStream value)
+ {
+ LOG.warn("Not supported Value type: BINARY");
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Value loadValue(ValueData data, int type) throws RepositoryException
+ {
+ if (type == PropertyType.BINARY)
+ {
+ LOG.warn("Not supported Value type: BINARY");
+ return null;
+ }
+
+ return super.loadValue(data, type);
+ }
+ }
+
+ public NodeTypeDataValidator(LocationFactory locationFactory, NodeTypeRepository
hierarchy)
+ {
this.hierarchy = hierarchy;
+
+ this.valueFactory = new ValidatorValueFactory(locationFactory);
}
public void validateNodeType(List<NodeTypeData> nodeTypeDataList) throws
RepositoryException
@@ -100,7 +160,6 @@
&&
!resolvedDependecies.contains(childnodeDefinitionData.getDefaultPrimaryType()))
{
unresolvedDependecies.add(childnodeDefinitionData.getDefaultPrimaryType());
-
}
}
}
@@ -133,36 +192,77 @@
throw new RepositoryException("NodeType object " + nodeType + "
is null");
}
- for (int i = 0; i < nodeType.getDeclaredSupertypeNames().length; i++)
+ if (nodeType.getName() == null)
{
- if (!nodeType.getName().equals(Constants.NT_BASE)
- &&
nodeType.getName().equals(nodeType.getDeclaredSupertypeNames()[i]))
+ throw new RepositoryException("NodeType implementation class " +
nodeType.getClass().getName()
+ + " is not supported in this method");
+ }
+
+ for (InternalQName sname : nodeType.getDeclaredSupertypeNames())
+ {
+ if (!nodeType.getName().equals(Constants.NT_BASE) &&
nodeType.getName().equals(sname))
{
- throw new RepositoryException("Invalid super type name"
- + nodeType.getDeclaredSupertypeNames()[i].getAsString());
+ throw new RepositoryException("Invalid super type name" +
sname.getAsString());
}
}
- for (int i = 0; i < nodeType.getDeclaredPropertyDefinitions().length; i++)
+
+ for (PropertyDefinitionData pdef : nodeType.getDeclaredPropertyDefinitions())
{
- if
(!nodeType.getDeclaredPropertyDefinitions()[i].getDeclaringNodeType().equals(nodeType.getName()))
+ if (!pdef.getDeclaringNodeType().equals(nodeType.getName()))
{
- throw new RepositoryException("Invalid declared node type in property
definitions with name "
- + nodeType.getDeclaredPropertyDefinitions()[i].getName().getAsString() +
" not registred");
+ throw new RepositoryException("Invalid declared node type in property
definitions with name "
+ + pdef.getName().getAsString() + " not registred");
}
+
+ // validate default values
+ try
+ {
+ validateValueDefaults(pdef.getRequiredType(), pdef.getDefaultValues());
+ }
+ catch (ValueFormatException e)
+ {
+ throw new ValueFormatException("Default value is incompatible with
Property type "
+ + PropertyType.nameFromValue(pdef.getRequiredType()) + " of " +
pdef.getName().getAsString()
+ + " in nodetype " + nodeType.getName().getAsString(), e);
+ }
+
+ // TODO validate constraints, we have issue with TCK nodetype
tests:canSetProperty
+ try
+ {
+ validateValueConstraints(pdef.getRequiredType(),
pdef.getValueConstraints());
+ }
+ catch (ValueFormatException e)
+ {
+ throw new ValueFormatException("Constraints is incompatible with
Property type "
+ + PropertyType.nameFromValue(pdef.getRequiredType()) + " of " +
pdef.getName().getAsString()
+ + " in nodetype " + nodeType.getName().getAsString(), e);
+ }
}
- for (int i = 0; i < nodeType.getDeclaredChildNodeDefinitions().length; i++)
+
+ for (NodeDefinitionData cndef : nodeType.getDeclaredChildNodeDefinitions())
{
- if
(!nodeType.getDeclaredChildNodeDefinitions()[i].getDeclaringNodeType().equals(nodeType.getName()))
+ if (!cndef.getDeclaringNodeType().equals(nodeType.getName()))
{
- throw new RepositoryException("Invalid declared node type in child node
definitions with name "
- + nodeType.getDeclaredChildNodeDefinitions()[i].getName().getAsString() +
" not registred");
+ throw new RepositoryException("Invalid declared node type in child node
definitions with name "
+ + cndef.getName().getAsString() + " not registred");
}
}
+ }
- if (nodeType.getName() == null)
+ private void validateValueDefaults(int requiredType, String[] defValues) throws
ValueFormatException
+ {
+ if (requiredType != PropertyType.STRING && requiredType !=
PropertyType.UNDEFINED && requiredType != PropertyType.BINARY)
{
- throw new RepositoryException("NodeType implementation class " +
nodeType.getClass().getName()
- + " is not supported in this method");
+ for (String dv : defValues)
+ {
+ valueFactory.createValue(dv, requiredType);
+ }
}
}
+
+ private void validateValueConstraints(int requiredType, String[] constraints) throws
ValueFormatException
+ {
+ ValueConstraintsValidator validator = new ValueConstraintsValidator(constraints);
+ validator.validateFor(requiredType);
+ }
}
Property changes on:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/NodeTypeDataValidator.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/PropertyDefinitionComparator.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/PropertyDefinitionComparator.java 2010-05-21
10:28:31 UTC (rev 2429)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/PropertyDefinitionComparator.java 2010-05-21
12:21:59 UTC (rev 2430)
@@ -335,8 +335,7 @@
}
}
- private void checkValueConstraints(PropertyDefinitionData def, PropertyData
propertyData)
- throws ConstraintViolationException, RepositoryException
+ private void checkValueConstraints(PropertyDefinitionData def, PropertyData
propertyData) throws RepositoryException
{
ValueConstraintsMatcher constraints =
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/value/ValueConstraintsMatcher.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/value/ValueConstraintsMatcher.java 2010-05-21
10:28:31 UTC (rev 2429)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/value/ValueConstraintsMatcher.java 2010-05-21
12:21:59 UTC (rev 2430)
@@ -39,25 +39,18 @@
import javax.jcr.PropertyType;
import javax.jcr.RepositoryException;
import javax.jcr.ValueFormatException;
-import javax.jcr.nodetype.ConstraintViolationException;
/**
- * Created by The eXo Platform SAS Author : Peter Nedonosko
- * peter.nedonosko(a)exoplatform.com.ua 13.09.2006
+ * Created by The eXo Platform SAS.
*
- * @author <a href="mailto:peter.nedonosko@exoplatform.com.ua">Peter
- * Nedonosko</a>
- * @version $Id: ValueConstraintsMatcher.java 12171 2008-03-20 15:37:28Z ksm $
+ * @author <a href="mailto:peter.nedonosko@exoplatform.com">Peter
Nedonosko</a>
+ * @version $Id$
*/
-public class ValueConstraintsMatcher
+public class ValueConstraintsMatcher extends ValueConstraintsValidator
{
- protected static Log log =
ExoLogger.getLogger("exo.jcr.component.core.ValueConstraintsMatcher");
+ protected static final Log LOG =
ExoLogger.getLogger("exo.jcr.component.core.ValueConstraintsMatcher");
- protected final static String DEFAULT_THRESHOLD = "";
-
- private final String[] constraints;
-
private final LocationFactory locator;
private final ItemDataConsumer itemDataConsumer;
@@ -67,24 +60,32 @@
public ValueConstraintsMatcher(String[] constraints, LocationFactory locator,
ItemDataConsumer itemDataConsumer,
NodeTypeDataManager nodeTypeDataManager)
{
- this.constraints = constraints;
+ super(constraints);
this.locator = locator;
this.itemDataConsumer = itemDataConsumer;
this.nodeTypeDataManager = nodeTypeDataManager;
-
}
- public boolean match(ValueData value, int type) throws ConstraintViolationException,
IllegalStateException,
- RepositoryException
+ /**
+ * Check given value on compatibility with a given type.
+ *
+ * @param value ValueData
+ * @param type int, property type
+ * @return boolean true if the value matches the type, false otherwise
+ * @throws RepositoryException if gathering of match conditions meets errors
(IOException or ItemNotFoundException)
+ */
+ public boolean match(ValueData value, int type) throws RepositoryException
{
if (constraints == null || constraints.length <= 0)
+ {
return true;
+ }
boolean invalid = true;
// do not use getString because of string consuming
- ValueData valueData = (ValueData)value;
+ ValueData valueData = value;
if (type == PropertyType.STRING)
{
try
@@ -112,7 +113,6 @@
}
else if (type == PropertyType.NAME)
{
-
NameValue nameVal;
try
{
@@ -131,11 +131,9 @@
invalid = false;
}
}
-
}
else if (type == PropertyType.PATH)
{
-
PathValue pathVal;
try
{
@@ -147,24 +145,18 @@
}
for (int i = 0; invalid && i < constraints.length; i++)
{
- String constrString = constraints[i];
-
- JCRPathMatcher constrPath = parsePathMatcher(locator, constrString);
+ JCRPathMatcher constrPath = parsePathMatcher(locator, constraints[i]);
if (constrPath.match(pathVal.getQPath()))
{
invalid = false;
}
}
-
}
else if (type == PropertyType.REFERENCE)
{
-
try
{
ReferenceValue refVal = new ReferenceValue(valueData);
- // NodeImpl refNode = (NodeImpl)
- // session.getNodeByUUID(refVal.getIdentifier().getString());
NodeData refNode =
(NodeData)itemDataConsumer.getItemData(refVal.getIdentifier().getString());
for (int i = 0; invalid && i < constraints.length; i++)
{
@@ -179,8 +171,10 @@
}
catch (ItemNotFoundException e)
{
- if (log.isDebugEnabled())
- log.debug("Reference constraint node is not found: " +
e.getMessage());
+ if (LOG.isDebugEnabled())
+ {
+ LOG.debug("Reference constraint node is not found: " +
e.getMessage());
+ }
// But if it's a versionHisroy ref property for add mix:versionable...
// we haven't a versionHisroy created until save method will be called
// on this
@@ -190,21 +184,19 @@
}
catch (RepositoryException e)
{
- log.error("Reference constraint error: " + e.getMessage(), e);
+ LOG.error("Reference constraint error: " + e.getMessage(), e);
// [PN] Posible trouble is session.getNodeByUUID() call result,
// till bug can be found in version restore operation.
invalid = true;
}
catch (IOException e)
{
- log.error("Reference constraint error: " + e.getMessage(), e);
+ LOG.error("Reference constraint error: " + e.getMessage(), e);
invalid = true;
}
-
}
else if (type == PropertyType.BINARY)
{
-
long valueLength = valueData.getLength();
for (int i = 0; invalid && i < constraints.length; i++)
{
@@ -221,12 +213,16 @@
if (constraint.getMin().isExclusive())
{
if (valueLength > min)
+ {
minInvalid = false;
+ }
}
else
{
if (valueLength >= min)
+ {
minInvalid = false;
+ }
}
long max =
@@ -244,11 +240,9 @@
}
invalid = maxInvalid | minInvalid;
}
-
}
else if (type == PropertyType.DATE)
{
-
Calendar valueCalendar;
try
{
@@ -260,13 +254,10 @@
}
for (int i = 0; invalid && i < constraints.length; i++)
{
- String constrString = constraints[i];
-
boolean minInvalid = true;
boolean maxInvalid = true;
- MinMaxConstraint constraint = parseAsMinMax(constrString);
-
+ MinMaxConstraint constraint = parseAsMinMax(constraints[i]);
try
{
if (constraint.getMin().getThreshold().length() > 0)
@@ -275,16 +266,22 @@
if (constraint.getMin().isExclusive())
{
if (valueCalendar.compareTo(min) > 0)
+ {
minInvalid = false;
+ }
}
else
{
if (valueCalendar.compareTo(min) >= 0)
+ {
minInvalid = false;
+ }
}
}
else
+ {
minInvalid = false;
+ }
}
catch (ValueFormatException e)
{
@@ -308,7 +305,9 @@
}
}
else
+ {
maxInvalid = false;
+ }
}
catch (ValueFormatException e)
{
@@ -317,11 +316,9 @@
invalid = maxInvalid | minInvalid;
}
-
}
else if (type == PropertyType.LONG || type == PropertyType.DOUBLE)
{
-
// will be compared as double in any case
Number valueNumber;
try
@@ -334,12 +331,10 @@
}
for (int i = 0; invalid && i < constraints.length; i++)
{
- String constrString = constraints[i];
-
boolean minInvalid = true;
boolean maxInvalid = true;
- MinMaxConstraint constraint = parseAsMinMax(constrString);
+ MinMaxConstraint constraint = parseAsMinMax(constraints[i]);
Number min =
constraint.getMin().getThreshold().length() > 0 ? new
Double(constraint.getMin().getThreshold())
@@ -347,12 +342,16 @@
if (constraint.getMin().isExclusive())
{
if (valueNumber.doubleValue() > min.doubleValue())
+ {
minInvalid = false;
+ }
}
else
{
if (valueNumber.doubleValue() >= min.doubleValue())
+ {
minInvalid = false;
+ }
}
Number max =
@@ -361,26 +360,43 @@
if (constraint.getMax().isExclusive())
{
if (valueNumber.doubleValue() < max.doubleValue())
+ {
maxInvalid = false;
+ }
}
else
{
if (valueNumber.doubleValue() <= max.doubleValue())
+ {
maxInvalid = false;
+ }
}
invalid = maxInvalid | minInvalid;
}
}
else if (type == PropertyType.BOOLEAN)
{
- // JSR-283, 4.7.17.6 BOOLEAN has no Constraint
- invalid = false;
+ try
+ {
+ boolean bvalue = Boolean.parseBoolean(new
String(valueData.getAsByteArray()));
+ for (int i = 0; invalid && i < constraints.length; i++)
+ {
+ if (Boolean.parseBoolean(constraints[i]) == bvalue)
+ {
+ invalid = false;
+ }
+ }
+ }
+ catch (IOException e)
+ {
+ throw new RepositoryException("FATAL ERROR Value data stream reading
error " + e.getMessage(), e);
+ }
}
return !invalid;
}
- JCRPath parsePath(String path, LocationFactory locFactory) throws RepositoryException
+ protected JCRPath parsePath(String path, LocationFactory locFactory) throws
RepositoryException
{
try
{
@@ -399,58 +415,14 @@
}
}
- protected MinMaxConstraint parseAsMinMax(String constraint) throws
ConstraintViolationException
- {
-
- // constraint as min,max range:
- // value constraints in the form of inclusive or exclusive ranges:
- // i.e., "[min, max]", "(min, max)", "(min, max]" or
"[min, max)".
- // Where "[" and "]" indicate "inclusive", while
"(" and ")" indicate
- // "exclusive".
- // A missing min or max value indicates no bound in that direction
-
- String[] parts = constraint.split(",");
-
- if (parts.length != 2)
- throw new ConstraintViolationException("Value constraint '" +
constraint
- + "' is invalid accrding the JSR-170 spec.");
-
- boolean exclusive = false;
-
- if (parts[0].startsWith("("))
- exclusive = true;
- else if (parts[0].startsWith("["))
- exclusive = false;
- else
- throw new ConstraintViolationException("Value constraint '" +
constraint
- + "' min exclusion rule is unefined accrding the JSR-170
spec.");
-
- ConstraintRange minValue =
- new ConstraintRange(parts[0].length() > 1 ? parts[0].substring(1) :
DEFAULT_THRESHOLD, exclusive);
-
- if (parts[1].endsWith(")"))
- exclusive = true;
- else if (parts[1].endsWith("]"))
- exclusive = false;
- else
- throw new ConstraintViolationException("Value constraint '" +
constraint
- + "' max exclusion rule is unefined accrding the JSR-170
spec.");
-
- ConstraintRange maxValue =
- new ConstraintRange(parts[1].length() > 1 ? parts[1].substring(0,
parts[1].length() - 1) : DEFAULT_THRESHOLD,
- exclusive);
-
- return new MinMaxConstraint(minValue, maxValue);
- }
-
/**
- * Parses JCR path matcher from string
+ * Parses JCR path matcher from string.
*
* @param path
* @return
* @throws RepositoryException
*/
- private JCRPathMatcher parsePathMatcher(LocationFactory locFactory, String path)
throws RepositoryException
+ protected JCRPathMatcher parsePathMatcher(LocationFactory locFactory, String path)
throws RepositoryException
{
JCRPath knownPath = null;
@@ -485,69 +457,5 @@
}
return new JCRPathMatcher(knownPath.getInternalPath(), forDescendants,
forAncestors);
-
}
-
- public class ConstraintRange
- {
-
- private final String value;
-
- private final boolean exclusive;
-
- public ConstraintRange(String value)
- {
- this.value = value;
- this.exclusive = false;
- }
-
- public ConstraintRange(String value, boolean exclusive)
- {
- this.value = value;
- this.exclusive = exclusive;
- }
-
- protected String getThreshold()
- {
- return value;
- }
-
- protected boolean isExclusive()
- {
- return exclusive;
- }
- }
-
- public class MinMaxConstraint
- {
-
- private final ConstraintRange minValue;
-
- private final ConstraintRange maxValue;
-
- private final ConstraintRange singleValue;
-
- public MinMaxConstraint(ConstraintRange minValue, ConstraintRange maxValue)
- {
- this.minValue = minValue;
- this.maxValue = maxValue;
- this.singleValue = null;
- }
-
- public ConstraintRange getSingleValue()
- {
- return singleValue;
- }
-
- protected ConstraintRange getMax()
- {
- return maxValue;
- }
-
- protected ConstraintRange getMin()
- {
- return minValue;
- }
- }
-
}
Property changes on:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/value/ValueConstraintsMatcher.java
___________________________________________________________________
Name: svn:keywords
+ Id
Added:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/value/ValueConstraintsValidator.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/value/ValueConstraintsValidator.java
(rev 0)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/value/ValueConstraintsValidator.java 2010-05-21
12:21:59 UTC (rev 2430)
@@ -0,0 +1,263 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.impl.core.value;
+
+import org.exoplatform.services.jcr.impl.util.JCRDateFormat;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+import javax.jcr.PropertyType;
+import javax.jcr.ValueFormatException;
+import javax.jcr.nodetype.ConstraintViolationException;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * @author <a href="mailto:peter.nedonosko@exoplatform.com">Peter
Nedonosko</a>
+ * @version $Id: ValueConstraintsValidator.java 12171 2008-03-20 15:37:28Z ksm $
+ */
+public class ValueConstraintsValidator
+{
+
+ protected static final Log LOG =
ExoLogger.getLogger("exo.jcr.component.core.ValueConstraintsValidator");
+
+ protected final static String DEFAULT_THRESHOLD = "";
+
+ protected final String[] constraints;
+
+ public ValueConstraintsValidator(String[] constraints)
+ {
+ this.constraints = constraints;
+ }
+
+ protected MinMaxConstraint parseAsMinMax(String constraint) throws
ConstraintViolationException
+ {
+
+ // constraint as min,max range:
+ // value constraints in the form of inclusive or exclusive ranges:
+ // i.e., "[min, max]", "(min, max)", "(min, max]" or
"[min, max)".
+ // Where "[" and "]" indicate "inclusive", while
"(" and ")" indicate
+ // "exclusive".
+ // A missing min or max value indicates no bound in that direction
+
+ String[] parts = constraint.split(",");
+
+ if (parts.length != 2)
+ {
+ throw new ConstraintViolationException("Value constraint '" +
constraint
+ + "' is invalid accrding the JSR-170 spec.");
+ }
+
+ boolean exclusive = false;
+
+ if (parts[0].startsWith("("))
+ {
+ exclusive = true;
+ }
+ else if (parts[0].startsWith("["))
+ {
+ exclusive = false;
+ }
+ else
+ {
+ throw new ConstraintViolationException("Value constraint '" +
constraint
+ + "' min exclusion rule is unefined accrding the JSR-170
spec.");
+ }
+
+ ConstraintRange minValue =
+ new ConstraintRange(parts[0].length() > 1 ? parts[0].substring(1) :
DEFAULT_THRESHOLD, exclusive);
+
+ if (parts[1].endsWith(")"))
+ {
+ exclusive = true;
+ }
+ else if (parts[1].endsWith("]"))
+ {
+ exclusive = false;
+ }
+ else
+ {
+ throw new ConstraintViolationException("Value constraint '" +
constraint
+ + "' max exclusion rule is unefined accrding the JSR-170
spec.");
+ }
+
+ ConstraintRange maxValue =
+ new ConstraintRange(parts[1].length() > 1 ? parts[1].substring(0,
parts[1].length() - 1) : DEFAULT_THRESHOLD,
+ exclusive);
+
+ return new MinMaxConstraint(minValue, maxValue);
+ }
+
+ /**
+ * Validate this matcher constraints for a validity to a given type.
+ *
+ * @param type int, property type
+ * @throws ValueFormatException if the constraint (at least one) incompatible with the
given type
+ */
+ public void validateFor(final int type) throws ValueFormatException
+ {
+ if (constraints == null || constraints.length <= 0)
+ {
+ return;
+ }
+
+ if (type == PropertyType.DATE)
+ {
+ for (String constrString : constraints)
+ {
+ try
+ {
+ MinMaxConstraint constraint = parseAsMinMax(constrString);
+ if (constraint.getMin().getThreshold().length() > 0)
+ {
+ JCRDateFormat.parse(constraint.getMin().getThreshold());
+ }
+
+ if (constraint.getMax().getThreshold().length() > 0)
+ {
+ JCRDateFormat.parse(constraint.getMax().getThreshold());
+ }
+ }
+ catch (ValueFormatException e)
+ {
+ throw new ValueFormatException("Wrong DATE constraint format " +
constrString, e);
+ }
+ catch (ConstraintViolationException e)
+ {
+ throw new ValueFormatException("Wrong DATE constraint format " +
constrString, e);
+ }
+ }
+ }
+ else if (type == PropertyType.DOUBLE)
+ {
+ for (String constrString : constraints)
+ {
+ try
+ {
+ MinMaxConstraint constraint = parseAsMinMax(constrString);
+ if (constraint.getMin().getThreshold().length() > 0)
+ {
+ Double.parseDouble(constraint.getMin().getThreshold());
+ }
+ if (constraint.getMax().getThreshold().length() > 0)
+ {
+ Double.parseDouble(constraint.getMax().getThreshold());
+ }
+ }
+ catch (NumberFormatException e)
+ {
+ throw new ValueFormatException("Wrong DOUBLE constraint format "
+ constrString, e);
+ }
+ catch (ConstraintViolationException e)
+ {
+ throw new ValueFormatException("Wrong DOUBLE constraint format "
+ constrString, e);
+ }
+ }
+ }
+ else if (type == PropertyType.LONG || type == PropertyType.BINARY)
+ {
+ for (String constrString : constraints)
+ {
+ try
+ {
+ MinMaxConstraint constraint = parseAsMinMax(constrString);
+ if (constraint.getMin().getThreshold().length() > 0)
+ {
+ Long.parseLong(constraint.getMin().getThreshold());
+ }
+ if (constraint.getMax().getThreshold().length() > 0)
+ {
+ Long.parseLong(constraint.getMax().getThreshold());
+ }
+ }
+ catch (NumberFormatException e)
+ {
+ throw new ValueFormatException("Wrong LONG (or BINARY size)
constraint format " + constrString, e);
+ }
+ catch (ConstraintViolationException e)
+ {
+ throw new ValueFormatException("Wrong LONG (or BINARY size)
constraint format " + constrString, e);
+ }
+ }
+ }
+ else if (type == PropertyType.BOOLEAN)
+ {
+ for (String constrString : constraints)
+ {
+ if (!constrString.equalsIgnoreCase("true") &&
!constrString.equalsIgnoreCase("false"))
+ {
+ throw new ValueFormatException("Wrong BOOLEAN constraint format:
" + constrString);
+ }
+ }
+ }
+ }
+
+ protected class ConstraintRange
+ {
+
+ private final String value;
+
+ private final boolean exclusive;
+
+ public ConstraintRange(String value)
+ {
+ this.value = value;
+ this.exclusive = false;
+ }
+
+ public ConstraintRange(String value, boolean exclusive)
+ {
+ this.value = value;
+ this.exclusive = exclusive;
+ }
+
+ protected String getThreshold()
+ {
+ return value;
+ }
+
+ protected boolean isExclusive()
+ {
+ return exclusive;
+ }
+ }
+
+ protected class MinMaxConstraint
+ {
+ private final ConstraintRange minValue;
+
+ private final ConstraintRange maxValue;
+
+ public MinMaxConstraint(ConstraintRange minValue, ConstraintRange maxValue)
+ {
+ this.minValue = minValue;
+ this.maxValue = maxValue;
+ }
+
+ protected ConstraintRange getMax()
+ {
+ return maxValue;
+ }
+
+ protected ConstraintRange getMin()
+ {
+ return minValue;
+ }
+ }
+}
Property changes on:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/value/ValueConstraintsValidator.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/value/ValueFactoryImpl.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/value/ValueFactoryImpl.java 2010-05-21
10:28:31 UTC (rev 2429)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/value/ValueFactoryImpl.java 2010-05-21
12:21:59 UTC (rev 2430)
@@ -54,7 +54,7 @@
* ValueFactory implementation
*
* @author Gennady Azarenkov
- * @version $Id: ValueFactoryImpl.java 11907 2008-03-13 15:36:21Z ksm $
+ * @version $Id$
*/
public class ValueFactoryImpl implements ValueFactory
@@ -87,7 +87,6 @@
public ValueFactoryImpl(LocationFactory locationFactory)
{
-
this.locationFactory = locationFactory;
this.tempDirectory = new File(System.getProperty("java.io.tmpdir"));
this.maxBufferSize = WorkspaceDataContainer.DEF_MAXBUFFERSIZE;
Property changes on:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/value/ValueFactoryImpl.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified:
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/nodetypes/TestValueConstraints.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/nodetypes/TestValueConstraints.java 2010-05-21
10:28:31 UTC (rev 2429)
+++
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/nodetypes/TestValueConstraints.java 2010-05-21
12:21:59 UTC (rev 2430)
@@ -31,6 +31,7 @@
import javax.jcr.Property;
import javax.jcr.PropertyType;
import javax.jcr.Value;
+import javax.jcr.nodetype.ConstraintViolationException;
/**
* Created by The eXo Platform SAS.
@@ -312,17 +313,17 @@
public void testBOOLEANProperty() throws Exception
{
-
Property testProperty =
testValueConstraintsNode.setProperty("jcr:testBOOLEAN", true);
session.save();
try
{
testProperty.setValue(false);
root.save();
+ fail("setValue(BOOLEAN value) should throws ConstraintViolationException on
'false'");
}
- catch (Exception e)
+ catch (ConstraintViolationException e)
{
- fail("setValue(BOOLEAN value) here should be no Exception ");
+ // ok
}
}