1 6 7 package SOFA.Connector.EEG.EEM.Actions; 8 9 import SOFA.Connector.EEG.CodeWriter.CDL2JavaMapping; 10 import SOFA.Connector.EEG.EEM.ActionException; 11 import SOFA.Connector.EEG.EEM.ActionInterface; 12 import SOFA.SOFAnode.Made.TIR.InterfaceDef; 13 import SOFA.SOFAnode.Made.TIR.Access.TIRAccessMethods; 14 15 20 public class JImpl implements ActionInterface { 21 22 23 public JImpl(java.util.HashMap props) { 24 } 25 26 public String getName() { 27 return "jimpl"; 28 } 29 30 public void perform(SOFA.Connector.Property[] params, String sourceDir, String sourcePackage, String destDir, String destPackage) throws ActionException { 31 String outFile, className, reqIfaceCDL, provIfaceCDL, reqIfaceMapped=null, provIfaceMapped=null, generator; 32 if ((outFile=SOFA.Connector.Property.findFirst(params,"file"))==null) { 33 throw new ActionException("file param not specified"); 34 } 35 if ((className=SOFA.Connector.Property.findFirst(params,"class"))==null) { 36 throw new ActionException("class param not specified"); 37 } 38 if ((generator=SOFA.Connector.Property.findFirst(params,"generator"))==null) { 39 throw new ActionException("generator param not specified"); 40 } 41 if ((provIfaceCDL=SOFA.Connector.Property.findFirst(params,"provIfaceCDL"))!=null) { 42 provIfaceMapped=SOFA.Connector.Property.findFirst(params,"provIfaceMapped"); 43 } 44 if ((reqIfaceCDL=SOFA.Connector.Property.findFirst(params,"reqIfaceCDL"))!=null) { 45 reqIfaceMapped=SOFA.Connector.Property.findFirst(params,"reqIfaceMapped"); 46 } 47 48 try { 49 SOFA.Connector.EEG.CodeWriter.JWriter jwriter; 50 51 if (provIfaceCDL!=null) { 52 jwriter=new SOFA.Connector.EEG.CodeWriter.JWriter(provIfaceCDL); 53 } else { 54 jwriter=new SOFA.Connector.EEG.CodeWriter.JWriter(); 55 } 56 jwriter.setOut(destDir+"/"+outFile,destPackage,className); 57 58 int addn=0; 59 if (provIfaceCDL!=null && provIfaceMapped==null) { 60 addn++; 61 } 62 if (reqIfaceCDL!=null && reqIfaceMapped==null) { 63 addn++; 64 } 65 66 SOFA.Connector.Property[] dirParams=new SOFA.Connector.Property[params.length+4+addn]; 67 68 addn=0; 69 if (provIfaceCDL!=null && provIfaceMapped==null) { 70 InterfaceDef provIface=(InterfaceDef)TIRAccessMethods.lookupCDLContained(SOFA.Connector.TIRAccess.TIRAccess.repository,provIfaceCDL); 71 provIfaceMapped=CDL2JavaMapping.getAbsoluteName(provIface.get_identification().absolute_name()); 72 dirParams[addn]=new SOFA.Connector.Property("provIfaceMapped",provIfaceMapped); 73 addn++; 74 } 75 if (reqIfaceCDL!=null && reqIfaceMapped==null) { 76 InterfaceDef reqIface=(InterfaceDef)TIRAccessMethods.lookupCDLContained(SOFA.Connector.TIRAccess.TIRAccess.repository,reqIfaceCDL); 77 reqIfaceMapped=CDL2JavaMapping.getAbsoluteName(reqIface.get_identification().absolute_name()); 78 dirParams[addn]=new SOFA.Connector.Property("reqIfaceMapped",reqIfaceMapped); 79 addn++; 80 } 81 82 dirParams[addn+0]=new SOFA.Connector.Property("outFile",destDir+"/"+outFile); 83 dirParams[addn+1]=new SOFA.Connector.Property("outClass",className); 84 dirParams[addn+2]=new SOFA.Connector.Property("outPackage",destPackage); 85 dirParams[addn+3]=new SOFA.Connector.Property("implIface",provIfaceMapped); 86 87 88 for (int i=0;i<params.length;i++) { 89 dirParams[i+addn+4]=params[i]; 90 } 91 92 Class dirClass=Class.forName(sourcePackage+"."+generator); 93 94 Class [] coParCls=new Class [2]; 95 coParCls[0]=Class.forName("java.lang.String"); 96 coParCls[1]=Class.forName("[LSOFA.Connector.Property;"); 97 java.lang.reflect.Constructor dirClassCo=dirClass.getConstructor(coParCls); 98 99 Object [] coPar=new Object [2]; 100 coPar[0]=provIfaceCDL; 101 coPar[1]=dirParams; 102 SOFA.Connector.EEG.CodeWriter.JWriterDirector director=(SOFA.Connector.EEG.CodeWriter.JWriterDirector)dirClassCo.newInstance(coPar); 103 104 if (provIfaceCDL!=null) { 105 jwriter.write(director,provIfaceMapped); 106 } else { 107 jwriter.write(director); 108 } 109 110 } catch (Exception e) { 111 throw new ActionException("Can't generate java source "+destDir+"/"+outFile+".",e); 112 } 113 } 114 115 } 116 | Popular Tags |