Source code: edu/ou/kmi/buddyspace/xml/XDataFieldBuilder.java
1 /*
2 * License
3 *
4 * The contents of this file are subject to the Jabber Open Source License
5 * Version 1.0 (the "License"). You may not copy or use this file, in either
6 * source code or executable form, except in compliance with the License. You
7 * may obtain a copy of the License at http://www.jabber.com/license/ or at
8 * http://www.opensource.org/.
9 *
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
14 *
15 * Copyrights
16 *
17 * Portions created by or assigned to Jabber.com, Inc. are
18 * Copyright (c) 2000 Jabber.com, Inc. All Rights Reserved. Contact
19 * information for Jabber.com, Inc. is available at http://www.jabber.com/.
20 *
21 * Portions Copyright (c) 1999-2000 David Waite
22 *
23 * Acknowledgements
24 *
25 * Special thanks to the Jabber Open Source Contributors for their
26 * suggestions and support of Jabber.
27 *
28 * Changes
29 *
30 * @author David Waite <a href="mailto:dwaite@jabber.com">
31 * <i><dwaite@jabber.com></i></a>
32 *
33 * @author $Author: brouk $
34 * @version $Revision: 1.2 $
35 *
36 * j.komzak
37 * Changed into XDataFieldBuilder
38 */
39
40 package edu.ou.kmi.buddyspace.xml;
41
42 /*
43 * XDataFieldBuilder.java
44 *
45 * Project: BuddySpace
46 * (C) Copyright Knowledge Media Institute 2002
47 *
48 *
49 * Created on 5 February 2003, 12:23
50 */
51
52 import java.util.Vector;
53 import org.jabber.jabberbeans.Extension.*;
54 import org.jabber.jabberbeans.*;
55
56 /**
57 * <code>XDataFieldBuilder</code> is used to construct XDataField objects
58 *
59 * @author Jiri Komzak, Knowledge Media Institute, Open University, United Kingdom
60 */
61 public class XDataFieldBuilder
62 implements ExtensionBuilder
63 {
64 /** Vector of values fields contained. */
65 private Vector valueList;
66
67 /** Vector of option tags contained. */
68 private Vector optionList;
69
70 /** Attributes. */
71 private String label;
72 private String type;
73 private String var;
74 private String desc;
75 private boolean required;
76
77 /** Creates a new <code>XDataFieldBuilder</code> instance. */
78 public XDataFieldBuilder()
79 { reset(); }
80
81 /**
82 * <code>reset</code> the builder to a default state, so it can be reused.
83 */
84 public void reset() {
85 valueList = new Vector();
86 optionList = new Vector();
87 label = type = var = desc = null;
88 required = false;
89 }
90
91 public void setLabel(String newLabel) {
92 label = newLabel;
93 }
94
95 public String getLabel() {
96 return label;
97 }
98
99 public void setType(String newType) {
100 type = newType;
101 }
102
103 public String getType() {
104 return type;
105 }
106
107 public void setVar(String newVar) {
108 var = newVar;
109 }
110
111 public String getVar() {
112 return var;
113 }
114
115 public void setDesc(String newDesc) {
116 desc = newDesc;
117 }
118
119 public String getDesc() {
120 return desc;
121 }
122
123 public void setRequired(boolean newRequired) {
124 required = newRequired;
125 }
126
127 public boolean getRequired() {
128 return required;
129 }
130
131 public void addValue(String newValue) {
132 //if (!valueList.contains(newValue))
133 valueList.addElement(newValue);
134 }
135
136 /**
137 * <code>addChild</code> adds a new child tag object to the end of this
138 * list.
139 */
140 public void addChild(XMLData child)
141 {
142 if (child instanceof XDataFieldOption)
143 if (!optionList.contains(child))
144 optionList.addElement(child);
145
146 /*else if (child instanceof SingleValueTag) {
147 SingleValueTag t = (SingleValueTag) child;
148 if ("value".equals(t.getName())) {
149 if (!valueList.contains(t.getValue()))
150 valueList.addElement(t.getValue());
151 }
152 else if ("desc".equals(t.getName()))
153 desc = t.getValue();
154 else if ("required".equals(t.getName()))
155 setRequired(true);
156 }*/
157 }
158
159 /**
160 * <code>getOptions</code> returns the vector representing the option
161 * objects associated with this object.
162 *
163 * @return a <code>Vector</code> value
164 */
165 public Vector getOptions()
166 { return optionList; }
167
168 /**
169 * <code>getOptions</code> returns the vector representing the value
170 * objects associated with this object.
171 *
172 * @return a <code>Vector</code> value
173 */
174 public Vector getValues()
175 { return valueList; }
176
177 /**
178 * <code>build</code> a new MapTag object
179 *
180 * @return an <code>Extension</code> value
181 * @exception InstantiationException if insufficient or incorrect data
182 * was proviced.
183 */
184 public Extension build()
185 throws InstantiationException
186 { return new XDataField(this); }
187 }