@Override public void generateProxyMethodBodyAfterReturningCode( BlockSourceCodeVisitor mv, Method proxym ) { // End of the try block mv.visitln(" }"); mv.visitln(" finally {"); // Release the content instance mv.visit(" releaseContent(impl,"); if( proxym.getAnnotation(EndsConversation.class) == null ) { mv.visit("false"); } else { mv.visit("true"); } mv.visitln(");"); // End of the finally block mv.visitln(" }"); } }
@Override protected void generateExtraCode( ClassSourceCodeVisitor cv ) { BlockSourceCodeVisitor mv = cv.visitMethod( Modifier.PRIVATE, null, "Object", "getFcInterface", new String[]{Component.class.getName()+" c","String name"}, new String[]{InstantiationException.class.getName()} ); mv.visitln(" try {"); mv.visitln(" return c.getFcInterface(name);"); mv.visitln(" }"); mv.visitln(" catch( "+NoSuchInterfaceException.class.getName()+" nsie ) {"); mv.visit (" throw new "+ChainedInstantiationException.class.getName()); mv.visitln("(nsie,null,\"No such interface: \"+nsie.getMessage());"); mv.visitln(" }"); mv.visitEnd(); } }
mv.visitln(" "+InitializationContext.class.getName()+" ic = initFcInitializationContext();"); if(isComposite) { mv.visitln(" ic.internalInterfaces = new "+HashMap.class.getName()+"();"); mv.visitln(" "+Component.class.getName()+" compctrl = newFcControllerInstantiation(ic);"); mv.visitSet("Object intercept","null"); if( ! icg.generateInterceptorCreation(mv,compctrlit,"compctrl") ) { mv.visitSet("intercept","compctrl"); generateNCICMProxyCreation( mv,true,fcitfClassname,"compctrl","component",compctrlit); mv.visit (" "+Component.class.getName()+" proxyForCompCtrl = "); mv.visitln("("+Component.class.getName()+") proxy;"); mv.visitSet("Object ctrl","null"); for (int i=0; i < membraneits.length; i++) { mv.visitSet( "ctrl", "getFcController(ic,content,",membraneit.getFcItfSignature(),".class)"); mv.visitSet("intercept","ctrl"); fcitfClassname = itfscg.getTargetTypeName(); String itstring = InterfaceTypeHelper.javaify(intit).toString(); mv.visit (" proxy = "); mv.visit ("new "+fcitfClassname+"("); mv.visit ("proxyForCompCtrl,\""+itname+"\","+itstring);
@Override protected void generateContentChecks( BlockSourceCodeVisitor mv ) { String ctrlDesc = membraneDesc.getDescriptor(); String contentClassName = JuliacHelper.getContentClassName(ctrlDesc,contentDesc); if( contentClassName != null ) { InterfaceType[] its = ct.getFcInterfaceTypes(); for (int i = 0; i < its.length; i++) { if( ! its[i].isFcClientItf() ) { String signature = its[i].getFcItfSignature(); BlockSourceCodeVisitor then = mv.visitIf( "!",signature,".class.isAssignableFrom(", contentClassName,".class)"); then.visitVar( "String","msg","\""+contentClassName,"should implement", signature+"\""); then.visitIns( "throw","new", InstantiationException.class.getName()+"(msg)"); then.visitEnd(); } } } }
@Override public void generateConstructors( ClassSourceCodeVisitor cv ) { super.generateConstructors(cv); // public constructor() BlockSourceCodeVisitor mv = cv.visitConstructor(Modifier.PUBLIC,null,null,null); mv.visitEnd(); // public constructor(Component,String,Type,boolean,Object) String[] parameters = new String[]{ Component.class.getName()+" component", "String s", Type.class.getName()+" type", "boolean flag", "Object obj" }; mv = cv.visitConstructor(Modifier.PUBLIC,null,parameters,null); mv.visitIns("super(component,s,type,flag,obj);"); mv.visitEnd(); }
@Override protected void generateNewFcContentMethod( BlockSourceCodeVisitor mv ) { String ctrlDesc = membraneDesc.getDescriptor(); String contentClassName = JuliacHelper.getContentClassName(ctrlDesc,contentDesc); if( contentClassName == null ) { mv.visitIns("return null"); } else { // Handle inner classes contentClassName = contentClassName.replace('$','.'); CatchSourceCodeVisitor cv = mv.visitTry(); mv.visitVar("Object","content","new",contentClassName+"()"); mv.visitIns("return content"); cv = cv.visitCatch(Throwable.class,"t"); cv.visitIns( "throw","new",ChainedInstantiationException.class.getName(), "(t,null,\"\")" ); cv.visitEnd(); } }
@Override public void generateMethodClone( BlockSourceCodeVisitor mv ) { mv.visitIns("initFcClone(clone)"); } }
@Override public void generateMethodInitFcController( BlockSourceCodeVisitor mv ) { mv.visitln(" initIntentHandlersMap(METHODS);"); }
protected void generateNewFcControllerInstantiationMethod( ClassSourceCodeVisitor cv ) { BlockSourceCodeVisitor mv = cv.visitMethod( Modifier.PUBLIC, null, Component.class.getName(), "newFcControllerInstantiation", new String[]{InitializationContext.class.getName()+" ic"}, new String[]{InstantiationException.class.getName()} ); generateNewFcControllerInstantiationMethod(mv); mv.visitEnd(); }
@Override public void generateInitializationContextForContent( BlockSourceCodeVisitor mv ) { mv.visitSet( "ic.content", contentDesc==null ? "null" : (contentDesc.toString()+".class") ); }
/** * @since 1.4.1 */ @Override public void generateMethods( ClassSourceCodeVisitor cv ) { super.generateMethods(cv); /* * Override the getService method inherited from ServiceReferenceImpl. * The idea is that in generated subclasses of ServiceReferenceImpl we * can directly return "this" for getService. Whereas when getService is * invoked on an instance of ServiceReferenceImpl, getService should * return an instance which implements both the ServiceReference * interface and the business interface. This is the case of generated * subclass instances. */ String signature = it.getFcItfSignature(); BlockSourceCodeVisitor mv = cv.visitMethod( Modifier.PUBLIC, null, signature, "getService", null, null ); mv.visitIns("return this"); mv.visitEnd(); }
@Override public void generateMethodInitFcController( BlockSourceCodeVisitor mv ) { mv.visitIns("super.initFcController(ic)"); }
@Override public void generateMethodClone( BlockSourceCodeVisitor mv ) { mv.visitln(" clone.initIntentHandlersMap(METHODS);"); }
protected void generateNewFcInitializationContextMethod( ClassSourceCodeVisitor cv ) { BlockSourceCodeVisitor mv = cv.visitMethod( Modifier.PUBLIC, null, InitializationContext.class.getName(), "newFcInitializationContext", new String[]{"Object content"}, new String[]{InstantiationException.class.getName()} ); generateNewFcInitializationContextMethod(mv); mv.visitEnd(); }
BlockSourceCodeVisitor bv = cv.visitStaticPart(); if( proxymethods.length > 0 ) { bv.visitln(" try {"); bv.visitln(" METHODS = new java.lang.reflect.Method[]{"); bv.visit(" "); bv.visit(proxyclname); bv.visit(".class.getMethod(\""); bv.visit(proxymname); bv.visit("\""); for (Class<?> paramtype : paramtypes) { String paramtypename = ClassHelper.getName(paramtype); bv.visit(","); bv.visit(paramtypename); bv.visit(".class"); bv.visitln("),"); bv.visitln(" };"); bv.visitln(" }"); bv.visitln(" catch( NoSuchMethodException e ) {"); bv.visit (" throw new "); bv.visit (TinfiRuntimeException.class.getName()); bv.visitln("(e);"); bv.visitln(" }"); bv.visitEnd();
@Override public void generateConstructors( ClassSourceCodeVisitor cv ) { super.generateConstructors(cv); /* * Create the signature of the proxy interface with generic parameters * if any. */ String signature = it.getFcItfSignature(); String[] tpnames = ClassHelper.getTypeParameterNames(proxycl); if( tpnames.length != 0 ) { String s = ClassHelper.getTypeParameterNamesSignature(tpnames); signature += s; } // public constructor(Class<B>,B) String[] parameters = new String[]{ "Class<"+signature+"> businessInterface", signature+" service" }; BlockSourceCodeVisitor mv = cv.visitConstructor(Modifier.PUBLIC,null,parameters,null); mv.visitIns("super(businessInterface,service)"); mv.visitEnd(); }
@Override protected void generateNewFcContentMethod( BlockSourceCodeVisitor mv ) { mv.visitIns("return null"); }