jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tri...@apache.org
Subject svn commit: r157939 - in incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core: ./ nodetype/ nodetype/virtual/ version/ virtual/
Date Thu, 17 Mar 2005 16:08:56 GMT
Author: tripod
Date: Thu Mar 17 08:08:52 2005
New Revision: 157939

URL: http://svn.apache.org/viewcvs?view=rev&rev=157939
Log:
(JCR-70) Expose registered node types below /jcr:system/jcr:nodeTypes

Added:
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/nodetype/virtual/
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/nodetype/virtual/VirtualNodeTypeStateProvider.java   (with props)
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/virtual/AbstractVISProvider.java   (with props)
Modified:
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/Constants.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/nodetype/builtin_nodetypes.xml
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/VersionHistoryNodeState.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/VersionItemStateProvider.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/virtual/VirtualItemStateProvider.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/virtual/VirtualNodeState.java

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/Constants.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/Constants.java?view=diff&r1=157938&r2=157939
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/Constants.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/Constants.java Thu Mar 17 08:08:52 2005
@@ -53,18 +53,13 @@
     public static final String NS_XMLNS_PREFIX = "xmlns";
     public static final String NS_XMLNS_URI = "http://www.w3.org/2000/xmlns/";
 
-    //--------------------------------------------------< item name constants >
+    //----------------------------------------< general item name constants >---
+
     /** jcr:system */
     public static final QName JCR_SYSTEM = new QName(NS_JCR_URI, "system");
 
-    /** jcr:root (dummy name for root node used in XML serialization) */
-    public static final QName JCR_ROOT = new QName(NS_JCR_URI, "root");
-
-    /** jcr:xmltext */
-    public static final QName JCR_XMLTEXT = new QName(NS_JCR_URI, "xmltext");
-
-    /** jcr:xmlcharacters */
-    public static final QName JCR_XMLCHARACTERS = new QName(NS_JCR_URI, "xmlcharacters");
+    /** jcr:nodeTypes */
+    public static final QName JCR_NODETYPES = new QName(NS_JCR_URI, "nodeTypes");
 
     /** jcr:uuid */
     public static final QName JCR_UUID = new QName(NS_JCR_URI, "uuid");
@@ -81,8 +76,18 @@
     /** jcr:lastModified */
     public static final QName JCR_LASTMODIFIED = new QName(NS_JCR_URI, "lastModified");
 
-    /** jcr:mergeFailed */
-    public static final QName JCR_MERGEFAILED = new QName(NS_JCR_URI, "mergeFailed");
+    //------------------------------------< xml related item name constants >---
+
+    /** jcr:root (dummy name for root node used in XML serialization) */
+    public static final QName JCR_ROOT = new QName(NS_JCR_URI, "root");
+
+    /** jcr:xmltext */
+    public static final QName JCR_XMLTEXT = new QName(NS_JCR_URI, "xmltext");
+
+    /** jcr:xmlcharacters */
+    public static final QName JCR_XMLCHARACTERS = new QName(NS_JCR_URI, "xmlcharacters");
+
+    //----------------------------------------< locking item name constants >---
 
     /** jcr:lockOwner */
     public static final QName JCR_LOCKOWNER = new QName(NS_JCR_URI, "lockOwner");
@@ -90,60 +95,111 @@
     /** jcr:lockIsDeep */
     public static final QName JCR_LOCKISDEEP = new QName(NS_JCR_URI, "lockIsDeep");
 
-    /**
-     * root path for version storage
-     */
+    //-------------------------------------< versioning item name constants >---
+
+    /** jcr:versionStorage */
     public static final QName JCR_VERSIONSTORAGE = new QName(NS_JCR_URI, "versionStorage");
-    /**
-     * the name of the frozen node
-     */
+
+    /** jcr:mergeFailed */
+    public static final QName JCR_MERGEFAILED = new QName(NS_JCR_URI, "mergeFailed");
+
+    /** jcr:frozenNode */
     public static final QName JCR_FROZENNODE = new QName(NS_JCR_URI, "frozenNode");
-    /**
-     * name of the 'jcr:frozenUuid' property
-     */
+
+    /** jcr:frozenUuid */
     public static final QName JCR_FROZENUUID = new QName(NS_JCR_URI, "frozenUuid");
-    /**
-     * name of the 'jcr:frozenPrimaryType' property
-     */
+
+    /** jcr:frozenPrimaryType */
     public static final QName JCR_FROZENPRIMARYTYPE = new QName(NS_JCR_URI, "frozenPrimaryType");
-    /**
-     * name of the 'jcr:frozenMixinTypes' property
-     */
+
+    /** jcr:frozenMixinTypes  */
     public static final QName JCR_FROZENMIXINTYPES = new QName(NS_JCR_URI, "frozenMixinTypes");
-    /**
-     * name of the 'jcr:predecessors' property
-     */
+
+    /** jcr:predecessors */
     public static final QName JCR_PREDECESSORS = new QName(NS_JCR_URI, "predecessors");
-    /**
-     * name of the 'jcr:versionLabels' property
-     */
+
+    /** jcr:versionLabels */
     public static final QName JCR_VERSIONLABELS = new QName(NS_JCR_URI, "versionLabels");
-    /**
-     * name of the 'jcr:successors' property
-     */
+
+    /** jcr:successors */
     public static final QName JCR_SUCCESSORS = new QName(NS_JCR_URI, "successors");
-    /**
-     * name of the 'jcr:isCheckedOut' property
-     */
+
+    /** jcr:isCheckedOut */
     public static final QName JCR_ISCHECKEDOUT = new QName(NS_JCR_URI, "isCheckedOut");
-    /**
-     * name of the 'jcr:versionHistory' property
-     */
+
+    /** jcr:versionHistory */
     public static final QName JCR_VERSIONHISTORY = new QName(NS_JCR_URI, "versionHistory");
-    /**
-     * name of the 'jcr:baseVersion' property
-     */
+
+    /** jcr:baseVersion */
     public static final QName JCR_BASEVERSION = new QName(NS_JCR_URI, "baseVersion");
-    /**
-     * name of the 'jcr:child' property
-     */
+
+    /** jcr:child */
     public static final QName JCR_CHILD = new QName(NS_JCR_URI, "child");
-    /**
-     * the name of the 'jcr:rootVersion' node
-     */
+
+    /** jcr:rootVersion */
     public static final QName JCR_ROOTVERSION = new QName(NS_JCR_URI, "rootVersion");
 
-    //---------------------------------------------< node type name constants >
+    //---------------------------------------< nodetype item name constants >---
+
+    /** jcr:nodeTypeName */
+    public static final QName JCR_NODETYPENAME = new QName(NamespaceRegistryImpl.NS_JCR_URI, "nodeTypeName");
+
+    /** jcr:hasOrderableChildNodes */
+    public static final QName JCR_HASORDERABLECHILDNODES = new QName(NamespaceRegistryImpl.NS_JCR_URI, "hasOrderableChildNodes");
+
+    /** jcr:isMixin */
+    public static final QName JCR_ISMIXIN = new QName(NamespaceRegistryImpl.NS_JCR_URI, "isMixin");
+
+    /** jcr:supertypes */
+    public static final QName JCR_SUPERTYPES = new QName(NamespaceRegistryImpl.NS_JCR_URI, "supertypes");
+
+    /** jcr:propertyDef */
+    public static final QName JCR_PROPERTYDEF = new QName(NamespaceRegistryImpl.NS_JCR_URI, "propertyDef");
+
+    /** jcr:name */
+    public static final QName JCR_NAME = new QName(NamespaceRegistryImpl.NS_JCR_URI, "name");
+
+    /** jcr:mandatory */
+    public static final QName JCR_MANDATORY = new QName(NamespaceRegistryImpl.NS_JCR_URI, "mandatory");
+
+    /** jcr:protected */
+    public static final QName JCR_PROTECTED = new QName(NamespaceRegistryImpl.NS_JCR_URI, "protected");
+
+    /** jcr:requiredType */
+    public static final QName JCR_REQUIREDTYPE = new QName(NamespaceRegistryImpl.NS_JCR_URI, "requiredType");
+
+    /** jcr:onParentVersion */
+    public static final QName JCR_ONPARENTVERSION = new QName(NamespaceRegistryImpl.NS_JCR_URI, "onParentVersion");
+
+    /** jcr:primaryItemName */
+    public static final QName JCR_PRIMARYITEMNAME = new QName(NamespaceRegistryImpl.NS_JCR_URI, "primaryItemName");
+
+    /** jcr:multiple */
+    public static final QName JCR_MULTIPLE = new QName(NamespaceRegistryImpl.NS_JCR_URI, "multiple");
+
+    /** jcr:valueConstraints */
+    public static final QName JCR_VALUECONSTRAINTS = new QName(NamespaceRegistryImpl.NS_JCR_URI, "valueConstraints");
+
+    /** jcr:defaultValues */
+    public static final QName JCR_DEFAULTVALUES = new QName(NamespaceRegistryImpl.NS_JCR_URI, "defaultValues");
+
+    /** jcr:autoCreate */
+    public static final QName JCR_AUTOCREATE = new QName(NamespaceRegistryImpl.NS_JCR_URI, "autoCreate");
+
+    /** jcr:childNodeDef */
+    public static final QName JCR_CHILDNODEDEF = new QName(NamespaceRegistryImpl.NS_JCR_URI, "childNodeDef");
+
+    /** jcr:sameNameSibs */
+    public static final QName JCR_SAMENAMESIBS = new QName(NamespaceRegistryImpl.NS_JCR_URI, "sameNameSibs");
+
+    /** jcr:defaultPrimaryType */
+    public static final QName JCR_DEFAULTPRIMARYTYPE = new QName(NamespaceRegistryImpl.NS_JCR_URI, "defaultPrimaryType");
+
+    /** jcr:requiredPrimaryTypes */
+    public static final QName JCR_REQUIREDPRIMARYTYPES = new QName(NamespaceRegistryImpl.NS_JCR_URI, "requiredPrimaryTypes");
+
+    //-------------------------------------------< node type name constants >---
+
     /** rep:root */
     public static final QName REP_ROOT = new QName(NS_REP_URI, "root");
 
@@ -153,6 +209,9 @@
     /** rep:versionStorage */
     public static final QName REP_VERSIONSTORAGE = new QName(NS_REP_URI, "versionStorage");
 
+    /** rep:versionStorage */
+    public static final QName REP_NODETYPES = new QName(NS_REP_URI, "nodeTypes");
+
     /** nt:unstructured */
     public static final QName NT_UNSTRUCTURED = new QName(NS_NT_URI, "unstructured");
 
@@ -191,4 +250,13 @@
 
     /** nt:frozenNode */
     public static final QName NT_FROZENNODE = new QName(NS_NT_URI, "frozenNode");
+
+    /** nt:nodeType */
+    public static final QName NT_NODETYPE= new QName(NS_NT_URI, "nodeType");
+
+    /** nt:propertyDef */
+    public static final QName NT_PROPERTYDEF = new QName(NS_NT_URI, "propertyDef");
+
+    /** nt:childNodeDef */
+    public static final QName NT_CHILDNODEDEF = new QName(NS_NT_URI, "childNodeDef");
 }

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java?view=diff&r1=157938&r2=157939
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java Thu Mar 17 08:08:52 2005
@@ -30,6 +30,7 @@
 import org.apache.jackrabbit.core.lock.LockManagerImpl;
 import org.apache.jackrabbit.core.nodetype.NodeTypeImpl;
 import org.apache.jackrabbit.core.nodetype.NodeTypeRegistry;
+import org.apache.jackrabbit.core.nodetype.virtual.VirtualNodeTypeStateProvider;
 import org.apache.jackrabbit.core.observation.ObservationManagerFactory;
 import org.apache.jackrabbit.core.security.CredentialsCallbackHandler;
 import org.apache.jackrabbit.core.state.ItemStateException;
@@ -85,6 +86,7 @@
 
     private static final String SYSTEM_ROOT_NODE_UUID = "deadbeef-cafe-babe-cafe-babecafebabe";
     private static final String VERSION_STORAGE_NODE_UUID = "deadbeef-face-babe-cafe-babecafebabe";
+    private static final String NODETYPES_NODE_UUID = "deadbeef-cafe-cafe-cafe-babecafebabe";
 
     private static final String PROPERTIES_RESOURCE = "rep.properties";
     private final Properties repProps;
@@ -325,6 +327,9 @@
             // add version storage
             nt = sysSession.getNodeTypeManager().getNodeType(REP_VERSIONSTORAGE);
             sysRoot.internalAddChildNode(JCR_VERSIONSTORAGE, nt, VERSION_STORAGE_NODE_UUID);
+            // add nodetypes
+            nt = sysSession.getNodeTypeManager().getNodeType(REP_NODETYPES);
+            sysRoot.internalAddChildNode(JCR_NODETYPES, nt, NODETYPES_NODE_UUID);
             rootNode.save();
         }
 
@@ -1001,6 +1006,9 @@
                     itemStateMgr = new SharedItemStateManager(getPersistenceManager(config.getPersistenceManagerConfig()), rootNodeUUID, ntReg);
                     try {
                         itemStateMgr.addVirtualItemStateProvider(vMgr.getVirtualItemStateProvider(itemStateMgr));
+                        itemStateMgr.addVirtualItemStateProvider(
+                                new VirtualNodeTypeStateProvider(ntReg, NODETYPES_NODE_UUID, SYSTEM_ROOT_NODE_UUID)
+                        );
                     } catch (Exception e) {
                         log.error("Unable to add vmgr: " + e.toString(), e);
                     }

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/nodetype/builtin_nodetypes.xml
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/nodetype/builtin_nodetypes.xml?view=diff&r1=157938&r2=157939
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/nodetype/builtin_nodetypes.xml (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/nodetype/builtin_nodetypes.xml Thu Mar 17 08:08:52 2005
@@ -336,6 +336,16 @@
             </requiredPrimaryTypes>
         </childNodeDef>
     </nodeType>
+    <nodeType name="rep:nodeTypes" isMixin="false" hasOrderableChildNodes="false" primaryItemName="">
+        <supertypes>
+            <supertype>nt:base</supertype>
+        </supertypes>
+        <childNodeDef name="*" defaultPrimaryType="nt:nodeType" autoCreate="false" mandatory="false" onParentVersion="ABORT" protected="true" sameNameSibs="false">
+            <requiredPrimaryTypes>
+                <requiredPrimaryType>nt:nodeType</requiredPrimaryType>
+            </requiredPrimaryTypes>
+        </childNodeDef>
+    </nodeType>
     <!-- internal node types for persistent version manager -->
     <nodeType name="rep:versionHistory" isMixin="false" hasOrderableChildNodes="false" primaryItemName="">
         <supertypes>

Added: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/nodetype/virtual/VirtualNodeTypeStateProvider.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/nodetype/virtual/VirtualNodeTypeStateProvider.java?view=auto&rev=157939
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/nodetype/virtual/VirtualNodeTypeStateProvider.java (added)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/nodetype/virtual/VirtualNodeTypeStateProvider.java Thu Mar 17 08:08:52 2005
@@ -0,0 +1,217 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.core.nodetype.virtual;
+
+import org.apache.jackrabbit.core.virtual.VirtualNodeState;
+import org.apache.jackrabbit.core.virtual.AbstractVISProvider;
+import org.apache.jackrabbit.core.NodeId;
+import org.apache.jackrabbit.core.QName;
+import org.apache.jackrabbit.core.InternalValue;
+import org.apache.jackrabbit.core.nodetype.NodeTypeRegistry;
+import org.apache.jackrabbit.core.nodetype.NodeTypeDef;
+import org.apache.jackrabbit.core.nodetype.PropDef;
+import org.apache.jackrabbit.core.nodetype.ChildNodeDef;
+import org.apache.jackrabbit.core.nodetype.ValueConstraint;
+import org.apache.jackrabbit.core.nodetype.NodeTypeRegistryListener;
+import org.apache.jackrabbit.core.state.ItemStateException;
+import org.apache.jackrabbit.core.state.NoSuchItemStateException;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.PropertyType;
+import javax.jcr.version.OnParentVersionAction;
+
+/**
+ * This Class implements a virtual item state provider that exposes the
+ * registered nodetypes.
+ */
+public class VirtualNodeTypeStateProvider extends AbstractVISProvider implements NodeTypeRegistryListener {
+
+    /**
+     * the parent id
+     */
+    private final String parentId;
+
+    /**
+     *
+     * @param ntReg
+     * @param rootNodeId
+     * @param parentId
+     */
+    public VirtualNodeTypeStateProvider(NodeTypeRegistry ntReg, String rootNodeId, String parentId) {
+        super(ntReg, new NodeId(rootNodeId));
+        this.parentId = parentId;
+        ntReg.addListener(this);
+    }
+
+    /**
+     * {@inheritDoc}
+     *
+     * currently we have no dynamic ones, we just recreate the entire nodetypes tree
+     */
+    protected VirtualNodeState createRootNodeState() throws RepositoryException {
+        VirtualNodeState root = new VirtualNodeState(this, parentId, rootNodeId.getUUID(), REP_NODETYPES, null);
+        QName[] ntNames = ntReg.getRegisteredNodeTypes();
+        for (int i=0; i<ntNames.length; i++) {
+            NodeTypeDef ntDef = ntReg.getNodeTypeDef(ntNames[i]);
+            VirtualNodeState ntState = createNodeTypeState(root, ntDef);
+            root.addChildNodeEntry(ntNames[i], ntState.getUUID());
+            // add as hard reference
+            root.addStateReference(ntState);
+        }
+        return root;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    protected boolean internalHasNodeState(NodeId id) {
+        return false;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    protected VirtualNodeState internalGetNodeState(NodeId id) throws NoSuchItemStateException, ItemStateException {
+        return null;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void nodeTypeRegistered(QName ntName) {
+        // todo: do more efficient reloading
+        try {
+            getRootState().discard();
+        } catch (ItemStateException e) {
+            // ignore
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void nodeTypeReRegistered(QName ntName) {
+        // todo: do more efficient reloading
+        try {
+            getRootState().discard();
+        } catch (ItemStateException e) {
+            // ignore
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void nodeTypeUnregistered(QName ntName) {
+        // todo: do more efficient reloading
+        try {
+            getRootState().discard();
+        } catch (ItemStateException e) {
+            // ignore
+        }
+    }
+
+    /**
+     * Creates a node type state
+     * @param parent
+     * @param ntDef
+     * @return
+     * @throws RepositoryException
+     */
+    private VirtualNodeState createNodeTypeState(VirtualNodeState parent, NodeTypeDef ntDef) throws RepositoryException {
+        VirtualNodeState ntState = createNodeState(parent, ntDef.getName(), null, NT_NODETYPE);
+
+        // add properties
+        ntState.setPropertyValue(JCR_NODETYPENAME, InternalValue.create(ntDef.getName()));
+        ntState.setPropertyValues(JCR_SUPERTYPES, PropertyType.NAME, InternalValue.create(ntDef.getSupertypes()));
+        ntState.setPropertyValue(JCR_ISMIXIN, InternalValue.create(ntDef.isMixin()));
+        ntState.setPropertyValue(JCR_HASORDERABLECHILDNODES, InternalValue.create(ntDef.hasOrderableChildNodes()));
+        if (ntDef.getPrimaryItemName() != null) {
+            ntState.setPropertyValue(JCR_PRIMARYITEMNAME, InternalValue.create(ntDef.getPrimaryItemName()));
+        }
+
+        // add property defs
+        PropDef[] propDefs = ntDef.getPropertyDefs();
+        for (int i=0; i<propDefs.length; i++) {
+            VirtualNodeState pdState = createPropertyDefState(ntState, propDefs[i]);
+            ntState.addChildNodeEntry(JCR_PROPERTYDEF, pdState.getUUID());
+            // add as hard reference
+            ntState.addStateReference(pdState);
+        }
+
+        // add child node defs
+        ChildNodeDef[] cnDefs = ntDef.getChildNodeDefs();
+        for (int i=0; i<cnDefs.length; i++) {
+            VirtualNodeState cnState = createChildNodeDefState(ntState, cnDefs[i]);
+            ntState.addChildNodeEntry(JCR_CHILDNODEDEF, cnState.getUUID());
+            // add as hard reference
+            ntState.addStateReference(cnState);
+        }
+
+        return ntState;
+    }
+
+    /**
+     * creates a node state for the given property def
+     * @param parent
+     * @param propDef
+     * @return
+     * @throws RepositoryException
+     */
+    private VirtualNodeState createPropertyDefState(VirtualNodeState parent, PropDef propDef) throws RepositoryException {
+        VirtualNodeState pState = createNodeState(parent, JCR_PROPERTYDEF, null, NT_PROPERTYDEF);
+        // add properties
+        pState.setPropertyValue(JCR_NAME, InternalValue.create(propDef.getName()));
+        pState.setPropertyValue(JCR_AUTOCREATE, InternalValue.create(propDef.isAutoCreate()));
+        pState.setPropertyValue(JCR_MANDATORY, InternalValue.create(propDef.isMandatory()));
+        pState.setPropertyValue(JCR_ONPARENTVERSION, InternalValue.create(OnParentVersionAction.nameFromValue(propDef.getOnParentVersion())));
+        pState.setPropertyValue(JCR_PROTECTED, InternalValue.create(propDef.isProtected()));
+        pState.setPropertyValue(JCR_MULTIPLE, InternalValue.create(propDef.isMultiple()));
+        pState.setPropertyValue(JCR_REQUIREDTYPE, InternalValue.create(PropertyType.nameFromValue(propDef.getRequiredType())));
+        pState.setPropertyValues(JCR_DEFAULTVALUES, PropertyType.STRING, propDef.getDefaultValues());
+        ValueConstraint[] vc = propDef.getValueConstraints();
+        InternalValue[] vals = new InternalValue[vc.length];
+        for (int i=0; i<vc.length; i++) {
+            vals[i] = InternalValue.create(vc[i].getDefinition());
+        }
+        pState.setPropertyValues(JCR_VALUECONSTRAINTS, PropertyType.STRING, vals);
+        return pState;
+    }
+
+    /**
+     * creates a node state for the given child node def
+     * @param parent
+     * @param cnDef
+     * @return
+     * @throws RepositoryException
+     */
+    private VirtualNodeState createChildNodeDefState(VirtualNodeState parent, ChildNodeDef cnDef) throws RepositoryException {
+        VirtualNodeState pState = createNodeState(parent, JCR_CHILDNODEDEF, null, NT_CHILDNODEDEF);
+        // add properties
+        pState.setPropertyValue(JCR_NAME, InternalValue.create(cnDef.getName()));
+        pState.setPropertyValue(JCR_AUTOCREATE, InternalValue.create(cnDef.isAutoCreate()));
+        pState.setPropertyValue(JCR_MANDATORY, InternalValue.create(cnDef.isMandatory()));
+        pState.setPropertyValue(JCR_ONPARENTVERSION, InternalValue.create(OnParentVersionAction.nameFromValue(cnDef.getOnParentVersion())));
+        pState.setPropertyValue(JCR_PROTECTED, InternalValue.create(cnDef.isProtected()));
+        pState.setPropertyValues(JCR_REQUIREDPRIMARYTYPES, PropertyType.NAME, InternalValue.create(cnDef.getRequiredPrimaryTypes()));
+        if (cnDef.getDefaultPrimaryType() != null) {
+            pState.setPropertyValue(JCR_DEFAULTPRIMARYTYPE, InternalValue.create(cnDef.getDefaultPrimaryType()));
+        }
+        pState.setPropertyValue(JCR_SAMENAMESIBS, InternalValue.create(cnDef.allowSameNameSibs()));
+        return pState;
+    }
+}

Propchange: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/nodetype/virtual/VirtualNodeTypeStateProvider.java
------------------------------------------------------------------------------
    svn = 

Propchange: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/nodetype/virtual/VirtualNodeTypeStateProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/VersionHistoryNodeState.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/VersionHistoryNodeState.java?view=diff&r1=157938&r2=157939
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/VersionHistoryNodeState.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/VersionHistoryNodeState.java Thu Mar 17 08:08:52 2005
@@ -57,14 +57,14 @@
     }
 
     /**
-     * @see org.apache.jackrabbit.core.state.NodeState#hasChildNodeEntry(org.apache.jackrabbit.core.QName)
+     * {@inheritDoc}
      */
     public synchronized boolean hasChildNodeEntry(QName name) {
         return vh.hasVersion(name) ? true : super.hasChildNodeEntry(name);
     }
 
     /**
-     * @see org.apache.jackrabbit.core.state.NodeState#hasChildNodeEntry(org.apache.jackrabbit.core.QName, int)
+     * {@inheritDoc}
      */
     public synchronized boolean hasChildNodeEntry(QName name, int index) {
         // no same name siblings
@@ -72,7 +72,7 @@
     }
 
     /**
-     * @see org.apache.jackrabbit.core.state.NodeState#getChildNodeEntry(org.apache.jackrabbit.core.QName, int)
+     * {@inheritDoc}
      */
     public synchronized ChildNodeEntry getChildNodeEntry(QName nodeName, int index) {
         if (super.hasChildNodeEntry(nodeName, index)) {
@@ -92,7 +92,7 @@
     }
 
     /**
-     * @see org.apache.jackrabbit.core.state.NodeState#getChildNodeEntries()
+     * {@inheritDoc}
      */
     public synchronized List getChildNodeEntries() {
         List list = new ArrayList(super.getChildNodeEntries());
@@ -105,7 +105,7 @@
     }
 
     /**
-     * @see org.apache.jackrabbit.core.state.NodeState#getChildNodeEntries(String)
+     * {@inheritDoc}
      */
     public synchronized List getChildNodeEntries(String uuid) {
         List list = new ArrayList(super.getChildNodeEntries(uuid));
@@ -117,7 +117,7 @@
     }
 
     /**
-     * @see org.apache.jackrabbit.core.state.NodeState#getChildNodeEntries(org.apache.jackrabbit.core.QName)
+     * {@inheritDoc}
      */
     public synchronized List getChildNodeEntries(QName nodeName) {
         List list = new ArrayList(super.getChildNodeEntries(nodeName));

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/VersionItemStateProvider.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/VersionItemStateProvider.java?view=diff&r1=157938&r2=157939
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/VersionItemStateProvider.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/VersionItemStateProvider.java Thu Mar 17 08:08:52 2005
@@ -16,73 +16,49 @@
  */
 package org.apache.jackrabbit.core.version;
 
-import org.apache.commons.collections.ReferenceMap;
-import org.apache.jackrabbit.core.Constants;
 import org.apache.jackrabbit.core.InternalValue;
-import org.apache.jackrabbit.core.ItemId;
 import org.apache.jackrabbit.core.NodeId;
 import org.apache.jackrabbit.core.PropertyId;
-import org.apache.jackrabbit.core.QName;
-import org.apache.jackrabbit.core.nodetype.ChildNodeDef;
-import org.apache.jackrabbit.core.nodetype.EffectiveNodeType;
 import org.apache.jackrabbit.core.nodetype.NodeDefId;
-import org.apache.jackrabbit.core.nodetype.NodeTypeConflictException;
 import org.apache.jackrabbit.core.nodetype.NodeTypeRegistry;
-import org.apache.jackrabbit.core.nodetype.PropDef;
-import org.apache.jackrabbit.core.nodetype.PropDefId;
-import org.apache.jackrabbit.core.state.ItemState;
 import org.apache.jackrabbit.core.state.ItemStateException;
-import org.apache.jackrabbit.core.state.ItemStateManager;
 import org.apache.jackrabbit.core.state.NoSuchItemStateException;
 import org.apache.jackrabbit.core.state.NodeReferences;
 import org.apache.jackrabbit.core.state.NodeReferencesId;
-import org.apache.jackrabbit.core.state.NodeState;
 import org.apache.jackrabbit.core.state.PropertyState;
 import org.apache.jackrabbit.core.util.uuid.UUID;
-import org.apache.jackrabbit.core.virtual.VirtualItemStateProvider;
 import org.apache.jackrabbit.core.virtual.VirtualNodeState;
-import org.apache.jackrabbit.core.virtual.VirtualPropertyState;
+import org.apache.jackrabbit.core.virtual.AbstractVISProvider;
 import org.apache.log4j.Logger;
 
 import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
-import java.util.HashSet;
-import java.util.Map;
 
 /**
  * This Class implements a virtual item state provider, in order to expose the
  * versions to the version storage.
  */
-public class VersionItemStateProvider implements VirtualItemStateProvider, Constants {
+public class VersionItemStateProvider extends AbstractVISProvider {
     /**
      * the default logger
      */
     private static Logger log = Logger.getLogger(VersionItemStateProvider.class);
-    /**
-     * the root node
-     */
-    private HistoryRootNodeState root;
+
     /**
      * the version manager
      */
     private final VersionManager vMgr;
-    /**
-     * the node type manager
-     */
-    private final NodeTypeRegistry ntReg;
 
     /**
-     * the cache node states. key=ItemId, value=ItemState
-     */
-    private Map nodes = new ReferenceMap(ReferenceMap.HARD, ReferenceMap.SOFT);
-    /**
      * node def id for a version node state
      */
     private NodeDefId NDEF_VERSION;
+
     /**
      * node def id for a version history node state
      */
     private NodeDefId NDEF_VERSION_HISTORY;
+
     /**
      * node def id for a version history root node state
      */
@@ -99,11 +75,6 @@
     private final String parentId;
 
     /**
-     * the root node id
-     */
-    private final String rootNodeId;
-
-    /**
      * creates a new version item state provide
      *
      * @param vMgr
@@ -111,56 +82,45 @@
      * @param parentId
      * @throws RepositoryException
      */
-    public VersionItemStateProvider(VersionManager vMgr, NodeTypeRegistry ntReg, String rootId, String parentId) throws RepositoryException {
+    public VersionItemStateProvider(VersionManager vMgr, NodeTypeRegistry ntReg,
+                                    String rootId, String parentId)
+            throws RepositoryException {
+        super(ntReg, new NodeId(rootId));
         this.vMgr = vMgr;
-        this.ntReg = ntReg;
-        this.rootNodeId = rootId;
         this.parentId = parentId;
         NDEF_VERSION = new NodeDefId(ntReg.getEffectiveNodeType(NT_VERSIONHISTORY).getApplicableChildNodeDef(JCR_ROOTVERSION, NT_VERSION));
         NDEF_VERSION_HISTORY = new NodeDefId(ntReg.getEffectiveNodeType(NT_UNSTRUCTURED).getApplicableChildNodeDef(JCR_ROOTVERSION, NT_VERSIONHISTORY));
         NDEF_VERSION_HISTORY_ROOT = new NodeDefId(ntReg.getEffectiveNodeType(REP_SYSTEM).getApplicableChildNodeDef(JCR_VERSIONSTORAGE, REP_VERSIONSTORAGE));
         NDEF_VERSION_LABELS = new NodeDefId(ntReg.getEffectiveNodeType(NT_VERSIONHISTORY).getApplicableChildNodeDef(JCR_VERSIONLABELS, NT_VERSIONLABELS));
-
-        createRootNodeState();
     }
 
     /**
-     * Creates a new root node state
-     *
-     * @throws RepositoryException
+     * {@inheritDoc}
      */
-    private void createRootNodeState() throws RepositoryException {
-        root = new HistoryRootNodeState(this, vMgr, parentId, rootNodeId);
+    protected VirtualNodeState createRootNodeState() throws RepositoryException {
+        VirtualNodeState root = new HistoryRootNodeState(this, vMgr, parentId, rootNodeId.getUUID());
         root.setDefinitionId(NDEF_VERSION_HISTORY_ROOT);
-    }
-
-    //-----------------------------------------------------< ItemStateManager >
-    /**
-     * @see ItemStateManager#hasItemState(org.apache.jackrabbit.core.ItemId)
-     */
-    public boolean hasItemState(ItemId id) {
-        if (id instanceof NodeId) {
-            return hasNodeState((NodeId) id);
-        } else {
-            return hasPropertyState((PropertyId) id);
-        }
+        return root;
     }
 
     /**
-     * @see ItemStateManager#getItemState(ItemId)
+     * {@inheritDoc}
      */
-    public ItemState getItemState(ItemId id)
-            throws NoSuchItemStateException, ItemStateException {
-
-        if (id instanceof NodeId) {
-            return getNodeState((NodeId) id);
-        } else {
-            return getPropertyState((PropertyId) id);
+    public boolean setNodeReferences(NodeReferences refs) {
+        try {
+            InternalVersionItem vi = vMgr.getItem(refs.getUUID());
+            if (vi != null) {
+                vMgr.setItemReferences(vi, refs.getReferences());
+                return true;
+            }
+        } catch (RepositoryException e) {
+            // ignore
         }
+        return false;
     }
 
     /**
-     * @see ItemStateManager#getNodeReferences(NodeReferencesId)
+     * {@inheritDoc}
      */
     public NodeReferences getNodeReferences(NodeReferencesId id)
             throws NoSuchItemStateException, ItemStateException {
@@ -193,205 +153,82 @@
         throw new NoSuchItemStateException(id.getUUID());
     }
 
-    //-------------------------------------------< VirtualItemStateProvider >---
-    /**
-     * @see VirtualItemStateProvider#isVirtualRoot(ItemId)
-     */
-    public boolean isVirtualRoot(ItemId id) {
-        return id.equals(root.getId());
-    }
-
     /**
-     * @see VirtualItemStateProvider#getVirtualRootId()
+     * {@inheritDoc}
      */
-    public NodeId getVirtualRootId() {
-        return (NodeId) root.getId();
+    protected boolean internalHasNodeState(NodeId id) {
+        return vMgr.hasItem(id.getUUID());
     }
 
     /**
-     * @see VirtualItemStateProvider#hasNodeState(NodeId)
-     */
-    public boolean hasNodeState(NodeId id) {
-        if (nodes.containsKey(id)) {
-            return true;
-        } else if (id.equals(root.getId())) {
-            return true;
-        } else {
-            return vMgr.hasItem(id.getUUID());
-        }
-    }
-
-    /**
-     * @see VirtualItemStateProvider#getNodeState(NodeId)
+     * {@inheritDoc}
      */
-    public VirtualNodeState getNodeState(NodeId id)
+    protected VirtualNodeState internalGetNodeState(NodeId id)
             throws NoSuchItemStateException, ItemStateException {
 
-        // check if root
-        if (id.equals(root.getId())) {
-            return root;
-        }
-
-        // check cache
-        VirtualNodeState state = (VirtualNodeState) nodes.get(id);
-        if (state == null) {
-            try {
-                InternalVersionItem vi = vMgr.getItem(id.getUUID());
-                if (vi instanceof InternalVersionHistory) {
-                    state = new VersionHistoryNodeState(this, (InternalVersionHistory) vi, root.getUUID());
-                    state.setDefinitionId(NDEF_VERSION_HISTORY);
-                    // add version labels node state
-                    String uuid = UUID.randomUUID().toString();
-                    VersionLabelsNodeState vlns = new VersionLabelsNodeState(this, (InternalVersionHistory) vi, state.getUUID(), uuid);
-                    vlns.setDefinitionId(NDEF_VERSION_LABELS);
-                    state.addChildNodeEntry(JCR_VERSIONLABELS, uuid);
-                    // need to add as hard reference to version history, so that it does not get fluhed.
-                    state.addStateReference(vlns);
-                    nodes.put(new NodeId(uuid), vlns);
-
-                } else if (vi instanceof InternalVersion) {
-                    InternalVersion v = (InternalVersion) vi;
-                    state = new VersionNodeState(this, v, vi.getParent().getId());
-                    state.setDefinitionId(NDEF_VERSION);
-                    state.setPropertyValue(JCR_CREATED, InternalValue.create(v.getCreated()));
-                    // todo: do not read frozen stuff from frozen node instance here, rather put to version
-                    //state.setPropertyValue(JCR_FROZENUUID, InternalValue.create(v.getFrozenNode().getFrozenUUID()));
-                    //state.setPropertyValue(JCR_FROZENPRIMARYTYPE, InternalValue.create(v.getFrozenNode().getFrozenPrimaryType()));
-                    //state.setPropertyValues(JCR_FROZENMIXINTYPES, PropertyType.NAME, InternalValue.create(v.getFrozenNode().getFrozenMixinTypes()));
-                    //state.setPropertyValues(JCR_VERSIONLABELS, PropertyType.STRING, InternalValue.create(v.getLabels()));
-                    state.setPropertyValues(JCR_PREDECESSORS, PropertyType.REFERENCE, new InternalValue[0]);
-                    state.setPropertyValues(JCR_SUCCESSORS, PropertyType.REFERENCE, new InternalValue[0]);
-
-                } else if (vi instanceof InternalFrozenNode) {
-                    InternalFrozenNode fn = (InternalFrozenNode) vi;
-                    VirtualNodeState parent = getNodeState(new NodeId(fn.getParent().getId()));
-                    boolean mimicFrozen = !(parent instanceof VersionNodeState);
-                    state = createNodeState(parent,
-                            JCR_FROZENNODE,
-                            id.getUUID(),
-                            mimicFrozen ? fn.getFrozenPrimaryType() :
-                            NT_FROZENNODE);
-                    mapFrozenNode(state, fn, mimicFrozen);
-
-                } else if (vi instanceof InternalFrozenVersionHistory) {
-                    InternalFrozenVersionHistory fn = (InternalFrozenVersionHistory) vi;
-                    VirtualNodeState parent = getNodeState(new NodeId(fn.getParent().getId()));
-                    state = createNodeState(parent,
-                            fn.getName(),
-                            id.getUUID(),
-                            NT_VERSIONEDCHILD);
-                    // IMO, this should be exposed aswell
-                    // state.setPropertyValue(JCR_BASE_VERSION, InternalValue.create(UUID.fromString(fn.getBaseVersionId())));
-                    state.setPropertyValue(JCR_CHILD, InternalValue.create(UUID.fromString(fn.getVersionHistoryId())));
-                } else {
-                    // not found, throw
-                    throw new NoSuchItemStateException(id.toString());
-                }
-            } catch (RepositoryException e) {
-                log.error("Unable to check for item:" + e.toString());
-                throw new ItemStateException(e);
-            }
-
-            // add state to cache
-            nodes.put(id, state);
-            log.debug("item added to cache. size=" + nodes.size());
-        }
-        return state;
-    }
-
-    /**
-     * @see VirtualItemStateProvider#hasPropertyState(PropertyId)
-     */
-    public boolean hasPropertyState(PropertyId id) {
-
+        VirtualNodeState state = null;
         try {
-            // get parent state
-            NodeState parent = getNodeState(new NodeId(id.getParentUUID()));
-
-            // handle some default prop states
-            if (parent instanceof VirtualNodeState) {
-                return ((VirtualNodeState) parent).hasPropertyEntry(id.getName());
+            InternalVersionItem vi = vMgr.getItem(id.getUUID());
+            if (vi instanceof InternalVersionHistory) {
+                state = new VersionHistoryNodeState(this, (InternalVersionHistory) vi, rootNodeId.getUUID());
+                state.setDefinitionId(NDEF_VERSION_HISTORY);
+                // add version labels node state
+                String uuid = UUID.randomUUID().toString();
+                VersionLabelsNodeState vlns = new VersionLabelsNodeState(this, (InternalVersionHistory) vi, state.getUUID(), uuid);
+                vlns.setDefinitionId(NDEF_VERSION_LABELS);
+                state.addChildNodeEntry(JCR_VERSIONLABELS, uuid);
+                // need to add as hard reference to version history, so that it does not get fluhed.
+                state.addStateReference(vlns);
+                cache(vlns);
+
+            } else if (vi instanceof InternalVersion) {
+                InternalVersion v = (InternalVersion) vi;
+                state = new VersionNodeState(this, v, vi.getParent().getId());
+                state.setDefinitionId(NDEF_VERSION);
+                state.setPropertyValue(JCR_CREATED, InternalValue.create(v.getCreated()));
+                // todo: do not read frozen stuff from frozen node instance here, rather put to version
+                //state.setPropertyValue(JCR_FROZENUUID, InternalValue.create(v.getFrozenNode().getFrozenUUID()));
+                //state.setPropertyValue(JCR_FROZENPRIMARYTYPE, InternalValue.create(v.getFrozenNode().getFrozenPrimaryType()));
+                //state.setPropertyValues(JCR_FROZENMIXINTYPES, PropertyType.NAME, InternalValue.create(v.getFrozenNode().getFrozenMixinTypes()));
+                //state.setPropertyValues(JCR_VERSIONLABELS, PropertyType.STRING, InternalValue.create(v.getLabels()));
+                state.setPropertyValues(JCR_PREDECESSORS, PropertyType.REFERENCE, new InternalValue[0]);
+                state.setPropertyValues(JCR_SUCCESSORS, PropertyType.REFERENCE, new InternalValue[0]);
+
+            } else if (vi instanceof InternalFrozenNode) {
+                InternalFrozenNode fn = (InternalFrozenNode) vi;
+                VirtualNodeState parent = (VirtualNodeState) getItemState(new NodeId(fn.getParent().getId()));
+                boolean mimicFrozen = !(parent instanceof VersionNodeState);
+                state = createNodeState(parent,
+                        JCR_FROZENNODE,
+                        id.getUUID(),
+                        mimicFrozen ? fn.getFrozenPrimaryType() :
+                        NT_FROZENNODE);
+                mapFrozenNode(state, fn, mimicFrozen);
+
+            } else if (vi instanceof InternalFrozenVersionHistory) {
+                InternalFrozenVersionHistory fn = (InternalFrozenVersionHistory) vi;
+                VirtualNodeState parent = (VirtualNodeState) getItemState(new NodeId(fn.getParent().getId()));
+                state = createNodeState(parent,
+                        fn.getName(),
+                        id.getUUID(),
+                        NT_VERSIONEDCHILD);
+                // IMO, this should be exposed aswell
+                // state.setPropertyValue(JCR_BASE_VERSION, InternalValue.create(UUID.fromString(fn.getBaseVersionId())));
+                state.setPropertyValue(JCR_CHILD, InternalValue.create(UUID.fromString(fn.getVersionHistoryId())));
+            } else {
+                // not found, throw
+                throw new NoSuchItemStateException(id.toString());
             }
-        } catch (ItemStateException e) {
-            // ignore
-        }
-        return false;
-    }
-
-    /**
-     * @see VirtualItemStateProvider#getPropertyState(PropertyId)
-     */
-    public VirtualPropertyState getPropertyState(PropertyId id)
-            throws NoSuchItemStateException, ItemStateException {
-
-        // get parent state
-        NodeState parent = getNodeState(new NodeId(id.getParentUUID()));
-
-        // handle some default prop states
-        if (parent instanceof VirtualNodeState) {
-            return ((VirtualNodeState) parent).getProperty(id.getName());
-        }
-        throw new NoSuchItemStateException(id.toString());
-    }
-
-    /**
-     * @see VirtualItemStateProvider#createPropertyState(VirtualNodeState, QName, int, boolean)
-     */
-    public VirtualPropertyState createPropertyState(VirtualNodeState parent,
-                                                    QName name, int type,
-                                                    boolean multiValued)
-            throws RepositoryException {
-        PropDef def = getApplicablePropertyDef(parent, name, type, multiValued);
-        VirtualPropertyState prop = new VirtualPropertyState(name, parent.getUUID());
-        prop.setType(type);
-        prop.setMultiValued(multiValued);
-        prop.setDefinitionId(new PropDefId(def));
-        return prop;
-    }
-
-    /**
-     * @see VirtualItemStateProvider#createNodeState(VirtualNodeState, QName, String, QName)
-     */
-    public VirtualNodeState createNodeState(VirtualNodeState parent, QName name,
-                                            String uuid, QName nodeTypeName)
-            throws RepositoryException {
-
-        NodeDefId def;
-        try {
-            def = new NodeDefId(getApplicableChildNodeDef(parent, name, nodeTypeName));
-        } catch (RepositoryException re) {
-            // hack, use nt:unstructured as parent
-            NodeTypeRegistry ntReg = getNodeTypeRegistry();
-            EffectiveNodeType ent = ntReg.getEffectiveNodeType(NT_UNSTRUCTURED);
-            ChildNodeDef cnd = ent.getApplicableChildNodeDef(name, nodeTypeName);
-            ntReg.getNodeDef(new NodeDefId(cnd));
-            def = new NodeDefId(cnd);
-        }
-
-        // create a new node state
-        VirtualNodeState state = null;
-        if (uuid == null) {
-            uuid = UUID.randomUUID().toString();	// version 4 uuid
+        } catch (RepositoryException e) {
+            log.error("Unable to check for item:" + e.toString());
+            throw new ItemStateException(e);
         }
-        state = new VirtualNodeState(this, parent.getUUID(), uuid, nodeTypeName, new QName[0]);
-        state.setDefinitionId(def);
-
-        nodes.put(state.getId(), state);
         return state;
     }
 
     //-----------------------------------------------------< internal stuff >---
 
     /**
-     * returns the node type manager
-     *
-     * @return
-     */
-    private NodeTypeRegistry getNodeTypeRegistry() {
-        return ntReg;
-    }
-
-    /**
      * maps a frozen node
      *
      * @param state
@@ -435,111 +272,4 @@
         return state;
     }
 
-    /**
-     * retrieves the property definition for the given contraints
-     *
-     * @param propertyName
-     * @param type
-     * @param multiValued
-     * @return
-     * @throws RepositoryException
-     */
-    protected PropDef getApplicablePropertyDef(NodeState parent, QName propertyName,
-                                               int type, boolean multiValued)
-            throws RepositoryException {
-        return getEffectiveNodeType(parent).getApplicablePropertyDef(propertyName, type, multiValued);
-    }
-
-    /**
-     * Retrieves the node definition for the given contraints.
-     *
-     * @param nodeName
-     * @param nodeTypeName
-     * @return
-     * @throws RepositoryException
-     */
-    protected ChildNodeDef getApplicableChildNodeDef(NodeState parent, QName nodeName, QName nodeTypeName)
-            throws RepositoryException {
-        return getEffectiveNodeType(parent).getApplicableChildNodeDef(nodeName, nodeTypeName);
-    }
-
-    /**
-     * Returns the effective (i.e. merged and resolved) node type representation
-     * of this node's primary and mixin node types.
-     *
-     * @return the effective node type
-     * @throws RepositoryException
-     */
-    protected EffectiveNodeType getEffectiveNodeType(NodeState parent) throws RepositoryException {
-        // build effective node type of mixins & primary type
-        NodeTypeRegistry ntReg = getNodeTypeRegistry();
-        // existing mixin's
-        HashSet set = new HashSet(parent.getMixinTypeNames());
-        // primary type
-        set.add(parent.getNodeTypeName());
-        try {
-            return ntReg.getEffectiveNodeType((QName[]) set.toArray(new QName[set.size()]));
-        } catch (NodeTypeConflictException ntce) {
-            String msg = "internal error: failed to build effective node type for node " + parent.getUUID();
-            throw new RepositoryException(msg, ntce);
-        }
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public boolean setNodeReferences(NodeReferences refs) {
-        try {
-            InternalVersionItem vi = vMgr.getItem(refs.getUUID());
-            if (vi != null) {
-                vMgr.setItemReferences(vi, refs.getReferences());
-                return true;
-            }
-        } catch (RepositoryException e) {
-            // ignore
-        }
-        return false;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public void stateCreated(ItemState created) {
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public void stateModified(ItemState modified) {
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public void stateDestroyed(ItemState destroyed) {
-        destroyed.removeListener(this);
-        if (destroyed.isNode() && ((NodeState) destroyed).getUUID().equals(rootNodeId)) {
-            try {
-                createRootNodeState();
-            } catch (RepositoryException e) {
-                // ignore
-            }
-        }
-        nodes.remove(destroyed.getId());
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public void stateDiscarded(ItemState discarded) {
-        discarded.removeListener(this);
-        if (discarded.isNode() && ((NodeState) discarded).getUUID().equals(rootNodeId)) {
-            try {
-                createRootNodeState();
-            } catch (RepositoryException e) {
-                // ignore
-            }
-        }
-        nodes.remove(discarded.getId());
-    }
 }

Added: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/virtual/AbstractVISProvider.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/virtual/AbstractVISProvider.java?view=auto&rev=157939
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/virtual/AbstractVISProvider.java (added)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/virtual/AbstractVISProvider.java Thu Mar 17 08:08:52 2005
@@ -0,0 +1,398 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.core.virtual;
+
+import org.apache.commons.collections.ReferenceMap;
+import org.apache.jackrabbit.core.Constants;
+import org.apache.jackrabbit.core.ItemId;
+import org.apache.jackrabbit.core.NodeId;
+import org.apache.jackrabbit.core.PropertyId;
+import org.apache.jackrabbit.core.QName;
+import org.apache.jackrabbit.core.nodetype.ChildNodeDef;
+import org.apache.jackrabbit.core.nodetype.EffectiveNodeType;
+import org.apache.jackrabbit.core.nodetype.NodeDefId;
+import org.apache.jackrabbit.core.nodetype.NodeTypeConflictException;
+import org.apache.jackrabbit.core.nodetype.NodeTypeRegistry;
+import org.apache.jackrabbit.core.nodetype.PropDef;
+import org.apache.jackrabbit.core.nodetype.PropDefId;
+import org.apache.jackrabbit.core.state.ItemState;
+import org.apache.jackrabbit.core.state.ItemStateException;
+import org.apache.jackrabbit.core.state.NoSuchItemStateException;
+import org.apache.jackrabbit.core.state.NodeReferences;
+import org.apache.jackrabbit.core.state.NodeReferencesId;
+import org.apache.jackrabbit.core.state.NodeState;
+import org.apache.jackrabbit.core.util.uuid.UUID;
+import org.apache.log4j.Logger;
+
+import javax.jcr.RepositoryException;
+import java.util.HashSet;
+import java.util.Map;
+
+/**
+ * This Class implements a virtual item state provider, in order to expose the
+ * versions to the version storage.
+ */
+abstract public class AbstractVISProvider implements VirtualItemStateProvider, Constants {
+    /**
+     * the default logger
+     */
+    private static Logger log = Logger.getLogger(AbstractVISProvider.class);
+
+    /**
+     * the root node
+     */
+    private VirtualNodeState root = null;
+
+    /**
+     * the root node id
+     */
+    protected final NodeId rootNodeId;
+
+    /**
+     * the node type registry
+     */
+    protected final NodeTypeRegistry ntReg;
+
+    /**
+     * the cache node states. key=ItemId, value=ItemState
+     */
+    private Map nodes = new ReferenceMap(ReferenceMap.HARD, ReferenceMap.SOFT);
+
+    /**
+     * Creates an abstract virtual item state provider
+     * @param ntReg
+     * @param rootNodeId
+     */
+    public AbstractVISProvider(NodeTypeRegistry ntReg, NodeId rootNodeId) {
+        this.ntReg = ntReg;
+        this.rootNodeId = rootNodeId;
+    }
+
+    /**
+     * Creates the root node state.
+     * @return
+     * @throws RepositoryException
+     */
+    abstract protected VirtualNodeState createRootNodeState() throws RepositoryException;
+
+    //-----------------------------------------------------< ItemStateManager >
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean hasItemState(ItemId id) {
+        if (id instanceof NodeId) {
+            if (nodes.containsKey(id)) {
+                return true;
+            } else if (id.equals(rootNodeId)) {
+                return true;
+            } else {
+                return internalHasNodeState((NodeId) id);
+            }
+        } else {
+            return internalHasPropertyState((PropertyId) id);
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public ItemState getItemState(ItemId id)
+            throws NoSuchItemStateException, ItemStateException {
+
+        if (id instanceof NodeId) {
+            if (nodes.containsKey(id)) {
+                return (ItemState) nodes.get(id);
+            } else if (id.equals(rootNodeId)) {
+                return getRootState();
+            } else {
+                return cache(internalGetNodeState((NodeId) id));
+            }
+        } else {
+            return internalGetPropertyState((PropertyId) id);
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public NodeReferences getNodeReferences(NodeReferencesId id)
+            throws NoSuchItemStateException, ItemStateException {
+        throw new NoSuchItemStateException(id.getUUID());
+    }
+
+    //-------------------------------------------< VirtualItemStateProvider >---
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isVirtualRoot(ItemId id) {
+        return id.equals(rootNodeId);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public NodeId getVirtualRootId() {
+        return rootNodeId;
+    }
+
+    /**
+     * Returns the root state
+     * @return the root state
+     */
+    public synchronized NodeState getRootState() throws ItemStateException {
+        try {
+            if (root == null) {
+                root = createRootNodeState();
+            }
+            return root;
+        } catch (RepositoryException e) {
+            throw new ItemStateException(e);
+        }
+    }
+
+    /**
+     * Checks if this provide has the node state of the given node id
+     * @param id
+     * @return
+     */
+    abstract protected boolean internalHasNodeState(NodeId id);
+
+    /**
+     * Retrieves the node state with the given node id
+     * @param id
+     * @return
+     * @throws NoSuchItemStateException
+     * @throws ItemStateException
+     */
+    abstract protected VirtualNodeState internalGetNodeState(NodeId id)
+            throws NoSuchItemStateException, ItemStateException;
+
+    /**
+     * Checks if this provider has the property state of the given id.
+     * @param id
+     * @return
+     */
+    protected boolean internalHasPropertyState(PropertyId id) {
+
+        try {
+            // get parent state
+            NodeState parent = (NodeState) getItemState(new NodeId(id.getParentUUID()));
+
+            // handle some default prop states
+            if (parent instanceof VirtualNodeState) {
+                return ((VirtualNodeState) parent).hasPropertyEntry(id.getName());
+            }
+        } catch (ItemStateException e) {
+            // ignore
+        }
+        return false;
+    }
+
+    /**
+     * Retrieces the property state for the given id
+     * @param id
+     * @return
+     * @throws NoSuchItemStateException
+     * @throws ItemStateException
+     */
+    protected VirtualPropertyState internalGetPropertyState(PropertyId id)
+            throws NoSuchItemStateException, ItemStateException {
+
+        // get parent state
+        NodeState parent = (NodeState) getItemState(new NodeId(id.getParentUUID()));
+
+        // handle some default prop states
+        if (parent instanceof VirtualNodeState) {
+            return ((VirtualNodeState) parent).getProperty(id.getName());
+        }
+        throw new NoSuchItemStateException(id.toString());
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public VirtualPropertyState createPropertyState(VirtualNodeState parent,
+                                                    QName name, int type,
+                                                    boolean multiValued)
+            throws RepositoryException {
+        PropDef def = getApplicablePropertyDef(parent, name, type, multiValued);
+        VirtualPropertyState prop = new VirtualPropertyState(name, parent.getUUID());
+        prop.setType(type);
+        prop.setMultiValued(multiValued);
+        prop.setDefinitionId(new PropDefId(def));
+        return prop;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public VirtualNodeState createNodeState(VirtualNodeState parent, QName name,
+                                            String uuid, QName nodeTypeName)
+            throws RepositoryException {
+
+        NodeDefId def;
+        try {
+            def = new NodeDefId(getApplicableChildNodeDef(parent, name, nodeTypeName));
+        } catch (RepositoryException re) {
+            // hack, use nt:unstructured as parent
+            NodeTypeRegistry ntReg = getNodeTypeRegistry();
+            EffectiveNodeType ent = ntReg.getEffectiveNodeType(NT_UNSTRUCTURED);
+            ChildNodeDef cnd = ent.getApplicableChildNodeDef(name, nodeTypeName);
+            ntReg.getNodeDef(new NodeDefId(cnd));
+            def = new NodeDefId(cnd);
+        }
+
+        // create a new node state
+        VirtualNodeState state = null;
+        if (uuid == null) {
+            uuid = UUID.randomUUID().toString();	// version 4 uuid
+        }
+        state = new VirtualNodeState(this, parent.getUUID(), uuid, nodeTypeName, new QName[0]);
+        state.setDefinitionId(def);
+
+        cache(state);
+        return state;
+    }
+
+    /**
+     * returns the node type manager
+     *
+     * @return
+     */
+    protected NodeTypeRegistry getNodeTypeRegistry() {
+        return ntReg;
+    }
+
+    /**
+     * adds the node state to the cache
+     * @param state
+     */
+    protected NodeState cache(NodeState state) {
+        nodes.put(state.getId(), state);
+        log.debug("item added to cache. size=" + nodes.size());
+        return state;
+    }
+
+    /**
+     * removes the nodes state from the cache
+     * @param id
+     */
+    protected NodeState evict(NodeId id) {
+        return (NodeState) nodes.remove(id);
+    }
+
+    /**
+     * retrieves the property definition for the given contraints
+     *
+     * @param propertyName
+     * @param type
+     * @param multiValued
+     * @return
+     * @throws RepositoryException
+     */
+    protected PropDef getApplicablePropertyDef(NodeState parent, QName propertyName,
+                                               int type, boolean multiValued)
+            throws RepositoryException {
+        return getEffectiveNodeType(parent).getApplicablePropertyDef(propertyName, type, multiValued);
+    }
+
+    /**
+     * Retrieves the node definition for the given contraints.
+     *
+     * @param nodeName
+     * @param nodeTypeName
+     * @return
+     * @throws RepositoryException
+     */
+    protected ChildNodeDef getApplicableChildNodeDef(NodeState parent, QName nodeName, QName nodeTypeName)
+            throws RepositoryException {
+        return getEffectiveNodeType(parent).getApplicableChildNodeDef(nodeName, nodeTypeName);
+    }
+
+    /**
+     * Returns the effective (i.e. merged and resolved) node type representation
+     * of this node's primary and mixin node types.
+     *
+     * @return the effective node type
+     * @throws RepositoryException
+     */
+    protected EffectiveNodeType getEffectiveNodeType(NodeState parent) throws RepositoryException {
+        // build effective node type of mixins & primary type
+        NodeTypeRegistry ntReg = getNodeTypeRegistry();
+        // existing mixin's
+        HashSet set = new HashSet(parent.getMixinTypeNames());
+        // primary type
+        set.add(parent.getNodeTypeName());
+        try {
+            return ntReg.getEffectiveNodeType((QName[]) set.toArray(new QName[set.size()]));
+        } catch (NodeTypeConflictException ntce) {
+            String msg = "internal error: failed to build effective node type for node " + parent.getUUID();
+            throw new RepositoryException(msg, ntce);
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean setNodeReferences(NodeReferences refs) {
+        return false;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void stateCreated(ItemState created) {
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void stateModified(ItemState modified) {
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void stateDestroyed(ItemState destroyed) {
+        destroyed.removeListener(this);
+        if (destroyed.isNode() && ((NodeState) destroyed).getId().equals(rootNodeId)) {
+            try {
+                root = createRootNodeState();
+            } catch (RepositoryException e) {
+                // ignore
+            }
+        }
+        evict((NodeId) destroyed.getId());
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void stateDiscarded(ItemState discarded) {
+        discarded.removeListener(this);
+        if (discarded.isNode() && ((NodeState) discarded).getId().equals(rootNodeId)) {
+            try {
+                root = createRootNodeState();
+            } catch (RepositoryException e) {
+                // ignore
+            }
+        }
+        evict((NodeId) discarded.getId());
+    }
+}

Propchange: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/virtual/AbstractVISProvider.java
------------------------------------------------------------------------------
    svn = 

Propchange: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/virtual/AbstractVISProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/virtual/VirtualItemStateProvider.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/virtual/VirtualItemStateProvider.java?view=diff&r1=157938&r2=157939
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/virtual/VirtualItemStateProvider.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/virtual/VirtualItemStateProvider.java Thu Mar 17 08:08:52 2005
@@ -18,12 +18,9 @@
 
 import org.apache.jackrabbit.core.ItemId;
 import org.apache.jackrabbit.core.NodeId;
-import org.apache.jackrabbit.core.PropertyId;
 import org.apache.jackrabbit.core.QName;
-import org.apache.jackrabbit.core.state.ItemStateException;
 import org.apache.jackrabbit.core.state.ItemStateListener;
 import org.apache.jackrabbit.core.state.ItemStateManager;
-import org.apache.jackrabbit.core.state.NoSuchItemStateException;
 import org.apache.jackrabbit.core.state.NodeReferences;
 
 import javax.jcr.RepositoryException;
@@ -47,44 +44,6 @@
      * @return
      */
     public NodeId getVirtualRootId();
-
-    /**
-     * Checks if the node with the given id exists in this item state provider.
-     *
-     * @param id
-     * @return
-     */
-    public boolean hasNodeState(NodeId id);
-
-    /**
-     * Checks if the property with the given id exists in this item state provider.
-     *
-     * @param id
-     * @return
-     */
-    public boolean hasPropertyState(PropertyId id);
-
-    /**
-     * Returns the node state for the given node id
-     *
-     * @param id
-     * @return
-     * @throws ItemStateException
-     * @throws NoSuchItemStateException
-     */
-    public VirtualNodeState getNodeState(NodeId id)
-            throws ItemStateException, NoSuchItemStateException;
-
-    /**
-     * Returns the property state for the give property id
-     *
-     * @param id
-     * @return
-     * @throws ItemStateException
-     * @throws NoSuchItemStateException
-     */
-    public VirtualPropertyState getPropertyState(PropertyId id)
-            throws ItemStateException, NoSuchItemStateException;
 
     /**
      * Creats a new virtual property state

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/virtual/VirtualNodeState.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/virtual/VirtualNodeState.java?view=diff&r1=157938&r2=157939
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/virtual/VirtualNodeState.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/virtual/VirtualNodeState.java Thu Mar 17 08:08:52 2005
@@ -181,14 +181,16 @@
      * @throws RepositoryException
      */
     public void setMixinNodeTypes(QName[] mixins) throws RepositoryException {
-        HashSet set = new HashSet();
-        InternalValue[] values = new InternalValue[mixins.length];
-        for (int i = 0; i < mixins.length; i++) {
-            set.add(mixins[i]);
-            values[i] = InternalValue.create(mixins[i]);
+        if (mixins != null) {
+            HashSet set = new HashSet();
+            InternalValue[] values = new InternalValue[mixins.length];
+            for (int i = 0; i < mixins.length; i++) {
+                set.add(mixins[i]);
+                values[i] = InternalValue.create(mixins[i]);
+            }
+            setMixinTypeNames(set);
+            setPropertyValues(JCR_MIXINTYPES, PropertyType.NAME, values);
         }
-        setMixinTypeNames(set);
-        setPropertyValues(JCR_MIXINTYPES, PropertyType.NAME, values);
     }
 
     /**



Mime
View raw message