Glen, Based on this, it looks like it's safe for me to switch from ServiceDesc.getOperations() to ServiceDesc.getAllowedMethods() for the service details listing. Yes?
Alan -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Sent: Wednesday, April 03, 2002 1:10 AM To: [EMAIL PROTECTED] Subject: cvs commit: xml-axis/java/test/wsdd TestAllowedMethods.java gdaniels 02/04/02 22:09:56 Modified: java/src/org/apache/axis/deployment/wsdd WSDDService.java java/src/org/apache/axis/description ServiceDesc.java TypeDesc.java java/src/org/apache/axis/wsdl/fromJava Emitter.java java/src/org/apache/axis/wsdl/toJava JavaBeanHelperWriter.java JavaWriter.java java/test/encoding AttributeBean.java RETURN.java SimpleBean.java TestAttributes.java Added: java/test/encoding ParentBean.java java/test/wsdd TestAllowedMethods.java Log: * Make TypeDescs handle inheritance. Next step is to make this more efficient (only look for the parent TypeDesc once). * TypeDescs now require a Class in the constructor * Introduce a ParentBean to the attributes test to test this functionality. * Pass allowedMethods down into the ServiceDesc. Revision Changes Path 1.51 +11 -0 xml-axis/java/src/org/apache/axis/deployment/wsdd/WSDDService.java Index: WSDDService.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/deployment/wsdd/WSDDService.java ,v retrieving revision 1.50 retrieving revision 1.51 diff -u -r1.50 -r1.51 --- WSDDService.java 1 Apr 2002 20:29:40 -0000 1.50 +++ WSDDService.java 3 Apr 2002 06:09:55 -0000 1.51 @@ -76,6 +76,8 @@ import java.util.HashMap; import java.util.Set; import java.util.Iterator; +import java.util.ArrayList; +import java.util.StringTokenizer; import java.io.IOException; import java.beans.IntrospectionException; @@ -190,6 +192,15 @@ } } + String allowedMethods = getParameter("allowedMethods"); + if (allowedMethods != null) { + ArrayList methodList = new ArrayList(); + StringTokenizer tokenizer = new StringTokenizer(allowedMethods, " ,"); + while (tokenizer.hasMoreTokens()) { + methodList.add(tokenizer.nextToken()); + } + //desc.setAllowedMethods(methodList); + } } /** 1.13 +3 -3 xml-axis/java/src/org/apache/axis/description/ServiceDesc.java Index: ServiceDesc.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/description/ServiceDesc.java,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- ServiceDesc.java 2 Apr 2002 19:07:16 -0000 1.12 +++ ServiceDesc.java 3 Apr 2002 06:09:55 -0000 1.13 @@ -92,7 +92,7 @@ /** List of allowed methods */ /** null allows everything, an empty ArrayList allows nothing */ - private ArrayList allowedMethods = null; + private List allowedMethods = null; /** List if disallowed methods */ private List disallowedMethods = null; @@ -178,11 +178,11 @@ this.wsdlFileName = wsdlFileName; } - public ArrayList getAllowedMethods() { + public List getAllowedMethods() { return allowedMethods; } - public void setAllowedMethods(ArrayList allowedMethods) { + public void setAllowedMethods(List allowedMethods) { this.allowedMethods = allowedMethods; } 1.9 +77 -3 xml-axis/java/src/org/apache/axis/description/TypeDesc.java Index: TypeDesc.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/description/TypeDesc.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- TypeDesc.java 2 Apr 2002 21:24:40 -0000 1.8 +++ TypeDesc.java 3 Apr 2002 06:09:55 -0000 1.9 @@ -72,6 +72,10 @@ public class TypeDesc { public static Class [] noClasses = new Class [] {}; + public TypeDesc(Class javaClass) { + this.javaClass = javaClass; + } + /** * Static function for centralizing access to type metadata for a * given class. @@ -109,6 +113,8 @@ return null; } + private Class javaClass = null; + private FieldDesc [] fields; /** A cache of FieldDescs by name */ @@ -124,6 +130,24 @@ return fields; } + public FieldDesc[] getFields(boolean searchParents) { + if (searchParents) { + // check superclasses if they exist + Class cls = javaClass.getSuperclass(); + if (cls != null && !cls.getName().startsWith("java.")) { + TypeDesc superDesc = getTypeDescForClass(cls); + if (superDesc != null) { + FieldDesc [] parentFields = superDesc.getFields(true); + FieldDesc [] ret = new FieldDesc[parentFields.length + fields.length]; + System.arraycopy(fields, 0, ret, 0, fields.length); + System.arraycopy(parentFields, 0, ret, fields.length, parentFields.length); + } + } + } + + return fields; + } + /** * Replace the array of FieldDescs, making sure we keep our convenience * caches in sync. @@ -177,8 +201,18 @@ public QName getElementNameForField(String fieldName) { FieldDesc desc = (FieldDesc)fieldNameMap.get(fieldName); - if (desc == null || !desc.isElement()) + if (desc == null) { + // check superclasses if they exist + Class cls = javaClass.getSuperclass(); + if (cls != null && !cls.getName().startsWith("java.")) { + TypeDesc superDesc = getTypeDescForClass(cls); + if (superDesc != null) { + return superDesc.getElementNameForField(fieldName); + } + } + } else if (!desc.isElement()) { return null; + } return desc.getXmlName(); } @@ -189,8 +223,18 @@ public QName getAttributeNameForField(String fieldName) { FieldDesc desc = (FieldDesc)fieldNameMap.get(fieldName); - if (desc == null || desc.isElement()) + if (desc == null) { + // check superclasses if they exist + Class cls = javaClass.getSuperclass(); + if (cls != null && !cls.getName().startsWith("java.")) { + TypeDesc superDesc = getTypeDescForClass(cls); + if (superDesc != null) { + return superDesc.getAttributeNameForField(fieldName); + } + } + } else if (desc.isElement()) { return null; + } QName ret = desc.getXmlName(); if (ret == null) { ret = new QName("", fieldName); @@ -221,6 +265,15 @@ } } } + + // check superclasses if they exist + Class cls = javaClass.getSuperclass(); + if (cls != null && !cls.getName().startsWith("java.")) { + TypeDesc superDesc = getTypeDescForClass(cls); + if (superDesc != null) { + return superDesc.getFieldNameForElement(qname, ignoreNS); + } + } return null; } @@ -253,6 +306,17 @@ } } + if (possibleMatch == null) { + // check superclasses if they exist + Class cls = javaClass.getSuperclass(); + if (cls != null && !cls.getName().startsWith("java.")) { + TypeDesc superDesc = getTypeDescForClass(cls); + if (superDesc != null) { + possibleMatch = superDesc.getFieldNameForAttribute(qname); + } + } + } + return possibleMatch; } @@ -261,7 +325,17 @@ */ public FieldDesc getFieldByName(String name) { - return (FieldDesc)fieldNameMap.get(name); + FieldDesc ret = (FieldDesc)fieldNameMap.get(name); + if (ret == null) { + Class cls = javaClass.getSuperclass(); + if (cls != null && !cls.getName().startsWith("java.")) { + TypeDesc superDesc = getTypeDescForClass(cls); + if (superDesc != null) { + ret = superDesc.getFieldByName(name); + } + } + } + return ret; } /** 1.28 +1 -0 xml-axis/java/src/org/apache/axis/wsdl/fromJava/Emitter.java Index: Emitter.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/fromJava/Emitter.java,v retrieving revision 1.27 retrieving revision 1.28 diff -u -r1.27 -r1.28 --- Emitter.java 1 Apr 2002 20:12:17 -0000 1.27 +++ Emitter.java 3 Apr 2002 06:09:55 -0000 1.28 @@ -218,6 +218,7 @@ } serviceDesc.setStopClasses(stopClasses); + serviceDesc.setAllowedMethods(allowedMethods); serviceDesc.setDisallowedMethods(disallowedMethods); Document doc = null; 1.5 +2 -1 xml-axis/java/src/org/apache/axis/wsdl/toJava/JavaBeanHelperWriter.java Index: JavaBeanHelperWriter.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/toJava/JavaBeanHelperWriter .java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- JavaBeanHelperWriter.java 2 Apr 2002 21:24:40 -0000 1.4 +++ JavaBeanHelperWriter.java 3 Apr 2002 06:09:55 -0000 1.5 @@ -156,7 +156,8 @@ boolean wroteFieldType = false; pw.println(" // " + JavaUtils.getMessage("typeMeta")); pw.println(" private static org.apache.axis.description.TypeDesc typeDesc ="); - pw.println(" new org.apache.axis.description.TypeDesc();"); + pw.println(" new org.apache.axis.description.TypeDesc(" + + rootName + ".class);"); pw.println(); pw.println(" static {"); 1.10 +3 -2 xml-axis/java/src/org/apache/axis/wsdl/toJava/JavaWriter.java Index: JavaWriter.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/toJava/JavaWriter.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- JavaWriter.java 22 Mar 2002 14:38:45 -0000 1.9 +++ JavaWriter.java 3 Apr 2002 06:09:55 -0000 1.10 @@ -95,6 +95,7 @@ protected Emitter emitter; protected QName qname; protected Namespaces namespaces; + protected String rootName; // No suffix... protected String className; protected String fileName; protected String packageName; @@ -116,8 +117,8 @@ this.emitter = emitter; this.qname = entry.getQName(); this.namespaces = emitter.getNamespaces(); - this.className = Utils.getJavaLocalName(entry.getName()) - + (suffix == null ? "" : suffix); + this.rootName = Utils.getJavaLocalName(entry.getName()); + this.className = rootName + (suffix == null ? "" : suffix); this.fileName = className + '.' + extension; this.packageName = Utils.getJavaPackageName(entry.getName()); this.message = message; 1.4 +16 -5 xml-axis/java/test/encoding/AttributeBean.java Index: AttributeBean.java =================================================================== RCS file: /home/cvs/xml-axis/java/test/encoding/AttributeBean.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- AttributeBean.java 24 Mar 2002 18:51:29 -0000 1.3 +++ AttributeBean.java 3 Apr 2002 06:09:55 -0000 1.4 @@ -65,7 +65,7 @@ /** * Simple Java Bean with fields that should be serialized as attributes */ -public class AttributeBean implements java.io.Serializable { +public class AttributeBean extends ParentBean { private int age; private float iD; private java.lang.String name; // attribute @@ -124,16 +124,27 @@ return false; if (other.getMale() != male) return false; - if (name == null) - return other.getName() == null; - return name.equals(other.getName()); + if (name == null) { + if (other.getName() != null) { + return false; + } + } + if (!name.equals(other.getName())) { + return false; + } + if (getParentFloat() != other.getParentFloat()) + return false; + if (getParentStr() != null) { + return getParentStr().equals(other.getParentStr()); + } + return other.getParentStr() == null; } // Type metadata private static TypeDesc typeDesc; static { - typeDesc = new TypeDesc(); + typeDesc = new TypeDesc(AttributeBean.class); FieldDesc field; // An attribute with a specified QName 1.3 +1 -1 xml-axis/java/test/encoding/RETURN.java Index: RETURN.java =================================================================== RCS file: /home/cvs/xml-axis/java/test/encoding/RETURN.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- RETURN.java 2 Apr 2002 21:25:15 -0000 1.2 +++ RETURN.java 3 Apr 2002 06:09:55 -0000 1.3 @@ -152,7 +152,7 @@ // Type metadata private static org.apache.axis.description.TypeDesc typeDesc = - new org.apache.axis.description.TypeDesc(); + new org.apache.axis.description.TypeDesc(RETURN.class); static { org.apache.axis.description.FieldDesc field = new org.apache.axis.description.ElementDesc(); 1.2 +1 -1 xml-axis/java/test/encoding/SimpleBean.java Index: SimpleBean.java =================================================================== RCS file: /home/cvs/xml-axis/java/test/encoding/SimpleBean.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- SimpleBean.java 8 Mar 2002 05:04:54 -0000 1.1 +++ SimpleBean.java 3 Apr 2002 06:09:55 -0000 1.2 @@ -68,7 +68,7 @@ public String value; // Our "actual" value public float temp; // An attribute - private static TypeDesc typeDesc = new TypeDesc(); + private static TypeDesc typeDesc = new TypeDesc(SimpleBean.class); static { FieldDesc fd = new AttributeDesc(); fd.setFieldName("temp"); 1.4 +15 -14 xml-axis/java/test/encoding/TestAttributes.java Index: TestAttributes.java =================================================================== RCS file: /home/cvs/xml-axis/java/test/encoding/TestAttributes.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- TestAttributes.java 24 Mar 2002 18:51:29 -0000 1.3 +++ TestAttributes.java 3 Apr 2002 06:09:55 -0000 1.4 @@ -15,6 +15,7 @@ import org.apache.axis.encoding.ser.SimpleNonPrimitiveSerializerFactory; import org.apache.axis.Constants; import org.apache.axis.Message; +import org.apache.axis.configuration.BasicServerConfig; import org.apache.axis.description.TypeDesc; import org.apache.axis.description.FieldDesc; import org.apache.axis.description.OperationDesc; @@ -38,7 +39,7 @@ /** * Test the serialization of a bean with attributes - * + * * @author Tom Jordahl ([EMAIL PROTECTED]) * @author Glen Daniels ([EMAIL PROTECTED]) */ @@ -47,50 +48,50 @@ LogFactory.getLog(TestAttributes.class.getName()); public static final String myNS = "urn:myNS"; - + public static void main(String [] args) throws Exception { TestAttributes tester = new TestAttributes("TestAttributes"); tester.testBean(); tester.testSimpleType(); } - + public TestAttributes(String name) { super(name); } - + public void testBean () throws Exception { - MessageContext msgContext = new MessageContext(new AxisServer()); + MessageContext msgContext = new MessageContext(new AxisServer(new BasicServerConfig())); SOAPEnvelope msg = new SOAPEnvelope(); - + // Create bean with data AttributeBean bean = new AttributeBean(); bean.setAge(35); bean.setID(1.15F); bean.setMale(true); bean.setName("James Bond"); - + RPCParam arg = new RPCParam("", "struct", bean); RPCElement body = new RPCElement("urn:myNamespace", "method1", new Object[]{ arg }); msg.addBodyElement(body); body.setEncodingStyle(null); - + Writer stringWriter = new StringWriter(); SerializationContext context = new SerializationContextImpl(stringWriter, msgContext); context.setDoMultiRefs(false); // no multirefs context.setPretty(false); - + // Create a TypeMapping and register the Bean serializer/deserializer TypeMappingRegistry reg = context.getTypeMappingRegistry(); TypeMapping tm = (TypeMapping) reg.createTypeMapping(); // The "" namespace is literal (no encoding). tm.setSupportedNamespaces(new String[] {Constants.URI_CURRENT_SOAP_ENC}); reg.register(Constants.URI_CURRENT_SOAP_ENC, tm); - + QName beanQName = new QName("typeNS", "TheBean"); - tm.register(AttributeBean.class, - beanQName, - new BeanSerializerFactory(AttributeBean.class, beanQName), + tm.register(AttributeBean.class, + beanQName, + new BeanSerializerFactory(AttributeBean.class, beanQName), new BeanDeserializerFactory(AttributeBean.class, beanQName)); // Serialize the bean in to XML @@ -124,7 +125,7 @@ SimpleBean bean = new SimpleBean("test value"); bean.temp = 85.0F; - MessageContext msgContext = new MessageContext(new AxisServer()); + MessageContext msgContext = new MessageContext(new AxisServer(new BasicServerConfig())); SOAPEnvelope msg = new SOAPEnvelope(); RPCParam arg = new RPCParam("", "simple", bean); 1.1 xml-axis/java/test/encoding/ParentBean.java Index: ParentBean.java =================================================================== /* * The Apache Software License, Version 1.1 * * * Copyright (c) 2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Axis" and "Apache Software Foundation" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache", * nor may "Apache" appear in their name, without prior written * permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package test.encoding; import org.apache.axis.description.TypeDesc; import org.apache.axis.description.FieldDesc; import org.apache.axis.description.AttributeDesc; import org.apache.axis.description.ElementDesc; import javax.xml.rpc.namespace.QName; /** * @author Glen Daniels ([EMAIL PROTECTED]) */ public class ParentBean { private float parentFloat; // attribute private String parentStr; // element public float getParentFloat() { return parentFloat; } public void setParentFloat(float parentFloat) { this.parentFloat = parentFloat; } public String getParentStr() { return parentStr; } public void setParentStr(String parentStr) { this.parentStr = parentStr; } // Type metadata private static TypeDesc typeDesc; static { typeDesc = new TypeDesc(ParentBean.class); FieldDesc field; // An attribute with a specified QName field = new AttributeDesc(); field.setFieldName("parentFloat"); field.setXmlName(new QName("", "parentAttr")); typeDesc.addFieldDesc(field); // An element with a specified QName field = new ElementDesc(); field.setFieldName("parentStr"); field.setXmlName(new QName("", "parentElement")); typeDesc.addFieldDesc(field); } public static TypeDesc getTypeDesc() { return typeDesc; } } 1.1 xml-axis/java/test/wsdd/TestAllowedMethods.java Index: TestAllowedMethods.java =================================================================== /* * Created by IntelliJ IDEA. * User: gdaniels * Date: Apr 2, 2002 * Time: 10:14:06 AM * To change template for new class use * Code Style | Class Templates options (Tools | IDE Options). */ package test.wsdd; import org.apache.axis.deployment.wsdd.WSDDConstants; import org.apache.axis.server.AxisServer; import org.apache.axis.configuration.XMLStringProvider; import org.apache.axis.transport.local.LocalTransport; import org.apache.axis.client.Call; import org.apache.axis.client.Service; import junit.framework.TestCase; public class TestAllowedMethods extends TestCase { static final String SERVICE_NAME = "AllowedMethodService"; private static final String MESSAGE = "Allowed method"; AxisServer server; LocalTransport transport; // Two-part WSDD, with a space for scope option in the middle static final String doc1 = "<deployment xmlns=\"http://xml.apache.org/axis/wsdd/\" " + "xmlns:java=\"" + WSDDConstants.WSDD_JAVA + "\">\n" + " <service name=\"" + SERVICE_NAME + "\" " + "provider=\"java:RPC\">\n" + " <parameter name=\"allowedMethods\" value=\"allowed\"/>" + " <parameter name=\"className\" value=\"test.wsdd.TestAllowedMethods\"/>" + " </service>\n" + "</deployment>"; public TestAllowedMethods() { super("test"); } public TestAllowedMethods(String s) { super(s); } protected void setUp() throws Exception { XMLStringProvider config = new XMLStringProvider(doc1); server = new AxisServer(config); transport = new LocalTransport(server); transport.setRemoteService(SERVICE_NAME); } public void testAllowedMethods() throws Exception { Call call = new Call(new Service()); call.setTransport(transport); String ret = (String)call.invoke("allowed", null); assertEquals("Return didn't match", MESSAGE, ret); try { ret = (String)call.invoke("disallowed", null); } catch (Exception e) { // Success, we shouldn't have been allowed to call that. return; } fail("Successfully called disallowed method!"); } public String disallowed() throws Exception { return "You shouldn't have called me!"; } public String allowed() { return MESSAGE; } }