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 05:37:47 UTC
svn commit: r438756 -
/webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/analyzer/SimpleAnalyzer.java
Author: aeberbac
Date: Wed Aug 30 20:37:46 2006
New Revision: 438756
URL: http://svn.apache.org/viewvc?rev=438756&view=rev
Log:
added javadoc, some refactoring
Modified:
webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/analyzer/SimpleAnalyzer.java
Modified: webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/analyzer/SimpleAnalyzer.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/analyzer/SimpleAnalyzer.java?rev=438756&r1=438755&r2=438756&view=diff
==============================================================================
--- webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/analyzer/SimpleAnalyzer.java (original)
+++ webservices/muse/trunk/modules/muse-tools/src/org/apache/muse/tools/generator/analyzer/SimpleAnalyzer.java Wed Aug 30 20:37:46 2006
@@ -23,14 +23,13 @@
import javax.xml.namespace.QName;
-import org.apache.muse.core.descriptor.DescriptorConstants;
import org.apache.muse.tools.generator.util.Capability;
import org.apache.muse.tools.generator.util.ConfigurationData;
import org.apache.muse.tools.generator.util.ConfigurationDataDescriptor;
+import org.apache.muse.tools.generator.util.DeploymentDescriptorHelper;
import org.apache.muse.tools.inspector.JavaMethod;
import org.apache.muse.tools.inspector.JavaProperty;
import org.apache.muse.tools.inspector.ResourceInspector;
-import org.apache.muse.util.xml.XmlUtils;
import org.apache.muse.ws.dm.muws.MuwsConstants;
import org.apache.muse.ws.dm.muws.adv.impl.SimpleAdvertisement;
import org.apache.muse.ws.dm.muws.impl.SimpleConfiguration;
@@ -44,10 +43,19 @@
import org.apache.muse.ws.dm.muws.impl.SimpleRelationships;
import org.apache.muse.ws.dm.muws.impl.SimpleState;
import org.apache.muse.ws.metadata.WsxConstants;
+import org.apache.muse.ws.notification.NotificationProducer;
+import org.apache.muse.ws.notification.WsnConstants;
+import org.apache.muse.ws.notification.impl.SimpleNotificationConsumer;
+import org.apache.muse.ws.notification.impl.SimpleNotificationProducer;
import org.apache.muse.ws.resource.lifetime.WsrlConstants;
+import org.apache.muse.ws.resource.lifetime.impl.SimpleScheduledTermination;
import org.apache.muse.ws.resource.properties.WsrpConstants;
+import org.apache.muse.ws.resource.properties.get.impl.SimpleGetCapability;
+import org.apache.muse.ws.resource.sg.Entry;
+import org.apache.muse.ws.resource.sg.WssgConstants;
+import org.apache.muse.ws.resource.sg.impl.SimpleServiceGroup;
+import org.apache.muse.ws.resource.sg.impl.SimpleServiceGroupRegistration;
import org.w3c.dom.Document;
-import org.w3c.dom.Element;
/**
*
@@ -82,14 +90,8 @@
static {
//WS-X
- _qnameCapabilityMap.put(WsxConstants.DIALECT_QNAME,
- WsxConstants.GET_METADATA_CAPABILITY);
_qnameCapabilityMap.put(WsxConstants.GET_METADATA_QNAME,
WsxConstants.GET_METADATA_CAPABILITY);
- _qnameCapabilityMap.put(WsxConstants.METADATA_QNAME,
- WsxConstants.GET_METADATA_CAPABILITY);
- _qnameCapabilityMap.put(WsxConstants.SECTION_QNAME,
- WsxConstants.GET_METADATA_CAPABILITY);
_internalImplMap.put(WsxConstants.GET_METADATA_CAPABILITY,
org.apache.muse.ws.metadata.impl.SimpleMetadataExchange.class);
@@ -108,7 +110,7 @@
WsrpConstants.GET_CAPABILITY);
_internalImplMap.put(WsrpConstants.GET_CAPABILITY,
- org.apache.muse.ws.resource.properties.get.impl.SimpleGetCapability.class);
+ SimpleGetCapability.class);
_internalActionMap.put(WsrpConstants.GET_QNAME,
WsrpConstants.GET_RESOURCE_PROPERTY_URI);
@@ -150,10 +152,9 @@
WsrlConstants.DESTROY_URI);
//WS-RL Scheduled
- _qnameCapabilityMap.put(WsrlConstants.CURRENT_TIME_QNAME,
- WsrlConstants.SCHEDULED_TERMINATION_URI);
- _qnameCapabilityMap.put(WsrlConstants.TERMINATION_TIME_QNAME,
+ addProperties(SimpleScheduledTermination.PROPERTIES,
WsrlConstants.SCHEDULED_TERMINATION_URI);
+
_qnameCapabilityMap.put(WsrlConstants.SET_TERMINATION_QNAME,
WsrlConstants.SCHEDULED_TERMINATION_URI);
@@ -164,46 +165,42 @@
WsrlConstants.SET_TERMINATION_URI);
//WS-DM Identity
- _qnameCapabilityMap.put(MuwsConstants.RESOURCE_ID_QNAME,
+ addProperties(SimpleIdentity.PROPERTIES,
MuwsConstants.IDENTITY_URI);
_internalImplMap.put(MuwsConstants.IDENTITY_URI,
SimpleIdentity.class);
//WS-DM Manageability Characteristics
- _qnameCapabilityMap.put(MuwsConstants.MANAGEABILITY_CAPABILITY_QNAME,
+ addProperties(SimpleManageabilityCharacteristics.PROPERTIES,
MuwsConstants.CHARACTERISTICS_URI);
_internalImplMap.put(MuwsConstants.CHARACTERISTICS_URI,
SimpleManageabilityCharacteristics.class);
//WS-DM Correlatable Properties
- _qnameCapabilityMap.put(MuwsConstants.CORRELATABLE_QNAME,
+ addProperties(SimpleCorrelatableProperties.PROPERTIES,
MuwsConstants.CORRELATABLE_URI);
_internalImplMap.put(MuwsConstants.CORRELATABLE_URI,
SimpleCorrelatableProperties.class);
//WS-DM Description
- _qnameCapabilityMap.put(MuwsConstants.DESCRIPTION_QNAME,
- MuwsConstants.DESCRIPTION_URI);
- _qnameCapabilityMap.put(MuwsConstants.CAPTION_QNAME,
- MuwsConstants.DESCRIPTION_URI);
- _qnameCapabilityMap.put(MuwsConstants.VERSION_QNAME,
+ addProperties(SimpleDescription.PROPERTIES,
MuwsConstants.DESCRIPTION_URI);
_internalImplMap.put(MuwsConstants.DESCRIPTION_URI,
SimpleDescription.class);
//WS-DM Operational Status
- _qnameCapabilityMap.put(MuwsConstants.OP_STATUS_QNAME,
+ addProperties(SimpleOperationalStatus.PROPERTIES,
MuwsConstants.OP_STATUS_URI);
_internalImplMap.put(MuwsConstants.OP_STATUS_URI,
SimpleOperationalStatus.class);
//WS-DM Metrics
- _qnameCapabilityMap.put(MuwsConstants.CURRENT_TIME_QNAME,
+ addProperties(SimpleMetrics.PROPERTIES,
MuwsConstants.METRICS_URI);
_internalImplMap.put(MuwsConstants.METRICS_URI,
@@ -214,17 +211,15 @@
SimpleConfiguration.class);
//WS-DM State
- _qnameCapabilityMap.put(MuwsConstants.STATE_QNAME,
+ addProperties(SimpleState.PROPERTIES,
MuwsConstants.STATE_URI);
_internalImplMap.put(MuwsConstants.STATE_URI,
SimpleState.class);
//WS-DM Relationships
- _qnameCapabilityMap.put(MuwsConstants.RELATIONSHIP_QNAME,
+ addProperties(SimpleRelationships.PROPERTIES,
MuwsConstants.RELATIONSHIPS_URI);
- _qnameCapabilityMap.put(MuwsConstants.QUERY_RELATIONSHIPS_QNAME,
- MuwsConstants.RELATIONSHIPS_URI);
_internalImplMap.put(MuwsConstants.RELATIONSHIPS_URI,
SimpleRelationships.class);
@@ -233,11 +228,7 @@
MuwsConstants.QUERY_RELATIONSHIPS_URI);
//WS-DM Relationship Resource
- _qnameCapabilityMap.put(MuwsConstants.NAME_QNAME,
- MuwsConstants.RELATIONSHIP_RESOURCE_URI);
- _qnameCapabilityMap.put(MuwsConstants.TYPE_QNAME,
- MuwsConstants.RELATIONSHIP_RESOURCE_URI);
- _qnameCapabilityMap.put(MuwsConstants.PARTICIPANT_QNAME,
+ addProperties(SimpleRelationshipResource.PROPERTIES,
MuwsConstants.RELATIONSHIP_RESOURCE_URI);
_internalImplMap.put(MuwsConstants.RELATIONSHIP_RESOURCE_URI,
@@ -246,72 +237,196 @@
//WS-DM Advertisement
_internalImplMap.put(MuwsConstants.ADVERTISEMENT_URI,
SimpleAdvertisement.class);
+
+ //WS-SG
+ addProperties(SimpleServiceGroup.PROPERTIES,
+ WssgConstants.SERVICE_GROUP_URI);
+
+ _internalImplMap.put(WssgConstants.SERVICE_GROUP_URI,
+ SimpleServiceGroup.class);
+
+ addProperties(Entry.PROPERTIES,
+ WssgConstants.ENTRY_URI);
+
+ _internalImplMap.put(WssgConstants.ENTRY_URI,
+ Entry.class);
+
+ _internalActionMap.put(WssgConstants.ADD_URI,
+ WssgConstants.SERVICE_GROUP_REG_URI);
+
+ _internalImplMap.put(WssgConstants.SERVICE_GROUP_REG_URI,
+ SimpleServiceGroupRegistration.class);
+
+ //WS-N Consumer
+ _qnameCapabilityMap.put(WsnConstants.NOTIFY_QNAME,
+ WsnConstants.CONSUMER_URI);
+
+ _internalImplMap.put(WsnConstants.CONSUMER_URI,
+ SimpleNotificationConsumer.class);
+
+ _internalActionMap.put(WsnConstants.NOTIFY_QNAME,
+ WsnConstants.NOTIFY_URI);
+
+ //WS-N Producer
+ addProperties(NotificationProducer.PROPERTIES,
+ WsnConstants.PRODUCER_URI);
+
+ _qnameCapabilityMap.put(WsnConstants.SUBSCRIBE_QNAME,
+ WsnConstants.PRODUCER_URI);
+ _qnameCapabilityMap.put(WsnConstants.GET_CURRENT_QNAME,
+ WsnConstants.PRODUCER_URI);
+
+ _internalImplMap.put(WsnConstants.PRODUCER_URI,
+ SimpleNotificationProducer.class);
+
+ _internalActionMap.put(WsnConstants.SUBSCRIBE_QNAME,
+ WsnConstants.SUBSCRIBE_URI);
+ _internalActionMap.put(WsnConstants.SUBSCRIBE_QNAME,
+ WsnConstants.GET_CURRENT_URI);
}
static ConfigurationDataDescriptor[] REQUIRED_PARAMETERS =
new ConfigurationDataDescriptor[] {
- ConfigurationData.DESCRIPTOR_DOCUMENT_CONFIGURATION,
- ConfigurationData.WSDL_DOCUMENT_CONFIGURATION
+ ConfigurationData.DESCRIPTOR_DOCUMENT_CONFIGURATION
};
- private Map _capabilities = null;
-
- private ResourceInspector _inspector;
+ private Map[] _capabilityMaps = null;
+
+ private Document[] _wsdlDocuments = null;
+ /**
+ * Uses the <code>ResourceInspector</code> to analyze a given WSDL file and
+ * extract the capabilities it contains. Capabilities are grouped by namespace URI
+ * but special exception is made to "built-in" capabilities and standard capabilities
+ * defined by the standards bodies.
+ *
+ * @param configuration
+ * Contains the parameters for the analyzer
+ */
public ConfigurationData analyze(ConfigurationData configuration) throws Exception {
ConfigurationData.checkConfiguration(this, configuration);
-
- inspect(configuration);
- extractOperations();
+ loadParameters(configuration);
- extractProperties();
+ for(int i=0; i < _wsdlDocuments.length; i++) {
+ ResourceInspector inspector = inspect(_wsdlDocuments[i]);
+
+ _capabilityMaps[i] = new HashMap();
+
+ extractOperations(inspector, _capabilityMaps[i]);
+ extractProperties(inspector, _capabilityMaps[i]);
+
+ updateFromDescriptor(configuration, i);
+ }
- updateFromDescriptor(configuration);
-
return createResultData(configuration);
}
- private void inspect(ConfigurationData configuration) {
- Document wsdlDocument =
- (Document)configuration.getParameter(ConfigurationData.WSDL_DOCUMENT);
-
- _capabilities = new HashMap();
+ /**
+ * Add the given properties to the QName -> capability URI map.
+ *
+ * @param properties
+ * Properties to add
+ * @param uri
+ * URI to which they map
+ */
+ private static void addProperties(QName[] properties, String uri) {
+ for(int i=0; i < properties.length; i++) {
+ _qnameCapabilityMap.put(properties[i], uri);
+ }
+ }
- _inspector = new ResourceInspector();
- _inspector.run(wsdlDocument.getDocumentElement(), null);
+ /**
+ * Load the parameters from the <code>ConfigurationData</code>. The only
+ * parameter we really care about is the WSDL file from
+ * <code>ConfigurationData.WSDL_DOCUMENT</code>.
+ *
+ * @param configuration
+ * The configuration to read
+ */
+ private void loadParameters(ConfigurationData configuration) {
+ _wsdlDocuments =
+ (Document[])configuration.getParameter(ConfigurationData.WSDL_DOCUMENT_LIST);
+
+ _capabilityMaps = new HashMap[_wsdlDocuments.length];
}
+ /**
+ * Create a <code>ResourceInspector</code> and run it against the
+ * given WSDL file.
+ *
+ * @param wsdlDocument
+ * The document to inspect
+ * @return
+ * The <code>ResourceInspector</code> that analyzed the
+ * given document.
+ */
+ private ResourceInspector inspect(Document wsdlDocument) {
+ ResourceInspector inspector = new ResourceInspector();
+ inspector.run(wsdlDocument.getDocumentElement(), null);
+ return inspector;
+ }
+
+ /**
+ * Create the <code>ConfigurationData</code> that we wil pass back to the
+ * caller of <code>analyze</code> so that they can pass it on to the next
+ * phase. The current configuration is <code>clone</code>d.
+ *
+ * This class inserts a <code>Map[]</code> containing the capabilities for
+ * each resource found.
+ *
+ * @param configuration
+ * The current configuration.
+ * @return
+ * A cloned configuration with our result added.
+ */
private ConfigurationData createResultData(ConfigurationData configuration) {
ConfigurationData resultData = (ConfigurationData) configuration.clone();
- resultData.addParameter(ConfigurationData.CAPABILITIES_MAP, _capabilities);
- resultData.addParameter(ConfigurationData.PORT_TYPE, _inspector.getPortType());
+ resultData.addParameter(ConfigurationData.CAPABILITIES_MAP_LIST, _capabilityMaps);
return resultData;
}
- private void extractProperties() {
+ /**
+ * Find all of the properties that the inspector saw and split them up by
+ * capability URI.
+ *
+ * @param inspector
+ * The inspector that ran against the current WSDL
+ * @param capabilities
+ * A Map of capability objects (URI->Capability)
+ */
+ private void extractProperties(ResourceInspector inspector, Map capabilities) {
Capability capability = null;
- Collection properties = _inspector.getProperties();
+ Collection properties = inspector.getProperties();
if (properties != null) {
for (Iterator i = properties.iterator(); i.hasNext();) {
QName property = (QName) i.next();
- capability = getCapability(property);
- capability.addProperty(makeJavaProperty(property));
+ capability = getCapability(property,capabilities);
+ capability.addProperty(makeJavaProperty(property, inspector));
}
}
}
- private void extractOperations() {
+ /**
+ * Find all of the operations that the inspector saw and split them up by
+ * capability URI.
+
+ * @param inspector
+ * The inspector that ran against the current WSDL
+ * @param capabilities
+ * A Map of capability objects (URI->Capability)
+ */
+ private void extractOperations(ResourceInspector inspector, Map capabilities) {
Capability capability = null;
- Map methods = _inspector.getJavaMethods();
+ Map methods = inspector.getJavaMethods();
for (Iterator i = methods.values().iterator(); i.hasNext();) {
JavaMethod method = (JavaMethod) i.next();
- capability = getCapability(method.getName());
+ capability = getCapability(method.getName(), capabilities);
String actionURI = (String) _internalActionMap.get(method.getName());
if(actionURI != null) {
@@ -322,7 +437,24 @@
}
}
- private void updateFromDescriptor(ConfigurationData configuration) {
+ /**
+ * Check the descriptor to see if there are already mappings defined from Capability URIs to
+ * java classes. This is optional.
+ *
+ * If there are such mappings then they will overwrite the generated class names. This
+ * also works for creating custom implementations of built-in mappings.
+ *
+ * @param configuration
+ * The configuration that might contain the Descriptor (ConfigurationData.DESCRIPTOR_DOCUMENT).
+ *
+ * @param resourceIndex
+ * The index of resource-type element that we are currently dealing with, since
+ * a descriptor can contain more than one resource-type.
+ *
+ * @throws Exception
+ * If something goes wrong with reading the descriptor. See the DeploymentDescriptorHelper.
+ */
+ private void updateFromDescriptor(ConfigurationData configuration, int resourceIndex) throws Exception {
Document descriptorDocument =
(Document)configuration.getParameter(ConfigurationData.DESCRIPTOR_DOCUMENT);
@@ -330,47 +462,82 @@
return;
}
- Element descriptor = descriptorDocument.getDocumentElement();
-
- Element resourceType = XmlUtils.findFirstInSubTree(descriptor, DescriptorConstants.RESOURCE_TYPE_QNAME);
- if(resourceType == null) {
- return;
- }
-
- Element[] capabilities = XmlUtils.findInSubTree(resourceType, 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);
- Capability capability = (Capability)_capabilities.get(capabilityURI);
- if(capability == null) {
- continue;
- }
- Element javaResourceClassElement = XmlUtils.findFirstInSubTree(capabilities[i], DescriptorConstants.JAVA_RESOURCE_QNAME);
- if(javaResourceClassElement != null) {
- String javaResource = XmlUtils.extractText(javaResourceClassElement);
- capability.setImplementingClass(javaResource);
+ DeploymentDescriptorHelper helper =
+ new DeploymentDescriptorHelper(descriptorDocument, _wsdlDocuments[resourceIndex], resourceIndex);
+
+ for(Iterator i = _capabilityMaps[resourceIndex].values().iterator(); i.hasNext(); ) {
+ Capability capability = (Capability)i.next();
+
+ String uri = capability.getURI();
+ String implClass = helper.getCapabilityClass(uri);
+ if(implClass != null) {
+ String existingClass = capability.getImplementingClass();
+ if(existingClass == null) {
+ capability.setImplementingClass(implClass);
+ capability.setBuiltIn(false);
+ } else {
+ if(!existingClass.equals(implClass)) {
+ capability.setImplementingClass(implClass);
+ capability.setBuiltIn(false);
+ }
+ }
}
-
-
- //TODO capability.setBuiltIn(false);
- }
+ }
}
- private JavaProperty makeJavaProperty(QName property) {
+ /**
+ * Create a <code>JavaProperty</code> from a QName and a java type that
+ * we get from the <code>ResourInspector</code>.
+ *
+ * @param property
+ * The name of the property
+ * @param inspector
+ * The inspector run on the WSDL containing the property.
+ *
+ * @return
+ * A wrapped version of the property containing its QName and
+ * corresponding java class.
+ */
+ private JavaProperty makeJavaProperty(QName property, ResourceInspector inspector) {
JavaProperty javaProperty = new JavaProperty();
+
javaProperty.setQName(property);
- javaProperty.setJavaType(_inspector.getPropertyType(property));
+ javaProperty.setJavaType(inspector.getPropertyType(property));
+
return javaProperty;
}
- private Capability getCapability(QName qname) {
+ /**
+ * Given a QName get its capability. If the capability is
+ * not in the given capabilities map then create a new <code>Capability</code>.
+ *
+ * The QName can be a property or an input element on an operation.
+ *
+ * We also check to see if the capability URI is a built-in
+ * capability. If so then we mark the capability as "built-in" using
+ * <code>setBuiltIn(true)</code>;
+ *
+ * The reason why this class isn't just a lookupu into the capabilities
+ * map is that we don't know if the namespace uri of the given
+ * qname matches its capability URI.
+ *
+ * @param qname
+ * The name of the property or input element which
+ * we want to associate with a capability.
+ * @param capabilities
+ * The capabilities map (URI->Capability)
+ *
+ * @return
+ * A new wrapped capability or an existing capability.
+ */
+ private Capability getCapability(QName qname, Map capabilities) {
String capabilityURI = getCapabilityURI(qname);
- Capability capability = (Capability) _capabilities.get(capabilityURI);
+ Capability capability = (Capability) capabilities.get(capabilityURI);
if (capability == null) {
capability = new Capability(capabilityURI);
- _capabilities.put(capabilityURI, capability);
+ capabilities.put(capabilityURI, capability);
}
Class implementingClass = (Class)_internalImplMap.get(capabilityURI);
@@ -382,6 +549,15 @@
return capability;
}
+ /**
+ * Given a QName get the capability URI. This is
+ * the point at which we look into the giant map of
+ * QNames->URIs to find if the given QName has a capability URI
+ * that differs from its namespace URI.
+ *
+ * @param qname
+ * @return
+ */
private String getCapabilityURI(QName qname) {
String result = (String) _qnameCapabilityMap.get(qname);
@@ -390,6 +566,15 @@
return result == null ? qname.getNamespaceURI() : result;
}
+ /**
+ * Returns <code>REQUIRED_PARAMETERS</code> which is a descriptor of
+ * the parameters we need at a bare minimum.
+ *
+ * @return
+ * A list of descriptors for the parameters we need to run.
+ *
+ * @see org.apache.muse.tools.generator.util.Configurable#getConfigurationDataDescriptions()
+ */
public ConfigurationDataDescriptor[] getConfigurationDataDescriptions() {
return REQUIRED_PARAMETERS;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: muse-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: muse-commits-help@ws.apache.org