KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > ui > api > property > ExtensibilityElementPropertyAdapter


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.xml.wsdl.ui.api.property;
21
22 import org.netbeans.modules.xml.wsdl.model.ExtensibilityElement;
23 import org.netbeans.modules.xml.wsdl.ui.netbeans.module.Utility;
24 import org.netbeans.modules.xml.wsdl.ui.view.property.XSDBooleanAttributeProperty;
25 import org.openide.util.NbBundle;
26
27 public class ExtensibilityElementPropertyAdapter extends PropertyAdapter {
28     private ExtensibilityElement element;
29     private String JavaDoc attributeName;
30     private String JavaDoc defaultValue;
31     private boolean supportsDefaultValue;
32     private String JavaDoc valueNotSetMessage = NbBundle.getMessage(XSDBooleanAttributeProperty.class, "LBL_ValueNotSet");
33     private boolean isOptional;
34     
35     public ExtensibilityElementPropertyAdapter(ExtensibilityElement element, String JavaDoc name, boolean isOptional) {
36         super(element);
37         this.element = element;
38         this.attributeName = name;
39         this.isOptional = isOptional;
40     }
41     
42     public ExtensibilityElementPropertyAdapter(ExtensibilityElement element, String JavaDoc name) {
43         this(element, name, false);
44     }
45     
46     public ExtensibilityElementPropertyAdapter(ExtensibilityElement element, String JavaDoc name, String JavaDoc defaultValue) {
47         this(element, name, false);
48         this.defaultValue = defaultValue;
49         this.supportsDefaultValue = true;
50     }
51     
52     /*
53      * this is the default implementation, subclasses can override this.
54      * @return value
55      */

56     public String JavaDoc getValue() {
57         String JavaDoc value = element.getAttribute(attributeName);
58         if (value == null) {
59             value = supportsDefaultValue ? defaultValue : "";
60         }
61         return value;
62     }
63     
64     /*
65      * this is the default implementation, subclasses can override this.
66      * @param value the value to be set
67      */

68     public void setValue(String JavaDoc value) {
69         boolean inTransaction = Utility.startTransaction(element.getModel());
70         if (value == null || value.trim().length() == 0 || value.equalsIgnoreCase(valueNotSetMessage)) {
71             value = supportsDefaultValue ? defaultValue : null;
72         }
73         element.setAttribute(attributeName, value);
74         Utility.endTransaction(element.getModel(), inTransaction);
75     }
76     
77     /*
78      * generic setValue. if overridden, also override getValue
79      *
80      * @param val
81      */

82     public void setValue(Object JavaDoc val) {
83         
84     }
85     
86     public ExtensibilityElement getExtensibilityElement() {
87         return element;
88     }
89     
90     
91     public String JavaDoc getDefaultValue() {
92         if (defaultValue == null) {
93             return valueNotSetMessage;
94         }
95         return defaultValue;
96     }
97     
98     public boolean supportsDefaultValue() {
99         return supportsDefaultValue || isOptional;
100     }
101     
102     public void setOptional(boolean bool) {
103         isOptional = bool;
104     }
105     
106     public boolean isOptional() {
107         return isOptional;
108     }
109     
110     public String JavaDoc getMessageForUnSet() {
111         return valueNotSetMessage;
112     }
113     
114 }
115
Popular Tags