Source Code Cross Referenced for PropertyTransfer.java in  » Web-Services » soapui-1.7.5 » com » eviware » soapui » impl » wsdl » teststeps » 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 » Web Services » soapui 1.7.5 » com.eviware.soapui.impl.wsdl.teststeps 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  soapUI, copyright (C) 2004-2007 eviware.com 
003:         *
004:         *  soapUI is free software; you can redistribute it and/or modify it under the 
005:         *  terms of version 2.1 of the GNU Lesser General Public License as published by 
006:         *  the Free Software Foundation.
007:         *
008:         *  soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 
009:         *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
010:         *  See the GNU Lesser General Public License for more details at gnu.org.
011:         */
012:
013:        package com.eviware.soapui.impl.wsdl.teststeps;
014:
015:        import java.beans.PropertyChangeEvent;
016:        import java.beans.PropertyChangeListener;
017:        import java.beans.PropertyChangeSupport;
018:        import java.util.ArrayList;
019:        import java.util.List;
020:
021:        import org.apache.log4j.Logger;
022:        import org.apache.xmlbeans.XmlCursor;
023:        import org.apache.xmlbeans.XmlException;
024:        import org.apache.xmlbeans.XmlObject;
025:        import org.apache.xmlbeans.XmlOptions;
026:        import org.w3c.dom.DocumentFragment;
027:        import org.w3c.dom.Element;
028:        import org.w3c.dom.Node;
029:
030:        import com.eviware.soapui.config.ValueTransferConfig;
031:        import com.eviware.soapui.impl.wsdl.submit.filters.PropertyExpansionRequestFilter;
032:        import com.eviware.soapui.model.iface.SubmitContext;
033:        import com.eviware.soapui.model.support.TestSuiteListenerAdapter;
034:        import com.eviware.soapui.model.testsuite.TestCase;
035:        import com.eviware.soapui.model.testsuite.TestStep;
036:        import com.eviware.soapui.model.testsuite.TestStepProperty;
037:        import com.eviware.soapui.support.PropertyChangeNotifier;
038:        import com.eviware.soapui.support.xml.XmlUtils;
039:
040:        /**
041:         * Class for transferring a property value between 2 test steps. This class is relatively complex due
042:         * to backwards compatibility issues and to gracefull handling of references test steps and properties.
043:         * 
044:         * @author Ole.Matzura
045:         */
046:
047:        public class PropertyTransfer implements  PropertyChangeNotifier {
048:            private final static Logger log = Logger
049:                    .getLogger(PropertyTransfer.class);
050:
051:            public final static String SOURCE_PATH_PROPERTY = PropertyTransfer.class
052:                    .getName()
053:                    + "@sourcePath";
054:            public final static String SOURCE_TYPE_PROPERTY = PropertyTransfer.class
055:                    .getName()
056:                    + "@sourceProperty";
057:            public final static String SOURCE_STEP_PROPERTY = PropertyTransfer.class
058:                    .getName()
059:                    + "@sourceStep";
060:            public final static String TARGET_PATH_PROPERTY = PropertyTransfer.class
061:                    .getName()
062:                    + "@targetPath";
063:            public final static String TARGET_TYPE_PROPERTY = PropertyTransfer.class
064:                    .getName()
065:                    + "@targetProperty";
066:            public final static String TARGET_STEP_PROPERTY = PropertyTransfer.class
067:                    .getName()
068:                    + "@targetStep";
069:            public final static String NAME_PROPERTY = PropertyTransfer.class
070:                    .getName()
071:                    + "@name";
072:            public final static String CONFIG_PROPERTY = PropertyTransfer.class
073:                    .getName()
074:                    + "@config";
075:
076:            private TestStep testStep;
077:
078:            // create local copies since a deleted/changed valuetransfer can be referred to from a result 
079:            private ValueTransferConfig config;
080:            private String sourcePath;
081:            private String sourceType;
082:            private String targetPath;
083:            private String name;
084:            private String targetType;
085:            private String sourceStep;
086:            private String targetStep;
087:
088:            private TestStep currentTargetStep;
089:            private TestStep currentSourceStep;
090:            private TestStepProperty currentTargetProperty;
091:            private TestStepProperty currentSourceProperty;
092:
093:            private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(
094:                    this );
095:            private StepNameChangeListener stepNameChangeListener = new StepNameChangeListener();
096:            private PropertyNameChangeListener propertyNameChangeListener = new PropertyNameChangeListener();
097:            private TestCase testCase;
098:
099:            private InternalTestSuiteListener testSuiteListener = new InternalTestSuiteListener();
100:
101:            public PropertyTransfer(TestStep testStep) {
102:                this (testStep, ValueTransferConfig.Factory.newInstance());
103:            }
104:
105:            public PropertyTransfer(TestStep testStep,
106:                    ValueTransferConfig config) {
107:                this .testStep = testStep;
108:
109:                if (testStep != null) {
110:                    this .testCase = testStep.getTestCase();
111:                    testCase.getTestSuite().addTestSuiteListener(
112:                            testSuiteListener);
113:                }
114:
115:                setConfig(config);
116:            }
117:
118:            void setConfigOnMove(ValueTransferConfig config) {
119:                this .config = config;
120:            }
121:
122:            void setConfig(ValueTransferConfig config) {
123:                releaseListeners();
124:
125:                this .config = config;
126:
127:                if (!config.isSetSetNullOnMissingSource()) {
128:                    config.setSetNullOnMissingSource(true);
129:                }
130:
131:                if (!config.isSetTransferTextContent()) {
132:                    config.setTransferTextContent(true);
133:                }
134:
135:                sourceStep = config.getSourceStep();
136:                if (sourceStep == null) {
137:                    sourceStep = getSourceStepName();
138:                    if (sourceStep != null)
139:                        config.setSourceStep(sourceStep);
140:                }
141:
142:                currentSourceStep = (sourceStep == null || testCase == null) ? null
143:                        : testCase.getTestStepByName(sourceStep);
144:
145:                sourceType = config.getSourceType();
146:                currentSourceProperty = currentSourceStep == null
147:                        || sourceType == null ? null : currentSourceStep
148:                        .getProperty(sourceType);
149:
150:                sourcePath = config.getSourcePath();
151:
152:                targetStep = config.getTargetStep();
153:                if (targetStep == null) {
154:                    targetStep = getTargetStepName();
155:                    if (targetStep != null)
156:                        config.setTargetStep(targetStep);
157:                }
158:
159:                currentTargetStep = (targetStep == null || testCase == null) ? null
160:                        : testCase.getTestStepByName(targetStep);
161:
162:                targetType = config.getTargetType();
163:                currentTargetProperty = currentTargetStep == null
164:                        || targetType == null ? null : currentTargetStep
165:                        .getProperty(targetType);
166:
167:                targetPath = config.getTargetPath();
168:
169:                name = config.getName();
170:                initListeners();
171:
172:                propertyChangeSupport.firePropertyChange(CONFIG_PROPERTY, null,
173:                        null);
174:            }
175:
176:            private void initListeners() {
177:                if (currentSourceStep != null) {
178:                    currentSourceStep.addPropertyChangeListener(
179:                            TestStep.NAME_PROPERTY, stepNameChangeListener);
180:                    ((WsdlTestStep) currentSourceStep)
181:                            .addTestStepListener(propertyNameChangeListener);
182:                }
183:
184:                if (currentTargetStep != null) {
185:                    currentTargetStep.addPropertyChangeListener(
186:                            TestStep.NAME_PROPERTY, stepNameChangeListener);
187:                    ((WsdlTestStep) currentTargetStep)
188:                            .addTestStepListener(propertyNameChangeListener);
189:                }
190:            }
191:
192:            public void releaseListeners() {
193:                if (currentSourceStep != null) {
194:                    currentSourceStep.removePropertyChangeListener(
195:                            TestStep.NAME_PROPERTY, stepNameChangeListener);
196:                    ((WsdlTestStep) currentSourceStep)
197:                            .removeTestStepListener(propertyNameChangeListener);
198:                }
199:
200:                if (currentTargetStep != null) {
201:                    currentTargetStep.removePropertyChangeListener(
202:                            TestStep.NAME_PROPERTY, stepNameChangeListener);
203:                    ((WsdlTestStep) currentTargetStep)
204:                            .removeTestStepListener(propertyNameChangeListener);
205:                }
206:
207:                PropertyChangeListener[] listeners = propertyChangeSupport
208:                        .getPropertyChangeListeners();
209:                for (PropertyChangeListener listener : listeners)
210:                    propertyChangeSupport
211:                            .removePropertyChangeListener(listener);
212:            }
213:
214:            public void release() {
215:                releaseListeners();
216:                testCase.getTestSuite().removeTestSuiteListener(
217:                        testSuiteListener);
218:            }
219:
220:            public ValueTransferConfig getConfig() {
221:                return config;
222:            }
223:
224:            public String getSourcePath() {
225:                return sourcePath;
226:            }
227:
228:            public String getTargetPath() {
229:                return targetPath;
230:            }
231:
232:            public TestStepProperty getSourceProperty() {
233:                if (sourceType == null)
234:                    return null;
235:
236:                if (currentSourceProperty != null)
237:                    return currentSourceProperty;
238:
239:                TestStep actualSourceStep = getSourceStep();
240:                return actualSourceStep == null ? null : actualSourceStep
241:                        .getProperty(sourceType);
242:            }
243:
244:            public String[] transferProperties(SubmitContext context)
245:                    throws PropertyTransferException {
246:                TestStepProperty sourceProperty = getSourceProperty();
247:                TestStepProperty targetProperty = getTargetProperty();
248:
249:                try {
250:                    if (sourceProperty == null)
251:                        throw new Exception("Missing source property");
252:                    if (targetProperty == null)
253:                        throw new Exception("Missing target property");
254:                    if (sourceProperty.getValue() == null
255:                            && !getSetNullOnMissingSource()
256:                            && !getIgnoreEmpty())
257:                        throw new Exception("Source property is null");
258:
259:                    if (!hasSourcePath() && !hasTargetPath()) {
260:                        if (!getIgnoreEmpty()
261:                                || (sourceProperty.getValue() != null && sourceProperty
262:                                        .getValue().length() > 0))
263:                            return transferStringToString(sourceProperty,
264:                                    targetProperty);
265:                    } else if (hasSourcePath() && hasTargetPath()) {
266:                        return transferXmlToXml(sourceProperty, targetProperty,
267:                                context);
268:                    } else if (hasSourcePath() && !hasTargetPath()) {
269:                        return new String[] { transferXmlToString(
270:                                sourceProperty, targetProperty, context) };
271:                    } else if (!hasSourcePath() && hasTargetPath()) {
272:                        if (!getIgnoreEmpty()
273:                                || (sourceProperty.getValue() != null && sourceProperty
274:                                        .getValue().length() > 0))
275:                            return transferStringToXml(sourceProperty,
276:                                    targetProperty, context);
277:                    }
278:                } catch (Exception e) {
279:                    throw new PropertyTransferException(e.toString(),
280:                            getSourceStepName(), sourceProperty,
281:                            getTargetStepName(), targetProperty);
282:                }
283:
284:                return new String[0];
285:            }
286:
287:            private boolean hasTargetPath() {
288:                String path = getTargetPath();
289:                return path != null && path.trim().length() > 0;
290:            }
291:
292:            private boolean hasSourcePath() {
293:                String path = getSourcePath();
294:                return path != null && path.trim().length() > 0;
295:            }
296:
297:            protected String[] transferStringToString(
298:                    TestStepProperty sourceProperty,
299:                    TestStepProperty targetProperty) {
300:                String value = sourceProperty.getValue();
301:                targetProperty.setValue(value);
302:                return new String[] { value };
303:            }
304:
305:            protected String[] transferXmlToXml(
306:                    TestStepProperty sourceProperty,
307:                    TestStepProperty targetProperty, SubmitContext context)
308:                    throws XmlException, Exception {
309:                String sourcePropertyValue = sourceProperty.getValue();
310:                XmlObject sourceXmlObject = XmlObject.Factory
311:                        .parse(sourcePropertyValue);
312:                XmlCursor sourceXml = sourceXmlObject.newCursor();
313:
314:                String targetPropertyValue = targetProperty.getValue();
315:                XmlObject targetXmlObject = XmlObject.Factory
316:                        .parse(targetPropertyValue);
317:                XmlCursor targetXml = targetXmlObject.newCursor();
318:
319:                XmlCursor lastSource = null;
320:
321:                try {
322:                    List<String> result = new ArrayList<String>();
323:
324:                    targetXml.selectPath(PropertyExpansionRequestFilter
325:                            .expandProperties(context, getTargetPath()));
326:
327:                    if (!targetXml.hasNextSelection())
328:                        throw new Exception("Missing match for Target path ["
329:                                + getTargetPath() + "]");
330:
331:                    sourceXml.selectPath(PropertyExpansionRequestFilter
332:                            .expandProperties(context, getSourcePath()));
333:
334:                    if (!sourceXml.hasNextSelection()) {
335:                        if (getSetNullOnMissingSource()) {
336:                            while (targetXml.toNextSelection()) {
337:                                result.add(setNodeValue(null, targetXml
338:                                        .getDomNode()));
339:                                if (!getTransferToAll())
340:                                    break;
341:                            }
342:                        } else if (!getIgnoreEmpty())
343:                            throw new Exception(
344:                                    "Missing match for Source path ["
345:                                            + getSourcePath() + "]");
346:                    } else {
347:                        boolean hasSource = sourceXml.toNextSelection();
348:                        boolean hasTarget = targetXml.toNextSelection();
349:
350:                        while (hasSource && hasTarget) {
351:                            if (lastSource != null)
352:                                lastSource.dispose();
353:
354:                            lastSource = sourceXml.newCursor();
355:                            result.add(transferXmlValue(sourceXml, targetXml));
356:
357:                            hasSource = sourceXml.toNextSelection();
358:                            hasTarget = targetXml.toNextSelection();
359:                        }
360:
361:                        if (getTransferToAll() && !hasSource && hasTarget
362:                                && lastSource != null) {
363:                            while (hasTarget) {
364:                                result.add(transferXmlValue(lastSource,
365:                                        targetXml));
366:                                hasTarget = targetXml.toNextSelection();
367:                            }
368:                        }
369:                    }
370:
371:                    if (result.size() > 0) {
372:                        targetProperty.setValue(targetXmlObject
373:                                .xmlText(new XmlOptions()
374:                                        .setSaveAggressiveNamespaces()));
375:                    }
376:
377:                    return result.toArray(new String[result.size()]);
378:                } finally {
379:                    sourceXml.dispose();
380:                    targetXml.dispose();
381:
382:                    if (lastSource != null)
383:                        lastSource.dispose();
384:                }
385:            }
386:
387:            protected String[] transferStringToXml(
388:                    TestStepProperty sourceProperty,
389:                    TestStepProperty targetProperty, SubmitContext context)
390:                    throws XmlException, Exception {
391:                XmlObject targetXml = XmlObject.Factory.parse(targetProperty
392:                        .getValue());
393:                XmlCursor targetCursor = targetXml.newCursor();
394:
395:                try {
396:                    List<String> result = new ArrayList<String>();
397:
398:                    targetCursor.selectPath(PropertyExpansionRequestFilter
399:                            .expandProperties(context, getTargetPath()));
400:
401:                    if (!targetCursor.toNextSelection())
402:                        throw new Exception("Missing match for Target path ["
403:                                + getTargetPath() + "]");
404:
405:                    String value = sourceProperty.getValue();
406:
407:                    Node targetNode = targetCursor.getDomNode();
408:                    setNodeValue(value, targetNode);
409:
410:                    result.add(value);
411:
412:                    if (getTransferToAll()) {
413:                        while (targetCursor.toNextSelection()) {
414:                            targetNode = targetCursor.getDomNode();
415:                            setNodeValue(value, targetNode);
416:
417:                            result.add(value);
418:                        }
419:                    }
420:
421:                    targetProperty.setValue(targetXml.xmlText(new XmlOptions()
422:                            .setSaveAggressiveNamespaces()));
423:
424:                    return result.toArray(new String[result.size()]);
425:                } finally {
426:                    targetCursor.dispose();
427:                }
428:            }
429:
430:            private String setNodeValue(String value, Node node)
431:                    throws Exception {
432:                short targetNodeType = node.getNodeType();
433:
434:                if (targetNodeType == Node.DOCUMENT_FRAGMENT_NODE) {
435:                    node = ((DocumentFragment) node).getFirstChild();
436:                    if (node != null)
437:                        targetNodeType = node.getNodeType();
438:                    else
439:                        throw new Exception("Missing source value for "
440:                                + getSourcePropertyName());
441:                }
442:
443:                if (targetNodeType == Node.TEXT_NODE
444:                        || targetNodeType == Node.ATTRIBUTE_NODE) {
445:                    node.setNodeValue(value);
446:                } else if (targetNodeType == Node.ELEMENT_NODE) {
447:                    XmlUtils.setElementText((Element) node, value);
448:                } else {
449:                    throw new Exception("Failed to set value to node ["
450:                            + node.toString() + "] of type [" + targetNodeType
451:                            + "]");
452:                }
453:
454:                return value;
455:            }
456:
457:            protected String transferXmlToString(
458:                    TestStepProperty sourceProperty,
459:                    TestStepProperty targetProperty, SubmitContext context)
460:                    throws XmlException, Exception {
461:                XmlObject sourceXml = XmlObject.Factory.parse(sourceProperty
462:                        .getValue());
463:                XmlCursor sourceCursor = sourceXml.newCursor();
464:
465:                try {
466:                    String value = null;
467:
468:                    sourceCursor.selectPath(PropertyExpansionRequestFilter
469:                            .expandProperties(context, getSourcePath()));
470:
471:                    if (!sourceCursor.toNextSelection()) {
472:                        if (!getSetNullOnMissingSource() && !getIgnoreEmpty())
473:                            throw new Exception(
474:                                    "Missing match for Source path ["
475:                                            + getSourcePath() + "]");
476:                    } else {
477:                        Node sourceNode = sourceCursor.getDomNode();
478:                        short sourceNodeType = sourceNode.getNodeType();
479:
480:                        if (sourceNodeType == Node.DOCUMENT_FRAGMENT_NODE) {
481:                            sourceNode = ((DocumentFragment) sourceNode)
482:                                    .getFirstChild();
483:                            if (sourceNode != null)
484:                                sourceNodeType = sourceNode.getNodeType();
485:                            else
486:                                throw new Exception("Missing source value for "
487:                                        + getSourcePropertyName());
488:                        }
489:
490:                        if (sourceNodeType == Node.TEXT_NODE
491:                                || sourceNodeType == Node.ATTRIBUTE_NODE) {
492:                            value = sourceNode.getNodeValue();
493:                        } else if (sourceNodeType == Node.ELEMENT_NODE) {
494:                            value = XmlUtils
495:                                    .getElementText((Element) sourceNode);
496:                        }
497:                    }
498:
499:                    if (!getIgnoreEmpty()
500:                            || (value != null && value.length() > 0))
501:                        targetProperty.setValue(value);
502:                    else
503:                        value = "";
504:
505:                    return value;
506:                } finally {
507:                    sourceCursor.dispose();
508:                }
509:            }
510:
511:            /**
512:             * Method called for transferring between 2 xml properties..
513:             */
514:
515:            private String transferXmlValue(XmlCursor source, XmlCursor dest)
516:                    throws Exception {
517:                // just copy if nodes are of same type
518:                Node destNode = dest.getDomNode();
519:                Node sourceNode = source.getDomNode();
520:                short destNodeType = destNode.getNodeType();
521:                short sourceNodeType = sourceNode.getNodeType();
522:                String value = null;
523:
524:                if (sourceNodeType == Node.DOCUMENT_FRAGMENT_NODE) {
525:                    sourceNode = ((DocumentFragment) sourceNode)
526:                            .getFirstChild();
527:                    if (sourceNode != null)
528:                        sourceNodeType = sourceNode.getNodeType();
529:                    else
530:                        throw new Exception("Missing source value for "
531:                                + source);
532:                }
533:
534:                // same type of node?
535:                if (destNodeType == sourceNodeType) {
536:                    if (destNodeType == Node.TEXT_NODE
537:                            || destNodeType == Node.ATTRIBUTE_NODE) {
538:                        value = sourceNode.getNodeValue();
539:                        if (!getIgnoreEmpty()
540:                                || (value != null && value.length() > 0))
541:                            destNode.setNodeValue(value);
542:                    } else if (config.getTransferTextContent()
543:                            && destNodeType == Node.ELEMENT_NODE) {
544:                        value = XmlUtils.getElementText((Element) sourceNode);
545:                        if (!getIgnoreEmpty()
546:                                || (value != null && value.length() > 0))
547:                            XmlUtils.setElementText((Element) destNode, value);
548:                    } else {
549:                        destNode = destNode.getParentNode().replaceChild(
550:                                destNode.getOwnerDocument().importNode(
551:                                        sourceNode, true), destNode);
552:
553:                        value = dest.xmlText();
554:                    }
555:                }
556:                // text to attribute?
557:                else if ((sourceNodeType == Node.TEXT_NODE && destNodeType == Node.ATTRIBUTE_NODE)
558:                        || (sourceNodeType == Node.ATTRIBUTE_NODE && destNodeType == Node.TEXT_NODE)) {
559:                    value = sourceNode.getNodeValue();
560:                    if (!getIgnoreEmpty()
561:                            || (value != null && value.length() > 0))
562:                        destNode.setNodeValue(value);
563:                } else if (sourceNodeType == Node.ELEMENT_NODE
564:                        && destNodeType == Node.ATTRIBUTE_NODE
565:                        || destNodeType == Node.TEXT_NODE) {
566:                    value = XmlUtils.getElementText((Element) sourceNode);
567:                    if (!getIgnoreEmpty()
568:                            || (value != null && value.length() > 0))
569:                        destNode.setNodeValue(value);
570:                } else if (destNodeType == Node.ELEMENT_NODE
571:                        && sourceNodeType == Node.ATTRIBUTE_NODE
572:                        || sourceNodeType == Node.TEXT_NODE) {
573:                    // hmm.. not sure xmlbeans handles this ok
574:                    value = sourceNode.getNodeValue();
575:                    if (!getIgnoreEmpty()
576:                            || (value != null && value.length() > 0))
577:                        XmlUtils.setElementText((Element) destNode, value);
578:                }
579:
580:                return value;
581:            }
582:
583:            /**
584:             * Returns the name of the source property. 
585:             */
586:
587:            public String getSourcePropertyName() {
588:                if (sourceType == null)
589:                    return null;
590:
591:                if (currentSourceProperty != null)
592:                    return currentSourceProperty.getName();
593:
594:                TestStep actualSourceStep = getSourceStep();
595:                if (actualSourceStep == null)
596:                    return sourceType;
597:
598:                TestStepProperty property = actualSourceStep
599:                        .getProperty(sourceType);
600:                return property == null ? sourceType : property.getName();
601:            }
602:
603:            public void setSourcePropertyName(String name) {
604:                String old = getSourcePropertyName();
605:
606:                // check for change
607:                if ((name == null && old == null)
608:                        || (name != null && old != null && name.equals(old)))
609:                    return;
610:
611:                // update
612:                sourceType = name;
613:                config.setSourceType(name);
614:
615:                // update actual property
616:                TestStep sourceStep2 = getSourceStep();
617:                currentSourceProperty = sourceStep2 != null
618:                        && sourceType != null ? sourceStep2
619:                        .getProperty(sourceType) : null;
620:
621:                // notify!
622:                propertyChangeSupport.firePropertyChange(SOURCE_TYPE_PROPERTY,
623:                        old, name);
624:            }
625:
626:            public TestStepProperty getTargetProperty() {
627:                if (targetType == null)
628:                    return null;
629:
630:                if (currentTargetProperty != null)
631:                    return currentTargetProperty;
632:
633:                TestStep actualTargetStep = getTargetStep();
634:                return actualTargetStep == null ? null : actualTargetStep
635:                        .getProperty(targetType);
636:            }
637:
638:            public String getTargetPropertyName() {
639:                if (targetType == null)
640:                    return null;
641:
642:                if (currentTargetProperty != null)
643:                    return currentTargetProperty.getName();
644:
645:                TestStep actualTargetStep = getTargetStep();
646:                TestStepProperty property = actualTargetStep == null ? null
647:                        : actualTargetStep.getProperty(targetType);
648:                return actualTargetStep == null || property == null ? targetType
649:                        : property.getName();
650:            }
651:
652:            public void setTargetPropertyName(String name) {
653:                String old = getTargetPropertyName();
654:
655:                // check for change
656:                if ((name == null && old == null)
657:                        || (name != null && old != null && name.equals(old)))
658:                    return;
659:
660:                // update
661:                targetType = name;
662:                config.setTargetType(name);
663:
664:                // update actual property
665:                TestStep targetStep2 = getTargetStep();
666:
667:                currentTargetProperty = targetStep2 != null
668:                        && targetType != null ? targetStep2
669:                        .getProperty(targetType) : null;
670:
671:                // notify!
672:                propertyChangeSupport.firePropertyChange(TARGET_TYPE_PROPERTY,
673:                        old, name);
674:            }
675:
676:            public String getName() {
677:                return config.getName();
678:            }
679:
680:            public void setSourcePath(String path) {
681:                String old = sourcePath;
682:                sourcePath = path;
683:                config.setSourcePath(path);
684:                propertyChangeSupport.firePropertyChange(SOURCE_PATH_PROPERTY,
685:                        old, path);
686:            }
687:
688:            public void setTargetPath(String path) {
689:                String old = targetPath;
690:                targetPath = path;
691:                config.setTargetPath(path);
692:                propertyChangeSupport.firePropertyChange(TARGET_PATH_PROPERTY,
693:                        old, path);
694:            }
695:
696:            public void setName(String name) {
697:                String old = this .name;
698:                this .name = name;
699:                config.setName(name);
700:                propertyChangeSupport.firePropertyChange(NAME_PROPERTY, old,
701:                        name);
702:            }
703:
704:            public TestStep getSourceStep() {
705:                String sourceStepName = getSourceStepName();
706:                return sourceStepName == null ? null : testCase
707:                        .getTestStepByName(sourceStepName);
708:            }
709:
710:            public String getSourceStepName() {
711:                if (sourceStep != null)
712:                    return sourceStep;
713:
714:                if (testCase == null)
715:                    return null;
716:
717:                TestStep step = testCase.findPreviousStepOfType(this .testStep,
718:                        WsdlTestRequestStep.class);
719:                return step == null ? null : step.getName();
720:            }
721:
722:            public void setSourceStepName(String sourceStep) {
723:                String old = getSourceStepName();
724:
725:                //	 check for change
726:                if ((sourceStep == null && old == null)
727:                        || (sourceStep != null && old != null && sourceStep
728:                                .equals(old)))
729:                    return;
730:
731:                if (sourceStep == null)
732:                    log.debug("Setting sourceStep for transfer [" + getName()
733:                            + "] to null");
734:
735:                this .sourceStep = sourceStep;
736:                config.setSourceStep(sourceStep);
737:
738:                if (currentSourceStep != null) {
739:                    currentSourceStep
740:                            .removePropertyChangeListener(stepNameChangeListener);
741:                    ((WsdlTestStep) currentSourceStep)
742:                            .removeTestStepListener(propertyNameChangeListener);
743:                }
744:
745:                currentSourceStep = (WsdlTestStep) (sourceStep == null ? null
746:                        : testStep.getTestCase().getTestStepByName(sourceStep));
747:                if (currentSourceStep != null) {
748:                    currentSourceStep.addPropertyChangeListener(
749:                            TestStep.NAME_PROPERTY, stepNameChangeListener);
750:                    ((WsdlTestStep) currentSourceStep)
751:                            .addTestStepListener(propertyNameChangeListener);
752:                }
753:
754:                propertyChangeSupport.firePropertyChange(SOURCE_STEP_PROPERTY,
755:                        old, sourceStep);
756:                setSourcePropertyName(null);
757:            }
758:
759:            public TestStep getTargetStep() {
760:                String targetStepName = getTargetStepName();
761:                return targetStepName == null ? null : testCase
762:                        .getTestStepByName(targetStepName);
763:            }
764:
765:            public String getTargetStepName() {
766:                if (targetStep != null)
767:                    return targetStep;
768:
769:                if (testCase == null)
770:                    return null;
771:
772:                TestStep step = testCase.findNextStepOfType(this .testStep,
773:                        WsdlTestRequestStep.class);
774:                return step == null ? null : step.getName();
775:            }
776:
777:            public void setTargetStepName(String targetStep) {
778:                String old = getTargetStepName();
779:
780:                //	 check for change
781:                if ((targetStep == null && old == null)
782:                        || (targetStep != null && old != null && targetStep
783:                                .equals(old)))
784:                    return;
785:
786:                if (targetStep == null)
787:                    log.debug("Setting targetStep for transfer [" + getName()
788:                            + "] to null");
789:
790:                this .targetStep = targetStep;
791:                config.setTargetStep(targetStep);
792:
793:                if (currentTargetStep != null) {
794:                    currentTargetStep
795:                            .removePropertyChangeListener(stepNameChangeListener);
796:                    ((WsdlTestStep) currentTargetStep)
797:                            .removeTestStepListener(propertyNameChangeListener);
798:                }
799:
800:                currentTargetStep = (WsdlTestStep) (targetStep == null ? null
801:                        : testStep.getTestCase().getTestStepByName(targetStep));
802:                if (currentTargetStep != null) {
803:                    currentTargetStep.addPropertyChangeListener(
804:                            TestStep.NAME_PROPERTY, stepNameChangeListener);
805:                    ((WsdlTestStep) currentTargetStep)
806:                            .addTestStepListener(propertyNameChangeListener);
807:                }
808:
809:                propertyChangeSupport.firePropertyChange(TARGET_STEP_PROPERTY,
810:                        old, targetStep);
811:                setTargetPropertyName(null);
812:            }
813:
814:            public void addPropertyChangeListener(String propertyName,
815:                    PropertyChangeListener listener) {
816:                propertyChangeSupport.addPropertyChangeListener(propertyName,
817:                        listener);
818:            }
819:
820:            public void addPropertyChangeListener(
821:                    PropertyChangeListener listener) {
822:                propertyChangeSupport.addPropertyChangeListener(listener);
823:            }
824:
825:            public void removePropertyChangeListener(
826:                    PropertyChangeListener listener) {
827:                propertyChangeSupport.removePropertyChangeListener(listener);
828:            }
829:
830:            public void removePropertyChangeListener(String propertyName,
831:                    PropertyChangeListener listener) {
832:                propertyChangeSupport.removePropertyChangeListener(
833:                        propertyName, listener);
834:            }
835:
836:            public boolean getFailOnError() {
837:                return config.getFailOnError();
838:            }
839:
840:            public void setFailOnError(boolean failOnError) {
841:                config.setFailOnError(failOnError);
842:            }
843:
844:            public boolean getTransferToAll() {
845:                return config.getTransferToAll();
846:            }
847:
848:            public void setTransferToAll(boolean transferToAll) {
849:                config.setTransferToAll(transferToAll);
850:            }
851:
852:            public boolean getIgnoreEmpty() {
853:                return config.getIgnoreEmpty();
854:            }
855:
856:            public void setIgnoreEmpty(boolean ignoreEmpty) {
857:                config.setIgnoreEmpty(ignoreEmpty);
858:            }
859:
860:            public boolean getSetNullOnMissingSource() {
861:                return config.getSetNullOnMissingSource();
862:            }
863:
864:            public void setSetNullOnMissingSource(boolean setNullOnMissingSource) {
865:                config.setSetNullOnMissingSource(setNullOnMissingSource);
866:            }
867:
868:            public boolean getTransferTextContent() {
869:                return config.getTransferTextContent();
870:            }
871:
872:            public void setTransferTextContent(boolean transferTextContent) {
873:                config.setTransferTextContent(transferTextContent);
874:            }
875:
876:            private final class InternalTestSuiteListener extends
877:                    TestSuiteListenerAdapter {
878:                public void testStepRemoved(TestStep testStep, int index) {
879:                    if (testStep.getTestCase() == testCase) {
880:                        String stepName = testStep.getName();
881:                        if (stepName.equals(sourceStep)) {
882:                            setSourceStepName(null);
883:                        }
884:
885:                        if (stepName.equals(targetStep)) {
886:                            setTargetStepName(null);
887:                        }
888:                    }
889:                }
890:            }
891:
892:            /**
893:             * Handle changes to source/target testStep names
894:             * 
895:             * @author Ole.Matzura
896:             */
897:
898:            private class StepNameChangeListener implements 
899:                    PropertyChangeListener {
900:                public void propertyChange(PropertyChangeEvent evt) {
901:                    String oldName = (String) evt.getOldValue();
902:                    String newValue = (String) evt.getNewValue();
903:
904:                    if (newValue == null) {
905:                        log.error("Tried to change stepname to null!");
906:                        Thread.dumpStack();
907:                        return;
908:                    }
909:
910:                    if (oldName.equals(sourceStep)) {
911:                        sourceStep = newValue;
912:                        config.setSourceStep(sourceStep);
913:                        propertyChangeSupport.firePropertyChange(
914:                                SOURCE_STEP_PROPERTY, oldName, sourceStep);
915:                    }
916:
917:                    if (oldName.equals(targetStep)) {
918:                        targetStep = newValue;
919:                        config.setTargetStep(targetStep);
920:                        propertyChangeSupport.firePropertyChange(
921:                                TARGET_STEP_PROPERTY, oldName, targetStep);
922:                    }
923:                }
924:            }
925:
926:            /**
927:             * Handle changes to source/target property names
928:             * 
929:             * @author Ole.Matzura
930:             */
931:
932:            private class PropertyNameChangeListener extends
933:                    WsdlTestStepListenerAdapter {
934:                public void propertyRenamed(String oldName, String newName) {
935:                    if (oldName.equals(sourceType)) {
936:                        sourceType = newName;
937:                        config.setSourceType(sourceType);
938:                        propertyChangeSupport.firePropertyChange(
939:                                SOURCE_TYPE_PROPERTY, oldName, sourceType);
940:                    }
941:
942:                    if (oldName.equals(targetType)) {
943:                        targetType = newName;
944:                        config.setTargetType(targetType);
945:                        propertyChangeSupport.firePropertyChange(
946:                                TARGET_TYPE_PROPERTY, oldName, targetType);
947:                    }
948:                }
949:
950:                public void propertyRemoved(String name) {
951:                    if (name.equals(sourceType)) {
952:                        log.warn("source property for transfer [" + getName()
953:                                + "] in teststep [" + testStep.getName()
954:                                + "] set to null, was [" + name + "]");
955:
956:                        setSourcePropertyName(null);
957:                    }
958:
959:                    if (name.equals(targetType)) {
960:                        log.warn("target property for transfer [" + getName()
961:                                + "] in teststep [" + testStep.getName()
962:                                + "] set to null, was [" + name + "]");
963:
964:                        setTargetPropertyName(null);
965:                    }
966:                }
967:            }
968:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.