FileDocCategorySizeDatePackage
ContextFactory.javaAPI DocExample6961Tue May 29 16:57:18 BST 2007com.sun.xml.ws.tx.coordinator

ContextFactory

public class ContextFactory extends Object
This class is an abstraction of the two kinds of CoordinationContexts defined in WS-Coordination 2004/10 member submission and 2006/03 OASIS.
author
Ryan.Shoemaker@Sun.COM
version
$Revision: 1.8.4.1 $
since
1.0

Fields Summary
private static String
activityId
private static com.sun.xml.ws.tx.common.TxLogger
logger
Constructors Summary
Methods Summary
public static CoordinationContextInterfacecreateContext(java.lang.String coordType, long expires)
Create a new {@link CoordinationContextInterface} of the appropriate type based on the coordination type namespace uri.

param
coordType the nsuri of the coordination type, either {@link com.sun.xml.ws.tx.common.Constants#WSAT_2004_PROTOCOL} or {@link com.sun.xml.ws.tx.common.Constants#WSAT_OASIS_NSURI}
param
expires expiration timout in ms
return
the {@link CoordinationContextInterface}



                                                                     
              

        if (logger.isLogging(Level.FINER)) {
            logger.entering("ContextFactory.createContext: coordType=" + coordType + " expires=" + expires);
        }
        CoordinationContextInterface context;

        if (WSAT_2004_PROTOCOL.equals(coordType)) {
            context = new CoordinationContext200410();
            context.setCoordinationType(coordType);

            context.setExpires(expires);

            activityId = UUID.randomUUID().toString();
            context.setIdentifier("uuid:WSCOOR-SUN-" + activityId);

            // bake the activity id as <wsa:ReferenceParameters> into the registration service EPR, so we can
            // identify the activity when the <register> requests come in.
            context.setRegistrationService(
                    RegistrationManager.newRegistrationEPR(
                            new ActivityIdentifier(context.getIdentifier())));
        } else if (WSAT_OASIS_NSURI.equals(coordType)) {
            throw new UnsupportedOperationException(
                    LocalizationMessages.OASIS_UNSUPPORTED_3000()
            );
        } else {
            throw new UnsupportedOperationException(
                    LocalizationMessages.UNRECOGNIZED_COORDINATION_TYPE_3001(coordType)
            );
        }

        if (logger.isLogging(Level.FINER)) {
            logger.exiting("ContextFactory.createContext: created context for activity id: " + context.getIdentifier());
        }
        return context;
    
public static CoordinationContextInterfacecreateContext(com.sun.xml.ws.tx.webservice.member.coord.CreateCoordinationContextType contextRequest)
Create a context from the incoming message

param
contextRequest request
return
the coordination context

        return createContext(contextRequest.getCoordinationType(), contextRequest.getExpires().getValue());
    
static CoordinationContextInterfacecreateTestContext(java.lang.String coordType, long expires)


        CoordinationContextInterface context;

        if (WSAT_2004_PROTOCOL.equals(coordType)) {
            context = new CoordinationContext200410();
            context.setCoordinationType(coordType);

            context.setExpires(expires);

            activityId = UUID.randomUUID().toString();
            context.setIdentifier("uuid:WSCOOR-SUN-" + activityId);

            // we can't unit test the normal creation of an EPR this way because
            // it requires the use of injected stateful webservice managers on
            // the port type impls.  So set a dummy EPR instead.
            //
            // ActivityIdentifier activityId = new ActivityIdentifier(context.getIdentifier());
            // context.setRegistrationService(RegistrationManager.newRegistrationEPR(activityId));
            context.setRegistrationService(new MemberSubmissionEndpointReference());
        } else if (WSAT_OASIS_NSURI.equals(coordType)) {
            throw new UnsupportedOperationException(
                    LocalizationMessages.OASIS_UNSUPPORTED_3000()
            );
        } else {
            throw new UnsupportedOperationException(
                    LocalizationMessages.UNRECOGNIZED_COORDINATION_TYPE_3001(coordType)
            );
        }

        return context;