directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r604509 - in /directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry: BinaryValue.java EntryAttribute.java StringValue.java
Date Sat, 15 Dec 2007 20:36:26 GMT
Author: elecharny
Date: Sat Dec 15 12:36:26 2007
New Revision: 604509

URL: http://svn.apache.org/viewvc?rev=604509&view=rev
Log:
Added some helper methods in the Value classes
Added some varargs in EntryAttribute methods

Modified:
    directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/BinaryValue.java
    directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/EntryAttribute.java
    directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/StringValue.java

Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/BinaryValue.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/BinaryValue.java?rev=604509&r1=604508&r2=604509&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/BinaryValue.java
(original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/BinaryValue.java
Sat Dec 15 12:36:26 2007
@@ -20,11 +20,16 @@
 package org.apache.directory.shared.ldap.entry;
 
 
+import org.apache.directory.shared.ldap.schema.AttributeType;
 import org.apache.directory.shared.ldap.schema.ByteArrayComparator;
 import org.apache.directory.shared.ldap.util.StringTools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import java.util.Arrays;
 
+import javax.naming.NamingException;
+
 
 /**
  * A wrapper around byte[] values in entries.
@@ -34,10 +39,54 @@
  */
 public class BinaryValue implements Value<byte[]>
 {
+    /** logger for reporting errors that might not be handled properly upstream */
+    private static final Logger LOG = LoggerFactory.getLogger( BinaryValue.class );
+
+    
     /** the wrapped binary value */
     private byte[] wrapped;
 
 
+    // -----------------------------------------------------------------------
+    // utility methods
+    // -----------------------------------------------------------------------
+    /**
+     * Utility method to get some logs if an assert fails
+     */
+    protected String logAssert( String message )
+    {
+        LOG.error(  message );
+        return message;
+    }
+
+    
+    /**
+     *  Check the attributeType member. It should not be null, 
+     *  and it should contains a syntax.
+     */
+    protected String checkAttributeType( AttributeType attributeType )
+    {
+        try
+        {
+            if ( attributeType == null )
+            {
+                return "The AttributeType parameter should not be null";
+            }
+            
+            if ( attributeType.getSyntax() == null )
+            {
+                return "There is no Syntax associated with this attributeType";
+            }
+
+            return null;
+        }
+        catch ( NamingException ne )
+        {
+            return "This AttributeType is incorrect";
+        }
+    }
+
+    
     /**
      * Creates a new instance of BinaryValue with no initial wrapped value.
      */

Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/EntryAttribute.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/EntryAttribute.java?rev=604509&r1=604508&r2=604509&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/EntryAttribute.java
(original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/EntryAttribute.java
Sat Dec 15 12:36:26 2007
@@ -20,6 +20,9 @@
 
 import java.util.Iterator;
 
+import javax.naming.NamingException;
+import javax.naming.directory.InvalidAttributeValueException;
+
 
 /**
  * A generic interface mocking the Attribute JNDI interface. This interface
@@ -42,8 +45,26 @@
      *
      * @param val a new value to be added which may be null
      * @return true if a value was added, otherwise false
+     * 
+     * @exception InvalidAttributeValueException if the added value is not valid
      */
-    boolean add( String val );
+    boolean add( String val ) throws InvalidAttributeValueException, NamingException;
+
+
+    /**
+     * Adds some values to this attribute. If the new values are already present in
+     * the attribute values, the method has no effect.
+     * <p>
+     * The new values are added at the end of list of values.
+     * </p>
+     * <p>
+     * This method returns the number of values that were added.
+     * </p>
+     *
+     * @param val some new values to be added which may be null
+     * @return the number of added values, or 0 if none has been added
+     */
+    int add( String... vals ) throws InvalidAttributeValueException, NamingException;
 
 
     /**
@@ -59,7 +80,23 @@
      * @param val a new value to be added which may be null
      * @return true if a value was added, otherwise false
      */
-    boolean add( byte[] val );
+    boolean add( byte[] val ) throws InvalidAttributeValueException, NamingException;
+
+
+    /**
+     * Adds some values to this attribute. If the new values are already present in
+     * the attribute values, the method has no effect.
+     * <p>
+     * The new values are added at the end of list of values.
+     * </p>
+     * <p>
+     * This method returns the number of values that were added.
+     * </p>
+     *
+     * @param val some new values to be added which may be null
+     * @return the number of added values, or 0 if none has been added
+     */
+    int add( byte[]... vals ) throws InvalidAttributeValueException, NamingException;
 
 
     /**
@@ -78,6 +115,15 @@
 
 
     /**
+     * Indicates whether the specified values are some of the attribute's values.
+     *
+     * @param vals the values
+     * @return true if this attribute contains all the values, otherwise false
+     */
+    boolean contains( String... vals );
+
+
+    /**
      * Indicates whether the specified value is one of the attribute's values.
      *
      * @param val the value which may be null
@@ -86,6 +132,15 @@
     boolean contains( byte[] val );
 
 
+    /**
+     * Indicates whether the specified values are some of the attribute's values.
+     *
+     * @param vals the values
+     * @return true if this attribute contains all the values, otherwise false
+     */
+    boolean contains( byte[]... vals );
+
+
    /**
       * Retrieves the number of values in this attribute.
       *
@@ -109,6 +164,19 @@
 
 
     /**
+     * Removes all the  values that are equal to the given values.
+     * <p>
+     * Returns true if a value is removed. If there is no value equal to <code>
+     * val</code> this method simply returns false.
+     * </p>
+     *
+     * @param vals the values to be removed
+     * @return true if all the values are removed, otherwise false
+     */
+    boolean remove( byte[]... val );
+
+
+    /**
      * Removes a value that is equal to the given value.
      * <p>
      * Returns true if a value is removed. If there is no value equal to <code>
@@ -122,6 +190,19 @@
     
     
     /**
+     * Removes all the  values that are equal to the given values.
+     * <p>
+     * Returns true if a value is removed. If there is no value equal to <code>
+     * val</code> this method simply returns false.
+     * </p>
+     *
+     * @param vals the values to be removed
+     * @return true if all the values are removed, otherwise false
+     */
+    boolean remove( String... vals );
+    
+    
+    /**
      * Gets the first value of this attribute. <code>null</code> is a valid value.
      *
      * <p>
@@ -163,6 +244,19 @@
 
 
     /**
+     * Removes all the  values that are equal to the given values.
+     * <p>
+     * Returns true if a value is removed. If there is no value equal to <code>
+     * val</code> this method simply returns false.
+     * </p>
+     *
+     * @param vals the values to be removed
+     * @return true if all the values are removed, otherwise false
+     */
+    boolean remove( T... vals );
+
+    
+    /**
      * Indicates whether the specified value is one of the attribute's values.
      *
      * @param val the value which may be null
@@ -172,6 +266,15 @@
 
 
     /**
+     * Indicates whether the specified values are some of the attribute's values.
+     *
+     * @param vals the values
+     * @return true if this attribute contains all the values, otherwise false
+     */
+    boolean contains( T... vals );
+
+    
+    /**
      * Adds a value to this attribute. If the new value is already present in
      * the attribute values, the method has no effect.
      * <p>
@@ -184,5 +287,21 @@
      * @param val a new value to be added which may be null
      * @return true if a value was added, otherwise false
      */
-    boolean add( T val );
+    boolean add( T val ) throws InvalidAttributeValueException, NamingException;
+    
+    
+    /**
+     * Adds some values to this attribute. If the new values are already present in
+     * the attribute values, the method has no effect.
+     * <p>
+     * The new values are added at the end of list of values.
+     * </p>
+     * <p>
+     * This method returns the number of values that were added.
+     * </p>
+     *
+     * @param val some new values to be added which may be null
+     * @return the number of added values, or 0 if none has been added
+     */
+    int add( T... val ) throws InvalidAttributeValueException, NamingException;
 }

Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/StringValue.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/StringValue.java?rev=604509&r1=604508&r2=604509&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/StringValue.java
(original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/StringValue.java
Sat Dec 15 12:36:26 2007
@@ -19,19 +19,68 @@
  */
 package org.apache.directory.shared.ldap.entry;
 
+import javax.naming.NamingException;
+
+import org.apache.directory.shared.ldap.schema.AttributeType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 
 /**
- * A warpper around an EntryAttribute's String value.
+ * A wrapper around an EntryAttribute's String value.
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
 public class StringValue implements Value<String>
 {
+    /** logger for reporting errors that might not be handled properly upstream */
+    private static final Logger LOG = LoggerFactory.getLogger( StringValue.class );
+
     /** the wrapped string value */
     private String wrapped;
 
 
+    // -----------------------------------------------------------------------
+    // utility methods
+    // -----------------------------------------------------------------------
+    /**
+     * Utility method to get some logs if an assert fails
+     */
+    protected String logAssert( String message )
+    {
+        LOG.error(  message );
+        return message;
+    }
+
+    
+    /**
+     *  Check the attributeType member. It should not be null, 
+     *  and it should contains a syntax.
+     */
+    protected String checkAttributeType( AttributeType attributeType )
+    {
+        try
+        {
+            if ( attributeType == null )
+            {
+                return "The AttributeType parameter should not be null";
+            }
+            
+            if ( attributeType.getSyntax() == null )
+            {
+                return "There is no Syntax associated with this attributeType";
+            }
+
+            return null;
+        }
+        catch ( NamingException ne )
+        {
+            return "This AttributeType is incorrect";
+        }
+    }
+
+    
     /**
      * Creates a new instance of StringValue with no value.
      */



Mime
View raw message