01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18:
19: package org.apache.jmeter.save.converters;
20:
21: import org.apache.jmeter.testelement.property.StringProperty;
22:
23: import com.thoughtworks.xstream.converters.Converter;
24: import com.thoughtworks.xstream.converters.MarshallingContext;
25: import com.thoughtworks.xstream.converters.UnmarshallingContext;
26: import com.thoughtworks.xstream.io.HierarchicalStreamReader;
27: import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
28:
29: /**
30: * @author mstover
31: *
32: */
33: public class StringPropertyConverter implements Converter {
34:
35: private static final String ATT_NAME = "name"; // $NON-NLS-1$
36:
37: /**
38: * Returns the converter version; used to check for possible
39: * incompatibilities
40: */
41: public static String getVersion() {
42: return "$Revision: 493779 $"; // $NON-NLS-1$
43: }
44:
45: /*
46: * (non-Javadoc)
47: *
48: * @see com.thoughtworks.xstream.converters.Converter#canConvert(java.lang.Class)
49: */
50: public boolean canConvert(Class arg0) {
51: return StringProperty.class.equals(arg0);
52: }
53:
54: /*
55: * (non-Javadoc)
56: *
57: * @see com.thoughtworks.xstream.converters.Converter#marshal(java.lang.Object,
58: * com.thoughtworks.xstream.io.HierarchicalStreamWriter,
59: * com.thoughtworks.xstream.converters.MarshallingContext)
60: */
61: public void marshal(Object obj, HierarchicalStreamWriter writer,
62: MarshallingContext arg2) {
63: StringProperty prop = (StringProperty) obj;
64: writer.addAttribute(ATT_NAME, ConversionHelp.encode(prop
65: .getName()));
66: writer.setValue(ConversionHelp.encode(prop.getStringValue()));
67: }
68:
69: /*
70: * (non-Javadoc)
71: *
72: * @see com.thoughtworks.xstream.converters.Converter#unmarshal(com.thoughtworks.xstream.io.HierarchicalStreamReader,
73: * com.thoughtworks.xstream.converters.UnmarshallingContext)
74: */
75: public Object unmarshal(HierarchicalStreamReader reader,
76: UnmarshallingContext arg1) {
77: StringProperty prop = new StringProperty(ConversionHelp
78: .decode(reader.getAttribute(ATT_NAME)), ConversionHelp
79: .decode(reader.getValue()));
80: return prop;
81: }
82: }
|