You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2013/06/20 20:16:51 UTC

svn commit: r1495121 - in /cxf/branches/2.7.x-fixes: api/src/main/java/org/apache/cxf/annotations/EndpointProperty.java rt/core/src/main/java/org/apache/cxf/service/factory/AnnotationsFactoryBeanListener.java

Author: dkulp
Date: Thu Jun 20 18:16:51 2013
New Revision: 1495121

URL: http://svn.apache.org/r1495121
Log:
Merged revisions 1495117 via  git cherry-pick from
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1495117 | dkulp | 2013-06-20 14:10:47 -0400 (Thu, 20 Jun 2013) | 2 lines

  Update EndpointProperty annotation to allow grabbing a bean by ref or creating one

........

Modified:
    cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/annotations/EndpointProperty.java
    cxf/branches/2.7.x-fixes/rt/core/src/main/java/org/apache/cxf/service/factory/AnnotationsFactoryBeanListener.java

Modified: cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/annotations/EndpointProperty.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/annotations/EndpointProperty.java?rev=1495121&r1=1495120&r2=1495121&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/annotations/EndpointProperty.java (original)
+++ cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/annotations/EndpointProperty.java Thu Jun 20 18:16:51 2013
@@ -37,12 +37,33 @@ public @interface EndpointProperty {
      * The value(s) of the property
      * @return the value of the property
      */
-    String[] value();
+    String[] value() default { };
     
     /**
      * The key to record the property
      * @return the key for the property
      */
     String key();
+    
+    /**
+     * Reference to a named bean that is looked up from the
+     * configuration associated with the application. 
+     */
+    String ref() default "";
+    
+    /**
+     * The class for the property. If "ref" is specified,
+     * this class is used to cast the looked up reference
+     * to make sure the Object is of the correct type. 
+     * 
+     * If ref is not set and value is not set, this class
+     * is used to create a bean. The class must have either 
+     * a default constructor, a constructor that takes an
+     * org.apache.cxf.endpoint.Endpoint, or a constructor
+     * that takes a org.apache.cxf.endpoint.Endpoint and 
+     * an org.apache.cxf.Bus.
+     */
+    Class<?> beanClass() default Object.class;
+
 }
 

Modified: cxf/branches/2.7.x-fixes/rt/core/src/main/java/org/apache/cxf/service/factory/AnnotationsFactoryBeanListener.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/core/src/main/java/org/apache/cxf/service/factory/AnnotationsFactoryBeanListener.java?rev=1495121&r1=1495120&r2=1495121&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/core/src/main/java/org/apache/cxf/service/factory/AnnotationsFactoryBeanListener.java (original)
+++ cxf/branches/2.7.x-fixes/rt/core/src/main/java/org/apache/cxf/service/factory/AnnotationsFactoryBeanListener.java Thu Jun 20 18:16:51 2013
@@ -37,6 +37,7 @@ import org.apache.cxf.annotations.WSDLDo
 import org.apache.cxf.annotations.WSDLDocumentation.Placement;
 import org.apache.cxf.annotations.WSDLDocumentationCollection;
 import org.apache.cxf.common.util.StringUtils;
+import org.apache.cxf.configuration.ConfiguredBeanLocator;
 import org.apache.cxf.endpoint.Endpoint;
 import org.apache.cxf.endpoint.Server;
 import org.apache.cxf.feature.LoggingFeature;
@@ -216,16 +217,40 @@ public class AnnotationsFactoryBeanListe
             if (prop == null) {
                 continue;
             }
+            String ref = prop.ref();
+            Class<?> cls = prop.beanClass();
+            Object obj = null;
             String s[] = prop.value();
-            if (s.length == 1) {
-                ep.getEndpointInfo().setProperty(prop.key(), s[0]);
+            if (!StringUtils.isEmpty(ref)) {
+                obj = bus.getExtension(ConfiguredBeanLocator.class).getBeanOfType(ref, cls);
+            } else if (s.length == 0 && cls != Object.class) {
+                obj = createObject(cls, ep, bus);
+            } else if (s.length == 1) {
+                obj = s[0];
             } else {
-                ep.getEndpointInfo().setProperty(prop.key(), s);                
+                obj = s;
             }
+            ep.getEndpointInfo().setProperty(prop.key(), obj);                
         }
         
     }
 
+    private Object createObject(Class<?> cls, Endpoint ep, Bus bus) {
+        try {
+            try {
+                return cls.getConstructor(Endpoint.class, Bus.class).newInstance(ep, bus);
+            } catch (NoSuchMethodException e) {
+                try {
+                    return cls.getConstructor(Endpoint.class).newInstance(ep);
+                } catch (NoSuchMethodException e2) {
+                    return cls.newInstance();
+                }                
+            }
+        } catch (Exception ex) {
+            throw new ServiceConstructionException(ex);
+        }
+    }
+
     private void setDataBinding(AbstractServiceFactoryBean factory,
                                 DataBinding annotation) {
         if (annotation != null && factory.getDataBinding(false) == null) {