Search in sources :

Example 1 with FactoryInvoker

use of org.apache.cxf.service.invoker.FactoryInvoker in project cxf by apache.

the class AnnotationsFactoryBeanListener method setScope.

private void setScope(Server server, Class<?> cls) {
    FactoryType scope = cls.getAnnotation(FactoryType.class);
    if (scope != null) {
        Invoker i = server.getEndpoint().getService().getInvoker();
        if (i instanceof FactoryInvoker) {
            Factory f;
            if (scope.factoryClass() == FactoryType.DEFAULT.class) {
                switch(scope.value()) {
                    case Session:
                        if (scope.args().length > 0) {
                            f = new SessionFactory(cls, Boolean.parseBoolean(scope.args()[0]));
                        } else {
                            f = new SessionFactory(cls);
                        }
                        break;
                    case PerRequest:
                        f = new PerRequestFactory(cls);
                        break;
                    case Pooled:
                        f = new PooledFactory(cls, Integer.parseInt(scope.args()[0]));
                        break;
                    default:
                        f = new SingletonFactory(cls);
                        break;
                }
            } else {
                try {
                    f = scope.factoryClass().getConstructor(Class.class, String[].class).newInstance(cls, scope.args());
                } catch (Throwable t) {
                    throw new ServiceConstructionException(t);
                }
            }
            ((FactoryInvoker) i).setFactory(f);
        }
    }
}
Also used : SessionFactory(org.apache.cxf.service.invoker.SessionFactory) FactoryInvoker(org.apache.cxf.service.invoker.FactoryInvoker) Invoker(org.apache.cxf.service.invoker.Invoker) PooledFactory(org.apache.cxf.service.invoker.PooledFactory) Factory(org.apache.cxf.service.invoker.Factory) PooledFactory(org.apache.cxf.service.invoker.PooledFactory) PerRequestFactory(org.apache.cxf.service.invoker.PerRequestFactory) SessionFactory(org.apache.cxf.service.invoker.SessionFactory) SingletonFactory(org.apache.cxf.service.invoker.SingletonFactory) FactoryType(org.apache.cxf.annotations.FactoryType) FactoryInvoker(org.apache.cxf.service.invoker.FactoryInvoker) SingletonFactory(org.apache.cxf.service.invoker.SingletonFactory) PerRequestFactory(org.apache.cxf.service.invoker.PerRequestFactory)

Example 2 with FactoryInvoker

use of org.apache.cxf.service.invoker.FactoryInvoker in project cxf by apache.

the class AbstractValidationInterceptor method getServiceObject.

protected Object getServiceObject(Message message) {
    if (serviceObject != null) {
        return serviceObject;
    }
    Object current = message.getExchange().get(Message.SERVICE_OBJECT);
    if (current != null) {
        return current;
    }
    Endpoint e = message.getExchange().getEndpoint();
    if (e != null && e.getService() != null) {
        Invoker invoker = e.getService().getInvoker();
        if (invoker instanceof FactoryInvoker) {
            FactoryInvoker factoryInvoker = (FactoryInvoker) invoker;
            if (factoryInvoker.isSingletonFactory()) {
                return factoryInvoker.getServiceObject(message.getExchange());
            }
        }
    }
    return null;
}
Also used : Endpoint(org.apache.cxf.endpoint.Endpoint) FactoryInvoker(org.apache.cxf.service.invoker.FactoryInvoker) Invoker(org.apache.cxf.service.invoker.Invoker) FactoryInvoker(org.apache.cxf.service.invoker.FactoryInvoker)

Aggregations

FactoryInvoker (org.apache.cxf.service.invoker.FactoryInvoker)2 Invoker (org.apache.cxf.service.invoker.Invoker)2 FactoryType (org.apache.cxf.annotations.FactoryType)1 Endpoint (org.apache.cxf.endpoint.Endpoint)1 Factory (org.apache.cxf.service.invoker.Factory)1 PerRequestFactory (org.apache.cxf.service.invoker.PerRequestFactory)1 PooledFactory (org.apache.cxf.service.invoker.PooledFactory)1 SessionFactory (org.apache.cxf.service.invoker.SessionFactory)1 SingletonFactory (org.apache.cxf.service.invoker.SingletonFactory)1