FELIX-824 Applied slightly modified patch by Thijs Metsch (Thanks)
Modifications are some minor reformatting, slight change in how the
Reference object field is set from the tag and ensuring the field is
written to the private descriptor file required for extensibility 

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@721146 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/Constants.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/Constants.java
index 92bf0a0..f6dcdf8 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/Constants.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/Constants.java
@@ -100,6 +100,9 @@
     public static final String REFERENCE_UNDBIND = "unbind";
 
     public static final String REFERENCE_CHECKED = "checked";
+    
+    /** @since 1.0.10 */
+    public static final String REFERENCE_STRATEGY = "strategy";
 
     public static final String ABSTRACT_DESCRIPTOR_FILENAME = "scrinfo.xml";
 
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/SCRDescriptorMojo.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/SCRDescriptorMojo.java
index 3907392..6df4f9b 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/SCRDescriptorMojo.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/SCRDescriptorMojo.java
@@ -570,10 +570,15 @@
         if ( isChecked != null ) {
             ref.setChecked(Boolean.valueOf(isChecked).booleanValue());
         }
+        final String strategy = reference.getNamedParameter(Constants.REFERENCE_STRATEGY);
+        if ( strategy != null ) {
+            ref.setStrategy(strategy);
+        }
+        
         // if this is a field with a single cardinality,
         // we look for the bind/unbind methods
         // and create them if they are not availabe
-        if ( this.generateAccessors ) {
+        if ( this.generateAccessors && !ref.isLookupStrategy() ) {
             if ( reference.getField() != null && component.getJavaClassDescription() instanceof ModifiableJavaClassDescription ) {
                 if ( ref.getCardinality().equals("0..1") || ref.getCardinality().equals("1..1") ) {
                     boolean createBind = false;
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Reference.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Reference.java
index 1dbbb9d..ab458e4 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Reference.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Reference.java
@@ -37,6 +37,9 @@
     protected String policy;
     protected String bind;
     protected String unbind;
+    
+    /** @since 1.0.10 */
+    protected String strategy;
 
     /** Is this reference already checked? */
     protected boolean checked = false;
@@ -125,6 +128,21 @@
     public void setChecked(boolean checked) {
         this.checked = checked;
     }
+    
+    /** @since 1.0.10 */
+    public String getStrategy() {
+        return strategy;
+    }
+
+    /** @since 1.0.10 */
+    public void setStrategy(String strategy) {
+        this.strategy = strategy;
+    }
+    
+    /** @since 1.0.10 */
+    public boolean isLookupStrategy() {
+        return "lookup".equals(getStrategy());
+    }
 
     /**
      * Validate the property.
@@ -163,24 +181,36 @@
         } else if (!"static".equals(this.policy) && !"dynamic".equals(this.policy)) {
             issues.add(this.getMessage("Invalid Policy specification " + this.policy));
         }
+        
+        // validate strategy
+        if (this.strategy == null) {
+            this.strategy = "event";
+        } else if (!"event".equals(this.strategy) && !"lookup".equals(this.strategy)) {
+            issues.add(this.getMessage("Invalid startegy type " + this.strategy));
+        }
 
         // validate bind and unbind methods
-        final String oldBind = this.bind;
-        final String oldUnbind = this.unbind;
-        this.bind = this.validateMethod(this.bind, issues, warnings, componentIsAbstract);
-        this.unbind = this.validateMethod(this.unbind, issues, warnings, componentIsAbstract);
-        if ( issues.size() == currentIssueCount ) {
-            if ( this.bind != null && this.unbind != null ) {
-                // no errors, so we're checked
-                this.checked = true;
-            } else {
-                if ( this.bind == null ) {
-                    this.bind = oldBind;
-                }
-                if ( this.unbind == null ) {
-                    this.unbind = oldUnbind;
+        if (!isLookupStrategy()) {
+            final String oldBind = this.bind;
+            final String oldUnbind = this.unbind;
+            this.bind = this.validateMethod(this.bind, issues, warnings, componentIsAbstract);
+            this.unbind = this.validateMethod(this.unbind, issues, warnings, componentIsAbstract);
+            if ( issues.size() == currentIssueCount ) {
+                if ( this.bind != null && this.unbind != null ) {
+                    // no errors, so we're checked
+                    this.checked = true;
+                } else {
+                    if ( this.bind == null ) {
+                        this.bind = oldBind;
+                    }
+                    if ( this.unbind == null ) {
+                        this.unbind = oldUnbind;
+                    }
                 }
             }
+        } else {
+            this.bind = null;
+            this.unbind = null;
         }
     }
 
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/cl/ClassLoaderJavaTag.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/cl/ClassLoaderJavaTag.java
index 17f5dc9..8980aeb 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/cl/ClassLoaderJavaTag.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/cl/ClassLoaderJavaTag.java
@@ -113,6 +113,7 @@
             map.put(Constants.REFERENCE_TARGET, this.reference.getTarget());
             map.put(Constants.REFERENCE_UNDBIND, this.reference.getUnbind());
             map.put(Constants.REFERENCE_CHECKED, String.valueOf(this.reference.isChecked()));
+            map.put(Constants.REFERENCE_STRATEGY, this.reference.getStrategy());
             return map;
         } else if ( this.property != null ) {
             final Map map = new HashMap();
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/xml/ComponentDescriptorIO.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/xml/ComponentDescriptorIO.java
index c75dcff..9b0ecab 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/xml/ComponentDescriptorIO.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/xml/ComponentDescriptorIO.java
@@ -283,10 +283,14 @@
         IOUtils.addAttribute(ai, "cardinality", reference.getCardinality());
         IOUtils.addAttribute(ai, "policy", reference.getPolicy());
         IOUtils.addAttribute(ai, "target", reference.getTarget());
-        IOUtils.addAttribute(ai, "bind", reference.getBind());
-        IOUtils.addAttribute(ai, "unbind", reference.getUnbind());
+        
+        if (!reference.isLookupStrategy()) {
+            IOUtils.addAttribute(ai, "bind", reference.getBind());
+            IOUtils.addAttribute(ai, "unbind", reference.getUnbind());
+        }
         if ( isScrPrivateFile ) {
             IOUtils.addAttribute(ai, "checked", String.valueOf(reference.isChecked()));
+            IOUtils.addAttribute(ai, "strategy", reference.getStrategy());
         }
         IOUtils.indent(contentHandler, 2);
         contentHandler.startElement(INNER_NAMESPACE_URI, ComponentDescriptorIO.REFERENCE, ComponentDescriptorIO.REFERENCE_QNAME, ai);
@@ -420,6 +424,7 @@
                     ref.setTarget(attributes.getValue("target"));
                     ref.setBind(attributes.getValue("bind"));
                     ref.setUnbind(attributes.getValue("unbind"));
+                    ref.setStrategy(attributes.getValue("strategy"));
 
                     if ( attributes.getValue("checked") != null ) {
                         ref.setChecked(Boolean.valueOf(attributes.getValue("checked")).booleanValue());