geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dblev...@apache.org
Subject svn commit: r156300 - in geronimo/trunk/modules/axis-builder/src/java/org/apache/geronimo/axis/builder: AxisServiceBuilder.java ReadOnlyServiceDesc.java
Date Sun, 06 Mar 2005 10:01:22 GMT
Author: dblevins
Date: Sun Mar  6 02:01:20 2005
New Revision: 156300

URL: http://svn.apache.org/viewcvs?view=rev&rev=156300
Log:
Builds a JavaServiceDesc object for a pojo/ejb webservice and wraps it in ReadOnlyServiceDesc
so it cannot be modified by the runtime stack.

Added:
    geronimo/trunk/modules/axis-builder/src/java/org/apache/geronimo/axis/builder/AxisServiceBuilder.java
    geronimo/trunk/modules/axis-builder/src/java/org/apache/geronimo/axis/builder/ReadOnlyServiceDesc.java

Added: geronimo/trunk/modules/axis-builder/src/java/org/apache/geronimo/axis/builder/AxisServiceBuilder.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/axis-builder/src/java/org/apache/geronimo/axis/builder/AxisServiceBuilder.java?view=auto&rev=156300
==============================================================================
--- geronimo/trunk/modules/axis-builder/src/java/org/apache/geronimo/axis/builder/AxisServiceBuilder.java
(added)
+++ geronimo/trunk/modules/axis-builder/src/java/org/apache/geronimo/axis/builder/AxisServiceBuilder.java
Sun Mar  6 02:01:20 2005
@@ -0,0 +1,287 @@
+/**
+ *
+ * Copyright 2004 The Apache Software Foundation
+ *
+ *  Licensed 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.geronimo.axis.builder;
+
+import java.lang.reflect.Method;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.jar.JarFile;
+import javax.wsdl.*;
+import javax.wsdl.extensions.soap.SOAPAddress;
+import javax.wsdl.extensions.soap.SOAPBinding;
+import javax.wsdl.extensions.soap.SOAPBody;
+import javax.xml.namespace.QName;
+
+import org.apache.axis.constants.Style;
+import org.apache.axis.constants.Use;
+import org.apache.axis.description.JavaServiceDesc;
+import org.apache.axis.description.TypeDesc;
+import org.apache.axis.encoding.DeserializerFactory;
+import org.apache.axis.encoding.SerializerFactory;
+import org.apache.axis.encoding.TypeMapping;
+import org.apache.axis.encoding.TypeMappingRegistryImpl;
+import org.apache.axis.encoding.ser.*;
+import org.apache.geronimo.common.DeploymentException;
+import org.apache.geronimo.deployment.util.DeploymentUtil;
+import org.apache.geronimo.kernel.ClassLoading;
+import org.apache.geronimo.xbeans.j2ee.JavaXmlTypeMappingType;
+import org.apache.geronimo.xbeans.j2ee.ServiceEndpointMethodMappingType;
+import org.apache.xmlbeans.SchemaType;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class AxisServiceBuilder {
+
+    public static final String XSD_NS = "http://www.w3.org/2001/XMLSchema";
+
+
+    private static void validateLightweightMapping(Definition definition) throws DeploymentException
{
+        // TODO Plum in the validator
+    }
+
+
+    public static JavaServiceDesc createEJBServiceDesc(JarFile jarFile, String ejbName, ClassLoader
classLoader) throws DeploymentException {
+        Map portComponentsMap = null;
+        try {
+            URL webservicesURL = DeploymentUtil.createJarURL(jarFile, "META-INF/webservices.xml");
+            portComponentsMap = WSDescriptorParser.parseWebServiceDescriptor(webservicesURL,
jarFile, true);
+        } catch (MalformedURLException e1) {
+            throw new DeploymentException("Invalid URL to webservices.xml", e1);
+        }
+
+        // Grab the portInfo for this ejb
+        PortInfo portInfo = (PortInfo) portComponentsMap.get(ejbName);
+        return createServiceDesc(portInfo, classLoader);
+    }
+
+    public static JavaServiceDesc createPOJOServiceDesc(JarFile jarFile, String pojoName,
ClassLoader classLoader) throws DeploymentException {
+        Map portComponentsMap = null;
+        try {
+            URL webservicesURL = DeploymentUtil.createJarURL(jarFile, "WEB-INF/webservices.xml");
+            portComponentsMap = WSDescriptorParser.parseWebServiceDescriptor(webservicesURL,
jarFile, true);
+        } catch (MalformedURLException e1) {
+            throw new DeploymentException("Invalid URL to webservices.xml", e1);
+        }
+
+        // Grab the portInfo for this pojo
+        PortInfo portInfo = (PortInfo) portComponentsMap.get(pojoName);
+        return createServiceDesc(portInfo, classLoader);
+    }
+
+    public static JavaServiceDesc createServiceDesc(PortInfo portInfo, ClassLoader classLoader)
throws DeploymentException {
+        Port port = portInfo.getPort();
+        System.out.println("port = " + port);
+
+        Class serviceEndpointInterface = null;
+        try {
+            serviceEndpointInterface = classLoader.loadClass(portInfo.getServiceEndpointInterfaceName());
+        } catch (ClassNotFoundException e) {
+            throw (DeploymentException) new DeploymentException("Unable to load the service-endpoint
interface for port-component " + portInfo.getPortComponentName()).initCause(e);
+        }
+
+        Map exceptionMap = WSDescriptorParser.getExceptionMap(portInfo.getJavaWsdlMapping());
+        Map schemaTypeKeyToSchemaTypeMap = WSDescriptorParser.buildSchemaTypeKeyToSchemaTypeMap(portInfo.getDefinition());
+        Map complexTypeMap = WSDescriptorParser.getComplexTypesInWsdl(schemaTypeKeyToSchemaTypeMap);
+
+
+        JavaServiceDesc serviceDesc = new JavaServiceDesc();
+
+        URL location = getAddressLocation(port);
+        serviceDesc.setEndpointURL(location.toExternalForm());
+
+        Binding binding = port.getBinding();
+
+        serviceDesc.setStyle(getStyle(binding));
+
+
+        BindingInput bindingInput = ((BindingOperation) binding.getBindingOperations().get(0)).getBindingInput();
+        SOAPBody soapBody = (SOAPBody) WSDescriptorParser.getExtensibilityElement(SOAPBody.class,
bindingInput.getExtensibilityElements());
+
+        if (soapBody.getUse() != null) {
+            Use use = Use.getUse(soapBody.getUse());
+            serviceDesc.setUse(use);
+        } else {
+            serviceDesc.setUse(Use.ENCODED);
+        }
+
+
+        boolean isLightweight = portInfo.getServiceEndpointInterfaceMapping() == null;
+
+        if (isLightweight) {
+            validateLightweightMapping(portInfo.getDefinition());
+        }
+
+        buildOperations(binding, serviceEndpointInterface, isLightweight, portInfo, exceptionMap,
complexTypeMap, classLoader, serviceDesc);
+
+        TypeMappingRegistryImpl tmr = new TypeMappingRegistryImpl();
+        tmr.doRegisterFromVersion("1.3");
+
+        TypeMapping typeMapping = tmr.getOrMakeTypeMapping(serviceDesc.getUse().getEncoding());
+
+        serviceDesc.setTypeMappingRegistry(tmr);
+        serviceDesc.setTypeMapping(typeMapping);
+
+        JavaXmlTypeMappingType[] javaXmlTypeMappings = portInfo.getJavaWsdlMapping().getJavaXmlTypeMappingArray();
+        if (isLightweight) {
+            buildLightweightTypes(schemaTypeKeyToSchemaTypeMap, portInfo, classLoader, typeMapping);
+        } else {
+            buildHeavyweightTypes(javaXmlTypeMappings, classLoader, schemaTypeKeyToSchemaTypeMap,
typeMapping);
+        }
+        return new ReadOnlyServiceDesc(serviceDesc);
+    }
+
+    private static void buildHeavyweightTypes(JavaXmlTypeMappingType[] javaXmlTypeMappings,
ClassLoader classLoader, Map schemaTypeKeyToSchemaTypeMap, TypeMapping typeMapping) throws
DeploymentException {
+        for (int j = 0; j < javaXmlTypeMappings.length; j++) {
+            JavaXmlTypeMappingType javaXmlTypeMapping = javaXmlTypeMappings[j];
+            //default settings
+            Class serializerFactoryClass = BeanSerializerFactory.class;
+            Class deserializerFactoryClass = BeanDeserializerFactory.class;
+
+            String className = javaXmlTypeMapping.getJavaType().getStringValue().trim();
+
+            Class clazz = null;
+            try {
+                clazz = ClassLoading.loadClass(className, classLoader);
+            } catch (ClassNotFoundException e2) {
+                throw new DeploymentException("Could not load java type", e2);
+            }
+
+            if (clazz.isArray()) {
+                serializerFactoryClass = ArraySerializerFactory.class;
+                deserializerFactoryClass = ArrayDeserializerFactory.class;
+            }
+
+            QName typeQName;
+            SchemaTypeKey key;
+            boolean isElement = javaXmlTypeMapping.getQnameScope().getStringValue().equals("element");
+            boolean isSimpleType = javaXmlTypeMapping.getQnameScope().getStringValue().equals("simpleType");
+            if (javaXmlTypeMapping.isSetRootTypeQname()) {
+                typeQName = javaXmlTypeMapping.getRootTypeQname().getQNameValue();
+                key = new SchemaTypeKey(typeQName, isElement, isSimpleType, false);
+            } else if (javaXmlTypeMapping.isSetAnonymousTypeQname()) {
+                String anonTypeQNameString = javaXmlTypeMapping.getAnonymousTypeQname().getStringValue();
+                int pos = anonTypeQNameString.lastIndexOf(":");
+                if (pos == -1) {
+                    throw new DeploymentException("anon QName is invalid, no final ':' "
+ anonTypeQNameString);
+                }
+                //this appears to be ignored...
+                typeQName = new QName(anonTypeQNameString.substring(0, pos), anonTypeQNameString.substring(pos
+ 1));
+                key = new SchemaTypeKey(typeQName, isElement, isSimpleType, true);
+            } else {
+                throw new DeploymentException("either root type qname or anonymous type qname
must be set");
+            }
+
+            SchemaType schemaType = (SchemaType) schemaTypeKeyToSchemaTypeMap.get(key);
+            if (schemaType == null) {
+                throw new DeploymentException("Schema type key " + key + " not found in analyzed
schema: " + schemaTypeKeyToSchemaTypeMap);
+            }
+
+            TypeDesc typeDesc = TypeDescBuilder.getTypeDescriptor(clazz, typeQName, javaXmlTypeMapping,
schemaType);
+
+            SerializerFactory ser = BaseSerializerFactory.createFactory(serializerFactoryClass,
clazz, typeQName);
+            DeserializerFactory deser = BaseDeserializerFactory.createFactory(deserializerFactoryClass,
clazz, typeQName);
+
+            typeMapping.register(clazz, typeQName, ser, deser);
+            TypeDesc.registerTypeDescForClass(clazz, typeDesc);
+        }
+    }
+
+    private static void buildLightweightTypes(Map schemaTypeKeyToSchemaTypeMap, PortInfo
portInfo, ClassLoader classLoader, TypeMapping typeMapping) throws DeploymentException {
+        for (Iterator iterator = schemaTypeKeyToSchemaTypeMap.entrySet().iterator(); iterator.hasNext();)
{
+            Map.Entry entry = (Map.Entry) iterator.next();
+            SchemaTypeKey key = (SchemaTypeKey) entry.getKey();
+//            SchemaType schemaType = (SchemaType) entry.getValue();
+            if (!key.isElement() && !key.isAnonymous()) {
+                //default settings
+                QName typeQName = key.getqName();
+                String namespace = typeQName.getNamespaceURI();
+                String packageName = WSDescriptorParser.getPackageFromNamespace(namespace,
portInfo.getJavaWsdlMapping());
+                String classShortName = typeQName.getLocalPart();
+                String className = packageName + "." + classShortName;
+
+                Class clazz = null;
+                try {
+                    clazz = ClassLoading.loadClass(className, classLoader);
+                } catch (ClassNotFoundException e) {
+                    throw new DeploymentException("Could not load java type", e);
+                }
+
+                Class serializerFactoryClass = BeanSerializerFactory.class;
+                Class deserializerFactoryClass = BeanDeserializerFactory.class;
+
+                if (clazz.isArray()) {
+                    serializerFactoryClass = ArraySerializerFactory.class;
+                    deserializerFactoryClass = ArrayDeserializerFactory.class;
+                }
+
+                SerializerFactory ser = BaseSerializerFactory.createFactory(serializerFactoryClass,
clazz, typeQName);
+                DeserializerFactory deser = BaseDeserializerFactory.createFactory(deserializerFactoryClass,
clazz, typeQName);
+                typeMapping.register(clazz, typeQName, ser, deser);
+
+                //TODO construct typedesc as well.
+//                TypeDesc typeDesc = getTypeDescriptor(clazz, typeQName, javaXmlTypeMapping,
schemaType);
+//                typeDescriptors.put(clazz, typeDesc);
+
+            }
+        }
+    }
+
+    private static void buildOperations(Binding binding, Class serviceEndpointInterface,
boolean lightweight, PortInfo portInfo, Map exceptionMap, Map complexTypeMap, ClassLoader
classLoader, JavaServiceDesc serviceDesc) throws DeploymentException {
+        List bindingOperations = binding.getBindingOperations();
+        for (int i = 0; i < bindingOperations.size(); i++) {
+            BindingOperation bindingOperation = (BindingOperation) bindingOperations.get(i);
+            Method method = WSDescriptorParser.getMethodForOperation(serviceEndpointInterface,
bindingOperation.getOperation());
+
+            OperationDescBuilder operationDescBuilder;
+            if (lightweight) {
+                operationDescBuilder = new LightweightOperationDescBuilder(bindingOperation,
method);
+            } else {
+                String operationName = bindingOperation.getOperation().getName();
+                ServiceEndpointMethodMappingType[] methodMappings = portInfo.getServiceEndpointInterfaceMapping().getServiceEndpointMethodMappingArray();
+                ServiceEndpointMethodMappingType methodMapping = WSDescriptorParser.getMethodMappingForOperation(operationName,
methodMappings);
+                operationDescBuilder = new HeavyweightOperationDescBuilder(bindingOperation,
portInfo.getJavaWsdlMapping(), methodMapping, Style.RPC, exceptionMap, complexTypeMap, classLoader);
+            }
+
+            serviceDesc.addOperationDesc(operationDescBuilder.buildOperationDesc());
+        }
+    }
+
+
+    private static Style getStyle(Binding binding) throws DeploymentException {
+        SOAPBinding soapBinding = (SOAPBinding) WSDescriptorParser.getExtensibilityElement(SOAPBinding.class,
binding.getExtensibilityElements());
+//            String transportURI = soapBinding.getTransportURI();
+        String portStyleString = soapBinding.getStyle();
+        Style portStyle = Style.getStyle(portStyleString);
+        return portStyle;
+    }
+
+    private static URL getAddressLocation(Port port) throws DeploymentException {
+        SOAPAddress soapAddress = (SOAPAddress) WSDescriptorParser.getExtensibilityElement(SOAPAddress.class,
port.getExtensibilityElements());
+        String locationURIString = soapAddress.getLocationURI();
+        URL location = null;
+        try {
+            location = new URL(locationURIString);
+        } catch (MalformedURLException e) {
+            throw new DeploymentException("Could not construct web service location URL from
" + locationURIString);
+        }
+        return location;
+    }
+}

Added: geronimo/trunk/modules/axis-builder/src/java/org/apache/geronimo/axis/builder/ReadOnlyServiceDesc.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/axis-builder/src/java/org/apache/geronimo/axis/builder/ReadOnlyServiceDesc.java?view=auto&rev=156300
==============================================================================
--- geronimo/trunk/modules/axis-builder/src/java/org/apache/geronimo/axis/builder/ReadOnlyServiceDesc.java
(added)
+++ geronimo/trunk/modules/axis-builder/src/java/org/apache/geronimo/axis/builder/ReadOnlyServiceDesc.java
Sun Mar  6 02:01:20 2005
@@ -0,0 +1,190 @@
+/**
+ *
+ * Copyright 2004 The Apache Software Foundation
+ *
+ *  Licensed 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.geronimo.axis.builder;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.apache.axis.description.JavaServiceDesc;
+import org.apache.axis.description.OperationDesc;
+import org.apache.axis.encoding.TypeMapping;
+import org.apache.axis.encoding.TypeMappingRegistry;
+import org.apache.axis.constants.Style;
+import org.apache.axis.constants.Use;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ReadOnlyServiceDesc extends JavaServiceDesc {
+    private final JavaServiceDesc serviceDesc;
+
+    public ReadOnlyServiceDesc(JavaServiceDesc serviceDesc) {
+        this.serviceDesc = serviceDesc;
+    }
+
+    public Class getImplClass() {
+        return serviceDesc.getImplClass();
+    }
+
+    public void setImplClass(Class implClass) {
+        serviceDesc.setImplClass(implClass);
+    }
+
+    public ArrayList getStopClasses() {
+        return serviceDesc.getStopClasses();
+    }
+
+    public void setStopClasses(ArrayList stopClasses) {        }
+
+    public void loadServiceDescByIntrospection()
+    {
+        serviceDesc.loadServiceDescByIntrospection();
+    }
+
+    public void loadServiceDescByIntrospection(Class implClass) {
+        serviceDesc.loadServiceDescByIntrospection(implClass);
+    }
+
+    public void loadServiceDescByIntrospection(Class cls, TypeMapping tm)
+    {
+        serviceDesc.loadServiceDescByIntrospection(cls, tm);
+    }
+
+    public Style getStyle() {
+        return serviceDesc.getStyle();
+    }
+
+    public void setStyle(Style style) {
+    }
+
+    public Use getUse() {
+        return serviceDesc.getUse();
+    }
+
+    public void setUse(Use use) {
+    }
+
+    public String getWSDLFile() {
+        return serviceDesc.getWSDLFile();
+    }
+
+    public void setWSDLFile(String wsdlFileName) {
+    }
+
+    public List getAllowedMethods() {
+        return serviceDesc.getAllowedMethods();
+    }
+
+    public void setAllowedMethods(List allowedMethods) {
+    }
+
+    public TypeMapping getTypeMapping() {
+        return serviceDesc.getTypeMapping();
+    }
+
+    public void setTypeMapping(TypeMapping tm) {
+    }
+
+    public String getName() {
+        return serviceDesc.getName();
+    }
+
+    public void setName(String name) {
+    }
+
+    public String getDocumentation() {
+        return serviceDesc.getDocumentation();
+    }
+
+    public void setDocumentation(String documentation) {
+    }
+
+    public void removeOperationDesc(OperationDesc operation) {
+    }
+
+    public void addOperationDesc(OperationDesc operation) {
+    }
+
+    public ArrayList getOperations() {
+        return serviceDesc.getOperations();
+    }
+
+    public OperationDesc [] getOperationsByName(String methodName) {
+        return serviceDesc.getOperationsByName(methodName);
+    }
+
+    public OperationDesc getOperationByName(String methodName) {
+        return serviceDesc.getOperationByName(methodName);
+    }
+
+    public OperationDesc getOperationByElementQName(QName qname) {
+        return serviceDesc.getOperationByElementQName(qname);
+    }
+
+    public OperationDesc [] getOperationsByQName(QName qname) {
+        return serviceDesc.getOperationsByQName(qname);
+    }
+
+    public void setNamespaceMappings(List namespaces) {
+    }
+
+    public String getDefaultNamespace() {
+        return serviceDesc.getDefaultNamespace();
+    }
+
+    public void setDefaultNamespace(String namespace) {
+    }
+
+    public void setProperty(String name, Object value) {
+        serviceDesc.setProperty(name, value);
+    }
+
+    public Object getProperty(String name) {
+        return serviceDesc.getProperty(name);
+    }
+
+    public String getEndpointURL() {
+        return serviceDesc.getEndpointURL();
+    }
+
+    public void setEndpointURL(String endpointURL) {
+    }
+
+    public TypeMappingRegistry getTypeMappingRegistry() {
+        return serviceDesc.getTypeMappingRegistry();
+    }
+
+    public void setTypeMappingRegistry(TypeMappingRegistry tmr) {
+    }
+
+    public boolean isInitialized() {
+        return serviceDesc.isInitialized();
+    }
+
+    public boolean isWrapped() {
+        return serviceDesc.isWrapped();
+    }
+
+    public List getDisallowedMethods() {
+        return serviceDesc.getDisallowedMethods();
+    }
+
+    public void setDisallowedMethods(List disallowedMethods) {
+    }
+}



Mime
View raw message