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<>();
31    private List<PropertyInfo> transientProperties = new ArrayList<>();
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<>();
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    /**
49     * @deprecated since 2.0.0
50     */
51    @Deprecated
52    public ComponentInfo(final String sourceClass, final String qualifiedName, final String rendererType) {
53      super(sourceClass, qualifiedName, new String[]{rendererType});
54    }
55  
56    public void addPropertyInfo(final ComponentPropertyInfo propertyInfo) {
57      getProperties().add(propertyInfo);
58      propertyInfo.setIndex(index);
59      index++;
60      if (!propertyInfo.isTransient()) {
61        nonTransientProperties.add(propertyInfo);
62        propertyInfo.setNonTransientIndex(nonTransientIndex);
63        nonTransientIndex++;
64      } else {
65        transientProperties.add(propertyInfo);
66      }
67    }
68  
69    public List<PropertyInfo> getNonTransientProperties() {
70      return nonTransientProperties;
71    }
72  
73    public List<PropertyInfo> getTransientProperties() {
74      return transientProperties;
75    }
76  
77    @Override
78    public int getPropertiesSize() {
79      return index;
80    }
81  
82    @Override
83    public int getPropertiesSizePlusOne() {
84      return index + 1;
85    }
86  
87    public int getNonTransientPropertiesSize() {
88      return nonTransientIndex;
89    }
90  
91    public int getNonTransientPropertiesSizePlusOne() {
92      return nonTransientIndex + 1;
93    }
94  
95    public boolean isMessages() {
96      return messages;
97    }
98  
99    public void setMessages(final boolean messages) {
100     this.messages = messages;
101   }
102 
103   public void setDescription(final String description) {
104     this.description = description;
105   }
106 
107   public String getDescription() {
108     return description;
109   }
110 
111   public void setDeprecated(final boolean deprecated) {
112     this.deprecated = deprecated;
113   }
114 
115   public boolean isDeprecated() {
116     return deprecated;
117   }
118 
119   public List<String> getBehaviors() {
120     return behaviors;
121   }
122 
123   public String getDefaultBehavior() {
124     return defaultBehavior;
125   }
126 
127   public void setDefaultBehavior(final String defaultBehavior) {
128     this.defaultBehavior = defaultBehavior;
129   }
130 }