[exo-jcr-commits] exo-jcr SVN: r199 - in jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr: core/nodetype and 10 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Sun Oct 4 05:34:55 EDT 2009
Author: skabashnyuk
Date: 2009-10-04 05:34:54 -0400 (Sun, 04 Oct 2009)
New Revision: 199
Added:
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/core/ComponentPersister.java
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/core/nodetype/NodeTypeDataImpl.java
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/AbstractNodeTypeRepository.java
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/ExtendedItemDefinition.java
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/ExtendedNodeDefinition.java
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/InmemoryNodeTypeRepository.java
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/ItemAutocreator.java
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/NodeTypeDefinitionImpl.java
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/NodeTypeExistsException.java
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/NodeTypeRepository.java
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/AbstractItemDefinitionAccessProvider.java
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/JcrNodeTypeDataPersister.java
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/NodeDefinitionAccessProvider.java
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/NodeTypeConverter.java
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/NodeTypeDataBuilder.java
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/NodeTypeDataPersister.java
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/NodeTypeDataValidator.java
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/NodeTypeDefinitionAccessProvider.java
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/NodeTypeReadException.java
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/PropertyDefinitionAccessProvider.java
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/UpdateNodeTypeObserver.java
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/XmlNodeTypeDataPersister.java
Removed:
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/NodeTypeDataPersister.java
Modified:
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/core/nodetype/ExtendedNodeTypeManager.java
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/core/nodetype/ItemDefinitionData.java
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/core/nodetype/NodeDefinitionData.java
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/core/nodetype/NodeDefinitionValue.java
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/core/nodetype/NodeTypeData.java
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/core/nodetype/NodeTypeDataManager.java
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/RepositoryContainer.java
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/ItemImpl.java
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/NamespaceDataPersister.java
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/NamespaceRegistryImpl.java
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/NodeImpl.java
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/PropertyImpl.java
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/ScratchWorkspaceInitializer.java
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/ItemDefinitionDataHolder.java
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/ItemDefinitionImpl.java
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/NodeDefinitionImpl.java
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/NodeTypeDataHierarchyHolder.java
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/NodeTypeDataManagerImpl.java
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/NodeTypeImpl.java
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/NodeTypeManagerImpl.java
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/PropertyDefinitionImpl.java
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/VolatileNodeTypeDataManager.java
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/AbstractDefinitionComparator.java
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/NodeDefinitionComparator.java
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/PropertyDefinitionComparator.java
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/observation/ActionLauncher.java
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/PropertyTypeRegistry.java
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/QueryImpl.java
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchManager.java
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/AggregateRuleImpl.java
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/DocOrderScoreNodeIterator.java
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/NodeIteratorImpl.java
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/NodeTypeVirtualTableResolver.java
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/QueryImpl.java
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/QueryResultImpl.java
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/ScoreNodeIterator.java
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/ScoreNodeIteratorImpl.java
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/misc/Pattern.java
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/version/FrozenNodeInitializer.java
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/version/ItemDataCopyIgnoredVisitor.java
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/version/ItemDataRestoreVisitor.java
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/xml/importing/BaseXmlImporter.java
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/xml/importing/DocumentViewImporter.java
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/xml/importing/SystemViewImporter.java
Log:
EXOJCR-161 : Node type and namespaces changes to fit new query interfaces
Added: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/core/ComponentPersister.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/core/ComponentPersister.java (rev 0)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/core/ComponentPersister.java 2009-10-04 09:34:54 UTC (rev 199)
@@ -0,0 +1,41 @@
+/*
+ * 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.core;
+
+import org.picocontainer.Startable;
+
+import javax.jcr.RepositoryException;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * @author <a href="mailto:Sergey.Kabashnyuk at gmail.com">Sergey Kabashnyuk</a>
+ * @version $Id: $
+ */
+public interface ComponentPersister extends Startable
+{
+ /**
+ * Indicate what storage filled with some data.
+ *
+ * @return isStorageFilled flag.
+ * @throws RepositoryException
+ */
+ public boolean isStorageFilled();
+
+}
Property changes on: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/core/ComponentPersister.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/core/nodetype/ExtendedNodeTypeManager.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/core/nodetype/ExtendedNodeTypeManager.java 2009-10-02 15:41:14 UTC (rev 198)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/core/nodetype/ExtendedNodeTypeManager.java 2009-10-04 09:34:54 UTC (rev 199)
@@ -65,9 +65,22 @@
* @param alreadyExistsBehaviour a int
* @throws RepositoryException
*/
+ @Deprecated
NodeTypeIterator registerNodeTypes(InputStream xml, int alreadyExistsBehaviour) throws RepositoryException;
+
+
/**
+ * Registers all node types using XML binding value objects from xml stream.
+ *
+ * @param xml a InputStream
+ * @param alreadyExistsBehaviour a int
+ * @throws RepositoryException
+ */
+ NodeTypeIterator registerNodeTypes(InputStream xml, int alreadyExistsBehaviour, String contentType)
+ throws RepositoryException;
+
+ /**
* @return
* @throws RepositoryException
*/
Modified: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/core/nodetype/ItemDefinitionData.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/core/nodetype/ItemDefinitionData.java 2009-10-02 15:41:14 UTC (rev 198)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/core/nodetype/ItemDefinitionData.java 2009-10-04 09:34:54 UTC (rev 199)
@@ -22,11 +22,12 @@
import org.exoplatform.services.jcr.impl.Constants;
/**
- * Created by The eXo Platform SAS. <br/>Date: 25.11.2008
+ * Created by The eXo Platform SAS. <br/>
+ * Date: 25.11.2008
*
* @author <a href="mailto:peter.nedonosko at exoplatform.com.ua">Peter
* Nedonosko</a>
- * @version $Id: ItemDefinitionData.java 34801 2009-07-31 15:44:50Z dkatayev $
+ * @version $Id: ItemDefinitionData.java 26474 2009-01-09 16:15:25Z ksm $
*/
public class ItemDefinitionData
{
@@ -59,20 +60,6 @@
return this.getName().equals(Constants.JCR_ANY_NAME);
}
- @Override
- public boolean equals(Object obj)
- {
- if (this == obj)
- return true;
- if ((obj == null) || (obj.getClass() != this.getClass()))
- return false;
- // object must be Test at this point
- ItemDefinitionData test = (ItemDefinitionData)obj;
- return name == test.name && declaringNodeType == test.declaringNodeType && autoCreated == test.autoCreated
- && mandatory == test.mandatory && onParentVersion == test.onParentVersion
- && protectedItem == test.protectedItem;
- }
-
public InternalQName getName()
{
return name;
@@ -88,6 +75,83 @@
return autoCreated;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int hashCode()
+ {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + (autoCreated ? 1231 : 1237);
+ result = prime * result + ((declaringNodeType == null) ? 0 : declaringNodeType.hashCode());
+ result = prime * result + (mandatory ? 1231 : 1237);
+ result = prime * result + ((name == null) ? 0 : name.hashCode());
+ result = prime * result + onParentVersion;
+ result = prime * result + (protectedItem ? 1231 : 1237);
+ return result;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ {
+ return true;
+ }
+ if (obj == null)
+ {
+ return false;
+ }
+ if (!(obj instanceof ItemDefinitionData))
+ {
+ return false;
+ }
+ ItemDefinitionData other = (ItemDefinitionData)obj;
+ if (autoCreated != other.autoCreated)
+ {
+ return false;
+ }
+ if (declaringNodeType == null)
+ {
+ if (other.declaringNodeType != null)
+ {
+ return false;
+ }
+ }
+ else if (!declaringNodeType.equals(other.declaringNodeType))
+ {
+ return false;
+ }
+ if (mandatory != other.mandatory)
+ {
+ return false;
+ }
+ if (name == null)
+ {
+ if (other.name != null)
+ {
+ return false;
+ }
+ }
+ else if (!name.equals(other.name))
+ {
+ return false;
+ }
+ if (onParentVersion != other.onParentVersion)
+ {
+ return false;
+ }
+ if (protectedItem != other.protectedItem)
+ {
+ return false;
+ }
+ return true;
+ }
+
public boolean isMandatory()
{
return mandatory;
@@ -108,5 +172,4 @@
{
return name.getAsString();
}
-
}
Modified: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/core/nodetype/NodeDefinitionData.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/core/nodetype/NodeDefinitionData.java 2009-10-02 15:41:14 UTC (rev 198)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/core/nodetype/NodeDefinitionData.java 2009-10-04 09:34:54 UTC (rev 199)
@@ -21,17 +21,19 @@
import org.exoplatform.services.jcr.datamodel.InternalQName;
import java.util.Arrays;
+import java.util.Comparator;
/**
- * Created by The eXo Platform SAS. <br/>Date: 25.11.2008
+ * Created by The eXo Platform SAS. <br/>
+ * Date: 25.11.2008
*
* @author <a href="mailto:peter.nedonosko at exoplatform.com.ua">Peter
* Nedonosko</a>
- * @version $Id: NodeDefinitionData.java 34801 2009-07-31 15:44:50Z dkatayev $
+ * @version $Id: NodeDefinitionData.java 25471 2008-12-19 08:34:01Z ksm $
*/
+
public class NodeDefinitionData extends ItemDefinitionData
{
-
protected final InternalQName[] requiredPrimaryTypes;
protected final InternalQName defaultPrimaryType;
@@ -46,6 +48,14 @@
this.requiredPrimaryTypes = requiredPrimaryTypes;
this.defaultPrimaryType = defaultPrimaryType;
this.allowsSameNameSiblings = allowsSameNameSiblings;
+ Arrays.sort(requiredPrimaryTypes, new Comparator<InternalQName>()
+ {
+
+ public int compare(InternalQName o1, InternalQName o2)
+ {
+ return o1.getAsString().compareTo(o2.getAsString());
+ }
+ });
}
public InternalQName[] getRequiredPrimaryTypes()
@@ -58,21 +68,77 @@
return defaultPrimaryType;
}
- public boolean isAllowsSameNameSiblings()
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int hashCode()
{
- return allowsSameNameSiblings;
+ final int prime = 31;
+ int result = super.hashCode();
+ result = prime * result + (allowsSameNameSiblings ? 1231 : 1237);
+ result = prime * result + ((defaultPrimaryType == null) ? 0 : defaultPrimaryType.hashCode());
+ result = prime * result + Arrays.hashCode(requiredPrimaryTypes);
+ return result;
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public boolean equals(Object obj)
{
if (this == obj)
+ {
return true;
- if ((obj == null) || (obj.getClass() != this.getClass()))
+ }
+ if (!super.equals(obj))
+ {
return false;
- // object must be Test at this point
- NodeDefinitionData test = (NodeDefinitionData)obj;
- return defaultPrimaryType == test.defaultPrimaryType && allowsSameNameSiblings == test.allowsSameNameSiblings
- && super.equals(test) && Arrays.equals(this.requiredPrimaryTypes, test.requiredPrimaryTypes);
+ }
+ if (!(obj instanceof NodeDefinitionData))
+ {
+ return false;
+ }
+ NodeDefinitionData other = (NodeDefinitionData)obj;
+ if (allowsSameNameSiblings != other.allowsSameNameSiblings)
+ {
+ return false;
+ }
+ if (defaultPrimaryType == null)
+ {
+ if (other.defaultPrimaryType != null)
+ {
+ return false;
+ }
+ }
+ else if (!defaultPrimaryType.equals(other.defaultPrimaryType))
+ {
+ return false;
+ }
+ if (!Arrays.deepEquals(requiredPrimaryTypes, other.requiredPrimaryTypes))
+ {
+ return false;
+ }
+ return true;
}
+
+ public boolean isAllowsSameNameSiblings()
+ {
+ return allowsSameNameSiblings;
+ }
+
+ // @Override
+ // public boolean equals(Object obj) {
+ // if (this == obj)
+ // return true;
+ // if ((obj == null) || (obj.getClass() != this.getClass()))
+ // return false;
+ // // object must be Test at this point
+ // NodeDefinitionData test = (NodeDefinitionData) obj;
+ // return defaultPrimaryType == test.defaultPrimaryType
+ // && allowsSameNameSiblings == test.allowsSameNameSiblings &&
+ // super.equals(test)
+ // && Arrays.equals(this.requiredPrimaryTypes, test.requiredPrimaryTypes);
+ // }
}
Modified: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/core/nodetype/NodeDefinitionValue.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/core/nodetype/NodeDefinitionValue.java 2009-10-02 15:41:14 UTC (rev 198)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/core/nodetype/NodeDefinitionValue.java 2009-10-04 09:34:54 UTC (rev 199)
@@ -18,11 +18,15 @@
*/
package org.exoplatform.services.jcr.core.nodetype;
+import org.exoplatform.services.jcr.impl.core.nodetype.NodeDefinitionImpl;
+
+import java.util.Arrays;
import java.util.List;
+import javax.jcr.nodetype.NodeDefinition;
+
/**
- * Created by The eXo Platform SAS.<br/>
- * NodeDefinition value object
+ * Created by The eXo Platform SAS.<br/> NodeDefinition value object
*
* @author <a href="mailto:gennady.azarenkov at exoplatform.com">Gennady
* Azarenkov</a>
@@ -61,6 +65,14 @@
this.sameNameSiblings = sameNameSiblings;
}
+ public NodeDefinitionValue(NodeDefinition nodeDefinition)
+ {
+ super(nodeDefinition);
+ this.defaultNodeTypeName = ((NodeDefinitionImpl)nodeDefinition).getDefaultPrimaryTypeName();
+ this.requiredNodeTypeNames = Arrays.asList(((NodeDefinitionImpl)nodeDefinition).getRequiredPrimaryTypeNames());
+ this.sameNameSiblings = nodeDefinition.allowsSameNameSiblings();
+ }
+
/**
* @return Returns the defaultNodeTypeName.
*/
Modified: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/core/nodetype/NodeTypeData.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/core/nodetype/NodeTypeData.java 2009-10-02 15:41:14 UTC (rev 198)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/core/nodetype/NodeTypeData.java 2009-10-04 09:34:54 UTC (rev 199)
@@ -1,175 +1,103 @@
-/*
- * 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.core.nodetype;
-
-import org.exoplatform.services.jcr.datamodel.InternalQName;
-
-import java.util.Arrays;
-
-/**
- * Created by The eXo Platform SAS. Define base abstraction for NodeType data
- * used in core. <br/>Date: 25.11.2008
- *
- * @author <a href="mailto:peter.nedonosko at exoplatform.com.ua">Peter
- * Nedonosko</a>
- * @version $Id: NodeTypeData.java 34801 2009-07-31 15:44:50Z dkatayev $
- */
-
-public class NodeTypeData
-{
- protected InternalQName name;
-
- protected InternalQName primaryItemName;
-
- protected InternalQName[] declaredSupertypeNames;
-
- protected PropertyDefinitionData[] declaredPropertyDefinitions;
-
- protected NodeDefinitionData[] declaredChildNodeDefinitions;
-
- protected boolean hasOrderableChildNodes;
-
- protected boolean mixin;
-
- public NodeTypeData(InternalQName name, InternalQName primaryItemName, boolean mixin,
- boolean hasOrderableChildNodes, InternalQName[] declaredSupertypeNames,
- PropertyDefinitionData[] declaredPropertyDefinitions, NodeDefinitionData[] declaredChildNodeDefinitions)
- {
-
- this.name = name;
- this.primaryItemName = primaryItemName;
- this.mixin = mixin;
- this.hasOrderableChildNodes = hasOrderableChildNodes;
- this.declaredSupertypeNames = declaredSupertypeNames;
- this.declaredPropertyDefinitions = declaredPropertyDefinitions;
- this.declaredChildNodeDefinitions = declaredChildNodeDefinitions;
- }
-
- public NodeDefinitionData[] getDeclaredChildNodeDefinitions()
- {
- return declaredChildNodeDefinitions;
- }
-
- public PropertyDefinitionData[] getDeclaredPropertyDefinitions()
- {
- return declaredPropertyDefinitions;
- }
-
- @Override
- public int hashCode()
- {
- final int prime = 31;
- int result = 1;
- result = prime * result + Arrays.hashCode(declaredChildNodeDefinitions);
- result = prime * result + Arrays.hashCode(declaredPropertyDefinitions);
- result = prime * result + Arrays.hashCode(declaredSupertypeNames);
- result = prime * result + (hasOrderableChildNodes ? 1231 : 1237);
- result = prime * result + (mixin ? 1231 : 1237);
- result = prime * result + ((name == null) ? 0 : name.hashCode());
- result = prime * result + ((primaryItemName == null) ? 0 : primaryItemName.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj)
- {
- if (this == obj)
- {
- return true;
- }
- if (obj == null)
- {
- return false;
- }
- if (getClass() != obj.getClass())
- {
- return false;
- }
- NodeTypeData other = (NodeTypeData)obj;
- if (!Arrays.equals(declaredChildNodeDefinitions, other.declaredChildNodeDefinitions))
- {
- return false;
- }
- if (!Arrays.equals(declaredPropertyDefinitions, other.declaredPropertyDefinitions))
- {
- return false;
- }
- if (!Arrays.equals(declaredSupertypeNames, other.declaredSupertypeNames))
- {
- return false;
- }
- if (hasOrderableChildNodes != other.hasOrderableChildNodes)
- {
- return false;
- }
- if (mixin != other.mixin)
- {
- return false;
- }
- if (name == null)
- {
- if (other.name != null)
- {
- return false;
- }
- }
- else if (!name.equals(other.name))
- {
- return false;
- }
- if (primaryItemName == null)
- {
- if (other.primaryItemName != null)
- {
- return false;
- }
- }
- else if (!primaryItemName.equals(other.primaryItemName))
- {
- return false;
- }
- return true;
- }
-
- public InternalQName[] getDeclaredSupertypeNames()
- {
- return declaredSupertypeNames;
- }
-
- public InternalQName getPrimaryItemName()
- {
- return primaryItemName;
- }
-
- public InternalQName getName()
- {
- return name;
- }
-
- public boolean hasOrderableChildNodes()
- {
- return hasOrderableChildNodes;
- }
-
- public boolean isMixin()
- {
- return mixin;
- }
-
-}
+/*
+ * 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.core.nodetype;
+
+import org.exoplatform.services.jcr.datamodel.InternalQName;
+import org.exoplatform.services.jcr.impl.core.nodetype.registration.NodeTypeReadException;
+
+import javax.jcr.RepositoryException;
+
+/**
+ * @author <a href="mailto:Sergey.Kabashnyuk at exoplatform.org">Sergey Kabashnyuk</a>
+ * @version $Id: exo-jboss-codetemplates.xml 34360 2009-07-22 23:58:59Z ksm $
+ *
+ */
+public interface NodeTypeData
+{
+
+// /**
+// * @return the isAbstract
+// */
+// public boolean isAbstract();
+
+ /**
+ *
+ * @return
+ * @throws RepositoryException
+ * @throws NodeTypeReadException
+ */
+ public NodeDefinitionData[] getDeclaredChildNodeDefinitions();;
+
+ /**
+ *
+ * @return
+ * @throws RepositoryException
+ * @throws NodeTypeReadException
+ */
+ public PropertyDefinitionData[] getDeclaredPropertyDefinitions();
+
+ /**
+ *
+ * @return
+ * @throws RepositoryException
+ * @throws NodeTypeReadException
+ */
+ public InternalQName[] getDeclaredSupertypeNames();
+
+ /**
+ *
+ * @return
+ * @throws RepositoryException
+ * @throws NodeTypeReadException
+ */
+ public InternalQName getPrimaryItemName();
+
+ /**
+ *
+ * @return
+ * @throws RepositoryException
+ * @throws NodeTypeReadException
+ */
+ public InternalQName getName();
+
+ /**
+ *
+ * @return
+ * @throws RepositoryException
+ * @throws NodeTypeReadException
+ */
+ public boolean hasOrderableChildNodes();
+
+ /**
+ *
+ * @return
+ * @throws RepositoryException
+ * @throws NodeTypeReadException
+ */
+ public boolean isMixin();
+
+// /**
+// *
+// * @return
+// * @throws RepositoryException
+// * @throws NodeTypeReadException
+// */
+// public boolean isQueryable();
+
+}
\ No newline at end of file
Added: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/core/nodetype/NodeTypeDataImpl.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/core/nodetype/NodeTypeDataImpl.java (rev 0)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/core/nodetype/NodeTypeDataImpl.java 2009-10-04 09:34:54 UTC (rev 199)
@@ -0,0 +1,222 @@
+/*
+ * 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.core.nodetype;
+
+import org.exoplatform.services.jcr.datamodel.InternalQName;
+
+import java.util.Arrays;
+
+/**
+ * Created by The eXo Platform SAS. Define base abstraction for NodeType data
+ * used in core. <br/>
+ * Date: 25.11.2008
+ *
+ * @author <a href="mailto:peter.nedonosko at exoplatform.com.ua">Peter
+ * Nedonosko</a>
+ * @version $Id: NodeTypeData.java 27741 2009-02-02 16:59:51Z ksm $
+ */
+
+public class NodeTypeDataImpl implements NodeTypeData
+{
+ protected InternalQName name;
+
+ protected InternalQName primaryItemName;
+
+ protected InternalQName[] declaredSupertypeNames;
+
+ protected PropertyDefinitionData[] declaredPropertyDefinitions;
+
+ protected NodeDefinitionData[] declaredChildNodeDefinitions;
+
+ protected Boolean hasOrderableChildNodes;
+
+ protected Boolean mixin;
+
+ // protected Boolean isAbstract;
+
+// /**
+// * Default true.
+// */
+// protected boolean isQueryable;
+
+ public NodeTypeDataImpl(InternalQName name, InternalQName primaryItemName, boolean mixin,
+ boolean hasOrderableChildNodes, InternalQName[] declaredSupertypeNames,
+ PropertyDefinitionData[] declaredPropertyDefinitions, NodeDefinitionData[] declaredChildNodeDefinitions)
+ {
+
+ this.name = name;
+ this.primaryItemName = primaryItemName;
+ this.mixin = mixin;
+ this.hasOrderableChildNodes = hasOrderableChildNodes;
+ //this.isAbstract = isAbstract;
+ //this.isQueryable = isQueryable;
+ this.declaredSupertypeNames = declaredSupertypeNames;
+ this.declaredPropertyDefinitions = declaredPropertyDefinitions;
+ this.declaredChildNodeDefinitions = declaredChildNodeDefinitions;
+ }
+//
+// /**
+// * @see org.exoplatform.services.jcr.core.nodetype.NodeTypeData#isAbstract()
+// */
+// public boolean isAbstract()
+// {
+// return isAbstract;
+// }
+
+ /**
+ * @see org.exoplatform.services.jcr.core.nodetype.NodeTypeData#getDeclaredChildNodeDefinitions()
+ */
+ public NodeDefinitionData[] getDeclaredChildNodeDefinitions()
+ {
+ return declaredChildNodeDefinitions;
+ }
+
+ /**
+ * @see org.exoplatform.services.jcr.core.nodetype.NodeTypeData#getDeclaredPropertyDefinitions()
+ */
+ public PropertyDefinitionData[] getDeclaredPropertyDefinitions()
+ {
+ return declaredPropertyDefinitions;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + Arrays.hashCode(declaredChildNodeDefinitions);
+ result = prime * result + Arrays.hashCode(declaredPropertyDefinitions);
+ result = prime * result + Arrays.hashCode(declaredSupertypeNames);
+ result = prime * result + (hasOrderableChildNodes ? 1231 : 1237);
+ result = prime * result + (mixin ? 1231 : 1237);
+ result = prime * result + ((name == null) ? 0 : name.hashCode());
+ result = prime * result + ((primaryItemName == null) ? 0 : primaryItemName.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ {
+ return true;
+ }
+ if (obj == null)
+ {
+ return false;
+ }
+ if (getClass() != obj.getClass())
+ {
+ return false;
+ }
+ NodeTypeDataImpl other = (NodeTypeDataImpl)obj;
+ if (!Arrays.deepEquals(declaredChildNodeDefinitions, other.declaredChildNodeDefinitions))
+ {
+ return false;
+ }
+ if (!Arrays.deepEquals(declaredPropertyDefinitions, other.declaredPropertyDefinitions))
+ {
+ return false;
+ }
+ if (!Arrays.deepEquals(declaredSupertypeNames, other.declaredSupertypeNames))
+ {
+ return false;
+ }
+ if (hasOrderableChildNodes != other.hasOrderableChildNodes)
+ {
+ return false;
+ }
+ if (mixin != other.mixin)
+ {
+ return false;
+ }
+ if (name == null)
+ {
+ if (other.name != null)
+ {
+ return false;
+ }
+ }
+ else if (!name.equals(other.name))
+ {
+ return false;
+ }
+ if (primaryItemName == null)
+ {
+ if (other.primaryItemName != null)
+ {
+ return false;
+ }
+ }
+ else if (!primaryItemName.equals(other.primaryItemName))
+ {
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * @see org.exoplatform.services.jcr.core.nodetype.NodeTypeData#getDeclaredSupertypeNames()
+ */
+ public InternalQName[] getDeclaredSupertypeNames()
+ {
+ return declaredSupertypeNames;
+ }
+
+ /**
+ * @see org.exoplatform.services.jcr.core.nodetype.NodeTypeData#getPrimaryItemName()
+ */
+ public InternalQName getPrimaryItemName()
+ {
+ return primaryItemName;
+ }
+
+ /**
+ * @see org.exoplatform.services.jcr.core.nodetype.NodeTypeData#getName()
+ */
+ public InternalQName getName()
+ {
+ return name;
+ }
+
+ /**
+ * @see org.exoplatform.services.jcr.core.nodetype.NodeTypeData#hasOrderableChildNodes()
+ */
+ public boolean hasOrderableChildNodes()
+ {
+ return hasOrderableChildNodes;
+ }
+
+ /**
+ * @see org.exoplatform.services.jcr.core.nodetype.NodeTypeData#isMixin()
+ */
+ public boolean isMixin()
+ {
+ return mixin;
+ }
+
+// /**
+// * @see org.exoplatform.services.jcr.core.nodetype.NodeTypeData#isQueryable()
+// */
+// public boolean isQueryable()
+// {
+// return isQueryable;
+// }
+
+}
Property changes on: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/core/nodetype/NodeTypeDataImpl.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/core/nodetype/NodeTypeDataManager.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/core/nodetype/NodeTypeDataManager.java 2009-10-02 15:41:14 UTC (rev 198)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/core/nodetype/NodeTypeDataManager.java 2009-10-04 09:34:54 UTC (rev 199)
@@ -18,17 +18,17 @@
*/
package org.exoplatform.services.jcr.core.nodetype;
-import org.exoplatform.services.jcr.dataflow.ItemDataConsumer;
-import org.exoplatform.services.jcr.dataflow.ItemStateChangesLog;
import org.exoplatform.services.jcr.dataflow.PlainChangesLog;
import org.exoplatform.services.jcr.datamodel.InternalQName;
import org.exoplatform.services.jcr.datamodel.NodeData;
import java.io.InputStream;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import javax.jcr.RepositoryException;
+import javax.jcr.nodetype.ConstraintViolationException;
/**
* Created by The eXo Platform SAS. <br/>
@@ -43,47 +43,25 @@
{
/**
- * Returns all supertypes of this node type in the node type inheritance
- * hierarchy. For primary types apart from <code>nt:base</code>, this list
- * will always include at least <code>nt:base</code>. For mixin types, there
- * is no required supertype.
+ * The standard XML content type to be used with XML-formatted node type
+ * streams.
*/
- public Set<InternalQName> getSupertypes(final InternalQName nodeTypeName);
+ String TEXT_XML = "text/xml";
- //void addQueryHandler(QueryHandler queryHandler);
-
/**
- * @param nodeName
- * @param nodeTypeNames
- * @return
+ * The experimental content type for the compact node type definition files.
*/
- NodeDefinitionData findChildNodeDefinition(InternalQName nodeName, InternalQName... nodeTypeNames);
+ String TEXT_X_JCR_CND = "text/x-jcr-cnd";
/**
- * @param nodeName
- * @param primaryNodeType
- * @param mixinTypes
- * @return
+ * Returns all supertypes of this node type in the node type inheritance
+ * hierarchy. For primary types apart from <code>nt:base</code>, this list
+ * will always include at least <code>nt:base</code>. For mixin types, there
+ * is no required supertype.
*/
- NodeDefinitionData findChildNodeDefinition(InternalQName nodeName, InternalQName primaryNodeType,
- InternalQName[] mixinTypes);
+ public Set<InternalQName> getSupertypes(final InternalQName nodeTypeName);
/**
- * @param typeName
- * @return
- */
- NodeTypeData findNodeType(InternalQName typeName);
-
- /**
- * @param propertyName
- * @param primaryNodeType
- * @param mixinTypes
- * @return
- */
- PropertyDefinitionDatas findPropertyDefinitions(InternalQName propertyName, InternalQName primaryNodeType,
- InternalQName[] mixinTypes);
-
- /**
* @param nodeTypeNames
* @return
*/
@@ -105,14 +83,23 @@
/**
* @param nodeName
- * @param nodeTypeName
- * @param parentTypeName
+ * @param nodeTypeNames
* @return
+ * @throws RepositoryException
*/
- NodeDefinitionData getChildNodeDefinition(InternalQName nodeName, InternalQName nodeTypeName,
- InternalQName parentTypeName);
+ NodeDefinitionData getChildNodeDefinition(InternalQName nodeName, InternalQName... nodeTypeNames)
+ throws RepositoryException;
/**
+ * @param nodeName
+ * @param primaryNodeType
+ * @param mixinTypes
+ * @return
+ */
+ NodeDefinitionData getChildNodeDefinition(InternalQName nodeName, InternalQName primaryNodeType,
+ InternalQName[] mixinTypes) throws RepositoryException;
+
+ /**
* Returns the <i>direct</i> subtypes of this node type in the node type
* inheritance hierarchy, that is, those which actually declared this node
* type in their list of supertypes.
@@ -126,31 +113,40 @@
* @param mixinTypes
* @return
*/
- List<ItemDefinitionData> getManadatoryItemDefs(InternalQName primaryNodeType, InternalQName[] mixinTypes);
+ List<ItemDefinitionData> getManadatoryItemDefs(InternalQName primaryNodeType, InternalQName[] mixinTypes)
+ throws RepositoryException;
+ // /**
+ // * @param nodeName
+ // * @param nodeTypeName
+ // * @param parentTypeName
+ // * @return
+ // */
+ // NodeDefinitionData getChildNodeDefinition(InternalQName nodeName, InternalQName nodeTypeName,
+ // InternalQName parentTypeName) throws RepositoryException;
+
/**
- * @param name
+ * @param typeName
* @return
- * @throws RepositoryException
*/
- Set<String> getNodes(InternalQName name) throws RepositoryException;
+ NodeTypeData getNodeType(InternalQName typeName);
/**
- * @param name
- * @param internalQNames
- * @param internalQNames2
+ * @param propertyName
+ * @param nodeTypeNames
* @return
- * @throws RepositoryException
*/
- Set<String> getNodes(InternalQName name, InternalQName[] includeProperties, InternalQName[] excludeProperties)
+ PropertyDefinitionDatas getPropertyDefinitions(InternalQName propertyName, InternalQName... nodeTypeNames)
throws RepositoryException;
/**
* @param propertyName
- * @param nodeTypeNames
+ * @param primaryNodeType
+ * @param mixinTypes
* @return
*/
- PropertyDefinitionDatas getPropertyDefinitions(InternalQName propertyName, InternalQName... nodeTypeNames);
+ PropertyDefinitionDatas getPropertyDefinitions(InternalQName propertyName, InternalQName primaryNodeType,
+ InternalQName[] mixinTypes) throws RepositoryException;
/**
* Returns all subtypes of this node type in the node type inheritance
@@ -168,7 +164,7 @@
* @return
*/
boolean isChildNodePrimaryTypeAllowed(InternalQName childNodeTypeName, InternalQName parentNodeType,
- InternalQName[] parentMixinNames);
+ InternalQName[] parentMixinNames) throws RepositoryException;
/**
* @param testTypeName
@@ -190,40 +186,7 @@
* @param mixinTypes
* @return
*/
- boolean isOrderableChildNodesSupported(InternalQName primaryNodeType, InternalQName[] mixinTypes);
-
- /**
- * Create PlainChangesLog of autocreated items to this node. No checks will be
- * passed for autocreated items.
- *
- * @throws RepositoryException
- */
- PlainChangesLog makeAutoCreatedItems(NodeData parent, InternalQName nodeTypeName, ItemDataConsumer dataManager,
- String owner) throws RepositoryException;
-
- /**
- * @param nodeData
- * @param name
- * @param nodeDefinitionDatas
- * @param persister
- * @param owner
- * @return
- * @throws RepositoryException
- */
- ItemStateChangesLog makeAutoCreatedNodes(NodeData nodeData, InternalQName name,
- NodeDefinitionData[] nodeDefinitionDatas, ItemDataConsumer dataManager, String owner) throws RepositoryException;
-
- /**
- * @param nodeData
- * @param name
- * @param propertyDefinitionDatas
- * @param persister
- * @param owner
- * @return
- * @throws RepositoryException
- */
- PlainChangesLog makeAutoCreatedProperties(NodeData nodeData, InternalQName name,
- PropertyDefinitionData[] propertyDefinitionDatas, ItemDataConsumer dataManager, String owner)
+ boolean isOrderableChildNodesSupported(InternalQName primaryNodeType, InternalQName[] mixinTypes)
throws RepositoryException;
/**
@@ -232,7 +195,8 @@
* @return
* @throws RepositoryException
*/
- List<NodeTypeData> registerNodeTypes(InputStream xml, int alreadyExistsBehaviour) throws RepositoryException;
+ List<NodeTypeData> registerNodeTypes(InputStream xml, int alreadyExistsBehaviour, String contentType)
+ throws RepositoryException;
/**
* @param ntValues
@@ -244,8 +208,22 @@
throws RepositoryException;
/**
+ * Changes the primary node type of this node to nodeTypeName.
+ *
+ * @param nodeData
* @param nodeTypeName
+ * @return
* @throws RepositoryException
*/
+ PlainChangesLog setPrimaryType(NodeData nodeData, InternalQName nodeTypeName) throws RepositoryException;
+
+ /**
+ * @param nodeTypeName
+ * @throws RepositoryException
+ */
void unregisterNodeType(InternalQName nodeTypeName) throws RepositoryException;
+
+ PlainChangesLog updateNodeType(NodeTypeData ancestorDefinition, NodeTypeData recipientDefinition,
+ Map<InternalQName, NodeTypeData> volatileNodeTypes) throws ConstraintViolationException, RepositoryException;
+
}
Modified: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/RepositoryContainer.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/RepositoryContainer.java 2009-10-02 15:41:14 UTC (rev 198)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/RepositoryContainer.java 2009-10-04 09:34:54 UTC (rev 199)
@@ -44,8 +44,8 @@
import org.exoplatform.services.jcr.impl.core.access.DefaultAccessManagerImpl;
import org.exoplatform.services.jcr.impl.core.lock.LockManagerImpl;
import org.exoplatform.services.jcr.impl.core.nodetype.NodeTypeDataManagerImpl;
-import org.exoplatform.services.jcr.impl.core.nodetype.NodeTypeDataPersister;
import org.exoplatform.services.jcr.impl.core.nodetype.NodeTypeManagerImpl;
+import org.exoplatform.services.jcr.impl.core.nodetype.registration.JcrNodeTypeDataPersister;
import org.exoplatform.services.jcr.impl.core.observation.ObservationManagerRegistry;
import org.exoplatform.services.jcr.impl.core.query.QueryManagerFactory;
import org.exoplatform.services.jcr.impl.core.query.RepositoryIndexSearcherHolder;
@@ -570,7 +570,8 @@
}
if (log.isDebugEnabled())
log.debug("Trying register node types from xml-file " + nodeTypeFilesName);
- ntManager.registerNodeTypes(inXml, ExtendedNodeTypeManager.IGNORE_IF_EXISTS);
+ ntManager.registerNodeTypes(inXml, ExtendedNodeTypeManager.IGNORE_IF_EXISTS,
+ NodeTypeDataManager.TEXT_XML);
if (log.isDebugEnabled())
log.debug("Node types is registered from xml-file " + nodeTypeFilesName);
}
@@ -590,7 +591,8 @@
throw new RepositoryException(e);
}
log.info("Trying register node types (" + this.getName() + ") from xml-file " + nodeTypeFilesName);
- ntManager.registerNodeTypes(inXml, ExtendedNodeTypeManager.IGNORE_IF_EXISTS);
+ ntManager.registerNodeTypes(inXml, ExtendedNodeTypeManager.IGNORE_IF_EXISTS,
+ NodeTypeDataManager.TEXT_XML);
log.info("Node types is registered (" + this.getName() + ") from xml-file " + nodeTypeFilesName);
}
}
@@ -605,21 +607,24 @@
registerComponentImplementation(RepositoryIndexSearcherHolder.class);
- registerComponentImplementation(NamespaceDataPersister.class);
- registerComponentImplementation(NamespaceRegistryImpl.class);
-
- addNamespaces();
-
registerComponentImplementation(WorkspaceFileCleanerHolder.class);
registerComponentImplementation(LocationFactory.class);
registerComponentImplementation(ValueFactoryImpl.class);
- registerComponentImplementation(NodeTypeDataPersister.class);
+
+ registerComponentImplementation(JcrNodeTypeDataPersister.class);
+ registerComponentImplementation(NamespaceDataPersister.class);
+ registerComponentImplementation(NamespaceRegistryImpl.class);
+
registerComponentImplementation(NodeTypeManagerImpl.class);
registerComponentImplementation(NodeTypeDataManagerImpl.class);
-
+
+
+ //node types first
+ addNamespaces();
registerNodeTypes();
-
+
+
registerComponentImplementation(DefaultAccessManagerImpl.class);
registerComponentImplementation(SessionRegistry.class);
@@ -670,14 +675,23 @@
*/
private void load() throws RepositoryException
{
- NamespaceRegistryImpl nsRegistry = (NamespaceRegistryImpl)getNamespaceRegistry();
- NodeTypeDataPersister nodeTypeDataPersister =
- (NodeTypeDataPersister)getComponentInstanceOfType(NodeTypeDataPersister.class);
+ JcrNodeTypeDataPersister nodeTypePersister =
+ (JcrNodeTypeDataPersister)this.getComponentInstanceOfType(JcrNodeTypeDataPersister.class);
+ NamespaceDataPersister namespacePersister =
+ (NamespaceDataPersister)this.getComponentInstanceOfType(NamespaceDataPersister.class);
// Load from persistence
- nsRegistry.loadFromStorage();
- nodeTypeDataPersister.loadFromStorage();
+ nodeTypePersister.start();
+ namespacePersister.start();
+
+ NamespaceRegistryImpl nsRegistry = (NamespaceRegistryImpl)getNamespaceRegistry();
+ NodeTypeDataManagerImpl ntManager =
+ (NodeTypeDataManagerImpl)this.getComponentInstanceOfType(NodeTypeDataManagerImpl.class);
+ // initialize internal components.
+ nsRegistry.start();
+ ntManager.start();
+
}
/**
Modified: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/ItemImpl.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/ItemImpl.java 2009-10-02 15:41:14 UTC (rev 198)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/ItemImpl.java 2009-10-04 09:34:54 UTC (rev 199)
@@ -417,7 +417,7 @@
return nullProperty;
}
defs =
- ntm.findPropertyDefinitions(propertyName, parentData.getPrimaryTypeName(), parentData.getMixinTypeNames());
+ ntm.getPropertyDefinitions(propertyName, parentData.getPrimaryTypeName(), parentData.getMixinTypeNames());
state = ItemState.ADDED;
}
@@ -426,7 +426,7 @@
oldProp = (PropertyImpl)oldItem;
isMultiValue = oldProp.isMultiValued();
defs =
- ntm.findPropertyDefinitions(propertyName, parentData.getPrimaryTypeName(), parentData.getMixinTypeNames());
+ ntm.getPropertyDefinitions(propertyName, parentData.getPrimaryTypeName(), parentData.getMixinTypeNames());
identifier = oldProp.getInternalIdentifier();
version = oldProp.getData().getPersistedVersion();
@@ -725,10 +725,10 @@
NodeTypeData[] nodeTypes = new NodeTypeData[mixinNames.length + 1];
NodeTypeDataManager ntm = session.getWorkspace().getNodeTypesHolder();
- nodeTypes[0] = ntm.findNodeType(primaryTypeName);
+ nodeTypes[0] = ntm.getNodeType(primaryTypeName);
for (int i = 1; i <= mixinNames.length; i++)
{
- nodeTypes[i] = ntm.findNodeType(mixinNames[i - 1]);
+ nodeTypes[i] = ntm.getNodeType(mixinNames[i - 1]);
}
return nodeTypes;
Modified: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/NamespaceDataPersister.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/NamespaceDataPersister.java 2009-10-02 15:41:14 UTC (rev 198)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/NamespaceDataPersister.java 2009-10-04 09:34:54 UTC (rev 199)
@@ -20,9 +20,13 @@
import org.exoplatform.services.jcr.access.AccessControlEntry;
import org.exoplatform.services.jcr.access.AccessControlList;
+import org.exoplatform.services.jcr.access.AccessControlPolicy;
+import org.exoplatform.services.jcr.config.RepositoryEntry;
+import org.exoplatform.services.jcr.core.ComponentPersister;
import org.exoplatform.services.jcr.core.ExtendedPropertyType;
import org.exoplatform.services.jcr.dataflow.DataManager;
import org.exoplatform.services.jcr.dataflow.ItemState;
+import org.exoplatform.services.jcr.dataflow.ItemStateChangesLog;
import org.exoplatform.services.jcr.dataflow.PlainChangesLog;
import org.exoplatform.services.jcr.dataflow.PlainChangesLogImpl;
import org.exoplatform.services.jcr.dataflow.TransactionChangesLog;
@@ -45,130 +49,38 @@
import java.io.IOException;
import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import javax.jcr.InvalidItemStateException;
import javax.jcr.PropertyType;
import javax.jcr.RepositoryException;
/**
* Created by The eXo Platform SAS.
*
- * @author <a href="mailto:gennady.azarenkov at exoplatform.com">Gennady Azarenkov</a>
- * @version $Id: NamespaceDataPersister.java 13962 2008-05-07 16:00:48Z pnedonosko $
+ * @author <a href="mailto:gennady.azarenkov at exoplatform.com">Gennady
+ * Azarenkov</a>
+ * @version $Id: NamespaceDataPersister.java 13962 2008-05-07 16:00:48Z
+ * pnedonosko $
*/
-public class NamespaceDataPersister
+public class NamespaceDataPersister implements ComponentPersister
{
- public static Log log = ExoLogger.getLogger("jcr.NamespaceDataPersister");
+ public static Log log = ExoLogger.getLogger(NamespaceDataPersister.class.getName());
- private DataManager dataManager;
+ private final DataManager dataManager;
- private PlainChangesLog changesLog;
-
private NodeData nsRoot;
- public NamespaceDataPersister(DataManager dataManager)
- {
- this.dataManager = dataManager;
- this.changesLog = new PlainChangesLogImpl();
- try
- {
- NodeData jcrSystem = (NodeData)dataManager.getItemData(Constants.SYSTEM_UUID);
- if (jcrSystem != null)
- this.nsRoot = (NodeData)dataManager.getItemData(jcrSystem, new QPathEntry(Constants.EXO_NAMESPACES, 1));
- }
- catch (RepositoryException e)
- {
- log.warn("Namespace storage (/jcr:system/exo:namespaces node) is not initialized");
- }
- }
+ private final RepositoryEntry repConfig;
- DataManager getDataManager()
- {
- return dataManager;
- }
+ private boolean started = false;
- /**
- * Creates namespaces storage and fill it with given namespaces.
- *
- * @param nsSystem
- * @param addACL
- * @param namespaces
- * @throws RepositoryException
- */
- public void initStorage(NodeData nsSystem, boolean addACL, Map<String, String> namespaces)
- throws RepositoryException
+ public NamespaceDataPersister(DataManager dataManager, RepositoryEntry repConfig) throws RepositoryException
{
-
- TransientNodeData exoNamespaces =
- TransientNodeData.createNodeData(nsSystem, Constants.EXO_NAMESPACES, Constants.NT_UNSTRUCTURED);
-
- TransientPropertyData primaryType =
- TransientPropertyData.createPropertyData(exoNamespaces, Constants.JCR_PRIMARYTYPE, PropertyType.NAME, false);
- primaryType.setValue(new TransientValueData(exoNamespaces.getPrimaryTypeName()));
-
- changesLog.add(ItemState.createAddedState(exoNamespaces)).add(ItemState.createAddedState(primaryType));
-
- if (addACL)
- {
- AccessControlList acl = new AccessControlList();
-
- InternalQName[] mixins = new InternalQName[]{Constants.EXO_OWNEABLE, Constants.EXO_PRIVILEGEABLE};
- exoNamespaces.setMixinTypeNames(mixins);
-
- // jcr:mixinTypes
- List<ValueData> mixValues = new ArrayList<ValueData>();
- for (InternalQName mixin : mixins)
- {
- mixValues.add(new TransientValueData(mixin));
- }
- TransientPropertyData exoMixinTypes =
- TransientPropertyData.createPropertyData(exoNamespaces, Constants.JCR_MIXINTYPES, PropertyType.NAME, true,
- mixValues);
-
- TransientPropertyData exoOwner =
- TransientPropertyData.createPropertyData(exoNamespaces, Constants.EXO_OWNER, PropertyType.STRING, false,
- new TransientValueData(acl.getOwner()));
-
- List<ValueData> permsValues = new ArrayList<ValueData>();
- for (int i = 0; i < acl.getPermissionEntries().size(); i++)
- {
- AccessControlEntry entry = acl.getPermissionEntries().get(i);
- permsValues.add(new TransientValueData(entry));
- }
- TransientPropertyData exoPerms =
- TransientPropertyData.createPropertyData(exoNamespaces, Constants.EXO_PERMISSIONS,
- ExtendedPropertyType.PERMISSION, true, permsValues);
-
- changesLog.add(ItemState.createAddedState(exoMixinTypes)).add(ItemState.createAddedState(exoOwner)).add(
- ItemState.createAddedState(exoPerms));
- changesLog.add(new ItemState(exoNamespaces, ItemState.MIXIN_CHANGED, false, null));
- }
-
- nsRoot = exoNamespaces;
-
- Iterator<String> i = namespaces.keySet().iterator();
- while (i.hasNext())
- {
- String nsKey = i.next();
- if (nsKey != null)
- {
- if (log.isDebugEnabled())
- log.debug("Namespace " + nsKey + " " + namespaces.get(nsKey));
- addNamespace(nsKey, namespaces.get(nsKey));
- if (log.isDebugEnabled())
- log.debug("Namespace " + nsKey + " is initialized.");
- }
- else
- {
- log.warn("Namespace is " + nsKey + " " + namespaces.get(nsKey));
- }
- }
- saveChanges();
+ this.dataManager = dataManager;
+ this.repConfig = repConfig;
}
/**
@@ -183,13 +95,21 @@
*/
public void addNamespace(String prefix, String uri) throws RepositoryException
{
-
- if (!isInialized())
+ if (!started)
{
- log.warn("Namespace storage (/jcr:system/exo:namespaces node) is not initialized");
+ if(log.isDebugEnabled())
+ log.debug("Unable save namespace " + uri + "=" + prefix + " in to the storage. Storage not initialized");
return;
}
+ PlainChangesLog changesLog = new PlainChangesLogImpl();
+ internallAdd(changesLog, prefix, uri);
+ dataManager.save(new TransactionChangesLog(changesLog));
+
+ }
+
+ private PlainChangesLog internallAdd(PlainChangesLog changesLog, String prefix, String uri)
+ {
TransientNodeData nsNode =
TransientNodeData.createNodeData(nsRoot, new InternalQName("", prefix), Constants.EXO_NAMESPACE);
@@ -207,17 +127,65 @@
changesLog.add(ItemState.createAddedState(nsNode)).add(ItemState.createAddedState(primaryType)).add(
ItemState.createAddedState(exoUri)).add(ItemState.createAddedState(exoPrefix));
+ return changesLog;
+ }
+ /**
+ * Add new namespace.
+ *
+ * @param prefix NS prefix
+ * @param uri NS URI
+ * @throws RepositoryException Repository error
+ */
+ public void addNamespaces(Map<String, String> namespaceMap) throws RepositoryException
+ {
+ if (!started)
+ {
+ log.warn("Unable save namespaces in to the storage. Storage not initialized");
+ return;
+ }
+
+ PlainChangesLog changesLog = new PlainChangesLogImpl();
+ for (Map.Entry<String, String> entry : namespaceMap.entrySet())
+ {
+ String prefix = entry.getKey();
+ String uri = entry.getValue();
+
+ if (prefix != null)
+ {
+ if (log.isDebugEnabled())
+ log.debug("Namespace " + uri + ":" + prefix);
+ internallAdd(changesLog, prefix, uri);
+ }
+ }
+ dataManager.save(new TransactionChangesLog(changesLog));
+
}
+ public boolean isStorageFilled()
+ {
+ try
+ {
+ List<NodeData> storageContent = dataManager.getChildNodesData(nsRoot);
+ return storageContent.size() > 0;
+ }
+ catch (RepositoryException e)
+ {
+ log.error(e.getLocalizedMessage(), e);
+
+ }
+ return false;
+ }
+
public void removeNamespace(String prefix) throws RepositoryException
{
- if (!isInialized())
+ if (!started)
{
- log.warn("Namespace storage (/jcr:system/exo:namespaces node) is not initialized");
+ log.warn("Unable remove namspace "+prefix+" from the storage. Storage not initialized");
return;
}
+
PlainChangesLogImpl plainChangesLogImpl = new PlainChangesLogImpl();
ItemData prefData = dataManager.getItemData(nsRoot, new QPathEntry(new InternalQName("", prefix), 0));
@@ -237,9 +205,60 @@
}
- dataManager.save(new TransactionChangesLog(plainChangesLogImpl));
+ dataManager.save(new TransactionChangesLog(plainChangesLogImpl));
+
}
+ /**
+ * {@inheritDoc}
+ */
+ public void start()
+ {
+ if (!started)
+ {
+ try
+ {
+ NodeData jcrSystem = (NodeData)dataManager.getItemData(Constants.SYSTEM_UUID);
+ if (jcrSystem != null)
+ {
+ NodeData exoNamespaces =
+ (NodeData)dataManager.getItemData(jcrSystem, new QPathEntry(Constants.EXO_NAMESPACES, 1));
+ if (exoNamespaces == null)
+ {
+ initStorage(jcrSystem, !repConfig.getAccessControl().equals(AccessControlPolicy.DISABLE));
+ this.nsRoot =
+ (NodeData)dataManager.getItemData(jcrSystem, new QPathEntry(Constants.EXO_NAMESPACES, 1));
+ }
+ else
+ {
+ this.nsRoot = exoNamespaces;
+ }
+ }
+ else
+ {
+ throw new RepositoryException("Nodetypes storage (/jcr:systemnode) is not initialized.");
+
+ }
+ }
+ catch (RepositoryException e)
+ {
+ throw new RuntimeException(e.getLocalizedMessage(), e);
+ }
+
+ started = true;
+ }
+ }
+
+ public void stop()
+ {
+ }
+
+ @Deprecated
+ DataManager getDataManager()
+ {
+ return dataManager;
+ }
+
void loadNamespaces(Map<String, String> namespacesMap, Map<String, String> urisMap) throws RepositoryException
{
@@ -294,17 +313,7 @@
log.warn("Namespace storage (/jcr:system/exo:namespaces node) is not initialized. No namespaces loaded.");
}
- void saveChanges() throws RepositoryException, InvalidItemStateException
- {
- dataManager.save(new TransactionChangesLog(changesLog));
- changesLog = new PlainChangesLogImpl();
- }
- private boolean isInialized()
- {
- return nsRoot != null;
- }
-
/**
* Copy <code>PropertyData prop<code> to new TransientItemData
*
@@ -336,4 +345,71 @@
newData.setValues(values);
return newData;
}
+
+ /**
+ * Creates namespaces storage and fill it with given namespaces.
+ *
+ * @param nsSystem
+ * @param addACL
+ * @param namespaces
+ * @throws RepositoryException
+ */
+ private void initStorage(NodeData nsSystem, boolean addACL) throws RepositoryException
+ {
+ PlainChangesLog changesLog = new PlainChangesLogImpl();
+ TransientNodeData exoNamespaces =
+ TransientNodeData.createNodeData(nsSystem, Constants.EXO_NAMESPACES, Constants.NT_UNSTRUCTURED);
+
+ TransientPropertyData primaryType =
+ TransientPropertyData.createPropertyData(exoNamespaces, Constants.JCR_PRIMARYTYPE, PropertyType.NAME, false);
+ primaryType.setValue(new TransientValueData(exoNamespaces.getPrimaryTypeName()));
+
+ changesLog.add(ItemState.createAddedState(exoNamespaces)).add(ItemState.createAddedState(primaryType));
+
+ if (addACL)
+ {
+ AccessControlList acl = new AccessControlList();
+
+ InternalQName[] mixins = new InternalQName[]{Constants.EXO_OWNEABLE, Constants.EXO_PRIVILEGEABLE};
+ exoNamespaces.setMixinTypeNames(mixins);
+
+ // jcr:mixinTypes
+ List<ValueData> mixValues = new ArrayList<ValueData>();
+ for (InternalQName mixin : mixins)
+ {
+ mixValues.add(new TransientValueData(mixin));
+ }
+ TransientPropertyData exoMixinTypes =
+ TransientPropertyData.createPropertyData(exoNamespaces, Constants.JCR_MIXINTYPES, PropertyType.NAME, true,
+ mixValues);
+
+ TransientPropertyData exoOwner =
+ TransientPropertyData.createPropertyData(exoNamespaces, Constants.EXO_OWNER, PropertyType.STRING, false,
+ new TransientValueData(acl.getOwner()));
+
+ List<ValueData> permsValues = new ArrayList<ValueData>();
+ for (int i = 0; i < acl.getPermissionEntries().size(); i++)
+ {
+ AccessControlEntry entry = acl.getPermissionEntries().get(i);
+ permsValues.add(new TransientValueData(entry));
+ }
+ TransientPropertyData exoPerms =
+ TransientPropertyData.createPropertyData(exoNamespaces, Constants.EXO_PERMISSIONS,
+ ExtendedPropertyType.PERMISSION, true, permsValues);
+
+ changesLog.add(ItemState.createAddedState(exoMixinTypes)).add(ItemState.createAddedState(exoOwner)).add(
+ ItemState.createAddedState(exoPerms));
+ changesLog.add(new ItemState(exoNamespaces, ItemState.MIXIN_CHANGED, false, null));
+ }
+
+ nsRoot = exoNamespaces;
+ dataManager.save(new TransactionChangesLog(changesLog));
+ }
+
+ // TODO remove me
+ @Deprecated
+ private boolean isInialized()
+ {
+ return nsRoot != null;
+ }
}
Modified: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/NamespaceRegistryImpl.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/NamespaceRegistryImpl.java 2009-10-02 15:41:14 UTC (rev 198)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/NamespaceRegistryImpl.java 2009-10-04 09:34:54 UTC (rev 199)
@@ -23,6 +23,7 @@
import org.exoplatform.services.jcr.impl.core.query.RepositoryIndexSearcherHolder;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
+import org.picocontainer.Startable;
import java.io.IOException;
import java.util.HashMap;
@@ -41,7 +42,7 @@
* @version $Id: NamespaceRegistryImpl.java 11907 2008-03-13 15:36:21Z ksm $
*/
-public class NamespaceRegistryImpl implements ExtendedNamespaceRegistry
+public class NamespaceRegistryImpl implements ExtendedNamespaceRegistry, Startable
{
public static final Map<String, String> DEF_NAMESPACES = new HashMap<String, String>();
@@ -52,6 +53,7 @@
protected final static Log log = ExoLogger.getLogger("jcr.NamespaceRegistryImpl");
+ private boolean started = false;
static
{
@@ -88,39 +90,36 @@
}
- private Map<String, String> namespaces;
+ private final DataManager dataManager;
- private NamespaceDataPersister persister;
+ private final RepositoryIndexSearcherHolder indexSearcherHolder;
- private Map<String, String> prefixes;
+ private final Map<String, String> namespaces;
- // private HashSet<QueryHandler> queryHandlers;
+ private final Map<String, String> prefixes;
- private final RepositoryIndexSearcherHolder indexSearcherHolder;
+ private NamespaceDataPersister persister;
- // private final NodeTypeDataManager nodeTypeDataManager;
-
/**
* for tests.
*/
public NamespaceRegistryImpl()
{
- this.namespaces = DEF_NAMESPACES;
- this.prefixes = DEF_PREFIXES;
- this.indexSearcherHolder = new RepositoryIndexSearcherHolder();
- // this.queryHandlers = new HashSet<QueryHandler>();
- // this.nodeTypeDataManager = null;
+ this.namespaces = new HashMap<String, String>(DEF_NAMESPACES);
+ this.prefixes = new HashMap<String, String>(DEF_PREFIXES);
+ this.dataManager = null;
+ this.indexSearcherHolder = null;
}
- public NamespaceRegistryImpl(NamespaceDataPersister persister, RepositoryIndexSearcherHolder indexSearcherHolder)
+ public NamespaceRegistryImpl(NamespaceDataPersister persister, DataManager dataManager,
+ RepositoryIndexSearcherHolder indexSearcherHolder)
{
+ this.dataManager = dataManager;
this.indexSearcherHolder = indexSearcherHolder;
- // this.nodeTypeDataManager = nodeTypeDataManager;
this.namespaces = new HashMap<String, String>(DEF_NAMESPACES);
this.prefixes = new HashMap<String, String>(DEF_PREFIXES);
this.persister = persister;
- // this.queryHandlers = new HashSet<QueryHandler>();
}
/**
@@ -148,6 +147,22 @@
}
/**
+ * Return
+ *
+ * @param nodeType
+ * @return
+ * @throws RepositoryException
+ * @throws IOException
+ */
+ @Deprecated
+ public Set<String> getNodes(String uri) throws RepositoryException
+ {
+ validate();
+
+ return indexSearcherHolder.getNodesByUri(uri);
+ }
+
+ /**
* {@inheritDoc}
*/
public String getPrefix(String uri) throws NamespaceException
@@ -209,21 +224,6 @@
return prefixes.containsKey(uri);
}
- public void loadFromStorage() throws RepositoryException
- {
-
- try
- {
- persister.loadNamespaces(namespaces, prefixes);
- }
- catch (PathNotFoundException e)
- {
- log.info("Namespaces storage (/jcr:system/exo:namespaces) is not accessible."
- + " Default namespaces only will be used. " + e);
- return;
- }
- }
-
// //////////////////// NamespaceAccessor
/**
@@ -234,7 +234,6 @@
validateNamespace(prefix, uri);
- // if (namespaces.containsKey(prefix) || prefixes.containsKey(uri)) {
if (namespaces.containsKey(prefix))
{
unregisterNamespace(prefix);
@@ -243,17 +242,51 @@
{
unregisterNamespace(prefixes.get(uri));
}
+ if (persister != null)
+ {
+ persister.addNamespace(prefix, uri);
+ // persister.saveChanges();
+ }
+ final String newPrefix = new String(prefix);
+ final String newUri = new String(uri);
- persister.addNamespace(prefix, uri);
- persister.saveChanges();
-
- String newPrefix = new String(prefix);
- String newUri = new String(uri);
-
namespaces.put(newPrefix, newUri);
prefixes.put(newUri, newPrefix);
}
+ public void start()
+ {
+ if (!started)
+ {
+
+ // save default
+ if (persister != null)
+ {
+ // no save default
+ try
+ {
+ if (!persister.isStorageFilled())
+ {
+ persister.addNamespaces(DEF_NAMESPACES);
+ }
+ else
+ {
+ persister.loadNamespaces(namespaces, prefixes);
+ }
+ }
+ catch (final RepositoryException e)
+ {
+ throw new RuntimeException(e.getLocalizedMessage(), e);
+ }
+ }
+ started = true;
+ }
+ }
+
+ public void stop()
+ {
+ }
+
/**
* {@inheritDoc}
*/
@@ -269,37 +302,39 @@
{
throw new NamespaceException("Prefix " + prefix + " is protected");
}
-
- // throw new NamespaceException("Unregistration is not supported as"
- // + " may cause integrity problems. (todo issue #46)");
-
- Set<String> nodes = getNodes(prefix);
- if (nodes.size() > 0)
+ String uri = getURI(prefix);
+ if (indexSearcherHolder != null)
{
- StringBuffer buffer = new StringBuffer();
- buffer.append("Fail to unregister namespace");
- buffer.append(prefix);
- buffer.append(" because of following nodes: ");
- DataManager dm = persister.getDataManager();
- for (String uuid : nodes)
+ final Set<String> nodes = indexSearcherHolder.getNodesByUri(uri);
+ if (nodes.size() > 0)
{
- ItemData item = dm.getItemData(uuid);
- if (item != null && item.isNode())
- buffer.append(item.getQPath().getAsString());
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("Fail to unregister namespace");
+ buffer.append(prefix);
+ buffer.append(" because of following nodes: ");
+
+ for (String uuid : nodes)
+ {
+ ItemData item = dataManager.getItemData(uuid);
+ if (item != null && item.isNode())
+ {
+ buffer.append(item.getQPath().getAsString());
+ }
+ }
+ buffer.append(" contains whese prefix ");
+ throw new NamespaceException(buffer.toString());
}
- buffer.append(" contains whese prefix ");
- throw new NamespaceException(buffer.toString());
}
-
- prefixes.remove(getURI(prefix));
+ prefixes.remove(uri);
namespaces.remove(prefix);
- persister.removeNamespace(prefix);
-
+ if (persister != null)
+ {
+ persister.removeNamespace(prefix);
+ }
}
public void validateNamespace(String prefix, String uri) throws NamespaceException, RepositoryException
{
-
if (prefix.indexOf(":") > 0)
{
throw new RepositoryException("Namespace prefix should not contain ':' " + prefix);
@@ -309,9 +344,9 @@
{
if (uri == null)
{
- throw new NamespaceException("Can not remove built-in namespace");
+ throw new NamespaceException("Can not remove built-in namespace " + prefix);
}
- throw new NamespaceException("Can not change built-in namespace");
+ throw new NamespaceException("Can not change built-in namespace " + prefix);
}
if (prefix.toLowerCase().startsWith("xml"))
{
@@ -323,134 +358,17 @@
}
}
- // public void addQueryHandler(QueryHandler queryHandler)
- // {
- // queryHandlers.add(queryHandler);
- // }
-
- /**
- * Return
- *
- * @param nodeType
- * @return
- * @throws RepositoryException
- * @throws IOException
- */
- public Set<String> getNodes(String prefix) throws RepositoryException
+ private void validate() throws RepositoryException
{
+ if (dataManager == null)
+ {
+ throw new RepositoryException("Datamanager not initialized");
+ }
+ if (indexSearcherHolder == null)
+ {
+ throw new RepositoryException("RepositoryIndexSearcherHolder not initialized");
+ }
- // LocationFactory locationFactory = new LocationFactory(this);
- // ValueFactoryImpl valueFactory = new ValueFactoryImpl(locationFactory);
- //
- // BooleanQuery query = new BooleanQuery();
- // // query.add(new MatchAllDocsQuery(), Occur.MUST);
- // // name of the node
- // query.add(new WildcardQuery(new Term(FieldNames.LABEL, prefix + ":*")), Occur.SHOULD);
- // // name of the property
- // query.add(new WildcardQuery(new Term(FieldNames.PROPERTIES_SET, prefix + ":*")), Occur.SHOULD);
- //
- // Set<String> result = getNodes(query);
- //
- // // value of the property
- // Set<String> propSet = getNodes(new WildcardQuery(new Term(FieldNames.PROPERTIES, "*" + prefix + ":*")));
- // // Manually check property values;
- // for (String uuid : propSet)
- // {
- // if (isPrefixMatch(valueFactory, uuid, prefix))
- // result.add(uuid);
- // }
-
- return indexSearcherHolder.getNodesByUri(prefix);
}
- // /**
- // * @param valueFactory
- // * @param dm
- // * @param uuid
- // * @param prefix
- // * @throws RepositoryException
- // */
- // private boolean isPrefixMatch(ValueFactoryImpl valueFactory, String uuid, String prefix) throws RepositoryException
- // {
- // DataManager dm = persister.getDataManager();
- // ItemData node = dm.getItemData(uuid);
- // if (node != null && node.isNode())
- // {
- // List<PropertyData> props = dm.getChildPropertiesData((NodeData)node);
- // for (PropertyData propertyData : props)
- // {
- // if (propertyData.getType() == PropertyType.PATH || propertyData.getType() == PropertyType.NAME)
- // {
- // for (ValueData vdata : propertyData.getValues())
- // {
- // Value val =
- // valueFactory.loadValue(((AbstractValueData)vdata).createTransientCopy(), propertyData.getType());
- // if (propertyData.getType() == PropertyType.PATH)
- // {
- // if (isPrefixMatch(((PathValue)val).getQPath(), prefix))
- // return true;
- // }
- // else if (propertyData.getType() == PropertyType.NAME)
- // {
- // if (isPrefixMatch(((NameValue)val).getQName(), prefix))
- // return true;
- // }
- // }
- // }
- // }
- // }
- // return false;
- // }
- //
- // private boolean isPrefixMatch(QPath value, String prefix) throws NamespaceException
- // {
- // for (int i = 0; i < value.getEntries().length; i++)
- // {
- // if (isPrefixMatch(value.getEntries()[i], prefix))
- // return true;
- // }
- // return false;
- // }
- //
- // private boolean isPrefixMatch(InternalQName value, String prefix) throws NamespaceException
- // {
- // return (value.getNamespace().equals(getURI(prefix)));
- // }
-
- // /**
- // * @param query
- // * @return
- // * @throws RepositoryException
- // */
- // private Set<String> getNodes(Query query) throws RepositoryException
- // {
- // Set<String> result = new HashSet<String>();
- //
- // Iterator<QueryHandler> it = queryHandlers.iterator();
- // try
- // {
- // while (it.hasNext())
- // {
- // QueryHandler queryHandler = it.next();
- // QueryHits hits = queryHandler.executeQuery(query);
- //
- // ScoreNode sn;
- //
- // while ((sn = hits.nextScoreNode()) != null)
- // {
- // result.add(sn.getNodeId());
- // }
- // // for (int i = 0; i < hits.getSize(); i++)
- // // {
- // // result.add(hits.getFieldContent(i, FieldNames.UUID));
- // // }
- // }
- // }
- // catch (IOException e)
- // {
- // throw new RepositoryException(e.getLocalizedMessage(), e);
- // }
- // return result;
- // }
-
}
Modified: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/NodeImpl.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/NodeImpl.java 2009-10-02 15:41:14 UTC (rev 198)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/NodeImpl.java 2009-10-04 09:34:54 UTC (rev 199)
@@ -44,6 +44,7 @@
import org.exoplatform.services.jcr.impl.core.itemfilters.ItemFilter;
import org.exoplatform.services.jcr.impl.core.itemfilters.NamePatternFilter;
import org.exoplatform.services.jcr.impl.core.lock.LockImpl;
+import org.exoplatform.services.jcr.impl.core.nodetype.ItemAutocreator;
import org.exoplatform.services.jcr.impl.core.nodetype.NodeDefinitionImpl;
import org.exoplatform.services.jcr.impl.core.version.ItemDataMergeVisitor;
import org.exoplatform.services.jcr.impl.core.version.VersionHistoryImpl;
@@ -183,7 +184,7 @@
}
}
- NodeTypeData type = session.getWorkspace().getNodeTypesHolder().findNodeType(name);
+ NodeTypeData type = session.getWorkspace().getNodeTypesHolder().getNodeType(name);
// Mixin or not
if (type == null || !type.isMixin())
@@ -240,7 +241,7 @@
// find node type
NodeDefinitionData nodeDef =
- session.getWorkspace().getNodeTypesHolder().findChildNodeDefinition(name, nodeData().getPrimaryTypeName(),
+ session.getWorkspace().getNodeTypesHolder().getChildNodeDefinition(name, nodeData().getPrimaryTypeName(),
nodeData().getMixinTypeNames());
if (nodeDef == null)
@@ -300,7 +301,7 @@
checkValid();
NodeTypeData type =
- session.getWorkspace().getNodeTypesHolder().findNodeType(
+ session.getWorkspace().getNodeTypesHolder().getNodeType(
locationFactory.parseJCRName(mixinName).getInternalName());
if (type == null)
@@ -584,8 +585,11 @@
dataManager.update(state, false);
NodeTypeDataManager ntmanager = session.getWorkspace().getNodeTypesHolder();
+ ItemAutocreator itemAutocreator = new ItemAutocreator(ntmanager, valueFactory, dataManager);
+
PlainChangesLog changes =
- ntmanager.makeAutoCreatedItems(nodeData(), type.getName(), dataManager, session.getUserID());
+ itemAutocreator.makeAutoCreatedItems(nodeData(), type.getName(), dataManager, session.getUserID());
+
for (ItemState autoCreatedState : changes.getAllStates())
{
dataManager.update(autoCreatedState, false);
@@ -833,9 +837,13 @@
{
NodeType required =
nodeTypeManager.getNodeType(locationFactory.createJCRName(Constants.NT_BASE).getAsString());
+ InternalQName requiredName = sysLocFactory.parseJCRName(required.getName()).getInternalName();
+ NodeDefinitionData ntData =
+ new NodeDefinitionData(null, null, true, true, OnParentVersionAction.ABORT, false,
+ new InternalQName[]{requiredName}, null, true);
this.nodeDefinition =
- new NodeDefinitionImpl(null, null, new NodeType[]{required}, null, true, true,
- OnParentVersionAction.ABORT, false, false);
+ new NodeDefinitionImpl(ntData, nodeTypesHolder, nodeTypeManager, sysLocFactory, session
+ .getValueFactory());
}
}
else
@@ -844,7 +852,7 @@
NodeData parent = (NodeData)dataManager.getItemData(getParentIdentifier());
this.definition =
- nodeTypesHolder.findChildNodeDefinition(getInternalName(), parent.getPrimaryTypeName(), parent
+ nodeTypesHolder.getChildNodeDefinition(getInternalName(), parent.getPrimaryTypeName(), parent
.getMixinTypeNames());
if (definition == null)
@@ -857,17 +865,10 @@
rnts[j] = nodeTypeManager.findNodeType(rnames[j]);
}
- String name =
- locationFactory.createJCRName(
- definition.getName() != null ? definition.getName() : Constants.JCR_ANY_NAME).getAsString();
- NodeType defType =
- definition.getDefaultPrimaryType() != null ? nodeTypeManager.findNodeType(definition
- .getDefaultPrimaryType()) : null;
- NodeType declaringNodeType = nodeTypeManager.findNodeType(definition.getDeclaringNodeType());
nodeDefinition =
- new NodeDefinitionImpl(name, declaringNodeType, rnts, defType, definition.isAutoCreated(), definition
- .isMandatory(), definition.getOnParentVersion(), definition.isProtected(), definition
- .isAllowsSameNameSiblings());
+ new NodeDefinitionImpl(definition, nodeTypesHolder, nodeTypeManager, sysLocFactory, session
+ .getValueFactory());
+
}
}
@@ -1020,11 +1021,11 @@
// load nodeDatas
List<NodeTypeData> nodeTypes = new ArrayList<NodeTypeData>();
- nodeTypes.add(nodeTypeDataManager.findNodeType(nodeData().getPrimaryTypeName()));
+ nodeTypes.add(nodeTypeDataManager.getNodeType(nodeData().getPrimaryTypeName()));
InternalQName[] mixinNames = nodeData().getMixinTypeNames();
for (int i = 0; i < mixinNames.length; i++)
{
- nodeTypes.add(nodeTypeDataManager.findNodeType(mixinNames[i]));
+ nodeTypes.add(nodeTypeDataManager.getNodeType(mixinNames[i]));
}
// Searching default
@@ -2088,7 +2089,7 @@
// Check if nodeType exists and not mixin
NodeTypeDataManager nodeTypeDataManager = session.getWorkspace().getNodeTypesHolder();
- NodeTypeData nodeType = nodeTypeDataManager.findNodeType(primaryTypeName);
+ NodeTypeData nodeType = nodeTypeDataManager.getNodeType(primaryTypeName);
if (nodeType == null)
throw new NoSuchNodeTypeException("Nodetype not found "
+ sysLocFactory.createJCRName(primaryTypeName).getAsString());
@@ -2109,7 +2110,7 @@
}
// Check if node is not protected
NodeDefinitionData childNodeDefinition =
- session.getWorkspace().getNodeTypesHolder().findChildNodeDefinition(name, nodeData().getPrimaryTypeName(),
+ session.getWorkspace().getNodeTypesHolder().getChildNodeDefinition(name, nodeData().getPrimaryTypeName(),
nodeData().getMixinTypeNames());
if (childNodeDefinition == null)
throw new ConstraintViolationException("Can't find child node definition for "
@@ -2518,8 +2519,10 @@
NodeImpl node = (NodeImpl)dataManager.update(state, true);
NodeTypeDataManager ntmanager = session.getWorkspace().getNodeTypesHolder();
+ ItemAutocreator itemAutocreator = new ItemAutocreator(ntmanager, valueFactory, dataManager);
+
PlainChangesLog changes =
- ntmanager.makeAutoCreatedItems(node.nodeData(), primaryTypeName, dataManager, session.getUserID());
+ itemAutocreator.makeAutoCreatedItems(node.nodeData(), primaryTypeName, dataManager, session.getUserID());
for (ItemState autoCreatedState : changes.getAllStates())
{
dataManager.update(autoCreatedState, false);
@@ -2547,7 +2550,7 @@
if (sibling.getQPath().getName().equals(nameToAdd))
{
NodeDefinitionData def =
- session.getWorkspace().getNodeTypesHolder().findChildNodeDefinition(nameToAdd,
+ session.getWorkspace().getNodeTypesHolder().getChildNodeDefinition(nameToAdd,
parentNode.getPrimaryTypeName(), parentNode.getMixinTypeNames());
if (LOG.isDebugEnabled())
LOG.debug("Calculate index for " + nameToAdd + " " + sibling.getQPath().getAsString());
@@ -2617,7 +2620,7 @@
NodeData parent = (NodeData)dataManager.getItemData(getParentIdentifier());
this.definition =
- session.getWorkspace().getNodeTypesHolder().findChildNodeDefinition(getInternalName(),
+ session.getWorkspace().getNodeTypesHolder().getChildNodeDefinition(getInternalName(),
parent.getPrimaryTypeName(), parent.getMixinTypeNames());
if (definition == null)
Modified: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/PropertyImpl.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/PropertyImpl.java 2009-10-02 15:41:14 UTC (rev 198)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/PropertyImpl.java 2009-10-04 09:34:54 UTC (rev 199)
@@ -301,10 +301,9 @@
}
}
- return new PropertyDefinitionImpl(name, nodeTypeManager.findNodeType(propertyDef.getDeclaringNodeType()),
- propertyDef.getRequiredType(), propertyDef.getValueConstraints(), defaultValues, propertyDef.isAutoCreated(),
- propertyDef.isMandatory(), propertyDef.getOnParentVersion(), propertyDef.isProtected(), propertyDef
- .isMultiple());
+ return new PropertyDefinitionImpl(propertyDef, session.getWorkspace().getNodeTypesHolder(),
+ (ExtendedNodeTypeManager)session.getWorkspace().getNodeTypeManager(), session.getSystemLocationFactory(),
+ session.getValueFactory());
}
@@ -318,7 +317,7 @@
NodeData parent = parentData();
InternalQName pname = getData().getQPath().getName();
PropertyDefinitionDatas definitions =
- session.getWorkspace().getNodeTypesHolder().findPropertyDefinitions(pname, parent.getPrimaryTypeName(),
+ session.getWorkspace().getNodeTypesHolder().getPropertyDefinitions(pname, parent.getPrimaryTypeName(),
parent.getMixinTypeNames());
if (definitions == null)
throw new ConstraintViolationException("Definition for property " + getPath() + " not found.");
Modified: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/ScratchWorkspaceInitializer.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/ScratchWorkspaceInitializer.java 2009-10-02 15:41:14 UTC (rev 198)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/ScratchWorkspaceInitializer.java 2009-10-04 09:34:54 UTC (rev 199)
@@ -26,7 +26,6 @@
import org.exoplatform.services.jcr.config.RepositoryEntry;
import org.exoplatform.services.jcr.config.WorkspaceEntry;
import org.exoplatform.services.jcr.core.ExtendedPropertyType;
-import org.exoplatform.services.jcr.core.nodetype.NodeTypeDataManager;
import org.exoplatform.services.jcr.dataflow.DataManager;
import org.exoplatform.services.jcr.dataflow.ItemState;
import org.exoplatform.services.jcr.dataflow.PlainChangesLog;
@@ -37,7 +36,6 @@
import org.exoplatform.services.jcr.datamodel.QPath;
import org.exoplatform.services.jcr.datamodel.ValueData;
import org.exoplatform.services.jcr.impl.Constants;
-import org.exoplatform.services.jcr.impl.core.nodetype.NodeTypeDataPersister;
import org.exoplatform.services.jcr.impl.dataflow.TransientNodeData;
import org.exoplatform.services.jcr.impl.dataflow.TransientPropertyData;
import org.exoplatform.services.jcr.impl.dataflow.TransientValueData;
@@ -78,23 +76,17 @@
private final String accessControlType;
- private final NamespaceDataPersister nsPersister;
+ // private final NamespaceDataPersister nsPersister;
- private final NodeTypeDataPersister ntPersister;
-
private final String rootPermissions;
private final InternalQName rootNodeType;
- private final NodeTypeDataManager nodeTypeDataManager;
-
public ScratchWorkspaceInitializer(WorkspaceEntry config, RepositoryEntry repConfig,
- CacheableWorkspaceDataManager dataManager, LocationFactory locationFactory, NamespaceDataPersister nsPersister,
- NodeTypeDataManager nodeTypeDataManager, NodeTypeDataPersister ntPersister)
+ CacheableWorkspaceDataManager dataManager, LocationFactory locationFactory)
throws RepositoryConfigurationException, PathNotFoundException, RepositoryException
{
- this.nodeTypeDataManager = nodeTypeDataManager;
this.systemWorkspaceName = repConfig.getSystemWorkspaceName();
this.accessControlType = repConfig.getAccessControl();
this.workspaceName = config.getName();
@@ -147,9 +139,9 @@
: Constants.NT_UNSTRUCTURED;
this.dataManager = dataManager;
- this.nsPersister = nsPersister;
+ // this.nsPersister = nsPersister;
// this.ntRegistry = ntRegistry;
- this.ntPersister = ntPersister;
+
}
public NodeData initWorkspace() throws RepositoryException
@@ -329,13 +321,15 @@
dataManager.save(new TransactionChangesLog(changesLog));
- nsPersister.initStorage(jcrSystem, addACL, NamespaceRegistryImpl.DEF_NAMESPACES);
+ //nsPersister.initStorage(jcrSystem, addACL, NamespaceRegistryImpl.DEF_NAMESPACES);
// nodeTypes save
- changesLog = new PlainChangesLogImpl();
- changesLog.addAll(ntPersister.initNodetypesRoot(jcrSystem, addACL).getAllStates());
- changesLog.addAll(ntPersister.initStorage(nodeTypeDataManager.getAllNodeTypes()).getAllStates());
- ntPersister.saveChanges(changesLog);
+ // changesLog = new PlainChangesLogImpl();
+ // changesLog.addAll(ntPersister.initNodetypesRoot(jcrSystem,
+ // addACL).getAllStates());
+ // changesLog.addAll(ntPersister.initStorage(nodeTypeDataManager.getAllNodeTypes()).getAllStates());
+ // ntPersister.saveChanges(changesLog);
+ // nodeTypeDataManager.initDefaultNodeTypes(addACL);
return jcrSystem;
}
Added: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/AbstractNodeTypeRepository.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/AbstractNodeTypeRepository.java (rev 0)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/AbstractNodeTypeRepository.java 2009-10-04 09:34:54 UTC (rev 199)
@@ -0,0 +1,178 @@
+/*
+ * 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.nodetype;
+
+import org.exoplatform.services.jcr.access.AccessControlPolicy;
+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.PlainChangesLog;
+import org.exoplatform.services.jcr.datamodel.InternalQName;
+import org.exoplatform.services.jcr.impl.core.nodetype.registration.NodeTypeDataPersister;
+import org.exoplatform.services.jcr.impl.core.nodetype.registration.UpdateNodeTypeObserver;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.jcr.RepositoryException;
+
+
+/**
+ * @author <a href="mailto:Sergey.Kabashnyuk at exoplatform.org">Sergey Kabashnyuk</a>
+ * @version $Id: exo-jboss-codetemplates.xml 34360 2009-07-22 23:58:59Z ksm $
+ *
+ */
+public abstract class AbstractNodeTypeRepository implements NodeTypeRepository
+{
+ protected final NodeTypeDataPersister nodeTypeDataPersister;
+
+ /**
+ * @param nodeTypeDataPersister
+ */
+ public AbstractNodeTypeRepository(NodeTypeDataPersister nodeTypeDataPersister)
+ {
+ super();
+ this.nodeTypeDataPersister = nodeTypeDataPersister;
+ }
+
+ /**
+ * @see org.exoplatform.services.jcr.impl.core.nodetype.NodeTypeRepository#getAllNodeTypes()
+ */
+ public List<NodeTypeData> getAllNodeTypes() throws RepositoryException
+ {
+ // TODO Auto-generated method stub
+ return nodeTypeDataPersister.getAllNodeTypes();
+ }
+
+ /**
+ * @see org.exoplatform.services.jcr.core.ComponentPersister#isStorageFilled()
+ */
+ public boolean isStorageFilled()
+ {
+ // TODO Auto-generated method stub
+ return nodeTypeDataPersister.isStorageFilled();
+ }
+
+ /**
+ * @throws RepositoryException
+ * @see org.exoplatform.services.jcr.impl.core.nodetype.NodeTypeRepository#update(java.util.List, org.exoplatform.services.jcr.impl.core.nodetype.registration.UpdateNodeTypeObserver)
+ */
+ public void registerNodeType(final List<NodeTypeData> nodeTypes, final NodeTypeDataManager nodeTypeDataManager,
+ final String accessControlPolicy, final int alreadyExistsBehaviour) throws RepositoryException
+ {
+ // create map to speedUp registration process
+ final Map<InternalQName, NodeTypeData> volatileNodeTypes = new HashMap<InternalQName, NodeTypeData>();
+ for (final NodeTypeData nodeTypeData : nodeTypes)
+ {
+ volatileNodeTypes.put(nodeTypeData.getName(), nodeTypeData);
+ }
+ final List<NodeTypeData> wait4RegistrationNodeTypes = new ArrayList<NodeTypeData>();
+
+ // persist changes
+ if (this.nodeTypeDataPersister != null)
+ {
+ this.nodeTypeDataPersister.update(nodeTypes, new UpdateNodeTypeObserver()
+ {
+
+ public void afterUpdate(final NodeTypeData updatetNodetype, final Object context)
+ {
+
+ }
+
+ public void beforeUpdate(final NodeTypeData updatetNodetype, final Object context)
+ throws RepositoryException
+ {
+ if (updatetNodetype == null)
+ {
+ throw new RepositoryException("NodeTypeData object " + updatetNodetype + " is null");
+ }
+
+ if (accessControlPolicy.equals(AccessControlPolicy.DISABLE)
+ && updatetNodetype.getName().equals("exo:privilegeable"))
+ {
+ throw new RepositoryException("NodeType exo:privilegeable is DISABLED");
+ }
+
+ final InternalQName qname = updatetNodetype.getName();
+ if (qname == null)
+ {
+ throw new RepositoryException("NodeType implementation class " + updatetNodetype.getClass().getName()
+ + " is not supported in this method");
+ }
+
+ final NodeTypeData registeredNodeType = getNodeType(qname);
+ if (registeredNodeType != null)
+ {
+ switch (alreadyExistsBehaviour)
+ {
+ case ExtendedNodeTypeManager.FAIL_IF_EXISTS :
+ throw new NodeTypeExistsException("NodeType " + updatetNodetype.getName()
+ + " is already registered");
+ case ExtendedNodeTypeManager.REPLACE_IF_EXISTS :
+ ((PlainChangesLog)context).addAll(nodeTypeDataManager.updateNodeType(registeredNodeType,
+ updatetNodetype, volatileNodeTypes).getAllStates());
+ break;
+ }
+ }
+ else
+ {
+ wait4RegistrationNodeTypes.add(updatetNodetype);
+ }
+ }
+
+ public boolean shouldSkip(final NodeTypeData updatetNodetype, final Object context)
+ throws RepositoryException
+ {
+ final NodeTypeData registeredNodeType = getNodeType(updatetNodetype.getName());
+ if (registeredNodeType != null && alreadyExistsBehaviour == ExtendedNodeTypeManager.IGNORE_IF_EXISTS)
+ {
+ return true;
+
+ }
+ return false;
+ }
+ });
+ }
+ // register new node types
+ for (final NodeTypeData nodeTypeData : wait4RegistrationNodeTypes)
+ {
+ addNodeType(nodeTypeData, volatileNodeTypes);
+ }
+ }
+
+ /**
+ * @see org.picocontainer.Startable#start()
+ */
+ public void start()
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ /**
+ * @see org.picocontainer.Startable#stop()
+ */
+ public void stop()
+ {
+ // TODO Auto-generated method stub
+
+ }
+}
Property changes on: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/AbstractNodeTypeRepository.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/ExtendedItemDefinition.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/ExtendedItemDefinition.java (rev 0)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/ExtendedItemDefinition.java 2009-10-04 09:34:54 UTC (rev 199)
@@ -0,0 +1,49 @@
+/*
+ * 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.nodetype;
+
+import org.exoplatform.services.jcr.datamodel.InternalQName;
+
+import javax.jcr.nodetype.ItemDefinition;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * @author <a href="mailto:Sergey.Kabashnyuk at gmail.com">Sergey Kabashnyuk</a>
+ * @version $Id: $
+ */
+public interface ExtendedItemDefinition extends ItemDefinition
+{
+
+ /**
+ * @return
+ */
+ public InternalQName getQName();
+
+ /**
+ * @return
+ */
+ public InternalQName getDeclaringNodeTypeQName();
+
+ /**
+ * @return
+ */
+ public boolean isResidualSet();
+
+}
Property changes on: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/ExtendedItemDefinition.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/ExtendedNodeDefinition.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/ExtendedNodeDefinition.java (rev 0)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/ExtendedNodeDefinition.java 2009-10-04 09:34:54 UTC (rev 199)
@@ -0,0 +1,42 @@
+/*
+ * 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.nodetype;
+
+import org.exoplatform.services.jcr.datamodel.InternalQName;
+
+import javax.jcr.nodetype.NodeDefinition;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * @author <a href="mailto:Sergey.Kabashnyuk at gmail.com">Sergey Kabashnyuk</a>
+ * @version $Id: $
+ */
+public interface ExtendedNodeDefinition extends NodeDefinition
+{
+
+ public InternalQName getDefaultPrimaryTypeQName();
+
+ /**
+ * @return
+ */
+
+ public InternalQName[] getRequiredPrimaryTypeQNames();
+
+}
Property changes on: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/ExtendedNodeDefinition.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/InmemoryNodeTypeRepository.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/InmemoryNodeTypeRepository.java (rev 0)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/InmemoryNodeTypeRepository.java 2009-10-04 09:34:54 UTC (rev 199)
@@ -0,0 +1,245 @@
+/*
+ * 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.nodetype;
+
+import org.exoplatform.services.jcr.core.nodetype.NodeDefinitionData;
+import org.exoplatform.services.jcr.core.nodetype.NodeTypeData;
+import org.exoplatform.services.jcr.core.nodetype.PropertyDefinitionDatas;
+import org.exoplatform.services.jcr.datamodel.InternalQName;
+import org.exoplatform.services.jcr.impl.core.nodetype.registration.NodeTypeDataPersister;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.jcr.RepositoryException;
+
+/**
+ * @author <a href="mailto:Sergey.Kabashnyuk at exoplatform.org">Sergey Kabashnyuk</a>
+ * @version $Id: exo-jboss-codetemplates.xml 34360 2009-07-22 23:58:59Z ksm $
+ *
+ */
+public class InmemoryNodeTypeRepository extends AbstractNodeTypeRepository
+{
+ private final Log log = ExoLogger.getLogger(InmemoryNodeTypeRepository.class.getName());
+
+ private final ItemDefinitionDataHolder defsHolder;
+
+ private final NodeTypeDataHierarchyHolder hierarchy;
+
+ private boolean haveTypes = false;
+
+
+
+ /**
+ * @param defsHolder
+ * @param hierarchy
+ */
+ public InmemoryNodeTypeRepository(ItemDefinitionDataHolder defsHolder, NodeTypeDataHierarchyHolder hierarchy,
+ NodeTypeDataPersister nodeTypeDataPersister)
+ {
+ super(nodeTypeDataPersister);
+ this.defsHolder = defsHolder;
+ this.hierarchy = hierarchy;
+ }
+
+ /**
+ * @param defsHolder
+ * @param hierarchy
+ */
+ public InmemoryNodeTypeRepository(NodeTypeDataPersister nodeTypeDataPersister)
+ {
+ super(nodeTypeDataPersister);
+ this.hierarchy = new NodeTypeDataHierarchyHolder();
+ this.defsHolder = new ItemDefinitionDataHolder();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void addNodeType(NodeTypeData nodeType, Map<InternalQName, NodeTypeData> volatileNodeTypes)
+ throws RepositoryException
+ {
+
+ hierarchy.addNodeType(nodeType, volatileNodeTypes);
+ defsHolder.putDefinitions(nodeType.getName(), nodeType);
+ // put supers
+ final Set<InternalQName> supers = hierarchy.getSupertypes(nodeType.getName(), volatileNodeTypes);
+
+ for (final InternalQName superName : supers)
+ {
+ defsHolder.putDefinitions(nodeType.getName(), hierarchy.getNodeType(superName, volatileNodeTypes));
+ }
+ haveTypes = true;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public List<NodeTypeData> getAllNodeTypes()
+ {
+ if (!haveTypes)
+ try
+ {
+ return super.getAllNodeTypes();
+ }
+ catch (RepositoryException e)
+ {
+ log.error(e.getLocalizedMessage(), e);
+ }
+
+ return hierarchy.getAllNodeTypes();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public NodeDefinitionData getChildNodeDefinition(InternalQName parentTypeName, InternalQName nodeName,
+ InternalQName nodeTypeName)
+ {
+ return defsHolder.getChildNodeDefinition(parentTypeName, nodeName, nodeTypeName);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Set<InternalQName> getDeclaredSubtypes(InternalQName nodeTypeName)
+ {
+
+ return hierarchy.getDeclaredSubtypes(nodeTypeName);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public NodeDefinitionData getDefaultChildNodeDefinition(InternalQName nodeName, InternalQName[] nodeTypeNames)
+ {
+
+ return defsHolder.getDefaultChildNodeDefinition(nodeName, nodeTypeNames);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public NodeTypeData getNodeType(InternalQName typeName)
+ {
+
+ return hierarchy.getNodeType(typeName);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public NodeTypeData getNodeType(InternalQName superName, Map<InternalQName, NodeTypeData> volatileNodeTypes)
+ {
+
+ return hierarchy.getNodeType(superName, volatileNodeTypes);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public PropertyDefinitionDatas getPropertyDefinitions(InternalQName propertyName, InternalQName[] nodeTypeNames)
+ {
+
+ return defsHolder.getPropertyDefinitions(propertyName, nodeTypeNames);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Set<InternalQName> getSubtypes(InternalQName nodeTypeName)
+ {
+
+ return hierarchy.getSubtypes(nodeTypeName);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Set<InternalQName> getSupertypes(InternalQName ntname)
+ {
+
+ return hierarchy.getSupertypes(ntname);
+ }
+
+ /**
+ * {@inheritDoc}
+ * @throws RepositoryException
+ */
+ public Set<InternalQName> getSupertypes(InternalQName name, Map<InternalQName, NodeTypeData> volatileNodeTypes)
+ throws RepositoryException
+ {
+
+ return hierarchy.getSupertypes(name, volatileNodeTypes);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isNodeType(InternalQName testTypeName, InternalQName[] typesNames)
+ {
+
+ return hierarchy.isNodeType(testTypeName, typesNames);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isNodeType(InternalQName testTypeName, InternalQName primaryType)
+ {
+ return hierarchy.isNodeType(testTypeName, primaryType);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public NodeTypeRepository createCopy()
+ {
+
+ return new InmemoryNodeTypeRepository(defsHolder.createCopy(), hierarchy.createCopy(), nodeTypeDataPersister);
+ }
+
+ /**
+ * @see org.exoplatform.services.jcr.impl.core.nodetype.NodeTypeRepository#removeNodeType(org.exoplatform.services.jcr.datamodel.InternalQName, org.exoplatform.services.jcr.core.nodetype.NodeTypeData)
+ */
+ public void removeNodeType(NodeTypeData nodeType)
+ {
+ InternalQName nodeTypeName = nodeType.getName();
+ // put supers
+ final Set<InternalQName> supers = hierarchy.getSubtypes(nodeTypeName);
+
+ // remove from internal lists
+ hierarchy.removeNodeType(nodeTypeName);
+
+ // remove supers
+ if (supers != null)
+ {
+ for (final InternalQName superName : supers)
+ {
+ defsHolder.removeDefinitions(nodeTypeName, hierarchy.getNodeType(superName));
+ }
+ }
+ // remove it self
+ defsHolder.removeDefinitions(nodeTypeName, nodeType);
+ haveTypes = hierarchy.getAllNodeTypes().size()>0;
+ }
+}
Property changes on: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/InmemoryNodeTypeRepository.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/ItemAutocreator.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/ItemAutocreator.java (rev 0)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/ItemAutocreator.java 2009-10-04 09:34:54 UTC (rev 199)
@@ -0,0 +1,282 @@
+/*
+ * 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.nodetype;
+
+import org.exoplatform.services.jcr.access.AccessControlEntry;
+import org.exoplatform.services.jcr.access.AccessControlList;
+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.core.nodetype.PropertyDefinitionData;
+import org.exoplatform.services.jcr.dataflow.ItemDataConsumer;
+import org.exoplatform.services.jcr.dataflow.ItemState;
+import org.exoplatform.services.jcr.dataflow.PlainChangesLog;
+import org.exoplatform.services.jcr.dataflow.PlainChangesLogImpl;
+import org.exoplatform.services.jcr.datamodel.InternalQName;
+import org.exoplatform.services.jcr.datamodel.ItemData;
+import org.exoplatform.services.jcr.datamodel.NodeData;
+import org.exoplatform.services.jcr.datamodel.QPathEntry;
+import org.exoplatform.services.jcr.datamodel.ValueData;
+import org.exoplatform.services.jcr.impl.Constants;
+import org.exoplatform.services.jcr.impl.core.value.BaseValue;
+import org.exoplatform.services.jcr.impl.dataflow.TransientNodeData;
+import org.exoplatform.services.jcr.impl.dataflow.TransientPropertyData;
+import org.exoplatform.services.jcr.impl.dataflow.TransientValueData;
+import org.exoplatform.services.jcr.impl.dataflow.version.VersionHistoryDataHelper;
+import org.exoplatform.services.jcr.util.IdGenerator;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+import javax.jcr.ValueFactory;
+
+/**
+ * @author <a href="mailto:Sergey.Kabashnyuk at exoplatform.org">Sergey Kabashnyuk</a>
+ * @version $Id: exo-jboss-codetemplates.xml 34360 2009-07-22 23:58:59Z ksm $
+ *
+ */
+public class ItemAutocreator
+{
+
+ private final Log log = ExoLogger.getLogger(getClass().getName());
+
+ private final NodeTypeDataManager nodeTypeDataManager;
+
+ private final ItemDataConsumer dataConsumer;
+
+ private final ValueFactory valueFactory;
+
+ /**
+ * @param nodeTypeDataManager
+ */
+ public ItemAutocreator(NodeTypeDataManager nodeTypeDataManager, ValueFactory valueFactory,
+ ItemDataConsumer dataConsumer)
+ {
+ super();
+ this.nodeTypeDataManager = nodeTypeDataManager;
+ this.valueFactory = valueFactory;
+ this.dataConsumer = dataConsumer;
+ }
+
+ public PlainChangesLog makeAutoCreatedItems(final NodeData parent, final InternalQName nodeTypeName,
+ final ItemDataConsumer targetDataManager, final String owner) throws RepositoryException
+ {
+ final PlainChangesLogImpl changes = new PlainChangesLogImpl();
+ final NodeTypeData type = nodeTypeDataManager.getNodeType(nodeTypeName);
+
+ changes.addAll(makeAutoCreatedProperties(parent, nodeTypeName,
+ nodeTypeDataManager.getAllPropertyDefinitions(nodeTypeName), targetDataManager, owner).getAllStates());
+ // Add autocreated child nodes
+ changes.addAll(makeAutoCreatedNodes(parent, nodeTypeName,
+ nodeTypeDataManager.getAllChildNodeDefinitions(nodeTypeName), targetDataManager, owner).getAllStates());
+
+ // versionable
+ if (nodeTypeDataManager.isNodeType(Constants.MIX_VERSIONABLE, new InternalQName[]{type.getName()}))
+ {
+
+ // using VH helper as for one new VH, all changes in changes log
+ changes.addAll(makeMixVesionableChanges(parent).getAllStates());
+ }
+ return changes;
+ }
+
+ public PlainChangesLog makeAutoCreatedNodes(final NodeData parent, final InternalQName typeName,
+ final NodeDefinitionData[] nodeDefs, final ItemDataConsumer targetDataManager, final String owner)
+ throws RepositoryException
+ {
+ final PlainChangesLogImpl changes = new PlainChangesLogImpl();
+ final Set<InternalQName> addedNodes = new HashSet<InternalQName>();
+ for (final NodeDefinitionData ndef : nodeDefs)
+ {
+ if (ndef.isAutoCreated())
+ {
+ final ItemData pdata = targetDataManager.getItemData(parent, new QPathEntry(ndef.getName(), 0));
+ if (pdata == null && !addedNodes.contains(ndef.getName()) || pdata != null && !pdata.isNode())
+ {
+
+ final TransientNodeData childNodeData =
+ TransientNodeData.createNodeData(parent, ndef.getName(), ndef.getDefaultPrimaryType(), IdGenerator
+ .generate());
+ changes.add(ItemState.createAddedState(childNodeData, false));
+ changes.addAll(makeAutoCreatedItems(childNodeData, childNodeData.getPrimaryTypeName(),
+ targetDataManager, owner).getAllStates());
+ addedNodes.add(ndef.getName());
+ }
+ else
+ {
+ if (this.log.isDebugEnabled())
+ {
+ this.log.debug("Skipping existed node " + ndef.getName() + " in " + parent.getQPath().getAsString()
+ + " during the automatic creation of items for " + typeName.getAsString()
+ + " nodetype or mixin type");
+ }
+ }
+ }
+ }
+ return changes;
+
+ }
+
+ public PlainChangesLog makeAutoCreatedProperties(final NodeData parent, final InternalQName typeName,
+ final PropertyDefinitionData[] propDefs, final ItemDataConsumer targetDataManager, final String owner)
+ throws RepositoryException
+ {
+ final PlainChangesLogImpl changes = new PlainChangesLogImpl();
+
+ final Set<InternalQName> addedProperties = new HashSet<InternalQName>();
+
+ // Add autocreated child properties
+
+ for (final PropertyDefinitionData pdef : propDefs)
+ {
+
+ if (pdef.isAutoCreated())
+ {
+
+ final ItemData pdata = targetDataManager.getItemData(parent, new QPathEntry(pdef.getName(), 0));
+ if (pdata == null && !addedProperties.contains(pdef.getName()) || pdata != null && pdata.isNode())
+ {
+
+ final List<ValueData> listAutoCreateValue = autoCreatedValue(parent, typeName, pdef, owner);
+
+ if (listAutoCreateValue != null)
+ {
+ final TransientPropertyData propertyData =
+ TransientPropertyData.createPropertyData(parent, pdef.getName(), pdef.getRequiredType(), pdef
+ .isMultiple(), listAutoCreateValue);
+ changes.add(ItemState.createAddedState(propertyData));
+ addedProperties.add(pdef.getName());
+ }
+ }
+ else
+ {
+ // TODO if autocreated property exists it's has wrong data (e.g. ACL)
+ // - throw an exception
+ if (this.log.isDebugEnabled())
+ {
+ this.log.debug("Skipping existed property " + pdef.getName() + " in "
+ + parent.getQPath().getAsString() + " during the automatic creation of items for "
+ + typeName.getAsString() + " nodetype or mixin type");
+ }
+ }
+ }
+ }
+ return changes;
+ }
+
+ /**
+ * @param parent
+ * @param dataManager
+ * @param changes
+ * @return
+ * @throws RepositoryException
+ */
+ public PlainChangesLog makeMixVesionableChanges(final NodeData parent) throws RepositoryException
+ {
+ PlainChangesLog changesLog = new PlainChangesLogImpl();
+ new VersionHistoryDataHelper(parent, changesLog, dataConsumer, nodeTypeDataManager);
+ return changesLog;
+ }
+
+ protected List<ValueData> autoCreatedValue(final NodeData parent, final InternalQName typeName,
+ final PropertyDefinitionData def, final String owner) throws RepositoryException
+ {
+ final List<ValueData> vals = new ArrayList<ValueData>();
+
+ if (nodeTypeDataManager.isNodeType(Constants.NT_BASE, new InternalQName[]{typeName})
+ && def.getName().equals(Constants.JCR_PRIMARYTYPE))
+ {
+ vals.add(new TransientValueData(parent.getPrimaryTypeName()));
+
+ }
+ else if (nodeTypeDataManager.isNodeType(Constants.MIX_REFERENCEABLE, new InternalQName[]{typeName})
+ && def.getName().equals(Constants.JCR_UUID))
+ {
+ vals.add(new TransientValueData(parent.getIdentifier()));
+
+ }
+ else if (nodeTypeDataManager.isNodeType(Constants.NT_HIERARCHYNODE, new InternalQName[]{typeName})
+ && def.getName().equals(Constants.JCR_CREATED))
+ {
+ vals.add(new TransientValueData(Calendar.getInstance()));
+ }
+ else if (nodeTypeDataManager.isNodeType(Constants.NT_HIERARCHYNODE, new InternalQName[]{typeName})
+ && def.getName().equals(new InternalQName(Constants.NS_JCR_URI, "createdBy")))
+ {
+ vals.add(new TransientValueData(owner));
+
+ }
+ else if (nodeTypeDataManager.isNodeType(Constants.EXO_OWNEABLE, new InternalQName[]{typeName})
+ && def.getName().equals(Constants.EXO_OWNER))
+ {
+ // String owner = session.getUserID();
+ vals.add(new TransientValueData(owner));
+ parent.setACL(new AccessControlList(owner, parent.getACL().getPermissionEntries()));
+
+ }
+ else if (nodeTypeDataManager.isNodeType(Constants.EXO_PRIVILEGEABLE, new InternalQName[]{typeName})
+ && def.getName().equals(Constants.EXO_PERMISSIONS))
+ {
+ for (final AccessControlEntry ace : parent.getACL().getPermissionEntries())
+ {
+ vals.add(new TransientValueData(ace));
+ }
+
+ }
+ else
+ {
+ final String[] propVal = def.getDefaultValues();
+ // there can be null in definition but should not be null value
+ if (propVal != null && propVal.length != 0)
+ {
+ for (final String v : propVal)
+ {
+ if (v != null)
+ {
+ if (def.getRequiredType() == PropertyType.UNDEFINED)
+ {
+ vals.add(((BaseValue)this.valueFactory.createValue(v)).getInternalData());
+ }
+ else
+ {
+ vals.add(((BaseValue)this.valueFactory.createValue(v, def.getRequiredType())).getInternalData());
+ }
+ }
+ else
+ {
+ vals.add(null);
+ }
+ }
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ return vals;
+ }
+}
Property changes on: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/ItemAutocreator.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/ItemDefinitionDataHolder.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/ItemDefinitionDataHolder.java 2009-10-02 15:41:14 UTC (rev 198)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/ItemDefinitionDataHolder.java 2009-10-04 09:34:54 UTC (rev 199)
@@ -58,6 +58,15 @@
this.defNodeDefinitions = new HashMap<DefaultNodeDefKey, NodeDefinitionData>();
}
+ private ItemDefinitionDataHolder(HashMap<ChildNodeDefKey, NodeDefinitionData> nodeDefinitions,
+ HashMap<PropertyDefKey, PropertyDefinitionData> propertyDefinitions,
+ HashMap<DefaultNodeDefKey, NodeDefinitionData> defNodeDefinitions)
+ {
+ this.nodeDefinitions = nodeDefinitions;
+ this.propertyDefinitions = propertyDefinitions;
+ this.defNodeDefinitions = defNodeDefinitions;
+ }
+
/**
* @param parentNodeType - name of parent node type
* @param childName name of child node
@@ -265,8 +274,21 @@
return def;
}
+ /**
+ * Create copy of holder.
+ *
+ * @return
+ */
+ protected ItemDefinitionDataHolder createCopy()
+ {
+ return new ItemDefinitionDataHolder(new HashMap<ChildNodeDefKey, NodeDefinitionData>(nodeDefinitions),
+ new HashMap<PropertyDefKey, PropertyDefinitionData>(propertyDefinitions),
+ new HashMap<DefaultNodeDefKey, NodeDefinitionData>(defNodeDefinitions));
+ }
+
private class ChildNodeDefKey extends ItemDefKey
{
+ private int hashCode = -1;
private final InternalQName childNodeType;
@@ -319,11 +341,16 @@
@Override
public int hashCode()
{
- final int prime = 31;
- int result = super.hashCode();
- result = prime * result + getOuterType().hashCode();
- result = prime * result + ((childNodeType == null) ? 0 : childNodeType.hashCode());
- return result;
+ if (hashCode == -1)
+ {
+ final int prime = 31;
+ int result = super.hashCode();
+ result = prime * result + getOuterType().hashCode();
+ result = prime * result + ((childNodeType == null) ? 0 : childNodeType.hashCode());
+ hashCode = result;
+ }
+
+ return hashCode;
}
/**
@@ -365,6 +392,8 @@
private final InternalQName childName;
+ private int hashCode = -1;
+
protected ItemDefKey(InternalQName parentNodeType, InternalQName childName)
{
this.parentNodeType = parentNodeType;
@@ -425,12 +454,16 @@
@Override
public int hashCode()
{
- final int prime = 31;
- int result = 1;
- result = prime * result + getOuterType().hashCode();
- result = prime * result + ((childName == null) ? 0 : childName.hashCode());
- result = prime * result + ((parentNodeType == null) ? 0 : parentNodeType.hashCode());
- return result;
+ if (hashCode == -1)
+ {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + getOuterType().hashCode();
+ result = prime * result + ((childName == null) ? 0 : childName.hashCode());
+ result = prime * result + ((parentNodeType == null) ? 0 : parentNodeType.hashCode());
+ hashCode = result;
+ }
+ return hashCode;
}
/**
@@ -456,6 +489,8 @@
private final boolean multiValued;
+ private int hashCode = -1;
+
private PropertyDefKey(InternalQName parentNodeType, InternalQName childName, boolean multiValued)
{
super(parentNodeType, childName);
@@ -498,11 +533,16 @@
@Override
public int hashCode()
{
- final int prime = 31;
- int result = super.hashCode();
- result = prime * result + getOuterType().hashCode();
- result = prime * result + (multiValued ? 1231 : 1237);
- return result;
+ if (hashCode == -1)
+ {
+ final int prime = 31;
+ int result = super.hashCode();
+ result = prime * result + getOuterType().hashCode();
+ result = prime * result + (multiValued ? 1231 : 1237);
+ hashCode = result;
+ }
+
+ return hashCode;
}
/**
Modified: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/ItemDefinitionImpl.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/ItemDefinitionImpl.java 2009-10-02 15:41:14 UTC (rev 198)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/ItemDefinitionImpl.java 2009-10-04 09:34:54 UTC (rev 199)
@@ -18,74 +18,102 @@
*/
package org.exoplatform.services.jcr.impl.core.nodetype;
-import org.exoplatform.services.jcr.core.nodetype.ExtendedItemDefinition;
+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.datamodel.InternalQName;
import org.exoplatform.services.jcr.impl.Constants;
+import org.exoplatform.services.jcr.impl.core.LocationFactory;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+import javax.jcr.RepositoryException;
+import javax.jcr.ValueFactory;
import javax.jcr.nodetype.NodeType;
/**
* Created by The eXo Platform SAS.
*
- * @author Gennady Azarenkov
- * @version $Id: ItemDefinitionImpl.java 11907 2008-03-13 15:36:21Z ksm $
+ * @author <a href="mailto:Sergey.Kabashnyuk at gmail.com">Sergey Kabashnyuk</a>
+ * @version $Id: $
*/
-
-public abstract class ItemDefinitionImpl implements ExtendedItemDefinition
+public class ItemDefinitionImpl implements ExtendedItemDefinition
{
+ /**
+ * Class logger.
+ */
+ private static final Log LOG = ExoLogger.getLogger(ItemDefinitionImpl.class);
- protected final NodeType declaringNodeType;
+ protected final NodeTypeDataManager nodeTypeDataManager;
- protected final String name;
+ protected final LocationFactory locationFactory;
- protected final boolean autoCreate;
+ protected final ExtendedNodeTypeManager nodeTypeManager;
- protected final int onVersion;
+ protected final ValueFactory valueFactory;
- protected final boolean readOnly;
+ private final ItemDefinitionData itemDefinitionData;
- protected final boolean mandatory;
+ /**
+ * @param name
+ * @param declaringNodeType
+ * @param onParentVersion
+ * @param autoCreated
+ * @param mandatory
+ * @param protectedItem
+ */
+ public ItemDefinitionImpl(ItemDefinitionData itemDefinitionData, NodeTypeDataManager nodeTypeDataManager,
+ ExtendedNodeTypeManager nodeTypeManager, LocationFactory locationFactory, ValueFactory valueFactory)
+ {
- protected int hashCode;
+ this.itemDefinitionData = itemDefinitionData;
+ this.nodeTypeDataManager = nodeTypeDataManager;
+ this.nodeTypeManager = nodeTypeManager;
+ this.locationFactory = locationFactory;
+ this.valueFactory = valueFactory;
+ }
- public ItemDefinitionImpl(String name, NodeType declaringNodeType, boolean autoCreate, int onVersion,
- boolean readOnly, boolean mandatory)
+ /**
+ * {@inheritDoc}
+ */
+ public NodeType getDeclaringNodeType()
{
- this.declaringNodeType = declaringNodeType;
- this.autoCreate = autoCreate;
- this.onVersion = onVersion;
- this.readOnly = readOnly;
- this.mandatory = mandatory;
- this.name = name;
- int hk = 7;
- hk = 31 * hk + (name != null ? name.hashCode() : 0);
- hk = 31 * hk + (autoCreate ? 0 : 1);
- hk = 31 * hk + (readOnly ? 0 : 1);
- hk = 31 * hk + (mandatory ? 0 : 1);
- hk = 31 * hk + onVersion;
- this.hashCode = hk;
+ return new NodeTypeImpl(nodeTypeDataManager.getNodeType(itemDefinitionData.getDeclaringNodeType()),
+ nodeTypeDataManager, nodeTypeManager, locationFactory, valueFactory);
}
- @Override
- public int hashCode()
+ /**
+ * {@inheritDoc}
+ */
+ public String getName()
{
- return hashCode;
+ String result = "";
+ try
+ {
+ result = locationFactory.createJCRName(itemDefinitionData.getName()).getAsString();
+ }
+ catch (RepositoryException e)
+ {
+ LOG.error(e.getLocalizedMessage(), e);
+ }
+ return result;
}
/**
* {@inheritDoc}
*/
- public String getName()
+ public InternalQName getQName()
{
- return name;
+ return itemDefinitionData.getName();
}
/**
* {@inheritDoc}
*/
- public boolean isAutoCreated()
+ public InternalQName getDeclaringNodeTypeQName()
{
- return autoCreate;
+ return itemDefinitionData.getDeclaringNodeType();
}
/**
@@ -93,15 +121,15 @@
*/
public int getOnParentVersion()
{
- return onVersion;
+ return itemDefinitionData.getOnParentVersion();
}
/**
* {@inheritDoc}
*/
- public boolean isProtected()
+ public boolean isAutoCreated()
{
- return readOnly;
+ return itemDefinitionData.isAutoCreated();
}
/**
@@ -109,15 +137,15 @@
*/
public boolean isMandatory()
{
- return mandatory;
+ return itemDefinitionData.isMandatory();
}
/**
* {@inheritDoc}
*/
- public NodeType getDeclaringNodeType()
+ public boolean isProtected()
{
- return declaringNodeType;
+ return itemDefinitionData.isProtected();
}
/**
@@ -125,6 +153,6 @@
*/
public boolean isResidualSet()
{
- return this.name.equals(Constants.JCR_ANY_NAME.getName());
+ return getName().equals(Constants.JCR_ANY_NAME.getName());
}
}
Modified: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/NodeDefinitionImpl.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/NodeDefinitionImpl.java 2009-10-02 15:41:14 UTC (rev 198)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/NodeDefinitionImpl.java 2009-10-04 09:34:54 UTC (rev 199)
@@ -18,77 +18,152 @@
*/
package org.exoplatform.services.jcr.impl.core.nodetype;
-import javax.jcr.nodetype.NodeDefinition;
+import org.exoplatform.services.jcr.core.nodetype.ExtendedNodeTypeManager;
+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.datamodel.InternalQName;
+import org.exoplatform.services.jcr.impl.core.LocationFactory;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.ValueFactory;
import javax.jcr.nodetype.NodeType;
/**
* Created by The eXo Platform SAS.
*
- * @author Gennady Azarenkov
- * @version $Id: NodeDefinitionImpl.java 11907 2008-03-13 15:36:21Z ksm $
+ * @author <a href="mailto:Sergey.Kabashnyuk at gmail.com">Sergey Kabashnyuk</a>
+ * @version $Id: $
*/
-
-public class NodeDefinitionImpl extends ItemDefinitionImpl implements NodeDefinition
+public class NodeDefinitionImpl extends ItemDefinitionImpl implements ExtendedNodeDefinition
{
- private final NodeType defaultNodeType;
+ /**
+ * Class logger.
+ */
+ private static final Log LOG = ExoLogger.getLogger(NodeDefinitionImpl.class);
- private final NodeType[] requiredNodeTypes;
+ private final NodeDefinitionData nodeDefinitionData;
- private final boolean multiple;
-
- public NodeDefinitionImpl(String name, NodeType declaringNodeType, NodeType[] requiredNodeTypes,
- NodeType defaultNodeType, boolean autoCreate, boolean mandatory, int onVersion, boolean readOnly, boolean multiple)
+ /**
+ * @param itemDefinitionData
+ * @param nodeTypeDataManager
+ * @param nodeTypeManager
+ * @param locationFactory
+ * @param valueFactory
+ */
+ public NodeDefinitionImpl(NodeDefinitionData nodeDefinitionData, NodeTypeDataManager nodeTypeDataManager,
+ ExtendedNodeTypeManager nodeTypeManager, LocationFactory locationFactory, ValueFactory valueFactory)
{
+ super(nodeDefinitionData, nodeTypeDataManager, nodeTypeManager, locationFactory, valueFactory);
+ this.nodeDefinitionData = nodeDefinitionData;
- super(name, declaringNodeType, autoCreate, onVersion, readOnly, mandatory);
+ }
- this.requiredNodeTypes = requiredNodeTypes;
- this.defaultNodeType = defaultNodeType;
- this.multiple = multiple;
+ /**
+ * @param itemDefinitionData
+ * @param nodeTypeDataManager
+ * @param locationFactory
+ * @param name
+ */
- int hk = 31 * this.hashCode + requiredNodeTypes.hashCode();
- if (defaultNodeType != null)
- hk = 31 * hk + defaultNodeType.hashCode();
- this.hashCode = 31 * hk + (multiple ? 0 : 1);
+ /**
+ * {@inheritDoc}
+ */
+ public boolean allowsSameNameSiblings()
+ {
+ return nodeDefinitionData.isAllowsSameNameSiblings();
}
/**
* {@inheritDoc}
*/
- public NodeType[] getRequiredPrimaryTypes()
+ public NodeType getDefaultPrimaryType()
{
+ if (nodeDefinitionData.getDefaultPrimaryType() == null)
+ return null;
+ return new NodeTypeImpl(nodeTypeDataManager.getNodeType(nodeDefinitionData.getDefaultPrimaryType()),
+ nodeTypeDataManager, nodeTypeManager, locationFactory, valueFactory);
+ }
- return requiredNodeTypes;
+ /**
+ * {@inheritDoc}
+ */
+ public String getDefaultPrimaryTypeName()
+ {
+ String result = null;
+ if (nodeDefinitionData.getDefaultPrimaryType() != null)
+ {
+ try
+ {
+ result = locationFactory.createJCRName(nodeDefinitionData.getDefaultPrimaryType()).getAsString();
+ }
+ catch (RepositoryException e)
+ {
+ LOG.error(e.getLocalizedMessage(), e);
+ }
+ }
+ return result;
}
/**
* {@inheritDoc}
*/
- public NodeType getDefaultPrimaryType()
+ public InternalQName getDefaultPrimaryTypeQName()
{
- return defaultNodeType;
+ return nodeDefinitionData.getDefaultPrimaryType();
}
/**
* {@inheritDoc}
*/
- public boolean allowsSameNameSiblings()
+ public String[] getRequiredPrimaryTypeNames()
{
- return multiple;
+ InternalQName[] requiredPrimaryTypes = nodeDefinitionData.getRequiredPrimaryTypes();
+ String[] result = new String[requiredPrimaryTypes.length];
+ try
+ {
+ for (int i = 0; i < requiredPrimaryTypes.length; i++)
+ {
+ result[i] = locationFactory.createJCRName(requiredPrimaryTypes[i]).getAsString();
+ }
+
+ }
+ catch (RepositoryException e)
+ {
+ LOG.error(e.getLocalizedMessage(), e);
+ }
+ return result;
}
/**
* {@inheritDoc}
*/
- public boolean equals(Object obj)
+
+ public InternalQName[] getRequiredPrimaryTypeQNames()
{
- if (obj == null)
- return false;
- if (!(obj instanceof NodeDefinitionImpl))
- return false;
- if (this.getName() == null)
- return ((NodeDefinitionImpl)obj).getName() == null;
- return this.getName().equals(((NodeDefinitionImpl)obj).getName());
+ return nodeDefinitionData.getRequiredPrimaryTypes();
}
+
+ /**
+ * {@inheritDoc}
+ */
+ public NodeType[] getRequiredPrimaryTypes()
+ {
+ InternalQName[] requiredPrimaryTypes = nodeDefinitionData.getRequiredPrimaryTypes();
+ NodeType[] result = new NodeType[requiredPrimaryTypes.length];
+ for (int i = 0; i < requiredPrimaryTypes.length; i++)
+ {
+ NodeTypeData ntData = nodeTypeDataManager.getNodeType(requiredPrimaryTypes[i]);
+ if (ntData == null)
+ {
+ LOG.error("NODE TYPE NOT FOUND " + requiredPrimaryTypes[i].getAsString());
+ }
+ else
+ result[i] = new NodeTypeImpl(ntData, nodeTypeDataManager, nodeTypeManager, locationFactory, valueFactory);
+ }
+ return result;
+ }
}
Modified: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/NodeTypeDataHierarchyHolder.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/NodeTypeDataHierarchyHolder.java 2009-10-02 15:41:14 UTC (rev 198)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/NodeTypeDataHierarchyHolder.java 2009-10-04 09:34:54 UTC (rev 199)
@@ -48,25 +48,35 @@
private final Map<InternalQName, NodeTypeHolder> nodeTypes;
- class NodeTypeHolder
+ public NodeTypeDataHierarchyHolder()
{
+ nodeTypes = new ConcurrentHashMap<InternalQName, NodeTypeHolder>();
+ }
- final NodeTypeData nodeType;
+ /**
+ * Helper counstructor for create copy method.
+ *
+ * @param nodeTypes
+ */
+ public NodeTypeDataHierarchyHolder(Map<InternalQName, NodeTypeHolder> nodeTypes)
+ {
+ this.nodeTypes = nodeTypes;
+ }
- final Set<InternalQName> superTypes;
-
- NodeTypeHolder(NodeTypeData nodeType, Set<InternalQName> superTypes)
+ /**
+ * @return
+ */
+ public List<NodeTypeData> getAllNodeTypes()
+ {
+ Collection<NodeTypeHolder> hs = nodeTypes.values();
+ List<NodeTypeData> nts = new ArrayList<NodeTypeData>(hs.size());
+ for (NodeTypeHolder nt : hs)
{
- this.nodeType = nodeType;
- this.superTypes = superTypes;
+ nts.add(nt.nodeType);
}
+ return nts;
}
- public NodeTypeDataHierarchyHolder()
- {
- nodeTypes = new ConcurrentHashMap<InternalQName, NodeTypeHolder>();
- }
-
/**
* Returns the <i>direct</i> subtypes of this node type in the node type
* inheritance hierarchy, that is, those which actually declared this node
@@ -91,30 +101,9 @@
}
/**
- * Returns all subtypes of this node type in the node type inheritance
- * hierarchy.
- *
* @param nodeTypeName
* @return
*/
- public Set<InternalQName> getSubtypes(final InternalQName nodeTypeName)
- {
- // TODO Speed up this method
- Set<InternalQName> resultSet = new HashSet<InternalQName>();
- for (InternalQName ntName : nodeTypes.keySet())
- {
- if (getSupertypes(ntName).contains(nodeTypeName))
- {
- resultSet.add(ntName);
- }
- }
- return resultSet;
- }
-
- /**
- * @param nodeTypeName
- * @return
- */
public NodeTypeData getNodeType(final InternalQName nodeTypeName)
{
if (nodeTypeName != null)
@@ -143,9 +132,30 @@
}
/**
+ * Returns all subtypes of this node type in the node type inheritance
+ * hierarchy.
+ *
* @param nodeTypeName
* @return
*/
+ public Set<InternalQName> getSubtypes(final InternalQName nodeTypeName)
+ {
+ // TODO Speed up this method
+ Set<InternalQName> resultSet = new HashSet<InternalQName>();
+ for (InternalQName ntName : nodeTypes.keySet())
+ {
+ if (getSupertypes(ntName).contains(nodeTypeName))
+ {
+ resultSet.add(ntName);
+ }
+ }
+ return resultSet;
+ }
+
+ /**
+ * @param nodeTypeName
+ * @return
+ */
public Set<InternalQName> getSupertypes(final InternalQName nodeTypeName)
{
if (nodeTypeName != null)
@@ -175,20 +185,6 @@
}
/**
- * @return
- */
- public List<NodeTypeData> getAllNodeTypes()
- {
- Collection<NodeTypeHolder> hs = nodeTypes.values();
- List<NodeTypeData> nts = new ArrayList<NodeTypeData>(hs.size());
- for (NodeTypeHolder nt : hs)
- {
- nts.add(nt.nodeType);
- }
- return nts;
- }
-
- /**
* @param testTypeName
* @param typesNames
* @return
@@ -255,4 +251,26 @@
}
}
+
+ /**
+ * @return copy of holder.
+ */
+ protected NodeTypeDataHierarchyHolder createCopy()
+ {
+ return new NodeTypeDataHierarchyHolder(new ConcurrentHashMap<InternalQName, NodeTypeHolder>(nodeTypes));
+ }
+
+ class NodeTypeHolder
+ {
+
+ final NodeTypeData nodeType;
+
+ final Set<InternalQName> superTypes;
+
+ NodeTypeHolder(NodeTypeData nodeType, Set<InternalQName> superTypes)
+ {
+ this.nodeType = nodeType;
+ this.superTypes = superTypes;
+ }
+ }
}
Modified: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/NodeTypeDataManagerImpl.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/NodeTypeDataManagerImpl.java 2009-10-02 15:41:14 UTC (rev 198)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/NodeTypeDataManagerImpl.java 2009-10-04 09:34:54 UTC (rev 199)
@@ -18,26 +18,15 @@
*/
package org.exoplatform.services.jcr.impl.core.nodetype;
-import org.apache.lucene.index.Term;
-import org.apache.lucene.search.BooleanQuery;
-import org.apache.lucene.search.Query;
-import org.apache.lucene.search.TermQuery;
-import org.apache.lucene.search.BooleanClause.Occur;
-import org.exoplatform.services.jcr.access.AccessControlEntry;
-import org.exoplatform.services.jcr.access.AccessControlList;
-import org.exoplatform.services.jcr.access.AccessControlPolicy;
import org.exoplatform.services.jcr.config.RepositoryEntry;
import org.exoplatform.services.jcr.core.nodetype.ExtendedNodeTypeManager;
import org.exoplatform.services.jcr.core.nodetype.ItemDefinitionData;
import org.exoplatform.services.jcr.core.nodetype.NodeDefinitionData;
-import org.exoplatform.services.jcr.core.nodetype.NodeDefinitionValue;
import org.exoplatform.services.jcr.core.nodetype.NodeTypeData;
import org.exoplatform.services.jcr.core.nodetype.NodeTypeDataManager;
import org.exoplatform.services.jcr.core.nodetype.NodeTypeValue;
-import org.exoplatform.services.jcr.core.nodetype.NodeTypeValuesList;
import org.exoplatform.services.jcr.core.nodetype.PropertyDefinitionData;
import org.exoplatform.services.jcr.core.nodetype.PropertyDefinitionDatas;
-import org.exoplatform.services.jcr.core.nodetype.PropertyDefinitionValue;
import org.exoplatform.services.jcr.dataflow.ItemDataConsumer;
import org.exoplatform.services.jcr.dataflow.ItemState;
import org.exoplatform.services.jcr.dataflow.PlainChangesLog;
@@ -45,33 +34,29 @@
import org.exoplatform.services.jcr.datamodel.InternalQName;
import org.exoplatform.services.jcr.datamodel.ItemData;
import org.exoplatform.services.jcr.datamodel.NodeData;
+import org.exoplatform.services.jcr.datamodel.PropertyData;
import org.exoplatform.services.jcr.datamodel.QPathEntry;
-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.registration.NodeDefinitionComparator;
+import org.exoplatform.services.jcr.impl.core.nodetype.registration.NodeTypeConverter;
+import org.exoplatform.services.jcr.impl.core.nodetype.registration.NodeTypeDataPersister;
+import org.exoplatform.services.jcr.impl.core.nodetype.registration.NodeTypeDataValidator;
import org.exoplatform.services.jcr.impl.core.nodetype.registration.PropertyDefinitionComparator;
+import org.exoplatform.services.jcr.impl.core.nodetype.registration.XmlNodeTypeDataPersister;
import org.exoplatform.services.jcr.impl.core.query.RepositoryIndexSearcherHolder;
-import org.exoplatform.services.jcr.impl.core.query.lucene.FieldNames;
-import org.exoplatform.services.jcr.impl.core.value.BaseValue;
import org.exoplatform.services.jcr.impl.core.value.ValueFactoryImpl;
import org.exoplatform.services.jcr.impl.dataflow.TransientNodeData;
import org.exoplatform.services.jcr.impl.dataflow.TransientPropertyData;
import org.exoplatform.services.jcr.impl.dataflow.TransientValueData;
-import org.exoplatform.services.jcr.impl.dataflow.version.VersionHistoryDataHelper;
-import org.exoplatform.services.jcr.util.IdGenerator;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
-import org.jibx.runtime.BindingDirectory;
-import org.jibx.runtime.IBindingFactory;
-import org.jibx.runtime.IUnmarshallingContext;
-import org.jibx.runtime.JiBXException;
+import org.picocontainer.Startable;
-import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
@@ -80,14 +65,9 @@
import java.util.Map;
import java.util.Set;
import java.util.WeakHashMap;
-import java.util.Map.Entry;
-import javax.jcr.InvalidItemStateException;
import javax.jcr.NamespaceRegistry;
-import javax.jcr.PathNotFoundException;
-import javax.jcr.PropertyType;
import javax.jcr.RepositoryException;
-import javax.jcr.ValueFormatException;
import javax.jcr.nodetype.ConstraintViolationException;
import javax.jcr.nodetype.NoSuchNodeTypeException;
@@ -100,59 +80,55 @@
* @version $Id: NodeTypeDataManagerImpl.java 111 2008-11-11 11:11:11Z
* pnedonosko $
*/
-public class NodeTypeDataManagerImpl implements NodeTypeDataManager
+public class NodeTypeDataManagerImpl implements NodeTypeDataManager, Startable
{
- protected static final Log LOG = ExoLogger.getLogger("jcr.NodeTypeDataManagerImpl");
-
private static final String NODETYPES_FILE = "nodetypes.xml";
- protected final NamespaceRegistry namespaceRegistry;
+ private final Log log = ExoLogger.getLogger(NodeTypeDataManagerImpl.class.getName());
- protected final NodeTypeDataPersister persister;
+ protected final String accessControlPolicy;
- protected final LocationFactory locationFactory;
+ protected final ItemDataConsumer dataManager;
- protected final String accessControlPolicy;
+ protected final RepositoryIndexSearcherHolder indexSearcherHolder;
- protected final NodeTypeDataHierarchyHolder hierarchy;
+ protected final LocationFactory locationFactory;
- protected final ItemDefinitionDataHolder defsHolder;
+ protected final NamespaceRegistry namespaceRegistry;
private final Set<InternalQName> buildInNodeTypesNames;
+ protected final NodeTypeRepository nodeTypeRepository;
+
/**
* Listeners (soft references)
*/
private final Map<NodeTypeManagerListener, NodeTypeManagerListener> listeners;
- // protected HashSet<QueryHandler> queryHandlers;
-
private final ValueFactoryImpl valueFactory;
- protected final RepositoryIndexSearcherHolder indexSearcherHolder;
+ private boolean started = false;
- public NodeTypeDataManagerImpl(RepositoryEntry config, LocationFactory locationFactory,
- NamespaceRegistry namespaceRegistry, NodeTypeDataPersister persister,
- RepositoryIndexSearcherHolder indexSearcherHolder) throws RepositoryException
+ 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.persister = persister;
-
this.locationFactory = locationFactory;
+ this.dataManager = dataManager;
this.indexSearcherHolder = indexSearcherHolder;
+
this.valueFactory = new ValueFactoryImpl(locationFactory);
this.accessControlPolicy = config.getAccessControl();
- this.hierarchy = new NodeTypeDataHierarchyHolder();
-
- this.defsHolder = new ItemDefinitionDataHolder();
+ this.nodeTypeRepository = new InmemoryNodeTypeRepository(persister);
+ //this.nodeTypeRepository = new PersistedNodeTypeRepository(persister);
this.listeners = Collections.synchronizedMap(new WeakHashMap<NodeTypeManagerListener, NodeTypeManagerListener>());
this.buildInNodeTypesNames = new HashSet<InternalQName>();
initDefault();
- //this.queryHandlers = new HashSet<QueryHandler>();
}
/**
@@ -162,26 +138,26 @@
* @param persister
* @throws RepositoryException
*/
- public NodeTypeDataManagerImpl(String accessControlPolicy, LocationFactory locationFactory,
- NamespaceRegistry namespaceRegistry, NodeTypeDataPersister persister,
- RepositoryIndexSearcherHolder indexSearcherHolder) throws RepositoryException
+ 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
{
this.namespaceRegistry = namespaceRegistry;
- this.persister = persister;
+ //this.persister = persister;
this.locationFactory = locationFactory;
+ this.dataManager = dataManager;
this.indexSearcherHolder = indexSearcherHolder;
+
this.valueFactory = new ValueFactoryImpl(locationFactory);
this.accessControlPolicy = accessControlPolicy;
- this.hierarchy = new NodeTypeDataHierarchyHolder();
-
- this.defsHolder = new ItemDefinitionDataHolder();
+ this.nodeTypeRepository = nodeTypeRepository;
this.listeners = Collections.synchronizedMap(new WeakHashMap<NodeTypeManagerListener, NodeTypeManagerListener>());
this.buildInNodeTypesNames = new HashSet<InternalQName>();
- //this.queryHandlers = new HashSet<QueryHandler>();
}
/**
@@ -190,283 +166,212 @@
* @param listener the new listener to be informed on (un)registration of node
* types
*/
- public void addListener(NodeTypeManagerListener listener)
+ public void addListener(final NodeTypeManagerListener listener)
{
- if (!listeners.containsKey(listener))
+ if (!this.listeners.containsKey(listener))
{
- listeners.put(listener, listener);
+ this.listeners.put(listener, listener);
}
}
- //
- // public void addQueryHandler(QueryHandler queryHandler)
- // {
- // queryHandlers.add(queryHandler);
- // }
-
/**
* {@inheritDoc}
+ * @throws RepositoryException
*/
- public NodeDefinitionData findChildNodeDefinition(InternalQName nodeName, InternalQName... nodeTypeNames)
- {
+ public NodeDefinitionData[] getAllChildNodeDefinitions(final InternalQName... nodeTypeNames)
- NodeDefinitionData ndResidual = defsHolder.getDefaultChildNodeDefinition(nodeName, nodeTypeNames);
-
- if (ndResidual == null && !Constants.JCR_ANY_NAME.equals(nodeName))
- ndResidual = findChildNodeDefinition(Constants.JCR_ANY_NAME, nodeTypeNames);
-
- return ndResidual;
-
- }
-
- /**
- * {@inheritDoc}
- */
- public NodeDefinitionData findChildNodeDefinition(InternalQName nodeName, InternalQName primaryNodeType,
- InternalQName[] mixinTypes)
{
+ final Collection<NodeDefinitionData> defs = new HashSet<NodeDefinitionData>();
- if (mixinTypes != null)
+ for (final InternalQName ntname : nodeTypeNames)
{
- InternalQName[] nts = new InternalQName[mixinTypes.length + 1];
- nts[0] = primaryNodeType;
- for (int i = 0; i < mixinTypes.length; i++)
+ for (final NodeDefinitionData cnd : this.nodeTypeRepository.getNodeType(ntname)
+ .getDeclaredChildNodeDefinitions())
{
- nts[i + 1] = mixinTypes[i];
+ defs.add(cnd);
}
- return findChildNodeDefinition(nodeName, nts);
+
+ for (final InternalQName suname : this.nodeTypeRepository.getSupertypes(ntname))
+ {
+ for (final NodeDefinitionData cnd : this.nodeTypeRepository.getNodeType(suname)
+ .getDeclaredChildNodeDefinitions())
+ {
+ defs.add(cnd);
+ }
+ }
}
- return findChildNodeDefinition(nodeName, primaryNodeType);
+ return defs.toArray(new NodeDefinitionData[defs.size()]);
}
/**
* {@inheritDoc}
+ * @throws RepositoryException
*/
- public NodeTypeData findNodeType(InternalQName typeName)
+ public List<NodeTypeData> getAllNodeTypes()
{
- return hierarchy.getNodeType(typeName);
+ try
+ {
+ return this.nodeTypeRepository.getAllNodeTypes();
+ }
+ catch (RepositoryException e)
+ {
+ log.error(e.getLocalizedMessage());
+ }
+ return new ArrayList<NodeTypeData>();
+
}
/**
* {@inheritDoc}
+ * @throws RepositoryException
*/
- public PropertyDefinitionDatas findPropertyDefinitions(InternalQName propertyName, InternalQName primaryNodeType,
- InternalQName[] mixinTypes)
+ public PropertyDefinitionData[] getAllPropertyDefinitions(final InternalQName... nodeTypeNames)
+
{
+ final Collection<PropertyDefinitionData> defs = new HashSet<PropertyDefinitionData>();
- if (mixinTypes != null)
+ for (final InternalQName ntname : nodeTypeNames)
{
- InternalQName[] nts = new InternalQName[mixinTypes.length + 1];
- nts[0] = primaryNodeType;
- for (int i = 0; i < mixinTypes.length; i++)
+ for (final PropertyDefinitionData pd : this.nodeTypeRepository.getNodeType(ntname)
+ .getDeclaredPropertyDefinitions())
{
- nts[i + 1] = mixinTypes[i];
+ defs.add(pd);
}
- return getPropertyDefinitions(propertyName, nts);
+
+ for (final InternalQName suname : this.nodeTypeRepository.getSupertypes(ntname))
+ {
+ for (final PropertyDefinitionData pd : this.nodeTypeRepository.getNodeType(suname)
+ .getDeclaredPropertyDefinitions())
+ {
+ defs.add(pd);
+ }
+ }
}
- return getPropertyDefinitions(propertyName, primaryNodeType);
+ return defs.toArray(new PropertyDefinitionData[defs.size()]);
}
/**
- * @return the accessControlPolicy
- */
- public String getAccessControlPolicy()
- {
- return accessControlPolicy;
- }
-
- /**
* {@inheritDoc}
+ * @throws RepositoryException
*/
- public NodeDefinitionData[] getAllChildNodeDefinitions(InternalQName... nodeTypeNames)
+ public NodeDefinitionData getChildNodeDefinition(final InternalQName nodeName, final InternalQName... nodeTypeNames)
+ throws RepositoryException
{
- Collection<NodeDefinitionData> defs = new HashSet<NodeDefinitionData>();
- for (InternalQName ntname : nodeTypeNames)
- {
- for (NodeDefinitionData cnd : hierarchy.getNodeType(ntname).getDeclaredChildNodeDefinitions())
- defs.add(cnd);
+ NodeDefinitionData ndResidual = this.nodeTypeRepository.getDefaultChildNodeDefinition(nodeName, nodeTypeNames);
- for (InternalQName suname : hierarchy.getSupertypes(ntname))
- {
- for (NodeDefinitionData cnd : hierarchy.getNodeType(suname).getDeclaredChildNodeDefinitions())
- defs.add(cnd);
- }
+ if (ndResidual == null && !Constants.JCR_ANY_NAME.equals(nodeName))
+ {
+ ndResidual = getChildNodeDefinition(Constants.JCR_ANY_NAME, nodeTypeNames);
}
- return defs.toArray(new NodeDefinitionData[defs.size()]);
- }
+ return ndResidual;
- /**
- * {@inheritDoc}
- */
- public List<NodeTypeData> getAllNodeTypes()
- {
- return hierarchy.getAllNodeTypes();
}
/**
* {@inheritDoc}
+ * @throws RepositoryException
*/
- public PropertyDefinitionData[] getAllPropertyDefinitions(InternalQName... nodeTypeNames)
+ public NodeDefinitionData getChildNodeDefinition(final InternalQName nodeName, final InternalQName primaryNodeType,
+ final InternalQName[] mixinTypes) throws RepositoryException
{
- Collection<PropertyDefinitionData> defs = new HashSet<PropertyDefinitionData>();
- for (InternalQName ntname : nodeTypeNames)
+ if (mixinTypes != null)
{
- for (PropertyDefinitionData pd : hierarchy.getNodeType(ntname).getDeclaredPropertyDefinitions())
- defs.add(pd);
-
- for (InternalQName suname : hierarchy.getSupertypes(ntname))
+ final InternalQName[] nts = new InternalQName[mixinTypes.length + 1];
+ nts[0] = primaryNodeType;
+ for (int i = 0; i < mixinTypes.length; i++)
{
- for (PropertyDefinitionData pd : hierarchy.getNodeType(suname).getDeclaredPropertyDefinitions())
- defs.add(pd);
+ nts[i + 1] = mixinTypes[i];
}
+ return getChildNodeDefinition(nodeName, nts);
}
- return defs.toArray(new PropertyDefinitionData[defs.size()]);
+ return getChildNodeDefinition(nodeName, primaryNodeType);
}
- // impl
-
/**
* {@inheritDoc}
+ * @throws RepositoryException
*/
- public NodeDefinitionData getChildNodeDefinition(InternalQName nodeName, InternalQName nodeTypeName,
- InternalQName parentTypeName)
- {
- NodeDefinitionData def = defsHolder.getChildNodeDefinition(parentTypeName, nodeName, nodeTypeName);
- // residual
- if (def == null)
- def = defsHolder.getChildNodeDefinition(parentTypeName, Constants.JCR_ANY_NAME, nodeTypeName);
- return def;
- }
-
- /**
- * {@inheritDoc}
- */
public Set<InternalQName> getDeclaredSubtypes(final InternalQName nodeTypeName)
{
- return hierarchy.getDeclaredSubtypes(nodeTypeName);
+ return this.nodeTypeRepository.getDeclaredSubtypes(nodeTypeName);
}
- public List<ItemDefinitionData> getManadatoryItemDefs(InternalQName primaryNodeType, InternalQName[] mixinTypes)
+ public List<ItemDefinitionData> getManadatoryItemDefs(final InternalQName primaryNodeType,
+ final InternalQName[] mixinTypes) throws RepositoryException
{
- Collection<ItemDefinitionData> mandatoryDefs = new HashSet<ItemDefinitionData>();
+ final Collection<ItemDefinitionData> mandatoryDefs = new HashSet<ItemDefinitionData>();
// primary type properties
ItemDefinitionData[] itemDefs = getAllPropertyDefinitions(new InternalQName[]{primaryNodeType});
- for (int i = 0; i < itemDefs.length; i++)
+ for (final ItemDefinitionData itemDef : itemDefs)
{
- if (itemDefs[i].isMandatory())
- mandatoryDefs.add(itemDefs[i]);
+ if (itemDef.isMandatory())
+ {
+ mandatoryDefs.add(itemDef);
+ }
}
// primary type nodes
itemDefs = getAllChildNodeDefinitions(new InternalQName[]{primaryNodeType});
- for (int i = 0; i < itemDefs.length; i++)
+ for (final ItemDefinitionData itemDef : itemDefs)
{
- if (itemDefs[i].isMandatory())
- mandatoryDefs.add(itemDefs[i]);
+ if (itemDef.isMandatory())
+ {
+ mandatoryDefs.add(itemDef);
+ }
}
// mixin properties
itemDefs = getAllPropertyDefinitions(mixinTypes);
- for (int i = 0; i < itemDefs.length; i++)
+ for (final ItemDefinitionData itemDef : itemDefs)
{
- if (itemDefs[i].isMandatory())
- mandatoryDefs.add(itemDefs[i]);
+ if (itemDef.isMandatory())
+ {
+ mandatoryDefs.add(itemDef);
+ }
}
// mixin nodes
itemDefs = getAllChildNodeDefinitions(mixinTypes);
- for (int i = 0; i < itemDefs.length; i++)
+ for (final ItemDefinitionData itemDef : itemDefs)
{
- if (itemDefs[i].isMandatory())
- mandatoryDefs.add(itemDefs[i]);
+ if (itemDef.isMandatory())
+ {
+ mandatoryDefs.add(itemDef);
+ }
}
return new ArrayList<ItemDefinitionData>(mandatoryDefs);
}
/**
- * Return
- *
- * @param nodeType
- * @return
- * @throws RepositoryException
- * @throws IOException
+ * {@inheritDoc}
+ * @throws RepositoryException
*/
- public Set<String> getNodes(InternalQName nodeType) throws RepositoryException
+ public NodeTypeData getNodeType(final InternalQName typeName)
{
- return indexSearcherHolder.getNodesByNodeType(nodeType);
+ return this.nodeTypeRepository.getNodeType(typeName);
}
/**
- * Return
- *
- * @param nodeType
- * @return
- * @throws RepositoryException
- * @throws IOException
- */
- public Set<String> getNodes(InternalQName nodeType, InternalQName[] includeProperties,
- InternalQName[] excludeProperties) throws RepositoryException
- {
- return new HashSet<String>();
-
- // Query query = getQuery(nodeType);
- // if (includeProperties.length > 0)
- // {
- // BooleanQuery tmp = new BooleanQuery();
- // for (int i = 0; i < includeProperties.length; i++)
- // {
- //
- // String field = locationFactory.createJCRName(includeProperties[i]).getAsString();
- // tmp.add(new TermQuery(new Term(FieldNames.PROPERTIES_SET, field)), Occur.MUST);
- // }
- // tmp.add(query, Occur.MUST);
- // query = tmp;
- // }
- //
- // if (excludeProperties.length > 0)
- // {
- // BooleanQuery tmp = new BooleanQuery();
- // for (int i = 0; i < excludeProperties.length; i++)
- // {
- //
- // String field = locationFactory.createJCRName(excludeProperties[i]).getAsString();
- // tmp.add(new TermQuery(new Term(FieldNames.PROPERTIES_SET, field)), Occur.MUST_NOT);
- // }
- // tmp.add(query, Occur.MUST);
- // query = tmp;
- // }
- //
- // Iterator<QueryHandler> it = queryHandlers.iterator();
- // Set<String> result = new HashSet<String>();
- //
- // try
- // {
- // indexSearcherHolder.getNodesByNodeType()
- // }
- // catch (IOException e)
- // {
- // throw new RepositoryException(e.getLocalizedMessage(), e);
- // }
- // return result;
- }
-
- /**
* {@inheritDoc}
+ * @throws RepositoryException
*/
- public PropertyDefinitionDatas getPropertyDefinitions(InternalQName propertyName, InternalQName... nodeTypeNames)
+ public PropertyDefinitionDatas getPropertyDefinitions(final InternalQName propertyName,
+ final InternalQName... nodeTypeNames) throws RepositoryException
{
- PropertyDefinitionDatas propertyDefinitions = defsHolder.getPropertyDefinitions(propertyName, nodeTypeNames);
+ PropertyDefinitionDatas propertyDefinitions =
+ this.nodeTypeRepository.getPropertyDefinitions(propertyName, nodeTypeNames);
// Try super
if (propertyDefinitions == null)
{
for (int i = 0; i < nodeTypeNames.length && propertyDefinitions == null; i++)
{
- InternalQName[] supers = hierarchy.getNodeType(nodeTypeNames[i]).getDeclaredSupertypeNames();
+ final InternalQName[] supers =
+ this.nodeTypeRepository.getNodeType(nodeTypeNames[i]).getDeclaredSupertypeNames();
propertyDefinitions = getPropertyDefinitions(propertyName, supers);
}
@@ -481,56 +386,81 @@
return propertyDefinitions;
}
- // // TODO make me private
- // public Set<QueryHandler> getQueryHandlers()
- // {
- // return queryHandlers;
- // }
+ /**
+ * {@inheritDoc}
+ * @throws RepositoryException
+ */
+ public PropertyDefinitionDatas getPropertyDefinitions(final InternalQName propertyName,
+ final InternalQName primaryNodeType, final InternalQName[] mixinTypes) throws RepositoryException
+ {
+ if (mixinTypes != null)
+ {
+ final InternalQName[] nts = new InternalQName[mixinTypes.length + 1];
+ nts[0] = primaryNodeType;
+ for (int i = 0; i < mixinTypes.length; i++)
+ {
+ nts[i + 1] = mixinTypes[i];
+ }
+ return getPropertyDefinitions(propertyName, nts);
+ }
+
+ return getPropertyDefinitions(propertyName, primaryNodeType);
+ }
+
/**
* @param nodeTypeName
* @return
+ * @throws RepositoryException
*/
public Set<InternalQName> getSubtypes(final InternalQName nodeTypeName)
{
- return hierarchy.getSubtypes(nodeTypeName);
+ return this.nodeTypeRepository.getSubtypes(nodeTypeName);
}
public Set<InternalQName> getSupertypes(final InternalQName nodeTypeName)
{
- return hierarchy.getSupertypes(nodeTypeName);
+ return this.nodeTypeRepository.getSupertypes(nodeTypeName);
}
- public boolean isChildNodePrimaryTypeAllowed(InternalQName childNodeTypeName, InternalQName parentNodeType,
- InternalQName[] parentMixinNames)
+ public boolean isChildNodePrimaryTypeAllowed(final InternalQName childNodeTypeName,
+ final InternalQName parentNodeType, final InternalQName[] parentMixinNames) throws RepositoryException
{
// NodeTypeData childDef = findNodeType(childNodeTypeName);
- Set<InternalQName> testSuperTypesNames = hierarchy.getSupertypes(childNodeTypeName);
+ final Set<InternalQName> testSuperTypesNames = this.nodeTypeRepository.getSupertypes(childNodeTypeName);
NodeDefinitionData[] allChildNodeDefinitions = getAllChildNodeDefinitions(parentNodeType);
- for (NodeDefinitionData cnd : allChildNodeDefinitions)
+ for (final NodeDefinitionData cnd : allChildNodeDefinitions)
{
- for (InternalQName req : cnd.getRequiredPrimaryTypes())
+ for (final InternalQName req : cnd.getRequiredPrimaryTypes())
{
if (childNodeTypeName.equals(req))
+ {
return true;
- for (InternalQName superName : testSuperTypesNames)
+ }
+ for (final InternalQName superName : testSuperTypesNames)
{
if (superName.equals(req))
+ {
return true;
+ }
}
}
}
allChildNodeDefinitions = getAllChildNodeDefinitions(parentMixinNames);
- for (NodeDefinitionData cnd : allChildNodeDefinitions)
+ for (final NodeDefinitionData cnd : allChildNodeDefinitions)
{
- for (InternalQName req : cnd.getRequiredPrimaryTypes())
+ for (final InternalQName req : cnd.getRequiredPrimaryTypes())
{
if (childNodeTypeName.equals(req))
+ {
return true;
- for (InternalQName superName : testSuperTypesNames)
+ }
+ for (final InternalQName superName : testSuperTypesNames)
{
if (superName.equals(req))
+ {
return true;
+ }
}
}
}
@@ -540,32 +470,41 @@
/**
* {@inheritDoc}
+ * @throws RepositoryException
*/
public boolean isNodeType(final InternalQName testTypeName, final InternalQName... typesNames)
+
{
- return hierarchy.isNodeType(testTypeName, typesNames);
+ return this.nodeTypeRepository.isNodeType(testTypeName, typesNames);
}
/**
* {@inheritDoc}
+ * @throws RepositoryException
*/
public boolean isNodeType(final InternalQName testTypeName, final InternalQName primaryType,
final InternalQName[] mixinTypes)
{
- if (hierarchy.isNodeType(testTypeName, primaryType))
+ if (this.nodeTypeRepository.isNodeType(testTypeName, primaryType))
+ {
return true;
+ }
- if (hierarchy.isNodeType(testTypeName, mixinTypes))
+ if (this.nodeTypeRepository.isNodeType(testTypeName, mixinTypes))
+ {
return true;
+ }
return false;
}
/**
* {@inheritDoc}
+ * @throws RepositoryException
*/
public boolean isOrderableChildNodesSupported(final InternalQName primaryType, final InternalQName[] mixinTypes)
+ throws RepositoryException
{
final int nlen = mixinTypes != null ? mixinTypes.length : 0;
@@ -573,23 +512,31 @@
{
InternalQName name;
if (i < 0)
+ {
name = primaryType;
+ }
else
+ {
name = mixinTypes[i];
+ }
- NodeTypeData nt = hierarchy.getNodeType(name);
+ final NodeTypeData nt = this.nodeTypeRepository.getNodeType(name);
if (nt != null)
{
if (nt.hasOrderableChildNodes())
+ {
return true;
+ }
- Set<InternalQName> supers = hierarchy.getSupertypes(nt.getName());
- for (InternalQName suName : supers)
+ final Set<InternalQName> supers = this.nodeTypeRepository.getSupertypes(nt.getName());
+ for (final InternalQName suName : supers)
{
- NodeTypeData su = hierarchy.getNodeType(suName);
+ final NodeTypeData su = this.nodeTypeRepository.getNodeType(suName);
if (su != null && su.hasOrderableChildNodes())
+ {
return true;
+ }
}
}
}
@@ -597,174 +544,57 @@
return false;
}
- public PlainChangesLog makeAutoCreatedItems(NodeData parent, InternalQName nodeTypeName,
- ItemDataConsumer dataManager, String owner) throws RepositoryException
+ /**
+ * {@inheritDoc}
+ */
+ public List<NodeTypeData> registerNodeTypes(final InputStream is, final int alreadyExistsBehaviour,
+ final String contentType) throws RepositoryException
{
- PlainChangesLogImpl changes = new PlainChangesLogImpl();
- NodeTypeData type = findNodeType(nodeTypeName);
- changes.addAll(makeAutoCreatedProperties(parent, nodeTypeName, getAllPropertyDefinitions(nodeTypeName),
- dataManager, owner).getAllStates());
- changes.addAll(makeAutoCreatedNodes(parent, nodeTypeName, getAllChildNodeDefinitions(nodeTypeName), dataManager,
- owner).getAllStates());
-
- // Add autocreated child nodes
-
- // versionable
- if (isNodeType(Constants.MIX_VERSIONABLE, new InternalQName[]{type.getName()}))
+ final NodeTypeConverter nodeTypeConverter = new NodeTypeConverter(this.locationFactory, this.accessControlPolicy);
+ final NodeTypeDataValidator nodeTypeDataValidator = new NodeTypeDataValidator(this.nodeTypeRepository);
+ NodeTypeDataPersister serializer = null;
+ if (contentType.equalsIgnoreCase(TEXT_XML))
{
-
- // using VH helper as for one new VH, all changes in changes log
- makeMixVesionableChanges(parent, dataManager, changes);
+ serializer = new XmlNodeTypeDataPersister(nodeTypeConverter, is);
}
- return changes;
- }
-
- public PlainChangesLog makeAutoCreatedNodes(NodeData parent, InternalQName typeName, NodeDefinitionData[] nodeDefs,
- ItemDataConsumer dataManager, String owner) throws RepositoryException
- {
- PlainChangesLogImpl changes = new PlainChangesLogImpl();
- Set<InternalQName> addedNodes = new HashSet<InternalQName>();
- for (NodeDefinitionData ndef : nodeDefs)
+ else if (contentType.equalsIgnoreCase(TEXT_X_JCR_CND))
{
- if (ndef.isAutoCreated())
- {
- ItemData pdata = dataManager.getItemData(parent, new QPathEntry(ndef.getName(), 0));
- if ((pdata == null && !addedNodes.contains(ndef.getName())) || (pdata != null && !pdata.isNode()))
- {
-
- TransientNodeData childNodeData =
- TransientNodeData.createNodeData(parent, ndef.getName(), ndef.getDefaultPrimaryType(), IdGenerator
- .generate());
- changes.add(ItemState.createAddedState(childNodeData, false));
- changes.addAll(makeAutoCreatedItems(childNodeData, childNodeData.getPrimaryTypeName(), dataManager,
- owner).getAllStates());
- addedNodes.add(ndef.getName());
- }
- else
- {
- if (LOG.isDebugEnabled())
- {
- LOG.debug("Skipping existed node " + ndef.getName() + " in " + parent.getQPath().getAsString()
- + " during the automatic creation of items for " + typeName.getAsString()
- + " nodetype or mixin type");
- }
- }
- }
+ throw new RepositoryException("Unsupported content type:" + contentType);
}
- return changes;
-
- }
-
- public PlainChangesLog makeAutoCreatedProperties(NodeData parent, InternalQName typeName,
- PropertyDefinitionData[] propDefs, ItemDataConsumer dataManager, String owner) throws RepositoryException
- {
- PlainChangesLogImpl changes = new PlainChangesLogImpl();
-
- Set<InternalQName> addedProperties = new HashSet<InternalQName>();
-
- // Add autocreated child properties
-
- for (PropertyDefinitionData pdef : propDefs)
+ else
{
- // if (propDefs[i] == null) // TODO it is possible for not mandatory
- // propDef
- // continue;
-
- if (pdef.isAutoCreated())
- {
-
- ItemData pdata = dataManager.getItemData(parent, new QPathEntry(pdef.getName(), 0));
- if ((pdata == null && !addedProperties.contains(pdef.getName())) || (pdata != null && pdata.isNode()))
- {
-
- List<ValueData> listAutoCreateValue = autoCreatedValue(parent, typeName, pdef, owner);
-
- if (listAutoCreateValue != null)
- {
- TransientPropertyData propertyData =
- TransientPropertyData.createPropertyData(parent, pdef.getName(), pdef.getRequiredType(), pdef
- .isMultiple(), listAutoCreateValue);
- changes.add(ItemState.createAddedState(propertyData));
- addedProperties.add(pdef.getName());
- }
- }
- else
- {
- // TODO if autocreated property exists it's has wrong data (e.g. ACL)
- // - throw an exception
- if (LOG.isDebugEnabled())
- {
- LOG.debug("Skipping existed property " + pdef.getName() + " in " + parent.getQPath().getAsString()
- + " during the automatic creation of items for " + typeName.getAsString()
- + " nodetype or mixin type");
- }
- }
- }
+ throw new RepositoryException("Unsupported content type:" + contentType);
}
- return changes;
- }
+ final List<NodeTypeData> nodeTypes = serializer.getAllNodeTypes();
- /**
- * {@inheritDoc}
- */
- public List<NodeTypeData> registerNodeTypes(InputStream xml, int alreadyExistsBehaviour) throws RepositoryException
- {
+ // validate
+ nodeTypeDataValidator.validateNodeType(nodeTypes);
- try
- {
-
- IBindingFactory factory = BindingDirectory.getFactory(NodeTypeValuesList.class);
- IUnmarshallingContext uctx = factory.createUnmarshallingContext();
- NodeTypeValuesList nodeTypeValuesList = (NodeTypeValuesList)uctx.unmarshalDocument(xml, null);
- List ntvList = nodeTypeValuesList.getNodeTypeValuesList();
-
- long start = System.currentTimeMillis();
- List<NodeTypeValue> nts = new ArrayList<NodeTypeValue>();
- for (int i = 0; i < ntvList.size(); i++)
- {
- if (ntvList.get(i) != null)
- {
- NodeTypeValue nodeTypeValue = (NodeTypeValue)ntvList.get(i);
- nts.add(nodeTypeValue);
- }
- else
- {
- // Hm! Smth is wrong in xml document
- LOG.error("Empty nodeTypeValue in xml document, index: " + i + ", skiping...");
- }
- }
- if (LOG.isDebugEnabled())
- LOG.debug("Nodetypes registered from xml definitions (count: " + ntvList.size() + "). "
- + (System.currentTimeMillis() - start) + " ms.");
-
- return registerNodeTypes(nts, alreadyExistsBehaviour);
-
- }
- catch (JiBXException e)
- {
- throw new RepositoryException("Error in config initialization " + e, e);
- }
+ //registerNodeType(nodeTypes, alreadyExistsBehaviour);
+ nodeTypeRepository.registerNodeType(nodeTypes, this, accessControlPolicy, alreadyExistsBehaviour);
+ return nodeTypes;
}
/**
* {@inheritDoc}
*/
- public List<NodeTypeData> registerNodeTypes(List<NodeTypeValue> ntvalues, int alreadyExistsBehaviour)
+ public List<NodeTypeData> registerNodeTypes(final List<NodeTypeValue> ntvalues, final int alreadyExistsBehaviour)
throws RepositoryException
{
- PlainChangesLog changesLog = new PlainChangesLogImpl();
+ 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);
- Map<InternalQName, NodeTypeData> nodeTypeDataList = parseNodeTypes(ntvalues);
+ // validate
+ nodeTypeDataValidator.validateNodeType(nodeTypes);
- for (NodeTypeData nodeTypeData : nodeTypeDataList.values())
- {
- changesLog.addAll(registerNodeType(nodeTypeData, alreadyExistsBehaviour, nodeTypeDataList).getAllStates());
- }
+ //registerNodeType(nodeTypes, alreadyExistsBehaviour);
+ nodeTypeRepository.registerNodeType(nodeTypes, this, accessControlPolicy, alreadyExistsBehaviour);
- persister.saveChanges(changesLog);
- return new ArrayList<NodeTypeData>(nodeTypeDataList.values());
+ return nodeTypes;
}
/**
@@ -772,780 +602,270 @@
*
* @param listener an existing listener
*/
- public void removeListener(NodeTypeManagerListener listener)
+ public void removeListener(final NodeTypeManagerListener listener)
{
- listeners.remove(listener);
+ this.listeners.remove(listener);
}
/**
- * Unregisters the specified node type. In order for a node type to be
- * successfully unregistered it must meet the following conditions:
- * <ol>
- * <li>the node type must obviously be registered.</li>
- * <li>a built-in node type can not be unregistered.</li>
- * <li>the node type must not have dependents, i.e. other node types that are
- * referencing it.</li>
- * <li>the node type must not be currently used by any workspace.</li>
- * </ol>
- *
- * @param ntName name of the node type to be unregistered
- * @throws NoSuchNodeTypeException if <code>ntName</code> does not denote a
- * registered node type.
- * @throws RepositoryException
- * @throws RepositoryException if another error occurs.
- * @see #unregisterNodeTypes(Collection)
+ * {@inheritDoc}
*/
- public void unregisterNodeType(InternalQName nodeTypeName) throws RepositoryException
+ public PlainChangesLog setPrimaryType(final NodeData nodeData, final InternalQName nodeTypeName)
+ throws RepositoryException
{
+ final PlainChangesLog changesLog = new PlainChangesLogImpl();
- NodeTypeData nodeType = hierarchy.getNodeType(nodeTypeName);
- if (nodeType == null)
- throw new NoSuchNodeTypeException(nodeTypeName.getAsString());
- // check build in
- if (buildInNodeTypesNames.contains(nodeTypeName))
- throw new RepositoryException(nodeTypeName.toString() + ": can't unregister built-in node type.");
- // check dependencies
- Set<InternalQName> descendantNt = hierarchy.getSubtypes(nodeTypeName);
- if (descendantNt.size() > 0)
+ final NodeTypeData ancestorDefinition = getNodeType(nodeData.getPrimaryTypeName());
+ final NodeTypeData recipientDefinition = getNodeType(nodeTypeName);
+
+ InternalQName[] ancestorAllNodeTypeNames = null;
+ if (nodeData.getMixinTypeNames() == null || nodeData.getMixinTypeNames().length == 0)
{
- String message =
- "Can not remove " + nodeTypeName.getAsString()
- + "nodetype, because the following node types depend on it: ";
- for (InternalQName internalQName : descendantNt)
- {
- message += internalQName.getAsString() + " ";
- }
- throw new RepositoryException(message);
+ ancestorAllNodeTypeNames = new InternalQName[]{nodeData.getPrimaryTypeName()};
}
- Set<String> nodes = getNodes(nodeTypeName);
- if (nodes.size() > 0)
+ else
{
- String message =
- "Can not remove " + nodeTypeName.getAsString()
- + " nodetype, because the following node types is used in nodes with uuid: ";
- for (String uuids : nodes)
- {
- message += uuids + " ";
- }
- throw new RepositoryException(message);
-
+ ancestorAllNodeTypeNames = new InternalQName[nodeData.getMixinTypeNames().length + 1];
+ ancestorAllNodeTypeNames[0] = nodeData.getPrimaryTypeName();
+ System.arraycopy(nodeData.getMixinTypeNames(), 0, ancestorAllNodeTypeNames, 1,
+ nodeData.getMixinTypeNames().length);
}
- internalUnregister(nodeTypeName, nodeType);
- }
-
- protected List<ValueData> autoCreatedValue(NodeData parent, InternalQName typeName, PropertyDefinitionData def,
- String owner) throws RepositoryException
- {
- NodeTypeDataManager typeDataManager = this;
- List<ValueData> vals = new ArrayList<ValueData>();
-
- if (typeDataManager.isNodeType(Constants.NT_BASE, new InternalQName[]{typeName})
- && def.getName().equals(Constants.JCR_PRIMARYTYPE))
+ InternalQName[] recipienAllNodeTypeNames = null;
+ if (nodeData.getMixinTypeNames() == null || nodeData.getMixinTypeNames().length == 0)
{
- vals.add(new TransientValueData(parent.getPrimaryTypeName()));
-
+ recipienAllNodeTypeNames = new InternalQName[]{nodeTypeName};
}
- else if (typeDataManager.isNodeType(Constants.MIX_REFERENCEABLE, new InternalQName[]{typeName})
- && def.getName().equals(Constants.JCR_UUID))
+ else
{
- vals.add(new TransientValueData(parent.getIdentifier()));
-
+ recipienAllNodeTypeNames = new InternalQName[nodeData.getMixinTypeNames().length + 1];
+ recipienAllNodeTypeNames[0] = nodeTypeName;
+ System.arraycopy(nodeData.getMixinTypeNames(), 0, recipienAllNodeTypeNames, 1,
+ nodeData.getMixinTypeNames().length);
}
- else if (typeDataManager.isNodeType(Constants.NT_HIERARCHYNODE, new InternalQName[]{typeName})
- && def.getName().equals(Constants.JCR_CREATED))
- {
- vals.add(new TransientValueData(Calendar.getInstance()));
- }
- else if (typeDataManager.isNodeType(Constants.EXO_OWNEABLE, new InternalQName[]{typeName})
- && def.getName().equals(Constants.EXO_OWNER))
- {
- // String owner = session.getUserID();
- vals.add(new TransientValueData(owner));
- parent.setACL(new AccessControlList(owner, parent.getACL().getPermissionEntries()));
+ final boolean recipientsMixVersionable = isNodeType(Constants.MIX_VERSIONABLE, recipienAllNodeTypeNames);
+ final boolean ancestorIsMixVersionable = isNodeType(Constants.MIX_VERSIONABLE, ancestorAllNodeTypeNames);
- }
- else if (typeDataManager.isNodeType(Constants.EXO_PRIVILEGEABLE, new InternalQName[]{typeName})
- && def.getName().equals(Constants.EXO_PERMISSIONS))
+ ItemAutocreator itemAutocreator = new ItemAutocreator(this, valueFactory, dataManager);
+ if (recipientsMixVersionable && !ancestorIsMixVersionable)
{
- for (AccessControlEntry ace : parent.getACL().getPermissionEntries())
- {
- vals.add(new TransientValueData(ace));
- }
+ changesLog.addAll(itemAutocreator.makeMixVesionableChanges(nodeData).getAllStates());
}
- else
+ else if (!recipientsMixVersionable && ancestorIsMixVersionable)
{
- String[] propVal = def.getDefaultValues();
- // there can be null in definition but should not be null value
- if (propVal != null && propVal.length != 0)
- {
- for (String v : propVal)
- {
- if (v != null)
- if (def.getRequiredType() == PropertyType.UNDEFINED)
- vals.add(((BaseValue)valueFactory.createValue(v)).getInternalData());
- else
- vals.add(((BaseValue)valueFactory.createValue(v, def.getRequiredType())).getInternalData());
- else
- {
- vals.add(null);
- }
- }
- }
- else
- return null;
- }
- return vals;
- }
+ final StringBuffer buffer = new StringBuffer();
+ buffer.append("Fail to change node type from ");
+ buffer.append(ancestorDefinition.getName().getAsString());
+ buffer.append(" to ");
+ buffer.append(recipientDefinition.getName().getAsString());
+ buffer.append(" because change from mix:versionable = true ");
+ buffer.append(" to mix:versionable = false is not alowed");
- protected void initDefault() throws RepositoryException
- {
- long start = System.currentTimeMillis();
- try
- {
- InputStream xml = NodeTypeManagerImpl.class.getResourceAsStream(NODETYPES_FILE);
- if (xml != null)
- {
- List<NodeTypeData> registerNodeTypes = registerNodeTypes(xml, ExtendedNodeTypeManager.IGNORE_IF_EXISTS);
- for (NodeTypeData nodeTypeData : registerNodeTypes)
- {
- buildInNodeTypesNames.add(nodeTypeData.getName());
- }
- }
- else
- {
- String msg =
- "Resource file '" + NODETYPES_FILE
- + "' with NodeTypes configuration does not found. Can not create node type manager";
- LOG.error(msg);
- throw new RepositoryException(msg);
- }
+ throw new ConstraintViolationException(buffer.toString());
}
- catch (RepositoryException e)
- {
- String msg =
- "Error of initialization default types. Resource file with NodeTypes configuration '" + NODETYPES_FILE
- + "'. " + e;
- LOG.error(msg);
- throw new RepositoryException(msg, e);
- }
- finally
- {
- LOG.info("Initialization of default nodetypes done. " + (System.currentTimeMillis() - start) + " ms.");
- }
- }
- /**
- * @param nodeType
- * @throws RepositoryException
- * @throws ValueFormatException
- * @throws PathNotFoundException
- */
- protected void internalRegister(NodeTypeData nodeType, Map<InternalQName, NodeTypeData> volatileNodeTypes)
- throws PathNotFoundException, ValueFormatException, RepositoryException
- {
- hierarchy.addNodeType(nodeType, volatileNodeTypes);
+ // update primary type
- defsHolder.putDefinitions(nodeType.getName(), nodeType);
- // put supers
- Set<InternalQName> supers = hierarchy.getSupertypes(nodeType.getName(), volatileNodeTypes);
+ final PropertyData item =
+ (PropertyData)this.dataManager.getItemData(nodeData, new QPathEntry(Constants.JCR_PRIMARYTYPE, 1));
- for (InternalQName superName : supers)
- {
- defsHolder.putDefinitions(nodeType.getName(), hierarchy.getNodeType(superName, volatileNodeTypes));
- }
- }
+ final TransientPropertyData primaryTypeData =
+ new TransientPropertyData(item.getQPath(), item.getIdentifier(), item.getPersistedVersion(), item.getType(),
+ item.getParentIdentifier(), item.isMultiValued());
+ primaryTypeData.setValue(new TransientValueData(nodeTypeName));
- //
- // /**
- // * @param nodeType
- // * @return
- // * @throws RepositoryException
- // */
- // private NodeDefinitionData[] getAllChildNodeDefinitions(NodeTypeData
- // nodeType) throws RepositoryException {
- // Collection<NodeDefinitionData> defs = new HashSet<NodeDefinitionData>();
- //
- // for (NodeDefinitionData cnd : nodeType.getDeclaredChildNodeDefinitions()) {
- // defs.add(cnd);
- // }
- //
- // for (InternalQName suname : nodeType.getDeclaredSupertypeNames()) {
- // NodeDefinitionData[] superDefinitionData =
- // getAllChildNodeDefinitions(hierarchy.getNodeType(suname));
- // for (int i = 0; i < superDefinitionData.length; i++) {
- // defs.add(superDefinitionData[i]);
- // }
- // }
- // return defs.toArray(new NodeDefinitionData[defs.size()]);
- // }
- //
- // /**
- // * @param nodeType
- // * @return
- // */
- // private PropertyDefinitionData[] getAllPropertyDefinitions(NodeTypeData
- // nodeType) {
- // Collection<PropertyDefinitionData> defs = new
- // HashSet<PropertyDefinitionData>();
- //
- // for (PropertyDefinitionData pd : nodeType.getDeclaredPropertyDefinitions())
- // defs.add(pd);
- //
- // for (InternalQName suname : nodeType.getDeclaredSupertypeNames()) {
- // PropertyDefinitionData[] superDefinitionData =
- // getAllPropertyDefinitions(hierarchy.getNodeType(suname));
- // for (int i = 0; i < superDefinitionData.length; i++) {
- // defs.add(superDefinitionData[i]);
- // }
- //
- // }
- //
- // return defs.toArray(new PropertyDefinitionData[defs.size()]);
- // }
+ changesLog.add(ItemState.createUpdatedState(primaryTypeData, true));
- /**
- * @param nodeTypeName
- * @param nodeType
- * @throws RepositoryException
- */
- protected void internalUnregister(InternalQName nodeTypeName, NodeTypeData nodeType) throws RepositoryException
- {
- // put supers
- Set<InternalQName> supers = hierarchy.getSupertypes(nodeTypeName);
+ final List<NodeData> affectedNodes = new ArrayList<NodeData>();
+ affectedNodes.add(nodeData);
- // remove from internal lists
- hierarchy.removeNodeType(nodeTypeName);
+ // child nodes
+ final NodeDefinitionComparator nodeDefinitionComparator =
+ new NodeDefinitionComparator(this, dataManager, itemAutocreator, affectedNodes);
+ changesLog.addAll(nodeDefinitionComparator.compare(recipientDefinition,
+ getAllChildNodeDefinitions(ancestorAllNodeTypeNames), getAllChildNodeDefinitions(recipienAllNodeTypeNames))
+ .getAllStates());
- // remove supers
- if (supers != null)
- for (InternalQName superName : supers)
- {
- defsHolder.removeDefinitions(nodeTypeName, hierarchy.getNodeType(superName));
- }
- // remove it self
- defsHolder.removeDefinitions(nodeTypeName, nodeType);
+ // properties defs
+ final PropertyDefinitionComparator propertyDefinitionComparator =
+ new PropertyDefinitionComparator(this, dataManager, itemAutocreator, affectedNodes, locationFactory);
+ changesLog.addAll(propertyDefinitionComparator.compare(recipientDefinition,
+ getAllPropertyDefinitions(ancestorAllNodeTypeNames), getAllPropertyDefinitions(recipienAllNodeTypeNames))
+ .getAllStates());
+
+ return changesLog;
}
- /**
- * parseNodeType.
- *
- * @param ntvalue
- * @return
- * @throws RepositoryException
- */
- protected Map<InternalQName, NodeTypeData> parseNodeTypes(List<NodeTypeValue> ntvalues) throws RepositoryException
+ public void start()
+
{
- Map<InternalQName, NodeTypeData> nodeTypeDataList = new HashMap<InternalQName, NodeTypeData>();
- for (NodeTypeValue ntvalue : ntvalues)
+ if (!started)
{
-
- if (accessControlPolicy.equals(AccessControlPolicy.DISABLE))
+ try
{
- List<String> nsupertypes = ntvalue.getDeclaredSupertypeNames();
- if (nsupertypes != null && nsupertypes.contains("exo:privilegeable")
- || ntvalue.getName().equals("exo:privilegeable"))
- {
- // skip this node, so it's not necessary at this runtime
- // + "' -- it's not necessary at this runtime";
- LOG.warn("Node type " + ntvalue.getName() + " is not register due to DISABLE control policy");
- break;
- }
- }
+ final InputStream xml = NodeTypeManagerImpl.class.getResourceAsStream(NODETYPES_FILE);
- // We have to validate node value before registering it
- ntvalue.validateNodeType();
- // throw new RepositoryException("Invalid node type value");
-
- // declaring NT name
- InternalQName ntName = locationFactory.parseJCRName(ntvalue.getName()).getInternalName();
-
- List<String> stlist = ntvalue.getDeclaredSupertypeNames();
- InternalQName[] supertypes = new InternalQName[stlist.size()];
- for (int i = 0; i < stlist.size(); i++)
- {
- supertypes[i] = locationFactory.parseJCRName(stlist.get(i)).getInternalName();
- }
-
- List<PropertyDefinitionValue> pdlist = ntvalue.getDeclaredPropertyDefinitionValues();
- PropertyDefinitionData[] props = new PropertyDefinitionData[pdlist.size()];
- for (int i = 0; i < pdlist.size(); i++)
- {
- PropertyDefinitionValue v = pdlist.get(i);
-
- PropertyDefinitionData pd;
- pd =
- new PropertyDefinitionData(locationFactory.parseJCRName(v.getName()).getInternalName(), ntName, v
- .isAutoCreate(), v.isMandatory(), v.getOnVersion(), v.isReadOnly(), v.getRequiredType(), v
- .getValueConstraints() != null ? v.getValueConstraints().toArray(
- new String[v.getValueConstraints().size()]) : new String[0], v.getDefaultValueStrings() == null
- ? new String[0] : v.getDefaultValueStrings().toArray(new String[v.getDefaultValueStrings().size()]),
- v.isMultiple());
-
- props[i] = pd;
- }
-
- List<NodeDefinitionValue> ndlist = ntvalue.getDeclaredChildNodeDefinitionValues();
- NodeDefinitionData[] nodes = new NodeDefinitionData[ndlist.size()];
- for (int i = 0; i < ndlist.size(); i++)
- {
- NodeDefinitionValue v = ndlist.get(i);
-
- List<String> rnts = v.getRequiredNodeTypeNames();
- InternalQName[] requiredNTs = new InternalQName[rnts.size()];
- for (int ri = 0; ri < rnts.size(); ri++)
+ if (xml != null)
{
- requiredNTs[ri] = locationFactory.parseJCRName(rnts.get(ri)).getInternalName();
- }
- InternalQName defaultNodeName = null;
- if (v.getDefaultNodeTypeName() != null)
- {
- defaultNodeName = locationFactory.parseJCRName(v.getDefaultNodeTypeName()).getInternalName();
- }
- NodeDefinitionData nd =
- new NodeDefinitionData(locationFactory.parseJCRName(v.getName()).getInternalName(), ntName, v
- .isAutoCreate(), v.isMandatory(), v.getOnVersion(), v.isReadOnly(), requiredNTs, defaultNodeName, v
- .isSameNameSiblings());
- nodes[i] = nd;
- }
- InternalQName primaryItemName = null;
- if (ntvalue.getPrimaryItemName() != null)
- primaryItemName = locationFactory.parseJCRName(ntvalue.getPrimaryItemName()).getInternalName();
+ final NodeTypeConverter nodeTypeConverter =
+ new NodeTypeConverter(this.locationFactory, this.accessControlPolicy);
+ final NodeTypeDataValidator nodeTypeDataValidator = new NodeTypeDataValidator(this.nodeTypeRepository);
+ final NodeTypeDataPersister serializer = new XmlNodeTypeDataPersister(nodeTypeConverter, xml);
- NodeTypeData nodeTypeData =
- new NodeTypeData(ntName, primaryItemName, ntvalue.isMixin(), ntvalue.isOrderableChild(), supertypes, props,
- nodes);
+ final List<NodeTypeData> defaultNodeTypes = serializer.getAllNodeTypes();
- validateNodeType(nodeTypeData);
- nodeTypeDataList.put(nodeTypeData.getName(), nodeTypeData);
- }
- checkCyclicDependencies(nodeTypeDataList);
- return nodeTypeDataList;
- }
+ // validate
+ nodeTypeDataValidator.validateNodeType(defaultNodeTypes);
- /**
- * Check according the JSR-170
- */
- protected void validateNodeType(NodeTypeData nodeType) throws RepositoryException
- {
- if (nodeType == null)
- {
- throw new RepositoryException("NodeType object " + nodeType + " is null");
- }
+ // check if default node type saved
+ if (!nodeTypeRepository.isStorageFilled())
+ {
- for (int i = 0; i < nodeType.getDeclaredSupertypeNames().length; i++)
- {
- if (nodeType.getName().equals(nodeType.getDeclaredSupertypeNames()[i]))
- {
- throw new RepositoryException("Invalid super type name"
- + nodeType.getDeclaredSupertypeNames()[i].getAsString());
- }
- }
- for (int i = 0; i < nodeType.getDeclaredPropertyDefinitions().length; i++)
- {
- if (!nodeType.getDeclaredPropertyDefinitions()[i].getDeclaringNodeType().equals(nodeType.getName()))
- {
- throw new RepositoryException("Invalid declared node type in property definitions with name "
- + nodeType.getDeclaredPropertyDefinitions()[i].getName().getAsString() + " not registred");
- }
- }
- for (int i = 0; i < nodeType.getDeclaredChildNodeDefinitions().length; i++)
- {
- if (!nodeType.getDeclaredChildNodeDefinitions()[i].getDeclaringNodeType().equals(nodeType.getName()))
- {
- throw new RepositoryException("Invalid declared node type in child node definitions with name "
- + nodeType.getDeclaredChildNodeDefinitions()[i].getName().getAsString() + " not registred");
- }
- }
+ //registerNodeType(defaultNodeTypes, ExtendedNodeTypeManager.IGNORE_IF_EXISTS);
+ nodeTypeRepository.registerNodeType(defaultNodeTypes, this, accessControlPolicy,
+ ExtendedNodeTypeManager.IGNORE_IF_EXISTS);
+ }
+ else
+ {
+ final List<NodeTypeData> allNodeTypes = nodeTypeRepository.getAllNodeTypes();
+ // register nodetypes in runtime
+ final Map<InternalQName, NodeTypeData> volatileNodeTypes = new HashMap<InternalQName, NodeTypeData>();
- if (nodeType.getName() == null)
- {
- throw new RepositoryException("NodeType implementation class " + nodeType.getClass().getName()
- + " is not supported in this method");
- }
- }
+ for (final NodeTypeData nodeTypeData : allNodeTypes)
+ {
+ volatileNodeTypes.put(nodeTypeData.getName(), nodeTypeData);
+ }
- private void checkCyclicDependencies(Map<InternalQName, NodeTypeData> nodeTypeDataList) throws RepositoryException
- {
- Set<InternalQName> unresolvedDependecies = new HashSet<InternalQName>();
- Set<InternalQName> resolvedDependecies = new HashSet<InternalQName>();
- for (Entry<InternalQName, NodeTypeData> entry : nodeTypeDataList.entrySet())
- {
- // / add itself
- NodeTypeData nodeTypeData = entry.getValue();
- resolvedDependecies.add(nodeTypeData.getName());
- // remove from unresolved
- unresolvedDependecies.remove(nodeTypeData.getName());
- // check suppers
- for (int i = 0; i < nodeTypeData.getDeclaredSupertypeNames().length; i++)
- {
- InternalQName superName = nodeTypeData.getDeclaredSupertypeNames()[i];
- if (hierarchy.getNodeType(superName) == null && !resolvedDependecies.contains(superName))
- {
- unresolvedDependecies.add(superName);
- }
- }
- // check node definition
- for (int i = 0; i < nodeTypeData.getDeclaredChildNodeDefinitions().length; i++)
- {
- NodeDefinitionData childnodeDefinitionData = nodeTypeData.getDeclaredChildNodeDefinitions()[i];
- for (int j = 0; j < childnodeDefinitionData.getRequiredPrimaryTypes().length; j++)
- {
- InternalQName requiredPrimaryTypeName = childnodeDefinitionData.getRequiredPrimaryTypes()[j];
- if (hierarchy.getNodeType(requiredPrimaryTypeName) == null
- && !resolvedDependecies.contains(requiredPrimaryTypeName))
+ for (final NodeTypeData nodeTypeData : allNodeTypes)
+ {
+ this.nodeTypeRepository.addNodeType(nodeTypeData, volatileNodeTypes);
+ }
+ }
+ // fill default node types map
+ for (final NodeTypeData nodeTypeData : defaultNodeTypes)
{
- unresolvedDependecies.add(requiredPrimaryTypeName);
+ this.buildInNodeTypesNames.add(nodeTypeData.getName());
}
+
}
- if (childnodeDefinitionData.getDefaultPrimaryType() != null)
+ else
{
- if (hierarchy.getNodeType(childnodeDefinitionData.getDefaultPrimaryType()) == null
- && !resolvedDependecies.contains(childnodeDefinitionData.getDefaultPrimaryType()))
- {
- unresolvedDependecies.add(childnodeDefinitionData.getDefaultPrimaryType());
-
- }
+ throw new RuntimeException("Resource file '" + NODETYPES_FILE
+ + "' with NodeTypes configuration does not found. Can not create node type manager");
}
}
- }
- if (unresolvedDependecies.size() > 0)
- {
- String msg = "Fail. Unresolved cyclic dependecy for :";
- for (InternalQName internalQName : resolvedDependecies)
+ catch (final RepositoryException e)
{
- msg += " " + internalQName.getAsString();
+ throw new RuntimeException(e.getLocalizedMessage(), e);
}
- throw new RepositoryException(msg);
+ started = true;
}
}
- private NodeDefinitionData[] getAllChildNodeDefinitions(NodeTypeData nodeType,
- Map<InternalQName, NodeTypeData> volatileNodeTypes)
+ public void stop()
{
- Collection<NodeDefinitionData> defs = new HashSet<NodeDefinitionData>();
-
- for (NodeDefinitionData cnd : nodeType.getDeclaredChildNodeDefinitions())
- {
- defs.add(cnd);
- }
-
- for (InternalQName suname : nodeType.getDeclaredSupertypeNames())
- {
- NodeTypeData superNodeType = volatileNodeTypes.get(suname);
- if (superNodeType == null)
- superNodeType = hierarchy.getNodeType(suname);
- NodeDefinitionData[] superDefinitionData = getAllChildNodeDefinitions(superNodeType, volatileNodeTypes);
- for (int i = 0; i < superDefinitionData.length; i++)
- {
- defs.add(superDefinitionData[i]);
- }
- }
- return defs.toArray(new NodeDefinitionData[defs.size()]);
}
/**
- * @param recipientDefinition
- * @param volatileNodeTypes
- * @return
- */
- private PropertyDefinitionData[] getAllPropertyDefinitions(NodeTypeData recipientDefinition,
- Map<InternalQName, NodeTypeData> volatileNodeTypes)
- {
- Collection<PropertyDefinitionData> defs = new HashSet<PropertyDefinitionData>();
-
- for (PropertyDefinitionData pd : recipientDefinition.getDeclaredPropertyDefinitions())
- defs.add(pd);
-
- for (InternalQName suname : recipientDefinition.getDeclaredSupertypeNames())
- {
- NodeTypeData superNodeType = volatileNodeTypes.get(suname);
- if (superNodeType == null)
- superNodeType = hierarchy.getNodeType(suname);
- PropertyDefinitionData[] superDefinitionData = getAllPropertyDefinitions(superNodeType, volatileNodeTypes);
- for (int i = 0; i < superDefinitionData.length; i++)
- {
- defs.add(superDefinitionData[i]);
- }
-
- }
-
- return defs.toArray(new PropertyDefinitionData[defs.size()]);
- }
-
- private Query getQuery(InternalQName nodeType) throws RepositoryException
- {
- List<Term> terms = new ArrayList<Term>();
- // try {
- String mixinTypesField = locationFactory.createJCRName(Constants.JCR_MIXINTYPES).getAsString();
- String primaryTypeField = locationFactory.createJCRName(Constants.JCR_PRIMARYTYPE).getAsString();
-
- // ExtendedNodeTypeManager ntMgr =
- // session.getWorkspace().getNodeTypeManager();
- NodeTypeData base = findNodeType(nodeType);
-
- if (base.isMixin())
- {
- // search for nodes where jcr:mixinTypes is set to this mixin
- Term t =
- new Term(FieldNames.PROPERTIES, FieldNames.createNamedValue(mixinTypesField, locationFactory.createJCRName(
- nodeType).getAsString()));
- terms.add(t);
- }
- else
- {
- // search for nodes where jcr:primaryType is set to this type
- Term t =
- new Term(FieldNames.PROPERTIES, FieldNames.createNamedValue(primaryTypeField, locationFactory
- .createJCRName(nodeType).getAsString()));
- terms.add(t);
- }
-
- // now search for all node types that are derived from base
- Set<InternalQName> allTypes = getSubtypes(nodeType);
- for (InternalQName descendantNt : allTypes)
- {
-
- String ntName = locationFactory.createJCRName(descendantNt).getAsString();
- NodeTypeData nt = findNodeType(descendantNt);
- Term t;
- if (nt.isMixin())
- {
- // search on jcr:mixinTypes
- t = new Term(FieldNames.PROPERTIES, FieldNames.createNamedValue(mixinTypesField, ntName));
- }
- else
- {
- // search on jcr:primaryType
- t = new Term(FieldNames.PROPERTIES, FieldNames.createNamedValue(primaryTypeField, ntName));
- }
- terms.add(t);
- }
- // now search for all node types that are derived from base
-
- if (terms.size() == 0)
- {
- // exception occured
- return new BooleanQuery();
- }
- else if (terms.size() == 1)
- {
- return new TermQuery(terms.get(0));
- }
- else
- {
- BooleanQuery b = new BooleanQuery();
- for (Term term : terms)
- {
- b.add(new TermQuery(term), Occur.SHOULD);
- }
- return b;
- }
- }
-
- /**
- * @param parent
- * @param dataManager
- * @param changes
+ * Unregisters the specified node type. In order for a node type to be
+ * successfully unregistered it must meet the following conditions:
+ * <ol>
+ * <li>the node type must obviously be registered.</li>
+ * <li>a built-in node type can not be unregistered.</li>
+ * <li>the node type must not have dependents, i.e. other node types that are
+ * referencing it.</li>
+ * <li>the node type must not be currently used by any workspace.</li>
+ * </ol>
+ *
+ * @param ntName name of the node type to be unregistered
+ * @throws NoSuchNodeTypeException if <code>ntName</code> does not denote a
+ * registered node type.
* @throws RepositoryException
+ * @throws RepositoryException if another error occurs.
+ * @see #unregisterNodeTypes(Collection)
*/
- private void makeMixVesionableChanges(NodeData parent, ItemDataConsumer dataManager, PlainChangesLog changes)
- throws RepositoryException
+ public void unregisterNodeType(final InternalQName nodeTypeName) throws RepositoryException
{
- new VersionHistoryDataHelper(parent, changes, dataManager, this);
- }
- /**
- * Notify the listeners that a node type <code>ntName</code> has been
- * registered.
- *
- * @param ntName NT name.
- */
- private void notifyRegistered(InternalQName ntName)
- {
- // copy listeners to array to avoid ConcurrentModificationException
- NodeTypeManagerListener[] la = listeners.values().toArray(new NodeTypeManagerListener[listeners.size()]);
- for (int i = 0; i < la.length; i++)
+ final NodeTypeData nodeType = this.nodeTypeRepository.getNodeType(nodeTypeName);
+ if (nodeType == null)
{
- if (la[i] != null)
- {
- la[i].nodeTypeRegistered(ntName);
- }
+ throw new NoSuchNodeTypeException(nodeTypeName.getAsString());
}
- }
-
- /**
- * Notify the listeners that a node type <code>ntName</code> has been
- * re-registered.
- *
- * @param ntName NT name.
- */
- private void notifyReRegistered(InternalQName ntName)
- {
- // copy listeners to array to avoid ConcurrentModificationException
- NodeTypeManagerListener[] la = listeners.values().toArray(new NodeTypeManagerListener[listeners.size()]);
- for (int i = 0; i < la.length; i++)
+ // check build in
+ if (this.buildInNodeTypesNames.contains(nodeTypeName))
{
- if (la[i] != null)
- {
- la[i].nodeTypeReRegistered(ntName);
- }
+ throw new RepositoryException(nodeTypeName.toString() + ": can't unregister built-in node type.");
}
- }
-
- /**
- * Notify the listeners that a node type <code>ntName</code> has been
- * unregistered.
- *
- * @param ntName NT name.
- */
- private void notifyUnregistered(InternalQName ntName)
- {
- // copy listeners to array to avoid ConcurrentModificationException
- NodeTypeManagerListener[] la = listeners.values().toArray(new NodeTypeManagerListener[listeners.size()]);
- for (int i = 0; i < la.length; i++)
+ // check dependencies
+ final Set<InternalQName> descendantNt = this.nodeTypeRepository.getSubtypes(nodeTypeName);
+ if (descendantNt.size() > 0)
{
- if (la[i] != null)
+ String message =
+ "Can not remove " + nodeTypeName.getAsString()
+ + "nodetype, because the following node types depend on it: ";
+ for (final InternalQName internalQName : descendantNt)
{
- la[i].nodeTypeUnregistered(ntName);
+ message += internalQName.getAsString() + " ";
}
+ throw new RepositoryException(message);
}
- }
-
- /**
- * @param nodeType
- * @param checkExistence
- * @return
- * @throws RepositoryException
- * @throws PathNotFoundException
- * @throws ValueFormatException
- */
- private PlainChangesLog persistNodeTypeData(NodeTypeData nodeType, boolean checkExistence)
- throws RepositoryException, PathNotFoundException, ValueFormatException
- {
- PlainChangesLog changesLog = new PlainChangesLogImpl();
- long start = System.currentTimeMillis();
- if (persister.isInitialized())
+ final Set<String> nodes = this.indexSearcherHolder.getNodesByNodeType(nodeTypeName);
+ if (nodes.size() > 0)
{
- try
+ String message =
+ "Can not remove " + nodeTypeName.getAsString()
+ + " nodetype, because the following node types is used in nodes with uuid: ";
+ for (final String uuids : nodes)
{
- if (!(checkExistence && persister.hasNodeTypeData(nodeType.getName())))
- {
- changesLog.addAll(persister.addNodeType(nodeType).getAllStates());
- }
+ message += uuids + " ";
}
- catch (InvalidItemStateException e)
- {
- LOG.warn("Error of storing node type " + nodeType.getName() + ". May be node type already registered .", e);
- }
- if (LOG.isDebugEnabled())
- LOG.debug("NodeType " + nodeType.getName() + " initialized. " + (System.currentTimeMillis() - start)
- + " ms");
- }
- else
- {
- if (LOG.isDebugEnabled())
- LOG.debug("NodeType " + nodeType.getName()
- + " registered but not initialized (storage is not initialized). "
- + (System.currentTimeMillis() - start) + " ms");
- }
- return changesLog;
- }
+ throw new RepositoryException(message);
- /**
- * {@inheritDoc}
- */
- private PlainChangesLog registerNodeType(NodeTypeData nodeType, int alreadyExistsBehaviour,
- Map<InternalQName, NodeTypeData> volatileNodeTypes) throws RepositoryException
- {
-
- if (nodeType == null)
- {
- throw new RepositoryException("NodeTypeData object " + nodeType + " is null");
}
-
- long start = System.currentTimeMillis();
-
- if (accessControlPolicy.equals(AccessControlPolicy.DISABLE) && nodeType.getName().equals("exo:privilegeable"))
- {
- throw new RepositoryException("NodeType exo:privilegeable is DISABLED");
- }
-
- InternalQName qname = nodeType.getName();
- if (qname == null)
- {
- throw new RepositoryException("NodeType implementation class " + nodeType.getClass().getName()
- + " is not supported in this method");
- }
- PlainChangesLog changesLog = new PlainChangesLogImpl();
-
- NodeTypeData registeredNodeType = findNodeType(qname);
- if (registeredNodeType != null)
- {
- switch (alreadyExistsBehaviour)
- {
- case ExtendedNodeTypeManager.FAIL_IF_EXISTS :
- throw new RepositoryException("NodeType " + nodeType.getName() + " is already registered");
- case ExtendedNodeTypeManager.IGNORE_IF_EXISTS :
- if (LOG.isDebugEnabled())
- LOG.debug("Skipped " + nodeType.getName().getAsString() + " as already registered");
- break;
- case ExtendedNodeTypeManager.REPLACE_IF_EXISTS :
- changesLog.addAll(reregisterNodeType(registeredNodeType, nodeType, volatileNodeTypes).getAllStates());
- break;
- }
- }
- else
- {
- internalRegister(nodeType, volatileNodeTypes);
- changesLog.addAll(persistNodeTypeData(nodeType, true).getAllStates());
-
- }
- return changesLog;
+ this.nodeTypeRepository.removeNodeType(nodeType);
}
/**
- * @param nodeType
- * @return
- * @throws RepositoryException
+ * @throws RepositoryException
+ * @throws ConstraintViolationException
+ * @see org.exoplatform.services.jcr.core.nodetype.NodeTypeDataManager#updateNodeType(org.exoplatform.services.jcr.core.nodetype.NodeTypeData, org.exoplatform.services.jcr.core.nodetype.NodeTypeData, java.util.Map)
*/
- private List<ItemState> removePersistedNodeType(NodeTypeData nodeType) throws RepositoryException
- {
- return persister.removeNodeType(nodeType);
- }
-
- private PlainChangesLog reregisterNodeType(NodeTypeData ancestorDefinition, NodeTypeData recipientDefinition,
+ public PlainChangesLog updateNodeType(NodeTypeData ancestorDefinition, NodeTypeData recipientDefinition,
Map<InternalQName, NodeTypeData> volatileNodeTypes) throws ConstraintViolationException, RepositoryException
{
+
if (!ancestorDefinition.getName().equals(recipientDefinition.getName()))
{
throw new RepositoryException("Unsupported Operation");
}
- if (buildInNodeTypesNames.contains(recipientDefinition.getName()))
+ if (this.buildInNodeTypesNames.contains(recipientDefinition.getName()))
{
throw new RepositoryException(recipientDefinition.getName() + ": can't reregister built-in node type.");
}
- PlainChangesLog changesLog = new PlainChangesLogImpl();
- VolatileNodeTypeDataManager volatileNodeTypeDataManager = new VolatileNodeTypeDataManager(this);
+ final PlainChangesLog changesLog = new PlainChangesLogImpl();
+ final VolatileNodeTypeDataManager volatileNodeTypeDataManager = new VolatileNodeTypeDataManager(this);
volatileNodeTypeDataManager.registerVolatileNodeTypes(volatileNodeTypes);
- Set<String> nodes = getNodes(recipientDefinition.getName());
+ ItemAutocreator itemAutocreator = new ItemAutocreator(volatileNodeTypeDataManager, valueFactory, dataManager);
+
+ final Set<String> nodes = this.indexSearcherHolder.getNodesByNodeType(recipientDefinition.getName());
// check add mix:versionable super
if (isNodeType(Constants.MIX_VERSIONABLE, recipientDefinition.getDeclaredSupertypeNames())
&& !isNodeType(Constants.MIX_VERSIONABLE, ancestorDefinition.getDeclaredSupertypeNames()))
{
- for (String uuid : nodes)
+ for (final String uuid : nodes)
{
- ItemData item = persister.getDataManager().getItemData(uuid);
+ final ItemData item = this.dataManager.getItemData(uuid);
if (item != null && item.isNode())
{
- makeMixVesionableChanges(((NodeData)item), persister.getDataManager(), changesLog);
+ changesLog.addAll(itemAutocreator.makeMixVesionableChanges((NodeData)item).getAllStates());
}
}
}
@@ -1554,66 +874,85 @@
{
if (nodes.size() > 0)
{
- StringBuffer buffer = new StringBuffer();
+ final StringBuffer buffer = new StringBuffer();
buffer.append("Fail to change ");
buffer.append(recipientDefinition.getName().getAsString());
buffer.append(" node type from mix:versionable = true to mix:versionable = false");
buffer.append(" because the folowing node exists: ");
- for (String uuid : nodes)
+ if (nodes.size() < 100)
{
- ItemData item = persister.getDataManager().getItemData(uuid);
- if (item != null && item.isNode())
+ for (final String uuid : nodes)
{
- buffer.append(item.getQPath().getAsString());
- buffer.append(" ");
+ final ItemData item = this.dataManager.getItemData(uuid);
+ if (item != null && item.isNode())
+ {
+ buffer.append(item.getQPath().getAsString());
+ buffer.append(" ");
+ }
}
}
throw new ConstraintViolationException(buffer.toString());
}
}
+ final List<NodeData> affectedNodes = new ArrayList<NodeData>();
+ for (final String uuid : nodes)
+ {
+ final ItemData nodeData = this.dataManager.getItemData(uuid);
+ if (nodeData != null)
+ {
+ if (nodeData.isNode())
+ {
+ affectedNodes.add((NodeData)nodeData);
+ }
+ }
+ }
+
// child nodes
- NodeDefinitionComparator nodeDefinitionComparator =
- new NodeDefinitionComparator(volatileNodeTypeDataManager, persister.getDataManager());
+ final NodeDefinitionComparator nodeDefinitionComparator =
+ new NodeDefinitionComparator(volatileNodeTypeDataManager, this.dataManager, itemAutocreator, affectedNodes);
changesLog.addAll(nodeDefinitionComparator.compare(recipientDefinition,
- getAllChildNodeDefinitions(ancestorDefinition, new HashMap<InternalQName, NodeTypeData>()),
- getAllChildNodeDefinitions(recipientDefinition, volatileNodeTypes)).getAllStates());
+ getAllChildNodeDefinitions(ancestorDefinition.getName()),
+ volatileNodeTypeDataManager.getAllChildNodeDefinitions(recipientDefinition.getName())).getAllStates());
// properties defs
- PropertyDefinitionComparator propertyDefinitionComparator =
- new PropertyDefinitionComparator(volatileNodeTypeDataManager, persister.getDataManager(), locationFactory);
+ final PropertyDefinitionComparator propertyDefinitionComparator =
+ new PropertyDefinitionComparator(volatileNodeTypeDataManager, this.dataManager, itemAutocreator,
+ affectedNodes, this.locationFactory);
changesLog.addAll(propertyDefinitionComparator.compare(recipientDefinition,
- getAllPropertyDefinitions(ancestorDefinition, new HashMap<InternalQName, NodeTypeData>()),
- getAllPropertyDefinitions(recipientDefinition, volatileNodeTypes))
+ getAllPropertyDefinitions(ancestorDefinition.getName()),
+ volatileNodeTypeDataManager.getAllPropertyDefinitions(recipientDefinition.getName()))
.getAllStates());
- // mixin changed
+ // notify listeners about changes
if (!Arrays.deepEquals(recipientDefinition.getDeclaredSupertypeNames(), ancestorDefinition
.getDeclaredSupertypeNames()))
{
- for (String uuid : nodes)
+ for (final String uuid : nodes)
{
- ItemData item = persister.getDataManager().getItemData(uuid);
+ ItemData item = this.dataManager.getItemData(uuid);
if (item != null && item.isNode())
{
if (!(item instanceof TransientNodeData))
+ {
item =
new TransientNodeData(item.getQPath(), item.getIdentifier(), item.getPersistedVersion(),
((NodeData)item).getPrimaryTypeName(), ((NodeData)item).getMixinTypeNames(), ((NodeData)item)
.getOrderNumber(), ((NodeData)item).getParentIdentifier(), ((NodeData)item).getACL());
+ }
changesLog.add(new ItemState(item, ItemState.MIXIN_CHANGED, false, null));
}
}
}
- // mixin
+ // mixin changed
if (ancestorDefinition.isMixin() != recipientDefinition.isMixin())
{
if (nodes.size() > 0)
{
- StringBuffer buffer = new StringBuffer();
+ final StringBuffer buffer = new StringBuffer();
buffer.append("Fail to change ");
buffer.append(recipientDefinition.getName().getAsString());
buffer.append(" node type from IsMixin=");
@@ -1621,25 +960,62 @@
buffer.append(" to IsMixin=");
buffer.append(recipientDefinition.isMixin());
buffer.append(" because the folowing node exists: ");
- for (String uuid : nodes)
+ if (nodes.size() < 100)
{
- ItemData item = persister.getDataManager().getItemData(uuid);
- if (item != null && item.isNode())
+ for (final String uuid : nodes)
{
- buffer.append(item.getQPath().getAsString());
- buffer.append(" ");
+ final ItemData item = this.dataManager.getItemData(uuid);
+ if (item != null && item.isNode())
+ {
+ buffer.append(item.getQPath().getAsString());
+ buffer.append(" ");
+ }
}
}
throw new ConstraintViolationException(buffer.toString());
}
}
- internalUnregister(ancestorDefinition.getName(), ancestorDefinition);
- changesLog.addAll(removePersistedNodeType(ancestorDefinition));
+ this.nodeTypeRepository.removeNodeType(ancestorDefinition);
- internalRegister(recipientDefinition, volatileNodeTypes);
- changesLog.addAll(persistNodeTypeData(recipientDefinition, false).getAllStates());
+ this.nodeTypeRepository.addNodeType(recipientDefinition, volatileNodeTypes);
return changesLog;
}
+ protected void initDefault() throws RepositoryException
+ {
+ long start = System.currentTimeMillis();
+ try
+ {
+ InputStream xml = NodeTypeManagerImpl.class.getResourceAsStream(NODETYPES_FILE);
+ if (xml != null)
+ {
+ List<NodeTypeData> registerNodeTypes = registerNodeTypes(xml, ExtendedNodeTypeManager.IGNORE_IF_EXISTS,TEXT_XML);
+ for (NodeTypeData nodeTypeData : registerNodeTypes)
+ {
+ buildInNodeTypesNames.add(nodeTypeData.getName());
+ }
+ }
+ else
+ {
+ String msg =
+ "Resource file '" + NODETYPES_FILE
+ + "' with NodeTypes configuration does not found. Can not create node type manager";
+ log.error(msg);
+ throw new RepositoryException(msg);
+ }
+ }
+ catch (RepositoryException e)
+ {
+ String msg =
+ "Error of initialization default types. Resource file with NodeTypes configuration '" + NODETYPES_FILE
+ + "'. " + e;
+ log.error(msg);
+ throw new RepositoryException(msg, e);
+ }
+ finally
+ {
+ log.info("Initialization of default nodetypes done. " + (System.currentTimeMillis() - start) + " ms.");
+ }
+ }
}
Deleted: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/NodeTypeDataPersister.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/NodeTypeDataPersister.java 2009-10-02 15:41:14 UTC (rev 198)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/NodeTypeDataPersister.java 2009-10-04 09:34:54 UTC (rev 199)
@@ -1,805 +0,0 @@
-/*
- * 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.nodetype;
-
-import org.exoplatform.services.jcr.access.AccessControlEntry;
-import org.exoplatform.services.jcr.access.AccessControlList;
-import org.exoplatform.services.jcr.core.ExtendedPropertyType;
-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.dataflow.DataManager;
-import org.exoplatform.services.jcr.dataflow.ItemState;
-import org.exoplatform.services.jcr.dataflow.PlainChangesLog;
-import org.exoplatform.services.jcr.dataflow.PlainChangesLogImpl;
-import org.exoplatform.services.jcr.dataflow.TransactionChangesLog;
-import org.exoplatform.services.jcr.datamodel.IllegalNameException;
-import org.exoplatform.services.jcr.datamodel.InternalQName;
-import org.exoplatform.services.jcr.datamodel.NodeData;
-import org.exoplatform.services.jcr.datamodel.QPathEntry;
-import org.exoplatform.services.jcr.datamodel.ValueData;
-import org.exoplatform.services.jcr.impl.Constants;
-import org.exoplatform.services.jcr.impl.dataflow.ItemDataRemoveVisitor;
-import org.exoplatform.services.jcr.impl.dataflow.TransientNodeData;
-import org.exoplatform.services.jcr.impl.dataflow.TransientPropertyData;
-import org.exoplatform.services.jcr.impl.dataflow.TransientValueData;
-import org.exoplatform.services.jcr.impl.dataflow.ValueDataConvertor;
-import org.exoplatform.services.jcr.impl.util.NodeDataReader;
-import org.exoplatform.services.log.ExoLogger;
-import org.exoplatform.services.log.Log;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-import javax.jcr.InvalidItemStateException;
-import javax.jcr.ItemExistsException;
-import javax.jcr.PathNotFoundException;
-import javax.jcr.PropertyType;
-import javax.jcr.RepositoryException;
-import javax.jcr.ValueFormatException;
-import javax.jcr.version.OnParentVersionAction;
-
-/**
- * Created by The eXo Platform SAS.
- *
- * @author Gennady Azarenkov
- * @version $Id: NodeTypeDataPersister.java 13962 2008-05-07 16:00:48Z
- * pnedonosko $
- */
-
-public class NodeTypeDataPersister
-{
-
- public static final Log LOG = ExoLogger.getLogger("jcr.NodeTypeDataPersister");
-
- private DataManager dataManager;
-
- private NodeData ntRoot;
-
- public NodeTypeDataPersister(DataManager dataManager)
- {
- this.dataManager = dataManager;
- try
- {
- NodeData jcrSystem = (NodeData)dataManager.getItemData(Constants.SYSTEM_UUID);
- if (jcrSystem != null)
- this.ntRoot = (NodeData)dataManager.getItemData(jcrSystem, new QPathEntry(Constants.JCR_NODETYPES, 1));
- }
- catch (RepositoryException e)
- {
- LOG.warn("Nodetypes storage (/jcr:system/jcr:nodetypes node) is not initialized.");
- }
- }
-
- public PlainChangesLog addNodeType(NodeTypeData nodeType) throws PathNotFoundException, RepositoryException,
- ValueFormatException
- {
- PlainChangesLog changesLog = new PlainChangesLogImpl();
- if (!isInitialized())
- {
- LOG.warn("Nodetypes storage (/jcr:system/jcr:nodetypes node) is not initialized.");
- return null;
- }
-
- NodeData ntNode = TransientNodeData.createNodeData(ntRoot, nodeType.getName(), Constants.NT_NODETYPE);
-
- TransientPropertyData primaryType =
- TransientPropertyData.createPropertyData(ntNode, Constants.JCR_PRIMARYTYPE, PropertyType.NAME, false);
- primaryType.setValue(new TransientValueData(ntNode.getPrimaryTypeName()));
-
- // jcr:nodeTypeName
- TransientPropertyData name =
- TransientPropertyData.createPropertyData(ntNode, Constants.JCR_NODETYPENAME, PropertyType.NAME, false);
- name.setValue(new TransientValueData(nodeType.getName()));
-
- // jcr:isMixin
- TransientPropertyData isMixin =
- TransientPropertyData.createPropertyData(ntNode, Constants.JCR_ISMIXIN, PropertyType.BOOLEAN, false);
- isMixin.setValue(new TransientValueData(nodeType.isMixin()));
-
- // jcr:hasOrderableChildNodes
- TransientPropertyData hasOrderableChildNodes =
- TransientPropertyData.createPropertyData(ntNode, Constants.JCR_HASORDERABLECHILDNODES, PropertyType.BOOLEAN,
- false);
- hasOrderableChildNodes.setValue(new TransientValueData(nodeType.hasOrderableChildNodes()));
-
- changesLog.add(ItemState.createAddedState(ntNode)).add(ItemState.createAddedState(primaryType)).add(
- ItemState.createAddedState(name)).add(ItemState.createAddedState(isMixin)).add(
- ItemState.createAddedState(hasOrderableChildNodes));
-
- if (nodeType.getPrimaryItemName() != null)
- {
- // jcr:primaryItemName
- TransientPropertyData primaryItemName =
- TransientPropertyData.createPropertyData(ntNode, Constants.JCR_PRIMARYITEMNAME, PropertyType.NAME, false);
- primaryItemName.setValue(new TransientValueData(nodeType.getPrimaryItemName()));
- changesLog.add(ItemState.createAddedState(primaryItemName));
- }
-
- List<ValueData> parents = new ArrayList<ValueData>();
- for (InternalQName nt : nodeType.getDeclaredSupertypeNames())
- parents.add(new TransientValueData(nt));
-
- if (parents.size() != 0)
- {
- // jcr:supertypes
- TransientPropertyData supertypes =
- TransientPropertyData.createPropertyData(ntNode, Constants.JCR_SUPERTYPES, PropertyType.NAME, true);
- supertypes.setValues(parents);
- changesLog.add(ItemState.createAddedState(supertypes));
- }
-
- for (int i = 0; i < nodeType.getDeclaredPropertyDefinitions().length; i++)
- {
- NodeData childProps =
- TransientNodeData.createNodeData(ntNode, Constants.JCR_PROPERTYDEFINITION, Constants.NT_PROPERTYDEFINITION,
- i + 1);
-
- TransientPropertyData cpPrimaryType =
- TransientPropertyData.createPropertyData(childProps, Constants.JCR_PRIMARYTYPE, PropertyType.NAME, false);
- cpPrimaryType.setValue(new TransientValueData(childProps.getPrimaryTypeName()));
-
- changesLog.add(ItemState.createAddedState(childProps)).add(ItemState.createAddedState(cpPrimaryType));
-
- changesLog.addAll(initPropertyDefProps(childProps, nodeType.getDeclaredPropertyDefinitions()[i]));
- }
-
- for (int i = 0; i < nodeType.getDeclaredChildNodeDefinitions().length; i++)
- {
- NodeData childNodes =
- TransientNodeData.createNodeData(ntNode, Constants.JCR_CHILDNODEDEFINITION,
- Constants.NT_CHILDNODEDEFINITION, i + 1);
-
- TransientPropertyData cnPrimaryType =
- TransientPropertyData.createPropertyData(childNodes, Constants.JCR_PRIMARYTYPE, PropertyType.NAME, false);
- cnPrimaryType.setValue(new TransientValueData(childNodes.getPrimaryTypeName()));
-
- changesLog.add(ItemState.createAddedState(childNodes)).add(ItemState.createAddedState(cnPrimaryType));
-
- changesLog.addAll(initNodeDefProps(childNodes, nodeType.getDeclaredChildNodeDefinitions()[i]));
- }
-
- return changesLog;
- }
-
- public boolean hasNodeTypeData(InternalQName nodeTypeName) throws RepositoryException
- {
- try
- {
- return getNodeTypesData(nodeTypeName).size() > 0;
- }
- catch (PathNotFoundException e)
- {
- return false;
- }
- }
-
- public synchronized PlainChangesLog initNodetypesRoot(NodeData nsSystem, boolean addACL)
- {
- PlainChangesLog changesLog = new PlainChangesLogImpl();
- if (ntRoot == null)
- {
-
- long start = System.currentTimeMillis();
-
- TransientNodeData jcrNodetypes =
- TransientNodeData.createNodeData(nsSystem, Constants.JCR_NODETYPES, Constants.NT_UNSTRUCTURED,
- Constants.NODETYPESROOT_UUID);
-
- TransientPropertyData primaryType =
- TransientPropertyData.createPropertyData(jcrNodetypes, Constants.JCR_PRIMARYTYPE, PropertyType.NAME, false);
- primaryType.setValue(new TransientValueData(jcrNodetypes.getPrimaryTypeName()));
-
- changesLog.add(ItemState.createAddedState(jcrNodetypes)).add(ItemState.createAddedState(primaryType));
-
- if (addACL)
- {
- AccessControlList acl = new AccessControlList();
- InternalQName[] mixins = new InternalQName[]{Constants.EXO_OWNEABLE, Constants.EXO_PRIVILEGEABLE};
- jcrNodetypes.setMixinTypeNames(mixins);
-
- // jcr:mixinTypes
- List<ValueData> mixValues = new ArrayList<ValueData>();
- for (InternalQName mixin : mixins)
- {
- mixValues.add(new TransientValueData(mixin));
- }
- TransientPropertyData exoMixinTypes =
- TransientPropertyData.createPropertyData(jcrNodetypes, Constants.JCR_MIXINTYPES, PropertyType.NAME,
- true, mixValues);
-
- TransientPropertyData exoOwner =
- TransientPropertyData.createPropertyData(jcrNodetypes, Constants.EXO_OWNER, PropertyType.STRING, false,
- new TransientValueData(acl.getOwner()));
-
- List<ValueData> permsValues = new ArrayList<ValueData>();
- for (int i = 0; i < acl.getPermissionEntries().size(); i++)
- {
- AccessControlEntry entry = acl.getPermissionEntries().get(i);
- permsValues.add(new TransientValueData(entry));
- }
- TransientPropertyData exoPerms =
- TransientPropertyData.createPropertyData(jcrNodetypes, Constants.EXO_PERMISSIONS,
- ExtendedPropertyType.PERMISSION, true, permsValues);
-
- changesLog.add(ItemState.createAddedState(exoMixinTypes)).add(ItemState.createAddedState(exoOwner)).add(
- ItemState.createAddedState(exoPerms));
-
- changesLog.add(new ItemState(jcrNodetypes, ItemState.MIXIN_CHANGED, false, null));
- }
-
- ntRoot = jcrNodetypes;
- if (LOG.isDebugEnabled())
- LOG.debug("/jcr:system/jcr:nodetypes is created, creation time: " + (System.currentTimeMillis() - start)
- + " ms");
- }
- else
- {
- LOG.warn("/jcr:system/jcr:nodetypes already exists");
- }
- return changesLog;
- }
-
- public synchronized PlainChangesLog initStorage(Collection<NodeTypeData> nodetypes) throws PathNotFoundException,
- RepositoryException
- {
- PlainChangesLog changesLog = new PlainChangesLogImpl();
- if (!isInitialized())
- {
- LOG
- .warn("Nodetypes storage (/jcr:system/jcr:nodetypes node) is not exists. Possible is not initialized (call initNodetypesRoot() before)");
- return changesLog;
- }
- long ntStart = System.currentTimeMillis();
- for (NodeTypeData nt : nodetypes)
- {
- try
- {
- changesLog.addAll(addNodeType(nt).getAllStates());
- if (LOG.isDebugEnabled())
- LOG.debug("Node type " + nt.getName() + " is initialized. ");
- }
- catch (ItemExistsException e)
- {
- LOG.warn("Node exists " + nt.getName() + ". Error: " + e.getMessage());
- }
- }
- // saveChanges();
- LOG.info("Node types initialized. Time: " + (System.currentTimeMillis() - ntStart) + " ms");
- return changesLog;
- }
-
- public List<NodeTypeData> loadFromStorage() throws PathNotFoundException, RepositoryException
- {
-
- if (!isInitialized())
- {
- NodeData jcrSystem = (NodeData)dataManager.getItemData(Constants.SYSTEM_UUID);
- if (jcrSystem != null)
- this.ntRoot = (NodeData)dataManager.getItemData(jcrSystem, new QPathEntry(Constants.JCR_NODETYPES, 1));
- else
- throw new RepositoryException("jcr:system is not found. Possible the workspace is not initialized properly");
- }
-
- if (isInitialized())
- {
-
- List<NodeTypeData> loadedList = new ArrayList<NodeTypeData>();
-
- long cycleStart = System.currentTimeMillis();
- if (LOG.isDebugEnabled())
- LOG.debug(">>> Node types registration cycle started");
-
- NodeDataReader ntReader = new NodeDataReader(ntRoot, dataManager);
- ntReader.forNodesByType(Constants.NT_NODETYPE); // for nt:nodeType
- ntReader.read();
-
- nextNodeType : for (NodeDataReader ntr : ntReader.getNodesByType(Constants.NT_NODETYPE))
- {
-
- long ntStart = System.currentTimeMillis();
-
- InternalQName ntName = null;
- try
- {
-
- ntr.forProperty(Constants.JCR_NODETYPENAME, PropertyType.NAME);
- ntr.read();
-
- try
- {
- ntName = ValueDataConvertor.readQName(ntr.getPropertyValue(Constants.JCR_NODETYPENAME));
- }
- catch (IllegalNameException e)
- {
- LOG.error("NodeType name is not valid. " + e + ". NodeType skipped.");
- continue nextNodeType;
- }
-
- if (LOG.isDebugEnabled())
- LOG.debug("Reading from storage " + ntName.getAsString() + " "
- + (System.currentTimeMillis() - ntStart));
-
- ntr.forProperty(Constants.JCR_PRIMARYTYPE, PropertyType.NAME).forProperty(Constants.JCR_ISMIXIN,
- PropertyType.BOOLEAN).forProperty(Constants.JCR_HASORDERABLECHILDNODES, PropertyType.BOOLEAN)
- .forProperty(Constants.JCR_PRIMARYITEMNAME, PropertyType.NAME).forProperty(Constants.JCR_SUPERTYPES,
- PropertyType.NAME);
- ntr.forNodesByType(Constants.NT_PROPERTYDEFINITION).forNodesByType(Constants.NT_CHILDNODEDEFINITION);
- ntr.read();
-
- boolean mixin = ValueDataConvertor.readBoolean(ntr.getPropertyValue(Constants.JCR_ISMIXIN));
- boolean hasOrderableChilds =
- ValueDataConvertor.readBoolean(ntr.getPropertyValue(Constants.JCR_HASORDERABLECHILDNODES));
- InternalQName primaryItemName;
- try
- {
- primaryItemName = ValueDataConvertor.readQName(ntr.getPropertyValue(Constants.JCR_PRIMARYITEMNAME));
- }
- catch (PathNotFoundException e)
- {
- primaryItemName = null;
- }
- catch (IllegalNameException e)
- {
- LOG.error("NodeType primary item name is not valid. " + e + ". NodeType " + ntName.getAsString()
- + " skipped.");
- continue nextNodeType;
- }
-
- // -------- Super types --------
- InternalQName[] declaredSupertypes;
- try
- {
- List<ValueData> dst = ntr.getPropertyValues(Constants.JCR_SUPERTYPES);
- InternalQName[] supertypes = new InternalQName[dst.size()];
- for (int i = 0; i < dst.size(); i++)
- supertypes[i] = ValueDataConvertor.readQName(dst.get(i));
-
- declaredSupertypes = supertypes;
- }
- catch (PathNotFoundException e)
- {
- declaredSupertypes = new InternalQName[0];
- }
- catch (IllegalNameException e)
- {
- LOG.error("NodeType supertype name is not valid. " + e + ". NodeType " + ntName.getAsString()
- + " skipped.");
- continue nextNodeType;
- }
-
- // -------- Property definitions --------
- if (LOG.isDebugEnabled())
- LOG.debug("Reading Property definitions for " + ntName.getAsString() + " "
- + (System.currentTimeMillis() - ntStart));
-
- PropertyDefinitionData[] declaredProperties;
- try
- {
- List<NodeDataReader> pdNodes = ntr.getNodesByType(Constants.NT_PROPERTYDEFINITION);
- PropertyDefinitionData[] declaredPropertyDefs = new PropertyDefinitionData[pdNodes.size()];
- for (int pdi = 0; pdi < pdNodes.size(); pdi++)
- {
- NodeDataReader pdr = pdNodes.get(pdi);
-
- pdr.forProperty(Constants.JCR_NAME, PropertyType.NAME) // jcr:name
- .forProperty(Constants.JCR_AUTOCREATED, PropertyType.BOOLEAN)
- // jcr:autoCreated
- .forProperty(Constants.JCR_MANDATORY, PropertyType.BOOLEAN)
- // jcr:mandatory
- .forProperty(Constants.JCR_PROTECTED, PropertyType.BOOLEAN)
- // jcr:protected
- .forProperty(Constants.JCR_MULTIPLE, PropertyType.BOOLEAN)
- // jcr:multiple
- .forProperty(Constants.JCR_ONPARENTVERSION, PropertyType.STRING)
- // jcr:onParentVersion
- .forProperty(Constants.JCR_REQUIREDTYPE, PropertyType.STRING)
- // jcr:requiredType
- .forProperty(Constants.JCR_VALUECONSTRAINTS, PropertyType.STRING)
- // jcr:valueConstraints
- .forProperty(Constants.JCR_DEFAULTVALUES, PropertyType.STRING);
- // jcr:defaultValues
- pdr.read();
-
- InternalQName pname;
- try
- {
- pname = ValueDataConvertor.readQName(pdr.getPropertyValue(Constants.JCR_NAME));
- }
- catch (PathNotFoundException e)
- {
- pname = null; // residual property definition
- }
- catch (IllegalNameException e)
- {
- LOG.error("Property definition name is not valid. " + e + ". NodeType " + ntName.getAsString()
- + " skipped.");
- continue nextNodeType;
- }
-
- String[] valueConstraints;
- try
- {
- List<ValueData> valueConstraintValues = pdr.getPropertyValues(Constants.JCR_VALUECONSTRAINTS);
- valueConstraints = new String[valueConstraintValues.size()];
- for (int j = 0; j < valueConstraintValues.size(); j++)
- valueConstraints[j] = ValueDataConvertor.readString(valueConstraintValues.get(j));
- }
- catch (PathNotFoundException e)
- {
- valueConstraints = new String[0];
- }
-
- String[] defaultValues;
- try
- {
- List<ValueData> dvl = pdr.getPropertyValues(Constants.JCR_DEFAULTVALUES);
- defaultValues = new String[dvl.size()];
- for (int i = 0; i < dvl.size(); i++)
- defaultValues[i] = ValueDataConvertor.readString(dvl.get(i));
- }
- catch (PathNotFoundException e)
- {
- defaultValues = new String[0];
- }
-
- PropertyDefinitionData pDef =
- new PropertyDefinitionData(pname, ntName, ValueDataConvertor.readBoolean(pdr
- .getPropertyValue(Constants.JCR_AUTOCREATED)), ValueDataConvertor.readBoolean(pdr
- .getPropertyValue(Constants.JCR_MANDATORY)), OnParentVersionAction
- .valueFromName(ValueDataConvertor.readString(pdr
- .getPropertyValue(Constants.JCR_ONPARENTVERSION))), ValueDataConvertor.readBoolean(pdr
- .getPropertyValue(Constants.JCR_PROTECTED)), ExtendedPropertyType
- .valueFromName(ValueDataConvertor.readString(pdr
- .getPropertyValue(Constants.JCR_REQUIREDTYPE))), valueConstraints, defaultValues,
- ValueDataConvertor.readBoolean(pdr.getPropertyValue(Constants.JCR_MULTIPLE)));
- if (LOG.isDebugEnabled())
- LOG.debug("Property definitions readed "
- + (pname != null ? pname.getAsString() : Constants.JCR_ANY_NAME.getAsString()) + " "
- + (System.currentTimeMillis() - ntStart));
-
- declaredPropertyDefs[pdi] = pDef;
- }
-
- declaredProperties = declaredPropertyDefs;
- }
- catch (PathNotFoundException e)
- {
- if (LOG.isDebugEnabled())
- LOG.debug("Property definitions is not found. " + e + ". NodeType " + ntName.getAsString());
- declaredProperties = new PropertyDefinitionData[]{};
- }
-
- // --------- Child nodes definitions ----------
- if (LOG.isDebugEnabled())
- LOG.debug("Reading Child nodes definitions for " + ntName.getAsString() + " "
- + (System.currentTimeMillis() - ntStart));
-
- NodeDefinitionData[] declaredChildNodes;
- try
- {
- List<NodeDataReader> cdNodes = ntr.getNodesByType(Constants.NT_CHILDNODEDEFINITION);
- NodeDefinitionData[] declaredChildNodesDefs = new NodeDefinitionData[cdNodes.size()];
- for (int cdi = 0; cdi < cdNodes.size(); cdi++)
- {
- NodeDataReader cdr = cdNodes.get(cdi);
-
- cdr.forProperty(Constants.JCR_NAME, PropertyType.NAME) // jcr:name
- .forProperty(Constants.JCR_REQUIREDPRIMARYTYPES, PropertyType.NAME)
- // jcr:requiredPrimaryTypes
- .forProperty(Constants.JCR_AUTOCREATED, PropertyType.BOOLEAN)
- // jcr:autoCreated
- .forProperty(Constants.JCR_MANDATORY, PropertyType.BOOLEAN)
- // jcr:mandatory
- .forProperty(Constants.JCR_PROTECTED, PropertyType.BOOLEAN)
- // jcr:protected
- .forProperty(Constants.JCR_ONPARENTVERSION, PropertyType.STRING)
- // jcr:onParentVersion
- .forProperty(Constants.JCR_SAMENAMESIBLINGS, PropertyType.STRING)
- // jcr:sameNameSiblings
- .forProperty(Constants.JCR_DEFAULTPRIMNARYTYPE, PropertyType.NAME); // jcr
- // :
- // defaultPrimaryType
- cdr.read();
-
- InternalQName nname;
- try
- {
- nname = ValueDataConvertor.readQName(cdr.getPropertyValue(Constants.JCR_NAME));
- }
- catch (PathNotFoundException e)
- {
- nname = null; // residual
- }
- catch (IllegalNameException e)
- {
- LOG.error("Child node definition name is not valid. " + e + ". NodeType "
- + ntName.getAsString() + " skipped.");
- continue nextNodeType;
- }
-
- InternalQName defaultNodeTypeName;
- try
- {
- try
- {
- defaultNodeTypeName =
- ValueDataConvertor.readQName(cdr.getPropertyValue(Constants.JCR_DEFAULTPRIMNARYTYPE));
- }
- catch (IllegalNameException e)
- {
- LOG.error("Child node default nodetype name is not valid. " + e + ". NodeType "
- + ntName.getAsString() + " skipped.");
- continue nextNodeType;
- }
- }
- catch (PathNotFoundException e)
- {
- defaultNodeTypeName = null;
- }
-
- List<ValueData> requiredNodeTypesValues =
- cdr.getPropertyValues(Constants.JCR_REQUIREDPRIMARYTYPES);
- InternalQName[] requiredNodeTypes = new InternalQName[requiredNodeTypesValues.size()];
- try
- {
- for (int j = 0; j < requiredNodeTypesValues.size(); j++)
- requiredNodeTypes[j] = ValueDataConvertor.readQName(requiredNodeTypesValues.get(j));
- }
- catch (IllegalNameException e)
- {
- LOG.error("Child node required nodetype name is not valid. " + e + ". NodeType "
- + ntName.getAsString() + " skipped.");
- continue nextNodeType;
- }
-
- NodeDefinitionData nDef =
- new NodeDefinitionData(nname, ntName, ValueDataConvertor.readBoolean(cdr
- .getPropertyValue(Constants.JCR_AUTOCREATED)), ValueDataConvertor.readBoolean(cdr
- .getPropertyValue(Constants.JCR_MANDATORY)), OnParentVersionAction
- .valueFromName(ValueDataConvertor.readString(cdr
- .getPropertyValue(Constants.JCR_ONPARENTVERSION))), ValueDataConvertor.readBoolean(cdr
- .getPropertyValue(Constants.JCR_PROTECTED)), requiredNodeTypes, defaultNodeTypeName,
- ValueDataConvertor.readBoolean(cdr.getPropertyValue(Constants.JCR_SAMENAMESIBLINGS)));
-
- declaredChildNodesDefs[cdi] = nDef;
-
- if (LOG.isDebugEnabled())
- LOG.debug("Child nodes definitions readed "
- + (nname != null ? nname.getAsString() : Constants.JCR_ANY_NAME.getAsString()) + " "
- + (System.currentTimeMillis() - ntStart));
- }
-
- declaredChildNodes = declaredChildNodesDefs;
- }
- catch (PathNotFoundException e)
- {
- if (LOG.isDebugEnabled())
- LOG.debug("Child nodes definitions not found. " + e + ". NodeType " + ntName.getAsString());
-
- declaredChildNodes = new NodeDefinitionData[]{};
- }
-
- // -------- NodeType done --------
- NodeTypeData ntype =
- new NodeTypeData(ntName, primaryItemName, mixin, hasOrderableChilds, declaredSupertypes,
- declaredProperties, declaredChildNodes);
- loadedList.add(ntype);
-
- if (LOG.isDebugEnabled())
- LOG.debug("NodeType " + ntype.getName().getAsString() + " readed. "
- + (System.currentTimeMillis() - ntStart) + " ms");
-
- }
- catch (IOException e)
- {
- LOG.error("Error of NodeType " + (ntName != null ? ntName.getAsString() : "") + " load. " + e);
- }
- }
-
- if (LOG.isDebugEnabled())
- LOG.debug("<<< Node types registration cycle finished. " + (System.currentTimeMillis() - cycleStart)
- + " ms");
-
- return loadedList;
- }
- else
- {
- LOG.warn("Nodetypes storage (/jcr:system/jcr:nodetypes node) is not initialized. No nodetypes loaded.");
- return new ArrayList<NodeTypeData>();
- }
- }
-
- public List<ItemState> removeNodeType(NodeTypeData nodeType) throws RepositoryException
- {
- if (!isInitialized())
- {
- LOG.warn("Nodetypes storage (/jcr:system/jcr:nodetypes node) is not initialized.");
- return new ArrayList<ItemState>();
- }
- NodeData nodeTypeData = (NodeData)dataManager.getItemData(ntRoot, new QPathEntry(nodeType.getName(), 0));
- ItemDataRemoveVisitor removeVisitor = new ItemDataRemoveVisitor(dataManager, ntRoot.getQPath());
- nodeTypeData.accept(removeVisitor);
- return removeVisitor.getRemovedStates();
- }
-
- public void saveChanges(PlainChangesLog changesLog) throws RepositoryException, InvalidItemStateException
- {
- dataManager.save(new TransactionChangesLog(changesLog));
- }
-
- DataManager getDataManager()
- {
- return dataManager;
- }
-
- boolean isInitialized()
- {
- return ntRoot != null;
- }
-
- private List<NodeDataReader> getNodeTypesData(InternalQName nodeTypeName) throws RepositoryException
- {
-
- NodeDataReader ntReader = new NodeDataReader(ntRoot, dataManager);
- ntReader.forNode(nodeTypeName);
- ntReader.read();
-
- ntReader.getNodes(nodeTypeName);
-
- return ntReader.getNodes(nodeTypeName);
- }
-
- private List<ItemState> initNodeDefProps(NodeData parent, NodeDefinitionData def) throws ValueFormatException,
- RepositoryException
- {
- List<ItemState> changes = new ArrayList<ItemState>();
- if (def.getName() != null)
- { // Mandatory false
- TransientPropertyData name =
- TransientPropertyData.createPropertyData(parent, Constants.JCR_NAME, PropertyType.NAME, false);
- name.setValue(new TransientValueData(def.getName()));
- changes.add(ItemState.createAddedState(name));
- }
-
- TransientPropertyData autoCreated =
- TransientPropertyData.createPropertyData(parent, Constants.JCR_AUTOCREATED, PropertyType.BOOLEAN, false);
- autoCreated.setValue(new TransientValueData(def.isAutoCreated()));
-
- TransientPropertyData isMandatory =
- TransientPropertyData.createPropertyData(parent, Constants.JCR_MANDATORY, PropertyType.BOOLEAN, false);
- isMandatory.setValue(new TransientValueData(def.isMandatory()));
-
- TransientPropertyData onParentVersion =
- TransientPropertyData.createPropertyData(parent, Constants.JCR_ONPARENTVERSION, PropertyType.STRING, false);
- onParentVersion.setValue(new TransientValueData(OnParentVersionAction.nameFromValue(def.getOnParentVersion())));
-
- TransientPropertyData isProtected =
- TransientPropertyData.createPropertyData(parent, Constants.JCR_PROTECTED, PropertyType.BOOLEAN, false);
- isProtected.setValue(new TransientValueData(def.isProtected()));
-
- TransientPropertyData sameNameSiblings =
- TransientPropertyData.createPropertyData(parent, Constants.JCR_SAMENAMESIBLINGS, PropertyType.BOOLEAN, false);
- sameNameSiblings.setValue(new TransientValueData(def.isAllowsSameNameSiblings()));
-
- if (def.getDefaultPrimaryType() != null)
- { // Mandatory false
- TransientPropertyData defaultPrimaryType =
- TransientPropertyData.createPropertyData(parent, Constants.JCR_DEFAULTPRIMNARYTYPE, PropertyType.NAME,
- false);
- defaultPrimaryType.setValue(new TransientValueData(def.getDefaultPrimaryType()));
- changes.add(ItemState.createAddedState(defaultPrimaryType));
- }
-
- changes.add(ItemState.createAddedState(autoCreated));
- changes.add(ItemState.createAddedState(isMandatory));
- changes.add(ItemState.createAddedState(onParentVersion));
- changes.add(ItemState.createAddedState(isProtected));
- changes.add(ItemState.createAddedState(sameNameSiblings));
-
- if (def.getRequiredPrimaryTypes() != null && def.getRequiredPrimaryTypes().length != 0)
- {
- List<ValueData> requiredPrimaryTypesValues = new ArrayList<ValueData>();
- for (InternalQName rpt : def.getRequiredPrimaryTypes())
- requiredPrimaryTypesValues.add(new TransientValueData(rpt));
-
- TransientPropertyData requiredPrimaryTypes =
- TransientPropertyData.createPropertyData(parent, Constants.JCR_REQUIREDPRIMARYTYPES, PropertyType.NAME,
- true);
- requiredPrimaryTypes.setValues(requiredPrimaryTypesValues);
- changes.add(ItemState.createAddedState(requiredPrimaryTypes));
- }
- return changes;
- }
-
- private List<ItemState> initPropertyDefProps(NodeData parent, PropertyDefinitionData def)
- throws ValueFormatException, RepositoryException
- {
- List<ItemState> changes = new ArrayList<ItemState>();
- if (def.getName() != null)
- {
- TransientPropertyData name =
- TransientPropertyData.createPropertyData(parent, Constants.JCR_NAME, PropertyType.NAME, false);
- name.setValue(new TransientValueData(def.getName()));
- changes.add(ItemState.createAddedState(name));
- }
-
- TransientPropertyData autoCreated =
- TransientPropertyData.createPropertyData(parent, Constants.JCR_AUTOCREATED, PropertyType.BOOLEAN, false);
- autoCreated.setValue(new TransientValueData(def.isAutoCreated()));
-
- TransientPropertyData isMandatory =
- TransientPropertyData.createPropertyData(parent, Constants.JCR_MANDATORY, PropertyType.BOOLEAN, false);
- isMandatory.setValue(new TransientValueData(def.isMandatory()));
-
- TransientPropertyData onParentVersion =
- TransientPropertyData.createPropertyData(parent, Constants.JCR_ONPARENTVERSION, PropertyType.STRING, false);
- onParentVersion.setValue(new TransientValueData(OnParentVersionAction.nameFromValue(def.getOnParentVersion())));
-
- TransientPropertyData isProtected =
- TransientPropertyData.createPropertyData(parent, Constants.JCR_PROTECTED, PropertyType.BOOLEAN, false);
- isProtected.setValue(new TransientValueData(def.isProtected()));
-
- TransientPropertyData requiredType =
- TransientPropertyData.createPropertyData(parent, Constants.JCR_REQUIREDTYPE, PropertyType.STRING, false);
- requiredType.setValue(new TransientValueData(ExtendedPropertyType.nameFromValue(def.getRequiredType())));
-
- TransientPropertyData isMultiple =
- TransientPropertyData.createPropertyData(parent, Constants.JCR_MULTIPLE, PropertyType.BOOLEAN, false);
- isMultiple.setValue(new TransientValueData(def.isMultiple()));
-
- changes.add(ItemState.createAddedState(autoCreated));
- changes.add(ItemState.createAddedState(isMandatory));
- changes.add(ItemState.createAddedState(onParentVersion));
- changes.add(ItemState.createAddedState(isProtected));
- changes.add(ItemState.createAddedState(requiredType));
- changes.add(ItemState.createAddedState(isMultiple));
-
- if (def.getValueConstraints() != null && def.getValueConstraints().length != 0)
- {
- List<ValueData> valueConstraintsValues = new ArrayList<ValueData>();
- for (String vc : def.getValueConstraints())
- valueConstraintsValues.add(new TransientValueData(vc));
-
- TransientPropertyData valueConstraints =
- TransientPropertyData.createPropertyData(parent, Constants.JCR_VALUECONSTRAINTS, PropertyType.STRING, true);
- valueConstraints.setValues(valueConstraintsValues);
- changes.add(ItemState.createAddedState(valueConstraints));
- }
-
- if (def.getDefaultValues() != null && def.getDefaultValues().length != 0)
- {
- List<ValueData> defaultValuesValues = new ArrayList<ValueData>();
- for (String dv : def.getDefaultValues())
- {
- if (dv != null) // TODO dv can be null?
- defaultValuesValues.add(new TransientValueData(dv));
- }
- TransientPropertyData defaultValues =
- TransientPropertyData.createPropertyData(parent, Constants.JCR_DEFAULTVALUES, PropertyType.STRING, true);
- defaultValues.setValues(defaultValuesValues);
- changes.add(ItemState.createAddedState(defaultValues));
- }
-
- return changes;
- }
-
-}
Added: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/NodeTypeDefinitionImpl.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/NodeTypeDefinitionImpl.java (rev 0)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/NodeTypeDefinitionImpl.java 2009-10-04 09:34:54 UTC (rev 199)
@@ -0,0 +1,241 @@
+/*
+ * 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.nodetype;
+
+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.impl.core.LocationFactory;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.ValueFactory;
+import javax.jcr.nodetype.NodeDefinition;
+
+import javax.jcr.nodetype.PropertyDefinition;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * @author <a href="mailto:Sergey.Kabashnyuk at gmail.com">Sergey Kabashnyuk</a>
+ * @version $Id: $
+ */
+public class NodeTypeDefinitionImpl
+{
+ /**
+ * Class logger.
+ */
+ private static final Log LOG = ExoLogger.getLogger(NodeTypeDefinitionImpl.class);
+
+ protected NodeTypeData nodeTypeData;
+
+ protected final NodeTypeDataManager nodeTypeDataManager;
+
+ protected final LocationFactory locationFactory;
+
+ protected final ExtendedNodeTypeManager nodeTypeManager;
+
+ protected final ValueFactory valueFactory;
+
+ /**
+ * @param name
+ * @param declaredChildNodeDefinitions
+ * @param declaredPropertyDefinitions
+ * @param declaredSupertypeNames
+ * @param isAbstract
+ * @param isMixin
+ * @param orderableChildNodes
+ * @param primaryItemName
+ */
+ public NodeTypeDefinitionImpl(NodeTypeData nodeTypeData, NodeTypeDataManager nodeTypeDataManager,
+ ExtendedNodeTypeManager nodeTypeManager, LocationFactory locationFactory, ValueFactory valueFactory)
+ {
+ super();
+ this.nodeTypeData = nodeTypeData;
+ this.nodeTypeDataManager = nodeTypeDataManager;
+ this.nodeTypeManager = nodeTypeManager;
+ this.locationFactory = locationFactory;
+ this.valueFactory = valueFactory;
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ {
+ return true;
+ }
+ if (obj == null)
+ {
+ return false;
+ }
+ if (!(obj instanceof NodeTypeDefinitionImpl))
+ {
+ return false;
+ }
+ NodeTypeDefinitionImpl other = (NodeTypeDefinitionImpl)obj;
+ if (nodeTypeData == null)
+ {
+ if (other.nodeTypeData != null)
+ {
+ return false;
+ }
+ }
+ else if (!nodeTypeData.equals(other.nodeTypeData))
+ {
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public NodeDefinition[] getDeclaredChildNodeDefinitions()
+ {
+ NodeDefinition[] result = new NodeDefinition[nodeTypeData.getDeclaredChildNodeDefinitions().length];
+ for (int i = 0; i < nodeTypeData.getDeclaredChildNodeDefinitions().length; i++)
+ {
+ result[i] =
+ new NodeDefinitionImpl(nodeTypeData.getDeclaredChildNodeDefinitions()[i], nodeTypeDataManager,
+ nodeTypeManager, locationFactory, valueFactory);
+ }
+ return result;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public PropertyDefinition[] getDeclaredPropertyDefinitions()
+ {
+ PropertyDefinition[] result = new PropertyDefinition[nodeTypeData.getDeclaredPropertyDefinitions().length];
+ for (int i = 0; i < nodeTypeData.getDeclaredPropertyDefinitions().length; i++)
+ {
+ result[i] =
+ new PropertyDefinitionImpl(nodeTypeData.getDeclaredPropertyDefinitions()[i], nodeTypeDataManager,
+ nodeTypeManager, locationFactory, valueFactory);
+ }
+ return result;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String[] getDeclaredSupertypeNames()
+ {
+ String[] result = new String[nodeTypeData.getDeclaredSupertypeNames().length];
+ try
+ {
+ for (int i = 0; i < nodeTypeData.getDeclaredSupertypeNames().length; i++)
+ {
+ result[i] = locationFactory.createJCRName(nodeTypeData.getDeclaredSupertypeNames()[i]).getAsString();
+ }
+
+ }
+ catch (RepositoryException e)
+ {
+ LOG.error(e.getLocalizedMessage(), e);
+ }
+ return result;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getName()
+ {
+ String result = "";
+ try
+ {
+ result = locationFactory.createJCRName(nodeTypeData.getName()).getAsString();
+ }
+ catch (RepositoryException e)
+ {
+ LOG.error(e.getLocalizedMessage(), e);
+ }
+ return result;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getPrimaryItemName()
+ {
+ String result = "";
+ try
+ {
+ result = locationFactory.createJCRName(nodeTypeData.getPrimaryItemName()).getAsString();
+ }
+ catch (RepositoryException e)
+ {
+ LOG.error(e.getLocalizedMessage(), e);
+ }
+ return result;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int hashCode()
+ {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((nodeTypeData == null) ? 0 : nodeTypeData.hashCode());
+ return result;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean hasOrderableChildNodes()
+ {
+ return nodeTypeData.hasOrderableChildNodes();
+ }
+
+// /**
+// * {@inheritDoc}
+// */
+// public boolean isAbstract()
+// {
+// return nodeTypeData.isAbstract();
+// }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isMixin()
+ {
+ return nodeTypeData.isMixin();
+ }
+
+// /**
+// * {@inheritDoc}
+// */
+// public boolean isQueryable()
+// {
+// return nodeTypeData.isQueryable();
+// }
+
+}
Property changes on: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/NodeTypeDefinitionImpl.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/NodeTypeExistsException.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/NodeTypeExistsException.java (rev 0)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/NodeTypeExistsException.java 2009-10-04 09:34:54 UTC (rev 199)
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2009 Day Management AG, Switzerland. All rights reserved.
+ */
+package org.exoplatform.services.jcr.impl.core.nodetype;
+
+import javax.jcr.RepositoryException;
+
+/**
+ * Exception thrown when an attempt is made to register a node type that already
+ * exists, and <code>allowUpdate</code> has not been set to <code>true</code>.
+ *
+ * @since JCR 2.0
+ */
+public class NodeTypeExistsException extends RepositoryException {
+ /**
+ * Constructs a new instance of this class with <code>null</code> as its
+ * detail message.
+ */
+ public NodeTypeExistsException() {
+ super();
+ }
+
+ /**
+ * Constructs a new instance of this class with the specified detail
+ * message.
+ *
+ * @param message the detail message. The detail message is saved for later
+ * retrieval by the {@link #getMessage()} method.
+ */
+ public NodeTypeExistsException(String message) {
+ super(message);
+ }
+
+ /**
+ * Constructs a new instance of this class with the specified detail message
+ * and root cause.
+ *
+ * @param message the detail message. The detail message is saved for later
+ * retrieval by the {@link #getMessage()} method.
+ * @param rootCause root failure cause
+ */
+ public NodeTypeExistsException(String message, Throwable rootCause) {
+ super(message, rootCause);
+ }
+
+ /**
+ * Constructs a new instance of this class with the specified root cause.
+ *
+ * @param rootCause root failure cause
+ */
+ public NodeTypeExistsException(Throwable rootCause) {
+ super(rootCause);
+ }
+}
Property changes on: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/NodeTypeExistsException.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/NodeTypeImpl.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/NodeTypeImpl.java 2009-10-02 15:41:14 UTC (rev 198)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/NodeTypeImpl.java 2009-10-04 09:34:54 UTC (rev 199)
@@ -58,36 +58,27 @@
* Nedonosko</a>
* @version $Id: NodeTypeImpl.java 111 2008-11-11 11:11:11Z pnedonosko $
*/
-public class NodeTypeImpl implements NodeType
+public class NodeTypeImpl extends NodeTypeDefinitionImpl implements NodeType
{
+ /**
+ * Logger.
+ */
+ protected static final Log LOG = ExoLogger.getLogger("jcr.NodeTypeImpl");
- private static final Log LOG = ExoLogger.getLogger("jcr.NodeTypeImpl");
-
- protected final NodeTypeData nodeTypeData;
-
- protected final NodeTypeDataManager nodeTypeDataManager;
-
- protected final ExtendedNodeTypeManager nodeTypeManager;
-
- protected final LocationFactory locationFactory;
-
- protected final ValueFactory valueFactory;
-
/**
* @param nodeTypeData
* @param nodeTypeDataManager
* @param nodeTypeManager
* @param locationFactory
* @param valueFactory
+ * @throws RepositoryException
+ * @throws NodeTypeReadException
*/
public NodeTypeImpl(NodeTypeData nodeTypeData, NodeTypeDataManager nodeTypeDataManager,
ExtendedNodeTypeManager nodeTypeManager, LocationFactory locationFactory, ValueFactory valueFactory)
{
- this.nodeTypeData = nodeTypeData;
- this.nodeTypeDataManager = nodeTypeDataManager;
- this.nodeTypeManager = nodeTypeManager;
- this.locationFactory = locationFactory;
- this.valueFactory = valueFactory;
+ super(nodeTypeData, nodeTypeDataManager, nodeTypeManager, locationFactory, valueFactory);
+
}
/**
@@ -100,7 +91,7 @@
{
InternalQName cname = locationFactory.parseJCRName(childNodeName).getInternalName();
- NodeDefinitionData childNodeDef = nodeTypeDataManager.findChildNodeDefinition(cname, nodeTypeData.getName());
+ NodeDefinitionData childNodeDef = nodeTypeDataManager.getChildNodeDefinition(cname, nodeTypeData.getName());
return !(childNodeDef == null || childNodeDef.isProtected() || childNodeDef.getDefaultPrimaryType() == null);
}
catch (RepositoryException e)
@@ -121,7 +112,7 @@
InternalQName ntname = locationFactory.parseJCRName(nodeTypeName).getInternalName();
NodeDefinitionData childNodeDef =
- nodeTypeDataManager.findChildNodeDefinition(cname, ntname, nodeTypeData.getName());
+ nodeTypeDataManager.getChildNodeDefinition(cname, ntname, nodeTypeData.getName());
return !(childNodeDef == null || childNodeDef.isProtected()) && isChildNodePrimaryTypeAllowed(nodeTypeName);
}
catch (RepositoryException e)
@@ -148,7 +139,7 @@
if (pd != null)
return !(pd.isMandatory() || pd.isProtected());
}
- NodeDefinitionData cndef = nodeTypeDataManager.findChildNodeDefinition(iname, nodeTypeData.getName());
+ NodeDefinitionData cndef = nodeTypeDataManager.getChildNodeDefinition(iname, nodeTypeData.getName());
if (cndef != null)
return !(cndef.isMandatory() || cndef.isProtected());
@@ -249,23 +240,15 @@
for (int i = 0; i < nodeDefs.length; i++)
{
NodeDefinitionData cnd = nodeDefs[i];
- try
- {
- ndefs[i] = makeNodeDefinition(cnd);
- }
- catch (NoSuchNodeTypeException e)
- {
- LOG.error("Node type not found " + e, e);
- }
- catch (RepositoryException e)
- {
- LOG.error("Error of declared child node definition create " + e, e);
- }
+ ndefs[i] = new NodeDefinitionImpl(cnd, nodeTypeDataManager, nodeTypeManager, locationFactory, valueFactory);
}
return ndefs;
}
+ /**
+ * {@inheritDoc}
+ */
public NodeDefinition[] getDeclaredChildNodeDefinitions()
{
NodeDefinitionData[] cndefs = nodeTypeData.getDeclaredChildNodeDefinitions();
@@ -273,97 +256,21 @@
for (int i = 0; i < cndefs.length; i++)
{
NodeDefinitionData cnd = cndefs[i];
- try
- {
- ndefs[i] = makeNodeDefinition(cnd);
- }
- catch (NoSuchNodeTypeException e)
- {
- LOG.error("Node type not found " + e, e);
- }
- catch (RepositoryException e)
- {
- LOG.error("Error of declared child node definition create " + e, e);
- }
+ ndefs[i] = new NodeDefinitionImpl(cnd, nodeTypeDataManager, nodeTypeManager, locationFactory, valueFactory);
}
return ndefs;
}
- private NodeDefinition makeNodeDefinition(NodeDefinitionData data) throws NoSuchNodeTypeException,
- RepositoryException
- {
- InternalQName[] rnames = data.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(data.getName() != null ? data.getName() : Constants.JCR_ANY_NAME).getAsString();
- NodeType defType =
- data.getDefaultPrimaryType() != null ? nodeTypeManager.findNodeType(data.getDefaultPrimaryType()) : null;
- return new NodeDefinitionImpl(name, this, rnts, defType, data.isAutoCreated(), data.isMandatory(), data
- .getOnParentVersion(), data.isProtected(), data.isAllowsSameNameSiblings());
- }
-
+ /**
+ * {@inheritDoc}
+ */
public PropertyDefinition[] getDeclaredPropertyDefinitions()
{
PropertyDefinitionData[] pdefs = nodeTypeData.getDeclaredPropertyDefinitions();
return getPropertyDefinition(pdefs);
}
- private PropertyDefinition[] getPropertyDefinition(PropertyDefinitionData[] pdefs)
- {
- PropertyDefinition[] propertyDefinitions = new PropertyDefinition[pdefs.length];
- // TODO same in PropertyImpl
- for (int i = 0; i < pdefs.length; i++)
- {
-
- try
- {
- PropertyDefinitionData propertyDef = pdefs[i];
- String name =
- locationFactory.createJCRName(
- propertyDef.getName() != null ? propertyDef.getName() : Constants.JCR_ANY_NAME).getAsString();
-
- Value[] defaultValues = new Value[propertyDef.getDefaultValues().length];
- String[] propVal = propertyDef.getDefaultValues();
- // there can be null in definition but should not be null value
- if (propVal != null)
- {
- for (int j = 0; j < propVal.length; j++)
- {
- if (propertyDef.getRequiredType() == PropertyType.UNDEFINED)
- defaultValues[j] = valueFactory.createValue(propVal[j]);
- else
- defaultValues[j] = valueFactory.createValue(propVal[j], propertyDef.getRequiredType());
- }
- }
-
- propertyDefinitions[i] =
- new PropertyDefinitionImpl(name, nodeTypeManager.findNodeType(propertyDef.getDeclaringNodeType()),
- propertyDef.getRequiredType(), propertyDef.getValueConstraints(), defaultValues, propertyDef
- .isAutoCreated(), propertyDef.isMandatory(), propertyDef.getOnParentVersion(), propertyDef
- .isProtected(), propertyDef.isMultiple());
- }
- catch (ValueFormatException e)
- {
- e.printStackTrace();
- }
- catch (NoSuchNodeTypeException e)
- {
- e.printStackTrace();
- }
- catch (RepositoryException e)
- {
- e.printStackTrace();
- }
- }
- return propertyDefinitions;
- }
-
public NodeType[] getDeclaredSupertypes()
{
InternalQName[] snames = nodeTypeData.getDeclaredSupertypeNames();
@@ -372,14 +279,17 @@
for (int i = 0; i < snames.length; i++)
{
+ NodeTypeData superNodeTypeData = nodeTypeDataManager.getNodeType(snames[i]);
supers[i] =
- new NodeTypeImpl(nodeTypeDataManager.findNodeType(snames[i]), nodeTypeDataManager, nodeTypeManager,
- locationFactory, valueFactory);
+ new NodeTypeImpl(superNodeTypeData, nodeTypeDataManager, nodeTypeManager, locationFactory, valueFactory);
}
return supers;
}
+ /**
+ * {@inheritDoc}
+ */
public String getName()
{
try
@@ -393,6 +303,9 @@
}
}
+ /**
+ * {@inheritDoc}
+ */
public String getPrimaryItemName()
{
try
@@ -409,6 +322,9 @@
}
}
+ /**
+ * {@inheritDoc}
+ */
public PropertyDefinition[] getPropertyDefinitions()
{
PropertyDefinitionData[] propertyDefs = nodeTypeDataManager.getAllPropertyDefinitions(nodeTypeData.getName());
@@ -418,6 +334,14 @@
/**
* {@inheritDoc}
*/
+ public InternalQName getQName()
+ {
+ return nodeTypeData.getName();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public NodeType[] getSupertypes()
{
Set<InternalQName> supers = nodeTypeDataManager.getSupertypes(nodeTypeData.getName());
@@ -441,60 +365,64 @@
return superTypes;
}
+ /**
+ * {@inheritDoc}
+ */
public boolean hasOrderableChildNodes()
{
return nodeTypeData.hasOrderableChildNodes();
}
- public boolean isMixin()
+ public boolean isChildNodePrimaryTypeAllowed(String typeName)
{
- return nodeTypeData.isMixin();
- }
-
- public boolean isNodeType(String nodeTypeName)
- {
try
{
- return nodeTypeDataManager.isNodeType(locationFactory.parseJCRName(nodeTypeName).getInternalName(),
- nodeTypeData.getName());
+ InternalQName iname = locationFactory.parseJCRName(typeName).getInternalName();
+
+ return nodeTypeDataManager.isChildNodePrimaryTypeAllowed(iname, nodeTypeData.getName(), new InternalQName[0]);
}
catch (RepositoryException e)
{
- throw new RuntimeException("Wrong nodetype name " + e, e);
+ return false;
}
}
/**
* {@inheritDoc}
*/
- public InternalQName getQName()
+ public boolean isMixin()
{
- return nodeTypeData.getName();
+ return nodeTypeData.isMixin();
}
- public boolean isChildNodePrimaryTypeAllowed(String typeName)
+ public boolean isNodeType(InternalQName nodeTypeQName)
{
+ return nodeTypeDataManager.isNodeType(nodeTypeQName, nodeTypeData.getName(), new InternalQName[0]);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isNodeType(String nodeTypeName)
+ {
try
{
- InternalQName iname = locationFactory.parseJCRName(typeName).getInternalName();
-
- return nodeTypeDataManager.isChildNodePrimaryTypeAllowed(iname, nodeTypeData.getName(), new InternalQName[0]);
+ return nodeTypeDataManager.isNodeType(locationFactory.parseJCRName(nodeTypeName).getInternalName(),
+ nodeTypeData.getName());
}
catch (RepositoryException e)
{
- return false;
+ throw new RuntimeException("Wrong nodetype name " + e, e);
}
}
- public boolean isNodeType(InternalQName nodeTypeQName)
- {
- return nodeTypeDataManager.isNodeType(nodeTypeQName, nodeTypeData.getName(), new InternalQName[0]);
- }
-
- // internal stuff ============================
-
/**
- * Ported from 1.10. Check on empty value (property remove) removed.
+ * Returns true if satisfy type and constrains. Otherwise returns false.
+ *
+ * @param requiredType - type.
+ * @param value - value.
+ * @param constrains - constrains.
+ * @return a boolean.
*/
private boolean canSetPropertyForType(int requiredType, Value value, String[] constrains)
{
@@ -765,6 +693,13 @@
}
}
+ /**
+ * Check value constrains.
+ *
+ * @param constraints - string constrains.
+ * @param value - value to check.
+ * @return result of check.
+ */
private boolean checkValueConstraints(String[] constraints, Value value)
{
@@ -819,6 +754,21 @@
}
}
+ /**
+ * @param pdefs
+ * @return
+ */
+ private PropertyDefinition[] getPropertyDefinition(PropertyDefinitionData[] pdefs)
+ {
+ PropertyDefinition[] propertyDefinitions = new PropertyDefinition[pdefs.length];
+ for (int i = 0; i < pdefs.length; i++)
+ {
+ propertyDefinitions[i] =
+ new PropertyDefinitionImpl(pdefs[i], nodeTypeDataManager, nodeTypeManager, locationFactory, valueFactory);
+ }
+ return propertyDefinitions;
+ }
+
private boolean isCharsetString(String source, String charSetName)
{
try
@@ -832,4 +782,29 @@
}
}
+ /**
+ * @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/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/NodeTypeManagerImpl.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/NodeTypeManagerImpl.java 2009-10-02 15:41:14 UTC (rev 198)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/NodeTypeManagerImpl.java 2009-10-04 09:34:54 UTC (rev 199)
@@ -83,7 +83,7 @@
public NodeType findNodeType(InternalQName nodeTypeName) throws NoSuchNodeTypeException, RepositoryException
{
- NodeTypeData ntdata = typesManager.findNodeType(nodeTypeName);
+ NodeTypeData ntdata = typesManager.getNodeType(nodeTypeName);
if (ntdata != null)
return new NodeTypeImpl(ntdata, typesManager, this, locationFactory, valueFactory);
@@ -131,22 +131,27 @@
*/
public NodeType getNodeType(final String nodeTypeName) throws NoSuchNodeTypeException, RepositoryException
{
- NodeTypeData ntdata = typesManager.findNodeType(locationFactory.parseJCRName(nodeTypeName).getInternalName());
+ NodeTypeData ntdata = typesManager.getNodeType(locationFactory.parseJCRName(nodeTypeName).getInternalName());
if (ntdata != null)
return new NodeTypeImpl(ntdata, typesManager, this, locationFactory, valueFactory);
throw new NoSuchNodeTypeException("Nodetype not found " + nodeTypeName);
}
- // JSR-170 stuff ================================
- // Extended stuff ================================
+ /**
+ * {@inheritDoc}
+ */
+ public NodeTypeDataManager getNodeTypesHolder() throws RepositoryException
+ {
+ return typesManager;
+ }
/**
* {@inheritDoc}
*/
public NodeTypeValue getNodeTypeValue(String nodeTypeName) throws NoSuchNodeTypeException, RepositoryException
{
- NodeTypeData ntdata = typesManager.findNodeType(locationFactory.parseJCRName(nodeTypeName).getInternalName());
+ NodeTypeData ntdata = typesManager.getNodeType(locationFactory.parseJCRName(nodeTypeName).getInternalName());
if (ntdata != null)
{
NodeTypeValue nodeTypeValue = new NodeTypeValue();
@@ -210,6 +215,11 @@
return ec;
}
+ public boolean hasNodeType(String name) throws RepositoryException
+ {
+
+ return typesManager.getNodeType(locationFactory.parseJCRName(name).getInternalName()) != null;
+ }
/**
* {@inheritDoc}
*/
@@ -248,10 +258,29 @@
*
* @return
*/
+ 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));
+
+ return types;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @return
+ * @deprecated use registerNodeTypes(InputStream xml, int alreadyExistsBehaviour, String contentType)
+ */
+ @Deprecated
public NodeTypeIterator registerNodeTypes(InputStream xml, int alreadyExistsBehaviour) throws RepositoryException
{
- Collection<NodeTypeData> nts = typesManager.registerNodeTypes(xml, alreadyExistsBehaviour);
+ Collection<NodeTypeData> nts = typesManager.registerNodeTypes(xml, alreadyExistsBehaviour, NodeTypeDataManager.TEXT_XML);
EntityCollection types = new EntityCollection();
for (NodeTypeData ntdata : nts)
types.add(new NodeTypeImpl(ntdata, typesManager, this, locationFactory, valueFactory));
@@ -266,7 +295,7 @@
RepositoryException
{
InternalQName nodeTypeName = locationFactory.parseJCRName(name).getInternalName();
- if (typesManager.findNodeType(nodeTypeName) == null)
+ if (typesManager.getNodeType(nodeTypeName) == null)
throw new NoSuchNodeTypeException(name);
typesManager.unregisterNodeType(nodeTypeName);
}
@@ -355,29 +384,24 @@
public int compare(NodeTypeData o1, NodeTypeData o2)
{
- return getIndex(o2.getName().getNamespace()) - getIndex(o1.getName().getNamespace());
+ return getIndex(o2) - getIndex(o1);
}
- private int getIndex(String nameSpace)
+ private int getIndex(NodeTypeData data)
{
+ InternalQName name;
+ int result = OTHER;
+ name = data.getName();
+ String nameSpace = name.getNamespace();
if (Constants.NS_NT_URI.equals(nameSpace))
- return NT;
+ result = NT;
else if (Constants.NS_MIX_URI.equals(nameSpace))
- return MIX;
+ result = MIX;
else if (Constants.NS_JCR_URI.equals(nameSpace))
- return JCR;
+ result = JCR;
else if (Constants.NS_EXO_URI.equals(nameSpace))
- return EXO;
- return OTHER;
+ result = EXO;
+ return result;
}
}
-
- /**
- * {@inheritDoc}
- */
- public NodeTypeDataManager getNodeTypesHolder() throws RepositoryException
- {
- return typesManager;
- }
-
}
Added: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/NodeTypeRepository.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/NodeTypeRepository.java (rev 0)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/NodeTypeRepository.java 2009-10-04 09:34:54 UTC (rev 199)
@@ -0,0 +1,138 @@
+/*
+ * 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.nodetype;
+
+import org.exoplatform.services.jcr.core.ComponentPersister;
+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.core.nodetype.PropertyDefinitionDatas;
+import org.exoplatform.services.jcr.datamodel.InternalQName;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.jcr.RepositoryException;
+
+/**
+ * @author <a href="mailto:Sergey.Kabashnyuk at exoplatform.org">Sergey Kabashnyuk</a>
+ * @version $Id: exo-jboss-codetemplates.xml 34360 2009-07-22 23:58:59Z ksm $
+ *
+ */
+public interface NodeTypeRepository extends ComponentPersister
+{
+
+ /**
+ * @param nodeType
+ * @param volatileNodeTypes
+ * @throws RepositoryException
+ */
+ void addNodeType(NodeTypeData nodeType, Map<InternalQName, NodeTypeData> volatileNodeTypes)
+ throws RepositoryException;
+
+ /**
+ * @return
+ */
+ NodeTypeRepository createCopy();
+
+ /**
+ * @return
+ * @throws RepositoryException
+ */
+ List<NodeTypeData> getAllNodeTypes() throws RepositoryException;
+
+ /**
+ * @param nodeTypeName
+ * @return
+ * @throws RepositoryException
+ */
+ Set<InternalQName> getDeclaredSubtypes(InternalQName nodeTypeName);
+
+ /**
+ * @param nodeName
+ * @param nodeTypeNames
+ * @return
+ * @throws RepositoryException
+ */
+ NodeDefinitionData getDefaultChildNodeDefinition(InternalQName nodeName, InternalQName[] nodeTypeNames)
+ throws RepositoryException;
+
+ /**
+ * @param typeName
+ * @return
+ * @throws RepositoryException
+ */
+ NodeTypeData getNodeType(InternalQName typeName);
+
+ /**
+ * @param propertyName
+ * @param nodeTypeNames
+ * @return
+ * @throws RepositoryException
+ */
+ PropertyDefinitionDatas getPropertyDefinitions(InternalQName propertyName, InternalQName[] nodeTypeNames)
+ throws RepositoryException;
+
+ /**
+ * @param nodeTypeName
+ * @return
+ */
+ Set<InternalQName> getSubtypes(InternalQName nodeTypeName);
+
+ /**
+ * @param ntname
+ * @return
+ */
+ Set<InternalQName> getSupertypes(InternalQName ntname);
+
+ /**
+ * @param testTypeName
+ * @param primaryType
+ * @return
+ */
+ boolean isNodeType(InternalQName testTypeName, InternalQName primaryType);
+
+ /**
+ * @param testTypeName
+ * @param typesNames
+ * @return
+ */
+ boolean isNodeType(InternalQName testTypeName, InternalQName[] typesNames);
+
+ /**
+ * @param nodeTypeName
+ * @param nodeType
+ */
+ void removeNodeType(NodeTypeData nodeType);
+
+ /**
+ * Write node types to stream
+ *
+ * @param os output stream
+ * @param nodeTypes
+ * @throws RepositoryException
+ * @throws IOException
+ * @throws RepositoryException
+ */
+ void registerNodeType(final List<NodeTypeData> nodeTypes, final NodeTypeDataManager nodeTypeDataManager,
+ final String accessControlPolicy, final int alreadyExistsBehaviour) throws RepositoryException;
+
+}
Property changes on: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/NodeTypeRepository.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/PropertyDefinitionImpl.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/PropertyDefinitionImpl.java 2009-10-02 15:41:14 UTC (rev 198)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/PropertyDefinitionImpl.java 2009-10-04 09:34:54 UTC (rev 199)
@@ -18,112 +18,115 @@
*/
package org.exoplatform.services.jcr.impl.core.nodetype;
+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.impl.core.LocationFactory;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+import javax.jcr.PropertyType;
import javax.jcr.Value;
-import javax.jcr.nodetype.NodeType;
+import javax.jcr.ValueFactory;
+import javax.jcr.ValueFormatException;
import javax.jcr.nodetype.PropertyDefinition;
/**
* Created by The eXo Platform SAS.
*
- * @author Gennady Azarenkov
- * @version $Id: PropertyDefinitionImpl.java 11907 2008-03-13 15:36:21Z ksm $
+ * @author <a href="mailto:Sergey.Kabashnyuk at gmail.com">Sergey Kabashnyuk</a>
+ * @version $Id: $
*/
-
public class PropertyDefinitionImpl extends ItemDefinitionImpl implements PropertyDefinition
{
- private final int requiredType;
+ private final PropertyDefinitionData propertyDefinitionData;
- private String[] valueConstraints;
-
- private Value[] defaultValues;
-
- private final boolean multiple;
-
- public PropertyDefinitionImpl(String name, NodeType declaringNodeType, int requiredType, String[] valueConstraints,
- Value[] defaultValues, boolean autoCreate, boolean mandatory, int onVersion, boolean readOnly, boolean multiple)
- {
-
- super(name, declaringNodeType, autoCreate, onVersion, readOnly, mandatory);
-
- this.requiredType = requiredType;
- this.valueConstraints = valueConstraints;
- this.defaultValues = defaultValues;
- this.multiple = multiple;
-
- int hk = 31 * this.hashCode + requiredType;
- hk = 31 * hk + valueConstraints.hashCode();
- hk = 31 * hk + defaultValues.hashCode();
- this.hashCode = 31 * hk + (multiple ? 0 : 1);
- }
-
/**
- * {@inheritDoc}
+ * @param propertyDefinitionData
+ * @param nodeTypeDataManager
+ * @param nodeTypeManager
+ * @param locationFactory
+ * @param valueFactory
*/
- public int getRequiredType()
+ public PropertyDefinitionImpl(PropertyDefinitionData propertyDefinitionData,
+ NodeTypeDataManager nodeTypeDataManager, ExtendedNodeTypeManager nodeTypeManager,
+ LocationFactory locationFactory, ValueFactory valueFactory)
{
- return requiredType;
+ super(propertyDefinitionData, nodeTypeDataManager, nodeTypeManager, locationFactory, valueFactory);
+ this.propertyDefinitionData = propertyDefinitionData;
}
/**
- * {@inheritDoc}
+ * Class logger.
*/
- public String[] getValueConstraints()
- {
- return valueConstraints;
- }
+ private static final Log LOG = ExoLogger.getLogger(PropertyDefinitionImpl.class);
/**
* {@inheritDoc}
*/
public Value[] getDefaultValues()
{
- if (defaultValues != null && defaultValues.length > 0)
- return defaultValues;
- else
+ String[] defaultValues = propertyDefinitionData.getDefaultValues();
+ if (defaultValues == null)
return null;
+ Value[] vals = new Value[defaultValues.length];
+ for (int i = 0; i < defaultValues.length; i++)
+ {
+ if (propertyDefinitionData.getRequiredType() == PropertyType.UNDEFINED)
+ {
+ vals[i] = valueFactory.createValue(defaultValues[i]);
+ }
+ else
+ try
+ {
+ vals[i] = valueFactory.createValue(defaultValues[i], propertyDefinitionData.getRequiredType());
+ }
+ catch (ValueFormatException e)
+ {
+ LOG.error(e.getLocalizedMessage(), e);
+ }
+ }
+ return vals;
}
- /**
- * {@inheritDoc}
- */
- public boolean isMultiple()
+ public int getRequiredType()
{
- return multiple;
+ return propertyDefinitionData.getRequiredType();
}
- /**
- * @param defaultValues
- * The defaultValues to set.
- */
- public void setDefaultValues(Value[] defaultValues)
+ public String[] getValueConstraints()
{
- this.defaultValues = defaultValues;
+ return propertyDefinitionData.getValueConstraints();
}
- /**
- * @param valueConstraints
- * The valueConstraints to set.
- */
- public void setValueConstraints(String[] valueConstraints)
+ public boolean isMultiple()
{
- this.valueConstraints = valueConstraints;
+ return propertyDefinitionData.isMultiple();
}
+//
+// /**
+// * {@inheritDoc}
+// */
+// public String[] getAvailableQueryOperators()
+// {
+// return propertyDefinitionData.getAvailableQueryOperators();
+// }
+//
+// /**
+// * {@inheritDoc}
+// */
+// public boolean isFullTextSearchable()
+// {
+// return propertyDefinitionData.isFullTextSearchable();
+// }
+//
+// /**
+// * {@inheritDoc}
+// */
+// public boolean isQueryOrderable()
+// {
+// return propertyDefinitionData.isQueryOrderable();
+// }
- /**
- * Compare property definitions for equality by name, required type and miltiplicity flag. NOTE:
- * UNDEFINED is equals to UNDEFINED only. NOTE: PD without name is equals to PD without name
- */
- public boolean equals(Object obj)
- {
- if (obj == null)
- return false;
- if (super.equals(obj))
- return true;
- if (obj instanceof PropertyDefinitionImpl)
- {
- return obj.hashCode() == hashCode;
- }
- return false;
- }
}
Modified: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/VolatileNodeTypeDataManager.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/VolatileNodeTypeDataManager.java 2009-10-02 15:41:14 UTC (rev 198)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/VolatileNodeTypeDataManager.java 2009-10-04 09:34:54 UTC (rev 199)
@@ -38,41 +38,41 @@
public class VolatileNodeTypeDataManager extends NodeTypeDataManagerImpl
{
- public VolatileNodeTypeDataManager(NodeTypeDataManagerImpl nodeTypeDataManagerImpl) throws RepositoryException
- {
- super(nodeTypeDataManagerImpl.accessControlPolicy, nodeTypeDataManagerImpl.locationFactory,
- nodeTypeDataManagerImpl.namespaceRegistry, nodeTypeDataManagerImpl.persister,
- nodeTypeDataManagerImpl.indexSearcherHolder);
- this.superNodeTypeDataManager = nodeTypeDataManagerImpl;
- //this.queryHandlers = new HashSet<QueryHandler>(nodeTypeDataManagerImpl.queryHandlers);
-
- registerVolatileNodeTypes(superNodeTypeDataManager.getAllNodeTypes());
- }
-
/**
* Class logger.
*/
private final Log log = ExoLogger.getLogger(VolatileNodeTypeDataManager.class);
- private final NodeTypeDataManagerImpl superNodeTypeDataManager;
+ public VolatileNodeTypeDataManager(final NodeTypeDataManagerImpl nodeTypeDataManagerImpl) throws RepositoryException
+ {
+ super(nodeTypeDataManagerImpl.accessControlPolicy, nodeTypeDataManagerImpl.locationFactory,
+ nodeTypeDataManagerImpl.namespaceRegistry,
+ null, // to be sure
+ nodeTypeDataManagerImpl.dataManager, nodeTypeDataManagerImpl.indexSearcherHolder,
+ nodeTypeDataManagerImpl.nodeTypeRepository.createCopy());
- public void registerVolatileNodeTypes(Collection<NodeTypeData> volatileNodeTypes) throws RepositoryException
+ }
+
+ public void registerVolatileNodeTypes(final Collection<NodeTypeData> volatileNodeTypes) throws RepositoryException
{
- Map<InternalQName, NodeTypeData> map = new HashMap<InternalQName, NodeTypeData>();
- for (NodeTypeData nodeTypeData : volatileNodeTypes)
+ final Map<InternalQName, NodeTypeData> map = new HashMap<InternalQName, NodeTypeData>();
+ for (final NodeTypeData nodeTypeData : volatileNodeTypes)
{
map.put(nodeTypeData.getName(), nodeTypeData);
}
registerVolatileNodeTypes(map);
}
- public void registerVolatileNodeTypes(Map<InternalQName, NodeTypeData> volatileNodeTypes) throws RepositoryException
+ public void registerVolatileNodeTypes(final Map<InternalQName, NodeTypeData> volatileNodeTypes)
+ throws RepositoryException
{
- for (Map.Entry<InternalQName, NodeTypeData> entry : volatileNodeTypes.entrySet())
+ for (final Map.Entry<InternalQName, NodeTypeData> entry : volatileNodeTypes.entrySet())
{
- if (findNodeType(entry.getKey()) != null)
- internalUnregister(entry.getKey(), entry.getValue());
- internalRegister(entry.getValue(), volatileNodeTypes);
+ if (getNodeType(entry.getKey()) != null)
+ {
+ this.nodeTypeRepository.removeNodeType(entry.getValue());
+ }
+ this.nodeTypeRepository.addNodeType(entry.getValue(), volatileNodeTypes);
}
}
Modified: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/AbstractDefinitionComparator.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/AbstractDefinitionComparator.java 2009-10-02 15:41:14 UTC (rev 198)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/AbstractDefinitionComparator.java 2009-10-04 09:34:54 UTC (rev 199)
@@ -20,8 +20,6 @@
import org.exoplatform.services.jcr.core.nodetype.ItemDefinitionData;
import org.exoplatform.services.jcr.core.nodetype.NodeTypeData;
-import org.exoplatform.services.jcr.core.nodetype.NodeTypeDataManager;
-import org.exoplatform.services.jcr.dataflow.DataManager;
import org.exoplatform.services.jcr.dataflow.PlainChangesLog;
import org.exoplatform.services.jcr.datamodel.InternalQName;
import org.exoplatform.services.jcr.impl.Constants;
@@ -39,27 +37,6 @@
*/
public abstract class AbstractDefinitionComparator<T extends ItemDefinitionData>
{
- /**
- * Data manager
- */
- protected final DataManager persister;
-
- /**
- * Node type data manager
- */
- protected final NodeTypeDataManager nodeTypeDataManager;
-
- /**
- * @param nodeTypeDataManager
- * @param persister
- */
- public AbstractDefinitionComparator(NodeTypeDataManager nodeTypeDataManager, DataManager persister)
- {
- super();
- this.nodeTypeDataManager = nodeTypeDataManager;
- this.persister = persister;
- }
-
public abstract PlainChangesLog compare(NodeTypeData registeredNodeType, T[] ancestorDefinition,
T[] recipientDefinition) throws ConstraintViolationException, RepositoryException;
Added: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/AbstractItemDefinitionAccessProvider.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/AbstractItemDefinitionAccessProvider.java (rev 0)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/AbstractItemDefinitionAccessProvider.java 2009-10-04 09:34:54 UTC (rev 199)
@@ -0,0 +1,397 @@
+/*
+ * 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.nodetype.registration;
+
+import org.exoplatform.services.jcr.core.nodetype.ItemDefinitionData;
+import org.exoplatform.services.jcr.dataflow.DataManager;
+import org.exoplatform.services.jcr.dataflow.ItemState;
+import org.exoplatform.services.jcr.dataflow.PlainChangesLog;
+import org.exoplatform.services.jcr.datamodel.IllegalNameException;
+import org.exoplatform.services.jcr.datamodel.InternalQName;
+import org.exoplatform.services.jcr.datamodel.ItemData;
+import org.exoplatform.services.jcr.datamodel.NodeData;
+import org.exoplatform.services.jcr.datamodel.PropertyData;
+import org.exoplatform.services.jcr.datamodel.QPathEntry;
+import org.exoplatform.services.jcr.datamodel.ValueData;
+import org.exoplatform.services.jcr.impl.Constants;
+import org.exoplatform.services.jcr.impl.dataflow.TransientPropertyData;
+import org.exoplatform.services.jcr.impl.dataflow.TransientValueData;
+import org.exoplatform.services.jcr.impl.dataflow.ValueDataConvertor;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+import javax.jcr.version.OnParentVersionAction;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * @author <a href="mailto:Sergey.Kabashnyuk at gmail.com">Sergey Kabashnyuk</a>
+ * @version $Id: $
+ */
+public abstract class AbstractItemDefinitionAccessProvider
+{
+
+ protected final DataManager dataManager;
+
+ public AbstractItemDefinitionAccessProvider(DataManager dataManager)
+ {
+ super();
+ this.dataManager = dataManager;
+ }
+
+ /**
+ * Load values.
+ *
+ * @param parentNode
+ * @param propertyName
+ * @return
+ * @throws RepositoryException
+ */
+ protected List<ValueData> loadPropertyValues(NodeData parentNode, InternalQName propertyName)
+ throws RepositoryException
+ {
+ ItemData property = dataManager.getItemData(parentNode, new QPathEntry(propertyName, 1));
+ if (property != null)
+ {
+ if (property.isNode())
+ throw new RepositoryException("Fail to load property " + propertyName + "not found for "
+ + parentNode.getQPath().getAsString());
+ return ((PropertyData)property).getValues();
+ }
+ return null;
+ }
+
+ public Boolean readBoolean(NodeData parentNode, InternalQName propertyName) throws RepositoryException,
+ NodeTypeReadException
+ {
+ List<ValueData> values = loadPropertyValues(parentNode, propertyName);
+ if (values != null)
+ {
+ if (values.size() == 1)
+ {
+ try
+ {
+ return ValueDataConvertor.readBoolean(values.get(0));
+ }
+ catch (UnsupportedEncodingException e)
+ {
+ throw new NodeTypeReadException(e.getLocalizedMessage(), e.getCause());
+ }
+ catch (IllegalStateException e)
+ {
+ throw new NodeTypeReadException(e.getLocalizedMessage(), e.getCause());
+ }
+ catch (IOException e)
+ {
+ throw new NodeTypeReadException(e.getLocalizedMessage(), e.getCause());
+ }
+ }
+ }
+ return new Boolean(false);
+ }
+
+ public Long readLong(NodeData parentNode, InternalQName propertyName) throws RepositoryException,
+ NodeTypeReadException
+ {
+ List<ValueData> values = loadPropertyValues(parentNode, propertyName);
+ if (values != null)
+ {
+ if (values.size() == 1)
+ {
+ try
+ {
+ return ValueDataConvertor.readLong(values.get(0));
+ }
+ catch (NumberFormatException e)
+ {
+ throw new NodeTypeReadException(e.getLocalizedMessage(), e.getCause());
+ }
+ catch (UnsupportedEncodingException e)
+ {
+ throw new NodeTypeReadException(e.getLocalizedMessage(), e.getCause());
+ }
+ catch (IllegalStateException e)
+ {
+ throw new NodeTypeReadException(e.getLocalizedMessage(), e.getCause());
+ }
+ catch (IOException e)
+ {
+ throw new NodeTypeReadException(e.getLocalizedMessage(), e.getCause());
+ }
+ }
+ }
+ return null;
+ }
+
+ public Boolean readMandatoryBoolean(NodeData parentNode, InternalQName propertyName) throws RepositoryException,
+ NodeTypeReadException
+ {
+ Boolean name = readBoolean(parentNode, propertyName);
+ if (name == null)
+ throw new RepositoryException("Mandatory item " + propertyName + "not found for "
+ + parentNode.getQPath().getAsString());
+ return name;
+ }
+
+ public Long readMandatoryLong(NodeData parentNode, InternalQName propertyName) throws RepositoryException,
+ NodeTypeReadException
+ {
+ Long name = readLong(parentNode, propertyName);
+ if (name == null)
+ throw new RepositoryException("Mandatory item " + propertyName + "not found for "
+ + parentNode.getQPath().getAsString());
+ return name;
+ }
+
+ public InternalQName readMandatoryName(NodeData parentNode, InternalQName propertyName) throws RepositoryException,
+ NodeTypeReadException
+ {
+ InternalQName name = readName(parentNode, propertyName);
+ if (name == null)
+ throw new RepositoryException("Mandatory item " + propertyName + "not found for "
+ + parentNode.getQPath().getAsString());
+ return name;
+ }
+
+ public InternalQName[] readMandatoryNames(NodeData parentNode, InternalQName propertyName)
+ throws RepositoryException, NodeTypeReadException
+ {
+ InternalQName[] names = readNames(parentNode, propertyName);
+ if (names == null)
+ throw new RepositoryException("Mandatory item " + propertyName + "not found for "
+ + parentNode.getQPath().getAsString());
+ return names;
+ }
+
+ public String readMandatoryString(NodeData parentNode, InternalQName propertyName) throws RepositoryException,
+ NodeTypeReadException
+ {
+ String name = readString(parentNode, propertyName);
+ if (name == null)
+ throw new RepositoryException("Mandatory item " + propertyName + "not found for "
+ + parentNode.getQPath().getAsString());
+ return name;
+ }
+
+ public String[] readMandatoryStrings(NodeData parentNode, InternalQName propertyName) throws RepositoryException,
+ NodeTypeReadException
+ {
+ String[] name = readStrings(parentNode, propertyName);
+ if (name == null)
+ throw new RepositoryException("Mandatory item " + propertyName + "not found for "
+ + parentNode.getQPath().getAsString());
+ return name;
+ }
+
+ public InternalQName readName(NodeData parentNode, InternalQName propertyName) throws RepositoryException,
+ NodeTypeReadException
+ {
+ List<ValueData> values = loadPropertyValues(parentNode, propertyName);
+ if (values != null)
+ {
+ if (values.size() == 1)
+ {
+ try
+ {
+ return ValueDataConvertor.readQName(values.get(0));
+ }
+ catch (UnsupportedEncodingException e)
+ {
+ throw new NodeTypeReadException(e.getLocalizedMessage(), e.getCause());
+ }
+ catch (IllegalNameException e)
+ {
+ throw new NodeTypeReadException(e.getLocalizedMessage(), e.getCause());
+ }
+ catch (IOException e)
+ {
+ throw new NodeTypeReadException(e.getLocalizedMessage(), e.getCause());
+ }
+ }
+ }
+ return null;
+ }
+
+ public InternalQName[] readNames(NodeData parentNode, InternalQName propertyName) throws RepositoryException,
+ NodeTypeReadException
+ {
+ List<ValueData> values = loadPropertyValues(parentNode, propertyName);
+ if (values != null)
+ {
+ InternalQName[] result = new InternalQName[values.size()];
+ int i = 0;
+ for (ValueData valueData : values)
+ {
+ try
+ {
+ result[i++] = ValueDataConvertor.readQName(valueData);
+ }
+ catch (UnsupportedEncodingException e)
+ {
+ throw new NodeTypeReadException(e.getLocalizedMessage(), e.getCause());
+ }
+ catch (IllegalNameException e)
+ {
+ throw new NodeTypeReadException(e.getLocalizedMessage(), e.getCause());
+ }
+ catch (IOException e)
+ {
+ throw new NodeTypeReadException(e.getLocalizedMessage(), e.getCause());
+ }
+ }
+ return result;
+ }
+ return new InternalQName[0];
+ }
+
+ public String readString(NodeData parentNode, InternalQName propertyName) throws RepositoryException,
+ NodeTypeReadException
+ {
+ List<ValueData> values = loadPropertyValues(parentNode, propertyName);
+ if (values != null)
+ {
+ if (values.size() == 1)
+ {
+ try
+ {
+ return ValueDataConvertor.readString(values.get(0));
+ }
+ catch (UnsupportedEncodingException e)
+ {
+ throw new NodeTypeReadException(e.getLocalizedMessage(), e.getCause());
+ }
+ catch (IOException e)
+ {
+ throw new NodeTypeReadException(e.getLocalizedMessage(), e.getCause());
+ }
+ }
+ }
+ return null;
+ }
+
+ public String[] readStrings(NodeData parentNode, InternalQName propertyName) throws RepositoryException,
+ NodeTypeReadException
+ {
+ List<ValueData> values = loadPropertyValues(parentNode, propertyName);
+ if (values != null)
+ {
+ if (values.size() > 0)
+ {
+ String[] result = new String[values.size()];
+ int i = 0;
+ for (ValueData valueData : values)
+ {
+ try
+ {
+ result[i++] = ValueDataConvertor.readString(valueData);
+ }
+ catch (UnsupportedEncodingException e)
+ {
+ throw new NodeTypeReadException(e.getLocalizedMessage(), e.getCause());
+ }
+ catch (IOException e)
+ {
+ throw new NodeTypeReadException(e.getLocalizedMessage(), e.getCause());
+ }
+ }
+ return result;
+ }
+ }
+ return new String[0];
+ }
+
+ protected void writeBoolean(PlainChangesLog changesLog, NodeData parentNode, InternalQName propertyName,
+ boolean value)
+ {
+ TransientPropertyData propertyData =
+ TransientPropertyData.createPropertyData(parentNode, propertyName, PropertyType.BOOLEAN, false);
+ propertyData.setValue(new TransientValueData(value));
+ changesLog.add(ItemState.createAddedState(propertyData));
+ }
+
+ protected void writeItemDefinition(PlainChangesLog changesLog, NodeData itemDefinition,
+ ItemDefinitionData nodeDefinitionData)
+ {
+ if (nodeDefinitionData.getName() != null)
+ { // Mandatory false
+
+ writeName(changesLog, itemDefinition, Constants.JCR_NAME, nodeDefinitionData.getName());
+ }
+ writeBoolean(changesLog, itemDefinition, Constants.JCR_PROTECTED, nodeDefinitionData.isProtected());
+
+ writeBoolean(changesLog, itemDefinition, Constants.JCR_AUTOCREATED, nodeDefinitionData.isAutoCreated());
+
+ writeBoolean(changesLog, itemDefinition, Constants.JCR_MANDATORY, nodeDefinitionData.isMandatory());
+
+ writeString(changesLog, itemDefinition, Constants.JCR_ONPARENTVERSION, OnParentVersionAction
+ .nameFromValue(nodeDefinitionData.getOnParentVersion()));
+ }
+
+ protected void writeName(PlainChangesLog changesLog, NodeData parentNode, InternalQName propertyName,
+ InternalQName value)
+ {
+ TransientPropertyData propertyData =
+ TransientPropertyData.createPropertyData(parentNode, propertyName, PropertyType.NAME, false);
+ propertyData.setValue(new TransientValueData(value));
+ changesLog.add(ItemState.createAddedState(propertyData));
+ }
+
+ protected void writeNames(PlainChangesLog changesLog, NodeData parentNode, InternalQName propertyName,
+ InternalQName[] value)
+ {
+ TransientPropertyData propertyData =
+ TransientPropertyData.createPropertyData(parentNode, propertyName, PropertyType.NAME, false);
+
+ List<ValueData> parents = new ArrayList<ValueData>();
+ for (InternalQName nt : value)
+ parents.add(new TransientValueData(nt));
+
+ propertyData.setValues(parents);
+ changesLog.add(ItemState.createAddedState(propertyData));
+ }
+
+ protected void writeString(PlainChangesLog changesLog, NodeData parentNode, InternalQName propertyName, String value)
+ {
+ TransientPropertyData propertyData =
+ TransientPropertyData.createPropertyData(parentNode, propertyName, PropertyType.STRING, false);
+ propertyData.setValue(new TransientValueData(value));
+ changesLog.add(ItemState.createAddedState(propertyData));
+ }
+
+ protected void writeStrings(PlainChangesLog changesLog, NodeData parentNode, InternalQName propertyName,
+ String[] value)
+ {
+ TransientPropertyData propertyData =
+ TransientPropertyData.createPropertyData(parentNode, propertyName, PropertyType.STRING, false);
+ List<ValueData> valueDatas = new ArrayList<ValueData>();
+ for (String vc : value)
+ {
+ if (vc != null)
+ valueDatas.add(new TransientValueData(vc));
+ }
+
+ propertyData.setValues(valueDatas);
+ changesLog.add(ItemState.createAddedState(propertyData));
+ }
+}
Property changes on: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/AbstractItemDefinitionAccessProvider.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/JcrNodeTypeDataPersister.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/JcrNodeTypeDataPersister.java (rev 0)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/JcrNodeTypeDataPersister.java 2009-10-04 09:34:54 UTC (rev 199)
@@ -0,0 +1,413 @@
+/*
+ * 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.
+ */
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * @author <a href="mailto:Sergey.Kabashnyuk at gmail.com">Sergey Kabashnyuk</a>
+ * @version $Id: $
+ */
+package org.exoplatform.services.jcr.impl.core.nodetype.registration;
+
+import org.exoplatform.services.jcr.access.AccessControlEntry;
+import org.exoplatform.services.jcr.access.AccessControlList;
+import org.exoplatform.services.jcr.access.AccessControlPolicy;
+import org.exoplatform.services.jcr.config.RepositoryEntry;
+import org.exoplatform.services.jcr.core.ExtendedPropertyType;
+import org.exoplatform.services.jcr.core.nodetype.NodeTypeData;
+import org.exoplatform.services.jcr.dataflow.DataManager;
+import org.exoplatform.services.jcr.dataflow.ItemState;
+import org.exoplatform.services.jcr.dataflow.ItemStateChangesLog;
+import org.exoplatform.services.jcr.dataflow.PlainChangesLog;
+import org.exoplatform.services.jcr.dataflow.PlainChangesLogImpl;
+import org.exoplatform.services.jcr.dataflow.TransactionChangesLog;
+import org.exoplatform.services.jcr.datamodel.InternalQName;
+import org.exoplatform.services.jcr.datamodel.ItemData;
+import org.exoplatform.services.jcr.datamodel.NodeData;
+import org.exoplatform.services.jcr.datamodel.QPathEntry;
+import org.exoplatform.services.jcr.datamodel.ValueData;
+import org.exoplatform.services.jcr.impl.Constants;
+import org.exoplatform.services.jcr.impl.dataflow.ItemDataRemoveVisitor;
+import org.exoplatform.services.jcr.impl.dataflow.TransientNodeData;
+import org.exoplatform.services.jcr.impl.dataflow.TransientPropertyData;
+import org.exoplatform.services.jcr.impl.dataflow.TransientValueData;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+import javax.jcr.nodetype.NoSuchNodeTypeException;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * @author <a href="mailto:Sergey.Kabashnyuk at gmail.com">Sergey Kabashnyuk</a>
+ * @version $Id: $
+ */
+public class JcrNodeTypeDataPersister implements NodeTypeDataPersister
+{
+
+ protected final Log log = ExoLogger.getLogger(getClass().getName());
+
+ private final DataManager dataManager;
+
+ private NodeData nodeTypeStorageRoot;
+
+ private final NodeTypeDefinitionAccessProvider definitionAccessProvider;
+
+ private final boolean addACL;
+
+ private boolean started = false;
+
+ // /**
+ // * ChangesLog Buffer (used for saves before start).
+ // */
+ // private List<ItemStateChangesLog> changesLogBuffer = new ArrayList<ItemStateChangesLog>();
+
+ /**
+ * @param dataManager
+ * @throws RepositoryException
+ */
+ public JcrNodeTypeDataPersister(DataManager dataManager, boolean addACL) throws RepositoryException
+ {
+ super();
+ this.dataManager = dataManager;
+ this.addACL = addACL;
+
+ this.definitionAccessProvider = new NodeTypeDefinitionAccessProvider(dataManager);
+ }
+
+ /**
+ * @param dataManager
+ * @throws RepositoryException
+ */
+ public JcrNodeTypeDataPersister(DataManager dataManager, NodeData nodeTypeStorageRoot) throws RepositoryException
+ {
+ super();
+ this.dataManager = dataManager;
+ this.nodeTypeStorageRoot = nodeTypeStorageRoot;
+ this.definitionAccessProvider = new NodeTypeDefinitionAccessProvider(dataManager);
+ this.addACL = true;
+
+ }
+
+ /**
+ * @param dataManager
+ * @throws RepositoryException
+ */
+ public JcrNodeTypeDataPersister(DataManager dataManager, RepositoryEntry repConfig) throws RepositoryException
+ {
+ this(dataManager, !repConfig.getAccessControl().equals(AccessControlPolicy.DISABLE));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void addNodeType(NodeTypeData nodeType) throws RepositoryException
+ {
+ if (!started)
+ {
+ log.warn("Unable save nodetype " + nodeType.getName().getAsString()
+ + " in to the storage. Storage not initialized");
+ return;
+ }
+
+ PlainChangesLog changesLog = new PlainChangesLogImpl();
+ definitionAccessProvider.write(changesLog, nodeTypeStorageRoot, nodeType);
+ dataManager.save(new TransactionChangesLog(changesLog));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean hasNodeType(InternalQName nodeTypeName) throws RepositoryException
+ {
+ if (!validatate())
+ {
+ return false;
+ }
+
+ NodeData nodeTypeData = (NodeData)dataManager.getItemData(nodeTypeStorageRoot, new QPathEntry(nodeTypeName, 1));
+
+ return nodeTypeData != null;
+ }
+
+ public NodeData initNodetypesRoot(NodeData nsSystem, boolean addACL) throws RepositoryException
+ {
+ PlainChangesLog changesLog = new PlainChangesLogImpl();
+
+ long start = System.currentTimeMillis();
+
+ TransientNodeData jcrNodetypes =
+ TransientNodeData.createNodeData(nsSystem, Constants.JCR_NODETYPES, Constants.NT_UNSTRUCTURED,
+ Constants.NODETYPESROOT_UUID);
+
+ TransientPropertyData primaryType =
+ TransientPropertyData.createPropertyData(jcrNodetypes, Constants.JCR_PRIMARYTYPE, PropertyType.NAME, false);
+ primaryType.setValue(new TransientValueData(jcrNodetypes.getPrimaryTypeName()));
+
+ changesLog.add(ItemState.createAddedState(jcrNodetypes)).add(ItemState.createAddedState(primaryType));
+
+ if (addACL)
+ {
+ AccessControlList acl = new AccessControlList();
+ InternalQName[] mixins = new InternalQName[]{Constants.EXO_OWNEABLE, Constants.EXO_PRIVILEGEABLE};
+ jcrNodetypes.setMixinTypeNames(mixins);
+
+ // jcr:mixinTypes
+ List<ValueData> mixValues = new ArrayList<ValueData>();
+ for (InternalQName mixin : mixins)
+ {
+ mixValues.add(new TransientValueData(mixin));
+ }
+ TransientPropertyData exoMixinTypes =
+ TransientPropertyData.createPropertyData(jcrNodetypes, Constants.JCR_MIXINTYPES, PropertyType.NAME, true,
+ mixValues);
+
+ TransientPropertyData exoOwner =
+ TransientPropertyData.createPropertyData(jcrNodetypes, Constants.EXO_OWNER, PropertyType.STRING, false,
+ new TransientValueData(acl.getOwner()));
+
+ List<ValueData> permsValues = new ArrayList<ValueData>();
+ for (int i = 0; i < acl.getPermissionEntries().size(); i++)
+ {
+ AccessControlEntry entry = acl.getPermissionEntries().get(i);
+ permsValues.add(new TransientValueData(entry));
+ }
+ TransientPropertyData exoPerms =
+ TransientPropertyData.createPropertyData(jcrNodetypes, Constants.EXO_PERMISSIONS,
+ ExtendedPropertyType.PERMISSION, true, permsValues);
+
+ changesLog.add(ItemState.createAddedState(exoMixinTypes)).add(ItemState.createAddedState(exoOwner)).add(
+ ItemState.createAddedState(exoPerms));
+ changesLog.add(new ItemState(jcrNodetypes, ItemState.MIXIN_CHANGED, false, null));
+ }
+
+ if (log.isDebugEnabled())
+ log.debug("/jcr:system/jcr:nodetypes is created, creation time: " + (System.currentTimeMillis() - start)
+ + " ms");
+
+ dataManager.save(new TransactionChangesLog(changesLog));
+
+ return jcrNodetypes;
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isStorageFilled()
+ {
+ if (nodeTypeStorageRoot == null)
+ {
+ log.warn(" Storage not initialized");
+ return false;
+ }
+ try
+ {
+ List<NodeData> storageContent = dataManager.getChildNodesData(nodeTypeStorageRoot);
+ return storageContent.size() > 0;
+ }
+ catch (RepositoryException e)
+ {
+ log.error(e.getLocalizedMessage(), e);
+
+ }
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void addNodeTypes(List<NodeTypeData> nodeTypes) throws RepositoryException
+ {
+ if (!validatate())
+ {
+ return;
+ }
+
+ PlainChangesLog changesLog = new PlainChangesLogImpl();
+ for (NodeTypeData nodeTypeData : nodeTypes)
+ {
+ definitionAccessProvider.write(changesLog, nodeTypeStorageRoot, nodeTypeData);
+ }
+
+ dataManager.save(new TransactionChangesLog(changesLog));
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void removeNodeType(NodeTypeData nodeType) throws RepositoryException
+ {
+ if (!validatate())
+ {
+ return;
+ }
+
+ validatate();
+ NodeData nodeTypeData =
+ (NodeData)dataManager.getItemData(nodeTypeStorageRoot, new QPathEntry(nodeType.getName(), 1));
+ ItemDataRemoveVisitor removeVisitor = new ItemDataRemoveVisitor(dataManager, nodeTypeStorageRoot.getQPath());
+ nodeTypeData.accept(removeVisitor);
+
+ PlainChangesLog changesLog = new PlainChangesLogImpl();
+ changesLog.addAll(removeVisitor.getRemovedStates());
+ dataManager.save(new TransactionChangesLog(changesLog));
+
+ }
+
+ public void start()
+ {
+ if (!started)
+ {
+ try
+ {
+ NodeData jcrSystem = (NodeData)dataManager.getItemData(Constants.SYSTEM_UUID);
+ if (jcrSystem != null)
+ {
+ NodeData jcrNodetypes =
+ (NodeData)dataManager.getItemData(jcrSystem, new QPathEntry(Constants.JCR_NODETYPES, 1));
+ if (jcrNodetypes == null)
+ this.nodeTypeStorageRoot = initNodetypesRoot(jcrSystem, addACL);
+ else
+ this.nodeTypeStorageRoot = jcrNodetypes;
+ }
+ else
+ {
+ throw new RuntimeException("Nodetypes storage (/jcr:systemnode) is not initialized.");
+ }
+ }
+ catch (RepositoryException e)
+ {
+ throw new RuntimeException(e.getLocalizedMessage(), e);
+ }
+ started = true;
+ }
+ }
+
+ public void stop()
+ {
+ }
+
+ /**
+ * @see org.exoplatform.services.jcr.impl.core.nodetype.registration.NodeTypeDataPersister#unmarshall(org.exoplatform.services.jcr.datamodel.InternalQName, java.util.Set)
+ */
+ public NodeTypeData getNodeType(InternalQName nodeTypeName) throws RepositoryException, NoSuchNodeTypeException
+ {
+ if (nodeTypeStorageRoot == null)
+ {
+ log.warn(" Storage not initialized");
+ return null;
+ }
+ //Searching nodeType root
+ ItemData nodeType = dataManager.getItemData(nodeTypeStorageRoot, new QPathEntry(nodeTypeName, 1));
+ if (nodeType == null)
+ throw new NoSuchNodeTypeException("Node type definition " + nodeTypeName.getAsString() + "not found");
+ if (!nodeType.isNode())
+ throw new RepositoryException("Unexpected property found " + nodeType.getQPath().getAsString()
+ + ". Should be node.");
+
+ NodeData nodeTypeRoot = (NodeData)nodeType;
+
+ if (!Constants.NT_NODETYPE.equals(nodeTypeRoot.getPrimaryTypeName()))
+ throw new RepositoryException("Unexpected node type of NodeData found "
+ + nodeTypeRoot.getPrimaryTypeName().getAsString() + ". Should be " + Constants.NT_NODETYPE.getAsString());
+
+ return definitionAccessProvider.read(nodeTypeRoot);
+ }
+
+ /**
+ * @see org.exoplatform.services.jcr.impl.core.nodetype.registration.NodeTypeDataPersister#getNodeType(java.util.Set)
+ */
+ public List<NodeTypeData> getAllNodeTypes() throws RepositoryException
+ {
+ if (!validatate())
+ {
+ return new ArrayList<NodeTypeData>();
+ }
+
+ validatate();
+ List<NodeData> nodeTypes = dataManager.getChildNodesData(nodeTypeStorageRoot);
+ List<NodeTypeData> result = new ArrayList<NodeTypeData>();
+ for (NodeData nodeData : nodeTypes)
+ {
+ if (Constants.NT_NODETYPE.equals(nodeData.getPrimaryTypeName()))
+ result.add(definitionAccessProvider.read(nodeData));
+ }
+ return result;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void update(List<NodeTypeData> nodeTypes, UpdateNodeTypeObserver observer) throws RepositoryException
+ {
+
+ PlainChangesLog changesLog = new PlainChangesLogImpl();
+
+ for (NodeTypeData nodeTypeData : nodeTypes)
+ {
+
+ if (observer != null)
+ {
+ if (observer.shouldSkip(nodeTypeData, changesLog))
+ continue;
+ observer.beforeUpdate(nodeTypeData, changesLog);
+
+ }
+ if (!validatate())
+ {
+ continue;
+ }
+ // remove first
+ NodeData removeNodeTypeData =
+ (NodeData)dataManager.getItemData(nodeTypeStorageRoot, new QPathEntry(nodeTypeData.getName(), 1));
+ if (removeNodeTypeData != null)
+ {
+ ItemDataRemoveVisitor removeVisitor =
+ new ItemDataRemoveVisitor(dataManager, nodeTypeStorageRoot.getQPath());
+ removeNodeTypeData.accept(removeVisitor);
+
+ changesLog.addAll(removeVisitor.getRemovedStates());
+ }
+ // add
+ definitionAccessProvider.write(changesLog, nodeTypeStorageRoot, nodeTypeData);
+ if (observer != null)
+ observer.afterUpdate(nodeTypeData, changesLog);
+ }
+
+ dataManager.save(new TransactionChangesLog(changesLog));
+
+ }
+
+ private boolean validatate()
+ {
+ if (this.nodeTypeStorageRoot == null)
+ {
+ if (log.isDebugEnabled())
+ log.debug(" Storage not initialized");
+ return false;
+ }
+ return true;
+ }
+}
Property changes on: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/JcrNodeTypeDataPersister.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/NodeDefinitionAccessProvider.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/NodeDefinitionAccessProvider.java (rev 0)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/NodeDefinitionAccessProvider.java 2009-10-04 09:34:54 UTC (rev 199)
@@ -0,0 +1,122 @@
+/*
+ * 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.nodetype.registration;
+
+import org.exoplatform.services.jcr.core.nodetype.NodeDefinitionData;
+import org.exoplatform.services.jcr.dataflow.DataManager;
+import org.exoplatform.services.jcr.dataflow.ItemState;
+import org.exoplatform.services.jcr.dataflow.PlainChangesLog;
+import org.exoplatform.services.jcr.datamodel.IllegalNameException;
+import org.exoplatform.services.jcr.datamodel.InternalQName;
+import org.exoplatform.services.jcr.datamodel.NodeData;
+import org.exoplatform.services.jcr.impl.Constants;
+import org.exoplatform.services.jcr.impl.dataflow.TransientNodeData;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.version.OnParentVersionAction;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * @author <a href="mailto:Sergey.Kabashnyuk at gmail.com">Sergey Kabashnyuk</a>
+ * @version $Id: $
+ */
+public class NodeDefinitionAccessProvider extends AbstractItemDefinitionAccessProvider
+{
+ /**
+ * @param dataManager
+ */
+ public NodeDefinitionAccessProvider(DataManager dataManager)
+ {
+ super(dataManager);
+
+ }
+
+ /**
+ * @param childDefinition
+ * @param name
+ * @return
+ * @throws RepositoryException
+ * @throws NodeTypeReadException
+ * @throws IOException
+ * @throws IllegalNameException
+ * @throws RepositoryException
+ * @throws UnsupportedEncodingException
+ */
+ public NodeDefinitionData read(NodeData childDefinition, InternalQName declaringNodeType)
+ throws NodeTypeReadException, RepositoryException
+
+ {
+ // null if residual
+ InternalQName name = readName(childDefinition, Constants.JCR_NAME);
+
+ boolean autoCreated = readMandatoryBoolean(childDefinition, Constants.JCR_AUTOCREATED);
+
+ boolean mandatory = readMandatoryBoolean(childDefinition, Constants.JCR_MANDATORY);
+
+ int onParentVersion =
+ OnParentVersionAction.valueFromName(readMandatoryString(childDefinition, Constants.JCR_ONPARENTVERSION));
+
+ boolean protectedItem = readMandatoryBoolean(childDefinition, Constants.JCR_PROTECTED);
+
+ InternalQName[] requiredPrimaryTypes = readNames(childDefinition, Constants.JCR_REQUIREDPRIMARYTYPES);
+
+ InternalQName defaultPrimaryType = readName(childDefinition, Constants.JCR_DEFAULTPRIMNARYTYPE);
+
+ boolean allowsSameNameSiblings = readMandatoryBoolean(childDefinition, Constants.JCR_SAMENAMESIBLINGS);
+
+ return new NodeDefinitionData(name, declaringNodeType, autoCreated, mandatory, onParentVersion, protectedItem,
+ requiredPrimaryTypes, defaultPrimaryType, allowsSameNameSiblings);
+ }
+
+ public void write(PlainChangesLog changesLog, NodeData ntNode, NodeDefinitionData nodeDefinitionData, int index)
+ {
+
+ NodeData childNodesDefinition =
+ TransientNodeData.createNodeData(ntNode, Constants.JCR_CHILDNODEDEFINITION, Constants.NT_CHILDNODEDEFINITION,
+ index);
+
+ changesLog.add(ItemState.createAddedState(childNodesDefinition));
+
+ writeItemDefinition(changesLog, childNodesDefinition, nodeDefinitionData);
+
+ writeName(changesLog, childNodesDefinition, Constants.JCR_PRIMARYTYPE, childNodesDefinition.getPrimaryTypeName());
+
+ writeBoolean(changesLog, childNodesDefinition, Constants.JCR_SAMENAMESIBLINGS, nodeDefinitionData
+ .isAllowsSameNameSiblings());
+
+ if (nodeDefinitionData.getDefaultPrimaryType() != null)
+ { // Mandatory false
+
+ writeName(changesLog, childNodesDefinition, Constants.JCR_DEFAULTPRIMNARYTYPE, nodeDefinitionData
+ .getDefaultPrimaryType());
+ }
+
+ if (nodeDefinitionData.getRequiredPrimaryTypes() != null
+ && nodeDefinitionData.getRequiredPrimaryTypes().length != 0)
+ {
+ writeNames(changesLog, childNodesDefinition, Constants.JCR_REQUIREDPRIMARYTYPES, nodeDefinitionData
+ .getRequiredPrimaryTypes());
+ }
+ }
+
+}
Property changes on: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/NodeDefinitionAccessProvider.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/NodeDefinitionComparator.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/NodeDefinitionComparator.java 2009-10-02 15:41:14 UTC (rev 198)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/NodeDefinitionComparator.java 2009-10-04 09:34:54 UTC (rev 199)
@@ -21,7 +21,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.DataManager;
+import org.exoplatform.services.jcr.dataflow.ItemDataConsumer;
import org.exoplatform.services.jcr.dataflow.PlainChangesLog;
import org.exoplatform.services.jcr.dataflow.PlainChangesLogImpl;
import org.exoplatform.services.jcr.datamodel.InternalQName;
@@ -29,13 +29,13 @@
import org.exoplatform.services.jcr.datamodel.NodeData;
import org.exoplatform.services.jcr.datamodel.QPathEntry;
import org.exoplatform.services.jcr.impl.Constants;
+import org.exoplatform.services.jcr.impl.core.nodetype.ItemAutocreator;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
-import java.util.Set;
import javax.jcr.RepositoryException;
import javax.jcr.nodetype.ConstraintViolationException;
@@ -54,13 +54,25 @@
*/
private static final Log LOG = ExoLogger.getLogger(NodeDefinitionComparator.class);
+ private final List<NodeData> affectedNodes;
+
+ private final NodeTypeDataManager nodeTypeDataManager;
+
+ private final ItemDataConsumer dataConsumer;
+
+ private final ItemAutocreator itemAutocreator;
+
/**
* @param nodeTypeDataManager
* @param persister
*/
- public NodeDefinitionComparator(NodeTypeDataManager nodeTypeDataManager, DataManager persister)
+ public NodeDefinitionComparator(NodeTypeDataManager nodeTypeDataManager, ItemDataConsumer dataConsumer,
+ ItemAutocreator itemAutocreator, List<NodeData> affectedNodes)
{
- super(nodeTypeDataManager, persister);
+ this.nodeTypeDataManager = nodeTypeDataManager;
+ this.dataConsumer = dataConsumer;
+ this.itemAutocreator = itemAutocreator;
+ this.affectedNodes = affectedNodes;
}
public PlainChangesLog compare(NodeTypeData registeredNodeType, NodeDefinitionData[] ancestorDefinition,
@@ -76,18 +88,16 @@
removedDefinitionData);
// create changes log
PlainChangesLog changesLog = new PlainChangesLogImpl();
+
// check removed
+ validateRemoved(registeredNodeType, removedDefinitionData, recipientDefinition, affectedNodes);
- validateRemoved(registeredNodeType, removedDefinitionData, recipientDefinition);
-
- Set<String> nodes = nodeTypeDataManager.getNodes(registeredNodeType.getName());
-
- validateAdded(registeredNodeType.getName(), newDefinitionData, nodes, recipientDefinition);
+ validateAdded(registeredNodeType.getName(), newDefinitionData, affectedNodes, recipientDefinition);
// changed
- validateChanged(registeredNodeType.getName(), changedDefinitionData, nodes, recipientDefinition);
+ validateChanged(registeredNodeType.getName(), changedDefinitionData, affectedNodes, recipientDefinition);
//
- doAdd(newDefinitionData, changesLog, nodes, registeredNodeType);
+ doAdd(newDefinitionData, changesLog, affectedNodes, registeredNodeType);
return changesLog;
@@ -99,13 +109,12 @@
* @throws RepositoryException
* @throws ConstraintViolationException
*/
- private void checkMandatoryItems(Set<String> nodes, NodeDefinitionData nodeDefinitionData)
+ private void checkMandatoryItems(List<NodeData> nodesData, NodeDefinitionData nodeDefinitionData)
throws RepositoryException, ConstraintViolationException
{
- for (String uuid : nodes)
+ for (NodeData nodeData : nodesData)
{
- NodeData nodeData = (NodeData)persister.getItemData(uuid);
- ItemData child = persister.getItemData(nodeData, new QPathEntry(nodeDefinitionData.getName(), 0));
+ ItemData child = dataConsumer.getItemData(nodeData, new QPathEntry(nodeDefinitionData.getName(), 0));
if (child == null || !child.isNode())
{
throw new ConstraintViolationException("Fail to add mandatory and not auto-created "
@@ -125,19 +134,19 @@
* @param recipientDefinitionData
* @throws RepositoryException
*/
- private void checkRequiredPrimaryType(InternalQName registeredNodeType, Set<String> nodes,
+ private void checkRequiredPrimaryType(InternalQName registeredNodeType, List<NodeData> nodesData,
InternalQName[] ancestorRequiredPrimaryTypes, NodeDefinitionData recipientDefinitionData,
NodeDefinitionData[] allRecipientDefinition) throws RepositoryException
{
// Required type change
InternalQName[] requiredPrimaryTypes = recipientDefinitionData.getRequiredPrimaryTypes();
- for (String uuid : nodes)
+ for (NodeData nodeData : nodesData)
{
- NodeData nodeData = (NodeData)persister.getItemData(uuid);
+
if (recipientDefinitionData.getName().equals(Constants.JCR_ANY_NAME))
{
- List<NodeData> childs = persister.getChildNodesData(nodeData);
+ List<NodeData> childs = dataConsumer.getChildNodesData(nodeData);
for (NodeData child : childs)
{
if (isResidualMatch(child.getQPath().getName(), allRecipientDefinition))
@@ -173,7 +182,7 @@
}
else
{
- List<NodeData> childs = persister.getChildNodesData(nodeData);
+ List<NodeData> childs = dataConsumer.getChildNodesData(nodeData);
for (NodeData child : childs)
{
if (child.getQPath().getName().equals(recipientDefinitionData.getName()))
@@ -217,23 +226,22 @@
* @param recipientDefinitionData
* @throws RepositoryException
*/
- private void checkSameNameSibling(InternalQName registeredNodeType, Set<String> nodes, InternalQName recipientName,
- NodeDefinitionData[] allRecipientDefinition) throws RepositoryException
+ private void checkSameNameSibling(InternalQName registeredNodeType, List<NodeData> nodesData,
+ InternalQName recipientName, NodeDefinitionData[] allRecipientDefinition) throws RepositoryException
{
- for (String uuid : nodes)
+ for (NodeData nodeData : nodesData)
{
- NodeData nodeData = (NodeData)persister.getItemData(uuid);
if (recipientName.equals(Constants.JCR_ANY_NAME))
{
// child of node type
- List<NodeData> childs = persister.getChildNodesData(nodeData);
+ List<NodeData> childs = dataConsumer.getChildNodesData(nodeData);
for (NodeData child : childs)
{
if (isResidualMatch(child.getQPath().getName(), allRecipientDefinition))
{
- List<NodeData> childs2 = persister.getChildNodesData(child);
+ List<NodeData> childs2 = dataConsumer.getChildNodesData(child);
for (NodeData child2 : childs2)
{
@@ -259,12 +267,12 @@
{
// child of node type
- List<NodeData> childs = persister.getChildNodesData(nodeData);
+ List<NodeData> childs = dataConsumer.getChildNodesData(nodeData);
for (NodeData child : childs)
{
if (child.getQPath().getName().equals(recipientName))
{
- List<NodeData> childs2 = persister.getChildNodesData(child);
+ List<NodeData> childs2 = dataConsumer.getChildNodesData(child);
for (NodeData child2 : childs2)
{
@@ -299,21 +307,20 @@
* @param registeredNodeType
* @throws RepositoryException
*/
- private void doAdd(List<NodeDefinitionData> toAddList, PlainChangesLog changesLog, Set<String> nodes,
+ private void doAdd(List<NodeDefinitionData> toAddList, PlainChangesLog changesLog, List<NodeData> nodesData,
NodeTypeData registeredNodeType) throws RepositoryException
{
- for (String uuid : nodes)
+ for (NodeData nodeData : nodesData)
{
- NodeData nodeData = (NodeData)persister.getItemData(uuid);
// added properties
for (NodeDefinitionData newNodeDefinitionData : toAddList)
{
if (!newNodeDefinitionData.getName().equals(Constants.JCR_ANY_NAME)
&& newNodeDefinitionData.isAutoCreated())
- changesLog.addAll(nodeTypeDataManager.makeAutoCreatedNodes(nodeData, registeredNodeType.getName(),
- new NodeDefinitionData[]{newNodeDefinitionData}, persister, nodeData.getACL().getOwner())
+ changesLog.addAll(itemAutocreator.makeAutoCreatedNodes(nodeData, registeredNodeType.getName(),
+ new NodeDefinitionData[]{newNodeDefinitionData}, dataConsumer, nodeData.getACL().getOwner())
.getAllStates());
}
}
@@ -327,7 +334,7 @@
* @throws RepositoryException
*/
private void validateAdded(InternalQName nodeTypeName, List<NodeDefinitionData> newDefinitionData,
- Set<String> nodes, NodeDefinitionData[] recipientDefinition) throws RepositoryException
+ List<NodeData> nodesData, NodeDefinitionData[] recipientDefinition) throws RepositoryException
{
for (NodeDefinitionData nodeDefinitionData : newDefinitionData)
@@ -336,22 +343,22 @@
if (nodeDefinitionData.getName().equals(Constants.JCR_ANY_NAME))
{
- checkRequiredPrimaryType(nodeTypeName, nodes, null, nodeDefinitionData, recipientDefinition);
+ checkRequiredPrimaryType(nodeTypeName, nodesData, null, nodeDefinitionData, recipientDefinition);
- checkSameNameSibling(nodeTypeName, nodes, nodeDefinitionData.getName(), recipientDefinition);
+ checkSameNameSibling(nodeTypeName, nodesData, nodeDefinitionData.getName(), recipientDefinition);
}
else
{
// check existed nodes for new constraint
- checkRequiredPrimaryType(nodeTypeName, nodes, null, nodeDefinitionData, recipientDefinition);
- checkSameNameSibling(nodeTypeName, nodes, nodeDefinitionData.getName(), recipientDefinition);
+ checkRequiredPrimaryType(nodeTypeName, nodesData, null, nodeDefinitionData, recipientDefinition);
+ checkSameNameSibling(nodeTypeName, nodesData, nodeDefinitionData.getName(), recipientDefinition);
// try to add mandatory or auto-created properties for
// for already addded nodes.
if (nodeDefinitionData.isMandatory() && !nodeDefinitionData.isAutoCreated())
{
- checkMandatoryItems(nodes, nodeDefinitionData);
+ checkMandatoryItems(nodesData, nodeDefinitionData);
}
}
}
@@ -366,7 +373,7 @@
* @throws RepositoryException
*/
private void validateChanged(InternalQName registeredNodeType,
- List<RelatedDefinition<NodeDefinitionData>> changedDefinitionData, Set<String> nodes,
+ List<RelatedDefinition<NodeDefinitionData>> changedDefinitionData, List<NodeData> nodesData,
NodeDefinitionData[] allRecipientDefinition) throws RepositoryException
{
for (RelatedDefinition<NodeDefinitionData> changedDefinitions : changedDefinitionData)
@@ -377,10 +384,11 @@
// TODO residual
if (!ancestorDefinitionData.isMandatory() && recipientDefinitionData.isMandatory())
{
- for (String uuid : nodes)
+ for (NodeData nodeData : nodesData)
{
- NodeData nodeData = (NodeData)persister.getItemData(uuid);
- ItemData child = persister.getItemData(nodeData, new QPathEntry(recipientDefinitionData.getName(), 0));
+
+ ItemData child =
+ dataConsumer.getItemData(nodeData, new QPathEntry(recipientDefinitionData.getName(), 0));
if (child == null || !child.isNode())
{
String message =
@@ -389,7 +397,7 @@
+ " from mandatory=false to mandatory = true , because " + " node "
+ nodeData.getQPath().getAsString() + " doesn't have child node with name "
+ recipientDefinitionData.getName().getAsString();
- throw new RepositoryException(message);
+ throw new ConstraintViolationException(message);
}
}
}
@@ -398,32 +406,34 @@
if (!ancestorDefinitionData.isProtected() && recipientDefinitionData.isProtected())
{
// TODO residual
- for (String uuid : nodes)
+ for (NodeData nodeData : nodesData)
{
- NodeData nodeData = (NodeData)persister.getItemData(uuid);
- ItemData child = persister.getItemData(nodeData, new QPathEntry(recipientDefinitionData.getName(), 0));
+
+ ItemData child =
+ dataConsumer.getItemData(nodeData, new QPathEntry(recipientDefinitionData.getName(), 0));
if (child == null || !child.isNode())
{
String message =
"Fail to change " + recipientDefinitionData.getName().getAsString() + " node definition for "
+ registeredNodeType.getAsString()
- + " node type from rotected=false to Protected = true , because " + " node "
+ + " node type from protected=false to Protected = true , because " + " node "
+ nodeData.getQPath().getAsString() + " doesn't have child node with name "
+ recipientDefinitionData.getName().getAsString();
- throw new RepositoryException(message);
+ throw new ConstraintViolationException(message);
}
}
}
if (!Arrays.deepEquals(ancestorDefinitionData.getRequiredPrimaryTypes(), recipientDefinitionData
.getRequiredPrimaryTypes()))
{
- checkRequiredPrimaryType(registeredNodeType, nodes, ancestorDefinitionData.getRequiredPrimaryTypes(),
+ checkRequiredPrimaryType(registeredNodeType, nodesData, ancestorDefinitionData.getRequiredPrimaryTypes(),
recipientDefinitionData, allRecipientDefinition);
}
// check sibling
if (ancestorDefinitionData.isAllowsSameNameSiblings() && !recipientDefinitionData.isAllowsSameNameSiblings())
{
- checkSameNameSibling(registeredNodeType, nodes, recipientDefinitionData.getName(), allRecipientDefinition);
+ checkSameNameSibling(registeredNodeType, nodesData, recipientDefinitionData.getName(),
+ allRecipientDefinition);
}
}
}
@@ -436,19 +446,17 @@
* @throws RepositoryException
*/
private void validateRemoved(NodeTypeData registeredNodeType, List<NodeDefinitionData> removedDefinitionData,
- NodeDefinitionData[] recipientDefinition) throws ConstraintViolationException, RepositoryException
+ NodeDefinitionData[] recipientDefinition, List<NodeData> nodesData) throws ConstraintViolationException,
+ RepositoryException
{
for (NodeDefinitionData removeNodeDefinitionData : removedDefinitionData)
{
- Set<String> nodes;
if (removeNodeDefinitionData.getName().equals(Constants.JCR_ANY_NAME))
{
- nodes = nodeTypeDataManager.getNodes(registeredNodeType.getName());
- for (String uuid : nodes)
+ for (NodeData nodeData : nodesData)
{
- NodeData nodeData = (NodeData)persister.getItemData(uuid);
- List<NodeData> childs = persister.getChildNodesData(nodeData);
+ List<NodeData> childs = dataConsumer.getChildNodesData(nodeData);
// more then mixin and primary type
// TODO it could be possible, check add definitions
if (childs.size() > 0)
@@ -472,12 +480,10 @@
{
if (!isResidualMatch(removeNodeDefinitionData.getName(), recipientDefinition))
{
- nodes = nodeTypeDataManager.getNodes(registeredNodeType.getName());
- for (String uuid : nodes)
+ for (NodeData nodeData : nodesData)
{
- NodeData nodeData = (NodeData)persister.getItemData(uuid);
ItemData child =
- persister.getItemData(nodeData, new QPathEntry(removeNodeDefinitionData.getName(), 0));
+ dataConsumer.getItemData(nodeData, new QPathEntry(removeNodeDefinitionData.getName(), 0));
if (child != null && child.isNode())
{
throw new ConstraintViolationException("Can't remove node definition "
Added: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/NodeTypeConverter.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/NodeTypeConverter.java (rev 0)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/NodeTypeConverter.java 2009-10-04 09:34:54 UTC (rev 199)
@@ -0,0 +1,170 @@
+/*
+ * 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.nodetype.registration;
+
+import org.exoplatform.services.jcr.access.AccessControlPolicy;
+import org.exoplatform.services.jcr.core.nodetype.NodeDefinitionData;
+import org.exoplatform.services.jcr.core.nodetype.NodeDefinitionValue;
+import org.exoplatform.services.jcr.core.nodetype.NodeTypeData;
+import org.exoplatform.services.jcr.core.nodetype.NodeTypeDataImpl;
+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.datamodel.InternalQName;
+import org.exoplatform.services.jcr.impl.core.LocationFactory;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.jcr.RepositoryException;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * @author <a href="mailto:Sergey.Kabashnyuk at gmail.com">Sergey Kabashnyuk</a>
+ * @version $Id: $
+ */
+public class NodeTypeConverter
+{
+ /**
+ * Class logger.
+ */
+ private final Log log = ExoLogger.getLogger(NodeTypeConverter.class);
+
+ private final LocationFactory locationFactory;
+
+ protected final String accessControlPolicy;
+
+ public NodeTypeConverter(LocationFactory locationFactory, String accessControlPolicy)
+ {
+ super();
+ this.locationFactory = locationFactory;
+ this.accessControlPolicy = accessControlPolicy;
+ }
+
+ public List<NodeTypeData> convertFromValueToData(List<NodeTypeValue> ntvalues) throws RepositoryException
+ {
+ List<NodeTypeData> nodeTypeDataList = new ArrayList<NodeTypeData>();
+ for (NodeTypeValue ntvalue : ntvalues)
+ {
+
+ if (accessControlPolicy.equals(AccessControlPolicy.DISABLE))
+ {
+ List<String> nsupertypes = ntvalue.getDeclaredSupertypeNames();
+ if (nsupertypes != null && nsupertypes.contains("exo:privilegeable")
+ || ntvalue.getName().equals("exo:privilegeable"))
+ {
+ // skip this node, so it's not necessary at this runtime
+ // + "' -- it's not necessary at this runtime";
+ log.warn("Node type " + ntvalue.getName() + " is not register due to DISABLE control policy");
+ break;
+ }
+ }
+
+ // We have to validate node value before registering it
+ ntvalue.validateNodeType();
+ // throw new RepositoryException("Invalid node type value");
+
+ // declaring NT name
+ InternalQName ntName = locationFactory.parseJCRName(ntvalue.getName()).getInternalName();
+
+ List<String> stlist = ntvalue.getDeclaredSupertypeNames();
+ InternalQName[] supertypes = new InternalQName[stlist.size()];
+ for (int i = 0; i < stlist.size(); i++)
+ {
+ supertypes[i] = locationFactory.parseJCRName(stlist.get(i)).getInternalName();
+ }
+
+ List<PropertyDefinitionValue> pdlist = ntvalue.getDeclaredPropertyDefinitionValues();
+ PropertyDefinitionData[] props = new PropertyDefinitionData[pdlist.size()];
+ for (int i = 0; i < pdlist.size(); i++)
+ {
+ PropertyDefinitionValue v = pdlist.get(i);
+
+ PropertyDefinitionData pd;
+ pd =
+ new PropertyDefinitionData(locationFactory.parseJCRName(v.getName()).getInternalName(), ntName, v
+ .isAutoCreate(), v.isMandatory(), v.getOnVersion(), v.isReadOnly(), v.getRequiredType(),
+ safeListToArray(v.getValueConstraints()), safeListToArray(v.getDefaultValueStrings()),
+ v.isMultiple());
+
+ props[i] = pd;
+ }
+
+ List<NodeDefinitionValue> ndlist = ntvalue.getDeclaredChildNodeDefinitionValues();
+ NodeDefinitionData[] nodes = new NodeDefinitionData[ndlist.size()];
+ for (int i = 0; i < ndlist.size(); i++)
+ {
+ NodeDefinitionValue v = ndlist.get(i);
+
+ List<String> rnts = v.getRequiredNodeTypeNames();
+ InternalQName[] requiredNTs = new InternalQName[rnts.size()];
+ for (int ri = 0; ri < rnts.size(); ri++)
+ {
+ requiredNTs[ri] = locationFactory.parseJCRName(rnts.get(ri)).getInternalName();
+ }
+ InternalQName defaultNodeName = null;
+ if (v.getDefaultNodeTypeName() != null)
+ {
+ defaultNodeName = locationFactory.parseJCRName(v.getDefaultNodeTypeName()).getInternalName();
+ }
+ NodeDefinitionData nd =
+ new NodeDefinitionData(locationFactory.parseJCRName(v.getName()).getInternalName(), ntName, v
+ .isAutoCreate(), v.isMandatory(), v.getOnVersion(), v.isReadOnly(), requiredNTs, defaultNodeName, v
+ .isSameNameSiblings());
+ nodes[i] = nd;
+ }
+
+ InternalQName primaryItemName = null;
+ if (ntvalue.getPrimaryItemName() != null)
+ primaryItemName = locationFactory.parseJCRName(ntvalue.getPrimaryItemName()).getInternalName();
+
+ NodeTypeData nodeTypeData =
+ new NodeTypeDataImpl(ntName, primaryItemName, ntvalue.isMixin(), ntvalue.isOrderableChild(), supertypes, props, nodes);
+
+ nodeTypeDataList.add(nodeTypeData);
+ }
+ return nodeTypeDataList;
+ }
+
+ public Map<InternalQName, NodeTypeData> convertToMap(List<NodeTypeData> ntvalues)
+ {
+ Map<InternalQName, NodeTypeData> result = new HashMap<InternalQName, NodeTypeData>();
+ for (NodeTypeData nodeTypeData : ntvalues)
+ {
+ result.put(nodeTypeData.getName(), nodeTypeData);
+ }
+ return result;
+ }
+
+ /**
+ * Convert list to array.
+ *
+ * @param v list of string
+ * @return array of string, empty array if list null.
+ */
+ private String[] safeListToArray(List<String> v)
+ {
+ return v != null ? v.toArray(new String[v.size()]) : new String[0];
+ }
+}
Property changes on: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/NodeTypeConverter.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/NodeTypeDataBuilder.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/NodeTypeDataBuilder.java (rev 0)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/NodeTypeDataBuilder.java 2009-10-04 09:34:54 UTC (rev 199)
@@ -0,0 +1,436 @@
+/*
+ * 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.nodetype.registration;
+
+import org.exoplatform.services.jcr.core.nodetype.NodeDefinitionData;
+import org.exoplatform.services.jcr.core.nodetype.NodeTypeData;
+import org.exoplatform.services.jcr.core.nodetype.NodeTypeDataImpl;
+import org.exoplatform.services.jcr.core.nodetype.PropertyDefinitionData;
+import org.exoplatform.services.jcr.datamodel.InternalQName;
+import org.exoplatform.services.jcr.impl.Constants;
+
+
+import java.util.LinkedList;
+import java.util.List;
+
+import javax.jcr.PropertyType;
+import javax.jcr.version.OnParentVersionAction;
+
+/**
+ * Created by The eXo Platform SAS. <br>
+ * This class is designed to build NodeTypeData instances 'bit by bit'. It
+ * serves as a container to store NodeType definition setting in the process of
+ * reading the stream. When instance of builder is created default parameters
+ * are assigned to internal fields. When method <b>build()</b> is invoked new
+ * NodeTypeData instance is created using parameters from internal fields. To
+ * define new child or new property method <b>
+ * newNodeDefinitionDataBuilder()</b> or <b> newPropertyDefinitionDataBuilder()
+ * </b> should be invoked. <b>Instances of returned Builders are automatically
+ * added to internal child or property lists.</b> If some builder is not used it
+ * should be removed from internal lists by using NodeTypeDataBuilder's method
+ * removeNodeDefinitionDataBuilder() or removePropertyDefinitionDataBuilder.
+ *
+ * @author <a href="mailto:nikolazius at gmail.com">Nikolay Zamosenchuk</a>
+ * @version $Id: $
+ */
+public class NodeTypeDataBuilder
+{
+
+ private InternalQName name;
+
+ private InternalQName[] supertypes;
+
+ private boolean isMixin;
+
+ private boolean isOrderable;
+
+ private InternalQName primaryItemName;
+
+ private PropertyDefinitionData[] propertyDefinitions;
+
+ private NodeDefinitionData[] childNodeDefinitions;
+
+ private boolean isAbstract;
+
+ private boolean isQueryable = true;
+
+ private List<NodeDefinitionDataBuilder> nodeDefinitionDataBuilders;
+
+ private List<PropertyDefinitionDataBuilder> propertyDefinitionDataBuilders;
+
+ /**
+ * This subclass represents child builder. To create instance of this class
+ * you should call NodeTypeDataBuilder's method
+ * <b>newNodeDefinitionDataBuilder()</b>.
+ */
+ public class NodeDefinitionDataBuilder
+ {
+
+ private InternalQName name;
+
+ private InternalQName declaringType;
+
+ private InternalQName defaultPrimaryType;
+
+ private InternalQName[] requiredPrimaryTypes;
+
+ private boolean isAutoCreated;
+
+ private int onParentVersion;
+
+ private boolean isProtected;
+
+ private boolean isMandatory;
+
+ private boolean allowsSameNameSiblings;
+
+ /**
+ * Constructor is private. Could to be invoked only by NodeTypeDataBuilder.
+ *
+ * @param declaringType
+ */
+ private NodeDefinitionDataBuilder(InternalQName declaringType)
+ {
+ this.declaringType = declaringType;
+ this.defaultPrimaryType = null;
+ this.requiredPrimaryTypes = new InternalQName[]{Constants.NT_BASE};
+ this.isAutoCreated = false;
+ this.onParentVersion = OnParentVersionAction.COPY;
+ this.isProtected = false;
+ this.isMandatory = false;
+ this.allowsSameNameSiblings = false;
+ }
+
+ /**
+ * This method returns new instance of NodeDefinitionData using parameters
+ * stored in current instance. This method is called by
+ * <b>NodeTypeDataBuilder.build()</b> before creating NodeTypeData instance.
+ *
+ * @return instance of NodeDefinitionData
+ */
+ private NodeDefinitionData build()
+ {
+ return new NodeDefinitionData(name, declaringType, isAutoCreated, isMandatory, onParentVersion, isProtected,
+ requiredPrimaryTypes, defaultPrimaryType, allowsSameNameSiblings);
+ }
+
+ public void setName(InternalQName name)
+ {
+ this.name = name;
+ }
+
+ public void setDefaultPrimaryType(InternalQName defaultPrimaryType)
+ {
+ this.defaultPrimaryType = defaultPrimaryType;
+ }
+
+ public void setRequiredPrimaryTypes(InternalQName[] requiredPrimaryTypes)
+ {
+ this.requiredPrimaryTypes = requiredPrimaryTypes;
+ }
+
+ public void setAutoCreated(boolean isAutoCreated)
+ {
+ this.isAutoCreated = isAutoCreated;
+ }
+
+ public void setOnParentVersion(int onParentVersion)
+ {
+ this.onParentVersion = onParentVersion;
+ }
+
+ public void setProtected(boolean isProtected)
+ {
+ this.isProtected = isProtected;
+ }
+
+ public void setMandatory(boolean isMandatory)
+ {
+ this.isMandatory = isMandatory;
+ }
+
+ public void setAllowsSameNameSiblings(boolean allowsSameNameSiblings)
+ {
+ this.allowsSameNameSiblings = allowsSameNameSiblings;
+ }
+ }
+
+ /**
+ * This subclass represents property builder. To create instance of this class
+ * you should call NodeTypeDataBuilder's method
+ * <b>newPropertyDefinitionDataBuilders()</b>.
+ */
+ public class PropertyDefinitionDataBuilder
+ {
+
+ private InternalQName name;
+
+ private int requiredType;
+
+ private String[] valueConstraints;
+
+ private String[] defaultValues;
+
+ private boolean isAutoCreated;
+
+ private boolean isProtected;
+
+ private boolean isMandatory;
+
+ private boolean isMultiple;
+
+ private boolean isFullTextSearchable;
+
+ private boolean isQueryOrderable;
+
+ private String[] queryOperators;
+
+ private int onParentVersion;
+
+ private InternalQName declaringType;
+
+ /**
+ * Constructor is private. Could to be invoked only by NodeTypeDataBuilder.
+ *
+ * @param declaringType
+ */
+ private PropertyDefinitionDataBuilder(InternalQName declaringType)
+ {
+ this.requiredType = PropertyType.STRING;
+ this.valueConstraints = null;
+ this.defaultValues = null;
+ this.isAutoCreated = false;
+ this.isProtected = false;
+ this.isMandatory = false;
+ this.isMultiple = false;
+// this.isFullTextSearchable = true;
+// this.isQueryOrderable = true;
+// this.queryOperators = Operator.getAllQueryOperators();
+ this.onParentVersion = OnParentVersionAction.COPY;
+ this.declaringType = declaringType;
+ }
+
+ /**
+ * This method returns new instance of NodeDefinitionData using parameters
+ * stored in current instance. This method is called by
+ * <b>NodeTypeDataBuilder.build()</b> before creating NodeTypeData instance.
+ *
+ * @return instance of PropertyDefinitionData
+ */
+ private PropertyDefinitionData build()
+ {
+ return new PropertyDefinitionData(name, declaringType, isAutoCreated, isMandatory, onParentVersion,
+ isProtected, requiredType, valueConstraints, defaultValues, isMultiple);
+ }
+
+ public void setName(InternalQName name)
+ {
+ this.name = name;
+ }
+
+ public void setRequiredType(int requiredType)
+ {
+ this.requiredType = requiredType;
+ }
+
+ public void setValueConstraints(String[] valueConstraints)
+ {
+ this.valueConstraints = valueConstraints;
+ }
+
+ public void setDefaultValues(String[] defaultValues)
+ {
+ this.defaultValues = defaultValues;
+ }
+
+ public void setAutoCreated(boolean isAutoCreated)
+ {
+ this.isAutoCreated = isAutoCreated;
+ }
+
+ public void setProtected(boolean isProtected)
+ {
+ this.isProtected = isProtected;
+ }
+
+ public void setMandatory(boolean isMandatory)
+ {
+ this.isMandatory = isMandatory;
+ }
+
+ public void setMultiple(boolean isMultiple)
+ {
+ this.isMultiple = isMultiple;
+ }
+
+ public void setFullTextSearchable(boolean fullTextSearchable)
+ {
+ this.isFullTextSearchable = fullTextSearchable;
+ }
+
+ public void setQueryOrderable(boolean isQueryOrderable)
+ {
+ this.isQueryOrderable = isQueryOrderable;
+ }
+
+ public void setQueryOperators(String[] queryOperators)
+ {
+ this.queryOperators = queryOperators;
+ }
+
+ public void setOnParentVersion(int onParentVersion)
+ {
+ this.onParentVersion = onParentVersion;
+ }
+ }
+
+ /**
+ * Creates new instance of NodeTypeData builder with default parameters.
+ */
+ public NodeTypeDataBuilder()
+ {
+ this.isMixin = false;
+ this.isOrderable = false;
+ this.isAbstract = false;
+ this.isQueryable = true;
+ this.primaryItemName = null;
+ this.supertypes = new InternalQName[]{Constants.NT_BASE};
+ this.propertyDefinitions = new PropertyDefinitionData[0];
+ this.childNodeDefinitions = new NodeDefinitionData[0];
+ this.nodeDefinitionDataBuilders = new LinkedList<NodeDefinitionDataBuilder>();
+ this.propertyDefinitionDataBuilders = new LinkedList<PropertyDefinitionDataBuilder>();
+ }
+
+ /**
+ * Creates child builder. This builder is automatically added to list of child
+ * builders in order to fill nodetType's child declaration array. If this
+ * instance is not used, it should be removed from internal list by calling
+ * NodeTypeData's method <b>removeNodeDefinitionDataBuilder()</b>.
+ *
+ * @return new NodeDefinitionBuilder
+ */
+ public NodeDefinitionDataBuilder newNodeDefinitionDataBuilder()
+ {
+ NodeDefinitionDataBuilder child = new NodeDefinitionDataBuilder(this.name);
+ this.nodeDefinitionDataBuilders.add(child);
+ return child;
+ }
+
+ /**
+ * Creates property builder. This builder is automatically added to list of
+ * property builders in order to fill nodetType's property declaration array.
+ * If this instance is not used, it should be removed from internal list by
+ * calling NodeTypeData's method <b>removePropertyDefinitionDataBuilder()</b>.
+ *
+ * @return new NodeDefinitionBuilder
+ */
+ public PropertyDefinitionDataBuilder newPropertyDefinitionDataBuilder()
+ {
+ PropertyDefinitionDataBuilder property = new PropertyDefinitionDataBuilder(this.name);
+ this.propertyDefinitionDataBuilders.add(property);
+ return property;
+ }
+
+ /**
+ * Removes given NodeDefinitionDataBuilder from internal list of NodeType's
+ * children.
+ *
+ * @param NodeDefinitionDataBuilder
+ * @return result flag
+ */
+ public boolean removeNodeDefinitionDataBuilder(NodeDefinitionDataBuilder childBuilder)
+ {
+ return nodeDefinitionDataBuilders.remove(childBuilder);
+ }
+
+ /**
+ * Removes given PropertyDefinitionDataBuilder from internal list of
+ * NodeType's properties.
+ *
+ * @param PropertyDefinitionDataBuilder
+ * @return result flag
+ */
+ public boolean removePropertyDefinitionDataBuilder(PropertyDefinitionDataBuilder propertyBuilder)
+ {
+ return propertyDefinitionDataBuilders.remove(propertyBuilder);
+ }
+
+ /**
+ * Creates instance of NodeTypeData using parameters stored in this object.
+ *
+ * @return NodeTypeData
+ */
+ public NodeTypeData build()
+ {
+ if (nodeDefinitionDataBuilders.size() > 0)
+ {
+ childNodeDefinitions = new NodeDefinitionData[nodeDefinitionDataBuilders.size()];
+ for (int i = 0; i < childNodeDefinitions.length; i++)
+ {
+ childNodeDefinitions[i] = nodeDefinitionDataBuilders.get(i).build();
+ }
+ }
+ if (propertyDefinitionDataBuilders.size() > 0)
+ {
+ propertyDefinitions = new PropertyDefinitionData[propertyDefinitionDataBuilders.size()];
+ for (int i = 0; i < propertyDefinitions.length; i++)
+ {
+ propertyDefinitions[i] = propertyDefinitionDataBuilders.get(i).build();
+ }
+ }
+ return new NodeTypeDataImpl(name, primaryItemName, isMixin, isOrderable, supertypes,
+ propertyDefinitions, childNodeDefinitions);
+ }
+
+ public void setName(InternalQName name)
+ {
+ this.name = name;
+ }
+
+ public void setSupertypes(InternalQName[] supertypes)
+ {
+ this.supertypes = supertypes;
+ }
+
+ public void setMixin(boolean isMixin)
+ {
+ this.isMixin = isMixin;
+ }
+
+ public void setOrderable(boolean isOrderable)
+ {
+ this.isOrderable = isOrderable;
+ }
+
+ public void setPrimaryItemName(InternalQName primaryItemName)
+ {
+ this.primaryItemName = primaryItemName;
+ }
+
+ public void setAbstract(boolean isAbstract)
+ {
+ this.isAbstract = isAbstract;
+ }
+
+ public void setQueryable(boolean isQueryable)
+ {
+ this.isQueryable = isQueryable;
+ }
+
+}
Property changes on: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/NodeTypeDataBuilder.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/NodeTypeDataPersister.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/NodeTypeDataPersister.java (rev 0)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/NodeTypeDataPersister.java 2009-10-04 09:34:54 UTC (rev 199)
@@ -0,0 +1,105 @@
+/*
+ * 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.nodetype.registration;
+
+import org.exoplatform.services.jcr.core.ComponentPersister;
+import org.exoplatform.services.jcr.core.nodetype.NodeTypeData;
+import org.exoplatform.services.jcr.datamodel.IllegalNameException;
+import org.exoplatform.services.jcr.datamodel.InternalQName;
+
+import java.io.IOException;
+import java.util.List;
+
+import javax.jcr.RepositoryException;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * @author <a href="mailto:Sergey.Kabashnyuk at gmail.com">Sergey Kabashnyuk</a>
+ * @version $Id: $
+ */
+public interface NodeTypeDataPersister extends ComponentPersister
+{
+ /**
+ * Add new node type
+ *
+ * @param nodeType
+ * @return
+ * @throws RepositoryException
+ */
+ public void addNodeType(NodeTypeData nodeType) throws RepositoryException;
+
+ /**
+ * Check node type
+ *
+ * @param nodeTypeName
+ * @return
+ * @throws RepositoryException
+ */
+ public boolean hasNodeType(InternalQName nodeTypeName) throws RepositoryException;
+
+ /**
+ * Write node types to stream
+ *
+ * @param os output stream
+ * @param nodeTypes
+ * @throws IOException
+ * @throws RepositoryException
+ */
+ public void addNodeTypes(List<NodeTypeData> nodeTypes) throws RepositoryException;
+
+ /**
+ * Remove node type
+ *
+ * @param nodeType
+ * @return
+ * @throws RepositoryException
+ */
+ public void removeNodeType(NodeTypeData nodeType) throws RepositoryException;
+
+ /**
+ * Read node types.
+ *
+ * @param is input stream
+ * @return
+ * @throws RepositoryException
+ * @throws IllegalNameException
+ */
+ public List<NodeTypeData> getAllNodeTypes() throws RepositoryException;
+
+ /**
+ * Read node types.
+ *
+ * @param is input stream
+ * @return
+ * @throws RepositoryException
+ */
+ public NodeTypeData getNodeType(InternalQName nodeTypeName) throws RepositoryException;
+
+ /**
+ * Write node types to stream
+ *
+ * @param os output stream
+ * @param nodeTypes
+ * @throws IOException
+ * @throws RepositoryException
+ */
+ public void update(List<NodeTypeData> nodeTypes, UpdateNodeTypeObserver observer) throws RepositoryException;
+
+}
Property changes on: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/NodeTypeDataPersister.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/NodeTypeDataValidator.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/NodeTypeDataValidator.java (rev 0)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/NodeTypeDataValidator.java 2009-10-04 09:34:54 UTC (rev 199)
@@ -0,0 +1,168 @@
+/*
+ * 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.nodetype.registration;
+
+import org.exoplatform.services.jcr.core.nodetype.NodeDefinitionData;
+import org.exoplatform.services.jcr.core.nodetype.NodeTypeData;
+import org.exoplatform.services.jcr.datamodel.InternalQName;
+import org.exoplatform.services.jcr.impl.Constants;
+import org.exoplatform.services.jcr.impl.core.nodetype.NodeTypeRepository;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.jcr.RepositoryException;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * @author <a href="mailto:Sergey.Kabashnyuk at gmail.com">Sergey Kabashnyuk</a>
+ * @version $Id: $
+ */
+public class NodeTypeDataValidator
+{
+ /**
+ * Class logger.
+ */
+ private final Log log = ExoLogger.getLogger(NodeTypeDataValidator.class);
+
+ protected final NodeTypeRepository hierarchy;
+
+ public NodeTypeDataValidator(NodeTypeRepository hierarchy)
+ {
+ super();
+ this.hierarchy = hierarchy;
+ }
+
+ public void validateNodeType(List<NodeTypeData> nodeTypeDataList) throws RepositoryException
+ {
+ for (NodeTypeData nodeTypeData : nodeTypeDataList)
+ {
+ validateNodeType(nodeTypeData);
+ }
+ checkCyclicDependencies(nodeTypeDataList);
+ }
+
+ private void checkCyclicDependencies(List<NodeTypeData> nodeTypeDataList) throws RepositoryException
+ {
+ Set<InternalQName> unresolvedDependecies = new HashSet<InternalQName>();
+ Set<InternalQName> resolvedDependecies = new HashSet<InternalQName>();
+ for (NodeTypeData nodeTypeData : nodeTypeDataList)
+ {
+ // / add itself
+ resolvedDependecies.add(nodeTypeData.getName());
+ // remove from unresolved
+ unresolvedDependecies.remove(nodeTypeData.getName());
+ // check suppers
+ for (int i = 0; i < nodeTypeData.getDeclaredSupertypeNames().length; i++)
+ {
+ InternalQName superName = nodeTypeData.getDeclaredSupertypeNames()[i];
+ if (hierarchy.getNodeType(superName) == null && !resolvedDependecies.contains(superName))
+ {
+ unresolvedDependecies.add(superName);
+ }
+ }
+ // check node definition
+ for (int i = 0; i < nodeTypeData.getDeclaredChildNodeDefinitions().length; i++)
+ {
+ NodeDefinitionData childnodeDefinitionData = nodeTypeData.getDeclaredChildNodeDefinitions()[i];
+ for (int j = 0; j < childnodeDefinitionData.getRequiredPrimaryTypes().length; j++)
+ {
+ InternalQName requiredPrimaryTypeName = childnodeDefinitionData.getRequiredPrimaryTypes()[j];
+ if (hierarchy.getNodeType(requiredPrimaryTypeName) == null
+ && !resolvedDependecies.contains(requiredPrimaryTypeName))
+ {
+ unresolvedDependecies.add(requiredPrimaryTypeName);
+ }
+ }
+ if (childnodeDefinitionData.getDefaultPrimaryType() != null)
+ {
+ if (hierarchy.getNodeType(childnodeDefinitionData.getDefaultPrimaryType()) == null
+ && !resolvedDependecies.contains(childnodeDefinitionData.getDefaultPrimaryType()))
+ {
+ unresolvedDependecies.add(childnodeDefinitionData.getDefaultPrimaryType());
+
+ }
+ }
+ }
+ }
+ if (unresolvedDependecies.size() > 0)
+ {
+ String msg = "Fail. Unresolved cyclic dependecy for :";
+ for (InternalQName internalQName : resolvedDependecies)
+ {
+ msg += " " + internalQName.getAsString();
+ }
+
+ msg +=" Unresolved ";
+ for (InternalQName internalQName : unresolvedDependecies)
+ {
+ msg += " " + internalQName.getAsString();
+ }
+
+ throw new RepositoryException(msg);
+ }
+ }
+
+ /**
+ * Check according the JSR-170
+ */
+ private void validateNodeType(NodeTypeData nodeType) throws RepositoryException
+ {
+ if (nodeType == null)
+ {
+ throw new RepositoryException("NodeType object " + nodeType + " is null");
+ }
+
+ for (int i = 0; i < nodeType.getDeclaredSupertypeNames().length; i++)
+ {
+ if (!nodeType.getName().equals(Constants.NT_BASE)
+ && nodeType.getName().equals(nodeType.getDeclaredSupertypeNames()[i]))
+ {
+ throw new RepositoryException("Invalid super type name"
+ + nodeType.getDeclaredSupertypeNames()[i].getAsString());
+ }
+ }
+ for (int i = 0; i < nodeType.getDeclaredPropertyDefinitions().length; i++)
+ {
+ if (!nodeType.getDeclaredPropertyDefinitions()[i].getDeclaringNodeType().equals(nodeType.getName()))
+ {
+ throw new RepositoryException("Invalid declared node type in property definitions with name "
+ + nodeType.getDeclaredPropertyDefinitions()[i].getName().getAsString() + " not registred");
+ }
+ }
+ for (int i = 0; i < nodeType.getDeclaredChildNodeDefinitions().length; i++)
+ {
+ if (!nodeType.getDeclaredChildNodeDefinitions()[i].getDeclaringNodeType().equals(nodeType.getName()))
+ {
+ throw new RepositoryException("Invalid declared node type in child node definitions with name "
+ + nodeType.getDeclaredChildNodeDefinitions()[i].getName().getAsString() + " not registred");
+ }
+ }
+
+ if (nodeType.getName() == null)
+ {
+ throw new RepositoryException("NodeType implementation class " + nodeType.getClass().getName()
+ + " is not supported in this method");
+ }
+ }
+}
Property changes on: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/NodeTypeDataValidator.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/NodeTypeDefinitionAccessProvider.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/NodeTypeDefinitionAccessProvider.java (rev 0)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/NodeTypeDefinitionAccessProvider.java 2009-10-04 09:34:54 UTC (rev 199)
@@ -0,0 +1,251 @@
+/*
+ * 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.nodetype.registration;
+
+import org.exoplatform.services.jcr.core.nodetype.NodeDefinitionData;
+import org.exoplatform.services.jcr.core.nodetype.NodeTypeData;
+import org.exoplatform.services.jcr.core.nodetype.NodeTypeDataImpl;
+import org.exoplatform.services.jcr.core.nodetype.PropertyDefinitionData;
+import org.exoplatform.services.jcr.dataflow.DataManager;
+import org.exoplatform.services.jcr.dataflow.ItemState;
+import org.exoplatform.services.jcr.dataflow.PlainChangesLog;
+import org.exoplatform.services.jcr.datamodel.IllegalNameException;
+import org.exoplatform.services.jcr.datamodel.InternalQName;
+import org.exoplatform.services.jcr.datamodel.NodeData;
+import org.exoplatform.services.jcr.impl.Constants;
+import org.exoplatform.services.jcr.impl.dataflow.TransientNodeData;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.jcr.RepositoryException;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * @author <a href="mailto:Sergey.Kabashnyuk at gmail.com">Sergey Kabashnyuk</a>
+ * @version $Id: $
+ */
+public class NodeTypeDefinitionAccessProvider extends AbstractItemDefinitionAccessProvider
+{
+
+ private PropertyDefinitionAccessProvider propertyDefinitionAccessProvider;
+
+ private NodeDefinitionAccessProvider nodeDefinitionAccessProvider;
+
+ /**
+ * @param dataManager
+ */
+ public NodeTypeDefinitionAccessProvider(DataManager dataManager)
+ {
+ super(dataManager);
+ this.propertyDefinitionAccessProvider = new PropertyDefinitionAccessProvider(dataManager);
+ this.nodeDefinitionAccessProvider = new NodeDefinitionAccessProvider(dataManager);
+ }
+
+ public NodeTypeData read(NodeData nodeData) throws RepositoryException
+
+ {
+
+ //return new LazyLoadNodeTypeData(nodeData, this);
+ return readNow(nodeData);
+ }
+
+ /**
+ * @param nodeData
+ * @return
+ * @throws IOException
+ * @throws IllegalNameException
+ * @throws RepositoryException
+ * @throws UnsupportedEncodingException
+ */
+ public NodeTypeData readNow(NodeData nodeData) throws RepositoryException
+
+ {
+
+ InternalQName name = readMandatoryName(nodeData, Constants.JCR_NODETYPENAME);
+
+ InternalQName primaryItemName = readName(nodeData, Constants.JCR_PRIMARYITEMNAME);
+
+ boolean mixin = readMandatoryBoolean(nodeData, Constants.JCR_ISMIXIN);
+
+ boolean hasOrderableChildNodes = readMandatoryBoolean(nodeData, Constants.JCR_HASORDERABLECHILDNODES);
+ // TODO fix to mandatory
+ // boolean isAbstract = readMandatoryBoolean(nodeData, Constants.JCR_ISABSTRACT);
+ //
+ // boolean isQueryable = readBoolean(nodeData, Constants.JCR_ISQUERYABLE);
+
+ InternalQName[] declaredSupertypeNames = readNames(nodeData, Constants.JCR_SUPERTYPES);
+
+ List<PropertyDefinitionData> propertyDefinitionDataList = new ArrayList<PropertyDefinitionData>();
+ List<NodeDefinitionData> nodeDefinitionDataList = new ArrayList<NodeDefinitionData>();
+
+ List<NodeData> childDefinitions = dataManager.getChildNodesData(nodeData);
+ for (NodeData childDefinition : childDefinitions)
+ {
+ if (Constants.NT_PROPERTYDEFINITION.equals(childDefinition.getPrimaryTypeName()))
+ {
+ propertyDefinitionDataList.add(propertyDefinitionAccessProvider.read(childDefinition, name));
+ }
+ else if (Constants.NT_CHILDNODEDEFINITION.equals(childDefinition.getPrimaryTypeName()))
+ {
+ nodeDefinitionDataList.add(nodeDefinitionAccessProvider.read(childDefinition, name));
+ }
+ }
+
+ return new NodeTypeDataImpl(name, primaryItemName, mixin, hasOrderableChildNodes, declaredSupertypeNames,
+ propertyDefinitionDataList.toArray(new PropertyDefinitionData[propertyDefinitionDataList.size()]),
+ nodeDefinitionDataList.toArray(new NodeDefinitionData[nodeDefinitionDataList.size()]));
+ }
+
+ /**
+ * Read node NodeDefinitionData[] of node type
+ * @param nodeData
+ * @return
+ * @throws RepositoryException
+ * @throws NodeTypeReadException
+ * @throws UnsupportedEncodingException
+ * @throws RepositoryException
+ * @throws IllegalNameException
+ * @throws IOException
+ */
+ public NodeDefinitionData[] readNodeDefinitions(NodeData nodeData) throws NodeTypeReadException, RepositoryException
+ {
+ InternalQName name = null;
+ List<NodeDefinitionData> nodeDefinitionDataList;
+
+ List<NodeData> childDefinitions = dataManager.getChildNodesData(nodeData);
+
+ if (childDefinitions.size() > 0)
+ name = readMandatoryName(nodeData, Constants.JCR_NODETYPENAME);
+ else
+ return new NodeDefinitionData[0];
+
+ nodeDefinitionDataList = new ArrayList<NodeDefinitionData>();
+ for (NodeData childDefinition : childDefinitions)
+ {
+ if (Constants.NT_CHILDNODEDEFINITION.equals(childDefinition.getPrimaryTypeName()))
+ {
+ nodeDefinitionDataList.add(nodeDefinitionAccessProvider.read(childDefinition, name));
+ }
+ }
+
+ return nodeDefinitionDataList.toArray(new NodeDefinitionData[nodeDefinitionDataList.size()]);
+ }
+
+ /**
+ * Read PropertyDefinitionData of node type.
+ * @param nodeData
+ * @return
+ * @throws RepositoryException
+ * @throws NodeTypeReadException
+ * @throws UnsupportedEncodingException
+ * @throws RepositoryException
+ * @throws IllegalNameException
+ * @throws IOException
+ */
+ public PropertyDefinitionData[] readPropertyDefinitions(NodeData nodeData) throws NodeTypeReadException,
+ RepositoryException
+ {
+
+ List<PropertyDefinitionData> propertyDefinitionDataList;
+
+ List<NodeData> childDefinitions = dataManager.getChildNodesData(nodeData);
+ InternalQName name = null;
+ if (childDefinitions.size() > 0)
+ name = readMandatoryName(nodeData, Constants.JCR_NODETYPENAME);
+ else
+ return new PropertyDefinitionData[0];
+ propertyDefinitionDataList = new ArrayList<PropertyDefinitionData>();
+
+ for (NodeData childDefinition : childDefinitions)
+ {
+ if (Constants.NT_PROPERTYDEFINITION.equals(childDefinition.getPrimaryTypeName()))
+ {
+ propertyDefinitionDataList.add(propertyDefinitionAccessProvider.read(childDefinition, name));
+ }
+ }
+
+ return propertyDefinitionDataList.toArray(new PropertyDefinitionData[propertyDefinitionDataList.size()]);
+ }
+
+ /**
+ * @param nodeData
+ * @param nodeTypeData
+ * @return
+ * @throws RepositoryException
+ * @throws NodeTypeReadException
+ */
+ public void write(PlainChangesLog changesLog, NodeData nodeTypeStorageRoot, NodeTypeData nodeType)
+ throws NodeTypeReadException, RepositoryException
+ {
+
+ NodeData ntNode =
+ TransientNodeData.createNodeData(nodeTypeStorageRoot, nodeType.getName(), Constants.NT_NODETYPE);
+
+ changesLog.add(ItemState.createAddedState(ntNode));
+
+ writeName(changesLog, ntNode, Constants.JCR_PRIMARYTYPE, ntNode.getPrimaryTypeName());
+
+ // jcr:nodeTypeName
+ writeName(changesLog, ntNode, Constants.JCR_NODETYPENAME, nodeType.getName());
+
+ // jcr:isMixin
+ writeBoolean(changesLog, ntNode, Constants.JCR_ISMIXIN, nodeType.isMixin());
+
+ // // jcr:isAbstract
+ // writeBoolean(changesLog, ntNode, Constants.JCR_ISABSTRACT, nodeType.isAbstract());
+ //
+ // // jcr:isQueryable
+ // writeBoolean(changesLog, ntNode, Constants.JCR_ISQUERYABLE, nodeType.isQueryable());
+
+ // jcr:hasOrderableChildNodes
+ writeBoolean(changesLog, ntNode, Constants.JCR_HASORDERABLECHILDNODES, nodeType.hasOrderableChildNodes());
+
+ if (nodeType.getPrimaryItemName() != null)
+ {
+ // jcr:primaryItemName
+ writeName(changesLog, ntNode, Constants.JCR_PRIMARYITEMNAME, nodeType.getPrimaryItemName());
+ }
+
+ if (nodeType.getDeclaredSupertypeNames() != null && nodeType.getDeclaredSupertypeNames().length > 0)
+ {
+ // jcr:supertypes
+ writeNames(changesLog, ntNode, Constants.JCR_SUPERTYPES, nodeType.getDeclaredSupertypeNames());
+ }
+
+ for (int i = 0; i < nodeType.getDeclaredPropertyDefinitions().length; i++)
+ {
+
+ propertyDefinitionAccessProvider
+ .write(changesLog, ntNode, nodeType.getDeclaredPropertyDefinitions()[i], i + 1);
+
+ }
+
+ for (int i = 0; i < nodeType.getDeclaredChildNodeDefinitions().length; i++)
+ {
+
+ nodeDefinitionAccessProvider.write(changesLog, ntNode, nodeType.getDeclaredChildNodeDefinitions()[i], i + 1);
+
+ }
+
+ }
+}
Property changes on: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/NodeTypeDefinitionAccessProvider.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/NodeTypeReadException.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/NodeTypeReadException.java (rev 0)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/NodeTypeReadException.java 2009-10-04 09:34:54 UTC (rev 199)
@@ -0,0 +1,73 @@
+/*
+ * 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.nodetype.registration;
+
+import javax.jcr.RepositoryException;
+
+/**
+ * @author <a href="mailto:Sergey.Kabashnyuk at exoplatform.org">Sergey Kabashnyuk</a>
+ * @version $Id: exo-jboss-codetemplates.xml 34360 2009-07-22 23:58:59Z ksm $
+ *
+ */
+public class NodeTypeReadException extends RepositoryException
+{
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ *
+ */
+ public NodeTypeReadException()
+ {
+ super();
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * @param message
+ * @param rootCause
+ */
+ public NodeTypeReadException(String message, Throwable rootCause)
+ {
+ super(message, rootCause);
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * @param message
+ */
+ public NodeTypeReadException(String message)
+ {
+ super(message);
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * @param rootCause
+ */
+ public NodeTypeReadException(Throwable rootCause)
+ {
+ super(rootCause);
+ // TODO Auto-generated constructor stub
+ }
+
+}
Property changes on: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/NodeTypeReadException.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/PropertyDefinitionAccessProvider.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/PropertyDefinitionAccessProvider.java (rev 0)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/PropertyDefinitionAccessProvider.java 2009-10-04 09:34:54 UTC (rev 199)
@@ -0,0 +1,126 @@
+/*
+ * 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.nodetype.registration;
+
+import org.exoplatform.services.jcr.core.ExtendedPropertyType;
+import org.exoplatform.services.jcr.core.nodetype.PropertyDefinitionData;
+import org.exoplatform.services.jcr.dataflow.DataManager;
+import org.exoplatform.services.jcr.dataflow.ItemState;
+import org.exoplatform.services.jcr.dataflow.PlainChangesLog;
+import org.exoplatform.services.jcr.datamodel.InternalQName;
+import org.exoplatform.services.jcr.datamodel.NodeData;
+import org.exoplatform.services.jcr.impl.Constants;
+import org.exoplatform.services.jcr.impl.dataflow.TransientNodeData;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.version.OnParentVersionAction;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * @author <a href="mailto:Sergey.Kabashnyuk at gmail.com">Sergey Kabashnyuk</a>
+ * @version $Id: $
+ */
+public class PropertyDefinitionAccessProvider extends AbstractItemDefinitionAccessProvider
+{
+
+ public PropertyDefinitionAccessProvider(DataManager dataManager)
+ {
+ super(dataManager);
+
+ }
+
+ public PropertyDefinitionData read(NodeData nodeData, InternalQName declaringNodeType) throws NodeTypeReadException,
+ RepositoryException
+
+ {
+ if (Constants.NT_PROPERTYDEFINITION.equals(nodeData.getPrimaryTypeName()))
+ {
+
+ // null if residual;
+ InternalQName name = readName(nodeData, Constants.JCR_NAME);
+ boolean protectedItem = readMandatoryBoolean(nodeData, Constants.JCR_PROTECTED);
+ boolean autoCreated = readMandatoryBoolean(nodeData, Constants.JCR_AUTOCREATED);
+ boolean mandatory = readMandatoryBoolean(nodeData, Constants.JCR_MANDATORY);
+ int onParentVersion =
+ OnParentVersionAction.valueFromName(readMandatoryString(nodeData, Constants.JCR_ONPARENTVERSION));
+
+ int requiredType =
+ ExtendedPropertyType.valueFromName(readMandatoryString(nodeData, Constants.JCR_REQUIREDTYPE));
+
+ boolean multiple = readMandatoryBoolean(nodeData, Constants.JCR_MULTIPLE);
+
+ //3 Query atributes
+// boolean isQueryOrderable = readMandatoryBoolean(nodeData, Constants.JCR_QUERYORDERABLE);
+// String[] availableQueryOperators = readMandatoryStrings(nodeData, Constants.JCR_AVAILABLEQUERYOPERATORS);
+// boolean isFullTextSearchable = readMandatoryBoolean(nodeData, Constants.JCR_ISFULLTEXTSEARCHABLE);
+
+ String[] valueConstraints = readStrings(nodeData, Constants.JCR_VALUECONSTRAINTS);
+ String[] defaultValues = readStrings(nodeData, Constants.JCR_DEFAULTVALUES);
+
+ return new PropertyDefinitionData(name, declaringNodeType, autoCreated, mandatory, onParentVersion,
+ protectedItem, requiredType, valueConstraints, defaultValues, multiple);
+ }
+ return null;
+ }
+
+ public void write(PlainChangesLog changesLog, NodeData declaredNodeType,
+ PropertyDefinitionData propertyDefinitionData, int index)
+ {
+
+ NodeData propertyDefinition =
+ TransientNodeData.createNodeData(declaredNodeType, Constants.JCR_PROPERTYDEFINITION,
+ Constants.NT_PROPERTYDEFINITION, index);
+ changesLog.add(ItemState.createAddedState(propertyDefinition));
+
+ writeItemDefinition(changesLog, propertyDefinition, propertyDefinitionData);
+
+ writeName(changesLog, propertyDefinition, Constants.JCR_PRIMARYTYPE, propertyDefinition.getPrimaryTypeName());
+
+ writeString(changesLog, propertyDefinition, Constants.JCR_REQUIREDTYPE, ExtendedPropertyType
+ .nameFromValue(propertyDefinitionData.getRequiredType()));
+
+ writeBoolean(changesLog, propertyDefinition, Constants.JCR_MULTIPLE, propertyDefinitionData.isMultiple());
+
+ //3 Query atributes
+// writeBoolean(changesLog, propertyDefinition, Constants.JCR_QUERYORDERABLE, propertyDefinitionData
+// .isQueryOrderable());
+// writeStrings(changesLog, propertyDefinition, Constants.JCR_AVAILABLEQUERYOPERATORS, propertyDefinitionData
+// .getAvailableQueryOperators());
+// writeBoolean(changesLog, propertyDefinition, Constants.JCR_ISFULLTEXTSEARCHABLE, propertyDefinitionData
+// .isFullTextSearchable());
+
+ if (propertyDefinitionData.getValueConstraints() != null
+ && propertyDefinitionData.getValueConstraints().length != 0)
+ {
+
+ writeStrings(changesLog, propertyDefinition, Constants.JCR_VALUECONSTRAINTS, propertyDefinitionData
+ .getValueConstraints());
+ }
+
+ if (propertyDefinitionData.getDefaultValues() != null && propertyDefinitionData.getDefaultValues().length != 0)
+ {
+
+ writeStrings(changesLog, propertyDefinition, Constants.JCR_DEFAULTVALUES, propertyDefinitionData
+ .getDefaultValues());
+
+ }
+ }
+
+}
Property changes on: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/PropertyDefinitionAccessProvider.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/PropertyDefinitionComparator.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/PropertyDefinitionComparator.java 2009-10-02 15:41:14 UTC (rev 198)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/PropertyDefinitionComparator.java 2009-10-04 09:34:54 UTC (rev 199)
@@ -22,7 +22,7 @@
import org.exoplatform.services.jcr.core.nodetype.NodeTypeData;
import org.exoplatform.services.jcr.core.nodetype.NodeTypeDataManager;
import org.exoplatform.services.jcr.core.nodetype.PropertyDefinitionData;
-import org.exoplatform.services.jcr.dataflow.DataManager;
+import org.exoplatform.services.jcr.dataflow.ItemDataConsumer;
import org.exoplatform.services.jcr.dataflow.PlainChangesLog;
import org.exoplatform.services.jcr.dataflow.PlainChangesLogImpl;
import org.exoplatform.services.jcr.datamodel.InternalQName;
@@ -33,6 +33,7 @@
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.ItemAutocreator;
import org.exoplatform.services.jcr.impl.core.value.ValueConstraintsMatcher;
import org.exoplatform.services.jcr.impl.dataflow.AbstractValueData;
import org.exoplatform.services.log.ExoLogger;
@@ -41,7 +42,6 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
-import java.util.Set;
import javax.jcr.PropertyType;
import javax.jcr.RepositoryException;
@@ -60,17 +60,28 @@
*/
private static final Log LOG = ExoLogger.getLogger(PropertyDefinitionComparator.class);
+ private final List<NodeData> affectedNodes;
+
private final LocationFactory locationFactory;
+ private final NodeTypeDataManager nodeTypeDataManager;
+
+ private final ItemDataConsumer dataConsumer;
+
+ private final ItemAutocreator itemAutocreator;
+
/**
* @param nodeTypeDataManager
* @param persister
* @param locationFactory
*/
- public PropertyDefinitionComparator(NodeTypeDataManager nodeTypeDataManager, DataManager persister,
- LocationFactory locationFactory)
+ public PropertyDefinitionComparator(NodeTypeDataManager nodeTypeDataManager, ItemDataConsumer dataConsumer,
+ ItemAutocreator itemAutocreator, List<NodeData> affectedNodes, LocationFactory locationFactory)
{
- super(nodeTypeDataManager, persister);
+ this.nodeTypeDataManager = nodeTypeDataManager;
+ this.dataConsumer = dataConsumer;
+ this.itemAutocreator = itemAutocreator;
+ this.affectedNodes = affectedNodes;
this.locationFactory = locationFactory;
}
@@ -90,19 +101,17 @@
// create changes log
PlainChangesLog changesLog = new PlainChangesLogImpl();
- // DataManager dm = persister.getDataManager();
// removing properties
- validateRemoved(registeredNodeType, removedDefinitionData, recipientDefinition);
+ validateRemoved(registeredNodeType, removedDefinitionData, recipientDefinition, affectedNodes);
// new property definition
- validateAdded(registeredNodeType, newDefinitionData, recipientDefinition);
+ validateAdded(registeredNodeType, newDefinitionData, recipientDefinition, affectedNodes);
- Set<String> nodes = nodeTypeDataManager.getNodes(registeredNodeType.getName());
// changed
- validateChanged(registeredNodeType, changedDefinitionData, nodes, recipientDefinition);
+ validateChanged(registeredNodeType, changedDefinitionData, affectedNodes, recipientDefinition);
//
- doAdd(newDefinitionData, changesLog, nodes, registeredNodeType);
+ doAdd(newDefinitionData, changesLog, affectedNodes, registeredNodeType);
return changesLog;
}
@@ -115,25 +124,24 @@
* @throws ConstraintViolationException
*/
private void checkIsMultiple(NodeTypeData registeredNodeType, PropertyDefinitionData recipientDefinitionData,
- PropertyDefinitionData[] allRecipientDefinition) throws RepositoryException, ConstraintViolationException
+ PropertyDefinitionData[] allRecipientDefinition, List<NodeData> nodesData) throws RepositoryException,
+ ConstraintViolationException
{
- Set<String> nodes2;
+ List<NodeData> checkIsMultipleNodes;
if (Constants.JCR_ANY_NAME.equals(recipientDefinitionData.getName()))
{
- nodes2 = nodeTypeDataManager.getNodes(registeredNodeType.getName());
+ checkIsMultipleNodes = nodesData;
}
else
{
- nodes2 =
- nodeTypeDataManager.getNodes(registeredNodeType.getName(), new InternalQName[]{recipientDefinitionData
- .getName()}, new InternalQName[]{});
+ checkIsMultipleNodes =
+ getNodes(nodesData, new InternalQName[]{recipientDefinitionData.getName()}, new InternalQName[]{});
}
- for (String uuid : nodes2)
+ for (NodeData nodeData : checkIsMultipleNodes)
{
- NodeData nodeData = (NodeData)persister.getItemData(uuid);
if (Constants.JCR_ANY_NAME.equals(recipientDefinitionData.getName()))
{
- List<PropertyData> propertyDatas = persister.getChildPropertiesData(nodeData);
+ List<PropertyData> propertyDatas = dataConsumer.getChildPropertiesData(nodeData);
for (PropertyData propertyData : propertyDatas)
{
// skip mixin and primary type
@@ -151,7 +159,7 @@
else
{
PropertyData propertyData =
- (PropertyData)persister.getItemData(nodeData, new QPathEntry(recipientDefinitionData.getName(), 0));
+ (PropertyData)dataConsumer.getItemData(nodeData, new QPathEntry(recipientDefinitionData.getName(), 0));
if (propertyData.getValues().size() > 1)
{
throw new ConstraintViolationException("Can't change property definition "
@@ -169,23 +177,22 @@
* @param recipientDefinitionData
* @throws RepositoryException
*/
- private void checkMandatory(NodeTypeData registeredNodeType, Set<String> nodes,
+ private void checkMandatory(NodeTypeData registeredNodeType, List<NodeData> nodesData,
PropertyDefinitionData recipientDefinitionData) throws RepositoryException
{
if (Constants.JCR_ANY_NAME.equals(recipientDefinitionData.getName()) && recipientDefinitionData.isMandatory())
throw new ConstraintViolationException("Invalid property definition " + recipientDefinitionData.getName()
+ ". Residual definition can't be mandatory");
- Set<String> nodes2 =
- nodeTypeDataManager.getNodes(registeredNodeType.getName(), new InternalQName[]{},
- new InternalQName[]{recipientDefinitionData.getName()});
- if (nodes2.size() > 0)
+ List<NodeData> mandatoryNodes =
+ getNodes(nodesData, new InternalQName[]{}, new InternalQName[]{recipientDefinitionData.getName()});
+ if (mandatoryNodes.size() > 0)
{
String message =
"Can not change " + recipientDefinitionData.getName().getAsString()
+ " property definition from mandatory=false to mandatory = true , because " + " the following nodes ";
- for (String uuids : nodes)
+ for (NodeData nodeData : mandatoryNodes)
{
- message += uuids + " ";
+ message += nodeData.getQPath().getAsString() + " ";
}
message += " doesn't have these properties ";
@@ -199,24 +206,23 @@
* @param recipientDefinitionData
* @throws RepositoryException
*/
- private void checkProtected(NodeTypeData registeredNodeType, Set<String> nodes,
+ private void checkProtected(NodeTypeData registeredNodeType, List<NodeData> nodesData,
PropertyDefinitionData recipientDefinitionData) throws RepositoryException
{
if (Constants.JCR_ANY_NAME.equals(recipientDefinitionData.getName()) && recipientDefinitionData.isMandatory())
throw new ConstraintViolationException("Invalid property definition " + recipientDefinitionData.getName()
+ ". Residual definition can't be protected");
- Set<String> nodes2 =
- nodeTypeDataManager.getNodes(registeredNodeType.getName(), new InternalQName[]{},
- new InternalQName[]{recipientDefinitionData.getName()});
- if (nodes2.size() > 0)
+ List<NodeData> protectedNodes =
+ getNodes(nodesData, new InternalQName[]{}, new InternalQName[]{recipientDefinitionData.getName()});
+ if (protectedNodes.size() > 0)
{
String message =
"Can not change " + recipientDefinitionData.getName().getAsString()
+ " property definition from Protected=false to Protected = true , because " + " the following nodes ";
- for (String uuids : nodes)
+ for (NodeData nodeData : protectedNodes)
{
- message += uuids + " ";
+ message += nodeData.getQPath().getAsString() + " ";
}
message += " doesn't have these properties ";
@@ -231,31 +237,30 @@
* @throws RepositoryException
*/
private void checkRequiredType(NodeTypeData registeredNodeType, PropertyDefinitionData recipientDefinitionData,
- PropertyDefinitionData[] allRecipientDefinition) throws RepositoryException
+ PropertyDefinitionData[] allRecipientDefinition, List<NodeData> nodesData) throws RepositoryException
{
- Set<String> nodes2;
+ List<NodeData> requiredTypeNodes;
if (Constants.JCR_ANY_NAME.equals(recipientDefinitionData.getName()))
{
- nodes2 = nodeTypeDataManager.getNodes(registeredNodeType.getName());
+ requiredTypeNodes = nodesData;
}
else
{
- nodes2 =
- nodeTypeDataManager.getNodes(registeredNodeType.getName(), new InternalQName[]{recipientDefinitionData
- .getName()}, new InternalQName[]{});
+ requiredTypeNodes =
+ getNodes(nodesData, new InternalQName[]{recipientDefinitionData.getName()}, new InternalQName[]{});
}
- for (String uuid : nodes2)
+ for (NodeData nodeData : requiredTypeNodes)
{
- NodeData nodeData = (NodeData)persister.getItemData(uuid);
if (Constants.JCR_ANY_NAME.equals(recipientDefinitionData.getName()))
{
- List<PropertyData> propertyDatas = persister.getChildPropertiesData(nodeData);
+ List<PropertyData> propertyDatas = dataConsumer.getChildPropertiesData(nodeData);
for (PropertyData propertyData : propertyDatas)
{
// skip mixin and primary type
if (isResidualMatch(propertyData.getQPath().getName(), allRecipientDefinition))
{
- if (propertyData.getType() != recipientDefinitionData.getRequiredType())
+ if (recipientDefinitionData.getRequiredType() != PropertyType.UNDEFINED
+ && propertyData.getType() != recipientDefinitionData.getRequiredType())
{
throw new ConstraintViolationException("Can not change requiredType to "
+ ExtendedPropertyType.nameFromValue(recipientDefinitionData.getRequiredType()) + " in "
@@ -271,8 +276,9 @@
else
{
PropertyData propertyData =
- (PropertyData)persister.getItemData(nodeData, new QPathEntry(recipientDefinitionData.getName(), 0));
- if (propertyData.getType() != recipientDefinitionData.getRequiredType())
+ (PropertyData)dataConsumer.getItemData(nodeData, new QPathEntry(recipientDefinitionData.getName(), 0));
+ if (recipientDefinitionData.getRequiredType() != PropertyType.UNDEFINED
+ && propertyData.getType() != recipientDefinitionData.getRequiredType())
{
throw new ConstraintViolationException("Can not change requiredType to "
+ ExtendedPropertyType.nameFromValue(recipientDefinitionData.getRequiredType()) + " in "
@@ -293,25 +299,25 @@
* @throws ConstraintViolationException
*/
private void checkValueConstraints(NodeTypeData registeredNodeType, PropertyDefinitionData recipientDefinitionData,
- PropertyDefinitionData[] allRecipientDefinition) throws RepositoryException, ConstraintViolationException
+ PropertyDefinitionData[] allRecipientDefinition, List<NodeData> nodesData) throws RepositoryException,
+ ConstraintViolationException
{
- Set<String> nodes2;
+ List<NodeData> checkValueConstraintsNodes;
if (Constants.JCR_ANY_NAME.equals(recipientDefinitionData.getName()))
{
- nodes2 = nodeTypeDataManager.getNodes(registeredNodeType.getName());
+ checkValueConstraintsNodes = nodesData;
}
else
{
- nodes2 =
- nodeTypeDataManager.getNodes(registeredNodeType.getName(), new InternalQName[]{recipientDefinitionData
- .getName()}, new InternalQName[]{});
+ checkValueConstraintsNodes =
+ getNodes(nodesData, new InternalQName[]{recipientDefinitionData.getName()}, new InternalQName[]{});
}
- for (String uuid : nodes2)
+ for (NodeData nodeData : checkValueConstraintsNodes)
{
- NodeData nodeData = (NodeData)persister.getItemData(uuid);
+
if (Constants.JCR_ANY_NAME.equals(recipientDefinitionData.getName()))
{
- List<PropertyData> propertyDatas = persister.getChildPropertiesData(nodeData);
+ List<PropertyData> propertyDatas = dataConsumer.getChildPropertiesData(nodeData);
for (PropertyData propertyData : propertyDatas)
{
// skip mixin and primary type
@@ -324,7 +330,7 @@
else
{
PropertyData propertyData =
- (PropertyData)persister.getItemData(nodeData, new QPathEntry(recipientDefinitionData.getName(), 0));
+ (PropertyData)dataConsumer.getItemData(nodeData, new QPathEntry(recipientDefinitionData.getName(), 0));
checkValueConstraints(recipientDefinitionData, propertyData);
}
}
@@ -335,7 +341,7 @@
{
ValueConstraintsMatcher constraints =
- new ValueConstraintsMatcher(def.getValueConstraints(), locationFactory, persister, nodeTypeDataManager);
+ new ValueConstraintsMatcher(def.getValueConstraints(), locationFactory, dataConsumer, nodeTypeDataManager);
for (ValueData value : propertyData.getValues())
{
@@ -371,12 +377,11 @@
* @param registeredNodeType
* @throws RepositoryException
*/
- private void doAdd(List<PropertyDefinitionData> toAddList, PlainChangesLog changesLog, Set<String> nodes,
+ private void doAdd(List<PropertyDefinitionData> toAddList, PlainChangesLog changesLog, List<NodeData> nodesData,
NodeTypeData registeredNodeType) throws RepositoryException
{
- for (String uuid : nodes)
+ for (NodeData nodeData : nodesData)
{
- NodeData nodeData = (NodeData)persister.getItemData(uuid);
// added properties
for (PropertyDefinitionData newPropertyDefinitionData : toAddList)
@@ -384,12 +389,13 @@
if (!newPropertyDefinitionData.getName().equals(Constants.JCR_ANY_NAME)
&& newPropertyDefinitionData.isAutoCreated())
{
- ItemData pdata = persister.getItemData(nodeData, new QPathEntry(newPropertyDefinitionData.getName(), 0));
+ ItemData pdata =
+ dataConsumer.getItemData(nodeData, new QPathEntry(newPropertyDefinitionData.getName(), 0));
if (pdata == null || (pdata != null && pdata.isNode()))
{
PlainChangesLog autoCreatedChanges =
- nodeTypeDataManager.makeAutoCreatedProperties(nodeData, registeredNodeType.getName(),
- new PropertyDefinitionData[]{newPropertyDefinitionData}, persister, nodeData.getACL()
+ itemAutocreator.makeAutoCreatedProperties(nodeData, registeredNodeType.getName(),
+ new PropertyDefinitionData[]{newPropertyDefinitionData}, dataConsumer, nodeData.getACL()
.getOwner());
if (autoCreatedChanges.getSize() == 0)
{
@@ -405,6 +411,58 @@
}
/**
+ * @param nodes
+ * @param includeProperties
+ * @param excludeProperties
+ * @return All nodes from list nodes, what include properties from
+ * includeProperties, and doesn't include properties from
+ * excludeProperties.
+ * @throws RepositoryException
+ */
+ private List<NodeData> getNodes(List<NodeData> nodes, InternalQName[] includeProperties,
+ InternalQName[] excludeProperties) throws RepositoryException
+ {
+ List<NodeData> result = new ArrayList<NodeData>();
+
+ for (NodeData nodeData : nodes)
+ {
+ // search all properties
+ List<PropertyData> childProperties = dataConsumer.listChildPropertiesData(nodeData);
+ boolean toAdd = includeProperties.length == 0;
+ // check included
+ for (int i = 0; i < includeProperties.length; i++)
+ {
+ for (PropertyData propertyData : childProperties)
+ {
+ if (propertyData.getQPath().getName().equals(includeProperties[i]))
+ {
+ toAdd = true;
+ break;
+ }
+ }
+ }
+ if (toAdd)
+ {
+ // check excluded
+ for (int i = 0; i < excludeProperties.length; i++)
+ {
+ for (PropertyData propertyData : childProperties)
+ {
+ if (propertyData.getQPath().getName().equals(excludeProperties[i]))
+ {
+ toAdd = false;
+ break;
+ }
+ }
+ }
+ if (toAdd)
+ result.add(nodeData);
+ }
+ }
+ return result;
+ }
+
+ /**
* @param registeredNodeType
* @param newDefinitionData
* @param removedDefinitionData
@@ -412,7 +470,7 @@
* @throws RepositoryException
*/
private void validateAdded(NodeTypeData registeredNodeType, List<PropertyDefinitionData> newDefinitionData,
- PropertyDefinitionData[] allRecipientDefinition) throws RepositoryException
+ PropertyDefinitionData[] allRecipientDefinition, List<NodeData> nodesData) throws RepositoryException
{
if (newDefinitionData.size() > 0)
{
@@ -421,11 +479,11 @@
if (propertyDefinitionData.getName().equals(Constants.JCR_ANY_NAME))
{
// Required type change
- checkRequiredType(registeredNodeType, propertyDefinitionData, allRecipientDefinition);
+ checkRequiredType(registeredNodeType, propertyDefinitionData, allRecipientDefinition, nodesData);
// ValueConstraints
- checkValueConstraints(registeredNodeType, propertyDefinitionData, allRecipientDefinition);
+ checkValueConstraints(registeredNodeType, propertyDefinitionData, allRecipientDefinition, nodesData);
// multiple change
- checkIsMultiple(registeredNodeType, propertyDefinitionData, allRecipientDefinition);
+ checkIsMultiple(registeredNodeType, propertyDefinitionData, allRecipientDefinition, nodesData);
}
}
}
@@ -439,7 +497,7 @@
* @throws RepositoryException
*/
private void validateChanged(NodeTypeData registeredNodeType,
- List<RelatedDefinition<PropertyDefinitionData>> changedDefinitionData, Set<String> nodes,
+ List<RelatedDefinition<PropertyDefinitionData>> changedDefinitionData, List<NodeData> nodesData,
PropertyDefinitionData[] allRecipientDefinition) throws RepositoryException
{
for (RelatedDefinition<PropertyDefinitionData> relatedDefinitions : changedDefinitionData)
@@ -449,30 +507,31 @@
// change from mandatory=false to mandatory = true
if (!ancestorDefinitionData.isMandatory() && recipientDefinitionData.isMandatory())
{
- checkMandatory(registeredNodeType, nodes, recipientDefinitionData);
+ checkMandatory(registeredNodeType, nodesData, recipientDefinitionData);
}
+ // No need to check protected
// change from Protected=false to Protected = true
- if (!ancestorDefinitionData.isProtected() && recipientDefinitionData.isProtected())
- {
- checkProtected(registeredNodeType, nodes, recipientDefinitionData);
- }
+ // if (!ancestorDefinitionData.isProtected() &&
+ // recipientDefinitionData.isProtected()) {
+ // checkProtected(registeredNodeType, nodesData, recipientDefinitionData);
+ // }
// Required type change
if (ancestorDefinitionData.getRequiredType() != recipientDefinitionData.getRequiredType()
&& recipientDefinitionData.getRequiredType() != PropertyType.UNDEFINED)
{
- checkRequiredType(registeredNodeType, recipientDefinitionData, allRecipientDefinition);
+ checkRequiredType(registeredNodeType, recipientDefinitionData, allRecipientDefinition, nodesData);
}
// ValueConstraints
if (!Arrays.deepEquals(ancestorDefinitionData.getValueConstraints(), recipientDefinitionData
.getValueConstraints()))
{
- checkValueConstraints(registeredNodeType, recipientDefinitionData, allRecipientDefinition);
+ checkValueConstraints(registeredNodeType, recipientDefinitionData, allRecipientDefinition, nodesData);
}
// multiple change
if (ancestorDefinitionData.isMultiple() && !recipientDefinitionData.isMultiple())
{
- checkIsMultiple(registeredNodeType, recipientDefinitionData, allRecipientDefinition);
+ checkIsMultiple(registeredNodeType, recipientDefinitionData, allRecipientDefinition, nodesData);
}
}
@@ -485,18 +544,16 @@
* @throws RepositoryException
*/
private void validateRemoved(NodeTypeData registeredNodeType, List<PropertyDefinitionData> removedDefinitionData,
- PropertyDefinitionData[] recipientDefinition) throws RepositoryException
+ PropertyDefinitionData[] recipientDefinition, List<NodeData> nodesData) throws RepositoryException
{
for (PropertyDefinitionData removePropertyDefinitionData : removedDefinitionData)
{
- Set<String> nodes;
if (removePropertyDefinitionData.getName().equals(Constants.JCR_ANY_NAME))
{
- nodes = nodeTypeDataManager.getNodes(registeredNodeType.getName());
- for (String uuid : nodes)
+
+ for (NodeData nodeData : nodesData)
{
- NodeData nodeData = (NodeData)persister.getItemData(uuid);
- List<PropertyData> childs = persister.getChildPropertiesData(nodeData);
+ List<PropertyData> childs = dataConsumer.getChildPropertiesData(nodeData);
// more then mixin and primary type
// TODO it could be possible, check add definitions
for (PropertyData propertyData : childs)
@@ -514,17 +571,16 @@
else if (!isResidualMatch(removePropertyDefinitionData.getName(), recipientDefinition))
{
// TODO more complex exception
- nodes =
- nodeTypeDataManager.getNodes(registeredNodeType.getName(),
- new InternalQName[]{removePropertyDefinitionData.getName()}, new InternalQName[]{});
+ List<NodeData> nodes =
+ getNodes(nodesData, new InternalQName[]{removePropertyDefinitionData.getName()}, new InternalQName[]{});
if (nodes.size() > 0)
{
String message =
"Can not remove " + removePropertyDefinitionData.getName().getAsString()
+ " PropertyDefinitionData, because the following nodes have these properties: ";
- for (String uuids : nodes)
+ for (NodeData nodeData : nodes)
{
- message += uuids + " ";
+ message += nodeData.getQPath().getAsString() + " ";
}
throw new ConstraintViolationException(message);
Added: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/UpdateNodeTypeObserver.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/UpdateNodeTypeObserver.java (rev 0)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/UpdateNodeTypeObserver.java 2009-10-04 09:34:54 UTC (rev 199)
@@ -0,0 +1,61 @@
+/*
+ * 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.nodetype.registration;
+
+import org.exoplatform.services.jcr.core.nodetype.NodeTypeData;
+
+import javax.jcr.RepositoryException;
+
+/**
+ * Created by The eXo Platform SAS. Helps to add changes in content in
+ * repository in case of node type update.
+ *
+ * @author <a href="mailto:Sergey.Kabashnyuk at gmail.com">Sergey Kabashnyuk</a>
+ * @version $Id: $
+ */
+public interface UpdateNodeTypeObserver
+{
+ /**
+ * Call after update.
+ *
+ * @param updatetNodetype
+ * @param context
+ */
+ void afterUpdate(NodeTypeData updatetNodetype, Object context) throws RepositoryException;
+
+ /**
+ * Call before update.
+ *
+ * @param updatetNodetype
+ * @param context
+ * @throws RepositoryException
+ */
+ void beforeUpdate(NodeTypeData updatetNodetype, Object context) throws RepositoryException;
+
+ /**
+ * Should the registration of node type be skipped.
+ * For example if ExtendedNodeTypeManager.IGNORE_IF_EXISTS flag is set.
+ *
+ * @param updatetNodetype
+ * @param context
+ * @throws RepositoryException
+ * @throws RepositoryException
+ */
+ boolean shouldSkip(NodeTypeData updatetNodetype, Object context) throws RepositoryException;
+}
Property changes on: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/UpdateNodeTypeObserver.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/XmlNodeTypeDataPersister.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/XmlNodeTypeDataPersister.java (rev 0)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/XmlNodeTypeDataPersister.java 2009-10-04 09:34:54 UTC (rev 199)
@@ -0,0 +1,164 @@
+/*
+ * 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.nodetype.registration;
+
+import org.exoplatform.services.jcr.core.nodetype.NodeTypeData;
+import org.exoplatform.services.jcr.core.nodetype.NodeTypeValuesList;
+import org.exoplatform.services.jcr.datamodel.InternalQName;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+import org.jibx.runtime.BindingDirectory;
+import org.jibx.runtime.IBindingFactory;
+import org.jibx.runtime.IUnmarshallingContext;
+import org.jibx.runtime.JiBXException;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.List;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.UnsupportedRepositoryOperationException;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * @author <a href="mailto:Sergey.Kabashnyuk at gmail.com">Sergey Kabashnyuk</a>
+ * @version $Id: $
+ */
+public class XmlNodeTypeDataPersister implements NodeTypeDataPersister
+{
+ /**
+ * Class logger.
+ */
+ private final Log log = ExoLogger.getLogger(XmlNodeTypeDataPersister.class);
+
+ private final NodeTypeConverter converter;
+
+ private final InputStream is;
+
+ private final OutputStream os;
+
+ public XmlNodeTypeDataPersister(NodeTypeConverter converter, InputStream is)
+ {
+ super();
+ this.converter = converter;
+ this.is = is;
+ this.os = null;
+ }
+
+ /**
+ * @param converter
+ * @param is
+ * @param os
+ */
+ public XmlNodeTypeDataPersister(NodeTypeConverter converter, InputStream is, OutputStream os)
+ {
+ super();
+ this.converter = converter;
+ this.is = is;
+ this.os = os;
+ }
+
+ public XmlNodeTypeDataPersister(NodeTypeConverter converter, OutputStream os)
+ {
+ super();
+ this.converter = converter;
+ this.os = os;
+ this.is = null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void addNodeType(NodeTypeData nodeType) throws RepositoryException
+ {
+ throw new UnsupportedRepositoryOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean hasNodeType(InternalQName nodeTypeName) throws RepositoryException
+ {
+ throw new UnsupportedRepositoryOperationException();
+ }
+
+ public boolean isStorageFilled()
+ {
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void addNodeTypes(List<NodeTypeData> nodeTypes) throws RepositoryException
+ {
+ throw new UnsupportedRepositoryOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void removeNodeType(NodeTypeData nodeType) throws RepositoryException
+ {
+ throw new UnsupportedRepositoryOperationException();
+ }
+
+ public void start()
+ {
+ }
+
+ public void stop()
+ {
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public List<NodeTypeData> getAllNodeTypes() throws RepositoryException
+ {
+ try
+ {
+ IBindingFactory factory = BindingDirectory.getFactory(NodeTypeValuesList.class);
+ IUnmarshallingContext uctx = factory.createUnmarshallingContext();
+ NodeTypeValuesList nodeTypeValuesList = (NodeTypeValuesList)uctx.unmarshalDocument(is, null);
+ List ntvList = nodeTypeValuesList.getNodeTypeValuesList();
+ return converter.convertFromValueToData(ntvList);
+ }
+ catch (JiBXException e)
+ {
+ throw new RepositoryException(e);
+ }
+ }
+
+ public void update(List<NodeTypeData> nodeTypes, UpdateNodeTypeObserver observer) throws RepositoryException
+ {
+ throw new UnsupportedRepositoryOperationException();
+ }
+
+ /**
+ * @see org.exoplatform.services.jcr.impl.core.nodetype.registration.NodeTypeDataPersister#getNodeType(org.exoplatform.services.jcr.datamodel.InternalQName)
+ */
+ public NodeTypeData getNodeType(InternalQName nodeTypeName) throws RepositoryException
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
Property changes on: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/XmlNodeTypeDataPersister.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/observation/ActionLauncher.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/observation/ActionLauncher.java 2009-10-02 15:41:14 UTC (rev 198)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/observation/ActionLauncher.java 2009-10-04 09:34:54 UTC (rev 199)
@@ -219,7 +219,7 @@
for (int i = 0; i < criteria.getNodeTypeName().length; i++)
{
InternalQName name = locationFactory.parseJCRName(criteria.getNodeTypeName()[i]).getInternalName();
- NodeTypeData criteriaNT = ntManager.findNodeType(name);
+ NodeTypeData criteriaNT = ntManager.getNodeType(name);
InternalQName[] testQNames;
if (criteriaNT.isMixin())
{
Modified: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/PropertyTypeRegistry.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/PropertyTypeRegistry.java 2009-10-02 15:41:14 UTC (rev 198)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/PropertyTypeRegistry.java 2009-10-04 09:34:54 UTC (rev 199)
@@ -95,7 +95,7 @@
public void nodeTypeRegistered(InternalQName ntName)
{
- NodeTypeData def = registry.findNodeType(ntName);
+ NodeTypeData def = registry.getNodeType(ntName);
if (def != null)
{
PropertyDefinitionData[] propDefs = def.getDeclaredPropertyDefinitions();
Modified: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/QueryImpl.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/QueryImpl.java 2009-10-02 15:41:14 UTC (rev 198)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/QueryImpl.java 2009-10-04 09:34:54 UTC (rev 199)
@@ -45,6 +45,7 @@
import org.exoplatform.services.jcr.impl.core.NodeImpl;
import org.exoplatform.services.jcr.impl.core.SessionDataManager;
import org.exoplatform.services.jcr.impl.core.SessionImpl;
+import org.exoplatform.services.jcr.impl.core.nodetype.ItemAutocreator;
import org.exoplatform.services.jcr.impl.dataflow.TransientNodeData;
import org.exoplatform.services.jcr.impl.dataflow.TransientPropertyData;
import org.exoplatform.services.jcr.impl.dataflow.TransientValueData;
@@ -254,9 +255,13 @@
(NodeImpl)session.getTransientNodesManager().update(ItemState.createAddedState(queryData), false);
NodeTypeDataManager ntmanager = session.getWorkspace().getNodeTypesHolder();
+
+ ItemAutocreator itemAutocreator = new ItemAutocreator(ntmanager, session.getValueFactory(),session.getTransientNodesManager());
+
PlainChangesLog changes =
- ntmanager.makeAutoCreatedItems((NodeData)queryNode.getData(), Constants.NT_QUERY, session
+ itemAutocreator.makeAutoCreatedItems((NodeData)queryNode.getData(), Constants.NT_QUERY, session
.getTransientNodesManager(), session.getUserID());
+
for (ItemState autoCreatedState : changes.getAllStates())
{
session.getTransientNodesManager().update(autoCreatedState, false);
Modified: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchManager.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchManager.java 2009-10-02 15:41:14 UTC (rev 198)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchManager.java 2009-10-04 09:34:54 UTC (rev 199)
@@ -630,7 +630,10 @@
// name of the property
query.add(new WildcardQuery(new Term(FieldNames.PROPERTIES_SET,
prefix + ":*")), Occur.SHOULD);
+
+
+
result = getNodes(query);
// value of the property
Modified: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/AggregateRuleImpl.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/AggregateRuleImpl.java 2009-10-02 15:41:14 UTC (rev 198)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/AggregateRuleImpl.java 2009-10-04 09:34:54 UTC (rev 199)
@@ -374,7 +374,7 @@
{
// check name
InternalQName name = nodeState.getQPath().getName();
- if (elements[e].getName().equals(name))
+ if (elements[e].equals(name))
{
nodeState = parent;
}
Modified: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/DocOrderScoreNodeIterator.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/DocOrderScoreNodeIterator.java 2009-10-02 15:41:14 UTC (rev 198)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/DocOrderScoreNodeIterator.java 2009-10-04 09:34:54 UTC (rev 199)
@@ -104,8 +104,17 @@
initOrderedIterator();
orderedNodes.skip(skipNum);
}
+ /**
+ * {@inheritDoc}
+ */
+ public void skipBack(long skipNum)
+ {
+ initOrderedIterator();
+ orderedNodes.skipBack(skipNum);
+
+ }
- /**
+ /**
* Returns the number of nodes in this iterator.
* </p>
* Note: The number returned by this method may differ from the number
Modified: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/NodeIteratorImpl.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/NodeIteratorImpl.java 2009-10-02 15:41:14 UTC (rev 198)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/NodeIteratorImpl.java 2009-10-04 09:34:54 UTC (rev 199)
@@ -32,172 +32,204 @@
* Implements a {@link javax.jcr.NodeIterator} returned by
* {@link javax.jcr.query.QueryResult#getNodes()}.
*/
-class NodeIteratorImpl implements NodeIterator {
+class NodeIteratorImpl implements TwoWayRangeIterator, NodeIterator
+{
- /** Logger instance for this class */
- private static final Logger log = LoggerFactory.getLogger(NodeIteratorImpl.class);
+ /** Logger instance for this class */
+ private static final Logger log = LoggerFactory.getLogger(NodeIteratorImpl.class);
- /** The node ids of the nodes in the result set with their score value */
- protected final ScoreNodeIterator scoreNodes;
+ /** The node ids of the nodes in the result set with their score value */
+ protected final ScoreNodeIterator scoreNodes;
- /** The index for the default selector withing {@link #scoreNodes} */
- private final int selectorIndex;
+ /** The index for the default selector withing {@link #scoreNodes} */
+ private final int selectorIndex;
- /** ItemManager to turn UUIDs into Node instances */
- protected final SessionDataManager itemMgr;
+ /** ItemManager to turn UUIDs into Node instances */
+ protected final SessionDataManager itemMgr;
- /** Number of invalid nodes */
- protected int invalid = 0;
+ /** Number of invalid nodes */
+ protected int invalid = 0;
- /** Reference to the next node instance */
- private NodeImpl next;
+ /** Reference to the next node instance */
+ private NodeImpl next;
- /**
- * Whether this iterator had been initialized.
- */
- private boolean initialized;
+ /**
+ * Whether this iterator had been initialized.
+ */
+ private boolean initialized;
- /**
- * Creates a new <code>NodeIteratorImpl</code> instance.
- *
- * @param itemMgr the <code>ItemManager</code> to turn UUIDs into
- * <code>Node</code> instances.
- * @param scoreNodes iterator over score nodes.
- * @param selectorIndex the index for the default selector within
- * <code>scoreNodes</code>.
- */
- NodeIteratorImpl(SessionDataManager itemMgr,
- ScoreNodeIterator scoreNodes,
- int selectorIndex) {
- this.itemMgr = itemMgr;
- this.scoreNodes = scoreNodes;
- this.selectorIndex = selectorIndex;
- }
+ /**
+ * Creates a new <code>NodeIteratorImpl</code> instance.
+ *
+ * @param itemMgr the <code>ItemManager</code> to turn UUIDs into
+ * <code>Node</code> instances.
+ * @param scoreNodes iterator over score nodes.
+ * @param selectorIndex the index for the default selector within
+ * <code>scoreNodes</code>.
+ */
+ NodeIteratorImpl(SessionDataManager itemMgr, ScoreNodeIterator scoreNodes, int selectorIndex)
+ {
+ this.itemMgr = itemMgr;
+ this.scoreNodes = scoreNodes;
+ this.selectorIndex = selectorIndex;
+ }
- /**
- * Returns the next <code>Node</code> in the result set.
- * @return the next <code>Node</code> in the result set.
- * @throws NoSuchElementException if iteration has no more
- * <code>Node</code>s.
- */
- public Node nextNode() throws NoSuchElementException {
- initialize();
- if (next == null) {
- throw new NoSuchElementException();
- }
- NodeImpl n = next;
- fetchNext();
- return n;
- }
+ /**
+ * Returns the current position in this <code>NodeIterator</code>.
+ * @return the current position in this <code>NodeIterator</code>.
+ */
+ public long getPosition()
+ {
+ initialize();
+ long position = scoreNodes.getPosition() - invalid;
+ // scoreNode.getPosition() is one ahead
+ // if there is a prefetched node
+ if (next != null)
+ {
+ position--;
+ }
+ return position;
+ }
- /**
- * Returns the next <code>Node</code> in the result set.
- * @return the next <code>Node</code> in the result set.
- * @throws NoSuchElementException if iteration has no more
- * <code>Node</code>s.
- */
- public Object next() throws NoSuchElementException {
- initialize();
- return nextNode();
- }
+ /**
+ * Returns the number of nodes in this iterator.
+ * </p>
+ * Note: The number returned by this method may differ from the number
+ * of nodes actually returned by calls to hasNext() / getNextNode()! This
+ * is because this iterator works on a lazy instantiation basis and while
+ * iterating over the nodes some of them might have been deleted in the
+ * meantime. Those will not be returned by getNextNode(). As soon as an
+ * invalid node is detected, the size of this iterator is adjusted.
+ *
+ * @return the number of node in this iterator.
+ */
+ public long getSize()
+ {
+ long size = scoreNodes.getSize();
+ if (size == -1)
+ {
+ return size;
+ }
+ else
+ {
+ return size - invalid;
+ }
+ }
- /**
- * Skip a number of <code>Node</code>s in this iterator.
- * @param skipNum the non-negative number of <code>Node</code>s to skip
- * @throws NoSuchElementException
- * if skipped past the last <code>Node</code> in this iterator.
- */
- public void skip(long skipNum) throws NoSuchElementException {
- initialize();
- if (skipNum > 0) {
- scoreNodes.skip(skipNum - 1);
- fetchNext();
- }
- }
+ /**
+ * Returns <code>true</code> if there is another <code>Node</code>
+ * available; <code>false</code> otherwise.
+ * @return <code>true</code> if there is another <code>Node</code>
+ * available; <code>false</code> otherwise.
+ */
+ public boolean hasNext()
+ {
+ initialize();
+ return next != null;
+ }
- /**
- * Returns the number of nodes in this iterator.
- * </p>
- * Note: The number returned by this method may differ from the number
- * of nodes actually returned by calls to hasNext() / getNextNode()! This
- * is because this iterator works on a lazy instantiation basis and while
- * iterating over the nodes some of them might have been deleted in the
- * meantime. Those will not be returned by getNextNode(). As soon as an
- * invalid node is detected, the size of this iterator is adjusted.
- *
- * @return the number of node in this iterator.
- */
- public long getSize() {
- long size = scoreNodes.getSize();
- if (size == -1) {
- return size;
- } else {
- return size - invalid;
- }
- }
+ /**
+ * Returns the next <code>Node</code> in the result set.
+ * @return the next <code>Node</code> in the result set.
+ * @throws NoSuchElementException if iteration has no more
+ * <code>Node</code>s.
+ */
+ public Object next() throws NoSuchElementException
+ {
+ initialize();
+ return nextNode();
+ }
- /**
- * Returns the current position in this <code>NodeIterator</code>.
- * @return the current position in this <code>NodeIterator</code>.
- */
- public long getPosition() {
- initialize();
- long position = scoreNodes.getPosition() - invalid;
- // scoreNode.getPosition() is one ahead
- // if there is a prefetched node
- if (next != null) {
- position--;
- }
- return position;
- }
+ /**
+ * Returns the next <code>Node</code> in the result set.
+ * @return the next <code>Node</code> in the result set.
+ * @throws NoSuchElementException if iteration has no more
+ * <code>Node</code>s.
+ */
+ public Node nextNode() throws NoSuchElementException
+ {
+ initialize();
+ if (next == null)
+ {
+ throw new NoSuchElementException();
+ }
+ NodeImpl n = next;
+ fetchNext();
+ return n;
+ }
- /**
- * Returns <code>true</code> if there is another <code>Node</code>
- * available; <code>false</code> otherwise.
- * @return <code>true</code> if there is another <code>Node</code>
- * available; <code>false</code> otherwise.
- */
- public boolean hasNext() {
- initialize();
- return next != null;
- }
+ /**
+ * @throws UnsupportedOperationException always.
+ */
+ public void remove()
+ {
+ throw new UnsupportedOperationException("remove");
+ }
- /**
- * @throws UnsupportedOperationException always.
- */
- public void remove() {
- throw new UnsupportedOperationException("remove");
- }
+ /**
+ * Skip a number of <code>Node</code>s in this iterator.
+ * @param skipNum the non-negative number of <code>Node</code>s to skip
+ * @throws NoSuchElementException
+ * if skipped past the last <code>Node</code> in this iterator.
+ */
+ public void skip(long skipNum) throws NoSuchElementException
+ {
+ initialize();
+ if (skipNum > 0)
+ {
+ scoreNodes.skip(skipNum - 1);
+ fetchNext();
+ }
+ }
- /**
- * Clears {@link #next} and tries to fetch the next Node instance.
- * When this method returns {@link #next} refers to the next available
- * node instance in this iterator. If {@link #next} is null when this
- * method returns, then there are no more valid element in this iterator.
- */
- protected void fetchNext() {
- // reset
- next = null;
- while (next == null && scoreNodes.hasNext()) {
- ScoreNode[] sn = scoreNodes.nextScoreNodes();
- try {
- next = (NodeImpl) itemMgr.getItemByIdentifier(sn[selectorIndex].getNodeId(),true);
- if(next == null){
- invalid++;
- }
- } catch (RepositoryException e) {
- log.warn("Exception retrieving Node with UUID: "
- + sn[selectorIndex].getNodeId() + ": " + e.toString());
- // try next
- invalid++;
+ public void skipBack(long skipNum)
+ {
+ initialize();
+ if (skipNum < 0)
+ {
+ throw new IllegalArgumentException("skipNum must not be negative");
+ }
+ scoreNodes.skipBack(skipNum - 1);
+ fetchNext();
+
+ }
+
+ /**
+ * Clears {@link #next} and tries to fetch the next Node instance.
+ * When this method returns {@link #next} refers to the next available
+ * node instance in this iterator. If {@link #next} is null when this
+ * method returns, then there are no more valid element in this iterator.
+ */
+ protected void fetchNext()
+ {
+ // reset
+ next = null;
+ while (next == null && scoreNodes.hasNext())
+ {
+ ScoreNode[] sn = scoreNodes.nextScoreNodes();
+ try
+ {
+ next = (NodeImpl)itemMgr.getItemByIdentifier(sn[selectorIndex].getNodeId(), true);
+ if (next == null)
+ {
+ invalid++;
}
- }
- }
+ }
+ catch (RepositoryException e)
+ {
+ log.warn("Exception retrieving Node with UUID: " + sn[selectorIndex].getNodeId() + ": " + e.toString());
+ // try next
+ invalid++;
+ }
+ }
+ }
- protected void initialize() {
- if (!initialized) {
- fetchNext();
- initialized = true;
- }
- }
+ protected void initialize()
+ {
+ if (!initialized)
+ {
+ fetchNext();
+ initialized = true;
+ }
+ }
}
Modified: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/NodeTypeVirtualTableResolver.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/NodeTypeVirtualTableResolver.java 2009-10-02 15:41:14 UTC (rev 198)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/NodeTypeVirtualTableResolver.java 2009-10-04 09:34:54 UTC (rev 199)
@@ -66,7 +66,7 @@
protected boolean isMixin(final InternalQName nodeTypeName)
throws RepositoryException {
final NodeTypeData nodeType = this.nodeTypeDataManager
- .findNodeType(nodeTypeName);
+ .getNodeType(nodeTypeName);
if (nodeType == null) {
throw new NoSuchNodeTypeException("Node type "
+ nodeTypeName.getAsString() + " not found");
Modified: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/QueryImpl.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/QueryImpl.java 2009-10-02 15:41:14 UTC (rev 198)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/QueryImpl.java 2009-10-04 09:34:54 UTC (rev 199)
@@ -178,7 +178,7 @@
ntName[0] = Constants.NT_BASE;
}
NodeTypeData nt = session.getWorkspace().getNodeTypesHolder()
- .findNodeType(ntName[0]);
+ .getNodeType(ntName[0]);
PropertyDefinitionData[] propDefs = nt
.getDeclaredPropertyDefinitions();
Modified: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/QueryResultImpl.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/QueryResultImpl.java 2009-10-02 15:41:14 UTC (rev 198)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/QueryResultImpl.java 2009-10-04 09:34:54 UTC (rev 199)
@@ -505,6 +505,32 @@
}
}
}
+ /**
+ *
+ * @see org.exoplatform.services.jcr.impl.core.query.lucene.TwoWayRangeIterator#skipBack(long)
+ */
+ public void skipBack(long skipNum)
+ {
+ initialize();
+ if (skipNum < 0)
+ {
+ throw new IllegalArgumentException("skipNum must not be negative");
+ }
+ if ((position - skipNum) < 0)
+ {
+ throw new NoSuchElementException();
+ }
+ if (skipNum == 0)
+ {
+ // do nothing
+ }
+ else
+ {
+ position -= skipNum + 1;
+ fetchNext();
+ }
+
+ }
/**
* {@inheritDoc}
Modified: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/ScoreNodeIterator.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/ScoreNodeIterator.java 2009-10-02 15:41:14 UTC (rev 198)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/ScoreNodeIterator.java 2009-10-04 09:34:54 UTC (rev 199)
@@ -16,19 +16,19 @@
*/
package org.exoplatform.services.jcr.impl.core.query.lucene;
-import javax.jcr.RangeIterator;
/**
* A range iterator over {@link ScoreNode}[].
*/
-public interface ScoreNodeIterator extends RangeIterator {
+public interface ScoreNodeIterator extends TwoWayRangeIterator
+{
- /**
- * Returns the next score nodes.
- *
- * @return the next score nodes.
- * @throws java.util.NoSuchElementException
- * if there are no next score nodes.
- */
- ScoreNode[] nextScoreNodes();
+ /**
+ * Returns the next score nodes.
+ *
+ * @return the next score nodes.
+ * @throws java.util.NoSuchElementException
+ * if there are no next score nodes.
+ */
+ ScoreNode[] nextScoreNodes();
}
Modified: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/ScoreNodeIteratorImpl.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/ScoreNodeIteratorImpl.java 2009-10-02 15:41:14 UTC (rev 198)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/ScoreNodeIteratorImpl.java 2009-10-04 09:34:54 UTC (rev 199)
@@ -17,20 +17,21 @@
package org.exoplatform.services.jcr.impl.core.query.lucene;
import java.util.Arrays;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.NoSuchElementException;
-import org.exoplatform.services.jcr.impl.util.EntityCollection;
+import javax.jcr.RangeIterator;
/**
* <code>ScoreNodeIteratorImpl</code> implements a {@link ScoreNodeIterator}
* over an array of {@link ScoreNode ScoreNode[]}.
*/
-public class ScoreNodeIteratorImpl extends EntityCollection implements ScoreNodeIterator
-{
+public class ScoreNodeIteratorImpl implements ScoreNodeIterator{
-
public ScoreNodeIteratorImpl(ScoreNode[][] scoreNodes)
{
- super(Arrays.asList(scoreNodes));
+ this(Arrays.asList(scoreNodes));
}
/**
@@ -40,4 +41,185 @@
{
return (ScoreNode[])next();
}
+
+ /**
+ * Static instance of an empty {@link RangeIterator}.
+ */
+ //public static final RangeIterator EMPTY = new RangeIteratorAdapter(Collections.EMPTY_LIST);
+
+ /**
+ * The adapted iterator instance.
+ */
+ private final Iterator iterator;
+
+ /**
+ * Number of elements in the adapted iterator, or -1 if unknown.
+ */
+ private long size;
+
+ /**
+ * Current position of the iterator.
+ */
+ private long position;
+
+ /**
+ * Creates an adapter for the given iterator of the given size.
+ *
+ * @param iterator adapted iterator
+ * @param size size of the iterator, or -1 if unknown
+ */
+ public ScoreNodeIteratorImpl(Iterator iterator, long size)
+ {
+ this.iterator = iterator;
+ this.size = size;
+ this.position = 0;
+ }
+
+ /**
+ * Creates an adapter for the given iterator of unknown size.
+ *
+ * @param iterator adapted iterator
+ */
+ public ScoreNodeIteratorImpl(Iterator iterator)
+ {
+ this(iterator, -1);
+ }
+
+ /**
+ * Creates a {@link RangeIterator} for the given collection.
+ *
+ * @param collection the collection to iterate
+ */
+ public ScoreNodeIteratorImpl(Collection collection)
+ {
+ this(collection.iterator(), collection.size());
+ }
+
+ //-------------------------------------------------------< RangeIterator >
+
+ /**
+ * Returns the current position of the iterator.
+ *
+ * @return iterator position
+ */
+ public long getPosition()
+ {
+ return position;
+ }
+
+ /**
+ * Returns the size of the iterator.
+ *
+ * @return iterator size, or -1 if unknown
+ */
+ public long getSize()
+ {
+ return size;
+ }
+
+ /**
+ * Skips the given number of elements.
+ *
+ * @param n number of elements to skip
+ * @throws IllegalArgumentException if n is negative
+ * @throws NoSuchElementException if skipped past the last element
+ */
+ public void skip(long n) throws IllegalArgumentException, NoSuchElementException
+ {
+ if (n < 0)
+ {
+ throw new IllegalArgumentException("skip(" + n + ")");
+ }
+ for (long i = 0; i < n; i++)
+ {
+ next();
+ }
+ }
+
+ //------------------------------------------------------------< Iterator >
+
+ /**
+ * Checks if this iterator has more elements. If there are no more
+ * elements and the size of the iterator is unknown, then the size is
+ * set to the current position.
+ *
+ * @return <code>true</code> if this iterator has more elements,
+ * <code>false</code> otherwise
+ */
+ public boolean hasNext()
+ {
+ if (iterator.hasNext())
+ {
+ return true;
+ }
+ else
+ {
+ if (size == -1)
+ {
+ size = position;
+ }
+ return false;
+ }
+ }
+
+ /**
+ * Returns the next element in this iterator and advances the iterator
+ * position. If there are no more elements and the size of the iterator
+ * is unknown, then the size is set to the current position.
+ *
+ * @return next element
+ * @throws NoSuchElementException if there are no more elements
+ */
+ public Object next() throws NoSuchElementException
+ {
+ try
+ {
+ Object next = iterator.next();
+ position++;
+ return next;
+ }
+ catch (NoSuchElementException e)
+ {
+ if (size == -1)
+ {
+ size = position;
+ }
+ throw e;
+ }
+ }
+
+ /**
+ * Removes the previously retrieved element. Decreases the current
+ * position and size of this iterator.
+ *
+ * @throws UnsupportedOperationException if removes are not permitted
+ * @throws IllegalStateException if there is no previous element to remove
+ */
+ public void remove() throws UnsupportedOperationException, IllegalStateException
+ {
+ iterator.remove();
+ position--;
+ if (size != -1)
+ {
+ size--;
+ }
+ }
+
+ public void skipBack(long skipNum)
+ {
+ if (skipNum < 0)
+ {
+ throw new IllegalArgumentException("skipNum must not be negative");
+ }
+ if ((position - skipNum) < 0)
+ {
+ throw new NoSuchElementException();
+ }
+ if (skipNum > 0)
+ {
+ position -= skipNum + 1;
+ next();
+ }
+
+ }
}
Modified: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/misc/Pattern.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/misc/Pattern.java 2009-10-02 15:41:14 UTC (rev 198)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/misc/Pattern.java 2009-10-04 09:34:54 UTC (rev 199)
@@ -457,7 +457,7 @@
}
protected boolean matches(QPathEntry element) {
- return name.equals(element.getName());
+ return name.equals(element);
}
public String toString() {
Modified: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/version/FrozenNodeInitializer.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/version/FrozenNodeInitializer.java 2009-10-02 15:41:14 UTC (rev 198)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/version/FrozenNodeInitializer.java 2009-10-04 09:34:54 UTC (rev 199)
@@ -132,7 +132,7 @@
NodeData parent = (NodeData)dataManager.getItemData(property.getParentIdentifier());
PropertyDefinitionData pdef =
- ntManager.findPropertyDefinitions(qname, parent.getPrimaryTypeName(), parent.getMixinTypeNames())
+ ntManager.getPropertyDefinitions(qname, parent.getPrimaryTypeName(), parent.getMixinTypeNames())
.getAnyDefinition();
int action = pdef.getOnParentVersion();
@@ -227,7 +227,7 @@
NodeData parent = (NodeData)dataManager.getItemData(node.getParentIdentifier());
NodeDefinitionData ndef =
- ntManager.findChildNodeDefinition(qname, parent.getPrimaryTypeName(), parent.getMixinTypeNames());
+ ntManager.getChildNodeDefinition(qname, parent.getPrimaryTypeName(), parent.getMixinTypeNames());
if (ndef == null)
{
throw new ConstraintViolationException("Definition not found for " + qname.getAsString());
Modified: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/version/ItemDataCopyIgnoredVisitor.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/version/ItemDataCopyIgnoredVisitor.java 2009-10-02 15:41:14 UTC (rev 198)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/version/ItemDataCopyIgnoredVisitor.java 2009-10-04 09:34:54 UTC (rev 199)
@@ -71,7 +71,7 @@
NodeData existedParent = (NodeData)dataManager.getItemData(property.getParentIdentifier());
PropertyDefinitionData pdef =
- ntManager.findPropertyDefinitions(property.getQPath().getName(), existedParent.getPrimaryTypeName(),
+ ntManager.getPropertyDefinitions(property.getQPath().getName(), existedParent.getPrimaryTypeName(),
existedParent.getMixinTypeNames()).getAnyDefinition();
if (pdef.getOnParentVersion() == OnParentVersionAction.IGNORE)
@@ -118,7 +118,7 @@
{
NodeData existedParent = (NodeData)dataManager.getItemData(node.getParentIdentifier());
NodeDefinitionData ndef =
- ntManager.findChildNodeDefinition(node.getQPath().getName(), existedParent.getPrimaryTypeName(),
+ ntManager.getChildNodeDefinition(node.getQPath().getName(), existedParent.getPrimaryTypeName(),
existedParent.getMixinTypeNames());
// the node can be stored as IGNOREd in restore set, check an action
Modified: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/version/ItemDataRestoreVisitor.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/version/ItemDataRestoreVisitor.java 2009-10-02 15:41:14 UTC (rev 198)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/version/ItemDataRestoreVisitor.java 2009-10-04 09:34:54 UTC (rev 199)
@@ -486,7 +486,7 @@
// current C in the workspace will be left unchanged.
int action =
- nodeTypeDataManager.findChildNodeDefinition(qname, currentNode().getPrimaryTypeName(),
+ nodeTypeDataManager.getChildNodeDefinition(qname, currentNode().getPrimaryTypeName(),
currentNode().getMixinTypeNames()).getOnParentVersion();
if (log.isDebugEnabled())
@@ -635,7 +635,7 @@
}
int action =
- nodeTypeDataManager.findPropertyDefinitions(qname, currentNode().getPrimaryTypeName(),
+ nodeTypeDataManager.getPropertyDefinitions(qname, currentNode().getPrimaryTypeName(),
currentNode().getMixinTypeNames()).getAnyDefinition().getOnParentVersion();
if (log.isDebugEnabled())
Modified: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/xml/importing/BaseXmlImporter.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/xml/importing/BaseXmlImporter.java 2009-10-02 15:41:14 UTC (rev 198)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/xml/importing/BaseXmlImporter.java 2009-10-04 09:34:54 UTC (rev 199)
@@ -223,7 +223,7 @@
int newIndex = 1;
NodeDefinitionData nodedef =
- nodeTypeDataManager.findChildNodeDefinition(name, parentData.getPrimaryTypeName(), parentData
+ nodeTypeDataManager.getChildNodeDefinition(name, parentData.getPrimaryTypeName(), parentData
.getMixinTypeNames());
ItemData sameNameNode = null;
Modified: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/xml/importing/DocumentViewImporter.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/xml/importing/DocumentViewImporter.java 2009-10-02 15:41:14 UTC (rev 198)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/xml/importing/DocumentViewImporter.java 2009-10-04 09:34:54 UTC (rev 199)
@@ -525,16 +525,16 @@
NodeData parent = getParent();
NodeDefinitionData nodeNt =
- nodeTypeDataManager.findChildNodeDefinition(nodeName, parent.getPrimaryTypeName(), parent
+ nodeTypeDataManager.getChildNodeDefinition(nodeName, parent.getPrimaryTypeName(), parent
.getMixinTypeNames());
NodeTypeData nodeType;
if (nodeNt.getName().equals(Constants.JCR_ANY_NAME) && nodeNt.getDefaultPrimaryType() != null)
{
- nodeType = nodeTypeDataManager.findNodeType(nodeNt.getDefaultPrimaryType());
+ nodeType = nodeTypeDataManager.getNodeType(nodeNt.getDefaultPrimaryType());
}
else
{
- nodeType = nodeTypeDataManager.findNodeType(nodeNt.getName());
+ nodeType = nodeTypeDataManager.getNodeType(nodeNt.getName());
}
if (nodeType == null)
@@ -563,7 +563,7 @@
{
String primaryNodeType = StringConverter.denormalizeString(attValue);
InternalQName ntName = locationFactory.parseJCRName(primaryNodeType).getInternalName();
- NodeTypeData nodeType = nodeTypeDataManager.findNodeType(ntName);
+ NodeTypeData nodeType = nodeTypeDataManager.getNodeType(ntName);
if (nodeType == null)
throw new ConstraintViolationException("Can not find node type " + primaryNodeType);
nodeTypes.add(nodeType);
@@ -577,7 +577,7 @@
amTypes[mi] = StringConverter.denormalizeString(amTypes[mi]);
InternalQName name = locationFactory.parseJCRName(amTypes[mi]).getInternalName();
mixinNodeTypes.add(name);
- NodeTypeData nodeType = nodeTypeDataManager.findNodeType(name);
+ NodeTypeData nodeType = nodeTypeDataManager.getNodeType(name);
if (nodeType == null)
throw new ConstraintViolationException("Can not find node type " + amTypes[mi]);
Modified: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/xml/importing/SystemViewImporter.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/xml/importing/SystemViewImporter.java 2009-10-02 15:41:14 UTC (rev 198)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/xml/importing/SystemViewImporter.java 2009-10-04 09:34:54 UTC (rev 199)
@@ -262,7 +262,7 @@
String value = propertyInfo.getValues().get(i).toString();
mixinNames[i] = locationFactory.parseJCRName(value).getInternalName();
- currentNodeInfo.addNodeType((nodeTypeDataManager.findNodeType(mixinNames[i])));
+ currentNodeInfo.addNodeType((nodeTypeDataManager.getNodeType(mixinNames[i])));
values.add(new TransientValueData(value.toString()));
}
@@ -325,7 +325,7 @@
}
}
//
- nodeData.addNodeType((nodeTypeDataManager.findNodeType(primaryTypeName)));
+ nodeData.addNodeType((nodeTypeDataManager.getNodeType(primaryTypeName)));
nodeData.setPrimaryTypeName(primaryTypeName);
propertyData =
@@ -385,7 +385,7 @@
boolean isMultivalue = true;
PropertyDefinitionDatas defs =
- nodeTypeDataManager.findPropertyDefinitions(propertyInfo.getName(), currentNodeInfo.getPrimaryTypeName(),
+ nodeTypeDataManager.getPropertyDefinitions(propertyInfo.getName(), currentNodeInfo.getPrimaryTypeName(),
currentNodeInfo.getMixinTypeNames());
if (defs == null)
More information about the exo-jcr-commits
mailing list