felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1079719 - in /felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin: SCRDescriptorGenerator.java om/Reference.java
Date Wed, 09 Mar 2011 10:02:47 GMT
Author: cziegeler
Date: Wed Mar  9 10:02:47 2011
New Revision: 1079719

URL: http://svn.apache.org/viewvc?rev=1079719&view=rev
Log:
FELIX-2876 : <reference> element not generated when name is missing

Modified:
    felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/SCRDescriptorGenerator.java
    felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Reference.java

Modified: felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/SCRDescriptorGenerator.java
URL: http://svn.apache.org/viewvc/felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/SCRDescriptorGenerator.java?rev=1079719&r1=1079718&r2=1079719&view=diff
==============================================================================
--- felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/SCRDescriptorGenerator.java
(original)
+++ felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/SCRDescriptorGenerator.java
Wed Mar  9 10:02:47 2011
@@ -525,7 +525,7 @@ public class SCRDescriptorGenerator
             final String refName = entry.getKey();
             final Object[] values = entry.getValue();
             final JavaTag tag = ( JavaTag ) values[0];
-            this.doReference( tag, refName, component, values[1].toString() );
+            this.doReference( tag, refName, component, values[1].toString(), ((Boolean)values[2]).booleanValue()
);
         }
 
         // pid handling
@@ -763,7 +763,13 @@ public class SCRDescriptorGenerator
     protected void testReference( Map<String, Object[]> references, JavaTag reference,
String defaultName,
         boolean isInspectedClass ) throws SCRDescriptorException
     {
-        final String refName = this.getReferenceName( reference, defaultName );
+        String refName = this.getReferenceName( reference, defaultName );
+
+        boolean setName = refName != null;
+        if ( refName == null)
+        {
+            refName = this.getReferencedInterface(reference, isInspectedClass, null);
+        }
 
         if ( refName != null )
         {
@@ -780,41 +786,54 @@ public class SCRDescriptorGenerator
             else
             {
                 // ensure interface
-                String type = reference.getNamedParameter( Constants.REFERENCE_INTERFACE
);
-                if ( StringUtils.isEmpty( type ) )
-                {
-                    if ( reference.getField() != null )
-                    {
-                        type = reference.getField().getType();
-                    }
-                    else
-                    {
-                        throw new SCRDescriptorException( "Interface missing for reference
" + refName + " in class "
-                            + reference.getJavaClassDescription().getName(), reference );
-                    }
-                }
-                else if ( isInspectedClass )
-                {
-                    // check if the value points to a class/interface
-                    // and search through the imports
-                    final JavaClassDescription serviceClass = reference.getJavaClassDescription().getReferencedClass(
-                        type );
-                    if ( serviceClass == null )
-                    {
-                        throw new SCRDescriptorException( "Interface '" + type + "' in class
"
-                            + reference.getJavaClassDescription().getName()
-                            + " does not point to a valid class/interface.", reference );
-                    }
-                    type = serviceClass.getName();
-                }
+                final String type = this.getReferencedInterface(reference, isInspectedClass,
refName);
                 references.put( refName, new Object[]
-                    { reference, type } );
+                    { reference, type, (setName ? Boolean.TRUE : Boolean.FALSE) } );
             }
         }
+        else
+        {
+            throw new SCRDescriptorException( "No name detectable for reference in class
"
+                    + reference.getJavaClassDescription().getName(), reference );
+        }
     }
 
+    protected String getReferencedInterface(final JavaTag reference,
+                                            final boolean isInspectedClass,
+                                            final String refName) throws SCRDescriptorException
+    {
+        String type = reference.getNamedParameter( Constants.REFERENCE_INTERFACE );
+        if ( StringUtils.isEmpty( type ) )
+        {
+            if ( reference.getField() != null )
+            {
+                type = reference.getField().getType();
+            }
+            else
+            {
+                throw new SCRDescriptorException( "Interface missing for reference " + (refName
== null ? "" : refName) + " in class "
+                    + reference.getJavaClassDescription().getName(), reference );
+            }
+        }
+        else if ( isInspectedClass )
+        {
+            // check if the value points to a class/interface
+            // and search through the imports
+            final JavaClassDescription serviceClass = reference.getJavaClassDescription().getReferencedClass(
+                type );
+            if ( serviceClass == null )
+            {
+                throw new SCRDescriptorException( "Interface '" + type + "' in class "
+                    + reference.getJavaClassDescription().getName()
+                    + " does not point to a valid class/interface.", reference );
+            }
+            type = serviceClass.getName();
+        }
+        return type;
+    }
 
-    protected String getReferenceName( JavaTag reference, String defaultName ) throws SCRDescriptorException
+    protected String getReferenceName( final JavaTag reference,
+            final String defaultName) throws SCRDescriptorException
     {
         String name = reference.getNamedParameter( Constants.REFERENCE_NAME );
         if ( !StringUtils.isEmpty( name ) )
@@ -836,7 +855,7 @@ public class SCRDescriptorGenerator
                 throw new SCRDescriptorException( "Referenced field " + name
                     + " has more than one value for a reference name.", reference );
             }
-            name = values[0];
+            return values[0];
         }
 
         return defaultName;
@@ -866,15 +885,20 @@ public class SCRDescriptorGenerator
 
 
     /**
+     * Process a reference
      * @param reference
      * @param defaultName
      * @param component
      */
-    protected void doReference( JavaTag reference, String name, Component component, String
type )
+    protected void doReference( JavaTag reference, String name, Component component, String
type,
+            final boolean setName)
         throws SCRDescriptorException
     {
         final Reference ref = new Reference( reference, component.getJavaClassDescription()
);
-        ref.setName( name );
+        if ( setName )
+        {
+            ref.setName( name );
+        }
         ref.setInterfacename( type );
         ref.setCardinality( reference.getNamedParameter( Constants.REFERENCE_CARDINALITY
) );
         if ( ref.getCardinality() == null )

Modified: felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Reference.java
URL: http://svn.apache.org/viewvc/felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Reference.java?rev=1079719&r1=1079718&r2=1079719&view=diff
==============================================================================
--- felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Reference.java
(original)
+++ felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Reference.java
Wed Mar  9 10:02:47 2011
@@ -22,9 +22,7 @@ import org.apache.felix.scrplugin.Consta
 import org.apache.felix.scrplugin.SCRDescriptorException;
 import org.apache.felix.scrplugin.helper.IssueLog;
 import org.apache.felix.scrplugin.helper.StringUtils;
-import org.apache.felix.scrplugin.tags.JavaClassDescription;
-import org.apache.felix.scrplugin.tags.JavaMethod;
-import org.apache.felix.scrplugin.tags.JavaTag;
+import org.apache.felix.scrplugin.tags.*;
 
 /**
  * <code>Reference.java</code>...
@@ -169,7 +167,9 @@ public class Reference extends AbstractO
 
         // validate name
         if (StringUtils.isEmpty(this.name)) {
-            this.logError( iLog, "Reference has no name" );
+            if ( specVersion < Constants.VERSION_1_1 ) {
+                this.logError( iLog, "Reference has no name" );
+            }
         }
 
         // validate interface



Mime
View raw message