View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2010 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.support.wss.crypto;
14  
15  import java.beans.PropertyChangeListener;
16  
17  import javax.swing.JComponent;
18  
19  import com.eviware.soapui.config.WSSCryptoConfig;
20  import com.eviware.soapui.impl.wsdl.support.wss.WssContainer;
21  import com.eviware.soapui.impl.wsdl.support.wss.WssCrypto;
22  import com.eviware.soapui.model.propertyexpansion.PropertyExpansion;
23  import com.eviware.soapui.model.propertyexpansion.PropertyExpansionContainer;
24  import com.eviware.soapui.model.propertyexpansion.PropertyExpansionsResult;
25  import com.eviware.soapui.support.xml.XmlObjectConfigurationBuilder;
26  import com.eviware.soapui.support.xml.XmlObjectConfigurationReader;
27  
28  public abstract class WssCryptoBase implements WssCrypto, PropertyExpansionContainer
29  {
30  	private WSSCryptoConfig config;
31  	private WssContainer container;
32  	private JComponent configComponent;
33  	private String label;
34  
35  	public void init( WSSCryptoConfig config, WssContainer container, String label )
36  	{
37  		this.config = config;
38  		this.container = container;
39  		this.label = label;
40  
41  		if( config.getConfiguration() == null )
42  			config.addNewConfiguration();
43  
44  		load( new XmlObjectConfigurationReader( config.getConfiguration() ) );
45  	}
46  
47  	public JComponent getConfigurationPanel()
48  	{
49  		if( configComponent == null )
50  			configComponent = buildUI();
51  
52  		return configComponent;
53  	}
54  
55  	public String getLabel()
56  	{
57  		return label;
58  	}
59  
60  	protected abstract JComponent buildUI();
61  
62  	protected abstract void load( XmlObjectConfigurationReader reader );
63  
64  	public void setConfig( WSSCryptoConfig config )
65  	{
66  		this.config = config;
67  	}
68  
69  	public void saveConfig()
70  	{
71  		XmlObjectConfigurationBuilder builder = new XmlObjectConfigurationBuilder();
72  		save( builder );
73  		config.getConfiguration().set( builder.finish() );
74  	}
75  
76  	protected abstract void save( XmlObjectConfigurationBuilder builder );
77  
78  	public WssContainer getContainer()
79  	{
80  		return container;
81  	}
82  
83  	public void addPropertyChangeListener( PropertyChangeListener listener )
84  	{
85  	}
86  
87  	public void removePropertyChangeListener( PropertyChangeListener listener )
88  	{
89  	}
90  
91  	public PropertyExpansion[] getPropertyExpansions()
92  	{
93  		PropertyExpansionsResult result = new PropertyExpansionsResult( getContainer().getModelItem(), this );
94  
95  		addPropertyExpansions( result );
96  
97  		return result.toArray();
98  	}
99  
100 	protected void addPropertyExpansions( PropertyExpansionsResult result )
101 	{
102 		result.extractAndAddAll( "username" );
103 		result.extractAndAddAll( "password" );
104 	}
105 
106 	@Override
107 	public String toString()
108 	{
109 		return getLabel();
110 	}
111 
112 	public void udpateConfig( WSSCryptoConfig config )
113 	{
114 		this.config = config;
115 	}
116 }