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:
037: /*
038: * TxBasePipe.java
039: *
040: * Created on March 16, 2007, 7:40 PM
041: *
042: * To change this template, choose Tools | Template Manager
043: * and open the template in the editor.
044: */
045:
046: package com.sun.xml.ws.tx.common;
047:
048: import com.sun.xml.ws.api.model.wsdl.WSDLBoundOperation;
049: import com.sun.xml.ws.api.model.wsdl.WSDLPort;
050: import com.sun.xml.ws.api.pipe.Pipe;
051: import com.sun.xml.ws.policy.AssertionSet;
052: import com.sun.xml.ws.policy.Policy;
053: import com.sun.xml.ws.policy.PolicyAssertion;
054: import com.sun.xml.ws.policy.PolicyException;
055: import com.sun.xml.ws.policy.PolicyMap;
056: import com.sun.xml.ws.policy.PolicyMapKey;
057: import java.util.Iterator;
058: import javax.xml.ws.WebServiceException;
059: import static com.sun.xml.ws.tx.common.Constants.*;
060: import static com.sun.xml.ws.tx.common.ATAssertion.*;
061:
062: /**
063: *
064: * @author jf39279
065: */
066: abstract public class TxBasePipe implements Pipe {
067: protected final TransactionManagerImpl txnMgr;
068:
069: /**
070: * next pipe in the chain
071: */
072: protected final Pipe next;
073:
074: public TxBasePipe(Pipe next) {
075: this .next = next;
076: txnMgr = TransactionManagerImpl.getInstance();
077: }
078:
079: /**
080: * Invoked before the last copy of the pipeline is about to be discarded,
081: * to give Pipes a chance to clean up any resources.
082: */
083: public void preDestroy() {
084: next.preDestroy();
085: }
086:
087: /**
088: * Representation of all WS-AT policy assertions: ATAssertion and ATAlwaysCapability.
089: */
090: static public class OperationATPolicy {
091: public ATAssertion atAssertion = ATAssertion.NOT_ALLOWED;
092: public boolean ATAlwaysCapability = false;
093: }
094:
095: protected OperationATPolicy getOperationATPolicy(PolicyMap pmap,
096: WSDLPort wsdlModel, WSDLBoundOperation wsdlBoundOp)
097: throws WebServiceException {
098: OperationATPolicy opat = new OperationATPolicy();
099: try {
100: if (pmap != null) {
101: PolicyMapKey opKey = pmap.createWsdlOperationScopeKey(
102: wsdlModel.getOwner().getName(), // service
103: wsdlModel.getName(), // port
104: wsdlBoundOp.getName() // operation
105: );
106: Policy effectivePolicy = pmap
107: .getOperationEffectivePolicy(opKey);
108: if (effectivePolicy != null) {
109: Iterator<AssertionSet> assertionIter = effectivePolicy
110: .iterator();
111: AssertionSet assertionSet;
112: while (assertionIter.hasNext()) {
113: assertionSet = assertionIter.next();
114: for (PolicyAssertion pa : assertionSet) {
115:
116: // Check for 2004 WS-Atomic Transaction Policy Assertions
117: if (pa.getName().equals(AT_ASSERTION)) {
118: opat.atAssertion = (pa.isOptional() ? ALLOWED
119: : MANDATORY);
120:
121: // begin patch for wsit issue 419
122: if (opat.atAssertion == MANDATORY) {
123: String optionalBoolValue = pa
124: .getAttributeValue(WSP2002_OPTIONAL);
125: if (optionalBoolValue != null
126: && Boolean
127: .valueOf(optionalBoolValue)) {
128: opat.atAssertion = ATAssertion.ALLOWED;
129: }
130: }
131: // end patch
132: } else if (pa.getName().equals(
133: AT_ALWAYS_CAPABILITY)) {
134: opat.ATAlwaysCapability = true;
135: }
136:
137: // TODO: To implement OASIS WS-Atomic Transaction,
138: // check for OASIS WS-Atomic Transaction Policy Assertion ATAssertion here
139: }
140: }
141: }
142: }
143: } catch (PolicyException pe) {
144: throw new WebServiceException(pe.getMessage(), pe);
145: }
146: return opat;
147: }
148: }
|