cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1495117 - in /cxf/trunk: api/src/main/java/org/apache/cxf/annotations/EndpointProperty.java rt/core/src/main/java/org/apache/cxf/service/factory/AnnotationsFactoryBeanListener.java
Date Thu, 20 Jun 2013 18:10:47 GMT
Author: dkulp
Date: Thu Jun 20 18:10:47 2013
New Revision: 1495117

URL: http://svn.apache.org/r1495117
Log:
Update EndpointProperty annotation to allow grabbing a bean by ref or creating one

Modified:
    cxf/trunk/api/src/main/java/org/apache/cxf/annotations/EndpointProperty.java
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/factory/AnnotationsFactoryBeanListener.java

Modified: cxf/trunk/api/src/main/java/org/apache/cxf/annotations/EndpointProperty.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/annotations/EndpointProperty.java?rev=1495117&r1=1495116&r2=1495117&view=diff
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/annotations/EndpointProperty.java (original)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/annotations/EndpointProperty.java Thu Jun 20
18:10:47 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/trunk/rt/core/src/main/java/org/apache/cxf/service/factory/AnnotationsFactoryBeanListener.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/factory/AnnotationsFactoryBeanListener.java?rev=1495117&r1=1495116&r2=1495117&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/factory/AnnotationsFactoryBeanListener.java
(original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/factory/AnnotationsFactoryBeanListener.java
Thu Jun 20 18:10:47 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) { 



Mime
View raw message