View Javadoc

    1   /*
    2    *  soapUI, copyright (C) 2004-2007 eviware.com
    3    *
    4    *  soapUI is free software; you can redistribute it and/or modify it under the
    5    *  terms of version 2.1 of the GNU Lesser General Public License as published by
    6    *  the Free Software Foundation.
    7    *
    8    *  soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
    9    *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    10   *  See the GNU Lesser General Public License for more details at gnu.org.
    11   */
    12
    13  package com.eviware.soapui.impl.wsdl;
    14
    15  import java.util.Collection;
    16
    17  import javax.swing.ImageIcon;
    18
    19  import com.eviware.soapui.SoapUI;
    20  import com.eviware.soapui.config.ModelItemConfig;
    21  import com.eviware.soapui.impl.settings.XmlBeansSettingsImpl;
    22  import com.eviware.soapui.model.ModelItem;
    23  import com.eviware.soapui.model.settings.Settings;
    24  import com.eviware.soapui.model.support.AbstractModelItem;
    25  import com.eviware.soapui.support.UISupport;
    26
    27  /***
    28   * Abstract base class for WSDL-implementation classes
    29   *
    30   * @author Ole.Matzura
    31   */
    32
    33  public abstract class AbstractWsdlModelItem<T extends ModelItemConfig> extends AbstractModelItem
    34  {
    35  	private XmlBeansSettingsImpl settings;
    36  	private T config;
    37  	private ImageIcon icon;
    38  	private final ModelItem parent;
    39
    40  	protected AbstractWsdlModelItem( T config, ModelItem parent, String icon )
    41  	{
    42  		this.parent = parent;
    43  		if( config != null )
    44  			setConfig( config );
    45
    46  		if( icon != null )
    47  			this.icon = UISupport.createImageIcon(icon);
    48  	}
    49
    50     public ModelItem getParent()
    51  	{
    52  		return parent;
    53  	}
    54
    55  	public ImageIcon getIcon()
    56  	{
    57  		return icon;
    58  	}
    59
    60  	public void setIcon(ImageIcon icon)
    61  	{
    62  		if( icon == this.icon )
    63  			return;
    64
    65  		ImageIcon oldIcon = this.icon;
    66  		this.icon = icon;
    67  		notifyPropertyChanged( ICON_PROPERTY, oldIcon, icon );
    68  	}
    69
    70  	public String getDescription()
    71     {
    72        String description = config.getDescription();
    73  		return description ==  null || description.trim().length() == 0 ? null : description;
    74     }
    75
    76     public void setDescription(String description)
    77     {
    78        String old = getDescription();
    79        config.setDescription( description );
    80        notifyPropertyChanged( DESCRIPTION_PROPERTY, old, description );
    81     }
    82
    83     public String getName()
    84     {
    85        return config.getName();
    86     }
    87
    88     public void setName(String name)
    89     {
    90        String old = getName();
    91        config.setName( name );
    92        notifyPropertyChanged( NAME_PROPERTY, old, name );
    93     }
    94
    95  	public Settings getSettings()
    96  	{
    97  		return settings;
    98  	}
    99
    100 	final public T getConfig()
    101 	{
    102 		return config;
    103 	}
    104
    105 	final public void setConfig( T config )
    106 	{
    107 		this.config = config;
    108
    109 		if( settings != null )
    110 			settings.release();
    111
    112 		if( !config.isSetSettings() )
    113 			config.addNewSettings();
    114
    115 		settings = new XmlBeansSettingsImpl( this, parent == null ? SoapUI.getSettings() : parent.getSettings(), this.config.getSettings() );
    116 	}
    117
    118 	protected void setSettings( XmlBeansSettingsImpl settings )
    119 	{
    120 		if( this.settings != null )
    121 			this.settings.release();
    122
    123 		this.settings = settings;
    124 	}
    125
    126 	public AbstractWsdlModelItem getWsdlModelItemByName( Collection<? extends AbstractWsdlModelItem> items, String name )
    127 	{
    128 		for( AbstractWsdlModelItem item : items )
    129 		{
    130 			if( item.getName().equals( name ))
    131 				return item;
    132 		}
    133
    134 		return null;
    135
    136 	}
    137
    138 	public void release()
    139 	{
    140 		if( settings != null )
    141 		{
    142 			settings.release();
    143 		}
    144 	}
    145
    146 	public void onSave()
    147 	{}
    148 }