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

EnhancedXmlStreamWriterProxy

public final class EnhancedXmlStreamWriterProxy extends Object implements InvocationHandler
The class provides an implementation of an {@link InvocationHandler} interface that handles requests of {@link XMLStreamWriter} proxy instances.

This {@link InvocationHandler} implementation adds additional feature or enhancement to the underlying {@link XMLStreamWriter} instance. The new enhancement or feature is defined by an {@link InvocationProcessor} implementation.

The class also contains a static factory method for creating such 'enhanced' {@link XMLStreamWriter} proxies.

author
Marek Potociar (marek.potociar at sun.com)

Fields Summary
private static final com.sun.xml.ws.policy.privateutil.PolicyLogger
LOGGER
private static final Class[]
PROXIED_INTERFACES
private static final Method
hashCodeMethod
private static final Method
equalsMethod
private static final Method
toStringMethod
private final InvocationProcessor
invocationProcessor
Constructors Summary
private EnhancedXmlStreamWriterProxy(XMLStreamWriter writer, InvocationProcessorFactory processorFactory)

        this.invocationProcessor = processorFactory.createInvocationProcessor(writer);
    
Methods Summary
public static javax.xml.stream.XMLStreamWritercreateProxy(javax.xml.stream.XMLStreamWriter writer, InvocationProcessorFactory processorFactory)
Creates a wrapper {@link XMLStreamWriter} proxy that adds enhanced feature to the {@code writer} instance.

param
writer {@link XMLStreamWriter} instance that should be enhanced with content filtering feature.
param
processorFactory {@link InvocationProcessorFactory} instance that is used to create {@link InvocationProcessor} which implements new enhancement or feature.
return
new enhanced {XMLStreamWriter} (proxy) instance
throws
XMLStreamException in case of any problems with creating the proxy

        LOGGER.entering();
        
        XMLStreamWriter proxy = null;
        try {
            proxy = (XMLStreamWriter) Proxy.newProxyInstance(
                    writer.getClass().getClassLoader(),
                    PROXIED_INTERFACES,
                    new EnhancedXmlStreamWriterProxy(writer, processorFactory));
            
            return proxy;
        } finally {
            LOGGER.exiting(proxy);
        }
    
private java.lang.ObjecthandleObjectMethodCall(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args)

        if (method.equals(hashCodeMethod)) {
            return new Integer(System.identityHashCode(proxy));
        } else if (method.equals(equalsMethod)) {
            return (proxy == args[0] ? Boolean.TRUE : Boolean.FALSE);
        } else if (method.equals(toStringMethod)) {
            return proxy.getClass().getName() + '@" + Integer.toHexString(proxy.hashCode());
        } else {
            throw LOGGER.logSevereException(new InternalError(LocalizationMessages.WSP_1007_UNEXPECTED_OBJECT_METHOD(method)));
        }
    
public java.lang.Objectinvoke(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args)

        if (LOGGER.isMethodCallLoggable()) {
            LOGGER.entering(method, args);
        }
        
        Object result = null;
        try {
            final Class declaringClass = method.getDeclaringClass();
            if (declaringClass == Object.class) {
                return handleObjectMethodCall(proxy, method, args);
            } else {
                final Invocation invocation = Invocation.createInvocation(method, args);
                result = invocationProcessor.process(invocation);
                return result;
            }
        } finally {
            LOGGER.exiting(result);
        }