Return-Path: X-Original-To: apmail-cxf-commits-archive@www.apache.org Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E2A66101A5 for ; Thu, 20 Jun 2013 18:11:11 +0000 (UTC) Received: (qmail 86079 invoked by uid 500); 20 Jun 2013 18:11:11 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 86039 invoked by uid 500); 20 Jun 2013 18:11:11 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 86026 invoked by uid 99); 20 Jun 2013 18:11:11 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 20 Jun 2013 18:11:11 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 20 Jun 2013 18:11:07 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id DB7542388AB9; Thu, 20 Jun 2013 18:10:47 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@cxf.apache.org From: dkulp@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130620181047.DB7542388AB9@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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) {