jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r578863 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core: lock/LockImpl.java nodetype/EffectiveNodeType.java nodetype/ItemDefinitionImpl.java nodetype/NodeDefinitionImpl.java nodetype/NodeTypeImpl.java
Date Mon, 24 Sep 2007 15:54:49 GMT
Author: stefan
Date: Mon Sep 24 08:54:47 2007
New Revision: 578863

URL: http://svn.apache.org/viewvc?rev=578863&view=rev
Log:
JCR-1104: JSR 283 support

work in (slow) progress...

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/LockImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/EffectiveNodeType.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/ItemDefinitionImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeDefinitionImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeImpl.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/LockImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/LockImpl.java?rev=578863&r1=578862&r2=578863&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/LockImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/LockImpl.java
Mon Sep 24 08:54:47 2007
@@ -48,7 +48,7 @@
         this.node = node;
     }
 
-    //------------------------------------------------------------------< Lock >
+    //-----------------------------------------------------------------< Lock >
 
     /**
      * {@inheritDoc}
@@ -109,5 +109,23 @@
             throw new LockException("Session does not hold lock.");
         }
         // since a lock has no expiration date no other action is required
+    }
+
+    //--------------------------------------------------< new JSR 283 methods >
+    /**
+     * Returns <code>true</code> if the current session is the owner of this
+     * lock, either because it is session-scoped and bound to this session or
+     * open-scoped and this session currently holds the token for this lock.
+     * Returns <code>false</code> otherwise.
+     *
+     * @return a <code>boolean</code>.
+     * @since JCR 2.0
+     */
+    public boolean isLockOwningSession() {
+        try {
+            return info.getLockHolder().equals(node.getSession());
+        } catch (RepositoryException e) {
+            return false;
+        }
     }
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/EffectiveNodeType.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/EffectiveNodeType.java?rev=578863&r1=578862&r2=578863&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/EffectiveNodeType.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/EffectiveNodeType.java
Mon Sep 24 08:54:47 2007
@@ -905,6 +905,50 @@
     }
 
     /**
+     * @param name
+     * @throws ConstraintViolationException
+     */
+    public void checkRemoveNodeConstraints(QName name) throws ConstraintViolationException
{
+        /**
+         * as there might be multiple definitions with the same name and we
+         * don't know which one is applicable, we check all of them
+         */
+        ItemDef[] defs = getNamedNodeDefs(name);
+        if (defs != null) {
+            for (int i = 0; i < defs.length; i++) {
+                if (defs[i].isMandatory()) {
+                    throw new ConstraintViolationException("can't remove mandatory node");
+                }
+                if (defs[i].isProtected()) {
+                    throw new ConstraintViolationException("can't remove protected node");
+                }
+            }
+        }
+    }
+
+    /**
+     * @param name
+     * @throws ConstraintViolationException
+     */
+    public void checkRemovePropertyConstraints(QName name) throws ConstraintViolationException
{
+        /**
+         * as there might be multiple definitions with the same name and we
+         * don't know which one is applicable, we check all of them
+         */
+        ItemDef[] defs = getNamedPropDefs(name);
+        if (defs != null) {
+            for (int i = 0; i < defs.length; i++) {
+                if (defs[i].isMandatory()) {
+                    throw new ConstraintViolationException("can't remove mandatory property");
+                }
+                if (defs[i].isProtected()) {
+                    throw new ConstraintViolationException("can't remove protected property");
+                }
+            }
+        }
+    }
+
+    /**
      * Merges another <code>EffectiveNodeType</code> with this one.
      * Checks for merge conflicts.
      *

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/ItemDefinitionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/ItemDefinitionImpl.java?rev=578863&r1=578862&r2=578863&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/ItemDefinitionImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/ItemDefinitionImpl.java
Mon Sep 24 08:54:47 2007
@@ -119,7 +119,7 @@
                 return NameFormat.format(itemDef.getName(), nsResolver);
             } catch (NoPrefixDeclaredException npde) {
                 // should never get here
-                log.error("encountered unregistered namespace in property name",
+                log.error("encountered unregistered namespace in item name",
                         npde);
                 // not correct, but an acceptable fallback
                 return itemDef.getName().toString();

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeDefinitionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeDefinitionImpl.java?rev=578863&r1=578862&r2=578863&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeDefinitionImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeDefinitionImpl.java
Mon Sep 24 08:54:47 2007
@@ -18,6 +18,8 @@
 
 import org.apache.jackrabbit.name.NamespaceResolver;
 import org.apache.jackrabbit.name.QName;
+import org.apache.jackrabbit.name.NameFormat;
+import org.apache.jackrabbit.name.NoPrefixDeclaredException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -105,6 +107,78 @@
      */
     public boolean allowsSameNameSiblings() {
         return ((NodeDef) itemDef).allowsSameNameSiblings();
+    }
+
+    //--------------------------------------------------< new JSR 283 methods >
+    /**
+     * Returns the names of the required primary node types.
+     * <p/>
+     * If this <code>NodeDefinition</code> is acquired from a live
+     * <code>NodeType</code> this list will reflect the node types returned by
+     * <code>getRequiredPrimaryTypes</code>, above.
+     * <p/>
+     * If this <code>NodeDefinition</code> is actually a
+     * <code>NodeDefinitionTemplate</code> that is not part of a registered node
+     * type, then this method will return the required primary types as set in
+     * that template. If that template is a newly-created empty one, then this
+     * method will return an array containing a single string indicating the
+     * node type <code>nt:base</code>.
+     *
+     * @return a String array
+     * @since JCR 2.0
+     */
+    public String[] getRequiredPrimaryTypeNames() {
+        QName[] ntNames = ((NodeDef) itemDef).getRequiredPrimaryTypes();
+        try {
+            if (ntNames == null || ntNames.length == 0) {
+                // return "nt:base"
+                return new String[] {NameFormat.format(QName.NT_BASE, nsResolver)};
+            } else {
+                String[] names = new String[ntNames.length];
+                for (int i = 0; i < ntNames.length; i++) {
+                    names[i] = NameFormat.format(ntNames[i], nsResolver);
+                }
+                return names;
+            }
+        } catch (NoPrefixDeclaredException npde) {
+            // should never get here
+            log.error("encountered unregistered namespace in node type name",
+                    npde);
+            return new String[0];
+        }
+    }
+
+    /**
+     * Returns the name of the default primary node type.
+     * <p/>
+     * If this <code>NodeDefinition</code> is acquired from a live
+     * <code>NodeType</code> this list will reflect the NodeType returned by
+     * getDefaultPrimaryType, above.
+     * <p/>
+     * If this <code>NodeDefinition</code> is actually a
+     * <code>NodeDefinitionTemplate</code> that is not part of a registered node
+     * type, then this method will return the required primary types as set in
+     * that template. If that template is a newly-created empty one, then this
+     * method will return <code>null</code>.
+     *
+     * @return a String
+     * @since JCR 2.0
+     */
+    public String getDefaultPrimaryTypeName() {
+        QName ntName = ((NodeDef) itemDef).getDefaultPrimaryType();
+        if (ntName == null) {
+            return null;
+        }
+
+        try {
+            return NameFormat.format(ntName, nsResolver);
+        } catch (NoPrefixDeclaredException npde) {
+            // should never get here
+            log.error("encountered unregistered namespace in node type name",
+                    npde);
+            // not correct, but an acceptable fallback
+            return ntName.toString();
+        }
     }
 }
 

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeImpl.java?rev=578863&r1=578862&r2=578863&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeImpl.java
Mon Sep 24 08:54:47 2007
@@ -541,4 +541,47 @@
         }
         return propDefs;
     }
+
+    //--------------------------------------------------< new JSR 283 methods >
+    /**
+     * Returns <code>true</code> if removing the child node called
+     * <code>nodeName</code> is allowed by this node type. Returns
+     * <code>false</code> otherwise.
+     *
+     * @param nodeName The name of the child node
+     * @return a boolean
+     * @since JCR 2.0
+     */
+    public boolean canRemoveNode(String nodeName) {
+        try {
+            ent.checkRemoveNodeConstraints(NameFormat.parse(nodeName, nsResolver));
+            return true;
+        } catch (NameException be) {
+            // implementation specific exception, fall through
+        } catch (RepositoryException re) {
+            // fall through
+        }
+        return false;
+    }
+
+    /**
+     * Returns <code>true</code> if removing the property called
+     * <code>propertyName</code> is allowed by this node type. Returns
+     * <code>false</code> otherwise.
+     *
+     * @param propertyName The name of the property
+     * @return a boolean
+     * @since JCR 2.0
+     */
+    public boolean canRemoveProperty(String propertyName) {
+        try {
+            ent.checkRemovePropertyConstraints(NameFormat.parse(propertyName, nsResolver));
+            return true;
+        } catch (NameException be) {
+            // implementation specific exception, fall through
+        } catch (RepositoryException re) {
+            // fall through
+        }
+        return false;
+    }
 }



Mime
View raw message