cxf-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel Kulp <dk...@apache.org>
Subject Re: svn commit: r581781 - in /incubator/cxf/trunk: common/common/src/main/java/org/apache/cxf/common/annotation/ common/common/src/main/java/org/apache/cxf/common/injection/ common/common/src/test/java/org/apache/cxf/common/injection/ rt/frontend/jaxws/ rt...
Date Thu, 04 Oct 2007 10:59:39 GMT


This commit makes using jaxws 100% dependent on having the Spring jars.   
Thus, I'm -1 on this.    The Spring stuff must be localized to the 
spring subpackage and the rest needs to work without spring.

Dan




On Thursday 04 October 2007, ningjiang@apache.org wrote:
> Author: ningjiang
> Date: Wed Oct  3 22:42:29 2007
> New Revision: 581781
>
> URL: http://svn.apache.org/viewvc?rev=581781&view=rev
> Log:
> CXF-1074 using the spring's AOPUtils.getTargetClass() as the resource
> injector target class.
>
> Modified:
>    
> incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/
>annotation/AnnotationProcessor.java
> incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/
>injection/ResourceInjector.java
> incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/common/
>injection/ResourceInjectorTest.java
> incubator/cxf/trunk/rt/frontend/jaxws/pom.xml
>    
> incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jax
>ws/JaxWsServerFactoryBean.java
>
> Modified:
> incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/
>annotation/AnnotationProcessor.java URL:
> http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/mai
>n/java/org/apache/cxf/common/annotation/AnnotationProcessor.java?rev=58
>1781&r1=581780&r2=581781&view=diff
> ======================================================================
>======== ---
> incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/
>annotation/AnnotationProcessor.java (original) +++
> incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/
>annotation/AnnotationProcessor.java Wed Oct  3 22:42:29 2007 @@ -74,9
> +74,9 @@
>       * Visits each of the annotated elements of the object.
>       *
>       * @param visitor a visitor
> -     *
> +     * @param claz the Class of the targe object
>       */
> -    public void accept(AnnotationVisitor visitor) {
> +    public void accept(AnnotationVisitor visitor, Class<?> claz) {
>
>          if (visitor == null) {
>              throw new IllegalArgumentException();
> @@ -85,10 +85,14 @@
>          annotationTypes = visitor.getTargetAnnotations();
>          visitor.setTarget(target);
>          //recursively check annotation in super class
> -        processClass(visitor, target.getClass());
> -        processFields(visitor, target.getClass());
> -        processMethods(visitor, target.getClass());
> +        processClass(visitor, claz);
> +        processFields(visitor, claz);
> +        processMethods(visitor, claz);
>      }
> +
> +    public void accept(AnnotationVisitor visitor) {
> +        accept(visitor, target.getClass());
> +    }
>
>
>      private void processMethods(AnnotationVisitor visitor, Class<?
> extends Object> targetClass) {
>
> Modified:
> incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/
>injection/ResourceInjector.java URL:
> http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/mai
>n/java/org/apache/cxf/common/injection/ResourceInjector.java?rev=581781
>&r1=581780&r2=581781&view=diff
> ======================================================================
>======== ---
> incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/
>injection/ResourceInjector.java (original) +++
> incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/
>injection/ResourceInjector.java Wed Oct  3 22:42:29 2007 @@ -52,6 +52,7
> @@
>      private static final List<Class<? extends Annotation>>
> ANNOTATIONS = new ArrayList<Class<? extends Annotation>>();
>
> +
>      static {
>          ANNOTATIONS.add(Resource.class);
>          ANNOTATIONS.add(Resources.class);
> @@ -71,11 +72,13 @@
>      }
>
>
> -    public void inject(Object o) {
> -
> +    public void inject(Object o) {
> +        inject(o, o.getClass());
> +    }
> +
> +    public void inject(Object o, Class claz) {
>          AnnotationProcessor processor = new AnnotationProcessor(o);
> -        processor.accept(this);
> -
> +        processor.accept(this, claz);
>          invokePostConstruct();
>      }
>
> @@ -377,4 +380,5 @@
>      private Object resolveResource(String resourceName, Class<?>
> type) { return resourceManager.resolveResource(resourceName, type,
> resourceResolvers); }
> +
>  }
>
> Modified:
> incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/common/
>injection/ResourceInjectorTest.java URL:
> http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/tes
>t/java/org/apache/cxf/common/injection/ResourceInjectorTest.java?rev=58
>1781&r1=581780&r2=581781&view=diff
> ======================================================================
>======== ---
> incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/common/
>injection/ResourceInjectorTest.java (original) +++
> incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/common/
>injection/ResourceInjectorTest.java Wed Oct  3 22:42:29 2007 @@ -19,7
> +19,8 @@
>
>  package org.apache.cxf.common.injection;
>
> -
> +import java.lang.reflect.Method;
> +import java.lang.reflect.Modifier;
>
>  import java.util.ArrayList;
>  import java.util.List;
> @@ -29,6 +30,10 @@
>  import javax.annotation.Resource;
>  import javax.annotation.Resources;
>
> +import net.sf.cglib.proxy.Enhancer;
> +import net.sf.cglib.proxy.MethodInterceptor;
> +import net.sf.cglib.proxy.MethodProxy;
> +
>  import org.apache.cxf.resource.ResourceManager;
>  import org.apache.cxf.resource.ResourceResolver;
>
> @@ -64,6 +69,7 @@
>          doInjectTest(new FieldTarget());
>      }
>
> +
>      @Test
>      public void testFieldInSuperClassInjection() {
>         
> setUpResourceManager("org.apache.cxf.common.injection.FieldTarget/");
> @@ -81,6 +87,12 @@
>          setUpResourceManager(SetterTarget.class.getCanonicalName() +
> "/"); doInjectTest(new SetterTarget());
>      }
> +
> +    @Test
> +    public void testProxyInjection() {
> +        setUpResourceManager(FieldTarget.class.getCanonicalName() +
> "/"); +        doInjectTest(getProxyObject());
> +    }
>
>      @Test
>      public void testClassLevelInjection() {
> @@ -111,15 +123,23 @@
>          assertTrue(target.preDestroyCalled());
>      }
>
> -    protected void doInjectTest(Target target) {
> -
> -        injector.inject(target);
> +    protected void doInjectTest(Target target) {
>
> +        injector.inject(target);
>          assertNotNull(target.getResource1());
>          assertEquals(RESOURCE_ONE, target.getResource1());
>
>          assertNotNull(target.getResource2());
> -        assertEquals(RESOURCE_TWO, target.getResource2());
> +        assertEquals(RESOURCE_TWO, target.getResource2());
> +
> +    }
> +
> +
> +    private FieldTarget getProxyObject() {
> +        Enhancer e = new Enhancer();
> +        e.setSuperclass(FieldTarget.class);
> +        e.setCallback(new CallInterceptor());
> +        return (FieldTarget)e.create();
>      }
>
>  }
> @@ -130,6 +150,17 @@
>      String getResource2();
>  }
>
> +class CallInterceptor implements MethodInterceptor {
> +
> +    public Object intercept(Object obj, Method method, Object[] args,
> MethodProxy proxy) throws Throwable { +        Object retValFromSuper
> = null;
> +        if (!Modifier.isAbstract(method.getModifiers())) {
> +            retValFromSuper = proxy.invokeSuper(obj, args);
> +        }
> +        return retValFromSuper;
> +    }
> +}
> +
>
>  class FieldTarget implements Target {
>
> @@ -228,7 +259,8 @@
>  @Resource(name = "resource1")
>  class ClassTarget implements Target {
>
> -    @Resource(name = "resource2") public String resource2foo;
> +    @Resource(name = "resource2")
> +    public String resource2foo;
>      private String res1;
>
>      public final void setResource1(String res) {
>
> Modified: incubator/cxf/trunk/rt/frontend/jaxws/pom.xml
> URL:
> http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/pom
>.xml?rev=581781&r1=581780&r2=581781&view=diff
> ======================================================================
>======== --- incubator/cxf/trunk/rt/frontend/jaxws/pom.xml (original)
> +++ incubator/cxf/trunk/rt/frontend/jaxws/pom.xml Wed Oct  3 22:42:29
> 2007 @@ -107,6 +107,11 @@
>          </dependency>
>          <dependency>
>              <groupId>org.springframework</groupId>
> +            <artifactId>spring-aop</artifactId>
> +            <version>${spring.version}</version>
> +        </dependency>
> +        <dependency>
> +            <groupId>org.springframework</groupId>
>              <artifactId>spring-web</artifactId>
>              <scope>test</scope>
>              <version>${spring.version}</version>
>
> Modified:
> incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jax
>ws/JaxWsServerFactoryBean.java URL:
> http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src
>/main/java/org/apache/cxf/jaxws/JaxWsServerFactoryBean.java?rev=581781&
>r1=581780&r2=581781&view=diff
> ======================================================================
>======== ---
> incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jax
>ws/JaxWsServerFactoryBean.java (original) +++
> incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jax
>ws/JaxWsServerFactoryBean.java Wed Oct  3 22:42:29 2007 @@ -45,6 +45,8
> @@
>  import org.apache.cxf.service.invoker.Invoker;
>  import org.apache.cxf.service.model.BindingInfo;
>
> +import org.springframework.aop.support.AopUtils;
> +
>  /**
>   * Bean to help easily create Server endpoints for JAX-WS. Example:
>   * <pre>
> @@ -196,7 +198,7 @@
>              resourceManager = new DefaultResourceManager(resolvers);
>              resourceManager.addResourceResolver(new
> WebServiceContextResourceResolver()); ResourceInjector injector = new
> ResourceInjector(resourceManager); -           
> injector.inject(instance);
> +            injector.inject(instance,
> AopUtils.getTargetClass(instance)); }
>      }
>  }



-- 
J. Daniel Kulp
Principal Engineer
IONA
P: 781-902-8727    C: 508-380-7194
daniel.kulp@iona.com
http://www.dankulp.com/blog

Mime
View raw message