View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.myfaces.tobago.facelets;
21  
22  import javax.el.ELContext;
23  import javax.el.ELException;
24  import javax.el.MethodExpression;
25  import javax.el.MethodInfo;
26  import javax.el.MethodNotFoundException;
27  import javax.el.PropertyNotFoundException;
28  import javax.faces.FacesWrapper;
29  import javax.faces.view.facelets.TagAttribute;
30  import java.io.Externalizable;
31  import java.io.IOException;
32  import java.io.ObjectInput;
33  import java.io.ObjectOutput;
34  
35  /*
36   * Was copied from MyFaces-Impl.
37   */
38  
39  /**
40   * Jacob Hookom
41   */
42  public final class TagMethodExpression extends MethodExpression
43      implements Externalizable, FacesWrapper<MethodExpression> {
44  
45    private static final long serialVersionUID = 1L;
46  
47    private String attr;
48    private MethodExpression orig;
49  
50    public TagMethodExpression() {
51      super();
52    }
53  
54    public TagMethodExpression(final TagAttribute attr, final MethodExpression orig) {
55      this.attr = attr.toString();
56      this.orig = orig;
57    }
58  
59    public MethodInfo getMethodInfo(final ELContext context) {
60      try {
61        return this.orig.getMethodInfo(context);
62      } catch (final PropertyNotFoundException pnfe) {
63        throw new PropertyNotFoundException(this.attr + ": " + pnfe.getMessage(), pnfe.getCause());
64      } catch (final MethodNotFoundException mnfe) {
65        throw new MethodNotFoundException(this.attr + ": " + mnfe.getMessage(), mnfe.getCause());
66      } catch (final ELException e) {
67        throw new ELException(this.attr + ": " + e.getMessage(), e.getCause());
68      }
69    }
70  
71    public Object invoke(final ELContext context, final Object[] params) {
72      try {
73        return this.orig.invoke(context, params);
74      } catch (final PropertyNotFoundException pnfe) {
75        throw new PropertyNotFoundException(this.attr + ": " + pnfe.getMessage(), pnfe.getCause());
76      } catch (final MethodNotFoundException mnfe) {
77        throw new MethodNotFoundException(this.attr + ": " + mnfe.getMessage(), mnfe.getCause());
78      } catch (final ELException e) {
79        throw new ELException(this.attr + ": " + e.getMessage(), e.getCause());
80      }
81    }
82  
83    public String getExpressionString() {
84      return this.orig.getExpressionString();
85    }
86  
87    public boolean equals(final Object obj) {
88      return this.orig.equals(obj);
89    }
90  
91    public int hashCode() {
92      return this.orig.hashCode();
93    }
94  
95    public boolean isLiteralText() {
96      return this.orig.isLiteralText();
97    }
98  
99    public void writeExternal(final ObjectOutput out) throws IOException {
100     out.writeObject(this.orig);
101     out.writeUTF(this.attr);
102   }
103 
104   public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
105     this.orig = (MethodExpression) in.readObject();
106     this.attr = in.readUTF();
107   }
108 
109   public String toString() {
110     return this.attr + ": " + this.orig;
111   }
112 
113   public MethodExpression getWrapped() {
114     return this.orig;
115   }
116 }