Package org.apache.muse.tools.inspector

Source Code of org.apache.muse.tools.inspector.ResourceInspector

/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements.  See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership.  The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License.  You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied.  See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/

package org.apache.muse.tools.inspector;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.net.URI;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.logging.Logger;

import javax.wsdl.Definition;
import javax.wsdl.Operation;
import javax.wsdl.Output;
import javax.wsdl.Part;
import javax.wsdl.Port;
import javax.wsdl.PortType;
import javax.wsdl.Service;
import javax.wsdl.factory.WSDLFactory;
import javax.wsdl.xml.WSDLReader;
import javax.xml.namespace.QName;

import org.apache.muse.core.Environment;
import org.apache.muse.core.proxy.ProxyHandler;
import org.apache.muse.core.proxy.ReflectionProxyHandler;
import org.apache.muse.util.ReflectUtils;
import org.apache.muse.util.messages.Messages;
import org.apache.muse.util.messages.MessagesFactory;
import org.apache.muse.util.xml.XmlUtils;
import org.apache.muse.util.xml.XsdUtils;
import org.apache.muse.ws.addressing.EndpointReference;
import org.apache.muse.ws.addressing.WsaConstants;
import org.apache.muse.ws.addressing.soap.SoapFault;
import org.apache.muse.ws.notification.WsnConstants;
import org.apache.muse.ws.notification.remote.NotificationConsumerClient;
import org.apache.muse.ws.notification.remote.NotificationProducerClient;
import org.apache.muse.ws.resource.lifetime.WsrlConstants;
import org.apache.muse.ws.resource.metadata.MetadataDescriptor;
import org.apache.muse.ws.resource.metadata.OpenMetadataDescriptor;
import org.apache.muse.ws.resource.properties.WsrpConstants;
import org.apache.muse.ws.resource.properties.impl.WsrpUtils;
import org.apache.muse.ws.resource.properties.schema.ResourcePropertiesSchema;
import org.apache.muse.ws.resource.properties.schema.impl.SimpleResourcePropertiesSchema;
import org.apache.muse.ws.resource.remote.WsResourceClient;
import org.apache.muse.ws.wsdl.WsdlUtils;
import org.w3c.dom.Element;

/**
*
* This tool allows a client to dynamically discover the properties and operations
* of a resource by parsing its WSDL. The inspector provides all of the data
* structures necessary to invoke operations with the proper SOAP messages and
* to reason about properties and their metadata. Its chief use is as the data
* model to the client generator that converts WSDL to a Java interface/class.
* <br><br>
* The inspector can also be used in browser/explorer-like clients that do not
* know anything about the resource interfaces they will communicate with ahead
* of time. By providing a WSDL, a client can show (via UI) a user all of the
* properties and operations that are available, as well as a list of what
* parameters/return types to expect. The inspector can take care of converting
* input parameter values into the proper SOAP messages based on the WSDL, and
* then convert the response message back to the expected type.
*
* @author Dan Jemiolo (danj)
* @author Andrew Eberbach (aeberbac)
*
*/
public class ResourceInspector
{
    //
    // Used to lookup all exception messages
    //
    private static Messages _MESSAGES = MessagesFactory.get(ResourceInspector.class);
   
    //
    // The collection of operation names from WS-*
    //
    private static final Set _BASIC_RESOURCE_METHODS = new HashSet();
   
    //
    // A Map between XSD built-in types and JDK types
    //
    private static final Map _JAVA_TYPES = new HashMap();
   
    //
    // The XMLSchema namespace URI
    //
    public static final String NAMESPACE_URI =
        "http://www.w3.org/2001/XMLSchema";
   
    public static final String PREFIX = "xsd";
   
    public static final QName ANY_TYPE_QNAME =
        new QName(NAMESPACE_URI, "anyType", PREFIX);
   
    public static final QName ANY_URI_QNAME =
        new QName(NAMESPACE_URI, "anyURI", PREFIX);
   
    public static final QName ATTRIBUTE_GROUP_QNAME =
        new QName(NAMESPACE_URI, "attributeGroup", PREFIX);

  public static final QName ATTRIBUTE_QNAME =
        new QName(NAMESPACE_URI, "attribute", PREFIX);
   
    public static final QName BOOLEAN_QNAME =
        new QName(NAMESPACE_URI, "boolean", PREFIX);
   
    public static final QName COMPLEX_TYPE_QNAME =
        new QName(NAMESPACE_URI, "complexType", PREFIX);

    public static final QName DATE_QNAME =
        new QName(NAMESPACE_URI, "date", PREFIX);
   
    public static final QName DATE_TIME_QNAME =
        new QName(NAMESPACE_URI, "dateTime", PREFIX);
   
    public static final QName DOUBLE_QNAME =
        new QName(NAMESPACE_URI, "double", PREFIX);
   
    public static final QName DURATION_QNAME =
        new QName(NAMESPACE_URI, "duration", PREFIX);
   
    public static final QName ELEMENT_QNAME =
        new QName(NAMESPACE_URI, "element", PREFIX);
   
    public static final QName FLOAT_QNAME =
        new QName(NAMESPACE_URI, "float", PREFIX);
   
    public static final QName IMPORT_QNAME =
        new QName(NAMESPACE_URI, "import", PREFIX);
   
    public static final QName INCLUDE_QNAME =
        new QName(NAMESPACE_URI, "include", PREFIX);
   
    public static final QName INT_QNAME =
        new QName(NAMESPACE_URI, "int", PREFIX);
   
    public static final QName INTEGER_QNAME =
        new QName(NAMESPACE_URI, "integer", PREFIX);
   
    public static final QName LANGSTRING_QNAME =
        new QName("http://docs.oasis-open.org/wsdm/muws2-2.xsd", "LangString");
    
    public static final QName LONG_QNAME =
        new QName(NAMESPACE_URI, "long", PREFIX);
   
    public static final QName NC_NAME_QNAME =
        new QName(NAMESPACE_URI, "NCName", PREFIX);
   
    public static final QName QNAME_QNAME =
        new QName(NAMESPACE_URI, "QName", PREFIX);
   
    public static final QName SCHEMA_QNAME =
        new QName(NAMESPACE_URI, "schema", PREFIX);
   
    public static final QName SEQUENCE_QNAME =
        new QName(NAMESPACE_URI, "sequence", PREFIX);
   
    public static final QName SHORT_QNAME =
        new QName(NAMESPACE_URI, "short", PREFIX);
   
    public static final QName SIMPLE_TYPE_QNAME =
        new QName(NAMESPACE_URI, "simpleType", PREFIX);
       
    public static final QName STRING_QNAME =
        new QName(NAMESPACE_URI, "string", PREFIX);

    static
    {
        _BASIC_RESOURCE_METHODS.add(WsrpConstants.GET_QNAME);
        _BASIC_RESOURCE_METHODS.add(WsrpConstants.GET_MULTIPLE_QNAME);
        _BASIC_RESOURCE_METHODS.add(WsrpConstants.QUERY_QNAME);
        _BASIC_RESOURCE_METHODS.add(WsrpConstants.SET_QNAME);
        _BASIC_RESOURCE_METHODS.add(WsrlConstants.DESTROY_QNAME);
        _BASIC_RESOURCE_METHODS.add(WsrlConstants.SET_TERMINATION_QNAME);
        _BASIC_RESOURCE_METHODS.add(WsnConstants.NOTIFY_QNAME);
        _BASIC_RESOURCE_METHODS.add(WsnConstants.SUBSCRIBE_QNAME);
        _BASIC_RESOURCE_METHODS.add(WsnConstants.GET_CURRENT_QNAME);
       
        //
        // create the XSD -> JDK mapping for all supported types
        //
       
        _JAVA_TYPES.put(ANY_TYPE_QNAME, Element.class);
        _JAVA_TYPES.put(ANY_URI_QNAME, URI.class);
        _JAVA_TYPES.put(STRING_QNAME, String.class);
        _JAVA_TYPES.put(NC_NAME_QNAME, String.class);
        _JAVA_TYPES.put(QNAME_QNAME, QName.class);
        _JAVA_TYPES.put(BOOLEAN_QNAME, boolean.class);
        _JAVA_TYPES.put(INT_QNAME, int.class);
        _JAVA_TYPES.put(INTEGER_QNAME, int.class);
        _JAVA_TYPES.put(SHORT_QNAME, short.class);
        _JAVA_TYPES.put(LONG_QNAME, long.class);
        _JAVA_TYPES.put(FLOAT_QNAME, float.class);
        _JAVA_TYPES.put(DOUBLE_QNAME, double.class);
        _JAVA_TYPES.put(DATE_QNAME, Date.class);
        _JAVA_TYPES.put(DATE_TIME_QNAME, Date.class);
        _JAVA_TYPES.put(DURATION_QNAME, String.class);
        _JAVA_TYPES.put(LANGSTRING_QNAME, String.class);
       
        //
        // this isn't a XSD type, but it's common to all WS-* services
        //
        _JAVA_TYPES.put(WsaConstants.EPR_QNAME, EndpointReference.class);
        _JAVA_TYPES.put(WsaConstants.EPR_TYPE_QNAME, EndpointReference.class);
    }
   
    public static String getLowerCamelName(String operationName)
    {
        if (operationName == null)
            throw new NullPointerException(_MESSAGES.get("NullOperationName"));
       
        char first = operationName.charAt(0);
        return Character.toLowerCase(first) + operationName.substring(1);
    }
   
    /**
     *
     * @param type
     *        A Class representing the Java type that maps to the XSD type.
     *
     * @return The QName of the XSD type representing the given Java type,
     *         or ANY_TYPE_QNAME if no such mapping exists.
     *
     */
    public static QName getSchemaType(Class type)
    {
        Iterator i = _JAVA_TYPES.entrySet().iterator();
       
        while (i.hasNext())
        {
            Map.Entry next = (Map.Entry)i.next();
            Class nextType = (Class)next.getValue();
           
            if (type.equals(nextType))
                return (QName)next.getKey();
        }
       
        return null;
    }
   
    /**
     *
     * @param typeName
     *        The _name of an XSD built-in type (or WS-A EndpointReference).
     *
     * @return A Class representing the Java type that maps to the XSD
     *         type, or null if no mapping exists.
     *
     */
    public static Class getXsdJavaType(QName typeName)
    {
        return (Class)_JAVA_TYPES.get(typeName);
    }
   
    //
    // The proxy type that will handle the core WS-* operations
    //
    private Class _baseProxyClass = null;
   
    //
    // Map[operation _name, ProxyHandler] for invoking services
    //
    private Map _handlersByName = null;
   
    private LinkedHashMap _javaMethodsByName;
   
    //
    // A WSDL might have multiple port types, but it should only have one
    // concrete service, which maps to one port type
    //
    private QName _portType = null;
   
    //
    // The (optional) RMD that supplements the WS-RP definition in the WSDL.
    // The default is the "empty" RMD, which allows all operations, is set
    // if the inspector cannot find a descriptor referenced in the WSDL.
    //
    private MetadataDescriptor _rmd = null;
   
    //
    // The service's WS-RP doc
    //
    private ResourcePropertiesSchema _wsrpSchema = null;

  private Logger _logger = Logger.getLogger(ResourceInspector.class.getPackage().getName());
   
    private Object createBaseProxy(WsResourceClient resource)
        throws Exception
    {
        EndpointReference src = resource.getSource();
        EndpointReference dest = resource.getDestination();
       
        Class[] paramTypes = new Class[]{
                EndpointReference.class, EndpointReference.class
        };
        Constructor ctor = getBaseProxyClass().getConstructor(paramTypes);
        return ctor.newInstance(new Object[]{ dest, src });
    }
   
    private JavaMethod createJavaMethod(Element wsdl, Operation op)
    {
        JavaMethod method = new JavaMethod();
        method.setName(getInputName(op));
       
        // set to the element name that's on the only message part
        method.setReturnName(getOutputName(op));
       
        Element inputElement = WsdlUtils.getElementDeclaration(wsdl, method.getName());
        if (inputElement == null)
        {
            Object[] filler = { method.getName() };
            throw new RuntimeException(_MESSAGES.get("NoTypeDef", filler));
        }
       
        //if this is null then we've got a void method
        Element outputElement = null;
       
        if (method.getReturnName() != null)
            outputElement = WsdlUtils.getElementDeclaration(wsdl, method.getReturnName());
               
        method.setReturnSchemaType(getSchemaType(outputElement));
       
        //get the java type using the outputElement declaration because it
        //might have minOccurs/maxOccurs data
        method.setReturnType(getJavaType(outputElement));
               
        Element[] paramXML = XmlUtils.findInSubTree(inputElement, XsdUtils.ELEMENT_QNAME);

        Element schema = (Element)inputElement.getParentNode();
        String targetNS = schema.getAttribute(XmlUtils.TARGET_NS);
       
        Class[] parameterTypes = new Class[paramXML.length];
        QName[] parameterSchemaTypes = new QName[paramXML.length];
        QName[] parameterTypeNames = new QName[paramXML.length];
       
        for (int n = 0; n < paramXML.length; ++n)
        {
            String localName = paramXML[n].getAttribute(XsdUtils.NAME);
            if(localName != null && localName.length() != 0)
            {
              parameterTypeNames[n] = new QName(targetNS, localName, "pfx");             
            }
            else
            {
              parameterTypeNames[n] = XmlUtils.parseQName(paramXML[n].getAttribute(XsdUtils.REF),paramXML[n]);
            }           
           
            parameterSchemaTypes[n] = getSchemaType(paramXML[n]);
           
            //get the java type using the paramXML Element declaration because it
            //might have minOccurs/maxOccurs data
            parameterTypes[n] = getJavaType(paramXML[n]);
        }
       
        Object actionURI = op.getInput().getExtensionAttribute(WsaConstants.ACTION_QNAME);
        if(actionURI != null)
        {
          if(actionURI instanceof QName)
          {
            method.setActionURI(((QName)actionURI).getLocalPart());
          }
          else if(actionURI instanceof String)
          {
            method.setActionURI(actionURI.toString());
          }
        }
               
        method.setParameterTypes(parameterTypes);
        method.setParameterSchemaTypes(parameterSchemaTypes);
        method.setParameterTypeNames(parameterTypeNames);
       
        return method;
    }
   
    private ProxyHandler createReflectionHandler(JavaMethod method)
    {
        ProxyHandler handler = new ReflectionProxyHandler();
       
        handler.setAction(method.getActionURI());
       
        handler.setRequestName(method.getName());
        handler.setRequestParameterNames(method.getParameterTypeNames());
        handler.setRequestParameterSchemaTypes(method.getParameterSchemaTypes());
        handler.setRequestParameterTypes(method.getParameterTypes());
        handler.setResponseName(method.getReturnName());
        handler.setReturnSchemaType(method.getReturnSchemaType());
        handler.setReturnType(method.getReturnType());
       
        return handler;
    }
   
    public String getAction(String operation)
    {
        ProxyHandler handler = getHandler(operation);
       
        if (handler != null)
            return handler.getAction();
       
        return null;       
    }
   
    public Class getBaseProxyClass()
    {
        return _baseProxyClass;
    }
   
    private Method getBaseProxyMethod(String operation)
    {
        Method[] methods = getBaseProxyClass().getMethods();
       
        if (!isBasicResourceOperation(operation))
        {
            Object[] filler = { operation };
            throw new RuntimeException(_MESSAGES.get("OperationUndefined", filler));
        }
           
        for (int n = 0; n < methods.length; ++n)
            if (methods[n].getName().equals(operation))
                return methods[n];
       
        Object[] filler = { operation };
        throw new RuntimeException(_MESSAGES.get("OperationUndefined", filler));
    }
   
   
    private ProxyHandler getHandler(String operation)
    {
        return (ProxyHandler)_handlersByName.get(operation);
    }
   
    private Map getHandlers(Map operations)
    {
        _baseProxyClass = getProxyExtends(operations);
        Iterator i = operations.keySet().iterator();
        Map handlers = new HashMap();
       
        while (i.hasNext())
        {
            JavaMethod method = (JavaMethod)operations.get(i.next());
           
            if (isBasicResourceOperation(method.getName()))
                continue;
           
            ProxyHandler handler = createReflectionHandler(method);
           
            String javaName = method.getJavaName();
            handlers.put(javaName, handler);
        }
       
        return handlers;
    }
   
    private QName getInputName(Operation op)
    {
        Map parts = op.getInput().getMessage().getParts();
       
        if (parts.size() != 1)
        {
            Object[] filler = { op.getName() };
            throw new RuntimeException(_MESSAGES.get("NotDocLiteral", filler));
        }
       
        Part docLiteralPart = (Part)parts.values().iterator().next();
        return docLiteralPart.getElementName();
    }
   
    //
    // below are the names for some XSD built-in types
    //
   
   
    public Map getJavaMethods() {
      return _javaMethodsByName;
    }
   
    private Class getJavaType(Element outputElement)
    {
      if (outputElement == null)
            return Void.TYPE;
     
      String typeName = outputElement.getAttribute(XsdUtils.TYPE);
      QName typeQName = XmlUtils.parseQName(typeName, outputElement);             
       
        Class type = getXsdJavaType(typeQName);
       
        if(type == null) {
          type = Element.class;
        }
       
        if(isArrayType(outputElement)) {
          return ReflectUtils.getArrayClassFromClass(type);
        }
              
        return type;
    }
   
    private boolean isArrayType(Element element) {       
        String minOccursAttr = element.getAttribute(XsdUtils.MIN_OCCURS);
        int minOccurs = 1;
        if(minOccursAttr != null && minOccursAttr.length() > 0) {
          minOccurs = Integer.valueOf(minOccursAttr).intValue();
        }
               
        String maxOccursAttr = element.getAttribute(XsdUtils.MAX_OCCURS);
        int maxOccurs = 1;
        if(maxOccursAttr != null && maxOccursAttr.length() > 0) {
            //
            // check for 'unbounded' so we don't throw a NFE
            //
            if (maxOccursAttr.equalsIgnoreCase(XsdUtils.UNBOUNDED))
                maxOccurs = Integer.MAX_VALUE;
            else
                maxOccurs = Integer.valueOf(maxOccursAttr).intValue();
        }
       
    return maxOccurs > 1 || minOccurs > 1;
  }

  public Collection getOperations()
    {
        Collection ops = new HashSet(_handlersByName.keySet());
       
        Method[] baseOps = getBaseProxyClass().getMethods();
       
        for (int n = 0; n < baseOps.length; ++n)
            if (isBasicResourceOperation(baseOps[n].getName()))
                ops.add(baseOps[n].getName());
       
        return ops;
    }
   
    private Map getOperations(Definition wsdlDef, Element wsdlXML, QName portTypeName)
    {
        PortType portType = wsdlDef.getPortType(portTypeName);
       
        List operations = portType.getOperations();
       
        _javaMethodsByName = new LinkedHashMap();
        Iterator i = operations.iterator();
       
        while (i.hasNext())
        {
            Operation next = (Operation)i.next();           
            JavaMethod method = createJavaMethod(wsdlXML, next);           
            _javaMethodsByName.put(method.getName(), method);
        }
       
        return getHandlers(_javaMethodsByName);
    }   
   
    private QName getOutputName(Operation op)
    {
        Output output = op.getOutput();
       
        if (output == null)
            return null;
       
        Map parts = output.getMessage().getParts();
       
        if (parts.size() != 1)
        {
            Object[] filler = { op.getName() };
            throw new RuntimeException(_MESSAGES.get("NotDocLiteral", filler));
        }
       
        Part docLiteralPart = (Part)parts.values().iterator().next();
        return docLiteralPart.getElementName();
    }

    public String[] getParameterNames(String operation)
    {
        QName[] qnames = getParameterQNames(operation);
        String[] names = new String[qnames.length];
       
        for (int n = 0; n < qnames.length; ++n) {
            names[n] = getLowerCamelName(qnames[n].getLocalPart());
        }
       
        return names;
    }

    public QName[] getParameterQNames(String operation)
    {
        ProxyHandler handler = getHandler(operation);
       
        if (handler != null)
            return handler.getRequestParameterNames();
       
        return new QName[0];
    }

    public QName[] getParameterSchemaTypes(String operation)
    {
        ProxyHandler handler = getHandler(operation);
       
        if (handler != null)
            return handler.getRequestParameterSchemaTypes();
       
        Method method = getBaseProxyMethod(operation);
        Class[] types = method.getParameterTypes();
        QName[] qnames = new QName[types.length];
       
        for (int n = 0; n < types.length; ++n)
            qnames[n] = getSchemaType(types[n]);
       
        return qnames;
    }

    public Class[] getParameterTypes(String operation)
    {
        ProxyHandler handler = getHandler(operation);
       
        if (handler != null)
            return handler.getRequestParameterTypes();
       
        Method method = getBaseProxyMethod(operation);
        return method.getParameterTypes();
    }

    public QName getPortType()
    {
        return _portType;
    }

    private QName getPortType(Definition wsdl)
    {
        Map services = wsdl.getServices();
       
        if (services.size() != 1)
            throw new RuntimeException(_MESSAGES.get("OneServicePerWSDL"));
       
        Service service = (Service)services.values().iterator().next();
        Map ports = service.getPorts();
       
        if (ports.size() != 1)
            throw new RuntimeException(_MESSAGES.get("OnePortPerWSDL"));
       
        Port port = (Port)ports.values().iterator().next();
        PortType portType = port.getBinding().getPortType();       
        return portType.getQName();
    }

    public Collection getProperties()
    {
        return _wsrpSchema == null?null:_wsrpSchema.getPropertyNames();
    }

    public Class getPropertyType(QName property)
    {
        QName type = _wsrpSchema.getPropertyTypeName(property);
       
        //HACK
        if(type.getNamespaceURI() == null|| type.getNamespaceURI().length() == 0) {
          type = new QName(XsdUtils.NAMESPACE_URI, type.getLocalPart(), "xsd");
        }
        Class javaType = getXsdJavaType(type);
       
        if(javaType == null) {
          javaType = Element.class;
        }
       
        if (isPropertyMultiple(property))
            javaType = ReflectUtils.getArrayClassFromClass(javaType);
       
        return javaType;           
    }

    private Class getProxyExtends(Map operations)
    {
        if (operations.keySet().contains(WsnConstants.SUBSCRIBE_QNAME))
            return NotificationProducerClient.class;
       
        else if (operations.keySet().contains(WsnConstants.NOTIFY_QNAME))
            return NotificationConsumerClient.class;
       
        return WsResourceClient.class;
    }

    public QName getRequestName(String operation)
    {
        ProxyHandler handler = getHandler(operation);
       
        if (handler != null)
            return handler.getRequestName();
       
        return null;       
    }

    public QName getReturnName(String operation)
    {
        ProxyHandler handler = getHandler(operation);
       
        if (handler != null)
            return handler.getResponseName();
       
        return null;
    }
   
    //
    // below are the common names for XSD tags
    //

   
   
    public QName getReturnSchemaType(String operation)
    {
        ProxyHandler handler = getHandler(operation);
       
        if (handler != null)
            return handler.getReturnSchemaType();
       
        Method method = getBaseProxyMethod(operation);
        Class type = method.getReturnType();
        return getSchemaType(type);
    }

    public Class getReturnType(String operation)
    {
        ProxyHandler handler = getHandler(operation);
       
        if (handler != null)
            return handler.getReturnType();
       
        Method method = getBaseProxyMethod(operation);
        return method.getReturnType();       
    }
   
    private QName getSchemaType(Element element)
    {
        if (element == null)
            return null;
       
        String typeName = element.getAttribute(XsdUtils.TYPE);
                    
        if (typeName == null || typeName.length() == 0) {
          return XsdUtils.ANY_TYPE_QNAME; 
        }
        return XmlUtils.parseQName(typeName, element);
    }

  private ResourcePropertiesSchema getWsrpSchema(Element wsdl, QName portType)
    {
        QName wsrpName = WsrpUtils.getPropertiesName(wsdl, portType);
        Element wsrp = WsdlUtils.getElementDeclaration(wsdl, wsrpName);
        return new SimpleResourcePropertiesSchema(wsrpName, wsrp);
    }
   
    /**
     *
     * This method will invoke form the proper SOAP request for the given
     * operation and parameters and send it to the resource represented by
     * the given client. The response is the content of the SOAP response's
     * Body, deserialized into POJO form.
     *
     */
    public Object invoke(WsResourceClient resource, String operation, Object[] parameters)
        throws SoapFault
    {
        ProxyHandler handler = getHandler(operation);

        if (handler != null)
            return resource.invoke(handler, parameters);
       
        Object proxy = null;
       
        try
        {
            proxy = createBaseProxy(resource);
        }
       
        catch (Exception error)
        {
            throw new RuntimeException(error.getMessage(), error);
        }
       
        Method method = getBaseProxyMethod(operation);
       
        try
        {
            return method.invoke(proxy, parameters);
        }
       
        catch (Exception error)
        {
            throw new SoapFault(error);
        }
    }
   
    public boolean isBasicResourceOperation(QName name)
    {
        return _BASIC_RESOURCE_METHODS.contains(name);
    }
   
    public boolean isBasicResourceOperation(String name)
    {
        Iterator i = _BASIC_RESOURCE_METHODS.iterator();
       
        while (i.hasNext())
        {
            QName qname = (QName)i.next();
           
            if (name.equalsIgnoreCase(qname.getLocalPart()))
                return true;
        }
           
        return false;
    }
   
    public boolean isPropertyAppendable(QName property)
    {
        return !_rmd.isReadOnlyExternal(property) && _rmd.canInsert(property);
    }
   
    public boolean isPropertyMultiple(QName property)
    {
        return _wsrpSchema.getMaxOccurs(property) > 1;
    }
   
    public boolean isPropertyMutable(QName property)
    {
        return !_rmd.isReadOnlyExternal(property) && _rmd.canUpdate(property);
    }
   
    public void run(Element wsdl)
    {
        run(wsdl, null);
    }
       
    public void run(Element wsdl, Environment env)
    {
        Definition def = null;
        String path = null;
       
        if (env != null)
            path = env.getRealDirectory().getAbsolutePath();
       
        try
        {
            WSDLFactory factory = WSDLFactory.newInstance();
            WSDLReader reader = factory.newWSDLReader();
            reader.setFeature(WsdlUtils.WSDL4J_VERBOSE_FLAG, false);
            def = reader.readWSDL(path, wsdl);
        }
       
        catch (Exception error)
        {
            throw new RuntimeException(error);
        }
       
        _portType = getPortType(def);       
       
        try
        {
          _wsrpSchema = getWsrpSchema(wsdl, _portType);
        }
       
        catch (Exception e)
        {
          _logger.warning(_MESSAGES.get("NoWSRPSchema"));
        }
       
        _handlersByName = getOperations(def, wsdl, _portType);
    }

  public void setMetadata(MetadataDescriptor descriptor)
    {
    if(descriptor != null) {
      _rmd = descriptor;
    } else {
      _rmd = OpenMetadataDescriptor.getInstance();
    }
    }
   
    public MetadataDescriptor getMetadata() {
      return _rmd;
    }
}
TOP

Related Classes of org.apache.muse.tools.inspector.ResourceInspector

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.