src/share/jaxws_classes/com/sun/xml/internal/ws/client/sei/ValueSetter.java

Fri, 04 Oct 2013 16:21:34 +0100

author
mkos
date
Fri, 04 Oct 2013 16:21:34 +0100
changeset 408
b0610cd08440
parent 368
0989ad8c0860
child 637
9c07ef4934dd
permissions
-rw-r--r--

8025054: Update JAX-WS RI integration to 2.2.9-b130926.1035
Reviewed-by: chegar

ohair@286 1 /*
alanb@368 2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
ohair@286 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ohair@286 4 *
ohair@286 5 * This code is free software; you can redistribute it and/or modify it
ohair@286 6 * under the terms of the GNU General Public License version 2 only, as
ohair@286 7 * published by the Free Software Foundation. Oracle designates this
ohair@286 8 * particular file as subject to the "Classpath" exception as provided
ohair@286 9 * by Oracle in the LICENSE file that accompanied this code.
ohair@286 10 *
ohair@286 11 * This code is distributed in the hope that it will be useful, but WITHOUT
ohair@286 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ohair@286 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ohair@286 14 * version 2 for more details (a copy is included in the LICENSE file that
ohair@286 15 * accompanied this code).
ohair@286 16 *
ohair@286 17 * You should have received a copy of the GNU General Public License version
ohair@286 18 * 2 along with this work; if not, write to the Free Software Foundation,
ohair@286 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ohair@286 20 *
ohair@286 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@286 22 * or visit www.oracle.com if you need additional information or have any
ohair@286 23 * questions.
ohair@286 24 */
ohair@286 25
ohair@286 26 package com.sun.xml.internal.ws.client.sei;
ohair@286 27
ohair@286 28 import com.sun.xml.internal.ws.api.model.Parameter;
ohair@286 29 import com.sun.xml.internal.ws.model.ParameterImpl;
ohair@286 30 import com.sun.xml.internal.ws.spi.db.PropertyAccessor;
ohair@286 31
ohair@286 32 import javax.xml.ws.Holder;
ohair@286 33 import javax.xml.ws.WebServiceException;
ohair@286 34 import javax.xml.namespace.QName;
ohair@286 35 import javax.xml.bind.JAXBException;
ohair@286 36
ohair@286 37 /**
ohair@286 38 * Moves a Java value unmarshalled from a response message
ohair@286 39 * to the right place.
ohair@286 40 *
ohair@286 41 * <p>
ohair@286 42 * Sometimes values are returned as a return value, and
ohair@286 43 * others are returned in the {@link Holder} value. Instances
ohair@286 44 * of this interface abstracts this detail.
ohair@286 45 *
ohair@286 46 * <p>
ohair@286 47 * {@link ValueSetter} is a stateless behavior encapsulation.
ohair@286 48 *
ohair@286 49 * @author Kohsuke Kawaguchi
ohair@286 50 */
ohair@286 51 public abstract class ValueSetter {
ohair@286 52 private ValueSetter() {}
ohair@286 53
ohair@286 54 /**
ohair@286 55 * Moves the value to the expected place.
ohair@286 56 *
ohair@286 57 * @param obj
ohair@286 58 * The unmarshalled object.
ohair@286 59 * @param args
ohair@286 60 * The arguments given to the Java method invocation. If <tt>obj</tt>
ohair@286 61 * is supposed to be returned as a {@link Holder} value, a suitable
ohair@286 62 * {@link Holder} is obtained from this argument list and <tt>obj</tt>
ohair@286 63 * is set.
ohair@286 64 *
ohair@286 65 * @return
ohair@286 66 * if <tt>obj</tt> is supposed to be returned as a return value
ohair@286 67 * from the method, this method returns <tt>obj</tt>. Otherwise null.
ohair@286 68 */
ohair@286 69 abstract Object put(Object obj, Object[] args);
ohair@286 70
ohair@286 71 /**
ohair@286 72 * Singleton instance.
ohair@286 73 */
ohair@286 74 private static final ValueSetter RETURN_VALUE = new ReturnValue();
ohair@286 75 /**
ohair@286 76 * {@link Param}s with small index numbers are used often,
ohair@286 77 * so we pool them to reduce the footprint.
ohair@286 78 */
ohair@286 79 private static final ValueSetter[] POOL = new ValueSetter[16];
ohair@286 80
ohair@286 81 static {
ohair@286 82 for( int i=0; i<POOL.length; i++ )
ohair@286 83 POOL[i] = new Param(i);
ohair@286 84 }
ohair@286 85
ohair@286 86 /**
ohair@286 87 * Returns a {@link ValueSetter} suitable for the given {@link Parameter}.
ohair@286 88 */
ohair@286 89 static ValueSetter getSync(ParameterImpl p) {
ohair@286 90 int idx = p.getIndex();
ohair@286 91
ohair@286 92 if(idx==-1)
ohair@286 93 return RETURN_VALUE;
ohair@286 94 if(idx<POOL.length)
ohair@286 95 return POOL[idx];
ohair@286 96 else
ohair@286 97 return new Param(idx);
ohair@286 98 }
ohair@286 99
ohair@286 100
ohair@286 101 private static final class ReturnValue extends ValueSetter {
ohair@286 102 Object put(Object obj, Object[] args) {
ohair@286 103 return obj;
ohair@286 104 }
ohair@286 105 }
ohair@286 106
ohair@286 107 static final class Param extends ValueSetter {
ohair@286 108 /**
ohair@286 109 * Index of the argument to put the value to.
ohair@286 110 */
ohair@286 111 private final int idx;
ohair@286 112
ohair@286 113 public Param(int idx) {
ohair@286 114 this.idx = idx;
ohair@286 115 }
ohair@286 116
ohair@286 117 Object put(Object obj, Object[] args) {
ohair@286 118 Object arg = args[idx];
ohair@286 119 if(arg!=null) {
ohair@286 120 // we build model in such a way that this is guaranteed
ohair@286 121 assert arg instanceof Holder;
ohair@286 122 ((Holder)arg).value = obj;
ohair@286 123 }
ohair@286 124 // else {
ohair@286 125 // if null is given as a Holder, there's no place to return
ohair@286 126 // the value, so just ignore.
ohair@286 127 // }
ohair@286 128
ohair@286 129 // no value to return
ohair@286 130 return null;
ohair@286 131 }
ohair@286 132 }
ohair@286 133
ohair@286 134 /**
ohair@286 135 * Singleton instance.
ohair@286 136 */
ohair@286 137 static final ValueSetter SINGLE_VALUE = new SingleValue();
ohair@286 138
ohair@286 139 /**
ohair@286 140 * Used in case of async invocation, where there is only one OUT parameter
ohair@286 141 */
ohair@286 142 private static final class SingleValue extends ValueSetter {
ohair@286 143 /**
ohair@286 144 * Set args[0] as the value
ohair@286 145 */
ohair@286 146 Object put(Object obj, Object[] args) {
ohair@286 147 args[0] = obj;
ohair@286 148 return null;
ohair@286 149 }
ohair@286 150 }
ohair@286 151
ohair@286 152 /**
ohair@286 153 * OUT parameters are set in async bean
ohair@286 154 */
ohair@286 155 static final class AsyncBeanValueSetter extends ValueSetter {
ohair@286 156
ohair@286 157 private final PropertyAccessor accessor;
ohair@286 158
ohair@286 159 AsyncBeanValueSetter(ParameterImpl p, Class wrapper) {
ohair@286 160 QName name = p.getName();
ohair@286 161 try {
ohair@286 162 accessor = p.getOwner().getBindingContext().getElementPropertyAccessor(
ohair@286 163 wrapper, name.getNamespaceURI(), name.getLocalPart() );
ohair@286 164 } catch (JAXBException e) {
ohair@286 165 throw new WebServiceException( // TODO: i18n
ohair@286 166 wrapper+" do not have a property of the name "+name,e);
ohair@286 167 }
ohair@286 168 }
ohair@286 169
ohair@286 170 /**
ohair@286 171 * Sets the property in async bean instance
ohair@286 172 *
ohair@286 173 * @param obj property in async bean
ohair@286 174 * @param args args[0] contains async bean instance
ohair@286 175 * @return null always
ohair@286 176 */
ohair@286 177 Object put(Object obj, Object[] args) {
ohair@286 178 assert args != null;
ohair@286 179 assert args.length == 1;
ohair@286 180 assert args[0] != null;
ohair@286 181
ohair@286 182 Object bean = args[0];
ohair@286 183 try {
ohair@286 184 accessor.set(bean, obj);
ohair@286 185 } catch (Exception e) {
ohair@286 186 throw new WebServiceException(e); // TODO:i18n
ohair@286 187 }
ohair@286 188 return null;
ohair@286 189 }
ohair@286 190
ohair@286 191 }
ohair@286 192
ohair@286 193 }

mercurial