001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: /**
042: * This generated bean class PreferenceType
043: * matches the schema element 'preferenceType'.
044: * The root bean class is PortletApp
045: *
046: * ===============================================================
047: *
048: * Persistent preference values that may be used for customization
049: * and personalization by the portlet.
050: * Used in: portlet-preferences
051: *
052: * ===============================================================
053: * Generated on Tue Apr 26 19:08:25 MDT 2005
054: * @Generated
055: */package org.netbeans.modules.visualweb.api.portlet.dd;
056:
057: public class PreferenceType
058: implements
059: org.netbeans.modules.visualweb.api.portlet.dd.PreferenceTypeInterface,
060: org.netbeans.modules.visualweb.api.portlet.dd.CommonBean {
061: public static final String ID = "Id"; // NOI18N
062: public static final String NAME = "Name"; // NOI18N
063: public static final String VALUE = "Value"; // NOI18N
064: public static final String READ_ONLY = "ReadOnly"; // NOI18N
065:
066: private java.lang.String _Id;
067: private java.lang.String _Name;
068: private java.util.List _Value = new java.util.ArrayList(); // List<java.lang.String>
069: private java.lang.String _ReadOnly;
070:
071: /**
072: * Normal starting point constructor.
073: */
074: public PreferenceType() {
075: _Name = "";
076: }
077:
078: /**
079: * Required parameters constructor
080: */
081: public PreferenceType(java.lang.String name) {
082: _Name = name;
083: }
084:
085: /**
086: * Deep copy
087: */
088: public PreferenceType(
089: org.netbeans.modules.visualweb.api.portlet.dd.PreferenceType source) {
090: this (source, false);
091: }
092:
093: /**
094: * Deep copy
095: * @param justData just copy the XML relevant data
096: */
097: public PreferenceType(
098: org.netbeans.modules.visualweb.api.portlet.dd.PreferenceType source,
099: boolean justData) {
100: _Id = source._Id;
101: _Name = source._Name;
102: for (java.util.Iterator it = source._Value.iterator(); it
103: .hasNext();) {
104: java.lang.String srcElement = (java.lang.String) it.next();
105: _Value.add(srcElement);
106: }
107: _ReadOnly = source._ReadOnly;
108: }
109:
110: // This attribute is optional
111: public void setId(java.lang.String value) {
112: _Id = value;
113: }
114:
115: public java.lang.String getId() {
116: return _Id;
117: }
118:
119: // This attribute is mandatory
120: public void setName(java.lang.String value) {
121: _Name = value;
122: }
123:
124: public java.lang.String getName() {
125: return _Name;
126: }
127:
128: // This attribute is an array, possibly empty
129: public void setValue(java.lang.String[] value) {
130: if (value == null)
131: value = new java.lang.String[0];
132: _Value.clear();
133: ((java.util.ArrayList) _Value).ensureCapacity(value.length);
134: for (int i = 0; i < value.length; ++i) {
135: _Value.add(value[i]);
136: }
137: }
138:
139: public void setValue(int index, java.lang.String value) {
140: _Value.set(index, value);
141: }
142:
143: public java.lang.String[] getValue() {
144: java.lang.String[] arr = new java.lang.String[_Value.size()];
145: return (java.lang.String[]) _Value.toArray(arr);
146: }
147:
148: public java.util.List fetchValueList() {
149: return _Value;
150: }
151:
152: public java.lang.String getValue(int index) {
153: return (java.lang.String) _Value.get(index);
154: }
155:
156: // Return the number of value
157: public int sizeValue() {
158: return _Value.size();
159: }
160:
161: public int addValue(java.lang.String value) {
162: _Value.add(value);
163: int positionOfNewItem = _Value.size() - 1;
164: return positionOfNewItem;
165: }
166:
167: /**
168: * Search from the end looking for @param value, and then remove it.
169: */
170: public int removeValue(java.lang.String value) {
171: int pos = _Value.indexOf(value);
172: if (pos >= 0) {
173: _Value.remove(pos);
174: }
175: return pos;
176: }
177:
178: // This attribute is optional
179: public void setReadOnly(java.lang.String value) {
180: _ReadOnly = value;
181: }
182:
183: public java.lang.String getReadOnly() {
184: return _ReadOnly;
185: }
186:
187: public void writeNode(java.io.Writer out)
188: throws java.io.IOException {
189: String myName;
190: myName = "preferenceType";
191: writeNode(out, myName, ""); // NOI18N
192: }
193:
194: public void writeNode(java.io.Writer out, String nodeName,
195: String indent) throws java.io.IOException {
196: writeNode(out, nodeName, null, indent, new java.util.HashMap());
197: }
198:
199: /**
200: * It's not recommended to call this method directly.
201: */
202: public void writeNode(java.io.Writer out, String nodeName,
203: String namespace, String indent, java.util.Map namespaceMap)
204: throws java.io.IOException {
205: out.write(indent);
206: out.write("<");
207: if (namespace != null) {
208: out.write((String) namespaceMap.get(namespace));
209: out.write(":");
210: }
211: out.write(nodeName);
212: // id is an attribute with namespace http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd
213: if (_Id != null) {
214: out.write(" id='");
215: org.netbeans.modules.visualweb.api.portlet.dd.PortletApp
216: .writeXML(out, _Id, true);
217: out.write("'"); // NOI18N
218: }
219: out.write(">\n");
220: String nextIndent = indent + " ";
221: if (_Name != null) {
222: out.write(nextIndent);
223: out.write("<name"); // NOI18N
224: out.write(">"); // NOI18N
225: org.netbeans.modules.visualweb.api.portlet.dd.PortletApp
226: .writeXML(out, _Name, false);
227: out.write("</name>\n"); // NOI18N
228: }
229: for (java.util.Iterator it = _Value.iterator(); it.hasNext();) {
230: java.lang.String element = (java.lang.String) it.next();
231: if (element != null) {
232: out.write(nextIndent);
233: out.write("<value"); // NOI18N
234: out.write(">"); // NOI18N
235: org.netbeans.modules.visualweb.api.portlet.dd.PortletApp
236: .writeXML(out, element, false);
237: out.write("</value>\n"); // NOI18N
238: }
239: }
240: if (_ReadOnly != null) {
241: out.write(nextIndent);
242: out.write("<read-only"); // NOI18N
243: out.write(">"); // NOI18N
244: org.netbeans.modules.visualweb.api.portlet.dd.PortletApp
245: .writeXML(out, _ReadOnly, false);
246: out.write("</read-only>\n"); // NOI18N
247: }
248: out.write(indent);
249: out.write("</");
250: if (namespace != null) {
251: out.write((String) namespaceMap.get(namespace));
252: out.write(":");
253: }
254: out.write(nodeName);
255: out.write(">\n");
256: }
257:
258: public void readNode(org.w3c.dom.Node node) {
259: readNode(node, new java.util.HashMap());
260: }
261:
262: public void readNode(org.w3c.dom.Node node,
263: java.util.Map namespacePrefixes) {
264: if (node.hasAttributes()) {
265: org.w3c.dom.NamedNodeMap attrs = node.getAttributes();
266: org.w3c.dom.Attr attr;
267: java.lang.String attrValue;
268: boolean firstNamespaceDef = true;
269: for (int attrNum = 0; attrNum < attrs.getLength(); ++attrNum) {
270: attr = (org.w3c.dom.Attr) attrs.item(attrNum);
271: String attrName = attr.getName();
272: if (attrName.startsWith("xmlns:")) {
273: if (firstNamespaceDef) {
274: firstNamespaceDef = false;
275: // Dup prefix map, so as to not write over previous values, and to make it easy to clear out our entries.
276: namespacePrefixes = new java.util.HashMap(
277: namespacePrefixes);
278: }
279: String attrNSPrefix = attrName.substring(6,
280: attrName.length());
281: namespacePrefixes
282: .put(attrNSPrefix, attr.getValue());
283: }
284: }
285: attr = (org.w3c.dom.Attr) attrs.getNamedItem("id");
286: if (attr != null) {
287: attrValue = attr.getValue();
288: _Id = attrValue;
289: }
290: }
291: org.w3c.dom.NodeList children = node.getChildNodes();
292: for (int i = 0, size = children.getLength(); i < size; ++i) {
293: org.w3c.dom.Node childNode = children.item(i);
294: String childNodeName = (childNode.getLocalName() == null ? childNode
295: .getNodeName().intern()
296: : childNode.getLocalName().intern());
297: String childNodeValue = "";
298: if (childNode.getFirstChild() != null) {
299: childNodeValue = childNode.getFirstChild()
300: .getNodeValue();
301: }
302: if (childNodeName == "name") {
303: _Name = childNodeValue;
304: } else if (childNodeName == "value") {
305: java.lang.String aValue;
306: aValue = childNodeValue;
307: _Value.add(aValue);
308: } else if (childNodeName == "read-only") {
309: _ReadOnly = childNodeValue;
310: } else {
311: // Found extra unrecognized childNode
312: }
313: }
314: }
315:
316: public void validate()
317: throws org.netbeans.modules.visualweb.api.portlet.dd.PortletApp.ValidateException {
318: boolean restrictionFailure = false;
319: boolean restrictionPassed = false;
320: // Validating property id
321: // Validating property name
322: if (getName() == null) {
323: throw new org.netbeans.modules.visualweb.api.portlet.dd.PortletApp.ValidateException(
324: "getName() == null",
325: org.netbeans.modules.visualweb.api.portlet.dd.PortletApp.ValidateException.FailureType.NULL_VALUE,
326: "name", this ); // NOI18N
327: }
328: // Validating property value
329: // Validating property readOnly
330: if (getReadOnly() != null) {
331: final java.lang.String[] enumRestrictionReadOnly = {
332: "true", "false" };
333: restrictionFailure = true;
334: for (int _index2 = 0; _index2 < enumRestrictionReadOnly.length; ++_index2) {
335: if (enumRestrictionReadOnly[_index2]
336: .equals(getReadOnly())) {
337: restrictionFailure = false;
338: break;
339: }
340: }
341: if (restrictionFailure) {
342: throw new org.netbeans.modules.visualweb.api.portlet.dd.PortletApp.ValidateException(
343: "getReadOnly() enumeration test",
344: org.netbeans.modules.visualweb.api.portlet.dd.PortletApp.ValidateException.FailureType.ENUM_RESTRICTION,
345: "readOnly", this ); // NOI18N
346: }
347: }
348: }
349:
350: public void changePropertyByName(String name, Object value) {
351: if (name == null)
352: return;
353: name = name.intern();
354: if (name == "id")
355: setId((java.lang.String) value);
356: else if (name == "name")
357: setName((java.lang.String) value);
358: else if (name == "value")
359: addValue((java.lang.String) value);
360: else if (name == "value[]")
361: setValue((java.lang.String[]) value);
362: else if (name == "readOnly")
363: setReadOnly((java.lang.String) value);
364: else
365: throw new IllegalArgumentException(
366: name
367: + " is not a valid property name for PreferenceType");
368: }
369:
370: public Object fetchPropertyByName(String name) {
371: if (name == "id")
372: return getId();
373: if (name == "name")
374: return getName();
375: if (name == "value[]")
376: return getValue();
377: if (name == "readOnly")
378: return getReadOnly();
379: throw new IllegalArgumentException(name
380: + " is not a valid property name for PreferenceType");
381: }
382:
383: public String nameSelf() {
384: return "PreferenceType";
385: }
386:
387: public String nameChild(Object childObj) {
388: return nameChild(childObj, false, false);
389: }
390:
391: /**
392: * @param childObj The child object to search for
393: * @param returnSchemaName Whether or not the schema name should be returned or the property name
394: * @return null if not found
395: */
396: public String nameChild(Object childObj, boolean returnConstName,
397: boolean returnSchemaName) {
398: return nameChild(childObj, returnConstName, returnSchemaName,
399: false);
400: }
401:
402: /**
403: * @param childObj The child object to search for
404: * @param returnSchemaName Whether or not the schema name should be returned or the property name
405: * @return null if not found
406: */
407: public String nameChild(Object childObj, boolean returnConstName,
408: boolean returnSchemaName, boolean returnXPathName) {
409: if (childObj instanceof java.lang.String) {
410: java.lang.String child = (java.lang.String) childObj;
411: if (child == _Id) {
412: if (returnConstName) {
413: return ID;
414: } else if (returnSchemaName) {
415: return "id";
416: } else if (returnXPathName) {
417: return "@id";
418: } else {
419: return "Id";
420: }
421: }
422: if (child == _Name) {
423: if (returnConstName) {
424: return NAME;
425: } else if (returnSchemaName) {
426: return "name";
427: } else if (returnXPathName) {
428: return "name";
429: } else {
430: return "Name";
431: }
432: }
433: int index = 0;
434: for (java.util.Iterator it = _Value.iterator(); it
435: .hasNext();) {
436: java.lang.String element = (java.lang.String) it.next();
437: if (child == element) {
438: if (returnConstName) {
439: return VALUE;
440: } else if (returnSchemaName) {
441: return "value";
442: } else if (returnXPathName) {
443: return "value[position()=" + index + "]";
444: } else {
445: return "Value." + Integer.toHexString(index);
446: }
447: }
448: ++index;
449: }
450: if (child == _ReadOnly) {
451: if (returnConstName) {
452: return READ_ONLY;
453: } else if (returnSchemaName) {
454: return "read-only";
455: } else if (returnXPathName) {
456: return "read-only";
457: } else {
458: return "ReadOnly";
459: }
460: }
461: }
462: return null;
463: }
464:
465: /**
466: * Return an array of all of the properties that are beans and are set.
467: */
468: public org.netbeans.modules.visualweb.api.portlet.dd.CommonBean[] childBeans(
469: boolean recursive) {
470: java.util.List children = new java.util.LinkedList();
471: childBeans(recursive, children);
472: org.netbeans.modules.visualweb.api.portlet.dd.CommonBean[] result = new org.netbeans.modules.visualweb.api.portlet.dd.CommonBean[children
473: .size()];
474: return (org.netbeans.modules.visualweb.api.portlet.dd.CommonBean[]) children
475: .toArray(result);
476: }
477:
478: /**
479: * Put all child beans into the beans list.
480: */
481: public void childBeans(boolean recursive, java.util.List beans) {
482: }
483:
484: public boolean equals(Object o) {
485: return o instanceof org.netbeans.modules.visualweb.api.portlet.dd.PreferenceType
486: && equals((org.netbeans.modules.visualweb.api.portlet.dd.PreferenceType) o);
487: }
488:
489: public boolean equals(
490: org.netbeans.modules.visualweb.api.portlet.dd.PreferenceType inst) {
491: if (inst == this ) {
492: return true;
493: }
494: if (inst == null) {
495: return false;
496: }
497: if (!(_Id == null ? inst._Id == null : _Id.equals(inst._Id))) {
498: return false;
499: }
500: if (!(_Name == null ? inst._Name == null : _Name
501: .equals(inst._Name))) {
502: return false;
503: }
504: if (sizeValue() != inst.sizeValue())
505: return false;
506: // Compare every element.
507: for (java.util.Iterator it = _Value.iterator(), it2 = inst._Value
508: .iterator(); it.hasNext() && it2.hasNext();) {
509: java.lang.String element = (java.lang.String) it.next();
510: java.lang.String element2 = (java.lang.String) it2.next();
511: if (!(element == null ? element2 == null : element
512: .equals(element2))) {
513: return false;
514: }
515: }
516: if (!(_ReadOnly == null ? inst._ReadOnly == null : _ReadOnly
517: .equals(inst._ReadOnly))) {
518: return false;
519: }
520: return true;
521: }
522:
523: public int hashCode() {
524: int result = 17;
525: result = 37 * result + (_Id == null ? 0 : _Id.hashCode());
526: result = 37 * result + (_Name == null ? 0 : _Name.hashCode());
527: result = 37 * result + (_Value == null ? 0 : _Value.hashCode());
528: result = 37 * result
529: + (_ReadOnly == null ? 0 : _ReadOnly.hashCode());
530: return result;
531: }
532:
533: public String toString() {
534: java.io.StringWriter sw = new java.io.StringWriter();
535: try {
536: writeNode(sw);
537: } catch (java.io.IOException e) {
538: // How can we actually get an IOException on a StringWriter?
539: throw new RuntimeException(e);
540: }
541: return sw.toString();
542: }
543:
544: }
|