You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jaxme-dev@ws.apache.org by jo...@apache.org on 2004/09/07 13:01:48 UTC

cvs commit: ws-jaxme/src/js/org/apache/ws/jaxme/js/pattern Ant.java

jochen      2004/09/07 04:01:47

  Modified:    src/js/org/apache/ws/jaxme/js/junit
                        XmlRpcClientTestRemoteClass.java
                        XmlRpcClientTest.java
               src/js/org/apache/ws/jaxme/js/apps XmlRpcCaller.java
                        XmlRpcClientGenerator.java
               src/js/org/apache/ws/jaxme/js/util JavaParser.java
               src/js/org/apache/ws/jaxme/js/pattern Ant.java
  Log:
  Bug fixes on the XML-RPC client.
  
  Revision  Changes    Path
  1.2       +6 -1      ws-jaxme/src/js/org/apache/ws/jaxme/js/junit/XmlRpcClientTestRemoteClass.java
  
  Index: XmlRpcClientTestRemoteClass.java
  ===================================================================
  RCS file: /home/cvs/ws-jaxme/src/js/org/apache/ws/jaxme/js/junit/XmlRpcClientTestRemoteClass.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- XmlRpcClientTestRemoteClass.java	7 Sep 2004 00:47:27 -0000	1.1
  +++ XmlRpcClientTestRemoteClass.java	7 Sep 2004 11:01:47 -0000	1.2
  @@ -1,5 +1,8 @@
   package org.apache.ws.jaxme.js.junit;
   
  +import java.io.IOException;
  +import java.net.MalformedURLException;
  +
   
   /** A test class, does nothing useful.
    */
  @@ -32,8 +35,10 @@
       }
   
       /** Converts the sum into a string and returns it.
  +     * @throws IOException Never actually thrown, just to verify
  +     *   whether exceptions in the signature are handled properly.
        */
  -    public String getSumAsString() {
  +    public String getSumAsString() throws IOException, MalformedURLException {
       	return Integer.toString(sum);
       }
   }
  
  
  
  1.2       +15 -2     ws-jaxme/src/js/org/apache/ws/jaxme/js/junit/XmlRpcClientTest.java
  
  Index: XmlRpcClientTest.java
  ===================================================================
  RCS file: /home/cvs/ws-jaxme/src/js/org/apache/ws/jaxme/js/junit/XmlRpcClientTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- XmlRpcClientTest.java	7 Sep 2004 00:47:27 -0000	1.1
  +++ XmlRpcClientTest.java	7 Sep 2004 11:01:47 -0000	1.2
  @@ -1,5 +1,6 @@
   package org.apache.ws.jaxme.js.junit;
   
  +import java.io.IOException;
   import java.lang.reflect.UndeclaredThrowableException;
   import java.util.Vector;
   
  @@ -39,8 +40,20 @@
       	assertEquals(pSum, server.getSum());
           assertEquals(pSum, client.getSum());
           String sumAsString = Integer.toString(pSum);
  -        assertEquals(sumAsString, server.getSumAsString());
  -        assertEquals(sumAsString, client.getSumAsString());
  +        try {
  +        	assertEquals(sumAsString, server.getSumAsString());
  +        } catch (IOException e) {
  +            // This IOException is never actually thrown.
  +            // However, the try .. catch clause ensures, that
  +            // it is present in the signature of server.getSumAsString().
  +        }
  +        try {
  +        	assertEquals(sumAsString, client.getSumAsString());
  +        } catch (IOException e) {
  +            // This IOException is never actually thrown.
  +            // However, the try .. catch clause ensures, that
  +            // it is present in the signature of client.getSumAsString().
  +        }
       }
   
       /** Creates a dispatcher and uses it to run the
  
  
  
  1.2       +1 -1      ws-jaxme/src/js/org/apache/ws/jaxme/js/apps/XmlRpcCaller.java
  
  Index: XmlRpcCaller.java
  ===================================================================
  RCS file: /home/cvs/ws-jaxme/src/js/org/apache/ws/jaxme/js/apps/XmlRpcCaller.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- XmlRpcCaller.java	6 Sep 2004 14:51:57 -0000	1.1
  +++ XmlRpcCaller.java	7 Sep 2004 11:01:47 -0000	1.2
  @@ -12,5 +12,5 @@
   	/** Call the server, invoking the method named <code>pName</code>,
        * passing the arguments given by <code>pVector</code>.
   	 */
  -    public Object xmlRpcCall(String pName, Vector pVector);
  +    public Object xmlRpcCall(String pName, Vector pVector) throws Exception;
   }
  
  
  
  1.3       +33 -3     ws-jaxme/src/js/org/apache/ws/jaxme/js/apps/XmlRpcClientGenerator.java
  
  Index: XmlRpcClientGenerator.java
  ===================================================================
  RCS file: /home/cvs/ws-jaxme/src/js/org/apache/ws/jaxme/js/apps/XmlRpcClientGenerator.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- XmlRpcClientGenerator.java	7 Sep 2004 00:47:27 -0000	1.2
  +++ XmlRpcClientGenerator.java	7 Sep 2004 11:01:47 -0000	1.3
  @@ -1,5 +1,7 @@
   package org.apache.ws.jaxme.js.apps;
   
  +import java.lang.reflect.Method;
  +import java.lang.reflect.UndeclaredThrowableException;
   import java.util.ArrayList;
   import java.util.HashMap;
   import java.util.Iterator;
  @@ -76,7 +78,9 @@
        * requested type <code>pType</code>.
        */
       protected Object getResultValue(JavaMethod pMethod, JavaQName pType, Object pValue) {
  -    	if (JavaQNameImpl.BYTE.equals(pType)) {
  +        if (JavaQNameImpl.BOOLEAN.equals(pType)) {
  +            return new Object[]{"((", Boolean.class, ") ", pValue, ").booleanValue()"};
  +        } else if (JavaQNameImpl.BYTE.equals(pType)) {
       		return new Object[]{"((", Byte.class, ") ", pValue, ").byteValue()"};
           } else if (JavaQNameImpl.SHORT.equals(pType)) {
               return new Object[]{"((", Short.class, ") ", pValue, ").shortValue()"};
  @@ -151,9 +155,24 @@
   
       /** Generates a method, invoking method <code>pMethod</code> using
        * the name <code>pName</code>.
  +     * @throws NoSuchMethodException
  +     * @throws SecurityException
        */
       protected JavaMethod getMethod(JavaSource pJs, JavaField pCaller,
  -                                   String pName, JavaMethod pMethod) {
  +                                   String pName, JavaMethod pMethod)
  +            throws SecurityException, NoSuchMethodException {
  +    	Method m = XmlRpcCaller.class.getMethod("xmlRpcCall", new Class[]{String.class, Vector.class});
  +        Class[] exceptions = m.getExceptionTypes();
  +        List exceptionList = new ArrayList();
  +        if (exceptions != null) {
  +        	for (int i = 0;  i < exceptions.length;  i++) {
  +        		JavaQName qName = JavaQNameImpl.getInstance(exceptions[i]);
  +                if (!pMethod.isThrowing(qName)) {
  +                	exceptionList.add(qName);
  +                }
  +        	}
  +        }
  +        
           JavaMethod jm = pJs.newJavaMethod(pMethod);
           LocalJavaField v = jm.newJavaField(Vector.class);
           v.addLine("new ", Vector.class, "()");
  @@ -162,6 +181,9 @@
           	Parameter p = params[i];
               jm.addLine(v, ".add(", getInputValue(jm, p.getType(), p), ");");
           }
  +        if (!exceptionList.isEmpty()) {
  +        	jm.addTry();
  +        }
           Object result = new Object[]{pCaller, ".xmlRpcCall(",
           		                     JavaSource.getQuoted(pName), ", ", v, ")"};
           if (JavaQNameImpl.VOID.equals(jm.getType())) {
  @@ -169,6 +191,14 @@
           } else {
           	jm.addLine("return ", getResultValue(jm, jm.getType(), result), ";");
           }
  +        if (!exceptionList.isEmpty()) {
  +            for (int i = 0;  i < exceptionList.size();  i++) {
  +            	JavaQName exClass = (JavaQName) exceptionList.get(i);
  +                DirectAccessible e = jm.addCatch(exClass);
  +                jm.addThrowNew(UndeclaredThrowableException.class, e);
  +            }
  +            jm.addEndTry();
  +        }
           return jm;
       }
   
  @@ -197,7 +227,7 @@
       /** Creates a new client class, which is invoking the given
        * server side class <code>pSource</code>.
        */
  -    public JavaSource addClass(JavaSource pSource) {
  +    public JavaSource addClass(JavaSource pSource) throws SecurityException, NoSuchMethodException {
           JavaSource js = getFactory().newJavaSource(JavaQNameImpl.getInstance(getTargetPackage(), pSource.getQName().getClassName()), JavaSource.PUBLIC);
           JavaField jf = getXmlRpcCaller(js);
           getConstructor(js, jf);
  
  
  
  1.6       +23 -0     ws-jaxme/src/js/org/apache/ws/jaxme/js/util/JavaParser.java
  
  Index: JavaParser.java
  ===================================================================
  RCS file: /home/cvs/ws-jaxme/src/js/org/apache/ws/jaxme/js/util/JavaParser.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- JavaParser.java	7 Sep 2004 00:47:27 -0000	1.5
  +++ JavaParser.java	7 Sep 2004 11:01:47 -0000	1.6
  @@ -130,12 +130,19 @@
           return sb.toString();
       }
   
  +    private String parseSimpleIdentifier(AST pAST) {
  +        StringBuffer sb = new StringBuffer();
  +        parseIdentifier(pAST, sb);
  +        return sb.toString();
  +    }
  +
       private void parseIdentifier(AST pAST, StringBuffer sb) {
       	switch (pAST.getType()) {
   	        case JavaTokenTypes.ANNOTATIONS:
   	        	// Ignore this
   	        	break;
   	        case JavaTokenTypes.LITERAL_void:
  +            case JavaTokenTypes.LITERAL_boolean:
   	        case JavaTokenTypes.LITERAL_byte:
   	        case JavaTokenTypes.LITERAL_char:
   	        case JavaTokenTypes.LITERAL_short:
  @@ -264,6 +271,9 @@
       }
   
       private JavaQName getQName(String pName) {
  +        if (pName.endsWith("[]")) {
  +        	return JavaQNameImpl.getArray(getQName(pName.substring(0, pName.length()-2)));
  +        }
       	int offset = pName.indexOf('.');
       	String firstIdent;
       	String suffix;
  @@ -376,16 +386,29 @@
           }
       }
   
  +    private void parseExceptions(AbstractJavaMethod pMethod, AST pAST) {
  +        AST throwsClause = findChild(pAST, JavaTokenTypes.LITERAL_throws);
  +        if (throwsClause != null) {
  +        	for (AST child = throwsClause.getFirstChild();  child != null;  child = child.getNextSibling()) {
  +        		String ident = parseSimpleIdentifier(child);
  +                JavaQName qName = getQName(ident);
  +                pMethod.addThrows(qName);
  +            }
  +        }
  +    }
  +
       private void parseMethodDefinition(JavaSource pSource, AST pAST) {
       	JavaMethod jm = getJavaMethod(pSource, pAST);
           parseModifiers(jm, pAST);
           parseParameters(jm, pAST);
  +        parseExceptions(jm, pAST);
       }
   
       private void parseConstructorDefinition(JavaSource pSource, AST pAST) {
       	JavaConstructor jc = pSource.newJavaConstructor(JavaSource.DEFAULT_PROTECTION);
           parseModifiers(jc, pAST);
           parseParameters(jc, pAST);
  +        parseExceptions(jc, pAST);
       }
   
       private void parseObjects(JavaSource pSource, AST pAST) {
  
  
  
  1.7       +9 -3      ws-jaxme/src/js/org/apache/ws/jaxme/js/pattern/Ant.java
  
  Index: Ant.java
  ===================================================================
  RCS file: /home/cvs/ws-jaxme/src/js/org/apache/ws/jaxme/js/pattern/Ant.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- Ant.java	6 Sep 2004 14:51:57 -0000	1.6
  +++ Ant.java	7 Sep 2004 11:01:47 -0000	1.7
  @@ -48,6 +48,7 @@
   import org.apache.tools.ant.AntClassLoader;
   import org.apache.tools.ant.BuildException;
   import org.apache.tools.ant.DirectoryScanner;
  +import org.apache.tools.ant.Project;
   import org.apache.tools.ant.Task;
   import org.apache.tools.ant.types.FileSet;
   import org.apache.tools.ant.types.Path;
  @@ -595,7 +596,7 @@
                   DirectoryScanner ds = fs.getDirectoryScanner(getProject());
                   String[] files = ds.getIncludedFiles();
                   for (int j = 0;  j < files.length;  j++) {
  -                    String s = files[i];
  +                    String s = files[j];
                       Reflector r;
                       if (s.endsWith(".class")) {
                           s = s.substring(0, s.length() - ".class".length());
  @@ -608,7 +609,12 @@
                                                    getLocation());
                       }
                       JavaSource js = r.getJavaSource(new JavaSourceFactory());
  -                    gen.addClass(js);
  +                    if (js.isAbstract()) {
  +                    	getProject().log("Ignoring abstract class " + js.getQName(), Project.MSG_VERBOSE);
  +                    } else {
  +                        getProject().log("Generating XML-RPC client for " + js.getQName(), Project.MSG_DEBUG);
  +                    	gen.addClass(js);
  +                    }
                   }
               }
               if (getDispatcher() != null) {
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: jaxme-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: jaxme-dev-help@ws.apache.org