KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > es > parser > PackageExpr


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  * Free SoftwareFoundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Scott Ferguson
27  */

28
29 package com.caucho.es.parser;
30
31 import com.caucho.es.ESException;
32 import com.caucho.es.ESId;
33 import com.caucho.server.util.CauchoSystem;
34
35 import java.io.IOException JavaDoc;
36 import java.lang.reflect.Modifier JavaDoc;
37
38 /**
39  * Expression representing a Java package, i.e. a partial class.
40  */

41 class PackageExpr extends Expr {
42   private Expr rawExpr;
43   private String JavaDoc name;
44
45   private PackageExpr(Block block, Expr rawExpr, String JavaDoc name)
46   {
47     super(block);
48
49     this.rawExpr = rawExpr;
50     this.name = name;
51   }
52
53   PackageExpr(Block block)
54   {
55     super(block);
56
57     this.rawExpr = block.newVar(ESId.intern("Packages"));
58     this.name = null;
59   }
60
61   static Expr create(Block block, Expr rawExpr, String JavaDoc name)
62   {
63     ClassLoader JavaDoc loader = block.getClassLoader();
64
65     try {
66       Class JavaDoc cl;
67
68       cl = CauchoSystem.loadClass(name, false, loader);
69
70       if (Modifier.isPublic(cl.getModifiers()))
71         return new JavaClassExpr(block, cl);
72     } catch (Throwable JavaDoc e) {
73     }
74
75     return new PackageExpr(block, rawExpr, name);
76   }
77
78   void setType(int type)
79   {
80   }
81
82   int getType()
83   {
84     return TYPE_ES;
85   }
86
87   Expr getTypeExpr()
88   {
89     return null;
90   }
91   
92   Expr fieldReference(ESId id)
93     throws ESException
94   {
95     String JavaDoc newName = null;
96     
97     if (name == null)
98       newName = id.toString();
99     else
100       newName = name + "." + id.toString();
101
102     return PackageExpr.create(block, rawExpr.fieldReference(id), newName);
103   }
104   
105   Expr fieldReference(Expr expr)
106   {
107     return rawExpr.fieldReference(expr);
108   }
109
110   CallExpr startCall()
111     throws ESException
112   {
113     return rawExpr.startCall();
114   }
115
116   CallExpr startNew()
117     throws ESException
118   {
119     return rawExpr.startNew();
120   }
121
122   void printImpl() throws IOException JavaDoc
123   {
124     rawExpr.printImpl();
125   }
126 }
127
Popular Tags