001: /*
002: * soapUI, copyright (C) 2004-2007 eviware.com
003: *
004: * soapUI is free software; you can redistribute it and/or modify it under the
005: * terms of version 2.1 of the GNU Lesser General Public License as published by
006: * the Free Software Foundation.
007: *
008: * soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
009: * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
010: * See the GNU Lesser General Public License for more details at gnu.org.
011: */
012:
013: package com.eviware.soapui.impl.wsdl;
014:
015: import java.util.Collection;
016:
017: import javax.swing.ImageIcon;
018:
019: import com.eviware.soapui.SoapUI;
020: import com.eviware.soapui.config.ModelItemConfig;
021: import com.eviware.soapui.impl.settings.XmlBeansSettingsImpl;
022: import com.eviware.soapui.model.ModelItem;
023: import com.eviware.soapui.model.settings.Settings;
024: import com.eviware.soapui.model.support.AbstractModelItem;
025: import com.eviware.soapui.support.UISupport;
026:
027: /**
028: * Abstract base class for WSDL-implementation classes
029: *
030: * @author Ole.Matzura
031: */
032:
033: public abstract class AbstractWsdlModelItem<T extends ModelItemConfig>
034: extends AbstractModelItem {
035: private XmlBeansSettingsImpl settings;
036: private T config;
037: private ImageIcon icon;
038: private final ModelItem parent;
039:
040: protected AbstractWsdlModelItem(T config, ModelItem parent,
041: String icon) {
042: this .parent = parent;
043: if (config != null)
044: setConfig(config);
045:
046: if (icon != null)
047: this .icon = UISupport.createImageIcon(icon);
048: }
049:
050: public ModelItem getParent() {
051: return parent;
052: }
053:
054: public ImageIcon getIcon() {
055: return icon;
056: }
057:
058: public void setIcon(ImageIcon icon) {
059: if (icon == this .icon)
060: return;
061:
062: ImageIcon oldIcon = this .icon;
063: this .icon = icon;
064: notifyPropertyChanged(ICON_PROPERTY, oldIcon, icon);
065: }
066:
067: public String getDescription() {
068: String description = config.getDescription();
069: return description == null || description.trim().length() == 0 ? null
070: : description;
071: }
072:
073: public void setDescription(String description) {
074: String old = getDescription();
075: config.setDescription(description);
076: notifyPropertyChanged(DESCRIPTION_PROPERTY, old, description);
077: }
078:
079: public String getName() {
080: return config.getName();
081: }
082:
083: public void setName(String name) {
084: String old = getName();
085: config.setName(name);
086: notifyPropertyChanged(NAME_PROPERTY, old, name);
087: }
088:
089: public Settings getSettings() {
090: return settings;
091: }
092:
093: final public T getConfig() {
094: return config;
095: }
096:
097: final public void setConfig(T config) {
098: this .config = config;
099:
100: if (settings != null)
101: settings.release();
102:
103: if (!config.isSetSettings())
104: config.addNewSettings();
105:
106: settings = new XmlBeansSettingsImpl(this ,
107: parent == null ? SoapUI.getSettings() : parent
108: .getSettings(), this .config.getSettings());
109: }
110:
111: protected void setSettings(XmlBeansSettingsImpl settings) {
112: if (this .settings != null)
113: this .settings.release();
114:
115: this .settings = settings;
116: }
117:
118: public AbstractWsdlModelItem getWsdlModelItemByName(
119: Collection<? extends AbstractWsdlModelItem> items,
120: String name) {
121: for (AbstractWsdlModelItem item : items) {
122: if (item.getName().equals(name))
123: return item;
124: }
125:
126: return null;
127:
128: }
129:
130: public void release() {
131: if (settings != null) {
132: settings.release();
133: }
134: }
135:
136: public void onSave() {
137: }
138: }
|