@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(); } }
generateNCICMProxyCreation( mv,true,fcitfClassname,"compctrl","component",compctrlit); mv.visit (" "+Component.class.getName()+" proxyForCompCtrl = "); mv.visitln("("+Component.class.getName()+") proxy;"); fcitfClassname = itfscg.getTargetTypeName(); String itstring = InterfaceTypeHelper.javaify(intit).toString(); mv.visit (" proxy = "); mv.visit ("new "+fcitfClassname+"("); mv.visit ("proxyForCompCtrl,\""+itname+"\","+itstring); mv.visitln(",true,intercept);"); mv.visitln(" ic.internalInterfaces.put(\""+itname+"\",proxy);");
@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(" }"); } }
Class<?>[] paramtypes = proxym.getParameterTypes(); 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(" catch( NoSuchMethodException e ) {"); bv.visit (" throw new "); bv.visit (TinfiRuntimeException.class.getName()); bv.visitln("(e);"); bv.visitln(" }");
@Override public void generateMethods( ClassSourceCodeVisitor cv ) { super.generateMethods(cv); BlockSourceCodeVisitor mv = cv.visitMethod( Modifier.PUBLIC, null, ServiceReference.class.getName()+'<'+it.getFcItfSignature()+'>', "getServiceReference", null, null ); SourceCodeGeneratorItf cg = new ServiceReferenceClassGenerator( it,this.proxycl,pkgRoot,membraneDesc,mergeable); String srclname = cg.getTargetTypeName(); mv.visit (" return new "); mv.visit (srclname); mv.visit ("("); mv.visit (it.getFcItfSignature()); mv.visitln(".class,this);"); mv.visitEnd(); }
@Override protected void generateNewFcContentMethod( BlockSourceCodeVisitor mv ) { String ctrlDesc = membraneDesc.getDescriptor(); String contentClassName = JuliacHelper.getContentClassName(ctrlDesc,contentDesc); mv.visit(" Object content = "); if( contentClassName == null ) { mv.visitln("null;"); } else { mv.visit ("new "); mv.visit (contentClassName); mv.visitln("();"); } mv.visitln(" return content;"); }
@Override protected void generateNewFcContentMethod( BlockSourceCodeVisitor mv ) { String ctrlDesc = membraneDesc.getDescriptor(); String contentClassName = JuliacHelper.getContentClassName(ctrlDesc,contentDesc); if( contentClassName == null ) { mv.visitln(" return null;"); } else { mv.visitln(" try {"); mv.visit (" Object content = new "); mv.visit (contentClassName); mv.visitln("();"); mv.visitln(" return content;"); mv.visitln(" }"); mv.visitln(" catch( Throwable t ) {"); mv.visit (" throw new "); mv.visit (ChainedInstantiationException.class.getName()); mv.visitln("(t,null,\"\");"); mv.visitln(" }"); } }
if( rtype.isPrimitive() ) { mv.visitln(" Object proceed = ijp.proceed();"); mv.visit (" "); mv.visit (rtypename); mv.visit (" ret = (proceed==null) ? "); String nul = ClassHelper.getNullValue(rtype); mv.visit (nul); mv.visit (" : ("); Class<?> boxed = ClassHelper.box(rtype); mv.visit (boxed.getName()); mv.visitln(")proceed;"); mv.visit(" "); mv.visit(rtypename); mv.visit(" ret = "); if( ! rtypename.equals("java.lang.Object") ) { mv.visit("("); mv.visit(rtypename); mv.visit(") ");
mv.visit (" "); mv.visit (it.getFcItfSignature()); mv.visit (" impl = setRequestContextAndGet(\""); mv.visit (it.getFcItfName()); mv.visitln("\","+it.getFcItfSignature()+".class,this);"); mv.visit(" releaseContent(impl,"); if( proxym.getAnnotation(EndsConversation.class) == null ) { mv.visit("false"); mv.visit("true");
@Override public void generateProxyMethodBodyBeforeCode( BlockSourceCodeVisitor mv, Method proxym ) { /* * Regiqter the request context and get the content instance which * corresponds to the current scope policy. */ mv.visit (" "); mv.visit (it.getFcItfSignature()); String[] tpnames = ClassHelper.getTypeParameterNames(proxycl); if( tpnames.length != 0 ) { String s = ClassHelper.getTypeParameterNamesSignature(tpnames); mv.visit(s); } mv.visit (" impl = setRequestContextAndGet(\""); mv.visit (it.getFcItfName()); mv.visitln("\","+it.getFcItfSignature()+".class,this);"); // TODO the request context created by setRequestContextAndGet should be given a client proxy (not this which is a server one) // Begin of the try block mv.visitln(" try {"); }
protected void generateNFICMExternalInterface( BlockSourceCodeVisitor mv, InterfaceType it, boolean attrimplgenerated ) { String itname = it.getFcItfName(); if( it.isFcCollectionItf() ) { // Julia naming convention for collection interfaces itname = "/collection/" + itname; } // External interface SourceCodeGeneratorItf itfscg = fcscg.getInterfaceClassGenerator(it); String fcitfClassname = itfscg.getTargetTypeName(); String itstring = InterfaceTypeHelper.javaify(it).toString(); mv.visit(" proxy = "); mv.visit("new "+fcitfClassname+"("); mv.visit("proxyForCompCtrl,\""+itname+"\","+itstring+",false,"); if( itname.equals("attribute-controller") && attrimplgenerated ) { mv.visit("attrimpl"); } else { mv.visit("intercept"); // interceptor or content or null } mv.visitln(");"); mv.visitln(" ic.interfaces.put(\""+itname+"\",proxy);"); }
String fcitfClassname = itfscg.getTargetTypeName(); String itstring = InterfaceTypeHelper.javaify(it).toString(); mv.visit (" proxy = "); mv.visit ("new "+fcitfClassname+"("); mv.visitln("proxyForCompCtrl,\""+itname+"\","+itstring+",false,delegate);"); mv.visitln(" ic.interfaces.put(\""+itname+"\",proxy);");
mv.visit(" intercept = "); mv.visit( its[i].isFcClientItf() ? "null" : "content" ); mv.visitln(";"); String fcitfClassname = itfscg.getTargetTypeName(); String itstring = InterfaceTypeHelper.javaify(intit).toString(); mv.visit (" proxy = "); mv.visit ("new "+fcitfClassname+"("); mv.visit ("proxyForCompCtrl,\""+itname+"\","+itstring); mv.visitln(",true,intercept);"); // interceptor or content or null mv.visitln(" ic.internalInterfaces.put(\""+itname+"\",proxy);");