KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > el > LongLiteral


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.el;
31
32 import com.caucho.vfs.WriteStream;
33
34 import javax.el.ELContext;
35 import javax.el.ELException;
36 import java.io.IOException JavaDoc;
37
38 /**
39  * Represents a long literal expression.
40  */

41 public class LongLiteral extends Expr {
42   private long _value;
43   private Long JavaDoc _objValue;
44
45   /**
46    * Creates the literal with its value.
47    */

48   public LongLiteral(long value)
49   {
50     _value = value;
51     _objValue = new Long JavaDoc(value);
52   }
53
54   /**
55    * Returns true if the expression is constant.
56    */

57   @Override JavaDoc
58   public boolean isConstant()
59   {
60     return true;
61   }
62
63   /**
64    * Evaluate the expression as an object.
65    *
66    * @param env the variable environment
67    *
68    * @return the long value as a Long
69    */

70   @Override JavaDoc
71   public Object JavaDoc getValue(ELContext env)
72     throws ELException
73   {
74     return _objValue;
75   }
76
77   /**
78    * Evaluate the expression as an object as a long.
79    *
80    * @param env the variable environment
81    *
82    * @return the long value
83    */

84   @Override JavaDoc
85   public long evalLong(ELContext env)
86     throws ELException
87   {
88     return _value;
89   }
90
91   /**
92    * Evaluate the expression as a double.
93    *
94    * @param env the variable environment
95    *
96    * @return the double value
97    */

98   @Override JavaDoc
99   public double evalDouble(ELContext env)
100     throws ELException
101   {
102     return (double) _value;
103   }
104
105   /**
106    * Evalutes directly to the output.
107    *
108    * @param out the output stream
109    * @param env the variable environment
110    */

111   @Override JavaDoc
112   public boolean print(WriteStream out, ELContext env, boolean isEscaped)
113     throws IOException JavaDoc, ELException
114   {
115     out.print(_value);
116
117     return false;
118   }
119
120   /**
121    * Prints the code to create an LongLiteral.
122    *
123    * @param os the stream to the generated *.java file
124    */

125   public void printCreate(WriteStream os)
126     throws IOException JavaDoc
127   {
128     os.print("new com.caucho.el.LongLiteral(");
129     os.print(_value);
130     os.print("L)");
131   }
132
133   /**
134    * Returns true for equal strings.
135    */

136   public boolean equals(Object JavaDoc o)
137   {
138     if (! (o instanceof LongLiteral))
139       return false;
140
141     LongLiteral literal = (LongLiteral) o;
142
143     return _value == literal._value;
144   }
145   
146   /**
147    * Returns a readable representation of the expr.
148    */

149   public String JavaDoc toString()
150   {
151     return String.valueOf(_value);
152   }
153 }
154
Popular Tags