com.sun.xml.ws.server.sei.ValueGetter Maven / Gradle / Ivy
/*
* The contents of this file are subject to the terms
* of the Common Development and Distribution License
* (the License). You may not use this file except in
* compliance with the License.
*
* You can obtain a copy of the license at
* https://glassfish.dev.java.net/public/CDDLv1.0.html.
* See the License for the specific language governing
* permissions and limitations under the License.
*
* When distributing Covered Code, include this CDDL
* Header Notice in each file and include the License file
* at https://glassfish.dev.java.net/public/CDDLv1.0.html.
* If applicable, add the following below the CDDL Header,
* with the fields enclosed by brackets [] replaced by
* you own identifying information:
* "Portions Copyrighted [year] [name of copyright owner]"
*
* Copyright 2006 Sun Microsystems Inc. All Rights Reserved
*/
package com.sun.xml.ws.server.sei;
import com.sun.xml.ws.model.ParameterImpl;
import com.sun.xml.ws.api.model.Parameter;
import javax.jws.WebParam.Mode;
import javax.xml.ws.Holder;
/**
* Gets a value from an object that represents a parameter passed
* as a method argument.
*
*
* This abstraction hides the handling of {@link Holder}.
*
*
* {@link ValueGetter} is a stateless behavior encapsulation.
*
* @author Kohsuke Kawaguchi
*/
enum ValueGetter {
/**
* {@link ValueGetter} that works for {@link Mode#IN} parameter.
*
*
* Since it's the IN mode, the parameter is not a {@link Holder},
* therefore the parameter itself is a value.
*/
PLAIN() {
Object get(Object parameter) {
return parameter;
}
},
/**
* Creates {@link ValueGetter} that works for {@link Holder},
* which is {@link Mode#INOUT} or {@link Mode#OUT}.
*
*
* In those {@link Mode}s, the parameter is a {@link Holder},
* so the value to be sent is obtained by getting the value of the holder.
*/
HOLDER() {
Object get(Object parameter) {
if(parameter==null)
// the user is allowed to pass in null where a Holder is expected.
return null;
return ((Holder)parameter).value;
}
};
/**
* Gets the value to be sent, from a parameter given as a method argument.
*/
abstract Object get(Object parameter);
/**
* Returns a {@link ValueGetter} suitable for the given {@link Parameter}.
*/
static ValueGetter get(ParameterImpl p) {
// return value is always PLAIN
if(p.getMode() == Mode.IN || p.getIndex() == -1) {
return PLAIN;
} else {
return HOLDER;
}
}
}