KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nextime > ion > backoffice > bean > TypeBean


1 package org.nextime.ion.backoffice.bean;
2
3 import java.io.InputStream JavaDoc;
4 import java.util.StringTokenizer JavaDoc;
5 import java.util.Vector JavaDoc;
6
7 import org.apache.struts.digester.Digester;
8 import org.nextime.ion.framework.business.TypePublication;
9
10 public class TypeBean {
11
12     protected String JavaDoc _name;
13     protected String JavaDoc _template;
14     protected String JavaDoc _description;
15     protected Vector JavaDoc _properties = new Vector JavaDoc();
16     protected Vector JavaDoc _publicationsTypes = new Vector JavaDoc();
17
18     protected static Vector JavaDoc _types = new Vector JavaDoc();
19
20     public String JavaDoc getName() {
21         return _name;
22     }
23
24     public String JavaDoc getTemplate() {
25         return _template;
26     }
27
28     protected static TypeBean getBean(String JavaDoc template) {
29         for (int i = 0; i < _types.size(); i++) {
30             if (((TypeBean) _types.get(i)).getTemplate().equals(template)) {
31                 return (TypeBean) _types.get(i);
32             }
33         }
34         return null;
35     }
36
37     public String JavaDoc getDescription() {
38         return _description;
39     }
40
41     public Vector JavaDoc getPublicationTypes() {
42         try {
43             if (_publicationsTypes.contains("*")) {
44                 Vector JavaDoc r = new Vector JavaDoc();
45                 Vector JavaDoc rt = TypePublication.listAll();
46                 for (int i = 0; i < rt.size(); i++) {
47                     r.add(((TypePublication) rt.get(i)).getId());
48                 }
49                 return r;
50             }
51         } catch (Exception JavaDoc e) {
52             e.printStackTrace();
53         }
54         return _publicationsTypes;
55     }
56
57     public void setPublicationTypes(String JavaDoc types) {
58         StringTokenizer JavaDoc tokenizer = new StringTokenizer JavaDoc(types, ", ");
59         while (tokenizer.hasMoreTokens()) {
60             _publicationsTypes.add(tokenizer.nextToken());
61         }
62     }
63
64     public void setDescription(String JavaDoc description) {
65         _description = description;
66     }
67
68     public void setName(String JavaDoc name) {
69         _name = name;
70     }
71
72     public void setTemplate(String JavaDoc template) {
73         _template = template;
74     }
75
76     public Vector JavaDoc getProperties() {
77         return _properties;
78     }
79
80     public PropertyBean getProperty(String JavaDoc name) {
81         for (int i = 0; i < _properties.size(); i++) {
82             PropertyBean p = (PropertyBean) _properties.get(i);
83             if (name.equals(p.getName())) {
84                 return p;
85             }
86         }
87         return null;
88     }
89
90     public int getPropertiesNumber() {
91         return _properties.size();
92     }
93
94     public void addProperty(PropertyBean p) {
95         _properties.add(p);
96     }
97
98     public Vector JavaDoc getItems() {
99         return _types;
100     }
101
102     public static void addBean(TypeBean bean) {
103         _types.add(bean);
104     }
105
106     protected static TypeBean parse(InputStream JavaDoc in) throws Exception JavaDoc {
107         TypeBean bean = new TypeBean();
108         Digester digester = new Digester();
109         digester.push(bean);
110         digester.setValidating(false);
111         digester.addObjectCreate(
112             "templates-description/template",
113             "org.nextime.ion.backoffice.bean.TypeBean");
114         digester.addSetProperties("templates-description/template");
115         digester.addSetNext("templates-description/template", "addBean");
116         digester.addCallMethod(
117             "templates-description/template/description",
118             "setDescription",
119             0);
120         digester.addCallMethod(
121             "templates-description/template/publication-types",
122             "setPublicationTypes",
123             0);
124         digester.addObjectCreate(
125             "templates-description/template/property",
126             "org.nextime.ion.backoffice.bean.PropertyBean");
127         digester.addSetProperties("templates-description/template/property");
128         digester.addSetTop(
129             "templates-description/template/property",
130             "setSectionType");
131         digester.parse(in);
132         return bean;
133     }
134 }
135
Popular Tags