KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SOFA > SOFAnode > Made > CodeGen > ContainedGeneratedObject


1 /* $Id: ContainedGeneratedObject.java,v 1.2 2004/05/20 14:23:51 bures Exp $ */
2 package SOFA.SOFAnode.Made.CodeGen;
3
4 import java.io.IOException JavaDoc;
5 import java.rmi.RemoteException JavaDoc;
6
7 import SOFA.SOFAnode.Made.TIR.Contained;
8 import SOFA.SOFAnode.Made.TIR.Identification;
9  
10 /** Representation of already generated contained object. It's for generating of correct references to
11   * this object, especially for generating reference to typedefs.
12   *
13   * @author Petr Hnetynka
14   */

15 public class ContainedGeneratedObject extends GeneratedObject {
16
17   /** object in TIR */
18   Contained obj;
19   /** generated name */
20   String JavaDoc generatedName;
21
22   String JavaDoc inRef;
23   String JavaDoc outRef;
24  
25   /** Constructor
26     *
27     * @param obj represented repository object
28     * @param generatedName name of generated type
29     * @exception RemoteException remote exception
30     */

31   public ContainedGeneratedObject(Contained obj, String JavaDoc generatedName) throws RemoteException JavaDoc {
32     this.obj = obj;
33     this.generatedName = generatedName;
34     key = createKey(obj);
35     inRef = generatedName;
36     outRef = generatedName+"Holder";
37   }
38
39 /** Constructor
40     *
41     * @param obj represented repository object
42     * @param inRefer in reference
43     * @param outRefer out reference
44     * @exception RemoteException remote exception
45     */

46   public ContainedGeneratedObject(Contained obj, String JavaDoc inRefer, String JavaDoc outRefer) throws RemoteException JavaDoc {
47     this.obj = obj;
48     this.generatedName = inRefer;
49     key = createKey(obj);
50     inRef = inRefer;
51     outRef = outRefer;
52   }
53   
54   /** Compare identification of this object with given absolute name and version.
55     *
56     * @param absName absolute name of object
57     * @param ver version identifier
58     * @return <tt>true</tt> if this is object with given identification
59     * @exception RemoteException remote exception
60     */

61   public boolean isEqual(String JavaDoc absName, String JavaDoc ver) throws RemoteException JavaDoc {
62     Identification idl = obj.get_identification();
63     return absName.compareTo(idl.absolute_name().name())==0 && ver.compareTo(idl.version())==0;
64   }
65
66   /** Compare identification of this object with given identification.
67     *
68     * @param identification tested identification
69     * @return <tt>true</tt> if this is object with given identification
70     * @exception RemoteException remote exception
71     */

72   public boolean isEqual(Identification identification) throws RemoteException JavaDoc {
73     return obj.get_identification().is_equal(identification);
74   }
75
76   // inherited from GeneratedObject
77
public String JavaDoc genReference(int kind) {
78     switch (kind) {
79     case INREF: return inRef;
80     case OUTREF: return outRef;
81     default: return null;
82     }
83   }
84
85   // inherited from GeneratedObject
86
public void genReference(CGFileWriter out, int kind) throws IOException JavaDoc {
87     switch (kind) {
88     case INREF: out.iwrite(inRef);
89     case OUTREF: out.iwrite(outRef);
90     default: ;
91     }
92   }
93
94   // inherited from GeneratedObject
95
public String JavaDoc genSpecReference(int kind, int specType) {
96     if (specType == 0) {
97       switch (kind) {
98       case INREF: return inRef;
99       case OUTREF: return outRef;
100       default: return null;
101       }
102     } else if (specType == 1) { // CN interface
103
int n = inRef.lastIndexOf('.');
104       StringBuffer JavaDoc sb = new StringBuffer JavaDoc(inRef);
105       if (n != -1) {
106         sb.insert(n+1,"CN");
107       } else {
108         sb.insert(inRef.lastIndexOf(":")+1,"CN");
109       }
110       return sb.toString();
111     }
112     return null;
113   }
114
115   // inherited from GeneratedObject
116
public void genSpecReference(CGFileWriter out, int kind, int specType) throws IOException JavaDoc {
117     out.iwrite(genSpecReference(kind,specType));
118   }
119
120
121   public void defaultValue(CGFileWriter out) throws IOException JavaDoc {
122     out.iwriteln("null");
123   }
124
125   public String JavaDoc defaultValue() throws IOException JavaDoc {
126     return "null";
127   }
128
129   public void genReadType(CGFileWriter out, String JavaDoc varName) throws IOException JavaDoc {
130     out.iwrite(varName+" = "+generatedName+"Helper.read("+defaultIstream+")");
131   }
132
133   public String JavaDoc genReadType(String JavaDoc varName) throws IOException JavaDoc {
134     return varName+" = "+generatedName+"Helper.read("+defaultIstream+")";
135   }
136
137   public void genWriteType(CGFileWriter out, String JavaDoc varName) throws IOException JavaDoc {
138     out.iwrite(generatedName+"Helper.write("+defaultOstream+", "+ varName+")");
139   }
140
141   public String JavaDoc genWriteType(String JavaDoc varName) throws IOException JavaDoc {
142     return generatedName+"Helper.write("+defaultOstream+", "+ varName+")";
143   }
144
145   public String JavaDoc toString() {
146     return inRef;
147   }
148 }
149
Popular Tags