001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036: package com.sun.xml.ws.tx.coordinator;
037:
038: import com.sun.istack.NotNull;
039: import com.sun.xml.ws.developer.MemberSubmissionEndpointReference;
040: import com.sun.xml.ws.tx.common.ActivityIdentifier;
041: import static com.sun.xml.ws.tx.common.Constants.WSAT_2004_PROTOCOL;
042: import static com.sun.xml.ws.tx.common.Constants.WSAT_OASIS_NSURI;
043: import com.sun.xml.ws.tx.common.TxLogger;
044: import com.sun.xml.ws.tx.webservice.member.coord.CreateCoordinationContextType;
045:
046: import java.util.UUID;
047: import java.util.logging.Level;
048:
049: /**
050: * This class is an abstraction of the two kinds of CoordinationContexts defined
051: * in WS-Coordination 2004/10 member submission and 2006/03 OASIS.
052: *
053: * @author Ryan.Shoemaker@Sun.COM
054: * @version $Revision: 1.9 $
055: * @since 1.0
056: */
057: public class ContextFactory {
058:
059: private static String activityId;
060:
061: static private TxLogger logger = TxLogger
062: .getCoordLogger(ContextFactory.class);
063:
064: /**
065: * Create a new {@link CoordinationContextInterface} of the appropriate type based on
066: * the coordination type namespace uri.
067: * <p/>
068: *
069: * @param coordType the nsuri of the coordination type, either {@link com.sun.xml.ws.tx.common.Constants#WSAT_2004_PROTOCOL}
070: * or {@link com.sun.xml.ws.tx.common.Constants#WSAT_OASIS_NSURI}
071: * @param expires expiration timout in ms
072: * @return the {@link CoordinationContextInterface}
073: */
074: public static CoordinationContextInterface createContext(@NotNull
075: final String coordType, final long expires) {
076:
077: if (logger.isLogging(Level.FINER)) {
078: logger.entering("ContextFactory.createContext: coordType="
079: + coordType + " expires=" + expires);
080: }
081: CoordinationContextInterface context;
082:
083: if (WSAT_2004_PROTOCOL.equals(coordType)) {
084: context = new CoordinationContext200410();
085: context.setCoordinationType(coordType);
086:
087: context.setExpires(expires);
088:
089: activityId = UUID.randomUUID().toString();
090: context.setIdentifier("uuid:WSCOOR-SUN-" + activityId);
091:
092: // bake the activity id as <wsa:ReferenceParameters> into the registration service EPR, so we can
093: // identify the activity when the <register> requests come in.
094: context.setRegistrationService(RegistrationManager
095: .newRegistrationEPR(new ActivityIdentifier(context
096: .getIdentifier())));
097: } else if (WSAT_OASIS_NSURI.equals(coordType)) {
098: throw new UnsupportedOperationException(
099: LocalizationMessages.OASIS_UNSUPPORTED_3000());
100: } else {
101: throw new UnsupportedOperationException(
102: LocalizationMessages
103: .UNRECOGNIZED_COORDINATION_TYPE_3001(coordType));
104: }
105:
106: if (logger.isLogging(Level.FINER)) {
107: logger
108: .exiting("ContextFactory.createContext: created context for activity id: "
109: + context.getIdentifier());
110: }
111: return context;
112: }
113:
114: /**
115: * Create a context from the incoming <createContext> message
116: *
117: * @param contextRequest <createContext> request
118: * @return the coordination context
119: */
120: public static CoordinationContextInterface createContext(@NotNull
121: final CreateCoordinationContextType contextRequest) {
122: return createContext(contextRequest.getCoordinationType(),
123: contextRequest.getExpires().getValue());
124: }
125:
126: /*
127: * FOR UNIT TESTING ONLY
128: */
129: static CoordinationContextInterface createTestContext(
130: final String coordType, final long expires) {
131:
132: CoordinationContextInterface context;
133:
134: if (WSAT_2004_PROTOCOL.equals(coordType)) {
135: context = new CoordinationContext200410();
136: context.setCoordinationType(coordType);
137:
138: context.setExpires(expires);
139:
140: activityId = UUID.randomUUID().toString();
141: context.setIdentifier("uuid:WSCOOR-SUN-" + activityId);
142:
143: // we can't unit test the normal creation of an EPR this way because
144: // it requires the use of injected stateful webservice managers on
145: // the port type impls. So set a dummy EPR instead.
146: //
147: // ActivityIdentifier activityId = new ActivityIdentifier(context.getIdentifier());
148: // context.setRegistrationService(RegistrationManager.newRegistrationEPR(activityId));
149: context
150: .setRegistrationService(new MemberSubmissionEndpointReference());
151: } else if (WSAT_OASIS_NSURI.equals(coordType)) {
152: throw new UnsupportedOperationException(
153: LocalizationMessages.OASIS_UNSUPPORTED_3000());
154: } else {
155: throw new UnsupportedOperationException(
156: LocalizationMessages
157: .UNRECOGNIZED_COORDINATION_TYPE_3001(coordType));
158: }
159:
160: return context;
161: }
162: }
|