KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > quercus > program > ClassDef


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Scott Ferguson
28  */

29
30 package com.caucho.quercus.program;
31
32 import com.caucho.quercus.env.Env;
33 import com.caucho.quercus.env.ObjectExtValue;
34 import com.caucho.quercus.env.QuercusClass;
35 import com.caucho.quercus.env.Value;
36 import com.caucho.quercus.expr.Expr;
37 import com.caucho.util.L10N;
38
39 import java.util.Map JavaDoc;
40 import java.util.Set JavaDoc;
41
42 /**
43  * Represents a Quercus class definition
44  */

45 abstract public class ClassDef {
46   private final static L10N L = new L10N(ClassDef.class);
47   
48   private final String JavaDoc _name;
49   private final String JavaDoc _parentName;
50
51   private final String JavaDoc []_ifaceList;
52
53   protected ClassDef(String JavaDoc name, String JavaDoc parentName, String JavaDoc []ifaceList)
54   {
55     _name = name;
56     _parentName = parentName;
57     _ifaceList = ifaceList;
58   }
59   
60   /**
61    * Returns the name.
62    */

63   public String JavaDoc getName()
64   {
65     return _name;
66   }
67
68   /**
69    * Returns the parent name.
70    */

71   public String JavaDoc getParentName()
72   {
73     return _parentName;
74   }
75
76   /**
77    * Returns the interfaces.
78    */

79   public String JavaDoc []getInterfaces()
80   {
81     return _ifaceList;
82   }
83
84   /**
85    * Return true for an abstract class.
86    */

87   public boolean isAbstract()
88   {
89     return false;
90   }
91
92   /**
93    * Return true for an interface class.
94    */

95   public boolean isInterface()
96   {
97     return false;
98   }
99
100   /**
101    * Initialize the quercus class.
102    */

103   public void initClass(QuercusClass cl)
104   {
105   }
106
107   /**
108    * Creates a new instance.
109    */

110   public Value newInstance(Env env, QuercusClass qcl)
111   {
112     if (isAbstract()) {
113       throw env.errorException(L.l("abstract class '{0}' cannot be instantiated.",
114                    getName()));
115     }
116     else if (isInterface()) {
117       throw env.errorException(L.l("interface '{0}' cannot be instantiated.",
118                    getName()));
119     }
120     
121     return new ObjectExtValue(qcl);
122   }
123
124   /**
125    * Creates a new instance.
126    */

127   public Value callNew(Env env, Expr []args)
128   {
129     return null;
130   }
131
132   /**
133    * Creates a new instance.
134    */

135   public Value callNew(Env env, Value []args)
136   {
137     return null;
138   }
139
140   /**
141    * Returns value for instanceof.
142    */

143   public boolean isA(String JavaDoc name)
144   {
145     if (_name.equalsIgnoreCase(name))
146       return true;
147
148     for (int i = 0; i < _ifaceList.length; i++) {
149       if (_ifaceList[i].equalsIgnoreCase(name))
150     return true;
151     }
152
153     return false;
154   }
155
156   /**
157    * Returns the constructor
158    */

159   abstract public AbstractFunction findConstructor();
160
161   /**
162    * Finds the matching constant
163    */

164   public Expr findConstant(String JavaDoc name)
165   {
166     return null;
167   }
168
169   public String JavaDoc toString()
170   {
171     return "Class[" + getName() + "]";
172   }
173   
174   public Set JavaDoc<Map.Entry JavaDoc<String JavaDoc, Expr>> fieldSet()
175   {
176     return null;
177   }
178   
179   public Set JavaDoc<Map.Entry JavaDoc<String JavaDoc, AbstractFunction>> functionSet()
180   {
181     return null;
182   }
183 }
184
185
Popular Tags