1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.wsdl;
14
15 import java.util.Map;
16
17 import org.apache.log4j.Logger;
18
19 import com.eviware.soapui.config.ModelItemConfig;
20 import com.eviware.soapui.config.PropertiesTypeConfig;
21 import com.eviware.soapui.impl.wsdl.support.XmlBeansPropertiesTestPropertyHolder;
22 import com.eviware.soapui.model.ModelItem;
23 import com.eviware.soapui.model.propertyexpansion.PropertyExpansionUtils;
24 import com.eviware.soapui.model.testsuite.TestProperty;
25 import com.eviware.soapui.model.testsuite.TestPropertyListener;
26 import com.eviware.soapui.support.StringUtils;
27
28 public abstract class AbstractTestPropertyHolderWsdlModelItem<T extends ModelItemConfig> extends AbstractWsdlModelItem<T>
29 implements MutableTestPropertyHolder
30 {
31 private XmlBeansPropertiesTestPropertyHolder propertyHolderSupport;
32 private final static Logger log = Logger.getLogger(AbstractTestPropertyHolderWsdlModelItem.class);
33
34 protected AbstractTestPropertyHolderWsdlModelItem( T config, ModelItem parent, String icon )
35 {
36 super( config, parent, icon );
37 }
38
39 protected void setPropertiesConfig( PropertiesTypeConfig config )
40 {
41 if( propertyHolderSupport == null )
42 propertyHolderSupport = new XmlBeansPropertiesTestPropertyHolder( this, config );
43 else
44 propertyHolderSupport.resetPropertiesConfig( config );
45
46 String propertyName = createPropertyName( getName() );
47 if( StringUtils.hasContent(propertyName))
48 {
49 String propFile = System.getProperty( "soapui.properties." + propertyName);
50 if( StringUtils.hasContent(propFile))
51 {
52 int result = propertyHolderSupport.addPropertiesFromFile( propFile);
53 if( result > 0 )
54 {
55 log.info("Overriding " + result + " properties from [" + propFile + "] in [" + getName() + "]" );
56 }
57 }
58 }
59 }
60
61 private String createPropertyName(String str)
62 {
63 if( str == null )
64 return null;
65
66 StringBuffer result = new StringBuffer();
67 for( char ch : str.toCharArray() )
68 {
69 if( Character.isLetterOrDigit(ch))
70 result.append(ch);
71 }
72
73 return result.toString();
74 }
75
76 public TestProperty addProperty( String name )
77 {
78 return propertyHolderSupport.addProperty( name );
79 }
80
81 public void addTestPropertyListener( TestPropertyListener listener )
82 {
83 propertyHolderSupport.addTestPropertyListener( listener );
84 }
85
86 public TestProperty getProperty( String name )
87 {
88 return propertyHolderSupport.getProperty( name );
89 }
90
91 public String[] getPropertyNames()
92 {
93 return propertyHolderSupport.getPropertyNames();
94 }
95
96 public String getPropertyValue( String name )
97 {
98 return propertyHolderSupport.getPropertyValue( name );
99 }
100
101 public TestProperty removeProperty( String propertyName )
102 {
103 return propertyHolderSupport.removeProperty( propertyName );
104 }
105
106 public void removeTestPropertyListener( TestPropertyListener listener )
107 {
108 propertyHolderSupport.removeTestPropertyListener( listener );
109 }
110
111 public void setPropertyValue( String name, String value )
112 {
113 propertyHolderSupport.setPropertyValue( name, value );
114 }
115
116 public boolean renameProperty( String name, String newName )
117 {
118 return PropertyExpansionUtils.renameProperty( propertyHolderSupport.getProperty( name ), newName, this ) != null;
119 }
120
121 public Map<String, TestProperty> getProperties()
122 {
123 return propertyHolderSupport.getProperties();
124 }
125
126 public boolean hasProperty( String name )
127 {
128 return propertyHolderSupport.hasProperty( name );
129 }
130
131 public TestProperty getPropertyAt(int index)
132 {
133 return propertyHolderSupport.getPropertyAt(index);
134 }
135
136 public int getPropertyCount()
137 {
138 return propertyHolderSupport.getPropertyCount();
139 }
140
141 public void moveProperty(String propertyName, int targetIndex)
142 {
143 propertyHolderSupport.moveProperty(propertyName, targetIndex);
144 }
145
146 public ModelItem getModelItem()
147 {
148 return this;
149 }
150
151 public String getPropertiesLabel()
152 {
153 return "Test Properties";
154 }
155 }