You are viewing a plain text version of this content. The canonical link for it is here.
Posted to wsrf-dev@ws.apache.org by ip...@apache.org on 2004/12/10 17:25:36 UTC
svn commit: r111519 - in incubator/apollo/trunk/src/java/org/apache/ws: resource resource/impl resource/properties util
Author: ips
Date: Fri Dec 10 08:25:35 2004
New Revision: 111519
URL: http://svn.apache.org/viewcvs?view=rev&rev=111519
Log:
util classes to aid code generation
Added:
incubator/apollo/trunk/src/java/org/apache/ws/resource/ResourceDefinition.java
incubator/apollo/trunk/src/java/org/apache/ws/resource/impl/ResourceDefinitionImpl.java
incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/ResourceProperties1_1Constants.java
incubator/apollo/trunk/src/java/org/apache/ws/util/WsrfWsdlUtils.java
Modified:
incubator/apollo/trunk/src/java/org/apache/ws/resource/Wsdl2Java.java
Added: incubator/apollo/trunk/src/java/org/apache/ws/resource/ResourceDefinition.java
Url: http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/java/org/apache/ws/resource/ResourceDefinition.java?view=auto&rev=111519
==============================================================================
--- (empty file)
+++ incubator/apollo/trunk/src/java/org/apache/ws/resource/ResourceDefinition.java Fri Dec 10 08:25:35 2004
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ws.resource;
+
+import javax.wsdl.Definition;
+import javax.wsdl.Operation;
+import javax.wsdl.PortType;
+import javax.xml.namespace.QName;
+import java.util.Map;
+
+/**
+ * A WSDM Web Service Definition.
+ *
+ * @author Ian P. Springer (Hewlett-Packard Company)
+ */
+public interface ResourceDefinition
+{
+ /**
+ *
+ * @param portType a portType from this WSDL
+ *
+ * @return a Map of all custom operations (i.e. operations that are not derived
+ * from a "base" portType) from the specified portType; the Map's keys
+ * are the {@link QName}s of the operations, and the values are the
+ * {@link Operation}s themselves.
+ */
+ Map getCustomOperations( PortType portType );
+
+ /**
+ * Returns the JWSDL {@link Definition} corresponding to this WSDM Web Service.
+ *
+ * @return
+ */
+ Definition getDefinition( );
+
+ /**
+ *
+ * @param portType a portType from this WSDL
+ *
+ * @return a Map of all "base" portTypes that the specified portType implements;
+ * the Map's keys are the {@link QName}s of the portTypes, and the values
+ * are the {@link PortType}s themselves.
+ */
+ Map getImplementedPortTypes( PortType portType );
+
+ /**
+ * Returns a list of the QNames of the resource properties that are
+ * defined for the specified portType, or null if the portType does
+ * not have any associated resource properties.
+ *
+ * @param portType a port type from this WSDL
+ *
+ * @return the QNames of the resource properties defined for the specified portType
+ */
+ QName[] getResourcePropertyQNames( PortType portType );
+}
Modified: incubator/apollo/trunk/src/java/org/apache/ws/resource/Wsdl2Java.java
Url: http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/java/org/apache/ws/resource/Wsdl2Java.java?view=diff&rev=111519&p1=incubator/apollo/trunk/src/java/org/apache/ws/resource/Wsdl2Java.java&r1=111518&p2=incubator/apollo/trunk/src/java/org/apache/ws/resource/Wsdl2Java.java&r2=111519
==============================================================================
--- incubator/apollo/trunk/src/java/org/apache/ws/resource/Wsdl2Java.java (original)
+++ incubator/apollo/trunk/src/java/org/apache/ws/resource/Wsdl2Java.java Fri Dec 10 08:25:35 2004
@@ -96,6 +96,7 @@
{
throw new Exception( xErrorListener.toString() );
}
+
}
public File[] getWsdlFiles()
Added: incubator/apollo/trunk/src/java/org/apache/ws/resource/impl/ResourceDefinitionImpl.java
Url: http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/java/org/apache/ws/resource/impl/ResourceDefinitionImpl.java?view=auto&rev=111519
==============================================================================
--- (empty file)
+++ incubator/apollo/trunk/src/java/org/apache/ws/resource/impl/ResourceDefinitionImpl.java Fri Dec 10 08:25:35 2004
@@ -0,0 +1,290 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ws.resource.impl;
+
+import org.apache.ws.resource.ResourceDefinition;
+import org.apache.ws.resource.properties.ResourceProperties1_1Constants;
+import org.apache.ws.resource.properties.ResourceProperties1_2Constants;
+import org.apache.ws.util.WsrfWsdlUtils;
+import org.apache.ws.util.XmlConstants;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import javax.wsdl.Definition;
+import javax.wsdl.Import;
+import javax.wsdl.Port;
+import javax.wsdl.PortType;
+import javax.wsdl.Service;
+import javax.wsdl.extensions.ExtensibilityElement;
+import javax.wsdl.extensions.UnknownExtensibilityElement;
+import javax.wsdl.factory.WSDLFactory;
+import javax.wsdl.xml.WSDLReader;
+import javax.xml.namespace.QName;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * A {@link ResourceDefinition} implementation.
+ *
+ * @author Ian Springer
+ */
+public class ResourceDefinitionImpl
+ implements ResourceDefinition
+{
+ private PortType[] m_importedPortTypes;
+ private Definition m_def;
+
+ /**
+ * Creates a new {@link ResourceDefinitionImpl} based on the specified JWSDL definition.
+ *
+ * @param def a JWSDL definition
+ */
+ public ResourceDefinitionImpl( Definition def )
+ {
+ m_def = def;
+ m_importedPortTypes = getImportedPortTypes();
+ Map services = def.getServices();
+ Iterator iter = services.values().iterator();
+ while ( iter.hasNext() )
+ {
+ Service service = (Service) iter.next();
+ Map portTypes = getPortTypes( service );
+ Iterator portTypesIter = portTypes.values().iterator();
+ while ( portTypesIter.hasNext() )
+ {
+ PortType portType = (PortType) portTypesIter.next();
+ Map implementedPortTypes = getImplementedPortTypes( portType );
+ System.out.println( "PortType " + portType.getQName() + " implements:" );
+ Iterator qNameIter = implementedPortTypes.keySet().iterator();
+ while ( qNameIter.hasNext() )
+ {
+ System.out.println( "\to " + (QName) qNameIter.next() );
+ }
+ }
+ }
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param portType DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public Map getCustomOperations( PortType portType )
+ {
+ Map customOps = new HashMap();
+
+ // TODO
+ return customOps;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public Definition getDefinition()
+ {
+ return m_def;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param portType DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public Map getImplementedPortTypes( PortType portType )
+ {
+ Map implementedPortTypes = new HashMap();
+ for ( int i = 0; i < m_importedPortTypes.length; i++ )
+ {
+ PortType importedPortType = m_importedPortTypes[i];
+ if ( WsrfWsdlUtils.implementsPortType( portType, importedPortType ) )
+ {
+ implementedPortTypes.put( importedPortType.getQName(),
+ importedPortType );
+ }
+ }
+
+ return implementedPortTypes;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param service DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public Map getPortTypes( Service service )
+ {
+ System.out.println( "Validating service " + service.getQName() + "..." );
+ Map portTypes = new HashMap();
+ Map ports = service.getPorts();
+ Iterator portsIter = ports.values().iterator();
+ while ( portsIter.hasNext() )
+ {
+ Port port = (Port) portsIter.next();
+ PortType portType = port.getBinding().getPortType();
+ portTypes.put( portType.getQName(),
+ portType );
+ }
+
+ return portTypes;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param portType DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public QName[] getResourcePropertyQNames( PortType portType )
+ {
+ return getResourcePropertyQNames( portType, m_def );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param args DOCUMENT_ME
+ *
+ * @throws Exception DOCUMENT_ME
+ */
+ public static void main( String[] args )
+ throws Exception
+ {
+ WSDLReader wsdlReader = WSDLFactory.newInstance().newWSDLReader();
+ String diskWsdlPath = "C:/Projects/muse/target/wsdm/wsdl/disk.wsdl";
+ Definition def = wsdlReader.readWSDL( diskWsdlPath );
+ ResourceDefinition wsResourceDef = new ResourceDefinitionImpl( def );
+ wsResourceDef.getResourcePropertyQNames( (PortType) def.getPortTypes().values().iterator().next() );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public String toString()
+ {
+ return "WS-Resource Web Service Definition with namespace " + m_def.getTargetNamespace();
+ }
+
+ private PortType[] getImportedPortTypes()
+ {
+ List importedPortTypes = new ArrayList();
+ Map imports = m_def.getImports();
+ Iterator iter = imports.keySet().iterator();
+ while ( iter.hasNext() )
+ {
+ String nsURI = (String) iter.next();
+ Iterator importsIter = ( (List) imports.get( nsURI ) ).iterator();
+ while ( importsIter.hasNext() )
+ {
+ Import anImport = (Import) importsIter.next();
+ Definition importedDef = anImport.getDefinition();
+ importedPortTypes.addAll( importedDef.getPortTypes().values() );
+ }
+ }
+
+ return (PortType[]) importedPortTypes.toArray( new PortType[0] );
+ }
+
+ private Element getResourcePropertiesDocumentTypeElem( Definition def,
+ QName rpDocTypeElemQName )
+ {
+ Element schemaElem = getSchemaElement( def );
+ NodeList children = schemaElem.getChildNodes();
+ for ( int i = 0; i < children.getLength(); i++ )
+ {
+ Node child = children.item( i );
+ if ( child instanceof Element && child.getLocalName().equals( "element" ) )
+ {
+ Element elementElem = (Element) child;
+ if ( String.valueOf( elementElem.getAttribute( "name" ) ).equals( rpDocTypeElemQName.getLocalPart() ) )
+ {
+ return elementElem;
+ }
+ }
+ }
+
+ return null;
+ }
+
+ private QName getResourcePropertiesTypeElementQName( PortType portType )
+ {
+ Map extAttribs = portType.getExtensionAttributes();
+ QName rpDocDefQName =
+ (QName) extAttribs.get( ResourceProperties1_2Constants.RESOURCE_PROPERTIES_PORTTYPE_ATTRIB );
+ if ( rpDocDefQName == null )
+ {
+ rpDocDefQName =
+ (QName) extAttribs.get( ResourceProperties1_1Constants.RESOURCE_PROPERTIES_PORTTYPE_ATTRIB );
+ }
+
+ return rpDocDefQName;
+ }
+
+ private QName[] getResourcePropertyQNames( PortType portType,
+ Definition def )
+ {
+ QName rpDocTypeElemQName = getResourcePropertiesTypeElementQName( portType );
+ if ( rpDocTypeElemQName == null )
+ {
+ return null;
+ }
+
+ Element rpDocTypeElem = getResourcePropertiesDocumentTypeElem( def, rpDocTypeElemQName );
+
+ // TODO: get xsd:sequence or xsd:all child element
+ // TODO: get all xsd:element children of above element (these are the RP elems)
+ // TODO: make sure all of the above use ref attrib as required by spec
+ // TODO: return the QNames of the RP elems
+ return new QName[0];
+ }
+
+ private Element getSchemaElement( Definition def )
+ {
+ Element schemaElem = null;
+ List extElems = def.getTypes().getExtensibilityElements();
+ for ( int i = 0; i < extElems.size(); i++ )
+ {
+ ExtensibilityElement extElem = (ExtensibilityElement) extElems.get( i );
+ if ( extElem instanceof UnknownExtensibilityElement )
+ {
+ UnknownExtensibilityElement unknownExtElem = (UnknownExtensibilityElement) extElem;
+ Element elem = unknownExtElem.getElement();
+ if ( elem.getNamespaceURI().equals( XmlConstants.NSURI_SCHEMA_XSD )
+ && elem.getLocalName().equals( XmlConstants.XSD_SCHEMA.getLocalPart() ) )
+ {
+ schemaElem = elem;
+ break;
+ }
+ }
+ }
+
+ return schemaElem;
+ }
+}
\ No newline at end of file
Added: incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/ResourceProperties1_1Constants.java
Url: http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/ResourceProperties1_1Constants.java?view=auto&rev=111519
==============================================================================
--- (empty file)
+++ incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/ResourceProperties1_1Constants.java Fri Dec 10 08:25:35 2004
@@ -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.
+ *=============================================================================*/
+package org.apache.ws.resource.properties;
+
+import javax.xml.namespace.QName;
+
+/**
+ * @author Ian P. Springer
+ */
+public interface ResourceProperties1_1Constants
+{
+ /**
+ * Namespace URI for WS-ResourceProperties 1.1 schema and WSDL.
+ */
+ String NSURI_WSRP = "http://www.ibm.com/xmlns/stdwip/web-services/WS-ResourceProperties";
+
+ /**
+ * Namespace prefix for WS-ResourceProperties 1.1 schema and WSDL.
+ */
+ String NSPREFIX_WSRP = "wsrp";
+
+ /**
+ * QName of the "ResourceProperties" portType attribute.
+ */
+ QName RESOURCE_PROPERTIES_PORTTYPE_ATTRIB =
+ new QName( NSURI_WSRP, "ResourceProperties", NSPREFIX_WSRP );
+}
\ No newline at end of file
Added: incubator/apollo/trunk/src/java/org/apache/ws/util/WsrfWsdlUtils.java
Url: http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/java/org/apache/ws/util/WsrfWsdlUtils.java?view=auto&rev=111519
==============================================================================
--- (empty file)
+++ incubator/apollo/trunk/src/java/org/apache/ws/util/WsrfWsdlUtils.java Fri Dec 10 08:25:35 2004
@@ -0,0 +1,116 @@
+/*=============================================================================*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *=============================================================================*/
+package org.apache.ws.util;
+
+import javax.wsdl.Input;
+import javax.wsdl.Message;
+import javax.wsdl.Operation;
+import javax.wsdl.Output;
+import javax.wsdl.PortType;
+import java.util.List;
+
+/**
+ * Utility methods for working with a WSRF WSDL definition.
+ *
+ * @author Ian Springer
+ */
+public abstract class WsrfWsdlUtils
+{
+ /**
+ * DOCUMENT_ME
+ *
+ * @param mostDerivedPortType DOCUMENT_ME
+ * @param specPortType DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public static boolean implementsPortType( PortType mostDerivedPortType,
+ PortType specPortType )
+ {
+ List specOps = specPortType.getOperations( );
+ boolean foundSome = false;
+ for ( int i = 0; i < specOps.size( ); i++ )
+ {
+ Operation specOp = (Operation) specOps.get( i );
+ Operation aggregatedOp = mostDerivedPortType.getOperation( specOp.getName( ),
+ null,
+ null );
+ if ( !equals( specOp, aggregatedOp ) )
+ {
+ if ( foundSome )
+ {
+ System.out.println( "WARNING: PortType " + mostDerivedPortType.getQName( )
+ + " contains some, but not all, operations from portType "
+ + specPortType.getQName( ) );
+ }
+
+ return false;
+ }
+
+ if ( !isInheritedOperation( specOp, specPortType ) )
+ {
+ foundSome = true;
+ }
+ }
+
+ return true;
+ }
+
+ private static boolean isInheritedOperation( Operation specOp,
+ PortType specPortType )
+ {
+ return !specOp.getInput( ).getMessage( ).getQName( ).getNamespaceURI( ).equals( specPortType.getQName( )
+ .getNamespaceURI( ) );
+ }
+
+ private static boolean equals( Operation op1,
+ Operation op2 )
+ {
+ if ( op1 == null )
+ {
+ return op2 == null;
+ }
+
+ if ( op2 == null )
+ {
+ return false;
+ }
+
+ return equals( op1.getInput( ),
+ op2.getInput( ) ) && equals( op1.getOutput( ),
+ op2.getOutput( ) );
+ }
+
+ private static boolean equals( Input input1,
+ Input input2 )
+ {
+ return equals( input1.getMessage( ),
+ input2.getMessage( ) );
+ }
+
+ private static boolean equals( Output output1,
+ Output output2 )
+ {
+ return equals( output1.getMessage( ),
+ output2.getMessage( ) );
+ }
+
+ private static boolean equals( Message msg1,
+ Message msg2 )
+ {
+ return msg1.getQName( ).equals( msg2.getQName( ) );
+ }
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: apollo-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: apollo-dev-help@ws.apache.org