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  package org.apache.myfaces.commons.converter;
20  
21  import javax.faces.view.facelets.FaceletContext;
22  import javax.faces.view.facelets.MetaRule;
23  import javax.faces.view.facelets.Metadata;
24  import javax.faces.view.facelets.MetadataTarget;
25  import javax.faces.view.facelets.TagAttribute;
26  
27  final class _ConverterRule extends MetaRule {
28  
29      final static class ValueExpressionMetadata extends Metadata {
30  
31          private final String name;
32  
33          private final TagAttribute attr;
34  
35          private final Class type;
36  
37          public ValueExpressionMetadata(String name, Class type,
38                  TagAttribute attr) {
39              this.name = name;
40              this.attr = attr;
41              this.type = type;
42          }
43  
44          public void applyMetadata(FaceletContext ctx, Object instance) {
45              ((ConverterBase) instance).setValueExpression(this.name, this.attr
46                      .getValueExpression(ctx, this.type));
47          }
48  
49      }
50  
51      /*
52      final static class ValueBindingMetadata extends Metadata {
53  
54          private final String name;
55  
56          private final TagAttribute attr;
57  
58          private final Class type;
59  
60          public ValueBindingMetadata(String name, Class type, TagAttribute attr) {
61              this.name = name;
62              this.attr = attr;
63              this.type = type;
64          }
65  
66          public void applyMetadata(FaceletContext ctx, Object instance) {
67              ((ConverterBase) instance).setValueBinding(this.name,
68                      new LegacyValueBinding(this.attr.getValueExpression(ctx,
69                              this.type)));
70          }
71  
72      }
73      */
74  
75      public final static _ConverterRule Instance = new _ConverterRule();
76  
77      public _ConverterRule() {
78          super();
79      }
80  
81      public Metadata applyRule(String name, TagAttribute attribute,
82              MetadataTarget meta) {
83          if (meta.isTargetInstanceOf(ConverterBase.class)) {
84  
85              // if component and dynamic, then must set expression
86              if (!attribute.isLiteral()) {
87                  Class type = meta.getPropertyType(name);
88                  if (type == null) {
89                      type = Object.class;
90                  }
91                  //if (FacesAPI.getComponentVersion(meta.getTargetClass()) >= 12) {
92                      return new ValueExpressionMetadata(name, type, attribute);
93                  //} else {
94                  //    return new ValueBindingMetadata(name, type, attribute);
95                  //}
96              }
97          }
98          return null;
99      }
100 }