FELIX-3884 : Default value and options 

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1519567 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/metatype/changelog.txt b/metatype/changelog.txt
index 2537eb6..6388583 100644
--- a/metatype/changelog.txt
+++ b/metatype/changelog.txt
@@ -6,6 +6,7 @@
     * [FELIX-3757] - If an AttributeDefinition did not specify a minimum, maximum or option values, it did not detect missing values;
     * [FELIX-3758] - AttributeDefinition.validate() did not take non-zero cardinality into consideration.
     * [FELIX-4214] - Cache in BundleResources works only for a single metatype properties file per bundle
+    * [FELIX-3884] - Default value and options 
 
 
 Changes from 1.0.4 to 1.0.6
diff --git a/metatype/src/main/java/org/apache/felix/metatype/AD.java b/metatype/src/main/java/org/apache/felix/metatype/AD.java
index f2456f2..6d08ece 100644
--- a/metatype/src/main/java/org/apache/felix/metatype/AD.java
+++ b/metatype/src/main/java/org/apache/felix/metatype/AD.java
@@ -145,7 +145,7 @@
      *        can be <code>null</code>.
      *
      * @return <code>null</code> if no validation is performed, <tt>""</tt> if
-     *         the value is accepted as valid, or a non-empty string 
+     *         the value is accepted as valid, or a non-empty string
      *         indicating a validation problem was found.
      *
      * @see ADValidator#validate(AD, String)
@@ -223,7 +223,7 @@
      */
     public void setDefaultValue(String defaultValue)
     {
-        this.defaultValue = splitList(defaultValue);
+        this.setDefaultValue( splitList(defaultValue) );
     }
 
     /**
@@ -243,11 +243,44 @@
     }
 
     /**
-     * @param defaultValue the defaultValue to set
+     * @param values the defaultValue to set
      */
-    public void setDefaultValue(String[] defaultValue)
+    public void setDefaultValue(String[] values)
     {
-        this.defaultValue = (String[]) defaultValue.clone();
+        if ( values != null )
+        {
+            int count = 0;
+            for(int i=0; i<values.length; i++)
+            {
+                if ( "".equals(ADValidator.validate(this, values[i])) )
+                {
+                    count++;
+                }
+                else
+                {
+                    values[i] = null;
+                }
+            }
+            if ( count == 0 )
+            {
+                values = null;
+            }
+            else if ( count != values.length )
+            {
+                String[] filterValues = new String[count];
+                int index = 0;
+                for(int i=0; i<values.length; i++)
+                {
+                    if ( values[i] != null )
+                    {
+                        filterValues[index] = values[i];
+                        index++;
+                    }
+                }
+                values = filterValues;
+            }
+        }
+        this.defaultValue = values;
     }
 
     /**
diff --git a/metatype/src/main/java/org/apache/felix/metatype/MetaDataReader.java b/metatype/src/main/java/org/apache/felix/metatype/MetaDataReader.java
index 33c3271..5f9c7a9 100644
--- a/metatype/src/main/java/org/apache/felix/metatype/MetaDataReader.java
+++ b/metatype/src/main/java/org/apache/felix/metatype/MetaDataReader.java
@@ -419,6 +419,11 @@
 
         ad.setOptions( options );
 
+        // reset value to force an options check (FELIX-3884)
+        if ( ad.getDefaultValue() != null )
+        {
+            ad.setDefaultValue( ad.getDefaultValue() );
+        }
         return ad;
     }