View Javadoc

1   /*
2    * Copyright 2002-2004 The Apache Software Foundation
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.apache.commons.clazz.reflect.common;
17  
18  import org.apache.commons.clazz.reflect.ReflectedClazz;
19  
20  /**
21   * Holds parse results for individual accessor methods for a 
22   * scalar property.
23   * 
24   * @author <a href="mailto:dmitri@apache.org">Dmitri Plotnikov</a>
25   * @version $Id: ReflectedScalarPropertyParseResults.java 155436 2005-02-26 13:17:48Z dirkv $
26   */
27  public class ReflectedScalarPropertyParseResults 
28              extends ReflectedPropertyParseResults
29  {
30      /**
31       * Constructor for ReflectedScalarPropertyParseResults.
32       */
33      public ReflectedScalarPropertyParseResults(
34              ReflectedClazz clazz, String propertyName) 
35      {
36          super(clazz, propertyName);
37      }
38      
39      protected String getPropertyCategory() {
40          return "scalar";
41      }
42      
43      public boolean checkConsistency() {        
44          if (!super.checkConsistency()) {
45              return false;
46          }
47                  
48          if (readMethodParseResults == null) {
49              return false;
50          }
51  
52          Class type = readMethodParseResults.getType();
53          if (writeMethodParseResults != null) {
54              if (!type.equals(writeMethodParseResults.getType())) {
55                  return false;
56              }
57          }
58          return true;
59      }
60          
61      protected boolean appendInconsistencyDescriptions(StringBuffer buffer) {
62          if (!super.appendInconsistencyDescriptions(buffer)) {
63              return false;
64          }
65                  
66          if (readMethodParseResults == null) {
67              buffer.append("\n     - Does not have a get() method");
68              return true;
69          }
70  
71          Class type = readMethodParseResults.getType();
72          if (writeMethodParseResults != null) {
73              if (!type.equals(writeMethodParseResults.getType())) {
74                  buffer.append("\n     - Get() and set(v) types do not match");
75              }
76          }
77          return true;  
78      }  
79  }