jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1127980 - /jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/ItemInfoBuilder.java
Date Thu, 26 May 2011 16:10:42 GMT
Author: mduerig
Date: Thu May 26 16:10:42 2011
New Revision: 1127980

URL: http://svn.apache.org/viewvc?rev=1127980&view=rev
Log:
JCR-2972: Allow name to be set in PropertyInfoBuilder and NodeInfoBuilder

Modified:
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/ItemInfoBuilder.java

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/ItemInfoBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/ItemInfoBuilder.java?rev=1127980&r1=1127979&r2=1127980&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/ItemInfoBuilder.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/ItemInfoBuilder.java
Thu May 26 16:10:42 2011
@@ -28,7 +28,6 @@ import org.apache.jackrabbit.spi.Path;
 import org.apache.jackrabbit.spi.PropertyId;
 import org.apache.jackrabbit.spi.PropertyInfo;
 import org.apache.jackrabbit.spi.QValue;
-import org.apache.jackrabbit.spi.commons.ItemInfoBuilder.NodeInfoBuilder;
 import org.apache.jackrabbit.spi.commons.identifier.IdFactoryImpl;
 import org.apache.jackrabbit.spi.commons.iterator.Iterators;
 import org.apache.jackrabbit.spi.commons.iterator.Predicate;
@@ -97,22 +96,33 @@ public final class ItemInfoBuilder {
     }
 
     /**
-     * Same as <code>nodeInfoBuilder(name, null)</code>
-     * @param name
+     * Same as <code>nodeInfoBuilder(localName, null)</code>
+     * @param localName
      * @return
      */
-    public static NodeInfoBuilder nodeInfoBuilder(String name) {
-        return nodeInfoBuilder(name, null);
+    public static NodeInfoBuilder nodeInfoBuilder(String localName) {
+        return nodeInfoBuilder(localName, null);
+    }
+
+    /**
+     * Return a {@link NodeInfoBuilder} for a node with a given <code>localName</code>.
+     * @param localName  localName of the node
+     * @param listener  {@link Listener} to receive notifications about {@link NodeInfo}s,
+     *                  {@link PropertyInfo}s and {@link ChildInfo}s built.
+     * @return
+     */
+    public static NodeInfoBuilder nodeInfoBuilder(String localName, Listener listener) {
+        return new NodeInfoBuilder(null, localName, listener);
     }
 
     /**
      * Return a {@link NodeInfoBuilder} for a node with a given <code>name</code>.
-     * @param name  Name of the node
+     * @param name  name of the node
      * @param listener  {@link Listener} to receive notifications about {@link NodeInfo}s,
      *                  {@link PropertyInfo}s and {@link ChildInfo}s built.
      * @return
      */
-    public static NodeInfoBuilder nodeInfoBuilder(String name, Listener listener) {
+    public static NodeInfoBuilder nodeInfoBuilder(Name name, Listener listener) {
         return new NodeInfoBuilder(null, name, listener);
     }
 
@@ -150,9 +160,10 @@ public final class ItemInfoBuilder {
         private final Listener listener;
 
         private Path parentPath;
-        private String name;
-        private int index = Path.INDEX_DEFAULT;
+        private String localName;
         private String namespace;
+        private Name name;
+        private int index = Path.INDEX_DEFAULT;
         private Name primaryTypeName = NameConstants.NT_UNSTRUCTURED;
         private final List<Name> mixins = new ArrayList<Name>();
         private boolean includeChildInfos = true;
@@ -161,7 +172,14 @@ public final class ItemInfoBuilder {
         private final List<ItemInfo> itemInfos = new ArrayList<ItemInfo>();
         private NodeInfo nodeInfo;
 
-        private NodeInfoBuilder(NodeInfoBuilder nodeInfoBuilder, String name, Listener listener)
{
+        private NodeInfoBuilder(NodeInfoBuilder nodeInfoBuilder, String localName, Listener
listener) {
+            super();
+            parent = nodeInfoBuilder;
+            this.localName = localName;
+            this.listener = listener;
+        }
+
+        private NodeInfoBuilder(NodeInfoBuilder nodeInfoBuilder, Name name, Listener listener)
{
             super();
             parent = nodeInfoBuilder;
             this.name = name;
@@ -169,29 +187,29 @@ public final class ItemInfoBuilder {
         }
 
         /**
-         * Create a new child {@link PropertyInfo} with a given <code>name</code>
and a given
+         * Create a new child {@link PropertyInfo} with a given <code>localName</code>
and a given
          * <code>value</code> of type <code>String</code> on this
{@link NodeInfo}.
          *
-         * @param name
+         * @param localName
          * @param value
          * @return  <code>this</code>
          * @throws RepositoryException
          */
-        public PropertyInfoBuilder createPropertyInfo(String name, String value) throws RepositoryException
{
-            PropertyInfoBuilder pBuilder = new PropertyInfoBuilder(this, name, listener);
+        public PropertyInfoBuilder createPropertyInfo(String localName, String value) throws
RepositoryException {
+            PropertyInfoBuilder pBuilder = new PropertyInfoBuilder(this, localName, listener);
             pBuilder.addValue(value);
             return  pBuilder;
         }
 
         /**
          * Create a new child {@link PropertyInfo} with a given
-         * <code>name</code> on this {@link NodeInfo}.
+         * <code>localName</code> on this {@link NodeInfo}.
          *
-         * @param name
+         * @param localName
          * @return  <code>this</code>
          */
-        public PropertyInfoBuilder createPropertyInfo(String name) {
-            return new PropertyInfoBuilder(this, name, listener);
+        public PropertyInfoBuilder createPropertyInfo(String localName) {
+            return new PropertyInfoBuilder(this, localName, listener);
         }
 
         /**
@@ -204,12 +222,12 @@ public final class ItemInfoBuilder {
         }
 
         /**
-         * Create a new child {@link NodeInfo} on this NodeInfo with a given <code>name</code>.
-         * @param name
+         * Create a new child {@link NodeInfo} on this NodeInfo with a given <code>localName</code>.
+         * @param localName
          * @return  <code>this</code>
          */
-        public NodeInfoBuilder createNodeInfo(String name) {
-            return new NodeInfoBuilder(this, name, listener);
+        public NodeInfoBuilder createNodeInfo(String localName) {
+            return new NodeInfoBuilder(this, localName, listener);
         }
 
         /**
@@ -218,31 +236,30 @@ public final class ItemInfoBuilder {
          * @return  <code>this</code>
          */
         public NodeInfoBuilder createNodeInfo() {
-            return new NodeInfoBuilder(this, null, listener);
+            return new NodeInfoBuilder(this, (String) null, listener);
         }
 
         /**
-         * Set the name of the node
-
+         * Set the <code>name</code> of the node
+         *
          * @param name
          * @return
          */
-        public NodeInfoBuilder setName(String name) {
+        public NodeInfoBuilder setName(Name name) {
             this.name = name;
             return this;
         }
+
         /**
-         * Set the index.
-         * @see NodeInfo#getIndex()
+         * Set the <code>localName</code> of the node
          *
-         * @param index
+         * @param localName
          * @return
          */
-        public NodeInfoBuilder setIndex(int index) {
-            this.index = index;
+        public NodeInfoBuilder setName(String localName) {
+            this.localName = localName;
             return this;
         }
-
         /**
          * Set the namespace
          *
@@ -255,6 +272,18 @@ public final class ItemInfoBuilder {
         }
 
         /**
+         * Set the index.
+         * @see NodeInfo#getIndex()
+         *
+         * @param index
+         * @return
+         */
+        public NodeInfoBuilder setIndex(int index) {
+            this.index = index;
+            return this;
+        }
+
+        /**
          * Set the parent's path of the node
          * 
          * @param parentPath
@@ -377,7 +406,7 @@ public final class ItemInfoBuilder {
         }
 
         private Path getPath() throws RepositoryException {
-            if (this.name == null) {
+            if (localName == null && name == null) {
                 throw new IllegalStateException("Name not set");
             }
             
@@ -386,8 +415,10 @@ public final class ItemInfoBuilder {
             }
             else {
                 Path path = parentPath == null ? parent.getPath() : parentPath;
-                String namespace = this.namespace == null ? Name.NS_DEFAULT_URI : this.namespace;
-                Name name = NameFactoryImpl.getInstance().create(namespace, this.name);
+                if (name == null) {
+                    String ns = namespace == null ? Name.NS_DEFAULT_URI : namespace;
+                    name = NameFactoryImpl.getInstance().create(ns, localName);
+                }
                 return PathFactoryImpl.getInstance().create(path, name, true);
             }
         }
@@ -432,7 +463,8 @@ public final class ItemInfoBuilder {
         private final NodeInfoBuilder parent;
         private final Listener listener;
 
-        private String name;
+        private Name name;
+        private String localName;
         private String namespace;
         private final List<QValue> values = new ArrayList<QValue>();
         private int type = PropertyType.UNDEFINED;
@@ -441,25 +473,36 @@ public final class ItemInfoBuilder {
         private boolean stale;
         private PropertyInfo propertyInfo;
 
-        private PropertyInfoBuilder(NodeInfoBuilder nodeInfoBuilder, String name, Listener
listener) {
+        private PropertyInfoBuilder(NodeInfoBuilder nodeInfoBuilder, String localName, Listener
listener) {
             super();
             parent = nodeInfoBuilder;
-            this.name = name;
+            this.localName = localName;
             this.listener = listener;
         }
 
         /**
-         * Set the name of this property
+         * Set the <code>name</code> of this property
          *
          * @param name
          * @return
          */
-        public PropertyInfoBuilder setName(String name) {
+        public PropertyInfoBuilder setName(Name name) {
             this.name = name;
             return this;
         }
 
         /**
+         * Set the <code>localName</code> of this property
+         *
+         * @param localName
+         * @return
+         */
+        public PropertyInfoBuilder setName(String localName) {
+            this.localName = localName;
+            return this;
+        }
+
+        /**
          * Set the namespace
          *
          * @param namespace
@@ -687,17 +730,19 @@ public final class ItemInfoBuilder {
             else if (type == PropertyType.UNDEFINED) {
                 throw new IllegalStateException("Type not set");
             }
-            else if (this.name == null) {
+            else if (localName == null && name == null) {
                 throw new IllegalStateException("Name not set");
             }
             else {
                 stale = true;
 
                 NodeId parentId = parent.getId();
-                String namespace = this.namespace == null ? Name.NS_DEFAULT_URI : this.namespace;
-                Name propertyName = NameFactoryImpl.getInstance().create(namespace, this.name);
-                Path path = PathFactoryImpl.getInstance().create(parentId.getPath(), propertyName,
true);
-                PropertyId id = IdFactoryImpl.getInstance().createPropertyId(parentId, propertyName);
+                if (name == null) {
+                    String ns = namespace == null ? Name.NS_DEFAULT_URI : namespace;
+                    name = NameFactoryImpl.getInstance().create(ns, localName);
+                }
+                Path path = PathFactoryImpl.getInstance().create(parentId.getPath(), name,
true);
+                PropertyId id = IdFactoryImpl.getInstance().createPropertyId(parentId, name);
 
                 propertyInfo = new PropertyInfoImpl(path, id, type, isMultivalued,
                         values.toArray(new QValue[values.size()]));



Mime
View raw message