You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beehive.apache.org by ek...@apache.org on 2006/01/21 22:55:43 UTC
svn commit: r371120 - in /beehive/trunk/wsm:
src/axis/org/apache/beehive/wsm/axis/
src/axis/org/apache/beehive/wsm/axis/handlers/
src/core/org/apache/beehive/wsm/exception/
src/core/org/apache/beehive/wsm/processor/generator/axis/
src/core/org/apache/b...
Author: ekoneil
Date: Sat Jan 21 13:55:35 2006
New Revision: 371120
URL: http://svn.apache.org/viewcvs?rev=371120&view=rev
Log:
Checkpoint the WSM work to produce an XML file that describes the mapping between a WSM web service (Java class) and a WSDL. This is wired up at build time but isn't consumed at runtime yet. The latter work is started but is more complex than I initially thought and is in great part commented out in ServiceDescriptionFactory. Will continue this work after the 1.0.1 Beehive release is complete.
BB: self
Test: WSM && WSC pass
Added:
beehive/trunk/wsm/src/core/org/apache/beehive/wsm/exception/ConfigurationException.java (with props)
beehive/trunk/wsm/src/core/org/apache/beehive/wsm/processor/model/factory/mirror/MirrorWsmBuilder.java (with props)
beehive/trunk/wsm/src/core/org/apache/beehive/wsm/util/WsmddUtils.java (with props)
Removed:
beehive/trunk/wsm/src/core/org/apache/beehive/wsm/processor/model/factory/mirror/MirrorFactoryImpl.java
Modified:
beehive/trunk/wsm/src/axis/org/apache/beehive/wsm/axis/ServiceDescriptionFactory.java
beehive/trunk/wsm/src/axis/org/apache/beehive/wsm/axis/handlers/AnnotatedWebServiceDeploymentHandler.java
beehive/trunk/wsm/src/core/org/apache/beehive/wsm/processor/generator/axis/AxisGenerator.java
beehive/trunk/wsm/src/core/org/apache/beehive/wsm/processor/model/factory/WsmServiceStyleFactory.java
beehive/trunk/wsm/test/src/junit/org/apache/beehive/wsm/test/axis/AxisHookTest.java
Modified: beehive/trunk/wsm/src/axis/org/apache/beehive/wsm/axis/ServiceDescriptionFactory.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/wsm/src/axis/org/apache/beehive/wsm/axis/ServiceDescriptionFactory.java?rev=371120&r1=371119&r2=371120&view=diff
==============================================================================
--- beehive/trunk/wsm/src/axis/org/apache/beehive/wsm/axis/ServiceDescriptionFactory.java (original)
+++ beehive/trunk/wsm/src/axis/org/apache/beehive/wsm/axis/ServiceDescriptionFactory.java Sat Jan 21 13:55:35 2006
@@ -22,7 +22,6 @@
import java.util.List;
import java.util.Map;
import java.util.Iterator;
-import java.util.Collection;
import javax.jws.WebParam;
import javax.jws.soap.SOAPBinding;
import javax.wsdl.OperationType;
@@ -58,6 +57,7 @@
import org.apache.beehive.wsm.model.WsmSoapBinding;
import org.apache.beehive.wsm.model.WsmService;
import org.apache.beehive.wsm.exception.InvalidTypeMappingException;
+import org.apache.beehive.wsm.exception.ConfigurationException;
import org.apache.beehive.wsm.util.JavaClassUtils;
import org.apache.beehive.wsm.util.TypeUtils;
import org.apache.beehive.wsm.util.TypeMappingConstants;
@@ -140,27 +140,26 @@
* directly. The introspected OperationDesc and ParameterDescs are
* overrided by WSM. When appropriate type mapping registry is set, Axis
* fills the ParameterDesc's typeEntry from the preset typemapping
- * registry, which is required for Axis to work in wrapped/lit mode.
*/
/* todo: does this configure the service correctly? */
axisServiceDesc.getOperations();
for(int i = 0; i < operations.size(); i++) {
- WsmOperation wsmOperationDesc = (WsmOperation)operations.get(i);
- String operationName = wsmOperationDesc.getOperationName();
+ WsmOperation wsmOperation = (WsmOperation)operations.get(i);
+ String operationName = wsmOperation.getOperationName();
- OperationDesc axisOperationDesc = getOperationDesc(axisServiceDesc, wsmOperationDesc);
+ OperationDesc axisOperationDesc = getOperationDesc(axisServiceDesc, wsmOperation);
assert axisOperationDesc != null : "Can not find method: " + operationName + " in webservice";
/*
Configure the method. This uses a combination of the metadata processed from a WSM
interface / implementation to further configure an Axis OperationDesc object.
*/
- axisOperationDesc.setElementQName(new QName(targetNamespace, operationName));
axisOperationDesc.setName(operationName);
- axisOperationDesc.setSoapAction(wsmOperationDesc.getAction());
+ axisOperationDesc.setElementQName(new QName(targetNamespace, operationName));
+ axisOperationDesc.setSoapAction(wsmOperation.getAction());
- if(wsmOperationDesc.isOneWay())
+ if(wsmOperation.isOneWay())
axisOperationDesc.setMep(OperationType.ONE_WAY);
else {
String namespace = "";
@@ -169,13 +168,13 @@
RPC style doesn't need name space for return type.
*/
if(wsmServiceDesc.getSoapBinding().getStyle() == SOAPBinding.Style.DOCUMENT)
- namespace = wsmOperationDesc.getTargetNamespace();
+ namespace = wsmOperation.getTargetNamespace();
- axisOperationDesc.setReturnQName(new QName(namespace, wsmOperationDesc.getName()));
+ axisOperationDesc.setReturnQName(new QName(namespace, wsmOperation.getName()));
QName qn = null;
QName odReturnType = axisOperationDesc.getReturnType();
- final Class returnType = createClass(wsmOperationDesc.getJavaReturnType());
+ final Class returnType = createClass(wsmOperation.getJavaReturnType());
/*
if we are processing an rpc encoded service, and the qname of the return type
@@ -193,9 +192,8 @@
if (qn == null) {
Class type = returnType;
- if (type.isArray()) {
+ if (type.isArray())
type = type.getComponentType();
- }
if(isActivationEnabled() && java.awt.Image.class.isAssignableFrom(type)) {
/* no-op: Axis will have already set value correctly */
@@ -204,7 +202,7 @@
/* no-op: Axis will have already set the value correctly */
}
else {
- qn = configureTypeMapping(axisServiceDesc, returnType, wsmOperationDesc.getTargetNamespace());
+ qn = configureTypeMapping(axisServiceDesc, returnType, wsmOperation.getTargetNamespace());
axisOperationDesc.setReturnType(qn);
axisOperationDesc.setReturnClass(returnType);
}
@@ -214,14 +212,28 @@
axisOperationDesc.getReturnParamDesc().setItemQName(new QName("", "item"));
}
+ /* todo: calculate the Java method given the parameters */
+ List wsmParameters = wsmOperation.getParameters();
+ Method javaMethod = axisOperationDesc.getMethod();
+ /*
+ // new
+ String javaMethodName = wsmOperation.getJavaMethodName();
+ Method javaMethod = lookupJavaMethod(serviceClass, javaMethodName, wsmParameters);
+ axisOperationDesc.setMethod(javaMethod);
+ */
+
/*
Configure method parameters. This uses a combination of the metadata processed from the
service interface / implementation to further configure the parameters Axis has already
configured.
*/
- List wsmParameters = wsmOperationDesc.getParameters();
for(int j = 0; j < wsmParameters.size(); j++) {
WsmParameter wsmParameterDesc = (WsmParameter)wsmParameters.get(j);
+
+ // new
+ //ParameterDesc axisParameterDesc = new ParameterDesc();
+
+ // old
ParameterDesc axisParameterDesc = axisOperationDesc.getParameter(j);
final Class paramType = createClass(wsmParameterDesc.getJavaType());
@@ -271,12 +283,14 @@
throw new IllegalArgumentException("Illegal value for WebParam.Mode: " + mode);
}
axisParameterDesc.setJavaType(paramType);
+
+ // new
+ //axisOperationDesc.addParameter(axisParameterDesc);
}
/*
Configure faults.
*/
- Method javaMethod = axisOperationDesc.getMethod();
for(Class thrown : javaMethod.getExceptionTypes()) {
FaultDesc fd = axisOperationDesc.getFaultByClass(thrown);
@@ -289,7 +303,7 @@
continue;
}
- QName qname = configureTypeMapping(axisServiceDesc, thrown, wsmOperationDesc.getTargetNamespace());
+ QName qname = configureTypeMapping(axisServiceDesc, thrown, wsmOperation.getTargetNamespace());
fd.setXmlType(qname);
fd.setQName(qname);
fd.setComplex(true);
@@ -329,6 +343,46 @@
serviceDesc.setStyle(Style.WRAPPED);
else serviceDesc.setStyle(Style.DOCUMENT);
}
+ }
+
+ /**
+ *
+ * @param implementationClass
+ * @param methodName
+ * @param wsmParameters
+ * @return the {@link Method} object from the class that matches the given method name and parameter descriptions
+ */
+ private Method lookupJavaMethod(Class implementationClass, String methodName, List wsmParameters) {
+ Method javaMethod = null;
+ try {
+ if(wsmParameters == null || wsmParameters.size() == 0)
+ javaMethod = implementationClass.getMethod(methodName, null);
+ else {
+ Class parameterTypes[] = new Class[wsmParameters.size()];
+ for(int i = 0; i < wsmParameters.size(); i++) {
+ WsmParameter wsmParameter = (WsmParameter)wsmParameters.get(i);
+ /*
+ Ensure that the parameter types exist
+ */
+ try {
+ parameterTypes[i] = Class.forName(wsmParameter.getJavaType());
+ }
+ catch(ClassNotFoundException e) {
+ throw new ConfigurationException("Unable to load parameter type \"" +
+ wsmParameter.getJavaType() + "\" for method \"" + methodName + "\"");
+ }
+ }
+
+ javaMethod = implementationClass.getMethod(methodName, parameterTypes);
+ }
+ }
+ catch(NoSuchMethodException e) {
+ throw new ConfigurationException("Unable to find method \"" + methodName + "\"");
+ }
+
+ if(javaMethod != null)
+ return javaMethod;
+ else throw new ConfigurationException("Unable to find method \"" + methodName + "\"");
}
/**
Modified: beehive/trunk/wsm/src/axis/org/apache/beehive/wsm/axis/handlers/AnnotatedWebServiceDeploymentHandler.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/wsm/src/axis/org/apache/beehive/wsm/axis/handlers/AnnotatedWebServiceDeploymentHandler.java?rev=371120&r1=371119&r2=371120&view=diff
==============================================================================
--- beehive/trunk/wsm/src/axis/org/apache/beehive/wsm/axis/handlers/AnnotatedWebServiceDeploymentHandler.java (original)
+++ beehive/trunk/wsm/src/axis/org/apache/beehive/wsm/axis/handlers/AnnotatedWebServiceDeploymentHandler.java Sat Jan 21 13:55:35 2006
@@ -24,6 +24,7 @@
import java.util.List;
import java.util.Map;
import java.io.IOException;
+import java.io.InputStream;
import javax.xml.namespace.QName;
import javax.xml.rpc.handler.HandlerInfo;
@@ -44,6 +45,7 @@
import org.apache.beehive.wsm.model.WsmService;
import org.apache.beehive.wsm.model.jsr181.Jsr181ObjectModelStore;
import org.apache.beehive.wsm.exception.InvalidTypeMappingException;
+import org.apache.beehive.wsm.util.WsmddUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -102,36 +104,52 @@
SOAPService axisService = _soapServices.get(clazz.getName());
if(axisService == null) {
+
+ /*
+ InputStream inputStream = null;
+ */
WsmService wsmService = null;
try {
wsmService = Jsr181ObjectModelStore.load(clazz);
+/*
+ String wsmddName = clazz.getName().replace('.', '/') + ".xml";
+ System.out.println("load WsmService using path: " + wsmddName);
+
+ ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ inputStream = classLoader.getResourceAsStream(wsmddName);
+
+ wsmService = WsmddUtils.read(inputStream);
+*/
}
- catch (IOException e) {
+ catch (Exception e) {
throw new IllegalStateException("Unable to load metadata for service \"" +
clazz.getName() + "\". Cause: " + e, e);
}
- catch (ClassNotFoundException e) {
- throw new IllegalStateException("Unable to load metadata for service \"" +
- clazz.getName() + "\". Cause: " + e, e);
+/*
+ finally {
+ if(inputStream != null)
+ try{inputStream.close();}catch(IOException ignore) {}
}
+*/
+
axisService = createSOAPService(wsmService, clazz);
}
assert axisService != null;
return axisService;
}
- private SOAPService createSOAPService(WsmService wsm, Class cls) {
+ private SOAPService createSOAPService(WsmService wsmService, Class cls) {
- assert wsm != null : "Unable to create SOAPService since the WSM object model is null";
+ assert wsmService != null : "Unable to create SOAPService since the WSM object model is null";
/* todo: wire-up the ControlProvider as a handler. is that possible? */
SOAPService axisSoapService = new SOAPService(null, new ControlProvider(), null);
/* add jaxrpc handlers if there are any. */
- HandlerInfoChainFactory jaxrpcHandlerChain = configureJaxRpcHandlerChainFactory(wsm);
+ HandlerInfoChainFactory jaxrpcHandlerChain = configureJaxRpcHandlerChainFactory(wsmService);
if(jaxrpcHandlerChain != null)
axisSoapService.setOption(Constants.ATTR_HANDLERINFOCHAIN, jaxrpcHandlerChain);
- axisSoapService.setName(wsm.getName());
+ axisSoapService.setName(wsmService.getName());
axisSoapService.setOption(RPCProvider.OPTION_CLASSNAME, cls.getName());
/* Take the setting for the scope option from the handler parameter named "scope" */
@@ -142,15 +160,15 @@
axisSoapService.setOption(RPCProvider.OPTION_SCOPE, scope);
ServiceDesc axisServiceDesc = null;
try {
- axisServiceDesc = ServiceDescriptionFactory.getInstance().createServiceDescription(wsm, cls.getClassLoader());
+ axisServiceDesc = ServiceDescriptionFactory.getInstance().createServiceDescription(wsmService, cls.getClassLoader());
}
catch(ClassNotFoundException e) {
throw new IllegalStateException("Unable to create service description for web service in class \""
- + wsm.getServiceClassName() + "\". Cause: " + e, e);
+ + wsmService.getServiceClassName() + "\". Cause: " + e, e);
}
catch(InvalidTypeMappingException e) {
throw new IllegalStateException("Unable to create service description for web service in class \""
- + wsm.getServiceClassName() + "\". Cause: " + e, e);
+ + wsmService.getServiceClassName() + "\". Cause: " + e, e);
}
axisSoapService.setServiceDescription(axisServiceDesc);
@@ -164,10 +182,10 @@
}
axisSoapService.setOption(RPCProvider.OPTION_ALLOWEDMETHODS, sb.toString());
- axisSoapService.setOption(RPCProvider.OPTION_WSDL_PORTTYPE, wsm.getName());
- axisSoapService.setOption(RPCProvider.OPTION_WSDL_SERVICEPORT, wsm.getName());
- axisSoapService.setOption(RPCProvider.OPTION_WSDL_SERVICEELEMENT, wsm.getServiceName());
- axisSoapService.setOption(RPCProvider.OPTION_WSDL_TARGETNAMESPACE, wsm.getTargetNamespace());
+ axisSoapService.setOption(RPCProvider.OPTION_WSDL_PORTTYPE, wsmService.getName());
+ axisSoapService.setOption(RPCProvider.OPTION_WSDL_SERVICEPORT, wsmService.getName());
+ axisSoapService.setOption(RPCProvider.OPTION_WSDL_SERVICEELEMENT, wsmService.getServiceName());
+ axisSoapService.setOption(RPCProvider.OPTION_WSDL_TARGETNAMESPACE, wsmService.getTargetNamespace());
axisSoapService.setStyle(axisServiceDesc.getStyle());
axisSoapService.setUse(axisServiceDesc.getUse());
_soapServices.put(cls.getName(), axisSoapService);
Added: beehive/trunk/wsm/src/core/org/apache/beehive/wsm/exception/ConfigurationException.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/wsm/src/core/org/apache/beehive/wsm/exception/ConfigurationException.java?rev=371120&view=auto
==============================================================================
--- beehive/trunk/wsm/src/core/org/apache/beehive/wsm/exception/ConfigurationException.java (added)
+++ beehive/trunk/wsm/src/core/org/apache/beehive/wsm/exception/ConfigurationException.java Sat Jan 21 13:55:35 2006
@@ -0,0 +1,40 @@
+/*
+ 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.
+
+ $Header:$
+*/
+package org.apache.beehive.wsm.exception;
+
+/**
+ *
+ */
+public class ConfigurationException
+ extends RuntimeException {
+
+ public ConfigurationException() {
+ }
+
+ public ConfigurationException(String message) {
+ super(message);
+ }
+
+ public ConfigurationException(Throwable cause) {
+ super(cause);
+ }
+
+ public ConfigurationException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
Propchange: beehive/trunk/wsm/src/core/org/apache/beehive/wsm/exception/ConfigurationException.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: beehive/trunk/wsm/src/core/org/apache/beehive/wsm/processor/generator/axis/AxisGenerator.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/wsm/src/core/org/apache/beehive/wsm/processor/generator/axis/AxisGenerator.java?rev=371120&r1=371119&r2=371120&view=diff
==============================================================================
--- beehive/trunk/wsm/src/core/org/apache/beehive/wsm/processor/generator/axis/AxisGenerator.java (original)
+++ beehive/trunk/wsm/src/core/org/apache/beehive/wsm/processor/generator/axis/AxisGenerator.java Sat Jan 21 13:55:35 2006
@@ -17,9 +17,15 @@
*/
package org.apache.beehive.wsm.processor.generator.axis;
+import java.io.InputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.PrintWriter;
+
import com.sun.mirror.declaration.TypeDeclaration;
import com.sun.mirror.util.SourcePosition;
import com.sun.mirror.apt.AnnotationProcessorEnvironment;
+import com.sun.mirror.apt.Filer;
import org.apache.beehive.wsm.model.WsmService;
import org.apache.beehive.wsm.model.jsr181.Jsr181ObjectModelStore;
import org.apache.beehive.wsm.processor.model.factory.WsmServiceStyleFactory;
@@ -27,6 +33,8 @@
import org.apache.beehive.wsm.processor.model.factory.TypeResolver;
import org.apache.beehive.wsm.processor.model.factory.mirror.MirrorTypeResolver;
import org.apache.beehive.wsm.processor.generator.WsmResourceGenerator;
+import org.apache.beehive.wsm.util.WsmddUtils;
+import org.apache.beehive.wsm.exception.CodeGenerationException;
public class AxisGenerator
extends WsmResourceGenerator {
@@ -43,10 +51,6 @@
WsmServiceFactory factory =
WsmServiceStyleFactory.create(WsmServiceStyleFactory.FactoryType.MIRROR);
- /* todo: there needs to be an environmental abstraction for resolving types from
- a reflection client / environment and a Mirror client / environment
- */
-
String serviceBeanClassName = typeDecl.getQualifiedName();
TypeResolver typeResolver = MirrorTypeResolver.getInstance(env);
@@ -55,8 +59,31 @@
typeResolver,
position.file().getParent());
- /* serialize WsmService model to XML */
-
+ /* todo: delete this... */
Jsr181ObjectModelStore.store(env, wsmService);
+
+ String implementationClass = wsmService.getServiceClassName();
+ int lastDot = implementationClass.lastIndexOf(".");
+ if(lastDot == -1)
+ lastDot = 0;
+
+ String packageName = implementationClass.substring(0, lastDot);
+ String fileName = implementationClass.substring(lastDot+1, implementationClass.length()) + ".xml";
+
+ PrintWriter printWriter = null;
+ try {
+ Filer filer = env.getFiler();
+ printWriter = filer.createTextFile(Filer.Location.CLASS_TREE, packageName, new File(fileName), null);
+
+ WsmddUtils.write(wsmService, printWriter);
+ printWriter.close();
+ }
+ catch(IOException io) {
+ throw new CodeGenerationException("Unable to create file WSM deployment descriptor. Cause: " + io, io);
+ }
+ finally {
+ if(printWriter != null)
+ printWriter.close();
+ }
}
}
Modified: beehive/trunk/wsm/src/core/org/apache/beehive/wsm/processor/model/factory/WsmServiceStyleFactory.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/wsm/src/core/org/apache/beehive/wsm/processor/model/factory/WsmServiceStyleFactory.java?rev=371120&r1=371119&r2=371120&view=diff
==============================================================================
--- beehive/trunk/wsm/src/core/org/apache/beehive/wsm/processor/model/factory/WsmServiceStyleFactory.java (original)
+++ beehive/trunk/wsm/src/core/org/apache/beehive/wsm/processor/model/factory/WsmServiceStyleFactory.java Sat Jan 21 13:55:35 2006
@@ -45,7 +45,7 @@
String className = null;
if(factoryType == FactoryType.MIRROR)
- className = "org.apache.beehive.wsm.processor.model.factory.mirror.MirrorFactoryImpl";
+ className = "org.apache.beehive.wsm.processor.model.factory.mirror.MirrorWsmBuilder";
else throw new IllegalArgumentException("Can not create factory of type " + factoryType);
WsmServiceFactory factory = null;
Added: beehive/trunk/wsm/src/core/org/apache/beehive/wsm/processor/model/factory/mirror/MirrorWsmBuilder.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/wsm/src/core/org/apache/beehive/wsm/processor/model/factory/mirror/MirrorWsmBuilder.java?rev=371120&view=auto
==============================================================================
--- beehive/trunk/wsm/src/core/org/apache/beehive/wsm/processor/model/factory/mirror/MirrorWsmBuilder.java (added)
+++ beehive/trunk/wsm/src/core/org/apache/beehive/wsm/processor/model/factory/mirror/MirrorWsmBuilder.java Sat Jan 21 13:55:35 2006
@@ -0,0 +1,364 @@
+/*
+ * 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.
+ *
+ * $Header:$
+ */
+package org.apache.beehive.wsm.processor.model.factory.mirror;
+
+import java.io.File;
+import java.io.InputStream;
+import java.io.IOException;
+import java.net.URL;
+import java.net.MalformedURLException;
+import java.util.Iterator;
+import java.util.List;
+import javax.jws.WebService;
+import javax.jws.WebMethod;
+import javax.jws.Oneway;
+import javax.jws.WebResult;
+import javax.jws.WebParam;
+import javax.jws.HandlerChain;
+import javax.jws.soap.SOAPBinding;
+import javax.jws.soap.SOAPMessageHandler;
+import javax.jws.soap.SOAPMessageHandlers;
+import javax.jws.soap.InitParam;
+
+import com.sun.mirror.declaration.TypeDeclaration;
+import com.sun.mirror.declaration.MethodDeclaration;
+import com.sun.mirror.declaration.ParameterDeclaration;
+import com.sun.mirror.declaration.Modifier;
+
+import org.apache.beehive.wsm.processor.model.factory.WsmServiceFactory;
+import org.apache.beehive.wsm.processor.model.factory.TypeResolver;
+import org.apache.beehive.wsm.model.WsmService;
+import org.apache.beehive.wsm.model.WsmOperation;
+import org.apache.beehive.wsm.model.WsmParameter;
+import org.apache.beehive.wsm.model.WsmSoapBinding;
+import org.apache.beehive.wsm.model.WsmSoapMessageHandler;
+import org.apache.beehive.wsm.exception.Jsr181ValidationException;
+import org.apache.beehive.wsm.exception.IllegalHandlerConfigException;
+import org.apache.beehive.wsm.util.HandlerChainParser;
+
+/**
+ * This class is used to create a {@link WsmService} object model given
+ * type metadata available via Java 5's annotation processing infrastructure. The
+ * Mirror classes provide the type system used to read annotations at bulid time.
+ *
+ * This class will work on TypeDeclarations (a Mirror representation of a Class, Interface, etc)
+ * to read annotations and other processed type metadata such as methods, parameters, etc. The
+ * combination of a TypeDeclaration and "Mirror"-ed metadata is processed into the WsmService
+ * object model.
+ *
+ * The client is responsible for performing code generation, serializing, etc the object model.
+ */
+public class MirrorWsmBuilder
+ extends WsmServiceFactory {
+
+ private static final String SERVICE_SUFFIX = "Service";
+ private static final String DEFAULT_WR_NAME = "return";
+
+ public WsmService create(String serviceBeanClassName,
+ TypeResolver typeResolver,
+ String baseLocation) {
+ WsmService wsMetadata = new WsmService();
+
+ TypeDeclaration implDecl = (TypeDeclaration)typeResolver.resolveType(serviceBeanClassName);
+
+ TypeDeclaration endpointDecl = null;
+ WebService webService = implDecl.getAnnotation(WebService.class);
+ if(webService.endpointInterface() != null && !webService.endpointInterface().equals(""))
+ endpointDecl = (TypeDeclaration)typeResolver.resolveType(webService.endpointInterface());
+
+ /* class-level annotations */
+ if(endpointDecl != null) {
+ processClass(wsMetadata, endpointDecl, baseLocation);
+
+ String serviceName = implDecl.getAnnotation(WebService.class).serviceName();
+ if(serviceName == null || serviceName.trim().length() == 0)
+ wsMetadata.setServiceName(implDecl.getSimpleName() + SERVICE_SUFFIX);
+ else wsMetadata.setServiceName(serviceName);
+
+ /* todo: what to do when the service impl has a WebService.endpointInterface annotation? */
+
+ wsMetadata.setServiceClassName(implDecl.getQualifiedName());
+
+ /* todo: verify that no additional annotations are visible on the implementation type */
+
+ /* process _all_ methods */
+ for(MethodDeclaration method : endpointDecl.getMethods())
+ processMethod(wsMetadata, method);
+ }
+ else {
+ processClass(wsMetadata, implDecl, baseLocation);
+
+ boolean allWebMethods = true;
+ for(MethodDeclaration method: implDecl.getMethods())
+ if(method.getAnnotation(WebMethod.class) != null)
+ allWebMethods = false;
+
+ /* process the @WebMethods */
+ for(MethodDeclaration method : implDecl.getMethods()) {
+ /*
+ In the case that a class doesn't have any @WebMethod annotations, all web methods
+ except those matching method names / signatures matching those inherited from
+ java.lang.Object are exposed as @WebMethods
+ */
+ if(allWebMethods && acceptWebMethod(method, typeResolver))
+ processMethod(wsMetadata, method);
+ else if(method.getAnnotation(WebMethod.class) != null)
+ processMethod(wsMetadata, method);
+ }
+ }
+
+ return wsMetadata;
+ }
+
+ private void processClass(WsmService wsMetadata, TypeDeclaration typeDecl, String baseLocation) {
+ WebService ws = typeDecl.getAnnotation(WebService.class);
+
+ wsMetadata.setServiceClassName(typeDecl.getQualifiedName());
+
+ if(ws.name().trim().length() == 0)
+ wsMetadata.setName(typeDecl.getSimpleName());
+ else wsMetadata.setName(ws.name());
+
+ if(ws.serviceName().trim().length() == 0)
+ wsMetadata.setServiceName(typeDecl.getSimpleName() + SERVICE_SUFFIX);
+ else wsMetadata.setServiceName(ws.serviceName());
+
+ if(ws.targetNamespace() == null || ws.targetNamespace().length() == 0)
+ wsMetadata.setTargetNamespace(computeTargetNamespace(typeDecl.getQualifiedName()));
+ else wsMetadata.setTargetNamespace(ws.targetNamespace());
+
+ /* assume that the wsdlLocation annotation has already been validated */
+ // todo: this JavaBean property doesn't seem like it's needed */
+ //wsMetadata.setWsdlLocation(ws.wsdlLocation());
+ //wsMetadata.setWsEndpointInterface(ws.endpointInterface());
+
+ /* annot: SOAPBinding.class */
+ SOAPBinding soapBinding = typeDecl.getAnnotation(SOAPBinding.class);
+ if(soapBinding != null) {
+ WsmSoapBinding soapBindingInfo = new WsmSoapBinding();
+ soapBindingInfo.setStyle(soapBinding.style());
+ soapBindingInfo.setUse(soapBinding.use());
+ soapBindingInfo.setParameterStyle(soapBinding.parameterStyle());
+ wsMetadata.setSoapBinding(soapBindingInfo);
+ }
+
+ /* annot: SOAPMessageHandlers.class */
+ /* todo: in the presence of both an endpoint interface and service implementation bean with a @SOAPMessageHandler
+ interface, the implementation's version wins */
+ SOAPMessageHandlers soapMessageHandlers = typeDecl.getAnnotation(SOAPMessageHandlers.class);
+ if(soapMessageHandlers != null) {
+ for(SOAPMessageHandler soapMessageHandlerAnnot : soapMessageHandlers.value()) {
+ WsmSoapMessageHandler soapMessageHandlerInfo = new WsmSoapMessageHandler();
+
+ String className = soapMessageHandlerAnnot.className();
+ soapMessageHandlerInfo.setClassName(className);
+
+ if(soapMessageHandlerAnnot.name() != null && soapMessageHandlerAnnot.name().length() > 0)
+ soapMessageHandlerInfo.setName(soapMessageHandlerAnnot.name());
+ else soapMessageHandlerInfo.setName(className);
+
+ for(InitParam p : soapMessageHandlerAnnot.initParams())
+ soapMessageHandlerInfo.addInitParam(p.name(), p.value());
+
+ String[] roles = soapMessageHandlerAnnot.roles();
+ for(String role : roles)
+ soapMessageHandlerInfo.addRole(role);
+
+ for(String header : soapMessageHandlerAnnot.headers())
+ soapMessageHandlerInfo.addHeader(header);
+
+ wsMetadata.addSoapHandler(soapMessageHandlerInfo);
+ }
+ }
+
+ /* annot: HandlerChain.class */
+ /* todo: in the presence of both an endpoint interface and service implementation bean with a @HandlerChain
+ interface, the implementation's version wins */
+ HandlerChain handlerChain = typeDecl.getAnnotation(HandlerChain.class);
+ if(handlerChain != null)
+ configureHandlerChain(handlerChain, wsMetadata, baseLocation);
+ }
+
+ private void processMethod(WsmService wsMetadata, MethodDeclaration methodDecl) {
+ if(!methodDecl.getModifiers().contains(Modifier.PUBLIC))
+ return;
+
+ WebMethod webMethod = methodDecl.getAnnotation(WebMethod.class);
+ String methodName = methodDecl.getSimpleName();
+
+ WsmOperation wsMethod = new WsmOperation();
+ wsMethod.setJavaReturnType(methodDecl.getReturnType().toString());
+ wsMethod.setJavaMethodName(methodName);
+ wsMethod.setName(DEFAULT_WR_NAME);
+
+ WebResult webResult = methodDecl.getAnnotation(WebResult.class);
+ if(webResult != null) {
+ wsMethod.setName(webResult.name());
+ wsMethod.setTargetNamespace(webResult.targetNamespace());
+ }
+
+ Oneway oneway = methodDecl.getAnnotation(Oneway.class);
+ if(oneway != null) {
+ wsMethod.setOneWay(true);
+ }
+
+ if(webMethod != null) {
+ wsMethod.setAction(webMethod.action());
+ wsMethod.setOperationName(webMethod.operationName());
+ }
+
+ if(wsMethod.getOperationName() == null || wsMethod.getOperationName().length() == 0)
+ wsMethod.setOperationName(methodName);
+
+ if(wsMethod.getAction() == null || wsMethod.getAction().length() == 0)
+ wsMethod.setAction("");
+
+ /* fill-in the targetNamespace from the @WebService annotation */
+ /* todo: it seems that this information should come from the parent so that the targetNamespace
+ is stored in *exactly* one place rather than 1 + # of WebMethods
+ */
+ String webMethodNamespace = wsMethod.getTargetNamespace();
+ if(webMethodNamespace == null || webMethodNamespace.length() == 0)
+ wsMethod.setTargetNamespace(wsMetadata.getTargetNamespace());
+
+ for(ParameterDeclaration paramDecl : methodDecl.getParameters()) {
+ WsmParameter wsParam = new WsmParameter();
+
+ wsParam.setJavaType(paramDecl.getType().toString());
+ wsParam.setName(paramDecl.getSimpleName());
+ wsParam.setMode(WebParam.Mode.IN);
+
+ WebParam webParam = paramDecl.getAnnotation(WebParam.class);
+ if(webParam != null) {
+ if(!webParam.name().equals(""))
+ wsParam.setName(webParam.name());
+ wsParam.setTargetNamespace(webParam.targetNamespace());
+ wsParam.setMode(webParam.mode());
+ wsParam.setHeader(webParam.header());
+ }
+
+ String wpTargetNamespace = wsParam.getTargetNamespace();
+ if(wpTargetNamespace == null || wpTargetNamespace.length() == 0)
+ wsParam.setTargetNamespace(wsMetadata.getTargetNamespace());
+
+ wsMethod.addParameter(wsParam);
+ }
+
+ wsMetadata.addOperation(wsMethod);
+ }
+
+ /**
+ * Initialize the @HandlerChain from the provided annotation.
+ * @throws IllegalHandlerConfigException when the given file does not exist, is invalid, or some other runtime error occurs
+ * during processing.
+ */
+ private void configureHandlerChain(HandlerChain handlerChain, WsmService wsMetadata, String baseLocation) {
+ /*
+ todo: need to figure out if URLs are the right thing to use here. the spec says
+ that URLs are relative (at the time of processing) or absolute. how does
+ that affect the runtime? does it mean that the contents of this file need to be
+ processed and deployed with the service and that this file *isn't* parsed
+ at runtime?
+ */
+
+ String handlerChainFile = handlerChain.file();
+ String chainName = handlerChain.name();
+
+ URL chainConfigURL = findResource(baseLocation, handlerChainFile);
+ if(null == chainConfigURL)
+ throw new IllegalHandlerConfigException("Can not resolve relative URL: " +
+ handlerChainFile + " from directory: " + baseLocation);
+
+ if(null == chainName)
+ throw new Jsr181ValidationException("@HandlerChain: URL for handler-chain config required");
+
+ /* todo: the JSR 181 annotation validation needs to occurr extenrally to where this XML file is processed */
+ if(!wsMetadata.getSoapHandlers().isEmpty())
+ throw new Jsr181ValidationException("@HandlerChain: annotation doesn't allow for @SOAPMessageHandlers");
+
+ final String xmlResourcePath = chainConfigURL.toString();
+ InputStream xmlInputStream = null;
+ try {
+ xmlInputStream = chainConfigURL.openStream();
+
+ List soapHandlers = HandlerChainParser.getInstance().parse(xmlInputStream, xmlResourcePath);
+ for(int i = 0; i < soapHandlers.size(); i++) {
+ wsMetadata.addSoapHandler((WsmSoapMessageHandler)soapHandlers.get(i));
+ }
+ }
+ catch(Exception e) {
+ throw new IllegalHandlerConfigException("Exception parsing handler config file. Cause: " + e, e);
+ }
+ finally {
+ try {if(xmlInputStream != null) xmlInputStream.close();} catch(IOException ignore) {/**/}
+ }
+ }
+
+ private static URL findResource(String baseLocation, String resourceName) {
+ /* todo: compost up into a base class */
+ assert resourceName != null;
+
+ /* handle the URL case */
+ if(resourceName.startsWith("http://") || resourceName.startsWith("file://")) {
+ try {
+ return new URL(resourceName);
+ }
+ catch(MalformedURLException e) {
+ throw new Jsr181ValidationException("The resource URL '" + resourceName + "' could not be resolved.", e);
+ }
+ }
+ /* todo: handle absolute URLs. what would these be absolute to? */
+ /* handle the relative case */
+ else {
+ File file = new File(baseLocation, resourceName);
+ try {
+ return file.toURL();
+ }
+ catch(MalformedURLException e) {
+ throw new Jsr181ValidationException("The resource URL '" + resourceName +
+ "' could not be loaded from the base path '" + baseLocation + "'");
+ }
+ }
+ }
+
+ private static String computeTargetNamespace(String className) {
+ /* todo: compost up into a base class */
+ if(className == null || className.length() == 0)
+ return className;
+
+ String[] tokens = className.split("\\.");
+ String targetNamespace = tokens[0];
+ for(int i = 1; i <= tokens.length - 2; i++) {
+ targetNamespace = tokens[i] + "." + targetNamespace;
+ }
+ return "http://" + targetNamespace;
+ }
+
+ private boolean acceptWebMethod(MethodDeclaration webMethod, TypeResolver typeResolver) {
+ TypeDeclaration objectDecl = (TypeDeclaration)typeResolver.resolveType("java.lang.Object");
+
+ Iterator objectMethodsIterator = objectDecl.getMethods().iterator();
+ while(objectMethodsIterator.hasNext()) {
+ MethodDeclaration objectMethod = (MethodDeclaration)objectMethodsIterator.next();
+ if(objectMethod.getSimpleName().equals(webMethod.getSimpleName()))
+ return false;
+ }
+
+ return true;
+ }
+}
\ No newline at end of file
Propchange: beehive/trunk/wsm/src/core/org/apache/beehive/wsm/processor/model/factory/mirror/MirrorWsmBuilder.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: beehive/trunk/wsm/src/core/org/apache/beehive/wsm/util/WsmddUtils.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/wsm/src/core/org/apache/beehive/wsm/util/WsmddUtils.java?rev=371120&view=auto
==============================================================================
--- beehive/trunk/wsm/src/core/org/apache/beehive/wsm/util/WsmddUtils.java (added)
+++ beehive/trunk/wsm/src/core/org/apache/beehive/wsm/util/WsmddUtils.java Sat Jan 21 13:55:35 2006
@@ -0,0 +1,399 @@
+/*
+ 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.
+
+ $Header:$
+ */
+package org.apache.beehive.wsm.util;
+
+import java.io.InputStream;
+import java.io.PrintWriter;
+import java.util.Map;
+import java.util.Iterator;
+import java.util.List;
+import java.util.HashMap;
+import java.util.LinkedList;
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.jws.soap.SOAPBinding;
+import javax.jws.WebParam;
+
+import org.apache.beehive.wsm.model.WsmService;
+import org.apache.beehive.wsm.model.WsmOperation;
+import org.apache.beehive.wsm.model.WsmParameter;
+import org.apache.beehive.wsm.model.WsmSoapMessageHandler;
+import org.apache.beehive.wsm.model.WsmSoapBinding;
+import org.apache.beehive.wsm.exception.ConfigurationException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.SAXParseException;
+
+/**
+ *
+ */
+public final class WsmddUtils {
+
+ private static final Log LOG = LogFactory.getLog(WsmddUtils.class);
+
+ private WsmddUtils() {}
+
+ public static void write(WsmService service, PrintWriter printWriter) {
+ XmlWriter xmlWriter = new SimpleXmlWriter();
+
+ HashMap attributes = new HashMap(3);
+ attributes.put("xmlns", "http://beehive.apache.org/wsm/service/2006");
+ xmlWriter.startElement("wsmservice", attributes);
+
+ /* WsmService object */
+ xmlWriter.startElement("service", null);
+ xmlWriter.writeElement("name", null, service.getName());
+ xmlWriter.writeElement("servicename", null, service.getServiceName());
+ if(service.getPortName() != null)
+ xmlWriter.writeElement("portname", null, service.getPortName());
+ xmlWriter.writeElement("classname", null, service.getServiceClassName());
+ xmlWriter.writeElement("targetnamespace", null, service.getTargetNamespace());
+ xmlWriter.writeElement("wsdllocation", null, service.getWsdlLocation());
+
+ /* WsmSoapBinding */
+ xmlWriter.startElement("soapbinding", null);
+ xmlWriter.writeElement("style", null, service.getSoapBinding().getStyle());
+ xmlWriter.writeElement("use", null, service.getSoapBinding().getUse());
+ xmlWriter.writeElement("parameterstyle", null, service.getSoapBinding().getParameterStyle());
+ xmlWriter.endElement("soapbinding");
+
+ /* WsmOperations */
+ List operations = service.getOperations();
+ if(operations != null) {
+ xmlWriter.startElement("operations", null);
+ for(int i = 0; i < operations.size(); i++) {
+ WsmOperation operation = (WsmOperation)operations.get(i);
+ xmlWriter.startElement("operation", null);
+ xmlWriter.writeElement("name", null, operation.getName());
+ xmlWriter.writeElement("operationname", null, operation.getOperationName());
+ xmlWriter.writeElement("oneway", null, operation.isOneWay());
+ xmlWriter.writeElement("action", null, operation.getAction());
+ xmlWriter.writeElement("targetnamespace", null, operation.getTargetNamespace());
+ xmlWriter.writeElement("javamethodname", null, operation.getJavaMethodName());
+ xmlWriter.writeElement("javareturntype", null, operation.getJavaReturnType());
+ if(operation.getXmlReturnType() != null)
+ xmlWriter.writeElement("xmlreturntype", null, qnameToString(operation.getXmlReturnType()));
+
+ /* Wsm Parameter */
+ List parameters = operation.getParameters();
+ if(parameters != null) {
+ for(int j = 0; j < parameters.size(); j++) {
+ WsmParameter parameter = (WsmParameter)parameters.get(j);
+ xmlWriter.startElement("parameter", null);
+ xmlWriter.writeElement("name", null, parameter.getName());
+ xmlWriter.writeElement("targetnamespace", null, parameter.getTargetNamespace());
+ xmlWriter.writeElement("javatype", null, parameter.getJavaType());
+ if(parameter.getXmlType() != null)
+ xmlWriter.writeElement("xmltype", null, qnameToString(parameter.getXmlType()));
+ xmlWriter.writeElement("header", null, parameter.isHeader());
+ xmlWriter.writeElement("mode", null, parameter.getMode());
+ xmlWriter.endElement("parameter");
+ }
+ }
+
+ xmlWriter.endElement("operation");
+ }
+ xmlWriter.endElement("operations");
+ }
+
+ /* WsmSoapMessageHandler */
+ List handlers = service.getSoapHandlers();
+ if(handlers != null && handlers.size() > 0) {
+ xmlWriter.startElement("handlers", null);
+ for(int i = 0; i < handlers.size(); i++) {
+ WsmSoapMessageHandler handler = (WsmSoapMessageHandler)handlers.get(i);
+ xmlWriter.startElement("handler", null);
+
+ /* headers */
+ List headers = handler.getHeaders();
+ xmlWriter.startElement("headers", null);
+ for(int j = 0; j < headers.size(); i++) {
+ String header = (String)headers.get(i);
+ xmlWriter.writeElement("headers", null, header);
+ }
+ xmlWriter.endElement("headers");
+
+ /* roles */
+ List roles = handler.getRoles();
+ xmlWriter.startElement("roles", null);
+ for(int j = 0; j < headers.size(); i++) {
+ String role = (String)roles.get(i);
+ xmlWriter.writeElement("role", null, role);
+ }
+ xmlWriter.endElement("roles");
+
+ /* parameters */
+ Map parameters = handler.getParameterMap();
+ xmlWriter.startElement("parameters", null);
+ Iterator keys = parameters.keySet().iterator();
+ while(keys.hasNext()) {
+ String key = (String)keys.next();
+ String value = (String)parameters.get(key);
+ xmlWriter.startElement("parameter", null);
+ xmlWriter.writeElement("name", null, key);
+ xmlWriter.writeElement("value", null, value);
+ xmlWriter.endElement("parameter");
+ }
+ xmlWriter.endElement("parameters");
+
+ xmlWriter.endElement("handler");
+ }
+ xmlWriter.endElement("handlers");
+ }
+
+ xmlWriter.endElement("service");
+ xmlWriter.endElement("wsmservice");
+
+ printWriter.append(xmlWriter.toString());
+ }
+
+ public static WsmService read(InputStream xmlInputStream) {
+ Document document = null;
+ try {
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ dbf.setValidating(false);
+ dbf.setNamespaceAware(false);
+
+ DocumentBuilder db = dbf.newDocumentBuilder();
+ db.setErrorHandler(new ErrorHandler() {
+ public void warning(SAXParseException exception) {
+ if (LOG.isWarnEnabled())
+ LOG.warn("Error parsing document. Cause: " + exception, exception);
+ }
+
+ public void error(SAXParseException exception) {
+ if (LOG.isErrorEnabled())
+ LOG.error("Error parsing document. Cause: " + exception, exception);
+ }
+
+ public void fatalError(SAXParseException exception) {
+ if (LOG.isFatalEnabled())
+ LOG.fatal("Error parsing document. Cause: " + exception, exception);
+ }
+ });
+
+ document = db.parse(xmlInputStream);
+ }
+ catch (Exception e) {
+ assert e instanceof ParserConfigurationException;
+ throw new IllegalStateException("Exception occurred parsing document. Cause: " + e, e);
+ }
+
+ assert document != null;
+
+ WsmService wsmService = new WsmService();
+ Element rootElement = DomUtils.getChildElementByName(document.getDocumentElement(), "service");
+
+ /* WsmService */
+ wsmService.setName(DomUtils.getChildElementText(rootElement, "name"));
+ wsmService.setServiceName(DomUtils.getChildElementText(rootElement, "servicename"));
+ wsmService.setPortName(DomUtils.getChildElementText(rootElement, "portname"));
+ wsmService.setTargetNamespace(DomUtils.getChildElementText(rootElement, "targetnamespace"));
+ wsmService.setServiceClassName(DomUtils.getChildElementText(rootElement, "classname"));
+
+ /* WsmSoapBinding */
+ WsmSoapBinding wsmSoapBinding = new WsmSoapBinding();
+ wsmService.setSoapBinding(wsmSoapBinding);
+
+ Element soapBindingElement = DomUtils.getChildElementByName(rootElement, "soapbinding");
+ wsmSoapBinding.setStyle(stringToStyle(DomUtils.getChildElementText(soapBindingElement, "style")));
+ wsmSoapBinding.setUse(stringToUse(DomUtils.getChildElementText(soapBindingElement, "use")));
+ wsmSoapBinding.setParameterStyle(stringToParameterStyle(DomUtils.getChildElementText(soapBindingElement, "parameterstyle")));
+
+ /* WsmOperation */
+ Element operationsElement = DomUtils.getChildElementByName(rootElement, "operations");
+ NodeList operationsList = operationsElement.getElementsByTagName("operation");
+ for (int i = 0; i < operationsList.getLength(); i++) {
+ Element operationElement = (Element)operationsList.item(i);
+ WsmOperation wsmOperation = new WsmOperation();
+ wsmOperation.setName(DomUtils.getChildElementText(operationElement, "name"));
+ wsmOperation.setOperationName(DomUtils.getChildElementText(operationElement, "operationname"));
+ wsmOperation.setOneWay(Boolean.parseBoolean(DomUtils.getChildElementText(operationElement, "oneway")));
+ wsmOperation.setAction(DomUtils.getChildElementText(operationElement, "action"));
+ wsmOperation.setTargetNamespace(DomUtils.getChildElementText(operationElement, "targetnamespace"));
+ wsmOperation.setJavaMethodName(DomUtils.getChildElementText(operationElement, "javamethodname"));
+ wsmOperation.setJavaReturnType(DomUtils.getChildElementText(operationElement, "javareturntype"));
+
+ /* WsmParameter */
+ NodeList parameterList = operationElement.getElementsByTagName("parameter");
+ for(int j = 0; j < parameterList.getLength(); j++) {
+ Element parameterElement = (Element)parameterList.item(j);
+ WsmParameter wsmParameter = new WsmParameter();
+ wsmParameter.setName(DomUtils.getChildElementText(parameterElement, "name"));
+ wsmParameter.setTargetNamespace(DomUtils.getChildElementText(parameterElement, "targetnamespace"));
+ wsmParameter.setJavaType(DomUtils.getChildElementText(parameterElement, "javatype"));
+ wsmParameter.setHeader(Boolean.parseBoolean(DomUtils.getChildElementText(parameterElement, "header")));
+ wsmParameter.setMode(stringToMode(DomUtils.getChildElementText(parameterElement, "mode")));
+
+ wsmOperation.addParameter(wsmParameter);
+ }
+
+ wsmService.addOperation(wsmOperation);
+ }
+
+ /* todo: WsmSoapMessageHandler */
+
+ return wsmService;
+ }
+
+ private static String qnameToString(QName qname) {
+ return qname.getPrefix() + ":" + qname.getLocalPart();
+ }
+
+ private static SOAPBinding.Style stringToStyle(String string) {
+ if(SOAPBinding.Style.DOCUMENT.toString().equals(string))
+ return SOAPBinding.Style.DOCUMENT;
+ else if(SOAPBinding.Style.RPC.toString().equals(string))
+ return SOAPBinding.Style.RPC;
+ else throw new ConfigurationException("Unable to convert string \"" + string + "\" into SOAP binding style");
+ }
+
+ private static SOAPBinding.Use stringToUse(String string) {
+ if(SOAPBinding.Use.ENCODED.toString().equals(string))
+ return SOAPBinding.Use.ENCODED;
+ else if(SOAPBinding.Use.LITERAL.toString().equals(string))
+ return SOAPBinding.Use.LITERAL;
+ else throw new ConfigurationException("Unable to convert string \"" + string + "\" into SOAP binding use");
+ }
+
+ private static SOAPBinding.ParameterStyle stringToParameterStyle(String string) {
+ if(SOAPBinding.ParameterStyle.BARE.toString().equals(string))
+ return SOAPBinding.ParameterStyle.BARE;
+ else if(SOAPBinding.ParameterStyle.WRAPPED.toString().equals(string))
+ return SOAPBinding.ParameterStyle.WRAPPED;
+ else throw new ConfigurationException("Unable to convert string \"" + string + "\" into SOAP binding parameter style");
+ }
+
+ private static WebParam.Mode stringToMode(String string) {
+ if(WebParam.Mode.IN.toString().equals(string))
+ return WebParam.Mode.IN;
+ else if(WebParam.Mode.OUT.toString().equals(string))
+ return WebParam.Mode.OUT;
+ else if(WebParam.Mode.INOUT.toString().equals(string))
+ return WebParam.Mode.INOUT;
+ else throw new ConfigurationException("Unable to convert string \"" + string + "\" into web parameter mode");
+ }
+}
+
+abstract class XmlWriter {
+ abstract void writeElement(String elementName, Map attributes, Object elementValue);
+ abstract void startElement(String elementName, Map attributes);
+ abstract void endElement(String elementName);
+}
+
+/**
+ * This is a <b>fast</b> way to write XML. DOM is really slow...
+ */
+class SimpleXmlWriter
+ extends XmlWriter {
+
+ private static final String[] INDENTS = {
+ "",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " "
+ };
+
+ private StringBuffer _buf = new StringBuffer();
+ private int _indentLevel;
+
+ SimpleXmlWriter() {
+ _indentLevel = 0;
+ _buf = new StringBuffer(512);
+ _buf.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
+ }
+
+ void writeElement(String elementName, Map attributes, Object elementValue) {
+ startLine("<");
+ continueLine(elementName);
+
+ if(attributes != null ) {
+ Iterator keys = attributes.keySet().iterator();
+ while(keys.hasNext()) {
+ Object key = keys.next();
+ continueLine(key);
+ continueLine("=\"");
+ continueLine(attributes.get(key));
+ continueLine("\" ");
+ }
+ }
+
+ continueLine(">");
+ continueLine(elementValue);
+ continueLine("</");
+ continueLine(elementName);
+ endLine(">");
+ }
+
+ void startElement(String elementName, Map attributes) {
+ startLine("<");
+ continueLine(elementName);
+
+ if(attributes != null) {
+ continueLine(" ");
+ Iterator keys = attributes.keySet().iterator();
+ while(keys.hasNext()) {
+ Object key = keys.next();
+ continueLine(key);
+ continueLine("=\"");
+ continueLine(attributes.get(key));
+ continueLine(keys.hasNext() ? "\" " : "\"");
+ }
+ }
+
+ endLine(">");
+
+ _indentLevel++;
+ }
+
+ void endElement(String elementName) {
+ _indentLevel--;
+ assert _indentLevel >= 0;
+
+ startLine("</");
+ continueLine(elementName);
+ endLine(">");
+ }
+
+ public String toString() {
+ return _buf.toString();
+ }
+
+ private final void startLine(Object value) {
+ _buf.append(INDENTS[_indentLevel]);
+ _buf.append(value);
+ }
+
+ private void continueLine(Object value) {
+ _buf.append(value);
+ }
+
+ private void endLine(Object value) {
+ _buf.append(value);
+ _buf.append('\n');
+ }
+}
\ No newline at end of file
Propchange: beehive/trunk/wsm/src/core/org/apache/beehive/wsm/util/WsmddUtils.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: beehive/trunk/wsm/test/src/junit/org/apache/beehive/wsm/test/axis/AxisHookTest.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/wsm/test/src/junit/org/apache/beehive/wsm/test/axis/AxisHookTest.java?rev=371120&r1=371119&r2=371120&view=diff
==============================================================================
--- beehive/trunk/wsm/test/src/junit/org/apache/beehive/wsm/test/axis/AxisHookTest.java (original)
+++ beehive/trunk/wsm/test/src/junit/org/apache/beehive/wsm/test/axis/AxisHookTest.java Sat Jan 21 13:55:35 2006
@@ -47,6 +47,7 @@
private static final String WM_JAVAONEWAYMETHODNAME = "fakeOneWayWebMethod";
private static final String WM_JAVAMETHODWITHEXCEPIONNAME= "fakeWayWebMethodWithException";
private static final String WS_NAME = "WebServiceName";
+ private static final String WS_SERVICENAME = WS_NAME + "Service";
private static final String WS_NAMESPACE = "http://web.service/namespace";
private static final String WM_OPERATION = "OperationName";
private static final String WM_ACTION = "Lights_Camera_Action!";
@@ -93,19 +94,14 @@
throws Exception {
OperationDesc twoWayOp = _serviceDescription.getOperationByName(WM_JAVAMETHODNAME);
assertNotNull(twoWayOp);
- if (twoWayOp != null) {
- assertEquals(WM_ACTION, twoWayOp.getSoapAction());
- assertEquals(OperationType.REQUEST_RESPONSE, twoWayOp.getMep());
- // NOTE jcolwell@bea.com 2004-Sep-13 --
- //check that this method returns something
- ParameterDesc param = twoWayOp.getParameter(0);
- assertNotNull(param);
- if (param != null) {
- assertEquals(WM_TWOWAYPARAM, param.getName());
- assertEquals(javax.xml.rpc.holders.IntHolder.class, param.getJavaType());
- assertEquals(ParameterDesc.INOUT, param.getMode());
- }
- }
+ assertEquals(WM_ACTION, twoWayOp.getSoapAction());
+ assertEquals(OperationType.REQUEST_RESPONSE, twoWayOp.getMep());
+
+ ParameterDesc param = twoWayOp.getParameter(0);
+ assertNotNull(param);
+ assertEquals(WM_TWOWAYPARAM, param.getName());
+ assertEquals(javax.xml.rpc.holders.IntHolder.class, param.getJavaType());
+ assertEquals(ParameterDesc.INOUT, param.getMode());
}
public void testExceptions()
@@ -120,19 +116,15 @@
throws Exception {
OperationDesc oneWayOp = _serviceDescription.getOperationByName(WM_JAVAONEWAYMETHODNAME);
assertNotNull(oneWayOp);
- if (oneWayOp != null) {
- assertEquals(WM_ONEWAY + WM_ACTION, oneWayOp.getSoapAction());
- assertEquals(OperationType.ONE_WAY, oneWayOp.getMep());
- // NOTE jcolwell@bea.com 2004-Sep-13 --
- // make sure this method does not return anything
- ParameterDesc param = oneWayOp.getParameter(0);
- assertNotNull(param);
- if (param != null) {
- assertEquals(WM_ONEWAYPARAM, param.getName());
- assertEquals(Boolean.class, param.getJavaType());
- assertEquals(ParameterDesc.IN, param.getMode());
- }
- }
+ assertEquals(WM_ONEWAY + WM_ACTION, oneWayOp.getSoapAction());
+ assertEquals(OperationType.ONE_WAY, oneWayOp.getMep());
+
+ ParameterDesc param = oneWayOp.getParameter(0);
+ assertNotNull(param);
+ System.out.println("eko: " + param.getName());
+ assertEquals(WM_ONEWAYPARAM, param.getName());
+ assertEquals(Boolean.class, param.getJavaType());
+ assertEquals(ParameterDesc.IN, param.getMode());
}
private WsmService configureMockService()
@@ -140,11 +132,7 @@
WsmService wstm = new WsmService();
wstm.setServiceClassName(WS_CLASS.getName());
wstm.setName(WS_NAME);
- /*
- * NOTE jcolwell@bea.com 2004-Sep-13 --
- * service name not used in the ServiceDesc
- */
- //wstm.setServiceName(WS_SERVICENAME);
+ wstm.setServiceName(WS_SERVICENAME);
wstm.setTargetNamespace(WS_NAMESPACE);
wstm.setSoapBinding(configureMockSoapBinding());
wstm.addOperation(configureMockMethod());