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-2006 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: /**
043: * Superclass that implements DescriptionInterface for Servlet2.4 beans.
044: *
045: * @author Milan Kuchtiak
046: */package org.netbeans.modules.j2ee.dd.impl.commonws;
047:
048: import org.netbeans.modules.schema2beans.Version;
049: import org.netbeans.modules.j2ee.dd.api.common.*;
050: import org.openide.ErrorManager;
051:
052: public abstract class DescriptionBeanMultiple extends EnclosingBean
053: implements DescriptionInterface {
054:
055: public DescriptionBeanMultiple(java.util.Vector comps,
056: Version version) {
057: super (comps, version);
058: }
059:
060: // methods implemented by specific s2b beans
061: public void setDescription(int index, java.lang.String value) {
062: }
063:
064: public String getDescription(int index) {
065: return null;
066: }
067:
068: public void setDescription(java.lang.String[] value) {
069: }
070:
071: //public abstract java.lang.String[] getDescription();
072: public int sizeDescription() {
073: return 0;
074: }
075:
076: public int addDescription(java.lang.String value) {
077: return 0;
078: }
079:
080: //public abstract int removeDescription(java.lang.String value);
081: public void setDescriptionXmlLang(int index, java.lang.String value) {
082: }
083:
084: public String getDescriptionXmlLang(int index) {
085: return null;
086: }
087:
088: public void setDescription(String locale, String description)
089: throws VersionNotSupportedException {
090: if (description == null)
091: removeDescriptionForLocale(locale);
092: else {
093: int size = sizeDescription();
094: boolean found = false;
095: for (int i = 0; i < size; i++) {
096: String loc = getDescriptionXmlLang(i);
097: if ((locale == null && loc == null)
098: || (locale != null && locale
099: .equalsIgnoreCase(loc))) {
100: found = true;
101: setDescription(i, description);
102: break;
103: }
104: }
105: if (!found) {
106: addDescription(description);
107: if (locale != null)
108: setDescriptionXmlLang(size, locale.toLowerCase());
109: }
110: }
111: }
112:
113: public void setDescription(String description) {
114: try {
115: setDescription(null, description);
116: } catch (VersionNotSupportedException ex) {
117: ErrorManager.getDefault().notify(ex);
118: }
119: }
120:
121: public void setAllDescriptions(java.util.Map descriptions)
122: throws VersionNotSupportedException {
123: removeAllDescriptions();
124: if (descriptions != null) {
125: java.util.Iterator keys = descriptions.keySet().iterator();
126: int i = 0;
127: while (keys.hasNext()) {
128: String key = (String) keys.next();
129: addDescription((String) descriptions.get(key));
130: setDescriptionXmlLang(i++, key);
131: }
132: }
133: }
134:
135: public String getDescription(String locale)
136: throws VersionNotSupportedException {
137: for (int i = 0; i < sizeDescription(); i++) {
138: String loc = getDescriptionXmlLang(i);
139: if ((locale == null && loc == null)
140: || (locale != null && locale.equalsIgnoreCase(loc))) {
141: return getDescription(i);
142: }
143: }
144: return null;
145: }
146:
147: public String getDefaultDescription() {
148: try {
149: return getDescription(null);
150: } catch (VersionNotSupportedException ex) {
151: return null;
152: }
153: }
154:
155: public java.util.Map getAllDescriptions() {
156: java.util.Map map = new java.util.HashMap();
157: for (int i = 0; i < sizeDescription(); i++) {
158: String desc = getDescription(i);
159: String loc = getDescriptionXmlLang(i);
160: map.put(loc, desc);
161: }
162: return map;
163: }
164:
165: public void removeDescriptionForLocale(String locale)
166: throws VersionNotSupportedException {
167: java.util.Map map = new java.util.HashMap();
168: for (int i = 0; i < sizeDescription(); i++) {
169: String desc = getDescription(i);
170: String loc = getDescriptionXmlLang(i);
171: if ((locale == null && loc != null)
172: || (locale != null && !locale.equalsIgnoreCase(loc)))
173: map.put(loc, desc);
174: }
175: setAllDescriptions(map);
176: }
177:
178: public void removeDescription() {
179: try {
180: removeDescriptionForLocale(null);
181: } catch (VersionNotSupportedException ex) {
182: ErrorManager.getDefault().notify(ex);
183: }
184: }
185:
186: public void removeAllDescriptions() {
187: setDescription(new String[] {});
188: }
189: }
|