1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/server/sei/EndpointValueSetter.java Tue Mar 06 16:09:35 2012 -0800 1.3 @@ -0,0 +1,123 @@ 1.4 +/* 1.5 + * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. Oracle designates this 1.11 + * particular file as subject to the "Classpath" exception as provided 1.12 + * by Oracle in the LICENSE file that accompanied this code. 1.13 + * 1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 + * version 2 for more details (a copy is included in the LICENSE file that 1.18 + * accompanied this code). 1.19 + * 1.20 + * You should have received a copy of the GNU General Public License version 1.21 + * 2 along with this work; if not, write to the Free Software Foundation, 1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 + * 1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.25 + * or visit www.oracle.com if you need additional information or have any 1.26 + * questions. 1.27 + */ 1.28 + 1.29 +package com.sun.xml.internal.ws.server.sei; 1.30 + 1.31 +import com.sun.xml.internal.ws.api.model.Parameter; 1.32 +import com.sun.xml.internal.ws.model.ParameterImpl; 1.33 + 1.34 +import javax.xml.ws.Holder; 1.35 + 1.36 +/** 1.37 + * Moves a Java value unmarshalled from a response message 1.38 + * to the right place. 1.39 + * 1.40 + * <p> 1.41 + * Sometimes values are returned as a return value, and 1.42 + * others are returned in the {@link Holder} value. Instances 1.43 + * of this interface abstracts this detail. 1.44 + * 1.45 + * <p> 1.46 + * {@link EndpointValueSetter} is a stateless behavior encapsulation. 1.47 + * 1.48 + * @author Jitendra Kotamraju 1.49 + */ 1.50 +public abstract class EndpointValueSetter { 1.51 + private EndpointValueSetter() {} 1.52 + 1.53 + /** 1.54 + * Moves the value to the expected place. 1.55 + * 1.56 + * @param obj 1.57 + * The unmarshalled object. 1.58 + * @param args 1.59 + * The arguments that need to be given to the Java method invocation. If <tt>obj</tt> 1.60 + * is supposed to be returned as a {@link Holder} value, a suitable 1.61 + * {@link Holder} is obtained from this argument list and <tt>obj</tt> 1.62 + * is set. 1.63 + * 1.64 + */ 1.65 + abstract void put(Object obj, Object[] args); 1.66 + 1.67 + /** 1.68 + * {@link Param}s with small index numbers are used often, 1.69 + * so we pool them to reduce the footprint. 1.70 + */ 1.71 + private static final EndpointValueSetter[] POOL = new EndpointValueSetter[16]; 1.72 + 1.73 + static { 1.74 + for( int i=0; i<POOL.length; i++ ) 1.75 + POOL[i] = new Param(i); 1.76 + } 1.77 + 1.78 + /** 1.79 + * Returns a {@link EndpointValueSetter} suitable for the given {@link Parameter}. 1.80 + */ 1.81 + public static EndpointValueSetter get(ParameterImpl p) { 1.82 + int idx = p.getIndex(); 1.83 + if (p.isIN()) { 1.84 + if (idx<POOL.length) { 1.85 + return POOL[idx]; 1.86 + } else { 1.87 + return new Param(idx); 1.88 + } 1.89 + } else { 1.90 + return new HolderParam(idx); 1.91 + } 1.92 + } 1.93 + 1.94 + static class Param extends EndpointValueSetter { 1.95 + /** 1.96 + * Index of the argument to put the value to. 1.97 + */ 1.98 + protected final int idx; 1.99 + 1.100 + public Param(int idx) { 1.101 + this.idx = idx; 1.102 + } 1.103 + 1.104 + void put(Object obj, Object[] args) { 1.105 + if (obj != null) { 1.106 + args[idx] = obj; 1.107 + } 1.108 + } 1.109 + } 1.110 + 1.111 + static final class HolderParam extends Param { 1.112 + 1.113 + public HolderParam(int idx) { 1.114 + super(idx); 1.115 + } 1.116 + 1.117 + @Override 1.118 + void put(Object obj, Object[] args) { 1.119 + Holder holder = new Holder(); 1.120 + if (obj != null) { 1.121 + holder.value = obj; 1.122 + } 1.123 + args[idx] = holder; 1.124 + } 1.125 + } 1.126 +}