directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r601651 - in /directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap: ldif/LdifUtils.java name/LdapDN.java util/ImmutableAttributeWrapper.java util/ImmutableAttributesWrapper.java
Date Thu, 06 Dec 2007 08:11:16 GMT
Author: akarasulu
Date: Thu Dec  6 00:11:16 2007
New Revision: 601651

URL: http://svn.apache.org/viewvc?rev=601651&view=rev
Log:
changes ...

 o fixed problem which hid NPE in LdifUtils
 o added a couple wrappers around an Attributes object for immutibility
 o made normalize() method return 'this' so I can chain ops


Added:
    directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/util/ImmutableAttributeWrapper.java
    directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/util/ImmutableAttributesWrapper.java
Modified:
    directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifUtils.java
    directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDN.java

Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifUtils.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifUtils.java?rev=601651&r1=601650&r2=601651&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifUtils.java
(original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifUtils.java
Thu Dec  6 00:11:16 2007
@@ -700,7 +700,7 @@
                                        Attributes modifiedEntry ) throws NamingException
     {
         // First, protect the original entry by cloning it : we will modify it
-        Attributes clonedEntry = (Attributes)modifiedEntry.clone();
+        Attributes clonedEntry = ( Attributes ) modifiedEntry.clone();
 
         Entry entry = new Entry();
         entry.setChangeType( ChangeType.Modify );
@@ -786,7 +786,8 @@
         // Special case if we don't have any reverse modifications
         if ( reverseModifications.size() == 0 )
         {
-            return null;
+            throw new IllegalArgumentException( "Could not deduce reverse modifications from
provided modifications: "
+                    + forwardModifications );
         }
 
         // Now, push the reversed list into the entry

Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDN.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDN.java?rev=601651&r1=601650&r2=601651&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDN.java
(original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDN.java
Thu Dec  6 00:11:16 2007
@@ -1606,16 +1606,16 @@
      * @throws InvalidNameException If the DN is invalid.
      * @throws NamingException If something went wrong.
      */
-    public void normalize( Map<String, OidNormalizer> oidsMap ) throws InvalidNameException,
NamingException
+    public LdapDN normalize( Map<String, OidNormalizer> oidsMap ) throws InvalidNameException,
NamingException
     {
         if ( ( oidsMap == null ) || ( oidsMap.size() == 0 ) )
         {
-            return;
+            return this;
         }
 
         if ( size() == 0 )
         {
-            return;
+            return this;
         }
 
         Enumeration<Rdn> localRdns = getAllRdn();
@@ -1632,6 +1632,7 @@
 
         normalizeInternal();
         normalized = true;
+        return this;
     }
 
 

Added: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/util/ImmutableAttributeWrapper.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/util/ImmutableAttributeWrapper.java?rev=601651&view=auto
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/util/ImmutableAttributeWrapper.java
(added)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/util/ImmutableAttributeWrapper.java
Thu Dec  6 00:11:16 2007
@@ -0,0 +1,140 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.directory.shared.ldap.util;
+
+
+import javax.naming.directory.Attribute;
+import javax.naming.directory.DirContext;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+
+
+/**
+ * A read only wrapper around an Attributes object.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ImmutableAttributeWrapper implements Attribute
+{
+    private final Attribute wrapped;
+
+
+    public ImmutableAttributeWrapper( Attribute wrapped )
+    {
+        this.wrapped = wrapped;
+    }
+
+
+    public NamingEnumeration<?> getAll() throws NamingException
+    {
+        return wrapped.getAll();
+    }
+
+
+    public Object get() throws NamingException
+    {
+        return wrapped.get();
+    }
+
+
+    public int size()
+    {
+        return wrapped.size();
+    }
+
+
+    public String getID()
+    {
+        return wrapped.getID();
+    }
+
+
+    public boolean contains( Object attrVal )
+    {
+        return wrapped.contains( attrVal );
+    }
+
+
+    public boolean add( Object attrVal )
+    {
+        throw new UnsupportedOperationException( "Value addition not supported for immutable
attribute" );
+    }
+
+
+    public boolean remove( Object attrval )
+    {
+        throw new UnsupportedOperationException( "Value removal not supported for immutable
attribute" );
+    }
+
+
+    public void clear()
+    {
+        throw new UnsupportedOperationException( "Clearing all values not supported for immutable
attribute" );
+    }
+
+
+    public DirContext getAttributeSyntaxDefinition() throws NamingException
+    {
+        return wrapped.getAttributeSyntaxDefinition();
+    }
+
+
+    public DirContext getAttributeDefinition() throws NamingException
+    {
+        return wrapped.getAttributeDefinition();
+    }
+
+
+    @SuppressWarnings ( { "CloneDoesntCallSuperClone" } )
+    public Object clone()
+    {
+        throw new IllegalStateException( "Now why would you ever want to clone an immutable
object?" );
+    }
+
+
+    public boolean isOrdered()
+    {
+        return wrapped.isOrdered();
+    }
+
+
+    public Object get( int ix ) throws NamingException
+    {
+        return wrapped.get( ix );
+    }
+
+
+    public Object remove( int ix )
+    {
+        throw new UnsupportedOperationException( "Value removal not supported for immutable
attribute" );
+    }
+
+
+    public void add( int ix, Object attrVal )
+    {
+        throw new UnsupportedOperationException( "Value addition not supported for immutable
attribute" );
+    }
+
+
+    public Object set( int ix, Object attrVal )
+    {
+        throw new UnsupportedOperationException( "Value alteration is not supported for immutable
attribute" );
+    }
+}

Added: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/util/ImmutableAttributesWrapper.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/util/ImmutableAttributesWrapper.java?rev=601651&view=auto
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/util/ImmutableAttributesWrapper.java
(added)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/util/ImmutableAttributesWrapper.java
Thu Dec  6 00:11:16 2007
@@ -0,0 +1,140 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.directory.shared.ldap.util;
+
+
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+
+
+/**
+ * Document me!
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ImmutableAttributesWrapper implements Attributes
+{
+    private final Attributes wrapped;
+
+
+    public ImmutableAttributesWrapper( Attributes wrapped )
+    {
+        this.wrapped = wrapped;
+    }
+
+
+    public boolean isCaseIgnored()
+    {
+        return wrapped.isCaseIgnored();
+    }
+
+
+    public int size()
+    {
+        return wrapped.size();
+    }
+
+
+    public Attribute get( String attrID )
+    {
+        return new ImmutableAttributeWrapper( wrapped.get( attrID ) );
+    }
+
+
+    public NamingEnumeration<? extends Attribute> getAll()
+    {
+        return new ImmutableEnumeration( wrapped.getAll() );
+    }
+
+
+    public NamingEnumeration<String> getIDs()
+    {
+        return wrapped.getIDs();
+    }
+
+
+    public Attribute put( String attrID, Object val )
+    {
+        throw new UnsupportedOperationException( "Putting attributes not supported by immutable
attributes" );
+    }
+
+
+    public Attribute put( Attribute attr )
+    {
+        throw new UnsupportedOperationException( "Putting attributes not supported by immutable
attributes" );
+    }
+
+
+    public Attribute remove( String attrID )
+    {
+        throw new UnsupportedOperationException( "Removing attributes not supported by immutable
attributes" );
+    }
+
+
+    @SuppressWarnings ( { "CloneDoesntCallSuperClone" } )
+    public Object clone()
+    {
+        throw new IllegalStateException( "Now why would you want to clone() an immutable
object in the first place." );
+    }
+
+
+    class ImmutableEnumeration implements NamingEnumeration
+    {
+        private NamingEnumeration wrappedEnum;
+
+
+        public ImmutableEnumeration( NamingEnumeration<? extends Attribute> all )
+        {
+            wrappedEnum = all;
+        }
+
+
+        public Attribute next() throws NamingException
+        {
+            return new ImmutableAttributeWrapper( ( Attribute ) wrappedEnum.next() );
+        }
+
+
+        public boolean hasMore() throws NamingException
+        {
+            return wrappedEnum.hasMore();
+        }
+
+
+        public void close() throws NamingException
+        {
+            wrappedEnum.close();
+        }
+
+
+        public boolean hasMoreElements()
+        {
+            return wrappedEnum.hasMoreElements();
+        }
+
+
+        public Attribute nextElement()
+        {
+            return new ImmutableAttributeWrapper( ( Attribute ) wrappedEnum.nextElement()
);
+        }
+    }
+}



Mime
View raw message