Search in sources :

Example 1 with ContextProvider

use of com.arjuna.mwlabs.wscf.utils.ContextProvider in project narayana by jbosstm.

the class SagasHLSImple method ensureContextInitialised.

private void ensureContextInitialised() throws SystemException {
    if (!initialised) {
        synchronized (this) {
            if (!initialised) {
                // we  only do this once no matter what happens
                initialised = true;
                try {
                    Class<?> factoryClass = ProtocolRegistry.sharedManager().getProtocolImplementation(coordinationType).getClass();
                    ContextProvider contextProvider = factoryClass.getAnnotation(ContextProvider.class);
                    String providerServiceType = contextProvider.serviceType();
                    if (!providerServiceType.equals(serviceType)) {
                        throw new SystemException("Invalid serviceType for SOAPContext factory registered for SAGAS 1.1 service expecting " + serviceType + " got " + providerServiceType);
                    }
                    Class contextClass = contextProvider.contextImplementation();
                    if (!SOAPContext.class.isAssignableFrom(contextClass)) {
                        throw new SystemException("SOAPContext factory registered for SAGAS 1.1 service provides invalid context implementation");
                    }
                    CONTEXT_IMPLE_CLASS = contextClass;
                } catch (ProtocolNotRegisteredException pnre) {
                    throw new SystemException("No SOAPContext factory registered for SAGAS 1.1 service");
                }
            }
        }
    }
}
Also used : SystemException(com.arjuna.mw.wsas.exceptions.SystemException) SOAPContext(com.arjuna.mw.wsas.context.soap.SOAPContext) ContextProvider(com.arjuna.mwlabs.wscf.utils.ContextProvider)

Example 2 with ContextProvider

use of com.arjuna.mwlabs.wscf.utils.ContextProvider in project narayana by jbosstm.

the class TwoPhaseHLSImple method ensureContextInitialised.

private void ensureContextInitialised() throws SystemException {
    if (!initialised) {
        synchronized (this) {
            if (!initialised) {
                try {
                    Class<?> factoryClass = ProtocolRegistry.sharedManager().getProtocolImplementation(coordinationType).getClass();
                    ContextProvider contextProvider = factoryClass.getAnnotation(ContextProvider.class);
                    String providerServiceType = contextProvider.serviceType();
                    if (!providerServiceType.equals(serviceType)) {
                        throw new SystemException("Invalid serviceType for SOAPContext factory registered for Two Phase 1.1 service expecting " + serviceType + " got " + providerServiceType);
                    }
                    Class contextClass = contextProvider.contextImplementation();
                    if (!SOAPContext.class.isAssignableFrom(contextClass)) {
                        throw new SystemException("SOAPContext factory registered for Two Phase 1.1 service provides invalid context implementation");
                    }
                    CONTEXT_IMPLE_CLASS = contextClass;
                } catch (ProtocolNotRegisteredException pnre) {
                    throw new SystemException("No SOAPContext factory registered for Two Phase 1.1 service");
                } finally {
                    // we  only do this once no matter what happens
                    initialised = true;
                }
            }
        }
    }
}
Also used : SystemException(com.arjuna.mw.wsas.exceptions.SystemException) SOAPContext(com.arjuna.mw.wsas.context.soap.SOAPContext) ContextProvider(com.arjuna.mwlabs.wscf.utils.ContextProvider)

Example 3 with ContextProvider

use of com.arjuna.mwlabs.wscf.utils.ContextProvider in project narayana by jbosstm.

the class ProtocolManager method initialise.

/*
	 * install all registered protocol implementations which should be either context factories
	 * or high level services
	 */
public final synchronized void initialise() {
    if (_initialised)
        return;
    else
        _initialised = true;
    WSCFEnvironmentBean wscfEnvironmentBean = XTSPropertyManager.getWSCFEnvironmentBean();
    List<String> protocolImplementations = wscfEnvironmentBean.getProtocolImplementations();
    if (protocolImplementations == null) {
        wscfLogger.i18NLogger.info_protocols_ProtocolManager_1();
        return;
    }
    ListIterator<String> iterator = protocolImplementations.listIterator();
    List<Class<?>> contextProviderClasses = new ArrayList<Class<?>>();
    List<Class<?>> hlsProviderClasses = new ArrayList<Class<?>>();
    while (iterator.hasNext()) {
        String className = (String) iterator.next();
        Class<?> clazz = null;
        try {
            clazz = this.getClass().getClassLoader().loadClass(className);
            ContextProvider contextProvider = clazz.getAnnotation(ContextProvider.class);
            if (contextProvider != null) {
                contextProviderClasses.add(clazz);
            } else {
                HLSProvider hlsProvider = clazz.getAnnotation(HLSProvider.class);
                if (hlsProvider != null) {
                    hlsProviderClasses.add(clazz);
                } else {
                    wscfLogger.i18NLogger.error_protocols_ProtocolManager_2(className);
                }
            }
        } catch (ClassNotFoundException cnfe) {
            wscfLogger.i18NLogger.error_protocols_ProtocolManager_3(className, cnfe);
        }
    }
    for (Class<?> clazz : hlsProviderClasses) {
        String className = clazz.getName();
        try {
            HLSProvider hlsProvider = clazz.getAnnotation(HLSProvider.class);
            String serviceType = hlsProvider.serviceType();
            wscfLogger.i18NLogger.info_protocols_ProtocolManager_4(className, serviceType);
            Object object = clazz.newInstance();
            _protocols.put(serviceType, object);
        } catch (InstantiationException ie) {
            wscfLogger.i18NLogger.error_protocols_ProtocolManager_5(className, ie);
        } catch (IllegalAccessException iae) {
            wscfLogger.i18NLogger.error_protocols_ProtocolManager_5(className, iae);
        }
    }
    for (Class<?> clazz : contextProviderClasses) {
        String className = clazz.getName();
        try {
            ContextProvider contextProvider = clazz.getAnnotation(ContextProvider.class);
            if (contextProvider != null) {
                String coordinationType = contextProvider.coordinationType();
                wscfLogger.i18NLogger.info_protocols_ProtocolManager_4(className, coordinationType);
                Object object = clazz.newInstance();
                _protocols.put(coordinationType, object);
            }
        } catch (InstantiationException ie) {
            wscfLogger.i18NLogger.error_protocols_ProtocolManager_5(className, ie);
            // To change body of catch statement use File | Settings | File Templates.
            ie.printStackTrace();
        } catch (IllegalAccessException iae) {
            wscfLogger.i18NLogger.error_protocols_ProtocolManager_5(className, iae);
            // To change body of catch statement use File | Settings | File Templates.
            iae.printStackTrace();
        }
    }
}
Also used : WSCFEnvironmentBean(org.jboss.jbossts.xts.environment.WSCFEnvironmentBean) ContextProvider(com.arjuna.mwlabs.wscf.utils.ContextProvider) HLSProvider(com.arjuna.mwlabs.wscf.utils.HLSProvider)

Aggregations

ContextProvider (com.arjuna.mwlabs.wscf.utils.ContextProvider)3 SOAPContext (com.arjuna.mw.wsas.context.soap.SOAPContext)2 SystemException (com.arjuna.mw.wsas.exceptions.SystemException)2 HLSProvider (com.arjuna.mwlabs.wscf.utils.HLSProvider)1 WSCFEnvironmentBean (org.jboss.jbossts.xts.environment.WSCFEnvironmentBean)1