001: /*
002: * Portions Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025: package com.sun.xml.internal.ws.client;
026:
027: import javax.xml.bind.JAXBContext;
028: import javax.xml.ws.BindingProvider;
029: import static javax.xml.ws.BindingProvider.*;
030: import javax.xml.ws.WebServiceException;
031: import javax.xml.ws.handler.MessageContext;
032: import java.util.HashMap;
033: import java.util.HashSet;
034: import java.util.Iterator;
035: import java.util.Set;
036:
037: public abstract class ContextMap extends HashMap<String, Object>
038: implements BindingProviderProperties {
039:
040: /**
041: * Read-only list of known properties.
042: */
043: private static final Set<String> KNOWN_PROPERTIES;
044:
045: private static final HashMap<String, Class> _allowedClass = new HashMap<String, Class>();
046:
047: protected BindingProvider _owner;
048: protected PortInfoBase portInfo;
049:
050: public abstract ContextMap copy();
051:
052: static {
053: //JAXWS 2.0 defined
054: _allowedClass.put(USERNAME_PROPERTY, java.lang.String.class);
055: _allowedClass.put(PASSWORD_PROPERTY, java.lang.String.class);
056: _allowedClass.put(ENDPOINT_ADDRESS_PROPERTY,
057: java.lang.String.class);
058: _allowedClass.put(SESSION_MAINTAIN_PROPERTY,
059: java.lang.Boolean.class);
060: _allowedClass.put(SOAPACTION_USE_PROPERTY,
061: java.lang.Boolean.class);
062: _allowedClass.put(SOAPACTION_URI_PROPERTY,
063: java.lang.String.class);
064:
065: //now defined in jaxwscontext
066: _allowedClass.put(
067: BindingProviderProperties.JAXB_CONTEXT_PROPERTY,
068: JAXBContext.class);
069:
070: Set<String> temp = new HashSet<String>();
071: //JAXWS 2.0 defined
072: temp.add(USERNAME_PROPERTY);
073: temp.add(PASSWORD_PROPERTY);
074: temp.add(ENDPOINT_ADDRESS_PROPERTY);
075: temp.add(SESSION_MAINTAIN_PROPERTY);
076: temp.add(SOAPACTION_USE_PROPERTY);
077: temp.add(SOAPACTION_URI_PROPERTY);
078:
079: temp.add(BindingProviderProperties.JAXB_CONTEXT_PROPERTY);
080: //implementation specific
081: temp.add(BindingProviderProperties.ACCEPT_ENCODING_PROPERTY);
082: temp.add(BindingProviderProperties.CLIENT_TRANSPORT_FACTORY);
083: //used to get stub in runtime for handler chain
084: temp
085: .add(BindingProviderProperties.JAXWS_CLIENT_HANDLE_PROPERTY);
086: temp
087: .add(BindingProviderProperties.JAXWS_CLIENT_HANDLE_PROPERTY);
088:
089: //JAXRPC 1.0 - 1.1 DEFINED - implementation specific
090: temp.add(BindingProviderProperties.HTTP_COOKIE_JAR);
091: temp.add(BindingProviderProperties.ONE_WAY_OPERATION);
092: temp.add(BindingProviderProperties.HTTP_STATUS_CODE);
093: temp
094: .add(BindingProviderProperties.HOSTNAME_VERIFICATION_PROPERTY);
095: temp.add(BindingProviderProperties.REDIRECT_REQUEST_PROPERTY);
096: temp.add(BindingProviderProperties.SECURITY_CONTEXT);
097: temp.add(BindingProviderProperties.SET_ATTACHMENT_PROPERTY);
098: temp.add(BindingProviderProperties.GET_ATTACHMENT_PROPERTY);
099: //Tod:check with mark regarding property modification
100: //KNOWN_PROPERTIES = Collections.unmodifiableSet(temp);
101:
102: temp.add(MessageContext.INBOUND_MESSAGE_ATTACHMENTS);
103: temp.add(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS);
104: temp.add(MessageContext.WSDL_DESCRIPTION);
105: temp.add(MessageContext.WSDL_INTERFACE);
106: temp.add(MessageContext.WSDL_OPERATION);
107: temp.add(MessageContext.WSDL_PORT);
108: temp.add(MessageContext.WSDL_SERVICE);
109: temp.add(MessageContext.HTTP_REQUEST_METHOD);
110: temp.add(MessageContext.HTTP_REQUEST_HEADERS);
111: temp.add(MessageContext.HTTP_RESPONSE_CODE);
112: temp.add(MessageContext.HTTP_RESPONSE_HEADERS);
113: temp.add(MessageContext.PATH_INFO);
114: temp.add(MessageContext.QUERY_STRING);
115: // Content negotiation property for FI -- "none", "pessimistic", "optimistic"
116: temp
117: .add(BindingProviderProperties.CONTENT_NEGOTIATION_PROPERTY);
118: temp.add(BindingProviderProperties.MTOM_THRESHOLOD_VALUE);
119: KNOWN_PROPERTIES = temp;
120: }
121:
122: //used for dispatch
123: public ContextMap(PortInfoBase info, BindingProvider provider) {
124: _owner = provider;
125: if (info != null) {
126: this .portInfo = info;
127: }
128: }
129:
130: /**
131: * Copy constructor.
132: */
133: public ContextMap(ContextMap original) {
134: super (original);
135: this ._owner = original._owner;
136: }
137:
138: //may not need this
139: public ContextMap(BindingProvider owner) {
140: this (null, owner);
141: }
142:
143: boolean doValidation() {
144: return _owner != null;
145: }
146:
147: public Object put(String name, Object value) {
148: if (doValidation()) {
149: validateProperty(name, value, true);
150: return super .put(name, value);
151: }
152: return null;
153: }
154:
155: public Object get(String name) {
156: if (doValidation()) {
157: validateProperty(name, null, false);
158: return super .get(name);
159: }
160: return null;
161: }
162:
163: public Iterator<String> getPropertyNames() {
164: return keySet().iterator();
165: }
166:
167: public Object remove(String name) {
168: if (doValidation()) {
169: validateProperty(name, null, false);
170: return super .remove(name);
171: }
172: return null;
173: }
174:
175: private boolean isAllowedValue(String name, Object value) {
176: if (name.equals(MessageContext.PATH_INFO)
177: || name.equals(MessageContext.QUERY_STRING))
178: return true;
179:
180: if (value == null)
181: return false;
182:
183: return true;
184: }
185:
186: // no value check needed today
187: // Object[] values = _allowedValues.get(name);
188: // if (values != null) {
189: // boolean allowed = false;
190: // for (Object o : values) {
191: // if (STRING_CLASS.isInstance(o) && (STRING_CLASS.isInstance(value))) {
192: // if (((java.lang.String) o).equalsIgnoreCase((java.lang.String) value)) {
193: // allowed = true;
194: // break;
195: // }
196: // } else if (BOOLEAN_CLASS.isInstance(o) && (BOOLEAN_CLASS.isInstance(value))) {
197: // if (Boolean.FALSE.equals(o) || Boolean.TRUE.equals(o)) {
198: // allowed = true;
199: // break;
200: // }
201: // } else {
202: // //log this
203: // }
204: // }
205: // return allowed;
206: // }
207:
208: private boolean isAllowedClass(String propName, Object value) {
209:
210: Class allowedClass = _allowedClass.get(propName);
211: if (allowedClass != null) {
212: return allowedClass.isInstance(value);
213: }
214: return true;
215: }
216:
217: private void validateProperty(String name, Object value,
218: boolean isSetter) {
219: if (name == null)
220: throw new WebServiceException(
221: name
222: + " is a User-defined property - property name can not be null. ",
223: new IllegalArgumentException(
224: "Name of property is null. This is an invalid property name. "));
225:
226: /* Spec clarifies that this check is not needed.
227: if (!KNOWN_PROPERTIES.contains(name)) {
228: //do validation check on not "javax.xml.ws."
229: if (name.startsWith("javax.xml.ws"))
230: throw new WebServiceException(name + " is a User-defined property - can not start with javax.xml.ws. package",
231: new IllegalArgumentException("can not start with javax.xml.ws. package")); //let's check the propertyContext
232: }
233: */
234: //is it alreadySet
235: //Object currentPropValue = get(name);
236: //if (currentPropValue != null) {
237: // if (!isDynamic(name))
238: // throw new WebServiceException("Property bound to Binding Instance",
239: // new IllegalArgumentException("Cannot overwrite the Static Property"));
240: //}
241: if (isSetter) {
242: if (!isAllowedClass(name, value))
243: throw new WebServiceException(value
244: + " is Not Allowed Class for property " + name,
245: new IllegalArgumentException(
246: "Not Allowed Class for property"));
247:
248: if (!isAllowedValue(name, value))
249: throw new WebServiceException(value
250: + " is Not Allowed Value for property " + name,
251: new IllegalArgumentException(
252: "Not Allowed value"));
253: }
254:
255: }
256:
257: //currently not used
258: /* public static enum StyleAndUse {
259: RPC_LITERAL,
260: DOCLIT_WRAPPER_STYLE, DOCLIT_NONWRAPPER_STYLE
261: }
262: */
263: }
|