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 SupportsType
043: * matches the schema element 'supportsType'.
044: * The root bean class is PortletApp
045: *
046: * ===============================================================
047: *
048: * Supports indicates the portlet modes a
049: * portlet supports for a specific content type. All portlets must
050: * support the view mode.
051: * Used in: portlet
052: *
053: * ===============================================================
054: * Generated on Tue Apr 26 19:08:25 MDT 2005
055: * @Generated
056: */package org.netbeans.modules.visualweb.api.portlet.dd;
057:
058: public class SupportsType
059: implements
060: org.netbeans.modules.visualweb.api.portlet.dd.SupportsTypeInterface,
061: org.netbeans.modules.visualweb.api.portlet.dd.CommonBean {
062: public static final String ID = "Id"; // NOI18N
063: public static final String MIME_TYPE = "MimeType"; // NOI18N
064: public static final String PORTLET_MODE = "PortletMode"; // NOI18N
065:
066: private java.lang.String _Id;
067: private java.lang.String _MimeType;
068: private java.util.List _PortletMode = new java.util.ArrayList(); // List<java.lang.String>
069:
070: /**
071: * Normal starting point constructor.
072: */
073: public SupportsType() {
074: _MimeType = "";
075: }
076:
077: /**
078: * Required parameters constructor
079: */
080: public SupportsType(java.lang.String mimeType) {
081: _MimeType = mimeType;
082: }
083:
084: /**
085: * Deep copy
086: */
087: public SupportsType(
088: org.netbeans.modules.visualweb.api.portlet.dd.SupportsType source) {
089: this (source, false);
090: }
091:
092: /**
093: * Deep copy
094: * @param justData just copy the XML relevant data
095: */
096: public SupportsType(
097: org.netbeans.modules.visualweb.api.portlet.dd.SupportsType source,
098: boolean justData) {
099: _Id = source._Id;
100: _MimeType = source._MimeType;
101: for (java.util.Iterator it = source._PortletMode.iterator(); it
102: .hasNext();) {
103: java.lang.String srcElement = (java.lang.String) it.next();
104: _PortletMode.add(srcElement);
105: }
106: }
107:
108: // This attribute is optional
109: public void setId(java.lang.String value) {
110: _Id = value;
111: }
112:
113: public java.lang.String getId() {
114: return _Id;
115: }
116:
117: // This attribute is mandatory
118: public void setMimeType(java.lang.String value) {
119: _MimeType = value;
120: }
121:
122: public java.lang.String getMimeType() {
123: return _MimeType;
124: }
125:
126: // This attribute is an array, possibly empty
127: public void setPortletMode(java.lang.String[] value) {
128: if (value == null)
129: value = new java.lang.String[0];
130: _PortletMode.clear();
131: ((java.util.ArrayList) _PortletMode)
132: .ensureCapacity(value.length);
133: for (int i = 0; i < value.length; ++i) {
134: _PortletMode.add(value[i]);
135: }
136: }
137:
138: public void setPortletMode(int index, java.lang.String value) {
139: _PortletMode.set(index, value);
140: }
141:
142: public java.lang.String[] getPortletMode() {
143: java.lang.String[] arr = new java.lang.String[_PortletMode
144: .size()];
145: return (java.lang.String[]) _PortletMode.toArray(arr);
146: }
147:
148: public java.util.List fetchPortletModeList() {
149: return _PortletMode;
150: }
151:
152: public java.lang.String getPortletMode(int index) {
153: return (java.lang.String) _PortletMode.get(index);
154: }
155:
156: // Return the number of portletMode
157: public int sizePortletMode() {
158: return _PortletMode.size();
159: }
160:
161: public int addPortletMode(java.lang.String value) {
162: _PortletMode.add(value);
163: int positionOfNewItem = _PortletMode.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 removePortletMode(java.lang.String value) {
171: int pos = _PortletMode.indexOf(value);
172: if (pos >= 0) {
173: _PortletMode.remove(pos);
174: }
175: return pos;
176: }
177:
178: public void writeNode(java.io.Writer out)
179: throws java.io.IOException {
180: String myName;
181: myName = "supportsType";
182: writeNode(out, myName, ""); // NOI18N
183: }
184:
185: public void writeNode(java.io.Writer out, String nodeName,
186: String indent) throws java.io.IOException {
187: writeNode(out, nodeName, null, indent, new java.util.HashMap());
188: }
189:
190: /**
191: * It's not recommended to call this method directly.
192: */
193: public void writeNode(java.io.Writer out, String nodeName,
194: String namespace, String indent, java.util.Map namespaceMap)
195: throws java.io.IOException {
196: out.write(indent);
197: out.write("<");
198: if (namespace != null) {
199: out.write((String) namespaceMap.get(namespace));
200: out.write(":");
201: }
202: out.write(nodeName);
203: // id is an attribute with namespace http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd
204: if (_Id != null) {
205: out.write(" id='");
206: org.netbeans.modules.visualweb.api.portlet.dd.PortletApp
207: .writeXML(out, _Id, true);
208: out.write("'"); // NOI18N
209: }
210: out.write(">\n");
211: String nextIndent = indent + " ";
212: if (_MimeType != null) {
213: out.write(nextIndent);
214: out.write("<mime-type"); // NOI18N
215: out.write(">"); // NOI18N
216: org.netbeans.modules.visualweb.api.portlet.dd.PortletApp
217: .writeXML(out, _MimeType, false);
218: out.write("</mime-type>\n"); // NOI18N
219: }
220: for (java.util.Iterator it = _PortletMode.iterator(); it
221: .hasNext();) {
222: java.lang.String element = (java.lang.String) it.next();
223: if (element != null) {
224: out.write(nextIndent);
225: out.write("<portlet-mode"); // NOI18N
226: out.write(">"); // NOI18N
227: org.netbeans.modules.visualweb.api.portlet.dd.PortletApp
228: .writeXML(out, element, false);
229: out.write("</portlet-mode>\n"); // NOI18N
230: }
231: }
232: out.write(indent);
233: out.write("</");
234: if (namespace != null) {
235: out.write((String) namespaceMap.get(namespace));
236: out.write(":");
237: }
238: out.write(nodeName);
239: out.write(">\n");
240: }
241:
242: public void readNode(org.w3c.dom.Node node) {
243: readNode(node, new java.util.HashMap());
244: }
245:
246: public void readNode(org.w3c.dom.Node node,
247: java.util.Map namespacePrefixes) {
248: if (node.hasAttributes()) {
249: org.w3c.dom.NamedNodeMap attrs = node.getAttributes();
250: org.w3c.dom.Attr attr;
251: java.lang.String attrValue;
252: boolean firstNamespaceDef = true;
253: for (int attrNum = 0; attrNum < attrs.getLength(); ++attrNum) {
254: attr = (org.w3c.dom.Attr) attrs.item(attrNum);
255: String attrName = attr.getName();
256: if (attrName.startsWith("xmlns:")) {
257: if (firstNamespaceDef) {
258: firstNamespaceDef = false;
259: // Dup prefix map, so as to not write over previous values, and to make it easy to clear out our entries.
260: namespacePrefixes = new java.util.HashMap(
261: namespacePrefixes);
262: }
263: String attrNSPrefix = attrName.substring(6,
264: attrName.length());
265: namespacePrefixes
266: .put(attrNSPrefix, attr.getValue());
267: }
268: }
269: attr = (org.w3c.dom.Attr) attrs.getNamedItem("id");
270: if (attr != null) {
271: attrValue = attr.getValue();
272: _Id = attrValue;
273: }
274: }
275: org.w3c.dom.NodeList children = node.getChildNodes();
276: for (int i = 0, size = children.getLength(); i < size; ++i) {
277: org.w3c.dom.Node childNode = children.item(i);
278: String childNodeName = (childNode.getLocalName() == null ? childNode
279: .getNodeName().intern()
280: : childNode.getLocalName().intern());
281: String childNodeValue = "";
282: if (childNode.getFirstChild() != null) {
283: childNodeValue = childNode.getFirstChild()
284: .getNodeValue();
285: }
286: if (childNodeName == "mime-type") {
287: _MimeType = childNodeValue;
288: } else if (childNodeName == "portlet-mode") {
289: java.lang.String aPortletMode;
290: aPortletMode = childNodeValue;
291: _PortletMode.add(aPortletMode);
292: } else {
293: // Found extra unrecognized childNode
294: }
295: }
296: }
297:
298: public void validate()
299: throws org.netbeans.modules.visualweb.api.portlet.dd.PortletApp.ValidateException {
300: boolean restrictionFailure = false;
301: boolean restrictionPassed = false;
302: // Validating property id
303: // Validating property mimeType
304: if (getMimeType() == null) {
305: throw new org.netbeans.modules.visualweb.api.portlet.dd.PortletApp.ValidateException(
306: "getMimeType() == null",
307: org.netbeans.modules.visualweb.api.portlet.dd.PortletApp.ValidateException.FailureType.NULL_VALUE,
308: "mimeType", this ); // NOI18N
309: }
310: // Validating property portletMode
311: }
312:
313: public void changePropertyByName(String name, Object value) {
314: if (name == null)
315: return;
316: name = name.intern();
317: if (name == "id")
318: setId((java.lang.String) value);
319: else if (name == "mimeType")
320: setMimeType((java.lang.String) value);
321: else if (name == "portletMode")
322: addPortletMode((java.lang.String) value);
323: else if (name == "portletMode[]")
324: setPortletMode((java.lang.String[]) value);
325: else
326: throw new IllegalArgumentException(name
327: + " is not a valid property name for SupportsType");
328: }
329:
330: public Object fetchPropertyByName(String name) {
331: if (name == "id")
332: return getId();
333: if (name == "mimeType")
334: return getMimeType();
335: if (name == "portletMode[]")
336: return getPortletMode();
337: throw new IllegalArgumentException(name
338: + " is not a valid property name for SupportsType");
339: }
340:
341: public String nameSelf() {
342: return "SupportsType";
343: }
344:
345: public String nameChild(Object childObj) {
346: return nameChild(childObj, false, false);
347: }
348:
349: /**
350: * @param childObj The child object to search for
351: * @param returnSchemaName Whether or not the schema name should be returned or the property name
352: * @return null if not found
353: */
354: public String nameChild(Object childObj, boolean returnConstName,
355: boolean returnSchemaName) {
356: return nameChild(childObj, returnConstName, returnSchemaName,
357: false);
358: }
359:
360: /**
361: * @param childObj The child object to search for
362: * @param returnSchemaName Whether or not the schema name should be returned or the property name
363: * @return null if not found
364: */
365: public String nameChild(Object childObj, boolean returnConstName,
366: boolean returnSchemaName, boolean returnXPathName) {
367: if (childObj instanceof java.lang.String) {
368: java.lang.String child = (java.lang.String) childObj;
369: if (child == _Id) {
370: if (returnConstName) {
371: return ID;
372: } else if (returnSchemaName) {
373: return "id";
374: } else if (returnXPathName) {
375: return "@id";
376: } else {
377: return "Id";
378: }
379: }
380: if (child == _MimeType) {
381: if (returnConstName) {
382: return MIME_TYPE;
383: } else if (returnSchemaName) {
384: return "mime-type";
385: } else if (returnXPathName) {
386: return "mime-type";
387: } else {
388: return "MimeType";
389: }
390: }
391: int index = 0;
392: for (java.util.Iterator it = _PortletMode.iterator(); it
393: .hasNext();) {
394: java.lang.String element = (java.lang.String) it.next();
395: if (child == element) {
396: if (returnConstName) {
397: return PORTLET_MODE;
398: } else if (returnSchemaName) {
399: return "portlet-mode";
400: } else if (returnXPathName) {
401: return "portlet-mode[position()=" + index + "]";
402: } else {
403: return "PortletMode."
404: + Integer.toHexString(index);
405: }
406: }
407: ++index;
408: }
409: }
410: return null;
411: }
412:
413: /**
414: * Return an array of all of the properties that are beans and are set.
415: */
416: public org.netbeans.modules.visualweb.api.portlet.dd.CommonBean[] childBeans(
417: boolean recursive) {
418: java.util.List children = new java.util.LinkedList();
419: childBeans(recursive, children);
420: org.netbeans.modules.visualweb.api.portlet.dd.CommonBean[] result = new org.netbeans.modules.visualweb.api.portlet.dd.CommonBean[children
421: .size()];
422: return (org.netbeans.modules.visualweb.api.portlet.dd.CommonBean[]) children
423: .toArray(result);
424: }
425:
426: /**
427: * Put all child beans into the beans list.
428: */
429: public void childBeans(boolean recursive, java.util.List beans) {
430: }
431:
432: public boolean equals(Object o) {
433: return o instanceof org.netbeans.modules.visualweb.api.portlet.dd.SupportsType
434: && equals((org.netbeans.modules.visualweb.api.portlet.dd.SupportsType) o);
435: }
436:
437: public boolean equals(
438: org.netbeans.modules.visualweb.api.portlet.dd.SupportsType inst) {
439: if (inst == this ) {
440: return true;
441: }
442: if (inst == null) {
443: return false;
444: }
445: if (!(_Id == null ? inst._Id == null : _Id.equals(inst._Id))) {
446: return false;
447: }
448: if (!(_MimeType == null ? inst._MimeType == null : _MimeType
449: .equals(inst._MimeType))) {
450: return false;
451: }
452: if (sizePortletMode() != inst.sizePortletMode())
453: return false;
454: // Compare every element.
455: for (java.util.Iterator it = _PortletMode.iterator(), it2 = inst._PortletMode
456: .iterator(); it.hasNext() && it2.hasNext();) {
457: java.lang.String element = (java.lang.String) it.next();
458: java.lang.String element2 = (java.lang.String) it2.next();
459: if (!(element == null ? element2 == null : element
460: .equals(element2))) {
461: return false;
462: }
463: }
464: return true;
465: }
466:
467: public int hashCode() {
468: int result = 17;
469: result = 37 * result + (_Id == null ? 0 : _Id.hashCode());
470: result = 37 * result
471: + (_MimeType == null ? 0 : _MimeType.hashCode());
472: result = 37 * result
473: + (_PortletMode == null ? 0 : _PortletMode.hashCode());
474: return result;
475: }
476:
477: public String toString() {
478: java.io.StringWriter sw = new java.io.StringWriter();
479: try {
480: writeNode(sw);
481: } catch (java.io.IOException e) {
482: // How can we actually get an IOException on a StringWriter?
483: throw new RuntimeException(e);
484: }
485: return sw.toString();
486: }
487:
488: }
|