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.IntegerProperty;
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: * To change the template for this generated type comment go to Window -
33: * Preferences - Java - Code Generation - Code and Comments
34: */
35: public class IntegerPropertyConverter implements Converter {
36:
37: private static final String ATT_NAME = "name"; // $NON-NLS-1$
38:
39: /**
40: * Returns the converter version; used to check for possible
41: * incompatibilities
42: */
43: public static String getVersion() {
44: return "$Revision: 493779 $"; // $NON-NLS-1$
45: }
46:
47: /*
48: * (non-Javadoc)
49: *
50: * @see com.thoughtworks.xstream.converters.Converter#canConvert(java.lang.Class)
51: */
52: public boolean canConvert(Class arg0) {
53: return arg0.equals(IntegerProperty.class);
54: }
55:
56: /*
57: * (non-Javadoc)
58: *
59: * @see com.thoughtworks.xstream.converters.Converter#marshal(java.lang.Object,
60: * com.thoughtworks.xstream.io.HierarchicalStreamWriter,
61: * com.thoughtworks.xstream.converters.MarshallingContext)
62: */
63: public void marshal(Object obj, HierarchicalStreamWriter writer,
64: MarshallingContext arg2) {
65: IntegerProperty prop = (IntegerProperty) obj;
66: writer.addAttribute(ATT_NAME, ConversionHelp.encode(prop
67: .getName()));
68: writer.setValue(prop.getStringValue());
69: }
70:
71: /*
72: * (non-Javadoc)
73: *
74: * @see com.thoughtworks.xstream.converters.Converter#unmarshal(com.thoughtworks.xstream.io.HierarchicalStreamReader,
75: * com.thoughtworks.xstream.converters.UnmarshallingContext)
76: */
77: public Object unmarshal(HierarchicalStreamReader reader,
78: UnmarshallingContext arg1) {
79: IntegerProperty prop = new IntegerProperty(ConversionHelp
80: .decode(reader.getAttribute(ATT_NAME)), Integer
81: .parseInt(reader.getValue()));
82: return prop;
83: }
84: }
|