hammant 02/01/27 15:51:48 Modified: altrmi/src/java/org/apache/commons/altrmi/common AbstractMethodHandler.java altrmi/src/java/org/apache/commons/altrmi/generator PrimarySourceGenerator.java altrmi/src/java/org/apache/commons/altrmi/generator/ant AltrmiInterfaceTask.java Log: Changes to make AltRMI more embeddable Revision Changes Path 1.4 +5 -1 jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/common/AbstractMethodHandler.java Index: AbstractMethodHandler.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/common/AbstractMethodHandler.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- AbstractMethodHandler.java 25 Jan 2002 16:40:13 -0000 1.3 +++ AbstractMethodHandler.java 27 Jan 2002 23:51:48 -0000 1.4 @@ -20,7 +20,7 @@ * * * @author Paul Hammant <a href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]</a> - * @version $Revision: 1.3 $ + * @version $Revision: 1.4 $ */ public class AbstractMethodHandler { @@ -43,6 +43,10 @@ methodSignature.append(")"); return methodSignature.toString().intern(); + } + + protected String encodeClassName(Class clazz) { + return encodeClassName(clazz.getName()); } protected String encodeClassName(String className) { 1.8 +21 -40 jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/generator/PrimarySourceGenerator.java Index: PrimarySourceGenerator.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/generator/PrimarySourceGenerator.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- PrimarySourceGenerator.java 25 Jan 2002 16:40:13 -0000 1.7 +++ PrimarySourceGenerator.java 27 Jan 2002 23:51:48 -0000 1.8 @@ -30,12 +30,12 @@ * * * @author Paul Hammant <a href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]</a> - * @version $Revision: 1.7 $ + * @version $Revision: 1.8 $ */ public class PrimarySourceGenerator extends AbstractMethodHandler { - private String[] mClassesOrInterfacesToExpose; - private String[] mAdditionalFacades; + private Class[] mClassesOrInterfacesToExpose; + private Class[] mAdditionalFacades; protected String mSrcGenDir; protected String mClassGenDir; protected String mClasspath; @@ -49,15 +49,8 @@ * @param classesOrInterfacesToExpose * */ - public void setClassOrInterfacesToExpose(String[] classesOrInterfacesToExpose) { - mClassesOrInterfacesToExpose = classesOrInterfacesToExpose; - } public void setClassOrInterfacesToExpose(Class[] classesOrInterfacesToExpose) { - mClassesOrInterfacesToExpose = new String[classesOrInterfacesToExpose.length]; - for (int i = 0; i < classesOrInterfacesToExpose.length; i++) { - Class facade = classesOrInterfacesToExpose[i]; - mClassesOrInterfacesToExpose[i] = facade.getName(); - } + mClassesOrInterfacesToExpose = classesOrInterfacesToExpose; } /** @@ -68,15 +61,8 @@ * @param additionalFacades * */ - public void setAdditionalfacades(String[] additionalFacades) { - mAdditionalFacades = additionalFacades; - } public void setAdditionalfacades(Class[] additionalFacades) { - mAdditionalFacades = new String[additionalFacades.length]; - for (int i = 0; i < additionalFacades.length; i++) { - Class facade = additionalFacades[i]; - mAdditionalFacades[i] = facade.getName(); - } + mAdditionalFacades = additionalFacades; } public void setSrcGenDir(String srcGenDir) { @@ -117,10 +103,10 @@ if (mAdditionalFacades != null) { for (int i = 0; i < mAdditionalFacades.length; i++) { - String facade = mAdditionalFacades[i]; + Class facade = mAdditionalFacades[i]; - makeSource(cL, encodeClassName(facade), new String[]{ facade }); - makeSource2(cL, encodeClassName(facade), new String[]{ facade }); + makeSource(cL, encodeClassName(facade), new Class[]{ facade }); + makeSource2(cL, encodeClassName(facade), new Class[]{ facade }); } } } @@ -157,7 +143,7 @@ * @throws SourceGenerationException * */ - public void makeSource(ClassLoader cL, String name, String[] classOrInterfacesToExpose) + public void makeSource(ClassLoader cL, String name, Class[] classOrInterfacesToExpose) throws SourceGenerationException { // methdos could be in more than one interface. @@ -181,13 +167,7 @@ mClassSource.println(" }"); for (int x = 0; x < classOrInterfacesToExpose.length; x++) { - Class clazz = null; - - try { - clazz = cL.loadClass(classOrInterfacesToExpose[x]); - } catch (ClassNotFoundException e) { - throw new SourceGenerationException("Cannot find '" + classOrInterfacesToExpose[x] + "' interface in classpath"); - } + Class clazz = classOrInterfacesToExpose[x]; Method[] methods = clazz.getMethods(); @@ -235,9 +215,8 @@ + "];"); for (int i = 0; i < argTypes.length; i++) { - String cn = argTypes[i].getName(); - generateAssignLine(cn, i); + generateAssignLine(argTypes[i], i); } mClassSource.println(" try {"); @@ -247,7 +226,7 @@ + methodSignature.toString() + "\",args);"); } else { boolean isFacadeRetVal = - isAdditionalFacade(method.getReturnType().getName()); + isAdditionalFacade(method.getReturnType()); if (isFacadeRetVal) { mClassSource.println( @@ -300,7 +279,7 @@ * @throws SourceGenerationException * */ - public void makeSource2(ClassLoader cL, String name, String[] classOrInterfacesToExpose) + public void makeSource2(ClassLoader cL, String name, Class[] classOrInterfacesToExpose) throws SourceGenerationException { String filename = mSrcGenDir + File.separator + "AltrmiGenerated2" + mGenName + "_" + name + ".java"; @@ -353,10 +332,10 @@ } } - private void generateInterfaceList(PrintWriter pw, String[] classOrInterfacesToExpose) { + private void generateInterfaceList(PrintWriter pw, Class[] classOrInterfacesToExpose) { for (int x = 0; x < classOrInterfacesToExpose.length; x++) { - pw.print(classOrInterfacesToExpose[x]); + pw.print(classOrInterfacesToExpose[x].getName()); if (x + 1 < classOrInterfacesToExpose.length) { pw.print(", "); @@ -397,7 +376,9 @@ } } - private void generateAssignLine(String cn, int i) { + private void generateAssignLine(Class clazz, int i) { + + String cn = clazz.getName(); if (cn.equals("int")) { mClassSource.println(" args[" + i + "] = new Integer(v" + i + ");"); @@ -415,7 +396,7 @@ mClassSource.println(" args[" + i + "] = new Boolean(v" + i + ");"); } else if (cn.equals("byte")) { mClassSource.println(" args[" + i + "] = new Byte(v" + i + ");"); - } else if (isAdditionalFacade(cn)) { + } else if (isAdditionalFacade(clazz)) { mClassSource.println(" args[" + i + "] = mBaseServedObject.makeFacadeRefHolder(v" + i + ",\"" + super.encodeClassName(cn) + "\");"); } else { @@ -495,14 +476,14 @@ } - private boolean isAdditionalFacade(String className) { + private boolean isAdditionalFacade(Class clazz) { if (mAdditionalFacades == null) { return false; } for (int p = 0; p < mAdditionalFacades.length; p++) { - if (className.equals(mAdditionalFacades[p])) { + if (clazz.equals(mAdditionalFacades[p])) { return true; } } 1.5 +14 -2 jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/generator/ant/AltrmiInterfaceTask.java Index: AltrmiInterfaceTask.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/generator/ant/AltrmiInterfaceTask.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- AltrmiInterfaceTask.java 25 Jan 2002 16:40:13 -0000 1.4 +++ AltrmiInterfaceTask.java 27 Jan 2002 23:51:48 -0000 1.5 @@ -105,8 +105,18 @@ sg.setClassGenDir(new File(mClassGenDir).getAbsolutePath()); sg.setGenName(mGenName); sg.setClasspath(classpath.toString()); - sg.setClassOrInterfacesToExpose(mClassOrInterfacesToExpose); - sg.setAdditionalfacades(mAdditionalFacades); + Class[] classesOrInterfaces = new Class[mClassOrInterfacesToExpose.length]; + for (int i = 0; i < mClassOrInterfacesToExpose.length; i++) { + String cn = mClassOrInterfacesToExpose[i]; + classesOrInterfaces[i] = Class.forName(cn); + } + sg.setClassOrInterfacesToExpose(classesOrInterfaces); + Class[] additionalFacades = new Class[mAdditionalFacades.length]; + for (int i = 0; i < mAdditionalFacades.length; i++) { + String cn = mAdditionalFacades[i]; + additionalFacades[i] = Class.forName(cn); + } + sg.setAdditionalfacades(additionalFacades); ClassLoader cL = null; if (classpath != null) { cL = new AntClassLoader(project, classpath); @@ -116,6 +126,8 @@ sg.generateSrc(cL); sg.generateClass(cL); + } catch (ClassNotFoundException cnfe) { + throw new BuildException(cnfe.getMessage()); } catch (SourceGenerationException sge) { throw new BuildException(sge.getMessage()); }
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>