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.AbstractAnimatableModelItem;
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
37 AbstractAnimatableModelItem<ModelItemConfig>
38 {
39 private XmlBeansSettingsImpl settings;
40 private T config;
41 private ImageIcon icon;
42 private final ModelItem parent;
43
44 protected AbstractWsdlModelItem( T config, ModelItem parent, String icon )
45 {
46 this.parent = parent;
47 if( config != null )
48 setConfig( config );
49
50 if( icon != null )
51 this.icon = UISupport.createImageIcon( icon );
52 }
53
54 public boolean dependsOn( ModelItem modelItem )
55 {
56 return ModelSupport.dependsOn( this, modelItem );
57 }
58
59 public ModelItem getParent()
60 {
61 return parent;
62 }
63
64 public ImageIcon getIcon()
65 {
66 return icon;
67 }
68
69 @Override
70 public void setIcon( ImageIcon icon )
71 {
72 if( icon == this.icon )
73 return;
74
75 ImageIcon oldIcon = this.icon;
76 this.icon = icon;
77 notifyPropertyChanged( ICON_PROPERTY, oldIcon, icon );
78 }
79
80 public String getDescription()
81 {
82 String description = config.getDescription();
83 return StringUtils.hasContent( description ) ? description : "";
84 }
85
86 public void setDescription( String description )
87 {
88 String old = getDescription();
89 if( String.valueOf( old ).equals( description ) )
90 return;
91
92 config.setDescription( description );
93 notifyPropertyChanged( DESCRIPTION_PROPERTY, old, description );
94 }
95
96 public String getName()
97 {
98 return config.getName();
99 }
100
101 public void setName( String name )
102 {
103 String old = getName();
104 name = name.trim();
105 config.setName( name );
106 notifyPropertyChanged( NAME_PROPERTY, old, name );
107 }
108
109 public XmlBeansSettingsImpl getSettings()
110 {
111 return settings;
112 }
113
114 public T getConfig()
115 {
116 return config;
117 }
118
119 public void setConfig( T config )
120 {
121 this.config = config;
122
123 if( config != null && config.isSetName() )
124 {
125 config.setName( config.getName().trim() );
126 }
127
128 if( settings != null )
129 settings.release();
130
131 if( !config.isSetSettings() )
132 config.addNewSettings();
133
134 settings = new XmlBeansSettingsImpl( this, parent == null ? SoapUI.getSettings() : parent.getSettings(),
135 this.config.getSettings() );
136 }
137
138 public String getId()
139 {
140 if( !config.isSetId() )
141 config.setId( ModelSupport.generateModelItemID() );
142
143 return config.getId();
144 }
145
146 protected void setSettings( XmlBeansSettingsImpl settings )
147 {
148 if( this.settings != null )
149 this.settings.release();
150
151 this.settings = settings;
152 }
153
154 public AbstractWsdlModelItem<?> getWsdlModelItemByName( Collection<? extends AbstractWsdlModelItem<?>> items,
155 String name )
156 {
157 for( AbstractWsdlModelItem<?> item : items )
158 {
159 if( item.getName() != null && item.getName().equals( name ) )
160 return item;
161 }
162
163 return null;
164 }
165
166 public void release()
167 {
168 if( settings != null )
169 {
170 settings.release();
171 }
172 }
173
174 public void resolve( ResolveContext<?> context )
175 {
176 List<? extends ModelItem> children = getChildren();
177 if( children == null )
178 return;
179
180 for( ModelItem modelItem : children )
181 {
182 if( modelItem instanceof AbstractWsdlModelItem<?> )
183 {
184 ( ( AbstractWsdlModelItem<?> )modelItem ).resolve( context );
185 }
186 }
187 }
188
189 public void beforeSave()
190 {
191 List<? extends ModelItem> children = getChildren();
192 if( children == null )
193 return;
194
195 for( ModelItem modelItem : children )
196 {
197 if( modelItem instanceof AbstractWsdlModelItem<?> )
198 {
199 ( ( AbstractWsdlModelItem<?> )modelItem ).beforeSave();
200 }
201 }
202 }
203
204 public void afterLoad()
205 {
206 List<? extends ModelItem> children = getChildren();
207 if( children == null )
208 return;
209
210 for( ModelItem modelItem : children )
211 {
212 if( modelItem instanceof AbstractWsdlModelItem<?> )
213 {
214 ( ( AbstractWsdlModelItem<?> )modelItem ).afterLoad();
215 }
216 }
217 }
218 }