001: /*
002: * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package com.caucho.es.parser;
030:
031: import com.caucho.es.ESException;
032: import com.caucho.es.ESId;
033: import com.caucho.server.util.CauchoSystem;
034:
035: import java.io.IOException;
036: import java.lang.reflect.Modifier;
037:
038: /**
039: * Expression representing a Java package, i.e. a partial class.
040: */
041: class PackageExpr extends Expr {
042: private Expr rawExpr;
043: private String name;
044:
045: private PackageExpr(Block block, Expr rawExpr, String name) {
046: super (block);
047:
048: this .rawExpr = rawExpr;
049: this .name = name;
050: }
051:
052: PackageExpr(Block block) {
053: super (block);
054:
055: this .rawExpr = block.newVar(ESId.intern("Packages"));
056: this .name = null;
057: }
058:
059: static Expr create(Block block, Expr rawExpr, String name) {
060: ClassLoader loader = block.getClassLoader();
061:
062: try {
063: Class cl;
064:
065: cl = CauchoSystem.loadClass(name, false, loader);
066:
067: if (Modifier.isPublic(cl.getModifiers()))
068: return new JavaClassExpr(block, cl);
069: } catch (Throwable e) {
070: }
071:
072: return new PackageExpr(block, rawExpr, name);
073: }
074:
075: void setType(int type) {
076: }
077:
078: int getType() {
079: return TYPE_ES;
080: }
081:
082: Expr getTypeExpr() {
083: return null;
084: }
085:
086: Expr fieldReference(ESId id) throws ESException {
087: String newName = null;
088:
089: if (name == null)
090: newName = id.toString();
091: else
092: newName = name + "." + id.toString();
093:
094: return PackageExpr.create(block, rawExpr.fieldReference(id),
095: newName);
096: }
097:
098: Expr fieldReference(Expr expr) {
099: return rawExpr.fieldReference(expr);
100: }
101:
102: CallExpr startCall() throws ESException {
103: return rawExpr.startCall();
104: }
105:
106: CallExpr startNew() throws ESException {
107: return rawExpr.startNew();
108: }
109:
110: void printImpl() throws IOException {
111: rawExpr.printImpl();
112: }
113: }
|