001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.jasper.el;
018:
019: import java.io.Externalizable;
020: import java.io.IOException;
021: import java.io.ObjectInput;
022: import java.io.ObjectOutput;
023:
024: import javax.el.ELContext;
025: import javax.el.ELException;
026: import javax.el.PropertyNotFoundException;
027: import javax.el.PropertyNotWritableException;
028: import javax.el.ValueExpression;
029:
030: /**
031: * Wrapper for providing context to ValueExpressions
032: *
033: * @author Jacob Hookom
034: */
035: public final class JspValueExpression extends ValueExpression implements
036: Externalizable {
037:
038: private ValueExpression target;
039:
040: private String mark;
041:
042: public JspValueExpression() {
043: super ();
044: }
045:
046: public JspValueExpression(String mark, ValueExpression target) {
047: this .target = target;
048: this .mark = mark;
049: }
050:
051: public Class<?> getExpectedType() {
052: return this .target.getExpectedType();
053: }
054:
055: public Class<?> getType(ELContext context)
056: throws NullPointerException, PropertyNotFoundException,
057: ELException {
058: try {
059: return this .target.getType(context);
060: } catch (PropertyNotFoundException e) {
061: if (e instanceof JspPropertyNotFoundException)
062: throw e;
063: throw new JspPropertyNotFoundException(this .mark, e);
064: } catch (ELException e) {
065: if (e instanceof JspELException)
066: throw e;
067: throw new JspELException(this .mark, e);
068: }
069: }
070:
071: public boolean isReadOnly(ELContext context)
072: throws NullPointerException, PropertyNotFoundException,
073: ELException {
074: try {
075: return this .target.isReadOnly(context);
076: } catch (PropertyNotFoundException e) {
077: if (e instanceof JspPropertyNotFoundException)
078: throw e;
079: throw new JspPropertyNotFoundException(this .mark, e);
080: } catch (ELException e) {
081: if (e instanceof JspELException)
082: throw e;
083: throw new JspELException(this .mark, e);
084: }
085: }
086:
087: public void setValue(ELContext context, Object value)
088: throws NullPointerException, PropertyNotFoundException,
089: PropertyNotWritableException, ELException {
090: try {
091: this .target.setValue(context, value);
092: } catch (PropertyNotWritableException e) {
093: if (e instanceof JspPropertyNotWritableException)
094: throw e;
095: throw new JspPropertyNotWritableException(this .mark, e);
096: } catch (PropertyNotFoundException e) {
097: if (e instanceof JspPropertyNotFoundException)
098: throw e;
099: throw new JspPropertyNotFoundException(this .mark, e);
100: } catch (ELException e) {
101: if (e instanceof JspELException)
102: throw e;
103: throw new JspELException(this .mark, e);
104: }
105: }
106:
107: public Object getValue(ELContext context)
108: throws NullPointerException, PropertyNotFoundException,
109: ELException {
110: try {
111: return this .target.getValue(context);
112: } catch (PropertyNotFoundException e) {
113: if (e instanceof JspPropertyNotFoundException)
114: throw e;
115: throw new JspPropertyNotFoundException(this .mark, e);
116: } catch (ELException e) {
117: if (e instanceof JspELException)
118: throw e;
119: throw new JspELException(this .mark, e);
120: }
121: }
122:
123: public boolean equals(Object obj) {
124: return this .target.equals(obj);
125: }
126:
127: public int hashCode() {
128: return this .target.hashCode();
129: }
130:
131: public String getExpressionString() {
132: return this .target.getExpressionString();
133: }
134:
135: public boolean isLiteralText() {
136: return this .target.isLiteralText();
137: }
138:
139: public void writeExternal(ObjectOutput out) throws IOException {
140: out.writeUTF(this .mark);
141: out.writeObject(this .target);
142: }
143:
144: public void readExternal(ObjectInput in) throws IOException,
145: ClassNotFoundException {
146: this .mark = in.readUTF();
147: this .target = (ValueExpression) in.readObject();
148: }
149: }
|