KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SOFA > SOFAnode > Made > CDL > CompVG


1 /* $Id: CompVG.java,v 1.2 2004/05/20 14:23:51 bures Exp $ */
2 package SOFA.SOFAnode.Made.CDL;
3 import java.rmi.RemoteException JavaDoc;
4
5 import SOFA.SOFAnode.Made.TIR.CDLRepository;
6 import SOFA.SOFAnode.Made.TIR.ExprOperDef;
7 import SOFA.SOFAnode.Made.TIR.Repository;
8 import SOFA.SOFAnode.Made.TIR.TIRExceptCreate;
9 import SOFA.SOFAnode.Made.TIR.ValueGen;
10
11 class CompVG extends CompExprOper {
12   List elements;
13   
14   public CompVG(List els) {
15     super(CompExprKind.e_valuegen);
16     if (els==null)
17       elements = new List();
18     else
19       elements = els;
20   }
21
22   public int type() {
23     return CompExprKind.e_valuegen;
24   }
25   
26   public boolean isProp() {
27     elements.toFirst();
28     for (int i=0;i<elements.size(); i++) {
29       CompVGElem el = (CompVGElem) elements.aktual();
30       if (el.expr1.isProp())
31         return true;
32       if (el.expr2 != null)
33         if (el.expr2.isProp())
34           return true;
35       elements.toNext();
36     }
37     return false;
38   }
39
40   public EnumList nameProp(CompRepository rep) throws CDLExceptRemote, CDLExceptLock {
41     EnumList ret = new EnumList();
42     elements.toFirst();
43     for (int i=0;i<elements.size(); i++) {
44       CompVGElem el = (CompVGElem) elements.aktual();
45       int j;
46       EnumList l = el.expr1.nameProp(rep);
47       l.toFirst();
48       for (j=0;j<l.size();j++) {
49         ret.addName((String JavaDoc) l.aktual());
50         l.toNext();
51       }
52       if (el.expr2 != null)
53         l = el.expr2.nameProp(rep);
54         l.toFirst();
55         for (j=0;j<l.size();j++) {
56           ret.addName((String JavaDoc) l.aktual());
57           l.toNext();
58         }
59       elements.toNext();
60     }
61     return ret;
62   }
63
64   public ExprOperDef toNormal(CDLRepository rep) throws CDLExceptToNormal, CDLExceptRemote, CDLExceptLock {
65     try {
66       ValueGen ret = ((Repository) rep.get_containing_repository()).create_valuegen();
67       elements.toFirst();
68       for(int i=0;i<elements.size();i++) {
69         ExprOperDef ex1 = ((CompVGElem) elements.aktual()).expr1.toNormal(rep);
70         ExprOperDef ex2 = null;
71         if (((CompVGElem) elements.aktual()).expr2 != null)
72           ex2 = ((CompVGElem) elements.aktual()).expr2.toNormal(rep);
73         if ((ret.create_element(ex1, ex2))==null)
74           throw new CDLExceptToNormal("Can't create value generator");
75         elements.toNext();
76       }
77       return ret;
78     } catch (RemoteException JavaDoc e) {
79       throw new CDLExceptRemote("Remote exception occured: "+e.getMessage());
80     } catch (TIRExceptCreate ecr) {
81       throw new CDLExceptToNormal("Can't create expression");
82     }
83   }
84
85   public void checkConsist(EnumList props, CompRepository rep) throws CDLExceptCheck, CDLExceptLock, CDLExceptRemote {
86     elements.toFirst();
87     for(int i=0;i<elements.size();i++) {
88       ((CompVGElem) elements.aktual()).checkConsist(props, rep);
89       elements.toNext();
90     }
91   }
92
93   public String JavaDoc toString() {
94     StringBuffer JavaDoc sb = new StringBuffer JavaDoc("<");
95     elements.toFirst();
96     for (int i=0;i<elements.size();i++) {
97       if (i!=0)
98         sb.append(",");
99       sb.append(((CompVGElem) elements.aktual()).toString());
100       elements.toNext();
101     }
102     sb.append(">");
103     return sb.toString();
104   }
105 }
106
Popular Tags