You are viewing a plain text version of this content. The canonical link for it is here.
Posted to muse-commits@ws.apache.org by ae...@apache.org on 2006/08/31 06:05:40 UTC
svn commit: r438771 -
/webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/util/
Author: aeberbac
Date: Wed Aug 30 21:05:40 2006
New Revision: 438771
URL: http://svn.apache.org/viewvc?rev=438771&view=rev
Log:
added helpers for creating and modifying the services.xml and muse.xml files.
Added:
webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/util/DeploymentDescriptorHelper.java
webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/util/ServicesDescriptorHelper.java
Modified:
webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/util/AbstractCommandLineApp.java
webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/util/ConfigurationData.java
webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/util/LocalEnvironment.java
webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/util/Messages.properties
Modified: webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/util/AbstractCommandLineApp.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/util/AbstractCommandLineApp.java?rev=438771&r1=438770&r2=438771&view=diff
==============================================================================
--- webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/util/AbstractCommandLineApp.java (original)
+++ webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/util/AbstractCommandLineApp.java Wed Aug 30 21:05:40 2006
@@ -63,8 +63,24 @@
* if the file is null or doesn't exist.
*
* @param wsdlFile The WSDL File to parse
+ * @param descriptorFile
* @return A Document representing the parsed WSDL
*/
+ public static Document[] getWSDLDocuments(File wsdlFile, File deploymentDescriptorFile, Document deploymentDescriptorDocument) throws Exception {
+ if(wsdlFile != null) {
+ return new Document[] { getWSDLDocument(wsdlFile) };
+ }
+
+ File[] wsdlFiles = DeploymentDescriptorHelper.getWsdls(deploymentDescriptorFile, deploymentDescriptorDocument);
+
+ Document[] wsdlDocuments = new Document[wsdlFiles.length];
+ for(int i=0; i < wsdlFiles.length; i++) {
+ wsdlDocuments[i] = getWSDLDocument(wsdlFiles[i]);
+ }
+
+ return wsdlDocuments;
+ }
+
public static Document getWSDLDocument(File wsdlFile) throws Exception {
if (wsdlFile == null) {
throw new IllegalArgumentException(_MESSAGES.get("NullWSDL"));
Modified: webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/util/ConfigurationData.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/util/ConfigurationData.java?rev=438771&r1=438770&r2=438771&view=diff
==============================================================================
--- webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/util/ConfigurationData.java (original)
+++ webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/util/ConfigurationData.java Wed Aug 30 21:05:40 2006
@@ -20,20 +20,18 @@
import java.util.HashMap;
import java.util.Map;
-import javax.xml.namespace.QName;
-
import org.apache.muse.util.messages.Messages;
import org.apache.muse.util.messages.MessagesFactory;
import org.w3c.dom.Document;
public class ConfigurationData implements Cloneable {
- public static final String WSDL_DOCUMENT = "wsdl_document";
+ public static final String WSDL_DOCUMENT_LIST = "wsdl_documents";
- public static ConfigurationDataDescriptor WSDL_DOCUMENT_CONFIGURATION =
+ public static ConfigurationDataDescriptor WSDL_DOCUMENT_LIST_CONFIGURATION =
new ConfigurationDataDescriptor(
- WSDL_DOCUMENT,
- Document.class);
+ WSDL_DOCUMENT_LIST,
+ Document[].class);
public static final String DESCRIPTOR_DOCUMENT = "descriptor_document";
@@ -49,26 +47,19 @@
OVERWRITE,
Boolean.class);
- public static final String CAPABILITIES_MAP = "capabilities_map";
-
- public static final ConfigurationDataDescriptor CAPABILITIES_MAP_CONFIGURATION =
- new ConfigurationDataDescriptor(
- CAPABILITIES_MAP,
- Map.class);
+ public static final String CAPABILITIES_MAP_LIST = "capabilities_map_list";
- public static final String PORT_TYPE = "port_type";
-
- public static final ConfigurationDataDescriptor PORT_TYPE_CONFIGURATION =
+ public static final ConfigurationDataDescriptor CAPABILITIES_MAP_LIST_CONFIGURATION =
new ConfigurationDataDescriptor(
- PORT_TYPE,
- QName.class);
+ CAPABILITIES_MAP_LIST,
+ Map[].class);
- public static final String FILES_MAP = "files_map" ;
+ public static final String FILES_MAP_LIST = "files_map_list" ;
- public static final ConfigurationDataDescriptor FILES_MAP_CONFIGURATION =
+ public static final ConfigurationDataDescriptor FILES_MAP_LIST_CONFIGURATION =
new ConfigurationDataDescriptor(
- FILES_MAP,
- Map.class);
+ FILES_MAP_LIST,
+ Map[].class);
public static final String TARGET_DIRECTORY = "target_dir";
Added: webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/util/DeploymentDescriptorHelper.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/util/DeploymentDescriptorHelper.java?rev=438771&view=auto
==============================================================================
--- webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/util/DeploymentDescriptorHelper.java (added)
+++ webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/util/DeploymentDescriptorHelper.java Wed Aug 30 21:05:40 2006
@@ -0,0 +1,190 @@
+package org.apache.muse.tools.generator.util;
+
+import java.io.File;
+
+import org.apache.muse.core.descriptor.DescriptorConstants;
+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.ws.wsdl.WsdlUtils;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+public class DeploymentDescriptorHelper {
+
+ private Document _descriptorDocument;
+ private Element _wsdlFileElement;
+ private Element _resourceTypeElement;
+ private Element _contextPathElement;
+ private Element _javaResourceClass;
+ private static Messages _MESSAGES = MessagesFactory.get(DeploymentDescriptorHelper.class);
+
+ public DeploymentDescriptorHelper(Document descriptorDocument, Document wsdlDocument, int resourceIndex) throws Exception {
+ _descriptorDocument = descriptorDocument;
+ _resourceTypeElement = findResourceTypeElement(_descriptorDocument, wsdlDocument, resourceIndex);
+ _wsdlFileElement = XmlUtils.findFirstInSubTree(_resourceTypeElement, DescriptorConstants.WSDL_FILE_QNAME);
+ _contextPathElement = XmlUtils.findFirstInSubTree(_resourceTypeElement, DescriptorConstants.CONTEXT_PATH_QNAME);
+ _javaResourceClass = XmlUtils.findFirstInSubTree(_resourceTypeElement, DescriptorConstants.JAVA_RESOURCE_QNAME);
+ }
+
+ private Element findResourceTypeElement(Document descriptorDocument, Document wsdlDocument, int resourceIndex) throws Exception {
+ Element portTypeElement = XmlUtils.findFirstInSubTree(wsdlDocument.getDocumentElement(), WsdlUtils.PORT_TYPE_QNAME );
+
+ if(portTypeElement == null) {
+ throw new Exception(_MESSAGES .get("NoPortType"));
+ }
+
+ String portTypeName = portTypeElement.getAttribute(WsdlUtils.NAME);
+
+ if(portTypeName == null) {
+ throw new Exception(_MESSAGES .get("NoPortTypeName"));
+ }
+
+ String portTypeURI = wsdlDocument.getDocumentElement().getAttribute(XmlUtils.TARGET_NS);
+
+ if(portTypeURI == null) {
+ throw new Exception(_MESSAGES .get("NoTargetNamespace"));
+ }
+
+ Element[] resourceTypes = XmlUtils.findInSubTree(_descriptorDocument.getDocumentElement(), DescriptorConstants.RESOURCE_TYPE_QNAME);
+
+ if(resourceTypes.length < 1) {
+ throw new Exception(_MESSAGES.get("NoResourceTypeElements"));
+ }
+
+ if(resourceIndex >= resourceTypes.length) {
+ Object[] filler = { new Integer(resourceIndex), new Integer(resourceTypes.length) };
+ throw new IndexOutOfBoundsException(_MESSAGES.get("InvalidResourceIndex", filler));
+ }
+
+
+ if(findPortTypeElement(resourceTypes[resourceIndex], portTypeName, portTypeURI) != null) {
+ return resourceTypes[resourceIndex];
+ }
+
+ if(resourceTypes.length != 1) {
+ Object[] filler = { portTypeName, portTypeURI };
+ throw new Exception(_MESSAGES.get("NoPortTypeMultipleCapabilities",filler));
+ }
+
+ portTypeElement = XmlUtils.findFirstInSubTree(resourceTypes[0], DescriptorConstants.WSDL_PORT_TYPE_QNAME);
+
+ if(portTypeElement == null) {
+ throw new Exception(_MESSAGES .get("NoPortTypeElement"));
+ }
+
+ String prefix = "pfx";
+ XmlUtils.setElementText(portTypeElement, prefix + ":" + portTypeName);
+ XmlUtils.setNamespaceAttribute(portTypeElement,prefix , portTypeURI);
+
+ return resourceTypes[0];
+ }
+
+ private Element findPortTypeElement(Element resourceTypeElement, String portTypeName, String portTypeURI) throws Exception {
+ Element portTypeElement = XmlUtils.findFirstInSubTree(resourceTypeElement, DescriptorConstants.WSDL_PORT_TYPE_QNAME);
+
+ if(portTypeElement == null) {
+ Object[] filler = { XmlUtils.toString(resourceTypeElement) };
+ throw new Exception(_MESSAGES.get("NoPortTypeElement", filler));
+ }
+
+ String qname = XmlUtils.extractText(portTypeElement);
+
+ if(qname == null) {
+ return null;
+ }
+
+ String namespace = XmlUtils.resolveNamespace(qname, portTypeElement);
+
+ if(namespace == portTypeURI && namespace == null) {
+ return portTypeElement;
+ }
+
+ if(portTypeURI.equals(namespace)) {
+ return portTypeElement;
+ }
+
+ return null;
+ }
+
+ public String getCapabilityClass(String uri) {
+ Element capabilityElement = findCapabilityElement(uri);
+
+ if(capabilityElement == null) {
+ return null;
+ }
+
+ Element javaResourceClassElement = XmlUtils.findFirstInSubTree(capabilityElement, DescriptorConstants.JAVA_CAPABILITY_QNAME);
+
+ if(javaResourceClassElement != null) {
+ return XmlUtils.extractText(javaResourceClassElement);
+ }
+
+ return null;
+ }
+
+ private Element findCapabilityElement(String uri) {
+ Element[] capabilities = XmlUtils.findInSubTree(_resourceTypeElement, DescriptorConstants.CAPABILITY_QNAME);
+ for(int i=0; i < capabilities.length; i++) {
+ Element capabilityURIElement = XmlUtils.findFirstInSubTree(capabilities[i],DescriptorConstants.CAPABILITY_URI_QNAME);
+ String capabilityURI = XmlUtils.extractText(capabilityURIElement);
+ if(uri.equals(capabilityURI)) {
+ return capabilities[i];
+ }
+ }
+ return null;
+ }
+
+ public void setWsdlFile(String wsdlFileName) {
+ XmlUtils.setElementText(_wsdlFileElement, wsdlFileName);
+ }
+
+ public void setContextPath(String contextPathName) {
+ XmlUtils.setElementText(_contextPathElement, contextPathName);
+ }
+
+ public void setJavaResourceClass(String name) {
+ XmlUtils.setElementText(_javaResourceClass, name);
+ }
+
+ public void addCapability(Capability capability) {
+ Element capabilityElement = findCapabilityElement(capability.getURI());
+
+ if(capabilityElement == null) {
+ capabilityElement = XmlUtils.createElement(_descriptorDocument, DescriptorConstants.CAPABILITY_QNAME);
+ Element capabilityUriElement = XmlUtils.createElement(_descriptorDocument, DescriptorConstants.CAPABILITY_URI_QNAME, capability.getURI() );
+
+ capabilityElement.appendChild(capabilityUriElement);
+ _resourceTypeElement.appendChild(capabilityElement);
+ }
+
+ Element javaResourceClassElement = XmlUtils.findFirstInSubTree(capabilityElement, DescriptorConstants.JAVA_CAPABILITY_QNAME);
+ if(javaResourceClassElement == null) {
+ javaResourceClassElement = XmlUtils.createElement(_descriptorDocument, DescriptorConstants.JAVA_CAPABILITY_QNAME);
+ capabilityElement.appendChild(javaResourceClassElement);
+ }
+
+ XmlUtils.setElementText(javaResourceClassElement, capability.getImplementingClass());
+ }
+
+ public static File[] getWsdls(File deploymentDescriptorFile, Document deploymentDescriptorDocument) throws Exception {
+ Element[] wsdlFileElements = XmlUtils.findInSubTree(deploymentDescriptorDocument.getDocumentElement(), DescriptorConstants.WSDL_FILE_QNAME);
+ File[] files = new File[wsdlFileElements.length];
+
+ for(int i=0; i < wsdlFileElements.length; i++) {
+ String wsdlFileName = XmlUtils.extractText(wsdlFileElements[i]);
+ if(wsdlFileName == null || wsdlFileName.length() == 0) {
+ Object[] filler = { deploymentDescriptorFile.getAbsolutePath() };
+ throw new Exception(_MESSAGES.get("EmptyWsdlFileElement", filler));
+ }
+
+ files[i] = new File(deploymentDescriptorFile.getAbsoluteFile().getParentFile(), wsdlFileName);
+ if(!files[i].exists()) {
+ Object[] filler = { files[i].getAbsolutePath() };
+ throw new Exception(_MESSAGES.get("RelativeWsdlFileNotFound", filler));
+ }
+ }
+
+ return files;
+ }
+}
Modified: webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/util/LocalEnvironment.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/util/LocalEnvironment.java?rev=438771&r1=438770&r2=438771&view=diff
==============================================================================
--- webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/util/LocalEnvironment.java (original)
+++ webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/util/LocalEnvironment.java Wed Aug 30 21:05:40 2006
@@ -36,7 +36,7 @@
* to access the file system and resolve any resource paths.
*
* @author Dan Jemiolo (danj)
- * @author Andrew Eberbach
+ * @author Andrew Eberbach (aeberbac)
*
*/
Modified: webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/util/Messages.properties
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/util/Messages.properties?rev=438771&r1=438770&r2=438771&view=diff
==============================================================================
--- webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/util/Messages.properties (original)
+++ webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/util/Messages.properties Wed Aug 30 21:05:40 2006
@@ -29,4 +29,13 @@
\n\n XXX\tThe address that is the value for the \n\t\tlocation attribute on the generated service \n\t\t(REQUIRED).\
\n\n XXX\tThe target file to write the generated \n\t\tWSDL should be written \n\t\t(REQUIRED).\
\n\n XXX\tAn option to overwrite the target \n\t\tfile if it exists \n\t\t(OPTIONAL).\
-\n\n XXX\t\tDisplay this message\n\t\t(OPTIONAL).
\ No newline at end of file
+\n\n XXX\t\tDisplay this message\n\t\t(OPTIONAL).
+
+NoPortType = No portType element found in the WSDL document.
+NoPortTypeName = No "name" attribute on the portType.
+NoTargetNamespace = No "targetNamespace" found on WSDL document.
+NoResourceTypeElements = There must be at least one "resource-type" element in the deployment descriptor.
+NoPortTypeMultipleCapabilities = There are multiple "resource-type" elements in the deployment descriptor, but thhere are none that contain a "wsdl-port-type" element that has a value which resolves to XXX bound to namespace XXX.
+InvalidResourceIndex = The index XXX is more than XXX, the total number of resources.
+EmptyWsdlFileElement = The descritor at XXX has a "wsdl-file" element with no content.
+RelativeWsdlFileNotFound = The WSDL file XXX was not found. The path must be relative to the descriptor document.
\ No newline at end of file
Added: webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/util/ServicesDescriptorHelper.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/util/ServicesDescriptorHelper.java?rev=438771&view=auto
==============================================================================
--- webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/util/ServicesDescriptorHelper.java (added)
+++ webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/util/ServicesDescriptorHelper.java Wed Aug 30 21:05:40 2006
@@ -0,0 +1,118 @@
+package org.apache.muse.tools.generator.util;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+import org.apache.muse.tools.inspector.JavaMethod;
+import org.apache.muse.util.xml.XmlUtils;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+public class ServicesDescriptorHelper {
+ private static final QName SERVICE_GROUP_QNAME = new QName("serviceGroup");
+ private static final QName SERVICE_QNAME = new QName("service");
+ private static final QName OPERATION_QNAME = new QName("operation");
+
+
+ String AXIS2_ISOLATION_LAYER = "org.apache.muse.core.platform.axis2.AxisIsolationLayer";
+ private static final QName ACTION_MAPPING = new QName("actionMapping");
+ private static final String NAME_ATTRIBUTE = "name";
+ private static final String SERVICE_CLASS = "ServiceClass";
+ private static final QName PARAMETER_QNAME = new QName("parameter");
+ private static final String LOCKED_ATTRIBUTE = "locked";
+ private static final String HANDLE_REQUEST = "handleRequest";
+ private static final String MESSAGE_RECV_CLASS = "org.apache.axis2.receivers.RawXMLINOutMessageReceiver";
+ private static final QName MESSAGE_RECV_QNAME = new QName("messageReceiver");
+ private static final String CLASS_ATTRIBUTE = "class";
+
+ private Document _servicesDocument;
+ private Element _serviceGroupElement;
+ private Map _serviceOperations;
+
+ public ServicesDescriptorHelper() {
+ _serviceOperations = new HashMap();
+
+ _servicesDocument = XmlUtils.createDocument();
+ _serviceGroupElement = XmlUtils.createElement(_servicesDocument, SERVICE_GROUP_QNAME);
+ _servicesDocument.appendChild(_serviceGroupElement);
+ }
+
+ private String makeActionURI(Capability capability, JavaMethod method) {
+ String actionURI = method.getActionURI();
+ if(actionURI != null) {
+ return actionURI;
+ }
+
+ String name = method.getName().getLocalPart();
+ name = name.substring(0,1).toUpperCase() + name.substring(1);
+ return capability.getURI() + "/" + name;
+ }
+
+
+ public void addActionMappings(Capability capability, String serviceName) {
+ Element operationElement = (Element) _serviceOperations.get(serviceName);
+ for (Iterator j = capability.getOperations().iterator(); j.hasNext();) {
+ JavaMethod method = (JavaMethod) j.next();
+
+ Element actionMapping = XmlUtils.createElement(_servicesDocument,ACTION_MAPPING);
+
+ XmlUtils.setElementText(actionMapping, makeActionURI(
+ capability, method));
+
+ operationElement.appendChild(actionMapping);
+ }
+ }
+
+ public Node getDocument() {
+ return _servicesDocument;
+ }
+
+ public void createService(String serviceName) {
+ Element serviceElement = XmlUtils.createElement(_servicesDocument, SERVICE_QNAME);
+ setName(serviceElement, serviceName);
+
+ Element parameter = createParameter(SERVICE_CLASS, AXIS2_ISOLATION_LAYER,false);
+ serviceElement.appendChild(parameter);
+
+ Element operation = createOperation(HANDLE_REQUEST);
+ serviceElement.appendChild(operation);
+
+ _serviceOperations.put(serviceName, operation);
+
+ _serviceGroupElement.appendChild(serviceElement);
+ }
+
+ private Element createOperation(String name) {
+ Element operationElement = XmlUtils.createElement(_servicesDocument, OPERATION_QNAME);
+ operationElement.setAttribute(NAME_ATTRIBUTE, name);
+
+ Element messageReceiver = createMessageReceiver(MESSAGE_RECV_CLASS);
+ operationElement.appendChild(messageReceiver);
+
+ return operationElement;
+ }
+
+ private Element createMessageReceiver(String recvClass) {
+ Element messageRecvElement = XmlUtils.createElement(_servicesDocument, MESSAGE_RECV_QNAME);
+ messageRecvElement.setAttribute(CLASS_ATTRIBUTE, recvClass);
+ return messageRecvElement;
+ }
+
+ private Element createParameter(String name, String value, boolean locked) {
+ Element parameterElement = XmlUtils.createElement(_servicesDocument, PARAMETER_QNAME);
+ parameterElement.setAttribute(NAME_ATTRIBUTE, name);
+ parameterElement.setAttribute(LOCKED_ATTRIBUTE, String.valueOf(locked));
+ XmlUtils.setElementText(parameterElement, value);
+
+ return parameterElement;
+ }
+
+ private void setName(Element serviceElement, String serviceName) {
+ serviceElement.setAttribute(NAME_ATTRIBUTE, serviceName);
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: muse-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: muse-commits-help@ws.apache.org