KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * JIface.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.EEM.ActionException;
10 import SOFA.Connector.EEG.EEM.ActionInterface;
11
12 /**
13  *
14  * @author ghort
15  * @version
16  */

17 public class JIface implements ActionInterface {
18
19     /** Creates new JIface */
20    public JIface(java.util.HashMap JavaDoc props) {
21    }
22
23     public String JavaDoc getName() {
24         return "jiface";
25     }
26      
27     public void perform(SOFA.Connector.Property[] params, String JavaDoc sourceDir, String JavaDoc sourcePackage, String JavaDoc destDir, String JavaDoc destPackage) throws ActionException {
28         String JavaDoc outFile, className, ifaceCDL, generator;
29         if ((outFile=SOFA.Connector.Property.findFirst(params,"file"))==null) {
30             throw new ActionException("file param not specified");
31         }
32         if ((className=SOFA.Connector.Property.findFirst(params,"class"))==null) {
33             throw new ActionException("class param not specified");
34         }
35         if ((generator=SOFA.Connector.Property.findFirst(params,"generator"))==null) {
36             throw new ActionException("generator param not specified");
37         }
38         if ((ifaceCDL=SOFA.Connector.Property.findFirst(params,"ifaceCDL"))==null) {
39             throw new ActionException("ifaceCDL param not specified");
40         }
41          
42         try {
43             SOFA.Connector.EEG.CodeWriter.JWriter jwriter=new SOFA.Connector.EEG.CodeWriter.JWriter(ifaceCDL);
44             jwriter.setOut(destDir+"/"+outFile,destPackage,className);
45
46             SOFA.Connector.Property[] dirParams=new SOFA.Connector.Property[params.length+3];
47             dirParams[0]=new SOFA.Connector.Property("outFile",destDir+"/"+outFile);
48             dirParams[1]=new SOFA.Connector.Property("outClass",className);
49             dirParams[2]=new SOFA.Connector.Property("outPackage",destPackage);
50             
51             for (int i=0;i<params.length;i++) {
52                 dirParams[i+3]=params[i];
53             }
54             
55             Class JavaDoc dirClass=Class.forName(sourcePackage+"."+generator);
56
57             Class JavaDoc[] coParCls=new Class JavaDoc[2];
58             coParCls[0]=Class.forName("java.lang.String");
59             coParCls[1]=Class.forName("[LSOFA.Connector.Property;");
60             java.lang.reflect.Constructor JavaDoc dirClassCo=dirClass.getConstructor(coParCls);
61
62             Object JavaDoc[] coPar=new Object JavaDoc[2];
63             coPar[0]=ifaceCDL;
64             coPar[1]=dirParams;
65             SOFA.Connector.EEG.CodeWriter.JWriterInterfaceDirector director=(SOFA.Connector.EEG.CodeWriter.JWriterInterfaceDirector)dirClassCo.newInstance(coPar);
66
67             jwriter.writeInterface(director);
68              
69         } catch (Exception JavaDoc e) {
70             throw new ActionException("Can't generate java source "+destDir+"/"+outFile+".",e);
71         }
72     }
73      
74 }
75
Popular Tags