cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r630263 - in /incubator/cxf/trunk: common/common/src/main/java/org/apache/cxf/common/util/factory/ rt/core/src/main/java/org/apache/cxf/service/invoker/ rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ rt/frontend/jaxws/src/test/java/o...
Date Fri, 22 Feb 2008 17:45:00 GMT
Author: dkulp
Date: Fri Feb 22 09:44:55 2008
New Revision: 630263

URL: http://svn.apache.org/viewvc?rev=630263&view=rev
Log:
Updates to make the factory stuff more sane and much easier to configure via spring
Also makes the pooled stuff actually return objects to the pool.
Add a SpringBeanFactory to grab the bean from the context each time.
Make sure beans created PerRequest get properly resource injected. 

Added:
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/Factory.java
  (with props)
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/PerRequestFactory.java
  (with props)
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/PooledFactory.java
  (with props)
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/SessionFactory.java
  (with props)
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/SingletonFactory.java
  (with props)
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/SpringBeanFactory.java
  (with props)
Removed:
    incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/factory/
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/ApplicationScopePolicy.java
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/LocalFactory.java
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/RequestScopePolicy.java
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/ScopePolicy.java
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/ScopePolicyEditor.java
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/SessionScopePolicy.java
Modified:
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/BeanInvoker.java
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/FactoryInvoker.java
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/Messages.properties
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JAXWSMethodInvoker.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/JAXWSMethodInvokerTest.java
    incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java

Modified: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/BeanInvoker.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/BeanInvoker.java?rev=630263&r1=630262&r2=630263&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/BeanInvoker.java
(original)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/BeanInvoker.java
Fri Feb 22 09:44:55 2008
@@ -24,9 +24,6 @@
 /**
  * Invoker for externally created service objects.
  * 
- * @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse</a>
- * @author <a href="mailto:ajoo.email@gmail.com">Ben Yu</a>
- * @since Feb 9, 2005
  */
 public class BeanInvoker extends AbstractInvoker {
     private Object proxy;

Added: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/Factory.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/Factory.java?rev=630263&view=auto
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/Factory.java
(added)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/Factory.java
Fri Feb 22 09:44:55 2008
@@ -0,0 +1,45 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.service.invoker;
+
+import org.apache.cxf.message.Exchange;
+
+/**
+ * Represents an object factory.
+ * 
+ * Used at invoke time to find the object that the invokation will use
+ */
+public interface Factory {
+    
+    /**
+     * Creates the object that will be used for the invoke 
+     * @param e 
+     * @return
+     * @throws Throwable
+     */
+    Object create(Exchange e) throws Throwable;
+    
+    /**
+     * Post invoke, this is called to allow the factory to release
+     * the object, store it, etc...
+     * @param e
+     * @param o object created from the create method
+     */
+    void release(Exchange e, Object o);
+}

Propchange: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/Factory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/Factory.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/Factory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/FactoryInvoker.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/FactoryInvoker.java?rev=630263&r1=630262&r2=630263&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/FactoryInvoker.java
(original)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/FactoryInvoker.java
Fri Feb 22 09:44:55 2008
@@ -23,42 +23,38 @@
 
 import org.apache.cxf.common.i18n.BundleUtils;
 import org.apache.cxf.common.i18n.Message;
-import org.apache.cxf.common.util.factory.Factory;
 import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.message.Exchange;
 
 /**
- * This invoker implementation calls a Factory to create the service object and
- * then applies a scope policy for caching.
+ * This invoker implementation calls a Factory to create the service object.
  * 
- * @author Ben Yu Feb 2, 2006 12:55:59 PM
  */
 public class FactoryInvoker extends AbstractInvoker {
     private static final ResourceBundle BUNDLE = BundleUtils.getBundle(FactoryInvoker.class);
 
     private final Factory factory;
-    private final ScopePolicy scope;
 
     /**
      * Create a FactoryInvoker object.
      * 
      * @param factory the factory used to create service object.
-     * @param scope the scope policy. Null for default.
      */
-    public FactoryInvoker(Factory factory, ScopePolicy scope) {
+    public FactoryInvoker(Factory factory) {
         this.factory = factory;
-        this.scope = scope == null ? new ApplicationScopePolicy() : scope;
     }
 
     public Object getServiceObject(Exchange ex) {
         try {
-            return getScopedFactory(ex).create();
+            return factory.create(ex);
+        } catch (Fault e) {
+            throw e;
         } catch (Throwable e) {
             throw new Fault(new Message("CREATE_SERVICE_OBJECT_EXC", BUNDLE), e);
         }
     }
-
-    private Factory getScopedFactory(Exchange ex) {
-        return scope.applyScope(factory, ex);
+    
+    public void releaseServiceObject(final Exchange ex, Object obj) {
+        factory.release(ex, obj);
     }
 }

Modified: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/Messages.properties
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/Messages.properties?rev=630263&r1=630262&r2=630263&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/Messages.properties
(original)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/Messages.properties
Fri Feb 22 09:44:55 2008
@@ -22,5 +22,6 @@
 SVC_CLASS_IS_ABSTRACT=Could not instantiate service class {0} because it is abstract.
 COULD_NOT_INSTANTIATE=Couldn't instantiate service object.
 ILLEGAL_ACCESS=Couldn't access service object.
+CREATE_SERVICE_OBJECT_EXC=Couldn't instantiate service object.
 EXCEPTION_INVOKING_OBJECT={0} while invoking {1} with params {2}.
-INVOKING_METHOD=Invoking method {1} on object {0} with params {2}.
\ No newline at end of file
+INVOKING_METHOD=Invoking method {1} on object {0} with params {2}.

Added: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/PerRequestFactory.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/PerRequestFactory.java?rev=630263&view=auto
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/PerRequestFactory.java
(added)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/PerRequestFactory.java
Fri Feb 22 09:44:55 2008
@@ -0,0 +1,74 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.service.invoker;
+
+import java.lang.reflect.Modifier;
+import java.util.ResourceBundle;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.common.i18n.BundleUtils;
+import org.apache.cxf.common.i18n.Message;
+import org.apache.cxf.common.injection.ResourceInjector;
+import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.message.Exchange;
+import org.apache.cxf.resource.ResourceManager;
+
+/**
+ * Creates a new instance of the service object for each call to create().
+ */
+public class PerRequestFactory implements Factory {
+    private static final ResourceBundle BUNDLE = BundleUtils.getBundle(PerRequestFactory.class);
+
+    private final Class svcClass;
+
+    public PerRequestFactory(final Class svcClass) {
+        super();
+        this.svcClass = svcClass;
+    }
+
+    public Object create(Exchange ex) throws Throwable {
+        try {
+            if (svcClass.isInterface()) {
+                throw new Fault(new Message("SVC_CLASS_IS_INTERFACE", BUNDLE, svcClass.getName()));
+            }
+
+            if (Modifier.isAbstract(svcClass.getModifiers())) {
+                throw new Fault(new Message("SVC_CLASS_IS_ABSTRACT", BUNDLE, svcClass.getName()));
+            }
+            Object o = svcClass.newInstance();
+            Bus b = ex.get(Bus.class);
+            ResourceManager resourceManager = b.getExtension(ResourceManager.class);
+            if (resourceManager != null) {
+                ResourceInjector injector = new ResourceInjector(resourceManager);
+                injector.inject(o);
+                injector.construct(o);
+            }
+            return o;
+        } catch (InstantiationException e) {
+            throw new Fault(new Message("COULD_NOT_INSTANTIATE", BUNDLE));
+        } catch (IllegalAccessException e) {
+            throw new Fault(new Message("ILLEGAL_ACCESS", BUNDLE));
+        }
+    }
+
+    public void release(Exchange ex, Object o) {
+        //nothing to do
+    }
+}

Propchange: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/PerRequestFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/PerRequestFactory.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/PerRequestFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/PooledFactory.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/PooledFactory.java?rev=630263&view=auto
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/PooledFactory.java
(added)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/PooledFactory.java
Fri Feb 22 09:44:55 2008
@@ -0,0 +1,105 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.service.invoker;
+
+import java.util.Collection;
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.BlockingQueue;
+
+import org.apache.cxf.message.Exchange;
+
+/**
+ * Factory the maintains a pool of instances that are used.
+ * 
+ * Can optionally create more instances than the size of the queue
+ */
+public class PooledFactory implements Factory {
+    BlockingQueue<Object> pool;
+    Factory factory;
+    int count;
+    int max;
+    boolean createMore;
+
+    /**
+     * Pool of instances of the svcClass
+     * @param svcClass the class to create
+     * @param max the absolute maximum number to create and pool
+     */
+    public PooledFactory(final Class svcClass, int max) {
+        this(new PerRequestFactory(svcClass), max, false);
+    }
+    /**
+     * Pool of instances contructed from the given factory
+     * @param factory
+     * @param max the absolute maximum number to create and pool
+     */
+    public PooledFactory(final Factory factory, int max) {
+        this(factory, max, false);
+    }
+
+    /**
+     * Pool of instances contructed from the given factory
+     * @param factory
+     * @param max the absolute maximum number to create and pool
+     * @param createMore If the pool is empty, but max objects have already 
+     * been constructed, should more be constructed on a per-request basis (and 
+     * then discarded when done) or should requests block until instances are 
+     * released back into the pool. 
+     */
+    public PooledFactory(final Factory factory, int max, boolean createMore) {
+        this.factory = factory;
+        if (max < 1) {
+            max = 16;
+        }
+        pool = new ArrayBlockingQueue<Object>(max, true);
+        this.max = max;
+        this.count = 0;
+        this.createMore = createMore;
+    }
+    
+    /**
+     * Pool constructed from the give Collection of objects. 
+     * @param objs The collection of objects to pre-polulate the pool
+     */
+    public PooledFactory(Collection<Object> objs) {
+        pool = new ArrayBlockingQueue<Object>(objs.size(), true);
+        pool.addAll(objs);
+    }
+
+    /** {@inheritDoc}*/
+    public Object create(Exchange ex) throws Throwable {
+        if (factory == null 
+            || ((count == max) && !createMore)) {
+            return pool.take();
+        }
+        Object o = pool.poll();
+        if (o == null) {
+            count++;
+            return factory.create(ex);
+        }
+        return o;
+    }
+
+    /** {@inheritDoc}*/
+    public void release(Exchange ex, Object o) {
+        pool.offer(o);
+    }
+
+}

Propchange: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/PooledFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/PooledFactory.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/PooledFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/SessionFactory.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/SessionFactory.java?rev=630263&view=auto
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/SessionFactory.java
(added)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/SessionFactory.java
Fri Feb 22 09:44:55 2008
@@ -0,0 +1,59 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.service.invoker;
+
+import org.apache.cxf.message.Exchange;
+import org.apache.cxf.service.Service;
+
+/**
+ * Creates a new instance for each session.
+ * 
+ * This may have restrictions on what the bean can look like.   For example, 
+ * some session implementations require the beans to be Serializable
+ */
+public class SessionFactory implements Factory {
+    Factory factory;
+    public SessionFactory(Class<?> svcClass) {
+        this(new PerRequestFactory(svcClass));
+    }
+    public SessionFactory(Factory f) {
+        factory = f;
+    }
+
+    /** {@inheritDoc}*/
+    public Object create(Exchange e) throws Throwable {
+        Service serv = e.get(Service.class);
+        Object o = null;
+        synchronized (serv) {
+            o = e.getSession().get(serv.getName());
+            if (o == null) {
+                o = factory.create(e);
+                e.getSession().put(serv.getName(), o);
+            }
+        }
+        return o;
+    }
+
+    /** {@inheritDoc}*/
+    public void release(Exchange e, Object o) {
+        //nothing
+    }
+
+}

Propchange: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/SessionFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/SessionFactory.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/SessionFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/SingletonFactory.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/SingletonFactory.java?rev=630263&view=auto
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/SingletonFactory.java
(added)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/SingletonFactory.java
Fri Feb 22 09:44:55 2008
@@ -0,0 +1,61 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.service.invoker;
+
+import org.apache.cxf.message.Exchange;
+
+/**
+ * Always returns a single instance of the bean.
+ * 
+ * This is generally the default.
+ */
+public class SingletonFactory implements Factory {
+    Object bean;
+    Factory factory;
+    public SingletonFactory(final Object bean) {
+        this.bean = bean;
+    }
+    public SingletonFactory(final Class<?> beanClass) {
+        this.factory = new PerRequestFactory(beanClass);
+    }
+    public SingletonFactory(final Factory f) {
+        this.factory = f;
+    }
+
+    /** {@inheritDoc}*/
+    public Object create(Exchange ex) throws Throwable {
+        if (bean == null && factory != null) {
+            createBean(ex);
+        }
+        return bean;
+    }
+
+    private synchronized void createBean(Exchange e) throws Throwable {
+        if (bean == null) {
+            bean = factory.create(e);
+        }
+    }
+    
+    /** {@inheritDoc}*/
+    public void release(Exchange ex, Object o) {
+        //nothing to do
+    }
+
+}

Propchange: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/SingletonFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/SingletonFactory.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/SingletonFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/SpringBeanFactory.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/SpringBeanFactory.java?rev=630263&view=auto
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/SpringBeanFactory.java
(added)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/SpringBeanFactory.java
Fri Feb 22 09:44:55 2008
@@ -0,0 +1,58 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.service.invoker;
+
+import org.apache.cxf.message.Exchange;
+import org.springframework.beans.BeansException;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+
+/**
+ * Factory that will query the Spring ApplicationContext for the 
+ * appropriate bean for each request.
+ * 
+ * This can be expensive.  If the bean is "prototype" or similar such that a 
+ * new instance is created each time, this could slow things down.  In that 
+ * case, it's recommended to use this in conjunction with the PooledFactory
+ * to pool the beans or the SessionFactory or similar.
+ */
+public class SpringBeanFactory implements Factory, ApplicationContextAware {
+    ApplicationContext ctx;
+    String beanName;
+    
+    public SpringBeanFactory(String name) {
+        beanName = name;
+    }
+    
+    /** {@inheritDoc}*/
+    public Object create(Exchange e) throws Throwable {
+        return ctx.getBean(beanName);
+    }
+
+    /** {@inheritDoc}*/
+    public void release(Exchange e, Object o) {
+        //nothing
+    }
+
+    public void setApplicationContext(ApplicationContext arg0) throws BeansException {
+        ctx = arg0;
+    }
+
+}

Propchange: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/SpringBeanFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/SpringBeanFactory.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/SpringBeanFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JAXWSMethodInvoker.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JAXWSMethodInvoker.java?rev=630263&r1=630262&r2=630263&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JAXWSMethodInvoker.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JAXWSMethodInvoker.java
Fri Feb 22 09:44:55 2008
@@ -29,38 +29,26 @@
 import javax.xml.ws.soap.SOAPFaultException;
 
 import org.apache.cxf.binding.soap.SoapFault;
-import org.apache.cxf.common.util.factory.Factory;
 import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.jaxws.context.WebServiceContextImpl;
 import org.apache.cxf.jaxws.context.WrappedMessageContext;
 import org.apache.cxf.jaxws.support.ContextPropertiesMapping;
 import org.apache.cxf.message.Exchange;
-import org.apache.cxf.service.invoker.ApplicationScopePolicy;
+import org.apache.cxf.service.invoker.Factory;
 import org.apache.cxf.service.invoker.FactoryInvoker;
-import org.apache.cxf.service.invoker.ScopePolicy;
+import org.apache.cxf.service.invoker.SingletonFactory;
 
 public class JAXWSMethodInvoker extends FactoryInvoker {
 
     public JAXWSMethodInvoker(final Object bean) {
-        super(
-            new Factory() {
-                public Object create() {
-                    return bean;
-                }
-            },
-            ApplicationScopePolicy.instance());
-        
+        super(new SingletonFactory(bean));
     }
     
     public JAXWSMethodInvoker(Factory factory) {
-        super(factory, ApplicationScopePolicy.instance());
+        super(factory);
     }
     
-    public JAXWSMethodInvoker(Factory factory, ScopePolicy scope) {
-        super(factory, scope);
-    }
-
     protected Fault createFault(Throwable ex, Method m, List<Object> params, boolean
checked) {
         //map the JAX-WS faults
         if (ex instanceof SOAPFaultException) {

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/JAXWSMethodInvokerTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/JAXWSMethodInvokerTest.java?rev=630263&r1=630262&r2=630263&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/JAXWSMethodInvokerTest.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/JAXWSMethodInvokerTest.java
Fri Feb 22 09:44:55 2008
@@ -19,10 +19,9 @@
 package org.apache.cxf.jaxws;
 
 
-import org.apache.cxf.common.util.factory.Factory;
 import org.apache.cxf.jaxws.service.Hello;
 import org.apache.cxf.message.Exchange;
-import org.apache.cxf.service.invoker.ScopePolicy;
+import org.apache.cxf.service.invoker.Factory;
 import org.easymock.classextension.EasyMock;
 import org.junit.Assert;
 import org.junit.Test;
@@ -30,16 +29,15 @@
 public class JAXWSMethodInvokerTest {
     Factory factory = EasyMock.createMock(Factory.class);
     Object target = EasyMock.createMock(Hello.class);
-    ScopePolicy scope = EasyMock.createMock(ScopePolicy.class);
         
     @Test
     public void testFactoryBeans() throws Throwable {
+        Exchange ex = EasyMock.createMock(Exchange.class);               
         EasyMock.reset(factory);
-        factory.create();
+        factory.create(ex);
         EasyMock.expectLastCall().andReturn(target);
         EasyMock.replay(factory);
         JAXWSMethodInvoker jaxwsMethodInvoker = new JAXWSMethodInvoker(factory);
-        Exchange ex = EasyMock.createMock(Exchange.class);               
         Object object = jaxwsMethodInvoker.getServiceObject(ex);
         Assert.assertEquals("the target object and service object should be equal ", object,
target);
         EasyMock.verify(factory);

Modified: incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java?rev=630263&r1=630262&r2=630263&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java
(original)
+++ incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java
Fri Feb 22 09:44:55 2008
@@ -74,10 +74,9 @@
 import org.apache.cxf.service.Service;
 import org.apache.cxf.service.ServiceImpl;
 import org.apache.cxf.service.ServiceModelSchemaValidator;
-import org.apache.cxf.service.invoker.ApplicationScopePolicy;
 import org.apache.cxf.service.invoker.FactoryInvoker;
 import org.apache.cxf.service.invoker.Invoker;
-import org.apache.cxf.service.invoker.LocalFactory;
+import org.apache.cxf.service.invoker.SingletonFactory;
 import org.apache.cxf.service.model.AbstractMessageContainer;
 import org.apache.cxf.service.model.BindingInfo;
 import org.apache.cxf.service.model.BindingOperationInfo;
@@ -696,7 +695,7 @@
         }
     }
     protected Invoker createInvoker() {
-        return new FactoryInvoker(new LocalFactory(getServiceClass()), new ApplicationScopePolicy());
+        return new FactoryInvoker(new SingletonFactory(getServiceClass()));
     }
 
     protected ServiceInfo createServiceInfo(InterfaceInfo intf) {



Mime
View raw message