FileDocCategorySizeDatePackage
Invocation.javaAPI DocExample9460Tue May 29 16:56:36 BST 2007com.sun.xml.ws.policy.jaxws.xmlstreamwriter

Invocation

public final class Invocation extends Object
The class represents a wrapper around {@code XMLStreamWriter} invocations.
author
Marek Potociar (marek.potociar at sun.com)

Fields Summary
private static final com.sun.xml.ws.policy.privateutil.PolicyLogger
LOGGER
private final Method
method
private final Object[]
arguments
private String
argsString
private final XmlStreamWriterMethodType
methodType
Constructors Summary
private Invocation(Method method, XmlStreamWriterMethodType type, Object[] args)
Private constructor of the class used in the {@link createInvocation(Method, Object[])} factory method.

param
method method represented by the new {@link Invocation} instance
param
type method type represented by the new {@link Invocation} instance
param
args invocation arguments to be passed to the method when {@link #execute()} method is invoked on the {@link Invocation} instance.
see
XmlStreamWriterMethodType

        this.method = method;
        this.arguments = args;
        this.methodType = type;
    
Methods Summary
public java.lang.StringargsToString()
Method returns {@link String} representation of arguments stored in the {@link Invocation} instance.

return
{@link String} representation of arguments stored in the {@link Invocation} instance.

        if (argsString == null) {
            List<Object> argList = null;
            if (arguments != null && arguments.length > 0) {
                if (arguments.length == 3 && "writeCharacters".equals(method.getName())) {
                    argList = new ArrayList<Object>(3);
                    argList.add(new String((char[]) arguments[0]));
                    argList.add(arguments[1]);
                    argList.add(arguments[2]);
                } else {
                    argList = Arrays.asList(arguments);
                }
            }
            argsString = (argList == null) ? "no arguments" : argList.toString();
        }
        
        return argsString;
    
public static com.sun.xml.ws.policy.jaxws.xmlstreamwriter.InvocationcreateInvocation(java.lang.reflect.Method method, java.lang.Object[] args)
Factory method that creates {@link Invocation} instance according to input arguments

param
method method represented by the {@link Invocation} instance returned as a result of this factory method call
param
args invocation arguments to be passed to the method when {@link #execute()} method is invoked on the {@link Invocation} instance.
return
the {@link Invocation} instance representing invocation of method defined by value of {@code method} argument.

    
                                                                                                    
             
        final Object[] arguments;
        final XmlStreamWriterMethodType methodType = XmlStreamWriterMethodType.getMethodType(method.getName());
        if (methodType == WRITE_CHARACTERS && args.length == 3) {
            final Integer start = (Integer) args[1];
            final Integer length = (Integer) args[2];
            final char[] charArrayCopy = new char[length.intValue()];
            System.arraycopy(args[0], start, charArrayCopy, 0, length);
            
            arguments = new Object[3];
            arguments[0] = charArrayCopy;
            arguments[1] = Integer.valueOf(0);
            arguments[2] = length;
        } else {
            arguments = args;
        }
        
        return new Invocation(method, methodType, arguments);
    
public java.lang.Objectexecute(javax.xml.stream.XMLStreamWriter target)
Executes the method on {@code target} {@code XMLStreamWriter} instance.

return
execution result.
exception
IllegalAccessException see {@link java.lang.reflect.Method.invoke(Object, Object[]) Method.invoke()}.
exception
IllegalArgumentException see {@link java.lang.reflect.Method.invoke(Object, Object[]) Method.invoke()}.
exception
InvocationTargetException see {@link java.lang.reflect.Method.invoke(Object, Object[]) Method.invoke()}.
exception
NullPointerException see {@link java.lang.reflect.Method.invoke(Object, Object[]) Method.invoke()}.
exception
ExceptionInInitializerError see {@link java.lang.reflect.Method.invoke(Object, Object[]) Method.invoke()}.

        return method.invoke(target, arguments);
    
public java.lang.ObjectgetArgument(int index)
Returns single invocation argument for this {@link Invocation} instance that is stored in the invocation arguments array at position determined by {@code index} argument.

return
single invocation argument for this {@link Invocation} instance at position determined by {@code index} argument
throws
ArrayIndexOutOfBoundsException if there are no arguments in the array or if the index parameter is out of bounds of invocation arguments array

        if (arguments == null) {
            throw LOGGER.logSevereException(new ArrayIndexOutOfBoundsException(WSP_1052_NO_ARGUMENTS_IN_INVOCATION(this.toString())));
        }
        return arguments[index];
    
public intgetArgumentsCount()
Returns information about the number of arguments stored in this {@link Invocation} instance

return
number of arguments stored in this {@link Invocation} instance

        return (arguments == null) ? 0 : arguments.length;
    
public java.lang.StringgetMethodName()
Returns information about the name of the method represented by this {@link Invocation} instance

return
method name represented by this {@link Invocation} instance

        return method.getName();
    
public XmlStreamWriterMethodTypegetMethodType()
Returns information about the type of the method represented by this {@link Invocation} instance

return
method type represented by this {@link Invocation} instance
see
XmlStreamWriterMethodType

        return methodType;
    
public java.lang.StringtoString()
Method returns {@link String} representation of the {@link Invocation} instance.

return
{@link String} representation of the {@link Invocation} instance.

        final StringBuffer retValue = new StringBuffer(30);
        retValue.append("invocation { method='").append(method.getName()).append("', args=").append(argsToString());
        retValue.append('}");
        
        return retValue.toString();