felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r741601 - /felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/ComponentMetadata.java
Date Fri, 06 Feb 2009 15:54:34 GMT
Author: fmeschbe
Date: Fri Feb  6 15:54:34 2009
New Revision: 741601

URL: http://svn.apache.org/viewvc?rev=741601&view=rev
Log:
Prevent multiple validations (unneeded work) and ensure dependencies may not be added after
validation

Modified:
    felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/ComponentMetadata.java

Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/ComponentMetadata.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/ComponentMetadata.java?rev=741601&r1=741600&r2=741601&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/ComponentMetadata.java (original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/ComponentMetadata.java Fri Feb
 6 15:54:34 2009
@@ -21,6 +21,7 @@
 import java.util.ArrayList;
 import java.util.Dictionary;
 import java.util.Hashtable;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 
@@ -159,6 +160,9 @@
      * @param newReference a new ReferenceMetadata to be added
      */
     public void addDependency(ReferenceMetadata newReference) {
+        if(m_validated) {
+            return;
+        }
     	if(newReference == null) {
     		throw new IllegalArgumentException ("Cannot add a null ReferenceMetadata");
     	}
@@ -267,7 +271,11 @@
      */
     void validate()
     {
-
+        // nothing to do if already validated
+        if (m_validated) {
+            return;
+        }
+        
         // 112.10 The name of the component is required
         if ( m_name == null )
         {
@@ -297,10 +305,18 @@
         }
 
         // Check that the references are ok
+        HashSet refs = new HashSet();
         Iterator referenceIterator = m_references.iterator();
         while ( referenceIterator.hasNext() )
         {
-            ( ( ReferenceMetadata ) referenceIterator.next() ).validate( this );
+            ReferenceMetadata refMeta = ( ReferenceMetadata ) referenceIterator.next();
+            refMeta.validate( this );
+            
+            // flag duplicates
+            if ( !refs.add( refMeta.getName() ) )
+            {
+                throw validationFailure( "Detected duplicate reference name: \"" + refMeta.getName()
+ "\"" );
+            }
         }
 
         // verify value of immediate attribute if set



Mime
View raw message