View Javadoc

1   /*
2    * Copyright  2004 The Apache Software Foundation.
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License");
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License.
15   *
16   */
17  package org.apache.kandula.context;
18  
19  import org.apache.axis2.addressing.EndpointReference;
20  import org.apache.kandula.context.impl.ATActivityContext;
21  import org.apache.kandula.faults.InvalidProtocolException;
22  
23  /***
24   * @author <a href="mailto:thilina@opensource.lk"> Thilina Gunarathne </a>
25   */
26  public class ContextFactory {
27  	private static ContextFactory instance = new ContextFactory();
28  	
29  	public static ContextFactory getInstance() {
30  		return instance;
31  	}
32  	
33  	public AbstractContext createActivity(CoordinationContext context)
34  	throws InvalidProtocolException {
35  		if (org.apache.kandula.Constants.WS_AT.equalsIgnoreCase(context
36  				.getCoordinationType())) {
37  			return new ATActivityContext(context);
38  		} else {
39  			throw new InvalidProtocolException("Unsupported Protocol Type");
40  		}
41  	}
42  	
43  	public AbstractContext createActivity(String protocol)
44  	throws InvalidProtocolException {
45  		if (org.apache.kandula.Constants.WS_AT.equalsIgnoreCase(protocol)) {
46  			return new ATActivityContext();
47  		} else {
48  			throw new InvalidProtocolException("Unsupported Protocol Type");
49  		}
50  	}
51  	
52  	/***
53  	 * To be used by the initaitor TxManager to create the initial context
54  	 * 
55  	 * @param protocol
56  	 * @param activationEPR
57  	 * @return
58  	 * @throws InvalidProtocolException
59  	 */
60  	public AbstractContext createActivity(String protocol,
61  			EndpointReference activationEPR) throws InvalidProtocolException {
62  		if (org.apache.kandula.Constants.WS_AT.equalsIgnoreCase(protocol)) {
63  			return new ATActivityContext(activationEPR);
64  		} else {
65  			throw new InvalidProtocolException("Unsupported Protocol Type");
66  		}
67  	}
68  }