static void genclass( DelegatorGenerator dg, Class intfcl, String fqcn, File srcroot ) throws IOException { File genDir = new File( srcroot, dirForFqcn( fqcn ) ); if (! genDir.exists() ) { System.err.println( JdbcProxyGenerator.class.getName() + " -- creating directory: " + genDir.getAbsolutePath() ); genDir.mkdirs(); } String fileName = CodegenUtils.fqcnLastElement( fqcn ) + ".java"; Writer w = null; try { w = new BufferedWriter( new FileWriter( new File( genDir, fileName ) ) ); dg.writeDelegator( intfcl, fqcn, w ); w.flush(); System.err.println("Generated " + fileName); } finally { try { if (w != null) w.close(); } catch ( Exception e ) { e.printStackTrace(); } } }
public static String methodCall( Method m, String[] argNames ) { StringBuffer sb = new StringBuffer(256); sb.append( m.getName() ); sb.append('('); Class[] cls = m.getParameterTypes(); for(int i = 0, len = cls.length; i < len; ++i) { if (i != 0) sb.append(", "); sb.append( argNames == null ? generatedArgumentName( i ) : argNames[i] ); } sb.append(')'); return sb.toString(); }
public static String methodCall( Method m ) { return methodCall( m, null ); }
private void ensureImports(String genclass, Set imports, Method[] methods ) { for (int i = 0, len = methods.length; i < len; ++i) { Class[] args = methods[i].getParameterTypes(); for (int j = 0, jlen = args.length; j < jlen; ++j) { if (! CodegenUtils.inSamePackage( args[j].getName(), genclass ) ) imports.add( CodegenUtils.unarrayClass( args[j] ) ); } Class[] excClasses = methods[i].getExceptionTypes(); for (int j = 0, jlen = excClasses.length; j < jlen; ++j) { if (! CodegenUtils.inSamePackage( excClasses[j].getName(), genclass ) ) { //System.err.println("Adding exception type: " + excClasses[j]); imports.add( CodegenUtils.unarrayClass( excClasses[j] ) ); } } if (! CodegenUtils.inSamePackage( methods[i].getReturnType().getName(), genclass ) ) imports.add( CodegenUtils.unarrayClass( methods[i].getReturnType() ) ); } }
IndentedWriter iw = CodegenUtils.toIndentedWriter(w); String sgc = CodegenUtils.fqcnLastElement( genclass ); String scn = (superclass != null ? ClassUtils.simpleClassName( superclass ) : null); String sin = ClassUtils.simpleClassName( intfcl ); if (! CodegenUtils.inSamePackage( intfcl.getName(), genclass ) ) imports.add( intfcl ); if (superclass != null && ! CodegenUtils.inSamePackage( superclass.getName(), genclass ) ) imports.add( superclass ); if (extraInterfaces != null) if (! CodegenUtils.inSamePackage( checkMe.getName(), genclass ) ) imports.add( checkMe ); if (! CodegenUtils.inSamePackage( args[j].getName(), genclass ) ) imports.add( CodegenUtils.unarrayClass( args[j] ) ); if (! CodegenUtils.inSamePackage( excClasses[j].getName(), genclass ) ) imports.add( CodegenUtils.unarrayClass( excClasses[j] ) ); if (! CodegenUtils.inSamePackage( methods[i].getReturnType().getName(), genclass ) ) imports.add( CodegenUtils.unarrayClass( methods[i].getReturnType() ) ); generateExtraImports( iw ); iw.println(); iw.print(CodegenUtils.getModifierString( class_modifiers ) + " class " + sgc); if (superclass != null)
public static String methodSignature( int modifiers, Method m, String[] argNames ) sb.append(getModifierString(modifiers)); sb.append(' '); sb.append( ClassUtils.simpleClassName( m.getReturnType() ) );
protected void generateExtraDeclarations( Class intfcl, String genclass, IndentedWriter iw ) throws IOException { super.generateExtraDeclarations( intfcl, genclass, iw ); iw.println(); iw.println("NewProxyConnection proxyCon;"); iw.println(); iw.print( CodegenUtils.fqcnLastElement( genclass ) ); iw.println("( " + CodegenUtils.simpleClassName( intfcl ) + " inner, NewPooledConnection parentPooledConnection, NewProxyConnection proxyCon )"); iw.println("{"); iw.upIndent(); iw.println("this( inner, parentPooledConnection );"); iw.println("this.proxyCon = proxyCon;"); iw.downIndent(); iw.println("}"); } }
iw.println("Statement innerStmt = inner." + CodegenUtils.methodCall( method ) + ";"); iw.println("parentPooledConnection.markActiveUncachedStatement( innerStmt );"); iw.println("return new NewProxyStatement( innerStmt, parentPooledConnection, false, this );"); iw.println("innerStmt = inner." + CodegenUtils.methodCall( method ) + ";"); iw.println("parentPooledConnection.markActiveUncachedStatement( innerStmt );"); iw.println("return new NewProxyPreparedStatement( innerStmt, parentPooledConnection, false, this );"); iw.println("innerStmt = inner." + CodegenUtils.methodCall( method ) + ";"); iw.println("parentPooledConnection.markActiveUncachedStatement( innerStmt );"); iw.println("return new NewProxyPreparedStatement( innerStmt, parentPooledConnection, false, this );"); iw.println("innerStmt = inner." + CodegenUtils.methodCall( method ) + ";"); iw.println("parentPooledConnection.markActiveUncachedStatement( innerStmt );"); iw.println("return new NewProxyCallableStatement( innerStmt, parentPooledConnection, false, this );"); iw.println("innerStmt = inner." + CodegenUtils.methodCall( method ) + ";"); iw.println("parentPooledConnection.markActiveUncachedStatement( innerStmt );"); iw.println("return new NewProxyCallableStatement( innerStmt, parentPooledConnection, false, this );"); iw.println("{"); iw.upIndent(); iw.println("DatabaseMetaData innerMetaData = inner." + CodegenUtils.methodCall( method ) + ";"); iw.println("this.metaData = new NewProxyDatabaseMetaData( innerMetaData, parentPooledConnection, this );"); iw.downIndent(); iw.println( "parentPooledConnection.markNewTxnIsolation( " + CodegenUtils.generatedArgumentName( 0 ) + " );"); iw.println( "parentPooledConnection.markNewCatalog( " + CodegenUtils.generatedArgumentName( 0 ) + " );");
public static String methodSignature( Method m, String[] argNames ) { return methodSignature( Modifier.PUBLIC, m, argNames ); }
iw.print( CodegenUtils.simpleClassName( argTypes[i] ) + ".class" ); String argName = CodegenUtils.generatedArgumentName( i ); Class argType = argTypes[i]; if (argType.isPrimitive())
IndentedWriter iw = CodegenUtils.toIndentedWriter(w); String sgc = CodegenUtils.fqcnLastElement( genclass ); String scn = (superclass != null ? ClassUtils.simpleClassName( superclass ) : null); String sin = ClassUtils.simpleClassName( intfcl ); if (! CodegenUtils.inSamePackage( intfcl.getName(), genclass ) ) imports.add( intfcl ); if (superclass != null && ! CodegenUtils.inSamePackage( superclass.getName(), genclass ) ) imports.add( superclass ); if (extraInterfaces != null) if (! CodegenUtils.inSamePackage( checkMe.getName(), genclass ) ) imports.add( checkMe ); if (! CodegenUtils.inSamePackage( args[j].getName(), genclass ) ) imports.add( CodegenUtils.unarrayClass( args[j] ) ); if (! CodegenUtils.inSamePackage( excClasses[j].getName(), genclass ) ) imports.add( CodegenUtils.unarrayClass( excClasses[j] ) ); if (! CodegenUtils.inSamePackage( methods[i].getReturnType().getName(), genclass ) ) imports.add( CodegenUtils.unarrayClass( methods[i].getReturnType() ) ); generateExtraImports( iw ); iw.println(); iw.print(CodegenUtils.getModifierString( class_modifiers ) + " class " + sgc); if (superclass != null)
public static String methodSignature( int modifiers, Method m, String[] argNames ) sb.append(getModifierString(modifiers)); sb.append(' '); sb.append( ClassUtils.simpleClassName( m.getReturnType() ) );
protected void generateExtraDeclarations( Class intfcl, String genclass, IndentedWriter iw ) throws IOException { super.generateExtraDeclarations( intfcl, genclass, iw ); iw.println(); iw.println("NewProxyConnection proxyCon;"); iw.println(); iw.print( CodegenUtils.fqcnLastElement( genclass ) ); iw.println("( " + CodegenUtils.simpleClassName( intfcl ) + " inner, NewPooledConnection parentPooledConnection, NewProxyConnection proxyCon )"); iw.println("{"); iw.upIndent(); iw.println("this( inner, parentPooledConnection );"); iw.println("this.proxyCon = proxyCon;"); iw.downIndent(); iw.println("}"); } }
iw.println("Statement innerStmt = inner." + CodegenUtils.methodCall( method ) + ";"); iw.println("parentPooledConnection.markActiveUncachedStatement( innerStmt );"); iw.println("return new NewProxyStatement( innerStmt, parentPooledConnection, false, this );"); iw.println("innerStmt = inner." + CodegenUtils.methodCall( method ) + ";"); iw.println("parentPooledConnection.markActiveUncachedStatement( innerStmt );"); iw.println("return new NewProxyPreparedStatement( innerStmt, parentPooledConnection, false, this );"); iw.println("innerStmt = inner." + CodegenUtils.methodCall( method ) + ";"); iw.println("parentPooledConnection.markActiveUncachedStatement( innerStmt );"); iw.println("return new NewProxyPreparedStatement( innerStmt, parentPooledConnection, false, this );"); iw.println("innerStmt = inner." + CodegenUtils.methodCall( method ) + ";"); iw.println("parentPooledConnection.markActiveUncachedStatement( innerStmt );"); iw.println("return new NewProxyCallableStatement( innerStmt, parentPooledConnection, false, this );"); iw.println("innerStmt = inner." + CodegenUtils.methodCall( method ) + ";"); iw.println("parentPooledConnection.markActiveUncachedStatement( innerStmt );"); iw.println("return new NewProxyCallableStatement( innerStmt, parentPooledConnection, false, this );"); iw.println("{"); iw.upIndent(); iw.println("DatabaseMetaData innerMetaData = inner." + CodegenUtils.methodCall( method ) + ";"); iw.println("this.metaData = new NewProxyDatabaseMetaData( innerMetaData, parentPooledConnection, this );"); iw.downIndent(); iw.println( "parentPooledConnection.markNewTxnIsolation( " + CodegenUtils.generatedArgumentName( 0 ) + " );"); iw.println( "parentPooledConnection.markNewCatalog( " + CodegenUtils.generatedArgumentName( 0 ) + " );");
public static String methodSignature( Method m ) { return methodSignature( m, null ); }
iw.print( CodegenUtils.simpleClassName( argTypes[i] ) + ".class" ); String argName = CodegenUtils.generatedArgumentName( i ); Class argType = argTypes[i]; if (argType.isPrimitive())
IndentedWriter iw = CodegenUtils.toIndentedWriter(w); String sgc = CodegenUtils.fqcnLastElement( genclass ); String scn = (superclass != null ? ClassUtils.simpleClassName( superclass ) : null); String sin = ClassUtils.simpleClassName( intfcl ); if (! CodegenUtils.inSamePackage( intfcl.getName(), genclass ) ) imports.add( intfcl ); if (superclass != null && ! CodegenUtils.inSamePackage( superclass.getName(), genclass ) ) imports.add( superclass ); if (extraInterfaces != null) if (! CodegenUtils.inSamePackage( checkMe.getName(), genclass ) ) imports.add( checkMe ); if ( reflectiveDelegationPolicy.delegateClass != null && !CodegenUtils.inSamePackage( reflectiveDelegationPolicy.delegateClass.getName(), genclass ) ) imports.add( reflectiveDelegationPolicy.delegateClass ); iw.println(); generateClassJavaDocComment( iw ); iw.print(CodegenUtils.getModifierString( class_modifiers ) + " class " + sgc); if (superclass != null) iw.print(" extends " + scn); iw.println(CodegenUtils.getModifierString( wrapping_ctor_modifiers ) + ' ' + sgc + '(' + sin + " inner)"); iw.println("{ __setInner( inner ); }"); iw.println(CodegenUtils.getModifierString( default_ctor_modifiers ) + ' ' + sgc + "()"); iw.println("{}");
public static String methodSignature( int modifiers, Method m, String[] argNames ) sb.append(getModifierString(modifiers)); sb.append(' '); sb.append( ClassUtils.simpleClassName( m.getReturnType() ) );
protected void generateExtraDeclarations( Class intfcl, String genclass, IndentedWriter iw ) throws IOException { super.generateExtraDeclarations( intfcl, genclass, iw ); iw.println(); iw.println("Object creator;"); iw.println("Object creatorProxy;"); iw.println("NewProxyConnection proxyConn;"); iw.println(); iw.print( CodegenUtils.fqcnLastElement( genclass ) ); iw.println("( " + CodegenUtils.simpleClassName( intfcl ) + " inner, NewPooledConnection parentPooledConnection, Object c, Object cProxy )"); iw.println("{"); iw.upIndent(); iw.println("this( inner, parentPooledConnection );"); iw.println("this.creator = c;"); iw.println("this.creatorProxy = cProxy;"); iw.println("if (creatorProxy instanceof NewProxyConnection) this.proxyConn = (NewProxyConnection) cProxy;"); iw.downIndent(); iw.println("}"); }
public static String methodCall( Method m ) { return methodCall( m, null ); }