KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SOFA > Connector > EEG > EEM > Actions > JImpl


1 /*
2  * JImpl.java
3  *
4  * Created on 2. duben 2002, 23:37
5  */

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 /**
16  *
17  * @author ghort
18  * @version
19  */

20 public class JImpl implements ActionInterface {
21
22     /** Creates new JImpl */
23    public JImpl(java.util.HashMap JavaDoc props) {
24    }
25
26     public String JavaDoc getName() {
27         return "jimpl";
28     }
29      
30     public void perform(SOFA.Connector.Property[] params, String JavaDoc sourceDir, String JavaDoc sourcePackage, String JavaDoc destDir, String JavaDoc destPackage) throws ActionException {
31         String JavaDoc 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 JavaDoc dirClass=Class.forName(sourcePackage+"."+generator);
93
94             Class JavaDoc[] coParCls=new Class JavaDoc[2];
95             coParCls[0]=Class.forName("java.lang.String");
96             coParCls[1]=Class.forName("[LSOFA.Connector.Property;");
97             java.lang.reflect.Constructor JavaDoc dirClassCo=dirClass.getConstructor(coParCls);
98
99             Object JavaDoc[] coPar=new Object JavaDoc[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 JavaDoc e) {
111             throw new ActionException("Can't generate java source "+destDir+"/"+outFile+".",e);
112         }
113     }
114      
115 }
116
Popular Tags