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.apt.generate;
21  
22  import org.apache.myfaces.tobago.apt.AnnotationUtils;
23  import org.apache.myfaces.tobago.apt.annotation.UIComponentTag;
24  
25  import javax.lang.model.element.TypeElement;
26  import java.util.ArrayList;
27  import java.util.List;
28  
29  public class ComponentInfo extends TagInfo {
30    private List<PropertyInfo> nonTransientProperties = new ArrayList<PropertyInfo>();
31    private List<PropertyInfo> transientProperties = new ArrayList<PropertyInfo>();
32    private boolean messages;
33    private String description;
34    private boolean deprecated;
35    private int index = 0;
36    private int nonTransientIndex = 0;
37    private List<String> behaviors = new ArrayList<String>();
38    private String defaultBehavior;
39  
40    public ComponentInfo(final TypeElement declaration, final UIComponentTag componentTag) {
41      super(declaration.getQualifiedName().toString(), componentTag.uiComponent(), componentTag.rendererType());
42  
43      setComponentType(AnnotationUtils.componentType(componentTag));
44      setComponentFamily(componentTag.componentFamily());
45      setComponentClassName(componentTag.uiComponent());
46    }
47  
48    @Deprecated
49    public ComponentInfo(final String sourceClass, final String qualifiedName, final String rendererType) {
50      super(sourceClass, qualifiedName, rendererType);
51    }
52  
53    public void addPropertyInfo(final ComponentPropertyInfo propertyInfo) {
54      getProperties().add(propertyInfo);
55      propertyInfo.setIndex(index);
56      index++;
57      if (!propertyInfo.isTransient()) {
58        nonTransientProperties.add(propertyInfo);
59        propertyInfo.setNonTransientIndex(nonTransientIndex);
60        nonTransientIndex++;
61      } else {
62        transientProperties.add(propertyInfo);
63      }
64    }
65  
66    public List<PropertyInfo> getNonTransientProperties() {
67      return nonTransientProperties;
68    }
69  
70    public List<PropertyInfo> getTransientProperties() {
71      return transientProperties;
72    }
73  
74    @Override
75    public int getPropertiesSize() {
76      return index;
77    }
78  
79    @Override
80    public int getPropertiesSizePlusOne() {
81      return index + 1;
82    }
83  
84    public int getNonTransientPropertiesSize() {
85      return nonTransientIndex;
86    }
87  
88    public int getNonTransientPropertiesSizePlusOne() {
89      return nonTransientIndex + 1;
90    }
91  
92    public boolean isMessages() {
93      return messages;
94    }
95  
96    public void setMessages(final boolean messages) {
97      this.messages = messages;
98    }
99  
100   public void setDescription(final String description) {
101     this.description = description;
102   }
103 
104   public String getDescription() {
105     return description;
106   }
107 
108   public void setDeprecated(final boolean deprecated) {
109     this.deprecated = deprecated;
110   }
111 
112   public boolean isDeprecated() {
113     return deprecated;
114   }
115 
116   public List<String> getBehaviors() {
117     return behaviors;
118   }
119 
120   public String getDefaultBehavior() {
121     return defaultBehavior;
122   }
123 
124   public void setDefaultBehavior(String defaultBehavior) {
125     this.defaultBehavior = defaultBehavior;
126   }
127 }