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: package com.sun.xml.ws.server.sei;
038:
039: import com.sun.xml.ws.api.model.Parameter;
040: import com.sun.xml.ws.model.ParameterImpl;
041:
042: import javax.xml.ws.Holder;
043:
044: /**
045: * Moves a Java value unmarshalled from a response message
046: * to the right place.
047: *
048: * <p>
049: * Sometimes values are returned as a return value, and
050: * others are returned in the {@link Holder} value. Instances
051: * of this interface abstracts this detail.
052: *
053: * <p>
054: * {@link EndpointValueSetter} is a stateless behavior encapsulation.
055: *
056: * @author Jitendra Kotamraju
057: */
058: abstract class EndpointValueSetter {
059: private EndpointValueSetter() {
060: }
061:
062: /**
063: * Moves the value to the expected place.
064: *
065: * @param obj
066: * The unmarshalled object.
067: * @param args
068: * The arguments that need to be given to the Java method invocation. If <tt>obj</tt>
069: * is supposed to be returned as a {@link Holder} value, a suitable
070: * {@link Holder} is obtained from this argument list and <tt>obj</tt>
071: * is set.
072: *
073: */
074: abstract void put(Object obj, Object[] args);
075:
076: /**
077: * {@link Param}s with small index numbers are used often,
078: * so we pool them to reduce the footprint.
079: */
080: private static final EndpointValueSetter[] POOL = new EndpointValueSetter[16];
081:
082: static {
083: for (int i = 0; i < POOL.length; i++)
084: POOL[i] = new Param(i);
085: }
086:
087: /**
088: * Returns a {@link EndpointValueSetter} suitable for the given {@link Parameter}.
089: */
090: public static EndpointValueSetter get(ParameterImpl p) {
091: int idx = p.getIndex();
092: if (p.isIN()) {
093: if (idx < POOL.length) {
094: return POOL[idx];
095: } else {
096: return new Param(idx);
097: }
098: } else {
099: return new HolderParam(idx);
100: }
101: }
102:
103: static class Param extends EndpointValueSetter {
104: /**
105: * Index of the argument to put the value to.
106: */
107: protected final int idx;
108:
109: public Param(int idx) {
110: this .idx = idx;
111: }
112:
113: void put(Object obj, Object[] args) {
114: if (obj != null) {
115: args[idx] = obj;
116: }
117: }
118: }
119:
120: static final class HolderParam extends Param {
121:
122: public HolderParam(int idx) {
123: super (idx);
124: }
125:
126: @Override
127: void put(Object obj, Object[] args) {
128: Holder holder = new Holder();
129: if (obj != null) {
130: holder.value = obj;
131: }
132: args[idx] = holder;
133: }
134: }
135: }
|