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.4.4.1 2005/11/22 10:36:14 kconner Exp $
  */
 
 package com.arjuna.mwlabs.wst11.ba;
 
 
 
         serviceType = .,
         contextImplementation = ArjunaContextImple.class)
 public class ContextFactoryImple implements ContextFactory
 {
     public ContextFactoryImple()
     {
         try
         {
              = CoordinatorManagerFactory.coordinatorManager();
 
              = new RegistrarImple();
 
             // install the factory for the mapper to locate
 
             ContextFactoryMapper.getMapper().addContextFactory(.this);
         }
         catch (Exception ex)
         {
             ex.printStackTrace();
         }
     }

    
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)
    {
    }
    // TODO interposition
    /*
     * If there is a context passed through to create then this newly created
     * coordinator should be interposed.
     */

    
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 coordinationTypeURI,
            final Long expiresfinal CoordinationContextType currentContextfinal boolean isSecure)
        throws InvalidCreateParametersException
    {
        if (..equals(coordinationTypeURI))
    	{
    	    try
    	    {
    		// make sure no transaction is currently associated
            if (currentContext == null) {
    		final int timeout ;
            if (expires == null)
            {
                timeout = 0 ;
            }
            else
            {
                final long longTimeout = expires.longValue() ;
                timeout = (longTimeout > . ? . : (int)longTimeout) ;
            }
            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);
            }
            final W3CEndpointReference registrationCoordinator = getRegistrationCoordinator(registrationCoordinatorURIarjunaContext);
            coordinationContext.setRegistrationService(registrationCoordinator) ;
                // why is this created early even though the enlistment for termination
                // is done late? well that's a good question. look at the corresponding registrar
                // code to see why
                // TODO sort this out
            String transactionIdentifier = arjunaContext.getTransactionIdentifier();
            BusinessActivityTerminator terminator = new BusinessActivityTerminatorImple();
            TerminationCoordinatorProcessor.getProcessor().activateParticipant(terminatortransactionIdentifier);
    		return coordinationContext;
            } else {
                // we need to create a subordinate transaction -- this transaction will not be associated
                // with an activity which identifes the parent transaction this means that we cannot use
                // the activity service to do things like enlist participants or deliver participant
                // initiated messages.
                SubordinateBACoordinator subTx = (SubordinateBACoordinatorcreateSubordinate();
                // now we register a coordinator completion participant on behalf of the subtransaction
                // with the registration service defined in the current context
                // there is no point registering a participant completion participant because we cannot
                // know when it is ok to forward a completed message -- even when all N registered PC
                // participants have notified completed another PC participant might enlist.
                String ccpid = subTx.getCoordinatorCompletionParticipantid();
                String messageId = MessageId.getMessageId() ;
                W3CEndpointReference participant = getParticipant(ccpidisSecure);
                W3CEndpointReference coordinator = RegistrationCoordinator.register(currentContextmessageIdparticipant.) ;
                final CoordinatorCompletionParticipantEngine engine = new CoordinatorCompletionParticipantEngine(ccpidcoordinatorccp) ;
                CoordinatorCompletionParticipantProcessor.getProcessor().activateParticipant(engineccpid) ;
                // we need to pass a manager to the stub in case it has to fail at completion
                BAParticipantManager manager = new BACoordinatorCompletionParticipantManagerStub(engine);
                ccp.setManager(manager);
                // 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;
            }
	    }
	    {
		// TODO handle properly
            ex.printStackTrace();
	    }
	    {
		// TODO handle properly
	    }
	    {
		// TODO handle properly
	    }
	    catch (Exception ex)
	    {
		// TODO handle properly
	    }
	}
	else {
            throw new InvalidCreateParametersException(..get_mwlabs_wst_ba_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 SubordinateBACoordinator coordinator;
        public String identifier;
    }

    
create a bridged to subordinate WS-BA 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-BA transaction bridge code.

Parameters:
expires the timeout for the bridged to BA 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 (final Long expiresfinal boolean isSecure)
    {
        // we need to create a subordinate transaction and expose it to the bridge layer so it can
        // be driven to completion
        
        SubordinateBACoordinator subTx = null;
        try {
            subTx = (SubordinateBACoordinatorcreateSubordinate();
        } 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 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) {
        final 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 (String coordinationTypeURI)
    {
	// we don't use this as one implementation is registered per type
    }
    {
        try
        {
            CoordinatorServiceImple coordManager = (CoordinatorServiceImple;
            BACoordinator subordinateTransaction = coordManager.createSubordinate();
            /*
             * 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 ()
    {
        return ;
    }
    private CoordinatorManager                   _coordManager;
    private RegistrarImple _theRegistrar;
New to GrepCode? Check out our FAQ X