jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1022488 - in /jackrabbit/trunk: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/authorization/ jackrabbit-core/src/main/java/org/apache/jackrabbit...
Date Thu, 14 Oct 2010 12:28:57 GMT
Author: jukka
Date: Thu Oct 14 12:28:57 2010
New Revision: 1022488

URL: http://svn.apache.org/viewvc?rev=1022488&view=rev
Log:
JCR-2762: Optimize bundle serialization

Add common names used by the access control features. Reorder names by popularity.

Rename read/writeInt() to read/writeVarInt() as suggested by Thomas. Remove recursion from
writeVarInt().

Minor optimizations in read/writeName(), including a fix to the case where the local name
is more than 15 characters long.

Extend the use of read/writeVarInt() and read/writeString() to more places in the code.

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/BundleNames.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/BundleReader.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/BundleWriter.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/authorization/AccessControlConstants.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/authorization/principalbased/ACLTemplate.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/NameConstants.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/BundleNames.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/BundleNames.java?rev=1022488&r1=1022487&r2=1022488&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/BundleNames.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/BundleNames.java
Thu Oct 14 12:28:57 2010
@@ -32,7 +32,6 @@ import org.apache.jackrabbit.spi.commons
 //                                                                         //
 // WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING //
 
-
 /**
  * Static collection of common JCR names. This class is used by the
  * {@link BundleWriter} and {@link BundleReader} classes to optimize the
@@ -46,119 +45,147 @@ class BundleNames {
     private static final Name[] NAME_ARRAY = {
         // WARNING: Only edit if you really know what you're doing!
         null,
-        NameConstants.JCR_ACTIVITIES,
-        NameConstants.JCR_ACTIVITY,
-        NameConstants.JCR_ACTIVITY_TITLE,
-        NameConstants.JCR_AUTOCREATED,
-        NameConstants.JCR_BASEVERSION,
-        NameConstants.JCR_CHILDNODEDEFINITION,
-        NameConstants.JCR_CHILDVERSIONHISTORY,
-        NameConstants.JCR_CONFIGURATION,
-        NameConstants.JCR_CONFIGURATIONS,
-        NameConstants.JCR_CONTENT,
-        NameConstants.JCR_COPIEDFROM,
+        // Most frequently used names
+        NameConstants.NT_UNSTRUCTURED,
+        NameConstants.NT_RESOURCE,
+        NameConstants.NT_FILE,
+        NameConstants.NT_FOLDER,
+        NameConstants.NT_HIERARCHYNODE,
+        NameConstants.MIX_REFERENCEABLE,
         NameConstants.JCR_CREATED,
         NameConstants.JCR_CREATEDBY,
-        NameConstants.JCR_CURRENT_LIFECYCLE_STATE,
+        NameConstants.JCR_LASTMODIFIED,
+        NameConstants.JCR_LASTMODIFIEDBY,
+        NameConstants.JCR_CONTENT,
+        NameConstants.JCR_MIMETYPE,
         NameConstants.JCR_DATA,
-        NameConstants.JCR_DEFAULTPRIMARYTYPE,
-        NameConstants.JCR_DEFAULTVALUES,
+        NameConstants.JCR_TITLE,
+        NameConstants.JCR_LANGUAGE,
         NameConstants.JCR_ENCODING,
-        NameConstants.JCR_ETAG,
-        NameConstants.JCR_FROZENMIXINTYPES,
-        NameConstants.JCR_FROZENNODE,
+        NameConstants.JCR_SYSTEM,
+        NameConstants.REP_ROOT,
+        NameConstants.REP_SYSTEM,
+
+        // Access control
+        NameConstants.JCR_ADD_CHILD_NODES,
+        NameConstants.JCR_LIFECYCLE_MANAGEMENT,
+        NameConstants.JCR_LOCK_MANAGEMENT,
+        NameConstants.JCR_MODIFY_ACCESS_CONTROL,
+        NameConstants.JCR_MODIFY_PROPERTIES,
+        NameConstants.JCR_NODE_TYPE_MANAGEMENT,
+        NameConstants.JCR_READ,
+        NameConstants.JCR_READ_ACCESS_CONTROL,
+        NameConstants.JCR_REMOVE_CHILD_NODES,
+        NameConstants.JCR_REMOVE_NODE,
+        NameConstants.JCR_VERSION_MANAGEMENT,
+        NameConstants.REP_ACCESSCONTROL,
+        NameConstants.REP_ACCESS_CONTROL,
+        NameConstants.REP_ACCESS_CONTROLLABLE,
+        NameConstants.REP_ACE,
+        NameConstants.REP_ACL,
+        NameConstants.REP_DENY_ACE,
+        NameConstants.REP_GLOB,
+        NameConstants.REP_GRANT_ACE,
+        NameConstants.REP_POLICY,
+        NameConstants.REP_PRINCIPAL_ACCESS_CONTROL,
+        NameConstants.REP_PRINCIPAL_NAME,
+        NameConstants.REP_PRIVILEGES,
+
+        // Locking
+        NameConstants.MIX_LOCKABLE,
+        NameConstants.JCR_LOCKISDEEP,
+        NameConstants.JCR_LOCKOWNER,
+
+        // Versioning
+        NameConstants.MIX_VERSIONABLE,
+        NameConstants.NT_FROZENNODE,
+        NameConstants.NT_VERSION,
+        NameConstants.NT_VERSIONEDCHILD,
+        NameConstants.NT_VERSIONHISTORY,
+        NameConstants.NT_VERSIONLABELS,
+        NameConstants.JCR_VERSIONSTORAGE,
         NameConstants.JCR_FROZENPRIMARYTYPE,
         NameConstants.JCR_FROZENUUID,
-        NameConstants.JCR_HASORDERABLECHILDNODES,
-        NameConstants.JCR_HOST,
-        NameConstants.JCR_ID,
+        NameConstants.JCR_FROZENNODE,
+        NameConstants.JCR_PREDECESSORS,
+        NameConstants.JCR_SUCCESSORS,
+        NameConstants.JCR_VERSIONLABELS,
+        NameConstants.JCR_VERSIONHISTORY,
+        NameConstants.JCR_VERSIONABLEUUID,
+        NameConstants.JCR_ROOTVERSION,
         NameConstants.JCR_ISCHECKEDOUT,
-        NameConstants.JCR_ISMIXIN,
-        NameConstants.JCR_LANGUAGE,
-        NameConstants.JCR_LASTMODIFIED,
-        NameConstants.JCR_LASTMODIFIEDBY,
-        NameConstants.JCR_LIFECYCLE_POLICY,
-        NameConstants.JCR_LOCKISDEEP,
-        NameConstants.JCR_LOCKOWNER,
-        NameConstants.JCR_MANDATORY,
+        NameConstants.JCR_BASEVERSION,
         NameConstants.JCR_MERGEFAILED,
-        NameConstants.JCR_MIMETYPE,
-        NameConstants.JCR_MIXINTYPES,
-        NameConstants.JCR_MULTIPLE,
-        NameConstants.JCR_NAME,
-        NameConstants.JCR_NODETYPENAME,
+        NameConstants.REP_NODETYPES,
+
+        // Node types
+        NameConstants.NT_NODETYPE,
+        NameConstants.NT_PROPERTYDEFINITION,
+        NameConstants.NT_CHILDNODEDEFINITION,
+        NameConstants.NT_BASE,
         NameConstants.JCR_NODETYPES,
-        NameConstants.JCR_ONPARENTVERSION,
-        NameConstants.JCR_PATH,
-        NameConstants.JCR_PORT,
-        NameConstants.JCR_PREDECESSORS,
-        NameConstants.JCR_PRIMARYITEMNAME,
-        NameConstants.JCR_PRIMARYTYPE,
-        NameConstants.JCR_PROPERTYDEFINITION,
         NameConstants.JCR_PROTECTED,
-        NameConstants.JCR_PROTOCOL,
-        NameConstants.JCR_REPOSITORY,
-        NameConstants.JCR_REQUIREDPRIMARYTYPES,
+        NameConstants.JCR_ONPARENTVERSION,
+        NameConstants.JCR_MANDATORY,
+        NameConstants.JCR_AUTOCREATED,
+        NameConstants.JCR_FROZENMIXINTYPES,
+        NameConstants.JCR_NAME,
+        NameConstants.JCR_VALUECONSTRAINTS,
         NameConstants.JCR_REQUIREDTYPE,
-        NameConstants.JCR_ROOT,
-        NameConstants.JCR_ROOTVERSION,
-        NameConstants.JCR_SAMENAMESIBLINGS,
-        NameConstants.JCR_SCORE,
-        NameConstants.JCR_STATEMENT,
-        NameConstants.JCR_SUCCESSORS,
+        NameConstants.JCR_PROPERTYDEFINITION,
+        NameConstants.JCR_MULTIPLE,
+        NameConstants.JCR_DEFAULTVALUES,
         NameConstants.JCR_SUPERTYPES,
-        NameConstants.JCR_SYSTEM,
-        NameConstants.JCR_UUID,
-        NameConstants.JCR_VALUECONSTRAINTS,
-        NameConstants.JCR_VERSIONHISTORY,
-        NameConstants.JCR_VERSIONLABELS,
-        NameConstants.JCR_VERSIONSTORAGE,
-        NameConstants.JCR_VERSIONABLEUUID,
-        NameConstants.JCR_WORKSPACE,
-        NameConstants.JCR_XMLCHARACTERS,
-        NameConstants.JCR_XMLTEXT,
+        NameConstants.JCR_NODETYPENAME,
+        NameConstants.JCR_ISMIXIN,
+        NameConstants.JCR_HASORDERABLECHILDNODES,
+        NameConstants.JCR_SAMENAMESIBLINGS,
+        NameConstants.JCR_REQUIREDPRIMARYTYPES,
+        NameConstants.JCR_CHILDNODEDEFINITION,
+        NameConstants.JCR_DEFAULTPRIMARYTYPE,
+        NameConstants.JCR_PRIMARYITEMNAME,
+        NameConstants.JCR_CHILDVERSIONHISTORY,
+        NameConstants.REP_VERSIONS,
+        NameConstants.REP_VERSIONSTORAGE,
+        NameConstants.REP_VERSION_REFERENCE,
+        NameConstants.REP_BASEVERSIONS,
+
+        // Miscellaneous node types
         NameConstants.MIX_CREATED,
         NameConstants.MIX_ETAG,
         NameConstants.MIX_LANGUAGE,
         NameConstants.MIX_LASTMODIFIED,
         NameConstants.MIX_LIFECYCLE,
-        NameConstants.MIX_LOCKABLE,
         NameConstants.MIX_MIMETYPE,
-        NameConstants.MIX_REFERENCEABLE,
         NameConstants.MIX_SHAREABLE,
         NameConstants.MIX_SIMPLE_VERSIONABLE,
         NameConstants.MIX_TITLE,
-        NameConstants.MIX_VERSIONABLE,
         NameConstants.NT_ACTIVITY,
         NameConstants.NT_ADDRESS,
-        NameConstants.NT_BASE,
-        NameConstants.NT_CHILDNODEDEFINITION,
         NameConstants.NT_CONFIGURATION,
-        NameConstants.NT_FILE,
-        NameConstants.NT_FOLDER,
-        NameConstants.NT_FROZENNODE,
-        NameConstants.NT_HIERARCHYNODE,
-        NameConstants.NT_NODETYPE,
-        NameConstants.NT_PROPERTYDEFINITION,
         NameConstants.NT_QUERY,
-        NameConstants.NT_RESOURCE,
         NameConstants.NT_SHARE,
-        NameConstants.NT_UNSTRUCTURED,
-        NameConstants.NT_VERSION,
-        NameConstants.NT_VERSIONEDCHILD,
-        NameConstants.NT_VERSIONHISTORY,
-        NameConstants.NT_VERSIONLABELS,
+
+        // Miscellaneous names
         NameConstants.REP_ACTIVITIES,
+        NameConstants.JCR_ACTIVITIES,
+        NameConstants.JCR_ACTIVITY,
+        NameConstants.JCR_ACTIVITY_TITLE,
+        NameConstants.JCR_XMLCHARACTERS,
+        NameConstants.JCR_XMLTEXT,
         NameConstants.REP_CONFIGURATIONS,
-        NameConstants.REP_VERSION_REFERENCE,
-        NameConstants.REP_BASEVERSIONS,
-        NameConstants.REP_NODETYPES,
-        NameConstants.REP_ROOT,
-        NameConstants.REP_SYSTEM,
-        NameConstants.REP_VERSIONS,
-        NameConstants.REP_VERSIONSTORAGE
-    };  // WARNING: Only edit if you really know what you're doing!
+        NameConstants.JCR_CONFIGURATION,
+        NameConstants.JCR_CONFIGURATIONS,
+        NameConstants.JCR_COPIEDFROM,
+        NameConstants.JCR_CURRENT_LIFECYCLE_STATE,
+        NameConstants.JCR_ETAG,
+        NameConstants.JCR_HOST,
+        NameConstants.JCR_ID,
+        NameConstants.JCR_LIFECYCLE_POLICY,
+        NameConstants.JCR_PATH,
+        NameConstants.JCR_STATEMENT,
 
+    };  // WARNING: Only edit if you really know what you're doing!
 
     private static final Map<Name, Integer> NAME_MAP =
         new HashMap<Name, Integer>();

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/BundleReader.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/BundleReader.java?rev=1022488&r1=1022487&r2=1022488&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/BundleReader.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/BundleReader.java
Thu Oct 14 12:28:57 2010
@@ -141,7 +141,7 @@ class BundleReader {
 
         // read modcount, since version 1.0
         if (version >= BundleBinding.VERSION_3) {
-            bundle.setModCount((short) readInt());
+            bundle.setModCount((short) readVarInt());
         } else if (version >= BundleBinding.VERSION_1) {
             bundle.setModCount(in.readShort());
         }
@@ -182,13 +182,13 @@ class BundleReader {
             if (len != 0) {
                 entry.setMultiValued(true);
                 if (len == 0x0f) {
-                    count = readInt() + 0x0f - 1;
+                    count = readVarInt() + 0x0f - 1;
                 } else {
                     count = len - 1;
                 }
             }
 
-            entry.setModCount((short) readInt());
+            entry.setModCount((short) readVarInt());
         } else {
             // type and modcount
             int type = in.readInt();
@@ -215,9 +215,9 @@ class BundleReader {
                 case PropertyType.BINARY:
                     int size = in.readInt();
                     if (size == BundleBinding.BINARY_IN_DATA_STORE) {
-                        val = InternalValue.create(binding.dataStore, in.readUTF());
+                        val = InternalValue.create(binding.dataStore, readString());
                     } else if (size == BundleBinding.BINARY_IN_BLOB_STORE) {
-                        blobIds[i] = in.readUTF();
+                        blobIds[i] = readString();
                         try {
                             BLOBStore blobStore = binding.getBlobStore();
                             if (blobStore instanceof ResourceBasedBLOBStore) {
@@ -264,18 +264,18 @@ class BundleReader {
                     val = InternalValue.create(readNodeId(), false);
                     break;
                 default:
-                    // because writeUTF(String) has a size limit of 64k,
-                    // Strings are serialized as <length><byte[]>
-                    int len;
                     if (version >= BundleBinding.VERSION_3) {
-                        len = readInt();
+                        val = InternalValue.valueOf(
+                                readString(), entry.getType());
                     } else {
-                        len = in.readInt();
+                        // because writeUTF(String) has a size limit of 64k,
+                        // Strings are serialized as <length><byte[]>
+                        int len = in.readInt();
+                        byte[] bytes = new byte[len];
+                        in.readFully(bytes);
+                        val = InternalValue.valueOf(
+                                new String(bytes, "UTF-8"), entry.getType());
                     }
-                    byte[] bytes = new byte[len];
-                    in.readFully(bytes);
-                    val = InternalValue.valueOf(
-                            new String(bytes, "UTF-8"), entry.getType());
             }
             values[i] = val;
         }
@@ -310,7 +310,7 @@ class BundleReader {
     private BigDecimal readDecimal() throws IOException {
         if (in.readBoolean()) {
             // TODO more efficient serialization format
-            return new BigDecimal(in.readUTF());
+            return new BigDecimal(readString());
         } else {
             return null;
         }
@@ -369,21 +369,13 @@ class BundleReader {
             if (ns < namespaces.length && namespaces[ns] != null) {
                 uri = namespaces[ns];
             } else {
-                uri = in.readUTF();
+                uri = readString();
                 if (ns < namespaces.length) {
                     namespaces[ns] = uri;
                 }
             }
 
-            String local;
-            int len = b & 0x0f;
-            if (b != 0x0f) {
-                byte[] buffer = new byte[len + 1];
-                in.readFully(buffer);
-                local = new String(buffer, "UTF-8");
-            } else {
-                local = in.readUTF();
-            }
+            String local = new String(readBytes((b & 0x0f) + 1, 0x10), "UTF-8");
 
             return NameFactoryImpl.getInstance().create(uri, local);
         }
@@ -396,13 +388,30 @@ class BundleReader {
      * @return deserialized name
      * @throws IOException if an I/O error occurs
      */
-    private int readInt() throws IOException {
+    private int readVarInt() throws IOException {
         int b = in.readUnsignedByte();
         if ((b & 0x80) == 0) {
             return b;
         } else {
-            return readInt() << 7 | b & 0x7f;
+            return readVarInt() << 7 | b & 0x7f;
         }
     }
 
+    private String readString() throws IOException {
+        if (version >= BundleBinding.VERSION_3) {
+            return new String(readBytes(0, 0), "UTF-8");
+        } else {
+            return in.readUTF();
+        }
+    }
+
+    private byte[] readBytes(int len, int base) throws IOException {
+        if (len == base) {
+            len += readVarInt();
+        }
+        byte[] bytes = new byte[len];
+        in.readFully(bytes);
+        return bytes;
+    }
+
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/BundleWriter.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/BundleWriter.java?rev=1022488&r1=1022487&r2=1022488&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/BundleWriter.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/BundleWriter.java
Thu Oct 14 12:28:57 2010
@@ -124,7 +124,7 @@ class BundleWriter {
         writeNodeId(null);
 
         // write mod count
-        writeInt(bundle.getModCount());
+        writeVarInt(bundle.getModCount());
 
         // write shared set
         for (NodeId nodeId: bundle.getSharedSet()) {
@@ -155,7 +155,7 @@ class BundleWriter {
      * the number of property values plus one and truncated at 15 (the highest
      * four-bit value). If there are 14 or more (14 + 1 == 15) property values,
      * then the number of additional values is serialized as a variable-length
-     * integer (see {@link #writeInt(int)}) right after this byte.
+     * integer (see {@link #writeVarInt(int)}) right after this byte.
      * <p>
      * The modification count of the property state is written next as a
      * variable-length integer, followed by the serializations of all the
@@ -176,14 +176,14 @@ class BundleWriter {
                 out.writeByte(len << 4 | type);
             } else {
                 out.writeByte(0xf0 | type);
-                writeInt(len - 0x0f);
+                writeVarInt(len - 0x0f);
             }
         } else {
             assert values.length == 1;
             out.writeByte(type);
         }
 
-        writeInt(state.getModCount());
+        writeVarInt(state.getModCount());
 
         // values
         for (int i = 0; i < values.length; i++) {
@@ -200,7 +200,7 @@ class BundleWriter {
                             } else {
                                 out.writeInt(BundleBinding.BINARY_IN_DATA_STORE);
                                 val.store(dataStore);
-                                out.writeUTF(val.toString());
+                                writeString(val.toString());
                             }
                             break;
                         }
@@ -248,7 +248,7 @@ class BundleWriter {
                                 val.discard();
                             }
                             // store id of blob as property value
-                            out.writeUTF(blobId);   // value
+                            writeString(blobId);   // value
                         } else {
                             // delete evt. blob
                             byte[] data = writeSmallBinary(val, state, i);
@@ -309,11 +309,8 @@ class BundleWriter {
                     writeNodeId(val.getNodeId());
                     break;
                 default:
-                    // because writeUTF(String) has a size limit of 64k,
-                    // we're using write(byte[]) instead
-                    byte[] bytes = val.toString().getBytes("UTF-8");
-                    writeInt(bytes.length); // length of byte[]
-                    out.write(bytes);   // byte[]
+                    writeString(val.toString());
+                    break;
             }
         }
     }
@@ -379,7 +376,7 @@ class BundleWriter {
         } else {
             out.writeBoolean(true);
             // TODO more efficient serialization format
-            out.writeUTF(decimal.toString());
+            writeString(decimal.toString());
         }
     }
 
@@ -408,7 +405,7 @@ class BundleWriter {
      * most six other other namespaces (values 1-6), in the order they appear
      * in the bundle. When one of these six custom namespaces first appears
      * in the bundle, then the namespace URI is written using
-     * {@link DataOutputStream#writeUTF(String)} right after this byte.
+     * {@link #writeString(String)} right after this byte.
      * Later uses of such a namespace simply refers back to the already read
      * namespace URI string. Any other namespaces are identified with value 7
      * and always written to the bundle after this byte.
@@ -419,8 +416,9 @@ class BundleWriter {
      * field. The UTF-8 byte sequence is written out after this byte and the
      * possible namespace URI string. If the length of the local name is
      * larger than 15 (i.e. would be stored as 0x0f or more), then the value
-     * 0x0f is stored as the name length and the name string is written
-     * using {@link DataOutputStream#writeUTF(String)}.
+     * 0x0f is stored as the name length and the name string is written as
+     * UTF-8 using {@link #writeBytes(byte[], int)} with a base length of
+     * 0x10 (0x0f + 1).
      *
      * @param name the name
      * @throws IOException in an I/O error occurs.
@@ -445,7 +443,7 @@ class BundleWriter {
 
             out.writeByte(0x80 | ns << 4 | len);
             if (ns == namespaces.length || namespaces[ns] == null) {
-                out.writeUTF(uri);
+                writeString(uri);
                 if (ns < namespaces.length) {
                     namespaces[ns] = uri;
                 }
@@ -453,7 +451,7 @@ class BundleWriter {
             if (len != 0x0f) {
                 out.write(bytes);
             } else {
-                out.writeUTF(local);
+                writeBytes(bytes, 0x0f + 1);
             }
         }
     }
@@ -482,14 +480,44 @@ class BundleWriter {
      * @param integer integer value
      * @throws IOException if an I/O error occurs
      */
-    private void writeInt(int value) throws IOException {
-        int b = value & 0x7f;
-        if (b == value) {
-            out.writeByte(b);
-        } else {
-            out.writeByte(b | 0x80);
-            writeInt(value >>> 7);
+    private void writeVarInt(int value) throws IOException {
+        while (true) {
+            int b = value & 0x7f;
+            if (b != value) {
+                out.writeByte(b | 0x80);
+                value >>>= 7; // unsigned shift
+            } else {
+                out.writeByte(b);
+                return;
+            }
         }
     }
 
+    /**
+     * Serializes a string in UTF-8. The length of the UTF-8 byte sequence
+     * is first written as a variable-length string (see
+     * {@link #writeVarInt(int)}), and then the sequence itself is written.
+     *
+     * @param value string value
+     * @throws IOException if an I/O error occurs
+     */
+    private void writeString(String value) throws IOException {
+        writeBytes(value.getBytes("UTF-8"), 0);
+    }
+
+    /**
+     * Serializes the given array of bytes. The length of the byte array is
+     * first written as a {@link #writeVarInt(int) variable length integer},
+     * followed by the given bytes.
+     *
+     * @param bytes the bytes to be serialized
+     * @param base optional base length
+     * @throws IOException if an I/O error occurs
+     */
+    private void writeBytes(byte[] bytes, int base) throws IOException {
+        assert bytes.length >= base;
+        writeVarInt(bytes.length - base);
+        out.write(bytes);
+    }
+
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/authorization/AccessControlConstants.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/authorization/AccessControlConstants.java?rev=1022488&r1=1022487&r2=1022488&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/authorization/AccessControlConstants.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/authorization/AccessControlConstants.java
Thu Oct 14 12:28:57 2010
@@ -17,21 +17,18 @@
 package org.apache.jackrabbit.core.security.authorization;
 
 import org.apache.jackrabbit.spi.Name;
-import org.apache.jackrabbit.spi.NameFactory;
-import org.apache.jackrabbit.spi.commons.name.NameFactoryImpl;
+import org.apache.jackrabbit.spi.commons.name.NameConstants;
 
 /**
  * <code>AccessControlConstants</code>...
  */
 public interface AccessControlConstants {
 
-    NameFactory NF = NameFactoryImpl.getInstance();
-
     //---------------------------------------------------------< node names >---
     /**
      * Default name for a node of type rep:Policy.
      */
-    Name N_POLICY = NF.create(Name.NS_REP_URI, "policy");
+    Name N_POLICY = NameConstants.REP_POLICY;
 
     /**
      * PrincipalBased-ACL:
@@ -39,55 +36,55 @@ public interface AccessControlConstants 
      * privileges for individual principals. This node is created upon
      * initializing this provider.
      */
-    Name N_ACCESSCONTROL = NF.create(Name.NS_REP_URI, "accesscontrol");
+    Name N_ACCESSCONTROL = NameConstants.REP_ACCESSCONTROL;
 
     //-----------------------------------------------------< property names >---
     /**
      * rep:privileges property name
      */
-    Name P_PRIVILEGES = NF.create(Name.NS_REP_URI, "privileges");
+    Name P_PRIVILEGES =  NameConstants.REP_PRIVILEGES;
     /**
      * rep:principalName property name
      */
-    Name P_PRINCIPAL_NAME = NF.create(Name.NS_REP_URI, "principalName");
+    Name P_PRINCIPAL_NAME = NameConstants.REP_PRINCIPAL_NAME;
 
     /**
      * rep:glob property name used to restrict the number of child nodes
      * or properties that are affected by an ACL inherited from a parent node.
      */
-    Name P_GLOB = NF.create(Name.NS_REP_URI, "glob");
+    Name P_GLOB = NameConstants.REP_GLOB;
 
     //----------------------------------------------------< node type names >---
     /**
      * rep:AccessControllable nodetype
      */
-    Name NT_REP_ACCESS_CONTROLLABLE = NF.create(Name.NS_REP_URI, "AccessControllable");
+    Name NT_REP_ACCESS_CONTROLLABLE = NameConstants.REP_ACCESS_CONTROLLABLE;
     /**
      * rep:ACL nodetype
      */
-    Name NT_REP_ACL = NF.create(Name.NS_REP_URI, "ACL");
+    Name NT_REP_ACL = NameConstants.REP_ACL;
     /**
      * rep:ACE nodetype
      */
-    Name NT_REP_ACE = NF.create(Name.NS_REP_URI, "ACE");
+    Name NT_REP_ACE = NameConstants.REP_ACE;
     /**
      * rep:GrantACE nodetype
      */
-    Name NT_REP_GRANT_ACE = NF.create(Name.NS_REP_URI, "GrantACE");
+    Name NT_REP_GRANT_ACE = NameConstants.REP_GRANT_ACE;
     /**
      * rep:DenyACE nodetype
      */
-    Name NT_REP_DENY_ACE = NF.create(Name.NS_REP_URI, "DenyACE");
+    Name NT_REP_DENY_ACE = NameConstants.REP_DENY_ACE;
 
     //----------------------------------< node types for principal based ac >---
     /**
      * rep:AccessControl nodetype
      */
-    Name NT_REP_ACCESS_CONTROL = NF.create(Name.NS_REP_URI, "AccessControl");
+    Name NT_REP_ACCESS_CONTROL = NameConstants.REP_ACCESS_CONTROL;
 
     /**
      * rep:PrincipalAccessControl nodetype
      */
-    Name NT_REP_PRINCIPAL_ACCESS_CONTROL = NF.create(Name.NS_REP_URI, "PrincipalAccessControl");
-    
+    Name NT_REP_PRINCIPAL_ACCESS_CONTROL = NameConstants.REP_PRINCIPAL_ACCESS_CONTROL;
+
 }
\ No newline at end of file

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/authorization/principalbased/ACLTemplate.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/authorization/principalbased/ACLTemplate.java?rev=1022488&r1=1022487&r2=1022488&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/authorization/principalbased/ACLTemplate.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/authorization/principalbased/ACLTemplate.java
Thu Oct 14 12:28:57 2010
@@ -25,6 +25,7 @@ import org.apache.jackrabbit.core.securi
 import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
 import org.apache.jackrabbit.spi.commons.conversion.NameResolver;
+import org.apache.jackrabbit.spi.commons.name.NameConstants;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -62,7 +63,7 @@ class ACLTemplate extends AbstractACLTem
      * rep:nodePath property name (optional if the ACL is stored with the
      * node itself).
      */
-    static final Name P_NODE_PATH = NF.create(Name.NS_REP_URI, "nodePath");
+    static final Name P_NODE_PATH = NameConstants.REP_NODE_PATH;
 
     private final Principal principal;
 

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/NameConstants.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/NameConstants.java?rev=1022488&r1=1022487&r2=1022488&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/NameConstants.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/NameConstants.java
Thu Oct 14 12:28:57 2010
@@ -16,6 +16,9 @@
  */
 package org.apache.jackrabbit.spi.commons.name;
 
+import javax.jcr.Property;
+import javax.jcr.security.Privilege;
+
 import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.NameFactory;
 
@@ -131,6 +134,9 @@ public class NameConstants {
      */
     public static final Name JCR_ID = FACTORY.create(Name.NS_JCR_URI, "id");
 
+    /** jcr:title */
+    public static final Name JCR_TITLE = FACTORY.create(Property.JCR_TITLE);
+
     //--------------------------------------< xml related item name constants >
 
     /**
@@ -562,50 +568,77 @@ public class NameConstants {
     public static final Name NT_CONFIGURATION = FACTORY.create(Name.NS_NT_URI, "configuration");
 
     //--------------------------------------------------------------------------
-    /**
-     * rep:root
-     */
-    public static final Name REP_ROOT = FACTORY.create(Name.NS_REP_URI, "root");
 
-    /**
-     * rep:system
-     */
-    public static final Name REP_SYSTEM = FACTORY.create(Name.NS_REP_URI, "system");
+    private static final Name rep(String local) {
+        return FACTORY.create(Name.NS_REP_URI, local);
+    }
 
-    /**
-     * rep:versionStorage
-     */
-    public static final Name REP_VERSIONSTORAGE = FACTORY.create(Name.NS_REP_URI, "versionStorage");
+    /** rep:root */
+    public static final Name REP_ROOT = rep("root");
 
-    /**
-     * rep:Activities
-     */
-    public static final Name REP_ACTIVITIES = FACTORY.create(Name.NS_REP_URI, "Activities");
+    /** rep:system */
+    public static final Name REP_SYSTEM = rep("system");
 
-    /**
-     * rep:Configurations
-     */
-    public static final Name REP_CONFIGURATIONS = FACTORY.create(Name.NS_REP_URI, "Configurations");
+    /** rep:versionStorage */
+    public static final Name REP_VERSIONSTORAGE = rep("versionStorage");
 
-    /**
-     * rep:baseVersions
-     */
-    public static final Name REP_BASEVERSIONS = FACTORY.create(Name.NS_REP_URI, "baseVersions");
+    /** rep:Activities */
+    public static final Name REP_ACTIVITIES = rep("Activities");
 
-    /**
-     * rep:VersionReference
-     */
-    public static final Name REP_VERSION_REFERENCE = FACTORY.create(Name.NS_REP_URI, "VersionReference");
+    /** rep:Configurations */
+    public static final Name REP_CONFIGURATIONS = rep("Configurations");
 
-    /**
-     * rep:versions
-     */
-    public static final Name REP_VERSIONS = FACTORY.create(Name.NS_REP_URI, "versions");
+    /** rep:baseVersions */
+    public static final Name REP_BASEVERSIONS = rep("baseVersions");
+
+    /** rep:VersionReference */
+    public static final Name REP_VERSION_REFERENCE = rep("VersionReference");
+
+    /** rep:versions */
+    public static final Name REP_VERSIONS = rep("versions");
     
-    /**
-     * rep:nodeTypes
-     */
-    public static final Name REP_NODETYPES = FACTORY.create(Name.NS_REP_URI, "nodeTypes");
+    /** rep:nodeTypes */
+    public static final Name REP_NODETYPES = rep("nodeTypes");
+
+    /** rep:policy */
+    public static final Name REP_POLICY = rep("policy");
+
+    /** rep:accesscontrol */
+    public static final Name REP_ACCESSCONTROL = rep("accesscontrol");
+
+    /** rep:privileges  */
+    public static final Name REP_PRIVILEGES = rep("privileges");
+
+    /** rep:principalName  */
+    public static final Name REP_PRINCIPAL_NAME = rep("principalName");
+
+    /** rep:glob */
+    public static final Name REP_GLOB = rep("glob");
+
+    /** rep:AccessControllable */
+    public static final Name REP_ACCESS_CONTROLLABLE = rep("AccessControllable");
+
+    /** rep:ACL */
+    public static final Name REP_ACL = rep("ACL");
+
+    /** rep:ACE */
+    public static final Name REP_ACE = rep("ACE");
+
+    /** rep:GrantACE */
+    public static final Name REP_GRANT_ACE = rep("GrantACE");
+
+    /** rep:DenyACE */
+    public static final Name REP_DENY_ACE = rep("DenyACE");
+
+    /** rep:AccessControl */
+    public static final Name REP_ACCESS_CONTROL = rep("AccessControl");
+
+    /** rep:PrincipalAccessControl */
+    public static final Name REP_PRINCIPAL_ACCESS_CONTROL =
+        rep("PrincipalAccessControl");
+
+    /** rep:nodePath */
+    public static final Name REP_NODE_PATH = rep("nodePath");
 
     /**
      * The special wildcard name used as the name of residual item definitions.
@@ -638,4 +671,54 @@ public class NameConstants {
      */
     public static final Name SV_MULTIPLE = FACTORY.create(Name.NS_SV_URI, "multiple");
 
+    //--------------------------------------------< privilege name constants >
+
+    /** jcr:read */
+    public static final Name JCR_READ =
+        FACTORY.create(Privilege.JCR_READ);
+
+    /** jcr:modifyProperties */
+    public static final Name JCR_MODIFY_PROPERTIES =
+        FACTORY.create(Privilege.JCR_MODIFY_PROPERTIES);
+
+    /** jcr:addChildNodes */
+    public static final Name JCR_ADD_CHILD_NODES =
+        FACTORY.create(Privilege.JCR_ADD_CHILD_NODES);
+
+    /** jcr:removeChildNodes */
+    public static final Name JCR_REMOVE_CHILD_NODES =
+        FACTORY.create(Privilege.JCR_REMOVE_CHILD_NODES);
+
+    /** jcr:removeNode */
+    public static final Name JCR_REMOVE_NODE =
+        FACTORY.create(Privilege.JCR_REMOVE_NODE);
+
+    /** jcr:readAccessControl */
+    public static final Name JCR_READ_ACCESS_CONTROL =
+        FACTORY.create(Privilege.JCR_READ_ACCESS_CONTROL);
+
+    /** jcr:modifyAccessControl */
+    public static final Name JCR_MODIFY_ACCESS_CONTROL =
+        FACTORY.create(Privilege.JCR_MODIFY_ACCESS_CONTROL);
+
+    /** jcr:nodeTypeManagement */
+    public static final Name JCR_NODE_TYPE_MANAGEMENT =
+        FACTORY.create(Privilege.JCR_NODE_TYPE_MANAGEMENT);
+
+    /** jcr:versionManagement */
+    public static final Name JCR_VERSION_MANAGEMENT =
+        FACTORY.create(Privilege.JCR_VERSION_MANAGEMENT);
+
+    /** jcr:lockManagement */
+    public static final Name JCR_LOCK_MANAGEMENT =
+        FACTORY.create(Privilege.JCR_LOCK_MANAGEMENT);
+
+    /** jcr:lifecycleManagement */
+    public static final Name JCR_LIFECYCLE_MANAGEMENT =
+        FACTORY.create(Privilege.JCR_LIFECYCLE_MANAGEMENT);
+
+    /** jcr:retentionManagement */
+    public static final Name JCR_RETENTION_MANAGEMENT =
+        FACTORY.create(Privilege.JCR_RETENTION_MANAGEMENT);
+
 }
\ No newline at end of file



Mime
View raw message