1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.wsdl;
14
15 import java.util.Collection;
16 import java.util.List;
17
18 import javax.swing.ImageIcon;
19
20 import com.eviware.soapui.SoapUI;
21 import com.eviware.soapui.config.ModelItemConfig;
22 import com.eviware.soapui.impl.settings.XmlBeansSettingsImpl;
23 import com.eviware.soapui.model.ModelItem;
24 import com.eviware.soapui.model.support.AbstractModelItem;
25 import com.eviware.soapui.model.support.ModelSupport;
26 import com.eviware.soapui.support.StringUtils;
27 import com.eviware.soapui.support.UISupport;
28 import com.eviware.soapui.support.resolver.ResolveContext;
29
30 /***
31 * Abstract base class for WSDL-implementation classes
32 *
33 * @author Ole.Matzura
34 */
35
36 public abstract class AbstractWsdlModelItem<T extends ModelItemConfig> extends AbstractModelItem
37 {
38 private XmlBeansSettingsImpl settings;
39 private T config;
40 private ImageIcon icon;
41 private final ModelItem parent;
42
43 protected AbstractWsdlModelItem( T config, ModelItem parent, String icon )
44 {
45 this.parent = parent;
46 if( config != null )
47 setConfig( config );
48
49 if( icon != null )
50 this.icon = UISupport.createImageIcon( icon );
51 }
52
53 public boolean dependsOn( ModelItem modelItem )
54 {
55 return ModelSupport.dependsOn( this, modelItem );
56 }
57
58 public ModelItem getParent()
59 {
60 return parent;
61 }
62
63 public ImageIcon getIcon()
64 {
65 return icon;
66 }
67
68 public void setIcon( ImageIcon icon )
69 {
70 if( icon == this.icon )
71 return;
72
73 ImageIcon oldIcon = this.icon;
74 this.icon = icon;
75 notifyPropertyChanged( ICON_PROPERTY, oldIcon, icon );
76 }
77
78 public String getDescription()
79 {
80 String description = config.getDescription();
81 return StringUtils.hasContent( description ) ? description : "";
82 }
83
84 public void setDescription( String description )
85 {
86 String old = getDescription();
87 config.setDescription( description );
88 notifyPropertyChanged( DESCRIPTION_PROPERTY, old, description );
89 }
90
91 public String getName()
92 {
93 return config.getName();
94 }
95
96 public void setName( String name )
97 {
98 String old = getName();
99 config.setName( name );
100 notifyPropertyChanged( NAME_PROPERTY, old, name );
101 }
102
103 public XmlBeansSettingsImpl getSettings()
104 {
105 return settings;
106 }
107
108 public T getConfig()
109 {
110 return config;
111 }
112
113 public void setConfig( T config )
114 {
115 this.config = config;
116
117 if( settings != null )
118 settings.release();
119
120 if( !config.isSetSettings() )
121 config.addNewSettings();
122
123 settings = new XmlBeansSettingsImpl( this, parent == null ? SoapUI.getSettings() : parent.getSettings(),
124 this.config.getSettings() );
125 }
126
127 public String getId()
128 {
129 if( !config.isSetId() )
130 config.setId( ModelSupport.generateModelItemID() );
131
132 return config.getId();
133 }
134
135 protected void setSettings( XmlBeansSettingsImpl settings )
136 {
137 if( this.settings != null )
138 this.settings.release();
139
140 this.settings = settings;
141 }
142
143 public AbstractWsdlModelItem<?> getWsdlModelItemByName( Collection<? extends AbstractWsdlModelItem<?>> items,
144 String name )
145 {
146 for( AbstractWsdlModelItem<?> item : items )
147 {
148 if( item.getName() != null && item.getName().equals( name ) )
149 return item;
150 }
151
152 return null;
153 }
154
155 public void release()
156 {
157 if( settings != null )
158 {
159 settings.release();
160 }
161 }
162
163 public void resolve( ResolveContext<?> context )
164 {
165 List<? extends ModelItem> children = getChildren();
166 if( children == null )
167 return;
168
169 for( ModelItem modelItem : children )
170 {
171 if( modelItem instanceof AbstractWsdlModelItem )
172 {
173 ( ( AbstractWsdlModelItem<?> )modelItem ).resolve( context );
174 }
175 }
176 }
177
178 public void beforeSave()
179 {
180 List<? extends ModelItem> children = getChildren();
181 if( children == null )
182 return;
183
184 for( ModelItem modelItem : children )
185 {
186 if( modelItem instanceof AbstractWsdlModelItem )
187 {
188 ( ( AbstractWsdlModelItem<?> )modelItem ).beforeSave();
189 }
190 }
191 }
192
193 public void afterLoad()
194 {
195 List<? extends ModelItem> children = getChildren();
196 if( children == null )
197 return;
198
199 for( ModelItem modelItem : children )
200 {
201 if( modelItem instanceof AbstractWsdlModelItem )
202 {
203 ( ( AbstractWsdlModelItem<?> )modelItem ).afterLoad();
204 }
205 }
206 }
207 }