View Javadoc

1   /*
2    * Copyright 2004-2008 the Seasar Foundation and the Others.
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, 
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
15   */
16  package org.seasar.uruma.component.factory.desc;
17  
18  import java.util.ArrayList;
19  import java.util.Collections;
20  import java.util.List;
21  
22  /**
23   * <code>urumaComponent</code> 要素の情報を保持するためのクラスです。<br />
24   * 
25   * @author y-komori
26   */
27  public class UrumaComponentDesc {
28      private String tagName;
29  
30      private String tagHandlerClass;
31  
32      private String rendererClass;
33  
34      private List<String> tagHandlerArgs;
35  
36      private List<String> rendererArgs;
37  
38      /**
39       * タグ名称を返します。<br />
40       * 
41       * @return タグ名称
42       */
43      public String getTagName() {
44          return this.tagName;
45      }
46  
47      /**
48       * タグ名称を設定します。<br />
49       * 
50       * @param tagName
51       *            タグ名称
52       */
53      public void setTagName(final String tagName) {
54          this.tagName = tagName;
55      }
56  
57      /**
58       * タグハンドラのクラス名を返します。<br />
59       * 
60       * @return タグハンドラのクラス名
61       */
62      public String getTagHandlerClass() {
63          return this.tagHandlerClass;
64      }
65  
66      /**
67       * タグハンドラのクラス名を設定します。<br />
68       * 
69       * @param tagHandlerClass
70       *            タグハンドラのクラス名
71       */
72      public void setTagHandlerClass(final String tagHandlerClass) {
73          this.tagHandlerClass = tagHandlerClass;
74      }
75  
76      /**
77       * レンダラのクラス名を返します。<br />
78       * 
79       * @return レンダラのクラス名
80       */
81      public String getRendererClass() {
82          return this.rendererClass;
83      }
84  
85      /**
86       * レンダラのクラス名を設定します。<br />
87       * 
88       * @param rendererClass
89       *            レンダラのクラス名
90       */
91      public void setRendererClass(final String rendererClass) {
92          this.rendererClass = rendererClass;
93      }
94  
95      /**
96       * タグハンドラクラスの引数を追加します。<br />
97       * 
98       * @param arg
99       *            引数
100      */
101     public void addTagHandlerArg(final String arg) {
102         if (arg == null) {
103             return;
104         }
105         if (tagHandlerArgs == null) {
106             tagHandlerArgs = new ArrayList<String>();
107         }
108         tagHandlerArgs.add(arg);
109     }
110 
111     /**
112      * タグハンドラクラスの引数リストを返します。<br />
113      * 
114      * @return 引数リスト
115      */
116     @SuppressWarnings("unchecked")
117     public List<String> getTagHandlerArgs() {
118         if (tagHandlerArgs != null) {
119             return tagHandlerArgs;
120         } else {
121             return Collections.EMPTY_LIST;
122         }
123     }
124 
125     /**
126      * レンダラクラスの引数を追加します。<br />
127      * 
128      * @param arg
129      *            引数
130      */
131     public void addRendererArg(final String arg) {
132         if (arg == null) {
133             return;
134         }
135         if (rendererArgs == null) {
136             rendererArgs = new ArrayList<String>();
137         }
138         rendererArgs.add(arg);
139     }
140 
141     /**
142      * レンダラクラスの引数リストを返します。<br />
143      * 
144      * @return 引数リスト
145      */
146     @SuppressWarnings("unchecked")
147     public List<String> getRendererArgs() {
148         if (rendererArgs != null) {
149             return rendererArgs;
150         } else {
151             return Collections.EMPTY_LIST;
152         }
153     }
154 
155     /*
156      * @see java.lang.Object#toString()
157      */
158     @Override
159     public String toString() {
160         StringBuilder builder = new StringBuilder(512);
161         builder.append("tagName:" + getTagName());
162         builder.append(" tagHandler:" + getTagHandlerClass());
163         builder.append(listToString(getTagHandlerArgs()));
164         builder.append(" renderer:" + getRendererClass());
165         builder.append(listToString(getRendererArgs()));
166         return builder.toString();
167     }
168 
169     private String listToString(final List<?> list) {
170         if (list == null) {
171             return "()";
172         }
173 
174         StringBuilder builder = new StringBuilder(512);
175         builder.append("(");
176         for (Object obj : list) {
177             builder.append(obj.toString());
178             builder.append(", ");
179         }
180         if (list.size() > 0) {
181             builder.delete(builder.length() - 2, builder.length());
182         }
183         builder.append(")");
184         return builder.toString();
185     }
186 }