001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
013: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
014: * License for the specific language governing permissions and limitations
015: * under the License.
016: *
017: */
018:
019: /*
020: * Created on Sep 7, 2004
021: */
022: package org.apache.jmeter.save.converters;
023:
024: import java.util.ArrayList;
025: import java.util.Collection;
026:
027: import org.apache.jmeter.samplers.SampleResult;
028: import org.apache.jmeter.save.TestResultWrapper;
029:
030: import com.thoughtworks.xstream.mapper.Mapper;
031: import com.thoughtworks.xstream.converters.MarshallingContext;
032: import com.thoughtworks.xstream.converters.UnmarshallingContext;
033: import com.thoughtworks.xstream.converters.collections.AbstractCollectionConverter;
034: import com.thoughtworks.xstream.io.HierarchicalStreamReader;
035: import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
036:
037: /**
038: * @author mstover
039: *
040: */
041: public class TestResultWrapperConverter extends
042: AbstractCollectionConverter {
043:
044: /**
045: * Returns the converter version; used to check for possible
046: * incompatibilities
047: */
048: public static String getVersion() {
049: return "$Revision: 514283 $"; //$NON-NLS-1$
050: }
051:
052: /**
053: * @param arg0
054: */
055: public TestResultWrapperConverter(Mapper arg0) {
056: super (arg0);
057: }
058:
059: /*
060: * (non-Javadoc)
061: *
062: * @see com.thoughtworks.xstream.converters.Converter#canConvert(java.lang.Class)
063: */
064: public boolean canConvert(Class arg0) {
065: return arg0.equals(TestResultWrapper.class);
066: }
067:
068: /*
069: * (non-Javadoc)
070: *
071: * @see com.thoughtworks.xstream.converters.Converter#marshal(java.lang.Object,
072: * com.thoughtworks.xstream.io.HierarchicalStreamWriter,
073: * com.thoughtworks.xstream.converters.MarshallingContext)
074: */
075: public void marshal(Object arg0, HierarchicalStreamWriter arg1,
076: MarshallingContext arg2) {
077: // Not used, as the <testResult> element is generated by the
078: // ResultCollector class
079: }
080:
081: /*
082: * (non-Javadoc)
083: *
084: * @see com.thoughtworks.xstream.converters.Converter#unmarshal(com.thoughtworks.xstream.io.HierarchicalStreamReader,
085: * com.thoughtworks.xstream.converters.UnmarshallingContext)
086: */
087: public Object unmarshal(HierarchicalStreamReader reader,
088: UnmarshallingContext context) {
089: TestResultWrapper results = new TestResultWrapper();
090: Collection samples = new ArrayList();
091: String ver = reader.getAttribute("version"); //$NON-NLS-1$
092: if (ver == null || ver.length() == 0)
093: ver = "1.0"; //$NON-NLS-1$
094: results.setVersion(ver);
095: ConversionHelp.setInVersion(ver);// Make sure decoding follows input
096: // file
097: while (reader.hasMoreChildren()) {
098: reader.moveDown();
099: SampleResult res = (SampleResult) readItem(reader, context,
100: results);
101: samples.add(res);
102: reader.moveUp();
103: }
104: results.setSampleResults(samples);
105: return results;
106: }
107: }
|