Return-Path: Delivered-To: apmail-jakarta-avalon-cvs-archive@apache.org Received: (qmail 93073 invoked from network); 1 Feb 2003 12:29:24 -0000 Received: from exchange.sun.com (192.18.33.10) by daedalus.apache.org with SMTP; 1 Feb 2003 12:29:24 -0000 Received: (qmail 26654 invoked by uid 97); 1 Feb 2003 12:30:51 -0000 Delivered-To: qmlist-jakarta-archive-avalon-cvs@nagoya.betaversion.org Received: (qmail 26647 invoked from network); 1 Feb 2003 12:30:50 -0000 Received: from daedalus.apache.org (HELO apache.org) (208.185.179.12) by nagoya.betaversion.org with SMTP; 1 Feb 2003 12:30:50 -0000 Received: (qmail 92967 invoked by uid 500); 1 Feb 2003 12:29:23 -0000 Mailing-List: contact avalon-cvs-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Avalon CVS List" Reply-To: "Avalon Developers List" Delivered-To: mailing list avalon-cvs@jakarta.apache.org Received: (qmail 92956 invoked by uid 500); 1 Feb 2003 12:29:22 -0000 Received: (qmail 92953 invoked from network); 1 Feb 2003 12:29:22 -0000 Received: from icarus.apache.org (208.185.179.13) by daedalus.apache.org with SMTP; 1 Feb 2003 12:29:22 -0000 Received: (qmail 44766 invoked by uid 1233); 1 Feb 2003 12:29:22 -0000 Date: 1 Feb 2003 12:29:22 -0000 Message-ID: <20030201122922.44765.qmail@icarus.apache.org> From: hammant@apache.org To: jakarta-avalon-excalibur-cvs@apache.org Subject: cvs commit: jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/generator ProxyGeneratorImpl.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N hammant 2003/02/01 04:29:21 Modified: altrmi/src/java/org/apache/excalibur/altrmi/generator ProxyGeneratorImpl.java Log: javac proxy gen passes printwriter as param now Revision Changes Path 1.22 +144 -145 jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/generator/ProxyGeneratorImpl.java Index: ProxyGeneratorImpl.java =================================================================== RCS file: /home/cvs/jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/generator/ProxyGeneratorImpl.java,v retrieving revision 1.21 retrieving revision 1.22 diff -u -r1.21 -r1.22 --- ProxyGeneratorImpl.java 1 Feb 2003 11:33:49 -0000 1.21 +++ ProxyGeneratorImpl.java 1 Feb 2003 12:29:21 -0000 1.22 @@ -32,9 +32,6 @@ public class ProxyGeneratorImpl extends AbstractProxyGenerator { - private PrintWriter m_classSource; - - /** * Method generate * @@ -135,9 +132,10 @@ String filename = getSrcGenDir() + File.separator + "AltrmiGenerated" + getGenName() + "_" + name + ".java"; + PrintWriter classSource = null; try { - m_classSource = new PrintWriter( new FileOutputStream( filename ) ); + classSource = new PrintWriter( new FileOutputStream( filename ) ); } catch( FileNotFoundException e ) { @@ -145,42 +143,42 @@ + filename + "'" ); } - m_classSource.print( "public final class AltrmiGenerated" + getGenName() + "_" + name ); - m_classSource.println( " implements org.apache.excalibur.altrmi.client.Proxy, " ); - generateInterfaceList( m_classSource, interfacesToExpose ); - m_classSource.println( " { " ); - m_classSource.println( + classSource.print( "public final class AltrmiGenerated" + getGenName() + "_" + name ); + classSource.println( " implements org.apache.excalibur.altrmi.client.Proxy, " ); + generateInterfaceList( classSource, interfacesToExpose ); + classSource.println( " { " ); + classSource.println( " private transient org.apache.excalibur.altrmi.client.ProxyHelper m_proxyHelper;" ); if (needsAsyncBehavior(interfacesToExpose)) { - m_classSource.println( + classSource.println( " private transient java.util.Vector m_asyncInvocations = new java.util.Vector();" ); } // Generate Constructor - m_classSource.println( + classSource.println( " public AltrmiGenerated" + getGenName() + "_" + name + " (org.apache.excalibur.altrmi.client.ProxyHelper proxyHelper) {" ); - m_classSource.println( " m_proxyHelper = proxyHelper;" ); - m_classSource.println( " }" ); + classSource.println( " m_proxyHelper = proxyHelper;" ); + classSource.println( " }" ); // helper method for the factory. // from Proxy interface - m_classSource + classSource .println( " public Long altrmiGetReferenceID(Object factoryThatIsAsking) {" ); - m_classSource + classSource .println( " return m_proxyHelper.getReferenceID(factoryThatIsAsking);" ); - m_classSource.println( " }" ); + classSource.println( " }" ); - makeSourceInterfaces(interfacesToExpose, methodsDone); + makeSourceInterfaces(classSource, interfacesToExpose, methodsDone); - m_classSource.print( "}" ); - m_classSource.close(); + classSource.print( "}" ); + classSource.close(); } - private void makeSourceInterfaces(PublicationDescriptionItem[] interfacesToExpose, + private void makeSourceInterfaces(PrintWriter classSource, PublicationDescriptionItem[] interfacesToExpose, Vector methodsDone) throws ProxyGenerationException { // TODO DefaultProxyHelper altrmiGetProxyHelper(); @@ -224,6 +222,7 @@ if( !methodsDone.contains( methodSignature ) ) { makeSourceInterfacesMethodsNotDone( + classSource, methodsDone, methodSignature, method, @@ -238,7 +237,7 @@ } } - private void makeSourceInterfacesMethodsNotDone(Vector methodsDone, + private void makeSourceInterfacesMethodsNotDone(PrintWriter classSource, Vector methodsDone, String methodSignature, Method method, boolean async, boolean commit, boolean rollback) throws ProxyGenerationException @@ -255,7 +254,7 @@ String mName = method.getName(); - m_classSource.print( " public " + generateReturnValue( rClass ) + " " + mName + classSource.print( " public " + generateReturnValue( rClass ) + " " + mName + " (" ); Class[] argTypes = method.getParameterTypes(); @@ -272,157 +271,157 @@ + " must be serializable" ); } - generateParameter( argTypes[ i ], i ); + generateParameter( classSource, argTypes[ i ], i ); } - m_classSource.print( ") " ); + classSource.print( ") " ); Class[] throwsTypes = method.getExceptionTypes(); for( int i = 0; i < throwsTypes.length; i++ ) { - generateThrows( i, throwsTypes ); + generateThrows( classSource, i, throwsTypes ); } - m_classSource.println( "{" ); + classSource.println( "{" ); if (async) { - m_classSource.println( " synchronized(m_asyncInvocations) {" ); - generateAsyncMethodBody(argTypes, rClass, methodSignature, method); - m_classSource.println( " }" ); + classSource.println( " synchronized(m_asyncInvocations) {" ); + generateAsyncMethodBody(classSource, argTypes, rClass, methodSignature, method); + classSource.println( " }" ); } else if (commit) { - m_classSource.println( " synchronized(m_asyncInvocations) {" ); - generateAsyncMethodBody(argTypes, rClass, methodSignature, method); - generateAsyncCommitMethodBody(); - m_classSource.println( " }" ); + classSource.println( " synchronized(m_asyncInvocations) {" ); + generateAsyncMethodBody(classSource, argTypes, rClass, methodSignature, method); + generateAsyncCommitMethodBody(classSource); + classSource.println( " }" ); } else if (rollback) { - m_classSource.println( " synchronized(m_asyncInvocations) {" ); - generateAsyncRollbackMethodBody(argTypes, methodSignature); - m_classSource.println( " }" ); + classSource.println( " synchronized(m_asyncInvocations) {" ); + generateAsyncRollbackMethodBody(classSource, argTypes, methodSignature); + classSource.println( " }" ); } else { - generateNonAsyncMethodBody(argTypes, rClass, methodSignature, method); + generateNonAsyncMethodBody(classSource, argTypes, rClass, methodSignature, method); } - m_classSource.println( " " + + classSource.println( " " + "" + "" + "}" ); } - private void generateNonAsyncMethodBody(Class[] argTypes, Class rClass, String methodSignature, Method method) + private void generateNonAsyncMethodBody(PrintWriter classSource, Class[] argTypes, Class rClass, String methodSignature, Method method) { Class[] throwsTypes; - generateMethodArgs(argTypes); + generateMethodArgs(classSource, argTypes); - m_classSource.println( " try {" ); + classSource.println( " try {" ); if( rClass.equals( "void" ) ) { - m_classSource.println( " m_proxyHelper.processVoidRequest(\"" + classSource.println( " m_proxyHelper.processVoidRequest(\"" + methodSignature.toString() + "\",args);" ); } else { - makeSourceInterfacesMethodsNotDoneNotVoid(method, rClass, methodSignature); + makeSourceInterfacesMethodsNotDoneNotVoid(classSource, method, rClass, methodSignature); } - m_classSource.println( " } catch (Throwable t) {" ); + classSource.println( " } catch (Throwable t) {" ); throwsTypes = method.getExceptionTypes(); for( int i = 0; i < throwsTypes.length; i++ ) { - generateThrowHandler( i, throwsTypes ); + generateThrowHandler( classSource, i, throwsTypes ); } - m_classSource.println( " if (t instanceof RuntimeException) { " ); - m_classSource.println( " throw (RuntimeException) t;" ); - m_classSource.println( " } else if (t instanceof Error) { " ); - m_classSource.println( " throw (Error) t;" ); - m_classSource.println( " } else { " ); - m_classSource.println( " t.printStackTrace(); " ); - m_classSource.println( + classSource.println( " if (t instanceof RuntimeException) { " ); + classSource.println( " throw (RuntimeException) t;" ); + classSource.println( " } else if (t instanceof Error) { " ); + classSource.println( " throw (Error) t;" ); + classSource.println( " } else { " ); + classSource.println( " t.printStackTrace(); " ); + classSource.println( " throw new org.apache.excalibur.altrmi.common." + "InvocationException(\"Should never get here: \" +t.getMessage());"); - m_classSource.println( " }" ); - m_classSource.println( " }" ); + classSource.println( " }" ); + classSource.println( " }" ); } - private void generateMethodArgs(Class[] argTypes) + private void generateMethodArgs(PrintWriter classSource, Class[] argTypes) { - m_classSource.println( " Object[] args = new Object[" + argTypes.length + classSource.println( " Object[] args = new Object[" + argTypes.length + "];" ); - m_classSource.println( " Class[] argClasses = new Class[" + argTypes.length + classSource.println( " Class[] argClasses = new Class[" + argTypes.length + "];" ); for( int i = 0; i < argTypes.length; i++ ) { - generateAssignLine( argTypes[ i ], i ); + generateAssignLine( classSource, argTypes[ i ], i ); } } - private void generateAsyncMethodBody(Class[] argTypes, Class rClass, String methodSignature, Method method) + private void generateAsyncMethodBody(PrintWriter classSource,Class[] argTypes, Class rClass, String methodSignature, Method method) { - generateMethodArgs(argTypes); - m_classSource.println( " m_asyncInvocations.add(new org.apache.excalibur.altrmi.common.RawRequest(\"" + generateMethodArgs(classSource, argTypes); + classSource.println( " m_asyncInvocations.add(new org.apache.excalibur.altrmi.common.RawRequest(\"" + methodSignature + "\", args));" ); } - private void generateAsyncCommitMethodBody() + private void generateAsyncCommitMethodBody(PrintWriter classSource) { - m_classSource.println( " try {" ); + classSource.println( " try {" ); - m_classSource.println( " m_proxyHelper.processVoidRequests(m_asyncInvocations);" ); - m_classSource.println( " } catch (Throwable t) {" ); - m_classSource.println( " if (t instanceof RuntimeException) { " ); - m_classSource.println( " throw (RuntimeException) t;" ); - m_classSource.println( " } else if (t instanceof Error) { " ); - m_classSource.println( " throw (Error) t;" ); - m_classSource.println( " } else { " ); - m_classSource.println( " t.printStackTrace(); " ); - m_classSource.println( + classSource.println( " m_proxyHelper.processVoidRequests(m_asyncInvocations);" ); + classSource.println( " } catch (Throwable t) {" ); + classSource.println( " if (t instanceof RuntimeException) { " ); + classSource.println( " throw (RuntimeException) t;" ); + classSource.println( " } else if (t instanceof Error) { " ); + classSource.println( " throw (Error) t;" ); + classSource.println( " } else { " ); + classSource.println( " t.printStackTrace(); " ); + classSource.println( " throw new org.apache.excalibur.altrmi.common." + "InvocationException(\"Should never get here: \" +t.getMessage());"); - m_classSource.println( " }" ); - m_classSource.println( " } finally { " ); - m_classSource.println( " m_asyncInvocations.removeAllElements();"); - m_classSource.println( " }" ); + classSource.println( " }" ); + classSource.println( " } finally { " ); + classSource.println( " m_asyncInvocations.removeAllElements();"); + classSource.println( " }" ); } - private void generateAsyncRollbackMethodBody(Class[] argTypes, String methodSignature) + private void generateAsyncRollbackMethodBody(PrintWriter classSource, Class[] argTypes, String methodSignature) { Vector v = new Vector(); v.removeAllElements(); - generateMethodArgs(argTypes); + generateMethodArgs(classSource, argTypes); - m_classSource.println( " try {" ); - m_classSource.println( " m_asyncInvocations.removeAllElements();"); - m_classSource.println( " m_proxyHelper.processVoidRequest(\"" + classSource.println( " try {" ); + classSource.println( " m_asyncInvocations.removeAllElements();"); + classSource.println( " m_proxyHelper.processVoidRequest(\"" + methodSignature.toString() + "\",args);" ); - m_classSource.println( " } catch (Throwable t) {" ); - m_classSource.println( " if (t instanceof RuntimeException) { " ); - m_classSource.println( " throw (RuntimeException) t;" ); - m_classSource.println( " } else if (t instanceof Error) { " ); - m_classSource.println( " throw (Error) t;" ); - m_classSource.println( " } else { " ); - m_classSource.println( " t.printStackTrace(); " ); - m_classSource.println( + classSource.println( " } catch (Throwable t) {" ); + classSource.println( " if (t instanceof RuntimeException) { " ); + classSource.println( " throw (RuntimeException) t;" ); + classSource.println( " } else if (t instanceof Error) { " ); + classSource.println( " throw (Error) t;" ); + classSource.println( " } else { " ); + classSource.println( " t.printStackTrace(); " ); + classSource.println( " throw new org.apache.excalibur.altrmi.common." + "InvocationException(\"Should never get here: \" +t.getMessage());"); - m_classSource.println( " }" ); - m_classSource.println( " }" ); + classSource.println( " }" ); + classSource.println( " }" ); } - private void makeSourceInterfacesMethodsNotDoneNotVoid(Method method, + private void makeSourceInterfacesMethodsNotDoneNotVoid(PrintWriter classSource, Method method, Class rClass, String methodSignature) { boolean isFacadeRetVal = isAdditionalFacade( method.getReturnType() ); @@ -435,221 +434,221 @@ retClassType = rClass.getComponentType(); } - m_classSource.println( + classSource.println( " Object retVal = m_proxyHelper.processObjectRequestGettingFacade(" + retClassType.getName() + ".class , \"" + methodSignature.toString() + "\",args,\"" + MethodNameHelper.encodeClassName( getClassType( rClass ) ) + "\");" ); - m_classSource.println( " return (" + getClassType( rClass ) + classSource.println( " return (" + getClassType( rClass ) + ") retVal;" ); } else { - m_classSource.println( + classSource.println( " Object retVal = m_proxyHelper.processObjectRequest(\"" + methodSignature.toString() + "\",args,argClasses);" ); - generateReturnLine( rClass ); + generateReturnLine( classSource, rClass ); } } - private void generateThrowHandler( int i, Class[] throwsTypes ) + private void generateThrowHandler(PrintWriter classSource, int i, Class[] throwsTypes ) { if( i == 0 ) { - m_classSource.println( + classSource.println( " if (t instanceof " + throwsTypes[ i ].getName() + ") { " ); } else { - m_classSource.println( " } else if (t instanceof " + throwsTypes[ i ].getName() + classSource.println( " } else if (t instanceof " + throwsTypes[ i ].getName() + ") { " ); } - m_classSource.println( " throw (" + throwsTypes[ i ].getName() + ") t;" ); + classSource.println( " throw (" + throwsTypes[ i ].getName() + ") t;" ); if( i + 1 == throwsTypes.length ) { - m_classSource.print( " } else" ); + classSource.print( " } else" ); } } - private void generateThrows( int i, Class[] throwsTypes ) + private void generateThrows(PrintWriter classSource, int i, Class[] throwsTypes ) { if( i == 0 ) { - m_classSource.print( "throws " ); + classSource.print( "throws " ); } - m_classSource.print( throwsTypes[ i ].getName() ); + classSource.print( throwsTypes[ i ].getName() ); if( i + 1 < throwsTypes.length ) { - m_classSource.print( ", " ); + classSource.print( ", " ); } } - private void generateInterfaceList( PrintWriter pw, PublicationDescriptionItem[] interfacesToExpose ) + private void generateInterfaceList(PrintWriter classSource, PublicationDescriptionItem[] interfacesToExpose ) { for( int x = 0; x < interfacesToExpose.length; x++ ) { - pw.print( interfacesToExpose[ x ].getFacadeClass().getName() ); + classSource.print( interfacesToExpose[ x ].getFacadeClass().getName() ); if( x + 1 < interfacesToExpose.length ) { - pw.print( ", " ); + classSource.print( ", " ); } } } - private void generateParameter( Class cl, int i ) + private void generateParameter(PrintWriter classSource, Class cl, int i ) { if( i > 0 ) { - m_classSource.print( ", " ); + classSource.print( ", " ); } if( cl.isArray() ) { - m_classSource.print( cl.getComponentType().getName() + "[]" ); + classSource.print( cl.getComponentType().getName() + "[]" ); } else { - m_classSource.print( cl.getName() ); + classSource.print( cl.getName() ); } - m_classSource.print( " v" + i ); + classSource.print( " v" + i ); } - private void generateAssignLine( Class clazz, int i ) + private void generateAssignLine( PrintWriter classSource, Class clazz, int i ) { String cn = clazz.getName(); if( cn.equals( "int" ) ) { - m_classSource.println( " args[" + i + "] = new Integer(v" + i + ");" ); + classSource.println( " args[" + i + "] = new Integer(v" + i + ");" ); } else if( cn.equals( "short" ) ) { - m_classSource.println( " args[" + i + "] = new Short(v" + i + ");" ); + classSource.println( " args[" + i + "] = new Short(v" + i + ");" ); } else if( cn.equals( "float" ) ) { - m_classSource.println( " args[" + i + "] = new Float(v" + i + ");" ); + classSource.println( " args[" + i + "] = new Float(v" + i + ");" ); } else if( cn.equals( "double" ) ) { - m_classSource.println( " args[" + i + "] = new Double(v" + i + ");" ); + classSource.println( " args[" + i + "] = new Double(v" + i + ");" ); } else if( cn.equals( "long" ) ) { - m_classSource.println( " args[" + i + "] = new Long(v" + i + ");" ); + classSource.println( " args[" + i + "] = new Long(v" + i + ");" ); } else if( cn.equals( "char" ) ) { - m_classSource.println( " args[" + i + "] = new Character(v" + i + ");" ); + classSource.println( " args[" + i + "] = new Character(v" + i + ");" ); } else if( cn.equals( "boolean" ) ) { - m_classSource.println( " args[" + i + "] = new Boolean(v" + i + ");" ); + classSource.println( " args[" + i + "] = new Boolean(v" + i + ");" ); } else if( cn.equals( "byte" ) ) { - m_classSource.println( " args[" + i + "] = new Byte(v" + i + ");" ); + classSource.println( " args[" + i + "] = new Byte(v" + i + ");" ); } else { - m_classSource.println( " args[" + i + "] = v" + i + ";" ); - m_classSource.println( " argClasses[" + i + "] = " + classSource.println( " args[" + i + "] = v" + i + ";" ); + classSource.println( " argClasses[" + i + "] = " + generateReturnValue( clazz ) + ".class;" ); } } - private void generateReturnLine( Class rClass ) + private void generateReturnLine( PrintWriter classSource, Class rClass ) { String cn = rClass.getName(); if( cn.equals( "boolean" ) ) { - m_classSource.println( " return ((Boolean) retVal).booleanValue();" ); + classSource.println( " return ((Boolean) retVal).booleanValue();" ); } else if( cn.equals( "int" ) ) { - m_classSource.println( " return ((Integer) retVal).intValue();" ); + classSource.println( " return ((Integer) retVal).intValue();" ); } else if( cn.equals( "short" ) ) { - m_classSource.println( " return ((Short) retVal).shortValue();" ); + classSource.println( " return ((Short) retVal).shortValue();" ); } else if( cn.equals( "float" ) ) { - m_classSource.println( " return ((Float) retVal).floatValue();" ); + classSource.println( " return ((Float) retVal).floatValue();" ); } else if( cn.equals( "double" ) ) { - m_classSource.println( " return ((Double) retVal).doubleValue();" ); + classSource.println( " return ((Double) retVal).doubleValue();" ); } else if( cn.equals( "long" ) ) { - m_classSource.println( " return ((Long) retVal).longValue();" ); + classSource.println( " return ((Long) retVal).longValue();" ); } else if( cn.equals( "char" ) ) { - m_classSource.println( " return ((Character) retVal).charValue();" ); + classSource.println( " return ((Character) retVal).charValue();" ); } else if( cn.equals( "void" ) ) { - m_classSource.println( " return;" ); + classSource.println( " return;" ); } else if( cn.equals( "byte" ) ) { - m_classSource.println( " return ((Byte) retVal).byteValue();" ); + classSource.println( " return ((Byte) retVal).byteValue();" ); } else if( cn.equals( "[B" ) ) { - m_classSource.println( " return (byte[]) retVal;" ); + classSource.println( " return (byte[]) retVal;" ); } else if( cn.equals( "[C" ) ) { - m_classSource.println( " return (char[]) retVal;" ); + classSource.println( " return (char[]) retVal;" ); } else if( cn.equals( "[D" ) ) { - m_classSource.println( " return (double[]) retVal;" ); + classSource.println( " return (double[]) retVal;" ); } else if( cn.equals( "[F" ) ) { - m_classSource.println( " return (float[]) retVal;" ); + classSource.println( " return (float[]) retVal;" ); } else if( cn.equals( "[I" ) ) { - m_classSource.println( " return (int[]) retVal;" ); + classSource.println( " return (int[]) retVal;" ); } else if( cn.equals( "[J" ) ) { - m_classSource.println( " return (long[]) retVal;" ); + classSource.println( " return (long[]) retVal;" ); } else if( cn.equals( "[S" ) ) { - m_classSource.println( " return (short[]) retVal;" ); + classSource.println( " return (short[]) retVal;" ); } else if( cn.equals( "[Z" ) ) { - m_classSource.println( " return (boolean[]) retVal;" ); + classSource.println( " return (boolean[]) retVal;" ); } else if( rClass.getName().startsWith( "[L" ) ) { - m_classSource.println( " return (" + cn.substring( 2, cn.length() - 1 ) + classSource.println( " return (" + cn.substring( 2, cn.length() - 1 ) + "[]) retVal;" ); } else { - m_classSource.println( " return (" + cn + ") retVal;" ); + classSource.println( " return (" + cn + ") retVal;" ); } } --------------------------------------------------------------------- To unsubscribe, e-mail: avalon-cvs-unsubscribe@jakarta.apache.org For additional commands, e-mail: avalon-cvs-help@jakarta.apache.org