Source Code Cross Referenced for TestElementPropertyConverter.java in  » Testing » jakarta-jmeter » org » apache » jmeter » save » converters » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Testing » jakarta jmeter » org.apache.jmeter.save.converters 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         * 
017:         */
018:
019:        package org.apache.jmeter.save.converters;
020:
021:        import org.apache.jmeter.config.ConfigTestElement;
022:        import org.apache.jmeter.save.SaveService;
023:        import org.apache.jmeter.testelement.TestElement;
024:        import org.apache.jmeter.testelement.property.JMeterProperty;
025:        import org.apache.jmeter.testelement.property.PropertyIterator;
026:        import org.apache.jmeter.testelement.property.TestElementProperty;
027:        import org.apache.jorphan.logging.LoggingManager;
028:        import org.apache.log.Logger;
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:         * To change the template for this generated type comment go to Window -
041:         * Preferences - Java - Code Generation - Code and Comments
042:         */
043:        public class TestElementPropertyConverter extends
044:                AbstractCollectionConverter {
045:            private static final Logger log = LoggingManager
046:                    .getLoggerForClass();
047:
048:            private final boolean testFormat22 = SaveService
049:                    .isSaveTestPlanFormat22();
050:
051:            private static final String HEADER_CLASSNAME = "org.apache.jmeter.protocol.http.control.Header"; // $NON-NLS-1$
052:
053:            /**
054:             * Returns the converter version; used to check for possible
055:             * incompatibilities
056:             */
057:            public static String getVersion() {
058:                return "$Revision: 592814 $"; // $NON-NLS-1$
059:            }
060:
061:            /*
062:             * (non-Javadoc)
063:             * 
064:             * @see com.thoughtworks.xstream.converters.Converter#canConvert(java.lang.Class)
065:             */
066:            public boolean canConvert(Class arg0) {
067:                return arg0.equals(TestElementProperty.class);
068:            }
069:
070:            /*
071:             * (non-Javadoc)
072:             * 
073:             * @see com.thoughtworks.xstream.converters.Converter#marshal(java.lang.Object,
074:             *      com.thoughtworks.xstream.io.HierarchicalStreamWriter,
075:             *      com.thoughtworks.xstream.converters.MarshallingContext)
076:             */
077:            public void marshal(Object arg0, HierarchicalStreamWriter writer,
078:                    MarshallingContext context) {
079:                TestElementProperty prop = (TestElementProperty) arg0;
080:                writer.addAttribute(ConversionHelp.ATT_NAME, ConversionHelp
081:                        .encode(prop.getName()));
082:                Class clazz = prop.getObjectValue().getClass();
083:                writer.addAttribute(ConversionHelp.ATT_ELEMENT_TYPE,
084:                        testFormat22 ? mapper().serializedClass(clazz) : clazz
085:                                .getName());
086:                if (testFormat22) {
087:                    TestElement te = (TestElement) prop.getObjectValue();
088:                    ConversionHelp.saveSpecialProperties(te, writer);
089:                }
090:                PropertyIterator iter = prop.iterator();
091:                while (iter.hasNext()) {
092:                    JMeterProperty jmp = iter.next();
093:                    // Skip special properties if required
094:                    if (!testFormat22
095:                            || !ConversionHelp.isSpecialProperty(jmp.getName())) {
096:                        // Don't save empty comments
097:                        if (!(TestElement.COMMENTS.equals(jmp.getName()) && jmp
098:                                .getStringValue().length() == 0)) {
099:                            writeItem(jmp, context, writer);
100:                        }
101:                    }
102:                }
103:                //TODO clazz is probably always the same as testclass
104:            }
105:
106:            /*
107:             * TODO - convert to work more like upgrade.properties/NameUpdater.java
108:             * 
109:             * Special processing is carried out for the Header Class The String
110:             * property TestElement.name is converted to Header.name for example:
111:             * <elementProp name="User-Agent"
112:             * elementType="org.apache.jmeter.protocol.http.control.Header"> <stringProp
113:             * name="Header.value">Mozilla%2F4.0+%28compatible%3B+MSIE+5.5%3B+Windows+98%29</stringProp>
114:             * <stringProp name="TestElement.name">User-Agent</stringProp>
115:             * </elementProp> becomes <elementProp name="User-Agent"
116:             * elementType="org.apache.jmeter.protocol.http.control.Header"> <stringProp
117:             * name="Header.value">Mozilla%2F4.0+%28compatible%3B+MSIE+5.5%3B+Windows+98%29</stringProp>
118:             * <stringProp name="Header.name">User-Agent</stringProp> </elementProp>
119:             */
120:            /*
121:             * (non-Javadoc)
122:             * 
123:             * @see com.thoughtworks.xstream.converters.Converter#unmarshal(com.thoughtworks.xstream.io.HierarchicalStreamReader,
124:             *      com.thoughtworks.xstream.converters.UnmarshallingContext)
125:             */
126:            public Object unmarshal(HierarchicalStreamReader reader,
127:                    UnmarshallingContext context) {
128:                try {
129:                    TestElementProperty prop = (TestElementProperty) createCollection(context
130:                            .getRequiredType());
131:                    prop.setName(ConversionHelp.decode(reader
132:                            .getAttribute(ConversionHelp.ATT_NAME)));
133:                    String element = reader
134:                            .getAttribute(ConversionHelp.ATT_ELEMENT_TYPE);
135:                    boolean isHeader = HEADER_CLASSNAME.equals(element);
136:                    prop.setObjectValue(mapper().realClass(element)
137:                            .newInstance());// Always decode
138:                    TestElement te = (TestElement) prop.getObjectValue();
139:                    // No need to check version, just process the attributes if present
140:                    ConversionHelp.restoreSpecialProperties(te, reader);
141:                    while (reader.hasMoreChildren()) {
142:                        reader.moveDown();
143:                        JMeterProperty subProp = (JMeterProperty) readItem(
144:                                reader, context, prop);
145:                        if (isHeader) {
146:                            String name = subProp.getName();
147:                            if (TestElement.NAME.equals(name)) {
148:                                subProp.setName("Header.name");// $NON-NLS-1$
149:                                // Must be same as Header.HNAME - but that is built
150:                                // later
151:                            }
152:                        }
153:                        prop.addProperty(subProp);
154:                        reader.moveUp();
155:                    }
156:                    return prop;
157:                } catch (Exception e) {
158:                    log.error("Couldn't unmarshall TestElementProperty", e);
159:                    return new TestElementProperty("ERROR",
160:                            new ConfigTestElement());// $NON-NLS-1$
161:                }
162:            }
163:
164:            /**
165:             * @param arg0
166:             */
167:            public TestElementPropertyConverter(Mapper arg0) {
168:                super(arg0);
169:            }
170:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.