Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source
   * Copyright 2006, Red Hat Middleware LLC, and individual contributors
   * as indicated by the @author tags. 
   * See the copyright.txt in the distribution for a full listing 
   * of individual contributors.
   * This copyrighted material is made available to anyone wishing to use,
   * modify, copy, or redistribute it subject to the terms and conditions
   * of the GNU Lesser General Public License, v. 2.1.
  * This program is distributed in the hope that it will be useful, but WITHOUT A
  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
  * You should have received a copy of the GNU Lesser General Public License,
  * v.2.1 along with this distribution; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  * MA  02110-1301, USA.
  * 
  * (C) 2005-2006,
  * @author JBoss Inc.
  */
 /*
  * Copyright (C) 2002,
  *
  * Arjuna Technologies Limited,
  * Newcastle upon Tyne,
  * Tyne and Wear,
  * UK.
  *
  * $Id: ContextFactoryImple.java,v 1.16.4.1 2005/11/22 10:36:21 kconner Exp $
  */
 
 package com.arjuna.mwlabs.wst11.at;
 
 
 
         serviceType = .,
         contextImplementation = ArjunaContextImple.class)
 public class ContextFactoryImple implements ContextFactoryLocalFactory
 {
 	{
 		try
 		{
 			 = CoordinatorManagerFactory.coordinatorManager();
 
              = new RegistrarImple();
 
             // install the factory for the mapper to locate
 
             ContextFactoryMapper.getMapper().addContextFactory(.this);
         }
 		catch (Exception ex)
 		{
 		}
 	}

Called when a context factory is added to a context factory mapper. This method will be called multiple times if the context factory is added to multiple context factory mappers or to the same context mapper with different protocol identifiers.

Parameters:
coordinationTypeURI the coordination type uri
	public void install(final String coordinationTypeURI)
	{
	}

Creates a coordination context.

Parameters:
coordinationTypeURI the coordination type uri
expires the expire date/time for the returned context, can be null
currentContext the current context, can be null
Returns:
the created coordination context
Throws:
com.arjuna.wsc.InvalidCreateParametersException if a parameter passed is invalid this activity identifier.
	public CoordinationContext create (final String coordinationTypeURIfinal Long expires,
            final CoordinationContextType currentContextfinal boolean isSecure)
	{
		{
			try
			{
                if (currentContext == null) {
				// make sure no transaction is currently associated
				final int timeout ;
                if (expires == null)
                {
                    timeout = 0 ;
                }
                else
                {
                    final long timeoutVal = expires.longValue() ;
                    timeout = (timeoutVal > . ? . : (int)timeoutVal) ;
                }
                final ArjunaContextImple arjunaContext = ArjunaContextImple.getContext() ;
                final ServiceRegistry serviceRegistry = ServiceRegistry.getRegistry() ;
                final String registrationCoordinatorURI = serviceRegistry.getServiceURI(.isSecure) ;
                final CoordinationContext coordinationContext = new CoordinationContext() ;
                coordinationContext.setCoordinationType(coordinationTypeURI);
                CoordinationContextType.Identifier identifier = new CoordinationContextType.Identifier();
                identifier.setValue("urn:"+arjunaContext.getTransactionIdentifier());
                coordinationContext.setIdentifier(identifier) ;
                final int transactionExpires = arjunaContext.getTransactionExpires();
                if (transactionExpires > 0)
                {
                    Expires expiresInstance = new Expires();
                    expiresInstance.setValue(transactionExpires);
                    coordinationContext.setExpires(expiresInstance);
                }
                W3CEndpointReference registrationCoordinator = getRegistrationCoordinator(registrationCoordinatorURIarjunaContext);
                coordinationContext.setRegistrationService(registrationCoordinator) ;
				/*
				 * Now add the registrar for this specific coordinator to the
				 * mapper.
				 */
				/*
				 * TODO Uughh! This does a suspend for us! Left over from original
				 * WS-AS stuff.
				 *
				 * TODO
				 * REFACTOR, REFACTOR, REFACTOR.
				 */
				return coordinationContext;
                } else {
                    // we need to create a subordinate transaction and register it as both a durable and volatile
                    // participant with the registration service defined in the current context
                    SubordinateATCoordinator subTx = (SubordinateATCoordinatorcreateSubordinate();
                    // hmm, need to create wrappers here as the subTx is in WSCF which only knows
                    // about WSAS and WS-C and the participant is in WS-T
                    String vtppid = subTx.getVolatile2PhaseId();
                    String dtppid = subTx.getDurable2PhaseId();
                    Volatile2PCParticipant vtpp = new SubordinateVolatile2PCStub(subTx);
                    Durable2PCParticipant dtpp = new SubordinateDurable2PCStub(subTx);
                    final String messageId = MessageId.getMessageId() ;
                    W3CEndpointReference participant;
                    W3CEndpointReference coordinator;
                    participantgetParticipant(vtppidisSecure);
                    coordinator = RegistrationCoordinator.register(currentContextmessageIdparticipant.) ;
                    ParticipantProcessor.getProcessor().activateParticipant(new ParticipantEngine(vtppvtppidcoordinator), vtppid) ;
                    participantgetParticipant(dtppidisSecure);
                    coordinator = RegistrationCoordinator.register(currentContextmessageIdparticipant.) ;
                    ParticipantProcessor.getProcessor().activateParticipant(new ParticipantEngine(dtppdtppidcoordinator), dtppid) ;
                    // ok now create the context
                    final ServiceRegistry serviceRegistry = ServiceRegistry.getRegistry() ;
                    final String registrationCoordinatorURI = serviceRegistry.getServiceURI(.isSecure) ;
                    final CoordinationContext coordinationContext = new CoordinationContext() ;
                    coordinationContext.setCoordinationType(coordinationTypeURI);
                    CoordinationContextType.Identifier identifier = new CoordinationContextType.Identifier();
                    String txId = subTx.get_uid().stringForm();
                    identifier.setValue("urn:" + txId);
                    coordinationContext.setIdentifier(identifier) ;
                    Expires expiresInstance = currentContext.getExpires();
                    final long transactionExpires = (expiresInstance != null ? expiresInstance.getValue() : 0);
                    if (transactionExpires > 0)
                    {
                        expiresInstance = new Expires();
                        expiresInstance.setValue(transactionExpires);
                        coordinationContext.setExpires(expiresInstance);
                    }
                    W3CEndpointReference registrationCoordinator = getRegistrationCoordinator(registrationCoordinatorURItxId);
                    coordinationContext.setRegistrationService(registrationCoordinator) ;
                    // now associate the tx id with the sub transaction
                    .associate(subTx);
                    return coordinationContext;
                }
			}
			{
			}
			catch (SystemException ex)
			{
            }
			{
			}
			catch (Exception ex)
			{
				// TODO handle properly
			}
		}
		else {
            throw new InvalidCreateParametersException(
                    ..get_mwlabs_wst_at_Context11FactoryImple_3()
                            + " < "
                            + .
                            + ", "
                            + coordinationTypeURI + " >");
        }
		return null;
	}

    
class used to return data required to manage a bridged to subordinate transaction
    public class BridgeTxData
    {
        public CoordinationContext context;
        public SubordinateATCoordinator coordinator;
        public String identifier;
    }

    
create a bridged to subordinate WS-AT 1.1 transaction, associate it with the registrar and create and return a coordination context for it. n.b. this is a private, behind-the-scenes method for use by the JTA-AT transaction bridge code.

Parameters:
subordinateType a unique string which groups subordinates for the benefit of their parent tx/app and allows them to be identified and retrieved as a group during recovery
expires the timeout for the bridged to AT transaction
isSecure true if the registration cooridnator URL should use a secure address, otherwise false.
Returns:
a coordination context for the bridged to transaction
    public BridgeTxData createBridgedTransaction (String subordinateTypefinal Long expiresfinal boolean isSecure)
    {
        // we must have a type and it must not be the AT-AT subordinate type
        if (subordinateType == null || ..equals(subordinateType)) {
            return null;
        }
        // we need to create a subordinate transaction and register it as both a durable and volatile
        // participant with the registration service defined in the current context
        SubordinateATCoordinator subTx = null;
        try {
            subTx = (SubordinateATCoordinatorcreateSubordinate(subordinateType);
        } catch (NoActivityException e) {
            // will not happen
            return null;
        } catch (InvalidProtocolException e) {
            // will not happen
            return null;
        } catch (SystemException e) {
            // may happen
            return null;
        }
        // ok now create the context
        final ServiceRegistry serviceRegistry = ServiceRegistry.getRegistry() ;
        final String registrationCoordinatorURI = serviceRegistry.getServiceURI(.isSecure) ;
        final CoordinationContext coordinationContext = new CoordinationContext() ;
        String txId = subTx.get_uid().stringForm();
        identifier.setValue("urn:" + txId);
        coordinationContext.setIdentifier(identifier) ;
        if (expires != null && expires.longValue() > 0)
        {
            Expires expiresInstance = new Expires();
            expiresInstance.setValue(expires);
            coordinationContext.setExpires(expiresInstance);
        }
        W3CEndpointReference registrationCoordinator = getRegistrationCoordinator(registrationCoordinatorURItxId);
        coordinationContext.setRegistrationService(registrationCoordinator) ;
        // now associate the tx id with the sub transaction
        try {
            .associate(subTx);
        } catch (Exception e) {
            // will not happen
        }
        BridgeTxData bridgeTxData = new BridgeTxData();
        bridgeTxData.context = coordinationContext;
        bridgeTxData.coordinator = subTx;
        bridgeTxData.identifier = txId;
        return bridgeTxData;
    }
    private W3CEndpointReference getParticipant(final String idfinal boolean isSecure)
    {
        final QName serviceName = .;
        final QName endpointName = .;
        final String address = ServiceRegistry.getRegistry().getServiceURI(.isSecure);
        W3CEndpointReferenceBuilder builder = new W3CEndpointReferenceBuilder();
        builder.serviceName(serviceName);
        builder.endpointName(endpointName);
        builder.address(address);
        InstanceIdentifier.setEndpointInstanceIdentifier(builderid);
        return builder.build();
    }
    private static W3CEndpointReference getRegistrationCoordinator(String registrationCoordinatorURIArjunaContextImple arjunaContext)
    {
        String identifier = arjunaContext.getTransactionIdentifier();
        return getRegistrationCoordinator(registrationCoordinatorURIidentifier);
    }
    private static W3CEndpointReference getRegistrationCoordinator(String registrationCoordinatorURIString identifier)
    {
        final W3CEndpointReferenceBuilder builder = new W3CEndpointReferenceBuilder();
        // strictly we shouldn't need to set the address because we are in the same web app as the
        // coordinator but we have to as the W3CEndpointReference implementation is incomplete
        builder.address(registrationCoordinatorURI);
        InstanceIdentifier.setEndpointInstanceIdentifier(builderidentifier);
        W3CEndpointReference registrationCoordinator = builder.build();
        return registrationCoordinator;
    }

    
Called when a context factory is removed from a context factory mapper. This method will be called multiple times if the context factory is removed from multiple context factory mappers or from the same context factory mapper with different coordination type uris.

Parameters:
coordinationTypeURI the coordination type uri
	public void uninstall (final String coordinationTypeURI)
	{
		// we don't use this as one implementation is registered per type
	}
    {
    }
    
	{
		try
		{
			CoordinatorControl theControl = coordManager.coordinatorControl();
			ATCoordinator subordinateTransaction = theControl.createSubordinate(subordinateType);
			/*
			 * Now add the registrar for this specific coordinator to the
			 * mapper.
			 */
			subordinateTransaction.enlistSynchronization(new CleanupSynchronization(subordinateTransaction.get_uid().stringForm(), ));
			.associate(subordinateTransaction);
			return subordinateTransaction;
		}
		catch (Exception ex)
		{
			throw new SystemException(ex.toString());
		}
	}
	public final RegistrarImple registrar ()
	{
	}
New to GrepCode? Check out our FAQ X