Project Tiles has retired. For details please refer to its Attic page.
NestedObjectDelegatePropertyAccessor xref
View Javadoc

1   /*
2    * $Id: NestedObjectDelegatePropertyAccessor.java 1049696 2010-12-15 20:30:10Z apetrelli $
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   * http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  package org.apache.tiles.ognl;
23  
24  import java.util.Map;
25  
26  import ognl.OgnlContext;
27  import ognl.OgnlException;
28  import ognl.PropertyAccessor;
29  
30  /**
31   * Uses a {@link PropertyAccessor} as a delegate, but passing a nested object as
32   * target.
33   *
34   * @param <T> The root object type from which the target object will be
35   * extracted.
36   * @since 2.2.0
37   * @version $Rev: 1049696 $ $Date: 2010-12-16 07:30:10 +1100 (Thu, 16 Dec 2010) $
38   */
39  public class NestedObjectDelegatePropertyAccessor<T> implements
40          PropertyAccessor {
41  
42      /**
43       * The extractor of the nested object.
44       *
45       * @since 2.2.0
46       */
47      private NestedObjectExtractor<T> nestedObjectExtractor;
48  
49      /**
50       * The delegated property accessor.
51       *
52       * @since 2.2.0
53       */
54      private PropertyAccessor propertyAccessor;
55  
56      /**
57       * Constructor.
58       *
59       * @param nestedObjectExtractor The extractor of the nested object.
60       * @param propertyAccessor The delegated property accessor.
61       * @since 2.2.0
62       */
63      public NestedObjectDelegatePropertyAccessor(
64              NestedObjectExtractor<T> nestedObjectExtractor,
65              PropertyAccessor propertyAccessor) {
66          this.nestedObjectExtractor = nestedObjectExtractor;
67          this.propertyAccessor = propertyAccessor;
68      }
69  
70      /** {@inheritDoc} */
71      @SuppressWarnings("unchecked")
72      public Object getProperty(@SuppressWarnings("rawtypes") Map context, Object target, Object name)
73              throws OgnlException {
74          return propertyAccessor.getProperty(context, nestedObjectExtractor
75                  .getNestedObject((T) target), name);
76      }
77  
78      /** {@inheritDoc} */
79      @SuppressWarnings("unchecked")
80      public void setProperty(@SuppressWarnings("rawtypes") Map context, Object target, Object name,
81              Object value) throws OgnlException {
82          propertyAccessor.setProperty(context, nestedObjectExtractor
83                  .getNestedObject((T) target), name, value);
84      }
85  
86      /** {@inheritDoc} */
87      @SuppressWarnings("unchecked")
88      public String getSourceAccessor(OgnlContext context, Object target,
89              Object index) {
90          return propertyAccessor.getSourceAccessor(context,
91                  nestedObjectExtractor.getNestedObject((T) target), index);
92      }
93  
94      /** {@inheritDoc} */
95      @SuppressWarnings("unchecked")
96      public String getSourceSetter(OgnlContext context, Object target,
97              Object index) {
98          return propertyAccessor.getSourceSetter(context, nestedObjectExtractor
99                  .getNestedObject((T) target), index);
100     }
101 }