From d9b0b7e43ca9b1969d9048ea3016f9b1b5731526 Mon Sep 17 00:00:00 2001 From: lauzond Date: Thu, 24 Mar 2005 00:07:43 +0000 Subject: [Bug 88955] Check in initial WSI contribution --- .../eclipse/wst/wsi/internal/ToolEnvironment.java | 254 ++ .../org/eclipse/wst/wsi/internal/ToolInfo.java | 465 +++ .../org/eclipse/wst/wsi/internal/URIEncoder.java | 204 ++ .../org/eclipse/wst/wsi/internal/WSIConstants.java | 485 +++ .../org/eclipse/wst/wsi/internal/WSIException.java | 145 + .../wst/wsi/internal/WSIFileNotFoundException.java | 51 + .../eclipse/wst/wsi/internal/WSIPreferences.java | 73 + .../wst/wsi/internal/WSIRuntimeException.java | 50 + .../org/eclipse/wst/wsi/internal/WSITag.java | 114 + .../wst/wsi/internal/WSITestToolsPlugin.java | 74 + .../wst/wsi/internal/WSITestToolsProperties.java | 207 ++ .../wst/wsi/internal/analyzer/Analyzer.java | 313 ++ .../wst/wsi/internal/analyzer/Analyzer.properties | 44 + .../wst/wsi/internal/analyzer/AnalyzerContext.java | 113 + .../internal/analyzer/AssertionFailException.java | 43 + .../analyzer/AssertionNotApplicableException.java | 43 + .../internal/analyzer/AssertionPassException.java | 43 + .../analyzer/AssertionResultException.java | 65 + .../internal/analyzer/BasicProfileAnalyzer.java | 655 ++++ .../wst/wsi/internal/analyzer/CandidateInfo.java | 921 ++++++ .../wst/wsi/internal/analyzer/EnvironmentInfo.java | 82 + .../wst/wsi/internal/analyzer/MessageAnalyzer.java | 325 ++ .../wsi/internal/analyzer/ServiceReference.java | 109 + .../wst/wsi/internal/analyzer/WSDLAnalyzer.java | 382 +++ .../internal/analyzer/WSIAnalyzerException.java | 82 + .../internal/analyzer/WSIBasicProfileAnalyzer.java | 87 + .../internal/analyzer/config/AnalyzerConfig.java | 256 ++ .../analyzer/config/AnalyzerConfigReader.java | 51 + .../analyzer/config/AssertionResultType.java | 160 + .../analyzer/config/AssertionResultsOption.java | 100 + .../internal/analyzer/config/UDDIReference.java | 116 + .../wsi/internal/analyzer/config/WSDLElement.java | 135 + .../internal/analyzer/config/WSDLReference.java | 78 + .../analyzer/config/impl/AnalyzerConfigImpl.java | 1060 +++++++ .../config/impl/AnalyzerConfigReaderImpl.java | 570 ++++ .../config/impl/AssertionResultsOptionImpl.java | 199 ++ .../analyzer/config/impl/UDDIReferenceImpl.java | 197 ++ .../analyzer/config/impl/WSDLElementImpl.java | 201 ++ .../analyzer/config/impl/WSDLReferenceImpl.java | 162 + .../wst/wsi/internal/common/AddStyleSheet.java | 124 + .../internal/common/impl/AddStyleSheetImpl.java | 219 ++ .../wst/wsi/internal/document/DocumentElement.java | 28 + .../wst/wsi/internal/document/DocumentFactory.java | 175 ++ .../wst/wsi/internal/document/DocumentReader.java | 34 + .../wst/wsi/internal/document/DocumentWriter.java | 67 + .../wst/wsi/internal/document/WSIDocument.java | 34 + .../document/impl/DocumentFactoryImpl.java | 157 + .../internal/document/impl/DocumentWriterImpl.java | 125 + .../document/impl/WSIDocumentFactoryImpl.java | 54 + .../org/eclipse/wst/wsi/internal/log/Log.java | 98 + .../eclipse/wst/wsi/internal/log/LogReader.java | 48 + .../eclipse/wst/wsi/internal/log/LogWriter.java | 47 + .../eclipse/wst/wsi/internal/log/MessageEntry.java | 217 ++ .../wst/wsi/internal/log/MessageEntryHandler.java | 41 + .../org/eclipse/wst/wsi/internal/log/MimePart.java | 75 + .../eclipse/wst/wsi/internal/log/MimeParts.java | 60 + .../eclipse/wst/wsi/internal/log/impl/LogImpl.java | 219 ++ .../wst/wsi/internal/log/impl/LogReaderImpl.java | 782 +++++ .../wst/wsi/internal/log/impl/LogWriterImpl.java | 51 + .../wsi/internal/log/impl/MessageEntryImpl.java | 374 +++ .../wst/wsi/internal/log/impl/MimePartImpl.java | 135 + .../wst/wsi/internal/log/impl/MimePartsImpl.java | 75 + .../wst/wsi/internal/monitor/ChunkedData.java | 225 ++ .../wsi/internal/monitor/ConnectionListener.java | 26 + .../wsi/internal/monitor/MessageEntryQueue.java | 220 ++ .../eclipse/wst/wsi/internal/monitor/Monitor.java | 501 +++ .../wst/wsi/internal/monitor/Monitor.properties | 38 + .../wsi/internal/monitor/ServerSocketListener.java | 140 + .../wst/wsi/internal/monitor/SocketConnection.java | 305 ++ .../wst/wsi/internal/monitor/SocketHandler.java | 966 ++++++ .../wst/wsi/internal/monitor/config/Comment.java | 50 + .../internal/monitor/config/ManInTheMiddle.java | 72 + .../wsi/internal/monitor/config/MonitorConfig.java | 165 + .../monitor/config/MonitorConfigReader.java | 49 + .../wst/wsi/internal/monitor/config/Redirect.java | 124 + .../internal/monitor/config/impl/CommentImpl.java | 75 + .../monitor/config/impl/ManInTheMiddleImpl.java | 142 + .../monitor/config/impl/MonitorConfigImpl.java | 556 ++++ .../config/impl/MonitorConfigReaderImpl.java | 474 +++ .../internal/monitor/config/impl/RedirectImpl.java | 297 ++ .../wst/wsi/internal/profile/EntryTypeList.java | 82 + .../eclipse/wst/wsi/internal/profile/Profile.java | 24 + .../wst/wsi/internal/profile/ProfileArtifact.java | 86 + .../wsi/internal/profile/ProfileAssertions.java | 123 + .../internal/profile/ProfileAssertionsReader.java | 44 + .../wst/wsi/internal/profile/TestAssertion.java | 176 ++ .../internal/profile/impl/EntryTypeListImpl.java | 94 + .../internal/profile/impl/ProfileArtifactImpl.java | 123 + .../profile/impl/ProfileAssertionsImpl.java | 194 ++ .../profile/impl/ProfileAssertionsReaderImpl.java | 515 +++ .../internal/profile/impl/TestAssertionImpl.java | 256 ++ .../internal/profile/validator/BaseValidator.java | 51 + .../internal/profile/validator/EntryContext.java | 223 ++ .../profile/validator/EnvelopeValidator.java | 52 + .../profile/validator/MessageValidator.java | 68 + .../profile/validator/ProfileValidatorFactory.java | 96 + .../internal/profile/validator/UDDIValidator.java | 54 + .../internal/profile/validator/WSDLValidator.java | 55 + .../profile/validator/impl/AssertionProcess.java | 66 + .../validator/impl/AssertionProcessVisitor.java | 157 + .../validator/impl/BaseMessageValidator.java | 1839 +++++++++++ .../profile/validator/impl/BaseValidatorImpl.java | 714 +++++ .../impl/ProfileValidatorFactoryImpl.java | 75 + .../profile/validator/impl/envelope/AP1920.java | 118 + .../profile/validator/impl/envelope/AP1928.java | 426 +++ .../profile/validator/impl/envelope/BP1005.java | 167 + .../profile/validator/impl/envelope/BP1007.java | 64 + .../profile/validator/impl/envelope/BP1008.java | 277 ++ .../profile/validator/impl/envelope/BP1009.java | 315 ++ .../profile/validator/impl/envelope/BP1011.java | 203 ++ .../profile/validator/impl/envelope/BP1012.java | 102 + .../profile/validator/impl/envelope/BP1013.java | 29 + .../profile/validator/impl/envelope/BP1031.java | 108 + .../profile/validator/impl/envelope/BP1032.java | 152 + .../profile/validator/impl/envelope/BP1033.java | 126 + .../profile/validator/impl/envelope/BP1100.java | 103 + .../profile/validator/impl/envelope/BP1107.java | 277 ++ .../profile/validator/impl/envelope/BP1201.java | 77 + .../profile/validator/impl/envelope/BP1202.java | 104 + .../profile/validator/impl/envelope/BP1203.java | 147 + .../profile/validator/impl/envelope/BP1204.java | 302 ++ .../profile/validator/impl/envelope/BP1208.java | 88 + .../profile/validator/impl/envelope/BP1211.java | 147 + .../profile/validator/impl/envelope/BP1212.java | 165 + .../profile/validator/impl/envelope/BP1213.java | 141 + .../profile/validator/impl/envelope/BP1214.java | 142 + .../profile/validator/impl/envelope/BP1301.java | 198 ++ .../profile/validator/impl/envelope/BP1302.java | 181 ++ .../profile/validator/impl/envelope/BP1305.java | 132 + .../profile/validator/impl/envelope/BP1306.java | 114 + .../profile/validator/impl/envelope/BP1307.java | 98 + .../profile/validator/impl/envelope/BP1308.java | 97 + .../profile/validator/impl/envelope/BP1309.java | 124 + .../profile/validator/impl/envelope/BP1316.java | 113 + .../profile/validator/impl/envelope/BP1318.java | 183 ++ .../profile/validator/impl/envelope/BP1600.java | 267 ++ .../profile/validator/impl/envelope/BP1601.java | 73 + .../profile/validator/impl/envelope/BP1701.java | 111 + .../profile/validator/impl/envelope/BP1755.java | 167 + .../profile/validator/impl/envelope/BP4100.java | 226 ++ .../profile/validator/impl/envelope/BP4101.java | 132 + .../profile/validator/impl/envelope/BP4102.java | 114 + .../profile/validator/impl/envelope/BP4109.java | 107 + .../impl/envelope/EnvelopeValidatorImpl.java | 56 + .../profile/validator/impl/envelope/SSBP1601.java | 28 + .../profile/validator/impl/envelope/SSBP9704.java | 126 + .../profile/validator/impl/message/AP1003.java | 59 + .../profile/validator/impl/message/AP1902.java | 124 + .../profile/validator/impl/message/AP1915.java | 136 + .../profile/validator/impl/message/AP1917.java | 153 + .../profile/validator/impl/message/AP1925.java | 136 + .../profile/validator/impl/message/AP1926.java | 210 ++ .../profile/validator/impl/message/AP1931.java | 91 + .../profile/validator/impl/message/AP1932.java | 80 + .../profile/validator/impl/message/AP1933.java | 257 ++ .../profile/validator/impl/message/AP1934.java | 103 + .../profile/validator/impl/message/AP1935.java | 348 +++ .../profile/validator/impl/message/AP1936.java | 72 + .../profile/validator/impl/message/AP1942.java | 264 ++ .../profile/validator/impl/message/AP1945.java | 73 + .../profile/validator/impl/message/AP1946.java | 64 + .../profile/validator/impl/message/AP5100.java | 53 + .../profile/validator/impl/message/AP5101.java | 51 + .../profile/validator/impl/message/BP1001.java | 101 + .../profile/validator/impl/message/BP1002.java | 137 + .../profile/validator/impl/message/BP1004.java | 73 + .../profile/validator/impl/message/BP1006.java | 69 + .../profile/validator/impl/message/BP1010.java | 126 + .../profile/validator/impl/message/BP1101.java | 86 + .../profile/validator/impl/message/BP1103.java | 80 + .../profile/validator/impl/message/BP1104.java | 93 + .../profile/validator/impl/message/BP1116.java | 150 + .../profile/validator/impl/message/BP4103.java | 126 + .../profile/validator/impl/message/BP4104.java | 87 + .../profile/validator/impl/message/BP4105.java | 95 + .../profile/validator/impl/message/BP4106.java | 77 + .../profile/validator/impl/message/BP4107.java | 66 + .../impl/message/MessageValidatorImpl.java | 57 + .../profile/validator/impl/message/SSBP1003.java | 228 ++ .../profile/validator/impl/message/SSBP5100.java | 80 + .../profile/validator/impl/message/SSBP5101.java | 67 + .../profile/validator/impl/message/WSI1001.java | 28 + .../profile/validator/impl/message/WSI1002.java | 28 + .../profile/validator/impl/message/WSI1003.java | 28 + .../profile/validator/impl/message/WSI1004.java | 28 + .../profile/validator/impl/message/WSI1005.java | 29 + .../profile/validator/impl/message/WSI1006.java | 28 + .../profile/validator/impl/message/WSI1007.java | 29 + .../profile/validator/impl/message/WSI1008.java | 29 + .../profile/validator/impl/message/WSI1009.java | 29 + .../profile/validator/impl/message/WSI1010.java | 28 + .../profile/validator/impl/message/WSI1011.java | 29 + .../profile/validator/impl/message/WSI1012.java | 29 + .../profile/validator/impl/message/WSI1013.java | 29 + .../profile/validator/impl/message/WSI1031.java | 29 + .../profile/validator/impl/message/WSI1100.java | 29 + .../profile/validator/impl/message/WSI1101.java | 28 + .../profile/validator/impl/message/WSI1102.java | 150 + .../profile/validator/impl/message/WSI1103.java | 28 + .../profile/validator/impl/message/WSI1104.java | 29 + .../profile/validator/impl/message/WSI1105.java | 110 + .../profile/validator/impl/message/WSI1107.java | 29 + .../profile/validator/impl/message/WSI1108.java | 415 +++ .../profile/validator/impl/message/WSI1109.java | 103 + .../profile/validator/impl/message/WSI1110.java | 104 + .../profile/validator/impl/message/WSI1111.java | 111 + .../profile/validator/impl/message/WSI1116.java | 28 + .../profile/validator/impl/message/WSI1121.java | 162 + .../profile/validator/impl/message/WSI1201.java | 29 + .../profile/validator/impl/message/WSI1202.java | 29 + .../profile/validator/impl/message/WSI1203.java | 29 + .../profile/validator/impl/message/WSI1204.java | 29 + .../profile/validator/impl/message/WSI1208.java | 29 + .../profile/validator/impl/message/WSI1211.java | 29 + .../profile/validator/impl/message/WSI1301.java | 29 + .../profile/validator/impl/message/WSI1302.java | 29 + .../profile/validator/impl/message/WSI1305.java | 29 + .../profile/validator/impl/message/WSI1306.java | 29 + .../profile/validator/impl/message/WSI1307.java | 29 + .../profile/validator/impl/message/WSI1308.java | 29 + .../profile/validator/impl/message/WSI1309.java | 29 + .../profile/validator/impl/message/WSI1311.java | 204 ++ .../profile/validator/impl/message/WSI1316.java | 29 + .../profile/validator/impl/message/WSI1318.java | 29 + .../profile/validator/impl/message/WSI1601.java | 29 + .../profile/validator/impl/message/WSI1701.java | 29 + .../profile/validator/impl/message/WSI4100.java | 29 + .../profile/validator/impl/message/WSI4101.java | 29 + .../profile/validator/impl/message/WSI4102.java | 29 + .../profile/validator/impl/message/WSI4103.java | 28 + .../profile/validator/impl/message/WSI4104.java | 28 + .../profile/validator/impl/message/WSI4105.java | 28 + .../profile/validator/impl/message/WSI4106.java | 28 + .../profile/validator/impl/message/WSI4107.java | 28 + .../profile/validator/impl/uddi/BP3001.java | 160 + .../profile/validator/impl/uddi/BP3002.java | 81 + .../profile/validator/impl/uddi/BP3003.java | 84 + .../validator/impl/uddi/UDDIValidatorImpl.java | 594 ++++ .../profile/validator/impl/uddi/WSI3001.java | 26 + .../profile/validator/impl/uddi/WSI3002.java | 26 + .../profile/validator/impl/uddi/WSI3003.java | 26 + .../profile/validator/impl/uddi/WSI3004.java | 290 ++ .../validator/impl/uddi/WSI3005_OBSOLETE.java | 119 + .../profile/validator/impl/uddi/WSI3006.java | 165 + .../profile/validator/impl/uddi/WSI3007.java | 157 + .../profile/validator/impl/uddi/WSI3021.java | 115 + .../profile/validator/impl/wsdl/AP2901.java | 146 + .../profile/validator/impl/wsdl/AP2903.java | 241 ++ .../profile/validator/impl/wsdl/AP2904.java | 50 + .../profile/validator/impl/wsdl/AP2906.java | 216 ++ .../profile/validator/impl/wsdl/AP2907.java | 52 + .../profile/validator/impl/wsdl/AP2908.java | 297 ++ .../profile/validator/impl/wsdl/AP2909.java | 215 ++ .../profile/validator/impl/wsdl/AP2910.java | 230 ++ .../profile/validator/impl/wsdl/AP2911.java | 228 ++ .../profile/validator/impl/wsdl/AP2930.java | 136 + .../profile/validator/impl/wsdl/AP2940.java | 450 +++ .../profile/validator/impl/wsdl/AP2941.java | 341 ++ .../profile/validator/impl/wsdl/AP2944.java | 234 ++ .../profile/validator/impl/wsdl/AP2946.java | 194 ++ .../profile/validator/impl/wsdl/BP2010.java | 119 + .../profile/validator/impl/wsdl/BP2011.java | 343 ++ .../profile/validator/impl/wsdl/BP2012.java | 123 + .../profile/validator/impl/wsdl/BP2013.java | 91 + .../profile/validator/impl/wsdl/BP2014.java | 286 ++ .../profile/validator/impl/wsdl/BP2017.java | 142 + .../profile/validator/impl/wsdl/BP2018.java | 195 ++ .../profile/validator/impl/wsdl/BP2019.java | 124 + .../profile/validator/impl/wsdl/BP2020.java | 162 + .../profile/validator/impl/wsdl/BP2021.java | 112 + .../profile/validator/impl/wsdl/BP2022.java | 82 + .../profile/validator/impl/wsdl/BP2023.java | 85 + .../profile/validator/impl/wsdl/BP2032.java | 86 + .../profile/validator/impl/wsdl/BP2034.java | 94 + .../profile/validator/impl/wsdl/BP2098.java | 69 + .../profile/validator/impl/wsdl/BP2101.java | 118 + .../profile/validator/impl/wsdl/BP2102.java | 203 ++ .../profile/validator/impl/wsdl/BP2103.java | 130 + .../profile/validator/impl/wsdl/BP2104.java | 100 + .../profile/validator/impl/wsdl/BP2105.java | 232 ++ .../profile/validator/impl/wsdl/BP2107.java | 202 ++ .../profile/validator/impl/wsdl/BP2108.java | 94 + .../profile/validator/impl/wsdl/BP2110.java | 98 + .../profile/validator/impl/wsdl/BP2111.java | 142 + .../profile/validator/impl/wsdl/BP2112.java | 204 ++ .../profile/validator/impl/wsdl/BP2113.java | 159 + .../profile/validator/impl/wsdl/BP2114.java | 278 ++ .../profile/validator/impl/wsdl/BP2115.java | 97 + .../profile/validator/impl/wsdl/BP2116.java | 88 + .../profile/validator/impl/wsdl/BP2117.java | 183 ++ .../profile/validator/impl/wsdl/BP2118.java | 98 + .../profile/validator/impl/wsdl/BP2119.java | 165 + .../profile/validator/impl/wsdl/BP2120.java | 247 ++ .../profile/validator/impl/wsdl/BP2121.java | 174 ++ .../profile/validator/impl/wsdl/BP2122.java | 109 + .../profile/validator/impl/wsdl/BP2123.java | 357 +++ .../profile/validator/impl/wsdl/BP2201.java | 189 ++ .../profile/validator/impl/wsdl/BP2202.java | 423 +++ .../profile/validator/impl/wsdl/BP2208.java | 72 + .../profile/validator/impl/wsdl/BP2402.java | 69 + .../profile/validator/impl/wsdl/BP2404.java | 76 + .../profile/validator/impl/wsdl/BP2406.java | 166 + .../profile/validator/impl/wsdl/BP2416.java | 209 ++ .../profile/validator/impl/wsdl/BP2417.java | 160 + .../profile/validator/impl/wsdl/BP2700.java | 82 + .../profile/validator/impl/wsdl/BP2701.java | 89 + .../profile/validator/impl/wsdl/BP2703.java | 111 + .../profile/validator/impl/wsdl/BP2803.java | 87 + .../profile/validator/impl/wsdl/BP4200.java | 162 + .../profile/validator/impl/wsdl/BP4201.java | 144 + .../profile/validator/impl/wsdl/BP4202.java | 135 + .../profile/validator/impl/wsdl/SSBP2209.java | 29 + .../profile/validator/impl/wsdl/SSBP2402.java | 26 + .../profile/validator/impl/wsdl/SSBP2403.java | 191 ++ .../validator/impl/wsdl/WSDLValidatorImpl.java | 2319 ++++++++++++++ .../profile/validator/impl/wsdl/WSI2010.java | 26 + .../profile/validator/impl/wsdl/WSI2011.java | 26 + .../profile/validator/impl/wsdl/WSI2012.java | 26 + .../profile/validator/impl/wsdl/WSI2013.java | 26 + .../profile/validator/impl/wsdl/WSI2014.java | 26 + .../profile/validator/impl/wsdl/WSI2017.java | 26 + .../profile/validator/impl/wsdl/WSI2018.java | 26 + .../profile/validator/impl/wsdl/WSI2019.java | 26 + .../profile/validator/impl/wsdl/WSI2020.java | 26 + .../profile/validator/impl/wsdl/WSI2021.java | 26 + .../profile/validator/impl/wsdl/WSI2022.java | 26 + .../profile/validator/impl/wsdl/WSI2032.java | 26 + .../profile/validator/impl/wsdl/WSI2098.java | 26 + .../profile/validator/impl/wsdl/WSI2099.java | 157 + .../profile/validator/impl/wsdl/WSI2100.java | 171 + .../profile/validator/impl/wsdl/WSI2101.java | 26 + .../profile/validator/impl/wsdl/WSI2102.java | 26 + .../profile/validator/impl/wsdl/WSI2103.java | 26 + .../profile/validator/impl/wsdl/WSI2104.java | 26 + .../profile/validator/impl/wsdl/WSI2105.java | 26 + .../profile/validator/impl/wsdl/WSI2107.java | 26 + .../profile/validator/impl/wsdl/WSI2108.java | 26 + .../profile/validator/impl/wsdl/WSI2110.java | 26 + .../profile/validator/impl/wsdl/WSI2111.java | 26 + .../profile/validator/impl/wsdl/WSI2112.java | 26 + .../profile/validator/impl/wsdl/WSI2113.java | 26 + .../profile/validator/impl/wsdl/WSI2114.java | 26 + .../profile/validator/impl/wsdl/WSI2115.java | 26 + .../profile/validator/impl/wsdl/WSI2116.java | 26 + .../profile/validator/impl/wsdl/WSI2117.java | 26 + .../profile/validator/impl/wsdl/WSI2118.java | 26 + .../profile/validator/impl/wsdl/WSI2119.java | 26 + .../profile/validator/impl/wsdl/WSI2120.java | 26 + .../profile/validator/impl/wsdl/WSI2122.java | 26 + .../profile/validator/impl/wsdl/WSI2123.java | 26 + .../profile/validator/impl/wsdl/WSI2201.java | 26 + .../profile/validator/impl/wsdl/WSI2202.java | 26 + .../profile/validator/impl/wsdl/WSI2208.java | 26 + .../profile/validator/impl/wsdl/WSI2402.java | 26 + .../profile/validator/impl/wsdl/WSI2403.java | 26 + .../profile/validator/impl/wsdl/WSI2404.java | 26 + .../profile/validator/impl/wsdl/WSI2406.java | 26 + .../profile/validator/impl/wsdl/WSI2416.java | 26 + .../profile/validator/impl/wsdl/WSI2417.java | 26 + .../profile/validator/impl/wsdl/WSI2700.java | 26 + .../profile/validator/impl/wsdl/WSI2701.java | 26 + .../profile/validator/impl/wsdl/WSI2703.java | 26 + .../profile/validator/impl/wsdl/WSI4200.java | 26 + .../profile/validator/impl/wsdl/WSI4201.java | 26 + .../profile/validator/impl/wsdl/WSI4202.java | 26 + .../wst/wsi/internal/report/ArtifactReference.java | 67 + .../wst/wsi/internal/report/AssertionError.java | 131 + .../wst/wsi/internal/report/AssertionResult.java | 148 + .../wst/wsi/internal/report/BuildReport.java | 125 + .../org/eclipse/wst/wsi/internal/report/Entry.java | 153 + .../wst/wsi/internal/report/EntryContainer.java | 35 + .../wst/wsi/internal/report/EntryResult.java | 42 + .../wst/wsi/internal/report/FailureDetail.java | 94 + .../wst/wsi/internal/report/PrereqFailedList.java | 43 + .../eclipse/wst/wsi/internal/report/Report.java | 105 + .../wst/wsi/internal/report/ReportArtifact.java | 79 + .../wst/wsi/internal/report/ReportContext.java | 116 + .../wst/wsi/internal/report/ReportWriter.java | 40 + .../eclipse/wst/wsi/internal/report/Reporter.java | 21 + .../wst/wsi/internal/report/WriteReport.java | 47 + .../report/impl/ArtifactReferenceImpl.java | 124 + .../internal/report/impl/AssertionResultImpl.java | 236 ++ .../wsi/internal/report/impl/DefaultReporter.java | 287 ++ .../internal/report/impl/EntryContainerImpl.java | 56 + .../wst/wsi/internal/report/impl/EntryImpl.java | 276 ++ .../wsi/internal/report/impl/EntryResultImpl.java | 56 + .../internal/report/impl/FailureDetailImpl.java | 150 + .../internal/report/impl/PrereqFailedListImpl.java | 74 + .../internal/report/impl/ReportArtifactImpl.java | 115 + .../wst/wsi/internal/report/impl/ReportImpl.java | 514 +++ .../internal/report/impl/ReportNoWriterImpl.java | 84 + .../wsi/internal/report/impl/ReportWriterImpl.java | 63 + .../eclipse/wst/wsi/internal/toolinfo.properties | 18 + .../wst/wsi/internal/util/ArtifactType.java | 140 + .../eclipse/wst/wsi/internal/util/BasicRules.java | 479 +++ .../eclipse/wst/wsi/internal/util/EntryType.java | 278 ++ .../eclipse/wst/wsi/internal/util/ErrorList.java | 156 + .../wst/wsi/internal/util/HTTPConstants.java | 600 ++++ .../eclipse/wst/wsi/internal/util/HTTPUtils.java | 182 ++ .../wsi/internal/util/HttpHeadersValidator.java | 1739 +++++++++++ .../wst/wsi/internal/util/JavaEncoding.properties | 31 + .../wst/wsi/internal/util/MIMEConstants.java | 24 + .../eclipse/wst/wsi/internal/util/MIMEUtils.java | 138 + .../eclipse/wst/wsi/internal/util/MessageList.java | 171 + .../eclipse/wst/wsi/internal/util/NullUtil.java | 40 + .../wst/wsi/internal/util/OperationSignature.java | 772 +++++ .../org/eclipse/wst/wsi/internal/util/Pair.java | 77 + .../wst/wsi/internal/util/SetCookie2Validator.java | 649 ++++ .../wst/wsi/internal/util/StringTokenizer.java | 213 ++ .../eclipse/wst/wsi/internal/util/TestUtils.java | 192 ++ .../wst/wsi/internal/util/TypesRegistry.java | 559 ++++ .../eclipse/wst/wsi/internal/util/UDDIUtils.java | 336 ++ .../org/eclipse/wst/wsi/internal/util/Utils.java | 1418 +++++++++ .../eclipse/wst/wsi/internal/util/WSDLUtil.java | 154 + .../wst/wsi/internal/util/WSIProperties.java | 344 ++ .../org/eclipse/wst/wsi/internal/util/XMLInfo.java | 27 + .../eclipse/wst/wsi/internal/util/wsi.properties | 46 + .../wst/wsi/internal/wsdl/WSDLDocument.java | 290 ++ .../wst/wsi/internal/wsdl/WSDLElementList.java | 98 + .../wst/wsi/internal/wsdl/WSDLReaderImpl.java | 766 +++++ .../eclipse/wst/wsi/internal/wsdl/WSDLUtils.java | 383 +++ .../internal/wsdl/traversal/VisitorAdaptor.java | 205 ++ .../wsi/internal/wsdl/traversal/WSDLTraversal.java | 3270 ++++++++++++++++++++ .../wsdl/traversal/WSDLTraversalContext.java | 1125 +++++++ .../wsi/internal/wsdl/traversal/WSDLVisitor.java | 232 ++ .../wsi/internal/wsdl/xsd/FileEntityResolver.java | 59 + .../internal/wsdl/xsd/InlineSchemaGenerator.java | 591 ++++ .../internal/wsdl/xsd/InlineSchemaValidator.java | 242 ++ .../wsi/internal/wsdl/xsd/InlineXSDResolver.java | 112 + .../internal/wsdl/xsd/SchemaAttributeTable.java | 105 + .../internal/wsdl/xsd/ValidateErrorHandler.java | 62 + .../wst/wsi/internal/wsdl/xsd/XMLCatalog.java | 90 + .../wst/wsi/internal/wsdl/xsd/XMLCatalogImpl.java | 45 + .../wsi/internal/wsdl/xsd/XMLCatalogResolver.java | 67 + .../internal/wsdl/xsd/XMLEntityResolverChain.java | 74 + .../wst/wsi/internal/wsdl/xsd/XSDValidator.java | 191 ++ .../eclipse/wst/wsi/internal/xml/XMLConvertor.java | 69 + .../wst/wsi/internal/xml/XMLDocumentCache.java | 65 + .../wst/wsi/internal/xml/XMLDocumentCacheUser.java | 122 + .../org/eclipse/wst/wsi/internal/xml/XMLTags.java | 60 + .../eclipse/wst/wsi/internal/xml/XMLTraversal.java | 129 + .../org/eclipse/wst/wsi/internal/xml/XMLUtils.java | 1503 +++++++++ .../eclipse/wst/wsi/internal/xml/XMLVisitor.java | 175 ++ .../wst/wsi/internal/xml/dom/DOMParser.java | 96 + .../wst/wsi/internal/xml/dom/ElementLocation.java | 92 + .../xml/jaxp/DocumentBuilderFactoryImpl.java | 86 + .../wsi/internal/xml/jaxp/DocumentBuilderImpl.java | 249 ++ .../xml/schema/TargetNamespaceProcessor.java | 136 + .../internal/xml/schema/XMLSchemaProcessor.java | 163 + .../internal/xml/schema/XMLSchemaValidator.java | 156 + 450 files changed, 74645 insertions(+) create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/ToolEnvironment.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/ToolInfo.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/URIEncoder.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/WSIConstants.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/WSIException.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/WSIFileNotFoundException.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/WSIPreferences.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/WSIRuntimeException.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/WSITag.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/WSITestToolsPlugin.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/WSITestToolsProperties.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/Analyzer.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/Analyzer.properties create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/AnalyzerContext.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/AssertionFailException.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/AssertionNotApplicableException.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/AssertionPassException.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/AssertionResultException.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/BasicProfileAnalyzer.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/CandidateInfo.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/EnvironmentInfo.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/MessageAnalyzer.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/ServiceReference.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/WSDLAnalyzer.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/WSIAnalyzerException.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/WSIBasicProfileAnalyzer.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/config/AnalyzerConfig.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/config/AnalyzerConfigReader.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/config/AssertionResultType.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/config/AssertionResultsOption.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/config/UDDIReference.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/config/WSDLElement.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/config/WSDLReference.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/config/impl/AnalyzerConfigImpl.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/config/impl/AnalyzerConfigReaderImpl.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/config/impl/AssertionResultsOptionImpl.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/config/impl/UDDIReferenceImpl.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/config/impl/WSDLElementImpl.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/config/impl/WSDLReferenceImpl.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/common/AddStyleSheet.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/common/impl/AddStyleSheetImpl.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/document/DocumentElement.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/document/DocumentFactory.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/document/DocumentReader.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/document/DocumentWriter.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/document/WSIDocument.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/document/impl/DocumentFactoryImpl.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/document/impl/DocumentWriterImpl.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/document/impl/WSIDocumentFactoryImpl.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/log/Log.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/log/LogReader.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/log/LogWriter.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/log/MessageEntry.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/log/MessageEntryHandler.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/log/MimePart.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/log/MimeParts.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/log/impl/LogImpl.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/log/impl/LogReaderImpl.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/log/impl/LogWriterImpl.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/log/impl/MessageEntryImpl.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/log/impl/MimePartImpl.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/log/impl/MimePartsImpl.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/ChunkedData.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/ConnectionListener.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/MessageEntryQueue.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/Monitor.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/Monitor.properties create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/ServerSocketListener.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/SocketConnection.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/SocketHandler.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/config/Comment.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/config/ManInTheMiddle.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/config/MonitorConfig.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/config/MonitorConfigReader.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/config/Redirect.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/config/impl/CommentImpl.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/config/impl/ManInTheMiddleImpl.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/config/impl/MonitorConfigImpl.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/config/impl/MonitorConfigReaderImpl.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/config/impl/RedirectImpl.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/EntryTypeList.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/Profile.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/ProfileArtifact.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/ProfileAssertions.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/ProfileAssertionsReader.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/TestAssertion.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/impl/EntryTypeListImpl.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/impl/ProfileArtifactImpl.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/impl/ProfileAssertionsImpl.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/impl/ProfileAssertionsReaderImpl.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/impl/TestAssertionImpl.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/BaseValidator.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/EntryContext.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/EnvelopeValidator.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/MessageValidator.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/ProfileValidatorFactory.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/UDDIValidator.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/WSDLValidator.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/AssertionProcess.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/AssertionProcessVisitor.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/BaseMessageValidator.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/BaseValidatorImpl.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/ProfileValidatorFactoryImpl.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/AP1920.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/AP1928.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1005.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1007.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1008.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1009.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1011.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1012.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1013.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1031.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1032.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1033.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1100.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1107.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1201.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1202.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1203.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1204.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1208.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1211.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1212.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1213.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1214.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1301.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1302.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1305.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1306.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1307.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1308.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1309.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1316.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1318.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1600.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1601.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1701.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1755.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP4100.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP4101.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP4102.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP4109.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/EnvelopeValidatorImpl.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/SSBP1601.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/SSBP9704.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/AP1003.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/AP1902.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/AP1915.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/AP1917.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/AP1925.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/AP1926.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/AP1931.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/AP1932.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/AP1933.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/AP1934.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/AP1935.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/AP1936.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/AP1942.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/AP1945.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/AP1946.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/AP5100.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/AP5101.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/BP1001.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/BP1002.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/BP1004.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/BP1006.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/BP1010.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/BP1101.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/BP1103.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/BP1104.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/BP1116.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/BP4103.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/BP4104.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/BP4105.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/BP4106.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/BP4107.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/MessageValidatorImpl.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/SSBP1003.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/SSBP5100.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/SSBP5101.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1001.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1002.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1003.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1004.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1005.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1006.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1007.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1008.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1009.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1010.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1011.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1012.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1013.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1031.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1100.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1101.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1102.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1103.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1104.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1105.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1107.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1108.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1109.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1110.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1111.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1116.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1121.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1201.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1202.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1203.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1204.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1208.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1211.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1301.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1302.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1305.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1306.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1307.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1308.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1309.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1311.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1316.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1318.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1601.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1701.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI4100.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI4101.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI4102.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI4103.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI4104.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI4105.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI4106.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI4107.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/uddi/BP3001.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/uddi/BP3002.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/uddi/BP3003.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/uddi/UDDIValidatorImpl.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/uddi/WSI3001.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/uddi/WSI3002.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/uddi/WSI3003.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/uddi/WSI3004.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/uddi/WSI3005_OBSOLETE.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/uddi/WSI3006.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/uddi/WSI3007.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/uddi/WSI3021.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/AP2901.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/AP2903.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/AP2904.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/AP2906.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/AP2907.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/AP2908.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/AP2909.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/AP2910.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/AP2911.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/AP2930.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/AP2940.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/AP2941.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/AP2944.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/AP2946.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2010.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2011.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2012.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2013.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2014.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2017.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2018.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2019.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2020.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2021.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2022.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2023.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2032.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2034.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2098.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2101.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2102.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2103.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2104.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2105.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2107.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2108.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2110.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2111.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2112.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2113.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2114.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2115.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2116.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2117.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2118.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2119.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2120.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2121.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2122.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2123.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2201.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2202.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2208.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2402.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2404.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2406.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2416.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2417.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2700.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2701.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2703.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2803.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP4200.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP4201.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP4202.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/SSBP2209.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/SSBP2402.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/SSBP2403.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSDLValidatorImpl.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2010.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2011.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2012.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2013.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2014.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2017.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2018.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2019.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2020.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2021.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2022.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2032.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2098.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2099.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2100.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2101.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2102.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2103.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2104.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2105.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2107.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2108.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2110.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2111.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2112.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2113.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2114.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2115.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2116.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2117.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2118.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2119.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2120.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2122.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2123.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2201.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2202.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2208.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2402.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2403.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2404.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2406.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2416.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2417.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2700.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2701.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2703.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI4200.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI4201.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI4202.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/ArtifactReference.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/AssertionError.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/AssertionResult.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/BuildReport.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/Entry.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/EntryContainer.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/EntryResult.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/FailureDetail.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/PrereqFailedList.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/Report.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/ReportArtifact.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/ReportContext.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/ReportWriter.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/Reporter.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/WriteReport.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/impl/ArtifactReferenceImpl.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/impl/AssertionResultImpl.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/impl/DefaultReporter.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/impl/EntryContainerImpl.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/impl/EntryImpl.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/impl/EntryResultImpl.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/impl/FailureDetailImpl.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/impl/PrereqFailedListImpl.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/impl/ReportArtifactImpl.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/impl/ReportImpl.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/impl/ReportNoWriterImpl.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/impl/ReportWriterImpl.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/toolinfo.properties create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/ArtifactType.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/BasicRules.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/EntryType.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/ErrorList.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/HTTPConstants.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/HTTPUtils.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/HttpHeadersValidator.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/JavaEncoding.properties create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/MIMEConstants.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/MIMEUtils.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/MessageList.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/NullUtil.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/OperationSignature.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/Pair.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/SetCookie2Validator.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/StringTokenizer.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/TestUtils.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/TypesRegistry.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/UDDIUtils.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/Utils.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/WSDLUtil.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/WSIProperties.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/XMLInfo.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/wsi.properties create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/WSDLDocument.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/WSDLElementList.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/WSDLReaderImpl.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/WSDLUtils.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/traversal/VisitorAdaptor.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/traversal/WSDLTraversal.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/traversal/WSDLTraversalContext.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/traversal/WSDLVisitor.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/xsd/FileEntityResolver.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/xsd/InlineSchemaGenerator.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/xsd/InlineSchemaValidator.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/xsd/InlineXSDResolver.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/xsd/SchemaAttributeTable.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/xsd/ValidateErrorHandler.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/xsd/XMLCatalog.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/xsd/XMLCatalogImpl.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/xsd/XMLCatalogResolver.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/xsd/XMLEntityResolverChain.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/xsd/XSDValidator.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/xml/XMLConvertor.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/xml/XMLDocumentCache.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/xml/XMLDocumentCacheUser.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/xml/XMLTags.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/xml/XMLTraversal.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/xml/XMLUtils.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/xml/XMLVisitor.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/xml/dom/DOMParser.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/xml/dom/ElementLocation.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/xml/jaxp/DocumentBuilderFactoryImpl.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/xml/jaxp/DocumentBuilderImpl.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/xml/schema/TargetNamespaceProcessor.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/xml/schema/XMLSchemaProcessor.java create mode 100644 bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/xml/schema/XMLSchemaValidator.java (limited to 'bundles/org.eclipse.wst.wsi/wsitools/org') diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/ToolEnvironment.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/ToolEnvironment.java new file mode 100644 index 000000000..9ba039efb --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/ToolEnvironment.java @@ -0,0 +1,254 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal; + +import java.io.PrintWriter; +import java.io.StringWriter; + +import org.eclipse.wst.wsi.internal.util.XMLInfo; + +/** + * This class contains Tool environment information. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public class ToolEnvironment +{ + /** + * Element name. + */ + public static final String ELEM_NAME = WSIConstants.ELEM_ENVIRONMENT; + + /** + * QName. + */ + //public static final QName QNAME = new QName(WSIConstants.NS_URI_WSI_COMMON, ELEM_NAME); + + /** + * Tool environment information. + */ + protected String runtimeName = System.getProperty("java.runtime.name"); + protected String runtimeVersion = System.getProperty("java.runtime.version"); + + protected String osName = System.getProperty("os.name"); + protected String osVersion = System.getProperty("os.version"); + + protected String xmlParserName = "?"; + protected String xmlParserVersion = "?"; + + /** + * Additional tool environment information. + */ + protected XMLInfo xmlInfo = null; + + /** + * Create object that represents tool runtime environment. + */ + public ToolEnvironment() + { + try + { + + // FUTURE: made compatible with later versions of Xerces where getVersion + // is no longer statically available. + // xmlParserVersion = new org.apache.xerces.impl.Version().getVersion(); + xmlParserVersion = org.apache.xerces.impl.Version.getVersion(); + + xmlParserName = "Apache Xerces"; + } + + catch (Exception e) + { + // ADD: How else can we get the name version number + } + + catch (Error err) + { + // ADD: How else can we get the name version number + } + } + + /** + * Create object that represents tool runtime environment. + * @param xmlInfo additional tool environment information. + */ + public ToolEnvironment(XMLInfo xmlInfo) + { + this.xmlInfo = xmlInfo; + } + + /** + * Returns the osName. + * @return the osName. + * @see #setOSName + */ + public String getOSName() + { + return osName; + } + + /** + * Returns the osVersion. + * @return the osVersion. + * @see #setOSVersion + */ + public String getOSVersion() + { + return osVersion; + } + + /** + * Returns the parserName. + * @return the parserName. + * @see #setXMLParserName + */ + public String getXMLParserName() + { + return xmlParserName; + } + + /** + * Returns the parserVersion. + * @return the parserVersion. + * @see #setXMLParserVersion + */ + public String getXMLParserVersion() + { + return xmlParserVersion; + } + + /** + * Returns the runtimeName. + * @return the runtimeName. + * @see #setRuntimeName + */ + public String getRuntimeName() + { + return runtimeName; + } + + /** + * Returns the runtimeVersion. + * @return the runtimeVersion. + * @see #setRuntimeVersion + */ + public String getRuntimeVersion() + { + return runtimeVersion; + } + + /** + * Sets the osName. + * @param osName the osName to set. + * @see #getOSName + */ + public void setOSName(String osName) + { + this.osName = osName; + } + + /** + * Sets the osVersion. + * @param osVersion the osVersion to set. + * @see #getOSVersion + */ + public void setOSVersion(String osVersion) + { + this.osVersion = osVersion; + } + + /** + * Sets the parserName. + * @param xmlParserName the parserName to set. + * @see #getXMLParserName + */ + public void setXMLParserName(String xmlParserName) + { + this.xmlParserName = xmlParserName; + } + + /** + * Sets the parserVersion. + * @param xmlParserVersion the parserVersion to set. + * @see #getXMLParserVersion + */ + public void setXMLParserVersion(String xmlParserVersion) + { + this.xmlParserVersion = xmlParserVersion; + } + + /** + * Sets the runtimeName. + * @param runtimeName the runtimeName to set. + * @see #getRuntimeName + */ + public void setRuntimeName(String runtimeName) + { + this.runtimeName = runtimeName; + } + + /** + * Sets the runtimeVersion. + * @param runtimeVersion the runtimeVersion to set. + * @see #getRuntimeVersion + */ + public void setRuntimeVersion(String runtimeVersion) + { + this.runtimeVersion = runtimeVersion; + } + + /** + * Sets the additional environment information. + * @param xmlInfo additional tool environment information. + */ + public void setAdditionalToolEnvironment(XMLInfo xmlInfo) + { + this.xmlInfo = xmlInfo; + } + + /** + * Return XML string representation of this object. + * @param namespaceName the namespace prefix. + * @return the XML string representation of this object. + */ + public String toXMLString(String namespaceName) + { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + + String nsName = namespaceName; + if (!nsName.equals("")) + nsName += ":"; + + // Start element + pw.println(" <" + nsName + ELEM_NAME + ">"); + + pw.print(" <" + nsName + WSIConstants.ELEM_RUNTIME + " "); + pw.print(WSIConstants.ATTR_NAME + "=\"" + runtimeName + "\" "); + pw.println(WSIConstants.ATTR_VERSION + "=\"" + runtimeVersion + "\"/>"); + pw.print(" <" + nsName + WSIConstants.ELEM_OPERATING_SYSTEM + " "); + pw.print(WSIConstants.ATTR_NAME + "=\"" + osName + "\" "); + pw.println(WSIConstants.ATTR_VERSION + "=\"" + osVersion + "\"/>"); + pw.print(" <" + nsName + WSIConstants.ELEM_XML_PARSER + " "); + pw.print(WSIConstants.ATTR_NAME + "=\"" + xmlParserName + "\" "); + pw.println(WSIConstants.ATTR_VERSION + "=\"" + xmlParserVersion + "\"/>"); + + // If addtional info, then get it + if (xmlInfo != null) + pw.print(xmlInfo.toXMLString(nsName)); + + // End element + pw.println(" "); + + return sw.toString(); + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/ToolInfo.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/ToolInfo.java new file mode 100644 index 000000000..f6afdf0eb --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/ToolInfo.java @@ -0,0 +1,465 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal; + +import java.io.FileWriter; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.MissingResourceException; +import java.util.ResourceBundle; + +import org.eclipse.wst.wsi.internal.util.Utils; +import org.eclipse.wst.wsi.internal.util.XMLInfo; + +/** + * Information that describes a conformance tool. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public class ToolInfo +{ + /** + * Tool information property names. + */ + public static final String PROP_TOOL_VERSION = "wsi.tool.version"; + public static final String PROP_TOOL_RELEASE_DATE = "wsi.tool.release.date"; + public static final String PROP_TOOL_IMPLEMENTER = "wsi.tool.implementer"; + public static final String PROP_TOOL_LOCATION = "wsi.tool.location"; + + /** + * Default tool information property values. + */ + private static final String DEF_TOOL_VERSION = "1.0.1"; + private static final String DEF_TOOL_RELEASE_DATE = "2004-01-22"; + private static final String DEF_TOOL_IMPLEMENTER = "Eclipse.org Organization"; + private static final String DEF_TOOL_LOCATION = "http://www.eclipse.org/wsvt"; + + /** + * Tool information. + */ + protected String name; + protected String version; + protected String releaseDate; + protected String implementer; + protected String location; + + /** + * Tool environment. + */ + protected ToolEnvironment toolEnvironment = null; + + /** + * Tool info properties filename. + */ + public static final String PROP_FILENAME = "org.wsi.test.toolinfo"; + + /** + * Create tool information. + */ + public ToolInfo() + { + this.toolEnvironment = new ToolEnvironment(); + } + + /** + * Create tool information from information in the toolinfo.properties file. + * @param name the tool name. + */ + public ToolInfo(String name) + { + this.name = name; + + getProperties(); + + this.toolEnvironment = new ToolEnvironment(); + } + + /** + * Create tool information. + * @param name the tool name. + * @param version the version of the tool. + * @param releaseDate the release date of the tool. + * @param implementer the implementer of the tool. + * @param location the implementer location. + */ + public ToolInfo( + String name, + String version, + String releaseDate, + String implementer, + String location) + { + this.name = name; + this.version = version; + this.releaseDate = releaseDate; + this.implementer = implementer; + this.location = location; + + this.toolEnvironment = new ToolEnvironment(); + } + + /** + * Create tool information with tool unique environment information. + * @param name the tool name. + * @param version the version of the tool. + * @param releaseDate the release date of the tool. + * @param implementer the implementer of the tool. + * @param location the implementer location. + * @param xmlInfo additional tool environment information. + */ + public ToolInfo( + String name, + String version, + String releaseDate, + String implementer, + String location, + XMLInfo xmlInfo) + { + this.name = name; + this.version = version; + this.releaseDate = releaseDate; + this.implementer = implementer; + this.location = location; + + this.toolEnvironment = new ToolEnvironment(xmlInfo); + } + + /** + * Get name. + * @return name. + * @see #setName + */ + public String getName() + { + return name; + } + + /** + * Get version. + * @return version. + * @see #setVersion + */ + public String getVersion() + { + return version; + } + + /** + * Get release date. + * @return release date. + * @see #setReleaseDate + */ + public String getReleaseDate() + { + return releaseDate; + } + + /** + * Get implementer. + * @return implementer. + * @see #setImplementer + */ + public String getImplementer() + { + return implementer; + } + + /** + * Get implementer location. + * @return implementer location. + * @see #setLocation + */ + public String getLocation() + { + return location; + } + + /** + * Returns the toolEnvironment. + * @return ToolEnvironment + * @see #setToolEnvironment + */ + public ToolEnvironment getToolEnvironment() + { + return toolEnvironment; + } + + /** + * Sets the implementer. + * @param implementer the implementer to set. + * @see #getImplementer + */ + public void setImplementer(String implementer) + { + this.implementer = implementer; + } + + /** + * Sets the location. + * @param location the location to set. + * @see #getLocation + */ + public void setLocation(String location) + { + this.location = location; + } + + /** + * Sets the name. + * @param name the name to set. + * @see #getName + */ + public void setName(String name) + { + this.name = name; + } + + /** + * Sets the releaseDate. + * @param releaseDate the releaseDate to set. + * @see #getReleaseDate + */ + public void setReleaseDate(String releaseDate) + { + this.releaseDate = releaseDate; + } + + /** + * Sets the toolEnvironment. + * @param toolEnvironment the toolEnvironment to set. + * @see #getToolEnvironment + */ + public void setToolEnvironment(ToolEnvironment toolEnvironment) + { + this.toolEnvironment = toolEnvironment; + } + + /** + * Sets the toolEnvironment. + * @param xmlInfo additional tool environment information. + */ + public void setAdditionalToolEnvironment(XMLInfo xmlInfo) + { + this.toolEnvironment.setAdditionalToolEnvironment(xmlInfo); + } + + /** + * Sets the version. + * @param version the version to set. + * @see #getVersion + */ + public void setVersion(String version) + { + this.version = version; + } + + /** + * Return start XML string representation of this object. + * @param namespaceName the namespace prefix. + * @return the start XML string representation of this object. + */ + public String getStartXMLString(String namespaceName) + { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + + String nsName = namespaceName; + if (!nsName.equals("")) + nsName += ":"; + + pw.print(" <" + nsName + getName().toLowerCase() + " "); + pw.print(WSIConstants.ATTR_VERSION + "=\"" + getVersion() + "\" "); + pw.println( + WSIConstants.ATTR_RELEASE_DATE + "=\"" + getReleaseDate() + "\">"); + + pw.print(" <" + nsName + WSIConstants.ELEM_IMPLEMENTER + " "); + pw.print(WSIConstants.ATTR_NAME + "=\"" + getImplementer() + "\" "); + pw.println(WSIConstants.ATTR_LOCATION + "=\"" + getLocation() + "\"/>"); + + // Environment + pw.print(toolEnvironment.toXMLString(namespaceName)); + + return sw.toString(); + } + + /** + * Return the end XML string representation of this object. + * @param namespaceName the namespace prefix. + * @return the end XML string representation of this object. + */ + public String getEndXMLString(String namespaceName) + { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + + String nsName = namespaceName; + if (!nsName.equals("")) + nsName += ":"; + + pw.println(" "); + + return sw.toString(); + } + + /** + * Get values from the tools.properties file. + */ + protected void getProperties() + { + //Properties props = new Properties(); + ResourceBundle resourceBundle; + + try + { + // Try to load properties from wsi.properties + //InputStream is = Utils.getInputStream(PROP_FILENAME); + + // Load properties from file + //props.load(is); + + // Get resource + resourceBundle = ResourceBundle.getBundle(PROP_FILENAME); + + // Get property values + this.version = + getProperty(resourceBundle, PROP_TOOL_VERSION, DEF_TOOL_VERSION); + this.releaseDate = + getProperty( + resourceBundle, + PROP_TOOL_RELEASE_DATE, + DEF_TOOL_RELEASE_DATE); + this.implementer = + getProperty( + resourceBundle, + PROP_TOOL_IMPLEMENTER, + DEF_TOOL_IMPLEMENTER); + this.location = + getProperty(resourceBundle, PROP_TOOL_LOCATION, DEF_TOOL_LOCATION); + } + + catch (MissingResourceException mre) + { + // DEBUG: + //System.out.println("Exception loading properties: " + e.toString()); + + // Set default property values + this.version = DEF_TOOL_VERSION; + this.releaseDate = DEF_TOOL_RELEASE_DATE; + this.implementer = DEF_TOOL_IMPLEMENTER; + this.location = DEF_TOOL_LOCATION; + } + } + + /** + * Get property. + * @param resourceBundle a resource bundle. + * @param key a key. + * @param defaultValue a default value. + * @return property. If not found return default value. + */ + protected String getProperty( + ResourceBundle resourceBundle, + String key, + String defaultValue) + { + String value; + + if ((value = resourceBundle.getString(key)) == null) + value = defaultValue; + + return value; + } + + /** + * Format tool location. + * @param location tool location. + * @return formatted tool location. + */ + private String formatToolLocation(String location) + { + // Start with specified location + String returnLocation = location; + + // Make sure string ends the "/" + if (!returnLocation.endsWith("/")) + returnLocation += "/"; + + // Add tool name and .html + return returnLocation + getName() + ".html"; + } + + /** + * Create the tools.properties file from the command line. + * The input arguements are: + *
    + *
  1. Filename for the properties file to create + *
  2. Version number + *
  3. + *
+ * @param args the arguments for main. + */ + public static void main(String[] args) + { + int statusCode = 0; + String filename = PROP_FILENAME; + String version = DEF_TOOL_VERSION; + String implementer = DEF_TOOL_IMPLEMENTER; + String location = DEF_TOOL_LOCATION; + + // Set the file name + if (args.length >= 1) + filename = args[0]; + + if (args.length >= 2) + version = args[1]; + + if (args.length >= 3) + implementer = args[2]; + + if (args.length >= 4) + location = args[3]; + + try + { + // Create file writer + FileWriter fileWriter = new FileWriter(filename); + + // Create print writer + PrintWriter printWriter = new PrintWriter(fileWriter); + + // Write out contents of properties file + printWriter.println(COMMENTS); + printWriter.println(PROP_TOOL_VERSION + "=" + version); + printWriter.println(PROP_TOOL_RELEASE_DATE + "=" + Utils.getDate()); + printWriter.println(PROP_TOOL_IMPLEMENTER + "=" + implementer); + printWriter.println(PROP_TOOL_LOCATION + "=" + location); + + // Close file writer + fileWriter.close(); + + // Done + System.out.println("File [" + filename + "] created."); + } + + catch (java.io.IOException ioe) + { + statusCode = 1; + System.out.println("EXCEPTION: " + ioe.toString()); + ioe.printStackTrace(); + } + + // Exit + System.exit(statusCode); + } + + private static final String COMMENTS = ""; +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/URIEncoder.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/URIEncoder.java new file mode 100644 index 000000000..a389ed1e8 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/URIEncoder.java @@ -0,0 +1,204 @@ +/* + * Licensed Material - Property of IBM + * (C) Copyright IBM Corp. 2002 - All Rights Reserved. + * US Government Users Restricted Rights - Use, duplication or disclosure + * restricted by GSA ADP Schedule Contract with IBM Corp. + * + * plugins/com.ibm.etools.xmlutility/src/com/ibm/etools/xmlutility/uri/URIEncoder.java, com.ibm.etools.xmlutility, wsa.xml.v51, 20030718_1605.o + * + * @version 1.3 7/18/03 + */ + +package org.eclipse.wst.wsi.internal; + +import java.io.ByteArrayOutputStream; +import java.io.BufferedWriter; +import java.io.OutputStreamWriter; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.util.BitSet; + +/** + * This class is a modified version of java.lang.URLEncoder. + */ +public class URIEncoder +{ + static BitSet dontNeedEncoding; + static final int caseDiff = ('a' - 'A'); + static String dfltEncName = null; + + static { + dontNeedEncoding = new BitSet(256); + int i; + for (i = 'a'; i <= 'z'; i++) + { + dontNeedEncoding.set(i); + } + for (i = 'A'; i <= 'Z'; i++) + { + dontNeedEncoding.set(i); + } + for (i = '0'; i <= '9'; i++) + { + dontNeedEncoding.set(i); + } + + //dontNeedEncoding.set(' '); // cs.. removed so that space character will be replaced by %20 + dontNeedEncoding.set('-'); + dontNeedEncoding.set('_'); + dontNeedEncoding.set('.'); + dontNeedEncoding.set('*'); + dontNeedEncoding.set(':'); // cs.. added + dontNeedEncoding.set('/'); + // cs.. added so that slashes don't get encoded as %2F + + // dfltEncName = (String)AccessController.doPrivileged(new GetPropertyAction("file.encoding")); + // As discussed with Sandy, we should encode URIs with UTF8 + dfltEncName = "UTF8"; + //System.out.println("dfltEncName " + dfltEncName); + } + + /** + * You can't call the constructor. + */ + private URIEncoder() + { + } + + /** + * Translates a string into x-www-form-urlencoded + * format. This method uses the platform's default encoding + * as the encoding scheme to obtain the bytes for unsafe characters. + * + * @param s String to be translated. + * @return the translated String. + */ + public static String encode(String s) + { + String str = null; + try + { + str = encode(s, dfltEncName); + } + catch (UnsupportedEncodingException e) + { + // The system should always have the platform default + } + return str; + } + + /** + * Translates a string into application/x-www-form-urlencoded + * format using a specific encoding scheme. This method uses the + * supplied encoding scheme to obtain the bytes for unsafe + * characters. + *

+ * Note: The + * World Wide Web Consortium Recommendation states that + * UTF-8 should be used. Not doing so may introduce + * incompatibilites. + * + * @param s String to be translated. + * @param enc The name of a supported + * character + * encoding. + * @return the translated String. + * @exception UnsupportedEncodingException + * If the named encoding is not supported + * @see URLDecoder#decode(java.lang.String, java.lang.String) + */ + public static String encode(String s, String enc) + throws UnsupportedEncodingException + { + boolean needToChange = false; + boolean wroteUnencodedChar = false; + int maxBytesPerChar = 10; // rather arbitrary limit, but safe for now + StringBuffer out = new StringBuffer(s.length()); + ByteArrayOutputStream buf = new ByteArrayOutputStream(maxBytesPerChar); + BufferedWriter writer = + new BufferedWriter(new OutputStreamWriter(buf, enc)); + + for (int i = 0; i < s.length(); i++) + { + int c = (int) s.charAt(i); + //System.out.println("Examining character: " + c); + if (dontNeedEncoding.get(c)) + { + //if (c == ' ') + //{ + // c = '+'; + // needToChange = true; + //} + //System.out.println("Storing: " + c); + out.append((char) c); + wroteUnencodedChar = true; + } + else + { + // convert to external encoding before hex conversion + try + { + if (wroteUnencodedChar) + { // Fix for 4407610 + writer = new BufferedWriter(new OutputStreamWriter(buf, enc)); + wroteUnencodedChar = false; + } + writer.write(c); + + // If this character represents the start of a Unicode + // surrogate pair, then pass in two characters. It's not + // clear what should be done if a bytes reserved in the + // surrogate pairs range occurs outside of a legal + // surrogate pair. For now, just treat it as if it were + // any other character. + // + if (c >= 0xD800 && c <= 0xDBFF) + { + // System.out.println(Integer.toHexString(c) + " is high surrogate"); + if ((i + 1) < s.length()) + { + int d = (int) s.charAt(i + 1); + // System.out.println("\tExamining " + Integer.toHexString(d)); + if (d >= 0xDC00 && d <= 0xDFFF) + { + // System.out.println("\t" + Integer.toHexString(d) + " is low surrogate"); + writer.write(d); + i++; + } + } + } + writer.flush(); + } + catch (IOException e) + { + buf.reset(); + continue; + } + byte[] ba = buf.toByteArray(); + + for (int j = 0; j < ba.length; j++) + { + out.append('%'); + char ch = Character.forDigit((ba[j] >> 4) & 0xF, 16); + // converting to use uppercase letter as part of + // the hex value if ch is a letter. + if (Character.isLetter(ch)) + { + ch -= caseDiff; + } + out.append(ch); + ch = Character.forDigit(ba[j] & 0xF, 16); + if (Character.isLetter(ch)) + { + ch -= caseDiff; + } + out.append(ch); + } + buf.reset(); + needToChange = true; + } + } + return (needToChange ? out.toString() : s); + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/WSIConstants.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/WSIConstants.java new file mode 100644 index 000000000..dc0d688df --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/WSIConstants.java @@ -0,0 +1,485 @@ +/******************************************************************************* + * Copyright (c) 2002-2003 IBM Corporation, Parasoft and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + * Parasoft - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal; + +/** + * WS-I constants. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + * @author Jim Clune + * @author Graham Turrell (gturrell@uk.ibm.com) + */ +public interface WSIConstants { + /** + * Copyright notice. + */ + public static final String COPYRIGHT = "Copyright (C) 2002-2003 by The Web Services-Interoperability Organization and Certain " + + "of its Members. All Rights Reserved.\nUse of this Material is governed by WS-I licenses included within the documentation."; + + /** + * XML declaration statement. + */ + public static final String XML_DECL = ""; + + /** + * XML namespace URI. + */ + public static final String NS_URI_XMLNS = "http://www.w3.org/2000/xmlns/"; + public static final String NS_URI_XML = "http://www.w3.org/XML/1998/namespace"; + /** + * XML schema namespace URI. + */ + public static final String NS_URI_XSD = "http://www.w3.org/2001/XMLSchema"; + + /** + * XML schema location. + */ + public static final String XSD_SCHEMA_LOCATION = "http://www.w3.org/2001/XMLSchema.xsd"; + + /** + * XML schema namespace name. + */ + public static final String NS_NAME_XSD = "xsd"; + + /** + * XML schema instance namespace URI. + */ + public static final String NS_URI_XSI = "http://www.w3.org/2001/XMLSchema-instance"; + + /** + * XML schema namespace name. + */ + public static final String NS_NAME_XSI = "xsi"; + + + /** + * WS-I message log namespace URI. + */ + public static final String NS_URI_WSI_LOG = "http://www.ws-i.org/testing/2004/07/log/"; + + public static final String NS_NAME_WSI_LOG = "wsi-log"; + + /** + * WS-I conformance report namespace URI. + */ + public static final String NS_URI_WSI_REPORT = "http://www.ws-i.org/testing/2004/07/report/"; + public static final String NS_NAME_WSI_REPORT = "wsi-report"; + + /** + * WS-I profile test assertions namespace URI. + */ + public static final String NS_URI_WSI_ASSERTIONS_2003 = "http://www.ws-i.org/testing/2003/03/assertions/"; + public static final String NS_URI_WSI_ASSERTIONS = "http://www.ws-i.org/testing/2004/07/assertions/"; + + public static final String NS_NAME_WSI_ASSERTIONS = "wsi-assertions"; + + /** + * WS-I monitor configuration file namesapce URI. + */ + public static final String NS_URI_WSI_MONITOR_CONFIG_2003 = "http://www.ws-i.org/testing/2003/03/monitorConfig/"; + public static final String NS_URI_WSI_MONITOR_CONFIG = "http://www.ws-i.org/testing/2004/07/monitorConfig/"; + + + public static final String NS_NAME_WSI_MONITOR_CONFIG = "wsi-monConfig"; + + /** + * WS-I analyzer configuration file namesapce URI. + */ + public static final String NS_URI_WSI_ANALYZER_CONFIG_2003 = "http://www.ws-i.org/testing/2003/03/analyzerConfig/"; + public static final String NS_URI_WSI_ANALYZER_CONFIG = "http://www.ws-i.org/testing/2004/07/analyzerConfig/"; + + public static final String NS_NAME_WSI_ANALYZER_CONFIG = "wsi-analyzerConfig"; + + /** + * WS-I common namesapce URI. + */ + public static final String NS_URI_WSI_COMMON_2003 = "http://www.ws-i.org/testing/2003/03/common/"; + public static final String NS_URI_WSI_COMMON = "http://www.ws-i.org/testing/2004/07/common/"; + public static final String NS_NAME_WSI_COMMON = "wsi-common"; + + /** + * SOAP V1.1 namespace. + */ + public final static String NS_URI_SOAP = "http://schemas.xmlsoap.org/soap/envelope/"; + + /** + * SOAP/1.1 encoding. + */ + public final static String NS_URI_SOAP_ENCODING = "http://schemas.xmlsoap.org/soap/encoding/"; + + public static final String NS_URI_SOAP_NEXT_ACTOR = "http://schemas.xmlsoap.org/soap/actor/next" ; + /** + * HTTP transport. + */ + public final static String NS_URI_SOAP_HTTP = "http://schemas.xmlsoap.org/soap/http"; + + /** + * WSDL V1.1 namespace. + */ + public final static String NS_URI_WSDL = "http://schemas.xmlsoap.org/wsdl/"; + + /** + * WSDL SOAP binding namespace. + */ + public final static String NS_URI_WSDL_SOAP = "http://schemas.xmlsoap.org/wsdl/soap/"; + + public final static String NS_NAME_WSDL_SOAP = "soap"; + + /** + * WSDL MIME binding namespace. + */ + public final static String NS_NAME_WSDL_MIME = "http://schemas.xmlsoap.org/wsdl/mime/"; + + /** + * WSDL HTTP GET & POST binding namespace. + */ + public final static String NS_NAME_WSDL_HTTP = "http://schemas.xmlsoap.org/wsdl/http/"; + + /** + * WSDL DIME binding namespace. + */ + public final static String NS_NAME_WSDL_DIME = "http://schemas.xmlsoap.org/ws/2002/04/dime/wsdl/"; + + /** + * Conformance Claim namespace. + */ + public final static String NS_URI_CLAIM = "http://ws-i.org/schemas/conformanceClaim/"; + + /** + * UDDI V2 namespace. + */ + public final static String NS_URI_UDDI_V2 = "urn:uddi-org:api_v2"; + + /** + * The XML Schema for the type used to refer to attachments from the SOAP + * envelope. + */ + public final static String NS_URI_SWA_REF = "http://ws-i.org/profiles/basic/1.1/xsd"; + + public final static String SCHEMA_TYPE_SWA_REF = "swaRef"; + + /** + * Element names. + */ + public static final String ELEM_ADD_STYLE_SHEET = "addStyleSheet"; + + public static final String ELEM_ADDITIONAL_ENTRY_TYPE_LIST = "additionalEntryTypeList"; + + public static final String ELEM_ANALYZER_FAILURE = "analyzerFailure"; + + public static final String ELEM_ARTIFACT = "artifact"; + + public static final String ELEM_ARTIFACT_REFERENCE = "artifactReference"; + + public static final String ELEM_ASSERTION_COVERAGE = "assertionCoverage"; + + public static final String ELEM_ASSERTION_DESCRIPTION = "assertionDescription"; + + public static final String ELEM_ASSERTION_RESULT = "assertionResult"; + + public static final String ELEM_ASSERTION_RESULT_SUMMARY = "assertionResultSummary"; + + public static final String ELEM_ASSERTION_RESULTS = "assertionResults"; + + public static final String ELEM_CLEANUP_TIMEOUT_SECONDS = "cleanupTimeoutSeconds"; + + public static final String ELEM_CONFIG = "configuration"; + + public static final String ELEM_COMMENT = "comment"; + + public static final String ELEM_CONTEXT = "context"; + + public static final String ELEM_DETAIL = "detail"; + + public static final String ELEM_DETAIL_DESCRIPTION = "detailDescription"; + + public static final String ELEM_DESCRIPTION = "description"; + + public static final String ELEM_ENVIRONMENT = "environment"; + + public static final String ELEM_ENTRY = "entry"; + + public static final String ELEM_FAILURE_DETAIL = "failureDetail"; + + public static final String ELEM_FAILURE_DETAIL_DESCRIPTION = "failureDetailDescription"; + + public static final String ELEM_FAILURE_MESSAGE = "failureMessage"; + + public static final String ELEM_HTTP_HEADERS = "httpHeaders"; + + public static final String ELEM_IMPLEMENTER = "implementer"; + + public static final String ELEM_INQUIRY_URL = "inquiryURL"; + + public static final String ELEM_LISTEN_PORT = "listenPort"; + + public static final String ELEM_LOG = "log"; + + public static final String ELEM_LOG_DURATION = "logDuration"; + + public static final String ELEM_LOG_FILE = "logFile"; + + public static final String ELEM_MAN_IN_THE_MIDDLE = "manInTheMiddle"; + + public static final String ELEM_MAX_CONNECTIONS = "maxConnections"; + + public static final String ELEM_MESSAGE_CONTENT = "messageContent"; + + public static final String ELEM_MESSAGE_CONTENT_WITH_ATTACHMENTS = "messageContentWithAttachments"; + + public static final String ELEM_MESSAGE_ENTRY = "messageEntry"; + + public static final String ELEM_MESSAGE_INPUT = "messageInput"; + + public static final String ELEM_MONITOR = "monitor"; + + public static final String ELEM_OPERATING_SYSTEM = "operatingSystem"; + + public static final String ELEM_PREREQ_FAILED_LIST = "prereqFailedList"; + + public static final String ELEM_PREREQ_LIST = "prereqList"; + + public static final String ELEM_PROFILE = "profile"; + + public static final String ELEM_PROFILE_ASSERTIONS = "profileAssertions"; + + public static final String ELEM_READ_TIMEOUT_SECONDS = "readTimeoutSeconds"; + + public static final String ELEM_RECEIVER_HOST_AND_PORT = "receiverHostAndPort"; + + public static final String ELEM_REDIRECT = "redirect"; + + public static final String ELEM_REPORT = "report"; + + public static final String ELEM_REPORT_FILE = "reportFile"; + + public static final String ELEM_RUNTIME = "runtime"; + + public static final String ELEM_SCHEME_AND_HOSTPORT = "schemeAndHostPort"; + + public static final String ELEM_SENDER_HOST_AND_PORT = "senderHostAndPort"; + + public static final String ELEM_SERVICE_LOCATION = "serviceLocation"; + + public static final String ELEM_SUMMARY = "summary"; + + public static final String ELEM_TEST_ASSERTION = "testAssertion"; + + public static final String ELEM_TEST_ASSERTIONS_FILE = "testAssertionsFile"; + + public static final String ELEM_TEST_ASSERTION_ID = "testAssertionID"; + + public static final String ELEM_TEST_COVERAGE = "testCoverage"; + + public static final String ELEM_UDDI_ENTRY = "uddiEntry"; + + public static final String ELEM_UDDI_KEY = "uddiKey"; + + public static final String ELEM_UDDI_REFERENCE = "uddiReference"; + + public static final String ELEM_VERBOSE = "verbose"; + + public static final String ELEM_WSDL_ELEMENT = "wsdlElement"; + + public static final String ELEM_WSDL_INPUT = "wsdlInput"; + + public static final String ELEM_WSDL_REFERENCE = "wsdlReference"; + + public static final String ELEM_WSDL_URI = "wsdlURI"; + + public static final String ELEM_XML_PARSER = "xmlParser"; + + public static final String ELEM_MIME_PART = "mimePart"; + + public static final String ELEM_MIME_HEADERS = "mimeHeaders"; + + public static final String ELEM_MIME_CONTENT = "mimeContent"; + + public static final String ELEM_BOUNDARY_STRING = "boundaryString"; + + /** + * Attribute names. + */ + public static final String ATTR_ALTERNATE = "alternate"; + + public static final String ATTR_ARRAY_TYPE = "arrayType"; + + public static final String ATTR_ASSERTION_DESCRIPTION = "assertionDescription"; + + public static final String ATTR_BOM = "BOM"; + + public static final String ATTR_CHARSET = "charset"; + + public static final String ATTR_CODE = "code"; + + public static final String ATTR_COLUMN_NUMBER = "columnNumber"; + + public static final String ATTR_CONVERSATION_ID = "conversationID"; + + public static final String ATTR_CORRELATION_TYPE = "correlationType"; + + public static final String ATTR_DATE = "date"; + + public static final String ATTR_ENABLED = "enabled"; + + public static final String ATTR_ENTRY_TYPE = "entryType"; + + public static final String ATTR_FAILURE_MESSAGE = "failureMessage"; + + public static final String ATTR_FAILURE_DETAIL = "failureDetail"; + + public static final String ATTR_HREF = "href"; + + public static final String ATTR_ID = "id"; + + public static final String ATTR_ID_UC = "ID"; + + public static final String ATTR_IMPLEMENTER = "implementer"; + + public static final String ATTR_LINE_NUMBER = "lineNumber"; + + public static final String ATTR_LOCATION = "location"; + + public static final String ATTR_MEDIA = "media"; + + public static final String ATTR_MESSAGE_ENTRY = "messageEntry"; + + public static final String ATTR_MESSAGES = "messages"; + + public static final String ATTR_NAME = "name"; + + public static final String ATTR_NAMESPACE = "namespace"; + + public static final String ATTR_PARENT_ELEMENT_NAME = "parentElementName"; + + public static final String ATTR_REFERENCE_ID = "referenceID"; + + public static final String ATTR_REFERENCE_TYPE = "referenceType"; + + public static final String ATTR_RELEASE_DATE = "releaseDate"; + + public static final String ATTR_REPLACE = "replace"; + + public static final String ATTR_RESULT = "result"; + + public static final String ATTR_SERVICE_NAME = "serviceName"; + + public static final String ATTR_SPECIFICATION = "specification"; + + public static final String ATTR_TIMESTAMP = "timestamp"; + + public static final String ATTR_TITLE = "title"; + + public static final String ATTR_TYPE = "type"; + + public static final String ATTR_VERSION = "version"; + + /** + * Default values. + */ + public static final String DEFAULT_REPORT_URI = "report.xml"; + + // TEMP: Use the following report title for the draft release only. + //public static final String DEFAULT_REPORT_TITLE = "WS-I Profile + // Conformance Report"; + public static final String DEFAULT_REPORT_TITLE = "WS-I Basic Profile Conformance Report."; + + public static final String DEFAULT_TEST_ASSERTIONS_DOCUMENT_URI = "../common/profiles/SSBP10_BP11_TAD.xml"; + + public static final String DEFAULT_LOG_XSL = "../common/xsl/log.xsl"; + + public static final String DEFAULT_REPORT_XSL = "../common/xsl/report.xsl"; + + public static final String DEFAULT_XSL_TYPE = "text/xsl"; + + public static final String DEFAULT_XML_ENCODING = "UTF-8"; + + /** + * BOM constants. + * + */ + public static int BOM_UTF16 = 0xFFFE; + + public static int BOM_UTF16_BIG_ENDIAN = 0xFEFF; + + public static int BOM_UTF8 = 0xEFBBBF; + + /** + * Validation constants. + * + */ + public static final String ATTRVAL_SOAP_BODY_USE_LIT = "literal"; + + public static final String ATTRVAL_SOAP_BODY_USE_ENC = "encoded"; + + public static final String ATTRVAL_SOAP_BIND_STYLE_DOC = "document"; + + public static final String ATTRVAL_SOAP_BIND_STYLE_RPC = "rpc"; + + public static final String ATTRVAL_CORRELATION_TYPE_ENDPOINT = "endpoint"; + + public static final String ATTRVAL_CORRELATION_TYPE_NAMESPACE = "namespace"; + + public static final String ATTRVAL_CORRELATION_TYPE_OPERATION = "operation"; + + /** + * WS-I constants - attributes for conformance claims (discovery). + * + */ + + public static final String ATTRVAL_UDDI_CLAIM_KEYVALUE = "http://ws-i.org/profiles/basic/1.0"; + + public static final String ATTRVAL_UDDI_CLAIM_TMODELKEY = "uuid:65719168-72c6-3f29-8c20-62defb0961c0"; + + /** + * WS-I names and versions of the profile test assertion document supported + * in the current version of the test tools. + */ + public static final String BASIC_PROFILE_TAD_NAME = "Basic Profile Test Assertions"; + + public static final String BASIC_PROFILE_1_1_TAD_NAME = "Basic Profile 1.1 Test Assertions"; + + public static final String SIMPLE_SOAP_BINDINGS_PROFILE_TAD_NAME = "Simple Soap Binding Profile [1.0] (with Basic Profile [1.1]) Test Assertions"; + + public static final String ATTACHMENTS_PROFILE_TAD_NAME = "Attachments Profile [1.0] (with Basic Profile [1.1] and Simple Soap Binding Profile [1.0]) Test Assertions"; + + public static final String BASIC_PROFILE_TAD_VERSION = "1.1.0"; + + public static final String BASIC_PROFILE_1_1_TAD_VERSION = "1.1.0"; + + public static final String SIMPLE_SOAP_BINDINGS_PROFILE_TAD_VERSION = "1.0.0"; + + public static final String ATTACHMENTS_PROFILE_TAD_VERSION = "1.0.0"; + + /** + * System dependent line separator character. + */ + public static final String LINE_SEPARATOR = System + .getProperty("line.separator"); + + /** + * System dependent path separator character. + */ + public static final String PATH_SEPARATOR = System + .getProperty("path.separator"); + + /** + * File which contains the copyright, license and feedback comments. + */ + public static final String COMMENTS_FILE = "comments.xml"; + + public static final String CONTENT_TYPE_TEXT_XML = "text/xml"; + + public static final String CONTENT_TYPE_MULTIPART = "multipart/related"; + +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/WSIException.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/WSIException.java new file mode 100644 index 000000000..f5b5dc091 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/WSIException.java @@ -0,0 +1,145 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal; + +import java.lang.reflect.InvocationTargetException; +import java.util.MissingResourceException; + +/** + * Primary WS-I exception. + * + * @version 1.0.1 + * @author Peter Brittenham + */ +public class WSIException extends Exception +{ + /** + * Throwable. + */ + protected Throwable throwable = null; + + /** + * Create an exception without a message. + */ + public WSIException() + { + // Exception + super(); + } + + /** + * Create an exception with a message. + * + * @param msg the exception message + */ + public WSIException(String msg) + { + // Exception + super(msg); + } + + /** + * Create an exception with a message and related exception. + * + * @param msg the exception message + * @param throwable throwable that is related to this exception + */ + public WSIException(String msg, Throwable throwable) + { + // Exception + super(msg); + + // Save input reference + this.throwable = throwable; + } + + /** + * Returns the String representation of this object's values. + * + * @return Returns the detail message of this throwable object. + */ + public String getMessage() + { + return super.getMessage(); + } + + /** + * Returns the String representation of this object's values. + * + * @return Returns the detail message of this throwable object. + */ + public String toString() + { + //StringWriter sw; + //PrintWriter pw; + + // Always get message from super class + String msg = super.getMessage(); + + // If this exception contains a reference to another exception, + // then add it to the message + if (throwable != null) + { + msg += "\n" + + "------------------------------------------------------------------------------\n" + + " Nested exception is: \n\n " + + throwable.toString() + + "\n"; + + // If throwable is MissingResourceException, + // then add class name and key to output + if (throwable instanceof MissingResourceException) + { + MissingResourceException mre = (MissingResourceException) throwable; + + // Get class name and key + msg += " - " + + mre.getKey() + + "\n\t" + + "[Class Name: " + + mre.getClassName() + + "]"; + } + + // If throwable is InvocationTargetException, + // then target of exception + else if (throwable instanceof InvocationTargetException) + { + InvocationTargetException ite = (InvocationTargetException) throwable; + + // Get target + msg += " - " + ite.getTargetException().toString(); + } + + // ADD: Print stack trace + //sw = new StringWriter(); + //pw = new PrintWriter(sw); + //throwable.printStackTrace(pw); + + // Add it to the message + //msg += sw.toString(); + } + + // Return message + return msg; + } + + /** + * Returns the exception that caused this exception to be created. + * + * @return Returns the encapsulated throwable object. + */ + public Throwable getTargetException() + { + // Return throwable + return throwable; + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/WSIFileNotFoundException.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/WSIFileNotFoundException.java new file mode 100644 index 000000000..5a1464237 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/WSIFileNotFoundException.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal; + +/** + * Signals that an attempt to open the file denoted by a specified + * pathname has failed. + * + * @author Peter Brittenham (peterbr@us.ibm.com) + * @version 1.0.1 + */ +public class WSIFileNotFoundException extends WSIException +{ + + /** + * Constructor for WSIFileNotFoundException. + */ + public WSIFileNotFoundException() + { + super(); + } + + /** + * Constructor for WSIFileNotFoundException. + * @param msg the detail message. + + */ + public WSIFileNotFoundException(String msg) + { + super(msg); + } + + /** + * Constructor for WSIFileNotFoundException. + * @param msg the detail message. + * @param throwable initial exception thrown. + */ + public WSIFileNotFoundException(String msg, Throwable throwable) + { + super(msg, throwable); + } + +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/WSIPreferences.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/WSIPreferences.java new file mode 100644 index 000000000..08e141fe8 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/WSIPreferences.java @@ -0,0 +1,73 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal; + +/** + * WS-I test tools property. + * + * @author David Lauzon, IBM + * + */ + +public class WSIPreferences +{ + protected String complianceLevel = ""; + protected String tadfile = ""; + + /** + * Constructor. + */ + public WSIPreferences() + { + super(); + } + + /** + * Returns the WS-I compliance level. + * @return the WS-I compliance level. + * @see #setComplianceLevel + */ + public String getComplianceLevel() + { + return complianceLevel; + } + + /** + * Set the WS-I compliance level. + * @param compliance the WS-I compliance level. + * @see #getComplianceLevel + */ + public void setComplianceLevel(String compliance) + { + this.complianceLevel = compliance; + } + + /** + * Returns the location of the Basic Profile Test Assertions file. + * @return the location of the Basic Profile Test Assertions file. + * @see #setTADFile + */ + public String getTADFile() + { + return tadfile; + } + + /** + * Set the location of the Basic Profile Test Assertions file. + * @param file the location of the Basic Profile Test Assertions file. + * @see #getTADFile + */ + public void setTADFile(String file) + { + this.tadfile = file; + } +} + diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/WSIRuntimeException.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/WSIRuntimeException.java new file mode 100644 index 000000000..9786986bb --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/WSIRuntimeException.java @@ -0,0 +1,50 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal; + +/** + * This class represents runtime exceptions that occur after processing the configuration files. + * + * @author Peter Brittenham (peterbr@us.ibm.com) + * @version 1.0.1 + */ +public class WSIRuntimeException extends WSIException +{ + + /** + * Constructor for WSIRuntimeException. + */ + public WSIRuntimeException() + { + super(); + } + + /** + * Constructor for WSIRuntimeException. + * @param msg the detail message. + */ + public WSIRuntimeException(String msg) + { + super(msg); + } + + /** + * Constructor for WSIRuntimeException. + * @param msg the detail message. + * @param throwable the initial exception thrown. + + */ + public WSIRuntimeException(String msg, Throwable throwable) + { + super(msg, throwable); + } + +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/WSITag.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/WSITag.java new file mode 100644 index 000000000..1d018fd4b --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/WSITag.java @@ -0,0 +1,114 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal; + +import org.eclipse.wst.wsi.internal.xml.XMLTags; + +import javax.xml.namespace.QName; + +/** + * WS-I constants. + * + * @author Kulik + */ +public interface WSITag extends XMLTags +{ + /** + * Qualified names of WSDL elements. + */ + public final static QName WSDL_IMPORT = + new QName(WSIConstants.NS_URI_WSDL, "import"); + public final static QName WSDL_TYPES = + new QName(WSIConstants.NS_URI_WSDL, "types"); + public final static QName WSDL_MESSAGE = + new QName(WSIConstants.NS_URI_WSDL, "message"); + public final static QName WSDL_DOCUMENTATION = + new QName(WSIConstants.NS_URI_WSDL, "documentation"); + public final static QName WSDL_DEFINITIONS = + new QName(WSIConstants.NS_URI_WSDL, "definitions"); + public final static QName WSDL_BINDING = + new QName(WSIConstants.NS_URI_WSDL, "binding"); + public final static QName WSDL_OPERATION = + new QName(WSIConstants.NS_URI_WSDL, "operation"); + public final static QName WSDL_PART = + new QName(WSIConstants.NS_URI_WSDL, "part"); + public final static QName WSDL_INPUT = + new QName(WSIConstants.NS_URI_WSDL, "input"); + public final static QName WSDL_OUTPUT = + new QName(WSIConstants.NS_URI_WSDL, "output"); + public final static QName WSDL_FAULT = + new QName(WSIConstants.NS_URI_WSDL, "fault"); + public final static QName WSDL_SERVICE = + new QName(WSIConstants.NS_URI_WSDL, "service"); + public final static QName WSDL_PORT = + new QName(WSIConstants.NS_URI_WSDL, "port"); + public final static QName WSDL_PORTTYPE = + new QName(WSIConstants.NS_URI_WSDL, "portType"); + + public static final QName WSDL_SOAP_BINDING = + new QName(WSIConstants.NS_URI_WSDL_SOAP, "binding"); + public static final QName WSDL_SOAP_BODY = + new QName(WSIConstants.NS_URI_WSDL_SOAP, "body"); + public static final QName WSDL_SOAP_HEADER = + new QName(WSIConstants.NS_URI_WSDL_SOAP, "header"); + public static final QName WSDL_SOAP_HEADERFAULT = + new QName(WSIConstants.NS_URI_WSDL_SOAP, "headerfault"); + public static final QName WSDL_SOAP_FAULT = + new QName(WSIConstants.NS_URI_WSDL_SOAP, "fault"); + + public static final QName WSDL_MIME_CONTENT = + new QName(WSIConstants.NS_NAME_WSDL_MIME, "content"); + public static final QName WSDL_MIME_XML = + new QName(WSIConstants.NS_NAME_WSDL_MIME, "mimeXml"); + public static final QName WSDL_MIME_PART = + new QName(WSIConstants.NS_NAME_WSDL_MIME, "part"); + public static final QName WSDL_MIME_MULTIPART = + new QName(WSIConstants.NS_NAME_WSDL_MIME, "multipartRelated"); + + public final static QName ATTR_WSDL_ARRAYTYPE = + new QName(WSIConstants.NS_URI_WSDL, "arrayType"); + public final static QName ATTR_WSDL_NAMESPACE = + new QName(WSIConstants.NS_URI_WSDL, "namespace"); + public final static QName ATTR_WSDL_LOCATION = + new QName(WSIConstants.NS_URI_WSDL, "location"); + + /** + * Namespaces. + */ + public final static String NS_URI_CLAIM = + "http://ws-i.org/schemas/conformanceClaim/"; + public final static String NS_URI_SOAP = + "http://schemas.xmlsoap.org/soap/envelope/"; + public final static String NS_URI_SOAPENC = + "http://schemas.xmlsoap.org/soap/encoding/"; + public final static String NS_URI_BASIC_PROFILE10 = + "http://wsi.org/profiles/basic1.0/"; + + public final static QName SOAPENC_ARRAY = new QName(NS_URI_SOAPENC, "Array"); + + /** + * Qualified names of WS-I claim elements. + */ + public final static QName WSI_CLAIM = new QName(NS_URI_CLAIM, "Claim"); + public final static QName ATTR_CLAIM_CONFORMSTO = + new QName(NS_URI_CLAIM, "conformsTo"); + public final static QName ATTR_SOAP_MUSTUNDERSTAND = + new QName(NS_URI_SOAP, "mustUnderstand"); + + /** + * Qualified names of SOAP elements. + */ + public final static QName ELEM_SOAP_ENVELOPE = new QName(NS_URI_SOAP, "Envelope"); + public final static QName ELEM_SOAP_BODY = new QName(NS_URI_SOAP, "Body"); + public final static QName ELEM_SOAP_FAULT = new QName(NS_URI_SOAP, "Fault"); + public final static QName ELEM_SOAP_HEADER = new QName(NS_URI_SOAP, "Header"); + +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/WSITestToolsPlugin.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/WSITestToolsPlugin.java new file mode 100644 index 000000000..dbb802c43 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/WSITestToolsPlugin.java @@ -0,0 +1,74 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal; + +import java.io.IOException; +import org.eclipse.core.runtime.IPluginDescriptor; +import org.eclipse.core.runtime.Platform; +import org.eclipse.ui.plugin.AbstractUIPlugin; + +/** + * The WS-I test tools plugin. + * + * @author lauzond + */ + +public class WSITestToolsPlugin extends AbstractUIPlugin +{ + private static AbstractUIPlugin instance; + + /** + * Constructor for wsiTestToolsPlugin. + * @param descriptor an IPluginDescriptor object. + */ + public WSITestToolsPlugin(IPluginDescriptor descriptor) + { + super(descriptor); + instance = this; + + // set the current directory + WSITestToolsProperties.setInstallDir(getInstallURL()); + } + + /** + * Method getInstance. + * @return AbstractUIPlugin + */ + public static AbstractUIPlugin getInstance() + { + return instance; + } + + /** + * Method getPlugin. + * @return WSIToolsUtilPlugin + */ + public static WSITestToolsPlugin getPlugin() + { + return (WSITestToolsPlugin) instance; + } + + /** + * Returns installable URL for this plugin. + * @return installable URL for this plugin. + */ + public String getInstallURL() + { + try + { + return Platform.resolve(getDescriptor().getInstallURL()).getFile(); + } + catch (IOException e) + { + return null; + } + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/WSITestToolsProperties.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/WSITestToolsProperties.java new file mode 100644 index 000000000..f9ed35a00 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/WSITestToolsProperties.java @@ -0,0 +1,207 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal; + +import java.io.UnsupportedEncodingException; +import java.util.Properties; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.Path; +import org.eclipse.wst.wsi.internal.util.WSIProperties; + +import com.ibm.etools.webservice.ui.plugin.WebServiceUIPlugin; +import com.ibm.etools.webservice.ui.wsi.preferences.PersistentWSIContext; + +/** + * WS-I test tools property. + * + * @author Lawrence Mandel, IBM + * + */ + +public class WSITestToolsProperties +{ + protected static String installURL = ""; + protected static String tadfile = ""; + + public final static String schemaDir = "common/schemas/"; + public final static String SSBP_ASSERTION_FILE = "common/profiles/SSBP10_BP11_TAD.xml"; + public final static String AP_ASSERTION_FILE = "common/profiles/AP10_BP11_SSBP10_TAD.xml"; + public final static String DEFAULT_ASSERTION_FILE = AP_ASSERTION_FILE; + + public static final String STOP_NON_WSI = PersistentWSIContext.STOP_NON_WSI; // "0"; + public static final String WARN_NON_WSI = PersistentWSIContext.WARN_NON_WSI; // "1"; + public static final String IGNORE_NON_WSI = PersistentWSIContext.IGNORE_NON_WSI; //"2"; + + /** + * Constructor. + */ + protected WSITestToolsProperties() + { + super(); + // TODO Auto-generated constructor stub + } + + /** + * Set the schema location. + * @param dir the schema location. + */ + public static void setInstallDir(String dir) + { + installURL = dir; + } + + /** + * Set local properties. + */ + public static void setLocal() + { + Properties schemaLocationProperties = new Properties(); + String schemaURL = installURL + schemaDir; + try + { + schemaLocationProperties.setProperty( + "wsi.analyzer.xmlschema.schema", + URIEncoder.encode(schemaURL + "XMLSchema.xsd", "UTF8")); + schemaLocationProperties.setProperty( + "wsi.analyzer.wsdl.schema", + URIEncoder.encode(schemaURL + "wsdl11.xsd", "UTF8")); + schemaLocationProperties.setProperty( + "wsi.analyzer.soap.schema", + URIEncoder.encode(schemaURL + "soapEnvelope.xsd", "UTF8")); + schemaLocationProperties.setProperty( + "wsi.analyzer.wsdlsoap.schema", + URIEncoder.encode(schemaURL + "wsdlSoap.xsd", "UTF8")); + } + catch (UnsupportedEncodingException e) + { + schemaLocationProperties.setProperty( + "wsi.analyzer.xmlschema.schema", + URIEncoder.encode(schemaURL + "XMLSchema.xsd")); + schemaLocationProperties.setProperty( + "wsi.analyzer.wsdl.schema", + URIEncoder.encode(schemaURL + "wsdl11.xsd")); + schemaLocationProperties.setProperty( + "wsi.analyzer.soap.schema", + URIEncoder.encode(schemaURL + "soapEnvelope.xsd")); + schemaLocationProperties.setProperty( + "wsi.analyzer.wsdlsoap.schema", + URIEncoder.encode(schemaURL + "wsdlSoap.xsd")); + } + WSIProperties.setThreadLocalProperties(schemaLocationProperties); + } + + + /* + * (non-Javadoc) + * + * @see org.eclipse.wsdl.validate.wsi.CheckWSI#checkWSI(java.lang.String) + */ + public static WSIPreferences checkWSIPreferences(String fileuri) + { + WSIPreferences preferences = new WSIPreferences(); + + // Remove file: and any slashes from the fileuri. + // Eclipse's resolution mechanism needs to start with the drive. + String uriStr = trimURI(fileuri); + + WebServiceUIPlugin wsui = WebServiceUIPlugin.getInstance(); + PersistentWSIContext APcontext = wsui.getWSIAPContext(); + PersistentWSIContext SSBPcontext = wsui.getWSISSBPContext(); + + IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(new Path(uriStr)); + if (files != null && files.length == 1) + { + // check project level conpliance + IProject project = files[0].getProject(); + + if (APcontext.projectStopNonWSICompliances(project)) + { + preferences.setTADFile(installURL + AP_ASSERTION_FILE); + preferences.setComplianceLevel(PersistentWSIContext.STOP_NON_WSI); + } + else if (APcontext.projectWarnNonWSICompliances(project)) + { + preferences.setTADFile(installURL + AP_ASSERTION_FILE); + preferences.setComplianceLevel(PersistentWSIContext.WARN_NON_WSI); + } + else if (SSBPcontext.projectStopNonWSICompliances(project)) + { + preferences.setTADFile(installURL + SSBP_ASSERTION_FILE); + preferences.setComplianceLevel(PersistentWSIContext.STOP_NON_WSI); + } + else if (SSBPcontext.projectWarnNonWSICompliances(project)) + { + preferences.setTADFile(installURL + SSBP_ASSERTION_FILE); + preferences.setComplianceLevel(PersistentWSIContext.WARN_NON_WSI); + } + else + { + preferences.setTADFile(installURL + DEFAULT_ASSERTION_FILE); + preferences.setComplianceLevel(PersistentWSIContext.IGNORE_NON_WSI); + } + } + else + { + // If we can't obtain the project preference use the global preference. + String APlevel = APcontext.getPersistentWSICompliance(); + String SSBPlevel = SSBPcontext.getPersistentWSICompliance(); + if(APlevel.equals(PersistentWSIContext.STOP_NON_WSI)) + { + preferences.setTADFile(installURL + AP_ASSERTION_FILE); + preferences.setComplianceLevel(PersistentWSIContext.STOP_NON_WSI); + } + else if(APlevel.equals(PersistentWSIContext.WARN_NON_WSI)) + { + preferences.setTADFile(installURL + AP_ASSERTION_FILE); + preferences.setComplianceLevel(PersistentWSIContext.WARN_NON_WSI); + } + if(SSBPlevel.equals(PersistentWSIContext.STOP_NON_WSI)) + { + preferences.setTADFile(installURL + SSBP_ASSERTION_FILE); + preferences.setComplianceLevel(PersistentWSIContext.STOP_NON_WSI); + } + else if(SSBPlevel.equals(PersistentWSIContext.WARN_NON_WSI)) + { + preferences.setTADFile(installURL + SSBP_ASSERTION_FILE); + preferences.setComplianceLevel(PersistentWSIContext.WARN_NON_WSI); + } + else + { + preferences.setTADFile(installURL + DEFAULT_ASSERTION_FILE); + preferences.setComplianceLevel(PersistentWSIContext.IGNORE_NON_WSI); + } + } + return preferences; + } + + /** + * Remove file: and any slashes from the fileuri. + * Eclipse's resolution mechanism needs to start with the drive. + */ + private static String trimURI(String fileuri) + { + String uriStr = fileuri; + + if(fileuri.startsWith("file:")) + { + uriStr = fileuri.substring(5); + } + while(uriStr.startsWith("/") || uriStr.startsWith("\\")) + { + uriStr = uriStr.substring(1); + } + return uriStr; + } + +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/Analyzer.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/Analyzer.java new file mode 100644 index 000000000..cca9fcd1c --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/Analyzer.java @@ -0,0 +1,313 @@ +/** + * + * + * Copyright (c) 2002-2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + * + * + */ +package org.eclipse.wst.wsi.internal.analyzer; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.analyzer.config.AnalyzerConfig; +import org.eclipse.wst.wsi.internal.document.DocumentFactory; +import org.eclipse.wst.wsi.internal.log.Log; +import org.eclipse.wst.wsi.internal.profile.ProfileAssertions; +import org.eclipse.wst.wsi.internal.profile.validator.ProfileValidatorFactory; +import org.eclipse.wst.wsi.internal.report.Reporter; +import org.eclipse.wst.wsi.internal.util.MessageList; +import org.eclipse.wst.wsi.internal.util.TestUtils; +import org.eclipse.wst.wsi.internal.ToolInfo; + +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.List; +import java.util.Vector; + +/** + * The Analyzer will process all Profile conformance functions. + * This class should be sub-classed for each profile. + * + * @version 1.0.1 + * @author Jim Clune + * @author Peter Brittenham + */ +public abstract class Analyzer +{ + /** + * Message list. + */ + protected MessageList messageList = null; + + protected final static String RESOURCE_BUNDLE_NAME = + "org.wsi.test.analyzer.Analyzer"; + + public final static String USAGE_MESSAGE = + "Usage: Analyzer -config "; + + protected Reporter reporter = null; + protected AnalyzerContext analyzerContext = null; + protected CandidateInfo candidateInfo = null; + + /** + * Analyzer tool information. + */ + protected ToolInfo toolInfo = null; + + /** + * Profile validator factory. + */ + protected ProfileValidatorFactory factory = null; + + /** + * Profile validator factory. + */ + protected DocumentFactory documentFactory = null; + + /** + * Analyzer config file list. + */ + protected List analyzerConfigList = new Vector(); + protected int analyzerConfigIndex = 0; + + /** + * Profile assertions. + */ + protected ProfileAssertions profileAssertions = null; + + /** + * Log file. + */ + protected Log log = null; + + /** + * Create an instance of the analyzer tool. + * @param args command line arguments. + * @param toolInfo analyzer tool information. + * @throws WSIException if problems creating the instance of the analyzer tool. + */ + public Analyzer(String[] args, ToolInfo toolInfo) throws WSIException + { + init(toolInfo); + + // Get new config object + this.analyzerConfigList.add( + analyzerConfigIndex, + documentFactory.newAnalyzerConfig()); + getAnalyzerConfig().init(messageList); + + // Parse command line arguments + getAnalyzerConfig().parseArgs(args, true); + + // Display copyright and options that were specified + TestUtils.printToolInfo(toolInfo); + System.out.println(getAnalyzerConfig().toString()); + + // Display message + printMessage( + "progress01", + null, + "Please wait while the specified artifacts are analyzed..."); + } + + /** + * Create an instance of the analyzer tool. + * @param args command line arguments. + * @param toolInfo analyzer tool information. + * @param validate flag for config options validation. + * @throws WSIException if problems creating the instance of the analyzer tool. + */ + public Analyzer(String[] args, ToolInfo toolInfo, boolean validate) throws WSIException + { + init(toolInfo); + + // Get new config object + this.analyzerConfigList.add( + analyzerConfigIndex, + documentFactory.newAnalyzerConfig()); + getAnalyzerConfig().init(messageList); + + // Parse command line arguments + getAnalyzerConfig().parseArgs(args, validate); + + // Display copyright and options that were specified + TestUtils.printToolInfo(toolInfo); + System.out.println(getAnalyzerConfig().toString()); + + // Display message + printMessage( + "progress01", + null, + "Please wait while the specified artifacts are analyzed..."); + } + + /** + * Create an instance of the analyzer tool. + * @param analyzerConfigList analyzer config file list. + * @param toolInfo analyzer tool information. + * @throws WSIException if problems creating the instance of the analyzer tool. + */ + public Analyzer(List analyzerConfigList, ToolInfo toolInfo) + throws WSIException + { + init(toolInfo); + + this.analyzerConfigList = analyzerConfigList; + } + + /** + * Common initialization. + * @param toolInfo analyzer tool information. + * @throws WSIException if problems occur during common initialization. + */ + protected void init(ToolInfo toolInfo) throws WSIException + { + this.toolInfo = toolInfo; + + // Create message list + messageList = new MessageList(RESOURCE_BUNDLE_NAME); + + // Create profile validator factory + factory = ProfileValidatorFactory.newInstance(); + + // Create document factory + documentFactory = DocumentFactory.newInstance(); + } + + /** + * Process all conformance validation functions. + * @return status code. + * @throws WSIException if problems occur during validation. + */ + public int validateAll() throws WSIException + { + int statusCode = 0; + int tempStatusCode; + + for (int index = 0; index < analyzerConfigList.size(); index++) + { + // DEBUG: + //System.out.println("index: " + index); + + // Set current analyzer config index + setAnalyzerConfig(index); + + if ((tempStatusCode = validateConformance()) > statusCode) + statusCode = tempStatusCode; + } + + return statusCode; + } + + /** + * Process all conformance validation functions. + * @return status code. + * @throws WSIException if problems occur during conformance validation. + */ + public abstract int validateConformance() throws WSIException; + + /** + * Get tool information. + * @return the tool information. + */ + public ToolInfo getToolInfo() + + { + return this.toolInfo; + } + + /** + * Set current analyzer configuration. + * @param index urrent analyzer configuration. + * @see #getAnalyzerConfig + */ + protected void setAnalyzerConfig(int index) + { + this.analyzerConfigIndex = index; + } + + /** + * Get analyzer configuration information. + * @return analyzer configuration information. + * @see #setAnalyzerConfig + */ + public AnalyzerConfig getAnalyzerConfig() + { + return (AnalyzerConfig) this.analyzerConfigList.get(analyzerConfigIndex); + } + + /** + * Print a message from the resource bundle. + * @param key a key. + * @param messageData message data. + * @param defaultMessage a default message. + */ + public void printMessage( + String key, + String messageData, + String defaultMessage) + { + messageList.printMessage(key, messageData, defaultMessage); + } + + /** + * Print message. + * @param key a key. + * @param messageData message data. + * @param defaultMessage a default message. + */ + public static void staticPrintMessage( + String key, + String messageData, + String defaultMessage) + { + MessageList.printMessage( + RESOURCE_BUNDLE_NAME, + key, + messageData, + defaultMessage); + } + + /** + * Return XML string representation of this object. + * @param namespaceName a namespace prefix. + * @return XML string representation of this object. + */ + public String toXMLString(String namespaceName) + { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + + // Start + pw.print(toolInfo.getStartXMLString(namespaceName)); + + // Config + pw.print( + getAnalyzerConfig().toXMLString( + WSIConstants.NS_NAME_WSI_ANALYZER_CONFIG)); + + // End + pw.println(toolInfo.getEndXMLString(namespaceName)); + + return sw.toString(); + } + + /** + * Print a message. + * @param message a message. + */ + public void printMessage(String message) + { + if (getAnalyzerConfig().getVerboseOption()) + { + System.err.println(message); + } + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/Analyzer.properties b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/Analyzer.properties new file mode 100644 index 000000000..d66cb7584 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/Analyzer.properties @@ -0,0 +1,44 @@ +# /** +# * +# * +# * Copyright (c) 2002-2005 IBM Corporation and others. +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * IBM - Initial API and implementation +# * +# * +# */ + +# +# Analyzer resource bundle. +# +usage01=Usage: Analyzer -config +created01=Conformance report has been created. +progress01=Please wait while the specified artifacts are analyzed... +error01=Analyzer Error: +error02=Analyzer Stopped By Exception: +error03=The conformance validation process failed. +exception01=Exception: +config01=Analyzer configuration file was not found. Specified file location: +config02=Could not find log file. Specified file location: +config03=Could not find WSDL file. Specified file location: +config04=Can not specify both the WSDL reference and UDDI reference options. +config05=WSDL document was either not found or could not be processed. +config06=Invalid analyzer configuration element: +config07=Both the and elements must be specified. +config08=Could not read analyzer configuration file. Specified file location: +config09=The parentElementName attribute must be specified with a WSDL type of port or operation. +config10=The -wsdlElement option must appear after the -wsdlURI or -uddiKey options. +config11=The -serviceLocation option must appear after the -wsdlURI or -uddiKey options. +config12=The specified option is not supported: +config13=Option did not contain a value. Specified option: +config14=Could not find test assertion document. Specified file location: +config15=Report file already exists and replace option was not specified. +config16=Test assertion document location must be specified. +config17=Could not get report file location. +config18=Invalid correlation type specified. +config19=The WSDL element name must be specified. diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/AnalyzerContext.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/AnalyzerContext.java new file mode 100644 index 000000000..53be32830 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/AnalyzerContext.java @@ -0,0 +1,113 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.analyzer; + +import org.eclipse.wst.wsi.internal.xml.XMLDocumentCache; + +/** + * This class contains contextual information which is required by test assertions across all artifacts. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public class AnalyzerContext +{ + protected ServiceReference serviceReference = null; + protected CandidateInfo candidateInfo = null; + protected XMLDocumentCache documentList = new XMLDocumentCache(); + + /** + * Do not allow the usage of the null constructor. + */ + private AnalyzerContext() + { + } + + /** + * Create analyzer context with service reference. + * @param serviceReference a service reference. + */ + public AnalyzerContext(ServiceReference serviceReference) + { + this.serviceReference = serviceReference; + } + + /** + * Get service reference. + * @return service reference. + * @see #setServiceReference + */ + public ServiceReference getServiceReference() + { + return this.serviceReference; + } + + /** + * Set service reference. + * @param serviceReference a service reference. + * @see #getServiceReference + */ + public void setServiceReference(ServiceReference serviceReference) + { + this.serviceReference = serviceReference; + } + + /** + * Returns the candidateInfo. + * @return CandidateInfo. + * @see #setCandidateInfo + */ + public CandidateInfo getCandidateInfo() + { + return candidateInfo; + } + + /** + * Sets the candidateInfo. + * @param candidateInfo the candidateInfo to set. + * @see #getCandidateInfo + */ + public void setCandidateInfo(CandidateInfo candidateInfo) + { + this.candidateInfo = candidateInfo; + } + + /** + * Get the list of cached documents. + * @return the list of cached documents. + * @see #setDocumentList + */ + public XMLDocumentCache getDocumentList() + { + return documentList; + } + + /** + * Set the list of cached documents. + * @param documentList a list of cached documents. + * @see #getDocumentList + */ + public void setDocumentList(XMLDocumentCache documentList) + { + this.documentList = documentList; + } + + /** + * Add a document to the list of cached documents. + * @param key a key to associate with the given document. + * @param document a document to be identified with the given key. + */ + public void addDocument(Object key, Object document) + { + this.documentList.put(key, document); + } + +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/AssertionFailException.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/AssertionFailException.java new file mode 100644 index 000000000..0b75c8370 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/AssertionFailException.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.analyzer; + +/** + * Base Exception for Assertion Fail. + * + * @author gturrell + * */ +public class AssertionFailException extends Exception +{ + + /** + * Comment for serialVersionUID + */ + private static final long serialVersionUID = 3257007635743258933L; + + /** + * Constructor for AssertionException. + */ + public AssertionFailException() + { + super(); + } + + /** + * Constructor for AssertionException. + * @param arg0 the detail message. + */ + public AssertionFailException(String arg0) + { + super(arg0); + } + +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/AssertionNotApplicableException.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/AssertionNotApplicableException.java new file mode 100644 index 000000000..a8cff2939 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/AssertionNotApplicableException.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.analyzer; + +/** + * Exception for Assertion Not Applicable. + * + * @author gturrell + */ +public class AssertionNotApplicableException extends Exception +{ + + /** + * Comment for serialVersionUID + */ + private static final long serialVersionUID = 3905523782994112564L; + + /** + * Constructor for AssertionNotApplicableException. + */ + public AssertionNotApplicableException() + { + super(); + } + + /** + * Constructor for AssertionNotApplicableException. + * @param arg0 the detail message. + */ + public AssertionNotApplicableException(String arg0) + { + super(arg0); + } + +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/AssertionPassException.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/AssertionPassException.java new file mode 100644 index 000000000..7163566f5 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/AssertionPassException.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.analyzer; + +/** + * Exception for Assertion Pass. + * + * @author gturrell + */ +public class AssertionPassException extends Exception +{ + + /** + * Comment for serialVersionUID + */ + private static final long serialVersionUID = 3257285842283541810L; + + /** + * Constructor for AssertionPAssException. + */ + public AssertionPassException() + { + super(); + } + + /** + * Constructor for AssertionPAssException. + * @param arg0 the detail message. + */ + public AssertionPassException(String arg0) + { + super(arg0); + } + +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/AssertionResultException.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/AssertionResultException.java new file mode 100644 index 000000000..c97ce781e --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/AssertionResultException.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.analyzer; + +/** + * Exception for Assertion Result. + * + * @author gturrell + */ +public class AssertionResultException extends Exception +{ + + /** + * Comment for serialVersionUID + */ + private static final long serialVersionUID = 3256720684700152632L; + private String detailMessage; + /** + * Constructor for AssertionresultException. + */ + public AssertionResultException() + { + super(); + detailMessage = null; + } + + /** + * Constructor for AssertionResultException. + * @param arg0 the detail message. + */ + public AssertionResultException(String arg0) + { + super(arg0); + detailMessage = null; + } + + /** + * Constructor for AssertionResultException. + * @param arg0 the detail message. + * @param arg1 further detailed message. + */ + public AssertionResultException(String arg0, String arg1) + { + super(arg0); + detailMessage = arg1; + } + + /** + * Returns the detailMessage. + * @return the detailMessage. + */ + public String getDetailMessage() + { + return detailMessage; + } + +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/BasicProfileAnalyzer.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/BasicProfileAnalyzer.java new file mode 100644 index 000000000..d310711da --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/BasicProfileAnalyzer.java @@ -0,0 +1,655 @@ +/******************************************************************************* + * Copyright (c) 2002-2003 IBM Corporation, Parasoft, Beacon Information Technology Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + * Parasoft - Initial API and implementation + * BeaconIT - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.analyzer; + +import java.io.IOException; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.List; + +import javax.wsdl.WSDLException; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.WSIFileNotFoundException; +import org.eclipse.wst.wsi.internal.log.LogReader; +import org.eclipse.wst.wsi.internal.log.MessageEntryHandler; +import org.eclipse.wst.wsi.internal.profile.ProfileAssertionsReader; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.EnvelopeValidator; +import org.eclipse.wst.wsi.internal.profile.validator.MessageValidator; +import org.eclipse.wst.wsi.internal.profile.validator.UDDIValidator; +import org.eclipse.wst.wsi.internal.profile.validator.WSDLValidator; +import org.eclipse.wst.wsi.internal.report.ArtifactReference; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.report.Report; +import org.eclipse.wst.wsi.internal.report.ReportArtifact; +import org.eclipse.wst.wsi.internal.report.ReportContext; +import org.eclipse.wst.wsi.internal.report.ReportWriter; +import org.eclipse.wst.wsi.internal.report.impl.DefaultReporter; +import org.eclipse.wst.wsi.internal.util.ArtifactType; +import org.eclipse.wst.wsi.internal.util.WSIProperties; +import org.eclipse.wst.wsi.internal.wsdl.WSDLDocument; +import org.uddi4j.transport.TransportFactory; + +import org.eclipse.wst.wsi.internal.ToolInfo; + +/** + * Analyzes log files to confirm conformance to a profile. + * + * @version 1.0.1 + * @author Jim Clune + * @author Peter Brittenham + * @author Graham Turrell + */ +public class BasicProfileAnalyzer extends Analyzer +{ + /** + * Tool information. + */ + public static final String TOOL_NAME = "Analyzer"; + + /** + * WSDL document to analyze. + */ + protected WSDLDocument wsdlDocument = null; + + /** + * Basic profile analyzer. + * @param args command line arguments. + * @throws WSIException if unable to create a Basic profile analyzer. + */ + public BasicProfileAnalyzer(String[] args) throws WSIException + { + super(args, new ToolInfo(TOOL_NAME)); + } + + /** + * Basic profile analyzer. + * @param args command line arguments. + * @param validate flag for command line argument validation. + * @throws WSIException if unable to create a Basic profile analyzer. + */ + public BasicProfileAnalyzer(String[] args, boolean validate) throws WSIException + { + super(args, new ToolInfo(TOOL_NAME), validate); + } + + /** + * Basic profile analyzer. + * @param analyzerConfigList a list of configurations for the analyzer. + * @throws WSIException if unable to create a Basic profile analyzer. + */ + public BasicProfileAnalyzer(List analyzerConfigList) throws WSIException + { + super(analyzerConfigList, new ToolInfo(TOOL_NAME)); + } + + /** + * Basic profile analyzer. + * @param analyzerConfigList a list of configurations for the analyzer. + * @param wsdlURI a wsdl document location. + * @throws WSIException if unable to create a Basic profile analyzer. + */ + public BasicProfileAnalyzer(List analyzerConfigList, String wsdlURI) + throws WSIException + { + super(analyzerConfigList, new ToolInfo(TOOL_NAME)); + + try + { + // Get the WSDL document + if (wsdlURI != null) + this.wsdlDocument = new WSDLDocument(wsdlURI); + } + + catch (WSDLException we) + { + throw new WSIException(we.getMessage(), we); + } + + } + + /** + * Process all conformance validation functions. + * @return status code. + * @throws WSIException if conformance validation process failed. + */ + public int validateConformance() throws WSIException + { + int statusCode = 0; + + Report report = null; + ReportArtifact reportArtifact = null; + String wsdlURI = null; + //WSDLDocument wsdlDocument = null; + + // Set up initial analyzer context based on entries in the config file + this.analyzerContext = + new AnalyzerContext(new ServiceReference(getAnalyzerConfig())); + + try + { + // Read profile assertions + ProfileAssertionsReader profileAssertionsReader = + documentFactory.newProfileAssertionsReader(); + this.profileAssertions = + profileAssertionsReader.readProfileAssertions( + getAnalyzerConfig().getTestAssertionsDocumentLocation()); + + // Create report from document factory + report = documentFactory.newReport(); + report.setLocation(getAnalyzerConfig().getReportLocation()); + + // Create report context + ReportContext reportContext = + new ReportContext( + WSIConstants.DEFAULT_REPORT_TITLE, + profileAssertions, + this); + report.setReportContext(reportContext); + + // Create report writer + ReportWriter reportWriter = documentFactory.newReportWriter(); + // I18N: 2003.02.26 modified by K.Nakagome@BeaconIT + //reportWriter.setWriter(new FileWriter(analyzerConfig.getReportLocation())); + reportWriter.setWriter(getAnalyzerConfig().getReportLocation()); + + // Create reporter + this.reporter = new DefaultReporter(report, reportWriter); + + // Start writing report + this.reporter.startReport(); + + // -------------------------------- + // DISCOVERY ARTIFACT: + // -------------------------------- + + // Set current artifact + reportArtifact = setCurrentArtifact(ArtifactType.ARTIFACT_TYPE_DISCOVERY); + + // If UDDI options specified, then process UDDI test assertions + if ((wsdlURI = validateUDDI(reportArtifact, factory.newUDDIValidator())) + == null) + { + if (getAnalyzerConfig().isWSDLReferenceSet()) + { + // Otherwise use the WSDL options to get the WSDL location + wsdlURI = getAnalyzerConfig().getWSDLLocation(); + } + } + + // Indicate that we are done with this artifact + this.reporter.endCurrentArtifact(); + + // -------------------------------- + // DESCRIPTION ARTIFACT: + // -------------------------------- + + // Set current artifact + reportArtifact = + setCurrentArtifact(ArtifactType.ARTIFACT_TYPE_DESCRIPTION); + + // Call WSDLValidator + wsdlDocument = + validateWSDL( + reportArtifact, + factory.newWSDLValidator(), + wsdlURI, + wsdlDocument); + + // If WSDL document object is null, then throw exception + if ((wsdlDocument == null) && (getAnalyzerConfig().isWSDLReferenceSet())) + { + throw new WSIException( + messageList.getMessage( + "config05", + "WSDL document was either not found or could not be processed.")); + } + + // Indicate that we are done with this artifact + this.reporter.endCurrentArtifact(); + + // REMOVE: + // If processing log entries and there isn't a WSDL URI, + // then throw an exception since it is required to process the log entries + //if ((wsdlURI == null) && (analyzerConfig.getLogLocation() != null)) { + // throw new WSIException("Must specify the WSDL document location to validate message log."); + //} + + // -------------------------------- + // MESSAGE ARTIFACT: + // -------------------------------- + + // Set current artifact + reportArtifact = setCurrentArtifact(ArtifactType.ARTIFACT_TYPE_MESSAGE); + + // Process test assertions for the messages + validateMessages( + reportArtifact, + factory.newMessageValidator(), + wsdlDocument); + + // Indicate that we are done with this artifact + this.reporter.endCurrentArtifact(); + + // -------------------------------- + // ENVELOPE ARTIFACT: + // -------------------------------- + + // If that is not the Basic Profile 1.0, then process + // the envelope artifact + if (!profileAssertions.getTADName() + .equals(WSIConstants.BASIC_PROFILE_TAD_NAME)) + { + + // Set current artifact + reportArtifact = setCurrentArtifact(ArtifactType.ARTIFACT_TYPE_ENVELOPE); + + // Process test assertions for the envelopes + validateEnvelopes( + reportArtifact, + factory.newEnvelopeValidator(), + wsdlDocument); + + // Indicate that we are done with this artifact + this.reporter.endCurrentArtifact(); + } + + // Finish the conformance report + reporter.finishReport(); + } + + catch (Exception e) + { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + + String message = + messageList.getMessage( + "error03", + "The conformance validation process failed."); + + // Finish report + if (reporter != null) + { + pw.println(message); + pw.println( + messageList.getMessage("exception01", "Exception: ") + + e.getClass().getName()); + e.printStackTrace(pw); + reporter.finishReportWithError(sw.toString()); + } + + if (e instanceof WSIException) + throw (WSIException) e; + else + throw new WSIException(message, e); + } + + if (report != null) + { + statusCode = + (report.getSummaryResult().equals(AssertionResult.RESULT_PASSED) + ? 0 + : 1); + } + + return statusCode; + } + + /** + * Run UDDI test assertions. + */ + private String validateUDDI( + ReportArtifact reportArtifact, + UDDIValidator uddiValidator) + throws WSIException + { + String wsdlURI = null; + + // Init UDDIValidator + uddiValidator.init( + this.analyzerContext, + this.profileAssertions.getArtifact(ArtifactType.TYPE_DISCOVERY), + reportArtifact, + getAnalyzerConfig().getUDDIReference(), + this.reporter); + + // Call UDDIValidator + if (getAnalyzerConfig().isUDDIReferenceSet()) + { + wsdlURI = uddiValidator.validate(); + + // Cleanup + uddiValidator.cleanup(); + } + + else + { + // Set all missingInput + uddiValidator.setAllMissingInput(); + } + + return wsdlURI; + } + + /** + * Run WSDL test assertions. + */ + private WSDLDocument validateWSDL( + ReportArtifact reportArtifact, + WSDLValidator wsdlValidator, + String wsdlURI, + WSDLDocument wsdlDocument) + throws WSIException + { + WSDLDocument returnWSDLDocument = null; + + // Init WSDLValidator + wsdlValidator.init( + this.analyzerContext, + this.profileAssertions.getArtifact(ArtifactType.TYPE_DESCRIPTION), + reportArtifact, + wsdlURI, + wsdlDocument, + this.reporter); + + // If a WSDL URI was specified or located in a UDDI registry, then process the WSDL tests + if (wsdlURI != null || wsdlDocument != null) + { + // Call WSDLValidator + returnWSDLDocument = wsdlValidator.validate(); + + // Cleanup + wsdlValidator.cleanup(); + } + + else + { + // Set all missingInput + wsdlValidator.setAllMissingInput(); + } + + return returnWSDLDocument; + } + + /** + * Run message test assertions. + */ + private void validateMessages( + ReportArtifact reportArtifact, + MessageValidator messageValidator, + WSDLDocument wsdlDocument) + throws WSIException + { + //Log log = null; + //MessageEntry logEntry = null; + + // Init MessageValidator + messageValidator.init( + this.analyzerContext, + this.profileAssertions.getArtifact(ArtifactType.TYPE_MESSAGE), + reportArtifact, + wsdlDocument, + this.reporter); + + // If the log file location was specified, then process test assertions for the messages + if (getAnalyzerConfig().getLogLocation() != null) + { + // Get the log file reader + LogReader logReader = documentFactory.newLogReader(); + + // Create log reader callback + MessageProcessor messageProcessor = + new MessageProcessor(messageValidator); + + // Start reading the log file + logReader.readLog(getAnalyzerConfig().getLogLocation(), messageProcessor); + + // Cleanup + messageValidator.cleanup(); + } + + // Otherwise all are missingInput + else + { + // Set all missingInput + messageValidator.setAllMissingInput(); + } + } + + /** + * Run envelope test assertions. + */ + private void validateEnvelopes( + ReportArtifact reportArtifact, + EnvelopeValidator envelopeValidator, + WSDLDocument wsdlDocument) + throws WSIException + { + // Init envelopeValidator + envelopeValidator.init( + this.analyzerContext, + this.profileAssertions.getArtifact(ArtifactType.TYPE_ENVELOPE), + reportArtifact, + wsdlDocument, + this.reporter); + + // If the log file location was specified, then process test assertions for the messages + if (getAnalyzerConfig().getLogLocation() != null) + { + // Get the log file reader + LogReader logReader = documentFactory.newLogReader(); + + // Create log reader callback + EnvelopeProcessor envelopeProcessor = + new EnvelopeProcessor(envelopeValidator); + + // Start reading the log file + logReader.readLog(getAnalyzerConfig().getLogLocation(), envelopeProcessor); + + // Cleanup + envelopeValidator.cleanup(); + } + + // Otherwise all are missingInput + else + { + // Set all missingInput + envelopeValidator.setAllMissingInput(); + } + } + + /** + * Command line interface for the analyzer tool. + * @param args command line arguments. + * @throws IOException if IO problems occur. + */ + public static void main(String[] args) throws IOException + { + int statusCode = 0; + Analyzer analyzer = null; + + try + { + // Set document builder factory class + System.setProperty( + WSIProperties.PROP_JAXP_DOCUMENT_FACTORY, + WSIProperties.getProperty(WSIProperties.PROP_JAXP_DOCUMENT_FACTORY)); + + // Set the system property for UDDI4J transport + System.setProperty( + TransportFactory.PROPERTY_NAME, + WSIProperties.getProperty(TransportFactory.PROPERTY_NAME)); + + // Create the analyzer object + analyzer = new BasicProfileAnalyzer(args); + + // Have it process the conformance validation functions + statusCode = analyzer.validateConformance(); + + // Display message + analyzer.printMessage( + "created01", + null, + "Conformance report has been created."); + } + + catch (Exception e) + { + statusCode = 1; + + boolean printStackTrace = true; + String messageID; + String defaultMessage; + String messageData; + + if ((e instanceof WSIFileNotFoundException) + || (e instanceof IllegalArgumentException)) + { + //printStackTrace = false; + messageID = "error01"; + defaultMessage = "Analyzer Error:"; + messageData = e.getMessage(); + } + + else + { + //printStackTrace = true; + messageID = "error02"; + defaultMessage = "Analyzer Stopped By Exception:"; + messageData = e.toString(); + } + + if (analyzer != null) + analyzer.printMessage(messageID, messageData, defaultMessage); + else + Analyzer.staticPrintMessage(messageID, messageData, defaultMessage); + + if (analyzer != null + && analyzer.getAnalyzerConfig() != null + && analyzer.getAnalyzerConfig().getVerboseOption()) + dump(e); + } + + // Exit + System.exit(statusCode); + } + + /** + * Set current artifact. + * @param artifactType an ArtifactType object. + * @return a ReportArtifact object. + * @throws WSIException if problems creating report artifact. + */ + protected ReportArtifact setCurrentArtifact(ArtifactType artifactType) + throws WSIException + { + // Create artifact + ReportArtifact reportArtifact = reporter.createArtifact(); + reportArtifact.setType(artifactType); + + // Add artifact to report + this.reporter.setCurrentArtifact(reportArtifact); + + return reportArtifact; + } + + /** + * Print exception. + * @param t a Throwable object. + */ + public static void dump(Throwable t) + { + while (t instanceof WSIException) + { + Throwable nested = ((WSIException) t).getTargetException(); + if (nested == null) + break; + else + t = nested; + } + t.printStackTrace(); + } + + /** + * Message processor class. + */ + class MessageProcessor implements MessageEntryHandler + { + MessageValidator messageValidator = null; + + /** + * Create message processor as a log reader callback function. + */ + MessageProcessor(MessageValidator messageValidator) + { + this.messageValidator = messageValidator; + } + + /** + * Process artifact reference. + */ + public void processArtifactReference(ArtifactReference artifactReference) + throws WSIException + { + reporter.addArtifactReference(artifactReference); + } + + /** + * Process a single log entry. + */ + public void processLogEntry(EntryContext entryContext) throws WSIException + { + // Validate message + messageValidator.validate(entryContext); + } + + } + + /** + * Envelope processor class. + */ + class EnvelopeProcessor implements MessageEntryHandler + { + EnvelopeValidator envelopeValidator = null; + + /** + * Create envelope processor as a log reader callback function. + */ + EnvelopeProcessor(EnvelopeValidator envelopeValidator) + { + this.envelopeValidator = envelopeValidator; + } + + /** + * Process artifact reference. + */ + public void processArtifactReference(ArtifactReference artifactReference) + throws WSIException + { + reporter.addArtifactReference(artifactReference); + } + + /** + * Process a single log entry. + */ + public void processLogEntry(EntryContext entryContext) throws WSIException + { + // Validate envelopes + envelopeValidator.validate(entryContext); + } + + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/CandidateInfo.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/CandidateInfo.java new file mode 100644 index 000000000..0939da832 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/CandidateInfo.java @@ -0,0 +1,921 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.analyzer; + +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Vector; + +import javax.wsdl.Binding; +import javax.wsdl.BindingOperation; +import javax.wsdl.Definition; +import javax.wsdl.Fault; +import javax.wsdl.Import; +import javax.wsdl.Message; +import javax.wsdl.Operation; +import javax.wsdl.Port; +import javax.wsdl.PortType; +import javax.wsdl.Service; +import javax.wsdl.Types; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.soap.SOAPAddress; +import javax.xml.namespace.QName; + +import org.apache.xerces.util.URI; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.analyzer.config.WSDLElement; +import org.eclipse.wst.wsi.internal.wsdl.WSDLDocument; +import org.eclipse.wst.wsi.internal.wsdl.WSDLUtils; + +/** + * Provide a normalized set of data relating to the service under test. + * For example, with endpoint correlation and wsdlElement of type "message" + * there could be multiple matches for most element types including WSDL Service. + * (though the objective is to ensure filtering to a single service if at all possible). + * + * @author gturrell + */ + +// ADD:could be better as a singleton? + +public class CandidateInfo +{ + + // Normalized fixed correlation data derived from the analyzer config and the wsdl, + // representing what we know about the service from these two sources. + private Definition[] definitions = null; + + private Import[] imports = null; + private Types[] types = null; + + private Message[] messages = null; + private Operation[] operations = null; + private PortType[] portTypes = null; + private Binding[] bindings = null; + private Port[] ports = null; + + private URI[] endPoints = null; // list obtainable from a port + + private WSDLDocument wsdlDocument; // reference probably not desirable here + + /** + * Constructor for CandidateInfo. + * Extract normalised entry data from wsdl, according to config wsdlElement & serviceLocation + * @param serviceReference a ServiceReference object. + * @param wsdlDocument a WSDL document. + * @throws WSIException if problems occur creating CandidateInfo object. + */ + public CandidateInfo( + ServiceReference serviceReference, + WSDLDocument wsdlDocument) + throws WSIException + { + + // ADD: check for null document? + + WSDLElement wsdlElement = serviceReference.getWSDLElement(); + + this.wsdlDocument = wsdlDocument; + + /* + * Generalised fields independent of wsdlElement: + */ + // ADD: check whether these need to be either expanded or filtered down. + // Assume WSDL4J pulls int the full tree at the root document for now + //this.imports = wsdlDocument.getImports(); + + // ... or if only down to first level.... + this.imports = + (Import[]) getAllImports( + wsdlDocument.getDefinitions()).toArray(new Import[] { + }); + + /* Definitions. + * Note that the the first array element is for the root doc + * which contains all WSDL elements in scope via declarations, + * as well as the root document itself. Therefore the second definitions + * array element and above are redundant, but *may* prove useful to the assertion + * code. + */ + + this.definitions = new Definition[imports.length + 1]; + // allow room for root doc + + this.definitions[0] = wsdlDocument.getDefinitions(); // root document + + // Allocate array for types elements + Types[] tempTypes = new Types[definitions.length]; + + int typesCount = 0; + + if (definitions[0].getTypes() != null) + { + tempTypes[0] = this.definitions[0].getTypes(); // root document + typesCount++; + } + + // Definitions from other (imported) wsdls correlating to the candidate + // Only one level down for now + for (int i = 0; i < imports.length; i++) + { + if (((definitions[i + 1] = imports[i].getDefinition()) != null) + && (definitions[i + 1].getTypes() != null)) + { + tempTypes[typesCount] = definitions[i + 1].getTypes(); + typesCount++; + } + } + + if (typesCount > 0) + { + this.types = new Types[typesCount]; + + for (int i = 0; i < typesCount; i++) + this.types[i] = tempTypes[i]; + } + /* + * Populate element hierachy: + * Port + * Binding + * PortType + * operation(s) + * message(s) + */ + + if (wsdlElement.isPort()) + { + + Port port = null; + + // Use parentElementName to qualify the port within a service. + QName serviceName = wsdlElement.getParentElementQName(); + Service[] s = wsdlDocument.getServices(); + String portName = wsdlElement.getName(); + for (int i = 0; i < s.length && port == null; i++) + { + if (s[i].getQName().equals(serviceName)) + { + port = s[i].getPort(portName); + } + } + + if (port == null) + { + throw new WSIException( + "WSDL Port \'" + + portName + + "\' for Service \'" + + serviceName + + "\' not found in service description"); + } + else + { + this.ports = new Port[] { port }; + // ADD: do serviceLocation check for soapbind:address? + descendents(port); + } + + // ADD: the following could be instantiated here instead to refine context info + // definitions + // imports + // types + + } + + else if (wsdlElement.isBinding()) + { + if (wsdlElement.getQName() != null + && wsdlElement.getQName().getLocalPart() != null + && wsdlElement.getQName().getLocalPart().length() > 0) + { + Binding binding = + wsdlDocument.getDefinitions().getBinding(wsdlElement.getQName()); + + if (binding == null) + { + throw new WSIException( + "WSDL Binding named \'" + + wsdlElement.getQName() + + "\' not found in service description"); + } + else + { + this.bindings = new Binding[] { binding }; + + // the rest ... below binding: + // portTypes from binding + // operations from portTypes + // messages from operations + descendents(binding); + + // above binding: + // ports + // definitions, imports, types (future?) + // ancestors(bindings); + } + } + } + + else if (wsdlElement.isPortType()) + { + + PortType portType = + wsdlDocument.getDefinitions().getPortType(wsdlElement.getQName()); + this.portTypes = new PortType[] { portType }; + + if (portType == null) + { + throw new WSIException( + "WSDL PortType named \'" + + wsdlElement.getQName() + + "\' not found in service description"); + } + else + { + this.portTypes = new PortType[] { portType }; + // the rest ... below portType: + descendents(portType); + + // above portType: + // ports + // definitions, imports, types (future) ? + //ancestors(portTypes); + } + } + else if (wsdlElement.isOperation()) + { + + Operation operation = null; + String configOpName = wsdlElement.getName(); + + // Use parentElementName to qualify the operation within a portType. + QName portTypeName = wsdlElement.getParentElementQName(); + PortType[] p = wsdlDocument.getPortTypes(); + for (int i = 0; i < p.length && operation == null; i++) + { + if (p[i].getQName().equals(portTypeName)) + { + // wsdl4j available method call below implies that only + // name+inputname+outputname uniquely defines operation! + // Since we do not have & name information + // available in the config, use this instead for now: - + // Get the first operation we find: + Iterator opIt = p[i].getOperations().iterator(); + Operation op = null; + while (opIt.hasNext() && operation == null) + { + op = (Operation) opIt.next(); + if (configOpName.equals(op.getName())) + { + operation = op; + } + } + } + } + + if (operation == null) + { + throw new WSIException( + "No WSDL Operation named \'" + + wsdlElement.getQName() + + "\' found in service description"); + } + else + { + this.operations = new Operation[] { operation }; + + descendents(operation); + //ancestors(operations); + } + } + + else if (wsdlElement.isMessage()) + { + + Message message = + wsdlDocument.getDefinitions().getMessage(wsdlElement.getQName()); + if (message == null) + { + throw new WSIException( + "No WSDL Message named \'" + + wsdlElement.getQName() + + "\' found in service description"); + } + else + { + this.messages = new Message[] { message }; + + //ancestors(messages); + } + } + + else + { + throw new WSIException( + "Unrecognised in config: " + wsdlElement.getType()); + } + + // get info about the effective service location (s) + //this.endPoints = deriveEndpoints(analyzerConfig, this.ports, this.definitions); + this.endPoints = + deriveEndpoints(serviceReference, this.ports, this.definitions); + } + + /** + * ancestor code is not used at present. + * + */ + /* + protected void ancestors(Port[] ports) { + // no ancestors of Port required (for now) + } + protected void ancestors(Binding[] bindings) { + // Ports from Bindings 1-2-1 + + // *** cheat for now - get ports from all services in the wsdl doc + // ADD: find correct mapping based on the supplied bindings + Service[] service = wsdlDocument.getServices(); + HashSet set = new HashSet(); + for (int i=0; i>service.length; i++) { + set.add(service[i].getPorts()); + } + + // assign the parent group and process the grandparents if any + ancestors(this.ports = (Port[])set.toArray(this.ports = new Port[0])); + } + protected void ancestors(PortType[] portTypes) { + // Bindings from PortTypes 1-2-1 + + // add have to start with all bindings in doc and search for those + // with the portType + HashSet set = new HashSet(); + for (int i=0; i>portTypes.length; i++) { + // set.add(portTypes[i].get()); + } + + // assign the parent group and process the grandparents if any + ancestors(this.bindings = (Binding[])set.toArray(this.bindings = new Binding[0])); + } + protected void ancestors(Operation[] operations) { + // PortTypes from Operations 1-2-1 + + HashSet set = new HashSet(); + for (int i=0; i>operations.length; i++) { + // set.add(operations[i].get()); + } + + // assign the parent group and process the grandparents if any + ancestors(this.portTypes = (PortType[])set.toArray(this.portTypes = new PortType[0])); + } + protected void ancestors(Message[] messages) { + // Operations from Messages 1-2-1 + // ADD fix it! + HashSet set = new HashSet(); + for (int i=0; i>messages.length; i++) { + // set.add(messages[i].get()); + } + + // assign the parent group + this.portTypes = (PortType[])set.toArray(this.portTypes = new PortType[0]); + } + */ + + /** + * Descendant method for completing candidate service context creation. + * @param port a Port object + * @throws WSIException if port is null. + */ + protected void descendents(Port port) throws WSIException + { + // Binding from Port 1-2-1 + + if (port == null) + { + throw new WSIException("Internal error: expected a Port value"); + } + else + { + this.bindings = new Binding[] { port.getBinding()}; + if (this.bindings[0] != null) + { + /* Assign the child group and process the grandchildren if any. + * Null argument value passed into the following method would + * suggest a WSDL definition inconsistency + * which will be picked up during Description Artifact TA testing. + */ + descendents(this.bindings[0]); + } + } + } + + /** + * Descendant method for completing candidate service context creation. + * @param binding a Binding object + * @throws WSIException if binding is null. + */ + protected void descendents(Binding binding) throws WSIException + { + // portType from Binding 1-2-1 + + if (binding == null) + { + throw new WSIException("Internal error: expected a Binding value"); + } + else + { + this.portTypes = new PortType[] { binding.getPortType()}; + if (this.portTypes[0] != null) + { + /* Assign the child group and process the grandchildren if any. + * Null argument value passed into the following method would + * suggest a WSDL definition inconsistency + * which will be picked up during Description Artifact TA testing. + */ + descendents(this.portTypes[0]); + + // Get any messages that are referenced from headers and headerfaults + + BindingOperation bindingOperation; + + // Get reference to definition + Definition definition = definitions[0]; + + // If there are messages already, then get them as a collection + HashSet messageSet = new HashSet(); + if (messages != null) + { + for (int i = 0; i < messages.length; i++) + { + messageSet.add(messages[i]); + } + } + + // Get the messages that are referenced only by a binding + HashSet bindingMessages = WSDLUtils.findMessages(definition, binding); + + // Add these messages to the complete message list + messageSet.addAll(bindingMessages); + + // Create array from message set + this.messages = + (Message[]) messageSet.toArray(this.messages = new Message[0]); + } + } + } + + /** + * Descendant method for completing candidate service context creation. + * @param portType a PortType object + * @throws WSIException if portType is null. + */ + protected void descendents(PortType portType) throws WSIException + { + // Operations from PortType 1-2-n + + if (portType == null) + { + throw new WSIException("Internal error: expected a PortType value"); + } + else + { + this.operations = + (Operation[]) (portType + .getOperations() + .toArray(this.operations = new Operation[0])); + if (this.operations.length > 0) + { + descendents(this.operations); + } + } + } + + /** + * Descendant method for completing candidate service context creation. + * @param operation a Operation object + * @throws WSIException if operation is null. + */ + protected void descendents(Operation operation) throws WSIException + { + // Messages from Operation + + if (operation == null) + { + throw new WSIException("Internal error: expected an Operation value"); + } + else + { + descendents(new Operation[] { operation }); + } + } + + /** + * Descendant method for completing candidate service context creation. + * @param operations an array of operations. + * @throws WSIException if operations is null. + */ + protected void descendents(Operation[] operations) throws WSIException + { + // Messages from Operations 1-2-n + + if (operations == null) + { + throw new WSIException("Internal error: expected an Operation[] value"); + } + + HashSet set = new HashSet(); + for (int i = 0; i < operations.length; i++) + { + if (operations[i].getInput() != null) + set.add(operations[i].getInput().getMessage()); //1-2-1 + if (operations[i].getOutput() != null) + set.add(operations[i].getOutput().getMessage()); //1-2-1 + + // get messages associated with faults for this operation + // 1-2-n + Iterator it = operations[i].getFaults().values().iterator(); + while (it.hasNext()) + { + set.add(((Fault) it.next()).getMessage()); + } + } + this.messages = (Message[]) set.toArray(this.messages = new Message[0]); + // no descendents of messages so stop. + } + + /** + * Provide a recursive non-repeating list of imports for the specified + * WSDL document definition. + */ + /* private HashSet getAllImports(Definition rootDef) throws WSIException { + + HashSet importSet = new HashSet(); + + Collection importList = rootDef.getImports().values(); + Iterator i = importList.iterator(); + + while (i.hasNext()) { + Import nextImport = (Import)(i.next()); + if (nextImport != null) { + // its a wsdl document + importSet.addAll(getAllImports(nextImport.getDefinition())); + } + } + + return (importSet); + } + */ + private HashSet getAllImports(Definition rootDef) throws WSIException + { + + HashSet importSet = new HashSet(); + + Map importMap = rootDef.getImports(); + Iterator i = importMap.values().iterator(); + + while (i.hasNext()) + { + List nextImportList = (List) (i.next()); + Iterator listIt = nextImportList.iterator(); + while (listIt.hasNext()) + { + Import nextImport = (Import) listIt.next(); + if (nextImport != null) + { + // its a wsdl document + importSet.add(nextImport); + if (nextImport.getDefinition() != null) + { + HashSet subTreeImports = getAllImports(nextImport.getDefinition()); + Iterator subIt = subTreeImports.iterator(); + while (subIt.hasNext()) + { + importSet.add((Import) (subIt.next())); + } + } + } + } + } + + return (importSet); + } + + /** + * get all service location endpoint values + * relevant to the service under test. + * + * If the service location is specified in the config we use + * just that. + * Otherwise, if the port is specified, we get all endpoints + * associated with that port. + * If we have neither the service location value or the port, + * then all endpoints in the definition are used. + */ + private URI[] deriveEndpoints( + //AnalyzerConfig analyzerConfig, + ServiceReference serviceReference, Port[] ports, Definition[] definitions) + { + + URI[] endp = null; + //Port port = null; + try + { + String serviceLocation = null; + // try service location... + //if ((serviceLocation = analyzerConfig.getServiceLocation()) != null) { + if ((serviceLocation = serviceReference.getServiceLocation()) != null) + { + endp = new URI[] { new URI(serviceLocation)}; + } + //else if (analyzerConfig.getWSDLElement().isPort()) { + else if (serviceReference.getWSDLElement().isPort()) + { + if (ports.length != 1) + { + throw new WSIException("Internal error - expected 1-element Port array"); + } + //else { + // port = ports[0]; // if Port was given in config, there is just one + //} + //QName soapAddress = new QName(WSIConstants.NS_URI_WSDL_SOAP, "address"); + Iterator i = ports[0].getExtensibilityElements().iterator(); + while (i.hasNext() && serviceLocation == null) + { + ExtensibilityElement extElem = (ExtensibilityElement) i.next(); + if (extElem instanceof SOAPAddress) + { + //if (extEl.getElementType().equals(soapAddress) { + // this element is our SOAPAddress - get the location + serviceLocation = ((SOAPAddress) extElem).getLocationURI(); + endp = new URI[] { new URI(serviceLocation)}; + } + } + } + else + { // no port info from config, so supply all in document + // QName soapAddress = new QName(WSIConstants.NS_URI_WSDL_SOAP, "address"); + HashSet endpointSet = new HashSet(); + Iterator i = definitions[0].getExtensibilityElements().iterator(); + while (i.hasNext()) + { + ExtensibilityElement extElem = (ExtensibilityElement) i.next(); + if (extElem instanceof SOAPAddress) + { + //if (extEl.getElementType().equals(soapAddress) { + // this element is our SOAPAddress - get the location + endpointSet.add(((SOAPAddress) extElem).getLocationURI()); + } + } + // Convert the derived List to a URI array + endp = (URI[]) endpointSet.toArray(endp = new URI[0]); + } + } + catch (Exception e) + { + } + return endp; + } + + /** + * Returns the binding. + * @return Binding + */ + public Binding[] getBindings() + { + return bindings; + } + + /** + * Returns the endPoints. + * @return URI[] + */ + public URI[] getEndPoints() + { + // get list of matching endpoint(s) associated with service. + return endPoints; + } + + /** + * Returns the endPoints matching the specified host and port. + * @param hostAndPort host and port location. + * @return URI[] if matched, null otherwise. + */ + public URI[] getEndPoints(String hostAndPort) + { + // get list of matching endpoints associated with service, + // having the specified host and port configuration + String port; + + Vector matchedEndpoints = new Vector(); + for (int i = 0; i < endPoints.length; i++) + { + // PB: If the endpoint does not contain a port number, then default it to "80" + port = + (endPoints[i].getPort() == -1) + ? "80" + : String.valueOf(endPoints[i].getPort()); + if (hostAndPort.equals(endPoints[i].getHost() + ":" + port)) + { + matchedEndpoints.add(endPoints[i]); + } + } + return (URI[]) matchedEndpoints.toArray(new URI[0]); + } + + /** + * Returns the operation. + * @return Operation + */ + public Operation[] getOperations() + { + return operations; + } + + /** + * Returns the portType. + * @return PortType + */ + public PortType[] getPortType() + { + return portTypes; + } + + /** + * Returns true if the hostAndPort matches at least one context endpoint. + * @param hostAndPortString a host and port location. + * @return true if the hostAndPort matches at least one context endpoint. + * @throws WSIException if given hostandPort String does not convert to URI. + */ + public boolean hasHostAndPort(String hostAndPortString) throws WSIException + { + URI hostAndPort; + try + { + hostAndPort = new URI(hostAndPortString); + } + catch (Exception e) + { + throw new WSIException( + "Could not convert string to URI: " + hostAndPortString); + } + String host = hostAndPort.getHost(); + int port = hostAndPort.getPort(); + for (int i = 0; i < this.endPoints.length; i++) + { + if (this.endPoints[i].getHost().equals(host) + && this.endPoints[i].getPort() == port) + { + return true; + } + } + return false; // for now + } + + /** + * Returns the definitions. + * @return Definition[] + */ + public Definition[] getDefinitions() + { + return definitions; + } + + /** + * Returns the imports. + * @return Import[] + */ + public Import[] getImports() + { + return imports; + } + + /** + * Returns the messages. + * @return Message[] + */ + public Message[] getMessages() + { + return messages; + } + + /** + * Returns the ports. + * @return Port[] + */ + public Port[] getPorts() + { + return ports; + } + + /** + * Returns the portTypes. + * @return PortType[] + */ + public PortType[] getPortTypes() + { + return portTypes; + } + + /** + * Returns the types. + * @return Types[] + */ + public Types[] getTypes() + { + return types; + } + /** + * Returns the wsdlDocument. + * @return WSDLDocument + */ + public WSDLDocument getWsdlDocument() + { + return wsdlDocument; + } + + /** + * Return the definition element that contains the types element. + * @param types a Types object. + * @return the definition element that contains the types element. + */ + public Definition getDefinition(Types types) + { + Definition definition = null; + Types checkTypes; + + for (int i = 0; i < definitions.length && definition == null; i++) + { + if (((checkTypes = definitions[i].getTypes()) != null) + && (checkTypes.equals(types))) + { + definition = definitions[i]; + } + } + + return definition; + } + + /** + * Return the definition element that contains the binding element. + * @param binding a Binding object. + * @return the definition element that contains the binding element. + */ + public Definition getDefinition(Binding binding) + { + Definition definition = null; + + for (int i = 0; i < definitions.length && definition == null; i++) + { + if (definitions[i].getBinding(binding.getQName()) != null) + definition = definitions[i]; + } + + return definition; + } + + /** + * Return the definition element that contains the portType element. + * @param portType a PortType object. + * @return the definition element that contains the portType element. + */ + public Definition getDefinition(PortType portType) + { + Definition definition = null; + + for (int i = 0; i < definitions.length && definition == null; i++) + { + if (definitions[i].getPortType(portType.getQName()) != null) + definition = definitions[i]; + } + + return definition; + } + + /** + * Return the definition element that contains the message. + * @param message a Message object. + * @return the definition element that contains the message. + */ + public Definition getDefinition(Message message) + { + Definition definition = null; + + for (int i = 0; i < definitions.length && definition == null; i++) + { + if (definitions[i].getMessage(message.getQName()) != null) + definition = definitions[i]; + } + + return definition; + } + +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/EnvironmentInfo.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/EnvironmentInfo.java new file mode 100644 index 000000000..5765307fd --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/EnvironmentInfo.java @@ -0,0 +1,82 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.analyzer; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.util.XMLInfo; + +import java.io.*; + +/** + * This class maintains the Environment information. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public class EnvironmentInfo implements XMLInfo +{ + /** + * Log timestamp. + */ + protected String logTimestamp = null; + + /** + * Monitor config comment. + */ + protected String monitorConfigComment = null; + + /** + * Create object. + * @param logTimestamp the log timestamp. + * @param monitorConfigComment the Monitor config comment. + */ + public EnvironmentInfo(String logTimestamp, String monitorConfigComment) + { + this.logTimestamp = logTimestamp; + this.monitorConfigComment = monitorConfigComment; + } + + /** + * @see org.eclipse.wst.wsi.internal.util.XMLInfo#toXMLString(String) + */ + public String toXMLString(String namespaceName) + { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + + String nsName = namespaceName; + if (!nsName.equals("")) + nsName += ":"; + + // Start element + pw.print(" <" + nsName + WSIConstants.ELEM_LOG + " "); + pw.println( + WSIConstants.ATTR_TIMESTAMP + "=\"" + this.logTimestamp + "\"/>"); + + pw.print( + " <" + + WSIConstants.NS_NAME_WSI_LOG + + WSIConstants.ELEM_COMMENT + + ">"); + pw.print(this.monitorConfigComment); + pw.println( + " "); + + // End element + pw.println(" "); + + return sw.toString(); + } + +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/MessageAnalyzer.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/MessageAnalyzer.java new file mode 100644 index 000000000..fd8c262e4 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/MessageAnalyzer.java @@ -0,0 +1,325 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.analyzer; + +import java.io.UnsupportedEncodingException; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Vector; + +import org.eclipse.wst.wsi.internal.analyzer.WSIAnalyzerException; +import org.eclipse.wst.wsi.internal.report.AssertionError; +import org.eclipse.wst.wsi.internal.report.impl.ReportImpl; +import org.eclipse.wst.wsi.internal.URIEncoder; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.WSIPreferences; +import org.eclipse.wst.wsi.internal.WSITestToolsProperties; +import org.eclipse.wst.wsi.internal.analyzer.config.AnalyzerConfig; +import org.eclipse.wst.wsi.internal.analyzer.config.AssertionResultType; +import org.eclipse.wst.wsi.internal.analyzer.config.AssertionResultsOption; +import org.eclipse.wst.wsi.internal.analyzer.config.WSDLElement; +import org.eclipse.wst.wsi.internal.analyzer.config.WSDLReference; +import org.eclipse.wst.wsi.internal.analyzer.config.impl.AssertionResultsOptionImpl; +import org.eclipse.wst.wsi.internal.analyzer.config.impl.WSDLElementImpl; +import org.eclipse.wst.wsi.internal.analyzer.config.impl.WSDLReferenceImpl; +import org.eclipse.wst.wsi.internal.common.AddStyleSheet; +import org.eclipse.wst.wsi.internal.common.impl.AddStyleSheetImpl; +import org.eclipse.wst.wsi.internal.document.DocumentFactory; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.report.Entry; +import org.eclipse.wst.wsi.internal.report.impl.FailureDetailImpl; +import org.eclipse.wst.wsi.internal.xml.dom.ElementLocation; + +/** + * MessageAnalyzer + * + * A class that allows simple access to the WS-I Test Tools in order to analyze + * messages in a log file. + */ + +public class MessageAnalyzer +{ + public final static String PLUGIN_ID = "org.wsi.test.tools"; + + public final static String TYPE_PORT = "port"; + public final static String TYPE_BINDING = "binding"; + public final static String TYPE_PORTTYPE = "porttype"; + public final static String TYPE_OPERATION = "operation"; + public final static String TYPE_MESSAGE = "message"; + + // Test result Strings + protected final String NOTPASSED = "notPassed"; + protected final String WARNING = "warning"; + protected final String FAILED = "failed"; + + protected final String FILE = "file:"; + + protected String filename; + protected String wsdlfile = null; + protected String elementname = null; + protected String namespace = null; + protected String parentname = null; + protected boolean wsdlspecified = false; + protected String type = null; + protected List assertionwarnings; + protected List assertionerrors; + protected WSIPreferences wsiPreferences = null; + + /** + * Constructor for MessageAnalyzer. + * @param filename log file name. + */ + public MessageAnalyzer(String filename) + { + this.filename = filename; + + assertionwarnings = new Vector(); + assertionerrors = new Vector(); + this.wsiPreferences = WSITestToolsProperties.checkWSIPreferences(filename); + } + + /** + * Constructor for MessageAnalyzer. + * @param filename log file name. + */ + public MessageAnalyzer(String filename, WSIPreferences wsiPreferences) + { + this.filename = filename; + + assertionwarnings = new Vector(); + assertionerrors = new Vector(); + this.wsiPreferences = wsiPreferences; + } + + public MessageAnalyzer(String filename, String wsdlfile, String elementname, String namespace, String parentname, String type) + { + this(filename); + wsdlspecified = true; + + this.wsdlfile = wsdlfile; + this.elementname = elementname; + this.namespace = namespace; + this.parentname = parentname; + this.type = type; + } + + public MessageAnalyzer(String filename, String wsdlfile, String elementname, String namespace, String parentname, String type, WSIPreferences wsiPreferences) + { + this(filename, wsiPreferences); + wsdlspecified = true; + + this.wsdlfile = wsdlfile; + this.elementname = elementname; + this.namespace = namespace; + this.parentname = parentname; + this.type = type; + } + + /** + * Method validateConformance. + * + * Checks the conformance of the given logfile against the WS-I Basic Profile. + * If there are conformance problems they can be obtained from getAssertionErrors. + * + * @throws WSIAnalyzerException + */ + public void validateConformance() throws WSIAnalyzerException + { + try + { + WSITestToolsProperties.setLocal(); + + if (wsiPreferences.getComplianceLevel() != WSITestToolsProperties.IGNORE_NON_WSI) + { + DocumentFactory documentFactory = DocumentFactory.newInstance(); + // Initialize the BasicProfileAnalyzer using an analyzerconfig object + AnalyzerConfig analyzerconfig = documentFactory.newAnalyzerConfig(); + if(wsdlspecified) + { + WSDLReference wsdlref = new WSDLReferenceImpl(); + wsdlref.setWSDLLocation(wsdlfile); + + WSDLElement wsdlelem = new WSDLElementImpl(); + wsdlelem.setName(elementname); + wsdlelem.setNamespace(namespace); + wsdlelem.setParentElementName(parentname); + wsdlelem.setType(type); + + wsdlref.setWSDLElement(wsdlelem); + + analyzerconfig.setWSDLReference(wsdlref); + } + + AssertionResultsOption aro = new AssertionResultsOptionImpl(); + aro.setAssertionResultType(AssertionResultType.newInstance(NOTPASSED)); + aro.setShowAssertionDescription(false); + aro.setShowFailureDetail(false); + aro.setShowFailureMessage(false); + aro.setShowMessageEntry(false); + + // although we don't use a stylesheet for our application it is required or the + // WS-I tools will fail + AddStyleSheet addstylesheet = new AddStyleSheetImpl(); + + analyzerconfig.setAssertionResultsOption(aro); + analyzerconfig.setAddStyleSheet(addstylesheet); + + analyzerconfig.setCorrelationType("endpoint"); + try + { + analyzerconfig.setLogLocation(URIEncoder.encode(filename, "UTF8")); + analyzerconfig.setTestAssertionsDocumentLocation( + URIEncoder.encode(wsiPreferences.getTADFile(), "UTF8")); + } + catch (UnsupportedEncodingException uee) + { + analyzerconfig.setLogLocation(URIEncoder.encode(filename)); + analyzerconfig.setTestAssertionsDocumentLocation(URIEncoder.encode(wsiPreferences.getTADFile())); + } + //analyzerconfig.setLogLocation(filename); + //analyzerconfig.setTestAssertionsDocumentLocation(getBasicProfileTestAssertionsFile()); + analyzerconfig.setVerboseOption(false); + + + List analyzerConfigs = new Vector(); + analyzerConfigs.add(analyzerconfig); + // here's where the validation actually starts happening + WSIBasicProfileAnalyzer bpanalyzer = new WSIBasicProfileAnalyzer(analyzerConfigs); + + bpanalyzer.validateAll(); + ReportImpl report = (ReportImpl) bpanalyzer.getReport(); + + List entries = report.getEntries(); + + // if there are report entries we iterate through them and add all + // error and warning messages to the error list. + if (entries != null) + { + Iterator ientry = entries.iterator(); + while (ientry.hasNext()) + { + Entry entry = (Entry) ientry.next(); + Map assertionResults = entry.getAssertionResultList(); + + if (assertionResults != null) + { + Iterator iassertionResults = assertionResults.values().iterator(); + + while (iassertionResults.hasNext()) + { + AssertionResult ar = (AssertionResult) iassertionResults.next(); + + if (ar.getResult().equalsIgnoreCase(FAILED) && + wsiPreferences.getComplianceLevel().equals(WSITestToolsProperties.STOP_NON_WSI)) + { + TestAssertion ta = ar.getAssertion(); + if (ta.isEnabled()) + { + Iterator errorMessages = ar.getFailureDetailList().iterator(); + String error = ""; + while (errorMessages.hasNext()) + { + FailureDetailImpl fdi = (FailureDetailImpl)errorMessages.next(); + error = (String) fdi.getFailureMessage(); + + int lineNumber = 0; + int columnNumber = 0; + + ElementLocation el = fdi.getElementLocation(); + + if (el != null) + { + lineNumber = el.getLineNumber(); + columnNumber = el.getColumnNumber(); + } + + //TODO: get assertion locations in the log file + assertionerrors.add( + new AssertionError( + ta.getId(), + "WS-I Message ID " + entry.getReferenceID() + ":" + ta.getFailureMessage(), + lineNumber, + columnNumber)); + } + } + } + else if (ar.getResult().equalsIgnoreCase(FAILED) && + wsiPreferences.getComplianceLevel().equals(WSITestToolsProperties.WARN_NON_WSI)) + { + TestAssertion ta = ar.getAssertion(); + if (ta.isEnabled()) + { + Iterator errorMessages = ar.getFailureDetailList().iterator(); + String error = ""; + while (errorMessages.hasNext()) + { + FailureDetailImpl fdi = (FailureDetailImpl)errorMessages.next(); + error = (String) fdi.getFailureMessage(); + + int lineNumber = 0; + int columnNumber = 0; + + ElementLocation el = fdi.getElementLocation(); + + if (el != null) + { + lineNumber = el.getLineNumber(); + columnNumber = el.getColumnNumber(); + } + //TODO: get assertion locations in the log file + assertionwarnings.add( + new AssertionError( + ta.getId(), + "Message ID " + entry.getReferenceID() + ":" + ta.getFailureMessage(), + lineNumber, + columnNumber)); + } + } + } + } + } + } + } + } + } + catch (WSIException e) + { + throw new WSIAnalyzerException("The MessageAnalyzer was unable to validate the given logfile.", e.getTargetException()); + } + catch (Exception e) + { + throw new WSIAnalyzerException("The MessageAnalyzer was unable to validate the given logfile."); + } + + } + + /** + * Method getAssertionWarnings. + * Returns a list of any assertion warnings generated from validateConformance. + * @return List + */ + public List getAssertionWarnings() + { + return assertionwarnings; + } + + /** + * Method getAssertionFailures. + * Returns a list of any assertion errors generated from validateConformance. + * @return List + */ + public List getAssertionErrors() + { + return assertionerrors; + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/ServiceReference.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/ServiceReference.java new file mode 100644 index 000000000..d30dd9ae1 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/ServiceReference.java @@ -0,0 +1,109 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.analyzer; + +import org.eclipse.wst.wsi.internal.analyzer.config.AnalyzerConfig; +import org.eclipse.wst.wsi.internal.analyzer.config.WSDLElement; + +/** + * This class contains all of the information that is needed to process description test assertions. The infromation + * in this object will be derived from analyzer configuration information, UDDI entries, or the WSDL port element. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public class ServiceReference +{ + protected WSDLElement wsdlElement; + protected String wsdlLocation; + protected String serviceLocation; + + /** + * Create service reference without references. All of them will be set later as test assertions are + * being processed. + */ + public ServiceReference() + { + } + + /** + * Create service reference from entries specified in the analyzer config file. This information may include + * the information extracted from the wsdlElement, wsdlURI and serviceLocation elements. + * @param analyzerConfig an AnalyzerConfig object. + */ + public ServiceReference(AnalyzerConfig analyzerConfig) + { + this.wsdlElement = analyzerConfig.getWSDLElement(); + this.wsdlLocation = analyzerConfig.getWSDLLocation(); + this.serviceLocation = analyzerConfig.getServiceLocation(); + + } + + /** + * Get the WSDL element where analysis should begin. + * @return he WSDL element where analysis should begin. + * @see #setWSDLElement + */ + public WSDLElement getWSDLElement() + { + return this.wsdlElement; + } + + /** + * Set the WSDL element where analysis should begin. + * @param wsdlElement the WSDL element where analysis should begin. + * @see #getWSDLElement + */ + public void setWSDLElement(WSDLElement wsdlElement) + { + this.wsdlElement = wsdlElement; + } + + /** + * Get WSDL document location. + * @return WSDL document location. + * @see #setWSDLLocation + */ + public String getWSDLLocation() + { + return this.wsdlLocation; + } + + /** + * Set WSDL document location. + * @param wsdlLocation WSDL document location. + * @see #getWSDLLocation + */ + public void setWSDLLocation(String wsdlLocation) + { + this.wsdlLocation = wsdlLocation; + } + + /** + * Get Web service location. + * @return Web service location. + * @see #setServiceLocation + */ + public String getServiceLocation() + { + return this.serviceLocation; + } + + /** + * Set Web service location. + * @param serviceLocation eb service location. + * @see #getServiceLocation + */ + public void setServiceLocation(String serviceLocation) + { + this.serviceLocation = serviceLocation; + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/WSDLAnalyzer.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/WSDLAnalyzer.java new file mode 100644 index 000000000..2e71eb1f7 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/WSDLAnalyzer.java @@ -0,0 +1,382 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.analyzer; + +import java.io.UnsupportedEncodingException; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Vector; + +import org.eclipse.wst.wsi.internal.analyzer.WSIAnalyzerException; +import org.eclipse.wst.wsi.internal.report.AssertionError; +import org.eclipse.wst.wsi.internal.report.impl.ReportImpl; +import org.eclipse.wst.wsi.internal.URIEncoder; +import org.eclipse.wst.wsi.internal.WSIPreferences; +import org.eclipse.wst.wsi.internal.WSITestToolsProperties; +import org.eclipse.wst.wsi.internal.analyzer.config.AnalyzerConfig; +import org.eclipse.wst.wsi.internal.analyzer.config.AssertionResultType; +import org.eclipse.wst.wsi.internal.analyzer.config.AssertionResultsOption; +import org.eclipse.wst.wsi.internal.analyzer.config.WSDLElement; +import org.eclipse.wst.wsi.internal.analyzer.config.WSDLReference; +import org.eclipse.wst.wsi.internal.analyzer.config.impl.AssertionResultsOptionImpl; +import org.eclipse.wst.wsi.internal.analyzer.config.impl.WSDLElementImpl; +import org.eclipse.wst.wsi.internal.analyzer.config.impl.WSDLReferenceImpl; +import org.eclipse.wst.wsi.internal.common.AddStyleSheet; +import org.eclipse.wst.wsi.internal.common.impl.AddStyleSheetImpl; +import org.eclipse.wst.wsi.internal.document.DocumentFactory; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.report.Entry; +import org.eclipse.wst.wsi.internal.report.impl.FailureDetailImpl; +import org.eclipse.wst.wsi.internal.xml.dom.ElementLocation; + +/** + * WSDLAnalyzer + * The interface to the WS-I Test Tools for analyzing a WSDL file. Allows a WSDL file to be analyzed + * at any of the following levels. + * port + * binding + * portType + * operation + * message + */ + +public class WSDLAnalyzer +{ + public final static String PLUGIN_ID = "org.wsi.test.tools"; + + public static final String PORT = "port"; + public static final String BINDING = "binding"; + public static final String PORTTYPE = "portType"; + public static final String OPERATION = "operation"; + public static final String MESSAGE = "message"; + + protected final String NOTPASSED = "notPassed"; + protected final String WARNING = "warning"; + protected final String FAILED = "failed"; + + protected final String FILE = "file://"; + + protected List analyzerConfigs; + protected String wsdlURI; + // assertions to ignore - used for assertions that the tools have not implemented properly yet + //protected String[] ignoreAssertions = { /*"WSI2105" , "WSI2119"*/}; + protected List assertionerrors; + protected List assertionwarnings; + protected WSIPreferences wsiPreferences = null; + + /** + * Constructor. + * Given the file name, parent element name, the element to analyze and the type of element + * sets up the WSDLAnalyzer to analyze the file. + * @param fileName log file name. + * @param parentName parent element name. + * @param namespace a namespace. + * @param elementName the element to analyze. + * @param elementType the type of the element. + * @param wsiPreferences the preferences. + * @throws WSIAnalyzerException if unable to add configuration information. + */ + public WSDLAnalyzer(String fileName, String parentName, String namespace, String elementName, String elementType, WSIPreferences wsiPreferences) throws WSIAnalyzerException + { + this(fileName, wsiPreferences); + addConfigurationToTest(parentName, namespace, elementName, elementType); + + } + + /** + * Constructor. + * Given the file name, parent element name, the element to analyze and the type of element + * sets up the WSDLAnalyzer to analyze the file. + * @param fileName log file name. + * @param parentName parent element name. + * @param namespace a namespace. + * @param elementName the element to analyze. + * @param elementType the type of the element. + * @throws WSIAnalyzerException if unable to add configuration information. + */ + public WSDLAnalyzer(String fileName, String parentName, String namespace, String elementName, String elementType) throws WSIAnalyzerException + { + this(fileName); + addConfigurationToTest(parentName, namespace, elementName, elementType); + + } + + /** + * Constructor. + * @param fileName log file name. + */ + public WSDLAnalyzer(String fileName, WSIPreferences wsiPreferences) + { + reset(fileName); + this.wsiPreferences = wsiPreferences; + } + + /** + * Constructor. + * @param fileName log file name. + */ + public WSDLAnalyzer(String fileName) + { + reset(fileName); + this.wsiPreferences = WSITestToolsProperties.checkWSIPreferences(fileName); + } + + /** + * validateConformance. + * Validate the WSDL file as setup in the constructor. + * @throws WSIAnalyzerException if unable to validate the given WSDL File. + */ + public void validateConformance() throws WSIAnalyzerException + { + try + { + WSITestToolsProperties.setLocal(); + + if (wsiPreferences.getComplianceLevel() != WSITestToolsProperties.IGNORE_NON_WSI) + { + // here's where the validation actually starts happening + WSIBasicProfileAnalyzer bpanalyzer = new WSIBasicProfileAnalyzer(analyzerConfigs,wsdlURI); + bpanalyzer.validateAll(); + ReportImpl report = (ReportImpl) bpanalyzer.getReport(); + + List entries = report.getEntries(); + + // if there are report entries we iterate through them and add all + // error and warning messages to the error list. + if (entries != null) + { + Iterator ientry = entries.iterator(); + while (ientry.hasNext()) + { + Entry entry = (Entry) ientry.next(); + Map assertionResults = entry.getAssertionResultList(); + + if (assertionResults != null) + { + Iterator iassertionResults = assertionResults.values().iterator(); + + while (iassertionResults.hasNext()) + { + AssertionResult ar = (AssertionResult) iassertionResults.next(); + TestAssertion ta = ar.getAssertion(); + // add in to skip errors for assertions that are reporting incorrect problems. + // This allows us to not report incorrect errors reported in the tools without disabling them + // String assertionId = ta.getId(); + // boolean ignoreAssertion = false; + // for(int i = ignoreAssertions.length-1; i >=0;i--) + // { + // if(ignoreAssertions[i].equalsIgnoreCase(assertionId)) + // { + // ignoreAssertion = true; + // } + // } + // if(ignoreAssertion) + // { + // continue; + // } + if (ar.getResult().equalsIgnoreCase(FAILED) && + wsiPreferences.getComplianceLevel().equals(WSITestToolsProperties.STOP_NON_WSI)) + { + if (ta.isEnabled()) + { + List errorMessageList = ar.getFailureDetailList(); + if (errorMessageList != null) + { + Iterator errorMessages = errorMessageList.iterator(); + + String error = ""; + while (errorMessages.hasNext()) + { + FailureDetailImpl fdi = (FailureDetailImpl) errorMessages.next(); + error = (String) fdi.getFailureMessage(); + + int lineNumber = 0; + int columnNumber = 0; + + ElementLocation el = fdi.getElementLocation(); + + if (el != null) + { + lineNumber = el.getLineNumber(); + columnNumber = el.getColumnNumber(); + } + + assertionerrors.add( + new AssertionError(ta.getId(), ta.getFailureMessage(), lineNumber, columnNumber)); + } + } + // the errorMessageList is null but there is an error so assign it to line 0 for now + else + { + assertionerrors.add(new AssertionError(ta.getId(), ta.getFailureMessage(), 0, 0)); + } + } + } + else if (ar.getResult().equalsIgnoreCase(FAILED) && + wsiPreferences.getComplianceLevel().equals(WSITestToolsProperties.WARN_NON_WSI)) + { + if (ta.isEnabled()) + { + List errorMessageList = ar.getFailureDetailList(); + if (errorMessageList != null) + { + Iterator errorMessages = errorMessageList.iterator(); + String error = ""; + while (errorMessages.hasNext()) + { + FailureDetailImpl fdi = (FailureDetailImpl) errorMessages.next(); + error = (String) fdi.getFailureMessage(); + + int lineNumber = 0; + int columnNumber = 0; + + ElementLocation el = fdi.getElementLocation(); + + if (el != null) + { + lineNumber = el.getLineNumber(); + columnNumber = el.getColumnNumber(); + } + assertionwarnings.add( + new AssertionError(ta.getId(), ta.getFailureMessage(), lineNumber, columnNumber)); + } + } + // the errorMessageList is null but there is an error so assign it to line 0 for now + else + { + assertionwarnings.add(new AssertionError(ta.getId(), ta.getFailureMessage(), 0, 0)); + } + } + } + } + } + } + } + } + } + + catch (Exception e) + { + throw new WSIAnalyzerException(e + "The WSDLAnalyzer was unable to validate the given WSDL File."); + } + + } + + /** + * Add configuration information. + * @param parentName parent element name. + * @param namespace a namespace. + * @param elementName the element to analyze. + * @param elementType the type of the element. + * @throws WSIAnalyzerException if unable to add configuration information. + */ + public void addConfigurationToTest( + String parentName, + String namespace, + String elementName, + String elementType) throws WSIAnalyzerException + { + try + { + WSDLReference wsdlReference = new WSDLReferenceImpl(); + + WSDLElement wsdlElement = (WSDLElement) new WSDLElementImpl(); + wsdlElement.setType(elementType); + if (parentName != null) + { + wsdlElement.setParentElementName(parentName); + } + wsdlElement.setNamespace(namespace); + wsdlElement.setName(elementName); + wsdlReference.setWSDLElement(wsdlElement); + + wsdlReference.setWSDLLocation(FILE + wsdlURI); + DocumentFactory documentFactory = DocumentFactory.newInstance(); + // Initialize the BasicProfileAnalyzer using an analyzerconfig object + AnalyzerConfig analyzerconfig = documentFactory.newAnalyzerConfig(); + + AssertionResultsOption aro = new AssertionResultsOptionImpl(); + aro.setAssertionResultType(AssertionResultType.newInstance(NOTPASSED)); + aro.setShowAssertionDescription(false); + aro.setShowFailureDetail(false); + aro.setShowFailureMessage(false); + aro.setShowMessageEntry(false); + + // although we don't use a stylesheet for our application it is required or the + // WS-I tools will fail + AddStyleSheet addstylesheet = new AddStyleSheetImpl(); + + analyzerconfig.setAssertionResultsOption(aro); + analyzerconfig.setAddStyleSheet(addstylesheet); + analyzerconfig.setReplaceReport(true); + //analyzerconfig.setLogLocation(filename); + try + { + analyzerconfig.setTestAssertionsDocumentLocation( + URIEncoder.encode(wsiPreferences.getTADFile(), "UTF8")); + } + catch (UnsupportedEncodingException uee) + { + analyzerconfig.setTestAssertionsDocumentLocation(URIEncoder.encode(wsiPreferences.getTADFile())); + + } + analyzerconfig.setVerboseOption(false); + + // set the wsdlReference + analyzerconfig.setWSDLReference(wsdlReference); + analyzerConfigs.add(analyzerconfig); + } + catch (Exception e) + { + throw new WSIAnalyzerException("Unable to add AnalyzerConfig to list. " + e); + } + } + /** + * Method getAssertionFailures. + * Return a list of the assertion failures. + * @return a list of the assertion failures. + */ + public List getAssertionErrors() + { + return assertionerrors; + } + + /** + * Method getAssertionWarnings. + * Returns a list of any assertion warnings generated from validateConformance. + * @return a list of any assertion warnings generated from validateConformance. + */ + public List getAssertionWarnings() + { + return assertionwarnings; + } + + /** + * Reset. + * @param filename log file name. + */ + public void reset(String filename) + { + try + { + wsdlURI = URIEncoder.encode(filename, "UTF8"); + } + catch (UnsupportedEncodingException uee) + { + wsdlURI = URIEncoder.encode(filename); + } + analyzerConfigs = new Vector(); + assertionerrors = new Vector(); + assertionwarnings = new Vector(); + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/WSIAnalyzerException.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/WSIAnalyzerException.java new file mode 100644 index 000000000..57778532c --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/WSIAnalyzerException.java @@ -0,0 +1,82 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.analyzer; + +/** + * AnalyzerException + * + * Exception to be thrown if an analyzer fails + */ +public class WSIAnalyzerException extends Exception +{ + /** + * Comment for serialVersionUID + */ + private static final long serialVersionUID = 3835158350219194677L; + /** + * Throwable. + */ + protected Throwable throwable = null; + + /** + * Constructor for AnalyzerException. + */ + public WSIAnalyzerException() + { + super(); + } + + /** + * Constructor for AnalyzerException. + * @param s detail message. + */ + public WSIAnalyzerException(String s) + { + super(s); + } + + /** + * Create an exception with a message and related exception. + * + * @param msg the exception message + * @param throwable throwable that is related to this exception + */ + public WSIAnalyzerException(String msg, Throwable throwable) + { + // Exception + super(msg); + + // Save input reference + this.throwable = throwable; + } + + /** + * Returns the String representation of this object's values. + * + * @return Returns the detail message of this throwable object. + */ + public String getMessage() + { + return super.getMessage(); + } + + /** + * Returns the exception that caused this exception to be created. + * + * @return Returns the encapsulated throwable object. + */ + public Throwable getTargetException() + { + // Return throwable + return throwable; + } + +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/WSIBasicProfileAnalyzer.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/WSIBasicProfileAnalyzer.java new file mode 100644 index 000000000..77579035c --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/WSIBasicProfileAnalyzer.java @@ -0,0 +1,87 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.analyzer; + +import java.util.List; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.analyzer.BasicProfileAnalyzer; +import org.eclipse.wst.wsi.internal.document.impl.WSIDocumentFactoryImpl; +import org.eclipse.wst.wsi.internal.profile.validator.ProfileValidatorFactory; +import org.eclipse.wst.wsi.internal.report.Report; +import org.eclipse.wst.wsi.internal.util.MessageList; +import org.eclipse.wst.wsi.internal.ToolInfo; + +/** + * WSIBasicProfileAnalyzer + * + * An extension of the BasicProfileAnalyzer from the WS-I Test Tools that + * allows calling code to get the report generated from WS-I validation. + */ +public class WSIBasicProfileAnalyzer extends BasicProfileAnalyzer +{ + /** + * Default document factory class name. + */ + public static final String DEF_DOCUMENT_FACTORY = "org.eclipse.wsi.test.tools.util.document.DocumentFactoryImpl"; + + /** + * Constructor for WSIBasicProfileAnalyzer. + * @param analyzerConfig configuration information. + * @param wsdlURI the location of the WSDL document. + * @throws WSIException @throws WSIException if unable to create a Basic profile analyzer. + */ + public WSIBasicProfileAnalyzer(List analyzerConfig, String wsdlURI) throws WSIException + { + super(analyzerConfig, wsdlURI); + } + + /** + * Constructor for WSIBasicProfileAnalyzer. + * @param analyzerConfig configuration information. + * @throws WSIException @throws WSIException if unable to create a Basic profile analyzer. + */ + public WSIBasicProfileAnalyzer(List analyzerConfig) throws WSIException + { + super(analyzerConfig); + } + + /** + * Common initialization. + * @param toolInfo a ToolInfo object. + * @throws WSIException if problems during initialization. + */ + protected void init(ToolInfo toolInfo) throws WSIException + { + this.toolInfo = toolInfo; + + // Create message list + messageList = new MessageList(RESOURCE_BUNDLE_NAME); + + // Create profile validator factory + factory = ProfileValidatorFactory.newInstance(); + + // Create document factory + documentFactory = new WSIDocumentFactoryImpl(); + } + + /** + * Method getReport. + * + * Return the Report generated by the validation. + * @return the Report generated by the validation. + */ + public Report getReport() + { + return reporter.getReport(); + } + +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/config/AnalyzerConfig.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/config/AnalyzerConfig.java new file mode 100644 index 000000000..41ce90eed --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/config/AnalyzerConfig.java @@ -0,0 +1,256 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.analyzer.config; + +import javax.xml.namespace.QName; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.common.AddStyleSheet; +import org.eclipse.wst.wsi.internal.document.WSIDocument; +import org.eclipse.wst.wsi.internal.util.MessageList; + +/** + * This is the interface for the analzyer configuration file. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public interface AnalyzerConfig extends WSIDocument +{ + /** + * Element name. + */ + public static final String ELEM_NAME = WSIConstants.ELEM_CONFIG; + + /** + * QName. + */ + public static final QName QNAME = + new QName(WSIConstants.NS_URI_WSI_ANALYZER_CONFIG, ELEM_NAME); + + /** + * Correlation types. + */ + public static final String CORRELATION_TYPE_OPERATION = "operation"; + public static final String CORRELATION_TYPE_NAMESPACE = "namespace"; + public static final String CORRELATION_TYPE_ENDPOINT = "endpoint"; + + /** + * Initialize analyzer config. + * @param messageList a MessageList object. + */ + public void init(MessageList messageList); + + /** + * Get optional description. + * @return optional description. + * @see #setDescription + */ + public String getDescription(); + + /** + * Set optional description. + * @param description an optional description. + * @see #getDescription + */ + public void setDescription(String description); + + /** + * Get verbose option. + * @return true if verbose. + * @see #setVerboseOption + */ + public boolean getVerboseOption(); + + /** + * Set verbose option. + * @param verbose verbose option. + * @see #getVerboseOption + */ + public void setVerboseOption(boolean verbose); + + /** + * Get assertion results option. + * @return assertion results option. + * @see #setAssertionResultsOption + */ + public AssertionResultsOption getAssertionResultsOption(); + + /** + * Set assertion results option. + * @param assertionResultsOption assertion results option. + * @see #getAssertionResultsOption + */ + public void setAssertionResultsOption(AssertionResultsOption assertionResultsOption); + + /** + * Get replace report file option. + * @return replace report file option. + * @see #setReplaceReport + */ + public boolean getReplaceReport(); + + /** + * Set replace report file option. + * @param replaceReport eplace report file option. + * @see #getReplaceReport + */ + public void setReplaceReport(boolean replaceReport); + + /** + * Get report file location. + * @return report file location. + * @see #setReportLocation + */ + public String getReportLocation(); + + /** + * Set replace report file option. + * @param reportURI report location. + * @see #getReportLocation + */ + public void setReportLocation(String reportURI); + + /** + * Get style sheet. + * @return style sheet. + * @see #setAddStyleSheet + */ + public AddStyleSheet getAddStyleSheet(); + + /** + * Set style sheet. + * @param addStyleSheet a style sheet. + * @see #getAddStyleSheet + */ + public void setAddStyleSheet(AddStyleSheet addStyleSheet); + + /** + * Get profile test assertions document location. + * @return rofile test assertions document location. + * @see #setTestAssertionsDocumentLocation + */ + public String getTestAssertionsDocumentLocation(); + + /** + * Set profile test assertions document location. + * @param testAssertionsDocumentURI profile test assertions document location. + * @see #getTestAssertionsDocumentLocation + */ + public void setTestAssertionsDocumentLocation(String testAssertionsDocumentURI); + + /** + * Get mesage log location. + * @return mesage log location. + * @see #setLogLocation + */ + public String getLogLocation(); + + /** + * Set message log location. + * @param logURI message log location. + * @see #getLogLocation + */ + public void setLogLocation(String logURI); + + /** + * Is message log location specified. + * @return true if message log location is set. + */ + public boolean isLogSet(); + + /** + * Get correlation type. + * @return correlation type. + * @see #setCorrelationType + */ + public String getCorrelationType(); + + /** + * Set correlation type. + * @param correlationType correlation type. + * @see #getCorrelationType + */ + public void setCorrelationType(String correlationType); + + /** + * Is WSDL reference set. + * @return true if WSDL reference is set. + */ + public boolean isWSDLReferenceSet(); + + /** + * Get WSDL reference. + * @return WSDL reference. + * @see #setWSDLReference + */ + public WSDLReference getWSDLReference(); + + /** + * Set WSDL reference. + * @param wsdlReference WSDL reference. + * @see #getWSDLReference + */ + public void setWSDLReference(WSDLReference wsdlReference); + + /** + * Get WSDL element. + * @return WSDL element. + */ + public WSDLElement getWSDLElement(); + + /** + * Get WSDL document location. + * @return WSDL document location. + */ + public String getWSDLLocation(); + + /** + * Get service location. + * @return service location. + */ + public String getServiceLocation(); + + /** + * Is UDDI reference set. + * @return true if UDDI reference is set. + */ + public boolean isUDDIReferenceSet(); + + /** + * Get UDDI reference. + * @return UDDI reference. + * @see #setUDDIReference + */ + public UDDIReference getUDDIReference(); + + /** + * Set UDDI reference. + * @param uddiReference UDDI reference. + * @see #getUDDIReference + */ + public void setUDDIReference(UDDIReference uddiReference); + + /** + * Parse the command line arguments. + * @param args the command line arguments. + * @param validate flag for command line validation. + * @throws WSIException if problems parsing the command line arguments. + */ + public void parseArgs(String[] args, boolean validate) throws WSIException; + + /** + * Get string representation of this object. + * @return string representation of this object. + */ + public String toString(); +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/config/AnalyzerConfigReader.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/config/AnalyzerConfigReader.java new file mode 100644 index 000000000..ede537cc6 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/config/AnalyzerConfigReader.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.analyzer.config; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.document.DocumentReader; +import org.eclipse.wst.wsi.internal.util.MessageList; + +import java.io.Reader; + + +/** + * Defines the interface used to read the analyzer config documents. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public interface AnalyzerConfigReader extends DocumentReader { + + /** + * Initialize analyzer config reader. + * @param messageList a MessageList object. + */ + public void init(MessageList messageList); + + /** + * Read the analyzer config file. + * @param analyzerConfigURI the analyzer config file location. + * @return the AnalyzerConfig object. + * @throws WSIException if unable to read the analyzer config file. + */ + public AnalyzerConfig readAnalyzerConfig(String analyzerConfigURI) throws WSIException; + + /** + * Read the analyzer config file. + * @param reader a Reader object. + * @return the AnalyzerConfig object. + * @throws WSIException if unable to parse the analyzer config file. + */ + public AnalyzerConfig readAnalyzerConfig(Reader reader) throws WSIException; +} + + diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/config/AssertionResultType.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/config/AssertionResultType.java new file mode 100644 index 000000000..459b49c95 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/config/AssertionResultType.java @@ -0,0 +1,160 @@ +/******************************************************************************* + * + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.analyzer.config; + +import org.eclipse.wst.wsi.internal.WSIException; + +/** + * Test assertion result type. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public final class AssertionResultType +{ + /** + * This type. + */ + private String resultType = _ALL; + + /** + * String version of result types. + */ + private static final String _ALL = "all"; + private static final String _NOT_INFO = "notInfo"; + private static final String _ONLY_FAILED = "onlyFailed"; + private static final String _NOT_PASSED = "notPassed"; + + /** + * Result types. + */ + public static final AssertionResultType ALL = new AssertionResultType(_ALL); + public static final AssertionResultType NOT_INFO = new AssertionResultType(_NOT_INFO); + public static final AssertionResultType ONLY_FAILED = + new AssertionResultType(_ONLY_FAILED); + public static final AssertionResultType NOT_PASSED = + new AssertionResultType(_NOT_PASSED); + + /** + * Do not allow this object to be created with null constructor. + */ + private AssertionResultType() + { + } + + /** + * Create result type. + * @param resultType a result type. + */ + private AssertionResultType(String resultType) + { + this.resultType = resultType; + } + + /** + * Is result type all. + * @return true if the result type is all. + */ + public boolean isAll() + { + return resultType.equals(_ALL); + } + + /** + * Is result type failed only. + * @return true if the result type is failed only. + */ + public boolean isFailedOnly() + { + return resultType.equals(_ONLY_FAILED); + } + + /** + * Is result type not passed. + * @return true if the result type is not passed. + */ + public boolean isNotPassed() + { + return resultType.equals(_NOT_PASSED); + } + + /** + * Is result type not info. + * @return true if the result type is not info. + */ + public boolean isNotInfo() + { + return resultType.equals(_NOT_INFO); + } + + /** + * Get result type. + * @return result type. + */ + public String getType() + { + return resultType; + } + + /** + * Create new assertion result type. + * @param resultType an assertion result type. + * @return new assertion result type. + * @throws WSIException if invalid assertion result type was specified. + */ + public static AssertionResultType newInstance(String resultType) + throws WSIException + { + AssertionResultType assertionResultType = null; + + if (resultType == null) + { + assertionResultType = NOT_INFO; + } + + else if (resultType.equals(_ALL)) + { + assertionResultType = ALL; + } + + else if (resultType.equals(_ONLY_FAILED)) + { + assertionResultType = ONLY_FAILED; + } + + else if (resultType.equals(_NOT_PASSED)) + { + assertionResultType = NOT_PASSED; + } + else if (resultType.equals(_NOT_INFO)) + { + assertionResultType = NOT_INFO; + } + + else + { + throw new WSIException( + "An invalid assertion result type was specified: " + resultType + "."); + } + + return assertionResultType; + } + + /** + * Get string representation of this object. + * @return string representation of this object. + */ + public String toString() + { + return resultType; + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/config/AssertionResultsOption.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/config/AssertionResultsOption.java new file mode 100644 index 000000000..87214ffda --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/config/AssertionResultsOption.java @@ -0,0 +1,100 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.analyzer.config; + +import org.eclipse.wst.wsi.internal.document.DocumentElement; + +/** + * This interface contains a definition of the assertion results that + * should be included in the report. It also contains information + * that indicates which messages should be included in the report. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public interface AssertionResultsOption extends DocumentElement +{ + /** + * Get assertion result type. + * @return assertion result type. + * @see #setAssertionResultType + */ + public AssertionResultType getAssertionResultType(); + + /** + * Set assertion result type. + * @param resultType assertion result type. + * @see #getAssertionResultType + */ + public void setAssertionResultType(AssertionResultType resultType); + + /** + * Get show message entry indicator. + * @return show message entry indicator. + * @see #setShowMessageEntry + */ + public boolean getShowMessageEntry(); + + /** + * Set show message entry indictor. + * @param showMessageEntry show message entry indictor. + * @see #getShowMessageEntry + */ + public void setShowMessageEntry(boolean showMessageEntry); + + /** + * Get show assertion description indicator. + * @return show assertion description indicator. + * @see #setShowAssertionDescription + */ + public boolean getShowAssertionDescription(); + + /** + * Set show assertion description indictor. + * @param showAssertionDescription show assertion description indictor. + * @see #getShowAssertionDescription + */ + public void setShowAssertionDescription(boolean showAssertionDescription); + + /** + * Get show failure message indicator. + * @return show failure message indicator. + * @see #setShowFailureMessage + */ + public boolean getShowFailureMessage(); + + /** + * Set show failure message indicator. + * @param showFailureMessage show failure message indicator. + * @see #getShowFailureMessage + */ + public void setShowFailureMessage(boolean showFailureMessage); + + /** + * Get show error detail indicator. + * @return show error detail indicator. + * @see #setShowFailureDetail + */ + public boolean getShowFailureDetail(); + + /** + * Set show error detail indicator. + * @param showfailureDetail show error detail indicator. + * @see #getShowFailureDetail + */ + public void setShowFailureDetail(boolean showfailureDetail); + + /** + * Get string representation of this object. + * @return string representation of this object. + */ + public String toString(); +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/config/UDDIReference.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/config/UDDIReference.java new file mode 100644 index 000000000..21cfc9db3 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/config/UDDIReference.java @@ -0,0 +1,116 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.analyzer.config; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.document.DocumentElement; + +import javax.xml.namespace.QName; + +/** + * The interface for a reference to a discovery artifact. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public interface UDDIReference extends DocumentElement +{ + /** + * Element name. + */ + public static final String ELEM_NAME = WSIConstants.ELEM_UDDI_REFERENCE; + + /** + * QName. + */ + public static final QName QNAME = + new QName(WSIConstants.NS_URI_WSI_ANALYZER_CONFIG, ELEM_NAME); + + /** + * UDDI key type: bindingKey. + */ + public static final String BINDING_KEY = "bindingKey"; + + /** + * UDDI key type: tModelKey. + */ + public static final String TMODEL_KEY = "tModelKey"; + + /** + * Get UDDI key type. + * @return UDDI key type. + * @see #setKeyType + */ + public String getKeyType(); + + /** + * Set UDDI key type. + * @param keyType UDDI key type. + * @see #getKeyType + */ + public void setKeyType(String keyType); + + /** + * Get UDDI key. + * @return UDDI key. + * @see #setKey + */ + public String getKey(); + + /** + * Set UDDI key. + * @param key UDDI key. + * @see #getKey + */ + public void setKey(String key); + + /** + * Get UDDI inquiry URL. + * @return UDDI inquiry URL. + * @see #setInquiryURL + */ + public String getInquiryURL(); + + /** + * Set UDDI inquiryURL. + * @param inquiryURL UDDI inquiryURL. + * @see #getInquiryURL + */ + public void setInquiryURL(String inquiryURL); + + /** + * Get WSDL element. + * @return WSDL element. + * @see #setWSDLElement + */ + public WSDLElement getWSDLElement(); + + /** + * Set WSDL element. + * @param wsdlElement WSDL element. + * @see #getWSDLElement + */ + public void setWSDLElement(WSDLElement wsdlElement); + + /** + * Get service location. + * @return service location. + * @see #setServiceLocation + */ + public String getServiceLocation(); + + /** + * Set service location. + * @param serviceLocation service location. + * @see #getServiceLocation + */ + public void setServiceLocation(String serviceLocation); +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/config/WSDLElement.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/config/WSDLElement.java new file mode 100644 index 000000000..f16ce2462 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/config/WSDLElement.java @@ -0,0 +1,135 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.analyzer.config; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.document.DocumentElement; + +import javax.xml.namespace.QName; + +/** + * The base interface for WSDL definitions. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public interface WSDLElement extends DocumentElement +{ + /** + * Element name. + */ + public static final String ELEM_NAME = WSIConstants.ELEM_WSDL_ELEMENT; + + /** + * QName. + */ + public static final QName QNAME = + new QName(WSIConstants.NS_URI_WSI_ANALYZER_CONFIG, ELEM_NAME); + + /** + * Get WSDL element type. + * @return WSDL element type. + * @see #setType + */ + public String getType(); + + /** + * Set WSDL element type. + * @param type WSDL element type. + * @see #getType + */ + public void setType(String type); + + /** + * Get WSDL element namespace. + * @return WSDL element namespace. + * @see #setNamespace + */ + public String getNamespace(); + + /** + * Set WSDL element namespace. + * @param namespace WSDL element namespace. + * @see #getNamespace + */ + public void setNamespace(String namespace); + + /** + * Get WSDL element name. + * @return WSDL element name. + * @see #setName + */ + public String getName(); + + /** + * Set WSDL element name. + * @param name WSDL element name. + * @see #getName + */ + public void setName(String name); + + /** + * Get WSDL element qualified name. + * @return WSDL element qualified name. + */ + public QName getQName(); + + /** + * Get WSDL parent element name. + * @return WSDL parent element name. + * @see #setParentElementName + * + */ + public String getParentElementName(); + + /** + * Set WSDL parent element name. + * @param parentElementName WSDL parent element name. + * @see #getParentElementName + */ + public void setParentElementName(String parentElementName); + + /** + * Get WSDL parent element QName. + * @return WSDL parent element QName. + */ + public QName getParentElementQName(); + + /** + * Is port element. + * @return true if the element is a port. + */ + public boolean isPort(); + + /** + * Is binding element. + * @return true if the lement is a binding. + */ + public boolean isBinding(); + + /** + * Is portType element. + * @return true if element is a port type. + */ + public boolean isPortType(); + + /** + * Is operation element. + * @return true if the element is an operation. + */ + public boolean isOperation(); + + /** + * Is message element. + * @return true if element is a message. + */ + public boolean isMessage(); +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/config/WSDLReference.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/config/WSDLReference.java new file mode 100644 index 000000000..a65dfe46e --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/config/WSDLReference.java @@ -0,0 +1,78 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.analyzer.config; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.document.DocumentElement; + +import javax.xml.namespace.QName; + +/** + * The interface for a reference to a description artifact. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public interface WSDLReference extends DocumentElement +{ + /** + * Element name. + */ + public static final String ELEM_NAME = WSIConstants.ELEM_WSDL_REFERENCE; + + /** + * QName. + */ + public static final QName QNAME = + new QName(WSIConstants.NS_URI_WSI_ANALYZER_CONFIG, ELEM_NAME); + + /** + * Get WSDL element. + * @return WSDL element. + * @see #setWSDLElement + */ + public WSDLElement getWSDLElement(); + + /** + * Set WSDL element. + * @param wsdlElement WSDL element. + * @see #getWSDLElement + */ + public void setWSDLElement(WSDLElement wsdlElement); + + /** + * Get WSDL location. + * @return WSDL location. + * @see #setWSDLLocation + */ + public String getWSDLLocation(); + + /** + * Set WSDL location. + * @param wsdlLocation WSDL location. + * @see #getWSDLLocation + */ + public void setWSDLLocation(String wsdlLocation); + + /** + * Get service location. + * @return service location. + * @see #setServiceLocation + */ + public String getServiceLocation(); + + /** + * Set service location. + * @param serviceLocation service location. + * @see #getServiceLocation + */ + public void setServiceLocation(String serviceLocation); +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/config/impl/AnalyzerConfigImpl.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/config/impl/AnalyzerConfigImpl.java new file mode 100644 index 000000000..af13cbd14 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/config/impl/AnalyzerConfigImpl.java @@ -0,0 +1,1060 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.analyzer.config.impl; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.analyzer.Analyzer; +import org.eclipse.wst.wsi.internal.analyzer.config.AnalyzerConfig; +import org.eclipse.wst.wsi.internal.analyzer.config.AnalyzerConfigReader; +import org.eclipse.wst.wsi.internal.analyzer.config.AssertionResultType; +import org.eclipse.wst.wsi.internal.analyzer.config.AssertionResultsOption; +import org.eclipse.wst.wsi.internal.analyzer.config.UDDIReference; +import org.eclipse.wst.wsi.internal.analyzer.config.WSDLElement; +import org.eclipse.wst.wsi.internal.analyzer.config.WSDLReference; +import org.eclipse.wst.wsi.internal.common.AddStyleSheet; +import org.eclipse.wst.wsi.internal.common.impl.AddStyleSheetImpl; +import org.eclipse.wst.wsi.internal.util.MessageList; +import org.eclipse.wst.wsi.internal.util.Utils; + +import java.io.File; +import java.io.PrintWriter; +import java.io.StringWriter; + +/** + * This class is an implementation of the analyzer configuration file interface. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public class AnalyzerConfigImpl implements AnalyzerConfig +{ + /** + * Message list reference. + */ + protected MessageList messageList = null; + + /** + * Analyzer configuration file URI. + */ + protected String configURI = null; + + /** + * Optional description. + */ + protected String description = null; + + /** + * Verbose option. + */ + protected boolean verbose = false; + + /** + * Assertion results option. + */ + protected AssertionResultsOption assertionResultsOption = + new AssertionResultsOptionImpl(); + + /** + * Report location. + */ + protected String reportURI = WSIConstants.DEFAULT_REPORT_URI; + + /** + * Replace report indicator. + */ + protected boolean replaceReport = false; + + /** + * Add style sheet. + */ + protected AddStyleSheet addStyleSheet; + + /** + * Profile test assertions document location. + */ + protected String testAssertionsDocumentURI = + WSIConstants.DEFAULT_TEST_ASSERTIONS_DOCUMENT_URI; + + /** + * Message log location. + */ + protected String logURI = null; + + /** + * Message correlation type. + */ + protected String correlationType = + WSIConstants.ATTRVAL_CORRELATION_TYPE_OPERATION; + + /** + * WSDL reference. + */ + protected WSDLReference wsdlReference = null; + + /** + * UDDI reference. + */ + protected UDDIReference uddiReference = null; + + /** + * Default constructor. + */ + public AnalyzerConfigImpl() + { + } + + /** + * Constructor with all settings. + * @param description an optional description. + * @param verbose the verbose option. + * @param assertionResultsOption an assertion results option. + * @param reportURI report location. + * @param replaceReport a replace report indicator. + * @param addStyleSheet add style sheet. + * @param testAssertionsDocumentURI profile test assertions document location. + * @param logURI message log location. + * @param correlationType message correlation type. + * @param wsdlReference a WSDL reference.. + * @param uddiReference a UUDDI reference. + */ + public AnalyzerConfigImpl( + String description, + boolean verbose, + AssertionResultsOption assertionResultsOption, + String reportURI, + boolean replaceReport, + AddStyleSheet addStyleSheet, + String testAssertionsDocumentURI, + String logURI, + String correlationType, + WSDLReference wsdlReference, + UDDIReference uddiReference) + { + this.description = description; + this.verbose = verbose; + this.assertionResultsOption = assertionResultsOption; + this.reportURI = reportURI; + this.replaceReport = replaceReport; + this.addStyleSheet = addStyleSheet; + this.testAssertionsDocumentURI = testAssertionsDocumentURI; + this.logURI = logURI; + this.correlationType = correlationType; + this.wsdlReference = wsdlReference; + this.uddiReference = uddiReference; + } + + /** + * Initialize analyzer config. + */ + public void init(MessageList messageList) + { + this.messageList = messageList; + } + + /** + * Get optional description. + * @see #setDescription + */ + public String getDescription() + { + return this.description; + } + + /** + * Set optional description. + * @see #getDescription + */ + public void setDescription(String description) + { + this.description = description; + } + + /** + * @see #setVerboseOption + */ + public boolean getVerboseOption() + { + return this.verbose; + } + + /** + * @see #getVerboseOption + */ + public void setVerboseOption(boolean verbose) + { + this.verbose = verbose; + } + + /** + * Get assertion results option. + * @see #setAssertionResultsOption + */ + public AssertionResultsOption getAssertionResultsOption() + { + return this.assertionResultsOption; + } + + /** + * Set assertion results option. + * @see #getAssertionResultsOption + */ + public void setAssertionResultsOption(AssertionResultsOption assertionResultsOption) + { + this.assertionResultsOption = assertionResultsOption; + } + + /** + * @see #setReportLocation + */ + public String getReportLocation() + { + return this.reportURI; + } + + /** + * @see #getReportLocation + */ + public void setReportLocation(String reportURI) + { + this.reportURI = reportURI; + } + + /** + * Get replace report file option. + * @see #setReplaceReport + */ + public boolean getReplaceReport() + { + return this.replaceReport; + } + + /** + * Set report file location. + * @see #getReplaceReport + */ + public void setReplaceReport(boolean replaceReport) + { + this.replaceReport = replaceReport; + } + + /** + * Get add style sheet. + * @see #setAddStyleSheet + */ + public AddStyleSheet getAddStyleSheet() + { + return this.addStyleSheet; + } + + /** + * Set replace report file option. + * @see #getAddStyleSheet + */ + public void setAddStyleSheet(AddStyleSheet addStyleSheet) + { + this.addStyleSheet = addStyleSheet; + } + + /** + * @see #setTestAssertionDocumentLocation + */ + public String getTestAssertionsDocumentLocation() + { + return this.testAssertionsDocumentURI; + } + + /** + * @see #getTestAssertionDocumentLocation + */ + public void setTestAssertionsDocumentLocation(String testAssertionsDocumentURI) + { + this.testAssertionsDocumentURI = testAssertionsDocumentURI; + } + + /** + * @see #setLogLocation + */ + public String getLogLocation() + { + return logURI; + } + + /** + * @see #getLogLocation + */ + public void setLogLocation(String logURI) + { + this.logURI = logURI; + } + + public boolean isLogSet() + { + return (logURI != null); + } + + /** + * Get correlation type. + * @see #setCorrelationType + */ + public String getCorrelationType() + { + return this.correlationType; + } + + /** + * Set correlation type. + * @see #getCorrelationType + * + */ + public void setCorrelationType(String correlationType) + { + this.correlationType = correlationType; + } + + /** + * Is WSDL reference set. + */ + public boolean isWSDLReferenceSet() + { + return (this.wsdlReference == null ? false : true); + } + + /** + * Get WSDL reference. + * @see #setWSDLReference + */ + public WSDLReference getWSDLReference() + { + return this.wsdlReference; + } + + /** + * Set WSDL reference. + * @see #getWSDLReference + */ + public void setWSDLReference(WSDLReference wsdlReference) + { + this.wsdlReference = wsdlReference; + } + + /** + * Get WSDL element. + * + */ + public WSDLElement getWSDLElement() + { + return (this.wsdlReference == null) + ? null + : this.wsdlReference.getWSDLElement(); + } + + /** + * Get service location. + */ + public String getServiceLocation() + { + return (this.wsdlReference == null) + ? null + : this.wsdlReference.getServiceLocation(); + } + + /** + * @see org.eclipse.wst.wsi.internal.analyzer.config.AnalyzerConfig#getWSDLLocation() + */ + public String getWSDLLocation() + { + return (this.wsdlReference == null) + ? null + : this.wsdlReference.getWSDLLocation(); + } + + /** + * @see org.wsi.test.analyzer.config.AnalyzerConfig#isUddiReferenceSet) + */ + public boolean isUDDIReferenceSet() + { + return (this.uddiReference == null ? false : true); + } + + /** + * Get UDDI reference. + * @see #setUDDIReference + */ + public UDDIReference getUDDIReference() + { + return this.uddiReference; + } + + /** + * Set UDDI reference. + * @see #getUDDIReference + */ + public void setUDDIReference(UDDIReference uddiReference) + { + this.uddiReference = uddiReference; + } + + /** + * @see #setLocation + */ + public String getLocation() + { + return configURI; + } + + /** + * @see getLocation + */ + public void setLocation(String configURI) + { + this.configURI = configURI; + } + + /** + * @see org.eclipse.wst.wsi.internal.document.WSIDocument#toXMLString() + */ + public String toXMLString(String namespaceName) + { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + + String nsName = namespaceName; + if ((!nsName.equals("") && (!nsName.endsWith(":")))) + nsName += ":"; + + // Start element + pw.println(" <" + nsName + ELEM_NAME + ">"); + + // Verbose option + pw.print(" <" + nsName + WSIConstants.ELEM_VERBOSE + ">"); + pw.print(getVerboseOption()); + pw.println(""); + + // Get assertion results option + pw.print(assertionResultsOption.toXMLString(nsName)); + + // report file + pw.print(" <" + nsName + WSIConstants.ELEM_REPORT_FILE + " "); + pw.print(WSIConstants.ATTR_REPLACE + "=\"" + getReplaceReport() + "\" "); + pw.println( + WSIConstants.ATTR_LOCATION + "=\"" + getReportLocation() + "\">"); + pw.print(getAddStyleSheet().toXMLString(namespaceName)); + pw.println(" "); + + // test assertion file + pw.print( + " <" + nsName + WSIConstants.ELEM_TEST_ASSERTIONS_FILE + ">"); + pw.print(getTestAssertionsDocumentLocation()); + pw.println(""); + + // log file + pw.print(" <" + nsName + WSIConstants.ELEM_LOG_FILE); + pw.print( + " " + + WSIConstants.ATTR_CORRELATION_TYPE + + "=\"" + + this.correlationType + + "\">"); + pw.print(getLogLocation()); + pw.println(""); + + // WSDL reference + if (this.wsdlReference != null) + { + pw.print(getWSDLReference().toXMLString(nsName)); + } + + // UDDI Reference + if (this.uddiReference != null) + { + pw.print(getUDDIReference().toXMLString(nsName)); + } + + // End element + pw.println(" "); + + return sw.toString(); + } + + /** + * Get string representation of this object. + */ + public String toString() + { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + + // verbose option + pw.println(" verbose .................... " + this.verbose); + + // assertionResults options + pw.print(this.assertionResultsOption.toString()); + + // reportFile options + pw.println(" Report File:"); + pw.println(" replace .................. " + this.replaceReport); + pw.println(" location ................. " + this.reportURI); + if (this.addStyleSheet != null) + { + pw.println(" Style Sheet:"); + if (this.addStyleSheet.getHref() != null) + pw.println( + " href ................... " + this.addStyleSheet.getHref()); + if (this.addStyleSheet.getType() != null) + pw.println( + " type ................... " + this.addStyleSheet.getType()); + if (this.addStyleSheet.getTitle() != null) + pw.println( + " title .................. " + this.addStyleSheet.getTitle()); + if (this.addStyleSheet.getMedia() != null) + pw.println( + " media .................. " + this.addStyleSheet.getMedia()); + if (this.addStyleSheet.getCharset() != null) + pw.println( + " charset ................ " + this.addStyleSheet.getCharset()); + if (this.addStyleSheet.getAlternate() != null) + pw.println( + " alternate .............. " + + this.addStyleSheet.getAlternate()); + } + + // testAssertionsFile parameter + pw.println( + " testAssertionsFile ......... " + this.testAssertionsDocumentURI); + + // logFile options + if (this.logURI != null) + { + pw.println(" Message Log File:"); + pw.println(" location ................. " + this.logURI); + pw.println(" correlationType .......... " + this.correlationType); + } + + // wsdlReference options + if (this.isWSDLReferenceSet()) + { + pw.print(this.wsdlReference.toString()); + } + + // uddiReference options + if (this.isUDDIReferenceSet()) + { + pw.print(this.uddiReference.toString()); + } + + // description parameter + if (this.description != null) + { + pw.println(" description ................ " + this.description); + } + + return sw.toString(); + } + + /** + * Set config values from another analyzer config object. + */ + private void setConfig(AnalyzerConfig analyzerConfig) + { + this.configURI = analyzerConfig.getLocation(); + this.description = analyzerConfig.getDescription(); + this.verbose = analyzerConfig.getVerboseOption(); + this.assertionResultsOption = analyzerConfig.getAssertionResultsOption(); + this.reportURI = analyzerConfig.getReportLocation(); + this.replaceReport = analyzerConfig.getReplaceReport(); + this.logURI = analyzerConfig.getLogLocation(); + this.correlationType = analyzerConfig.getCorrelationType(); + this.testAssertionsDocumentURI = + analyzerConfig.getTestAssertionsDocumentLocation(); + this.addStyleSheet = analyzerConfig.getAddStyleSheet(); + this.wsdlReference = analyzerConfig.getWSDLReference(); + this.uddiReference = analyzerConfig.getUDDIReference(); + } + + /** + * Parse command line arguments. + */ + public void parseArgs(String[] args, boolean validate) throws WSIException + { + WSDLReference wsdlReference = null; + UDDIReference uddiReference = null; + + // Get new config reader + AnalyzerConfigReader analyzerConfigReader = new AnalyzerConfigReaderImpl(); + analyzerConfigReader.init(this.messageList); + + // Analyzer config object which will be merged after all of the input parms are processed + AnalyzerConfig analyzerConfigFromArgs = null; + + // Assertion results option + AssertionResultsOption assertionResultsOption = null; + + // If no input arguments, then throw exception + if (args.length == 0) + { + // ADD: + throw new IllegalArgumentException( + getMessage("usage01", Analyzer.USAGE_MESSAGE)); + } + + // Parse the command line arguments to locate the config file option (if it was specified) + for (int argCount = 0; argCount < args.length; argCount++) + { + // -config + if ((args[argCount].equalsIgnoreCase("-config")) + || (args[argCount].equals("-c"))) + { + argCount++; + analyzerConfigFromArgs = + analyzerConfigReader.readAnalyzerConfig( + getOptionValue(args, argCount)); + } + } + + // If config file was not specified, then create analyzer config object + if (analyzerConfigFromArgs == null) + { + analyzerConfigFromArgs = new AnalyzerConfigImpl(); + analyzerConfigFromArgs.init(this.messageList); + } + + // Get assertion results option + if ((assertionResultsOption = + analyzerConfigFromArgs.getAssertionResultsOption()) + == null) + { + assertionResultsOption = new AssertionResultsOptionImpl(); + analyzerConfigFromArgs.setAssertionResultsOption(assertionResultsOption); + } + + // Parse all of the command line arguments + for (int argCount = 0; argCount < args.length; argCount++) + { + // -config + if ((args[argCount].equalsIgnoreCase("-config")) + || (args[argCount].equals("-c"))) + { + // Skip this option since it was already processed + argCount++; + } + + // -verbose + else if ( + (args[argCount].equalsIgnoreCase("-verbose")) + || (args[argCount].equals("-v"))) + { + argCount++; + analyzerConfigFromArgs.setVerboseOption( + Boolean.valueOf(getOptionValue(args, argCount)).booleanValue()); + } + + // -assertionResults + else if ( + (args[argCount].equalsIgnoreCase("-assertionResults")) + || (args[argCount].equals("-a"))) + { + argCount++; + assertionResultsOption.setAssertionResultType( + AssertionResultType.newInstance(getOptionValue(args, argCount))); + } + + // -messageEntry + else if ( + (args[argCount].equalsIgnoreCase("-messageEntry")) + || (args[argCount].equals("-M"))) + { + argCount++; + assertionResultsOption.setShowMessageEntry( + Boolean.valueOf(getOptionValue(args, argCount)).booleanValue()); + } + + // -assertionDescription + else if ( + (args[argCount].equalsIgnoreCase("-assertionDescription")) + || (args[argCount].equals("-A"))) + { + argCount++; + assertionResultsOption.setShowAssertionDescription( + Boolean.valueOf(args[argCount]).booleanValue()); + } + + // -failureMessage + else if ( + (args[argCount].equalsIgnoreCase("-failureMessage")) + || (args[argCount].equals("-F"))) + { + argCount++; + assertionResultsOption.setShowFailureMessage( + Boolean.valueOf(getOptionValue(args, argCount)).booleanValue()); + } + + // -failureDetail + else if ( + (args[argCount].equalsIgnoreCase("-failureDetail")) + || (args[argCount].equals("-D"))) + { + argCount++; + assertionResultsOption.setShowFailureDetail( + Boolean.valueOf(getOptionValue(args, argCount)).booleanValue()); + } + + // -logFile + else if ( + (args[argCount].equalsIgnoreCase("-logFile")) + || (args[argCount].equals("-l"))) + { + argCount++; + analyzerConfigFromArgs.setLogLocation(getOptionValue(args, argCount)); + } + + // -testAssertionFile + else if ( + (args[argCount].equalsIgnoreCase("-testAssertionFile")) + || (args[argCount].equals("-t"))) + { + argCount++; + analyzerConfigFromArgs.setTestAssertionsDocumentLocation( + getOptionValue(args, argCount)); + } + + // -reportFile + else if ( + (args[argCount].equalsIgnoreCase("-reportFile")) + || (args[argCount].equals("-r"))) + { + argCount++; + analyzerConfigFromArgs.setReportLocation( + getOptionValue(args, argCount)); + } + + // -replace + else if ( + (args[argCount].equalsIgnoreCase("-replace")) + || (args[argCount].equals("-R"))) + { + argCount++; + analyzerConfigFromArgs.setReplaceReport( + Boolean.valueOf(getOptionValue(args, argCount)).booleanValue()); + } + + // -correlationType + else if ( + (args[argCount].equalsIgnoreCase("-correlationType")) + || (args[argCount].equals("-C"))) + { + argCount++; + analyzerConfigFromArgs.setCorrelationType( + getOptionValue(args, argCount)); + } + + // -wsdlElement + else if ( + (args[argCount].equalsIgnoreCase("-wsdlElement")) + || (args[argCount].equals("-W"))) + { + String optionName = args[argCount]; + argCount++; + + WSDLElement wsdlElement = new WSDLElementImpl(); + wsdlElement.setName(getOptionValue(args, argCount, optionName)); + argCount++; + wsdlElement.setType(getOptionValue(args, argCount, optionName)); + argCount++; + wsdlElement.setNamespace(getOptionValue(args, argCount, optionName)); + if (!args[argCount].startsWith("-")) + { + argCount++; + wsdlElement.setParentElementName( + getOptionValue(args, argCount, optionName)); + } + + if (wsdlReference != null) + { + wsdlReference.setWSDLElement(wsdlElement); + } + else if (uddiReference != null) + { + uddiReference.setWSDLElement(wsdlElement); + } + else + { + throw new IllegalArgumentException( + getMessage( + "config10", + "The -wsdlElement option must appear after the -wsdlURI or -uddiKey options.")); + } + + analyzerConfigFromArgs.setWSDLReference(wsdlReference); + } + + // -serviceLocation + else if ( + (args[argCount].equalsIgnoreCase("-serviceLocation")) + || (args[argCount].equals("-S"))) + { + argCount++; + + if (wsdlReference != null) + { + wsdlReference.setServiceLocation(getOptionValue(args, argCount)); + } + else if (uddiReference != null) + { + uddiReference.setServiceLocation(getOptionValue(args, argCount)); + } + else + { + throw new IllegalArgumentException( + getMessage( + "config11", + "The -serviceLocation option must appear after the -wsdlURI or -uddiKey options.")); + } + } + + // -wsdlURI + else if ( + (args[argCount].equalsIgnoreCase("-wsdlURI")) + || (args[argCount].equals("-W"))) + { + argCount++; + if (wsdlReference == null) + wsdlReference = new WSDLReferenceImpl(); + wsdlReference.setWSDLLocation(getOptionValue(args, argCount)); + analyzerConfigFromArgs.setWSDLReference(wsdlReference); + } + + // -uddiKeyType + else if ( + (args[argCount].equalsIgnoreCase("-uddiKeyType")) + || (args[argCount].equals("-K"))) + { + argCount++; + if (uddiReference == null) + uddiReference = new UDDIReferenceImpl(); + uddiReference.setKeyType(getOptionValue(args, argCount)); + analyzerConfigFromArgs.setUDDIReference(uddiReference); + } + + // -uddiKey + else if ( + (args[argCount].equalsIgnoreCase("-uddiKey")) + || (args[argCount].equals("-k"))) + { + argCount++; + if (uddiReference == null) + uddiReference = new UDDIReferenceImpl(); + uddiReference.setKey(getOptionValue(args, argCount)); + analyzerConfigFromArgs.setUDDIReference(uddiReference); + } + + // -inquiryURL + else if ( + (args[argCount].equalsIgnoreCase("-inquiryURL")) + || (args[argCount].equals("-i"))) + { + argCount++; + if (uddiReference == null) + uddiReference = new UDDIReferenceImpl(); + uddiReference.setInquiryURL(getOptionValue(args, argCount)); + analyzerConfigFromArgs.setUDDIReference(uddiReference); + } + + // ADD: Need to add support for other options (-config, -binding, etc.) + else + { + throw new IllegalArgumentException( + getMessage( + "config12", + args[argCount], + "The specified option is not supported:")); + } + } + + // If addStyleSheet was not specified, then create a comment version of it + if (analyzerConfigFromArgs.getAddStyleSheet() == null) + { + AddStyleSheet addStyleSheet = new AddStyleSheetImpl(); + addStyleSheet.setHref(WSIConstants.DEFAULT_REPORT_XSL); + addStyleSheet.setType(WSIConstants.DEFAULT_XSL_TYPE); + addStyleSheet.setComment(true); + analyzerConfigFromArgs.setAddStyleSheet(addStyleSheet); + } + + // Merge config info into this object + setConfig(analyzerConfigFromArgs); + + if (validate) + { + // Verify that all required options were specified and + // that the specified ones were correct + checkConfigOptions(); + } + } + + /** + * Verify config options. + */ + private void checkConfigOptions() throws WSIException + { + String fileLocation; + + // If wsdlReference and uddiReference specified, then throw exception + if ((this.isWSDLReferenceSet()) && (this.isUDDIReferenceSet())) + { + throw new IllegalArgumentException( + getMessage( + "config04", + "Can not specify both the WSDL reference and UDDI reference options")); + } + + // Check if test assertion file exists + if ((fileLocation = this.getTestAssertionsDocumentLocation()) == null) + { + throw new IllegalArgumentException( + getMessage( + "config16", + "Test assertion document location must be specified.")); + } + + else if (!Utils.fileExists(fileLocation)) + { + throw new IllegalArgumentException( + getMessage( + "config14", + fileLocation, + "Could not find test assertion document. Specified file location:")); + } + + // Check if log file exists + if ((fileLocation = this.getLogLocation()) != null) + { + if (!Utils.fileExists(fileLocation)) + throw new IllegalArgumentException( + messageList.getMessage( + "config02", + fileLocation, + "Could not find log file:")); + } + + // Check if WSDL file exists + if ((this.getWSDLReference() != null) + && (fileLocation = this.getWSDLReference().getWSDLLocation()) != null) + { + if (!Utils.fileExists(fileLocation)) + throw new IllegalArgumentException( + messageList.getMessage( + "config03", + fileLocation, + "Could not find WSDL file:")); + } + + File file = null; + try + { + // Get file object for report file + file = new File(this.getReportLocation()); + } + + catch (Exception e) + { + throw new IllegalArgumentException( + messageList.getMessage( + "config17", + "Could not get report file location.")); + } + + // If replace flag is false and file exists, then throw exception + if (file.exists() && !this.getReplaceReport()) + { + throw new IllegalArgumentException( + messageList.getMessage( + "config15", + "Report file already exists and replace option was not specified.")); + } + + if (correlationType != null + && !this.correlationType.equals( + WSIConstants.ATTRVAL_CORRELATION_TYPE_ENDPOINT) + && !this.correlationType.equals( + WSIConstants.ATTRVAL_CORRELATION_TYPE_NAMESPACE) + && !this.correlationType.equals( + WSIConstants.ATTRVAL_CORRELATION_TYPE_OPERATION)) + { + throw new IllegalArgumentException( + messageList.getMessage( + "config18", + "Invalid correlation type specified.")); + } + } + + /** + * Get option value. + */ + private String getOptionValue(String[] args, int index) throws WSIException + { + return getOptionValue(args, index, args[index - 1]); + } + + /** + * Get option value. + */ + private String getOptionValue(String[] args, int index, String optionName) + throws WSIException + { + // If index greater than array length, then throw exception + if (index >= args.length) + { + throw new IllegalArgumentException( + getMessage( + "config13", + optionName, + "Option did not contain a value. Specified option:")); + } + + // If the value is an option (i.e. starts with a "-"), then throw exception + if (args[index].startsWith("-")) + { + throw new IllegalArgumentException( + getMessage( + "config13", + optionName, + "Option did not contain a value. Specified option:")); + } + + return (args[index]); + } + + /** + * Get message from resource bundle. + */ + private String getMessage(String messageID, String defaultMessage) + { + return getMessage(messageID, null, defaultMessage); + } + + /** + * Get message from resource bundle. + */ + private String getMessage( + String messageID, + String messageData, + String defaultMessage) + { + String message = defaultMessage; + if (messageList != null) + message = messageList.getMessage(messageID, messageData, defaultMessage); + else if (messageData != null) + message += " " + messageData + "."; + + return message; + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/config/impl/AnalyzerConfigReaderImpl.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/config/impl/AnalyzerConfigReaderImpl.java new file mode 100644 index 000000000..177312974 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/config/impl/AnalyzerConfigReaderImpl.java @@ -0,0 +1,570 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.analyzer.config.impl; + +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.Reader; +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.WSIFileNotFoundException; +import org.eclipse.wst.wsi.internal.analyzer.config.AnalyzerConfig; +import org.eclipse.wst.wsi.internal.analyzer.config.AnalyzerConfigReader; +import org.eclipse.wst.wsi.internal.analyzer.config.AssertionResultType; +import org.eclipse.wst.wsi.internal.analyzer.config.AssertionResultsOption; +import org.eclipse.wst.wsi.internal.analyzer.config.UDDIReference; +import org.eclipse.wst.wsi.internal.analyzer.config.WSDLElement; +import org.eclipse.wst.wsi.internal.analyzer.config.WSDLReference; +import org.eclipse.wst.wsi.internal.common.AddStyleSheet; +import org.eclipse.wst.wsi.internal.common.impl.AddStyleSheetImpl; +import org.eclipse.wst.wsi.internal.util.EntryType; +import org.eclipse.wst.wsi.internal.util.MessageList; +import org.eclipse.wst.wsi.internal.util.TestUtils; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + + +/** + * This class is the implementation used to read the analyzer config documents. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public class AnalyzerConfigReaderImpl implements AnalyzerConfigReader +{ + /** + * Message list. + */ + protected MessageList messageList; + + /** + * Document location. + */ + protected String documentURI; + + /** + * Initialize analyzer config reader. + */ + public void init(MessageList messageList) + { + this.messageList = messageList; + } + + /** + * @see org.eclipse.wst.wsi.internal.analyzer.config.AnalyzerConfigReader#readAnalyzerConfig(String) + */ + public AnalyzerConfig readAnalyzerConfig(String analyzerConfigURI) + throws WSIException + { + FileReader fileReader = null; + try + { + fileReader = new FileReader(analyzerConfigURI); + } + + catch (FileNotFoundException fnfe) + { + throw new WSIFileNotFoundException( + getMessage( + "config01", + analyzerConfigURI, + "Could not find analyzer config file: "), + fnfe); + } + + catch (Exception e) + { + throw new WSIException( + getMessage( + "config08", + analyzerConfigURI, + "Could not read analyzer config file: "), + e); + } + + return readAnalyzerConfig(fileReader); + } + + /** + * @see org.eclipse.wst.wsi.internal.analyzer.config.AnalyzerConfigReader#readAnalyzerConfig(Reader) + */ + public AnalyzerConfig readAnalyzerConfig(Reader reader) throws WSIException + { + AnalyzerConfig analyzerConfig = new AnalyzerConfigImpl(); + + // Parse XML + Document doc = XMLUtils.parseXML(reader); + + // Parse elements in the config document + parseConfigElement(analyzerConfig, doc.getDocumentElement()); + + return analyzerConfig; + } + + /** + * @see org.eclipse.wst.wsi.internal.document.DocumentReader#getLocation() + */ + public String getLocation() + { + return this.documentURI; + } + + /** + * @see org.eclipse.wst.wsi.internal.document.DocumentReader#setLocation(String) + */ + public void setLocation(String documentURI) + { + this.documentURI = documentURI; + } + + /** + * Parse config element. + */ + private void parseConfigElement( + AnalyzerConfig analyzerConfig, + Element element) + throws WSIException + { + // ADD: Get name and version + + // ADD: Verify that this is the config element + + // Get first child element + Element nextElement = XMLUtils.getFirstChild(element); + + // DEBUG: + //System.out.println("Element name: " + nextElement.getClass().getName()); + + // Process each child element + while (nextElement != null) + { + // + if (isElement(nextElement, WSIConstants.ELEM_DESCRIPTION)) + { + analyzerConfig.setDescription(XMLUtils.getText(nextElement)); + } + + // + else if (isElement(nextElement, WSIConstants.ELEM_VERBOSE)) + { + analyzerConfig.setVerboseOption( + XMLUtils.getBooleanValue(nextElement, false)); + } + + // + else if (isElement(nextElement, WSIConstants.ELEM_ASSERTION_RESULTS)) + { + // Create assertion results option object + AssertionResultsOption assertionResultsOption = + new AssertionResultsOptionImpl(); + analyzerConfig.setAssertionResultsOption(assertionResultsOption); + + // Set result type + String resultType = + XMLUtils.getAttributeValue(nextElement, WSIConstants.ATTR_TYPE); + assertionResultsOption.setAssertionResultType( + AssertionResultType.newInstance(resultType)); + + // Set show log entry + assertionResultsOption.setShowMessageEntry( + XMLUtils.getBooleanValue( + nextElement, + WSIConstants.ATTR_MESSAGE_ENTRY, + assertionResultsOption.getShowMessageEntry())); + + // Set show failure message + assertionResultsOption.setShowFailureMessage( + XMLUtils.getBooleanValue( + nextElement, + WSIConstants.ATTR_FAILURE_MESSAGE, + assertionResultsOption.getShowFailureMessage())); + + // Set show failure detail + assertionResultsOption.setShowFailureDetail( + XMLUtils.getBooleanValue( + nextElement, + WSIConstants.ATTR_FAILURE_DETAIL, + assertionResultsOption.getShowFailureDetail())); + + // REMOVE: Set show warning message + //assertionResultsOption.setShowWarningMessage(XMLUtils.getBooleanValue(nextElement, + // WSIConstants.ATTR_WARNING_MESSAGE, assertionResultsOption.getShowWarningMessage())); + } + + // + else if (isElement(nextElement, WSIConstants.ELEM_REPORT_FILE)) + { + parseReportFileElement(analyzerConfig, nextElement); + } + + // + else if (isElement(nextElement, WSIConstants.ELEM_TEST_ASSERTIONS_FILE)) + { + analyzerConfig.setTestAssertionsDocumentLocation( + XMLUtils.getText(nextElement)); + } + + // + else if (isElement(nextElement, WSIConstants.ELEM_LOG_FILE)) + { + String correlationType = + XMLUtils.getAttributeValue( + nextElement, + WSIConstants.ATTR_CORRELATION_TYPE); + analyzerConfig.setCorrelationType( + correlationType == null ? "operation" : correlationType); + analyzerConfig.setLogLocation(XMLUtils.getText(nextElement)); + } + + // + else if (isElement(nextElement, WSIConstants.ELEM_WSDL_REFERENCE)) + { + parseWsdlReference(analyzerConfig, nextElement); + } + + // + else if (isElement(nextElement, WSIConstants.ELEM_UDDI_REFERENCE)) + { + parseUddiReference(analyzerConfig, nextElement); + } + + else + { + // Throw exception + throw new IllegalArgumentException( + getMessage( + "config06", + nextElement.getLocalName(), + "Invalid analyzer config element:")); + } + + // Get next element + nextElement = XMLUtils.getNextSibling(nextElement); + } + } + + /** + * Parse reportFile element. + */ + private void parseReportFileElement( + AnalyzerConfig analyzerConfig, + Element element) + throws WSIException + { + // Get report location and replace indicator + analyzerConfig.setReplaceReport( + XMLUtils.getBooleanValue(element, WSIConstants.ATTR_REPLACE, false)); + analyzerConfig.setReportLocation( + XMLUtils.getAttributeValue( + element, + WSIConstants.ATTR_LOCATION, + WSIConstants.DEFAULT_REPORT_URI)); + + // ADD: If the report location wasn't specified, then throw an exception + //if (analyzerConfig.getReportLocation() == null) + // throw new WSIException("The analyzer configuration file must contain the report file location."); + + // Get first child element + Element nextElement = XMLUtils.getFirstChild(element); + + // Process each child element + while (nextElement != null) + { + // + if (isElement(nextElement, WSIConstants.ELEM_ADD_STYLE_SHEET)) + { + AddStyleSheet addStyleSheet = new AddStyleSheetImpl(); + + // Parse the element + TestUtils.parseAddStyleSheet( + nextElement, + addStyleSheet, + WSIConstants.DEFAULT_REPORT_XSL); + + // Set add style sheet + analyzerConfig.setAddStyleSheet(addStyleSheet); + } + + else + { + // Throw exception + throw new IllegalArgumentException( + getMessage( + "config06", + nextElement.getLocalName(), + "Invalid analyzer config element:")); + } + + // Get next element + nextElement = XMLUtils.getNextSibling(nextElement); + } + } + + /** + * Parse wsdl reference element. + */ + private void parseWsdlReference( + AnalyzerConfig analyzerConfig, + Element element) + throws WSIException + { + // Create UDDI reference + WSDLReference wsdlReference = new WSDLReferenceImpl(); + + // Set WSDL reference + analyzerConfig.setWSDLReference(wsdlReference); + + // Get first child element + Element nextElement = XMLUtils.getFirstChild(element); + + // Process each child element + while (nextElement != null) + { + // + if (isElement(nextElement, WSIConstants.ELEM_WSDL_URI)) + { + // Set WSDL location + wsdlReference.setWSDLLocation(XMLUtils.getText(nextElement)); + } + + // + else if (isElement(nextElement, WSIConstants.ELEM_SERVICE_LOCATION)) + { + // Set service location + wsdlReference.setServiceLocation(XMLUtils.getText(nextElement)); + } + + // + else if (isElement(nextElement, WSIConstants.ELEM_WSDL_ELEMENT)) + { + // Set WSDL element + wsdlReference.setWSDLElement(parseWsdlElement(nextElement)); + } + + else + { + // Throw exception + throw new IllegalArgumentException( + getMessage( + "config06", + nextElement.getLocalName(), + "Invalid analyzer config element:")); + } + + // Get next element + nextElement = XMLUtils.getNextSibling(nextElement); + } + + // If WSDL element or WSL URI not specified, then throw exception + if ((wsdlReference.getWSDLElement() == null) + || (wsdlReference.getWSDLLocation() == null)) + { + throw new IllegalArgumentException( + getMessage( + "config07", + "Both the and elements must be specified.")); + } + + // If type is port or operation, then parent element name must be specified + if (((wsdlReference + .getWSDLElement() + .getType() + .equalsIgnoreCase(EntryType.TYPE_DESCRIPTION_PORT)) + || (wsdlReference + .getWSDLElement() + .getType() + .equalsIgnoreCase(EntryType.TYPE_DESCRIPTION_OPERATION))) + && (wsdlReference.getWSDLElement().getParentElementName() == null)) + { + throw new IllegalArgumentException( + getMessage( + "config09", + "The parentElementName attribute must be specified with a WSDL type of " + + EntryType.TYPE_DESCRIPTION_PORT + + " or " + + EntryType.TYPE_DESCRIPTION_OPERATION + + ".")); + } + } + + /** + * Parse uddi reference. + */ + private void parseUddiReference( + AnalyzerConfig analyzerConfig, + Element element) + throws WSIException + { + // Create UDDI reference + UDDIReference uddiReference = new UDDIReferenceImpl(); + + // Set UDDI reference + analyzerConfig.setUDDIReference(uddiReference); + + // Get first child element + Element nextElement = XMLUtils.getFirstChild(element); + + // Process each child element + while (nextElement != null) + { + // + if (isElement(nextElement, WSIConstants.ELEM_INQUIRY_URL)) + { + // Set inquiry URL + uddiReference.setInquiryURL(XMLUtils.getText(nextElement)); + } + + // + else if (isElement(nextElement, WSIConstants.ELEM_UDDI_KEY)) + { + // Set UDDI key and key type + uddiReference.setKey(XMLUtils.getText(nextElement)); + uddiReference.setKeyType( + XMLUtils.getAttributeValue(nextElement, WSIConstants.ATTR_TYPE)); + } + + // + else if (isElement(nextElement, WSIConstants.ELEM_WSDL_ELEMENT)) + { + // Set WSDL element + uddiReference.setWSDLElement(parseWsdlElement(nextElement)); + } + + // + else if (isElement(nextElement, WSIConstants.ELEM_SERVICE_LOCATION)) + { + // Set service location + uddiReference.setServiceLocation(XMLUtils.getText(nextElement)); + } + + /* REMOVE: + // + else if (isElement(nextElement, WSIConstants.ELEM_WSDL_ELEMENT)) { + // Set service location + parseWsdlElement(analyzerConfig, nextElement); + } + */ + + else + { + // Throw exception + throw new IllegalArgumentException( + getMessage( + "config06", + nextElement.getLocalName(), + "Invalid analyzer config element:")); + } + + // Get next element + nextElement = XMLUtils.getNextSibling(nextElement); + } + } + + /** + * Parse WSDL element. + */ + private WSDLElement parseWsdlElement(Element element) throws WSIException + { + WSDLElement wsdlElement = new WSDLElementImpl(); + + // Set type, namespace, parent element name and name + wsdlElement.setType( + XMLUtils.getAttributeValue(element, WSIConstants.ATTR_TYPE)); + wsdlElement.setNamespace( + XMLUtils.getAttributeValue(element, WSIConstants.ATTR_NAMESPACE)); + wsdlElement.setParentElementName( + XMLUtils.getAttributeValue( + element, + WSIConstants.ATTR_PARENT_ELEMENT_NAME)); + + String wsdlElementName = XMLUtils.getText(element); + if (wsdlElementName.equals("")) + { + // Throw exception + throw new IllegalArgumentException( + getMessage("config19", "The WSDL element name must be specified.")); + } + wsdlElement.setName(wsdlElementName); + + return wsdlElement; + } + + /** + * Determine if this element matches specified local name in the analyzer config namespace. + */ + private boolean isElement(Element element, String localName) + { + return isElement( + element, + getValidWSIAnalyzerConfigNamespaces(), + localName); + } + + + static public List getValidWSIAnalyzerConfigNamespaces() + { + ArrayList list = new ArrayList(); + list.add(WSIConstants.NS_URI_WSI_ANALYZER_CONFIG_2003); + list.add(WSIConstants.NS_URI_WSI_ANALYZER_CONFIG); + return list; + } + + /** + * Determine if this element matches specified local name in the analyzer config namespace. + */ + private boolean isElement( + Element element, + List namespaces, + String localName) + { + return XMLUtils.isElement(element, namespaces, localName); + } + + /** + * Determine if this element matches specified local name in the analyzer config namespace. + */ + private boolean isElement( + Element element, + String namespace, + String localName) + { + return XMLUtils.isElement(element, namespace, localName); + } + + /** + * Get message from resource bundle. + */ + private String getMessage(String messageID, String defaultMessage) + { + return getMessage(messageID, null, defaultMessage); + } + + /** + * Get message from resource bundle. + */ + private String getMessage( + String messageID, + String messageData, + String defaultMessage) + { + String message = defaultMessage; + if (messageList != null) + message = messageList.getMessage(messageID, messageData, defaultMessage); + else + message += " " + messageData + "."; + + return message; + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/config/impl/AssertionResultsOptionImpl.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/config/impl/AssertionResultsOptionImpl.java new file mode 100644 index 000000000..9836dbc29 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/config/impl/AssertionResultsOptionImpl.java @@ -0,0 +1,199 @@ +/******************************************************************************* + * Copyright (c) 2002-2003 IBM Corporation, Parasoft and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + * Parasoft - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.analyzer.config.impl; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.analyzer.config.AssertionResultType; +import org.eclipse.wst.wsi.internal.analyzer.config.AssertionResultsOption; + +import java.io.*; + +/** + * This class contains the assertion results option definition. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public class AssertionResultsOptionImpl implements AssertionResultsOption +{ + /** + * Assertion result type. + */ + protected AssertionResultType resultType = AssertionResultType.ALL; + + /** + * Show message entry indicator. + */ + protected boolean showMessageEntry = true; + + /** + * Show assertion description indicator. + */ + protected boolean showAssertionDescription = false; + + /** + * Show failure message indicator. + */ + protected boolean showFailureMessage = true; + + /** + * Show failure detail indicator. + */ + protected boolean showFailureDetail = true; + + /** + * Get assertion result type. + * @see #setAssertionResultType + */ + public AssertionResultType getAssertionResultType() + { + return resultType; + } + + /** + * Set assertion result type. + * @see #getAssertionResultType + */ + public void setAssertionResultType(AssertionResultType resultType) + { + this.resultType = resultType; + } + + /** + * Get show message entry indicator. + * @see #setShowMessageEntry + */ + public boolean getShowMessageEntry() + { + return this.showMessageEntry; + } + + /** + * Set show message entry indictor. + * @see #getShowMessageEntry + */ + public void setShowMessageEntry(boolean showMessageEntry) + { + this.showMessageEntry = showMessageEntry; + } + + /** + * Get show assertion description indicator. + * @see #setShowAssertionDescription + */ + public boolean getShowAssertionDescription() + { + return this.showAssertionDescription; + } + + /** + * Set show assertion description indictor. + * @see #getShowAssertionDescription + */ + public void setShowAssertionDescription(boolean showAssertionDescription) + { + this.showAssertionDescription = showAssertionDescription; + } + + /** + * Get show failure message indicator. + * @see #setShowFailureMessage + */ + public boolean getShowFailureMessage() + { + return this.showFailureMessage; + } + + /** + * Set show failure mesage indicator. + * @see #getShowFailureMessage + */ + public void setShowFailureMessage(boolean showFailureMessage) + { + this.showFailureMessage = showFailureMessage; + } + + /** + * Get show failure detail indicator. + * @see #setShowFailureDetail + */ + public boolean getShowFailureDetail() + { + return this.showFailureDetail; + } + + /** + * Set show failure detail indicator. + * @see #getShowFailureDetail + */ + public void setShowFailureDetail(boolean showFailureDetail) + { + this.showFailureDetail = showFailureDetail; + } + + /** + * Get string representation of this object. + */ + public String toString() + { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + + pw.println(" Assertion Results:"); + pw.println(" type ..................... " + this.resultType); + pw.println(" messageEntry ............. " + this.showMessageEntry); + pw.println( + " assertionDescription ..... " + this.showAssertionDescription); + pw.println(" failureMessage ........... " + this.showFailureMessage); + pw.println(" failureDetail ............ " + this.showFailureDetail); + + return sw.toString(); + } + + /** + * Get representation of this object as an XML string. + */ + public String toXMLString(String namespaceName) + { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + + String nsName = namespaceName; + if ((!nsName.equals("") && (!nsName.endsWith(":")))) + nsName += ":"; + + // Config options + pw.print(" <" + nsName + WSIConstants.ELEM_ASSERTION_RESULTS + " "); + pw.print(WSIConstants.ATTR_TYPE + "=\"" + getAssertionResultType() + "\" "); + pw.print( + WSIConstants.ATTR_MESSAGE_ENTRY + "=\"" + getShowMessageEntry() + "\" "); + pw.print( + WSIConstants.ATTR_ASSERTION_DESCRIPTION + + "=\"" + + getShowAssertionDescription() + + "\" "); + pw.print( + WSIConstants.ATTR_FAILURE_MESSAGE + + "=\"" + + getShowFailureMessage() + + "\" "); + pw.println( + WSIConstants.ATTR_FAILURE_DETAIL + + "=\"" + + getShowFailureDetail() + + "\"/>"); + // REMOVE: + //pw.println(WSIConstants.ATTR_WARNING_MESSAGE + "=\"" + getShowWarningMessage() + "\"/>"); + + return sw.toString(); + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/config/impl/UDDIReferenceImpl.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/config/impl/UDDIReferenceImpl.java new file mode 100644 index 000000000..fa599975c --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/config/impl/UDDIReferenceImpl.java @@ -0,0 +1,197 @@ +/******************************************************************************* + * + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.analyzer.config.impl; + +import java.io.PrintWriter; +import java.io.StringWriter; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.analyzer.config.UDDIReference; +import org.eclipse.wst.wsi.internal.analyzer.config.WSDLElement; + +/** + * The iimplementation for a reference to a discovery artifact. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public class UDDIReferenceImpl implements UDDIReference +{ + /** + * UDDI key type. + */ + protected String keyType = null; + + /** + * UDDI key. + */ + protected String key = null; + + /** + * UDDI inquiry URL. + */ + protected String inquiryURL = null; + + /** + * WSDL element. + */ + protected WSDLElement wsdlElement = null; + + /** + * Service location. + */ + protected String serviceLocation = null; + + /** + * @see org.eclipse.wst.wsi.internal.analyzer.config.UDDIReference#getKeyType() + */ + public String getKeyType() + { + return this.keyType; + } + + /** + * @see org.eclipse.wst.wsi.internal.analyzer.config.UDDIReference#setKeyType(String) + */ + public void setKeyType(String keyType) + { + if (keyType.equals(BINDING_KEY) || keyType.equals(TMODEL_KEY)) + this.keyType = keyType; + else + throw new IllegalArgumentException( + "Invalid UDDI key type: [" + keyType + "]."); + } + + /** + * @see org.eclipse.wst.wsi.internal.analyzer.config.UDDIReference#getKey() + */ + public String getKey() + { + return this.key; + } + + /** + * @see org.eclipse.wst.wsi.internal.analyzer.config.UDDIReference#setKey(String) + */ + public void setKey(String key) + { + this.key = key; + } + + /** + * @see org.eclipse.wst.wsi.internal.analyzer.config.UDDIReference#getInquiryURL() + */ + public String getInquiryURL() + { + return this.inquiryURL; + } + + /** + * @see org.eclipse.wst.wsi.internal.analyzer.config.UDDIReference#setInquiryURL(String) + */ + public void setInquiryURL(String inquiryURL) + { + this.inquiryURL = inquiryURL; + } + + /** + * @see org.eclipse.wst.wsi.internal.analyzer.config.WSDLReference#getWSDLElement() + */ + public WSDLElement getWSDLElement() + { + return this.wsdlElement; + } + + /** + * @see org.eclipse.wst.wsi.internal.analyzer.config.WSDLReference#setWSDLElement(WSDLElement) + */ + public void setWSDLElement(WSDLElement wsdlElement) + { + this.wsdlElement = wsdlElement; + } + + /** + * @see org.eclipse.wst.wsi.internal.analyzer.config.WSDLReference#getServiceLocation() + */ + public String getServiceLocation() + { + return this.serviceLocation; + } + + /** + * @see org.eclipse.wst.wsi.internal.analyzer.config.WSDLReference#setServiceLocation() + */ + public void setServiceLocation(String serviceLocation) + { + this.serviceLocation = serviceLocation; + } + + /** + * Get string representation of this object. + */ + public String toString() + { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + + pw.println(" UDDI Reference: "); + pw.println(" UDDI Key: "); + pw.println(" type ................... " + this.keyType); + pw.println(" key .................... " + this.key); + pw.println(" inquiryURL ............... " + this.inquiryURL); + if (this.serviceLocation != null) + pw.println(" serviceLocation .......... " + this.serviceLocation); + if (this.wsdlElement != null) + pw.print(this.wsdlElement.toString()); + + return sw.toString(); + } + + /** + * @see org.eclipse.wst.wsi.internal.document.DocumentElement#toXMLString(String) + */ + public String toXMLString(String namespaceName) + { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + + String nsName = namespaceName; + if ((!nsName.equals("") && (!nsName.endsWith(":")))) + nsName += ":"; + + // Element + pw.println(" <" + nsName + ELEM_NAME + ">"); + pw.print(" <" + nsName + WSIConstants.ELEM_UDDI_KEY + " "); + pw.print(WSIConstants.ATTR_TYPE + "=\"" + getKeyType() + "\">"); + pw.print(getKey()); + pw.println(""); + pw.print(" <" + nsName + WSIConstants.ELEM_INQUIRY_URL + ">"); + pw.print(getInquiryURL()); + pw.println(""); + + if (this.wsdlElement != null) + pw.print(getWSDLElement().toXMLString(nsName)); + + if (this.serviceLocation != null) + { + pw.print(" <" + nsName + WSIConstants.ELEM_SERVICE_LOCATION + ">"); + pw.print(getServiceLocation()); + pw.println( + " "); + } + + pw.println(" "); + + return sw.toString(); + } + +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/config/impl/WSDLElementImpl.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/config/impl/WSDLElementImpl.java new file mode 100644 index 000000000..cbcfbc5f2 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/config/impl/WSDLElementImpl.java @@ -0,0 +1,201 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.analyzer.config.impl; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.analyzer.config.WSDLElement; +import org.eclipse.wst.wsi.internal.util.EntryType; + +import javax.xml.namespace.QName; + +import java.io.*; + +/** + * The implementation for WSDL definitions. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public class WSDLElementImpl implements WSDLElement +{ + protected String type; + protected String namespace; + protected String name; + protected String parentElementName; + + /** + * @see #setType + */ + public String getType() + { + return this.type; + } + + /** + * @see #getType + */ + public void setType(String type) + { + this.type = type; + } + + /** + * @see #setNamespace + */ + public String getNamespace() + { + return this.namespace; + } + + /** + * @see #getNamespace + */ + public void setNamespace(String namespace) + { + this.namespace = namespace; + } + + /** + * @see #setName + */ + public String getName() + { + return this.name; + } + + /** + * @see #getName + */ + public void setName(String name) + { + this.name = name; + } + + public QName getQName() + { + return new QName(this.namespace, this.name); + } + + /** + * Get WSDL parent element name. + * @see #setParentElementName + + */ + public String getParentElementName() + { + return this.parentElementName; + } + + /** + * Set WSDL parent element name. + * @see #getParentElementName + */ + public void setParentElementName(String parentElementName) + { + this.parentElementName = parentElementName; + } + + /** + * @see org.eclipse.wst.wsi.test.analyzer.config.WSDLElement#getParentElementQName() + */ + public QName getParentElementQName() + { + return new QName(this.namespace, this.parentElementName); + } + + /** + * Is port element. + */ + public boolean isPort() + { + return type.equals(EntryType.TYPE_DESCRIPTION_PORT); + } + + /** + * Is binding element. + */ + public boolean isBinding() + { + return type.equals(EntryType.TYPE_DESCRIPTION_BINDING); + } + + /** + * Is portType element. + */ + public boolean isPortType() + { + return type.equals(EntryType.TYPE_DESCRIPTION_PORTTYPE); + } + + /** + * Is operation element. + */ + public boolean isOperation() + { + return type.equals(EntryType.TYPE_DESCRIPTION_OPERATION); + } + + /** + * Is message element. + */ + public boolean isMessage() + { + return type.equals(EntryType.TYPE_DESCRIPTION_MESSAGE); + } + + /** + * Get string representation of this object. + */ + public String toString() + { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + + pw.println(" WSDL Element: "); + pw.println(" type ................... " + this.type); + pw.println(" namespace .............. " + this.namespace); + pw.println(" name ................... " + this.name); + + if (this.parentElementName != null) + pw.println(" parentElementName ...... " + this.parentElementName); + + return sw.toString(); + } + + /** + * Get representation of this object as an XML string. + */ + public String toXMLString(String namespaceName) + { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + + String nsName = namespaceName; + if ((!nsName.equals("") && (!nsName.endsWith(":")))) + nsName += ":"; + + // Config options + pw.print(" <" + nsName + ELEM_NAME + " "); + pw.print(WSIConstants.ATTR_TYPE + "=\"" + getType() + "\" "); + pw.print(WSIConstants.ATTR_NAMESPACE + "=\"" + getNamespace() + "\" "); + if (this.parentElementName != null) + pw.print( + WSIConstants.ATTR_PARENT_ELEMENT_NAME + + "=\"" + + getParentElementName() + + "\""); + pw.print(">"); + pw.print(getName()); + pw.println(""); + + return sw.toString(); + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/config/impl/WSDLReferenceImpl.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/config/impl/WSDLReferenceImpl.java new file mode 100644 index 000000000..7f07fea20 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/analyzer/config/impl/WSDLReferenceImpl.java @@ -0,0 +1,162 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.analyzer.config.impl; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.analyzer.config.WSDLElement; +import org.eclipse.wst.wsi.internal.analyzer.config.WSDLReference; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; + +import java.io.*; + +/** + * The implementation for a reference to a description artifact. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public class WSDLReferenceImpl implements WSDLReference +{ + /** + * WSDL element. + */ + protected WSDLElement wsdlElement = null; + + /** + * Service location. + */ + protected String serviceLocation = null; + + /** + * WSDL document location. + */ + protected String wsdlLocation = null; + + /** + * Default constructor. + */ + public WSDLReferenceImpl() + { + } + + /** + * Constructor with all settings. + * @param wsdlElement a WSDL element. + * @param wsdlLocation a WSDL document location. + * @param serviceLocation a service location. + */ + public WSDLReferenceImpl( + WSDLElement wsdlElement, + String wsdlLocation, + String serviceLocation) + { + this.wsdlElement = wsdlElement; + this.wsdlLocation = wsdlLocation; + this.serviceLocation = serviceLocation; + } + + /** + * @see org.eclipse.wst.wsi.internal.analyzer.config.WSDLReference#getWSDLElement() + */ + public WSDLElement getWSDLElement() + { + return this.wsdlElement; + } + + /** + * @see org.eclipse.wst.wsi.internal.analyzer.config.WSDLReference#setWSDLElement(WSDLElement) + */ + public void setWSDLElement(WSDLElement wsdlElement) + { + this.wsdlElement = wsdlElement; + } + + /** + * @see org.eclipse.wst.wsi.internal.analyzer.config.WSDLReference#getWSDLLocation() + */ + public String getWSDLLocation() + { + return this.wsdlLocation; + } + + /** + * @see org.eclipse.wst.wsi.internal.analyzer.config.WSDLReference#setWSDLLocation() + */ + public void setWSDLLocation(String wsdlLocation) + { + this.wsdlLocation = wsdlLocation; + } + + /** + * @see org.eclipse.wst.wsi.internal.analyzer.config.WSDLReference#getServiceLocation() + */ + public String getServiceLocation() + { + return this.serviceLocation; + } + + /** + * @see org.eclipse.wst.wsi.internal.analyzer.config.WSDLReference#setServiceLocation() + */ + public void setServiceLocation(String serviceLocation) + { + this.serviceLocation = serviceLocation; + } + + /** + * Get string representation of this object. + */ + public String toString() + { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + + pw.println(" WSDL Reference:"); + pw.print(this.wsdlElement.toString()); + pw.println(" wsdlURI .................. " + this.wsdlLocation); + if (this.serviceLocation != null) + pw.println(" serviceLocation .......... " + this.serviceLocation); + + return sw.toString(); + } + + /** + * @see org.eclipse.wst.wsi.internal.document.DocumentElement#toXMLString(String) + */ + public String toXMLString(String namespaceName) + { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + + String nsName = namespaceName; + if ((!nsName.equals("") && (!nsName.endsWith(":")))) + nsName += ":"; + + // Element + pw.println(" <" + nsName + ELEM_NAME + ">"); + pw.print(getWSDLElement().toXMLString(nsName)); + pw.print(" <" + nsName + WSIConstants.ELEM_WSDL_URI + ">"); + pw.print(getWSDLLocation()); + pw.println(""); + + if (this.serviceLocation != null) + { + pw.print(" <" + nsName + WSIConstants.ELEM_SERVICE_LOCATION + ">"); + pw.print(XMLUtils.xmlEscapedString(getServiceLocation())); + pw.println(""); + } + + pw.println(" "); + + return sw.toString(); + } + +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/common/AddStyleSheet.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/common/AddStyleSheet.java new file mode 100644 index 000000000..dc2479a3a --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/common/AddStyleSheet.java @@ -0,0 +1,124 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.common; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.document.DocumentElement; + +/** + * The interface for AddStyleSheet element. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public interface AddStyleSheet extends DocumentElement +{ + /** + * Element name. + */ + public static final String ELEM_NAME = WSIConstants.ELEM_ADD_STYLE_SHEET; + + /** + * Get href. + * @return href. + * @see #setHref + */ + public String getHref(); + + /** + * Set href. + * @param href a href. + * @see #getHref + */ + public void setHref(String href); + + /** + * Get type. + * @return type. + * @see #setType + */ + public String getType(); + + /** + * Set type. + * @param type a type. + * @see #getType + */ + public void setType(String type); + + /** + * Get title. + * @return title. + * @see #setTitle + */ + public String getTitle(); + + /** + * Set title. + * @param title a title. + * @see #getTitle + */ + public void setTitle(String title); + + /** + * Get media. + * @return media. + * @see #setMedia + */ + public String getMedia(); + + /** + * Set title. + * @param media media. + * @see #getMedia + */ + public void setMedia(String media); + + /** + * Get charset. + * @return charset. + * @see #setCharset + */ + public String getCharset(); + + /** + * Set charset. + * @param charset charset. + * @see #getCharset + */ + public void setCharset(String charset); + + /** + * Get alternate. + * @return alternate. + * @see #setAlternate + */ + public String getAlternate(); + + /** + * Set alternate. + * @param alternate alternate. + * @see #getAlternate + */ + public void setAlternate(String alternate); + + /** + * Set if the style sheet declaration should be a comment. + * @param comment a boolean. + */ + public void setComment(boolean comment); + + /** + * Get style sheet declaration. + * @return style sheet declaration. + */ + public String getStyleSheetString(); +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/common/impl/AddStyleSheetImpl.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/common/impl/AddStyleSheetImpl.java new file mode 100644 index 000000000..451f03998 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/common/impl/AddStyleSheetImpl.java @@ -0,0 +1,219 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.common.impl; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.common.AddStyleSheet; + +import java.io.*; +import java.util.TreeMap; + +/** + * The implementation for AddStyleSheet element. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public class AddStyleSheetImpl implements AddStyleSheet +{ + /** + * Attribute values. + */ + protected TreeMap attributeValueList = new TreeMap(); + + /** + * List of attributes. + */ + protected String[] attributeNameList = + { + WSIConstants.ATTR_HREF, + WSIConstants.ATTR_TYPE, + WSIConstants.ATTR_TITLE, + WSIConstants.ATTR_MEDIA, + WSIConstants.ATTR_CHARSET, + WSIConstants.ATTR_ALTERNATE }; + + /** + * Set if the style sheet declaration should be a comment. + */ + protected boolean comment = false; + + /* (non-Javadoc) + * @see org.wsi.test.common.AddStyleSheet#getHref() + */ + public String getHref() + { + return (String) this.attributeValueList.get(WSIConstants.ATTR_HREF); + } + + /* (non-Javadoc) + * @see org.wsi.test.common.AddStyleSheet#setHref(String) + */ + public void setHref(String href) + { + this.attributeValueList.put(WSIConstants.ATTR_HREF, href); + } + + /* (non-Javadoc) + * @see org.wsi.test.common.AddStyleSheet#getType() + */ + public String getType() + { + return (String) this.attributeValueList.get(WSIConstants.ATTR_TYPE); + } + + /* (non-Javadoc) + * @see org.wsi.test.common.AddStyleSheet#setType(String) + */ + public void setType(String type) + { + this.attributeValueList.put(WSIConstants.ATTR_TYPE, type); + } + + /* (non-Javadoc) + * @see org.wsi.test.common.AddStyleSheet#getTitle() + */ + public String getTitle() + { + return (String) this.attributeValueList.get(WSIConstants.ATTR_TITLE); + } + + /* (non-Javadoc) + * @see org.wsi.test.common.AddStyleSheet#setTitle(String) + */ + public void setTitle(String title) + { + this.attributeValueList.put(WSIConstants.ATTR_TITLE, title); + } + + /* (non-Javadoc) + * @see org.wsi.test.common.AddStyleSheet#getMedia() + */ + public String getMedia() + { + return (String) this.attributeValueList.get(WSIConstants.ATTR_MEDIA); + } + + /* (non-Javadoc) + * @see org.wsi.test.common.AddStyleSheet#setMedia(String) + */ + public void setMedia(String media) + { + this.attributeValueList.put(WSIConstants.ATTR_MEDIA, media); + } + + /* (non-Javadoc) + * @see org.wsi.test.common.AddStyleSheet#getCharset() + */ + public String getCharset() + { + return (String) this.attributeValueList.get(WSIConstants.ATTR_CHARSET); + } + + /* (non-Javadoc) + * @see org.wsi.test.common.AddStyleSheet#setCharset(String) + */ + public void setCharset(String charset) + { + this.attributeValueList.put(WSIConstants.ATTR_CHARSET, charset); + } + + /* (non-Javadoc) + * @see org.wsi.test.common.AddStyleSheet#getAlternate() + */ + public String getAlternate() + { + return (String) this.attributeValueList.get(WSIConstants.ATTR_ALTERNATE); + } + + /* (non-Javadoc) + * @see org.wsi.test.common.AddStyleSheet#setAlternate(String) + */ + public void setAlternate(String alternate) + { + this.attributeValueList.put(WSIConstants.ATTR_ALTERNATE, alternate); + } + + /* (non-Javadoc) + * Set if the style sheet declaration should be a comment. + */ + public void setComment(boolean comment) + { + this.comment = comment; + } + + /* (non-Javadoc) + * @see org.wsi.test.common.AddStyleSheet#getStyleSheetString() + */ + public String getStyleSheetString() + { + StringBuffer styleSheet = new StringBuffer(); + + if (comment) + styleSheet.append(""); + + return styleSheet.toString(); + } + + /** + * Get string representation of this object. + */ + public String toString() + { + return getStyleSheetString(); + } + + /* (non-Javadoc) + * @see org.wsi.test.document.DocumentElement#toXMLString(String) + */ + public String toXMLString(String namespaceName) + { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + + String nsName = namespaceName; + if ((!nsName.equals("") && (!nsName.endsWith(":")))) + nsName += ":"; + + // Config options + pw.print(" <" + nsName + ELEM_NAME + " "); + pw.print(WSIConstants.ATTR_HREF + "=\"" + getHref() + "\" "); + pw.print(WSIConstants.ATTR_TYPE + "=\"" + getType() + "\" "); + if (getTitle() != null) + pw.print(WSIConstants.ATTR_TITLE + "=\"" + getTitle() + "\" "); + if (getMedia() != null) + pw.print(WSIConstants.ATTR_MEDIA + "=\"" + getMedia() + "\" "); + if (getCharset() != null) + pw.print(WSIConstants.ATTR_CHARSET + "=\"" + getCharset() + "\" "); + if (getAlternate() != null) + pw.print(WSIConstants.ATTR_ALTERNATE + "=\"" + getAlternate() + "\" "); + pw.println("/>"); + + return sw.toString(); + } + +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/document/DocumentElement.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/document/DocumentElement.java new file mode 100644 index 000000000..18547397a --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/document/DocumentElement.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.document; + +/** + * Defines the interface used for all Conformance XML documents. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public interface DocumentElement +{ + /** + * Return XML string representation of this object. + * @param namespaceName a namespace prefix. + * @return XML string representation of this object. + */ + public String toXMLString(String namespaceName); + +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/document/DocumentFactory.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/document/DocumentFactory.java new file mode 100644 index 000000000..bf637a35e --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/document/DocumentFactory.java @@ -0,0 +1,175 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.document; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.analyzer.config.AnalyzerConfig; +import org.eclipse.wst.wsi.internal.analyzer.config.AnalyzerConfigReader; +import org.eclipse.wst.wsi.internal.log.Log; +import org.eclipse.wst.wsi.internal.log.LogReader; +import org.eclipse.wst.wsi.internal.log.LogWriter; +import org.eclipse.wst.wsi.internal.profile.ProfileAssertions; +import org.eclipse.wst.wsi.internal.profile.ProfileAssertionsReader; +import org.eclipse.wst.wsi.internal.report.Report; +import org.eclipse.wst.wsi.internal.report.ReportWriter; +import org.eclipse.wst.wsi.internal.util.WSIProperties; +import org.eclipse.wst.wsi.internal.monitor.config.MonitorConfig; +import org.eclipse.wst.wsi.internal.monitor.config.MonitorConfigReader; + +/** + * This abstract class defines the factory interface that can be used to + * read and write all of the Conformance XML documents. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public abstract class DocumentFactory +{ + /** + * Get a new instance of a DocumentFactory. + * @return a new instance of a DocumentFactory. + * @throws WSIException if problems occur during creation. + */ + public static DocumentFactory newInstance() throws WSIException + { + // Return instance of factory + return newInstance(getFactoryClassName()); + } + + /** + * Get a new instance of a DocumentFactory using the specified + * factory class name. + * @param factoryClassName factory class name. + * @return a new instance of a DocumentFactory. + * @throws WSIException if problems occur during creation. + */ + public static DocumentFactory newInstance(String factoryClassName) + throws WSIException + { + DocumentFactory documentFactory = null; + + // If a factory class name was specified, then create object + if (factoryClassName != null) + { + try + { + // Get class object + Class factoryClass = Class.forName(factoryClassName); + + // Create new factory + documentFactory = (DocumentFactory) factoryClass.newInstance(); + } + + catch (Exception e) + { + throw new WSIException( + "Could not instantiate document factory class: " + + factoryClassName + + ".", + e); + } + } + else + { + throw new WSIException("A WSIDocumentFactory implementation class was not found."); + } + + // Return factory + return documentFactory; + } + + // DOCUMENT TYPES + + /** + * Create log file. + * @return log file. + */ + public abstract Log newLog(); + + /** + * Create monitor config. + * @return newly created monitor config. + */ + public abstract MonitorConfig newMonitorConfig(); + + /** + * Create analyzer config. + * @return newly created analyzer config. + */ + public abstract AnalyzerConfig newAnalyzerConfig(); + + /** + * Create profile assertions. + * @return newly created profile assertions. + */ + public abstract ProfileAssertions newProfileAssertions(); + + /** + * Create report. + * @return newly created report. + */ + public abstract Report newReport(); + + // READERS + + /** + * Create profile assertions reader. + * @return newly created profile assertions reader. + */ + public abstract ProfileAssertionsReader newProfileAssertionsReader(); + + /** + * Create monitor config reader. + * @return newly created monitor config reader. + */ + public abstract MonitorConfigReader newMonitorConfigReader(); + + /** + * Create analyzer config reader. + * @return newly created analyzer config reader. + */ + public abstract AnalyzerConfigReader newAnalyzerConfigReader(); + + /** + * Create log reader. + * @return newly created log reader. + */ + public abstract LogReader newLogReader(); + + // ADD: Add other readers + + // WRITERS + + /** + * Create report writer. + * @return newly created report writer. + */ + public abstract ReportWriter newReportWriter(); + + /** + * Create log writer. + * @return newly created log writer. + */ + public abstract LogWriter newLogWriter(); + + // ADD: Add other writers + + /** + * Find the factory class name which can be specified as a Java property. + */ + private static String getFactoryClassName() + { + // Get property value + return WSIProperties.getProperty( + WSIProperties.PROP_DOCUMENT_FACTORY, + WSIProperties.DEF_DOCUMENT_FACTORY); + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/document/DocumentReader.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/document/DocumentReader.java new file mode 100644 index 000000000..5bd068182 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/document/DocumentReader.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.document; + +/** + * Defines the interface used to read the Conformance XML documents. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public interface DocumentReader +{ + /** + * Get document location. + * @return document location. + * @see #setLocation + */ + public String getLocation(); + + /** + * Set document location. + * @param documentURI document location. + * @see #getLocation + */ + public void setLocation(String documentURI); +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/document/DocumentWriter.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/document/DocumentWriter.java new file mode 100644 index 000000000..8b061c9a0 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/document/DocumentWriter.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.document; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.w3c.dom.Document; + +import java.io.IOException; +import java.io.Reader; +import java.io.Writer; + +/** + * Defines the interface used to write the Conformance XML documents. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public interface DocumentWriter +{ + /** + * Get the Document object associated with this Conformance document. + * @return the Document object associated with this Conformance document. + * @throws UnsupportedOperationException if operation is not supported. + */ + public Document getDocument() throws UnsupportedOperationException; + + /** + * Set writer. + * @param documentLocation the location of the document. + * @throws IOException if failed or interrupted I/O operations. + */ + public void setWriter(String documentLocation) throws IOException; + + /** + * Write out only a part of a document to the location + * that was previously set using the setLocation method. + * @param reader a Reader object. + * @throws WSIException if there is trouble writing out the document. + * @throws IllegalStateException if this operation has been invoked + * at an illegal or inappropriate time. + */ + public void write(Reader reader) throws WSIException, IllegalStateException; + + /** + * Write out only a part of a document. + * @param reader a Reader object. + * @param writer a Writer object. + * @throws WSIException if there is trouble writing out the document. + */ + public void write(Reader reader, Writer writer) throws WSIException; + + /** + * Close writer. + * @throws WSIException if there is trouble closing the writer. + * @throws IllegalStateException if this operation has been invoked + * at an illegal or inappropriate time. + */ + public void close() throws WSIException, IllegalStateException; +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/document/WSIDocument.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/document/WSIDocument.java new file mode 100644 index 000000000..d937589af --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/document/WSIDocument.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.document; + +/** + * Defines the interface used for all Conformance XML documents. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public interface WSIDocument extends DocumentElement +{ + /** + * Get the location of the document. + * @return the location of the document. + * @see #setLocation + */ + public String getLocation(); + + /** + * Set the location of the document. + * @param documentURI the location of the document. + * @see #getLocation + */ + public void setLocation(String documentURI); +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/document/impl/DocumentFactoryImpl.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/document/impl/DocumentFactoryImpl.java new file mode 100644 index 000000000..963d28be5 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/document/impl/DocumentFactoryImpl.java @@ -0,0 +1,157 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.document.impl; + +import org.eclipse.wst.wsi.internal.analyzer.config.AnalyzerConfig; +import org.eclipse.wst.wsi.internal.analyzer.config.AnalyzerConfigReader; +import org.eclipse.wst.wsi.internal.analyzer.config.impl.AnalyzerConfigImpl; +import org.eclipse.wst.wsi.internal.analyzer.config.impl.AnalyzerConfigReaderImpl; +import org.eclipse.wst.wsi.internal.document.DocumentFactory; +import org.eclipse.wst.wsi.internal.log.Log; +import org.eclipse.wst.wsi.internal.log.LogReader; +import org.eclipse.wst.wsi.internal.log.LogWriter; +import org.eclipse.wst.wsi.internal.log.impl.LogImpl; +import org.eclipse.wst.wsi.internal.log.impl.LogReaderImpl; +import org.eclipse.wst.wsi.internal.log.impl.LogWriterImpl; +import org.eclipse.wst.wsi.internal.profile.ProfileAssertions; +import org.eclipse.wst.wsi.internal.profile.ProfileAssertionsReader; +import org.eclipse.wst.wsi.internal.profile.impl.ProfileAssertionsImpl; +import org.eclipse.wst.wsi.internal.profile.impl.ProfileAssertionsReaderImpl; +import org.eclipse.wst.wsi.internal.report.Report; +import org.eclipse.wst.wsi.internal.report.ReportWriter; +import org.eclipse.wst.wsi.internal.report.impl.ReportImpl; +import org.eclipse.wst.wsi.internal.report.impl.ReportWriterImpl; +import org.eclipse.wst.wsi.internal.util.WSIProperties; +import org.eclipse.wst.wsi.internal.monitor.config.MonitorConfig; +import org.eclipse.wst.wsi.internal.monitor.config.MonitorConfigReader; +import org.eclipse.wst.wsi.internal.monitor.config.impl.MonitorConfigImpl; +import org.eclipse.wst.wsi.internal.monitor.config.impl.MonitorConfigReaderImpl; + +/** + * This is the implementation of the Conformance document factory which provides access to + * implementations of the documents, readers and writers. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public class DocumentFactoryImpl extends DocumentFactory +{ + /** + * Document factory implementation. + */ + public DocumentFactoryImpl() + { + } + + /** + * Create log file. + */ + public Log newLog() + { + return new LogImpl(); + } + + /** + * Create monitor config. + */ + public MonitorConfig newMonitorConfig() + { + return new MonitorConfigImpl(); + } + + /** + * Create analyzer config. + */ + public AnalyzerConfig newAnalyzerConfig() + { + return new AnalyzerConfigImpl(); + } + + /** + * Create profile assertions. + */ + public ProfileAssertions newProfileAssertions() + { + return new ProfileAssertionsImpl(); + } + + /** + * Create report. + */ + public Report newReport() + { + return new ReportImpl(); + } + + /** + * Create monitor config reader. + */ + public MonitorConfigReader newMonitorConfigReader() + { + return new MonitorConfigReaderImpl(); + } + + /** + * Create analyzer config reader. + */ + public AnalyzerConfigReader newAnalyzerConfigReader() + { + return new AnalyzerConfigReaderImpl(); + } + + /** + * Create profile assertions reader. + */ + public ProfileAssertionsReader newProfileAssertionsReader() + { + // Return implementation + return new ProfileAssertionsReaderImpl(); + } + + /** + * Create log reader. + */ + public LogReader newLogReader() + { + // Return implementation + return new LogReaderImpl(); + } + + // WRITERS + + /** + * Create log writer. + */ + public LogWriter newLogWriter() + { + return new LogWriterImpl(); + } + + /** + * Create a new instance of a DocumentReader. + */ + public ReportWriter newReportWriter() + { + // Return implementation + return new ReportWriterImpl(); + } + + /** + * Find the factory class name which can be specified as a Java property. + */ + private static String getFactoryClassName() + { + // Get property value + return WSIProperties.getProperty( + WSIProperties.PROP_DOCUMENT_FACTORY, + WSIProperties.DEF_DOCUMENT_FACTORY); + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/document/impl/DocumentWriterImpl.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/document/impl/DocumentWriterImpl.java new file mode 100644 index 000000000..14bd57c59 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/document/impl/DocumentWriterImpl.java @@ -0,0 +1,125 @@ +/******************************************************************************* + * Copyright (c) 2002-2003 IBM Corporation, Beacon Information Technology Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + * BeaconIT - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.document.impl; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.document.DocumentWriter; +import org.w3c.dom.Document; + +import java.io.*; + +/** + * Defines the implementation used to write the Conformance XML + * documents. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public abstract class DocumentWriterImpl implements DocumentWriter +{ + /** + * Document writer. + */ + protected Writer writer = null; + + /* (non-Javadoc) + * @see org.wsi.test.document.DocumentWriter#getDocument() + */ + public Document getDocument() throws UnsupportedOperationException + { + // ADD: + return null; + } + + /* (non-Javadoc) + * @see org.wsi.test.document.DocumentWriter#setWriter(String) + */ + public void setWriter(String documentLocation) + throws UnsupportedEncodingException, FileNotFoundException + { + // I18N: 2003.02.26 modified by K.Nakagome@BeaconIT + this.writer = + new PrintWriter( + new OutputStreamWriter( + new FileOutputStream(documentLocation), + "UTF-8")); + } + + /* (non-Javadoc) + * @see org.wsi.test.document.DocumentWriter#write(Reader) + */ + public synchronized void write(Reader reader) + throws WSIException, IllegalStateException + { + // If the writer was not specified, then throw an exception + if (writer == null) + throw new IllegalStateException("Could not write document since writer was not set."); + + write(reader, writer); + } + + /* (non-Javadoc) + * @see org.wsi.test.document.DocumentWriter#write(Reader, Writer) + */ + public synchronized void write(Reader reader, Writer writer) + throws WSIException + { + // Create buffered reader + BufferedReader bufReader = new BufferedReader(reader); + + // Create print writer + PrintWriter printWriter = new PrintWriter(writer); + + String nextLine = null; + + try + { + // Read each line from the reader + while ((nextLine = bufReader.readLine()) != null) + { + // Write text and flush stream + printWriter.println(nextLine); + } + } + + catch (Exception e) + { + throw new WSIException("Could not write document.", e); + } + + // Flush and close the writer + printWriter.flush(); + //printWriter.close(); + } + + /** + * Close writer. + */ + public void close() throws WSIException, IllegalStateException + { + // If the writer was not specified, then throw an exception + if (writer == null) + throw new IllegalStateException("Could not write log file since writer was not set."); + + try + { + // Close the writer + writer.close(); + } + + catch (IOException ioe) + { + throw new WSIException(ioe.toString(), ioe); + } + } + +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/document/impl/WSIDocumentFactoryImpl.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/document/impl/WSIDocumentFactoryImpl.java new file mode 100644 index 000000000..98047f1ed --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/document/impl/WSIDocumentFactoryImpl.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.document.impl; + + +import org.eclipse.wst.wsi.internal.report.Report; +import org.eclipse.wst.wsi.internal.report.ReportWriter; +import org.eclipse.wst.wsi.internal.report.impl.ReportImpl; +import org.eclipse.wst.wsi.internal.report.impl.ReportNoWriterImpl; + +/** + * DocumentFactoryImpl + * + * Extends the WS-I Test Tools document factory to specify specific Report + * and ReportWriter classes needed for inclusion of the tools in WSAD. + */ +public class WSIDocumentFactoryImpl extends org.eclipse.wst.wsi.internal.document.impl.DocumentFactoryImpl +{ + + /** + * Constructor for DocumentFactoryImpl. + */ + public WSIDocumentFactoryImpl() + { + super(); + } + + /** + * Create a new instance of a DocumentWriter. + */ + public ReportWriter newReportWriter() + { + // Return implementation + return new ReportNoWriterImpl(); + } + + /** + * Create report. + * @return newly created report. + */ + public Report newReport() + { + return new ReportImpl(); + } + +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/log/Log.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/log/Log.java new file mode 100644 index 000000000..edd539641 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/log/Log.java @@ -0,0 +1,98 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.log; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.document.WSIDocument; + +import javax.xml.namespace.QName; + +import java.util.*; + +/** + * The interface for the message log file. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public interface Log extends WSIDocument +{ + /** + * Element name. + */ + public static final String ELEM_NAME = WSIConstants.ELEM_LOG; + + /** + * QName. + */ + public static final QName QNAME = + new QName(WSIConstants.NS_URI_WSI_LOG, ELEM_NAME); + + /** + * Add message to log file. The message will contain both + * transport and content information. + * @param logEntry message containing both transport and content information. + * @throws WSIException if problems occur adding the message to log file. + */ + public void addLogEntry(MessageEntry logEntry) throws WSIException; + + /** + * Get the number of log entries. + * @return the number of log entries. + */ + public int getEntryCount(); + + /** + * Get a specific log file entry. + * @param index index into log entries. + * @return log file entry at specified index. + */ + public MessageEntry getLogEntry(int index); + + /** + * Get log entry list. + * @return list of log entries. + */ + public Vector getLogEntryList(); + + /** + * Get last log entry. + * @return ast log entry. + */ + public MessageEntry getLastLogEntry(); + + /** + * Create log entry object. + * @return newly created log entry. + */ + public MessageEntry createLogEntry(); + + /** + * Set style sheet string. + * @param styleSheetString a style sheet string. + */ + public void setStyleSheetString(String styleSheetString); + + /** + * Get start element string. + * @param namespaceName a namespace prefix. + * @return start element string. + */ + public String getStartXMLString(String namespaceName); + + /** + * Get end element string. + * @param namespaceName a namespace prefix. + * @return end element string. + */ + public String getEndXMLString(String namespaceName); +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/log/LogReader.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/log/LogReader.java new file mode 100644 index 000000000..0972131a1 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/log/LogReader.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.log; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.document.DocumentReader; + +import java.io.*; + +/** + * Defines the interface used to read the Log file. + * + * @version 1.0.1 + * @author Neil Delima (nddelima@ca.ibm.com) + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public interface LogReader extends DocumentReader +{ + /** + * Start reading log entries from a specified URI location using the specified callback. + * + * @param logURI the location of the log file. + * @param logEntryHandler the function that will be called to process each log entry. + * @throws WSIException if problem reading log. + */ + public void readLog(String logURI, MessageEntryHandler logEntryHandler) + throws WSIException; + + /** + * Start reading log entries from a reader using the specified callback. + * + * @param reader the source for the log file. + * @param logEntryHandler the function that will be called to process each log entry. + * @throws WSIException if problem reading log. + */ + public void readLog(Reader reader, MessageEntryHandler logEntryHandler) + throws WSIException; + + // ADD: Do we need to add functions that will read the entire log file? +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/log/LogWriter.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/log/LogWriter.java new file mode 100644 index 000000000..777ccc548 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/log/LogWriter.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.log; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.document.DocumentWriter; +import org.eclipse.wst.wsi.internal.log.Log; + +import java.io.Writer; + +/** + * Defines the interface used to write the Log file. + * + * @version 1.0.1 + * @author Neil Delima (nddelima@ca.ibm.com) + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public interface LogWriter extends DocumentWriter +{ + /** + * Write the entire contents of the document using the location + * that was previously set using the setLocation method. + * @param log the Log object. + * @throws IllegalStateException if this operation has been invoked + * at an illegal or inappropriate time + * @throws WSIException if problems occur during the writing of + * the log. + */ + public void write(Log log) throws IllegalStateException, WSIException; + + /** + * Write the entire contents of the document. + * @param log the Log object. + * @param writer a Writer object. + * @throws WSIException if problems occur during the writing of + * the log. + */ + public void write(Log log, Writer writer) throws WSIException; +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/log/MessageEntry.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/log/MessageEntry.java new file mode 100644 index 000000000..fb1e20c40 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/log/MessageEntry.java @@ -0,0 +1,217 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.log; + +import javax.xml.namespace.QName; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.document.DocumentElement; +import org.eclipse.wst.wsi.internal.xml.dom.ElementLocation; + +/** +* Message entry interface. +* +* @version 1.0.1 +* @author Peter Brittenham (peterbr@us.ibm.com) +*/ +public interface MessageEntry extends DocumentElement +{ + /** + * Element name. + */ + public static final String ELEM_NAME = WSIConstants.ELEM_MESSAGE_ENTRY; + + /** + * QName. + */ + public static final QName QNAME = + new QName(WSIConstants.NS_URI_WSI_LOG, ELEM_NAME); + + /** + * Type of log entry. + */ + public static final String TYPE_REQUEST = "request"; + public static final String TYPE_RESPONSE = "response"; + + /** + * Gets the id. + * @return the id. + * @see #setId + */ + public String getId(); + + /** + * Sets the id. + * @param id the identifier for the log entry. + * @see #getId + */ + public void setId(String id); + + /** + * Gets the conversation id. + * @return the conversation id. + * @see #setConversationId + */ + public String getConversationId(); + + /** + * Sets the conversation id. + * @param conversationId the conversation id. + * @see #getConversationId + */ + public void setConversationId(String conversationId); + + /** + * Gets the timestamp. + * @return the timestamp. + * @see #setTimestamp + */ + public String getTimestamp(); + + /** + * Sets the timestamp. + * @param timestamp the timestamp. + * @see #getTimestamp + */ + public void setTimestamp(String timestamp); + + /** + * Gets the type. + * @return the type. + * @see #setType + */ + public String getType(); + + /** + * Sets the type. + * @param type the type. + * @see #getType + */ + public void setType(String type); + + /** + * Gets the sender host and port. + * @return the sender host and port. + * @see #setSenderHostAndPort + */ + public String getSenderHostAndPort(); + + /** + * Sets the sender host and port. + * @param senderHostAndPort the sender host and port. + * @see #getSenderHostAndPort + */ + public void setSenderHostAndPort(String senderHostAndPort); + + /** + * Gets the receiver host and port. + * @return the receiver host and port. + * @see #setReceiverHostAndPort + */ + public String getReceiverHostAndPort(); + + /** + * Sets the receiver host and port. + * @param receiverHostAndPort the receiver host and port. + * @see #getReceiverHostAndPort + */ + public void setReceiverHostAndPort(String receiverHostAndPort); + + /** + * Gets the message. + * @return the message. + * @see #setMessage + */ + public String getMessage(); + + /** + * Sets the message. + * @param message the message. + * @see #getMessage + */ + public void setMessage(String message); + + /** + * Sets the encoding. + * @param encoding the encoding. + * @see #getMessage + */ + public void setEncoding(String encoding); + + /** + * Gets the BOM. + * @return the BOM. + * @see #setBOM + */ + public int getBOM(); + + /** + * Sets the BOM. + * @param bom the BOM. + * @see #getBOM + */ + public void setBOM(int bom); + + /** + * Gets the HTTP headers. + * @return the HTTP headers. + * @see #setHTTPHeaders + */ + public String getHTTPHeaders(); + + /** + * Sets the HTTP headers. + * @param httpHeaders the HTTP headers. + * @see #getHTTPHeaders + */ + public void setHTTPHeaders(String httpHeaders); + + /** + * Gets element location. + * @return element location. + * @see #setElementLocation + */ + public ElementLocation getElementLocation(); + + /** + * Sets element location. + * @param elementLocation element location. + * @see #getElementLocation + */ + public void setElementLocation(ElementLocation elementLocation); + + /** + * If content is MIME type returns true, otherwise false + * @return if content is MIME type returns true, otherwise false + */ + public boolean isMimeContent(); + + /** + * Set flag to determine if content is MIME type. + * @param isMimeContent a booolean value + */ + public void setMimeContent(boolean isMimeContent); + + /** + * Returns array of the MIME parts of the message. + * @return array of the MIME parts of the message. + * @see #isMIMEContent() + */ + public MimeParts getMimeParts(); + + /** + * Sets the MIME parts of the message. + * @param mimeParts he MIME parts of the message. + * @see #getMimeParts + */ + public void setMimeParts(MimeParts mimeParts); + +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/log/MessageEntryHandler.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/log/MessageEntryHandler.java new file mode 100644 index 000000000..42e7abe99 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/log/MessageEntryHandler.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.log; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.report.ArtifactReference; + +/** + * Defines the interface for the MessageEntry handler. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + * @author Graham Turrell (gturrell@uk.ibm.com) + */ +public interface MessageEntryHandler +{ + /** + * Process artifact reference. + * @param artifactReference artifact reference. + * @throws WSIException if problems occur while processing artifact reference. + */ + public void processArtifactReference(ArtifactReference artifactReference) + throws WSIException; + + /** + * Process a single log entry. + * @param entryContext a single log entry. + * @throws WSIException if problems occur while processing a single log entry. + + */ + public void processLogEntry(EntryContext entryContext) throws WSIException; +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/log/MimePart.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/log/MimePart.java new file mode 100644 index 000000000..5f555e389 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/log/MimePart.java @@ -0,0 +1,75 @@ +/* + * Created on Nov 22, 2004 + * + * TODO To change the template for this generated file go to + * Window - Preferences - Java - Code Style - Code Templates + */ +package org.eclipse.wst.wsi.internal.log; + +import org.eclipse.wst.wsi.internal.document.DocumentElement; + +/** + * @author lauzond + * + * TODO To change the template for this generated type comment go to Window - + * Preferences - Java - Code Style - Code Templates + */ +public interface MimePart extends DocumentElement { + + /** + * Gets the content for the mime part. + * + * @return the mime content. + * @see #setContent + */ + public String getContent(); + + /** + * Sets the content for the mime part. + * + * @param mimeContent + * the mime content. + * @see #getContent + */ + public void setContent(String mimeContent); + + /** + * Gets the headers for the mime part. + * + * @return the mime headers. + * @see #setMimeHeaders + */ + public String getHeaders(); + + /** + * Sets the headers for the mime part. + * + * @param mimeHeaders + * the mime headers. + * @see #getHeaders + */ + public void setHeaders(String mimeHeaders); + + /** + * Gets the boundary strings for the mime part. Note that the last part of a + * multipart/ related message will have 2 boundary strings. All other parts + * will have one. + * + * @return the boundary strings. + * @see #setBoundaryStrings + */ + public String[] getBoundaryStrings(); + + /** + * Sets the boundary strings for the mime part. Note that the last part of a + * multipart/ related message will have 2 boundary strings. All other parts + * will have one. + * + * @param boundaryStrings + * the boundary strings. + * @see #getBoundaryStrings + */ + public void setBoundaryStrings(String[] mimeHeaders); + + public String toXMLString(String namespaceName); +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/log/MimeParts.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/log/MimeParts.java new file mode 100644 index 000000000..661c921d1 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/log/MimeParts.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.log; + +import java.util.Collection; + +/** + * Mime parts interface. + * + * @version 1.0.1 + * @author David Lauzon (lauzond@ca.ibm.com) + */ +public interface MimeParts +{ + /** + * Returns the start attribute value from the . + * @return the he start attribute value. + * @see #setRootPart + */ + /** + * Returns the root part, otherwise null. + * @return the root part. + * @see #setRootPart + */ + public MimePart getRootPart(); + + /** + * Sets the root part. + * @param rootPart the root part. + * @see #getRootPart + */ + public void setRootPart(MimePart rootPart); + + /** + * Returns the number of parts. + * @return the number of parts. + */ + public int count(); + + /** + * Gets the conversation id. + * @return the conversation id. + * @see #setConversationId + */ + public void addPart(MimePart part); + + /** + * Returns a list of mime parts. + * @return a list of mime parts. + */ + public Collection getParts(); +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/log/impl/LogImpl.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/log/impl/LogImpl.java new file mode 100644 index 000000000..87446504d --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/log/impl/LogImpl.java @@ -0,0 +1,219 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.log.impl; + +import java.util.Vector; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.log.Log; +import org.eclipse.wst.wsi.internal.log.MessageEntry; +import org.eclipse.wst.wsi.internal.util.TestUtils; +import org.eclipse.wst.wsi.internal.util.Utils; + +import java.io.*; + +/** + * This class represents the message log file. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public class LogImpl implements Log +{ + /** + * Log URI. + */ + protected String logURI = null; + + /** + * Start time stamp. + */ + protected String startTimestamp = null; + + /** + * Log entries. + */ + protected Vector logEntryList = new Vector(); + + /** + * Last log entry. + */ + protected MessageEntry lastLogEntry = null; + + /** + * Log title. + */ + // ADD: Should we provide a way to set the log title? + protected String logTitle = "Message Log File"; + + /** + * Style sheet string. + */ + protected String styleSheetString = null; + + /** + * @see org.eclipse.wst.wsi.internal.log.Log#addLogEntry(LogEntry) + */ + public void addLogEntry(MessageEntry logEntry) throws WSIException + { + // Save last log entry + lastLogEntry = logEntry; + + // Add log entry + logEntryList.add(logEntry); + } + + /** + * @see org.eclipse.wst.wsi.internal.log.Log#getEntryCount() + */ + public int getEntryCount() + { + return logEntryList.size(); + } + + /** + * @see org.eclipse.wst.wsi.internal.log.Log#getLogEntry(int) + */ + public MessageEntry getLogEntry(int index) + { + return (MessageEntry) logEntryList.elementAt(index); + } + + /** + * @see org.eclipse.wst.wsi.internal.log.Log#getLogEntryList() + */ + public Vector getLogEntryList() + { + return logEntryList; + } + + /** + * Get last log entry. + */ + public MessageEntry getLastLogEntry() + { + return lastLogEntry; + } + + /** + * Create log entry object. + */ + public MessageEntry createLogEntry() + { + return new MessageEntryImpl(); + } + + /** + * @see org.eclipse.wst.wsi.internal.document.WSIDocument#getLocation() + */ + public String getLocation() + { + return this.logURI; + } + + /** + * @see org.eclipse.wst.wsi.internal.document.WSIDocument#setLocation(String) + */ + public void setLocation(String documentURI) + { + this.logURI = documentURI; + } + + /** + * Set style sheet string. + */ + public void setStyleSheetString(String styleSheetString) + { + this.styleSheetString = styleSheetString; + } + + /** + * Get start element string. + */ + public String getStartXMLString(String namespaceName) + { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + + String nsName = namespaceName; + if ((!nsName.equals("") && (!nsName.endsWith(":")))) + nsName += ":"; + + // Create report element + pw.println(WSIConstants.XML_DECL); + if (this.styleSheetString != null) + pw.println(this.styleSheetString); + + // Add XML comment + String comment; + if ((comment = TestUtils.getXMLComment()) != null) + pw.print(comment); + + // Log + pw.print("<" + nsName + ELEM_NAME); + + // REMOVED: No longer required by the monitor spec + //pw.print(" " + WSIConstants.ATTR_NAME + "=\"" + logTitle + "\""); + pw.println( + " " + WSIConstants.ATTR_TIMESTAMP + "=\"" + Utils.getTimestamp() + "\""); + pw.println(" xmlns=\"" + WSIConstants.NS_URI_WSI_LOG + "\""); + pw.println( + " xmlns:" + + WSIConstants.NS_NAME_WSI_MONITOR_CONFIG + + "=\"" + + WSIConstants.NS_URI_WSI_MONITOR_CONFIG + + "\""); + //pw.println(" xmlns:" + WSIConstants.NS_NAME_WSI_COMMON + "=\"" + + // WSIConstants.NS_URI_WSI_COMMON + "\""); + pw.println( + " xmlns:" + + WSIConstants.NS_NAME_XSI + + "=\"" + + WSIConstants.NS_URI_XSI + + "\">"); + + // Add monitor tool info + //pw.println(monitor.toXMLString(nsName)); + + // Return XML string + return sw.toString(); + } + + /** + * Get end element string. + */ + public String getEndXMLString(String namespaceName) + { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + + String nsName = namespaceName; + if ((!nsName.equals("") && (!nsName.endsWith(":")))) + nsName += ":"; + + // End log element + pw.println(""); + + // Return XML string + return sw.toString(); + } + + /** + * @see org.eclipse.wst.wsi.internal.document.DocumentElement#toXMLString(String) + */ + public String toXMLString(String namespaceName) + { + // ADD: + return null; + } + +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/log/impl/LogReaderImpl.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/log/impl/LogReaderImpl.java new file mode 100644 index 000000000..99301605d --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/log/impl/LogReaderImpl.java @@ -0,0 +1,782 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.log.impl; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.log.LogReader; +import org.eclipse.wst.wsi.internal.log.MessageEntry; +import org.eclipse.wst.wsi.internal.log.MessageEntryHandler; +import org.eclipse.wst.wsi.internal.log.MimePart; +import org.eclipse.wst.wsi.internal.log.MimeParts; +import org.eclipse.wst.wsi.internal.log.impl.MimePartImpl; +import org.eclipse.wst.wsi.internal.log.impl.MimePartsImpl; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.report.ArtifactReference; +import org.eclipse.wst.wsi.internal.report.Entry; +import org.eclipse.wst.wsi.internal.report.impl.ArtifactReferenceImpl; +import org.eclipse.wst.wsi.internal.report.impl.EntryImpl; +import org.eclipse.wst.wsi.internal.util.EntryType; +import org.eclipse.wst.wsi.internal.util.Utils; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; +import org.eclipse.wst.wsi.internal.xml.dom.ElementLocation; +import org.eclipse.wst.wsi.internal.monitor.config.Comment; +import org.eclipse.wst.wsi.internal.monitor.config.impl.CommentImpl; +import org.eclipse.wst.wsi.internal.ToolEnvironment; +import org.eclipse.wst.wsi.internal.ToolInfo; + +import org.xml.sax.*; +import org.xml.sax.helpers.*; + +import java.io.*; +import java.util.*; + +/** + * Defines the implementation used to read the Log file. + * + * @version 1.0.1 + * @author Neil Delima (nddelima@ca.ibm.com) + * @author Peter Brittenham (peterbr@us.ibm.com) + * @author Graham Turrell (gturrell@uk.ibm.com) + */ +public class LogReaderImpl implements LogReader +{ + /** + * Document location. + */ + private String documentURI; + + /** Used to ensure that the implementer is the first element after the log element **/ + private int firstLogElement = 0; + private int elementCount = 0; + private boolean bMonitorFirst = false; + + private WSIException wsiException = null; + + /** + * @see org.eclipse.wst.wsi.internal.log.LogReader#readLog(String, LogEntryHandler) + */ + public void readLog(String logURI, MessageEntryHandler logReaderCallback) + throws WSIException + { + // Read the log file entries + readLog(new InputSource(logURI), logReaderCallback); + } + + /** + * @see org.eclipse.wst.wsi.internal.log.LogReader#readLog(Reader, LogEntryHandler) + */ + public void readLog(Reader reader, MessageEntryHandler logReaderCallback) + throws WSIException + { + // Read the log file entries + readLog(new InputSource(reader), logReaderCallback); + } + + /** + * Read and parse the log file. + * @param inputSource an InputSource object + * @param messageEntryHandler a MessageEntryHandler object + * @throws WSIException if a problem occurs while reading the log file. + */ + protected void readLog( + InputSource inputSource, + MessageEntryHandler messageEntryHandler) + throws WSIException + { + try + { + // Get the XML reader + XMLReader xmlReader = XMLUtils.getXMLReader(); + + /** TO DO: The LogFile must be valid wrt its schema. The schemaLocation probably + * needs to be set in some properties file. + * These two are to turn on validation + reader.setFeature(FEATURE_VALIDATION,true); + */ + + // Set the content handler + xmlReader.setContentHandler(new LogFileHandler(messageEntryHandler)); + + // Start parsing the file + xmlReader.parse(inputSource); + + // ADD: Need to find a way to determine when this exception should be thrown, + // since by the time we get here all of the test assertions have been processed. + // Also, only the last exception is propogated back. Should all of the exceptions + // be captured and propogated back? + if (wsiException != null) + { + // TEMP: For now, don't throw the exception + //throw wsiException; + } + + //Requirement, the monitor MUST be the first child of the log. + //Perhaps we need to preprocess the log if this is the first condition to be met. + if (!bMonitorFirst) + throw new WSIException( + "The Element \"" + + WSIConstants.ELEM_MONITOR + + "\" is not the first child of the Element \"log\""); + } + catch (Exception e) + { + throw new WSIException( + "An error occurred while processing the message log file.", + e); + } + } + + /** + * @see org.eclipse.wst.wsi.internal.document.DocumentReader#getLocation() + */ + public String getLocation() + { + return this.documentURI; + } + + /** + * @see org.eclipse.wst.wsi.internal.document.DocumentReader#setLocation(String) + */ + public void setLocation(String documentURI) + { + this.documentURI = documentURI; + } + + /** + * Process and handles elements and attribute in the log file and invokes + * message validation assertions serially as the file is being processed, + * if a messagevalidator exists. + */ + private class LogFileHandler extends DefaultHandler + { + + /** private members that represent a MessageEntry.*/ + private String id; + private String conversationID; + private String type; + private String timestamp; + private StringBuffer senderHostAndPort = null; + private StringBuffer receiverHostAndPort = null; + private StringBuffer messageContent = null; + private StringBuffer httpHeaders = null; + private StringBuffer boundary = null; + private StringBuffer mimeHeaders = null; + private StringBuffer mimeContent = null; + private MimeParts mimeParts = null; + private List boundaries = null; + + private int bom = 0; + + private String logTimestamp = null; + private StringBuffer monitorComment; + private boolean ignoreComment = false; + + /** Other private members */ + private String currentElement; + + private ElementLocation entryElementLocation = null; + + private ToolInfo toolInfo = null; + + private Vector messageEntryList = new Vector(); + + private MessageEntryHandler logEntryHandler = null; + + private Locator locator = null; + + /** + * Log file handler. + */ + public LogFileHandler(MessageEntryHandler logEntryHandler) + { + this.logEntryHandler = logEntryHandler; + + toolInfo = new ToolInfo(); + toolInfo.setToolEnvironment(new ToolEnvironment()); + } + + /** + * Start document. + */ + public void startDocument() + { + } + + /** + * Set document locato. + */ + public void setDocumentLocator(Locator locator) + { + this.locator = locator; + + // DEBUG: + //System.out.println("line: " + locator.getLineNumber() + ", column: " + locator.getColumnNumber()); + } + + /** + * Start element. + */ + public void startElement( + String namespaceURI, + String localName, + String qName, + Attributes attributes) + { + // DEBUG: + //System.out.println("localName:" + localName + ", line: " + locator.getLineNumber() + ", column: " + locator.getColumnNumber()); + + //Requirement, the implementer MUST be the first child of the log + if (elementCount == 2) + if (firstLogElement == 1) + bMonitorFirst = true; + + elementCount++; + + // + if (localName == WSIConstants.ELEM_LOG) + { + // Save the timestamp value + this.logTimestamp = attributes.getValue(WSIConstants.ATTR_TIMESTAMP); + } + + // + else if ( + (localName == WSIConstants.ELEM_CONFIG) + && (namespaceURI == WSIConstants.NS_URI_WSI_MONITOR_CONFIG)) + { + // Save comment element if it exists + ignoreComment = false; + } + + // + else if ( + (localName == WSIConstants.ELEM_COMMENT) + && (namespaceURI == WSIConstants.NS_URI_WSI_MONITOR_CONFIG)) + { + // If this is the comment element within the configuration element, then get its content + if (!ignoreComment) + { + currentElement = WSIConstants.ELEM_COMMENT; + monitorComment = new StringBuffer(); + } + } + + // + else if ( + (localName == WSIConstants.ELEM_REDIRECT) + && (namespaceURI == WSIConstants.NS_URI_WSI_MONITOR_CONFIG)) + { + // After hitting the first redirect statement, ignore all comment elements + ignoreComment = true; + monitorComment = null; + } + + // + else if (localName == WSIConstants.ELEM_MONITOR) + { + firstLogElement++; + toolInfo.setName(WSIConstants.ELEM_MONITOR); + + // Get the monitor version and release date + toolInfo.setVersion(attributes.getValue(WSIConstants.ATTR_VERSION)); + toolInfo.setReleaseDate( + attributes.getValue(WSIConstants.ATTR_RELEASE_DATE)); + } + + // + else if (localName == WSIConstants.ELEM_IMPLEMENTER) + { + currentElement = WSIConstants.ELEM_IMPLEMENTER; + toolInfo.setImplementer(attributes.getValue(WSIConstants.ATTR_NAME)); + toolInfo.setLocation(attributes.getValue(WSIConstants.ATTR_LOCATION)); + } + + // + else if (localName == WSIConstants.ELEM_RUNTIME) + { + currentElement = WSIConstants.ELEM_RUNTIME; + toolInfo.getToolEnvironment().setRuntimeName( + attributes.getValue(WSIConstants.ATTR_NAME)); + toolInfo.getToolEnvironment().setRuntimeVersion( + attributes.getValue(WSIConstants.ATTR_VERSION)); + } + + // + else if (localName == WSIConstants.ELEM_OPERATING_SYSTEM) + { + currentElement = WSIConstants.ELEM_OPERATING_SYSTEM; + toolInfo.getToolEnvironment().setOSName( + attributes.getValue(WSIConstants.ATTR_NAME)); + toolInfo.getToolEnvironment().setOSVersion( + attributes.getValue(WSIConstants.ATTR_VERSION)); + } + + // + else if (localName == WSIConstants.ELEM_XML_PARSER) + { + currentElement = WSIConstants.ELEM_XML_PARSER; + toolInfo.getToolEnvironment().setXMLParserName( + attributes.getValue(WSIConstants.ATTR_NAME)); + toolInfo.getToolEnvironment().setXMLParserVersion( + attributes.getValue(WSIConstants.ATTR_VERSION)); + } + + // + else if (localName == WSIConstants.ELEM_MESSAGE_ENTRY) + { + currentElement = WSIConstants.ELEM_MESSAGE_ENTRY; + entryElementLocation = new ElementLocation(this.locator); + timestamp = attributes.getValue(WSIConstants.ATTR_TIMESTAMP); + conversationID = attributes.getValue(WSIConstants.ATTR_CONVERSATION_ID); + id = attributes.getValue(WSIConstants.ATTR_ID_UC); + type = attributes.getValue(WSIConstants.ATTR_TYPE); + } + + // + else if (localName == WSIConstants.ELEM_HTTP_HEADERS) + { + //Note: Character data could be split up and returned + //in more more than one characters call. + httpHeaders = new StringBuffer(); + currentElement = WSIConstants.ELEM_HTTP_HEADERS; + } + + // + else if (localName == WSIConstants.ELEM_MESSAGE_CONTENT) + { + messageContent = new StringBuffer(); + mimeParts = null; + currentElement = WSIConstants.ELEM_MESSAGE_CONTENT; + String bomString = attributes.getValue(WSIConstants.ATTR_BOM); + if (bomString != null) + bom = Integer.valueOf(bomString).intValue(); + else + bom = 0; + } + + // + else if (localName == WSIConstants.ELEM_MESSAGE_CONTENT_WITH_ATTACHMENTS) + { + messageContent = null; + mimeParts = new MimePartsImpl(); + + String bomString = attributes.getValue(WSIConstants.ATTR_BOM); + if (bomString != null) + bom = Integer.valueOf(bomString).intValue(); + else + bom = 0; + } + + // + else if (localName == WSIConstants.ELEM_MIME_PART) + { + if (boundaries == null) + boundaries = new ArrayList(2); + else + boundaries.clear(); + } + + // + else if (localName == WSIConstants.ELEM_BOUNDARY_STRING) + { + boundary = new StringBuffer(); + currentElement = WSIConstants.ELEM_BOUNDARY_STRING; + } + + // + else if (localName == WSIConstants.ELEM_MIME_HEADERS) + { + mimeHeaders = new StringBuffer(); + currentElement = WSIConstants.ELEM_MIME_HEADERS; + } + + // + else if (localName == WSIConstants.ELEM_MIME_CONTENT) + { + mimeContent = new StringBuffer(); + currentElement = WSIConstants.ELEM_MIME_CONTENT; + } + + // + else if (localName == WSIConstants.ELEM_SENDER_HOST_AND_PORT) + { + senderHostAndPort = new StringBuffer(); + currentElement = WSIConstants.ELEM_SENDER_HOST_AND_PORT; + } + + // + else if (localName == WSIConstants.ELEM_RECEIVER_HOST_AND_PORT) + { + receiverHostAndPort = new StringBuffer(); + currentElement = WSIConstants.ELEM_RECEIVER_HOST_AND_PORT; + } + } + + /** + * Characters callback. + */ + public void characters(char ch[], int start, int length) + { + // Ignoring CRLF that appears in log elements + int altStart = start; + int altLength = length; + if (start > 0 && ch[start-1] == 13 && ch[start] == 10) + { + altStart++; + altLength--; + } + + // + if (monitorComment != null && currentElement == WSIConstants.ELEM_COMMENT) + { + monitorComment.append(ch, start, length); + } + + // + else if (messageContent != null + && currentElement == WSIConstants.ELEM_MESSAGE_CONTENT) + { + messageContent.append(ch, start, length); + } + + // + else if (httpHeaders != null + && currentElement == WSIConstants.ELEM_HTTP_HEADERS) + { + httpHeaders.append(ch, start, length); + } + + // + else if (boundary != null + && currentElement == WSIConstants.ELEM_BOUNDARY_STRING) + { + boundary.append(ch, altStart, altLength); + } + + // + else if (mimeHeaders != null + && currentElement == WSIConstants.ELEM_MIME_HEADERS) + { + mimeHeaders.append(ch, altStart, altLength); + } + + // + else if (mimeContent != null + && currentElement == WSIConstants.ELEM_MIME_CONTENT) + { + mimeContent.append(ch, altStart, altLength); + } + + // + else if (senderHostAndPort != null + && currentElement == WSIConstants.ELEM_SENDER_HOST_AND_PORT) + { + senderHostAndPort.append(ch, start, length); + } + + // + else if (receiverHostAndPort != null + && currentElement == WSIConstants.ELEM_RECEIVER_HOST_AND_PORT) + { + receiverHostAndPort.append(ch, start, length); + } + } + + /** + * End Element. + */ + public void endElement(String namespaceURI, String localName, String qName) + { + // + if ( + (localName == WSIConstants.ELEM_COMMENT) + && (namespaceURI == WSIConstants.NS_URI_WSI_MONITOR_CONFIG)) + { + // If we saved the comment, then process it and the log timestamp + if (this.monitorComment != null) + { + ArtifactReference artifactReference = new ArtifactReferenceImpl(); + artifactReference.setTimestamp(this.logTimestamp); + Comment comment = new CommentImpl(); + comment.setText(monitorComment.toString()); + artifactReference.setDocumentElement( + comment, + WSIConstants.NS_NAME_WSI_MONITOR_CONFIG); + processArtifactReference(artifactReference); + } + } + + // + else if (localName == WSIConstants.ELEM_BOUNDARY_STRING) + { + // Adding boundary string to a list + boundaries.add(boundary.toString()); + } + + // + else if (localName == WSIConstants.ELEM_MIME_PART) + { + // Creating a MessageMIMEPart instance + MimePart part = new MimePartImpl(); + part.setHeaders(mimeHeaders.toString()); + part.setContent(mimeContent.toString()); + part.setBoundaryStrings((String[])boundaries.toArray(new String[0])); + + mimeParts.addPart(part); + } + + // + else if (localName == WSIConstants.ELEM_MESSAGE_ENTRY) + { + // Assumption: Related messages are sequentially available in the message log. + if (MessageEntry.TYPE_REQUEST.equalsIgnoreCase(type)) + { + // Create log entry + MessageEntry messageEntryRequest = + createMessageEntry( + id, + conversationID, + type, + timestamp, + senderHostAndPort.toString(), + receiverHostAndPort.toString(), + messageContent == null ? "" : messageContent.toString(), + httpHeaders.toString(), + mimeParts, + entryElementLocation); + + // Add log entry to the list + messageEntryList.add(messageEntryRequest); + + // Request is now processed only when the response is received. + } + + else if (MessageEntry.TYPE_RESPONSE.equalsIgnoreCase(type)) + { + // Create log entry + MessageEntry messageEntryResponse = + createMessageEntry( + id, + conversationID, + type, + timestamp, + senderHostAndPort.toString(), + receiverHostAndPort.toString(), + messageContent == null ? "" : messageContent.toString(), + httpHeaders.toString(), + mimeParts, + entryElementLocation); + + // Add log entry to the list + messageEntryList.add(messageEntryResponse); + + if (logEntryHandler != null) + { + // look up the request message + // ISSUE : need to throw & catch a nullpointerexception in here... + MessageEntry messageEntryRequest = findRelatedRequest(messageEntryResponse); + + if (messageEntryRequest != null) + { + // Create entry + // ADD: Need to create entry from report + //Entry entry = this.reporter.getReport().createEntry(); + Entry entry = new EntryImpl(); + entry.setEntryType( + EntryType.getEntryType(EntryType.TYPE_MESSAGE_REQUEST)); + entry.setReferenceID(messageEntryRequest.getId()); + entry.setEntryDetail(messageEntryRequest); + + // Create the context for the request-response pair + EntryContext requestTargetContext = + new EntryContext( + entry, + messageEntryRequest, + messageEntryResponse); + if (requestTargetContext != null) + processLogEntry(requestTargetContext); + } + + // Create entry + // ADD: Need to create entry from report + //Entry entry = this.reporter.getReport().createEntry(); + Entry entry = new EntryImpl(); + entry.setEntryType( + EntryType.getEntryType(EntryType.TYPE_MESSAGE_RESPONSE)); + entry.setReferenceID(messageEntryResponse.getId()); + entry.setEntryDetail(messageEntryResponse); + + EntryContext responseTargetContext = + new EntryContext( + entry, + messageEntryRequest, + messageEntryResponse); + if (responseTargetContext != null) + processLogEntry(responseTargetContext); + } + } + } + + currentElement = null; + } + + /** + * End Document. + */ + public void endDocument() + { + //If we want to serially process the log file. Invoke validateMessages with + //msgValidator!=null. Here we have the option of clearing the logEntry vector + //once message validation is done. + //if (msgValidator!=null) + //logEntryList.clear(); + } + + /** + * Process the message in the log entry. + */ + public void processLogEntry(EntryContext entryContext) + { + try + { + //Before validating any messages check if implementer is the first element. + logEntryHandler.processLogEntry(entryContext); + } + catch (Exception e) + { + wsiException = + new WSIException( + "An error occurred while validating" + + " the message logEntry: " + + entryContext.getMessageEntry().getId(), + e); + } + } + + /** + * Process the artifact reference. + */ + private void processArtifactReference(ArtifactReference artifactReference) + { + try + { + //Before validating any messages check if implementer is the first element. + logEntryHandler.processArtifactReference(artifactReference); + } + + catch (Exception e) + { + wsiException = + new WSIException( + "An error occurred while processing" + + " the artifact reference: " + + artifactReference.toString(), + e); + } + } + + /** + * Find the related Request LogEntry. The current rule for related log entires is + * that a request will always precede its response. + * ISSUE: Sequence in log file is timestamp driven (monitor spec). + * Assertion is that for a given conversationID, a second request is not sent + * until its response is received (chronologically). + * This method will have to be modified if the rule changes. + */ + // could be made more efficient by keeping a much smaller list of unresponded requests... + public MessageEntry findRelatedRequest(MessageEntry logEntryResponse) + { + for (int entry = messageEntryList.size() - 1; entry >= 0; entry--) + { + // Get the log entry of the matching request + MessageEntry logEntry = (MessageEntry) messageEntryList.get(entry); + // Ignore own entry + if (!logEntryResponse.equals(logEntry)) + { + if (logEntryResponse + .getConversationId() + .equals(logEntry.getConversationId())) + { + // found the most recently read message with the same conversationID. + // From above, this should be the corresponding request. Check as far as possible. + if (logEntry.getType().equals(MessageEntry.TYPE_REQUEST)) + { + return logEntry; + } + else + { + return null; // expected a request. need to throw an exception! + } + } + } + } + return null; + // conversationID match not found anywhere. need to throw an exception! + } + + /** + * Create log entry. + */ + private MessageEntry createMessageEntry( + String id, + String conversationId, + String type, + String timestamp, + String senderIPPort, + String receiverIPPort, + String messageContent, + String httpHeaders, + MimeParts mimeParts, + ElementLocation elementLocation) + { + // Create log entry + MessageEntry messageEntry = new MessageEntryImpl(); + messageEntry.setId(id); + messageEntry.setConversationId(conversationID); + messageEntry.setType(type); + messageEntry.setTimestamp(timestamp); + messageEntry.setSenderHostAndPort(senderIPPort); + messageEntry.setReceiverHostAndPort(receiverIPPort); + messageEntry.setHTTPHeaders(httpHeaders); + messageEntry.setBOM(bom); + messageEntry.setElementLocation(elementLocation); + + String encoding = null; + if (mimeParts == null) + { + // Get the encoding for this message content + encoding = Utils.getXMLEncoding(messageContent); + messageEntry.setMessage(messageContent); + messageEntry.setMimeContent(false); + } + else + { + messageEntry.setMimeParts(mimeParts); + MimePart root = Utils.findRootPart(httpHeaders, mimeParts.getParts()); + if (root != null) + { + // Get the encoding for this message content + encoding = Utils.getXMLEncoding(root.getContent()); + mimeParts.setRootPart(root); + } + // else empty body + messageEntry.setMimeContent(true); + } + if ((encoding == null) || (encoding.equals(""))) + encoding = WSIConstants.DEFAULT_XML_ENCODING; + messageEntry.setEncoding(encoding); + + return messageEntry; + } + + } //End ContentHandler +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/log/impl/LogWriterImpl.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/log/impl/LogWriterImpl.java new file mode 100644 index 000000000..8d3419910 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/log/impl/LogWriterImpl.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.log.impl; + +import java.io.Writer; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.document.impl.DocumentWriterImpl; +import org.eclipse.wst.wsi.internal.log.Log; +import org.eclipse.wst.wsi.internal.log.LogWriter; + +/** + * Defines the implementation used to write the Log file. + * + * @version 1.0.1 + * @author Neil Delima (nddelima@ca.ibm.com) + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public class LogWriterImpl extends DocumentWriterImpl implements LogWriter +{ + /** + * @see org.eclipse.wst.wsi.internal.log.LogWriter#write(Log) + */ + public synchronized void write(Log log) + throws IllegalStateException, WSIException + { + // If the writer was not specified, then throw an exception + if (writer == null) + throw new IllegalStateException("Could not write log file since writer was not set."); + + // Write log file + write(log, writer); + } + + /** + * @see org.eclipse.wst.wsi.internal.log.LogWriter#write(Log, Writer) + */ + public synchronized void write(Log log, Writer writer) throws WSIException + { + // ADD: + throw new WSIException("Write entire log file function not supported yet."); + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/log/impl/MessageEntryImpl.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/log/impl/MessageEntryImpl.java new file mode 100644 index 000000000..93bd251b0 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/log/impl/MessageEntryImpl.java @@ -0,0 +1,374 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.log.impl; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.log.MessageEntry; +import org.eclipse.wst.wsi.internal.log.MimePart; +import org.eclipse.wst.wsi.internal.log.MimeParts; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; +import org.eclipse.wst.wsi.internal.xml.dom.ElementLocation; + +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.Collection; +import java.util.Iterator; + +/** + * Message entry implementation. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public class MessageEntryImpl implements MessageEntry +{ + /** + * Log entry id. + */ + protected String id; + + protected String conversationId; + protected String type; + protected String timestamp; + protected String senderHostAndPort; + protected String receiverHostAndPort; + protected String message = ""; + protected String httpHeaders = ""; + protected int bom; + protected String encoding = ""; + protected boolean isMimeContent = false; + protected MimeParts mimeParts = new MimePartsImpl(); + + protected ElementLocation elementLocation = null; + + /** + * Empty constructor. + */ + public MessageEntryImpl() + { + } + + /* (non-Javadoc) + * @see org.wsi.test.log.LogEntry#getId() + */ + public String getId() + { + return this.id; + } + + /* (non-Javadoc) + * @see org.wsi.test.log.LogEntry#setId(String) + */ + public void setId(String id) + { + this.id = id; + } + + /* (non-Javadoc) + * @see org.wsi.test.log.LogEntry#getConversationId() + */ + public String getConversationId() + { + return this.conversationId; + } + + /* (non-Javadoc) + * @see org.wsi.test.log.LogEntry#setConversationId(String) + */ + public void setConversationId(String conversationId) + { + this.conversationId = conversationId; + } + + /* (non-Javadoc) + * @see org.wsi.test.log.LogEntry#getTimestamp() + */ + public String getTimestamp() + { + return this.timestamp; + } + + /* (non-Javadoc) + * @see org.wsi.test.log.LogEntry#setTimestamp(String) + */ + public void setTimestamp(String timestamp) + { + this.timestamp = timestamp; + } + + /* (non-Javadoc) + * @see org.wsi.test.log.LogEntry#getType() + */ + public String getType() + { + return this.type; + } + + /* (non-Javadoc) + * @see org.wsi.test.log.LogEntry#setType(String) + */ + public void setType(String type) + { + this.type = type; + } + + /* (non-Javadoc) + * @see org.wsi.test.log.LogEntry#getSenderHostAndPort() + */ + public String getSenderHostAndPort() + { + return this.senderHostAndPort; + } + + /* (non-Javadoc) + * @see org.wsi.test.log.LogEntry#setSenderHostAndPort(String) + */ + public void setSenderHostAndPort(String senderHostAndPort) + { + this.senderHostAndPort = senderHostAndPort; + } + + /* (non-Javadoc) + * @see org.wsi.test.log.LogEntry#getReceiverHostAndPort() + */ + public String getReceiverHostAndPort() + { + return this.receiverHostAndPort; + } + + /* (non-Javadoc) + * @see org.wsi.test.log.LogEntry#setReceiverHostAndPort(String) + */ + public void setReceiverHostAndPort(String receiverHostAndPort) + { + this.receiverHostAndPort = receiverHostAndPort; + } + + /* (non-Javadoc) + * @see org.wsi.test.log.LogEntry#getMessage() + */ + public String getMessage() + { + if (!this.isMimeContent) + return this.message; + else + { + if (this.mimeParts.getRootPart() == null) return ""; + else return this.mimeParts.getRootPart().getContent(); + } + } + + /* (non-Javadoc) + * @see org.wsi.test.log.LogEntry#setMessage(String) + */ + public void setMessage(String message) + { + this.message = message; + } + + /* (non-Javadoc) + * @see org.wsi.test.log.LogEntry#setEncoding(String) + */ + public void setEncoding(String encoding) + { + this.encoding = encoding; + } + + /* (non-Javadoc) + * @see org.wsi.test.log.MessageEntry#getBOM() + */ + public int getBOM() + { + return bom; + } + + /* (non-Javadoc) + * @see org.wsi.test.log.MessageEntry#setBOM(int) + */ + public void setBOM(int bom) + { + this.bom = bom; + } + + /* (non-Javadoc) + * @see org.wsi.test.log.LogEntry#getHTTPHeaders() + */ + public String getHTTPHeaders() + { + return this.httpHeaders; + } + + /* (non-Javadoc) + * @see org.wsi.test.log.LogEntry#setHTTPHeaders(String) + */ + public void setHTTPHeaders(String httpHeaders) + { + this.httpHeaders = httpHeaders; + } + + /* (non-Javadoc) + * @see org.wsi.test.log.MessageEntry#getElementLocation() + */ + public ElementLocation getElementLocation() + { + return this.elementLocation; + } + + /* (non-Javadoc) + * @see org.wsi.test.log.MessageEntry#setElementLocation(org.wsi.xml.dom.ElementLocation) + */ + public void setElementLocation(ElementLocation elementLocation) + { + this.elementLocation = elementLocation; + } + + /** + * Get string representation of this object. + */ + public String toString() + { + return toXMLString(WSIConstants.NS_NAME_WSI_LOG); + } + + /* (non-Javadoc) + * @see org.wsi.test.document.DocumentElement#toXMLString(String) + */ + public String toXMLString(String namespaceName) + { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + + String nsName = namespaceName; + if ((!nsName.equals("") && (!nsName.endsWith(":")))) + nsName += ":"; + + // ADD: Need to add way to indicate XML schema type for logEntry + // Add log entry + pw.print("<" + nsName + ELEM_NAME + " "); + pw.print( + "xsi:type=\"httpMessageEntry\" "); + pw.print(WSIConstants.ATTR_ID_UC + "=\"" + id + "\" "); + pw.print( + WSIConstants.ATTR_CONVERSATION_ID + "=\"" + conversationId + "\" "); + pw.print(WSIConstants.ATTR_TYPE + "=\"" + type + "\" "); + pw.println(WSIConstants.ATTR_TIMESTAMP + "=\"" + timestamp + "\">"); + + if (isMimeContent()) + { + // Add message content with attachments element + pw.print("<" + nsName + WSIConstants.ELEM_MESSAGE_CONTENT_WITH_ATTACHMENTS); + if (bom != 0) + pw.print(" " + WSIConstants.ATTR_BOM + "=\"" + bom + "\""); + pw.print(">"); + + Collection partList = mimeParts.getParts(); + if (!partList.isEmpty()) + { + Iterator iMimeParts = partList.iterator(); + while (iMimeParts.hasNext()) + { + MimePart mimePart = (MimePart)iMimeParts.next(); + pw.print(mimePart.toXMLString(namespaceName)); + } + } + + // Add end message element + pw.println(""); + } + else + { + // Add message content element + pw.print("<" + nsName + WSIConstants.ELEM_MESSAGE_CONTENT); + if (bom != 0) + pw.print(" " + WSIConstants.ATTR_BOM + "=\"" + bom + "\""); + pw.print(">"); + + // Add encoded message + pw.print(XMLUtils.xmlEscapedString(message)); + + // Add end message element + pw.println(""); + } + + // Add senderIPPort element + pw.println( + "<" + + nsName + + WSIConstants.ELEM_SENDER_HOST_AND_PORT + + ">" + + senderHostAndPort + + ""); + + // Add receiverIP element + pw.println( + "<" + + nsName + + WSIConstants.ELEM_RECEIVER_HOST_AND_PORT + + ">" + + receiverHostAndPort + + ""); + + // Add HTTPHeaders element + pw.print("<" + nsName + WSIConstants.ELEM_HTTP_HEADERS + ">"); + + // ADD: Does this string need to be XML encoded? + // Add HTTP headers + pw.print(XMLUtils.xmlEscapedString(httpHeaders)); + + // End HTTPHeaders element + pw.println(""); + + // End log entry + pw.println(""); + + // Return string + return sw.toString(); + } + + /* (non-Javadoc) + * @see org.wsi.test.log.MessageEntry#isMimeContent() + */ + public boolean isMimeContent() + { + return isMimeContent; + } + + /* (non-Javadoc) + * @see org.wsi.test.log.MessageEntry#setMimeContent() + */ + public void setMimeContent(boolean isMimeContent) + { + this.isMimeContent = isMimeContent; + } + + /* (non-Javadoc) + * @see org.wsi.test.log.MessageEntry#getMIMEParts() + */ + public MimeParts getMimeParts() + { + return mimeParts; + } + + /* (non-Javadoc) + * @see org.wsi.test.log.MessageEntry#setMimeParts() + */ + public void setMimeParts(MimeParts mimeParts) + { + this.mimeParts = mimeParts; + } + +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/log/impl/MimePartImpl.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/log/impl/MimePartImpl.java new file mode 100644 index 000000000..998fddf98 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/log/impl/MimePartImpl.java @@ -0,0 +1,135 @@ +/* + * Created on Nov 22, 2004 + * + * TODO To change the template for this generated file go to + * Window - Preferences - Java - Code Style - Code Templates + */ +package org.eclipse.wst.wsi.internal.log.impl; + +import java.io.PrintWriter; +import java.io.StringWriter; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.log.MimePart; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; + +/** + * @author lauzond + * + * TODO To change the template for this generated type comment go to + * Window - Preferences - Java - Code Style - Code Templates + */ +public class MimePartImpl implements MimePart +{ + private String mimeContent; + private String mimeHeaders; + private String[] boundaryStrings = new String[0]; + + public MimePartImpl () + { + } + + /* (non-Javadoc) + * @see org.wsi.test.log.MimePart#getContent() + */ + public String getContent() + { + return this.mimeContent; + } + + /* (non-Javadoc) + * @see org.wsi.test.log.MimePart#setContent(String) + */ + public void setContent(String mimeContent) + { + this.mimeContent = mimeContent; + } + + /** + /* (non-Javadoc) + * @see org.eclipse.wst.wsi.internal.log.MimePart#getHeaders() + */ + public String getHeaders() + { + return this.mimeHeaders; + } + + /* (non-Javadoc) + * @see org.wsi.test.log.MimePart#setHeaders(String) + */ + public void setHeaders(String mimeHeaders) + { + this.mimeHeaders = mimeHeaders; + } + + /* (non-Javadoc) + * @see org.wsi.test.log.MimePart#getBoundaryStrings() + */ + public String[] getBoundaryStrings() + { + return this.boundaryStrings; + } + + /* (non-Javadoc) + * @see org.wsi.test.log.MimePart#setBoundaryStrings(String[]) + */ + public void setBoundaryStrings(String[] boundaryStrings) + { + this.boundaryStrings = boundaryStrings; + } + + /** + * Get string representation of this object. + */ + public String toString() + { + return toXMLString(WSIConstants.NS_NAME_WSI_LOG); + } + + /* (non-Javadoc) + * @see org.wsi.test.document.DocumentElement#toXMLString(String) + */ + public String toXMLString(String namespaceName) + { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + + String nsName = namespaceName; + if ((!nsName.equals("") && (!nsName.endsWith(":")))) + nsName += ":"; + + // Add mimePart element + pw.println("<" + nsName + WSIConstants.ELEM_MIME_PART + ">"); + + // Add boundary string element + for (int i = 0; i < boundaryStrings.length; i++) + { + pw.print("<" + nsName + WSIConstants.ELEM_BOUNDARY_STRING + ">"); + pw.print(boundaryStrings[i]); + pw.println(""); + } + + // Add mimeHeaders element + pw.print("<" + nsName + WSIConstants.ELEM_MIME_HEADERS + ">"); + pw.print(XMLUtils.xmlEscapedString(mimeHeaders)); + pw.println(""); + + // Add encoded content + pw.print("<" + nsName + WSIConstants.ELEM_MIME_CONTENT + ">"); + if ((mimeContent.indexOf("<") != -1) || + (mimeContent.indexOf(">") != -1) || + (mimeContent.indexOf("\"") != -1) || + (mimeContent.indexOf("\'") != -1)) + pw.print(XMLUtils.xmlEscapedString(mimeContent)); + else + pw.print(getContent()); + pw.println(""); + + // Add end message element + pw.println(""); + + // Return string + return sw.toString(); + } + +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/log/impl/MimePartsImpl.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/log/impl/MimePartsImpl.java new file mode 100644 index 000000000..69e2d6521 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/log/impl/MimePartsImpl.java @@ -0,0 +1,75 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.log.impl; + +import java.util.ArrayList; +import java.util.Collection; + +import org.eclipse.wst.wsi.internal.log.MimePart; +import org.eclipse.wst.wsi.internal.log.MimeParts; + +/** + * MimePartsImpl class. + * + * @version 1.0.1 + * @author David Lauzon (lauzond@ca.ibm.com) + */ +public class MimePartsImpl implements MimeParts +{ + + protected MimePart rootPart; + protected Collection mimeParts = new ArrayList(); + + public MimePartsImpl() + { + } + + /* (non-Javadoc) + * @see org.wsi.test.log.MimeParts#getRootPart() + */ + public MimePart getRootPart() + { + return rootPart; + } + + /* (non-Javadoc) + * @see org.wsi.test.log.MimeParts#setRootPart(MimePart) + */ + public void setRootPart(MimePart rootPart) + { + this.rootPart = rootPart; + } + + /* (non-Javadoc) + * @see org.wsi.test.log.MimeParts#count() + */ + public int count() + { + return mimeParts.size(); + } + + /* (non-Javadoc) + * @see org.wsi.test.log.MimeParts#addPart(MimePart) + */ + public void addPart(MimePart part) + { + if (part != null) + mimeParts.add(part); + } + + /* (non-Javadoc) + * @see org.wsi.test.log.MimeParts#getParts() + */ + public Collection getParts() + { + return mimeParts; + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/ChunkedData.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/ChunkedData.java new file mode 100644 index 000000000..9f56dba41 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/ChunkedData.java @@ -0,0 +1,225 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.monitor; + +/** + * This class will process chunked data. + * + * @author Peter Brittenham (peterbr@us.ibm.com) + * @version 1.0.1 + */ +public class ChunkedData +{ + protected boolean moreChunkedData = false; + protected String chunkedData = ""; + protected SocketHandler socketHandler = null; + + /** + * Constructs a ChunkedData object. + */ + public ChunkedData() + { + } + + /** + * Constructs a ChunkedData object. + * @param socketHandler socket handler. + * @param moreChunkedData chunked data. + */ + public ChunkedData(SocketHandler socketHandler, boolean moreChunkedData) + { + this.socketHandler = socketHandler; + this.moreChunkedData = moreChunkedData; + } + + /** + * Constructs a ChunkedData object. + * @param socketHandler socket handler. + * @param chunkedData chunked data. + */ + public ChunkedData(SocketHandler socketHandler, String chunkedData) + { + this.socketHandler = socketHandler; + this.chunkedData = chunkedData; + this.moreChunkedData = checkData(chunkedData); + } + + /** + * Add the chunked data to the buffer. + * @param chunkedData chunked data. + */ + public void addData(String chunkedData) + { + this.chunkedData += chunkedData; + this.moreChunkedData = checkData(chunkedData); + } + + /** + * Get data buffer. + * @return data buffer. + */ + public String getData() + { + return this.chunkedData; + } + + /** + * Clear data buffer. + */ + public void clearData() + { + this.chunkedData = ""; + } + + /** + * Returns true if there is more chunked data. + * @return true if there is more chunked data. + */ + public boolean isMoreChunkedData() + { + return this.moreChunkedData; + } + + /** + * Decode and add data to the buffer. + * @param messageBuffer a StringBuffer object. + * @return true if data is added to the buffer. + */ + public boolean decodeAndAddDataToBuffer(StringBuffer messageBuffer) + { + boolean moreChunkedData = false; + if (!this.moreChunkedData) + { + // DEBUG: + debug("decodeAndAddDataToBuffer", "chunkedData: " + chunkedData); + + moreChunkedData = decodeData(chunkedData, messageBuffer); + } + + return moreChunkedData; + } + + /** + * Check data. + */ + private boolean checkData(String chunkedData) + { + boolean moreChunkedData = false; + int index; + + // Look for [CRLF][0][CRLF] in the chunked data + if ((index = + chunkedData.indexOf(SocketHandler.CRLF + "0" + SocketHandler.CRLF)) + != -1) + { + moreChunkedData = false; + + // DEBUG: + debug( + "checkData", + "Chunk contains [CRLF][0][CRLF], so there is no more data."); + } + + // Look for [0][CRLF] at start of chunked data + else if (chunkedData.startsWith("0" + SocketHandler.CRLF)) + { + moreChunkedData = false; + + // DEBUG: + debug( + "checkData", + "Chunk data starts with [0][CRLF], so there is no more data."); + } + + // Otherwise step through it to see if we have all of the data + else + { + moreChunkedData = true; + } + + return moreChunkedData; + } + + /** + * Decode chunked data. + * + * Data format: + *

+   *   [Chunk Size][CRLF][Data Chunk][CRLF][Chunk Size][CRLF][Data Chunk][CRLF]...[0][CRLF][Optional Footer][CRLF]
+   * 
+ * + * @param chunkedData + * @param messageLoggingBuffer + */ + private boolean decodeData(String chunkedData, StringBuffer messageBuffer) + { + boolean endOfData = false; + int nextIndex = 0; + int prevIndex = 0; + int chunkSize = 0; + + String nextChunkData = null; + + // Process each chunk of data + while (!(endOfData) + && (nextIndex < chunkedData.length()) + && (nextIndex = chunkedData.indexOf(SocketHandler.CRLF, prevIndex)) != -1) + { + // Get the data length which is right after this + String hexChunkedSize = chunkedData.substring(prevIndex, nextIndex); + + // Decode length + chunkSize = Integer.decode("0x" + hexChunkedSize).intValue(); + + // DEBUG: + debug("decodeData", "chunkedSize: " + chunkSize); + + // If size is zero, then we have hit the end of the chunked data + if (chunkSize == 0) + { + endOfData = true; + } + + // If we don't have all of the data then stop + else if (nextIndex + 2 + chunkSize > chunkedData.length()) + { + break; + } + + else + { + nextChunkData = + chunkedData.substring(nextIndex + 2, nextIndex + 2 + chunkSize); + + // DEBUG: + debug("decodeData", "nextChunkData: " + nextChunkData); + + // Get message based on length + if (messageBuffer != null) + messageBuffer.append(nextChunkData); + } + + // Point at the next chunk size + prevIndex = nextIndex + 2 + chunkSize + 2; + } + + return endOfData; + } + + /** + * Debug. + */ + private void debug(String method, String message) + { + this.socketHandler.debug("ChunkedData", method, message); + } + +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/ConnectionListener.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/ConnectionListener.java new file mode 100644 index 000000000..a12878047 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/ConnectionListener.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.monitor; + +/** + * This interface is for receiving connection events. + * + * @author Sergey Suhoruchkin + * @version 1.0.1 + */ +public interface ConnectionListener +{ + /** + * Invoked when connection is closed. + * @param connection socket connection. + */ + public void connectionClosed(SocketConnection connection); +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/MessageEntryQueue.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/MessageEntryQueue.java new file mode 100644 index 000000000..dd295c7ea --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/MessageEntryQueue.java @@ -0,0 +1,220 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.monitor; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.log.Log; +import org.eclipse.wst.wsi.internal.log.LogWriter; +import org.eclipse.wst.wsi.internal.log.MessageEntry; + +import java.io.*; +import java.util.*; + +/** + * This class is the queue that is used to write request and response messages + * to the log file in the correct order. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public class MessageEntryQueue +{ + /** + * Request type message entry queue. + */ + protected Vector requestList = new Vector(); + + /** + * Response type message entry queue. + */ + protected Vector responseList = new Vector(); + + /** + * Monitor. + */ + protected Monitor monitor = null; + + /** + * Log file. + */ + protected Log log = null; + + /** + * Log writer. + */ + protected LogWriter logWriter = null; + + /** + * List lock. + */ + protected String listLock = "listLock"; + + /** + * Message ID which is incremented when a new log entry is added to the log file. + */ + protected int messageId = 1; + + /** + * Create message entry queue. + * @param monitor a monitor. + * @param log the log. + * @param logWriter a log writer. + */ + public MessageEntryQueue(Monitor monitor, Log log, LogWriter logWriter) + { + // Save input references + this.monitor = monitor; + this.log = log; + this.logWriter = logWriter; + } + + /** + * Add log entry to queue. + * @param messageEntry a message entry. + * @throws WSIException is there is a problem adding the log + * entry to the queue. + */ + public synchronized void addMessageEntry(MessageEntry messageEntry) + throws WSIException + { + synchronized (listLock) + { + // If this is a request type of message entry, then add to request list + if (messageEntry.getType().equals(MessageEntry.TYPE_REQUEST)) + { + requestList.add(messageEntry); + } + + // Otherwise this is a response type of message entry + else + { + responseList.add(messageEntry); + } + } + + // Tell the log entry writer thread to run + writeFromQueue(); + } + + /** + * Determine if any log entries need to be written. + * @throws WSIException is there is a problem adding log entries. + + */ + public synchronized void writeFromQueue() throws WSIException + { + MessageEntry requestMessageEntry = null; + MessageEntry responseMessageEntry = null; + boolean responseFound = false; + + // Create array that will contain list of index to remove from request list + int[] requestIndexList = new int[requestList.size()]; + int reqIndexCount = 0; + + synchronized (listLock) + { + // If there are entries in the request queue, + // then try to match them with entries in the response queue + for (int reqIndex = 0; reqIndex < requestList.size(); reqIndex++) + { + // Get request log entry + requestMessageEntry = (MessageEntry) requestList.elementAt(reqIndex); + + // Check each response log entry to see if the conversationId matches + responseFound = false; + for (int respIndex = 0; + respIndex < responseList.size() && !responseFound; + respIndex++) + { + // Get response log entry + responseMessageEntry = + (MessageEntry) responseList.elementAt(respIndex); + + // If the request and response have the same conversationId, + // then write them out to the log file + if (requestMessageEntry + .getConversationId() + .equals(responseMessageEntry.getConversationId())) + { + responseFound = true; + + // Set the id for the log entries + requestMessageEntry.setId(getNextMessageId()); + responseMessageEntry.setId(getNextMessageId()); + + // Write out request and then response + //==== SS start : what this line is used for??? - causes memory leak, as no removeLogEntry is called ==== + // log.addLogEntry(requestMessageEntry); + //==== SS end === + StringReader requestReader = + new StringReader(requestMessageEntry.toXMLString("")); + logWriter.write(requestReader); + + // Display message + printMessage(requestMessageEntry); + + // Write out response + //==== SS start : what this line is used for??? - causes memory leak, as no removeLogEntry is called ==== + // log.addLogEntry(responseMessageEntry); + //==== SS end === + StringReader responseReader = + new StringReader(responseMessageEntry.toXMLString("")); + logWriter.write(responseReader); + + // Display message + printMessage(responseMessageEntry); + + // Add request to list so that it can be removed later + requestIndexList[reqIndexCount++] = reqIndex; + + // Remove log entry from response list + responseList.remove(respIndex); + } + } + } + + // Remove requests that were written out + for (int count = 0; count < reqIndexCount; count++) + requestList.remove(requestIndexList[count]); + } + } + + /** + * Get the next message identifier. + * @return the next message identifier. + */ + protected synchronized String getNextMessageId() + { + return String.valueOf(messageId++); + } + + /** + * Display message. + * @param messageEntry a message entry. + */ + protected void printMessage(MessageEntry messageEntry) + { + // Display message + monitor.printMessage( + "log01", + messageEntry.getId() + + ", " + + messageEntry.getType() + + ", " + + messageEntry.getSenderHostAndPort(), + "Log message entry - ID: " + + messageEntry.getId() + + ", Type: " + + messageEntry.getType() + + ", Sender: " + + messageEntry.getSenderHostAndPort()); + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/Monitor.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/Monitor.java new file mode 100644 index 000000000..077f93c3c --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/Monitor.java @@ -0,0 +1,501 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.monitor; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.WSIFileNotFoundException; +import org.eclipse.wst.wsi.internal.document.DocumentFactory; +import org.eclipse.wst.wsi.internal.log.Log; +import org.eclipse.wst.wsi.internal.log.LogWriter; +import org.eclipse.wst.wsi.internal.util.MessageList; +import org.eclipse.wst.wsi.internal.util.TestUtils; +import org.eclipse.wst.wsi.internal.monitor.config.*; +import org.eclipse.wst.wsi.internal.ToolInfo; + +import java.io.*; +import java.util.Iterator; +import java.util.Vector; + +/** + * Message Monitor. + * + * @author Peter Brittenham (peterbr.us.ibm.com) + */ + +public class Monitor +{ + /** + * Message list. + */ + protected MessageList messageList = null; + + private final static String RESOURCE_BUNDLE_NAME = + "org.wsi.test.monitor.Monitor"; + + public final static String USAGE_MESSAGE = + "Usage: Monitor -config "; + + /** + * Converstation ID. + */ + private int conversationId = 1; + + private Log log = null; + private LogWriter logWriter = null; + private MonitorConfig monitorConfig = null; + + /** + * Tool information. + */ + public static final String TOOL_NAME = "Monitor"; + + protected ToolInfo toolInfo = null; + + protected Vector listenerList = new Vector(); + + protected MessageEntryQueue messageEntryQueue = null; + + /** + * Message monitor. + * @param args command line arguments. + * @throws WSIException if there is a problem creating a Monitor object. + */ + public Monitor(String[] args) throws WSIException + { + // Create message list + this.messageList = new MessageList(RESOURCE_BUNDLE_NAME); + + // Tool information + toolInfo = new ToolInfo(TOOL_NAME); + + // Create document factory + DocumentFactory documentFactory = DocumentFactory.newInstance(); + + // Get new config object + monitorConfig = documentFactory.newMonitorConfig(); + monitorConfig.init(this.messageList); + + // Parse command line arguments + monitorConfig.parseArgs(args); + + String logLocation = monitorConfig.getLogLocation(); + if (logLocation.indexOf(WSIConstants.PATH_SEPARATOR) > -1) + { + throw new WSIException( + messageList.getMessage( + "config11", + monitorConfig.getLogLocation(), + "The log file location value cannot contain the pass separator character:")); + } + + File file = null; + try + { + // Get file object for log file + file = new File(monitorConfig.getLogLocation()); + } + + catch (Exception e) + { + throw new WSIException( + messageList.getMessage("config07", "Could not get log file location."), + e); + } + + // If replace flag is false and file exists, then throw exception + if (file.exists() && !monitorConfig.getReplaceLog()) + { + throw new IllegalArgumentException( + messageList.getMessage( + "config08", + monitorConfig.getLogLocation(), + "Log file already exists:")); + } + + try + { + // Create output file + log = documentFactory.newLog(); + + // Set style sheet string + log.setStyleSheetString( + monitorConfig.getAddStyleSheet().getStyleSheetString()); + + // Get log writer + logWriter = documentFactory.newLogWriter(); + logWriter.setWriter(monitorConfig.getLogLocation()); + + // Write start of log file + logWriter.write(new StringReader(log.getStartXMLString(""))); + + // Write monitor tool information + logWriter.write(new StringReader(toXMLString(""))); + + // Create log entry queue + messageEntryQueue = new MessageEntryQueue(this, log, logWriter); + } + + catch (Exception e) + { + throw new WSIException( + messageList.getMessage( + "error03", + "Could not create log or log writer."), + e); + } + + // Get manInTheMiddle settings + ManInTheMiddle manInTheMiddle = monitorConfig.getManInTheMiddle(); + + // Get list of redirects + Iterator iterator = manInTheMiddle.getRedirectList().iterator(); + + // Process each redirect + Redirect redirect; + while (iterator.hasNext()) + { + // Get next redirect + redirect = (Redirect) iterator.next(); + + // Create server socket socket listener + listenerList.add(new ServerSocketListener(this, redirect)); + } + + // Add shutdown hook + Runtime.getRuntime().addShutdownHook(new ShutdownHook()); + + // Create and start console + Console console = new Console(); + console.start(); + } + + /** + * Get the monitor config file. + * @return the monitor config file. + */ + public MonitorConfig getMonitorConfig() + { + return monitorConfig; + } + + /** + * Get the log object. + * @return the log object. + */ + public Log getLog() + { + return this.log; + } + + /** + * Get the log entry queue object. + * @return the log entry queue object. + */ + public MessageEntryQueue getMessageEntryQueue() + { + return this.messageEntryQueue; + } + + /** + * Terminate the monitor. + */ + void exitMonitor() + { + printMessage("stopping01", "Stopping the monitor..."); + System.exit(0); + } + + /** + * Stop the monitor because an exception occurred. + */ + void exitMonitor(Exception e) + { + // Display error message + printMessage( + "stopping02", + "Stopping monitor because an exception occurred."); + System.err.println("EXCEPTION: " + e.toString()); + if (this.monitorConfig.getVerboseOption()) + e.printStackTrace(); + + // Exit monitor + exitMonitor(); + } + + /** + * Stop the monitor. + */ + void stopMonitor() + { + try + { + // Get list of listeners to stop + Iterator iterator = listenerList.iterator(); + + while (iterator.hasNext()) + { + ((ServerSocketListener) iterator.next()).shutdown(); + } + + // Wait for the cleanup timeout seconds + Thread.sleep(monitorConfig.getTimeout() * 1000); + + // Write end of log file + if (logWriter != null) + { + logWriter.write(new StringReader(log.getEndXMLString(""))); + + logWriter.close(); + } + } + + catch (Exception e) + { + // ADD: How should this execption be handled? + } + + printMessage("stopped01", "Monitor stopped."); + } + + /** + * Command line interface. + * @param args command line arguments. + */ + public static void main(String[] args) + { + Monitor monitor = null; + + try + { + String configFileName; + if (args.length < 2) + { + staticPrintMessage("usage01", USAGE_MESSAGE); + System.exit(1); + } + + if (!args[0].equalsIgnoreCase("-config")) + { + staticPrintMessage("usage01", USAGE_MESSAGE); + System.exit(1); + } + + // Run the monitor + monitor = new Monitor(args); + } + + catch (Exception e) + { + boolean printStackTrace = true; + String messageID; + String defaultMessage; + String messageData; + + if ((e instanceof WSIFileNotFoundException) + || (e instanceof IllegalArgumentException)) + { + printStackTrace = false; + messageID = "error01"; + defaultMessage = "Monitor Error:"; + messageData = e.getMessage(); + } + + else + { + printStackTrace = true; + messageID = "error02"; + defaultMessage = "Monitor Stopped By Exception:"; + messageData = e.toString(); + } + + if (monitor != null) + monitor.printMessage(messageID, messageData, defaultMessage); + else + Monitor.staticPrintMessage(messageID, messageData, defaultMessage); + + if (printStackTrace) + e.printStackTrace(); + + // Exit + if (monitor != null) + monitor.exitMonitor(); + else + System.exit(2); + } + } + + /** + * Print a message from the resource bundle. + * @param key a key. + * @param defaultMessage a default message. + */ + public void printMessage(String key, String defaultMessage) + { + printMessage(key, null, defaultMessage); + } + + /** + * Print a message from the resource bundle. + * @param key a key. + * @param messageData message data. + * @param defaultMessage a default message. + */ + public void printMessage( + String key, + String messageData, + String defaultMessage) + { + messageList.printMessage(key, messageData, defaultMessage); + } + + /** + * Print message. + * @param key a key. + * @param defaultMessage a default message. + */ + public static void staticPrintMessage(String key, String defaultMessage) + { + staticPrintMessage(key, null, defaultMessage); + } + + /** + * Print message. + * @param key a key. + * @param messageData message data. + * @param defaultMessage a default message. + + */ + public static void staticPrintMessage( + String key, + String messageData, + String defaultMessage) + { + MessageList.printMessage( + RESOURCE_BUNDLE_NAME, + key, + messageData, + defaultMessage); + } + + /** + * Get the next conversation identifier. + * @return the next conversation identifier. + */ + synchronized int getNextConversationId() + { + return conversationId++; + } + + /** + * Return XML string representation of this object. + * @param namespaceName namespace prefix. + * @return XML string representation of this object. + */ + public String toXMLString(String namespaceName) + { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + + // Start + pw.print(toolInfo.getStartXMLString(namespaceName)); + + // Config + pw.print( + monitorConfig.toXMLString(WSIConstants.NS_NAME_WSI_MONITOR_CONFIG)); + + // End + pw.println(toolInfo.getEndXMLString(namespaceName)); + + return sw.toString(); + } + + /** + * Shutdown hook. + */ + class ShutdownHook extends Thread + { + /** + * Run shutdown procedure. + */ + public void run() + { + stopMonitor(); + } + } + + /** + * Run command from console. + */ + class Console extends Thread + { + /** + * Prompt user and wait for input. + */ + public void run() + { + String line = null; + + // Get the exit string + String exitString = messageList.getMessage("exit01", "exit"); + + // Display options and how to stop application + TestUtils.printToolInfo(toolInfo); + System.out.print(monitorConfig.toString()); + System.out.println(" "); + printMessage( + "start01", + "The " + + toolInfo.getName() + + " tool is ready to intercept and log web service messages."); + printMessage( + "start02", + "Type \"exit\" to stop the " + toolInfo.getName() + "."); + System.out.println(" "); + + // Get the time to stop accepting connections + long stopTime = + System.currentTimeMillis() + (monitorConfig.getLogDuration() * 1000); + // SS + + try + { + // Get stdin as a buffered reader + BufferedReader reader = + new BufferedReader(new InputStreamReader(System.in)); + + // Process input from console + boolean exit = false; + while ((!exit) && (System.currentTimeMillis() < stopTime)) + { // SS + // Sleep + Thread.sleep(500); + + // Check for user input + if (reader.ready()) + { + if (reader.readLine().equalsIgnoreCase(exitString)) + exit = true; + } + } + } + + catch (Exception e) + { + // ADD: How should this be handled? + System.err.println(e.toString()); + } + + // Exit + exitMonitor(); + } + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/Monitor.properties b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/Monitor.properties new file mode 100644 index 000000000..d4d606cb5 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/Monitor.properties @@ -0,0 +1,38 @@ +# /******************************************************************************* +# * Copyright (c) 2002-2005 IBM Corporation and others. +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * IBM - Initial API and implementation +# *******************************************************************************/ + +# +# Monitor message resource bundle. +# +usage01=Usage: Monitor -config +stopped01=Monitor stopped. +error01=Monitor Error: +error02=Monitor Stopped By Exception: +error03=Could not create log or log writer. +error04=Monitor cannot connect to a redirect host: +stopping01=Stopping the monitor... +stopping02=Stopping monitor because an exception occurred. +log01=Log message entry [ID, Type, Sender]: +start01=The Monitor tool is ready to intercept and log web service messages. +start02=Type "exit" to stop the Monitor. +exit01=exit +config01=The specified option is not supported: +config02=Monitor configuration file was not found. Specified file location: +config03=Could not read monitor configuration file. Specified file location: +config04=Element must contain an integer value. Element name: +config05=Monitor configuration file did not contain any redirect statements. +config06=Monitor configuration file did not contain the log file URI. +config07=Could not get log file location. +config08=Log file already exists. Specified file location: +config09=Element is missing. Element name: +config10=Parameter value can't be negative. Element name: +config11=The log file location value cannot contain the pass separator character: + diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/ServerSocketListener.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/ServerSocketListener.java new file mode 100644 index 000000000..ae3ee4e47 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/ServerSocketListener.java @@ -0,0 +1,140 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.monitor; + +import org.eclipse.wst.wsi.internal.monitor.config.Redirect; + +import java.net.ServerSocket; +import java.net.Socket; +import java.util.Iterator; +import java.util.Vector; + +/** + * A server socket listener. + * + * @author Peter Brittenham (peterbr@us.ibm.com) + * @version 1.0.1 + */ +public class ServerSocketListener + extends Thread + implements ConnectionListener // SS +{ + protected Monitor monitor = null; + protected Redirect redirect = null; + + protected ServerSocket serverSocket = null; + protected boolean stopServerSocket = false; + + protected Vector connectionList = new Vector(); + + /** + * Create server socket listener. + * @param monitor a Monitor object. + * @param redirect a Redirect object. + */ + public ServerSocketListener(Monitor monitor, Redirect redirect) + { + this.monitor = monitor; + this.redirect = redirect; + + // Start listening + start(); + } + + /** + * Run the thread and listen for a connection on the socket. + */ + public void run() + { + try + { + // Create server socket + serverSocket = + new ServerSocket( + redirect.getListenPort(), + redirect.getMaxConnections()); + // SS + + // Set timeout so that server socket will continue to accept connections + serverSocket.setSoTimeout(0); + + // Listen for connections until interrupted + while (!stopServerSocket) + { + // Accept connections + Socket socket = serverSocket.accept(); + + // If the server socket was NOT stopped, process connection + if (!stopServerSocket) + { + // Create new connection + SocketConnection socketConnection = + new SocketConnection(this.monitor, this.redirect, socket); + + //register as a listener + socketConnection.addConnectionListener(this); // SS + + // Add to connection list + connectionList.add(socketConnection); + } + } + } + + catch (Exception e) + { + // If the exception was NOT caused by closing the socket, then stop monitor + if (!e.getMessage().equals("socket closed")) + { + monitor.exitMonitor(e); + } + } + } + + /** + * Stop listening for a connection on the socket. + */ + public void shutdown() + { + try + { + // Shutdown all active connections + Iterator iterator = connectionList.iterator(); + while (iterator.hasNext()) + { + ((SocketConnection) iterator.next()).shutdown(); + } + + // Tell the server socket listening thread to stop + this.stopServerSocket = true; + + // Set the server socket timeout to 1 ms + serverSocket.setSoTimeout(1); + + // Close the server socket + if (serverSocket != null) + serverSocket.close(); + } + + catch (Exception e) + { + } + } + + // ==== SS start ==== + /* (non-Javadoc) + * @see org.wsi.test.monitor.ConnectionListener#connectionClosed() + */ + public void connectionClosed(SocketConnection connection) + { + connectionList.remove(connection); + } + // ==== SS end ==== +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/SocketConnection.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/SocketConnection.java new file mode 100644 index 000000000..378a26c59 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/SocketConnection.java @@ -0,0 +1,305 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.monitor; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.log.MessageEntry; +import org.eclipse.wst.wsi.internal.log.MimeParts; +import org.eclipse.wst.wsi.internal.util.Utils; +import org.eclipse.wst.wsi.internal.monitor.config.Redirect; + +import java.net.Socket; +import java.util.*; // SS + +/** + * A socket connection. + * + * @author Peter Brittenham (peterbr@us.ibm.com) + * @version 1.0.1 + */ +public class SocketConnection extends Thread +{ + protected Monitor monitor; + protected Redirect redirect; + protected Socket inSocket; + protected Socket outSocket; + + protected String httpProxyHost = null; + protected int httpProxyPort; + + protected SocketHandler requestSocketHandler = null; + protected SocketHandler responseSocketHandler = null; + + private Vector listeners = new Vector(); // SS + + /** + * Create socket connection. + * @param monitor a Monitor object. + * @param redirect a Redirect object. + * @param inSocket in socket. + */ + public SocketConnection(Monitor monitor, Redirect redirect, Socket inSocket) + { + this.monitor = monitor; + this.redirect = redirect; + this.inSocket = inSocket; + + // Start processing the connection + start(); + } + + /** + * Process the socket connection. + */ + public void run() + { + // Get the HTTP proxy settings if there are any set (not used currently) + loadHttpProxySettings(); + + try + { + // Open the connection to the server + this.outSocket = new Socket(redirect.getToHost(), redirect.getToPort()); + + // Set the read timeout for the input socket + this.inSocket.setSoTimeout(redirect.getReadTimeoutSeconds() * 1000); + + // Get the next conversation ID + int conversationId = monitor.getNextConversationId(); + + // Create the socket handlers which are used to send the data from + // the client to the server + requestSocketHandler = + new SocketHandler( + this, + MessageEntry.TYPE_REQUEST, + conversationId, + redirect.getToHost(), + this.inSocket, + this.outSocket, + redirect.getReadTimeoutSeconds()); + responseSocketHandler = + new SocketHandler( + this, + MessageEntry.TYPE_RESPONSE, + conversationId, + redirect.getToHost(), + this.outSocket, + this.inSocket, + redirect.getReadTimeoutSeconds()); + + // Tell each socketHandler about the other one + requestSocketHandler.setPairedSocketHandler(responseSocketHandler); + responseSocketHandler.setPairedSocketHandler(requestSocketHandler); + } + + catch (Exception e) + { + Monitor.staticPrintMessage( + "error04", + redirect.getToHost(), + "Monitor cannot connect to a redirect host:"); + + shutdown(); + + try + { + this.inSocket.close(); + } + catch (Throwable t) + { + } + } + } + + /** + * Log message. + * @param conversationID the coversation id. + * @param connectionType the connection type. + * @param timestamp the timestamp. + * @param senderHostAndPort the sender host and port. + * @param receiverHostAndPort the receiver host and port. + * @param messageBuffer the message. + * @param bom the BOM. + * @param encoding the encoding. + * @throws WSIException if there is a problem logging message. + */ + public void logMessage( + int conversationID, + String connectionType, + String timestamp, + String senderHostAndPort, + String receiverHostAndPort, + StringBuffer messageBuffer, + int bom, + String encoding) + throws WSIException + { + MessageEntry messageEntry = null; + + // Create message entry + messageEntry = + createMessageEntry( + conversationID, + connectionType, + timestamp, + senderHostAndPort, + receiverHostAndPort, + messageBuffer.toString(), + bom, + encoding); + + // DEBUG: + //debug("logMessage", " messageEntry: " + messageEntry); + + // Add entry to the queue + monitor.getMessageEntryQueue().addMessageEntry(messageEntry); + } + + /** + * Create a log entry from all of the data that was gathered. + */ + private MessageEntry createMessageEntry( + int conversationID, + String messageType, + String timestamp, + String senderHostAndPort, + String receiverHostAndPort, + String message, + int bom, + String encoding) + throws WSIException + { + // Create log entry object + MessageEntry messageEntry = monitor.getLog().createLogEntry(); + + // Set input information in log entry + // NOTE: The ID is set just before the log entry is written to the log file in LogEntryQueue + //logEntry.setId(id); + messageEntry.setConversationId(String.valueOf(conversationID)); + messageEntry.setType(messageType); + messageEntry.setTimestamp(timestamp); + messageEntry.setSenderHostAndPort(senderHostAndPort); + messageEntry.setReceiverHostAndPort(receiverHostAndPort); + messageEntry.setEncoding(encoding); + + // Get HTTP headers from full message + String httpHeaders = Utils.getHTTPHeaders(message); + messageEntry.setHTTPHeaders(httpHeaders); + + if (Utils.isMultipartRelatedMessage(httpHeaders)) + { + MimeParts mimeParts = Utils.parseMultipartRelatedMessage(message, httpHeaders, encoding); + if (mimeParts == null) + { + // problem creating Mimeparts -- treat it as simple SOAP message + String content = Utils.getContent(message); + messageEntry.setMessage(content); + messageEntry.setMimeContent(false); + } + else + { + messageEntry.setMimeParts(mimeParts); + messageEntry.setMimeContent(true); + } + } + else + { + // Get the message content + String content = Utils.getContent(message); + messageEntry.setMessage(content); + messageEntry.setMimeContent(false); + } + + // Set the BOM, if there is one + if (bom != 0) + messageEntry.setBOM(bom); + + return messageEntry; + } + + /** + * Load HTTP proxy settings. + */ + public void loadHttpProxySettings() + { + // Get the HTTP proxy host setting + this.httpProxyHost = System.getProperty("http.proxyHost"); + if (this.httpProxyHost != null && httpProxyHost.equals("")) + this.httpProxyHost = null; + + // If there was an HTTP proxy host setting, then get the port + if (this.httpProxyHost != null) + { + String portString = System.getProperty("http.proxyPort"); + + // Set default to 80 + if (portString == null || portString.equals("")) + this.httpProxyPort = 80; + else + httpProxyPort = Integer.parseInt(portString); + } + } + + Monitor getMonitor() + { + return this.monitor; + } + + synchronized void wakeUp() + { + fireConnectionClosed(); // SS + notifyAll(); + } + + /** + * Shutdown. + */ + public void shutdown() + { + if (this.requestSocketHandler != null) + this.requestSocketHandler.shutdown(); + if (this.responseSocketHandler != null) + this.responseSocketHandler.shutdown(); + } + + // ==== SS start ==== + /** + * Add connection event listener. + * @param listener event listener. + * @see #removeConnectionListener + */ + public void addConnectionListener(ConnectionListener listener) + { + listeners.add(listener); + } + /** + * Remove connection event listener. + * @param listener event listener. + * @see #addConnectionListener + */ + public void removeConnectionListener(ConnectionListener listener) + { + listeners.remove(listener); + } + /** + * Notify listeners on connection close. + */ + private void fireConnectionClosed() + { + for (Iterator i = listeners.iterator(); i.hasNext();) + { + ConnectionListener listener = (ConnectionListener) i.next(); + listener.connectionClosed(this); + } + } + // ==== SS end ==== +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/SocketHandler.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/SocketHandler.java new file mode 100644 index 000000000..6d4797da0 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/SocketHandler.java @@ -0,0 +1,966 @@ +/******************************************************************************* + * Copyright (c) 2002-2003 IBM Corporation, Beacon Information Technology Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + * BeaconIT - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.monitor; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.log.MessageEntry; +import org.eclipse.wst.wsi.internal.util.Utils; + +import java.net.Socket; + +import java.io.InputStream; +import java.io.InterruptedIOException; +import java.io.IOException; +import java.io.OutputStream; +import java.io.UnsupportedEncodingException; + +/** + * Socket Handler. + * + * @author Peter Brittenham (peterbr@us.ibm.com) + * @version 1.0.1 + */ +public class SocketHandler extends Thread +{ + protected SocketConnection socketConnection; + protected SocketHandler pairedSocketHandler; + protected String connectionType; + protected int conversationID; + protected String targetHost; + protected int readTimeoutSeconds; + + protected Socket inSocket; + protected Socket outSocket; + protected InputStream inputStream = null; + protected OutputStream outputStream = null; + + protected boolean verbose = false; + + protected boolean readTimedOut = false; + + // I18N: 2003.02.26 modified by K.Nakagome@BeaconIT + private String mimeCharset = null; + private String xmlEncoding = null; + + protected static final String CRLF = "\r\n"; + + protected static final String HTTP_100_CONTINUE = + "100 Continue".toUpperCase(); + protected static final String CHUNKED = + "Transfer-Encoding: chunked".toUpperCase(); + protected static final String CHUNKED_WITH_QUOTES = + "Transfer-Encoding: \"chunked\"".toUpperCase(); + protected static final String CONTENT_LENGTH = + "Content-Length:".toUpperCase(); + + /** + * Create socket handler. + * @param socketConnection socket connection. + * @param connectionType connection type. + * @param conversationID conversation id. + * @param targetHost target host. + * @param inSocket in socket. + * @param outSocket out socket. + * @param readTimeoutSeconds read timeout seconds. + */ + public SocketHandler( + SocketConnection socketConnection, + String connectionType, + int conversationID, + String targetHost, + Socket inSocket, + Socket outSocket, + int readTimeoutSeconds) + { + this.socketConnection = socketConnection; + this.connectionType = connectionType; + this.conversationID = conversationID; + this.targetHost = targetHost; + this.inSocket = inSocket; + this.outSocket = outSocket; + this.readTimeoutSeconds = readTimeoutSeconds; + + // ADD: + verbose = + socketConnection.getMonitor().getMonitorConfig().getVerboseOption(); + + start(); + } + + /** + * Set paired socket handler. + * @param pairedSocketHandler paired socket handler. + */ + public void setPairedSocketHandler(SocketHandler pairedSocketHandler) + { + this.pairedSocketHandler = pairedSocketHandler; + } + + /** + * Send the data from the input socket to the output socket. + */ + public void run() + { + int readLen; + String readMsg; + MessageContext messageContext = null; + + // Create read buffer + byte[] readBuffer = new byte[4096]; + + try + { + // Get the input and output streams + this.inputStream = this.inSocket.getInputStream(); + this.outputStream = this.outSocket.getOutputStream(); + + // Process while the connection is active + // (NOTE: there might be more than 1 message per connection) + boolean connectionActive = true; + while (connectionActive) + { + // Reset all data + readLen = 0; + messageContext = new MessageContext(); + + // Read until message is complete + boolean messageComplete = false; + while (!messageComplete) + { + try + { + // DEBUG: + debug("run", "Read data from the input stream."); + + // Read data from the input stream + readLen = inputStream.read(readBuffer, 0, readBuffer.length); + + // Reset read timeout flag + readTimedOut = false; + + // DEBUG: + debug("run", "readLen: " + readLen); + + if (readLen == -1) + { + connectionActive = false; + messageComplete = true; + } + + // If data was read, then check for 100 continue + else if (readLen > 0) + { + // If this is the first data that was read, then get the timestamp + if (messageContext.timestamp == null) + messageContext.timestamp = Utils.getTimestamp(); + + if (connectionType.equals(MessageEntry.TYPE_REQUEST)) + { + byte[] toHost = + new String( + socketConnection.redirect.getToHost() + + ":" + + socketConnection.redirect.getToPort()) + .getBytes(); + + String message = new String(readBuffer, 0, readLen); + + int index = message.indexOf(CRLF + "Host: "); + if (index > -1) + { + index += 8; + int secondPart = message.indexOf(CRLF, index); + + // Write the data to the output stream and then go format it + write(this.outputStream, readBuffer, 0, index); + write(this.outputStream, toHost, 0, toHost.length); + write( + this.outputStream, + readBuffer, + secondPart, + readLen - secondPart); + } + else + { + // Write the data to the output stream and then go format it + write(this.outputStream, readBuffer, 0, readLen); + } + } + else + { + // Write the data to the output stream and then go format it + write(this.outputStream, readBuffer, 0, readLen); + } + + // DEBUG: + if (verbose) + { + String bufferString = new String(readBuffer, 0, readLen); + debug("run", "buffer as string: [" + bufferString + "]"); + if (bufferString.length() <= 50) + debug( + "run", + "buffer as hexstring: [" + + Utils.toHexString(bufferString) + + "]"); + else + debug( + "run", + "buffer as hexstring: [" + + Utils.toHexString(bufferString.substring(0, 50)) + + " ...]"); + } + + // See if this part of the buffer contains the BOM + if (messageContext.bom == 0) + { + messageContext.bom = getBOM(readBuffer); + } + + // DEBUG + debug("run", "bom: " + messageContext.bom); + + String encoding; + + try + { + encoding = getEncoding(); + readMsg = + new String( + readBuffer, + 0, + readLen, + Utils.getJavaEncoding(encoding)); + setEncoding(readMsg); + if (!encoding.equals(getEncoding())) + { + encoding = getEncoding(); + readMsg = + new String( + readBuffer, + 0, + readLen, + Utils.getJavaEncoding(encoding)); + } + } + + catch (UnsupportedEncodingException uee) + { + debug("run", "EXCEPTION (3): " + uee.toString()); + throw new RuntimeException(uee.toString()); + } + + // Set encoding in the message context + messageContext.encoding = encoding; + + // DEBUG + debug("run", "encoding: " + messageContext.encoding); + + // Process message + messageContext = processMessage(readLen, readMsg, messageContext); + } + + // If message is complete, then log it and reset buffer + if ((isMessageComplete(messageContext)) + || ((readLen == -1) && (messageContext.messageBuffer.length() > 0))) + { + // Log message + logMessage(messageContext); + + // Set message complete + messageComplete = true; + } + } + + catch (InterruptedIOException ie) + { + // Set read timeout flag + readTimedOut = true; + + debug("run", "InterruptedIOException: " + ie.toString()); + + // If the read is not done, then shutdown + if (pairedSocketHandler != null + && pairedSocketHandler.isReadWaiting() + && pairedSocketHandler.isReadTimedOut()) + { + // DEBUG: + debug("run", "read timed out on both sockets"); + + // If there is data in the message buffer and it is complete, then log it + if ((isMessageComplete(messageContext)) + || (messageContext.messageBuffer.length() > 0)) + { + // Log message + logMessage(messageContext); + } + + // Set message complete + connectionActive = false; + messageComplete = true; + } + } + + catch (Exception e2) + { + // DEBUG: + debug( + "run", + "EXCEPTION (2): " + + e2.toString() + + "\n" + + Utils.getExceptionDetails(e2)); + //e2.printStackTrace(); + + // If there is data in the message buffer and it is complete, then log it + if ((isMessageComplete(messageContext)) + || (messageContext.messageBuffer.length() > 0)) + { + // Log message + logMessage(messageContext); + } + + // Set message complete + connectionActive = false; + messageComplete = true; + } + } + } + } + + catch (Exception e) + { + // DEBUG: + debug( + "run", + "EXCEPTION (1): " + + e.getMessage() + + "\n" + + Utils.getExceptionDetails(e)); + //e.printStackTrace(); + } + + catch (Error err) + { + // DEBUG: + debug("run", "ERROR: " + err.getMessage()); + //err.printStackTrace(); + } + + finally + { + shutdown(); + socketConnection.wakeUp(); + } + } + + /** + * Process the message. + */ + private MessageContext processMessage( + int readLen, + String readMsg, + MessageContext inMessageContext) + throws WSIException + { + boolean continueRead = false; + + // Initialize message context + MessageContext messageContext = inMessageContext; + + // Get message buffer and chunked data from message context + StringBuffer messageBuffer = messageContext.messageBuffer; + ChunkedData chunkedData = messageContext.chunkedData; + + // If all we received was the header with 100 continue, then ignore it + if ((readMsg.toUpperCase().indexOf(HTTP_100_CONTINUE) != -1) + && (readLen >= 25)) + { + // DEBUG: + debug("processMessage", "Ignore HTTP 100 Continue."); + + // Find the end of the HTTP 100 message + int index = Utils.getFirstCRLFCRLF(readMsg); + + // If there is only the HTTP 100 message, then just ignore it + if (index == readMsg.length()) + continueRead = true; + + // Otherwise remove the HTTP 100 message and continue + else + readMsg = readMsg.substring(index); + } + + // ADD: What if a bypassed message contains another message after it? + if (!continueRead && bypassMessage(readMsg)) + { + // DEBUG: + debug( + "processMessage", + "Do not log message as defined in the monitor spec, but it will be sent."); + + continueRead = true; + } + + if (!continueRead) + { + int index = 0; + + // If there is chunked data, then get the length + if ((readMsg.toUpperCase().indexOf(CHUNKED) != -1) + || (readMsg.toUpperCase().indexOf(CHUNKED_WITH_QUOTES) != -1)) + { + // DEBUG: + debug("processMessage", "Processing chunked data..."); + + // Get the location of the first CFLF + if ((index = readMsg.indexOf(CRLF + CRLF)) == -1) + { + throw new WSIException("Could not locate end of HTTP header."); + } + + // Include the CRLF+CRLF in the index + index += 4; + + // DEBUG: + debug( + "processMessage", + "Add header before decoding chunked data: [" + + readMsg.substring(0, index) + + "]"); + + // Add HTTP header to buffer + messageBuffer.append(readMsg.substring(0, index)); + + // If there is no more data (i.e. header only), then just indicate that there is more chunked data + if (readMsg.length() == index) + { + chunkedData = new ChunkedData(this, true); + + // DEBUG: + debug( + "processMessage", + "There is chunk data, but none in this part of the message."); + } + + // Determine if the remainder of the data is complete (i.e. ends with [0][CRLF][Optional Footer][CRLF]) + else + { + // Create chunked data object + chunkedData = new ChunkedData(this, readMsg.substring(index)); + + if (!chunkedData.isMoreChunkedData()) + { + chunkedData.decodeAndAddDataToBuffer(messageBuffer); + } + } + } + + else if (chunkedData != null && chunkedData.isMoreChunkedData()) + { + // DEBUG: + debug("processMessage", "Processing MORE chunked data..."); + + // Add data + chunkedData.addData(readMsg); + + // Decode data + if (!chunkedData.isMoreChunkedData()) + { + chunkedData.decodeAndAddDataToBuffer(messageBuffer); + } + } + + // Else just append the data to the buffer + else + { + // DEBUG: + debug( + "processMessage", + "Add data to message entry buffer: [" + readMsg + "]"); + + messageBuffer.append(readMsg); + } + } + + // Set updated message buffer and chunked data in message context + messageContext.messageBuffer = messageBuffer; + messageContext.chunkedData = chunkedData; + + // Return message context + return messageContext; + } + + /** + * Shutdown input socket and close input stream. + * @param inSocket in socket. + * @param inputStream input stream. + */ + protected void stopInput(Socket inSocket, InputStream inputStream) + { + try + { + // If there is a input socket, then shutdown the input + if (inSocket != null) + { + inSocket.shutdownInput(); + } + + // If there is an input stream then close it + if (inputStream != null) + { + inputStream.close(); + } + } + catch (Exception e) + { + // Ignore since we are stopping everything + } + + inputStream = null; + } + + /** + * Shutdown output socket and close output stream. + * @param outSocket out socket. + * @param outputStream output stream. + */ + protected void stopOutput(Socket outSocket, OutputStream outputStream) + { + try + { + // If there is an output stream, then flush it + if (outputStream != null) + { + outputStream.flush(); + } + + // If there is a input socket, then shutdown the input + if (outSocket != null) + { + outSocket.shutdownOutput(); + } + + // If there is an output stream then close it + if (outputStream != null) + { + outputStream.close(); + } + } + + catch (Exception e) + { + // Ignore since we are stopping everything + } + + outputStream = null; + } + + /** + * Shutdown handler. + */ + public void shutdown() + { + // Stop both the input and output + stopInput(this.inSocket, this.inputStream); + stopOutput(this.outSocket, this.outputStream); + } + + /** + * Display debug messages. + */ + void debug(String method, String message) + { + debug("SocketHandler", method, message); + } + + /** + * Display debug messages. + */ + void debug(String className, String method, String message) + { + if (verbose) + print(className, method, message); + } + + /** + * Display messages. + */ + void print(String className, String method, String message) + { + System.out.println( + "[" + + Thread.currentThread().getName() + + "] [" + + className + + "." + + method + + "] [" + + this.connectionType + + "] " + + message); + } + + /** + * Write data. + */ + private void write( + OutputStream outputStream, + byte[] buffer, + int start, + int length) + throws IOException + { + if (outputStream == null) + { + // DEBUG: + debug("write", "Could not write buffer because output stream is null."); + } + else + { + // DEBUG: + debug("write", "buffer: [" + new String(buffer, start, length) + "]"); + + outputStream.write(buffer, start, length); + } + } + + /** + * Check if message is complete. + * + * @param messageContext + */ + private boolean isMessageComplete(MessageContext messageContext) + throws WSIException + { + int index, index2, contentLen; + boolean messageComplete = false; + + boolean moreChunkedData = messageContext.chunkedData.isMoreChunkedData(); + + String message = messageContext.messageBuffer.toString(); + + // Find the first CRLF + CRLF which marks the end of the HTTP header + String httpHeader; + index = Utils.getFirstCRLFCRLF(message); + if (index == -1) + httpHeader = message; + else + httpHeader = message.substring(0, index); + + // If chunked data, then complete only if there is no more data + if (((httpHeader.toUpperCase().indexOf(CHUNKED) != -1) + || (httpHeader.toUpperCase().indexOf(CHUNKED_WITH_QUOTES) != -1)) + && (!moreChunkedData)) + { + debug( + "isMessageComplete", + "HTTP header indicates chunked data and there is no more chunked data"); + messageComplete = true; + } + + // Check for content length + else if ((index = httpHeader.toUpperCase().indexOf(CONTENT_LENGTH)) == -1) + { + debug("isMessageComplete", "HTTP header does not contain content length"); + + // Should not have complete POST header without content length + if (httpHeader.startsWith("POST")) + { + if (httpHeader.endsWith(CRLF + CRLF)) + { + throw new WSIException("Could not locate content-length in HTTP POST header."); + } + + messageComplete = false; + } + + // This could be a GET, so see if the the complete header has been received + else if ( + httpHeader.startsWith("GET") + && (message.length() == httpHeader.length() + && message.endsWith(CRLF + CRLF))) + { + messageComplete = true; + } + + else + { + messageComplete = false; + } + } + + // If there is content length, then see if the entire message has been received + else if ((index = httpHeader.toUpperCase().indexOf(CONTENT_LENGTH)) != -1) + { + // Find end of content length value + index2 = httpHeader.indexOf(CRLF, index); + + debug("isMessageComplete", "CRLF: " + Utils.toHexString(CRLF)); + debug( + "isMessageComplete", + "httpHeader/index: " + Utils.toHexString(httpHeader.substring(index))); + + // Get content length + contentLen = + Integer + .decode( + httpHeader.substring(index + CONTENT_LENGTH.length() + 1, index2)) + .intValue(); + + // DEBUG: + debug("isMessageComplete", "contentLen: " + contentLen); + + // Find the first CRLF + CRLF which marks the end of the HTTP header + index = Utils.getFirstCRLFCRLF(message); + + // DEBUG: + debug( + "isMessageComplete", + "actual received message length: " + (message.length() - (index))); + + // If content length is equal to actual message content length, then message is complete + if (contentLen == message.length() - index) + { + messageComplete = true; + + // DEBUG: + debug( + "isMessageComplete", + "contentLen = actual received message length."); + } + } + + // Message is not complete + else + { + messageComplete = false; + } + + // DEBUG: + debug("isMessageComplete", "messageComplete: " + messageComplete); + + return messageComplete; + } + + /** + * Log message. + * + * @param messageBuffer + */ + private void logMessage(MessageContext messageContext) throws WSIException + { + MessageEntry messageEntry = null; + + // Determine sender and receiver host/port + String senderHostAndPort, receiverHostAndPort; + + // Request + if (connectionType.equals(MessageEntry.TYPE_REQUEST)) + { + senderHostAndPort = + inSocket.getInetAddress().getHostAddress() + ":" + inSocket.getPort(); + receiverHostAndPort = targetHost + ":" + outSocket.getPort(); + } + + // Response + else + { + senderHostAndPort = targetHost + ":" + inSocket.getPort(); + receiverHostAndPort = + outSocket.getInetAddress().getHostAddress() + ":" + outSocket.getPort(); + } + + // Create message entry + this.socketConnection.logMessage( + conversationID, + this.connectionType, + messageContext.timestamp, + senderHostAndPort, + receiverHostAndPort, + messageContext.messageBuffer, + messageContext.bom, + messageContext.encoding); + } + + /** + * Check for HTTP messages that should not be logged. + */ + private boolean bypassMessage(String message) + { + boolean bypass = false; + if ((message.startsWith("CONNECT")) + || (message.startsWith("TRACE")) + || (message.startsWith("DELETE")) + || (message.startsWith("OPTIONS")) + || (message.startsWith("HEAD"))) + { + bypass = true; + } + + return bypass; + } + + // I18N: 2003.02.26 modified by K.Nakagome@BeaconIT + /** + * Set Encoding Parameters + * @param messageFragment String of a HTTP message fragment. + * @author K.Nakagome@BeaconIT Japan SIG + */ + private void setEncoding(String messageFragment) + { + if (mimeCharset == null || mimeCharset.length() == 0) + { + mimeCharset = Utils.getHTTPCharset(messageFragment); + } + if (xmlEncoding == null || xmlEncoding.length() == 0) + { + xmlEncoding = Utils.getXMLEncoding(messageFragment); + } + return; + } + + // I18N: 2003.02.26 modified by K.Nakagome@BeaconIT + /** + * Get Encoding Parameter + * @return Character encoding of HTTP message. + * @author K.Nakagome@BeaconIT Japan SIG + */ + private String getEncoding() + { + String encoding = WSIConstants.DEFAULT_XML_ENCODING; + if (mimeCharset != null && mimeCharset.length() > 0) + { + encoding = mimeCharset; + } + if (xmlEncoding != null && xmlEncoding.length() > 0) + { + encoding = xmlEncoding; + } + return encoding; + } + + /** + * Get the Byte Order Mark from the message (if there is one). + */ + private int getBOM(byte[] message) + { + int bom = 0; + + byte FF = (byte) 0xFF; + byte FE = (byte) 0xFE; + byte EF = (byte) 0xEF; + byte BB = (byte) 0xBB; + byte BF = (byte) 0xBF; + + // Search through the byte array for CRLF+CRLF. This will mark the end of the header. + int i = Utils.getFirstCRLFCRLF(message, 0); + if (i != -1) + { + // DEBUG: + debug( + "getBOM", + "message[i]: " + + message[i] + + ", message[i+1]: " + + message[i+1]); + + // Check for UTF-8 BOM + if (((i + 2) < message.length) + && message[i] == EF + && message[i+1] == BB + && message[i+2] == BF) + { + bom = 0xEFBBBF; + } + // Check for UTF-16 big-endian BOM + else if ( + ((i+1) < message.length) + && message[i] == FE + && message[i + 1] == FF) + { + bom = 0xFEFF; + } + // Check for UTF-16 little-endian BOM + else if ( + ((i+1) < message.length) + && message[i] == FF + && message[i+1] == FE) + { + bom = 0xFFFE; + } + // ADD: Do we need to check for other BOMs + } + return bom; + } + + /** + * Determine if the read is still waiting for data. + */ + boolean isReadWaiting() + { + boolean readWaiting = false; + + try + { + // DEBUG: + debug( + "isReadWaiting", + "inSocket.getInputStream().available(): " + + inSocket.getInputStream().available()); + + if (inSocket.getInputStream().available() == 0) + { + readWaiting = true; + } + } + + catch (IOException ioe) + { + } + + return readWaiting; + } + + /** + * Get read timed out flag. + */ + boolean isReadTimedOut() + { + return this.readTimedOut; + } + + /** + * Message context contains information about the message that is being processed. + */ + class MessageContext + { + StringBuffer messageBuffer; + ChunkedData chunkedData; + String timestamp; + int bom; + String encoding; + + /** + * Create new message context. + */ + MessageContext() + { + messageBuffer = new StringBuffer(); + chunkedData = new ChunkedData(); + timestamp = null; + bom = 0; + encoding = WSIConstants.DEFAULT_XML_ENCODING; + } + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/config/Comment.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/config/Comment.java new file mode 100644 index 000000000..f4017a0b7 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/config/Comment.java @@ -0,0 +1,50 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.monitor.config; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.document.DocumentElement; + +import javax.xml.namespace.QName; + +/** + * The interface for monitor config Comment element. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public interface Comment extends DocumentElement +{ + /** + * Element name. + */ + public static final String ELEM_NAME = WSIConstants.ELEM_COMMENT; + + /** + * QName. + */ + public static final QName QNAME = + new QName(WSIConstants.NS_URI_WSI_MONITOR_CONFIG, ELEM_NAME); + + /** + * Get comment text. + * @return comment text. + * @see #setText + */ + public String getText(); + + /** + * Set comment text. + * @param text the comment text. + * @see #getText + */ + public void setText(String text); +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/config/ManInTheMiddle.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/config/ManInTheMiddle.java new file mode 100644 index 000000000..a07227b54 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/config/ManInTheMiddle.java @@ -0,0 +1,72 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.monitor.config; + +import java.util.Vector; + +import javax.xml.namespace.QName; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.document.DocumentElement; + +/** + * The interface for the monitor config ManInTheMiddle element. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public interface ManInTheMiddle extends DocumentElement +{ + /** + * Element name. + */ + public static final String ELEM_NAME = WSIConstants.ELEM_MAN_IN_THE_MIDDLE; + + /** + * QName. + */ + public static final QName QNAME = + new QName(WSIConstants.NS_URI_WSI_MONITOR_CONFIG, ELEM_NAME); + + /** + * Get comment. + * @return comment. + * @see #setComment + */ + public Comment getComment(); + + /** + * Set comment. + * @param comment the Comment object. + * @see #getComment + */ + public void setComment(Comment comment); + + /** + * Get redirects. + * @return the redirirects. + * @see #setRedirectList + */ + public Vector getRedirectList(); + + /** + * Add redirect. + * @param redirect the Redirect object. + */ + public void addRedirect(Redirect redirect); + + /** + * Set redirects. + * @param redirectList a list of the redirects. + * @see #getRedirectList + */ + public void setRedirectList(Vector redirectList); +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/config/MonitorConfig.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/config/MonitorConfig.java new file mode 100644 index 000000000..dfa5d019e --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/config/MonitorConfig.java @@ -0,0 +1,165 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.monitor.config; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.common.AddStyleSheet; +import org.eclipse.wst.wsi.internal.document.WSIDocument; +import org.eclipse.wst.wsi.internal.util.MessageList; + +import javax.xml.namespace.QName; + +/** + * This is the interface for the monitor configuration file. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public interface MonitorConfig extends WSIDocument +{ + /** + * Element name. + */ + public static final String ELEM_NAME = WSIConstants.ELEM_CONFIG; + + /** + * QName. + */ + public static final QName QNAME = + new QName(WSIConstants.NS_URI_WSI_MONITOR_CONFIG, ELEM_NAME); + + /** + * Initialize monitor config. + * @param messageList a lMessageList object. + */ + public void init(MessageList messageList); + + /** + * Get comment. + * @return comment. + * @see #setComment + */ + public Comment getComment(); + + /** + * Set comment. + * @param comment a Comment object. + * @see #getComment + */ + public void setComment(Comment comment); + + /** + * Get log file location. + * @return log file location. + * @see #setLogLocation + */ + public String getLogLocation(); + + /** + * Set log file location. + * @param logURI log file location. + * @see #getLogLocation + */ + public void setLogLocation(String logURI); + + /** + * Get replace log. + * @return replace log. + * @see #setReplaceLog + */ + public boolean getReplaceLog(); + + /** + * Set replace log. + * @param replaceLog a replace log. + * @see #getReplaceLog + */ + public void setReplaceLog(boolean replaceLog); + + /** + * Get add style sheet. + * @return add style sheet. + * @see #setAddStyleSheet + */ + public AddStyleSheet getAddStyleSheet(); + + /** + * Set add style sheet. + * @param addStyleSheet add style sheet. + * @see #getAddStyleSheet + */ + public void setAddStyleSheet(AddStyleSheet addStyleSheet); + + /** + * Get log duration. + * @return log duration. + * @see #setLogDuration + */ + public int getLogDuration(); + + /** + * Set log duration. + * @param logDuration log duration. + * @see #getLogDuration + */ + public void setLogDuration(int logDuration); + + /** + * Get timeout. + * @return timeout. + * @see #setTimeout + */ + public int getTimeout(); + + /** + * Set timeout. + * @param timeout timeout. + * @see #getTimeout + */ + public void setTimeout(int timeout); + + /** + * Get man-in-the-middle information. + * @return man-in-the-middle information. + * @see #setManInTheMiddle + */ + public ManInTheMiddle getManInTheMiddle(); + + /** + * Set man-in-the-middle information. + * @param manInTheMiddle man-in-the-middle information. + * @see #getManInTheMiddle + */ + public void setManInTheMiddle(ManInTheMiddle manInTheMiddle); + + /** + * Get verbose option. + * @return verbose option. + * @see #setVerboseOption + */ + public boolean getVerboseOption(); + + /** + * Set verbose option. + * @param verbose verbose option. + * @see #getVerboseOption + */ + public void setVerboseOption(boolean verbose); + + /** + * Parse the command line arguments. + * @param args the command line arguments. + * @throws WSIException if problems occur while parsing the + * command line arguments, + */ + public void parseArgs(String[] args) throws WSIException; +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/config/MonitorConfigReader.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/config/MonitorConfigReader.java new file mode 100644 index 000000000..faf241006 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/config/MonitorConfigReader.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.monitor.config; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.document.DocumentReader; +import org.eclipse.wst.wsi.internal.util.MessageList; + +import java.io.Reader; + +/** + * Defines the interface used to read the monitor config documents. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public interface MonitorConfigReader extends DocumentReader +{ + /** + * Initialize monitor config. + * @param messageList a MessageList object. + */ + public void init(MessageList messageList); + + /** + * Read the monitor config file. + * @param monitorConfigURI the monitor config file location. + * @return a MonitorConfig object + * @throws WSIException if problems occur while reading monitor config file. + */ + public MonitorConfig readMonitorConfig(String monitorConfigURI) + throws WSIException; + + /** + * Read the monitor config file. + * @param reader a Reader object. + * @return a MonitorConfig object + * @throws WSIException if problems occur while reading monitor config file. + */ + public MonitorConfig readMonitorConfig(Reader reader) throws WSIException; +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/config/Redirect.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/config/Redirect.java new file mode 100644 index 000000000..68062477a --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/config/Redirect.java @@ -0,0 +1,124 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.monitor.config; + +import javax.xml.namespace.QName; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.document.DocumentElement; + +/** + * The interface for monitor config Redirect element. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public interface Redirect extends DocumentElement +{ + /** + * Element name. + */ + public static final String ELEM_NAME = WSIConstants.ELEM_REDIRECT; + + /** + * QName. + */ + public static final QName QNAME = + new QName(WSIConstants.NS_URI_WSI_MONITOR_CONFIG, ELEM_NAME); + + /** + * Get comment. + * @return comment. + * @see #setComment + */ + public Comment getComment(); + + /** + * Set comment. + * @param comment a Commentobject. + * @see #getComment + */ + public void setComment(Comment comment); + + /** + * Get listen port. + * @return listen port. + * @see #setListenPort + */ + public int getListenPort(); + + /** + * Set listen port. + * @param listenPort listen port. + * @see #getListenPort + */ + public void setListenPort(int listenPort); + + /** + * Get host. + * @return host. + * @see #setHost + */ + public String getHost(); + + /** + * Set host. + * @param host host. + * @see #getHost + */ + public void setHost(String host); + + /** + * Get send to port. + * @return send to port. + */ + public int getToPort(); + + /** + * Get send to host. + * @return send to host. + */ + public String getToHost(); + + /** + * Get send to protocol. + * @return send to protocol. + */ + public String getToProtocol(); + + /** + * Get maximum connections. + * @return maximum connections. + * @see #setMaxConnections + */ + public int getMaxConnections(); + + /** + * Set maximum connections. + * @param maxConnections maximum connections. + * @see #getMaxConnections + */ + public void setMaxConnections(int maxConnections); + + /** + * Get read timeout seconds. + * @return read timeout seconds. + * @see #setReadTimeoutSeconds + */ + public int getReadTimeoutSeconds(); + + /** + * Set read timeout seconds. + * @param readTimeoutSeconds read timeout seconds. + * @see #getReadTimeoutSeconds + */ + public void setReadTimeoutSeconds(int readTimeoutSeconds); +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/config/impl/CommentImpl.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/config/impl/CommentImpl.java new file mode 100644 index 000000000..bae549e09 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/config/impl/CommentImpl.java @@ -0,0 +1,75 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.monitor.config.impl; + +import java.io.PrintWriter; +import java.io.StringWriter; + +import org.eclipse.wst.wsi.internal.monitor.config.Comment; + +/** + * The implementation for monitor config Comment element. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public class CommentImpl implements Comment +{ + /** + * Comment text. + */ + protected String text = null; + + /* (non-Javadoc) + * @see org.wsi.test.monitor.config.Comment#getText() + */ + public String getText() + { + return this.text; + } + + /* (non-Javadoc) + * @see org.wsi.test.monitor.config.Comment#setText(String) + */ + public void setText(String text) + { + this.text = text; + } + + /* (non-Javadoc) + * @see org.wsi.test.document.DocumentElement#toXMLString(String) + */ + public String toXMLString(String namespaceName) + { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + + String nsName = namespaceName; + if ((!nsName.equals("") && (!nsName.endsWith(":")))) + nsName += ":"; + + // Config options + //pw.print(" <" + nsName + ELEM_NAME + " xmlns=\"" + WSIConstants.NS_URI_WSI_MONITOR_CONFIG + "\">"); + pw.print(" <" + nsName + ELEM_NAME + ">"); + pw.print(this.text); + + // End element + pw.println(""); + + return sw.toString(); + } + + public String toString() + { + return text; + } + +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/config/impl/ManInTheMiddleImpl.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/config/impl/ManInTheMiddleImpl.java new file mode 100644 index 000000000..0a06f8152 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/config/impl/ManInTheMiddleImpl.java @@ -0,0 +1,142 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.monitor.config.impl; + +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.Iterator; +import java.util.Vector; + +import org.eclipse.wst.wsi.internal.monitor.config.Comment; +import org.eclipse.wst.wsi.internal.monitor.config.ManInTheMiddle; +import org.eclipse.wst.wsi.internal.monitor.config.Redirect; + +/** + * The implementation for the monitor config ManInTheMiddle element. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public class ManInTheMiddleImpl implements ManInTheMiddle +{ + /** + * Comment. + */ + protected Comment comment; + + /** + * Redirect list. + */ + protected Vector redirectList = new Vector(); + + /* (non-Javadoc) + * @see org.wsi.test.monitor.config.ManInTheMiddle#getComment() + */ + public Comment getComment() + { + return this.comment; + } + + /* (non-Javadoc) + * @see org.wsi.test.monitor.config.ManInTheMiddle#setComment(Comment) + */ + public void setComment(Comment comment) + { + this.comment = comment; + } + + /* (non-Javadoc) + * @see org.wsi.test.monitor.config.ManInTheMiddle#getRedirectList() + */ + public Vector getRedirectList() + { + return redirectList; + } + + /* (non-Javadoc) + * @see org.wsi.test.monitor.config.ManInTheMiddle#addRedirect(Redirect) + */ + public void addRedirect(Redirect redirect) + { + redirectList.add(redirect); + } + + /* (non-Javadoc) + * @see org.wsi.test.monitor.config.ManInTheMiddle#setRedirectList(Vector) + */ + public void setRedirectList(Vector redirectList) + { + this.redirectList = redirectList; + } + + /* (non-Javadoc) + * Get string representation of this object. + */ + public String toString() + { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + + pw.println(" man-in-the-middle comment ... " + this.comment); + + // Redirect list + int count = 1; + Redirect redirect; + Iterator iterator = redirectList.iterator(); + while (iterator.hasNext()) + { + // Get next redirect element + redirect = (Redirect) iterator.next(); + pw.println(" redirect [" + count++ +"]"); + pw.print(redirect.toString()); + } + + return sw.toString(); + } + + /* (non-Javadoc) + * @see org.wsi.test.document.DocumentElement#toXMLString(String) + */ + public String toXMLString(String namespaceName) + { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + + String nsName = namespaceName; + if ((!nsName.equals("") && (!nsName.endsWith(":")))) + nsName += ":"; + + // Start element + pw.println(" <" + nsName + ELEM_NAME + ">"); + + // Comment + if (this.comment != null) + { + pw.println(this.comment.toXMLString(nsName)); + } + + // Redirect + Redirect redirect; + Iterator iterator = redirectList.iterator(); + while (iterator.hasNext()) + { + // Get next redirect element + redirect = (Redirect) iterator.next(); + pw.print(redirect.toXMLString(nsName)); + } + + // End element + pw.println(" "); + + return sw.toString(); + } + +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/config/impl/MonitorConfigImpl.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/config/impl/MonitorConfigImpl.java new file mode 100644 index 000000000..533f294d6 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/config/impl/MonitorConfigImpl.java @@ -0,0 +1,556 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.monitor.config.impl; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.common.AddStyleSheet; +import org.eclipse.wst.wsi.internal.common.impl.AddStyleSheetImpl; +import org.eclipse.wst.wsi.internal.util.MessageList; +import org.eclipse.wst.wsi.internal.monitor.Monitor; +import org.eclipse.wst.wsi.internal.monitor.config.*; + +import java.io.*; + +/** + * This is the implementation for the monitor configuration file. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public class MonitorConfigImpl implements MonitorConfig +{ + /** + * Message list reference. + */ + protected MessageList messageList = null; + + /** + * Monitor configuration file URI. + */ + protected String documentURI = null; + + /** + * Comment. + */ + protected Comment comment = null; + + /** + * Log location. + */ + protected String logURI; + + /** + * Replace log indicator. + */ + protected boolean replaceLog = false; + + /** + * Style sheet declaration. + */ + protected AddStyleSheet addStyleSheet; + + /** + * Log duration. + */ + protected int logDuration = 600; + + /** + * Timeout. + */ + protected int timeout = 3; + + /** + * Man-in-the-middle settings. + */ + protected ManInTheMiddle manInTheMiddle = null; + + /** + * Verbose option. + */ + protected boolean verbose = false; + + /** + * Initialize monitor config. + */ + public void init(MessageList messageList) + { + this.messageList = messageList; + } + + /* (non-Javadoc) + * @see org.wsi.test.monitor.config.MonitorConfig#getComment() + */ + public Comment getComment() + { + return this.comment; + } + + /* (non-Javadoc) + * @see org.wsi.test.monitor.config.MonitorConfig#setComment(Comment) + */ + public void setComment(Comment comment) + { + this.comment = comment; + } + + /* (non-Javadoc) + * @see org.wsi.test.monitor.config.MonitorConfig#getLogLocation() + */ + public String getLogLocation() + { + return this.logURI; + } + + /* (non-Javadoc) + * @see org.wsi.test.monitor.config.MonitorConfig#setLogLocation(String) + */ + public void setLogLocation(String logURI) + { + this.logURI = logURI; + } + + /* (non-Javadoc) + * @see org.wsi.test.monitor.config.MonitorConfig#getReplaceLog() + */ + public boolean getReplaceLog() + { + return this.replaceLog; + } + + /* (non-Javadoc) + * @see org.wsi.test.monitor.config.MonitorConfig#setReplaceLog(boolean) + */ + public void setReplaceLog(boolean replaceLog) + { + this.replaceLog = replaceLog; + } + + /* (non-Javadoc) + * @see org.wsi.test.monitor.config.MonitorConfig#getAddStyleSheet() + */ + public AddStyleSheet getAddStyleSheet() + { + return this.addStyleSheet; + } + + /* (non-Javadoc) + * @see org.wsi.test.monitor.config.MonitorConfig#setAddStyleSheet(org.wsi.test.common.AddStyleSheet) + */ + public void setAddStyleSheet(AddStyleSheet addStyleSheet) + { + this.addStyleSheet = addStyleSheet; + } + + /* (non-Javadoc) + * @see org.wsi.test.monitor.config.MonitorConfig#getLogDuration() + */ + public int getLogDuration() + { + return logDuration; + } + + /* (non-Javadoc) + * @see org.wsi.test.monitor.config.MonitorConfig#setLogDuration(int) + */ + public void setLogDuration(int logDuration) + { + this.logDuration = logDuration; + } + + /* (non-Javadoc) + * @see org.wsi.test.monitor.config.MonitorConfig#getTimeout() + */ + public int getTimeout() + { + return this.timeout; + } + + /* (non-Javadoc) + * @see org.wsi.test.monitor.config.MonitorConfig#setTimeout(int) + */ + public void setTimeout(int timeout) + { + this.timeout = timeout; + } + + /* (non-Javadoc) + * @see org.wsi.test.monitor.config.MonitorConfig#getManInTheMiddle() + */ + public ManInTheMiddle getManInTheMiddle() + { + return manInTheMiddle; + } + + /* (non-Javadoc) + * @see org.wsi.test.monitor.config.MonitorConfig#setManInTheMiddle(ManInTheMiddle) + */ + public void setManInTheMiddle(ManInTheMiddle manInTheMiddle) + { + this.manInTheMiddle = manInTheMiddle; + } + + /* (non-Javadoc) + * @see org.wsi.test.document.WSIDocument#getLocation() + */ + public String getLocation() + { + return this.documentURI; + } + + /* (non-Javadoc) + * @see org.wsi.test.document.WSIDocument#setLocation(String) + */ + public void setLocation(String documentURI) + { + this.documentURI = documentURI; + } + + /* (non-Javadoc) + * @see org.wsi.test.monitor.config.MonitorConfig#getVerboseOption() + */ + public boolean getVerboseOption() + { + return this.verbose; + } + + /* (non-Javadoc) + * @see org.wsi.test.monitor.config.MonitorConfig#setVerboseOption(boolean) + */ + public void setVerboseOption(boolean verbose) + { + this.verbose = verbose; + } + + /* (non-Javadoc) + * @see org.wsi.test.document.DocumentElement#toXMLString(String) + */ + public String toXMLString(String namespaceName) + { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + + String nsName = namespaceName; + if ((!nsName.equals("") && (!nsName.endsWith(":")))) + nsName += ":"; + + // Config options + pw.println(" <" + nsName + ELEM_NAME + ">"); + + // Comment + if (this.comment != null) + { + pw.print(comment.toXMLString(nsName)); + } + + // Log file + pw.print(" <" + nsName + WSIConstants.ELEM_LOG_FILE + " "); + pw.print(WSIConstants.ATTR_REPLACE + "=\"" + this.replaceLog + "\" "); + pw.println(WSIConstants.ATTR_LOCATION + "=\"" + this.logURI + "\">"); + pw.print(getAddStyleSheet().toXMLString(namespaceName)); + pw.println(" "); + + // Log duration + pw.print(" <" + nsName + WSIConstants.ELEM_LOG_DURATION + ">"); + pw.print(this.logDuration); + pw.println(""); + + // Timeout + pw.print( + " <" + nsName + WSIConstants.ELEM_CLEANUP_TIMEOUT_SECONDS + ">"); + pw.print(this.timeout); + pw.println(""); + + // Man-in-the-middle + if (this.manInTheMiddle != null) + { + pw.print(manInTheMiddle.toXMLString(nsName)); + } + + // End element + pw.println(" "); + + return sw.toString(); + } + + /** + * Get string representation of this object. + */ + public String toString() + { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + + pw.println(" comment ..................... " + this.comment); + pw.println(" logURI ...................... " + this.logURI); + pw.println(" replaceLog .................. " + this.replaceLog); + pw.println(" logDuration ................. " + this.logDuration); + pw.println(" timeout ..................... " + this.timeout); + + // addStyleSheet + if (this.addStyleSheet != null) + pw.println( + " addStyleSheet ............... " + this.addStyleSheet.toString()); + + // Man-in-the-middle + if (this.manInTheMiddle != null) + { + pw.print(this.manInTheMiddle.toString()); + } + + return sw.toString(); + } + + /** + * Set config values from another monitor config object. + */ + private void setConfig(MonitorConfig monitorConfig) + { + // ADD: Should this be a clone operation? + this.comment = monitorConfig.getComment(); + this.documentURI = monitorConfig.getLocation(); + this.logURI = monitorConfig.getLogLocation(); + this.replaceLog = monitorConfig.getReplaceLog(); + this.logDuration = monitorConfig.getLogDuration(); + this.timeout = monitorConfig.getTimeout(); + this.manInTheMiddle = monitorConfig.getManInTheMiddle(); + this.addStyleSheet = monitorConfig.getAddStyleSheet(); + this.verbose = monitorConfig.getVerboseOption(); + } + + /** + * Verify config options. + */ + private void verifyConfig() throws WSIException + { + // If no redirect statements, then exit + if ((this.manInTheMiddle == null) + || (this.manInTheMiddle.getRedirectList() == null) + || (this.manInTheMiddle.getRedirectList().size() == 0)) + { + throw new IllegalArgumentException( + getMessage( + "config05", + "Monitor config file did not contain any redirect statements.")); + } + + if (this.logURI == null) + { + throw new IllegalArgumentException( + getMessage( + "config06", + "Monitor config file did not contain the log file URI.")); + } + } + + /** + * Parse the command line arguments. + */ + public void parseArgs(String[] args) throws WSIException + { + // Get new config reader + MonitorConfigReader monitorConfigReader = new MonitorConfigReaderImpl(); + + // Monitor config object which will be merged after all of the input parms are processed + MonitorConfig monitorConfigFromArgs = null; + + // If no input arguments, then throw exception + if (args.length == 0) + { + // ADD: + throw new IllegalArgumentException( + getMessage("usage01", Monitor.USAGE_MESSAGE)); + } + + // Parse the command line arguments to locate the config file option (if it was specified) + for (int argCount = 0; argCount < args.length; argCount++) + { + // -configFile + if ((args[argCount].equalsIgnoreCase("-config")) + || (args[argCount].equals("-c"))) + { + argCount++; + monitorConfigFromArgs = + monitorConfigReader.readMonitorConfig(args[argCount]); + } + } + + // If config file was not specified, then create analyzer config object + if (monitorConfigFromArgs == null) + { + monitorConfigFromArgs = new MonitorConfigImpl(); + monitorConfigFromArgs.init(this.messageList); + } + + // Parse all of the command line arguments + for (int argCount = 0; argCount < args.length; argCount++) + { + // -configFile + if ((args[argCount].equalsIgnoreCase("-config")) + || (args[argCount].equals("-c"))) + { + // Skip this option since it was already processed + argCount++; + } + + // -comment + else if ( + (args[argCount].equalsIgnoreCase("-comment")) + || (args[argCount].equals("-C"))) + { + argCount++; + Comment comment = new CommentImpl(); + comment.setText(args[argCount]); + monitorConfigFromArgs.setComment(comment); + } + + // -logFile + else if ( + (args[argCount].equalsIgnoreCase("-logFile")) + || (args[argCount].equals("-l"))) + { + argCount++; + monitorConfigFromArgs.setLogLocation(args[argCount]); + } + + // -replace + else if ( + (args[argCount].equalsIgnoreCase("-replace")) + || (args[argCount].equals("-r"))) + { + argCount++; + monitorConfigFromArgs.setReplaceLog( + Boolean.valueOf(args[argCount]).booleanValue()); + } + + // -logDuration + else if ( + (args[argCount].equalsIgnoreCase("-logDuration")) + || (args[argCount].equals("-d"))) + { + argCount++; + monitorConfigFromArgs.setLogDuration( + Integer.valueOf(args[argCount]).intValue()); + } + + // -timeout + else if ( + (args[argCount].equalsIgnoreCase("-timeout")) + || (args[argCount].equals("-t"))) + { + argCount++; + monitorConfigFromArgs.setTimeout( + Integer.valueOf(args[argCount]).intValue()); + } + + // -manInTheMiddle + else if ( + (args[argCount].equalsIgnoreCase("-manInTheMiddle")) + || (args[argCount].equals("-m"))) + { + ManInTheMiddle manInTheMiddle = null; + + // Increment arg count + argCount++; + + // Get the man-in-the-middle object + if ((manInTheMiddle = monitorConfigFromArgs.getManInTheMiddle()) + == null) + manInTheMiddle = new ManInTheMiddleImpl(); + + // ADD: Check for correct number of remaining args + + // Create redirect + Redirect redirect = new RedirectImpl(); + + // Get the redirect values + redirect.setListenPort(Integer.valueOf(args[argCount++]).intValue()); + redirect.setHost(args[argCount++]); + redirect.setMaxConnections( + Integer.valueOf(args[argCount++]).intValue()); + redirect.setReadTimeoutSeconds( + Integer.valueOf(args[argCount++]).intValue()); + + // Add redirect + manInTheMiddle.addRedirect(redirect); + + // Set the man-in-the-middle + monitorConfigFromArgs.setManInTheMiddle(manInTheMiddle); + } + + // -verbose + else if ( + (args[argCount].equalsIgnoreCase("-verbose")) + || (args[argCount].equals("-v"))) + { + argCount++; + //monitorConfigFromArgs.setVerboseOption(Boolean.valueOf(args[argCount]).booleanValue()); + monitorConfigFromArgs.setVerboseOption(true); + } + + // -GUI + else if (args[argCount].equalsIgnoreCase("-GUI")) + { + // Ignore -GUI option + } + + else + { + throw new IllegalArgumentException( + getMessage( + "config01", + args[argCount], + "The specified option is not supported.")); + } + } + + // If addStyleSheet was not specified, then create a comment version of it + if (monitorConfigFromArgs.getAddStyleSheet() == null) + { + AddStyleSheet addStyleSheet = new AddStyleSheetImpl(); + addStyleSheet.setHref(WSIConstants.DEFAULT_LOG_XSL); + addStyleSheet.setType(WSIConstants.DEFAULT_XSL_TYPE); + addStyleSheet.setComment(true); + monitorConfigFromArgs.setAddStyleSheet(addStyleSheet); + } + + // Merge config info into this object + setConfig(monitorConfigFromArgs); + + // Verify config options + verifyConfig(); + } + + /** + * Get message from resource bundle. + */ + private String getMessage(String messageID, String defaultMessage) + { + return getMessage(messageID, null, defaultMessage); + } + + /** + * Get message from resource bundle. + */ + private String getMessage( + String messageID, + String messageData, + String defaultMessage) + { + String message = defaultMessage; + if (messageList != null) + message = messageList.getMessage(messageID, messageData, defaultMessage); + else + message += " " + messageData + "."; + + return message; + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/config/impl/MonitorConfigReaderImpl.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/config/impl/MonitorConfigReaderImpl.java new file mode 100644 index 000000000..0a882dedd --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/config/impl/MonitorConfigReaderImpl.java @@ -0,0 +1,474 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.monitor.config.impl; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.WSIFileNotFoundException; +import org.eclipse.wst.wsi.internal.common.AddStyleSheet; +import org.eclipse.wst.wsi.internal.common.impl.AddStyleSheetImpl; +import org.eclipse.wst.wsi.internal.util.MessageList; +import org.eclipse.wst.wsi.internal.util.TestUtils; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; +import org.eclipse.wst.wsi.internal.monitor.config.*; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +import java.io.*; + +/** + * Defines the implementation used to read the monitor config documents. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public class MonitorConfigReaderImpl implements MonitorConfigReader +{ + /** + * Message list reference. + */ + protected MessageList messageList = null; + + /** + * Document location. + */ + protected String documentURI; + + /** + * Initialize monitor config. + */ + public void init(MessageList messageList) + { + this.messageList = messageList; + } + + /* (non-Javadoc) + * @see org.wsi.test.monitor.config.MonitorConfigReader#readMonitorConfig(String) + */ + public MonitorConfig readMonitorConfig(String monitorConfigURI) + throws WSIException + { + FileReader fileReader = null; + + try + { + fileReader = new FileReader(monitorConfigURI); + } + + catch (FileNotFoundException fnfe) + { + throw new WSIFileNotFoundException( + getMessage("config02", monitorConfigURI, "Could not find file:"), + fnfe); + } + + catch (Exception e) + { + throw new WSIException( + getMessage("config03", monitorConfigURI, "Could not read file:"), + e); + } + + return readMonitorConfig(fileReader); + } + + /* (non-Javadoc) + * @see org.wsi.test.monitor.config.MonitorConfigReader#readMonitorConfig(Reader) + */ + public MonitorConfig readMonitorConfig(Reader reader) throws WSIException + { + MonitorConfig monitorConfig = new MonitorConfigImpl(); + + // Parse XML + Document doc = XMLUtils.parseXML(reader); + + // Parse elements in the config document + parseConfigElement(monitorConfig, doc.getDocumentElement()); + + return monitorConfig; + } + + /* (non-Javadoc) + * @see org.wsi.test.document.DocumentReader#getLocation() + */ + public String getLocation() + { + return this.documentURI; + } + + /* (non-Javadoc) + * @see org.wsi.test.document.DocumentReader#setLocation(String) + */ + public void setLocation(String documentURI) + { + this.documentURI = documentURI; + } + + /** + * Parse config element. + */ + private void parseConfigElement(MonitorConfig monitorConfig, Element element) + throws WSIException + { + // ADD: Verify that this is the config element + + // Get first child element + Element nextElement = XMLUtils.getFirstChild(element); + + boolean isLogDurationDefine = false; + boolean isCleanupTimeoutSecondsDefine = false; + + // Process each child element + while (nextElement != null) + { + // + if (isElement(nextElement, WSIConstants.ELEM_LOG_FILE)) + { + // Parse the log element + parseLogFileElement(monitorConfig, nextElement); + } + + // + else if (isElement(nextElement, WSIConstants.ELEM_LOG_DURATION)) + { + monitorConfig.setLogDuration(getIntValue(nextElement)); + if (monitorConfig.getLogDuration() < 0) + throw new IllegalArgumentException( + getMessage( + "config09", + WSIConstants.ELEM_LOG_DURATION, + "Parameter value can't be negative. Element name:")); + isLogDurationDefine = true; + } + + // + else if ( + isElement(nextElement, WSIConstants.ELEM_CLEANUP_TIMEOUT_SECONDS)) + { + monitorConfig.setTimeout(getIntValue(nextElement)); + if (monitorConfig.getTimeout() < 0) + throw new IllegalArgumentException( + getMessage( + "config09", + WSIConstants.ELEM_CLEANUP_TIMEOUT_SECONDS, + "Parameter value can't be negative. Element name:")); + isCleanupTimeoutSecondsDefine = true; + } + + // + else if (isElement(nextElement, WSIConstants.ELEM_MAN_IN_THE_MIDDLE)) + { + ManInTheMiddle manInTheMiddle = new ManInTheMiddleImpl(); + monitorConfig.setManInTheMiddle(manInTheMiddle); + parseManInTheMiddleElement(manInTheMiddle, nextElement); + } + + // + else if (isElement(nextElement, WSIConstants.ELEM_COMMENT)) + { + Comment comment = new CommentImpl(); + comment.setText(XMLUtils.getText(nextElement)); + monitorConfig.setComment(comment); + } + + else + { + // ADD: handle invalid elements + } + + // Get next element + nextElement = XMLUtils.getNextSibling(nextElement); + } + + if (!isLogDurationDefine) + { + throw new IllegalArgumentException( + getMessage( + "config10", + WSIConstants.ELEM_LOG_DURATION, + "Element is missing. Element name:")); + } + if (!isCleanupTimeoutSecondsDefine) + { + throw new IllegalArgumentException( + getMessage( + "config10", + WSIConstants.ELEM_CLEANUP_TIMEOUT_SECONDS, + "Element is missing. Element name:")); + } + } + + /** + * Parse logFile element. + */ + private void parseLogFileElement( + MonitorConfig monitorConfig, + Element element) + throws WSIException + { + // Get the location attribute + monitorConfig.setLogLocation( + XMLUtils.getAttributeValue(element, WSIConstants.ATTR_LOCATION)); + + // Get the replace attribute + monitorConfig.setReplaceLog( + XMLUtils.getBooleanValue(element, WSIConstants.ATTR_REPLACE, false)); + + // Get first child element + Element nextElement = XMLUtils.getFirstChild(element); + + // Process each child element + while (nextElement != null) + { + // + if (isElement(nextElement, WSIConstants.ELEM_ADD_STYLE_SHEET)) + { + AddStyleSheet addStyleSheet = new AddStyleSheetImpl(); + + // Parse the element + TestUtils.parseAddStyleSheet( + nextElement, + addStyleSheet, + WSIConstants.DEFAULT_LOG_XSL); + + // Set add style sheet + monitorConfig.setAddStyleSheet(addStyleSheet); + } + + else + { + // ADD: handle invalid elements + } + + // Get next element + nextElement = XMLUtils.getNextSibling(nextElement); + } + } + + /** + * Parse manIntheMiddle element. + */ + private void parseManInTheMiddleElement( + ManInTheMiddle manInTheMiddle, + Element element) + throws WSIException + { + // Get first child element + Element nextElement = XMLUtils.getFirstChild(element); + + // Process each child element + while (nextElement != null) + { + // + if (isElement(nextElement, WSIConstants.ELEM_REDIRECT)) + { + Redirect redirect = new RedirectImpl(); + manInTheMiddle.addRedirect(redirect); + parseRedirectElement(redirect, nextElement); + } + + // + else if (isElement(nextElement, WSIConstants.ELEM_COMMENT)) + { + Comment comment = new CommentImpl(); + comment.setText(XMLUtils.getText(nextElement)); + manInTheMiddle.setComment(comment); + } + + else + { + // ADD: handle invalid elements + } + + // Get next element + nextElement = XMLUtils.getNextSibling(nextElement); + } + } + + /** + * Parse redirect element. + */ + private void parseRedirectElement(Redirect redirect, Element element) + throws WSIException + { + // Get first child element + Element nextElement = XMLUtils.getFirstChild(element); + + boolean isListenPortDefine = false; + boolean isSchemeAndHostPortDefine = false; + boolean isMaxConnectionsDefine = false; + boolean isReadTimeoutSecondsDefine = false; + + // Process each child element + while (nextElement != null) + { + // + if (isElement(nextElement, WSIConstants.ELEM_LISTEN_PORT)) + { + redirect.setListenPort(getIntValue(nextElement)); + isListenPortDefine = true; + } + + // + else if (isElement(nextElement, WSIConstants.ELEM_SCHEME_AND_HOSTPORT)) + { + redirect.setHost(XMLUtils.getText(nextElement)); + isSchemeAndHostPortDefine = true; + } + + // + else if (isElement(nextElement, WSIConstants.ELEM_MAX_CONNECTIONS)) + { + redirect.setMaxConnections(getIntValue(nextElement)); + isMaxConnectionsDefine = true; + } + + // + else if (isElement(nextElement, WSIConstants.ELEM_READ_TIMEOUT_SECONDS)) + { + redirect.setReadTimeoutSeconds(getIntValue(nextElement)); + if (redirect.getReadTimeoutSeconds() < 0) + { + throw new IllegalArgumentException( + getMessage( + "config09", + WSIConstants.ELEM_READ_TIMEOUT_SECONDS, + "Parameter value can't be negative. Element name:")); + } + isReadTimeoutSecondsDefine = true; + } + + // + else if (isElement(nextElement, WSIConstants.ELEM_COMMENT)) + { + Comment comment = new CommentImpl(); + comment.setText(XMLUtils.getText(nextElement)); + redirect.setComment(comment); + } + + else + { + // ADD: handle invalid elements + } + + // Get next element + nextElement = XMLUtils.getNextSibling(nextElement); + } + + if (!isListenPortDefine) + { + throw new IllegalArgumentException( + getMessage( + "config10", + WSIConstants.ELEM_LISTEN_PORT, + "Element is missing. Element name:")); + } + if (!isSchemeAndHostPortDefine) + { + throw new IllegalArgumentException( + getMessage( + "config10", + WSIConstants.ELEM_SCHEME_AND_HOSTPORT, + "Element is missing. Element name:")); + + } + if (!isMaxConnectionsDefine) + { + throw new IllegalArgumentException( + getMessage( + "config10", + WSIConstants.ELEM_MAX_CONNECTIONS, + "Element is missing. Element name:")); + } + if (!isReadTimeoutSecondsDefine) + { + throw new IllegalArgumentException( + getMessage( + "config10", + WSIConstants.ELEM_READ_TIMEOUT_SECONDS, + "Element is missing. Element name:")); + } + } + + /** + * Determine if this element matches specified local name in the analyzer config namespace. + */ + private boolean isElement(Element element, String localName) + { + return isElement( + element, + WSIConstants.NS_URI_WSI_MONITOR_CONFIG, + localName); + } + + /** + * Determine if this element matches specified local name in the analyzer config namespace. + */ + private boolean isElement( + Element element, + String namespace, + String localName) + { + return XMLUtils.isElement(element, namespace, localName); + } + + /** + * Get element text as an int. + */ + private int getIntValue(Element element) throws WSIException + { + int returnValue; + String intValue = null; + + // Get value as a string + if ((intValue = XMLUtils.getText(element)) == null) + { + throw new WSIException( + getMessage( + "config04", + element.getLocalName() + "Element must contain an integer value:")); + } + + else + { + returnValue = Integer.valueOf(intValue).intValue(); + } + + // Return int + return returnValue; + } + + /** + * Get message from resource bundle. + */ + private String getMessage(String messageID, String defaultMessage) + { + return getMessage(messageID, null, defaultMessage); + } + + /** + * Get message from resource bundle. + */ + private String getMessage( + String messageID, + String messageData, + String defaultMessage) + { + String message = defaultMessage; + if (messageList != null) + message = messageList.getMessage(messageID, messageData, defaultMessage); + else + message += " " + messageData + "."; + + return message; + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/config/impl/RedirectImpl.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/config/impl/RedirectImpl.java new file mode 100644 index 000000000..599d7eb51 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/monitor/config/impl/RedirectImpl.java @@ -0,0 +1,297 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.monitor.config.impl; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; +import org.eclipse.wst.wsi.internal.monitor.config.Comment; +import org.eclipse.wst.wsi.internal.monitor.config.Redirect; + +import java.io.*; +import java.net.*; + +/** + * The implementation for monitor config Redirect element. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public class RedirectImpl implements Redirect +{ + /** + * Comment. + */ + protected Comment comment; + + /** + * Listen port. + */ + protected int listenPort; + + /** + * Host. + */ + protected String host; + + /** + * To protocol. + */ + protected String toProtocol; + + /** + * To port. + */ + protected int toPort; + + /** + * To host. + */ + protected String toHost; + + /** + * Maximum connections. + */ + protected int maxConnections; + + /** + * Read timeout seconds. + */ + protected int readTimeoutSeconds; + + /* (non-Javadoc) + * @see org.wsi.test.monitor.config.Redirect#getComment() + */ + public Comment getComment() + { + return this.comment; + } + + /* (non-Javadoc) + * @see org.wsi.test.monitor.config.Redirect#setComment(comment) + */ + public void setComment(Comment comment) + { + this.comment = comment; + } + + /* (non-Javadoc) + * @see org.wsi.test.monitor.config.Redirect#getListenPort() + */ + public int getListenPort() + { + return this.listenPort; + } + + /* (non-Javadoc) + * @see org.wsi.test.monitor.config.Redirect#setListenPort(int) + */ + public void setListenPort(int listenPort) + { + this.listenPort = listenPort; + } + + /* (non-Javadoc) + * @see org.wsi.test.monitor.config.Redirect#getHost() + */ + public String getHost() + { + return this.host; + } + + /* (non-Javadoc) + * @see org.wsi.test.monitor.config.Redirect#setHost(String) + */ + public void setHost(String host) + { + this.host = host; + + // Parse location to get protocol, host and port + URL url; + try + { + url = new URL(host); + this.toProtocol = url.getProtocol(); + this.toHost = url.getHost(); + this.toPort = url.getPort(); + if (this.toPort == -1) + { + if (this.toProtocol.equalsIgnoreCase("http")) + this.toPort = 80; + else + this.toPort = 80; + } + } + + catch (MalformedURLException mue) + { + throw new IllegalArgumentException( + "The " + + WSIConstants.ELEM_SCHEME_AND_HOSTPORT + + " option contains an invalid value: " + + host); + } + + if ((url.getPath() != null && !url.getPath().equals("")) + || (url.getQuery() != null && !url.getQuery().equals(""))) + throw new IllegalArgumentException( + "The " + + WSIConstants.ELEM_SCHEME_AND_HOSTPORT + + " option must contain only a scheme, host and port: " + + host); + } + + /** + * Get to port. + * @see org.eclipse.wst.wsi.monitor.config.Redirect#getToPort() + */ + public int getToPort() + { + return this.toPort; + } + + /** + * Get to host. + * @see org.eclipse.wst.wsi.monitor.config.Redirect#getToHost() + */ + public String getToHost() + { + return this.toHost; + } + + /** + * Get to protocol. + * @see org.eclipse.wst.wsi.monitor.config.Redirect#getToProtocol() + */ + public String getToProtocol() + { + return this.toProtocol; + } + + /* (non-Javadoc) + * @see org.wsi.test.monitor.config.Redirect#getMaxConnections() + */ + public int getMaxConnections() + { + return this.maxConnections; + } + + /* (non-Javadoc) + * @see org.wsi.test.monitor.config.Redirect#setMaxConnections(int) + */ + public void setMaxConnections(int maxConnections) + { + this.maxConnections = maxConnections; + } + + /* (non-Javadoc) + * @see org.wsi.test.monitor.config.Redirect#getReadTimeoutSeconds() + */ + public int getReadTimeoutSeconds() + { + return this.readTimeoutSeconds; + } + + /* (non-Javadoc) + * @see org.wsi.test.monitor.config.Redirect#setReadTimeoutSeconds(int) + */ + public void setReadTimeoutSeconds(int readTimeoutSeconds) + { + this.readTimeoutSeconds = readTimeoutSeconds; + } + + /** + * Get string representation of this object. + */ + public String toString() + { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + + pw.println(" comment ................... " + this.comment); + pw.println(" listenPort ................ " + this.listenPort); + pw.println(" host ...................... " + cutHost(this.host)); + pw.println(" maxConnections ............ " + this.maxConnections); + pw.println(" readTimeoutSeconds ........ " + this.readTimeoutSeconds); + + return sw.toString(); + } + + /** + * Formats host name according to the specification (path is ommited). + * @param host + * @return + */ + private String cutHost(String host) + { + try + { + URL url = new URL(host); + String port = url.getPort() > -1 ? String.valueOf(url.getPort()) : "80"; + // REMOVED: This code only works on 1.4 + // String.valueOf(url.getDefaultPort()); + return url.getProtocol() + "://" + url.getHost() + ":" + port; + } + catch (Exception e) + { + return host; + } + } + + /* (non-Javadoc) + * @see org.wsi.test.document.DocumentElement#toXMLString(String) + */ + public String toXMLString(String namespaceName) + { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + + String nsName = namespaceName; + if ((!nsName.equals("") && (!nsName.endsWith(":")))) + nsName += ":"; + + // Start element + pw.println(" <" + nsName + WSIConstants.ELEM_REDIRECT + ">"); + + // Comment + if (this.comment != null) + { + pw.println(this.comment.toXMLString(nsName)); + } + + // listenPort + pw.print(" <" + nsName + WSIConstants.ELEM_LISTEN_PORT + ">"); + pw.print(getListenPort()); + pw.println(""); + + // schemeAndHostPort + pw.print( + " <" + nsName + WSIConstants.ELEM_SCHEME_AND_HOSTPORT + ">"); + pw.print(XMLUtils.xmlEscapedString(getHost())); + pw.println(""); + + // maxConnections + pw.print(" <" + nsName + WSIConstants.ELEM_MAX_CONNECTIONS + ">"); + pw.print(getMaxConnections()); + pw.println(""); + + // readTimeoutSeconds + pw.print( + " <" + nsName + WSIConstants.ELEM_READ_TIMEOUT_SECONDS + ">"); + pw.print(getReadTimeoutSeconds()); + pw.println(""); + + // End Element + pw.println(" "); + + return sw.toString(); + } + +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/EntryTypeList.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/EntryTypeList.java new file mode 100644 index 000000000..6f4dbebde --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/EntryTypeList.java @@ -0,0 +1,82 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile; + +import org.eclipse.wst.wsi.internal.document.DocumentElement; + +/** + * This interface is used to maintain a profile EntryTypeList. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public interface EntryTypeList extends DocumentElement +{ + /** + * Log input. + */ + public static final String LOG_INPUT_NONE = "none"; + public static final String LOG_INPUT_REQUEST = "request"; + public static final String LOG_INPUT_RESPONSE = "response"; + + /** + * WSDL input. + */ + public static final String WSDL_INPUT_NONE = "none"; + + /** + * UDDI input. + */ + public static final String UDDI_INPUT_NONE = "none"; + + /** + * Get log input. + * @return log input. + * @see #setLogInput + */ + public String getLogInput(); + + /** + * Set log input. + * @param logInput log input. + * @see #getLogInput + */ + public void setLogInput(String logInput); + + /** + * Get WSDL input. + * @return WSDL input. + * @see #setWSDLInput + */ + public String getWSDLInput(); + + /** + * Set WSDL input. + * @param wsdlInput WSDL input. + * @see #getWSDLInput + */ + public void setWSDLInput(String wsdlInput); + + /** + * Get UDDI input. + * @return UDDI input. + * @see #setUDDIInput + */ + public String getUDDIInput(); + + /** + * Set UDDI input. + * @param uddiInput UDDI input. + * @see #getUDDIInput + */ + public void setUDDIInput(String uddiInput); + +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/Profile.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/Profile.java new file mode 100644 index 000000000..d45fe59dd --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/Profile.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile; + +import org.eclipse.wst.wsi.internal.document.DocumentElement; + +/** + * This interface is used to maintain Profile information. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public interface Profile extends DocumentElement +{ + +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/ProfileArtifact.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/ProfileArtifact.java new file mode 100644 index 000000000..73c9bcb90 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/ProfileArtifact.java @@ -0,0 +1,86 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.document.DocumentElement; +import org.eclipse.wst.wsi.internal.util.ArtifactType; + +import javax.xml.namespace.QName; + +import java.util.*; + +/** + * An artifact contains a set of related test assertions. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public interface ProfileArtifact extends DocumentElement +{ + /** + * Element name. + */ + public static final String ELEM_NAME = WSIConstants.ELEM_ARTIFACT; + + /** + * QName. + */ + public static final QName QNAME = + new QName(WSIConstants.NS_URI_WSI_ASSERTIONS, ELEM_NAME); + + /** + * Get type. + * @return artifact type. + * @see #setType + */ + public ArtifactType getType(); + + /** + * Set type. + * @param type an artifact type. + * @see #getType + */ + public void setType(ArtifactType type); + + /** + * Get specification list. + * @return specification list. + * @see #setSpecificationList + */ + public Vector getSpecificationList(); + + /** + * Set specification list. + * @param specificationList specification list. + * @see #getSpecificationList + */ + public void setSpecificationList(Vector specificationList); + + /** + * Get test assertion list. + * @return test assertion list. + */ + public LinkedList getTestAssertionList(); + + /** + * Get test assertion. + * @param id test assertion id. + * @return test assertion. + */ + public TestAssertion getTestAssertion(String id); + + /** + * Add test assertion. + * @param testAssertion test assertion. + */ + public void addTestAssertion(TestAssertion testAssertion); +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/ProfileAssertions.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/ProfileAssertions.java new file mode 100644 index 000000000..e38b4be19 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/ProfileAssertions.java @@ -0,0 +1,123 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.document.WSIDocument; + +import javax.xml.namespace.QName; + +import java.util.TreeMap; +import java.util.Vector; + +/** + * This interface maintains profile assertions. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public interface ProfileAssertions extends WSIDocument +{ + /** + * Element name. + */ + public static final String ELEM_NAME = WSIConstants.ELEM_PROFILE_ASSERTIONS; + + /** + * QName. + */ + public static final QName QNAME = + new QName(WSIConstants.NS_URI_WSI_ASSERTIONS, ELEM_NAME); + + /** + * Get list of profiles. + * @return list of profiles. + * @see #setProfileList + */ + public Vector getProfileList(); + + /** + * Set list of profiles. + * @param profileList list of profiles. + * @see #getProfileList + */ + public void setProfileList(Vector profileList); + + /** + * Add profile. + * @param profile profile. + */ + public void addProfile(Profile profile); + + /** + * Get list of artifacts. + * @return list of artifacts. + * @see #setArtifactList + */ + public TreeMap getArtifactList(); + + /** + * Get artifact. + * @param type an artifact type. + * @return a profile artifact based on the given type. + */ + public ProfileArtifact getArtifact(String type); + + /** + * Set list of artifacts. + * @param artifactList a list pf profile artifiacts. + * @see #getArtifactList + */ + public void setArtifactList(TreeMap artifactList); + + /** + * Add artifact. + * @param artifact profile artifact. + */ + public void addArtifact(ProfileArtifact artifact); + + /** + * Get test assertion. + * @param id test assertion id. + * @return test assertion. + */ + public TestAssertion getTestAssertion(String id); + + /** + * Create artifact. + * @return newly created profile artifact. + */ + public ProfileArtifact createArtifact(); + + /** + * Returns the name of the profile test assertion document. + * @return the name of the document. + */ + public String getTADName(); + + /** + * Set the name of the profile test assertion document. + * @param documentName the name of the document. + */ + public void setTADName(String documentName); + + /** + * Returns the version of the profile test assertion document. + * @return the version of the document. + */ + public String getTADVersion(); + + /** + * Set the version of the profile test assertion document. + * @param documentVersion the version of the document. + */ + public void setTADVersion(String documentVersion); +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/ProfileAssertionsReader.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/ProfileAssertionsReader.java new file mode 100644 index 000000000..66f05f30b --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/ProfileAssertionsReader.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.document.DocumentReader; +import org.eclipse.wst.wsi.internal.profile.ProfileAssertions; + +import java.io.Reader; + +/** + * Defines the interface used to read a profile assertions documents. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public interface ProfileAssertionsReader extends DocumentReader +{ + /** + * Read the profile assertions file. + * @param assertionsURI he profile assertions file location. + * @return the ProfileAssertions object. + * @throws WSIException if problem occur while reading the file. + */ + public ProfileAssertions readProfileAssertions(String assertionsURI) + throws WSIException; + + /** + * Read the profile assertions file. + * @param reader a Reader object. + * @return the ProfileAssertions object. + * @throws WSIException if problem occur while reading the file. + */ + public ProfileAssertions readProfileAssertions(Reader reader) + throws WSIException; +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/TestAssertion.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/TestAssertion.java new file mode 100644 index 000000000..fed688ce1 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/TestAssertion.java @@ -0,0 +1,176 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile; + +import java.util.*; + +/** + * A test assertion is one assertion in a profile definition. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public interface TestAssertion +{ + public static final String TYPE_INFORMATIONAL = "informational"; + + /** + * Get test assertion id. + * @return test assertion id. + * @see #setId + */ + public String getId(); + + /** + * Set test assertion id. + * @param id test assertion id. + * @see #getId + */ + public void setId(String id); + + /** + * Get test assertion type. + * @return test assertion type. + * @see #setType + */ + public String getType(); + + /** + * Set test assertion type. + * @param type test assertion type. + * @see #getType + */ + public void setType(String type); + + /** + * Get test assertion primary entry type name. + * @return test assertion primary entry type name. + * @see #setEntryTypeName + */ + public String getEntryTypeName(); + + /** + * Set test assertion primary entry type name. + * @param entryTypeName test assertion primary entry type name. + * @see #getEntryTypeName + */ + public void setEntryTypeName(String entryTypeName); + + /** + * Get enabled indicator. + * @return enabled indicator. + * @see #setEnabled + */ + public boolean isEnabled(); + + /** + * Set enabled indicator. + * @param enabled enabled indicator. + * @see #isEnabled + */ + public void setEnabled(boolean enabled); + + /** + * Get context. + * @return context. + * @see #setContext + */ + public String getContext(); + + /** + * Set context. + * @param context context. + * @see #getContext + */ + public void setContext(String context); + + /** + * Get assertion description. + * @return assertion description. + * @see #setAssertionDescription + */ + public String getAssertionDescription(); + + /** + * Set assertion description. + * @param assertionDescription assertion description. + * @see #getAssertionDescription + */ + public void setAssertionDescription(String assertionDescription); + + /** + * Get failure message. + * @return failure message. + * @see #setFailureMessage + */ + public String getFailureMessage(); + + /** + * Set failure message. + * @param failureMessage failure message. + * @see #getFailureMessage + */ + public void setFailureMessage(String failureMessage); + + /** + * Get failure detail description. + * @return failure detail description. + * @see #setFailureDetailDescription + */ + public String getFailureDetailDescription(); + + /** + * Set failure detail description. + * @param failureDetailDescription failure detail description. + * @see #getFailureDetailDescription + */ + public void setFailureDetailDescription(String failureDetailDescription); + + /** + * Get detail description. + * @return detail description. + * @see #setDetailDescription + */ + public String getDetailDescription(); + + /** + * Set detail description. + * @param detailDescription detail description. + * @see #getDetailDescription + */ + public void setDetailDescription(String detailDescription); + + /** + * Get additional entry type list. + * @return additional entry type list. + * @see #setAdditionalEntryTypeList + */ + public EntryTypeList getAdditionalEntryTypeList(); + + /** + * Set additional entry type list. + * @param entryTypeList additional entry type list. + * @see #getAdditionalEntryTypeList + */ + public void setAdditionalEntryTypeList(EntryTypeList entryTypeList); + + /** + * Get list of prereq ids. + * @return list of prereq ids. + */ + public Vector getPrereqIdList(); + + /** + * Add prereq test assertion id. + * @param prereqId prereq test assertion id. + */ + public void addPrereqId(String prereqId); +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/impl/EntryTypeListImpl.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/impl/EntryTypeListImpl.java new file mode 100644 index 000000000..3a50077a5 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/impl/EntryTypeListImpl.java @@ -0,0 +1,94 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.impl; + +import org.eclipse.wst.wsi.internal.profile.EntryTypeList; + +/** + * This implementation is used to maintain a profile EntryTypeList. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public class EntryTypeListImpl implements EntryTypeList +{ + /** + * Log input. + */ + protected String logInput = null; + + /** + * WSDL input. + */ + protected String wsdlInput = null; + + /** + * UDDI input. + */ + protected String uddiInput = null; + + /* (non-Javadoc) + * @see org.wsi.test.profile.EntryTypeList#getLogInput() + */ + public String getLogInput() + { + return this.logInput; + } + + /* (non-Javadoc) + * @see org.wsi.test.profile.EntryTypeList#setLogInput(String) + */ + public void setLogInput(String logInput) + { + this.logInput = logInput; + } + + /* (non-Javadoc) + * @see org.wsi.test.profile.EntryTypeList#getWSDLInput() + */ + public String getWSDLInput() + { + return this.wsdlInput; + } + + /* (non-Javadoc) + * @see org.wsi.test.profile.EntryTypeList#setWSDLInput(String) + */ + public void setWSDLInput(String wsdlInput) + { + this.wsdlInput = wsdlInput; + } + + /* (non-Javadoc) + * @see org.wsi.test.profile.EntryTypeList#getUDDIInput() + */ + public String getUDDIInput() + { + return this.uddiInput; + } + + /* (non-Javadoc) + * @see org.wsi.test.profile.EntryTypeList#setUDDIInput(String) + */ + public void setUDDIInput(String uddiInput) + { + this.uddiInput = uddiInput; + } + + /* (non-Javadoc) + * @see org.wsi.test.document.DocumentElement#toXMLString(String) + */ + public String toXMLString(String namespaceName) + { + return null; + } + +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/impl/ProfileArtifactImpl.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/impl/ProfileArtifactImpl.java new file mode 100644 index 000000000..4c27dd757 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/impl/ProfileArtifactImpl.java @@ -0,0 +1,123 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.impl; + +import org.eclipse.wst.wsi.internal.profile.ProfileArtifact; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.util.ArtifactType; + +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.LinkedList; +import java.util.TreeMap; +import java.util.Vector; + +/** + * An artifact contains a set of related test assertions. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public class ProfileArtifactImpl implements ProfileArtifact +{ + /** + * Artifact type. + */ + protected ArtifactType type; + + /** + * Test assertion map. + */ + protected TreeMap testAssertionMap = new TreeMap(); + + /** + * Test assertion list. + */ + protected LinkedList testAssertionList = new LinkedList(); + + /* (non-Javadoc) + * @see org.wsi.test.profile.ReportArtifact#getType() + */ + public ArtifactType getType() + { + return this.type; + } + + /* (non-Javadoc) + * @see org.wsi.test.profile.ReportArtifact#setType(ArtifactType) + */ + public void setType(ArtifactType type) + { + this.type = type; + } + + /* (non-Javadoc) + * @see org.wsi.test.profile.ReportArtifact#getSpecificationList() + */ + public Vector getSpecificationList() + { + return null; + } + + /* (non-Javadoc) + * @see org.wsi.test.profile.ReportArtifact#setSpecificationList(Vector) + */ + public void setSpecificationList(Vector specificationList) + { + } + + /* (non-Javadoc) + * @see org.wsi.test.profile.ReportArtifact#getTestAssertionList() + */ + public LinkedList getTestAssertionList() + { + return this.testAssertionList; + } + + /* (non-Javadoc) + * @see org.wsi.test.profile.ReportArtifact#getTestAssertion(String) + */ + public TestAssertion getTestAssertion(String id) + { + return (TestAssertion) this.testAssertionMap.get(id); + } + + /* (non-Javadoc) + * @see org.wsi.test.profile.ReportArtifact#addTestAssertion(TestAssertion) + */ + public void addTestAssertion(TestAssertion testAssertion) + { + // ADD: Need to merge the list and map + this.testAssertionMap.put(testAssertion.getId(), testAssertion); + this.testAssertionList.add(testAssertion); + } + + /* (non-Javadoc) + * @see org.wsi.test.document.DocumentElement#toXMLString(String) + */ + public String toXMLString(String namespaceName) + { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + + String nsName = namespaceName; + if ((!nsName.equals("") && (!nsName.endsWith(":")))) + nsName += ":"; + + // ReportArtifact + pw.println(" <" + nsName + ELEM_NAME + ">"); + + pw.println(" "); + + return sw.toString(); + } + +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/impl/ProfileAssertionsImpl.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/impl/ProfileAssertionsImpl.java new file mode 100644 index 000000000..8453dc20c --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/impl/ProfileAssertionsImpl.java @@ -0,0 +1,194 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.impl; + +import java.util.Vector; + +import org.eclipse.wst.wsi.internal.profile.Profile; +import org.eclipse.wst.wsi.internal.profile.ProfileArtifact; +import org.eclipse.wst.wsi.internal.profile.ProfileAssertions; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; + +import java.util.Iterator; +import java.util.TreeMap; + +/** + * This class ... + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public class ProfileAssertionsImpl implements ProfileAssertions +{ + /** + * Location of the profile definition. + */ + protected String documentURI; + + /** + * Name of the profile test assertion document. + */ + protected String documentName; + + /** + * Version of the profile test assertion document. + */ + protected String documentVersion; + + // ADD: A profile definition should also have a description. + + /** + * List of profiles. + */ + Vector profileList = new Vector(); + + /** + * List of artifacts. + */ + TreeMap artifactList = new TreeMap(); + + /* (non-Javadoc) + * @see org.wsi.test.profile.ProfileAssertions#getProfileList() + */ + public Vector getProfileList() + { + return this.profileList; + } + + /* (non-Javadoc) + * @see org.wsi.test.profile.ProfileAssertions#setProfileList(Vector) + */ + public void setProfileList(Vector profileList) + { + this.profileList = profileList; + } + + /* (non-Javadoc) + * @see org.wsi.test.profile.ProfileAssertions#addProfile(Profile) + */ + public void addProfile(Profile profile) + { + this.profileList.add(profile); + } + + /* (non-Javadoc) + * @see org.wsi.test.profile.ProfileAssertions#getArtifactList() + */ + public TreeMap getArtifactList() + { + return this.artifactList; + } + + /* (non-Javadoc) + * @see org.wsi.test.profile.ProfileAssertions#getArtifact(java.lang.String) + */ + public ProfileArtifact getArtifact(String type) + { + return (ProfileArtifact) this.artifactList.get(type); + } + + /* (non-Javadoc) + * @see org.wsi.test.profile.ProfileAssertions#setArtifactList(TreeMap) + */ + public void setArtifactList(TreeMap artifactList) + { + this.artifactList = artifactList; + } + + /* (non-Javadoc) + * @see org.wsi.test.profile.ProfileAssertions#addArtifact(ReportArtifact) + */ + public void addArtifact(ProfileArtifact artifact) + { + this.artifactList.put(artifact.getType(), artifact); + } + + /* (non-Javadoc) + * @see org.wsi.test.profile.ProfileAssertions#getTestAssertion(String) + */ + public TestAssertion getTestAssertion(String id) + { + TestAssertion testAssertion = null; + + // Go through the list of artifacts and find the test assertion + Iterator iterator = artifactList.values().iterator(); + while ((iterator.hasNext()) && (testAssertion == null)) + { + testAssertion = ((ProfileArtifact) iterator.next()).getTestAssertion(id); + } + + return testAssertion; + } + + /* (non-Javadoc) + * @see org.wsi.test.profile.ProfileAssertions#createArtifact() + */ + public ProfileArtifact createArtifact() + { + return new ProfileArtifactImpl(); + } + + /* (non-Javadoc) + * @see org.wsi.test.document.WSIDocument#getLocation() + */ + public String getLocation() + { + return this.documentURI; + } + + /* (non-Javadoc) + * @see org.wsi.test.document.WSIDocument#setLocation(String) + */ + public void setLocation(String documentURI) + { + this.documentURI = documentURI; + } + + /** + * @see org.eclipse.wst.wsi.internal.profile.ProfileAssertions#getTADName() + */ + public String getTADName() + { + return this.documentName; + } + + /** + * @see org.eclipse.wst.wsi.internal.profile.ProfileAssertions#setTADName(String) + */ + public void setTADName(String documentName) + { + this.documentName = documentName; + } + + /** + * @see org.eclipse.wst.wsi.internal.profile.ProfileAssertions#getTADVersion() + */ + public String getTADVersion() + { + return this.documentVersion; + } + + /** + * @see org.eclipse.wst.wsi.internal.profile.ProfileAssertions#setTADVersion(String) + */ + public void setTADVersion(String documentVersion) + { + this.documentVersion = documentVersion; + } + + /* (non-Javadoc) + * @see org.wsi.test.document.DocumentElement#toXMLString(String) + */ + public String toXMLString(String namespaceName) + { + return null; + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/impl/ProfileAssertionsReaderImpl.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/impl/ProfileAssertionsReaderImpl.java new file mode 100644 index 000000000..e55fbd98d --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/impl/ProfileAssertionsReaderImpl.java @@ -0,0 +1,515 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.impl; + +import java.io.Reader; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.TreeMap; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.profile.EntryTypeList; +import org.eclipse.wst.wsi.internal.profile.ProfileArtifact; +import org.eclipse.wst.wsi.internal.profile.ProfileAssertions; +import org.eclipse.wst.wsi.internal.profile.ProfileAssertionsReader; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.util.ArtifactType; +import org.eclipse.wst.wsi.internal.util.Utils; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; +import org.xml.sax.Attributes; +import org.xml.sax.InputSource; +import org.xml.sax.XMLReader; +import org.xml.sax.helpers.DefaultHandler; + +/** + * This class ... + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public class ProfileAssertionsReaderImpl implements ProfileAssertionsReader +{ + /** + * Profile assertions. + */ + protected ProfileAssertions profileAssertions; + + /** + * ReportArtifact list. + */ + protected TreeMap artifactList = new TreeMap(); + + /** + * Create new reader. + */ + public ProfileAssertionsReaderImpl() + { + } + + /* (non-Javadoc) + * @see org.wsi.test.profile.ProfileAssertionsReader#readProfileAssertions(String) + */ + public ProfileAssertions readProfileAssertions(String assertionsURI) + throws WSIException + { + return readProfileAssertions(new InputSource(assertionsURI)); + } + + /* (non-Javadoc) + * @see org.wsi.test.profile.ProfileAssertionsReader#readProfileAssertions(Reader) + */ + public ProfileAssertions readProfileAssertions(Reader reader) + throws WSIException + { + return readProfileAssertions(new InputSource(reader)); + } + + /** + * Read profile assertions. + */ + private ProfileAssertions readProfileAssertions(InputSource inputSource) + throws WSIException + { + // Create profile assertions + profileAssertions = new ProfileAssertionsImpl(); + + // Profile parts are put into a vector + artifactList = new TreeMap(); + + try + { + // Create xml reader + XMLReader reader = XMLUtils.getXMLReader(); + + // Set content handler to inner class + reader.setContentHandler(new ProfileAssertionsHandler()); + + // Parse profile definition file + reader.parse(inputSource); + } + + catch (Exception e) + { + throw new WSIException("Could not read and parse profile definition.", e); + } + finally + { + //Check to see if the version of test asssertion document is supported + if (!Utils.isValidProfileTADVersion(profileAssertions)) + { + throw new WSIException( + "\nVersion " + + profileAssertions.getTADVersion() + + " of the \"" + + profileAssertions.getTADName() + + "\"\n" + + "document is not compatible with this version of" + + "\n" + + "the test tools."); + } + } + + // The assertions from the TAD are reordered for purposes of processing. All + // assertions of an artifact are reordered such that prerequisites occur + // before the assertions they prereq. The assumption is that prerequisites do + // not cross artifact types. + // + Iterator it = artifactList.keySet().iterator(); + // for each artifact type do reordering assertion + while (it.hasNext()) + { + ProfileArtifact art = (ProfileArtifact) artifactList.get(it.next()); + // result list of the reordering assertions + LinkedList res = new LinkedList(); + Iterator it2 = art.getTestAssertionList().iterator(); + // sort the artifact assertions into result list + while (it2.hasNext()) + { + // call for each assertion , + // if the assertion has the prereq, the prereq will added first into res list + sortTestAssertions(art, (TestAssertion) it2.next(), res); + } + // replace the original assertions list to the prereq reordering assertions list + art.getTestAssertionList().clear(); + art.getTestAssertionList().addAll(res); + } + // Put the profile parts into the profile definition + profileAssertions.setArtifactList(artifactList); + + return profileAssertions; + } + + /* (non-Javadoc) + * @see org.wsi.test.document.DocumentReader#getLocation() + */ + public String getLocation() + { + return null; + } + + /* (non-Javadoc) + * @see org.wsi.test.document.DocumentReader#setLocation(String) + */ + public void setLocation(String documentURI) + { + } + + /** + * Recursive walk to order assertions so that assertions are + * processed following the ones that prereq them. + * If assertion has prereq, then add it to the result list first. + * + * @param art profile artifact for call @link ProfileArtifact#getTestAssertion(String) + * @param asrt test assertion + * @param list result list to sort + */ + private void sortTestAssertions(ProfileArtifact art, TestAssertion asrt, List list) + { + // if assertion is null or does not exist, then exit + if((asrt == null) || list.contains(asrt)) + return; + + // if it has not prereq, add the asertion and exit + if(asrt.getPrereqIdList().isEmpty()) + { + list.add(asrt); + return; + } + // get list prereq assertion and reqursive call sortTestAssertions this each + Iterator it = asrt.getPrereqIdList().iterator(); + while(it.hasNext()) { + String id = (String) it.next(); + sortTestAssertions(art, art.getTestAssertion(id), list); + } + list.add(asrt); + } + + /** + * Inner class: ProfileAssertionsHandler + */ + class ProfileAssertionsHandler extends DefaultHandler + { + private ProfileArtifact artifact = profileAssertions.createArtifact(); + private String id; + private StringBuffer context = null; + private StringBuffer assertionDescription = null; + private StringBuffer failureMessage = null; + private StringBuffer failureDetailDescription = null; + private StringBuffer detailDescription = null; + private StringBuffer testAssertionId = null; + // private Vector prereqIdList = new Vector(); + private TreeMap assertions = new TreeMap(); + private String currentElement = null; + private TestAssertion testAssertion = null; + private StringBuffer logInput = null; + private StringBuffer wsdlInput = null; + private StringBuffer uddiInput = null; + private EntryTypeList entryTypeList = null; + + // Process start element event + public void startElement( + String namespaceURI, + String localName, + String qName, + Attributes atts) + { + if (namespaceURI != null + && (namespaceURI.equals(WSIConstants.NS_URI_WSI_ASSERTIONS_2003) + || namespaceURI.equals(WSIConstants.NS_URI_WSI_ASSERTIONS))) + { + // Save element name + currentElement = localName; + + // + if (localName.equals(WSIConstants.ELEM_ARTIFACT)) + { + // Create a new profile artifact object + artifact = profileAssertions.createArtifact(); + + // Set type + artifact.setType( + ArtifactType.newArtifactType( + atts.getValue(WSIConstants.ATTR_TYPE))); + + // ADD: Get specification list + + // Add artifact to list of artifact list + artifactList.put(artifact.getType().getTypeName(), artifact); + } + + // + else if (localName.equals(WSIConstants.ELEM_TEST_ASSERTION)) + { + // Create test assertion + testAssertion = new TestAssertionImpl(); + + // Get attribute values + testAssertion.setId(atts.getValue("", WSIConstants.ATTR_ID)); + testAssertion.setType(atts.getValue("", WSIConstants.ATTR_TYPE)); + testAssertion.setEntryTypeName( + atts.getValue("", WSIConstants.ATTR_ENTRY_TYPE)); + testAssertion.setEnabled( + Boolean + .valueOf(atts.getValue("", WSIConstants.ATTR_ENABLED)) + .booleanValue()); + + // Add test assertion to artifact + artifact.addTestAssertion(testAssertion); + } + + // + else if (localName.equals(WSIConstants.ELEM_CONTEXT)) + { + context = new StringBuffer(); + } + + // + else if (localName.equals(WSIConstants.ELEM_ASSERTION_DESCRIPTION)) + { + assertionDescription = new StringBuffer(); + } + + // + else if (localName.equals(WSIConstants.ELEM_FAILURE_MESSAGE)) + { + failureMessage = new StringBuffer(); + } + + // + else if (localName.equals(WSIConstants.ELEM_FAILURE_DETAIL_DESCRIPTION)) + { + failureDetailDescription = new StringBuffer(); + } + + // + else if (localName.equals(WSIConstants.ELEM_DETAIL_DESCRIPTION)) + { + detailDescription = new StringBuffer(); + } + + // + else if (localName.equals(WSIConstants.ELEM_TEST_ASSERTION_ID)) + { + testAssertionId = new StringBuffer(); + } + + // + else if ( + localName.equals(WSIConstants.ELEM_ADDITIONAL_ENTRY_TYPE_LIST)) + { + // Create entry type list + entryTypeList = new EntryTypeListImpl(); + } + + // + else if (localName.equals(WSIConstants.ELEM_MESSAGE_INPUT)) + { + logInput = new StringBuffer(); + } + + // + else if (localName.equals(WSIConstants.ELEM_WSDL_INPUT)) + { + wsdlInput = new StringBuffer(); + } + // + else if (localName.equals(WSIConstants.ELEM_PROFILE_ASSERTIONS)) + { + profileAssertions.setTADName( + atts.getValue("", WSIConstants.ATTR_NAME)); + profileAssertions.setTADVersion( + atts.getValue("", WSIConstants.ATTR_VERSION)); + } + + /* REMOVE: + // + else if (localName.equals(WSIConstants.ELEM_UDDI_INPUT)) { + uddiInput = new StringBuffer(); + } + */ + } + } // END startElement + + public void endElement(String namespaceURI, String localName, String qname) + { + // If this is the profile namespace, then check for and process selected elements + if (namespaceURI != null + && (namespaceURI.equals(WSIConstants.NS_URI_WSI_ASSERTIONS_2003) + || namespaceURI.equals(WSIConstants.NS_URI_WSI_ASSERTIONS))) + { + // + if (localName.equals(WSIConstants.ELEM_CONTEXT)) + { + // Set context in test assertion + testAssertion.setContext(context.toString()); + context = null; + } + + // + else if (localName.equals(WSIConstants.ELEM_ASSERTION_DESCRIPTION)) + { + // Set assertion description in test assertion + testAssertion.setAssertionDescription( + assertionDescription.toString()); + assertionDescription = null; + } + + // + else if (localName.equals(WSIConstants.ELEM_FAILURE_MESSAGE)) + { + // Set failure message in test assertion + testAssertion.setFailureMessage(failureMessage.toString()); + failureMessage = null; + } + + // + else if (localName.equals(WSIConstants.ELEM_FAILURE_DETAIL_DESCRIPTION)) + { + // Set failure detail description in test assertion + testAssertion.setFailureDetailDescription( + failureDetailDescription.toString()); + failureDetailDescription = null; + } + + // + else if (localName.equals(WSIConstants.ELEM_DETAIL_DESCRIPTION)) + { + // Set detail description in test assertion + testAssertion.setDetailDescription(detailDescription.toString()); + detailDescription = null; + } + + // + else if (localName.equals(WSIConstants.ELEM_TEST_ASSERTION_ID)) + { + // Set test assertion id in prereq list + testAssertion.addPrereqId(testAssertionId.toString()); + testAssertionId = null; + } + + // + else if ( + localName.equals(WSIConstants.ELEM_ADDITIONAL_ENTRY_TYPE_LIST)) + { + // Set target list + testAssertion.setAdditionalEntryTypeList(entryTypeList); + entryTypeList = null; + } + + // + else if (localName.equals(WSIConstants.ELEM_MESSAGE_INPUT)) + { + // Set test assertion id in prereq list + entryTypeList.setLogInput(logInput.toString()); + logInput = null; + } + + // + else if (localName.equals(WSIConstants.ELEM_WSDL_INPUT)) + { + // Set test assertion id in prereq list + entryTypeList.setWSDLInput(wsdlInput.toString()); + wsdlInput = null; + } + + // + else if (localName.equals(WSIConstants.ELEM_PROFILE_ASSERTIONS)) + { + // a no-op + } + + /* REMOVE: + // + else if (localName.equals(WSIConstants.ELEM_UDDI_INPUT)) { + // Set test assertion id in prereq list + entryTypeList.setUDDIInput(uddiInput.toString()); + uddiInput = null; + } + */ + } + } // END endElement + + public void characters(char[] ch, int start, int length) + { + // + if ((context != null) + && (currentElement.equals(WSIConstants.ELEM_CONTEXT))) + { + context.append(ch, start, length); + } + + // + else if ( + (assertionDescription != null) + && (currentElement.equals(WSIConstants.ELEM_ASSERTION_DESCRIPTION))) + { + assertionDescription.append(ch, start, length); + } + + // + else if ( + (failureMessage != null) + && (currentElement.equals(WSIConstants.ELEM_FAILURE_MESSAGE))) + { + failureMessage.append(ch, start, length); + } + + // + else if ( + (failureDetailDescription != null) && ( + currentElement.equals(WSIConstants.ELEM_FAILURE_DETAIL_DESCRIPTION))) + { + failureDetailDescription.append(ch, start, length); + } + + // + else if ( + (detailDescription != null) + && (currentElement.equals(WSIConstants.ELEM_DETAIL_DESCRIPTION))) + { + detailDescription.append(ch, start, length); + } + + // + else if ( + (testAssertionId != null) + && (currentElement.equals(WSIConstants.ELEM_TEST_ASSERTION_ID))) + { + testAssertionId.append(ch, start, length); + } + + // + else if ( + (logInput != null) + && (currentElement.equals(WSIConstants.ELEM_MESSAGE_INPUT))) + { + logInput.append(ch, start, length); + } + + // + else if ( + (wsdlInput != null) + && (currentElement.equals(WSIConstants.ELEM_WSDL_INPUT))) + { + wsdlInput.append(ch, start, length); + } + + /* REMOVE: + // + else if ((uddiInput != null) && (currentElement.equals(WSIConstants.ELEM_UDDI_INPUT))) { + uddiInput.append(ch, start, length); + } + */ + } + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/impl/TestAssertionImpl.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/impl/TestAssertionImpl.java new file mode 100644 index 000000000..c60fc3cfd --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/impl/TestAssertionImpl.java @@ -0,0 +1,256 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.impl; + +import org.eclipse.wst.wsi.internal.profile.EntryTypeList; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; + +import java.util.Vector; + +/** + * This class ... + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public class TestAssertionImpl implements TestAssertion +{ + /** + * Test assertion id. + */ + protected String id = null; + + /** + * Test assertion type. + */ + protected String type = null; + + /** + * Test assertion primary entry type name. + */ + protected String entryTypeName = null; + + /** + * Test assertion enabled indicator. + */ + protected boolean enabled = true; + + /** + * Context. + */ + protected String context = null; + + /** + * Assertion description. + */ + protected String assertionDescription = null; + + /** + * Failure message. + */ + protected String failureMessage = null; + + /** + * Failure detail description. + */ + protected String failureDetailDescription = null; + + /** + * Detail description. + */ + protected String detailDescription = null; + + /** + * Addtional entry type list. + */ + protected EntryTypeList entryTypeList = null; + + /** + * Prereq ID list. + */ + protected Vector prereqIdList = new Vector(); + + /* (non-Javadoc) + * @see org.wsi.test.profile.TestAssertion#getId() + */ + public String getId() + { + return this.id; + } + + /* (non-Javadoc) + * @see org.wsi.test.profile.TestAssertion#setId(String) + */ + public void setId(String id) + { + this.id = id; + } + + /* (non-Javadoc) + * @see org.wsi.test.profile.TestAssertion#getType() + */ + public String getType() + { + return this.type; + } + + /* (non-Javadoc) + * @see org.wsi.test.profile.TestAssertion#setType(String) + */ + public void setType(String type) + { + this.type = type; + } + + /* (non-Javadoc) + * @see org.wsi.test.profile.TestAssertion#getEntryTypeName() + */ + public String getEntryTypeName() + { + return this.entryTypeName; + } + + /* (non-Javadoc) + * @see org.wsi.test.profile.TestAssertion#setEntryTypeName(String) + */ + public void setEntryTypeName(String entryTypeName) + { + this.entryTypeName = entryTypeName; + } + + /* (non-Javadoc) + * @see org.wsi.test.profile.TestAssertion#isEnabled() + */ + public boolean isEnabled() + { + return enabled; + } + + /* (non-Javadoc) + * @see org.wsi.test.profile.TestAssertion#setEnabled(boolean) + */ + public void setEnabled(boolean enabled) + { + this.enabled = enabled; + } + + /* (non-Javadoc) + * @see org.wsi.test.profile.TestAssertion#getContext() + */ + public String getContext() + { + return context; + } + + /* (non-Javadoc) + * @see org.wsi.test.profile.TestAssertion#setContext(String) + */ + public void setContext(String context) + { + this.context = context; + } + + /* (non-Javadoc) + * @see org.wsi.test.profile.TestAssertion#getAssertionDescription() + */ + public String getAssertionDescription() + { + return this.assertionDescription; + } + + /* (non-Javadoc) + * @see org.wsi.test.profile.TestAssertion#setAssertionDescription(String) + */ + public void setAssertionDescription(String assertionDescription) + { + this.assertionDescription = assertionDescription; + } + + /* (non-Javadoc) + * @see org.wsi.test.profile.TestAssertion#getFailureMessage() + */ + public String getFailureMessage() + { + return this.failureMessage; + } + + /* (non-Javadoc) + * @see org.wsi.test.profile.TestAssertion#setFailureMessage(String) + */ + public void setFailureMessage(String failureMessage) + { + this.failureMessage = failureMessage; + } + + /* (non-Javadoc) + * @see org.wsi.test.profile.TestAssertion#getFailureDetailDescription() + */ + public String getFailureDetailDescription() + { + return this.failureDetailDescription; + } + + /* (non-Javadoc) + * @see org.wsi.test.profile.TestAssertion#setFailureDetailDescription(String) + */ + public void setFailureDetailDescription(String failureDetailDescription) + { + this.failureDetailDescription = failureDetailDescription; + } + + /* (non-Javadoc) + * @see org.wsi.test.profile.TestAssertion#getDetailDescription() + */ + public String getDetailDescription() + { + return this.detailDescription; + } + + /* (non-Javadoc) + * @see org.wsi.test.profile.TestAssertion#setDetailDescription(String) + */ + public void setDetailDescription(String detailDescription) + { + this.detailDescription = detailDescription; + } + + /* (non-Javadoc) + * @see org.wsi.test.profile.TestAssertion#getAdditionalEntryTypeList() + */ + public EntryTypeList getAdditionalEntryTypeList() + { + return this.entryTypeList; + } + + /* (non-Javadoc) + * @see org.wsi.test.profile.TestAssertion#setAdditionalEntryTypeList(org.wsi.test.profile.EntryTypeList) + */ + public void setAdditionalEntryTypeList(EntryTypeList entryTypeList) + { + this.entryTypeList = entryTypeList; + } + + /* (non-Javadoc) + * @see org.wsi.test.profile.TestAssertion#getPrereqIdList() + */ + public Vector getPrereqIdList() + { + return prereqIdList; + } + + /* (non-Javadoc) + * @see org.wsi.test.profile.TestAssertion#addPrereqId(String) + */ + public void addPrereqId(String prereqId) + { + this.prereqIdList.add(prereqId); + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/BaseValidator.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/BaseValidator.java new file mode 100644 index 000000000..dbb73379e --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/BaseValidator.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator; + +import org.eclipse.wst.wsi.internal.WSIException; + +import org.w3c.dom.Document; + +/** + * The base interface for the profile validator. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public interface BaseValidator +{ + /** + * Set all test assertions for an artifact to missingInput. + * @throws WSIException if there is any problems while processing. + */ + public void setAllMissingInput() throws WSIException; + + /** + * Cleanup after processing all of the test assertions for an artifact. + * @throws WSIException if there is any problems during cleanup. + */ + public void cleanup() throws WSIException; + + /** + * Parse XML document and validate with a schema document. + * @param urlString XML document location. + * @param baseURI a base url to assist in locating the XML document. + * @param schema the related XML schema. + * @return XML document. + * @throws WSIException if there are any problems while parsing or + * validating the XML document. + */ + public Document parseXMLDocumentURL( + String urlString, + String baseURI, + String schema) + throws WSIException; +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/EntryContext.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/EntryContext.java new file mode 100644 index 000000000..a760b82e7 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/EntryContext.java @@ -0,0 +1,223 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.analyzer.AnalyzerContext; +import org.eclipse.wst.wsi.internal.log.MessageEntry; +import org.eclipse.wst.wsi.internal.log.MimePart; +import org.eclipse.wst.wsi.internal.report.Entry; +import org.eclipse.wst.wsi.internal.util.EntryType; +import org.eclipse.wst.wsi.internal.wsdl.WSDLDocument; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; + +import org.w3c.dom.Document; + +/** + * This class contains the target information needed by a test assertion. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + * @author Graham Turrell (gturrell@uk.ibm.com) + */ +public class EntryContext +{ + protected Entry entry = null; + + protected MessageEntry request = null; + protected MessageEntry response = null; + protected MessageEntry messageEntry = null; + + protected Document requestDocument = null; + protected Document responseDocument = null; + protected Document messageEntryDocument = null; + + protected WSDLDocument wsdlDocument = null; + + protected AnalyzerContext analyzerContext = null; + + /** + * Create entry context. + * @param entry a message entry. + * @param request the request. + * @param response the response. + */ + public EntryContext(Entry entry, MessageEntry request, MessageEntry response) + { + this(entry, request, response, null); + } + + /** + * Create entry context. + * @param entry a message entry. + * @param request the request. + * @param response the response. + * @param analyzerContext the analyzerContext. + */ + public EntryContext( + Entry entry, + MessageEntry request, + MessageEntry response, + AnalyzerContext analyzerContext) + { + this.entry = entry; + this.request = request; + this.response = response; + this.analyzerContext = analyzerContext; + + try + { + // Parse all documents + if(request.isMimeContent()) + { + MimePart part = request.getMimeParts().getRootPart(); + if ((part != null) && (part.getContent().length() > 0)) + requestDocument = XMLUtils.parseXML(part.getContent()); + } + else + { + if (request.getMessage().length() > 0) + requestDocument = XMLUtils.parseXML(request.getMessage()); + } + + if(response.isMimeContent()) + { + MimePart part = response.getMimeParts().getRootPart(); + if ((part != null) && (part.getContent().length() > 0)) + responseDocument = XMLUtils.parseXML(part.getContent()); + } + else + { + if (response.getMessage().length() > 0) + responseDocument = XMLUtils.parseXML(response.getMessage()); + } + } + + catch (WSIException we) + { + } + + // need some exception handling in here and more careful checking + if (entry.getEntryType().equals(EntryType.ENTRY_TYPE_REQUEST)) + { + this.messageEntry = request; + this.messageEntryDocument = requestDocument; + } + else + { + this.messageEntry = response; + this.messageEntryDocument = responseDocument; + } + } + + /** + * Create entry context. + * @param entry a message entry. + * @param wsdlDocument a WSDL document. + */ + public EntryContext(Entry entry, WSDLDocument wsdlDocument) + { + this.entry = entry; + this.wsdlDocument = wsdlDocument; + } + + /** + * Create entry context. + * @param entry a message entry. + * @param analyzerContext the analyzerContext. + */ + public EntryContext(Entry entry, AnalyzerContext analyzerContext) + { + this.entry = entry; + this.analyzerContext = analyzerContext; + } + + /** + * Returns the entry. + * @return the entry. + */ + public Entry getEntry() + { + return this.entry; + } + + /** + * Returns the request. + * @return the request. + */ + public MessageEntry getRequest() + { + return request; + } + + /** + * Returns the response. + * @return the response. + */ + public MessageEntry getResponse() + { + return response; + } + + /** + * Returns the log entry which is not null. + * @return the log entry. + */ + public MessageEntry getMessageEntry() + { + return messageEntry; + } + + /** + * Returns the request. + * @return MessageEntry + */ + public Document getRequestDocument() + { + return requestDocument; + } + + /** + * Returns the response. + * @return the response. + */ + public Document getResponseDocument() + { + return responseDocument; + } + + /** + * Returns the log entry which is not null. + * @return the log entry. + */ + public Document getMessageEntryDocument() + { + return messageEntryDocument; + } + + /** + * Returns the WSDL document. + * @return the WSDL document. + */ + public WSDLDocument getWSDLDocument() + { + return wsdlDocument; + } + + /** + * Returns analyzerContext. + * @return analyzerContext + */ + public AnalyzerContext getAnalyzerContext() + { + return this.analyzerContext; + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/EnvelopeValidator.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/EnvelopeValidator.java new file mode 100644 index 000000000..70ecf72fd --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/EnvelopeValidator.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.analyzer.AnalyzerContext; +import org.eclipse.wst.wsi.internal.profile.ProfileArtifact; +import org.eclipse.wst.wsi.internal.report.ReportArtifact; +import org.eclipse.wst.wsi.internal.report.Reporter; +import org.eclipse.wst.wsi.internal.wsdl.WSDLDocument; + +/** + * Interface definition for envelope validation test procedure. + * + * @version 1.0 + */ +public interface EnvelopeValidator extends BaseValidator +{ + + /** + * Initiailize validation test procedure. + * @param analyzerContext the analyzerContext. + * @param artifact an profile artifact. + * @param reportArtifact the report artifact. + * @param wsdlDocument the Web service definition + * @param reporter the reporter which is used to add errors to the conformance report + * @throws WSIException if message validator could not be initialized. + */ + public void init( + AnalyzerContext analyzerContext, + ProfileArtifact artifact, + ReportArtifact reportArtifact, + WSDLDocument wsdlDocument, + Reporter reporter) + throws WSIException; + + /** + * Validate the envelope located by the log entry. + * @param entryContext a log entry locating an envelope. + * @throws WSIException if an unexpected error occurred while + * processing the log entry. + */ + public void validate(EntryContext entryContext) throws WSIException; +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/MessageValidator.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/MessageValidator.java new file mode 100644 index 000000000..0bf970f76 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/MessageValidator.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.analyzer.AnalyzerContext; +import org.eclipse.wst.wsi.internal.profile.ProfileArtifact; +import org.eclipse.wst.wsi.internal.report.ReportArtifact; +import org.eclipse.wst.wsi.internal.report.Reporter; +import org.eclipse.wst.wsi.internal.wsdl.WSDLDocument; + +/** + * Interface definition for message validation test procedure. + * + * @version 1.0.1 + * @author Peter Brittenham + * @author Graham Turrell (gturrell@uk.ibm.com) + */ +public interface MessageValidator extends BaseValidator +{ + /** + * HTTP 1.0 version indicator. + */ + public static final String HTTP_VERSION_1_0 = "HTTP/1.0"; + + /** + * HTTP 1.1 version indicator. + */ + public static final String HTTP_VERSION_1_1 = "HTTP/1.1"; + + /** + * HTTP POST message indicator. + */ + public static final String HTTP_POST = "POST"; + + /** + * Initiailize validation test procedure. + * @param analyzerContext the analyzerContext. + * @param artifact an profile artifact. + * @param reportArtifact the report artifact. + * @param wsdlDocument the Web service definition + * @param reporter the reporter which is used to add errors to the conformance report + * @throws WSIException if message validator could not be initialized. + */ + public void init( + AnalyzerContext analyzerContext, + ProfileArtifact artifact, + ReportArtifact reportArtifact, + WSDLDocument wsdlDocument, + Reporter reporter) + throws WSIException; + + /** + * Validate the message located by the log entry. + * @param entryContext a log entry locating a message. + * @throws WSIException if an unexpected error occurred while + * processing the log entry. + */ + public void validate(EntryContext entryContext) throws WSIException; +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/ProfileValidatorFactory.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/ProfileValidatorFactory.java new file mode 100644 index 000000000..ebac27455 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/ProfileValidatorFactory.java @@ -0,0 +1,96 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.util.WSIProperties; + +/** +* This class is used to access an implementation of a ProfileValidatorFactory abstract class. + * + * @version 1.0.1 + * @author Peter Brittenham + */ +public abstract class ProfileValidatorFactory +{ + /** + * Create a new instance of a UDDI validator. + * @return an object that implements the WSDLValidator interface. + * @throws WSIException if UDDI validator cannot be instantiated. + */ + public abstract UDDIValidator newUDDIValidator() throws WSIException; + + /** + * Create a new instance of a WSDL validator. + * @return an object that implements the WSDLValidator interface. + * @throws WSIException if WSDL validator cannot be instantiated. + */ + public abstract WSDLValidator newWSDLValidator() throws WSIException; + + /** + * Create a new instance of a message validator. + * NOTE: Do we need to differentiate between the tranport and SOAP + * message validator? + * + * @return an object that implements the MessageValidator interface. + * @throws WSIException if message validatorcannot be instantiated. + */ + public abstract MessageValidator newMessageValidator() throws WSIException; + + /** + * Create a new instance of an envelope validator. + * @return an object that implements the EnvelopeValidator interface. + * @throws WSIException if message validator cannot be instantiated. + */ + public abstract EnvelopeValidator newEnvelopeValidator() throws WSIException; + + /** + * Instantiate the implementation of the ProfileValidatorFactory class. + * The implementation class for this interface is specified in the following + * Java system property: + *
    + *
  • wsi.profile.validator.factory + *
+ * + * @return the ProfileValidatorFactory object. + * @throws WSIException if factory class cannot be instantiated. + */ + public static ProfileValidatorFactory newInstance() throws WSIException + { + ProfileValidatorFactory factory = null; + String factoryClassName = null; + + try + { + // Get factory class name + factoryClassName = + WSIProperties.getProperty( + WSIProperties.PROP_VALIDATOR_FACTORY, + WSIProperties.DEF_VALIDATOR_FACTORY); + + // Create the factory class + Class factoryClass = Class.forName(factoryClassName); + + // Instantiate the factory + factory = (ProfileValidatorFactory) factoryClass.newInstance(); + } + + catch (Exception e) + { + throw new WSIException( + "Could not instantiate factory class: " + factoryClassName + ".", + e); + } + + // Return factory + return factory; + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/UDDIValidator.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/UDDIValidator.java new file mode 100644 index 000000000..f92fb2f0f --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/UDDIValidator.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.analyzer.AnalyzerContext; +import org.eclipse.wst.wsi.internal.analyzer.config.UDDIReference; +import org.eclipse.wst.wsi.internal.profile.ProfileArtifact; +import org.eclipse.wst.wsi.internal.report.ReportArtifact; +import org.eclipse.wst.wsi.internal.report.Reporter; + +/** + * The WSDL validator will verify that the WSDL and associated XML schema definitions + * are in conformance with the profile. + * + * @version 1.0.1 + * @author Peter Brittenham + */ +public interface UDDIValidator extends BaseValidator +{ + /** + * Initiailize validation test procedure. + * @param analyzerContext the analyzerContext. + * @param artifact an profile artifact. + * @param reportArtifact the report artifact. + * @param uddiReference a UDDI reference. + * @param reporter a Reporter object. + * @throws WSIException if UDDI validator could not be initialized. + */ + public void init( + AnalyzerContext analyzerContext, + ProfileArtifact artifact, + ReportArtifact reportArtifact, + UDDIReference uddiReference, + Reporter reporter) + throws WSIException; + + /** + * Validate the UDDI based service description. + * @return If the UDDI entries are valid, then the value returned + * is the URL for the WSDL document. + * @throws WSIException WSIException if an unexpected error occurred + * while processing the UDDIentries. + */ + public String validate() throws WSIException; +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/WSDLValidator.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/WSDLValidator.java new file mode 100644 index 000000000..8c1cf20f7 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/WSDLValidator.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.analyzer.AnalyzerContext; +import org.eclipse.wst.wsi.internal.profile.ProfileArtifact; +import org.eclipse.wst.wsi.internal.report.ReportArtifact; +import org.eclipse.wst.wsi.internal.report.Reporter; +import org.eclipse.wst.wsi.internal.wsdl.WSDLDocument; + +/** + * The WSDL validator will verify that the WSDL and associated XML schema definitions + * are in conformance with the profile. + * + * @version 1.0.1 + * @author Peter Brittenham + */ +public interface WSDLValidator extends BaseValidator +{ + /** + * Initiailize validation test procedure. + * @param analyzerContext the analyzerContext. + * @param artifact the profile artifact. + * @param reportArtifact the report artifact. + * @param wsdlURL the WSDL document location. + * @param wsdlDocument the WSDL document. + * @param reporter a Reporter object. + * @throws WSIException if WSDL validator could not be initialized. + */ + public void init( + AnalyzerContext analyzerContext, + ProfileArtifact artifact, + ReportArtifact reportArtifact, + String wsdlURL, + WSDLDocument wsdlDocument, + Reporter reporter) + throws WSIException; + + /** + * Validate the WSDL based service description. + * @return the WSDL document. + * @throws WSIException if an unexpected error occurred + * while validating he WSDL based service description. + */ + public WSDLDocument validate() throws WSIException; +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/AssertionProcess.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/AssertionProcess.java new file mode 100644 index 000000000..d4b868035 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/AssertionProcess.java @@ -0,0 +1,66 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.report.FailureDetail; + + +/** + * Process assertion. + */ +public abstract class AssertionProcess +{ + protected String result; + protected String failureDetailMessage; + protected FailureDetail failureDetail; + private final BaseValidatorImpl base_validator; + + /** + * @param BaseValidatorImpl + */ + public AssertionProcess(BaseValidatorImpl impl) + { + this.base_validator = impl; + } + + /** + * Create assertion result. + */ + void reset() + { + result = AssertionResult.RESULT_PASSED; + failureDetailMessage = null; + failureDetail = null; + } + + /** + * Validate assertion. + */ + public abstract AssertionResult validate( + TestAssertion testAssertion, + EntryContext targetContext) + throws WSIException; + + /** + * Verbose output. + */ + public void debug(String message) + { + if ((base_validator != null) && base_validator.verboseOption) + { + System.err.println(message); + } + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/AssertionProcessVisitor.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/AssertionProcessVisitor.java new file mode 100644 index 000000000..5b95c83b0 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/AssertionProcessVisitor.java @@ -0,0 +1,157 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl; + +import javax.wsdl.Binding; +import javax.wsdl.BindingFault; +import javax.wsdl.BindingInput; +import javax.wsdl.BindingOperation; +import javax.wsdl.BindingOutput; +import javax.wsdl.Definition; +import javax.wsdl.Fault; +import javax.wsdl.Import; +import javax.wsdl.Input; +import javax.wsdl.Message; +import javax.wsdl.Operation; +import javax.wsdl.Output; +import javax.wsdl.Part; +import javax.wsdl.Port; +import javax.wsdl.PortType; +import javax.wsdl.Service; +import javax.wsdl.Types; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.soap.SOAPBinding; +import javax.wsdl.extensions.soap.SOAPBody; +import javax.wsdl.extensions.soap.SOAPFault; +import javax.wsdl.extensions.soap.SOAPHeader; +import javax.wsdl.extensions.soap.SOAPHeaderFault; +import javax.wsdl.extensions.soap.SOAPOperation; + +import org.eclipse.wst.wsi.internal.wsdl.traversal.WSDLTraversalContext; +import org.eclipse.wst.wsi.internal.wsdl.traversal.WSDLVisitor; +import org.w3c.dom.Element; + + +/** + * Process assertion using WSDLVisitor interface. + */ +public abstract class AssertionProcessVisitor + extends AssertionProcess + implements WSDLVisitor +{ + private final BaseValidatorImpl base_validator; + + /** + * @param BaseValidatorImpl + */ + public AssertionProcessVisitor(BaseValidatorImpl impl) + { + super(impl); + this.base_validator = impl; + } + + public void visit(Part obj, Object parent, WSDLTraversalContext ctx) + { + } + public void visit(Service obj, Object parent, WSDLTraversalContext ctx) + { + } + public void visit(Types obj, Object parent, WSDLTraversalContext ctx) + { + } + public void visit(Operation obj, Object parent, WSDLTraversalContext ctx) + { + } + public void visit(Input obj, Object parent, WSDLTraversalContext ctx) + { + } + public void visit(Output obj, Object parent, WSDLTraversalContext ctx) + { + } + public void visit(Fault obj, Object parent, WSDLTraversalContext ctx) + { + } + public void visit(Binding obj, Object parent, WSDLTraversalContext ctx) + { + } + public void visit( + BindingOperation obj, + Object parent, + WSDLTraversalContext ctx) + { + } + public void visit( + BindingInput obj, + Object parent, + WSDLTraversalContext ctx) + { + } + public void visit( + BindingOutput obj, + Object parent, + WSDLTraversalContext ctx) + { + } + public void visit( + BindingFault obj, + Object parent, + WSDLTraversalContext ctx) + { + } + public void visit(Import obj, Object parent, WSDLTraversalContext ctx) + { + } + public void visit(Element obj, Object parent, WSDLTraversalContext ctx) + { + } + public void visit(Message obj, Object parent, WSDLTraversalContext ctx) + { + } + public void visit(Port obj, Object parent, WSDLTraversalContext ctx) + { + } + public void visit(PortType obj, Object parent, WSDLTraversalContext ctx) + { + } + public void visit(Definition obj, Object parent, WSDLTraversalContext ctx) + { + } + public void visit( + ExtensibilityElement obj, + Object parent, + WSDLTraversalContext ctx) + { + } + public void visit(SOAPBinding obj, Object parent, WSDLTraversalContext ctx) + { + } + public void visit(SOAPBody obj, Object parent, WSDLTraversalContext ctx) + { + } + public void visit(SOAPHeader obj, Object parent, WSDLTraversalContext ctx) + { + } + public void visit( + SOAPHeaderFault obj, + Object parent, + WSDLTraversalContext ctx) + { + } + public void visit(SOAPFault obj, Object parent, WSDLTraversalContext ctx) + { + } + public void visit( + SOAPOperation obj, + Object parent, + WSDLTraversalContext ctx) + { + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/BaseMessageValidator.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/BaseMessageValidator.java new file mode 100644 index 000000000..a89843d31 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/BaseMessageValidator.java @@ -0,0 +1,1839 @@ +/******************************************************************************* + * Copyright (c) 2002-2003 IBM Corporation, Parasoft and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + * Parasoft - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.StringTokenizer; +import java.util.Vector; + +import javax.wsdl.Binding; +import javax.wsdl.BindingOperation; +import javax.wsdl.Definition; +import javax.wsdl.Message; +import javax.wsdl.Part; +import javax.wsdl.Port; +import javax.wsdl.Service; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.mime.MIMEMultipartRelated; +import javax.wsdl.extensions.mime.MIMEPart; +import javax.wsdl.extensions.soap.SOAPBinding; +import javax.wsdl.extensions.soap.SOAPBody; +import javax.wsdl.extensions.soap.SOAPHeader; +import javax.wsdl.extensions.soap.SOAPOperation; +import javax.xml.namespace.QName; + +import org.apache.xerces.util.URI; +import org.apache.xerces.xs.XSConstants; +import org.apache.xerces.xs.XSModel; +import org.apache.xerces.xs.XSTypeDefinition; +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.WSITag; +import org.eclipse.wst.wsi.internal.analyzer.AnalyzerContext; +import org.eclipse.wst.wsi.internal.analyzer.CandidateInfo; +import org.eclipse.wst.wsi.internal.analyzer.ServiceReference; +import org.eclipse.wst.wsi.internal.analyzer.config.AnalyzerConfig; +import org.eclipse.wst.wsi.internal.log.Log; +import org.eclipse.wst.wsi.internal.log.MessageEntry; +import org.eclipse.wst.wsi.internal.profile.ProfileArtifact; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseValidatorImpl; +import org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl.*; +import org.eclipse.wst.wsi.internal.report.FailureDetail; +import org.eclipse.wst.wsi.internal.report.ReportArtifact; +import org.eclipse.wst.wsi.internal.report.Reporter; +import org.eclipse.wst.wsi.internal.util.EntryType; +import org.eclipse.wst.wsi.internal.util.HTTPUtils; +import org.eclipse.wst.wsi.internal.wsdl.WSDLDocument; +import org.eclipse.wst.wsi.internal.wsdl.WSDLUtils; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; +import org.w3c.dom.Attr; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.SAXException; + +import com.ibm.wsdl.Constants; +import com.ibm.wsdl.util.xml.DOM2Writer; +import com.ibm.wsdl.util.xml.DOMUtils; + +/** + * The WSDL validator will verify that the WSDL and associated XML schema definitions + * are in conformance with the profile. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + * @author Jim Clune + * @author Graham Turrell (gturrell@uk.ibm.com) + * @author Neil Delima (nddelima@ca.ibm.com) + */ +public abstract class BaseMessageValidator + extends BaseValidatorImpl +{ + /** + * WSDL document. + */ + private WSDLDocument wsdlDocument; + + /** + * Log entry. + */ + protected MessageEntry logEntry; + protected Log log; + + /* (non-Javadoc) + * @see org.wsi.test.profile.validator.MessageValidator#init(org.wsi.test.analyzer.AnalyzerContext, org.wsi.test.profile.ProfileArtifact, org.wsi.test.report.ReportArtifact, org.wsi.wsdl.WSDLDocument, org.wsi.test.report.Reporter) + */ + public void init( + AnalyzerContext analyzerContext, + ProfileArtifact profileArtifact, + ReportArtifact reportArtifact, + WSDLDocument wsdlDocument, + Reporter reporter) + throws WSIException + { + // BaseValidatorImpl + super.init(analyzerContext, profileArtifact, reportArtifact, reporter); + + // Save input references + this.wsdlDocument = wsdlDocument; + } + + /** + * Returns wsdlDocument + * @return wsdlDocument + */ + public WSDLDocument getWSDLDocument() + { + return wsdlDocument; + } + /* (non-Javadoc) + * @see org.wsi.test.profile.validator.MessageValidator#validate(org.wsi.test.profile.validator.EntryContext) + */ + public void validate(EntryContext entryContext) throws WSIException + { + //Entry entry = null; + + // Save log entry to be referenced by other methods + this.logEntry = entryContext.getMessageEntry(); + + // Get reference to the analyzer config object + AnalyzerConfig analyzerConfig = + reporter.getReport().getReportContext().getAnalyzer().getAnalyzerConfig(); + + /* If Service Description (WSDL/UDDI) NOT supplied in analyzer config OR + * Service Description IS supplied and the current message correlates to it... + */ + if ((wsdlDocument == null) + || messageCorrelatesToService( + entryContext, + analyzerConfig.getCorrelationType())) + { + // now inner classes moved out from the validator + //String classPrefix = this.getClass().getName() + "$"; + String classPrefix = this.getClass().getPackage().getName()+"."; + + // Process assertions for this artifact against the target context + processAssertions(classPrefix, entryContext); + } + } + + /** + * Check whether the message correlates to the service under test. + * Use the request part of the request-response pair, from which the correlation of the response is implied. + * Entities from the Service under test are determined once for all. + * @param entryContext an entry context. + * @param correlationType a correlation type. + * @return true if the message correlates to the service under test. + * @throws WSIException if correlation type is not appropriate. + */ + private boolean messageCorrelatesToService( + EntryContext entryContext, + String correlationType) + throws WSIException + { + + URI[] endpoints = null; + boolean correlation = false; + + /* TEMP: Get it from analyzer config passed in on init method + CandidateInfo candidate = entryContext + .getAnalyzerContext() + .getCandidateInfo(); + */ + CandidateInfo candidate = analyzerContext.getCandidateInfo(); + + // Service reference + ServiceReference serviceReference = analyzerContext.getServiceReference(); + + // Get the definition element + Definition definition = candidate.getWsdlDocument().getDefinitions(); + + Binding binding = null; + if (serviceReference.getWSDLElement().isPort()) + { + // Get service + Service service = + definition.getService( + serviceReference.getWSDLElement().getParentElementQName()); + + // Get port + Port port = service.getPort(serviceReference.getWSDLElement().getName()); + + // Get binding + binding = port.getBinding(); + } + else if (serviceReference.getWSDLElement().isBinding()) + { + // Get binding + binding = + definition.getBinding(serviceReference.getWSDLElement().getQName()); + } + + if (binding == null) + { + return false; + } + + if ((endpoints = hostAndPortCorrelation(entryContext)) != null + && urlPathCorrelation(entryContext, endpoints)) + { + + /* If correlation type is "endpoint", this is all the correlation that can be done. + * (Note - this is incomplete correlation since >1 service could be associated with the endpoint. + * Therefore , if messages for different services on the same endpoint appear in the log file + * and correlation type is "endpoint", all those messages will be analyzed). + */ + if (correlationType + .equals(WSIConstants.ATTRVAL_CORRELATION_TYPE_ENDPOINT)) + { + correlation = true; + } + else + { + // always allow GET requests right through if they've passed Endpoint Correlation + String requestType = getHttpRequestType(entryContext); + if ((requestType != null) && requestType.equalsIgnoreCase("GET")) + { + correlation = true; + } + else + { + // The correlationType is not "endpoint" so continue on to processing for at least + // "namespace" correlation... + + // get the operation signature (input & output) from request & response messages... + // and do a quick DOM parse + Document requestMessage = entryContext.getRequestDocument(); + + // Check if namespace is found in request message only + if (namespaceCorrelation(binding, requestMessage)) + { + // If namespace found and the correlation type is namespace, then process messages + if (correlationType + .equals(WSIConstants.ATTRVAL_CORRELATION_TYPE_NAMESPACE)) + { + correlation = true; + } + + // If operation is found and correlation type is operation, then process messages + else if ( + (operationCorrelation(binding, requestMessage)) + && (correlationType + .equals(WSIConstants.ATTRVAL_CORRELATION_TYPE_OPERATION))) + { + correlation = true; + } + else + { + // this should never happen if config schema was followed correctly + throw new WSIException( + "Bad correlation type found in config: " + correlationType); + } + } + } + } + } + + return correlation; + } + + /** + * Correlation Check 1: Service Description endpoint vs HTTP Header (test 1) + * Check if receiverHostAndPort from request message log matches host & port from WSDL SOAP binding for + * the Service under test. + * If it does not, stop processing this message pair. + * @param entryContext an entry context. + * @return if receiverHostAndPort from request message log matches + * host & port from WSDL SOAP binding for the Service. + * @throws WSIException if problem occurs during correlation check. + */ + private URI[] hostAndPortCorrelation(EntryContext entryContext) + throws WSIException + { + + // get from request message + String httpHostAndPort = entryContext.getRequest().getReceiverHostAndPort(); + // Search endpoint list for a match with + + /* TEMP: Get it from analyzer config passed in on init method + return entryContext.getAnalyzerContext() + .getCandidateInfo() + .getEndPoints(httpHostAndPort); + */ + return analyzerContext.getCandidateInfo().getEndPoints(httpHostAndPort); + } + + /** + * Correlation Check 2: Service Description endpoint vs HTTP Header (test 2) + * + * Use analyzer config host & port, plus URL path (from request message header HTTP POST) + * to look for the corresponding endpoint in the Service Definition. + * If it does not, stop processing this message pair. + * @param entryContext an entry context. + * @param endpoints an array of endpoints. + * @return true if corresponding endpoints are found in the Service Definition. + * @throws WSIException if problem occurs during correlation check. + */ + private boolean urlPathCorrelation( + EntryContext entryContext, + URI[] endpoints) + throws WSIException + { + + // compares: protocol (must be http for POST), host, port and path. + + // get POST URI path from message using Tokenizer + Vector requestLine = + getHttpRequest(entryContext.getRequest().getHTTPHeaders()); + if (requestLine == null) + { + return false; // an unexpected HTTP request type ! + } + + String requestPath = (String) requestLine.get(1); + // Path immediately follows POST + + // compare path with those in the previous generated URI list + Vector filteredEndpoints = new Vector(); + for (int i = 0; i < endpoints.length; i++) + { + if (endpoints[i].toString().endsWith(requestPath)) + { + filteredEndpoints.add(endpoints[i]); + } + } + + if (filteredEndpoints.size() == 0) + return false; + + // this URI should be unique in the WSDL - there should be at most one match + // but if we have at least one, that's sufficient to accept the message + + return true; + } + + /** + * Correlation Check 3: Service Description namespace. + * + * Determine if the Service Description declares the namespace that appears in the (request?) message soap body. + * Location of relevent namespace : + * Operation type - Message Namespace: (compare with) Service Definition Namespace: + * (from message? endpoint? where?) + * rpc-literal <soap:Body> child namespace. <soapbind:body> namespace. + * doc-literal <soap:Body> child namespace. targetNameSpace of schema that + * defines <soap:body> child. + * If it doesn't match, stop processing this message pair. + * @param binding a binding. + * @param request a request. + * @return true if description declared in the description are the + * same as those that appear in the message soap body. + * @throws WSIException if problem occurs during correlationcheck. + */ + private boolean namespaceCorrelation(Binding binding, Document request) + throws WSIException + { + boolean namespaceFound = false; + String bindingStyle = WSIConstants.ATTRVAL_SOAP_BIND_STYLE_DOC; + + // Get operation namespace from the request soap message + String soapOpNS = getSoapBodyChild(request).getNamespaceURI(); + + // Get soapbind:binding + SOAPBinding soapBinding = null; + if ((soapBinding = WSDLUtils.getSoapBinding(binding)) != null) + { + bindingStyle = soapBinding.getStyle(); + } + + // Go through each operation in the binding and check for namespace match + Iterator operations = binding.getBindingOperations().iterator(); + while (operations.hasNext() && !(namespaceFound)) + { + BindingOperation bindingOperation = (BindingOperation) operations.next(); + + // If rpc-literal, then look at namespace attribute on soapbind:body + if (WSDLUtils.isRpcLiteral(bindingStyle, bindingOperation)) + { + // Get soapbind:body element + SOAPBody soapBody = WSDLUtils.getInputSoapBody(bindingOperation); + + if ((soapBody.getNamespaceURI() != null) + && (soapBody.getNamespaceURI().equals(soapOpNS))) + { + namespaceFound = true; + } + } + + // If doc-literal, then check namespace + else if (WSDLUtils.isDocLiteral(bindingStyle, bindingOperation)) + { + int partCount; + Iterator partsIterator = null; + + // Get first part name from soapbind:body element parts attribute + String partName = getFirstPartName(bindingOperation); + + // Get the list of parts from the message + Map partsMap = null; + if ((partsMap = + bindingOperation.getOperation().getInput().getMessage().getParts()) + != null) + { + partsIterator = partsMap.values().iterator(); + + // If the part name wasn't specified on the soapbind:body element, then process just the first one + if (partName == null) + partCount = 1; + else + partCount = partsMap.size(); + + for (int i = 0; i < partCount && !namespaceFound; i++) + { + // Get next part + Part part = (Part) partsIterator.next(); + + // If part name matches or there is no part name, then check namespace + if ((partName == null) + || ((partName != null) && (part.getName().equals(partName)))) + { + if ((part.getElementName().getNamespaceURI() != null) + && (part.getElementName().getNamespaceURI().equals(soapOpNS))) + { + namespaceFound = true; + } + } + } + } + } + } + + return namespaceFound; + } + + /** + * Correlation Check 4 : Service Description "operation" + * + * Check if the message content matches any of the candidate operation definitions + * for request and response in the Service Description. + * + * For both request and response, look for the soap body child element name + * in the list of candidate operation names. + * @param binding a binding. + * @param requestMessage a request message. + * @return true if the message content matches any of the candidate + * operation definitions for request and response in the + * Service Description. + * @throws WSIException if problem occurs during correlationcheck. + */ + private boolean operationCorrelation( + Binding binding, + Document requestMessage) + throws WSIException + { + boolean operationFound = false; + + String bindingStyle = WSIConstants.ATTRVAL_SOAP_BIND_STYLE_DOC; + + // Get soapbind:binding + SOAPBinding soapBinding = null; + if ((soapBinding = WSDLUtils.getSoapBinding(binding)) != null) + { + bindingStyle = soapBinding.getStyle(); + } + + // Get the first child element from the soap body + Element soapBodyChild = getSoapBodyChild(requestMessage); + + // If there is a child element, then check it + if (soapBodyChild != null) + { + // Get operation name from the soap:body + String operationName = soapBodyChild.getLocalName(); + + // Get operation QName + QName operationQName = + new QName(soapBodyChild.getNamespaceURI(), operationName); + + // Go through each operation in the binding and check for namespace match + Iterator operations = binding.getBindingOperations().iterator(); + while (operations.hasNext() && !(operationFound)) + { + BindingOperation bindingOperation = + (BindingOperation) operations.next(); + + // If rpc-literal, then look at namespace attribute on soapbind:body + if (WSDLUtils.isRpcLiteral(bindingStyle, bindingOperation)) + { + // Get soapbind:body element + if (bindingOperation.getName().equals(operationName)) + operationFound = true; + } + + // If doc-literal, then check namespace + else if (WSDLUtils.isDocLiteral(bindingStyle, bindingOperation)) + { + int partCount; + Iterator partsIterator = null; + + // Get first part name from soapbind:body element parts attribute + String partName = getFirstPartName(bindingOperation); + + // Get the list of parts from the message + Map partsMap = null; + if ((partsMap = + bindingOperation.getOperation().getInput().getMessage().getParts()) + != null) + { + partsIterator = partsMap.values().iterator(); + + // If the part name wasn't specified on the soapbind:body element, then process just the first one + if (partName == null) + partCount = 1; + else + partCount = partsMap.size(); + + for (int i = 0; i < partCount && !operationFound; i++) + { + // Get next part + Part part = (Part) partsIterator.next(); + + // If part name matches or there is no part name, then check namespace + if ((partName == null) + || ((partName != null) && (part.getName().equals(partName)))) + { + if ((part.getElementName() != null) + && (part.getElementName().equals(operationQName))) + { + operationFound = true; + } + } + } + } + } + } + } + + // Go through each operation to find a match + return operationFound; + } + + /** + * Create failure detail. + * @param message a message. + * @param entryContext an entry context. + * @return failure detail. + */ + public FailureDetail createFailureDetail( + String message, + EntryContext entryContext) + { + FailureDetail failureDetail = reporter.createFailureDetail(); + failureDetail.setFailureMessage(message); + failureDetail.setElementLocation( + entryContext.getMessageEntry().getElementLocation()); + return failureDetail; + } + + /* (non-Javadoc) + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl#isNotApplicable(org.wsi.test.profile.TestAssertion) + */ + protected boolean isNotApplicable(TestAssertion testAssertion) + { + boolean notApplicable = false; + + // If the additional entry is not available, then set notApplicable + if (testAssertion.getAdditionalEntryTypeList().getWSDLInput() != null + && !testAssertion.getAdditionalEntryTypeList().getWSDLInput().equals("none") + && analyzerContext.getServiceReference().getWSDLLocation() == null) + { + notApplicable = true; + } + + return notApplicable; + } + + + /** + * Get POST request. + * @param httpHeader an HTTP + * @return POST request. + */ + public Vector getPostRequest(String httpHeader) + { + //Request-Line = Method SP Request-URI SP HTTP-Version CRLF + Vector requestLine = new Vector(); + String startLine = null; + + StringTokenizer httpMessageTokenizer = + new StringTokenizer(httpHeader, "\n\r\f"); + + if (httpMessageTokenizer.hasMoreTokens()) + { + startLine = httpMessageTokenizer.nextToken(); + } + + if (startLine.startsWith("POST")) + { + StringTokenizer startLineTokenizer = + new StringTokenizer(startLine, "\u0020"); + while (startLineTokenizer.hasMoreTokens()) + { + requestLine.add(startLineTokenizer.nextToken()); + } + } + return requestLine; + } + + /** + * Get HTTP request. + * @param httpHeader an HTTP + * @return HTTP request. + */ + private Vector getHttpRequest(String httpHeader) + { + //Request-Line = Method SP Request-URI SP HTTP-Version CRLF + Vector requestLine = new Vector(); + String startLine = null; + + StringTokenizer httpMessageTokenizer = + new StringTokenizer(httpHeader, "\n\r\f"); + + if (httpMessageTokenizer.hasMoreTokens()) + { + startLine = httpMessageTokenizer.nextToken(); + } + + if (startLine.startsWith("POST") || startLine.startsWith("GET")) + { + StringTokenizer startLineTokenizer = + new StringTokenizer(startLine, "\u0020"); + while (startLineTokenizer.hasMoreTokens()) + { + requestLine.add(startLineTokenizer.nextToken()); + } + } + else + { + requestLine = null; // signify not POST or GET + } + + return requestLine; + } + + /** + * Get HTTP request type. + * @param entryContext an entry context. + * @return HTTP request type. + */ + private String getHttpRequestType(EntryContext entryContext) + { + //Request-Line = Method SP Request-URI SP HTTP-Version CRLF + + String httpHeader = entryContext.getRequest().getHTTPHeaders(); + String httpRequestType = null; + String startLine = null; + + StringTokenizer httpMessageTokenizer = + new StringTokenizer(httpHeader, "\n\r\f"); + + if (httpMessageTokenizer.hasMoreTokens()) + { + startLine = httpMessageTokenizer.nextToken(); + StringTokenizer startLineTokenizer = + new StringTokenizer(startLine, "\u0020"); + if (startLineTokenizer.hasMoreTokens()) + { + httpRequestType = startLineTokenizer.nextToken(); + } + } + return httpRequestType; + } + + /** + * Determine if the message is a response for a one-way operation. + * @param entryContext an entry context. + * @return true if the message is a response for a one-way operation. + */ + public boolean isOneWayResponse(EntryContext entryContext) + { + boolean oneway = false; + + // TEMP: If this is a response message and there is no content, then set one-way to true + // TEMP: Need to find a way to determine if the response is for a one-way message + if (entryContext + .getMessageEntry() + .getType() + .equalsIgnoreCase(MessageEntry.TYPE_RESPONSE) + && entryContext.getMessageEntry().getMessage().length() == 0) + { + oneway = true; + } + + return oneway; + } + + /** + * messageIsDocLitSchemaValid. + * + * Validates the doc-lit messages against the schema found in a candidate wsdl document. + * + * Identify (or be given) a reference in the wsdl to elements (found in <wsdl:types><schema>...) + * that are immediate children elements in the soap body. + * @param entryContext an entry context. + * @return true if the document literal message is compliant to the + * schema found in a candidate WSDL document. + * @throws WSIException if there is a parsing problem during validation. + */ + public boolean messageIsDocLitSchemaValid(EntryContext entryContext) + throws WSIException + { + + // This method should use a validating parser that is capable of acceppting multiple schema references + // programmatically. Then, every schema in candidate wsdl can be passed in to the validator. This avoids the + // need to pinpoint a particular schema element from all candidate wsdl:types, corresponding to the + // wsdl:operation being used. The pinpointing is an incomplete workaround for parsers not capable + // of accepting arrays of scehma references + // [ i.e. the DOM factory.setAttribute(JAXP_SCHEMA SOURCE, Object[] {...}) ] + // get all xs:schema from all candidate wsdl:types + // add each to an array and pass this array to the validating parser + // when validating the/each soap body child. + + // use the referenced WSDL file and its imported files to find schemas + List schemaWSDLs = new ArrayList(); + List inlineSchemas = new ArrayList(); + List schemaStrings = new ArrayList(); + + Definition[] allDefs = + analyzerContext.getCandidateInfo().getDefinitions(); + for (int thisDef = 0; thisDef < allDefs.length; thisDef++) + { + schemaWSDLs.add(allDefs[thisDef].getDocumentBaseURI()); + } + Iterator fileIterator = schemaWSDLs.iterator(); + while (fileIterator.hasNext()) + { + // parse file if possible + Document wsdlDoc = null; + String wsdlURI = (String) fileIterator.next(); + try + { + wsdlDoc = XMLUtils.parseXMLDocumentURL(wsdlURI, null); + } + catch (Exception e) + { + continue; + } + Element root = wsdlDoc.getDocumentElement(); + // find the schema + NodeList schemaElements = root.getElementsByTagNameNS( + WSITag.ELEM_XSD_SCHEMA.getNamespaceURI(), + WSITag.ELEM_XSD_SCHEMA.getLocalPart()); + + for (int elem = 0; elem < schemaElements.getLength(); elem++) + { + Element schema = (Element) schemaElements.item(elem); + // copying all the NS declarations from wsdl:definitions wsdl:types + copyNSDeclarations(root, schema); + copyNSDeclarations((Element) schema.getParentNode(), schema); + // Replacing all relative schemaLocation URIs with absolute ones + replaceRelativeURIs(schema, wsdlURI); + inlineSchemas.add(schema); + } + } + + // Note that the Xerces parser ONLY accepts an array + // of schemas with unique namespaces. + if (!duplicateNamespacesDetected(inlineSchemas)) + { + // Serialize the schema elements inside the Types, then use this as + // the schema string for the validation + Iterator i = inlineSchemas.iterator(); + while (i.hasNext()) + { + Element schema = (Element)i.next(); + String schemaString = DOM2Writer.nodeToString(schema); + schemaStrings.add(schemaString); + } + + NodeList elementList = entryContext.getMessageEntryDocument() + .getElementsByTagNameNS(WSITag.ELEM_SOAP_BODY.getNamespaceURI(), + WSITag.ELEM_SOAP_BODY.getLocalPart()); + if (elementList == null || elementList.getLength() != 1) + { + // should only be a single soap body ! + return false; // probably an error condition though + } + + NodeList soapBodyChildList = ((Element)elementList.item(0)).getChildNodes(); + for (int child = 0; child < soapBodyChildList.getLength(); child++) + { + Node soapBodyChild = soapBodyChildList.item(child); + if (soapBodyChild.getNodeType() == Node.ELEMENT_NODE) + { + // do all for now + try + { + // Write out element tree to String + String messageContent = DOM2Writer.nodeToString(soapBodyChild); + // parse the child element, validating against the schema + XMLUtils.parseXML(messageContent, schemaStrings); + } + catch (WSIException e) + { + if (e.getTargetException() instanceof SAXException) + { + // validation failed + throw new WSIException(e.getTargetException().getMessage()); + } + throw e; + } + catch (Exception e) + { + throw new WSIException("Validating Parsing problem", e); + // Bad things have happened + } + } + } + } + return true; + } + + /** + * Copy the namespace declarations. + * @param parent a message. + * @param child a stripped message. + */ + private void copyNSDeclarations(Element parent, Element child) + { + NamedNodeMap nodeMap = parent.getAttributes(); + for (int nodeId = 0; nodeId < nodeMap.getLength(); nodeId++) + { + Node node = nodeMap.item(nodeId); + + if ((node.getNodeType() == Node.ATTRIBUTE_NODE) + && (node.getNodeName().startsWith("xmlns:"))) + { + String nodeName = node.getNodeName(); + // If an NS being copied is not the same as the child element has, copy it + if (!child.getNodeName().startsWith( + nodeName.substring(nodeName.indexOf(":") + 1) + ":")) + { + String nodeValue = node.getNodeValue(); + child.setAttribute(node.getNodeName(), node.getNodeValue()); + } + } + } + } + + /** + * Replaces all relative URIs for schemaLocation attributes. + * @param schema an xsd:schema element. + * @param wsdlURI an URI of WSDL that contains xsd:schema being processed. + */ + private void replaceRelativeURIs(Element schema, String wsdlURI) + { + // Retrieving all xsd:import elements + NodeList imports = schema.getElementsByTagNameNS( + WSITag.ELEM_XSD_IMPORT.getNamespaceURI(), + WSITag.ELEM_XSD_IMPORT.getLocalPart()); + // Going through the elements + for (int i = 0; i < imports.getLength(); i++) + { + Element imp = (Element) imports.item(i); + // Getting the schemaLocation attribute + Attr schemaLocation = + XMLUtils.getAttribute(imp, WSITag.ATTR_XSD_SCHEMALOCATION); + // If the attribute is present + if (schemaLocation != null) + { + // Trying to create an URI object using attribute's value + URI uri = null; + try + { + uri = new URI(schemaLocation.getValue()); + } + catch (Exception e) {} + // If the value is not an absolute URI (the URI constructor throws the + // MalformedURIException), creating the absolute URI using wsdlURI + if (uri == null) + { + String newURI = wsdlURI.substring(0, wsdlURI.lastIndexOf("/") + 1) + + schemaLocation.getValue(); + try + { + uri = new URI(newURI); + // Setting a new URI as a value for the schemaLocation attribute + schemaLocation.setValue(uri.toString()); + } + catch (Exception e) {} + } + } + } + } + + /** + * Returns binding operation matched for SOAP message. + * @param entryType message entry type. + * @param doc a message. + * @return any binding operation matched, null if it is not found. + */ + public BindingOperation getOperationMatch(EntryType entryType, Document doc) + { + BindingOperation bindingOperation = null; + try + { + // Getting the name of the first SOAP Body child element + QName operation = getOperationFromMessage(doc); + if (operation != null) + { + // Retrieving all the RPC binding operations from wsdl:binding + BindingOperation[] rpcBindingOps = getMatchingBindingOps( + WSIConstants.ATTRVAL_SOAP_BIND_STYLE_RPC, + analyzerContext.getCandidateInfo().getBindings()); + // Retrieving binding operation by the given operation name + bindingOperation = getOperationMatch( + entryType, operation, rpcBindingOps); + // If no one RPC operation matched + if(bindingOperation == null) + { + // Retrieving all the document binding operations from wsdl:binding + BindingOperation[] docBindingOperations = getMatchingBindingOps( + WSIConstants.ATTRVAL_SOAP_BIND_STYLE_DOC, + analyzerContext.getCandidateInfo().getBindings()); + // Retrieving binding operation by given element name + BindingOperation[] potentialDocLitOps = + getDocLitOperations(entryType, operation, docBindingOperations); + // If there is exactly one operation matched + if (potentialDocLitOps.length == 1) + bindingOperation = potentialDocLitOps[0]; + } + } + } + catch (Exception e) {} + + return bindingOperation; + } + + /** + * Match either Input or Output. + * @param messageEntryType message entry type. + * @param soapMessage soap message. + * @param op binding operations. + * @return matched operation. + */ + public BindingOperation getOperationMatch( + EntryType messageEntryType, + Document soapMessage, + BindingOperation[] op) + { + // Get operation from message + QName operation = getOperationFromMessage(soapMessage); + // list of QNames + + return getOperationMatch(messageEntryType, operation, op); + } + + /** + * Match either Input or Output. + * @param messageEntryType message entry type. + * @param operation SOAP operation name. + * @param op binding operations. + * @return matched operation. + */ + public BindingOperation getOperationMatch( + EntryType messageEntryType, + QName operation, + BindingOperation[] op) + { + QName checkOperation; + + // Look for a candidate operation in the wsdl that matches this signature. + for (int k = 0; k < op.length; k++) + { + String name = null; + List extensibles = null; + BindingOperation bindingOp = op[k]; + + if (messageEntryType.isType(EntryType.TYPE_MESSAGE_REQUEST) + && (bindingOp.getOperation().getInput() != null)) + { + name = bindingOp.getOperation().getName(); + extensibles = bindingOp.getBindingInput().getExtensibilityElements(); + } + else if ( + messageEntryType.isType(EntryType.TYPE_MESSAGE_RESPONSE) + && (bindingOp.getOperation().getOutput() != null)) + { + name = bindingOp.getOperation().getName() + "Response"; + extensibles = bindingOp.getBindingOutput().getExtensibilityElements(); + } + + // Get soap:body + SOAPBody soapBody = getSoapBody(extensibles); + if (soapBody == null) + checkOperation = new QName(name); + else + checkOperation = new QName(soapBody.getNamespaceURI(), name); + + if (operation != null && operation.equals(checkOperation)) + { + return (bindingOp); + } + } + return null; + } + + /** + * Match either Input or Output. + * @param messageEntryType a message entry type. + * @param soapMessage a soap message. + * @param op binsing operations. + * @return matched operation. + */ + public BindingOperation getOperationPartsMatch( + EntryType messageEntryType, + Document soapMessage, + BindingOperation[] op) + { + Map parts = getPartListFromMessage(soapMessage); // list of QNames + + // Look for a candidate operation in the wsdl that matches this signature. + for (int k = 0; k < op.length; k++) + { + + Message wsdlMessage = null; + List extensibles = null; + BindingOperation bindingOp = op[k]; + + if (messageEntryType.isType(EntryType.TYPE_MESSAGE_REQUEST) + && (bindingOp.getOperation().getInput() != null)) + { + wsdlMessage = bindingOp.getOperation().getInput().getMessage(); + extensibles = bindingOp.getBindingInput().getExtensibilityElements(); + } + else if ( + messageEntryType.isType(EntryType.TYPE_MESSAGE_RESPONSE) + && (bindingOp.getOperation().getOutput() != null)) + { + wsdlMessage = bindingOp.getOperation().getOutput().getMessage(); + extensibles = bindingOp.getBindingOutput().getExtensibilityElements(); + } + //wsdlFaultParts = op[k].getFaults(); + // ADD: check for case when response message is a fault + + if (sameParts(parts, wsdlMessage, getSoapHeader(extensibles))) + { + return (bindingOp); + } + } + return null; + } + + /** + * BindingOperation getOperationPartsMatch(..). + * + * Find one or more matching binding operations from the WSDL corresponding to the + * given request-response signature. + * + * This overloaded version is intended for possible Correlation only (not assertions), + * since it checks for an operation signature on a request-response pair. + * Assertions now check request & response messages independently. + * @param requestMessage a request message. + * @param responseMessage a response message. + * @param op binding operations. + * @return matched operation. + */ + private BindingOperation getOperationPartsMatch( + Document requestMessage, + Document responseMessage, + BindingOperation[] op) + { + Map inParts = getPartListFromMessage(requestMessage); // list of QNames + Map outParts = getPartListFromMessage(responseMessage); + // list of QNames + + // Look for a candidate operation in the wsdl that matches this signature. + for (int k = 0; k < op.length; k++) + { + + //Map wsdlFaultParts = null; + Message wsdlInMessage = null; + Message wsdlOutMessage = null; + + BindingOperation bindingOp = op[k]; + if (bindingOp.getOperation().getInput() != null) + { + wsdlInMessage = bindingOp.getOperation().getInput().getMessage(); + } + + if (bindingOp.getOperation().getOutput() != null) + { + wsdlOutMessage = bindingOp.getOperation().getOutput().getMessage(); + } + //wsdlFaultParts = op[k].getFaults(); + // ADD: check for case when response message is a fault + + if (sameParts(inParts, + wsdlInMessage, + getSoapHeader(bindingOp.getBindingInput().getExtensibilityElements()))) + { + // match on the request - now check response if its not a fault + if (responseMessage != null && isFault(responseMessage)) + { + return (bindingOp); + } + else if ( + sameParts( + outParts, + wsdlOutMessage, + getSoapHeader( + bindingOp.getBindingOutput().getExtensibilityElements()))) + { + // It does match so treat this as a relevant message pair. + // Let the message through for validation. + //ADD: could pass the operations list back to the entryContext for the message. + return (bindingOp); + } + } + } + return null; + } + + /** + * Get the soap:body from a List of extensibility elements. + * @param extElems a list of extensibility elements. + * @return the soap:body from a List of extensibility elements. + */ + private SOAPBody getSoapBody(List extElems) + { + // Find the soap body + if (extElems != null) + { + for (int i = 0; i < extElems.size(); i++) + { + ExtensibilityElement extElem = (ExtensibilityElement) extElems.get(i); + if (extElem.getElementType().equals(WSITag.WSDL_SOAP_BODY)) + { + return (SOAPBody) extElem; + } + // If the element is mime:multipartRelated + else if (extElem.getElementType().equals(WSITag.WSDL_MIME_MULTIPART)) + { + // Getting the mime:part elements of the mime:multipartRelated + List mimeParts = ((MIMEMultipartRelated) extElem).getMIMEParts(); + // Going through all the mime:part elements + for (int j = 0; j < mimeParts.size(); j++) + { + // Collecting all the mime:content elements of this mime:part + SOAPBody soapBody = getSoapBody( + ((MIMEPart) mimeParts.get(j)).getExtensibilityElements()); + if (soapBody != null) + return soapBody; + } + } + } + } + + return null; + } + + /** + * Get the SOAPHeader from a List of extensibility elements. + * @param extensibles a list of extensibility elements. + * @return the SOAPHeader from a List of extensibility elements. + */ + private SOAPHeader getSoapHeader(List extensibles) + { + SOAPHeader soapHeader = null; + + // find the soap header + if (extensibles != null) + { + Iterator i = extensibles.iterator(); + while (i.hasNext() && soapHeader == null) + { + try + { + soapHeader = (SOAPHeader) i.next(); + } + catch (ClassCastException c) + { + } + } + } + return soapHeader; + } + + /** + * Get first part name from soapbind:body element. + */ + private String getFirstPartName(BindingOperation bindingOperation) + { + String partName = null; + List extList = null; + Iterator partsIterator = null; + + // Determine if there is a list of parts by finding the soapbind:body element + if ((extList = + bindingOperation.getBindingInput().getExtensibilityElements()) + != null) + { + List partsList = null; + Iterator extIterator = extList.iterator(); + while (extIterator.hasNext() && (partName == null)) + { + Object extElement = extIterator.next(); + if (extElement instanceof SOAPBody) + { + if ((partsList = ((SOAPBody) extElement).getParts()) != null) + { + partsIterator = partsList.iterator(); + + // Since this is a doc literal binding there should be only one part name + if (partsIterator.hasNext()) + partName = (String) partsIterator.next(); + } + } + } + } + + return partName; + } + + public BindingOperation[] getDocLitOperations( + EntryType messageType, + QName partElementQName, + BindingOperation[] wsdlOperations) + { + + if (messageType.isType(EntryType.ENTRY_TYPE_REQUEST)) + { + return getInputDocLitOperations(partElementQName, wsdlOperations); + } + else if (messageType.isType(EntryType.ENTRY_TYPE_RESPONSE)) + { + return getOutputDocLitOperations(partElementQName, wsdlOperations); + } + else + { + return null; // should be one or the other + } + } + + private BindingOperation[] getInputDocLitOperations( + QName partElementQName, + BindingOperation[] wsdlOperations) + { + + Vector potentialOps = new Vector(); + + for (int i = 0; i < wsdlOperations.length; i++) + { + if (wsdlOperations[i].getOperation().getInput() != null) + { + Message message = wsdlOperations[i].getOperation().getInput().getMessage(); + // If SOAP Body child element is not present and wsdl:message does not have any wsdl:parts, that is the match + if (partElementQName == null) + { + if (message.getParts().isEmpty()) + potentialOps.add(wsdlOperations[i]); + continue; + } + + Iterator partsIt = message.getParts().values().iterator(); + while (partsIt.hasNext()) + { + Part nextPart = (Part) partsIt.next(); + if (partElementQName.equals(nextPart.getElementName())) + { + // matching part found (doc-lit) - add to list of possible operation matches + potentialOps.add(wsdlOperations[i]); + break; + } + } + } + } + return (BindingOperation[]) potentialOps.toArray(new BindingOperation[0]); + } + + private BindingOperation[] getOutputDocLitOperations( + QName partElementQName, + BindingOperation[] wsdlOperations) + { + + Vector potentialOps = new Vector(); + + for (int i = 0; i < wsdlOperations.length; i++) + { + if (wsdlOperations[i].getOperation().getOutput() != null) + { + Message message = wsdlOperations[i].getOperation().getOutput().getMessage(); + // If SOAP Body child element is not present and wsdl:message does not have any wsdl:parts, that is the match + if (partElementQName == null) + { + if (message.getParts().isEmpty()) + potentialOps.add(wsdlOperations[i]); + continue; + } + + Iterator partsIt = message.getParts().values().iterator(); + while (partsIt.hasNext()) + { + Part nextPart = (Part) partsIt.next(); + if (partElementQName.equals(nextPart.getElementName())) + { + // matching part found (doc-lit) - add to list of possible operation matches + potentialOps.add(wsdlOperations[i]); + break; + } + } + } + } + return (BindingOperation[]) potentialOps.toArray(new BindingOperation[0]); + } + + /** + * Compare soap message element part names with Parts from specified wsdl Operation + */ + private boolean sameParts(HashSet messageParts, Map wsdlParts) + { + + // look for the soap-message operation signature + Iterator i = wsdlParts.values().iterator(); + // build a set of Part names + HashSet h = new HashSet(); + while (i.hasNext()) + { + Part p = (Part) i.next(); + h.add(p.getName()); + } + + // compare with the parts list from the message (unordered) + return (h.equals(messageParts)); + } + + /** + * Compare soap message element part names with Parts from specified wsdl Operation + */ + private boolean sameParts( + Map messageParts, + Message wsdlMessage, + SOAPHeader soapHeader) + { + + String soapHeaderPart = null; + if (soapHeader != null) + soapHeaderPart = soapHeader.getPart(); + + // check null conditions + if (messageParts == null && wsdlMessage == null) + { + return true; // simple equality test + } + else if (messageParts == null || wsdlMessage == null) + { + return false; + } + + Vector v = new Vector(); + //List wsdlParts = wsdlMessage.getOrderedParts(null); + Map wsdlParts = null; + if (wsdlMessage.getParts() != null) + { + wsdlParts = wsdlMessage.getParts(); + // look for the soap-message operation signature + Iterator i = wsdlParts.values().iterator(); + // build a set of Part names + while (i.hasNext()) + { + Part p = (Part) i.next(); + // do not include the part for the soap:header (if any) + if (!p.getName().equals(soapHeaderPart)) + { + // check that the part is associated with the soap:body + v.add(new QName(p.getName())); + } + } + // if one of the parts is associated with a soap:header in the binding + // (by ), remove this from the set + + } + + // compare with the parts list from the message (ordered) + if (v.isEmpty() && messageParts.isEmpty()) + { + return true; + } + + // PB: Changed to containsAll() since equals() fails when using JRE 1.4 + if (v.containsAll(messageParts.keySet()) + && (v.size() == messageParts.size())) + { + // Check for xsi:type mismatch + Iterator parts = messageParts.keySet().iterator(); + QName partName, xsiType; + while (parts.hasNext()) + { + partName = (QName) parts.next(); + + // Get xsi:type QName + if ((xsiType = (QName) messageParts.get(partName)) != null + && wsdlParts != null) + { + // Get the WSDL part definition + Part part = (Part) wsdlParts.get(partName.getLocalPart()); + + // If xsiType is NOT derived from the type of the corresponding WSDL part + if (!isDerivedType(xsiType, part.getTypeName())) + { + // return false + return false; + } + } + } + + return true; + } + else + return false; + //return (v.equals(messageParts)); + } + + /** + * Checks whether one schema type is derived from another. + * @param extType an assumed derived type. + * @param type an assumed base type. + * @return true if extType is derived from type, false otherwise + */ + public boolean isDerivedType(QName extType, QName type) + { + // If either of types is null, return false + if (extType == null || type == null) + return false; + // If the types are equal, return true + if (extType.equals(type)) + return true; + + // Going through all schemas + Iterator i = wsdlDocument.getSchemas().values().iterator(); + while (i.hasNext()) + { + XSModel xsModel = (XSModel) i.next(); + // Retrieving the derived type definition + XSTypeDefinition xsType = xsModel.getTypeDefinition( + extType.getLocalPart(), extType.getNamespaceURI()); + // If it is found and derived from the base type, return true + if (xsType != null && xsType.derivedFrom(type.getNamespaceURI(), + type.getLocalPart(), XSConstants.DERIVATION_NONE)) + { + return true; + } + } + // extType is not derived from type, return false + return false; + } + + /** + * Get a list of QNames of parts from the soap body of the specified message + */ + public Element getSoapBodyChild(Document doc) + { + + Element opElem = null; + if (doc != null) + { + Element root = doc.getDocumentElement(); + NodeList bodies = + root.getElementsByTagNameNS(WSIConstants.NS_URI_SOAP, "Body"); + // Get the list of soap:body child element names from the request message + if (bodies != null && bodies.getLength() > 0) + { + Element body = (Element) bodies.item(0); + NodeList children = body.getChildNodes(); + for (int i = 0; i < children.getLength() && opElem == null; ++i) + { + Node n = children.item(i); + if (n instanceof Element) + { + opElem = (Element) n; + } + } + } + } + return opElem; + } + + /** Check whether this message is a soap fault + */ + public boolean isFault(Document doc) + { + boolean isFault = false; + + if (doc != null) + { + Element root = doc.getDocumentElement(); + isFault = + (root + .getElementsByTagNameNS(WSIConstants.NS_URI_SOAP, "Fault") + .getLength() + > 0); + } + + return isFault; + } + + /** + * Check whether this message has a soap body with a child element. + */ + public boolean containsSoapBodyWithChild(Document doc) + { + boolean contains = false; + + if (doc != null) + { + contains = ((getSoapBodyChild(doc) == null) ? false : true); + } + + return contains; + } + + /** + * Get SOAPAction value from the HTTP headers. + * @param headers HTTP headers + * @return SOAPAction value + */ + public String getSoapAction(String headers) throws WSIException + { + // get SOAPAction + String action = null; + if (headers != null) + action = (String) HTTPUtils.getHttpHeaderTokens(headers, ":").get("SOAPAction".toUpperCase()); + return action; + } + + /** + * Get a list of QNames of parts from the soap body of the specified message. + * This method assumes RPC style message content + */ + private QName getOperationFromMessage(Document doc) + { + QName operation = null; + if (doc != null) + { + Element root = doc.getDocumentElement(); + NodeList bodies = + root.getElementsByTagNameNS(WSIConstants.NS_URI_SOAP, "Body"); + if (bodies != null && bodies.getLength() > 0) + { + Element body = (Element) bodies.item(0); + NodeList children = body.getChildNodes(); + for (int i = 0; i < children.getLength(); ++i) + { + Node n = children.item(i); + // If element, then this is the operation name + if (n instanceof Element) + { + operation = new QName(n.getNamespaceURI(), n.getLocalName()); + } + } + } + } + + return operation; + } + + /** + * Get a list of QNames of parts from the soap body of the specified message. + * This method assumes RPC style message content + */ + private Map getPartListFromMessage(Document doc) + { + Map parts = new HashMap(); + if (doc != null) + { + Element root = doc.getDocumentElement(); + NodeList bodies = + root.getElementsByTagNameNS(WSIConstants.NS_URI_SOAP, "Body"); + // Get the list of soap:body grand-child element names from the request message + // (immediate child is the message name) + if (bodies != null && bodies.getLength() > 0) + { + Element body = (Element) bodies.item(0); + NodeList children = body.getChildNodes(); + for (int i = 0; i < children.getLength(); ++i) + { + Node n = children.item(i); + if (n instanceof Element) + { + // this is the operation name. Its children are the parts + NodeList grandChildren = n.getChildNodes(); + for (int j = 0; j < grandChildren.getLength(); j++) + { + Node m = grandChildren.item(j); + if (m instanceof Element) + { + // Determine if the part has an xsi:type + Attr attr = + XMLUtils.getAttribute( + (Element) m, + new QName(WSIConstants.NS_URI_XSI, "type")); + + QName xsiType = null; + + // If there is an xsi:type attribute, then get the value as a QName + try + { + if (attr != null) + xsiType = + DOMUtils.getQName(attr.getNodeValue(), (Element) m); + } + catch (javax.wsdl.WSDLException we) + { + } + + // add to the child element list + parts.put( + new QName(m.getNamespaceURI(), m.getLocalName()), + xsiType); + } + } + } + } + } + } + return parts; + } + + public BindingOperation[] getMatchingBindingOps( + String bindingStyle, + Binding[] bindings) + throws WSIException + { + + HashSet bindingOperationsSet = new HashSet(); + + // whizz through the bindings, checking for a bindingOperation matching the message + for (int i = 0; i < bindings.length; i++) + { + + Binding tryBinding = bindings[i]; + List bindingOps = tryBinding.getBindingOperations(); + + if (bindingOps != null) + { + + // search through binding Operations + Iterator bindingOpIt = tryBinding.getBindingOperations().iterator(); + while (bindingOpIt.hasNext()) + { + + BindingOperation bindingOp = (BindingOperation) bindingOpIt.next(); + // check depends on which binding style is declared in the wsdl + SOAPOperation soapOp = WSDLValidatorImpl.getSoapOperation(bindingOp); + //GT: move this method to utils + + String style; + if ((soapOp == null) || (style = soapOp.getStyle()) == null) + { + // use the style of the parent bindingOp + + SOAPBinding soapBind = WSDLValidatorImpl.getSoapBinding(tryBinding); + //GT: move this method to utils + if ((style = soapBind.getStyle()) == null) + { + style = WSIConstants.ATTRVAL_SOAP_BIND_STYLE_DOC; + //default + } + } + if (style.equals(bindingStyle)) + { + + bindingOperationsSet.add(bindingOp); + + } + } + } // current binding has no bindingOperations, ignore + } + return (BindingOperation[]) bindingOperationsSet.toArray( + new BindingOperation[0]); + } + + /** + * Checks whether soap:body element is literal. + * @param extElements extensibility elements of wsdl:input or wsdl:output + * of a binding + */ + public boolean isLiteral(List extElems) + { + SOAPBody soapBody = getSOAPBody(extElems); + if (soapBody != null + && soapBody.getUse().equals(WSIConstants.ATTRVAL_SOAP_BODY_USE_LIT)) + return true; + else + return false; + } + + /** + * Orders wsdl:part names keeping in mind the "parts" attribute of WSDL soap:body + * @param messageParts a list of wsdl:partS + * @param extElems extensibility elements in the binding + * @return the ordered list of part names + */ + public List orderPartNames(List messageParts, List extElems) + { + List orderedPartNames = new ArrayList(); + List bodyParts = null; + + SOAPBody soapBody = getSOAPBody(extElems); + if (soapBody != null) + bodyParts = soapBody.getParts(); + + Iterator i = messageParts.iterator(); + while (i.hasNext()) + { + String partName = ((Part) i.next()).getName(); + // If the parts attribute is not specified or contains + // the wsdl:part name, then adding part name to the ordered list + if (bodyParts == null || bodyParts.contains(partName)) + orderedPartNames.add(partName); + } + + return orderedPartNames; + } + + /** + * Retrieves the SOAPBody object from a list of extensibility elments in binding + * @param extElems extensibility elements + * @return the SOAPBody element + */ + public SOAPBody getSOAPBody(List extElems) + { + if (extElems == null) + return null; + for (Iterator i = extElems.iterator(); i.hasNext();) + { + Object obj = i.next(); + if (obj instanceof SOAPBody) + return (SOAPBody) obj; + } + + return null; + } + + public List resolveSameNamespaces(List schemaElements) + { + List namespaces = new ArrayList(); + List result = new ArrayList(); + Iterator i = schemaElements.iterator(); + while (i.hasNext()) + { + Element schema = (Element) i.next(); + String targetNamespace = schema.getAttribute(Constants.ATTR_TARGET_NAMESPACE); + if (!namespaces.contains(targetNamespace)) + { + namespaces.add(targetNamespace); + List schemas = getSchemasWithSameNamespace(schemaElements, targetNamespace); + if (schemas.size() == 1) + { + result.add(schema); + } + else + { + // copying all the NS declarations from wsdl:definitions wsdl:types + //copyNSDeclarations(root, schema); + copyNSDeclarations((Element) schema.getParentNode(), schema); + // Replacing all relative schemaLocation URIs with absolute ones + //replaceRelativeURIs(schema, wsdlURI); + // Serialize the schema elements inside the Types, then use this as + // the schema string for the validation + String schemaString = + DOM2Writer.nodeToString(schema); + // schemaStrings.add(schemaString); + } + } + } + return null; + } + + public List getSchemasWithSameNamespace(List schemaElements, String targetNamespace) + { + List result = new ArrayList(); + Iterator i = schemaElements.iterator(); + while (i.hasNext()) + { + Element schema = (Element)i.next(); + String schemaTargetNamespace = schema.getAttribute(Constants.ATTR_TARGET_NAMESPACE); + if (schemaTargetNamespace == null) + schemaTargetNamespace = ""; + + if (schemaTargetNamespace.equals(targetNamespace)) + { + result.add(schema); + } + } + return result; + } + + public boolean duplicateNamespacesDetected(List schemaElements) + { + boolean result = false; + List namespaces = new ArrayList(); + Iterator i = schemaElements.iterator(); + while (i.hasNext()) + { + Element schema = (Element)i.next(); + String targetNamespace = schema.getAttribute(Constants.ATTR_TARGET_NAMESPACE); + if (targetNamespace == null) + targetNamespace = ""; + + if (namespaces.contains(targetNamespace)) + { + result = true; + break; + } + else + { + namespaces.add(targetNamespace); + } + } + return result; + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/BaseValidatorImpl.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/BaseValidatorImpl.java new file mode 100644 index 000000000..d16933beb --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/BaseValidatorImpl.java @@ -0,0 +1,714 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl; + +import java.util.HashMap; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.TreeMap; +import java.util.Vector; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.analyzer.AnalyzerContext; +import org.eclipse.wst.wsi.internal.profile.ProfileArtifact; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.BaseValidator; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.EnvelopeValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.report.Entry; +import org.eclipse.wst.wsi.internal.report.FailureDetail; +import org.eclipse.wst.wsi.internal.report.PrereqFailedList; +import org.eclipse.wst.wsi.internal.report.ReportArtifact; +import org.eclipse.wst.wsi.internal.report.Reporter; +import org.eclipse.wst.wsi.internal.report.impl.PrereqFailedListImpl; +import org.eclipse.wst.wsi.internal.util.EntryType; +import org.eclipse.wst.wsi.internal.xml.XMLDocumentCacheUser; +import org.eclipse.wst.wsi.internal.xml.dom.ElementLocation; + +/** + * The WSDL validator will verify that the WSDL and associated XML schema definitions + * are in conformance with the profile. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + * @author Graham Turrell (gturrell@uk.ibm.com) + */ +public abstract class BaseValidatorImpl + extends XMLDocumentCacheUser + implements BaseValidator +{ + + /** + * A hashtable that maps assertion results to their priorities, 0 is lowest + */ + private static final Hashtable resultPriority = new Hashtable(6); + static { + resultPriority.put(AssertionResult.RESULT_PASSED, new Integer(0)); + resultPriority.put(AssertionResult.RESULT_NOT_APPLICABLE, new Integer(1)); + resultPriority.put(AssertionResult.RESULT_MISSING_INPUT, new Integer(2)); + resultPriority.put(AssertionResult.RESULT_WARNING, new Integer(3)); + resultPriority.put(AssertionResult.RESULT_PREREQ_FAILED, new Integer(4)); + resultPriority.put(AssertionResult.RESULT_FAILED, new Integer(5)); + } + + /** + * The highest priority value being passed when processing pre-requisites + */ + private static final int MAX_VALID_PRIORITY = 1; + + /** + * Analyzer context. + */ + public AnalyzerContext analyzerContext; + + /** + * Profile artifact. + */ + protected ProfileArtifact profileArtifact; + + /** + * Reporter. + */ + protected Reporter reporter; + + /** + * Entry. + */ + // protected Entry entry; + + /** + * Report artifact. + */ + protected ReportArtifact reportArtifact; + + /** + * Verbose option. + */ + public boolean verboseOption = false; + + /** + * Test assertion processed count. + */ + protected int assertionCount = 0; + + /** + * Constructor. + */ + public BaseValidatorImpl() + { + } + + /** + * Initiailize validation test procedure. + * @param analyzerContext the analyzerContext. + * @param profileArtifact the profile artifiact. + * @param reportArtifact the report artifact. + * @param reporter a Reporter object. + * @throws WSIException if validator could not be initialized. + */ + public void init( + AnalyzerContext analyzerContext, + ProfileArtifact profileArtifact, + ReportArtifact reportArtifact, + Reporter reporter) + throws WSIException + { + // Save input references + this.analyzerContext = analyzerContext; + this.profileArtifact = profileArtifact; + this.reportArtifact = reportArtifact; + this.reporter = reporter; + + // Make sure that the XML document cache is updated in the analyzer context + this.documentList = this.analyzerContext.getDocumentList(); + + // Get verbose option + verboseOption = + reporter + .getReport() + .getReportContext() + .getAnalyzer() + .getAnalyzerConfig() + .getVerboseOption(); + } + + /** + * Process all of the test assertions for one entry. + * @param classPrefix a class prefix. + * @param entryContext an entry context. + * @throws WSIException if serious problems occur while processing + * all of the test assertions for an entry. + */ + protected void processAssertions( + String classPrefix, + EntryContext entryContext) + throws WSIException + { + long startTime = 0; + + HashMap processList = new HashMap(); + TestAssertion testAssertion = null; + AssertionProcess assertionProcess; + AssertionResult assertionResult; + + TreeMap preReqResults; + PrereqFailedList prereqFailedList; + String preReqId; + + Class[] paramTypes = new Class[1]; + // If this is an instance of MessageValidator or EnvelopeValidator + // then use BaseMessageValidator as a param type of assertions constructor + paramTypes[0] = this instanceof BaseMessageValidator ? + BaseMessageValidator.class : this.getClass(); + + Object[] params = new Object[1]; + params[0] = this; + + // Get entry from context + Entry entry = entryContext.getEntry(); + + // Add entry to artifact + this.reportArtifact.addEntry(entry); + + // Add entry to report + if (this instanceof EnvelopeValidator) + this.reporter.setCurrentEnvelopeEntry(entry); + else this.reporter.setCurrentEntry(entry); + + try + { + // Go through the list of test assertions for the artifact + Iterator iterator = profileArtifact.getTestAssertionList().iterator(); + while (iterator.hasNext()) + { + // Get next test assertion + testAssertion = (TestAssertion) iterator.next(); + + // Reset variables + assertionResult = null; + + // If the test assertion is enabled, then continue + // if ((testAssertion.isEnabled()) && + // testAssertion.getEntryTypeName().equals(targetContext.getEntry().getEntryType().getTypeName())) { + if (testAssertion.isEnabled() + && isPrimaryEntryTypeMatch(testAssertion, entryContext)) + { + try + { + // Add 1 to assertion processed count + assertionCount++; + + // If the assertion process hasn't been created yet, then create it + if ((assertionProcess = + (AssertionProcess) processList.get(testAssertion.getId())) + == null) + { + + // Create a new assertion process + Class assertionClass = + Class.forName(classPrefix + testAssertion.getId()); + + assertionProcess = + (AssertionProcess) assertionClass.getConstructor( + paramTypes).newInstance( + params); + + // Add it to the list + processList.put(testAssertion.getId(), assertionProcess); + } + + // Check whether entry is null + if (entry.getEntryDetail() == null) + { + assertionResult = + createAssertionResult( + testAssertion, + AssertionResult.RESULT_MISSING_INPUT, + (String) null); + } + + // Check to see if the test assertion should be run + //if (isNotApplicable(testAssertion, entryContext)) { + else if (isNotApplicable(testAssertion)) + { + assertionResult = + createAssertionResult( + testAssertion, + AssertionResult.RESULT_NOT_APPLICABLE, + (String) null); + } + else + { + // Processing all the assertion pre-requisites + + preReqResults = null; + prereqFailedList = null; + // Get list of pre-reqs for specified assertion + Iterator i = testAssertion.getPrereqIdList().iterator(); + while (i.hasNext()) + { + if (preReqResults == null) + preReqResults = new TreeMap(); + // Get next id + preReqId = (String) i.next(); + // Get the prereq result + AssertionResult preReqResult = reporter.getAssertionResult(preReqId); + + // Adding a result priority value to preReqResults + preReqResults.put( + resultPriority.get(preReqResult.getResult()), + preReqResult.getResult()); + + // If the prereq failed, then add it to the list + if (((Integer)resultPriority.get(preReqResult.getResult())).intValue() + > MAX_VALID_PRIORITY) + { + // Adding failed prereq ID to the list + if (prereqFailedList == null) + prereqFailedList = new PrereqFailedListImpl(); + prereqFailedList.addTestAssertionID(preReqId); + } + } + + if (prereqFailedList != null) { + // Getting the highest pre-requisites' result + Integer maxRes = (Integer)preReqResults.lastKey(); + String resString = (String)preReqResults.get(maxRes); + if (resString.equals(AssertionResult.RESULT_FAILED) + ||resString.equals(AssertionResult.RESULT_WARNING)) { + resString = AssertionResult.RESULT_PREREQ_FAILED; + } + // Create assertion result based on pre-requisites which are not passed + assertionResult = createAssertionResult(testAssertion, resString, prereqFailedList); + } + + // Pre-requisites are passed, validate current assertion + else { + + // Reset test assertion + assertionProcess.reset(); + + // VERBOSE + if (verboseOption) + { + System.err.println( + " Processing " + + testAssertion.getId() + + " for entry reference ID [" + + entry.getReferenceID() + + "] ..."); + startTime = System.currentTimeMillis(); + } + + // Validate the target + assertionResult = + assertionProcess.validate(testAssertion, entryContext); + + // Make sure that the XML document cache is updated in the analyzer context + this.analyzerContext.setDocumentList(documentList); + + // VERBOSE + if (verboseOption) + { + System.err.println( + " Elapsed time: " + + (System.currentTimeMillis() - startTime) + + "ms"); + } + } + } + + // Add result to the report + reporter.addAssertionResult(assertionResult); + } + + catch (ClassNotFoundException cnfe) + { + // DEBUG: + if (testAssertion != null) + { + reporter + .getReport() + .getReportContext() + .getAnalyzer() + .printMessage( + "WARNING: " + + testAssertion.getId() + + " is not supported currently."); + } + } + } + } + } + + catch (Exception e) + { + System.err.println("EXECEPTION: " + e.getMessage()); + if (verboseOption) + e.printStackTrace(); + + if (e instanceof WSIException) + throw (WSIException) e; + else + throw new WSIException(e.getMessage(), e); + } + + finally + { + // Indicate that we are done with this assertion target + this.reporter.endCurrentEntry(); + } + } + + /** + * Determine if the test assertion should be processed for the current entry. + * @param testAssertion a test assertion. + * @param entryContext the entry context. + * @return true if the test assertion should be processed for the current entry. + */ + protected abstract boolean isPrimaryEntryTypeMatch( + TestAssertion testAssertion, + EntryContext entryContext); + + /** + * Determine if the test assertion should be processed for the current entry. + * @param testAssertion a test assertion. + * @param entry an Entry object + * @return true if the test assertion should be processed for the current entry. + */ + protected boolean isPrimaryEntryTypeMatch( + TestAssertion testAssertion, + Entry entry) + { + boolean match = false; + + // If the test assertion entry type matches the target context entry type, then contine + if (testAssertion + .getEntryTypeName() + .equals(entry.getEntryType().getTypeName())) + { + match = true; + } + + return match; + } + + /** + * Determine if the test assertion is not applicable. + * @param testAssertion a test assertion. + * @return true if the test assertion is not applicable. + */ + protected abstract boolean isNotApplicable(TestAssertion testAssertion); + + /* (non-Javadoc) + * @see org.wsi.test.profile.validator.BaseValidator#cleanup() + */ + public void cleanup() throws WSIException + { + // If no assertions were processed, then set all missingInput + if (assertionCount == 0) + setAllMissingInput(); + + // Set cached document list in case it was updated + this.analyzerContext.setDocumentList(this.documentList); + } + + /** + * Create assertion result. + * @param testAssertion a test assertion. + * @param result a String object. + * @param failureDetail a FailureDetail object. + * @return newly created test result. + */ + public AssertionResult createAssertionResult( + TestAssertion testAssertion, + String result, + FailureDetail failureDetail) + { + Vector failureDetailList = null; + + // Create failure detail list + if (failureDetail != null) + { + failureDetailList = new Vector(); + failureDetailList.add(failureDetail); + } + + return createAssertionResult(testAssertion, result, failureDetailList); + } + + /** + * Create assertion result. + * @param testAssertion a test assertion. + * @param result a String object. + * @param failureDetailMessage a failure detail message. + * @return newly created test result. + */ + public AssertionResult createAssertionResult( + TestAssertion testAssertion, + String result, + String failureDetailMessage) + { + return createAssertionResult( + testAssertion, + result, + failureDetailMessage, + null); + } + + /** + * Create assertion result. + * @param testAssertion a test assertion. + * @param result a String object. + * @param failureDetailMessage a failure detail message. + * @param elementLocation element location. + * @return newly created test result. + */ + public AssertionResult createAssertionResult( + TestAssertion testAssertion, + String result, + String failureDetailMessage, + ElementLocation elementLocation) + { + // Create failure detail list + Vector failureDetailList = null; + if (failureDetailMessage != null) + { + failureDetailList = new Vector(); + FailureDetail failureDetail = reporter.createFailureDetail(); + failureDetail.setFailureMessage(failureDetailMessage); + failureDetail.setElementLocation(elementLocation); + failureDetailList.add(failureDetail); + } + + return createAssertionResult(testAssertion, result, failureDetailList); + } + + /** + * Create assertion result. + * @param testAssertion a test assertion. + * @param result a String object. + * @param failureDetailList a failure detail list. + * @return newly created test result. + */ + public AssertionResult createAssertionResult( + TestAssertion testAssertion, + String result, + Vector failureDetailList) + { + // Create assertion result + AssertionResult assertionResult = reporter.createAssertionResult(); + + // Set values in assertion result + assertionResult.setAssertion(testAssertion); + assertionResult.setResult(result); + assertionResult.setEntry(reporter.getReport().getCurrentEntry()); + + // Set failure detail list + assertionResult.setFailureDetailList(failureDetailList); + + return assertionResult; + } + + /** + * Create assertion result. + * @param testAssertion a test assertion. + * @param result a String object. + * @param prereqFailedList a list failed pre-requisite assertions. + * @return newly created test result. + */ + public AssertionResult createAssertionResult( + TestAssertion testAssertion, + String result, + PrereqFailedList prereqFailedList) + { + // Create assertion result + AssertionResult assertionResult = reporter.createAssertionResult(); + + // Set values in assertion result + assertionResult.setAssertion(testAssertion); + assertionResult.setResult(result); + assertionResult.setEntry(reporter.getReport().getCurrentEntry()); + assertionResult.setPrereqFailedList(prereqFailedList); + + return assertionResult; + } + + /** + * Add assertion result to report. + * @param assertionId assertion id. + * @param result assertion result. + * @throws WSIException if the assertion result cannot be added to the report. + */ + protected void addAssertionResult(String assertionId, String result) + throws WSIException + { + // Create test assertion result + AssertionResult assertionResult = reporter.createAssertionResult(); + + // Set assertion, result and target + assertionResult.setAssertion(profileArtifact.getTestAssertion(assertionId)); + assertionResult.setResult(result); + assertionResult.setEntry(reporter.getReport().getCurrentEntry()); + + // Add it to the report + reporter.addAssertionResult(assertionResult); + } + + /** + * Add assertion result to report with an error detail message. + * @param assertionId assertion id. + * @param result assertion result. + * @param failureDetailMessage an error detail message. + * @throws WSIException if the assertion result cannot be added to the report. + */ + protected void addAssertionResult( + String assertionId, + String result, + String failureDetailMessage) + throws WSIException + { + // Convert message to vector + Vector failureDetailList = null; + if (failureDetailMessage != null) + { + failureDetailList = new Vector(); + FailureDetail failureDetail = reporter.createFailureDetail(); + failureDetailList.add(failureDetail); + } + + // Add assertion result + addAssertionResult(assertionId, result, failureDetailList); + } + + /** + * Add assertion result to report. + * @param assertionId assertion id. + * @param result assertion result. + * @param failureDetailList a list of error detail messages. + * @throws WSIException if the assertion result cannot be added to the report. + */ + protected void addAssertionResult( + String assertionId, + String result, + Vector failureDetailList) + throws WSIException + { + // Create test assertion result + AssertionResult assertionResult = reporter.createAssertionResult(); + + // Set assertion, result and target + assertionResult.setAssertion(profileArtifact.getTestAssertion(assertionId)); + assertionResult.setResult(result); + assertionResult.setEntry(reporter.getReport().getCurrentEntry()); + assertionResult.setFailureDetailList(failureDetailList); + + // Add it to the report + reporter.addAssertionResult(assertionResult); + } + + /** + * Add missingInput assertion result to report. + * @param testAssertion a test assertion. + * @throws WSIException if there is any problem adding missingInput + * assertion result to report. + */ + protected void addMissingInputResult(TestAssertion testAssertion) + throws WSIException + { + // Create test assertion result + AssertionResult assertionResult = reporter.createAssertionResult(); + + // Set assertion, result and target + assertionResult.setAssertion(testAssertion); + assertionResult.setResult(AssertionResult.RESULT_MISSING_INPUT); + assertionResult.setEntry(reporter.getReport().getCurrentEntry()); + + // Add it to the report + reporter.addAssertionResult(assertionResult); + } + + /* (non-Javadoc) + * @see org.wsi.test.profile.validator.BaseValidator#setAllMissingInput() + */ + public void setAllMissingInput() throws WSIException + { + // If profile artifact is set + if (profileArtifact != null) + { + TestAssertion testAssertion; + + // Create entry + Entry entry = this.reporter.getReport().createEntry(); + entry.setArtifactName(this.reportArtifact.getType().getTypeName()); + + // Add entry to artifact + this.reportArtifact.addEntry(entry); + + // Add entry to report + this.reporter.setCurrentEntry(entry); + + // Go through the list of test assertions for the artifact + Iterator iterator = profileArtifact.getTestAssertionList().iterator(); + while (iterator.hasNext()) + { + // Get next test assertion + testAssertion = (TestAssertion) iterator.next(); + + // Add missingInput result + if (testAssertion.isEnabled()) + addMissingInputResult(testAssertion); + } + + // Indicate that we are done with this assertion target + this.reporter.endCurrentEntry(); + } + } + + /** + * Set all results for an entry type to missingInput. + * @param entryType an EntryType object. + * @throws WSIException if there is any problem while processing. + */ + protected void setMissingInput(EntryType entryType) throws WSIException + { + TestAssertion testAssertion; + + // Create entry + Entry entry = this.reporter.getReport().createEntry(); + entry.setEntryType(entryType); + entry.setReferenceID("[" + entryType.getTypeName() + "]"); + + // Add entry to artifact + this.reportArtifact.addEntry(entry); + + // Add entry to report + this.reporter.setCurrentEntry(entry); + + //try { + // Go through the list of test assertions for the artifact + Iterator iterator = profileArtifact.getTestAssertionList().iterator(); + while (iterator.hasNext()) + { + // Get next test assertion + testAssertion = (TestAssertion) iterator.next(); + if (testAssertion.isEnabled() + && isPrimaryEntryTypeMatch(testAssertion, entry)) + { + addMissingInputResult(testAssertion); + } + } + + // Indicate that we are done with this entry + this.reporter.endCurrentEntry(); + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/ProfileValidatorFactoryImpl.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/ProfileValidatorFactoryImpl.java new file mode 100644 index 000000000..14a147d09 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/ProfileValidatorFactoryImpl.java @@ -0,0 +1,75 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.profile.validator.EnvelopeValidator; +import org.eclipse.wst.wsi.internal.profile.validator.MessageValidator; +import org.eclipse.wst.wsi.internal.profile.validator.ProfileValidatorFactory; +import org.eclipse.wst.wsi.internal.profile.validator.UDDIValidator; +import org.eclipse.wst.wsi.internal.profile.validator.WSDLValidator; +import org.eclipse.wst.wsi.internal.profile.validator.impl.envelope.EnvelopeValidatorImpl; +import org.eclipse.wst.wsi.internal.profile.validator.impl.message.MessageValidatorImpl; +import org.eclipse.wst.wsi.internal.profile.validator.impl.uddi.UDDIValidatorImpl; +import org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl.WSDLValidatorImpl; + +/** + * This class is an implementation of the WSILDocumentFactory. + * + * @version 1.0.1 + * @author: Peter Brittenham + */ +public class ProfileValidatorFactoryImpl extends ProfileValidatorFactory +{ + /* (non-Javadoc) + * @see org.wsi.test.profile.validator.ProfileValidatorFactory#newUDDIValidator() + */ + public UDDIValidator newUDDIValidator() throws WSIException + { + // Create new UDDI validator + UDDIValidator uddiValidator = new UDDIValidatorImpl(); + // Return validator + return uddiValidator; + } + /* (non-Javadoc) + * @see org.wsi.test.profile.validator.ProfileValidatorFactory#newWSDLValidator() + */ + public WSDLValidator newWSDLValidator() throws WSIException + { + // Create new WSDL validator + WSDLValidator wsdlValidator = new WSDLValidatorImpl(); + + // Return validator + return wsdlValidator; + } + + /* (non-Javadoc) + * @see org.wsi.test.profile.validator.ProfileValidatorFactory#newMessageValidator() + */ + public MessageValidator newMessageValidator() throws WSIException + { + // Create new message validator + MessageValidator messageValidator = new MessageValidatorImpl(); + // Return validator + return messageValidator; + } + + /* (non-Javadoc) + * @see org.wsi.test.profile.validator.ProfileValidatorFactory#newEnvelopeValidator() + */ + public EnvelopeValidator newEnvelopeValidator() throws WSIException + { + // Create new envelope validator + EnvelopeValidator envelopeValidator = new EnvelopeValidatorImpl(); + // Return validator + return envelopeValidator; + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/AP1920.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/AP1920.java new file mode 100644 index 000000000..7208b14ef --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/AP1920.java @@ -0,0 +1,118 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.envelope; + +import java.util.List; + +import javax.wsdl.BindingOperation; +import javax.wsdl.extensions.mime.MIMEMultipartRelated; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.WSITag; +import org.eclipse.wst.wsi.internal.analyzer.AssertionNotApplicableException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.EntryType; + +/** + * AP1920 + * + * For an envelope in a response message + * containing a soap:Fault element + * In a description, if and only if, the wsdl:output + * element is described using WSDL MIME binding, then the envelope in the + * response message can contain faults with attachments. + */ +public class AP1920 extends AssertionProcess +{ + private final BaseMessageValidator validator; + + /** + * @param WSDLValidatorImpl + */ + public AP1920(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + /* Validates the test assertion. + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + try + { + if (!entryContext.getMessageEntry().isMimeContent()) + { + throw new AssertionNotApplicableException(); + } + + // check for a fault element within the message + if((entryContext.getMessageEntryDocument() == null) || + entryContext.getMessageEntryDocument(). + getElementsByTagNameNS(WSITag.ELEM_SOAP_FAULT.getNamespaceURI(), + WSITag.ELEM_SOAP_FAULT.getLocalPart()).getLength() != 1) + throw new AssertionNotApplicableException(); + + BindingOperation bindingOperation = validator.getOperationMatch( + EntryType.getEntryType(EntryType.TYPE_MESSAGE_REQUEST), + entryContext.getRequestDocument()); + + // If there is no matched operation, the assertion is not applicable + if (bindingOperation == null) + throw new AssertionNotApplicableException(); + // If the envelope in a response message contains a fault with attachments + // and the corresponding wsdl:output element in the description is not + // described using the WSDL MIME binding, the assertion is failed + if ((entryContext.getMessageEntry().getMimeParts().count() > 1) && + (getMultipartRelatedBindings(bindingOperation) == null)) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = + validator.createFailureDetail("The message contains \"" + + entryContext.getMessageEntry().getMimeParts().count() + "\" part(s)", + entryContext); + } + } + catch(AssertionNotApplicableException e) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + // Return assertion result + return validator.createAssertionResult( + testAssertion, result, failureDetail); + } + + /** + * Returns Multipart related bindings, if does not found, returns null. + * @param op binding operation + * @return Multipart related bindings, if does not found, returns null. + */ + private MIMEMultipartRelated getMultipartRelatedBindings( + BindingOperation op) + { + // Finding operation extensibility elems + // in the binding depending on message type + List extElems = op.getBindingOutput().getExtensibilityElements(); + // check list on first element + if((extElems == null) || (extElems.size() == 0) || + !(extElems.get(0) instanceof MIMEMultipartRelated)) + return null; + return (MIMEMultipartRelated) extElems.get(0); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/AP1928.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/AP1928.java new file mode 100644 index 000000000..7ebabf1c6 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/AP1928.java @@ -0,0 +1,426 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.envelope; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import javax.wsdl.BindingOperation; +import javax.wsdl.Message; +import javax.wsdl.Part; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.UnknownExtensibilityElement; +import javax.wsdl.extensions.mime.MIMEMultipartRelated; +import javax.wsdl.extensions.mime.MIMEPart; +import javax.wsdl.extensions.soap.SOAPBody; +import javax.wsdl.extensions.soap.SOAPHeader; +import javax.xml.namespace.QName; + +import org.apache.xerces.xs.XSComplexTypeDefinition; +import org.apache.xerces.xs.XSConstants; +import org.apache.xerces.xs.XSElementDeclaration; +import org.apache.xerces.xs.XSModel; +import org.apache.xerces.xs.XSModelGroup; +import org.apache.xerces.xs.XSObjectList; +import org.apache.xerces.xs.XSParticle; +import org.apache.xerces.xs.XSTerm; +import org.apache.xerces.xs.XSTypeDefinition; +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.WSITag; +import org.eclipse.wst.wsi.internal.analyzer.AssertionFailException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionNotApplicableException; +import org.eclipse.wst.wsi.internal.log.MessageEntry; +import org.eclipse.wst.wsi.internal.log.MimePart; +import org.eclipse.wst.wsi.internal.log.MimeParts; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.MIMEConstants; +import org.eclipse.wst.wsi.internal.util.MIMEUtils; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +/** + * AP1928 + * + * For a candidate envelope containing a URI reference + * that is typed using the ref:swaRef schema type + * In an envelope, a URI reference that is typed using + * the ref:swaRef schema type resolves to a MIME part in the same message + * as the envelope. + */ +public class AP1928 extends AssertionProcess implements WSITag +{ + private final BaseMessageValidator validator; + + /** + * @param WSDLValidatorImpl + */ + public AP1928(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + /* Validates the test assertion. + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + try + { + if (!entryContext.getMessageEntry().isMimeContent()) + { + throw new AssertionNotApplicableException(); + } + // get the rrot part of a multipart/related message + Document root = entryContext.getMessageEntryDocument(); + MimeParts mimeParts = entryContext.getMessageEntry().getMimeParts(); + + // get an operation matched for the message + BindingOperation bindingOperation = validator.getOperationMatch( + entryContext.getEntry().getEntryType(), root); + + // if no one operation matches, the assertion is not applicable + if (bindingOperation == null) + throw new AssertionNotApplicableException(); + + // get the corresponding extensibility elements and message + List extElems; + Message message; + if (MessageEntry.TYPE_REQUEST + .equals(entryContext.getEntry().getEntryType())) + { + extElems = bindingOperation.getBindingInput() == null ? null + : bindingOperation.getBindingInput().getExtensibilityElements(); + message = bindingOperation.getOperation().getInput() == null ? null + : bindingOperation.getOperation().getInput().getMessage(); + } + else + { + extElems = bindingOperation.getBindingOutput() == null ? null + : bindingOperation.getBindingOutput().getExtensibilityElements(); + message = bindingOperation.getOperation().getOutput() == null ? null + : bindingOperation.getOperation().getOutput().getMessage(); + } + + // If there are no extensibility elements in the WSDL binding operation, + // the assertion is not applicable + if (extElems == null || extElems.size() < 1) + throw new AssertionNotApplicableException(); + + // Collecting the names of schema elements that are defined + // with the ref:swaRef schema type + List swaRefs = getSwaRefs((ExtensibilityElement)extElems.get(0), message); + // If such schema elements are not found, the assertion is not applicable + if (swaRefs.isEmpty()) + throw new AssertionNotApplicableException(); + + // Going through all the schema element names + for (int i = 0; i < swaRefs.size(); i++) + { + QName elemName = (QName) swaRefs.get(i); + // Looking for such elements in the root MIME part + NodeList elems = root.getDocumentElement().getElementsByTagNameNS( + elemName.getNamespaceURI(), elemName.getLocalPart()); + // Going through all the ref:swaRef references + for (int j = 0; j < elems.getLength(); j++) + { + Node elem = elems.item(j); + // Getting a value of this reference + String ref = elem.getFirstChild() == null ? null + : elem.getFirstChild().getNodeValue(); + // If the value is invalid, the assertion failed + if (ref == null) + throw new AssertionFailException("The element " + elem.getNodeName() + + " of the ref:swaRef schema type is specified, but its vaule" + + " is invalid."); + // If the URI does not start with the "cid:" content-id prefix + // The assertion failed + if (!ref.startsWith("cid:")) + { + throw new AssertionFailException("The URI " + ref + + " of the ref:swaRef schema type must use the cid: prefix."); + } + boolean refFound = false; + Iterator iMimeParts = mimeParts.getParts().iterator(); + // Going through all the MIME parts of the SOAP message + while (iMimeParts.hasNext()) + { + MimePart mimePart = (MimePart)iMimeParts.next(); + // Getting part's Content-ID header + String cid = MIMEUtils.getMimeHeaderAttribute( + mimePart.getHeaders(), MIMEConstants.HEADER_CONTENT_ID); + if (cid != null) + { + // If the header value equals the reference URI, + // the corresponding MIME part is found + if (cid.equals('<' + ref.substring(4) + '>')) + { + refFound = true; + break; + } + } + } + // If the corresponding MIME part is not found + // the assertion failed + if (!refFound) + throw new AssertionFailException("The SOAP message does not contain" + + " a MIME part with the <" + ref.substring(4) + "> Content-ID."); + } + } + } + catch (AssertionNotApplicableException anae) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + catch (AssertionFailException afe) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = validator.createFailureDetail( + afe.getMessage(), entryContext); + } + // Return assertion result + return validator.createAssertionResult( + testAssertion, result, failureDetail); + } + + /** + * Collects names of schema elements that are defined with the ref:swaRef + * schema type. + * @param extElem a list of extensibility elements + * @param message the corresponding message element. + * @return a list of such names found. + */ + private List getSwaRefs(ExtensibilityElement extElem, Message message) + { + List swaRefs = new ArrayList(); + if (extElem.getElementType().equals(WSDL_MIME_MULTIPART)) + { + // Getting the root mime:part + List mimeParts = ((MIMEMultipartRelated) extElem).getMIMEParts(); + if (mimeParts.size() > 0) + { + // Getting extensibility elements of the first mime:part + List elems = ((MIMEPart) mimeParts.get(0)).getExtensibilityElements(); + List boundParts = new ArrayList(); + // Going through all the MIME part's extensibility elements + for (int k = 0; k < elems.size(); k ++) + { + ExtensibilityElement elem = (ExtensibilityElement) elems.get(k); + // If that is a soap:body + if (elem.getElementType().equals(WSDL_SOAP_BODY) && message != null) + { + // Getting parts specified by the parts attribute + List bodyParts = ((SOAPBody) elem).getParts(); + // Collecting all the message parts bound by this soapbind:body + Iterator i = message.getParts().values().iterator(); + while (i.hasNext()) + { + Part part = (Part) i.next(); + if (bodyParts == null || bodyParts.contains(part.getName())) + { + boundParts.add(part); + } + } + } + // else if that is a soap:header + else if (elem.getElementType().equals(WSDL_SOAP_HEADER)) + { + QName msgName; + String partName; + if (elem instanceof SOAPHeader) + { + SOAPHeader header = (SOAPHeader) elem; + // If the part is bound by this element + msgName = header.getMessage(); + partName = header.getPart(); + } + // WSDL4J 1.4 does not recognize soap:header elements that + // are enclosed in mime:multipartRelated, so using a workaround + else + { + Element header = + ((UnknownExtensibilityElement) elem).getElement(); + // Getting the element's message attribute + String msgVal = header.getAttribute("message"); + // finding the colon delimiter + int colonPos = msgVal.indexOf(":"); + String ns = null; + // Getting a local part + String lp = colonPos > -1 ? msgVal.substring(colonPos + 1) : msgVal; + // If the delimiter is found + if (colonPos > -1) + { + // Retrieving a namespace URI + ns = validator.getWSDLDocument() + .getDefinitions().getNamespace(msgVal.substring(0, colonPos)); + } + msgName = new QName(ns, lp); + partName = header.getAttribute("part"); + } + // Getting a message referenced by this soapbind:header element + Message msg = + validator.getWSDLDocument().getDefinitions().getMessage(msgName); + if (msg != null) + { + // Adding the part to the list of bound parts + Part part = msg.getPart(partName); + if (part != null) + boundParts.add(part); + } + } + } + + // All the bound parts from soapbind:body and soapbind:header + // are collected, finding swaRef references. + for (int i = 0; i < boundParts.size(); i++) + { + Part part = (Part) boundParts.get(i); + QName ref; + short type; + // Getting either part's element reference or type reference + if ((ref = part.getTypeName()) != null) + { + type = XSConstants.TYPE_DEFINITION; + } + else if ((ref = part.getElementName()) != null) + { + type = XSConstants.ELEMENT_DECLARATION; + } + // The part conatins neither element nor type attribute, + // proceeding with the next part + else + { + continue; + } + // Getting a list of schemas defined + Map schemas = validator.getWSDLDocument().getSchemas(); + // Going through the schemas + Iterator it = schemas.values().iterator(); + while (it.hasNext()) + { + XSModel xsModel = (XSModel) it.next(); + XSTypeDefinition xsType = null; + // Getting the corresponding part type + if (type == XSConstants.ELEMENT_DECLARATION) + { + // Getting schema element + XSElementDeclaration elem = xsModel.getElementDeclaration( + ref.getLocalPart(), ref.getNamespaceURI()); + if (elem != null) + { + // Getting element's type + xsType = elem.getTypeDefinition(); + // If it is ref:swaRef + if (WSIConstants.NS_URI_SWA_REF.equals(xsType.getName()) + && WSIConstants.SCHEMA_TYPE_SWA_REF.equals( + xsType.getNamespace())) + { + // Adding the name of the element to the list + swaRefs.add( + new QName(elem.getNamespace(), elem.getName())); + } + } + } + else + { + xsType = xsModel.getTypeDefinition( + ref.getLocalPart(), ref.getNamespaceURI()); + } + // Collecting all the element names,adding element names to the list + swaRefs.addAll(collectSwaRefs(xsType)); + } + } + } + } + return swaRefs; + } + + /** + * Collects names of schema elements that are defined with the ref:swaRef + * schema type. + * @param xsType a schema type. + * @return a list of names found. + */ + private List collectSwaRefs(XSTypeDefinition xsType) + { + List swaRefs = new ArrayList(); + if (xsType != null) + { + // If this is a complex type + if (xsType.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE) + { + XSComplexTypeDefinition xsComplexType = + (XSComplexTypeDefinition) xsType; + // If it contains mixed context + if (xsComplexType.getParticle() != null) + { + // collecting element names + swaRefs.addAll(collectSwaRefs(xsComplexType.getParticle().getTerm())); + } + } + } + return swaRefs; + } + + /** + * Collects names of schema elements that are defined with the ref:swaRef + * schema type. + * @param term a schema term. + * @return a list of names found. + */ + private List collectSwaRefs(XSTerm term) + { + List swaRefs = new ArrayList(); + // If a term is an element declaration + if (term.getType() == XSConstants.ELEMENT_DECLARATION) + { + XSElementDeclaration elem = (XSElementDeclaration) term; + XSTypeDefinition xsType = elem.getTypeDefinition(); + // If element's type is ref:swaRef + if (WSIConstants.NS_URI_SWA_REF.equals(xsType.getNamespace()) + && WSIConstants.SCHEMA_TYPE_SWA_REF.equals(xsType.getName())) + { + // Add element's name to the list + swaRefs.add( + new QName(elem.getNamespace(), elem.getName())); + } + else + { + // else collecting element names from element's type + swaRefs.addAll(collectSwaRefs(xsType)); + } + } + // else if a term is a model group + else if(term.getType() == XSConstants.MODEL_GROUP) + { + // Getting a list of Particle schema components + XSObjectList list = ((XSModelGroup) term).getParticles(); + for (int i = 0; i < list.getLength(); i++) + { + // Collecting element names + swaRefs.addAll(collectSwaRefs(((XSParticle) list.item(i)).getTerm())); + } + } + return swaRefs; + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1005.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1005.java new file mode 100644 index 000000000..ef793af3a --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1005.java @@ -0,0 +1,167 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.envelope; + +import java.util.List; + +import javax.wsdl.Binding; +import javax.wsdl.BindingOperation; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionFailException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionNotApplicableException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.HTTPUtils; +import org.eclipse.wst.wsi.internal.util.OperationSignature; +import org.eclipse.wst.wsi.internal.util.TypesRegistry; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + + +/** + * BP1005. + */ +public class BP1005 extends AssertionProcess +{ + private final BaseMessageValidator validator; + + /** + * @param BaseMessageValidator + */ + public BP1005(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + try + { + if (this.validator.isOneWayResponse(entryContext)) + throw new AssertionNotApplicableException(); + + // Parse message + Document doc = entryContext.getMessageEntryDocument(); + + // If this is a fault mesage, then it is not applicable + if (this.validator.isFault(doc)) + { + throw new AssertionNotApplicableException(); + } + + // Check if there is a soap body element + if (!this.validator.containsSoapBodyWithChild(doc)) + { + throw new AssertionNotApplicableException(); + } + + // Parse request message + Document docRequest = entryContext.getRequestDocument(); + + // get SOAPAction + String headers = entryContext.getRequest().getHTTPHeaders(); + String action = null; + if (headers != null) + action = (String) HTTPUtils.getHttpHeaderTokens(headers, ":").get("SOAPAction".toUpperCase()); + + Binding binding = validator.analyzerContext.getCandidateInfo().getBindings()[0]; + TypesRegistry registry = + new TypesRegistry( + this.validator.getWSDLDocument().getDefinitions(), + validator); + OperationSignature.OperationMatch match = + OperationSignature.matchOperation( + docRequest, + action, + binding, + registry); + if (match == null) + throw new AssertionNotApplicableException(); + + BindingOperation bindingOperation = match.getOperation(); + + // Is rpc style? + if (!WSIConstants + .ATTRVAL_SOAP_BIND_STYLE_RPC + .equals(match.getOperationStyle())) + throw new AssertionNotApplicableException(); + + List extElements = null; + + if (bindingOperation.getBindingOutput() != null) + extElements = + bindingOperation.getBindingOutput().getExtensibilityElements(); + + // Is message RPC-literal? + if (!validator.isLiteral(extElements)) + throw new AssertionNotApplicableException(); + + //Get message + + // Gets body + NodeList soapBodyList = + doc.getElementsByTagNameNS( + WSIConstants.NS_URI_SOAP, + XMLUtils.SOAP_ELEM_BODY); + if (soapBodyList.getLength() == 0 || soapBodyList.getLength() > 1) + { + // There is not a body or more than one bodies in the envlope. + throw new AssertionFailException(); + } + Element soapBodyElem = (Element) soapBodyList.item(0); + + // Find wrapper element in the body + Element wrapperElement = XMLUtils.getFirstChild(soapBodyElem); + if (wrapperElement == null) + { + throw new AssertionFailException(); + } + + if (wrapperElement + .getLocalName() + .equals(bindingOperation.getName() + "Response")) + { + result = AssertionResult.RESULT_PASSED; + } + else + { + result = AssertionResult.RESULT_FAILED; + } + + } + catch (AssertionFailException e) + { + result = AssertionResult.RESULT_FAILED; + } + catch (AssertionNotApplicableException e) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + catch (Exception e) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + + // Return assertion result + return validator.createAssertionResult(testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1007.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1007.java new file mode 100644 index 000000000..a958e02d7 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1007.java @@ -0,0 +1,64 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.envelope; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.w3c.dom.Document; + + +/** + * BP1007 + * + * For a candidate message, in the message log file + * DTDs relating to soap:header or soap:body documents, are not present in the message: no DOCTYPE element is present. + */ +public class BP1007 extends AssertionProcess +{ + private final BaseMessageValidator validator; + + /** + * @param BaseMessageValidator + */ + public BP1007(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + // Parse log message + Document doc = entryContext.getMessageEntryDocument(); + if (doc == null) + { + // message is empty or invalid, the assertion is not applicable + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + // else if the message contains a Document Type Declaration, the assertion failed + else if (doc.getDoctype() != null) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = validator.createFailureDetail( + testAssertion.getFailureDetailDescription(), entryContext); + } + // Return assertion result + return validator.createAssertionResult( + testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1008.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1008.java new file mode 100644 index 000000000..0eb666134 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1008.java @@ -0,0 +1,277 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.envelope; + +import java.util.List; + +import javax.wsdl.Binding; +import javax.wsdl.BindingOperation; +import javax.wsdl.Message; +import javax.wsdl.Part; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionFailException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionNotApplicableException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionPassException; +import org.eclipse.wst.wsi.internal.log.MessageEntry; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.OperationSignature; +import org.eclipse.wst.wsi.internal.util.TypesRegistry; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + + +/** + * BP1008. + * Message has part accessor elements for parameters and return value, in no namespaces, + * but the children of these are namespace qualified with the same targetNamespace with which + * their types are defined. + */ +public class BP1008 extends AssertionProcess +{ + private final BaseMessageValidator validator; + + /** + * @param BaseMessageValidator + */ + public BP1008(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + /* (non-Javadoc) + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + try + { + + if (this.validator.isOneWayResponse(entryContext)) + throw new AssertionFailException( + AssertionResult.RESULT_NOT_APPLICABLE); + + // Parse message + Document doc = entryContext.getMessageEntryDocument(); + + // If there is no message, then throw fail exception + if (doc == null) + throw new AssertionFailException(); + + if (this.validator.isFault(doc)) + { + throw new AssertionFailException( + AssertionResult.RESULT_NOT_APPLICABLE); + } + + // Check if there is a soap body element + if (!this.validator.containsSoapBodyWithChild(doc)) + { + throw new AssertionNotApplicableException(); + } + + // Parse request message + Document docRequest = entryContext.getRequestDocument(); + + // get SOAPAction + String action = + validator.getSoapAction(entryContext.getRequest().getHTTPHeaders()); + + Binding binding = validator.analyzerContext.getCandidateInfo().getBindings()[0]; + //Definition definition = entryContext.getAnalyzerContext().getCandidateInfo().getDefinitions()[0]; + TypesRegistry registry = + new TypesRegistry( + this.validator.getWSDLDocument().getDefinitions(), + validator); + OperationSignature.OperationMatch match = + OperationSignature.matchOperation( + docRequest, + action, + binding, + registry); + if (match == null) + throw new AssertionNotApplicableException(); + + BindingOperation bindingOperation = match.getOperation(); + + // Is rpc style? + if (!WSIConstants + .ATTRVAL_SOAP_BIND_STYLE_RPC + .equals(match.getOperationStyle())) + throw new AssertionFailException( + AssertionResult.RESULT_NOT_APPLICABLE); + + // Gets body + NodeList soapBodyList = + doc.getElementsByTagNameNS( + WSIConstants.NS_URI_SOAP, + XMLUtils.SOAP_ELEM_BODY); + if (soapBodyList.getLength() == 0 || soapBodyList.getLength() > 1) + { + // There is not a body or more than one bodies in the envlope. + throw new AssertionFailException(); + } + Element soapBodyElem = (Element) soapBodyList.item(0); + + result = null; + + // Find operation in the body + Element soapOperation = XMLUtils.getFirstChild(soapBodyElem); + if (soapOperation == null) + { + throw new AssertionFailException(); + } + + // Find operation message and ext. elements in the binding + Message operationMessage = null; + List extElements = null; + if (MessageEntry + .TYPE_REQUEST + .equals(entryContext.getMessageEntry().getType())) + { + operationMessage = + bindingOperation.getOperation().getInput().getMessage(); + if (bindingOperation.getBindingInput() != null) + extElements = + bindingOperation.getBindingInput().getExtensibilityElements(); + } + else + { + if (MessageEntry + .TYPE_RESPONSE + .equals(entryContext.getMessageEntry().getType())) + { + operationMessage = + bindingOperation.getOperation().getOutput().getMessage(); + if (bindingOperation.getBindingOutput() != null) + extElements = + bindingOperation.getBindingOutput().getExtensibilityElements(); + } + } + + // Is message RPC-literal? + if (!validator.isLiteral(extElements)) + throw new AssertionFailException( + AssertionResult.RESULT_NOT_APPLICABLE); + + // gets first child of message + Element soapMessagePart = XMLUtils.getFirstChild(soapOperation); + if (soapMessagePart == null) + { + throw new AssertionPassException(); + } + + while (soapMessagePart != null) + { + // check whether part accessor or return are in no namespace + + if (soapMessagePart.getNamespaceURI() != null + || "".equals(soapMessagePart.getNamespaceURI())) + { + throw new AssertionFailException(); + } + + // check whether children are namespace qualified + // with the same targetNamespace with which their types are defined + String typesTargetNS = + getTypeNS(operationMessage, soapMessagePart.getLocalName()); + + if (typesTargetNS == null) + throw new AssertionFailException(); + + if (!checkChildrenNamespace(soapMessagePart, typesTargetNS)) + { + throw new AssertionFailException(); + } + + soapMessagePart = XMLUtils.getNextSibling(soapMessagePart); + } + + result = AssertionResult.RESULT_PASSED; + + } + catch (AssertionFailException e) + { + if (e.getMessage() != null && e.getMessage().length() > 0) + result = e.getMessage(); + else + result = AssertionResult.RESULT_FAILED; + } + catch (AssertionPassException e) + { + result = AssertionResult.RESULT_PASSED; + } + catch (Exception e) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + + if (result == AssertionResult.RESULT_FAILED) + { + failureDetail = this.validator.createFailureDetail(null, entryContext); + } + + // Return assertion result + return validator.createAssertionResult(testAssertion, result, failureDetail); + } + + /** + * Gets part type NS. + * @param message + * @param partName + * @return String + */ + private String getTypeNS(Message message, String partName) + { + Part part = message.getPart(partName); + if (part == null) + return null; + else + return part.getTypeName().getNamespaceURI(); + } + + /** + * Checks children elements' namespace. + * @param node + * @param typesTargetNS + * @return boolean + */ + + private boolean checkChildrenNamespace(Element node, String typesTargetNS) + { + NodeList parts = node.getElementsByTagName("*"); + for (int i = 0; i < parts.getLength(); i++) + { + Element part = (Element) parts.item(i); + if (!typesTargetNS.equals(part.getNamespaceURI())) + { + return false; + } + if (!checkChildrenNamespace(part, typesTargetNS)) + { + return false; + } + } + return true; + } + +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1009.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1009.java new file mode 100644 index 000000000..48be76a66 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1009.java @@ -0,0 +1,315 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.envelope; + +import java.util.Iterator; +import java.util.List; +import java.util.Vector; + +import javax.wsdl.Binding; +import javax.wsdl.BindingOperation; +import javax.wsdl.Definition; +import javax.wsdl.Message; +import javax.wsdl.OperationType; +import javax.wsdl.Part; +import javax.wsdl.extensions.soap.SOAPHeader; +import javax.xml.namespace.QName; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.WSITag; +import org.eclipse.wst.wsi.internal.analyzer.AssertionFailException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionNotApplicableException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionPassException; +import org.eclipse.wst.wsi.internal.log.MessageEntry; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.HTTPUtils; +import org.eclipse.wst.wsi.internal.util.OperationSignature; +import org.eclipse.wst.wsi.internal.util.TypesRegistry; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + + +/** + * BP1009. + * Message includes all soapbind:headers specified in the wsdl:input + * (if request) or wsdl:output (if response) of the operation referred + * to by its wsdl:binding, and may also include headers that were not specified. + */ +public class BP1009 extends AssertionProcess +{ + private final BaseMessageValidator validator; + + /** + * @param BaseMessageValidator + */ + public BP1009(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + /** + * @see org.eclipse.wst.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(TestAssertion, EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + try + { + if (this.validator.isOneWayResponse(entryContext)) + { + throw new AssertionNotApplicableException(); + } + + // Parse message + Document doc = entryContext.getMessageEntryDocument(); + + // Parse request message + Document docRequest = entryContext.getRequestDocument(); + + if (doc == null || docRequest == null) + throw new AssertionNotApplicableException(); + + // Check if there is a soap body element + if (!this.validator.containsSoapBodyWithChild(doc)) + { + throw new AssertionNotApplicableException(); + } + + if (this.validator.isFault(doc)) + { + throw new AssertionFailException( + AssertionResult.RESULT_NOT_APPLICABLE); + } + + // get SOAPAction + String headers = entryContext.getRequest().getHTTPHeaders(); + String action = null; + if (headers != null) + action = (String) HTTPUtils.getHttpHeaderTokens(headers, ":").get("SOAPAction".toUpperCase()); + + Binding binding = validator.analyzerContext.getCandidateInfo().getBindings()[0]; + TypesRegistry registry = + new TypesRegistry( + this.validator.getWSDLDocument().getDefinitions(), + validator); + OperationSignature.OperationMatch match = + OperationSignature.matchOperation( + docRequest, + action, + binding, + registry); + + if (match == null) + { + throw new AssertionNotApplicableException(); + } + + BindingOperation bindingOperation = match.getOperation(); + + // If this is a one-way operation and we are processing a response, then set result to notApplicable + if (bindingOperation + .getOperation() + .getStyle() + .equals(OperationType.ONE_WAY) + && (entryContext + .getMessageEntry() + .getType() + .equals(MessageEntry.TYPE_RESPONSE))) + { + throw new AssertionNotApplicableException(); + } + + // find body + NodeList soapBodyList = + doc.getElementsByTagNameNS( + WSIConstants.NS_URI_SOAP, + XMLUtils.SOAP_ELEM_BODY); + if (soapBodyList.getLength() == 0 || soapBodyList.getLength() > 1) + { + // There is not a body or more than one bodies in the envlope. + throw new AssertionPassException(); + } + Element soapBodyElem = (Element) soapBodyList.item(0); + + // find headers + NodeList soapHeaders = + doc.getElementsByTagNameNS( + WSITag.ELEM_SOAP_HEADER.getNamespaceURI(), + WSITag.ELEM_SOAP_HEADER.getLocalPart()); + + //find all operation + //Element soapOperation = XMLUtils.getFirstChild(soapBodyElem); + + // gets soapbind:headers + List bindingHeaders = null; + if (entryContext + .getMessageEntry() + .getType() + .equals(MessageEntry.TYPE_REQUEST)) + { + if (bindingOperation.getBindingInput() != null) + bindingHeaders = + bindingOperation.getBindingInput().getExtensibilityElements(); + else + throw new AssertionFailException(); + + } + else + { + if (entryContext + .getMessageEntry() + .getType() + .equals(MessageEntry.TYPE_RESPONSE)) + { + if (bindingOperation.getBindingOutput() != null) + bindingHeaders = + bindingOperation.getBindingOutput().getExtensibilityElements(); + else + throw new AssertionFailException(); + } + } + if (bindingHeaders == null || bindingHeaders.size() == 0) + { + throw new AssertionPassException(); + } + + Iterator iterator = bindingHeaders.iterator(); + while (iterator.hasNext()) + { + Object bindingHeader = iterator.next(); + if (bindingHeader instanceof SOAPHeader) + { + // find soapbind:header in SOAP message + if (!isBindingHeaderInSOAPMessage(entryContext, + soapHeaders, + (SOAPHeader) bindingHeader)) + { + throw new AssertionFailException(); + } + } + } + + result = AssertionResult.RESULT_PASSED; + + } + catch (AssertionFailException e) + { + if (e.getMessage() != null && e.getMessage().length() > 0) + result = e.getMessage(); + else + result = AssertionResult.RESULT_FAILED; + } + catch (AssertionPassException e) + { + result = AssertionResult.RESULT_PASSED; + } + catch (Exception e) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + + if (result == AssertionResult.RESULT_FAILED) + { + failureDetail = this.validator.createFailureDetail(null, entryContext); + } + + // Return assertion result + return validator.createAssertionResult(testAssertion, result, failureDetail); + } + + /** + * Checks whether specified SOAPHeader is in the SOAPMessage. + * @param soapHeaderList + * @param SOAPHeader + * @return boolean + */ + private boolean isBindingHeaderInSOAPMessage( + EntryContext entryContext, + NodeList soapHeaders, + SOAPHeader bindingHeader) + { + + Message msg = getMessageByQName(entryContext, bindingHeader.getMessage()); + if (msg == null) + return false; + + Part part = msg.getPart(bindingHeader.getPart()); + if (part == null) + return false; + + QName partElementName = part.getElementName(); + QName partTypeName = part.getTypeName(); + + if (partTypeName == null && partElementName == null) + return false; + + if (soapHeaders == null || soapHeaders.getLength() == 0) + { + return false; + } + Vector headersList = + XMLUtils.getChildElements((Element) soapHeaders.item(0)); + + for (int indexHeader = 0; + indexHeader < headersList.size(); + indexHeader++) + { + Element soapHeaderPart = (Element) headersList.get(indexHeader); + if (soapHeaderPart != null) + { + QName soapHeaderPartQName = + new QName( + soapHeaderPart.getNamespaceURI(), + soapHeaderPart.getLocalName()); + if ((partTypeName != null + && partTypeName.equals(soapHeaderPartQName)) + || (partElementName != null + && partElementName.equals(soapHeaderPartQName))) + { + return true; + } + } + } + + return false; + } + + /** + * Gets message by QName. + * @param entryContext + * @param messageName + * @return Message + */ + private Message getMessageByQName( + EntryContext entryContext, + QName messageName) + { + Definition[] defs = validator.analyzerContext.getCandidateInfo().getDefinitions(); + for (int i = 0; i < defs.length; i++) + { + Message msg = defs[i].getMessage(messageName); + if (msg != null) + return msg; + } + return null; + } + +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1011.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1011.java new file mode 100644 index 000000000..cc45bd7ea --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1011.java @@ -0,0 +1,203 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.envelope; + +import javax.wsdl.Binding; +import javax.wsdl.BindingOperation; +import javax.xml.namespace.QName; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionFailException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionNotApplicableException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionPassException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + + +/** + * BP1011. + */ +public class BP1011 extends AssertionProcess +{ + private final BaseMessageValidator validator; + + /** + * @param BaseMessageValidator + */ + public BP1011(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + try + { + // TODO need to handle soap with attachments + if (entryContext.getMessageEntry().isMimeContent()) + throw new AssertionNotApplicableException(); + + Binding[] bindings = validator.analyzerContext.getCandidateInfo().getBindings(); + + // get soap message child name + // Get the DOM contents of the message soap:body (if non-empty) + Document messageDoc = null; + + QName messagePartElementQName = null; + + if (!entryContext.getMessageEntry().getMessage().equals("")) + { + messageDoc = entryContext.getMessageEntryDocument(); + //messageDoc = XMLUtils.parseXML(entryContext.getMessageEntry().getMessage(), + // WSIProperties.DEF_SOAP_SCHEMA); + // get soap operation name from the soap:body + + // NOTE: getSoapBodyChild() may return null, if the soap:body did not contain any child elements + Element soapMessageElement = validator.getSoapBodyChild(messageDoc); + + // for doc-lit... find the wsdl:part from one of the specified operations that has + // the soap element used in the message. + // we are looking for a part with an element attrib val matching the soap message element + if (soapMessageElement != null) + { + messagePartElementQName = + new QName( + soapMessageElement.getNamespaceURI(), + soapMessageElement.getLocalName()); + } + } + + if ((messageDoc == null) || this.validator.isFault(messageDoc)) + { + // empty messages and fault messages do not qualify for this TA + throw new AssertionNotApplicableException(); + } + + // look for match(s) in doc operations + // if found, we're done, else + // look for match(s) in rpc operations + + /* Doc-lit + * get list of operations (from candidates) for which the first soap:body child QName is the + * value of that operation's or element (depending + * on whether message is a request or a response). + */ + + BindingOperation[] docBindingOperations = + validator.getMatchingBindingOps( + WSIConstants.ATTRVAL_SOAP_BIND_STYLE_DOC, + bindings); + // list of operations that match the or (depending on entryType) + // for part element="..." + // (ISSUE: what about part type="..."?) + BindingOperation[] potentialDocLitOps = + validator.getDocLitOperations( + entryContext.getEntry().getEntryType(), + messagePartElementQName, + docBindingOperations); + if (potentialDocLitOps.length != 0) + { + // found at least one doc lit match + + // *** Now we know it's document-literal, schema-validate the SOAP payload accordingly + try + { + boolean isSchemaValid = this.validator.messageIsDocLitSchemaValid(entryContext); + } + catch (Exception e) + { + throw new AssertionFailException(e.getMessage()); + } + throw new AssertionPassException(); + } + + /* soap message is not doc-lit so try : + * Rpc-lit + */ + BindingOperation[] rpcBindingOperations = + this.validator.getMatchingBindingOps( + WSIConstants.ATTRVAL_SOAP_BIND_STYLE_RPC, + bindings); + + // Determine if there is an operation match + BindingOperation rcpOpMatch = + this.validator.getOperationMatch( + entryContext.getEntry().getEntryType(), + messageDoc, + rpcBindingOperations); + if (rcpOpMatch != null) + { + // Determine if the parts match + rcpOpMatch = + this.validator.getOperationPartsMatch( + entryContext.getEntry().getEntryType(), + messageDoc, + rpcBindingOperations); + } + + if (rcpOpMatch == null) + { + //not matched with rpc either. Prepare assertion failure. + StringBuffer rpcOperationList = new StringBuffer(); + for (int i = 0; i < rpcBindingOperations.length; i++) + { + rpcOperationList.append(rpcBindingOperations[i].toString() + "\n"); + } + + StringBuffer docOperationList = new StringBuffer(); + for (int i = 0; i < docBindingOperations.length; i++) + { + docOperationList.append(docBindingOperations[i].toString() + "\n"); + } + + throw new AssertionFailException( + "--MESSAGE:\n" + + entryContext.getMessageEntry().getMessage() + + "\n--CANDIDATE RPC STYLE OPERATIONS (" + + (rpcBindingOperations.length != 0 + ? (rpcBindingOperations.length + "):\n" + rpcOperationList) + : "NONE)") + + "\n--CANDIDATE DOCUMENT STYLE OPERATIONS (" + + (docBindingOperations.length != 0 + ? (docBindingOperations.length + "):\n" + docOperationList) + : "NONE)")); + + } + } + catch (AssertionPassException e) + { + } + catch (AssertionFailException e) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = this.validator.createFailureDetail(e.getMessage(), entryContext); + } + catch (AssertionNotApplicableException e) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + + // Return assertion result + + return validator.createAssertionResult(testAssertion, result, failureDetail); + + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1012.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1012.java new file mode 100644 index 000000000..e81c59041 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1012.java @@ -0,0 +1,102 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.envelope; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionFailException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionNotApplicableException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + + +/** + * BP1012. + */ +public class BP1012 extends AssertionProcess +{ + private final BaseMessageValidator validator; + + /** + * @param BaseMessageValidator + */ + public BP1012(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + try + { + // look for elements: + // (Note: since this is a Soap message we expect exactly one soap envelope, but we do not assume it). + Document requestDoc = entryContext.getRequestDocument(); + + // message is empty or invalid, the assertion is not applicable + if (requestDoc == null) + throw new AssertionNotApplicableException(); + + Element envElem = requestDoc.getDocumentElement(); + //NodeList soapEnvList = requestDoc.getElementsByTagNameNS(WSIConstants.NS_URI_SOAP, "Envelope"); + + // If the document element tag name is not Envelope + // or the namespace is http://schemas.xmlsoap.org/soap/envelope/ + if (!envElem.getLocalName().equals(XMLUtils.SOAP_ELEM_ENVELOPE) + || envElem.getNamespaceURI().equals(WSIConstants.NS_URI_SOAP)) + // Request contains proper soap Envelope element + throw new AssertionNotApplicableException(); + + // we expect a Soap Fault as a response + Document responseDoc = + XMLUtils.parseXML(entryContext.getResponse().getMessage()); + NodeList soapFaultList = + responseDoc.getElementsByTagNameNS( + WSIConstants.NS_URI_SOAP, + "Fault"); + // ADD extra check here that the is a child of ?? + if ((soapFaultList == null) || (soapFaultList.getLength() == 0)) + { + // No Soap fault found. + // Assertion failed (ADD highlight the child here ?) + throw new AssertionFailException( + "--- REQUEST:\n" + + entryContext.getRequest().getMessage() + + "\n--- RESPONSE:\n" + + entryContext.getResponse().getMessage()); + } + + } + catch (AssertionNotApplicableException anae) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + catch (AssertionFailException e) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = this.validator.createFailureDetail(e.getMessage(), entryContext); + } + + // Return assertion result + return validator.createAssertionResult(testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1013.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1013.java new file mode 100644 index 000000000..df310bb15 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1013.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.envelope; + +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; + + + +/** + * BP1013. + */ +public class BP1013 extends BP1011 +{ + /** + * @param BaseMessageValidator + */ + public BP1013(BaseMessageValidator impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1031.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1031.java new file mode 100644 index 000000000..40ba3a961 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1031.java @@ -0,0 +1,108 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.envelope; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionFailException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionNotApplicableException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionPassException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.w3c.dom.Document; +import org.w3c.dom.NodeList; +import org.w3c.dom.Text; + + +/** + * BP1031. + * + * @author: Graham Turrell, IBM UK + */ +public class BP1031 extends AssertionProcess +{ + private final BaseMessageValidator validator; + + /** + * @param BaseMessageValidator + */ + public BP1031(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + failureDetail = null; + try + { + Document doc; + // Check if this is one way response + // or message is mepty or invalid + if (this.validator.isOneWayResponse(entryContext) + || (doc = entryContext.getMessageEntryDocument()) == null) + { + throw new AssertionNotApplicableException(); + } + + if (!this.validator.isFault(doc)) + { + throw new AssertionNotApplicableException(); + } + + NodeList faultCodes = doc.getElementsByTagName("faultcode"); + for (int i = 0; i < faultCodes.getLength(); i++) + { + NodeList faultCodeNodes = (faultCodes.item(i)).getChildNodes(); + for (int j = 0; j < faultCodeNodes.getLength(); j++) + { + if (faultCodeNodes.item(j) instanceof Text) + { + Text faultCodeText = (Text) faultCodeNodes.item(j); + if (faultCodeText.getData().indexOf('.') > 0) + { + throw new AssertionFailException(); + // dotted notation used. + } + } + } + } + + throw new AssertionPassException(); + // no dotted notation used in a faultcode element + } + catch (AssertionPassException e) + { + result = AssertionResult.RESULT_PASSED; + } + catch (AssertionNotApplicableException e) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + catch (AssertionFailException e) + { + result = AssertionResult.RESULT_WARNING; + failureDetail = + this.validator.createFailureDetail( + entryContext.getMessageEntry().getMessage(), + entryContext); + } + + // Return assertion result + return validator.createAssertionResult(testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1032.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1032.java new file mode 100644 index 000000000..0f91910bf --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1032.java @@ -0,0 +1,152 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.envelope; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionFailException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionNotApplicableException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; +import org.w3c.dom.Attr; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NamedNodeMap; + + +/** + * BP1032 + * + * For a candidate envelope + * The soap:Envelope, soap:Header, and soap:Body elements do not have any attributes in the namespace "http://schemas.xmlsoap.org/soap/envelope/" + */ +public class BP1032 extends AssertionProcess +{ + private final BaseMessageValidator validator; + + /** + * @param BaseMessageValidator + */ + public BP1032(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + + try + { + // Getting a message document + Document doc = entryContext.getMessageEntryDocument(); + + // If the message is empty or invalid, the assertion is not applicable + if (doc == null) + throw new AssertionNotApplicableException(); + + // Getting a root element + Element element = doc.getDocumentElement(); + + // Assuming that root element should be soap:Envelope + // If not, the assertion is not applicable + if (!element.getLocalName().equals(XMLUtils.SOAP_ELEM_ENVELOPE)) + throw new AssertionNotApplicableException(); + + // looking for any attribute of soap:Envelope in the namespace + // "http://schemas.xmlsoap.org/soap/envelope/" + // If at least one attribute is found, the assertion failed + Attr attr = getAttribute(element.getAttributes()); + if (attr != null) + throw new AssertionFailException("soap:Envelope attribute name is " + + attr.getName()); + + // Getting the first child of soap:Envelope + element = XMLUtils.getFirstChild(element); + + // If the child is soap:Header + if (element != null + && element.getLocalName().equals(XMLUtils.SOAP_ELEM_HEADER)) + { + // looking for any attribute of soap:Header in the namespace + // "http://schemas.xmlsoap.org/soap/envelope/" + // If at least one attribute is found, the assertion failed + attr = getAttribute(element.getAttributes()); + if (attr != null) + throw new AssertionFailException("soap:Header attribute name is " + + attr.getName()); + + // Moving to the next soap:Envelope child + element = XMLUtils.getNextSibling(element); + } + + // If the child is soap:Body + if (element != null + && element.getLocalName().equals(XMLUtils.SOAP_ELEM_BODY)) + { + // looking for any attribute of soap:Body in the namespace + // "http://schemas.xmlsoap.org/soap/envelope/" + // If at least one attribute is found, the assertion failed + attr = getAttribute(element.getAttributes()); + if (attr != null) + throw new AssertionFailException("soap:Body attribute name is " + + attr.getName()); + } + + } + catch (AssertionNotApplicableException anae) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + catch (AssertionFailException afe) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = validator.createFailureDetail( + afe.getMessage(), entryContext); + } + + return validator.createAssertionResult( + testAssertion, result, failureDetail); + } + + /** + * Looks for an attribute that is in the namespace + * http://schemas.xmlsoap.org/soap/envelope/ + * @param attrs a collection of attributes + * @return an attribute in the specified namespace or null + */ + private Attr getAttribute(NamedNodeMap attrs) + { + Attr ret = null; + if (attrs != null) + { + for(int i = 0; i < attrs.getLength(); i++) + { + Attr attr = (Attr) attrs.item(i); + if (attr.getNamespaceURI() != null + && attr.getNamespaceURI().equals(WSIConstants.NS_URI_SOAP)) + { + ret = attr; + break; + } + } + } + + return ret; + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1033.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1033.java new file mode 100644 index 000000000..7df6ca16d --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1033.java @@ -0,0 +1,126 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.envelope; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionFailException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionNotApplicableException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +/** + * BP1033 + * + * For a candidate envelope + * The SOAP envelope does not contain the namespace declaration xmlns:xml="http://www.w3.org/XML/1998/namespace". + */ +public class BP1033 extends AssertionProcess +{ + private final BaseMessageValidator validator; + + /** + * @param BaseMessageValidator + */ + public BP1033(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + try + { + // Getting a message document + Document doc = entryContext.getMessageEntryDocument(); + // If the message is empty or invalid, the assertion is not applicable + if (doc == null) + { + throw new AssertionNotApplicableException(); + } + + // Getting the root element + Element elem = doc.getDocumentElement(); + // If it is not the soap:Envelope, the assertion is not applicable + if (!elem.getNamespaceURI().equals(WSIConstants.NS_URI_SOAP) + || !elem.getLocalName().equals(XMLUtils.SOAP_ELEM_ENVELOPE)) + { + throw new AssertionNotApplicableException(); + } + + // If the envelope contains the xmlns:xml namespace declaration, + // the assertion failed + String incorrectElementName = getIncorrectElementName(elem); + if (incorrectElementName != null) + { + throw new AssertionFailException("The name of an element containing " + + "such namespace declaration is \"" + incorrectElementName + "\"."); + } + } + catch (AssertionNotApplicableException anae) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + catch (AssertionFailException afe) + { + result = AssertionResult.RESULT_WARNING; + failureDetail = validator.createFailureDetail( + afe.getMessage(), entryContext); + } + + // Return assertion result + return validator.createAssertionResult( + testAssertion, result, failureDetail); + } + + /** + * Looks for any element that contains the attribute xmlns:xml="http://www.w3.org/XML/1998/namespace". + * @param elem the root element. + * @return the name of an element found or null. + */ + private String getIncorrectElementName(Element elem) + { + // Getting a value of the attribute xmlns:xml + String attrValue = elem.getAttributeNS( + WSIConstants.NS_URI_XMLNS, "xml"); + // If it equals to "http://www.w3.org/XML/1998/namespace", + // return an element name; + if (WSIConstants.NS_URI_XML.equals(attrValue)) + { + return elem.getNodeName(); + } + // Going through element's children + Element child = XMLUtils.getFirstChild(elem); + while (child != null) + { + // If any of them has xmlns:xml attribute, return a value + String name = getIncorrectElementName(child); + if (name != null) + { + return name; + } + // Getting the next element's child + child = XMLUtils.getNextSibling(child); + } + // No xmlns:xml attributes found, return null + return null; + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1100.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1100.java new file mode 100644 index 000000000..edbc70f13 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1100.java @@ -0,0 +1,103 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.envelope; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.Utils; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + + +/** + * BP1100. + * A message that does not contain a SOAP fault SHOULD use a "200 OK" + * HTTP status code. + */ +public class BP1100 extends AssertionProcess +{ + private final BaseMessageValidator validator; + + /** + * @param BaseMessageValidator + */ + public BP1100(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + /** + * @see org.eclipse.wst.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(TestAssertion, EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + if (this.validator.isOneWayResponse(entryContext)) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + else + { + // look for element: + Document doc = entryContext.getMessageEntryDocument(); + if (doc == null) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + else + { + Element root = doc.getDocumentElement(); + NodeList faultList = + root.getElementsByTagNameNS(WSIConstants.NS_URI_SOAP, "Fault"); + + // If response does not contain a soap:Fault, then check it + if ((faultList == null) || (faultList.getLength() == 0)) + { + // Response does not contain a soap:Fault + // check HTTP status code + String httpStatus = + Utils.getHTTPStatusCode( + entryContext.getMessageEntry().getHTTPHeaders()); + if (!"200".equals(httpStatus)) + { + result = AssertionResult.RESULT_WARNING; + //failureDetailMessage = entryContext.getMessageEntry().getMessage(); + failureDetail = + this.validator.createFailureDetail( + "\nResponse message:\nHeaders:\n" + + entryContext.getMessageEntry().getHTTPHeaders() + + "\nMessage:\n" + + entryContext.getMessageEntry().getMessage(), + entryContext); + } + } + + // If it is a soap:Fault, then the result must be notApplicable + else + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + } + } + + // Return assertion result + return validator.createAssertionResult(testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1107.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1107.java new file mode 100644 index 000000000..8937346c2 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1107.java @@ -0,0 +1,277 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.envelope; + +import java.io.StringWriter; +import java.util.HashMap; +import java.util.Map; +import java.util.Vector; + +import javax.wsdl.Fault; +import javax.wsdl.Message; +import javax.wsdl.Operation; +import javax.wsdl.Part; +import javax.wsdl.extensions.soap.SOAPFault; +import javax.xml.namespace.QName; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.WSITag; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcessVisitor; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.NullUtil; +import org.eclipse.wst.wsi.internal.util.OperationSignature; +import org.eclipse.wst.wsi.internal.util.TypesRegistry; +import org.eclipse.wst.wsi.internal.util.WSDLUtil; +import org.eclipse.wst.wsi.internal.wsdl.traversal.WSDLTraversal; +import org.eclipse.wst.wsi.internal.wsdl.traversal.WSDLTraversalContext; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + + +/** + * BP1107. + * The contained soapbind:fault is defined in the wsdl:binding. + */ +public class BP1107 extends AssertionProcessVisitor +{ + + private final BaseMessageValidator validator; + + /** + * @param BaseMessageValidator + */ + public BP1107(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + private OperationSignature responseSig = null; + private Vector faults = null; + + /** + * @see org.eclipse.wst.wsi.wsdl.traversal.WSDLVisitor#visit(SOAPFault, Object, WSDLTraversalContext) + */ + public void visit(SOAPFault fault, Object parent, WSDLTraversalContext ctx) + { + String faultName = fault.getName(); + + if (faultName == null) + faultName = ctx.getBindingFault().getName(); + + Operation op = ctx.getBindingOperation().getOperation(); + if (op == null /* || faultName == null*/ + ) // may be it's possible to have legal fault with null name + return; + + // we suppose that SOAPFault.getName() corresponds to the abstract operation's fault name + Fault f = op.getFault(faultName); + if (f == null) + return; + + Message m = f.getMessage(); + // message should have only one part + if (m == null || m.getParts() == null || m.getParts().size() != 1) + return; + + //Part faultPart = WSDLUtil.getPart(m, faultName); + Part faultPart = (Part) m.getParts().values().iterator().next(); + + TypesRegistry tReg = (TypesRegistry) ctx.getParameter("TypesRegistry"); + QName elemQName = faultPart.getElementName(); + QName typeQName = faultPart.getTypeName(); + if (typeQName == null) + typeQName = tReg.getType(faultPart.getElementName()); + if (typeQName == null) + throw new IllegalArgumentException("Part type can not be null."); + + // for all faults; if it presents in the definition remove it from list + for (int i = 0; i < faults.size();) + { + Element elem = (Element) faults.get(i); + + // TODO: I don't understand why this is here. Only the element setting should be checked. + //boolean matchByType = + // elem.getLocalName().equals(typeQName.getLocalPart()) && NullUtil.equals(elem.getNamespaceURI(), typeQName.getNamespaceURI()); + + boolean matchByElement = + elemQName != null + && elem.getLocalName().equals(elemQName.getLocalPart()) + && NullUtil.equals( + elem.getNamespaceURI(), + elemQName.getNamespaceURI()); + + //if (matchByType || matchByElement) + if (matchByElement) + faults.remove(i); + else + i++; + } + } + + /** + * @see org.eclipse.wst.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(TestAssertion, EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + + if (this.validator.isOneWayResponse(entryContext)) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + else + { + // Parse request and response message + Document docRequest = entryContext.getRequestDocument(); + Document docResponse = entryContext.getMessageEntryDocument(); + + if ((docRequest == null) || (docResponse == null)) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + else if (!this.validator.isFault(docResponse)) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + else + { + // create request signature + OperationSignature.OperationMatch match = + OperationSignature.matchOperation( + docRequest, + this.validator.getSoapAction(entryContext.getRequest().getHTTPHeaders()), + validator.analyzerContext.getCandidateInfo().getBindings()[0], + new TypesRegistry( + validator.analyzerContext + .getCandidateInfo() + .getWsdlDocument() + .getDefinitions(), + validator)); + + result = AssertionResult.RESULT_NOT_APPLICABLE; + + if (match != null) + { + // MOVED: Parse response message + //doc = entryContext.getMessageEntryDocument(); + + responseSig = new OperationSignature(docResponse); + if (WSIConstants + .ATTRVAL_SOAP_BIND_STYLE_RPC + .equals(match.getOperationStyle())) + responseSig.createRPCSignature(); + + WSDLTraversal traversal = new WSDLTraversal(); + //VisitorAdaptor.adapt(this); + traversal.setVisitor(this); + traversal.visitSOAPFault(true); + traversal.ignoreBindingInput(); + traversal.ignoreBindingOutput(); + + if (responseSig == null || !responseSig.isFault()) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + else if (responseSig != null && responseSig.isFault()) + { + // extract all faults and try find them in the definition + // extracts only faults with namespace + Element body = + XMLUtils.findChildElement( + docResponse.getDocumentElement(), + WSITag.ELEM_SOAP_BODY); + Element fault = + XMLUtils.findChildElement(body, WSITag.ELEM_SOAP_FAULT); + Element detail = XMLUtils.getElement("detail", fault); + if (detail == null) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + else + { + result = AssertionResult.RESULT_PASSED; + + faults = XMLUtils.getChildElements(detail); + + // REMOVE: Why do the faults have to be namespaced qualified? + //XMLUtils.removeAllElementsWithoutNS(faults); + + // if faults exist try to validate it + if (faults.size() > 0) + { + Map m = new HashMap(); + WSDLUtil.expandDefinition( + validator.analyzerContext + .getCandidateInfo() + .getWsdlDocument() + .getDefinitions()); + m.put( + "definition", + validator.analyzerContext + .getCandidateInfo() + .getWsdlDocument() + .getDefinitions()); + TypesRegistry tReg = + new TypesRegistry( + validator.analyzerContext + .getCandidateInfo() + .getWsdlDocument() + .getDefinitions(), + validator); + m.put("TypesRegistry", tReg); + traversal.traverse(match.getOperation(), m); + if (faults.size() > 0) + { + result = AssertionResult.RESULT_WARNING; + StringWriter sw = new StringWriter(); + for (int i = 0; i < faults.size(); i++) + { + try + { + XMLUtils.serializeElement((Element) faults.get(i), sw); + } + catch (Exception e) + { + } + } + try + { + sw.close(); + } + catch (Exception e) + { + } + failureDetail = + this.validator.createFailureDetail( + "\nFaults:\n" + sw.toString(), + entryContext); + } + else + result = AssertionResult.RESULT_PASSED; + } + } + } + } + } + } + + // Return assertion result + return validator.createAssertionResult(testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1201.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1201.java new file mode 100644 index 000000000..7aafb0e62 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1201.java @@ -0,0 +1,77 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.envelope; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.WSITag; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + + +/** + * BP1201. + * The namespace of the soap:Envelope in the message has value: http://schemas.xmlsoap.org/soap/envelope/. + */ +public class BP1201 extends AssertionProcess implements WSITag +{ + private final BaseMessageValidator validator; + + /** + * @param BaseMessageValidator + */ + public BP1201(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + Document doc; + // Check if this is one way response or message is mepty or invalid + if (this.validator.isOneWayResponse(entryContext) || + (doc = entryContext.getMessageEntryDocument()) == null) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + else + { + Element root = doc.getDocumentElement(); + String ns = root.getNamespaceURI(); + String local = root.getLocalName(); + if (!ELEM_SOAP_ENVELOPE.getNamespaceURI().equals(ns)) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = validator.createFailureDetail( + "Root element has namespace: " + ns, entryContext); + } + + else if (!ELEM_SOAP_ENVELOPE.getLocalPart().equals(local)) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = validator.createFailureDetail( + "Root element has local name: " + local, entryContext); + } + } + + // Return assertion result + return validator.createAssertionResult( + testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1202.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1202.java new file mode 100644 index 000000000..e1d990416 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1202.java @@ -0,0 +1,104 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.envelope; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.WSITag; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + + +/** + * BP1202. + * Each child element (if any) of the soap:Body element is namespace qualified (not the grandchildren). + */ +public class BP1202 extends AssertionProcess implements WSITag +{ + private final BaseMessageValidator validator; + + /** + * @param BaseMessageValidator + */ + public BP1202(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + // Parse log message + Document doc = entryContext.getMessageEntryDocument(); + + if (validator.isOneWayResponse(entryContext)) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + + // Check if there is a soap body element + else if (!validator.containsSoapBodyWithChild(doc)) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + else + { + // Get the root element + Element root = doc.getDocumentElement(); + + // Get a node list which should contain the soap:Body element + NodeList rootNodeList = root.getElementsByTagNameNS( + ELEM_SOAP_BODY.getNamespaceURI(), ELEM_SOAP_BODY.getLocalPart()); + + // If there is at least one soap:Body element, + // then make sure that each child is namespace qualified + if (rootNodeList.getLength() > 0) + { + // Get the soap:Body element + Element body = (Element) rootNodeList.item(0); + + // Get the list of soap:Body child elements + NodeList children = body.getChildNodes(); + + // Make sure that each child element is namespace qualified + for (int i = 0; + i < children.getLength() && result == AssertionResult.RESULT_PASSED; + ++i) + { + Node n = children.item(i); + if (n instanceof Element) + { + String ns = n.getNamespaceURI(); + if (ns == null || ns.length() == 0) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = validator.createFailureDetail( + entryContext.getMessageEntry().getMessage(), entryContext); + } + } + } + } + } + + // Return assertion result + return validator.createAssertionResult( + testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1203.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1203.java new file mode 100644 index 000000000..cfb1cd5f6 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1203.java @@ -0,0 +1,147 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.envelope; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionFailException; +import org.eclipse.wst.wsi.internal.log.MessageEntry; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; +import org.w3c.dom.Attr; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.NodeList; + + +/** + * BP1203. + * The namespace of the detail element of a qualified attribute in the soap:Fault is a + * foreign namespace, different from "http://schemas.xmlsoap.org/soap/envelope/". + */ +public class BP1203 extends AssertionProcess +{ + private final BaseMessageValidator validator; + + /** + * @param BaseMessageValidator + */ + public BP1203(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + boolean qualifiedAttributes = false; + + Document doc; + // Check if this is one way response or message is mepty or invalid + if (this.validator.isOneWayResponse(entryContext) + || (doc = entryContext.getMessageEntryDocument()) == null) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + else + { + // ADD: Need to determine if this check is required, since it should already be done + // Applicable to response messages only + if (entryContext + .getMessageEntry() + .getType() + .equalsIgnoreCase(MessageEntry.TYPE_RESPONSE)) + { + // look for element: + NodeList faultList = + doc.getElementsByTagNameNS( + WSIConstants.NS_URI_SOAP, + XMLUtils.SOAP_ELEM_FAULT); + if ((faultList == null) || (faultList.getLength() == 0)) + { + // Response does not contain a soap:Fault + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + + // we have a soap:Fault. + else + { + try + { + // look at each soap:Fault in turn + for (int i = 0; i < faultList.getLength(); i++) + { + Element soapFault = (Element) faultList.item(i); + // find the detail element(s) if any + NodeList detailList = + soapFault.getElementsByTagName(XMLUtils.SOAP_ELEM_FAULT_DETAIL); + if (detailList != null) + { + // for each detail element... + for (int j = 0; j < detailList.getLength(); j++) + { + NamedNodeMap detailAttribs = + detailList.item(j).getAttributes(); + // check for any qualified attributes + if (detailAttribs != null) + { + for (int k = 0; k < detailAttribs.getLength(); k++) + { + Attr nextAttr = (Attr) (detailAttribs.item(k)); + // for each qualified attribute, check that + // qname != http://schemas.xmlsoap.org/soap/envelope + if (nextAttr.getNamespaceURI() != null) + { + qualifiedAttributes = true; + if (nextAttr + .getNamespaceURI() + .equals(WSIConstants.NS_URI_SOAP)) + { + // found unexpected qname + throw new AssertionFailException( + entryContext.getMessageEntry().getMessage()); + } + } + } + } + } + } + } + + if (!qualifiedAttributes) + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + catch (AssertionFailException e) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = this.validator.createFailureDetail(e.getMessage(), entryContext); + } + } + } + else + { + // target message is not a Response + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + } + + // Return assertion result + return validator.createAssertionResult(testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1204.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1204.java new file mode 100644 index 000000000..438a29022 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1204.java @@ -0,0 +1,302 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.envelope; + +import java.util.Collection; +import java.util.Iterator; +import java.util.List; + +import javax.wsdl.Binding; +import javax.wsdl.BindingOperation; +import javax.wsdl.Message; +import javax.wsdl.Part; +import javax.wsdl.Types; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.UnknownExtensibilityElement; +import javax.xml.namespace.QName; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionFailException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionNotApplicableException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionPassException; +import org.eclipse.wst.wsi.internal.log.MessageEntry; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.HTTPUtils; +import org.eclipse.wst.wsi.internal.util.OperationSignature; +import org.eclipse.wst.wsi.internal.util.TypesRegistry; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + + +/** + * BP1204. + * The serialized array form in the message does not contain the + * soapenc:arrayType attribute. + * + */ +public class BP1204 extends AssertionProcess +{ + private final BaseMessageValidator validator; + + /** + * @param BaseMessageValidator + */ + public BP1204(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + /** + * @see org.eclipse.wst.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(TestAssertion, EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + try + { + + if (this.validator.isOneWayResponse(entryContext)) + throw new AssertionNotApplicableException(); + + // Parse message + Document doc = + XMLUtils.parseXML(entryContext.getMessageEntry().getMessage()); + + if (this.validator.isFault(doc)) + { + throw new AssertionPassException(); + } + + // Parse request message + Document docRequest = + XMLUtils.parseXML(entryContext.getRequest().getMessage()); + + // get SOAPAction + String headers = entryContext.getRequest().getHTTPHeaders(); + String action = null; + if (headers != null) + action = (String) HTTPUtils.getHttpHeaderTokens(headers, ":").get("SOAPAction".toUpperCase()); + + Binding binding = validator.analyzerContext.getCandidateInfo().getBindings()[0]; + TypesRegistry registry = + new TypesRegistry( + this.validator.getWSDLDocument().getDefinitions(), + validator); + OperationSignature.OperationMatch match = + OperationSignature.matchOperation( + docRequest, + action, + binding, + registry); + + if (match == null) + throw new AssertionPassException(); + + BindingOperation bindingOperation = match.getOperation(); + + Message operationMessage = null; + if (MessageEntry + .TYPE_REQUEST + .equals(entryContext.getMessageEntry().getType()) + && (bindingOperation.getOperation().getInput() != null)) + { + operationMessage = + bindingOperation.getOperation().getInput().getMessage(); + } + else + { + if (MessageEntry + .TYPE_RESPONSE + .equals(entryContext.getMessageEntry().getType()) + && (bindingOperation.getOperation().getOutput() != null)) + { + operationMessage = + bindingOperation.getOperation().getOutput().getMessage(); + } + } + + if (operationMessage == null) + throw new AssertionPassException(); + + boolean isContainArray = false; + + Collection parts = operationMessage.getParts().values(); + for (Iterator iter = parts.iterator(); iter.hasNext();) + { + Part part = (Part) iter.next(); + + QName type = null; + + if (part.getTypeName() == null) + { + type = registry.getType(part.getElementName()); + } + else + { + type = part.getTypeName(); + } + + isContainArray = + registry.isExtendsArray(type) + || registry.isUsesWSDLArrayType(type) + || isArrayType(type); + if (isContainArray) + break; + } + + if (isContainArray) + { + // Gets body + NodeList soapBodyList = + doc.getElementsByTagNameNS( + WSIConstants.NS_URI_SOAP, + XMLUtils.SOAP_ELEM_BODY); + if (soapBodyList.getLength() == 0 || soapBodyList.getLength() > 1) + { + throw new AssertionFailException(); + } + + Element soapBodyElem = (Element) soapBodyList.item(0); + + NodeList soapBodyCildrenList = + soapBodyElem.getElementsByTagNameNS("*", "*"); + for (int indexChild = 0; + indexChild < soapBodyCildrenList.getLength(); + indexChild++) + { + Element elem = (Element) soapBodyCildrenList.item(indexChild); + if (elem + .hasAttributeNS( + WSIConstants.NS_URI_SOAP_ENCODING, + WSIConstants.ATTR_ARRAY_TYPE)) + { + throw new AssertionFailException(); + } + } + + throw new AssertionPassException(); + } + else + { + throw new AssertionPassException(); + } + + } + catch (AssertionNotApplicableException e) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + catch (AssertionFailException e) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = + this.validator.createFailureDetail( + entryContext.getMessageEntry().getMessage(), + entryContext); + } + catch (AssertionPassException e) + { + result = AssertionResult.RESULT_PASSED; + } + catch (Exception e) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + + // Return assertion result + return validator.createAssertionResult(testAssertion, result, failureDetail); + } + + /** + * Checks whether type uses an array or not. + * @param type + * @return boolean + */ + private boolean isArrayType(QName type) + { + boolean arrayType = false; + + Element typeElement = getTypeElement(type); + if (typeElement != null) + { + NodeList list = + typeElement.getElementsByTagNameNS( + WSIConstants.NS_URI_XSD, + "sequence"); + if (list.getLength() > 0) + arrayType = true; + } + + return arrayType; + } + + /** + * Gets XML element defining the type. + * @param type + * @return Element + */ + private Element getTypeElement(QName type) + { + Types[] allTypes = validator.analyzerContext.getCandidateInfo().getTypes(); + for (int i = 0; allTypes != null && i < allTypes.length; i++) + { + Element typesElement = null; + if (allTypes[i] != null) + { + typesElement = allTypes[i].getDocumentationElement(); + if (typesElement == null) + { + List extList = allTypes[i].getExtensibilityElements(); + for (Iterator iter = extList.iterator(); iter.hasNext();) + { + ExtensibilityElement extElem = (ExtensibilityElement) iter.next(); + + if (extElem + .getElementType() + .equals(new QName(WSIConstants.NS_URI_XSD, "schema"))) + { + typesElement = + ((UnknownExtensibilityElement) extElem).getElement(); + break; + } + } + } + if (typesElement != null) + { + NodeList complexTypesList = + typesElement.getElementsByTagNameNS( + WSIConstants.NS_URI_XSD, + "complexType"); + for (int j = 0; j < complexTypesList.getLength(); j++) + { + Element typeElem = (Element) complexTypesList.item(j); + if (type.getLocalPart().equals(typeElem.getAttribute("name"))) + { + return typeElem; + } + } + + } + } + } + return null; + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1208.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1208.java new file mode 100644 index 000000000..748703c34 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1208.java @@ -0,0 +1,88 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.envelope; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.xml.XMLTraversal; +import org.w3c.dom.Document; +import org.w3c.dom.ProcessingInstruction; + + +/** + * BP1208 NOT FULLY TESTED. + */ +public class BP1208 extends AssertionProcess +{ + private final BaseMessageValidator validator; + + /** + * @param BaseMessageValidator + */ + public BP1208(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + // Parse log message + Document doc = entryContext.getMessageEntryDocument(); + if (doc == null) { + //message is empty or invalid, the assertion is not applicable + result = AssertionResult.RESULT_NOT_APPLICABLE; + + } else { + + // Traverse document looking for processing instructions. + // ISSUE: this inner class needs ... revisiting/replacing + // EG. Do we want to list all processing instructions, + // or is the first sufficient? + XMLTraversal traversal = new XMLTraversal() + { + public void visit(ProcessingInstruction pi) + { + try + { + result = AssertionResult.RESULT_FAILED; + failureDetailMessage = + "Target: " + pi.getTarget() + ", Data: " + pi.getData(); + } + catch (Exception e) + { + // ADD: How should this exception be handled? + } + + super.visit(pi); + } + }; + + traversal.visit(doc); + + if (result == AssertionResult.RESULT_FAILED + && failureDetailMessage != null) + { + failureDetail = this.validator.createFailureDetail(failureDetailMessage, entryContext); + } + } + + // Return assertion result + return validator.createAssertionResult(testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1211.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1211.java new file mode 100644 index 000000000..6b846272e --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1211.java @@ -0,0 +1,147 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.envelope; + +import javax.wsdl.Binding; +import javax.wsdl.BindingOperation; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionFailException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionNotApplicableException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.HTTPUtils; +import org.eclipse.wst.wsi.internal.util.OperationSignature; +import org.eclipse.wst.wsi.internal.util.TypesRegistry; +import org.eclipse.wst.wsi.internal.wsdl.WSDLUtils; +import org.eclipse.wst.wsi.internal.xml.XMLTags; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; +import org.w3c.dom.Attr; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + + +/** + * BP1211. + * + * Context: + * For a candidate message in the message log file, that is referred by a binding style RPC-literal + * + * Description: + * Part accessor elements in the message do not have an xsi:nil attribute with a value of "1" or "true". + */ +public class BP1211 extends AssertionProcess implements XMLTags +{ + private final BaseMessageValidator validator; + + /** + * @param BaseMessageValidator + */ + public BP1211(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + /** + * @see org.eclipse.wst.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(TestAssertion, EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + try + { + if (validator.isOneWayResponse(entryContext)) + throw new AssertionNotApplicableException(); + + // Parse message + Document doc = entryContext.getMessageEntryDocument(); + Document docRequest = entryContext.getRequestDocument(); + + Element soapOperation = null; + // If there is a Fault entry or no body entries, + // the assertion is not applicable + if (validator.isFault(doc) + || (soapOperation = validator.getSoapBodyChild(doc)) == null) + throw new AssertionNotApplicableException(); + + // Get SOAPAction + String headers = entryContext.getRequest().getHTTPHeaders(); + String action = null; + if (headers != null) + action = (String) HTTPUtils.getHttpHeaderTokens(headers, ":").get("SOAPAction".toUpperCase()); + + // Get the binding that is being processed + Binding binding = validator.analyzerContext.getCandidateInfo().getBindings()[0]; + + //Create the types registry + TypesRegistry registry = + new TypesRegistry( + this.validator.getWSDLDocument().getDefinitions(), + validator); + + // Find an operation match + OperationSignature.OperationMatch match = + OperationSignature.matchOperation( + docRequest, + action, + binding, + registry); + if (match == null) + throw new AssertionNotApplicableException(); + + // Get the binding operation based on the match + BindingOperation bindingOperation = match.getOperation(); + + // If this is not rpc-literal, then return notApplicable result + if (!WSDLUtils + .isRpcLiteral(match.getOperationStyle(), bindingOperation)) + throw new AssertionNotApplicableException(); + + // Going through all the accessors + Element accessor = XMLUtils.getFirstChild(soapOperation); + while (accessor != null) + { + Attr attr = XMLUtils.getAttribute(accessor, ATTR_XSI_NIL); + // If there is xsi:nil attribute and its value is "1" or "true" + // the assertion failed + if (attr != null + && (attr.getValue().equals("1") || attr.getValue().equals("true"))) + { + throw new AssertionFailException("The accessor name is " + + accessor.getNodeName()); + } + // Getting the next accessor + accessor = XMLUtils.getNextSibling(accessor); + } + } + catch (AssertionFailException afe) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = validator.createFailureDetail( + afe.getMessage(), entryContext); + } + catch (Exception e) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + + // Return assertion result + return validator.createAssertionResult( + testAssertion, result, failureDetail); + } + +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1212.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1212.java new file mode 100644 index 000000000..2be83d9dd --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1212.java @@ -0,0 +1,165 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.envelope; + +import java.util.Iterator; +import java.util.List; + +import javax.wsdl.BindingOperation; +import javax.xml.namespace.QName; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionFailException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionNotApplicableException; +import org.eclipse.wst.wsi.internal.log.MessageEntry; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +/** + * BP1212 + * + * For a candidate non-fault envelope containing a soap:body with at least one element + * The envelope contains exactly one part accessor element for each of the wsdl:part elements bound to the envelope's corresponding soapbind:body element. + */ +public class BP1212 extends AssertionProcess { + + private final BaseMessageValidator validator; + + /** + * @param BaseMessageValidator + */ + public BP1212(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + try + { + if (validator.isOneWayResponse(entryContext)) + throw new AssertionNotApplicableException(); + + // Getting a message document + Document doc = entryContext.getMessageEntryDocument(); + + Element soapOperation = null; + // If there is a Fault entry or no body entries, + // the assertion is not applicable + if (validator.isFault(doc) + || (soapOperation = validator.getSoapBodyChild(doc)) == null) + throw new AssertionNotApplicableException(); + + // Creating a qualified name of potential SOAP operation + QName operationQName = new QName( + soapOperation.getNamespaceURI(), soapOperation.getLocalName()); + + // Retrieving all the RPC binding operations from wsdl:binding + BindingOperation[] rpcBindingOperations = + validator.getMatchingBindingOps( + WSIConstants.ATTRVAL_SOAP_BIND_STYLE_RPC, + validator.analyzerContext.getCandidateInfo().getBindings()); + + // Retrieving binding operation by given operation name + BindingOperation bindingOperation = validator.getOperationMatch( + entryContext.getEntry().getEntryType(), + operationQName, + rpcBindingOperations); + + // If there is no matched operation, the assertion is not applicable + if (bindingOperation == null) + throw new AssertionNotApplicableException(); + + // Finding operation message parts and extensibility elems + // in the binding depending on message type + List operationMessageParts = null; + List extElems = null; + if (entryContext.getMessageEntry().getType().equals( + MessageEntry.TYPE_REQUEST)) + { + operationMessageParts = bindingOperation.getOperation() + .getInput().getMessage().getOrderedParts(null); + if (bindingOperation.getBindingInput() != null) + extElems = + bindingOperation.getBindingInput().getExtensibilityElements(); + } + else + { + operationMessageParts = bindingOperation.getOperation() + .getOutput().getMessage().getOrderedParts(null); + if (bindingOperation.getBindingOutput() != null) + extElems = + bindingOperation.getBindingOutput().getExtensibilityElements(); + } + + // Getting all the accessors of the operation element + List accessors = XMLUtils.getChildElements(soapOperation); + // Getting the ordered list of wsdl:part names + List orderedPartNames = + validator.orderPartNames(operationMessageParts, extElems); + // Going through all the wsdl:part names + Iterator i = orderedPartNames.iterator(); + while (i.hasNext()) + { + String partName = (String) i.next(); + // If there is not exactly one accessor for the part specified, + // the assertion failed + if (getPartsCount(accessors, partName) != 1) + throw new AssertionFailException( + "The name of wsdl:part is " + partName); + } + } + catch (AssertionNotApplicableException anae) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + catch (AssertionFailException afe) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = validator.createFailureDetail( + afe.getMessage(), entryContext); + } + + return validator.createAssertionResult( + testAssertion, result, failureDetail); + } + + /** + * Counts the amount of accessors of a specific name + * @param accessors a list of accessors + * @param name the name of accessor elements to be counted + * @return + */ + private int getPartsCount(List accessors, String name) + { + int count = 0; + + for (int i = 0; i < accessors.size(); i++) + { + Element accessor = (Element) accessors.get(i); + if (accessor.getLocalName().equals(name)) + count++; + } + + return count; + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1213.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1213.java new file mode 100644 index 000000000..d472c5a43 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1213.java @@ -0,0 +1,141 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.envelope; + +import java.util.List; + +import javax.wsdl.BindingOperation; +import javax.wsdl.extensions.soap.SOAPBody; +import javax.xml.namespace.QName; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionFailException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionNotApplicableException; +import org.eclipse.wst.wsi.internal.log.MessageEntry; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +/** + * BP1213 + * + * For a candidate non-fault envelope containing a soap:Body element, and is referred by a doc-literal binding + * The envelope has no element content in the soap:Body element if the value of the parts attribute of the soapbind:body is an empty string in the corresponding doc-literal description. + */ +public class BP1213 extends AssertionProcess { + + private final BaseMessageValidator validator; + + /** + * @param BaseMessageValidator + */ + public BP1213(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + try + { + if (validator.isOneWayResponse(entryContext)) + throw new AssertionNotApplicableException(); + + // Getting a message document + Document doc = entryContext.getMessageEntryDocument(); + + Element messageElement = null; + // If the message is empty or invalid or there is a Fault entry + // or there is no body entries, the assertion is not applicable + if (doc == null + || validator.isFault(doc) + || (messageElement = validator.getSoapBodyChild(doc)) == null) + throw new AssertionNotApplicableException(); + + // Getting a qualified name of message element + QName messagePartElementQName = new QName( + messageElement.getNamespaceURI(), messageElement.getLocalName()); + + // Retrieving all the document binding operations from wsdl:binding + BindingOperation[] docBindingOperations = + validator.getMatchingBindingOps( + WSIConstants.ATTRVAL_SOAP_BIND_STYLE_DOC, + validator.analyzerContext.getCandidateInfo().getBindings()); + + // Retrieving binding operation by given element name + BindingOperation[] potentialDocLitOps = + validator.getDocLitOperations( + entryContext.getEntry().getEntryType(), + messagePartElementQName, + docBindingOperations); + + // If there is not exactly one operation matched, + // the assertion is not applicable + if (potentialDocLitOps.length != 1) + throw new AssertionNotApplicableException(); + + // Finding operation extensibility elems + // in the binding depending on message type + List extElems = null; + if (entryContext.getMessageEntry().getType().equals( + MessageEntry.TYPE_REQUEST) + && potentialDocLitOps[0].getBindingInput() != null) + { + extElems = potentialDocLitOps[0] + .getBindingInput().getExtensibilityElements(); + } + else if (entryContext.getMessageEntry().getType().equals( + MessageEntry.TYPE_RESPONSE) + && potentialDocLitOps[0].getBindingOutput() != null) + { + extElems = potentialDocLitOps[0] + .getBindingOutput().getExtensibilityElements(); + } + + // Getting the parts attribute from soapbind:body + List parts = null; + SOAPBody soapBody = validator.getSOAPBody(extElems); + if (soapBody != null) + parts = soapBody.getParts(); + + // if the parts attribute is an empty string and there is + // at least one accessor, the assertion failed + if (parts != null && parts.isEmpty() + && !XMLUtils.getChildElements(messageElement).isEmpty()) + throw new AssertionFailException("wsdl:operation name is " + + potentialDocLitOps[0].getName()); + + } + catch (AssertionNotApplicableException anae) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + catch (AssertionFailException afe) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = validator.createFailureDetail( + afe.getMessage(), entryContext); + } + + return validator.createAssertionResult( + testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1214.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1214.java new file mode 100644 index 000000000..909b6e5ba --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1214.java @@ -0,0 +1,142 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.envelope; + +import java.util.List; + +import javax.wsdl.BindingOperation; +import javax.wsdl.extensions.soap.SOAPBody; +import javax.xml.namespace.QName; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionFailException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionNotApplicableException; +import org.eclipse.wst.wsi.internal.log.MessageEntry; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +/** + * BP1214 + * + * For a candidate non-fault envelope containing a soap:Body element, and is referred by a rpc-literal binding + * The envelope does not contain any part accessor elements if the value of the parts attribute of the soapbind:body is an empty string in the corresponding rpc-literal description. + */ +public class BP1214 extends AssertionProcess { + + private final BaseMessageValidator validator; + + /** + * @param BaseMessageValidator + */ + public BP1214(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + try + { + if (validator.isOneWayResponse(entryContext)) + throw new AssertionNotApplicableException(); + + // Getting a message document + Document doc = entryContext.getMessageEntryDocument(); + + Element soapOperation = null; + // If there is a Fault entry or no body entries, + // the assertion is not applicable + if (validator.isFault(doc) + || (soapOperation = validator.getSoapBodyChild(doc)) == null) + throw new AssertionNotApplicableException(); + + // Creating a qualified name of potential SOAP operation + QName operationQName = new QName( + soapOperation.getNamespaceURI(), soapOperation.getLocalName()); + + // Retrieving all the RPC binding operations from wsdl:binding + BindingOperation[] rpcBindingOperations = + validator.getMatchingBindingOps( + WSIConstants.ATTRVAL_SOAP_BIND_STYLE_RPC, + validator.analyzerContext.getCandidateInfo().getBindings()); + + // Retrieving binding operation by given operation name + BindingOperation bindingOperation = validator.getOperationMatch( + entryContext.getEntry().getEntryType(), + operationQName, + rpcBindingOperations); + + // If there is no matched operation, the assertion is not applicable + if (bindingOperation == null) + throw new AssertionNotApplicableException(); + + // Finding operation extensibility elems + // in the binding depending on message type + List extElems = null; + if (entryContext.getMessageEntry().getType().equals( + MessageEntry.TYPE_REQUEST) + && bindingOperation.getBindingInput() != null) + { + extElems = + bindingOperation.getBindingInput().getExtensibilityElements(); + } + else if (entryContext.getMessageEntry().getType().equals( + MessageEntry.TYPE_RESPONSE) + && bindingOperation.getBindingOutput() != null) + { + extElems = + bindingOperation.getBindingOutput().getExtensibilityElements(); + } + + // If the message is not literal, the assertion is not applicable + if (!validator.isLiteral(extElems)) + throw new AssertionNotApplicableException(); + + // Getting the parts attribute from soapbind:body + List parts = null; + SOAPBody soapBody = validator.getSOAPBody(extElems); + if (soapBody != null) + parts = soapBody.getParts(); + + // if the parts attribute is an empty string and there is + // at least one accessor, the assertion failed + if (parts != null && parts.isEmpty() + && !XMLUtils.getChildElements(soapOperation).isEmpty()) + throw new AssertionFailException("wsdl:operation name is " + + bindingOperation.getName()); + + } + catch (AssertionNotApplicableException anae) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + catch (AssertionFailException afe) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = validator.createFailureDetail( + afe.getMessage(), entryContext); + } + + return validator.createAssertionResult( + testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1301.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1301.java new file mode 100644 index 000000000..a648fd818 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1301.java @@ -0,0 +1,198 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.envelope; + +import java.util.Vector; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; +import org.w3c.dom.Attr; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + + +/** + * BP1301. + */ +public class BP1301 extends AssertionProcess +{ + private final BaseMessageValidator validator; + + /** + * @param BaseMessageValidator + */ + public BP1301(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + + //Get the requets message and check the value of mustUnderstand. + String message = entryContext.getMessageEntry().getMessage(); + Object[] mustUnderstandAttributes = getMustUnderstandAttributes(message); + + if (mustUnderstandAttributes == null) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + else + { + for (int index = 0; index < mustUnderstandAttributes.length; index++) + { + if ((mustUnderstandAttributes[index] != null) + && (mustUnderstandAttributes[index].equals("1") + || mustUnderstandAttributes[index].equals("0"))) + { + result = AssertionResult.RESULT_PASSED; + } + else + { + result = AssertionResult.RESULT_FAILED; + failureDetail = + this.validator.createFailureDetail( + "The SOAP mustUnderstand attribute was present " + + " and its value was " + + mustUnderstandAttributes[index], + entryContext); + } //End if + } //End for + } + + // Return assertion result + return validator.createAssertionResult(testAssertion, result, failureDetail); + } + + //Retreives the value of the mustUnderstand attribute from ALL SOAP header + //If the Header is missing or if it does not contain any targets or if + //the header does not contain a mustUnderstand attribute then set the + //assertionResult to RESULT_NOT_APPLICABLE. + private Object[] getMustUnderstandAttributes(String message) + throws WSIException + { + if (message == null || message.trim().equals("")) { + return null; + } + + Document doc = XMLUtils.parseXML(message); + NodeList headers = + doc.getElementsByTagNameNS(WSIConstants.NS_URI_SOAP, "Header"); + + //If a header not present set result to notApplicable + //else process each headerEntry + if (headers.getLength() <= 0) + { + return null; + } + else + { + Vector mustUnderstandAttributes = new Vector(); + Element header = (Element) headers.item(0); + if (header == null) + return null; + + NodeList headerEntries = header.getChildNodes(); + //For each header entry check retreive the mustUnderstand attribute + //if any, else set the test result to notApplicable + + //This is used to indicate if a header contained any child Elements + boolean headerTargets = false; + + for (int index = 0; index < headerEntries.getLength(); ++index) + { + Node headerEntry = headerEntries.item(index); + if (headerEntry.getNodeType() == Node.ELEMENT_NODE) + { + headerTargets = true; + Attr mustUnderstand = + ((Element) headerEntry).getAttributeNodeNS( + WSIConstants.NS_URI_SOAP, + "mustUnderstand"); + //Retreive the value of the mustUnderstand attribute of the request. + if (mustUnderstand != null) + { + String mustUnderstandValue = mustUnderstand.getNodeValue(); + mustUnderstandAttributes.add(mustUnderstandValue); + } + else + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + //The SOAP Header does not contain a mustUnderstand attribute." + } // mustUnderstand != null + } + } //End for + + if (!headerTargets) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + //The SOAP Header does not contain any header entries. + } + + return mustUnderstandAttributes.toArray(); + } //End If headers.getLength() < 0 + } + + /** + * Returns true if this object is must understand fault code. + * @param faultCodeElem understand fault code. + * @return true if this object is must understand fault code. + */ + public boolean isMustUnderstandFaultCode(Element faultCodeElem) + { + //A faultcode may or maynot have a prefix, if it does its namespace should be + //htt://schemas.xmlsoap.org/soap/envelope which is the same as the faultcode element. + //If a prefix is present and it corresponds to a different namespace or is null + //then this returns false. The local part of the faultcode is then check to see + //if it is one of the permitted values. + if (faultCodeElem == null) + return false; + + String faultCode = faultCodeElem.getFirstChild().getNodeValue().trim(); + if (faultCode == null) + return false; + + String faultCodeElemPrefix = faultCodeElem.getPrefix(); + String faultCodePrefix = faultCode.substring(0, faultCode.indexOf(':')); + String faultCodeName = + faultCode.substring(faultCode.indexOf(':') + 1, faultCode.length()); + + if ((faultCodeElemPrefix != null || faultCodePrefix != null)) + { + if (faultCodePrefix.equals(faultCodeElemPrefix) + && (faultCodeName.equals("MustUnderstand") + || faultCodeName.startsWith("MustUnderstand."))) + return true; + else + return false; + } + else + { + if (faultCode.equals("MustUnderstand") + || faultCodeName.startsWith("MustUnderstand.")) + return true; + else + return false; + } + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1302.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1302.java new file mode 100644 index 000000000..ffe6af623 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1302.java @@ -0,0 +1,181 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.envelope; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.log.MessageEntry; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + + +/** + * BP1302. + * The soap:faultcode value in the soap:Fault element of the response + * message is not custom, and is one of: VersionMismatch, MustUnderstand, Client, Server. + */ +public class BP1302 extends AssertionProcess +{ + private final BaseMessageValidator validator; + + /** + * @param BaseMessageValidator + */ + public BP1302(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + //SOAP fault code values should not be custom: only standard code qualifiers + //are used: VersionMismatch, MustUnderstand, Client, Server + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + + //String requestMessage = null; + String responseMessage = null; + + if (this.validator.isOneWayResponse(entryContext)) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + else + { + //Get the response message check the faultcode. + MessageEntry logEntryResponse = entryContext.getResponse(); + if (logEntryResponse != null) + { + responseMessage = logEntryResponse.getMessage(); + + Document targetDoc = XMLUtils.parseXML(responseMessage); + NodeList faultCodes = targetDoc.getElementsByTagName("faultcode"); + // targetDoc.getElementsByTagNameNS(WSIConstants.NS_URI_SOAP, "faultcode"); + + if (faultCodes.getLength() <= 0) + result = AssertionResult.RESULT_NOT_APPLICABLE; + //No faultcode + + for (int i = 0; i < faultCodes.getLength(); i++) + { + Node faultCodeElem = faultCodes.item(i); + //If the faultcode was MustUnderstand, check the value of + //the mustUnderstand attribute in the request. + if (faultCodeElem == null) + result = AssertionResult.RESULT_NOT_APPLICABLE; + else if (faultCodeElem.getNodeType() == Node.ELEMENT_NODE) + { + if (isValidFaultCode((Element) faultCodeElem)) + { + result = AssertionResult.RESULT_PASSED; + } + else + { + result = AssertionResult.RESULT_WARNING; + failureDetail = + this.validator.createFailureDetail(responseMessage, entryContext); + //failureDetail = + // "The faultcode value was : " + // + faultCodeElem.getFirstChild().getNodeValue().trim(); + } //End if (faultCode.equals...) + } + else + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + } //End for + } //End if logEntryResponse!= null + } + + // Return assertion result + return validator.createAssertionResult(testAssertion, result, failureDetail); + } + + /** + * Check faultCode. + * @param faultCodeElem a faultcode. + * @return true if faultcode is valid. + */ + public boolean isValidFaultCode(Element faultCodeElem) + { + //A faultcode may or maynot have a prefix, if it does its namespace should be + //http://schemas.xmlsoap.org/soap/envelope which is the same as the faultcode element. + //If a prefix is present and it corresponds to a different namespace or is null + //then this returns false. The local part of the faultcode is then check to see + //if it is one of the permitted values. + if (faultCodeElem == null) + return true; + + String faultCode = faultCodeElem.getFirstChild().getNodeValue().trim(); + if (faultCode == null) + return false; + + // FIX: This is not correct, since this element can not be namespace qualified + String faultCodeElemPrefix = faultCodeElem.getParentNode().getPrefix(); + + // If this is not a QName then return false + int index; + String faultCodePrefix = null; + String faultCodeName = faultCode; + if ((index = faultCode.indexOf(':')) != -1) + { + faultCodePrefix = faultCode.substring(0, index); + faultCodeName = faultCode.substring(index + 1, faultCode.length()); + } + + if ((faultCodeElemPrefix != null && faultCodePrefix != null)) + { + if (faultCodePrefix.equals(faultCodeElemPrefix)) + { + if ((faultCodeName.equals("MustUnderstand") + || faultCodeName.equals("VersionMismatch") + || faultCodeName.equals("Client") + || faultCodeName.equals("Server"))) + /* REMOVE: + || faultCodeName.startsWith("MustUnderstand.") + || faultCodeName.startsWith("VersionMismatch.") + || faultCodeName.startsWith("Client.") + || faultCodeName.startsWith("Server."))) + */ + return true; + else + return false; + } + else + { + return true; + } + } + else + { + if (faultCodeName.equals("MustUnderstand") + || faultCodeName.equals("VersionMismatch") + || faultCodeName.equals("Client") + || faultCodeName.equals("Server") + || faultCodeName.startsWith("MustUnderstand.") + || faultCodeName.startsWith("VersionMismatch.") + || faultCodeName.startsWith("Client.") + || faultCodeName.startsWith("Server.")) + return true; + else + return false; + } + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1305.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1305.java new file mode 100644 index 000000000..fad1b9662 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1305.java @@ -0,0 +1,132 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.envelope; + +import java.net.HttpURLConnection; +import java.util.StringTokenizer; +import java.util.Vector; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionFailException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; +import org.w3c.dom.Document; +import org.w3c.dom.NodeList; + + +/** + * BP1305. + * It is in an HTTP 500 message with "Server" Error code. + */ +public class BP1305 extends AssertionProcess +{ + private final BaseMessageValidator validator; + + /** + * @param BaseMessageValidator + */ + public BP1305(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + + Document doc; + // Check if this is one way response + // or message is mepty or invalid + if (this.validator.isOneWayResponse(entryContext) + || (doc = entryContext.getMessageEntryDocument()) == null) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + else + { + // look for element: + NodeList faultList = + doc.getElementsByTagNameNS( + WSIConstants.NS_URI_SOAP, + XMLUtils.SOAP_ELEM_FAULT); + if ((faultList == null) || (faultList.getLength() == 0)) + { + // Response does not contain a soap:fault + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + else + { + // we have a soap:Fault. Check that it is contained in a HTTP 500 message + // GT : base HTTP Header parsing on BP1001 - this should be factored to a + // general-purpose HTTP message parsing method or methods (request & response) + String httpHeader = entryContext.getMessageEntry().getHTTPHeaders(); + //Response-Line = HTTP-Version ResponseCode ResponseMsg SP CRLF + Vector responseLine = new Vector(); + String startLine = null; + //String httpVersion = null; + //String responseCode = null; + String statusCode = null; + StringTokenizer httpMessageTokenizer = + new StringTokenizer(httpHeader, "\n\r\f"); + + if (httpMessageTokenizer.hasMoreTokens()) + startLine = httpMessageTokenizer.nextToken(); + + if (startLine.startsWith("HTTP")) + { + StringTokenizer startLineTokenizer = + new StringTokenizer(startLine, "\u0020"); + + while (startLineTokenizer.hasMoreTokens()) + { + responseLine.add(startLineTokenizer.nextToken()); + } + + //httpVersion = (String) responseLine.get(0); + + // PB: Check for 500 status code which should be the second token in the string + statusCode = (String) responseLine.get(1); + + //responseCode = (String) responseLine.get(1); + //statusCode = (String) responseLine.get(2); + } + try + { + // PB: Just check for 500 status code + if (!statusCode + .equals(String.valueOf(HttpURLConnection.HTTP_INTERNAL_ERROR))) + { + //if (!responseCode.equalsIgnoreCase("OK") || + // (!statusCode.equalsIgnoreCase("ServerError"))) { + // Assertion failed + throw new AssertionFailException(httpHeader); + } + } + catch (AssertionFailException e) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = this.validator.createFailureDetail(e.getMessage(), entryContext); + } + } + } + + // Return assertion result + return validator.createAssertionResult(testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1306.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1306.java new file mode 100644 index 000000000..1ec562f55 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1306.java @@ -0,0 +1,114 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.envelope; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionFailException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + + +/** + * BP1306. + * The soap:Fault element does not have children other than soap:faultcode, soap:faultstring, soap:faultactor or soap:detail. + */ +public class BP1306 extends AssertionProcess +{ + private final BaseMessageValidator validator; + + /** + * @param BaseMessageValidator + */ + public BP1306(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + + Document doc; + // Check if this is one way response + // or message is mepty or invalid + if (this.validator.isOneWayResponse(entryContext) + || (doc = entryContext.getMessageEntryDocument()) == null) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + else + { + // look for element: + NodeList faultList = + doc.getElementsByTagNameNS( + WSIConstants.NS_URI_SOAP, + XMLUtils.SOAP_ELEM_FAULT); + if ((faultList == null) || (faultList.getLength() == 0)) + { + // Response does not contain a soap:fault + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + else + { + // check that no soap:fault contains only faultcode, faultstring, faultactor, detail. + // If it does, further check that it is unqualified. + // For each + try + { + for (int n = 0; n < faultList.getLength(); n++) + { + for (Node child = faultList.item(n).getFirstChild(); + child != null; + child = child.getNextSibling()) + { + if ((child.getNodeType() == Node.ELEMENT_NODE) + && !(child + .getLocalName() + .equalsIgnoreCase(XMLUtils.SOAP_ELEM_FAULT_CODE) + || child.getLocalName().equalsIgnoreCase( + XMLUtils.SOAP_ELEM_FAULT_STRING) + || child.getLocalName().equalsIgnoreCase( + XMLUtils.SOAP_ELEM_FAULT_ACTOR) + || child.getLocalName().equalsIgnoreCase( + XMLUtils.SOAP_ELEM_FAULT_DETAIL))) + { + // PB: This is checked in 1316 now + //|| (child.getNamespaceURI() != null)) { + // Assertion failed + throw new AssertionFailException( + entryContext.getMessageEntry().getMessage()); + } + } + } + } + catch (AssertionFailException e) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = this.validator.createFailureDetail(e.getMessage(), entryContext); + } + } + } + + // Return assertion result + return validator.createAssertionResult(testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1307.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1307.java new file mode 100644 index 000000000..0e855da07 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1307.java @@ -0,0 +1,98 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.envelope; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionFailException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + + +/** + * BP1307. + * The elements of the message that are namespaced + * "http://schemas.xmlsoap.org/soap/envelope/" do not have a soap:encodingStyle attribute. + */ +public class BP1307 extends AssertionProcess +{ + private final BaseMessageValidator validator; + + /** + * @param BaseMessageValidator + */ + public BP1307(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + + Document doc; + // Check if this is one way response + // or message is mepty or invalid + if (this.validator.isOneWayResponse(entryContext) + || (doc = entryContext.getMessageEntryDocument()) == null) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + else + { + // look for elements: + NodeList soapList = + doc.getElementsByTagNameNS(WSIConstants.NS_URI_SOAP, "*"); + if ((soapList == null) || (soapList.getLength() == 0)) + { + // Response does not contain any soap envelope elements + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + else + { + // check that no elements contains a soap:encodingStyle attribute + // For each + try + { + for (int n = 0; n < soapList.getLength(); n++) + { + Element nextElem = (Element) soapList.item(n); + if (nextElem + .getAttributeNodeNS(WSIConstants.NS_URI_SOAP, "encodingStyle") + != null) + { + // Assertion failed + throw new AssertionFailException( + entryContext.getMessageEntry().getMessage()); + } + } + } + catch (AssertionFailException e) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = this.validator.createFailureDetail(e.getMessage(), entryContext); + } + } + } + + // Return assertion result + return validator.createAssertionResult(testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1308.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1308.java new file mode 100644 index 000000000..8c970c1d3 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1308.java @@ -0,0 +1,97 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.envelope; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.WSITag; +import org.eclipse.wst.wsi.internal.analyzer.AssertionFailException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionNotApplicableException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + + +/** + * BP1308. + * The children elements of soap:Body do not have a soap:encodingStyle attribute. + */ +public class BP1308 extends AssertionProcess implements WSITag +{ + private final BaseMessageValidator validator; + + /** + * @param BaseMessageValidator + */ + public BP1308(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + try + { + // Getting a message document + Document doc = entryContext.getMessageEntryDocument(); + // If the message is empty or invalid, the assertion is not applicable + if (doc == null) + throw new AssertionNotApplicableException(); + + // look for soap:Body elements: + NodeList soapBodyList = doc.getElementsByTagNameNS( + ELEM_SOAP_BODY.getNamespaceURI(), ELEM_SOAP_BODY.getLocalPart()); + + // The message does not contain any soap:Body, the assertion is not applicable + if ((soapBodyList == null) || (soapBodyList.getLength() == 0)) + throw new AssertionNotApplicableException(); + + // check that no soap:Body child elements contain a soap:encodingStyle attribute + // Getting the first soap:Body child element + Element child = + XMLUtils.getFirstChild((Element) soapBodyList.item(0)); + while (child != null) + { + if (child.getAttributeNodeNS( + ELEM_SOAP_BODY.getNamespaceURI(), "encodingStyle") != null) + { + throw new AssertionFailException("The child element name is \"" + + child.getNodeName() + "\"."); + } + // Getting the next soap:Body child element + child = XMLUtils.getNextSibling(child); + } + } + catch (AssertionNotApplicableException anae) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + catch (AssertionFailException afe) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = validator.createFailureDetail( + afe.getMessage(), entryContext); + } + + // Return assertion result + return validator.createAssertionResult( + testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1309.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1309.java new file mode 100644 index 000000000..9a011ea67 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1309.java @@ -0,0 +1,124 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.envelope; + +import java.util.Vector; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionFailException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + + +/** + * BP1309. + * The soap:Envelope does not have direct children after the soap:Body element + */ +public class BP1309 extends AssertionProcess +{ + private final BaseMessageValidator validator; + + /** + * @param BaseMessageValidator + */ + public BP1309(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + + Document doc; + // Check if this is one way response + // or message is mepty or invalid + if (this.validator.isOneWayResponse(entryContext) + || (doc = entryContext.getMessageEntryDocument()) == null) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + else + { + // look for elements: + // (Note: since this is a Soap message we expect exactly one soap envelope, but we do not assume it). + NodeList soapEnvList = + doc.getElementsByTagNameNS( + WSIConstants.NS_URI_SOAP, + XMLUtils.SOAP_ELEM_ENVELOPE); + if ((soapEnvList == null) || (soapEnvList.getLength() == 0)) + { + // Response does not contain any soap Envelope element(s) + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + else + { + // check that if a exists in a , that its the last in the envelope + try + { + // For each + for (int n = 0; n < soapEnvList.getLength(); n++) + { + // Get the list of all elements in the Envelope + Element soapEnv = (Element) soapEnvList.item(n); + NodeList envChildList = soapEnv.getChildNodes(); + Vector envChildElemList = new Vector(); + for (int v = 0; v < envChildList.getLength(); v++) + { + Node nextNode = envChildList.item(v); + if (nextNode.getNodeType() == Node.ELEMENT_NODE) + { + envChildElemList.addElement((Element) nextNode); + } + } + // Search the list for + for (int m = 0; m < envChildElemList.size(); m++) + { + Element envChildElem = (Element) envChildElemList.elementAt(m); + if (envChildElem + .getNamespaceURI() + .equals(WSIConstants.NS_URI_SOAP) + && envChildElem.getLocalName().equals(XMLUtils.SOAP_ELEM_BODY)) + { + // found a so check its the last in the list of child elements of the Envelope + if (envChildElem != envChildElemList.lastElement()) + { + throw new AssertionFailException( + entryContext.getMessageEntry().getMessage()); + } + } + } + } + } + catch (AssertionFailException e) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = this.validator.createFailureDetail(e.getMessage(), entryContext); + } + } + } + + // Return assertion result + return validator.createAssertionResult(testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1316.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1316.java new file mode 100644 index 000000000..b37461beb --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1316.java @@ -0,0 +1,113 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.envelope; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionFailException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + + +/** + * BP1316. + * The soap:Fault element children (soap:faultcode, soap:faultstring, soap:faultactor or soap:detail) are unqualified. + */ +public class BP1316 extends AssertionProcess +{ + private final BaseMessageValidator validator; + + /** + * @param BaseMessageValidator + */ + public BP1316(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + + Document doc; + // Check if this is one way response + // or message is mepty or invalid + if (this.validator.isOneWayResponse(entryContext) + || (doc = entryContext.getMessageEntryDocument()) == null) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + else + { + // look for element: + NodeList faultList = + doc.getElementsByTagNameNS( + WSIConstants.NS_URI_SOAP, + XMLUtils.SOAP_ELEM_FAULT); + if ((faultList == null) || (faultList.getLength() == 0)) + { + // Response does not contain a soap:fault + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + else + { + // check that no soap:fault contains only faultcode, faultstring, faultactor, detail. + // If it does, further check that it is unqualified. + // For each + try + { + for (int n = 0; n < faultList.getLength(); n++) + { + for (Node child = faultList.item(n).getFirstChild(); + child != null; + child = child.getNextSibling()) + { + if ((child.getNodeType() == Node.ELEMENT_NODE) + && (child + .getLocalName() + .equalsIgnoreCase(XMLUtils.SOAP_ELEM_FAULT_CODE) + || child.getLocalName().equalsIgnoreCase( + XMLUtils.SOAP_ELEM_FAULT_STRING) + || child.getLocalName().equalsIgnoreCase( + XMLUtils.SOAP_ELEM_FAULT_ACTOR) + || child.getLocalName().equalsIgnoreCase( + XMLUtils.SOAP_ELEM_FAULT_DETAIL)) + && (child.getNamespaceURI() != null)) + { + // Assertion failed + throw new AssertionFailException( + entryContext.getMessageEntry().getMessage()); + } + } + } + } + catch (AssertionFailException e) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = this.validator.createFailureDetail(e.getMessage(), entryContext); + } + } + } + + // Return assertion result + return validator.createAssertionResult(testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1318.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1318.java new file mode 100644 index 000000000..a6423b7c1 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1318.java @@ -0,0 +1,183 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.envelope; + +import javax.wsdl.Binding; +import javax.wsdl.BindingOperation; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionFailException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionNotApplicableException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.HTTPUtils; +import org.eclipse.wst.wsi.internal.util.OperationSignature; +import org.eclipse.wst.wsi.internal.util.TypesRegistry; +import org.eclipse.wst.wsi.internal.wsdl.WSDLUtils; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + + +/** + * BP1318 + * + * The grandchildren elements of soap:Body do not have a soap:encodingStyle attribute. + */ +public class BP1318 extends AssertionProcess +{ + private final BaseMessageValidator validator; + + /** + * @param BaseMessageValidator + */ + public BP1318(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + try + { + if (this.validator.isOneWayResponse(entryContext)) + throw new AssertionNotApplicableException(); + + // Parse message + Document responseDoc = entryContext.getMessageEntryDocument(); + Document requestDoc = entryContext.getRequestDocument(); + + // messages are empty or invalid, DOM objects are null + if (responseDoc == null || requestDoc == null) { + throw new AssertionNotApplicableException(); + } + + //if (isFault(responseDoc)) + // throw new AssertionNotApplicableException(); + + // Get SOAPAction + String headers = entryContext.getRequest().getHTTPHeaders(); + String action = null; + if (headers != null) + action = (String) HTTPUtils.getHttpHeaderTokens(headers, ":").get("SOAPAction".toUpperCase()); + + // Get the binding that is being processed + Binding binding = validator.analyzerContext.getCandidateInfo().getBindings()[0]; + + //Create the types registry + TypesRegistry registry = + new TypesRegistry( + this.validator.getWSDLDocument().getDefinitions(), + validator); + + // Find an operation match + OperationSignature.OperationMatch match = + OperationSignature.matchOperation( + requestDoc, + action, + binding, + registry); + if (match == null) + throw new AssertionNotApplicableException(); + + // Get the binding operation based on the match + BindingOperation bindingOperation = match.getOperation(); + + // If this is not rpc-literal, then return notApplicable result + if (!WSDLUtils + .isRpcLiteral(match.getOperationStyle(), bindingOperation)) + { + throw new AssertionNotApplicableException(); + } + // look for elements: + NodeList soapBodyList = + responseDoc.getElementsByTagNameNS( + WSIConstants.NS_URI_SOAP, + XMLUtils.SOAP_ELEM_BODY); + if ((soapBodyList == null) || (soapBodyList.getLength() == 0)) + // Response does not contain any soap Body elements + throw new AssertionNotApplicableException(); + + // check that no child or grandchild elements contains a soap:encodingStyle attribute + // For each + boolean grandChildFound = false; + for (int n = 0; n < soapBodyList.getLength(); n++) + { + Element nextBodyElem = (Element) soapBodyList.item(n); + // REMOVE: This will get all nodes (child, grandchildren, etc.) + //NodeList childList = nextBodyElem.getElementsByTagName("*"); + NodeList childList = nextBodyElem.getChildNodes(); + if (childList != null) + { + // check all child elements + for (int m = 0; m < childList.getLength(); m++) + { + if (childList.item(m).getNodeType() == Node.ELEMENT_NODE) + { + Element nextChildElem = (Element) childList.item(m); + // check children of this child + // REMOVE: This will get all nodes (child, grandchildren, etc.) + NodeList grandChildList = nextChildElem.getChildNodes(); + if (grandChildList != null) + { + for (int p = 0; p < grandChildList.getLength(); p++) + { + if (grandChildList.item(p).getNodeType() + == Node.ELEMENT_NODE) + { + grandChildFound = true; + Element nextGrandChildElem = + (Element) grandChildList.item(p); + if (nextGrandChildElem + .getAttributeNodeNS( + WSIConstants.NS_URI_SOAP, + "encodingStyle") + != null) + { + // Assertion failed (ADD highlight the child here ?) + throw new AssertionFailException( + entryContext.getMessageEntry().getMessage()); + } + } + } + } + } + } + } + } + if (!grandChildFound) + { + throw new AssertionNotApplicableException(); + } + } + catch (AssertionFailException e) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = this.validator.createFailureDetail(e.getMessage(), entryContext); + } + catch (AssertionNotApplicableException e) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + // Return assertion result + return validator.createAssertionResult(testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1600.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1600.java new file mode 100644 index 000000000..94712fd94 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1600.java @@ -0,0 +1,267 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.envelope; + +import java.util.Collection; +import java.util.HashSet; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionFailException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionNotApplicableException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; +import org.w3c.dom.Attr; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NamedNodeMap; + + +/** + * BP1600 + * + * For a candidate envelope + * The envelope conforms to the structure specified in SOAP 1.1 Section 4. + */ +public class BP1600 extends AssertionProcess +{ + private final BaseMessageValidator validator; + + /** + * @param BaseMessageValidator + */ + public BP1600(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + try + { + // Getting a message document + Document doc = entryContext.getMessageEntryDocument(); + + // If the message is empty or invalid, the assertion failed + if (doc == null) + { + if (this.validator.isOneWayResponse(entryContext)) + throw new AssertionNotApplicableException(); + else + throw new AssertionFailException("The log message is empty or invalid."); + } + // SOAP 1.1 specifications, Section 4. + // http://www.w3.org/TR/2000/NOTE-SOAP-20000508/#_Toc478383494 + + // The namespace identifier for the elements and attributes defined + // in this section is "http://schemas.xmlsoap.org/soap/envelope/". + + // o The Envelope is the top element of the XML document representing the message. + + // Rule 1. Envelope + // o The element name is "Envelope". + // o The element MUST be present in a SOAP message + // o The element MAY contain namespace declarations as well as additional attributes. + // If present, such additional attributes MUST be namespace-qualified. Similarly, + // the element MAY contain additional sub elements. If present these elements + // MUST be namespace-qualified and MUST follow the SOAP Body element. + + // Getting the top element + Element element = doc.getDocumentElement(); + + // Assuming that the top element should be soap:Envelope + // If not, the assertion failed + if (!element.getLocalName().equals(XMLUtils.SOAP_ELEM_ENVELOPE) + || !isSOAPNamespace(element.getNamespaceURI())) + throw new AssertionFailException("The top element is not soap:Envelope"); + + // Collecting all the namespace declarations + Collection envelopeNamespaces = collectNamespaces(element.getAttributes()); + envelopeNamespaces.add(WSIConstants.NS_URI_XMLNS); + + // Getting an attribute that is not in any of the namespaces + Attr notValidAttr = getNotValidAttr( + element.getAttributes(), + envelopeNamespaces); + + // If found one, the assertion failed + if (notValidAttr != null) + throw new AssertionFailException("The attribute " + + notValidAttr.getNodeName() + " is not namespace-qualified"); + + + // Rule 2. Header + // o The element name is "Header". + // o The element MAY be present in a SOAP message. If present, the element + // MUST be the first immediate child element of a SOAP Envelope element. + // o The element MAY contain a set of header entries each being an immediate + // child element of the SOAP Header element. All immediate child elements + // of the SOAP Header element MUST be namespace-qualified. + + // Getting the first sub element of the envelope + element = XMLUtils.getFirstChild(element); + + // If the child is soap:Header + if (element != null + && element.getLocalName().equals(XMLUtils.SOAP_ELEM_HEADER) + && isSOAPNamespace(element.getNamespaceURI())) + { + + // Going through all the Header entries + Element headerEntry = XMLUtils.getFirstChild(element); + while (headerEntry != null) + { + // Collecting all the namespaces for the current entry + Collection headerEntryNamespaces = collectNamespaces( + headerEntry.getAttributes()); + + // If the entry is not in the namespaces, the assertion failed + if (!envelopeNamespaces.contains(headerEntry.getNamespaceURI()) + && !headerEntryNamespaces.contains(headerEntry.getNamespaceURI())) + throw new AssertionFailException("The header entry " + + headerEntry.getNodeName() + " is not namespace-qualified"); + + // Getting the next Header entry + headerEntry = XMLUtils.getNextSibling(headerEntry); + } + + // Getting the next sub element of the envelope + element = XMLUtils.getNextSibling(element); + } + + + // Rule 3. Body + // o The element name is "Body". + // o The element MUST be present in a SOAP message and MUST be an immediate + // child element of a SOAP Envelope element. It MUST directly follow the + // SOAP Header element if present. Otherwise it MUST be the first immediate + // child element of the SOAP Envelope element. + // o The element MAY contain a set of body entries each being an immediate + // child element of the SOAP Body element. Immediate child elements of the + // SOAP Body element MAY be namespace-qualified. SOAP defines the SOAP Fault + // element, which is used to indicate error messages. + + // if the SOAP Body element is not presented, the assertion failed + if (element == null + || !element.getLocalName().equals(XMLUtils.SOAP_ELEM_BODY) + || !isSOAPNamespace(element.getNamespaceURI())) + throw new AssertionFailException("The soap:Body element is not presented " + + "or follows an additional sub element of soap:Envelope"); + + // Processing all other sub elements of the envelope + element = XMLUtils.getNextSibling(element); + while (element != null) + { + // Checking for the SOAP Header element + if (element.getLocalName().equals(XMLUtils.SOAP_ELEM_HEADER) + && isSOAPNamespace(element.getNamespaceURI())) + throw new AssertionFailException( + "The soap:Header element cannot follow the soap:Body element"); + + // Collecting all the namespaces for the current element + Collection elementNamespaces = collectNamespaces( + element.getAttributes()); + + // If the element is not in the namespaces, the assertion failed + if (!envelopeNamespaces.contains(element.getNamespaceURI()) + && !elementNamespaces.contains(element.getNamespaceURI())) + throw new AssertionFailException("The sub envelope element " + + element.getNodeName() + " is not namespace-qualified"); + + // Getting the next sub element of the envelope + element = XMLUtils.getNextSibling(element); + } + } + catch (AssertionFailException afe) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = validator.createFailureDetail( + afe.getMessage(), entryContext); + } + + catch (AssertionNotApplicableException anae) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + // Return assertion result + return validator.createAssertionResult( + testAssertion, result, failureDetail); + } + + /** + * Collects all the namespace declarations from attributes collection + * @param attrs an attributes collection + * @return a collection of namespaces + */ + private Collection collectNamespaces(NamedNodeMap attrs) + { + Collection ns = new HashSet(); + if (attrs != null) + { + for(int i = 0; i < attrs.getLength(); i++) + { + Attr attr = (Attr) attrs.item(i); + if (attr.getNamespaceURI() != null + && attr.getNamespaceURI().equals(WSIConstants.NS_URI_XMLNS)) + ns.add(attr.getValue()); + } + } + + return ns; + } + + /** + * Retrieves an attribute that is not in namespaces + * @param attrs an attributes collection + * @param ns a namespaces collection + * @return an attribtue that is not in any of the namespaces specified + */ + private Attr getNotValidAttr(NamedNodeMap attrs, Collection ns) + { + Attr ret = null; + if (attrs != null) + { + for(int i = 0; i < attrs.getLength(); i++) + { + Attr attr = (Attr) attrs.item(i); + if (attr.getNamespaceURI() == null + || !ns.contains(attr.getNamespaceURI())) + { + ret = attr; + break; + } + } + } + return ret; + } + + /** + * Qualifies whether a namespace is the SOAP namespace + * "http://schemas.xmlsoap.org/soap/envelope/" + * @param ns a namespace to be qualified + * @return true if the namespace is qualified, false otherwise + */ + private boolean isSOAPNamespace(String ns) + { + if (ns == null) + return false; + + return ns.equals(WSIConstants.NS_URI_SOAP); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1601.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1601.java new file mode 100644 index 000000000..602ddf8b8 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1601.java @@ -0,0 +1,73 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.envelope; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; +import org.xml.sax.SAXException; + + +/** + * BP1601. + */ +public class BP1601 extends AssertionProcess +{ + private final BaseMessageValidator validator; + + /** + * @param BaseMessageValidator + */ + public BP1601(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + // One-way responses will not contain a SOAP message + if (this.validator.isOneWayResponse(entryContext)) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + else + { + try + { + // Try to parse the SOAP message + //Document doc = XMLUtils.parseXML(entryContext.getMessageEntry().getMessage()); + XMLUtils.parseXML(entryContext.getMessageEntry().getMessage()); + } + catch (WSIException e) + { + if (e.getTargetException() instanceof SAXException) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = + this.validator.createFailureDetail( + e.getTargetException().getMessage(), + entryContext); + } + } + } + + // Return assertion result + return validator.createAssertionResult(testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1701.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1701.java new file mode 100644 index 000000000..ef7c55513 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1701.java @@ -0,0 +1,111 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.envelope; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.TestUtils; +import org.eclipse.wst.wsi.internal.util.Utils; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; +import org.xml.sax.SAXException; + +import com.ibm.wsdl.util.xml.DOM2Writer; + + +/** + * BP1701. + */ +public class BP1701 extends AssertionProcess +{ + private final BaseMessageValidator validator; + + /** + * @param BaseMessageValidator + */ + public BP1701(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + if (this.validator.isOneWayResponse(entryContext)) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + else + { + try + { + // TEMP: Use local copy of schema for now + // Document doc = XMLUtils.parseXML(entryContext.getLogEntry().getMessage(), WSIConstants.NS_URI_SOAP); + // Document doc = XMLUtils.parseXML(entryContext.getLogEntry().getMessage(), "schemas/soapEnvelope.xsd"); + + // Get a non-validated but (well-formed) DOM tree of the message content + Document doc = + XMLUtils.parseXML(entryContext.getMessageEntry().getMessage()); + + // Remove any xsi:types attributes from the message (SOAP Header, Body and Envelope itself) + + NodeList elementList = doc.getElementsByTagName("*"); + if (elementList != null) + { + for (int i = 0; i < elementList.getLength(); i++) + { + Element element = (Element) elementList.item(i); + element.removeAttributeNS(WSIConstants.NS_URI_XSI, "type"); + } + } + + // Write out the (potentially) modified tree to String + String filteredMessage = DOM2Writer.nodeToString(doc); + + // Parse the result with validation "on" + Document validationDoc = + XMLUtils.parseXML( + filteredMessage, + TestUtils.getSOAPSchemaLocation()); + } + catch (WSIException e) + { + if (e.getTargetException() instanceof SAXException) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = + this.validator.createFailureDetail( + Utils.getExceptionDetails(e.getTargetException()), + entryContext); + } + } + catch (Exception e) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = + this.validator.createFailureDetail(Utils.getExceptionDetails(e), entryContext); + } + } + + // Return assertion result + return validator.createAssertionResult(testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1755.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1755.java new file mode 100644 index 000000000..8f1a992b8 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP1755.java @@ -0,0 +1,167 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.envelope; + +import java.util.Iterator; +import java.util.List; + +import javax.wsdl.BindingOperation; +import javax.xml.namespace.QName; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionFailException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionNotApplicableException; +import org.eclipse.wst.wsi.internal.log.MessageEntry; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +/** + * BP1755 + * + * For a candidate non-fault envelope containing a soap:body with at least one element, and that is referred by a binding style RPC-literal + * Each part accessor element in the envelope has a local name of the same value as the name attribute of the corresponding wsdl:part element. + */ +public class BP1755 extends AssertionProcess { + + private final BaseMessageValidator validator; + + /** + * @param BaseMessageValidator + */ + public BP1755(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + try + { + if (validator.isOneWayResponse(entryContext)) + throw new AssertionNotApplicableException(); + + // Getting a message document + Document doc = entryContext.getMessageEntryDocument(); + + Element soapOperation = null; + // If there is a Fault entry or no body entries, + // the assertion is not applicable + if (validator.isFault(doc) + || (soapOperation = validator.getSoapBodyChild(doc)) == null) + throw new AssertionNotApplicableException(); + + // Creating a qualified name of potential SOAP operation + QName operationQName = new QName( + soapOperation.getNamespaceURI(), soapOperation.getLocalName()); + + // Retrieving all the RPC binding operations from wsdl:binding + BindingOperation[] rpcBindingOperations = + validator.getMatchingBindingOps( + WSIConstants.ATTRVAL_SOAP_BIND_STYLE_RPC, + validator.analyzerContext.getCandidateInfo().getBindings()); + + // Retrieving binding operation by given operation name + BindingOperation bindingOperation = validator.getOperationMatch( + entryContext.getEntry().getEntryType(), + operationQName, + rpcBindingOperations); + + // If there is no matched operation, the assertion is not applicable + if (bindingOperation == null) + throw new AssertionNotApplicableException(); + + // Finding operation message parts and extensibility elems + // in the binding depending on message type + List operationMessageParts = null; + List extElems = null; + if (entryContext.getMessageEntry().getType().equals( + MessageEntry.TYPE_REQUEST)) + { + operationMessageParts = bindingOperation.getOperation() + .getInput().getMessage().getOrderedParts(null); + if (bindingOperation.getBindingInput() != null) + extElems = + bindingOperation.getBindingInput().getExtensibilityElements(); + } + else + { + operationMessageParts = bindingOperation.getOperation() + .getOutput().getMessage().getOrderedParts(null); + if (bindingOperation.getBindingOutput() != null) + extElems = + bindingOperation.getBindingOutput().getExtensibilityElements(); + } + + // If the message is not literal, the assertion is not applicable + if (!validator.isLiteral(extElems)) + throw new AssertionNotApplicableException(); + + + /* Basic Profile Version 1.1 (http://www.ws-i.org/Profiles/Basic/2003-12/BasicProfile-1.1.htm) + * says that the order of the elements in the soap:body of an ENVELOPE MUST be + * the same as that of the wsdl:parts in the wsdl:message that describes it. + * However, we should keep in mind there is the "parts" attribute of soapbind:body + * that indicates which parts appear within the SOAP Body. + */ + + // Getting the ordered list of wsdl:part names + List orderedPartNames = + validator.orderPartNames(operationMessageParts, extElems); + Iterator i = orderedPartNames.iterator(); + // Getting the first accessor + Element accessor = XMLUtils.getFirstChild(soapOperation); + while (accessor != null) + { + // If there is no the corresponding wsdl:part element + // for an accessor, the assertion failed + if (!i.hasNext()) + throw new AssertionFailException( + "The part accessor element '" + accessor.getLocalName() + + "' does not have the corresponding wsdl:part element."); + + // If local name of accessor does not equal to the name of the + // corresponding wsdl:part element, the assertion failed + String partName = (String) i.next(); + if (!accessor.getLocalName().equals(partName)) + throw new AssertionFailException( + "The accessor local name is " + accessor.getLocalName() + + ", the corresponding part element name is " + partName); + + // Getting the next accessor + accessor = XMLUtils.getNextSibling(accessor); + } + } + catch (AssertionNotApplicableException anae) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + catch (AssertionFailException afe) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = validator.createFailureDetail( + afe.getMessage(), entryContext); + } + + return validator.createAssertionResult( + testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP4100.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP4100.java new file mode 100644 index 000000000..d3e8f1c9e --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP4100.java @@ -0,0 +1,226 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.envelope; + +import java.util.Iterator; +import java.util.List; + +import javax.wsdl.Binding; +import javax.wsdl.BindingInput; +import javax.wsdl.BindingOperation; +import javax.wsdl.BindingOutput; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.soap.SOAPHeader; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionNotApplicableException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionPassException; +import org.eclipse.wst.wsi.internal.log.MessageEntry; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + + + +/** + * BP4100 + * For a candidate envelope containing a header block that is either mandatory or is not described in the wsdl:binding. + * An envelope contains a header block that is either mandatory or is not described in the wsdl:binding. + */ +public class BP4100 extends AssertionProcess { + + private final BaseMessageValidator validator; + + /** + * @param BaseMessageValidator + */ + public BP4100(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + try + { + // Parsing the message + Document doc = entryContext.getMessageEntryDocument(); + + // If the message is empty or invalid, the assertion is not applicable + if (doc == null) + { + throw new AssertionNotApplicableException(); + } + + // Getting header elements from envelope + Element root = doc.getDocumentElement(); + NodeList headerList = root.getElementsByTagNameNS( + WSIConstants.NS_URI_SOAP, XMLUtils.SOAP_ELEM_HEADER); + + // If there is no header, the assertion is not applicable + if (headerList == null || headerList.getLength() == 0) + { + throw new AssertionNotApplicableException(); + } + + // Getting the header element + Node header = headerList.item(0); + + // Getting the immediate child elements of the header + NodeList elems = header.getChildNodes(); + + // If there are no child elements of the header + // the assertion is not applicable + if (elems == null || elems.getLength() == 0) + { + throw new AssertionNotApplicableException(); + } + + // Walking through child elements + for (int i = 0; i < elems.getLength(); i++) + { + + if (elems.item(i).hasAttributes()) + { + // Getting the mustUnderstand attribute + Node muNode = elems.item(i).getAttributes().getNamedItem( + root.getPrefix() + ":" + XMLUtils.SOAP_ATTR_MUST_UNDERSTAND); + // If a header block is mandatory, then the assertion passed + if (muNode != null && muNode.getNodeValue().equals("1")) + { + throw new AssertionPassException(); + } + } + + // Getting header block name + String blockName = elems.item(i).getLocalName(); + // If the name is not presented (occurs when element is empty string) + // then continue with the next element + if (blockName == null) + { + continue; + } + + boolean blockNameExists = false; + + // Getting WSDL bindings + Binding[] bindings = validator.getWSDLDocument().getBindings(); + for (int j = 0; j < bindings.length; j++) + { + // Getting wsdl:operations + List operations = bindings[j].getBindingOperations(); + Iterator k = operations.iterator(); + while (k.hasNext() && !blockNameExists) + { + BindingOperation operation = (BindingOperation) k.next(); + + // If this is a request message, + // then getting wsdl:input for an operation + if (entryContext.getMessageEntry().getType().equals( + MessageEntry.TYPE_REQUEST)) + { + BindingInput opInput = operation.getBindingInput(); + if (opInput != null) + { + // If wsdl:input is presented then checking + // whether the block name is described there or not + blockNameExists = blockNameExists( + opInput.getExtensibilityElements(), blockName); + } + } + // If this is a response message, + // then getting wsdl:output for an operation + else + { + BindingOutput opOutput = operation.getBindingOutput(); + if (opOutput != null) + { + // If wsdl:output is presented then checking + // whether the block name is described there or not + blockNameExists = blockNameExists( + opOutput.getExtensibilityElements(), blockName); + } + } + } + } + + // If a header block is not described in the appropriate wsdl:binding + // then the assertion passed + if (!blockNameExists) + { + throw new AssertionPassException(); + } + } + + // No one header block is either mandatory or is not described in the + // appropriate wsdl:binding, the assertion is not applicable + result = AssertionResult.RESULT_NOT_APPLICABLE; + + } + catch (AssertionPassException ape) + { + failureDetail = validator.createFailureDetail( + testAssertion.getDetailDescription(), entryContext); + } + catch (AssertionNotApplicableException anae) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + + return validator.createAssertionResult( + testAssertion, result, failureDetail); + } + + /** + * Checks the existense of blockName in wsdlsoap:header, if it is found in + * a list of ExtensibilityElement objects + * + * @param elems A list of ExtensibilityElement objects + * @param blockName The name that will be checked for existence + * @return true if blockName is described in the wsdlsoap:header extensibility element + */ + private boolean blockNameExists(List elems, String blockName) + { + if (elems == null) + { + return false; + } + + Iterator i = elems.iterator(); + while (i.hasNext()) + { + ExtensibilityElement elem = (ExtensibilityElement) i.next(); + String elemName = elem.getElementType().getLocalPart(); + if (elemName.equals("header")) + { + SOAPHeader soapHeader = (SOAPHeader) elem; + if (soapHeader.getPart().equals(blockName)) + { + return true; + } + } + } + + return false; + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP4101.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP4101.java new file mode 100644 index 000000000..ccf155e45 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP4101.java @@ -0,0 +1,132 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.envelope; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionNotApplicableException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionPassException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +/** + * BP4101 + * For a candidate envelope containing a soap:actor attribute with a value other than the special uri "http://schemas.xmlsoap.org/soap/actor/next". + * A header element in the envelope contains a soap:actor attribute with a value other than the special uri "http://schemas.xmlsoap.org/soap/actor/next". + */ +public class BP4101 extends AssertionProcess { + + private final BaseMessageValidator validator; + + /** + * @param BaseMessageValidator + */ + public BP4101(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + try { + + // Parsing the message + Document doc = entryContext.getMessageEntryDocument(); + + // If the message is empty or invalid, the assertion is not applicable + if (doc == null) + { + throw new AssertionNotApplicableException(); + } + + // Getting header elements from envelope + Element root = doc.getDocumentElement(); + NodeList headerList = root.getElementsByTagNameNS( + WSIConstants.NS_URI_SOAP, XMLUtils.SOAP_ELEM_HEADER); + + // If there is no header, the assertion is not applicable + if (headerList == null || headerList.getLength() == 0) + { + throw new AssertionNotApplicableException(); + } + + // Getting the header element + Node header = headerList.item(0); + + // Getting the immediate child elements of the header + NodeList elems = header.getChildNodes(); + + // If there is no child elements of the header + // the assertion is not applicable + if (elems == null || elems.getLength() == 0) + { + throw new AssertionNotApplicableException(); + } + + // Walking through child elements + for (int i = 0; i < elems.getLength(); i++) + { + // Getting node attributes + NamedNodeMap attrs = elems.item(i).getAttributes(); + + // If the node does not have attributes then continue + if (attrs == null) + { + continue; + } + + // Getting actor attribute + Node actor = attrs.getNamedItem(root.getPrefix() + + ":" + XMLUtils.SOAP_ATTR_ACTOR); + + // If the actor attribute is presented and does not equal + // to "http://schemas.xmlsoap.org/soap/actor/next", + // then the assertion passed + if (actor != null + && !actor.getNodeValue().equals(WSIConstants.NS_URI_SOAP_NEXT_ACTOR)) + { + throw new AssertionPassException(); + } + } + + // No one actor attribute has a value other than + // "http://schemas.xmlsoap.org/soap/actor/next", + // the assertion is not applicable + result = AssertionResult.RESULT_NOT_APPLICABLE; + + } + catch (AssertionPassException ape) + { + failureDetail = validator.createFailureDetail( + testAssertion.getDetailDescription(), entryContext); + } + catch (AssertionNotApplicableException anae) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + + return validator.createAssertionResult( + testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP4102.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP4102.java new file mode 100644 index 000000000..e49c072d3 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP4102.java @@ -0,0 +1,114 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.envelope; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionNotApplicableException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionPassException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +/** + * BP4102 + * For a candidate envelope containing a fault with a non-empty detail element. + * A Fault element in an envelope contains a non-empty detail element. + */ +public class BP4102 extends AssertionProcess { + + private final BaseMessageValidator validator; + + /** + * @param BaseMessageValidator + */ + public BP4102(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + try { + + // Parsing the message + Document doc = entryContext.getMessageEntryDocument(); + + // If the message is empty or invalid, the assertion is not applicable + if (doc == null) + { + throw new AssertionNotApplicableException(); + } + + // Getting Fault elements from envelope + Element root = doc.getDocumentElement(); + NodeList faultList = root.getElementsByTagNameNS( + WSIConstants.NS_URI_SOAP, XMLUtils.SOAP_ELEM_FAULT); + + // If there is no Fault element, the assertion is not applicable + if (faultList == null || faultList.getLength() == 0) + { + throw new AssertionNotApplicableException(); + } + + // Fault element must not appear more than once + // within a Body element, so getting the first one + Element fault = (Element) faultList.item(0); + + // Getting Fualt's detail elements + NodeList details = fault.getElementsByTagName( + XMLUtils.SOAP_ELEM_FAULT_DETAIL); + // If there is a non-empty detail element, then the assertion passed + if (details != null + && details.getLength() > 0) + { + NodeList list = details.item(0).getChildNodes(); + // search first element node + for (int i = 0; i < list.getLength(); i++) + { + if((list.item(i).getNodeType() == Node.ELEMENT_NODE) + && (list.item(i).getLocalName() != null) ) + { + throw new AssertionPassException(); + } + } + } + + // There is no detail element in Fault, + // the assertion is not applicable + result = AssertionResult.RESULT_NOT_APPLICABLE; + + } + catch (AssertionPassException ape) + { + failureDetail = validator.createFailureDetail( + testAssertion.getDetailDescription(), entryContext); + } + catch (AssertionNotApplicableException anae) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + + return validator.createAssertionResult( + testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP4109.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP4109.java new file mode 100644 index 000000000..0613b0d23 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/BP4109.java @@ -0,0 +1,107 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.envelope; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionNotApplicableException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionPassException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; +import org.w3c.dom.Attr; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.NodeList; + +/** + * BP4109 + * + * For a candidate envelope containing a soap:Body element with attributes + * An envelope contains a a soap:Body element with attributes. + */ +public class BP4109 extends AssertionProcess { + + private final BaseMessageValidator validator; + + /** + * @param BaseMessageValidator + */ + public BP4109(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + try { + + // Parsing the message + Document doc = entryContext.getMessageEntryDocument(); + + // If the message is empty or invalid, the assertion is not applicable + if (doc == null) + { + throw new AssertionNotApplicableException(); + } + + // Getting the soap:Body elements from envelope + NodeList bodyList = doc.getDocumentElement().getElementsByTagNameNS( + WSIConstants.NS_URI_SOAP, XMLUtils.SOAP_ELEM_BODY); + + // If there is no Body element, the assertion is not applicable + if (bodyList == null || bodyList.getLength() == 0) + { + throw new AssertionNotApplicableException(); + } + + // Getting the first soap:Body element + Element body = (Element) bodyList.item(0); + + // If the Body element has attributes (excluding namespace declarations), + // the assertion passed + NamedNodeMap attrs = body.getAttributes(); + if (attrs != null) + { + for (int i = 0; i < attrs.getLength(); i++) + { + String attrName = ((Attr) attrs.item(i)).getName(); + if (!attrName.equals("xmlns") && !attrName.startsWith("xmlns:")) + { + throw new AssertionPassException(); + } + } + } + + throw new AssertionNotApplicableException(); + } + catch (AssertionPassException ape) + { + failureDetail = validator.createFailureDetail( + testAssertion.getDetailDescription(), entryContext); + } + catch (AssertionNotApplicableException anae) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + + return validator.createAssertionResult( + testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/EnvelopeValidatorImpl.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/EnvelopeValidatorImpl.java new file mode 100644 index 000000000..f8c226939 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/EnvelopeValidatorImpl.java @@ -0,0 +1,56 @@ +/******************************************************************************* + * Copyright (c) 2002-2003 IBM Corporation, Parasoft and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + * Parasoft - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.envelope; + +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.EnvelopeValidator; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.util.EntryType; + +/** + * @version 1.0 + */ +public class EnvelopeValidatorImpl + extends BaseMessageValidator + implements EnvelopeValidator +{ + /* (non-Javadoc) + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl#isPrimaryEntryTypeMatch(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + protected boolean isPrimaryEntryTypeMatch( + TestAssertion testAssertion, + EntryContext entryContext) + { + boolean match = false; + + // Verify that the entry and test assertion have the same primary context + if ((testAssertion.getEntryTypeName().equals(EntryType.TYPE_ENVELOPE_ANY)) + || (testAssertion.getEntryTypeName().equals(EntryType.TYPE_ENVELOPE_REQUEST) + && (entryContext + .getEntry() + .getEntryType() + .getTypeName() + .equals(EntryType.TYPE_MESSAGE_REQUEST))) + || (testAssertion.getEntryTypeName().equals(EntryType.TYPE_ENVELOPE_RESPONSE) + && (entryContext + .getEntry() + .getEntryType() + .getTypeName() + .equals(EntryType.TYPE_MESSAGE_RESPONSE)))) + { + match = true; + } + + return match; + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/SSBP1601.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/SSBP1601.java new file mode 100644 index 000000000..5daae51b2 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/SSBP1601.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.envelope; + +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; + +/** + * SSBP1601 + */ +public class SSBP1601 extends BP1601 +{ + + /** + * @param BaseMessageValidator + */ + public SSBP1601(BaseMessageValidator impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/SSBP9704.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/SSBP9704.java new file mode 100644 index 000000000..1ac0eb1ad --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/envelope/SSBP9704.java @@ -0,0 +1,126 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.envelope; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionFailException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionNotApplicableException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +/** + * SSBP9704 + * + * For a candidate envelope + * The ENVELOPE does not contain the namespace declaration xmlns:xml="http://www.w3.org/XML/1998/namespace". + */ +public class SSBP9704 extends AssertionProcess +{ + private final BaseMessageValidator validator; + + /** + * @param BaseMessageValidator + */ + public SSBP9704(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + try + { + // Getting a message document + Document doc = entryContext.getMessageEntryDocument(); + // If the message is empty or invalid, the assertion is not applicable + if (doc == null) + { + throw new AssertionNotApplicableException(); + } + + // Getting the root element + Element elem = doc.getDocumentElement(); + // If it is not the soap:Envelope, the assertion is not applicable + if (!elem.getNamespaceURI().equals(WSIConstants.NS_URI_SOAP) + || !elem.getLocalName().equals(XMLUtils.SOAP_ELEM_ENVELOPE)) + { + throw new AssertionNotApplicableException(); + } + + // If the envelope contains the xmlns:xml namespace declaration, + // the assertion failed + String incorrectElementName = getIncorrectElementName(elem); + if (incorrectElementName != null) + { + throw new AssertionFailException("The name of an element containing " + + "such namespace declaration is \"" + incorrectElementName + "\"."); + } + } + catch (AssertionNotApplicableException anae) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + catch (AssertionFailException afe) + { + result = AssertionResult.RESULT_WARNING; + failureDetail = validator.createFailureDetail( + afe.getMessage(), entryContext); + } + + // Return assertion result + return validator.createAssertionResult( + testAssertion, result, failureDetail); + } + + /** + * Looks for any element that contains the attribute xmlns:xml="http://www.w3.org/XML/1998/namespace". + * @param elem the root element. + * @return the name of an element found or null. + */ + private String getIncorrectElementName(Element elem) + { + // Getting a value of the attribute xmlns:xml + String attrValue = elem.getAttributeNS( + WSIConstants.NS_URI_XMLNS, "xml"); + // If it equals to "http://www.w3.org/XML/1998/namespace", + // return an element name; + if (WSIConstants.NS_URI_XML.equals(attrValue)) + { + return elem.getNodeName(); + } + // Going through element's children + Element child = XMLUtils.getFirstChild(elem); + while (child != null) + { + // If any of them has xmlns:xml attribute, return a value + String name = getIncorrectElementName(child); + if (name != null) + { + return name; + } + // Getting the next element's child + child = XMLUtils.getNextSibling(child); + } + // No xmlns:xml attributes found, return null + return null; + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/AP1003.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/AP1003.java new file mode 100644 index 000000000..9d1217fd6 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/AP1003.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; + +/** + * AP1003 + * + * For a candidate non-multipart/related message in the log file, which has a non-empty entity-body + * + * The logged SOAP envelope is a UTF-8 transcript of an envelope originally encoded as UTF-8 or UTF-16. + * The HTTP Content-Type header's charset value is either UTF-8 or UTF-16. Looking at the messageContent + * element of the logged message, either + * (1) it has a BOM attribute which maps the charset value in the Content-Type header, or + * (2) it has it has an XML declaration which matches the charset value in the Content-Type header, or + * (3) there is no BOM attribute and no XML declaration, and the charset value is UTF-8. + * + * + * @author lauzond + */ +public class AP1003 extends SSBP1003 { + + /** + * @param impl + */ + public AP1003(BaseMessageValidator impl) + { + super(impl); + } + + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + // If there is a SOAP Message with Attachments, the assertion is not applicable + if (entryContext.getMessageEntry().isMimeContent()) + { + return validator.createAssertionResult(testAssertion, AssertionResult.RESULT_NOT_APPLICABLE, failureDetail); + } + else + { + return super.validate(testAssertion, entryContext); + } + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/AP1902.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/AP1902.java new file mode 100644 index 000000000..d0123a4e0 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/AP1902.java @@ -0,0 +1,124 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import java.util.List; + +import javax.wsdl.BindingOperation; +import javax.wsdl.extensions.ExtensibilityElement; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.WSITag; +import org.eclipse.wst.wsi.internal.analyzer.AssertionFailException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionNotApplicableException; +import org.eclipse.wst.wsi.internal.log.MessageEntry; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; + +/** + * AP1902 + * + * For a candidate message + * In a description, if the wsdl:input or wsdl:output + * element in the wsdl:binding specifies WSDL MIME binding, then the message + * can contain SOAP attachments. + */ +public class AP1902 extends AssertionProcess implements WSITag +{ + private final BaseMessageValidator validator; + + /** + * @param WSDLValidatorImpl + */ + public AP1902(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + /* Validates the test assertion. + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + try + { + // Getting an operation matched for a message + BindingOperation bindingOperation = validator.getOperationMatch( + entryContext.getEntry().getEntryType(), + entryContext.getMessageEntryDocument()); + // If no one operation matches, the assertion is not applicable + if (bindingOperation == null) + throw new AssertionNotApplicableException(); + // Getting the corresponding extensibility elements + List extElems; + String type; + if (MessageEntry.TYPE_REQUEST + .equals(entryContext.getEntry().getEntryType())) + { + type = "input"; + extElems = bindingOperation.getBindingInput() == null ? null + : bindingOperation.getBindingInput().getExtensibilityElements(); + } + else + { + type = "output"; + extElems = bindingOperation.getBindingOutput() == null ? null + : bindingOperation.getBindingOutput().getExtensibilityElements(); + } + // If the MIME binding is not used, but the message has + // at least one non-root MIME part, the assertion failed + if (!usesMimeBinding(extElems) + && entryContext.getMessageEntry().getMimeParts().count() > 1) + { + throw new AssertionFailException("The wsdl:" + type + " of the \"" + + bindingOperation.getName() + "\" binding operation."); + } + } + catch (AssertionNotApplicableException anae) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + catch (AssertionFailException afe) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = validator.createFailureDetail( + afe.getMessage(), entryContext); + } + // Return assertion result + return validator.createAssertionResult( + testAssertion, result, failureDetail); + } + + /** + * Checks whether the first extensibility element is mime:multipartRelated. + * @param extElems a list of extensibility elements. + * @return true if the element is mime:multipartRelated, false otherwise + */ + private boolean usesMimeBinding(List extElems) { + // If the first extensibility element is mime:multipartRelated, + // return true + if (extElems != null && extElems.size() > 0 + && ((ExtensibilityElement)extElems.get(0)) + .getElementType().equals(WSDL_MIME_MULTIPART)) + { + return true; + } + // otherwise return false + return false; + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/AP1915.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/AP1915.java new file mode 100644 index 000000000..138338d23 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/AP1915.java @@ -0,0 +1,136 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionFailException; +import org.eclipse.wst.wsi.internal.log.MimePart; +import org.eclipse.wst.wsi.internal.log.MimeParts; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.MIMEConstants; +import org.eclipse.wst.wsi.internal.util.MIMEUtils; +import org.eclipse.wst.wsi.internal.util.Utils; + +/** + * AP1915 + * + * For a candidate root-part of a multipart/related message + * The entity body of the root-part of a + * multipart/related message is serialized using either UTF-8 or UTF-16 + * character encoding. + */ +public class AP1915 extends AssertionProcess +{ + private final BaseMessageValidator validator; + + /** + * @param WSDLValidatorImpl + */ + public AP1915(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + /* Validates the test assertion. + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + // get MIME parts + if (!entryContext.getMessageEntry().isMimeContent()) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + else + { + MimeParts mimeParts = entryContext.getMessageEntry().getMimeParts(); + MimePart part = mimeParts.getRootPart(); + if (part == null) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + else + { + String xmlEncoding = null; + String charset = MIMEUtils.getMimeHeaderSubAttribute( + part.getHeaders(), + MIMEConstants.HEADER_CONTENT_TYPE, + "charset"); + try + { + // The HTTP Content-Type header's charset value is either UTF-8 or UTF-16. + if((charset != null) && (charset.equalsIgnoreCase("utf-8") || + charset.equalsIgnoreCase("utf-16"))) + { + // Looking at the messageContent element of the logged message, either + // (1) it has a BOM attribute which maps the charset value in the Content-Type header, or + int bom = 0; + if ((bom = entryContext.getMessageEntry().getBOM()) != 0) + { + if ((bom == WSIConstants.BOM_UTF8 + && !charset.equalsIgnoreCase("utf-8")) + || ((bom == WSIConstants.BOM_UTF16 + && !charset.equalsIgnoreCase("utf-16"))) + || ((bom == WSIConstants.BOM_UTF16_BIG_ENDIAN + && !charset.equalsIgnoreCase("utf-16")))) + { + throw new AssertionFailException("The BOM (" + bom + + ") and charset value (" + charset + ")do not match."); + } + } + // (2) it has an XML declaration which matches the charset value in the Content-Type header, or + else if (((xmlEncoding = + Utils.getXMLEncoding(part.getContent())) != null) && + !xmlEncoding.equals("")) + { + if(!xmlEncoding.equalsIgnoreCase(charset)) + { + throw new AssertionFailException("The XML declaration encoding (" + + xmlEncoding + ") and charset value (" + charset + + ") do not match."); + } + + } + // (3) there is no BOM attribute and no XML declaration, and the charset value is UTF-8. + else if(!charset.equalsIgnoreCase("utf-8")) + { + throw new AssertionFailException("The no BOM attribute and no XML "+ + "declaration, and the charset value is (" + charset + ")"); + } + } + // header do not found or incorrect charset value + else + { + throw new AssertionFailException("Either the Content-Type header is not "+ + "present in the Root Part or a charset value is invalid."); + } + } + catch (AssertionFailException e) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = validator.createFailureDetail(e.getMessage(), entryContext); + } + } + } + // Return assertion result + return validator.createAssertionResult( + testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/AP1917.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/AP1917.java new file mode 100644 index 000000000..723b8e002 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/AP1917.java @@ -0,0 +1,153 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import java.util.List; + +import javax.wsdl.BindingOperation; +import javax.wsdl.extensions.mime.MIMEMultipartRelated; +import javax.wsdl.extensions.soap.SOAPBody; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionFailException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionNotApplicableException; +import org.eclipse.wst.wsi.internal.log.MessageEntry; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.HTTPConstants; +import org.eclipse.wst.wsi.internal.util.HTTPUtils; + +/** + * AP1917 + * + * For a candidate message containing zero attachment parts + * A message containing zero attachment parts is sent + * using a content-type of either "text/xml" as though a SOAP HTTP binding were + * used or "multipart/related" when the WSDL description for the message + * specifies the mime:multipartRelated element on the corresponding wsdl:input + * or wsdl:output element in its wsdl:binding. + */ +public class AP1917 extends AssertionProcess +{ + private final BaseMessageValidator validator; + + /** + * @param WSDLValidatorImpl + */ + public AP1917(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + /* Validates the test assertion. + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + try + { + // not applicable if there are attachments + if (entryContext.getMessageEntry().isMimeContent()) + { + if (entryContext.getMessageEntry().getMimeParts().count() > 1) + throw new AssertionNotApplicableException(); + } + + BindingOperation bindingOperation = validator.getOperationMatch( + entryContext.getEntry().getEntryType(), + entryContext.getMessageEntryDocument()); + + // If there is no matched operation, the assertion is not applicable + if (bindingOperation == null) + throw new AssertionNotApplicableException(); + + // Finding operation extensibility elems + // in the binding depending on message type + List extElems = null; + if (entryContext.getMessageEntry().getType().equals( + MessageEntry.TYPE_REQUEST) + && bindingOperation.getBindingInput() != null) + { + extElems = bindingOperation + .getBindingInput().getExtensibilityElements(); + } + else if (entryContext.getMessageEntry().getType().equals( + MessageEntry.TYPE_RESPONSE) + && bindingOperation.getBindingOutput() != null) + { + extElems = bindingOperation + .getBindingOutput().getExtensibilityElements(); + } + + // check list + if((extElems == null) || (extElems.size() == 0)) + { + throw new AssertionNotApplicableException(); + } + + // determine type + boolean isMultiPart = false; + + // if MIMEMultipartRelated then only root-part allowed + if(extElems.get(0) instanceof MIMEMultipartRelated) + { + if(((MIMEMultipartRelated) extElems.get(0)).getMIMEParts().size() != 1) { + throw new AssertionNotApplicableException(); + } + isMultiPart = true; + } + // else if not soapbind:body root element + else if(!(extElems.get(0) instanceof SOAPBody)) + { + throw new AssertionNotApplicableException(); + } + + // get HTTP content type + String contentType = HTTPUtils.getHttpHeaderAttribute( + entryContext.getMessageEntry().getHTTPHeaders(), + HTTPConstants.HEADER_CONTENT_TYPE); + + //allow "text/xml" or + //("multipart/related" and "mime:multipartRelated" WSDL bindings) + if((contentType == null) || + (!contentType.equalsIgnoreCase(WSIConstants.CONTENT_TYPE_MULTIPART) && + !contentType.equalsIgnoreCase(WSIConstants.CONTENT_TYPE_TEXT_XML)) || + ((contentType.equalsIgnoreCase(WSIConstants.CONTENT_TYPE_MULTIPART) && + !isMultiPart))) + { + throw new AssertionFailException("The content-type header field " + + "value \"" + contentType + "\" is incorrect"); + } + } + catch (AssertionNotApplicableException e) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + catch (AssertionFailException e) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = + validator.createFailureDetail(e.getMessage(), entryContext); + } + + // Return assertion result + return validator.createAssertionResult( + testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/AP1925.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/AP1925.java new file mode 100644 index 000000000..d4a0b3cfa --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/AP1925.java @@ -0,0 +1,136 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import java.util.List; + +import javax.wsdl.BindingOperation; +import javax.wsdl.extensions.mime.MIMEContent; +import javax.wsdl.extensions.mime.MIMEMultipartRelated; +import javax.wsdl.extensions.mime.MIMEPart; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionFailException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionNotApplicableException; +import org.eclipse.wst.wsi.internal.log.MessageEntry; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.HTTPConstants; +import org.eclipse.wst.wsi.internal.util.HTTPUtils; + +/** + * AP1925 + * + * For a candidate message + * If the WSDL description lists at least one non-root + * MIME part, then the corresponding message has a Content-Type HTTP header + * field-value with a media-type of "multipart/related. + */ +public class AP1925 extends AssertionProcess +{ + private final BaseMessageValidator validator; + + /** + * @param WSDLValidatorImpl + */ + public AP1925(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + /* Validates the test assertion. + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + try + { + BindingOperation bindingOperation = validator.getOperationMatch( + entryContext.getEntry().getEntryType(), + entryContext.getMessageEntryDocument()); + + // If there is no matched operation, the assertion is not applicable + if (bindingOperation == null) + throw new AssertionNotApplicableException(); + + // Finding operation extensibility elems + // in the binding depending on message type + List extElems = null; + if (entryContext.getMessageEntry().getType().equals( + MessageEntry.TYPE_REQUEST) + && bindingOperation.getBindingInput() != null) + { + extElems = bindingOperation + .getBindingInput().getExtensibilityElements(); + } + else if (entryContext.getMessageEntry().getType().equals( + MessageEntry.TYPE_RESPONSE) + && bindingOperation.getBindingOutput() != null) + { + extElems = bindingOperation + .getBindingOutput().getExtensibilityElements(); + } + // check list on first element + if((extElems == null) || (extElems.size() == 0) || + !(extElems.get(0) instanceof MIMEMultipartRelated)) + throw new AssertionNotApplicableException(); + + // get list mime parts from definition + MIMEMultipartRelated mime = (MIMEMultipartRelated) extElems.get(0); + List parts = mime.getMIMEParts(); + // if parts count is more than one, than assertion is notApplicable + if(parts.size() <= 1) + throw new AssertionNotApplicableException(); + String contentType = HTTPUtils.getHttpHeaderAttribute( + entryContext.getMessageEntry().getHTTPHeaders(), + HTTPConstants.HEADER_CONTENT_TYPE); + if((contentType == null) || + !contentType.equalsIgnoreCase(WSIConstants.CONTENT_TYPE_MULTIPART)) + { + throw new AssertionFailException("Incorrect Content-Type value \"" + + contentType + "\" in HTTP header"); + } + } + catch (AssertionNotApplicableException e) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + catch (AssertionFailException e) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = + validator.createFailureDetail(e.getMessage(), entryContext); + } + // Return assertion result + return validator.createAssertionResult( + testAssertion, result, failureDetail); + } + + /** + * Returns the part value from MIMEContent element + * @param part MIMEPart element + * @return the part value from MIMEContent element + */ + private String getMIMEContentPart(MIMEPart part) { + List list = part.getExtensibilityElements(); + if(list.size() == 0) + return null; + return ((MIMEContent) list.get(0)).getPart(); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/AP1926.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/AP1926.java new file mode 100644 index 000000000..db0b7fe3c --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/AP1926.java @@ -0,0 +1,210 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import java.util.Collection; +import java.util.Iterator; +import java.util.List; + +import javax.wsdl.BindingOperation; +import javax.wsdl.extensions.mime.MIMEContent; +import javax.wsdl.extensions.mime.MIMEMultipartRelated; +import javax.wsdl.extensions.mime.MIMEPart; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionFailException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionNotApplicableException; +import org.eclipse.wst.wsi.internal.log.MessageEntry; +import org.eclipse.wst.wsi.internal.log.MimePart; +import org.eclipse.wst.wsi.internal.log.MimeParts; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.MIMEConstants; +import org.eclipse.wst.wsi.internal.util.MIMEUtils; + +/** + * AP1926 + * + * For a candidate message + * A message includes all of the MIME parts described by + * its WSDL MIME binding. + */ +public class AP1926 extends AssertionProcess +{ + private final BaseMessageValidator validator; + + /** + * @param WSDLValidatorImpl + */ + public AP1926(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + /* Validates the test assertion. + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + try + { + if(!entryContext.getMessageEntry().isMimeContent()) + { + throw new AssertionNotApplicableException(); + } + + // get message mime parts + MimeParts mimeParts = entryContext.getMessageEntry().getMimeParts(); + + BindingOperation bindingOperation = validator.getOperationMatch( + entryContext.getEntry().getEntryType(), + entryContext.getMessageEntryDocument()); + + // If there is no matched operation, the assertion is not applicable + if (bindingOperation == null) + throw new AssertionNotApplicableException(); + + // Finding operation extensibility elems + // in the binding depending on message type + List extElems = null; + if (entryContext.getMessageEntry().getType().equals( + MessageEntry.TYPE_REQUEST) + && bindingOperation.getBindingInput() != null) + { + extElems = bindingOperation + .getBindingInput().getExtensibilityElements(); + } + else if (entryContext.getMessageEntry().getType().equals( + MessageEntry.TYPE_RESPONSE) + && bindingOperation.getBindingOutput() != null) + { + extElems = bindingOperation + .getBindingOutput().getExtensibilityElements(); + } + // check list for the first element + if((extElems == null) || (extElems.size() == 0) || + !(extElems.get(0) instanceof MIMEMultipartRelated)) + throw new AssertionNotApplicableException(); + + // get list mime parts from definition + MIMEMultipartRelated mime = (MIMEMultipartRelated) extElems.get(0); + List parts = mime.getMIMEParts(); + + if(mimeParts.getRootPart() == null || mimeParts.count()==0) + throw new AssertionNotApplicableException(); + // skip root part + for (int i = 1; i < parts.size(); i++) + { + String partName = getMIMEContentPart((MIMEPart) parts.get(i)); + // find the corresponding MIME part + if (findMIMEPart(mimeParts.getParts(), partName) == null) + { + throw new AssertionFailException("The corresponding binding " + + "operation \"" + bindingOperation.getName() + + "\" does not contain part \"" + partName + "\""); + } + } + } + catch (AssertionNotApplicableException e) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + catch (AssertionFailException e) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = + validator.createFailureDetail(e.getMessage(), entryContext); + } + + // Return assertion result + return validator.createAssertionResult( + testAssertion, result, failureDetail); + } + + /** + * find corresponding MIME part + * @param parts array of soap MIME parts + * @param partName part name to find + * @return corresponding MIME part "Content-ID" value, + * if the part doesnt found, retuns null + * @throws WSIException + */ + private String findMIMEPart(Collection parts, String partName) + throws WSIException + { + if(partName == null) + return null; + Iterator iparts = parts.iterator(); + while (iparts.hasNext()) + { + MimePart part = (MimePart)iparts.next(); + String m_partName = MIMEUtils.getMimeHeaderAttribute( + part.getHeaders(), MIMEConstants.HEADER_CONTENT_ID); + + // check value format + if ((m_partName != null) && (m_partName.startsWith("<")) && + (m_partName.indexOf("=") != -1) && + (encodePartName(m_partName.substring(1, m_partName.indexOf("="))).equals(partName))) + { + return m_partName; + } + } + return null; + } + + /** + * Returns the part value from MIMEContent element + * @param part MIMEPart element + * @return the part value from MIMEContent element + */ + private String getMIMEContentPart(MIMEPart part) { + List list = part.getExtensibilityElements(); + if(list.size() == 0) + return null; + return ((MIMEContent) list.get(0)).getPart(); + } + + /** + * Encode string from %HH to UTF + * @param str string + * @return encoded string from %HH format + */ + private String encodePartName(String str) { + StringBuffer res = new StringBuffer(""); + for (int i = 0; i < str.length(); i++) + { + if((str.charAt(i) == '%') && (str.length() > i+2)) + { + try + { + int value = Integer.parseInt( + String.valueOf(str.charAt(i+1)) + + String.valueOf(str.charAt(i+2)), 16); + res.append((char) value); + i +=2; + } + catch(NumberFormatException e){} + } + else + { + res.append(str.charAt(i)); + } + } + return res.toString(); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/AP1931.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/AP1931.java new file mode 100644 index 000000000..6178e435b --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/AP1931.java @@ -0,0 +1,91 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.WSITag; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +/** + * AP1931 + * + * For a candidate root-part of a multipart/related message + * The entity body of the root-part of multipart/related + * message is a soap:Envelope. + */ +public class AP1931 extends AssertionProcess +{ + private final BaseMessageValidator validator; + + /** + * @param WSDLValidatorImpl + */ + public AP1931(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + /* Validates the test assertion. + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + // check for the root part + if(entryContext.getMessageEntry().isMimeContent() && + (entryContext.getMessageEntry().getMimeParts().getRootPart() != null)) + { + try + { + // parse root part message + Document doc = XMLUtils.parseXML( + entryContext.getMessageEntry().getMimeParts().getRootPart().getContent()); + + // get entity body + Element el = doc.getDocumentElement(); + + // if the element is not soap:Envelope, then fail + if(!el.getLocalName().equals(WSITag.ELEM_SOAP_ENVELOPE.getLocalPart()) || + !el.getNamespaceURI().equals(WSITag.ELEM_SOAP_ENVELOPE.getNamespaceURI())) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = validator.createFailureDetail( + "the entity body of the root part is {" + + el.getNamespaceURI() + "}" + el.getLocalName(), entryContext); + } + } + catch (Exception e) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = validator.createFailureDetail( + "the entity body of the root part does not contain " + + "\"soap:Envelope\" element", entryContext); + } + } + else + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + // Return assertion result + return validator.createAssertionResult( + testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/AP1932.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/AP1932.java new file mode 100644 index 000000000..bfba67561 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/AP1932.java @@ -0,0 +1,80 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.HTTPConstants; +import org.eclipse.wst.wsi.internal.util.HTTPUtils; + +/** + * AP1932 + * + * For a candidate message containing a Content-Type HTTP header + * field-value with a media type of "multipart/related" + * In a message, the Content-Type HTTP header field-value + * has a type parameter with a value of "text/xml" when it has a media type of + * "multipart/related". + */ +public class AP1932 extends AssertionProcess +{ + private final BaseMessageValidator validator; + + /** + * @param WSDLValidatorImpl + */ + public AP1932(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + /* Validates the test assertion. + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + // check for multipart/related content type + String content_type = HTTPUtils.getHttpHeaderAttribute( + entryContext.getMessageEntry().getHTTPHeaders(), + HTTPConstants.HEADER_CONTENT_TYPE); + + if((content_type == null) || + (!content_type.equalsIgnoreCase(WSIConstants.CONTENT_TYPE_MULTIPART))) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + else + { + String subType = HTTPUtils.getHttpHeaderSubAttribute( + entryContext.getMessageEntry().getHTTPHeaders(), + HTTPConstants.HEADER_CONTENT_TYPE, "type"); + if((subType == null) + || !subType.equalsIgnoreCase(WSIConstants.CONTENT_TYPE_TEXT_XML)) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = validator.createFailureDetail( + "The \"type\" parameter value is \"" + subType + "\"", entryContext); + } + } + // Return assertion result + return validator.createAssertionResult( + testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/AP1933.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/AP1933.java new file mode 100644 index 000000000..4ee6df11a --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/AP1933.java @@ -0,0 +1,257 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import java.net.MalformedURLException; +import java.net.URL; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; + +import javax.wsdl.BindingOperation; +import javax.wsdl.extensions.mime.MIMEContent; +import javax.wsdl.extensions.mime.MIMEMultipartRelated; +import javax.wsdl.extensions.mime.MIMEPart; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionFailException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionNotApplicableException; +import org.eclipse.wst.wsi.internal.log.MessageEntry; +import org.eclipse.wst.wsi.internal.log.MimePart; +import org.eclipse.wst.wsi.internal.log.MimeParts; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.MIMEConstants; +import org.eclipse.wst.wsi.internal.util.MIMEUtils; + +/** + * AP1933 + * + * For a candidate message + * If a description binds a wsdl:message part to a + * mime:content element, then the corresponding MIME part in a message has a + * content-id header with a globally unique value of the form + * <partname=ID@hostname>, where 'partname' is the value of the name attribute of + * the wsdl:part element referenced by the mime:content. + */ +public class AP1933 extends AssertionProcess +{ + private final BaseMessageValidator validator; + + /** + * @param WSDLValidatorImpl + */ + public AP1933(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + /* Validates the test assertion. + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + + try + { + if(!entryContext.getMessageEntry().isMimeContent()) + { + throw new AssertionNotApplicableException(); + } + + // get message mime parts + MimeParts mimeParts = entryContext.getMessageEntry().getMimeParts(); + + BindingOperation bindingOperation = validator.getOperationMatch( + entryContext.getEntry().getEntryType(), + entryContext.getMessageEntryDocument()); + + // If there is no matched operation, the assertion is not applicable + if (bindingOperation == null) + throw new AssertionNotApplicableException(); + + // Finding operation extensibility elems + // in the binding depending on message type + List extElems = null; + if (entryContext.getMessageEntry().getType().equals( + MessageEntry.TYPE_REQUEST) + && bindingOperation.getBindingInput() != null) + { + extElems = bindingOperation + .getBindingInput().getExtensibilityElements(); + } + else if (entryContext.getMessageEntry().getType().equals( + MessageEntry.TYPE_RESPONSE) + && bindingOperation.getBindingOutput() != null) + { + extElems = bindingOperation + .getBindingOutput().getExtensibilityElements(); + } + // check list for the first element + if((extElems == null) || (extElems.size() == 0) || + !(extElems.get(0) instanceof MIMEMultipartRelated)) + throw new AssertionNotApplicableException(); + + // get list mime parts from definition + MIMEMultipartRelated mime = (MIMEMultipartRelated) extElems.get(0); + List parts = mime.getMIMEParts(); + + // skip root part + for (int i = 1; i < parts.size(); i++) + { + String partName = getMIMEContentPart((MIMEPart) parts.get(i)); + // find the corresponding MIME part + if (findMIMEPart(mimeParts.getParts(), partName) == null) + { + throw new AssertionFailException("The corresponding binding " + + "operation \"" + bindingOperation.getName() + + "\" does not contain part \"" + partName + "\""); + } + } + } + catch (AssertionNotApplicableException e) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + catch (AssertionFailException e) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = + validator.createFailureDetail(e.getMessage(), entryContext); + } + // Return assertion result + return validator.createAssertionResult( + testAssertion, result, failureDetail); + } + + /** + * find corresponding MIME part + * @param parts array of soap MIME parts + * @param partName part name to find + * @return corresponding MIME part "Content-ID" value, + * if the part doesnt found, retuns null + * @throws WSIException + */ + private String findMIMEPart(Collection parts, String partName) + throws WSIException, AssertionFailException + { + if(partName == null) + return null; + + Iterator iparts = parts.iterator(); + int i = 0; + while (iparts.hasNext()) + { + i = i + 1; + MimePart part = (MimePart)iparts.next(); + String m_partName = MIMEUtils.getMimeHeaderAttribute( + part.getHeaders(), MIMEConstants.HEADER_CONTENT_ID); + + // check value format + if ((m_partName != null) && m_partName.startsWith("<") && m_partName.endsWith(">")) + { + int idx, atIdx; + String enPartName = null; + String uid = null; + String host = null; + + // get part name from content-id + if ((idx = m_partName.indexOf("=")) != -1) + { + enPartName = encodePartName(m_partName.substring(1, idx)); + } + // get uid and hostname from content-id + if (((atIdx = m_partName.indexOf("@")) != -1) && (atIdx > idx)) + { + uid = m_partName.substring(idx+1, atIdx); + host = m_partName.substring(atIdx+1, m_partName.length()-1); + } + // if part names match, validate format + if((enPartName != null) && enPartName.equals(partName)) + { + if((uid == null) || (uid.length() == 0)) + throw new AssertionFailException( + "The \"Content-ID\" attribute of the part \""+(i+1)+ + "\"contains value \""+ m_partName+ + "\" which has a incorrect UID format"); + if(host == null) + throw new AssertionFailException( + "The \"Content-ID\" attribute of the part \""+(i+1)+ + "\"contains value \""+ m_partName+ + "\" which has a incorrect host format"); + // check for malformed URL + try + { + new URL("HTTP", host, ""); + } + catch (MalformedURLException e) + { + throw new AssertionFailException( + "The \"Content-ID\" attribute of the part \""+(i+1)+ + "\"contains value \""+ m_partName+ + "\" which has a incorrect host format"); + } + return m_partName; + } + } + } + return null; + } + + /** + * Returns the part value from MIMEContent element + * @param part MIMEPart element + * @return the part value from MIMEContent element + */ + private String getMIMEContentPart(MIMEPart part) + { + List list = part.getExtensibilityElements(); + if(list.size() == 0) + return null; + return ((MIMEContent) list.get(0)).getPart(); + } + + /** + * Encode string from %HH to UTF + * @param str string + * @return encoded string from %HH format + */ + private String encodePartName(String str) { + StringBuffer res = new StringBuffer(""); + for (int i = 0; i < str.length(); i++) + { + if((str.charAt(i) == '%') && (str.length() > i+2)) + { + try + { + int value = Integer.parseInt( + String.valueOf(str.charAt(i+1)) + + String.valueOf(str.charAt(i+2)), 16); + res.append((char) value); + i +=2; + } + catch(NumberFormatException e){} + } + else + { + res.append(str.charAt(i)); + } + } + return res.toString(); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/AP1934.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/AP1934.java new file mode 100644 index 000000000..7a7a633b4 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/AP1934.java @@ -0,0 +1,103 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import java.util.Iterator; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.log.MimePart; +import org.eclipse.wst.wsi.internal.log.MimeParts; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.MIMEConstants; +import org.eclipse.wst.wsi.internal.util.MIMEUtils; + +/** + * AP1934 + * + * For a candidate part of a multipart/related message + * The Content-Transfer-Encoding field of a part in a + * multipart/related message has a value of "7bit", "8bit", "binary", + * "quoted-printable" or "base64". + */ +public class AP1934 extends AssertionProcess +{ + private final BaseMessageValidator validator; + + /** + * @param WSDLValidatorImpl + */ + public AP1934(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + /* Validates the test assertion. + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + // check for multipart/related content type + if(!entryContext.getMessageEntry().isMimeContent()) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + else + { + // get MIME parts + MimeParts parts = entryContext.getMessageEntry().getMimeParts(); + if(parts.count() == 0) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + else + { + Iterator iparts = parts.getParts().iterator(); + // check each part for the Content-Transfer-Encoding field + int i = 0; + while (iparts.hasNext()) + { + MimePart part = (MimePart)iparts.next(); + String type_value = MIMEUtils.getMimeHeaderAttribute( + part.getHeaders(), + MIMEConstants.HEADER_CONTENT_TRANSFER_ENCODING); + if (type_value != null) + { + if((type_value == null) || !(type_value.equalsIgnoreCase("7bit") || + type_value.equalsIgnoreCase("8bit") || + type_value.equalsIgnoreCase("base64") || + type_value.equalsIgnoreCase("quoted-printable") || + type_value.equalsIgnoreCase("binary"))) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = validator.createFailureDetail( + "(" + (i+1) + + "), part header field \"Content-Transfer-Encoding\" has incorrect value \""+ + type_value+"\"", entryContext); + } + } + i++; + } + } + } + + // Return assertion result + return validator.createAssertionResult( + testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/AP1935.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/AP1935.java new file mode 100644 index 000000000..e537ea427 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/AP1935.java @@ -0,0 +1,348 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import java.util.ArrayList; +import java.util.Iterator; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionFailException; +import org.eclipse.wst.wsi.internal.log.MimePart; +import org.eclipse.wst.wsi.internal.log.MimeParts; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.HTTPConstants; +import org.eclipse.wst.wsi.internal.util.HTTPUtils; +import org.eclipse.wst.wsi.internal.util.Utils; + +/** + * AP1935 + * + * For a candidate part of a multipart/related message + * The encoding of the body of a part in a + * multipart/related message conforms to the encoding indicated by the + * Content-Transfer-Encoding field-value, + * as specified by RFC2045. + */ +public class AP1935 extends AssertionProcess +{ + private final BaseMessageValidator validator; + + /** + * @param WSDLValidatorImpl + */ + public AP1935(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + /* Validates the test assertion. + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + if(!entryContext.getMessageEntry().isMimeContent()) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + else + { + // get MIME parts + MimeParts parts = entryContext.getMessageEntry().getMimeParts(); + if(parts.count() == 0) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + else + { + // check each part for the encoding match + Iterator iparts = parts.getParts().iterator(); + int i = 0; + MimePart root = parts.getRootPart(); + while (iparts.hasNext()) + { + i = i = 1; + try + { + MimePart part = (MimePart)iparts.next(); + + // get encoding from header + String encoding = HTTPUtils.getHttpHeaderAttribute(part.getHeaders(), + HTTPConstants.HEADER_CONTENT_TRANSFER_ENCODING); + + if ((part == root) || + ((encoding != null) && encoding.equalsIgnoreCase("base64"))) + checkPart(part, encoding, false); + else + checkPart(part, encoding, true); + } catch (AssertionFailException e) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = validator.createFailureDetail( + "part "+(i+1)+" Error: " + e.getMessage(), entryContext); + } + } + } + } + // Return assertion result + return validator.createAssertionResult( + testAssertion, result, failureDetail); + } + /** + * Check message entry to encoding conformity + * @param entry message entry + * @throws AssertionFailException if message does not encoding conformity + * @throws WSIException + */ + private void checkPart(MimePart part, String encoding, boolean encoded) + throws AssertionFailException, WSIException + { + String content = null; + if (encoded) + content = new String(Utils.decodeBase64(part.getContent())); + else + content = part.getContent(); + + if(encoding == null) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + // check 7bit + } else if(encoding.equalsIgnoreCase("7bit")) { + checkOn7bit(content); + // check 8bit + } else if(encoding.equalsIgnoreCase("8bit")) { + checkOn8bit(content); + // check quoted-printable + } else if(encoding.equalsIgnoreCase("quoted-printable")) { + checkOnQuotedPrintable(content); + // check base64 + } else if(encoding.equalsIgnoreCase("base64")) { + checkOnBase64(content); + } + // we dont check binary encoding, since message can contains any chars + } + + /** + * Validate a 7bit encoded message (RFC2045) + * @param message message to check + * @throws AssertionFailException if message does not conform + */ + private void checkOn7bit(String message) + throws AssertionFailException + { + String[] strs = split(message); + for (int i = 0; i < strs.length; i++) + { + String str = strs[i]; + + // check string length + if(str.length() > 998) + { + throw new AssertionFailException("The length (" + str.length() + + ") of the line (" + (i+1) + ") greater than 998"); + } + // No octets with decimal values greater than 127 + // are allowed and neither are NULs (octets with decimal value 0). CR + //(decimal value 13) and LF (decimal value 10) octets only occur as + // part of CRLF line separation sequences. + char[] chars = str.toCharArray(); + for (int j = 0; j < chars.length; j++) + { + if((chars[j] > 127) || (chars[j] == 0) || + (chars[j] == 10) || (chars[j] == 13)) + { + throw new AssertionFailException("The char (" + chars[j] + + ")[code=" + (byte) chars[j] + " position=" + j + + "] does not allows in 7bit encoding content"); + } + } + } + } + + /** + * Validate an 8bit encoded message (RFC2045) + * @param message message to check + * @throws AssertionFailException if message does not conform + */ + private void checkOn8bit(String message) + throws AssertionFailException + { + String[] strs = split(message); + for (int i = 0; i < strs.length; i++) + { + String str = strs[i]; + + // check string length + if(str.length() > 998) + { + throw new AssertionFailException("The length (" + str.length() + + ") of the line (" + (i+1) + ") greater than 998"); + } + // octets with decimal values greater than 127 + // may be used. As with "7bit data" CR and LF octets only occur as part + // of CRLF line separation sequences and no NULs are allowed. + char[] chars = str.toCharArray(); + for (int j = 0; j < chars.length; j++) + { + if((chars[j] == 0) || (chars[j] == 10) || (chars[j] == 13)) + { + throw new AssertionFailException("The char (" + chars[j] + + ")[code=" + (byte) chars[j] + " position=" + j + + "] does not allows in 8bit encoding content"); + } + } + } + } + + /** + * Validate a quoted-printable encoded message (RFC2045) + * @param message message to check + * @throws AssertionFailException if message does not conform + */ + private void checkOnQuotedPrintable(String message) + throws AssertionFailException + { + String[] strs = split(message); + for (int i = 0; i < strs.length; i++) + { + // check length + // RFC2045 + // (5) (Soft Line Breaks) The Quoted-Printable encoding + //REQUIRES that encoded lines be no more than 76 + //characters long. If longer lines are to be encoded + //with the Quoted-Printable encoding, "soft" line breaks + //must be used. An equal sign as the last character on a + //encoded line indicates such a non-significant ("soft") + //line break in the encoded text. + if(((strs[i].indexOf("\t") != -1) || (strs[i].indexOf(" ") != -1)) && + (strs[i].length() > 76)) + { + throw new AssertionFailException("The length (" + strs[i].length() + + ") of the line (" + (i+1) + + ") greater than 76, \"soft\" line breaks must be used"); + } + + char[] chars = strs[i].toCharArray(); + for (int j = 0; j < chars.length; j++) + { + //(1) (General 8bit representation) Any octet, except a CR or + //LF that is part of a CRLF line break of the canonical + //(standard) form of the data being encoded, may be + //represented by an "=" followed by a two digit + //hexadecimal representation of the octet's value. The + //digits of the hexadecimal alphabet, for this purpose, + //are "0123456789ABCDEF". Uppercase letters must be + //used; lowercase letters are not allowed. Thus, for + //example, the decimal value 12 (US-ASCII form feed) can + //be represented by "=0C", and the decimal value 61 (US- + //ASCII EQUAL SIGN) can be represented by "=3D". This + //rule must be followed except when the following rules + //allow an alternative encoding. + // (2) (Literal representation) Octets with decimal values of + //33 through 60 inclusive, and 62 through 126, inclusive, + //MAY be represented as the US-ASCII characters which + //correspond to those octets (EXCLAMATION POINT through + //LESS THAN, and GREATER THAN through TILDE, + //respectively). + if((chars[j] == 61) && (chars.length > j+2)) + { + if(!isHex(chars[j+1]) || !isHex(chars[j+2])) + { + throw new AssertionFailException("the quoted char (" + + chars[j] + chars[j+1] + chars[j+2] + ") is incorrect"); + } else { + j += 2; + } + } + // check for space and tab + else if((chars[j] != 9) && (chars[j] != 32)) + { + // check invalid symbol + if((chars[j] == 0) || (chars[j] == 10) || (chars[j] == 13) || + (chars[j] < 33) || (chars[j] > 126) || (chars[j] == 61)) + { + throw new AssertionFailException("The char (" + chars[j] + + ")[code=" + (byte) chars[j] + " position=" + j + + "] must be quoted"); + } + } + } + } + } + + /** + * Validate a base64 encoded message (RFC3548) + * @param message message to check + * @throws AssertionFailException if message does not conform + */ + private void checkOnBase64(String message) + throws AssertionFailException + { + String[] strs = split(message); + for (int i = 0; i < strs.length; i++) + { + String str = strs[i]; + + // check string length + if(str.length() > 76) + { + throw new AssertionFailException("The length (" + str.length() + + ") of the line (" + (i+1) + ") greater than 998"); + } + // check for "ABCDEFGHIJKLMNOPQRSTUVWXYZabcefghijklmnopqrstuvwxyz0123456789/+" + char[] chars = str.toCharArray(); + for (int j = 0; j < chars.length; j++) + { + char c = chars[i]; + if((c < 47) || (c > 122) || ((c > 57) && (c < 65)) || + ((c > 90) && (c < 97))) + { + throw new AssertionFailException("The char (" + chars[j] + + ")[code=" + (byte) chars[j] + " position=" + j + + "] does not allows in base64 encoding content"); + } + } + } + } + + /** + * split string to array of strings and use as delimeter CRLF + * @param str original string + * @return array of strings + */ + private String[] split(String str) + { + ArrayList list = new ArrayList(); + for(int idx = str.indexOf("\r\n"); idx != -1; idx = str.indexOf("\r\n")) + { + list.add(str.substring(0, idx)); + str = str.substring(idx+2); + } + list.add(str); + return (String[]) list.toArray(new String[list.size()]); + } + + /** + * Returns true if byte is "0123456789ABCDEF" range, false othewise + * @param c char + * @return true if byte is "0123456789ABCDEF" range, false othewise + */ + private boolean isHex(char c) { + return (((c >= 48) && (c <= 57)) || ((c >= 65) && (c <= 70))); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/AP1936.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/AP1936.java new file mode 100644 index 000000000..9d35ce778 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/AP1936.java @@ -0,0 +1,72 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; + +/** + * AP1936 + * For a candidate multipart/related message + * In a message, all MIME encapsulation boundary strings + * are preceded with the ascii characters CR (13) and LF (10) + * in that sequence. + */ +public class AP1936 extends AssertionProcess +{ + private final BaseMessageValidator validator; + + /** + * @param BaseMessageValidator + */ + public AP1936(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + // if boundary equals null, then result is not applicable + if (!entryContext.getMessageEntry().isMimeContent()) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + // otherwise it is true -- checked in monitor + // MimeParts mimeParts = entryContext.getMessageEntry().getMimeParts(); + // Iterator i = mimeParts.getParts().iterator(); + // boolean invalidBoundaryStringFound = false; + //while (i.hasNext() && !invalidBoundaryStringFound) + //{ + // MimePart part = (MimePart)i.next(); + // String[] boundaries = part.getBoundaryStrings(); + // for (int j = 0; jFor a candidate part of a multipart/related message that is bound + * to a mime:content that refers to global element declaration (via the element + * attribute of the wsdl:part element)
+ * The bound message part is serialized within the MIME + * part as a serialization of an XML infoset whose root element is described by + * the referenced element. + */ +public class AP1942 extends AssertionProcess implements WSITag +{ + private final BaseMessageValidator validator; + + /** + * @param WSDLValidatorImpl + */ + public AP1942(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + /* Validates the test assertion. + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + try + { + if (!entryContext.getMessageEntry().isMimeContent()) + { + throw new AssertionNotApplicableException(); + } + else + { + MimeParts mimeParts = entryContext.getMessageEntry().getMimeParts(); + + // If the message does not contain non-root MIME parts + // the assertion is not applicable + if (mimeParts.count()< 2) + throw new AssertionNotApplicableException(); + + // Getting an operation matched for a message + BindingOperation bindingOperation = validator.getOperationMatch( + entryContext.getEntry().getEntryType(), + entryContext.getMessageEntryDocument()); + // If no one operation matches, the assertion is not applicable + if (bindingOperation == null) + throw new AssertionNotApplicableException(); + // Getting the corresponding extensibility elements and message + List extElems; + Message message; + if (MessageEntry.TYPE_REQUEST + .equals(entryContext.getEntry().getEntryType())) + { + extElems = bindingOperation.getBindingInput() == null ? null + : bindingOperation.getBindingInput().getExtensibilityElements(); + message = bindingOperation.getOperation().getInput() == null ? null + : bindingOperation.getOperation().getInput().getMessage(); + } + else + { + extElems = bindingOperation.getBindingOutput() == null ? null + : bindingOperation.getBindingOutput().getExtensibilityElements(); + message = bindingOperation.getOperation().getOutput() == null ? null + : bindingOperation.getOperation().getOutput().getMessage(); + } + // A variable that indicates a binding contains at least one + // mime:content element that refers to global element declaration + boolean mimeContentFound = false; + // Going through the message MIME parts + Iterator iMimeParts = mimeParts.getParts().iterator(); + int i = 0; + while (iMimeParts.hasNext()) + { + i = i + 1; + // Getting a MIME part + MimePart mimePart = (MimePart)iMimeParts.next(); + // Getting a part name form the Content-ID header + String partName = MIMEUtils.getMimeHeaderAttribute( + mimePart.getHeaders(), MIMEConstants.HEADER_CONTENT_ID); + try + { + int idx = partName.indexOf("="); + if((idx != -1) && partName.startsWith("<")) + partName = encodePartName(partName.substring(1, idx)); + } + catch (Exception e) + { + // Could not extract a part name from the header, + // proceed with the next MIME part + continue; + } + + // If the part is bound by a mime:content element + if (boundToMimeContent(extElems, partName) && message != null) + { + // Getting the corresponding part + Part part = (Part) message.getParts().get(partName); + QName refName; + // If the part refers to global element declaration + if (part != null && (refName = part.getElementName()) != null) + { + mimeContentFound = true; + // Trying to parse part content + Document doc = null; + try + { + doc = XMLUtils.parseXML(mimePart.getContent()); + } + catch (Exception e) {} + // If the message is not an XML infoset, the assertion failed + if (doc == null) + { + throw new AssertionFailException("The bound message part of the " + + "MIME part number " + (i + 1) + " is invalid XML infoset."); + } + // Creating a QName object of the root element + QName rootName = new QName( + doc.getDocumentElement().getNamespaceURI(), + doc.getDocumentElement().getLocalName()); + // If the names of the root element and the referenced element + // are not equal, the assertion failed + if (!refName.equals(rootName)) + { + throw new AssertionFailException("The root element name is " + + rootName + ", the name of the referenced element is " + + refName + "."); + } + } + } + } + // If no mime:contentS found, the assertion is not applicable + if (!mimeContentFound) + throw new AssertionNotApplicableException(); + } + } + catch (AssertionNotApplicableException anae) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + catch (AssertionFailException afe) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = validator.createFailureDetail( + afe.getMessage(), entryContext); + } + // Return assertion result + return validator.createAssertionResult( + testAssertion, result, failureDetail); + } + + + /** + * Validates whether a part is bound by a mime:content element. + * @param extElems a list of extensibility elements. + * @param part a part name. + * @return true if a part is bound by mime:content, false otherwise. + */ + private boolean boundToMimeContent(List extElems, String part) + { + if (extElems != null && extElems.size() > 0) + { + ExtensibilityElement extElem = (ExtensibilityElement) extElems.get(0); + // Expected the first ext elem is mime:multipartRelated + if (extElem.getElementType().equals(WSDL_MIME_MULTIPART)) + { + // Getting the mime:part elements of the mime:multipartRelated + List mimeParts = ((MIMEMultipartRelated) extElem).getMIMEParts(); + for (int i = 0; i < mimeParts.size(); i++) + { + // Getting the mime:part element needed + List elems = ((MIMEPart) mimeParts.get(i)).getExtensibilityElements(); + if (elems.size() > 0) + { + // Getting the first element + ExtensibilityElement elem = (ExtensibilityElement) elems.get(0); + // If the element is mime:content and it binds a part + if (elem.getElementType().equals(WSDL_MIME_CONTENT) + && part.equals(((MIMEContent)elem).getPart())) + { + return true; + } + } + } + } + } + return false; + } + + /** + * Encode string from %HH to UTF + * @param str string + * @return encoded string from %HH format + */ + private String encodePartName(String str) { + StringBuffer res = new StringBuffer(""); + for (int i = 0; i < str.length(); i++) + { + if((str.charAt(i) == '%') && (str.length() > i+2)) + { + try + { + int value = Integer.parseInt( + String.valueOf(str.charAt(i+1)) + + String.valueOf(str.charAt(i+2)), 16); + res.append((char) value); + i +=2; + } + catch(NumberFormatException e){} + } + else + { + res.append(str.charAt(i)); + } + } + return res.toString(); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/AP1945.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/AP1945.java new file mode 100644 index 000000000..f9801e7b4 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/AP1945.java @@ -0,0 +1,73 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.HTTPConstants; +import org.eclipse.wst.wsi.internal.util.HTTPUtils; + +/** + * AP1945 + * For a candidate message + * The Content-Type HTTP header field-value in a message + * is either "multipart/related" or "text/xml". + */ +public class AP1945 extends AssertionProcess +{ + private final BaseMessageValidator validator; + + /** + * @param BaseMessageValidator + */ + public AP1945(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + String headerName = HTTPConstants.HEADER_CONTENT_TYPE; + + // Getting a header + String headerValue = HTTPUtils.getHttpHeaderAttribute( + entryContext.getMessageEntry().getHTTPHeaders(), + headerName); + // If headerValue is null, the assertion is not applicable + if (headerValue == null) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + // If the header is "multipart/related" or "text/xml", + // then the assertion passed + else if (headerValue.equalsIgnoreCase(WSIConstants.CONTENT_TYPE_MULTIPART) + || headerValue.equalsIgnoreCase(WSIConstants.CONTENT_TYPE_TEXT_XML)) + { + } + // else the assertion failed + else { + result = AssertionResult.RESULT_FAILED; + failureDetail = validator.createFailureDetail( + headerValue, entryContext); + } + return validator.createAssertionResult( + testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/AP1946.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/AP1946.java new file mode 100644 index 000000000..74eb84517 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/AP1946.java @@ -0,0 +1,64 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; + +/** + * AP1946 + * + * For a candidate multipart/related message + * containing non-root parts + * The candidate multipart/related message + * containing non-root parts. + */ +public class AP1946 extends AssertionProcess +{ + private final BaseMessageValidator validator; + + /** + * @param WSDLValidatorImpl + */ + public AP1946(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + /* Validates the test assertion. + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + // If there are more than one MIME parts, the assertion passed + if (entryContext.getMessageEntry().getMimeParts().count() > 1) + { + failureDetail = validator.createFailureDetail( + testAssertion.getDetailDescription(), entryContext); + } + // The assertion is not applicable + else + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + // Return assertion result + return validator.createAssertionResult( + testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/AP5100.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/AP5100.java new file mode 100644 index 000000000..3b25446fd --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/AP5100.java @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; + +/** + * AP5100 + * + * For a candidate non-multipart/related message in the log file, with an HTTP entity-body. + * The SOAP envelope is the exclusive payload of the HTTP entity-body. + * + * @author lauzond + */ +public class AP5100 extends SSBP5100 +{ + /** + * Constructor. + * @param impl + */ + public AP5100(BaseMessageValidator impl) + { + super(impl); + } + + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + // If there is a SOAP Message with Attachments, the assertion is not applicable + if (entryContext.getMessageEntry().isMimeContent()) + { + return validator.createAssertionResult(testAssertion, AssertionResult.RESULT_NOT_APPLICABLE, failureDetail); + } + else + { + return super.validate(testAssertion, entryContext); + } + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/AP5101.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/AP5101.java new file mode 100644 index 000000000..e173bc744 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/AP5101.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ + package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; + +/** + * AP5101 + * For a non-multipart/related candidate message in the log file. + * A message must have a "Content-Type" HTTP header field. The "Content-Type" HTTP header field must have a field-value whose media type is "text/xml". + * + * @author lauzond + */ +public class AP5101 extends SSBP5101 { + + /** + * @param impl + */ + public AP5101(BaseMessageValidator impl) + { + super(impl); + } + + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + // If there is a SOAP Message with Attachments, the assertion is not applicable + if (entryContext.getMessageEntry().isMimeContent()) + { + return validator.createAssertionResult(testAssertion, AssertionResult.RESULT_NOT_APPLICABLE, failureDetail); + } + else + { + return super.validate(testAssertion, entryContext); + } + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/BP1001.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/BP1001.java new file mode 100644 index 000000000..c991007cc --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/BP1001.java @@ -0,0 +1,101 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ + package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import java.util.Vector; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.log.MessageEntry; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.MessageValidator; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; + + +/** + * BP1001. + * If it is a request, the arg #2 of POST is <HTTP/1.1>. If absent, first line of the + * body is: HTTP-Version = HTTP/1.1. If it is a response, it starts with <HTTP/1.1>. + */ +public class BP1001 extends AssertionProcess +{ + private final BaseMessageValidator validator; + + /** + * @param BaseMessageValidator + */ + public BP1001(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + String httpHeader = entryContext.getMessageEntry().getHTTPHeaders(); + + // If this is a request message, then check POST header + if (entryContext + .getMessageEntry() + .getType() + .equalsIgnoreCase(MessageEntry.TYPE_REQUEST)) + { + Vector requestLine; + if (((requestLine = this.validator.getPostRequest(httpHeader)) == null) + || (requestLine.size() == 0)) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + else + { + String method = (String) requestLine.get(0); + //String requestURI = (String) requestLine.get(1); + String httpVersion = (String) requestLine.get(2); + + //For each request message that is an HTTP POST + if (method.equals(MessageValidator.HTTP_POST) && httpVersion != null) + { + if (httpVersion.equals(MessageValidator.HTTP_VERSION_1_1)) + { + result = AssertionResult.RESULT_PASSED; + } + else + { + result = AssertionResult.RESULT_WARNING; + failureDetail = this.validator.createFailureDetail(httpHeader, entryContext); + } + } + } + } + + // Otherwise it must be a response + else + { + if (httpHeader.startsWith(MessageValidator.HTTP_VERSION_1_1)) + { + result = AssertionResult.RESULT_PASSED; + } + else + { + result = AssertionResult.RESULT_WARNING; + failureDetail = this.validator.createFailureDetail(httpHeader, entryContext); + } + } + + // Return assertion result + return validator.createAssertionResult(testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/BP1002.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/BP1002.java new file mode 100644 index 000000000..2fa760f18 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/BP1002.java @@ -0,0 +1,137 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import java.util.StringTokenizer; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionFailException; +import org.eclipse.wst.wsi.internal.log.MessageEntry; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.MessageValidator; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; + + +/** + * BP1002. + * If it is a request, the arg #2 of POST is <HTTP/1.1> or <HTTP/1.0>. If absent, first line + * of the body is: HTTP-Version = HTTP/1.1. (or HTTP/1.0). If it is a response, it starts with + * <HTTP/1.1> or <HTTP/1.0> or higher; + */ +public class BP1002 extends AssertionProcess +{ + private final BaseMessageValidator validator; + + /** + * @param BaseMessageValidator + */ + public BP1002(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + String httpHeader = entryContext.getMessageEntry().getHTTPHeaders(); + + // If this is a request message, then check POST for 1.1 or 1.0 + if (entryContext + .getMessageEntry() + .getType() + .equalsIgnoreCase(MessageEntry.TYPE_REQUEST)) + { + // Get each entry in the post header + StringTokenizer postMessage = new StringTokenizer(httpHeader, " \r\n"); + + // If there is no third token, then fail + if (postMessage.countTokens() < 3) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = this.validator.createFailureDetail(httpHeader, entryContext); + } + else + { + // Get the 3rd token (there must be a better way to do this?) + String httpVersion = ""; + String messageType = ""; + for (int i = 0; i < 3; i++) + { + // Message type + if (i == 0) + messageType = postMessage.nextToken(); + else if (i == 2) + httpVersion = postMessage.nextToken(); + else + postMessage.nextToken(); + } + + if (!messageType.equals("POST")) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + + // If the third token is not HTTP/1.1 ot HTTP/1.0, then fail + else if ( + (!httpVersion.equalsIgnoreCase(MessageValidator.HTTP_VERSION_1_1)) + && (!httpVersion.equalsIgnoreCase(MessageValidator.HTTP_VERSION_1_0))) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = this.validator.createFailureDetail(httpHeader, entryContext); + } + } + } + + // Else it is a response message + else + { + // Response-Line (1st) = HTTP-Version SP Response-code SP Response-text CRLF + StringTokenizer httpMessageTokenizer = + new StringTokenizer(httpHeader, "\n\r\f"); + + String startLine = null; + try + { + if (httpMessageTokenizer.hasMoreTokens()) + { + startLine = httpMessageTokenizer.nextToken(); + } + else + { + // HTTP version info expected but not found + // (state the fact in the exception message?) + throw new AssertionFailException(httpHeader); + } + + // check that protocol version indicates HTTP/1.0 or HTTP/1.1 + if (!startLine.startsWith(MessageValidator.HTTP_VERSION_1_1) + && !startLine.startsWith(MessageValidator.HTTP_VERSION_1_0)) + { + throw new AssertionFailException(httpHeader); + } + } + catch (AssertionFailException e) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = this.validator.createFailureDetail(e.getMessage(), entryContext); + } + } + + // Return assertion result + return validator.createAssertionResult(testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/BP1004.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/BP1004.java new file mode 100644 index 000000000..6512e389f --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/BP1004.java @@ -0,0 +1,73 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import java.util.StringTokenizer; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.MessageValidator; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; + + +/** + * BP1004. + * The request message is a POST message, without any use of framework extension. + */ +public class BP1004 extends AssertionProcess +{ + private final BaseMessageValidator validator; + + /** + * @param BaseMessageValidator + */ + public BP1004(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + String httpHeader = entryContext.getMessageEntry().getHTTPHeaders(); + StringTokenizer httpMessageTokenizer = + new StringTokenizer(httpHeader, "\n\r\f"); + + // Check if this is a POST message + if (!httpHeader.startsWith(MessageValidator.HTTP_POST)) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = this.validator.createFailureDetail(httpHeader, entryContext); + } + + String line = null; + while (httpMessageTokenizer.hasMoreTokens() + && (result.equals(AssertionResult.RESULT_PASSED))) + { + line = httpMessageTokenizer.nextToken(); + if ((line != null) + && (line.startsWith("M-POST") || line.startsWith("Ext:"))) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = this.validator.createFailureDetail(httpHeader, entryContext); + } + } //End While + + // Return assertion result + return validator.createAssertionResult(testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/BP1006.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/BP1006.java new file mode 100644 index 000000000..c97d42421 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/BP1006.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import java.util.Map; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.HTTPUtils; + + +/** + * BP1006. + */ +public class BP1006 extends AssertionProcess +{ + private final BaseMessageValidator validator; + + /** + * @param BaseMessageValidator + */ + public BP1006(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + // Parse the HTTP header + String rawHTTPHeader = entryContext.getMessageEntry().getHTTPHeaders(); + Map httpHeader = HTTPUtils.getHttpHeaderTokens(rawHTTPHeader, ":"); + + // Get the soap action header + String soapAction = (String) httpHeader.get("SOAPAction".toUpperCase()); + + // If there is no soap action header, then NA + if (soapAction == null) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + else if (!(soapAction.startsWith("\"")) || !(soapAction.endsWith("\""))) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = + this.validator.createFailureDetail( + "HTTP Header: \"" + rawHTTPHeader + "\".", + entryContext); + } + + // Return assertion result + return validator.createAssertionResult(testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/BP1010.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/BP1010.java new file mode 100644 index 000000000..91511c1bd --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/BP1010.java @@ -0,0 +1,126 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import javax.wsdl.Binding; +import javax.wsdl.BindingOperation; +import javax.wsdl.Operation; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.HTTPUtils; +import org.eclipse.wst.wsi.internal.util.OperationSignature; +import org.eclipse.wst.wsi.internal.util.TypesRegistry; +import org.w3c.dom.Document; + + +/** + * BP1010. + * It MUST NOT contain a SOAP Envelope: the HTTP entity-body must be empty. + */ +public class BP1010 extends AssertionProcess +{ + private final BaseMessageValidator validator; + + /** + * @param BaseMessageValidator + */ + public BP1010(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + /** + * @see org.eclipse.wst.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(TestAssertion, EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + + try + { + // Parse request message + Document docRequest = entryContext.getRequestDocument(); + + // get SOAPAction + String headers = entryContext.getRequest().getHTTPHeaders(); + String action = null; + if (headers != null) + action = (String) HTTPUtils.getHttpHeaderTokens(headers, ":").get("SOAPAction".toUpperCase()); + + Binding binding = validator.analyzerContext.getCandidateInfo().getBindings()[0]; + TypesRegistry registry = + new TypesRegistry( + this.validator.getWSDLDocument().getDefinitions(), + validator); + OperationSignature.OperationMatch match = + OperationSignature.matchOperation( + docRequest, + action, + binding, + registry); + + if (match == null) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + else + { + + BindingOperation bindingOperation = match.getOperation(); + //find operation in port type + Operation operation = bindingOperation.getOperation(); + if (operation == null) + { + result = AssertionResult.RESULT_FAILED; + } + else + { + if (operation.getOutput() == null) + { + String message = entryContext.getMessageEntry().getMessage(); + if (message.length() == 0) + { + result = AssertionResult.RESULT_PASSED; + } + else + { + result = AssertionResult.RESULT_FAILED; + } + } + else + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + } + } + + if (result == AssertionResult.RESULT_FAILED) + { + failureDetail = this.validator.createFailureDetail(null, entryContext); + } + } + catch (Exception e) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + + // Return assertion result + return validator.createAssertionResult(testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/BP1101.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/BP1101.java new file mode 100644 index 000000000..429a9c436 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/BP1101.java @@ -0,0 +1,86 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.Utils; + + +/** + * BP1101. + * A response message that does not contain a SOAP message SHOULD be sent + * using either a "200 OK" or "202 Accepted" HTTP status code. + */ +public class BP1101 extends AssertionProcess +{ + private final BaseMessageValidator validator; + + /** + * @param BaseMessageValidator + */ + public BP1101(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + /** + * @see org.eclipse.wst.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(TestAssertion, EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + + // response does not contains SOAP message + if (entryContext.getMessageEntry().getMessage() == null + || "".equals(entryContext.getMessageEntry().getMessage())) + { + // check HTTP status code + String httpStatus = + Utils.getHTTPStatusCode( + entryContext.getMessageEntry().getHTTPHeaders()); + if ("200".equals(httpStatus)); + else if ("202".equals(httpStatus)); + + // If 4xx, then result is notApplicable + else if (httpStatus.startsWith("4")) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + else + { + result = AssertionResult.RESULT_WARNING; + failureDetail = + this.validator.createFailureDetail( + "\nResponse message:\nHeaders:\n" + + entryContext.getMessageEntry().getHTTPHeaders() + + "Message:\n" + + entryContext.getMessageEntry().getMessage(), + entryContext); + } + } + else + { + // response contains SOAP message + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + + // Return assertion result + return validator.createAssertionResult(testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/BP1103.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/BP1103.java new file mode 100644 index 000000000..d6d1b5f04 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/BP1103.java @@ -0,0 +1,80 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.log.MessageEntry; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.Utils; + + +/** + * BP1103. + * The request message should not contain a POST method. + */ +public class BP1103 extends AssertionProcess +{ + private final BaseMessageValidator validator; + + /** + * @param BaseMessageValidator + */ + public BP1103(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + /** + * @see org.eclipse.wst.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(TestAssertion, EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + + MessageEntry request = entryContext.getRequest(); + String requestHeaders = request.getHTTPHeaders(); + + // Get HTTP status code + String httpStatus = + Utils.getHTTPStatusCode( + entryContext.getMessageEntry().getHTTPHeaders()); + + if (requestHeaders.startsWith("POST ")) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + else if (!"405".equals(httpStatus)) + { + result = AssertionResult.RESULT_WARNING; + failureDetail = + this.validator.createFailureDetail( + "\nRequest message:\nHeaders:\n" + + entryContext.getRequest().getHTTPHeaders() + + "\nMessage:\n" + + entryContext.getRequest().getMessage() + + "\n\nResponse message:\nHeaders:\n" + + entryContext.getResponse().getHTTPHeaders() + + "\nMessage:\n" + + entryContext.getResponse().getMessage(), + entryContext); + } + + // Return assertion result + return validator.createAssertionResult(testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/BP1104.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/BP1104.java new file mode 100644 index 000000000..5af659fba --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/BP1104.java @@ -0,0 +1,93 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.log.MessageEntry; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.HTTPConstants; +import org.eclipse.wst.wsi.internal.util.HTTPUtils; +import org.eclipse.wst.wsi.internal.util.Utils; + + +/** + * BP1104. + * The request message should not contain a content-type of "text/xml". + */ +public class BP1104 extends AssertionProcess +{ + private final BaseMessageValidator validator; + + /** + * @param BaseMessageValidator + */ + public BP1104(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + /** + * @see org.eclipse.wst.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(TestAssertion, EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + // check request for the "text/xml" content type + MessageEntry request = entryContext.getRequest(); + String headers = request.getHTTPHeaders(); + String contentType = (String) HTTPUtils.getHttpHeaderTokens(headers, ":") + .get(HTTPConstants.HEADER_CONTENT_TYPE.toUpperCase()); + + // Get HTTP status code + String httpStatus = + Utils.getHTTPStatusCode( + entryContext.getMessageEntry().getHTTPHeaders()); + + // If the request message has a content type of text/xml, + // then the assertion is not applicable + if (contentType != null + && contentType.indexOf(WSIConstants.CONTENT_TYPE_TEXT_XML) != -1) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + else + { + // check HTTP status code + if (!"415".equals(httpStatus)) + { + result = AssertionResult.RESULT_WARNING; + failureDetail = + this.validator.createFailureDetail( + "\nRequest message:\nHeaders:\n" + + entryContext.getRequest().getHTTPHeaders() + + "\nMessage:\n" + + entryContext.getRequest().getMessage() + + "\n\nResponse message:\nHeaders:\n" + + entryContext.getResponse().getHTTPHeaders() + + "\nMessage:\n" + + entryContext.getResponse().getMessage(), + entryContext); + } + } + + // Return assertion result + return validator.createAssertionResult( + testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/BP1116.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/BP1116.java new file mode 100644 index 000000000..60509344a --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/BP1116.java @@ -0,0 +1,150 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import javax.wsdl.extensions.soap.SOAPOperation; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionNotApplicableException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcessVisitor; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.HTTPUtils; +import org.eclipse.wst.wsi.internal.util.OperationSignature; +import org.eclipse.wst.wsi.internal.util.TypesRegistry; +import org.eclipse.wst.wsi.internal.wsdl.traversal.WSDLTraversal; +import org.eclipse.wst.wsi.internal.wsdl.traversal.WSDLTraversalContext; +import org.w3c.dom.Document; + + +/** + * BP1116. + * SOAPAction header should contain a quoted string that has same + * value as the value of the soapbind:operation/@soapAction attribute, + * and an empty string ("") if there is no such attribute. + */ +public class BP1116 extends AssertionProcessVisitor +{ + + private final BaseMessageValidator validator; + + /** + * @param BaseMessageValidator + */ + public BP1116(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + private String action = null; + private String headers = null; + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.extensions.soap.SOAPOperation, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit( + SOAPOperation soapOper, + Object parent, + WSDLTraversalContext ctx) + { + String soapAction = soapOper.getSoapActionURI(); + if (soapAction == null) + { + if (!"".equals(action)) + { + result = AssertionResult.RESULT_FAILED; + failureDetailMessage = + "\nHTTP headers:\n" + headers + "\nsoapAction:\n" + soapAction; + } + } + else + { + if (!soapAction.equals(action)) + { + result = AssertionResult.RESULT_FAILED; + failureDetailMessage = + "\nHTTP headers:\n" + headers + "\nsoapAction:\n" + soapAction; + } + } + } + + /* (non-Javadoc) + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + try + { + // Parse request message + Document doc = entryContext.getMessageEntryDocument(); + + // get SOAPAction + headers = entryContext.getRequest().getHTTPHeaders(); + if (headers != null) + action = (String) HTTPUtils.getHttpHeaderTokens(headers, ":").get("SOAPAction".toUpperCase()); + + if (action == null) + throw new AssertionNotApplicableException(); + + if (action.length() > 1 + && action.charAt(0) == '"' + && action.charAt(action.length() - 1) == '"') + { + action = action.substring(1, action.length() - 1); + } + + OperationSignature.OperationMatch match = + OperationSignature.matchOperation( + doc, + null, + validator.analyzerContext.getCandidateInfo().getBindings()[0], + new TypesRegistry( + validator.analyzerContext + .getCandidateInfo() + .getWsdlDocument() + .getDefinitions(), + validator), + false); + + if (match != null) + { + WSDLTraversal traversal = new WSDLTraversal(); + //VisitorAdaptor.adapt(this); + traversal.setVisitor(this); + traversal.visitSOAPOperation(true); + traversal.traverse(match.getOperation()); + } + else + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + } + catch (Exception e) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + + if (result == AssertionResult.RESULT_FAILED + && failureDetailMessage != null) + { + failureDetail = this.validator.createFailureDetail(failureDetailMessage, entryContext); + } + + // Return assertion result + return validator.createAssertionResult(testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/BP4103.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/BP4103.java new file mode 100644 index 000000000..dd46795b2 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/BP4103.java @@ -0,0 +1,126 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.log.MessageEntry; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.HTTPConstants; +import org.eclipse.wst.wsi.internal.util.HTTPUtils; + +/** + * BP4103 + * + * For a candidate message in the message log file + * The message contains an HTTP Authentication header field + */ +public class BP4103 extends AssertionProcess { + + private static final String HTTP_AUTH_SCHEME_BASIC = "Basic"; + private static final String HTTP_AUTH_SCHEME_DIGEST = "Digest"; + + private final BaseMessageValidator validator; + + /** + * @param BaseMessageValidator + */ + public BP4103(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + // Getting message headers + String headers = entryContext.getMessageEntry().getHTTPHeaders(); + // If this is a request message + if (entryContext.getMessageEntry().getType().equals(MessageEntry.TYPE_REQUEST)) + { + // If the request headers contain authentication scheme "Basic" or "Digest" + // or there are no HTTP Authentication headers, the assertion is not applicable + if (!containsInvalidAuth(headers, HTTPConstants.HEADER_AUTHORIZATION) + && !containsInvalidAuth(headers, HTTPConstants.HEADER_PROXY_AUTHORIZATION)) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + } + // else this is a response + else + { + // If the response headers contain authentication scheme "Basic" or "Digest" + // or there are no HTTP Authentication headers, the assertion is not applicable + if (!containsInvalidAuth(headers, HTTPConstants.HEADER_WWW_AUTHENTICATE) + && !containsInvalidAuth(headers, HTTPConstants.HEADER_PROXY_AUTHENTICATE)) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + } + + // Assertion result has not been changed, HTTP Authentication headers + // does not contain authentication scheme "Basic" or "Digest", + // the assertion passed + if (result.equals(AssertionResult.RESULT_PASSED)) + { + failureDetail = validator.createFailureDetail( + testAssertion.getDetailDescription(), entryContext); + } + + // Return assertion result + return validator.createAssertionResult( + testAssertion, result, failureDetail); + } + + /** + * Checks whether HTTP headers contain HTTP Authentication headers that uses + * authentication scheme other than "Basic" or "Digest". + * @param headers HTTP headers. + * @param header a header name being retrieved. + * @return true if the HTTP Authentication header that uses authentication + * scheme other than "Basic" or "Digest" is found, false otherwise. + */ + private boolean containsInvalidAuth(String headers, String header) + { + // Getting a header value + String headerValue = null; + try + { + headerValue = (String) HTTPUtils.getHttpHeaderTokens(headers,":") + .get(header.toUpperCase()); + } + catch (Exception e) {} + + // If the header is presented + if (headerValue != null) + { + // Retrieving authentication scheme + int idxSP = headerValue.indexOf(" "); + if (idxSP > -1) + { + headerValue = headerValue.substring(0, idxSP); + } + // If a scheme is neither "Basic" nor "Digest", return true + if (!headerValue.equalsIgnoreCase(HTTP_AUTH_SCHEME_BASIC) + && !headerValue.equalsIgnoreCase(HTTP_AUTH_SCHEME_DIGEST)) + { + return true; + } + } + return false; + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/BP4104.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/BP4104.java new file mode 100644 index 000000000..2b50a0bd2 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/BP4104.java @@ -0,0 +1,87 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.HTTPConstants; +import org.eclipse.wst.wsi.internal.util.HTTPUtils; + +/** + * BP4104 + * For a candidate message in the message log file containing an HTTP Header field that is not from the following list of specified header fields: (http://www.mnot.net/drafts/draft-nottingham-http-header-reg-00.txt) + * The message contains an HTTP Header field that is not from the following list of specified header fields: (http://www.mnot.net/drafts/draft-nottingham-http-header-reg-00.txt) + */ +public class BP4104 extends AssertionProcess { + + private final BaseMessageValidator validator; + + private List knownHeaderNames; + + /** + * @param BaseMessageValidator + */ + public BP4104(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + knownHeaderNames = null; + } + + private List getAllKnownHeaderNames() { + if (knownHeaderNames == null) { + knownHeaderNames = HTTPConstants.getAllKnownHeaderNames(); + } + return knownHeaderNames; + } + + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + + // getting HTTP Headers + Map hmap = HTTPUtils.getHttpHeaderTokens( + entryContext.getMessageEntry().getHTTPHeaders(), ":"); + + Iterator i = hmap.keySet().iterator() ; + while (i.hasNext()) { + String headerName = (String) i.next(); + // If header name is not known, then the assertion passed + if (!getAllKnownHeaderNames().contains(headerName.toUpperCase())) + { + failureDetail = validator.createFailureDetail( + testAssertion.getDetailDescription(), entryContext); + + break; + } + } + + // If there is no HTTP header that is not from a list, + // then the assertion is not applicable + if (failureDetail == null) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + + return validator.createAssertionResult( + testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/BP4105.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/BP4105.java new file mode 100644 index 000000000..abd09f7dd --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/BP4105.java @@ -0,0 +1,95 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import java.util.StringTokenizer; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.HTTPConstants; +import org.eclipse.wst.wsi.internal.util.HTTPUtils; + + +/** + * BP4105 + * For a candidate message in the message log file containing a Content-encoding HTTP header field with a value other than "gzip", "compress" or "deflate" + * The contained Content-encoding HTTP header field has a value other than "gzip", "compress" or "deflate". + */ +public class BP4105 extends AssertionProcess { + + // All the registered content-coding value tokens (RFC2616) except "identity" + private static final String GZIP_VALUE = "gzip"; + private static final String COMPRESS_VALUE = "compress"; + private static final String DEFLATE_VALUE = "deflate"; + + private final BaseMessageValidator validator; + + /** + * @param BaseMessageValidator + */ + public BP4105(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + + // Getting the Content-Encoding HTTP header value + String contentEncoding = (String) HTTPUtils.getHttpHeaderTokens( + entryContext.getMessageEntry().getHTTPHeaders(), + ":").get(HTTPConstants.HEADER_CONTENT_ENCODING.toUpperCase()); + + if (contentEncoding != null) + { + // Lowering value's case because RFC2616 says + // that all content-coding values are case-insensitive + contentEncoding = contentEncoding.toLowerCase(); + + // Multiple encodings can be applied to an entity, + // so breaking the value into tokens + StringTokenizer st = new StringTokenizer(contentEncoding, ","); + while (st.hasMoreTokens()) + { + String token = st.nextToken().trim(); + // If a token does not equal to any registered one + // then the assertion passed + if ( !token.equals(GZIP_VALUE) + && !token.equals(COMPRESS_VALUE) + && !token.equals(DEFLATE_VALUE)) { + + failureDetail = validator.createFailureDetail( + testAssertion.getDetailDescription(), entryContext); + + break; + } + } + } + + // If there is no unregistered value of Content-Encoding, + // then the assertion is not applicable + if (failureDetail == null) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + + return validator.createAssertionResult( + testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/BP4106.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/BP4106.java new file mode 100644 index 000000000..0d9489b94 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/BP4106.java @@ -0,0 +1,77 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.HTTPConstants; +import org.eclipse.wst.wsi.internal.util.HTTPUtils; + + +/** + * BP4106 + * For a candidate response message in the message log file that contains a transfer-encoding HTTP header field. + * The contained transfer-encoding HTTP header field has a value of "chunked" + */ +public class BP4106 extends AssertionProcess { + + private static final String CHUNKED_VALUE = "chunked"; + + private final BaseMessageValidator validator; + + /** + * @param BaseMessageValidator + */ + public BP4106(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + + // Getting a Transfer-Encoding HTTP header value + String transferEncoding = (String) HTTPUtils.getHttpHeaderTokens( + entryContext.getMessageEntry().getHTTPHeaders(), + ":").get(HTTPConstants.HEADER_TRANSFER_ENCODING.toUpperCase()); + + if (transferEncoding != null) + { + // Lowering value's case because RFC2616 says + // that all transfer-coding values are case-insensitive + transferEncoding = transferEncoding.toLowerCase(); + + // If the value is other than "chunked", then the assertion passed + if (!transferEncoding.equals(CHUNKED_VALUE)) { + failureDetail = validator.createFailureDetail( + testAssertion.getDetailDescription(), entryContext); + } + } + + // If there is no Tranfer-Encoding or its value is "chunked", + // then the assertion is not applicable + if (failureDetail == null) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + + return validator.createAssertionResult( + testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/BP4107.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/BP4107.java new file mode 100644 index 000000000..4e68a612b --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/BP4107.java @@ -0,0 +1,66 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.HTTPConstants; +import org.eclipse.wst.wsi.internal.util.HTTPUtils; + + +/** + * BP4107 + * For a request message containing an Upgrade field in the HTTP Headers. + * The request message contains an Upgrade field in the HTTP Headers. + */ +public class BP4107 extends AssertionProcess { + + private final BaseMessageValidator validator; + + /** + * @param BaseMessageValidator + */ + public BP4107(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + // Getting the Upgrade HTTP header value + String upgrage = (String) HTTPUtils.getHttpHeaderTokens( + entryContext.getMessageEntry().getHTTPHeaders(), + ":").get(HTTPConstants.HEADER_UPGRADE.toUpperCase()); + + // If the header is presented, then the assertion passed + if (upgrage != null) + { + failureDetail = validator.createFailureDetail( + testAssertion.getDetailDescription(), entryContext); + } + // else the assertion is not applicable + else + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + + return validator.createAssertionResult( + testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/MessageValidatorImpl.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/MessageValidatorImpl.java new file mode 100644 index 000000000..0938add12 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/MessageValidatorImpl.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2002-2003 IBM Corporation, Parasoft and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * Contributors: + * IBM - Initial API and implementation + * Parasoft - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.MessageValidator; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.util.EntryType; + +/** + * @version 1.0 + */ +public class MessageValidatorImpl + extends BaseMessageValidator + implements MessageValidator +{ + /* (non-Javadoc) + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl#isPrimaryEntryTypeMatch(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + protected boolean isPrimaryEntryTypeMatch( + TestAssertion testAssertion, + EntryContext entryContext) + { + boolean match = false; + + // Verify that the entry and test assertion have the same primary context + if ((testAssertion.getEntryTypeName().equals(EntryType.TYPE_MESSAGE_ANY)) + || (testAssertion.getEntryTypeName().equals(EntryType.TYPE_MESSAGE_REQUEST) + && (entryContext + .getEntry() + .getEntryType() + .getTypeName() + .equals(EntryType.TYPE_MESSAGE_REQUEST))) + || (testAssertion.getEntryTypeName().equals(EntryType.TYPE_MESSAGE_RESPONSE) + && (entryContext + .getEntry() + .getEntryType() + .getTypeName() + .equals(EntryType.TYPE_MESSAGE_RESPONSE))) + || testAssertion.getEntryTypeName().equals(EntryType.TYPE_MIME_ROOT_PART) + || testAssertion.getEntryTypeName().equals(EntryType.TYPE_MIME_PART)) + { + match = true; + } + + return match; + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/SSBP1003.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/SSBP1003.java new file mode 100644 index 000000000..0c5bb9851 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/SSBP1003.java @@ -0,0 +1,228 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import java.util.Map; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionFailException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionNotApplicableException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionPassException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.HTTPUtils; + + +/** + * SSBP1003. + * + * For a candidate non-multipart/related message in the log file, which has a non-empty entity-body + * + * The logged SOAP envelope is a UTF-8 transcript of an envelope originally encoded as UTF-8 or UTF-16. + * The HTTP Content-Type header's charset value is either UTF-8 or UTF-16. Looking at the messageContent + * element of the logged message, either + * (1) it has a BOM attribute which maps the charset value in the Content-Type header, or + * (2) it has it has an XML declaration which matches the charset value in the Content-Type header, or + * (3) there is no BOM attribute and no XML declaration, and the charset value is UTF-8. + * + * + * @author lauzond + */ +public class SSBP1003 extends AssertionProcess +{ + protected final BaseMessageValidator validator; + + /** + * @param BaseMessageValidator + */ + public SSBP1003(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + try + { + // If there is a response message for one-way operation, the assertion is not applicable + if (validator.isOneWayResponse(entryContext)) + { + throw new AssertionNotApplicableException(); + } + + String httpHeader = entryContext.getMessageEntry().getHTTPHeaders(); + + Map httpHeaderMap = HTTPUtils.getHttpHeaderTokens(httpHeader, ":"); + String contentType = (String) httpHeaderMap.get("Content-Type".toUpperCase()); + + if (contentType == null) + { + throw new AssertionFailException( + "The Content-Type header is not present."); + } + + contentType = contentType.trim(); + String charset = contentType.substring( + contentType.indexOf(";") + 1, contentType.length()); + charset = charset.trim(); + if (!charset.startsWith("charset")) + { + throw new AssertionFailException( + "Missing or bad \"charset\" attribute in the Content-Type header: " + + charset); + } + + String charsetValue = charset.substring( + charset.indexOf("=") + 1, charset.length()); + if (charsetValue.startsWith("\"")) + { + charsetValue = charsetValue.substring(1, charsetValue.length() - 1); + } + + if (!charsetValue.equalsIgnoreCase("utf-8") + && !charsetValue.equalsIgnoreCase("utf-16")) + { + throw new AssertionFailException("The value of the \"charset\" " + + "attribute of the Content-Type header is " + contentType); + } + // Parse log message + //gets first string + int idx = entryContext.getMessageEntry().getMessage().indexOf(""); + if (idx2 == -1) + { + throw new AssertionPassException(); + } + + String xmlDeclaration = entryContext.getMessageEntry().getMessage() + .substring(idx, idx2 + "?>".length()); + + idx = xmlDeclaration.indexOf("encoding"); + if (idx == -1) + { + if (charsetValue.equalsIgnoreCase("utf-8")) + { + throw new AssertionPassException(); + } + else + { + throw new AssertionFailException("There is no XML declaration and the" + + " charset value in the Content-Type header is not UTF-8." + + "\nCharset value in the Content-Type header: " + charsetValue); + } + } + + int idxQ = xmlDeclaration.indexOf('\'', idx); + int idxQQ = xmlDeclaration.indexOf('\"', idx); + int idxQuote = -1; + char qouteCh = '\0'; + if (idxQ == -1) + { + idxQuote = idxQQ; + qouteCh = '\"'; + } + else + { + if (idxQQ == -1) + { + idxQuote = idxQ; + qouteCh = '\''; + } + else + { + if (idxQQ < idxQ) + { + idxQuote = idxQQ; + qouteCh = '\"'; + } + else + { + idxQuote = idxQ; + qouteCh = '\''; + } + } + } + + if (idxQuote == -1 || qouteCh == '\0') + { + throw new AssertionPassException(); + } + + int idxLQoute = xmlDeclaration.indexOf(qouteCh, idxQuote + 1); + + if (idxLQoute == -1) + { + throw new AssertionPassException(); + } + + String xmlEncoding = + xmlDeclaration.substring(idxQuote + 1, idxLQoute); + if (charsetValue.equalsIgnoreCase(xmlEncoding)) + { + // If there is a BOM, then check that it is the same as the xmlEncoding + int bom = 0; + if ((bom = entryContext.getMessageEntry().getBOM()) != 0) + { + if ((bom == WSIConstants.BOM_UTF8 + && !xmlEncoding.equalsIgnoreCase("utf-8")) + || ((bom == WSIConstants.BOM_UTF16 + && !xmlEncoding.equalsIgnoreCase("utf-16"))) + || ((bom == WSIConstants.BOM_UTF16_BIG_ENDIAN + && !xmlEncoding.equalsIgnoreCase("utf-16")))) + { + throw new AssertionFailException( + "The BOM and XML declaration do not match."); + } + } + + throw new AssertionPassException(); + } + else + { + throw new AssertionFailException("There is an XML declaration, but its " + + "encoding value does not match the charset value.\n" + + "Charset value in the Content-Type header: " + charsetValue + + "\nEncoding in the XML declaration: " + xmlEncoding); + } + } + catch (AssertionPassException e) + { + result = AssertionResult.RESULT_PASSED; + } + catch (AssertionNotApplicableException anae) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + catch (AssertionFailException afe) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = validator.createFailureDetail( + afe.getMessage(), entryContext); + } + + // Return assertion result + return validator.createAssertionResult( + testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/SSBP5100.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/SSBP5100.java new file mode 100644 index 000000000..db528ce45 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/SSBP5100.java @@ -0,0 +1,80 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionFailException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionNotApplicableException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; +import org.w3c.dom.Document; + + +/** + * SSBP5100 + * For a candidate message in the log file, with an HTTP entity-body. + * The SOAP envelope is the exclusive payload of the HTTP entity-body. + */ +public class SSBP5100 extends AssertionProcess { + + protected final BaseMessageValidator validator; + + /** + * @param BaseMessageValidator + */ + public SSBP5100(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + + try + { + // Getting a message document + Document doc = entryContext.getMessageEntryDocument(); + + // If the message is empty or invalid, the assertion is not applicable + if (doc == null) + { + if (this.validator.isOneWayResponse(entryContext)) + throw new AssertionNotApplicableException(); + else + throw new AssertionFailException(); + } + if (!doc.getDocumentElement().getLocalName().equals(XMLUtils.SOAP_ELEM_ENVELOPE)) + throw new AssertionFailException(); + } + catch (AssertionFailException afe) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = validator.createFailureDetail( + testAssertion.getFailureMessage(), + entryContext); + } + catch (AssertionNotApplicableException anae) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + + return validator.createAssertionResult( + testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/SSBP5101.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/SSBP5101.java new file mode 100644 index 000000000..0a7a68401 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/SSBP5101.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.HTTPConstants; +import org.eclipse.wst.wsi.internal.util.HTTPUtils; + +/** + * SSBP5101 + * For a candidate message in the log file. + * A message must have a "Content-Type" HTTP header field. The "Content-Type" HTTP header field must have a field-value whose media type is "text/xml". + * + * @author lauzond + */ +public class SSBP5101 extends AssertionProcess { + + protected final BaseMessageValidator validator; + + /** + * @param BaseMessageValidator + */ + public SSBP5101(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + + // getting Content-Type HTTP header + String contentType = (String) HTTPUtils.getHttpHeaderTokens( + entryContext.getMessageEntry().getHTTPHeaders(), + ":").get(HTTPConstants.HEADER_CONTENT_TYPE.toUpperCase()); + + // if Content-Type header is not presented + // or does not equal to text/xml, then the assertion is failed + if (contentType == null + || !contentType.startsWith(WSIConstants.CONTENT_TYPE_TEXT_XML)) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = validator.createFailureDetail( + testAssertion.getFailureMessage(), + entryContext); + } + return this.validator.createAssertionResult( + testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1001.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1001.java new file mode 100644 index 000000000..fd54c0a0b --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1001.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; + +/** + * WSI1001 + */ +public class WSI1001 extends BP1001 +{ + + /** + * @param BaseMessageValidator + */ + public WSI1001(BaseMessageValidator impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1002.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1002.java new file mode 100644 index 000000000..1596f8a52 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1002.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; + +/** + * WSI1002 + */ +public class WSI1002 extends BP1002 +{ + + /** + * @param BaseMessageValidator + */ + public WSI1002(BaseMessageValidator impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1003.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1003.java new file mode 100644 index 000000000..7ea67d346 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1003.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; + +/** + * WSI1003 + */ +public class WSI1003 extends SSBP1003 +{ + + /** + * @param BaseMessageValidator + */ + public WSI1003(BaseMessageValidator impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1004.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1004.java new file mode 100644 index 000000000..e3989c3f2 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1004.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; + +/** + * WSI1004 + */ +public class WSI1004 extends BP1004 +{ + + /** + * @param BaseMessageValidator + */ + public WSI1004(BaseMessageValidator impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1005.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1005.java new file mode 100644 index 000000000..f2e642af1 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1005.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.profile.validator.impl.envelope.BP1005; + +/** + * WSI1005 + */ +public class WSI1005 extends BP1005 +{ + + /** + * @param BaseMessageValidator + */ + public WSI1005(BaseMessageValidator impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1006.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1006.java new file mode 100644 index 000000000..e9bc23649 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1006.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; + +/** + * WSI1006 + */ +public class WSI1006 extends BP1006 +{ + + /** + * @param BaseMessageValidator + */ + public WSI1006(BaseMessageValidator impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1007.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1007.java new file mode 100644 index 000000000..b98682a79 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1007.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.profile.validator.impl.envelope.BP1007; + +/** + * WSI1007 + */ +public class WSI1007 extends BP1007 +{ + + /** + * @param BaseMessageValidator + */ + public WSI1007(BaseMessageValidator impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1008.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1008.java new file mode 100644 index 000000000..34215815c --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1008.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.profile.validator.impl.envelope.BP1008; + +/** + * WSI1008 + */ +public class WSI1008 extends BP1008 +{ + + /** + * @param BaseMessageValidator + */ + public WSI1008(BaseMessageValidator impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1009.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1009.java new file mode 100644 index 000000000..0fc8662d5 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1009.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.profile.validator.impl.envelope.BP1009; + +/** + * WSI1009 + */ +public class WSI1009 extends BP1009 +{ + + /** + * @param BaseMessageValidator + */ + public WSI1009(BaseMessageValidator impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1010.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1010.java new file mode 100644 index 000000000..0d18bf3cd --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1010.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; + +/** + * WSI1010 + */ +public class WSI1010 extends BP1010 +{ + + /** + * @param BaseMessageValidator + */ + public WSI1010(BaseMessageValidator impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1011.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1011.java new file mode 100644 index 000000000..d5b9743e8 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1011.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.profile.validator.impl.envelope.BP1011; + +/** + * WSI1011 + */ +public class WSI1011 extends BP1011 +{ + + /** + * @param BaseMessageValidator + */ + public WSI1011(BaseMessageValidator impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1012.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1012.java new file mode 100644 index 000000000..b2cc640fb --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1012.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.profile.validator.impl.envelope.BP1012; + +/** + * WSI1012 + */ +public class WSI1012 extends BP1012 +{ + + /** + * @param BaseMessageValidator + */ + public WSI1012(BaseMessageValidator impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1013.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1013.java new file mode 100644 index 000000000..e2f71dd44 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1013.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.profile.validator.impl.envelope.BP1013; + +/** + * WSI1013 + */ +public class WSI1013 extends BP1013 +{ + + /** + * @param BaseMessageValidator + */ + public WSI1013(BaseMessageValidator impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1031.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1031.java new file mode 100644 index 000000000..4383e9cfd --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1031.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.profile.validator.impl.envelope.BP1031; + +/** + * WSI1031 + */ +public class WSI1031 extends BP1031 +{ + + /** + * @param BaseMessageValidator + */ + public WSI1031(BaseMessageValidator impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1100.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1100.java new file mode 100644 index 000000000..4cdb358bc --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1100.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.profile.validator.impl.envelope.BP1100; + +/** + * WSI1100 + */ +public class WSI1100 extends BP1100 +{ + + /** + * @param BaseMessageValidator + */ + public WSI1100(BaseMessageValidator impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1101.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1101.java new file mode 100644 index 000000000..5ef5d2cb2 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1101.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; + +/** + * WSI1101 + */ +public class WSI1101 extends BP1101 +{ + + /** + * @param BaseMessageValidator + */ + public WSI1101(BaseMessageValidator impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1102.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1102.java new file mode 100644 index 000000000..042a4f6a3 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1102.java @@ -0,0 +1,150 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import java.io.StringReader; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.HTTPConstants; +import org.eclipse.wst.wsi.internal.util.HTTPUtils; +import org.eclipse.wst.wsi.internal.util.HttpHeadersValidator; +import org.eclipse.wst.wsi.internal.util.Utils; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; + + +/** + * BPWSI4. + * The request message should be invalid (HTTP request malformed, + * XML not well formed, ...). + */ +public class WSI1102 extends AssertionProcess +{ + private final BaseMessageValidator validator; + + /** + * @param BaseMessageValidator + */ + public WSI1102(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + /* (non-Javadoc) + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + + String httpHeader = entryContext.getMessageEntry().getHTTPHeaders(); + + String requestMessage = null; + //String responseMessage = null; + String contentType = null; + result = null; + // + + try + { + // check HTTP status code + String httpStatus = + Utils.getHTTPStatusCode( + entryContext.getMessageEntry().getHTTPHeaders()); + if ("400".equals(httpStatus)) + { + + requestMessage = entryContext.getRequest().getMessage(); + + String requestHTTPHeaders = + entryContext.getRequest().getHTTPHeaders(); + + //check request HTTP Headers + + //HttpHeadersValidator validator = new HttpHeadersValidator(); + + if (!HttpHeadersValidator + .validateHttpRequestHeaders(requestHTTPHeaders)) + { + result = AssertionResult.RESULT_PASSED; + } + + //check request xml message + + contentType = (String) HTTPUtils.getHttpHeaderTokens(httpHeader, ":") + .get(HTTPConstants.HEADER_CONTENT_TYPE.toUpperCase()); + if (contentType.indexOf(WSIConstants.CONTENT_TYPE_TEXT_XML) != -1) + { + try + { + if (requestMessage != null) + { + DocumentBuilderFactory factory = + DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = factory.newDocumentBuilder(); + //Document doc = builder.parse(new InputSource(new StringReader(requestMessage))); + builder.parse( + new InputSource(new StringReader(requestMessage))); + } + + } + catch (SAXException e) + { + result = AssertionResult.RESULT_PASSED; + } + catch (Exception e) + { + new WSIException(e.getMessage(), e); + } + } + + if (result == null) + { + result = AssertionResult.RESULT_WARNING; + failureDetail = + this.validator.createFailureDetail( + "\nRequest message:\nHeaders:\n" + + entryContext.getRequest().getHTTPHeaders() + + "Message:\n" + + entryContext.getRequest().getMessage() + + "\n\nResponse message:\nHeaders:\n" + + entryContext.getResponse().getHTTPHeaders() + + "Message:\n" + + entryContext.getResponse().getMessage(), + entryContext); + } + } + else + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + } + catch (WSIException wsie) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + + // Return assertion result + return validator.createAssertionResult(testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1103.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1103.java new file mode 100644 index 000000000..df52b104d --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1103.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; + +/** + * WSI1103 + */ +public class WSI1103 extends BP1103 +{ + + /** + * @param BaseMessageValidator + */ + public WSI1103(BaseMessageValidator impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1104.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1104.java new file mode 100644 index 000000000..9e0ce85aa --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1104.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; + +/** + * WSI1104. + * The request message should not contain a content-type of "text/xml". + */ +public class WSI1104 extends BP1104 +{ + + /** + * @param BaseMessageValidator + */ + public WSI1104(BaseMessageValidator impl) + { + super(impl); + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1105.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1105.java new file mode 100644 index 000000000..52c56f2a2 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1105.java @@ -0,0 +1,110 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.log.MessageEntry; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.HTTPUtils; +import org.eclipse.wst.wsi.internal.util.SetCookie2Validator; + + +/** + * BPWSI4. + * The Cookies should conform to RFC2965. + */ +public class WSI1105 extends AssertionProcess +{ + private final BaseMessageValidator validator; + + /** + * @param BaseMessageValidator + */ + public WSI1105(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + /** + * @see org.eclipse.wst.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(TestAssertion, EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + + SetCookie2Validator cookieVal = new SetCookie2Validator(); + String headers = entryContext.getMessageEntry().getHTTPHeaders(); + if (entryContext + .getMessageEntry() + .getType() + .equalsIgnoreCase(MessageEntry.TYPE_RESPONSE)) + { + // if response trom server + String setCookie2 = + (String) HTTPUtils.getHttpHeaderTokens(headers, ":").get("Set-Cookie2".toUpperCase()); + if (setCookie2 == null) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + else + { + if (cookieVal.isSetCookie2(setCookie2.trim())) + result = AssertionResult.RESULT_PASSED; + else + { + result = AssertionResult.RESULT_WARNING; + failureDetail = + this.validator.createFailureDetail( + "\nMessage:\nHeaders:\n" + + entryContext.getMessageEntry().getHTTPHeaders() + + "\nSOAP message:\n" + + entryContext.getMessageEntry().getMessage(), + entryContext); + } + } + } + else + { + // if request to the server + String cookie = + (String) HTTPUtils.getHttpHeaderTokens(headers, ":").get("Cookie"); + if (cookie == null) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + else + { + if (cookieVal.isCookie(cookie.trim())) + result = AssertionResult.RESULT_PASSED; + else + { + result = AssertionResult.RESULT_WARNING; + failureDetail = + this.validator.createFailureDetail( + "\nMessage:\nHeaders:\n" + + entryContext.getMessageEntry().getHTTPHeaders() + + "\nSOAP message:\n" + + entryContext.getMessageEntry().getMessage(), + entryContext); + } + } + } + // Return assertion result + return validator.createAssertionResult(testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1107.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1107.java new file mode 100644 index 000000000..0cfbac6da --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1107.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.profile.validator.impl.envelope.BP1107; + +/** + * WSI1107 + */ +public class WSI1107 extends BP1107 +{ + + /** + * @param BaseMessageValidator + */ + public WSI1107(BaseMessageValidator impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1108.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1108.java new file mode 100644 index 000000000..55782595a --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1108.java @@ -0,0 +1,415 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Vector; + +import javax.wsdl.BindingOperation; +import javax.wsdl.Definition; +import javax.wsdl.Message; +import javax.wsdl.Part; +import javax.wsdl.extensions.soap.SOAPBody; +import javax.wsdl.extensions.soap.SOAPFault; +import javax.wsdl.extensions.soap.SOAPHeader; +import javax.wsdl.extensions.soap.SOAPHeaderFault; +import javax.xml.namespace.QName; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.WSITag; +import org.eclipse.wst.wsi.internal.log.MessageEntry; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcessVisitor; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.NullUtil; +import org.eclipse.wst.wsi.internal.util.OperationSignature; +import org.eclipse.wst.wsi.internal.util.TypesRegistry; +import org.eclipse.wst.wsi.internal.util.WSDLUtil; +import org.eclipse.wst.wsi.internal.wsdl.traversal.WSDLTraversal; +import org.eclipse.wst.wsi.internal.wsdl.traversal.WSDLTraversalContext; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + + +/** + * BPWSI4. + * Each soapbind extension element with a wsdl:required + * attribute of false must appear in a message. + */ +public class WSI1108 extends AssertionProcessVisitor implements WSITag +{ + + private final BaseMessageValidator validator; + + /** + * @param BaseMessageValidator + */ + public WSI1108(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + private OperationSignature.OperationMatch match = null; + private EntryContext entryContext = null; + private OperationSignature responseSig = null; + private Vector headerRarts = null; + private boolean visitFault = false; + private boolean existSOAPHeader = true; + private boolean isRequest = false; + private boolean existSOAPHeaderFault = true; + + /** + * @see org.eclipse.wst.wsi.wsdl.traversal.WSDLVisitor#visit(SOAPBody, Object, WSDLTraversalContext) + */ + public void visit(SOAPBody body, Object parent, WSDLTraversalContext ctx) + { + + // if "wsdl:required" is true then return + if (body.getRequired() != null + && body.getRequired().booleanValue() == true) + return; + + // assert parent instanceof BindingOutput + BindingOperation bop = ctx.getBindingOperation(); + if (bop.getOperation() == null + || bop.getOperation().getOutput() == null + || bop.getOperation().getOutput().getMessage() == null) + return; + Message msg = bop.getOperation().getOutput().getMessage(); + List parts = + WSDLUtil.getParts( + bop.getOperation(), + msg, + body, + match.getOperationStyle()); + + QName additionalName = null; + // if operation is rpc, add to parts qname qith function name + if (WSIConstants + .ATTRVAL_SOAP_BIND_STYLE_RPC + .equals(match.getOperationStyle())) + { + // found out target namespace + String namespace = body.getNamespaceURI(); + if (namespace == null || namespace.length() == 0) + // !! ATTENTION + // namespace should be retrieved from service target nameapce + namespace = ctx.getBinding().getQName().getNamespaceURI(); + + // insert operation name as first signature part + additionalName = + new QName( + namespace, + bop + .getOperation() + .getOutput() + .getMessage() + .getQName() + .getLocalPart()); + } + + // create the signature of this operation + OperationSignature op = + new OperationSignature( + parts, + null, + new TypesRegistry( + validator.analyzerContext + .getCandidateInfo() + .getWsdlDocument() + .getDefinitions(), + validator), + false); + if (additionalName != null) + op.getSignature().add(0, additionalName); + + if (op.getSignature().equals(responseSig.getSignature())) + { + // ctx.cancelBindingOperationProcessing(); + } + else + { + // create the signature of this operation + op = + new OperationSignature( + parts, + null, + new TypesRegistry( + validator.analyzerContext + .getCandidateInfo() + .getWsdlDocument() + .getDefinitions(), + validator), + true); + + if (additionalName != null) + op.getSignature().add(0, additionalName); + if (op.getSignature().equals(responseSig.getSignature())) + { + // ctx.cancelBindingOperationProcessing(); + } + else + { + result = AssertionResult.RESULT_FAILED; + failureDetail = + this.validator.createFailureDetail( + "\nMessage:\n" + entryContext.getMessageEntry().getMessage(), + entryContext); + ctx.cancelBindingOperationProcessing(); + } + } + } + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.extensions.soap.SOAPHeader, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit( + SOAPHeader header, + Object parent, + WSDLTraversalContext ctx) + { + + if (existSOAPHeaderFault == false) + { + existSOAPHeader = false; + ctx.cancelBindingOperationProcessing(); + return; + } + // if "wsdl:required" is true then return + if (header.getRequired() != null + && header.getRequired().booleanValue() == true) + return; + // find headr part + Definition d = (Definition) ctx.getParameter("definition"); + TypesRegistry tReg = (TypesRegistry) ctx.getParameter("TypesRegistry"); + Part mesPart = + WSDLUtil.getPart(d.getMessage(header.getMessage()), header.getPart()); + + // test this part and parts from header + QName partQName = mesPart.getTypeName(); + if (partQName == null) + partQName = tReg.getType(mesPart.getElementName()); + if (partQName == null) + throw new IllegalArgumentException( + "Part type can not be null." + mesPart.getElementName().toString()); + String local = partQName.getLocalPart(); + String ns = partQName.getNamespaceURI(); + + existSOAPHeader = false; + for (int i = 0; i < headerRarts.size(); i++) + { + Element elem = (Element) headerRarts.get(i); + if (elem.getLocalName().equals(local) + && NullUtil.equals(ns, elem.getNamespaceURI())) + { + existSOAPHeader = true; + break; + } + } + if (existSOAPHeader == true) + ctx.cancelSOAPHeaderProcessing(); + if (isRequest == true) + ctx.cancelBindingOperationProcessing(); + if (existSOAPHeader == false && isRequest == false) + existSOAPHeaderFault = false; + } + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.extensions.soap.SOAPHeaderFault, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit( + SOAPHeaderFault headerFault, + Object parent, + WSDLTraversalContext ctx) + { + // find headr part + Definition d = (Definition) ctx.getParameter("definition"); + TypesRegistry tReg = (TypesRegistry) ctx.getParameter("TypesRegistry"); + Part mesPart = + WSDLUtil.getPart( + d.getMessage(headerFault.getMessage()), + headerFault.getPart()); + + // test this part and parts from headerfault + QName partQName = mesPart.getTypeName(); + if (partQName == null) + partQName = tReg.getType(mesPart.getElementName()); + if (partQName == null) + throw new IllegalArgumentException( + "Part type can not be null." + mesPart.getElementName().toString()); + String local = partQName.getLocalPart(); + String ns = partQName.getNamespaceURI(); + + for (int i = 0; i < headerRarts.size(); i++) + { + Element elem = (Element) headerRarts.get(i); + if (elem.getLocalName().equals(local) + && NullUtil.equals(ns, elem.getNamespaceURI())) + { + existSOAPHeaderFault = true; + break; + } + } + if (existSOAPHeaderFault == true) + ctx.cancelSOAPHeaderProcessing(); + } + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.extensions.soap.SOAPFault, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit(SOAPFault fault, Object parent, WSDLTraversalContext ctx) + { + // set in true if any SOAPFault exist + visitFault = true; + } + + /* (non-Javadoc) + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + + if (this.validator.isOneWayResponse(entryContext)) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + else + { + this.entryContext = entryContext; + // Parse request message + Document doc = entryContext.getRequestDocument(); + // create request signature + match = + OperationSignature.matchOperation( + doc, + null, + validator.analyzerContext.getCandidateInfo().getBindings()[0], + new TypesRegistry( + validator.analyzerContext + .getCandidateInfo() + .getWsdlDocument() + .getDefinitions(), + validator), + false); + + // if such operation exist + if (match != null) + { + isRequest = + MessageEntry.TYPE_REQUEST.equals( + entryContext.getMessageEntry().getType()); + // Parse message + doc = entryContext.getMessageEntryDocument(); + + if (!isRequest) + { + responseSig = new OperationSignature(doc); + if (WSIConstants + .ATTRVAL_SOAP_BIND_STYLE_RPC + .equals(match.getOperationStyle())) + responseSig.createRPCSignature(); + } + // extract all headers from message + Element headerElem = + XMLUtils.findChildElement( + doc.getDocumentElement(), + WSITag.ELEM_SOAP_HEADER); + headerRarts = new Vector(); + if (headerElem != null) + headerRarts = XMLUtils.getChildElements(headerElem); + + WSDLTraversal traversal = new WSDLTraversal(); + //VisitorAdaptor.adapt(this); + traversal.setVisitor(this); + traversal.visitSOAPBody(true); + traversal.visitSOAPHeader(true); + traversal.visitSOAPHeaderFault(true); + traversal.visitSOAPFault(true); + + traversal.ignoreReferences(); + traversal.ignoreBindingInput2SOAPBody(); + + if (isRequest) + traversal.ignoreBindingOutput(); + else + traversal.ignoreBindingInput2SOAPHeader(); + + if (responseSig != null && responseSig.isFault()) + traversal.ignoreBindingOutput(); + else + traversal.ignoreBindingFault(); + + existSOAPHeaderFault = true; + Map m = new HashMap(); + WSDLUtil.expandDefinition( + validator.analyzerContext + .getCandidateInfo() + .getWsdlDocument() + .getDefinitions()); + m.put( + "definition", + validator.analyzerContext + .getCandidateInfo() + .getWsdlDocument() + .getDefinitions()); + TypesRegistry tReg = + new TypesRegistry( + validator.analyzerContext + .getCandidateInfo() + .getWsdlDocument() + .getDefinitions(), + validator); + m.put("TypesRegistry", tReg); + traversal.traverse(match.getOperation(), m); + + if (isRequest == false) + if (existSOAPHeaderFault == true) + existSOAPHeader = true; + + if (responseSig != null + && responseSig.isFault() + && visitFault == false) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = + this.validator.createFailureDetail( + "\nMessage:\n" + entryContext.getMessageEntry().getMessage(), + entryContext); + } + if (existSOAPHeader == false) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = + this.validator.createFailureDetail( + "\nMessage:\n" + entryContext.getMessageEntry().getMessage(), + entryContext); + } + } + else + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + } + + // Return assertion result + return validator.createAssertionResult(testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1109.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1109.java new file mode 100644 index 000000000..0ce7391e0 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1109.java @@ -0,0 +1,103 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + + +/** + * WSI1109. + * Any conformance claims MUST be children of the soap:Header element. + */ +public class WSI1109 extends AssertionProcess +{ + private final BaseMessageValidator validator; + + /** + * @param BaseMessageValidator + */ + public WSI1109(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + /** + * @see org.eclipse.wst.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(TestAssertion, EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + + if ((entryContext.getMessageEntry() != null) + && (!this.validator.isOneWayResponse(entryContext))) + { + try + { + // Parse message + Document doc = entryContext.getMessageEntryDocument(); + Element root = doc.getDocumentElement(); + // find "Header" element + NodeList headerList = + root.getElementsByTagNameNS(WSIConstants.NS_URI_SOAP, "Header"); + Element headerElem = null; + if (headerList != null && headerList.getLength() != 0) + headerElem = (Element) headerList.item(0); + + // find "Claim" element + NodeList claimList = + root.getElementsByTagNameNS(WSIConstants.NS_URI_CLAIM, "Claim"); + if (claimList == null || claimList.getLength() == 0) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + else + { + for (int i = 0; i < claimList.getLength(); i++) + { + if (headerElem == null + || claimList.item(i).getParentNode() != headerElem) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = + this.validator.createFailureDetail( + "\nSOAP message:\n" + + entryContext.getMessageEntry().getMessage(), + entryContext); + break; + } + } + } + } + catch (Exception e) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + } + else + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + // Return assertion result + return validator.createAssertionResult(testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1110.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1110.java new file mode 100644 index 000000000..08a3c5972 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1110.java @@ -0,0 +1,104 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + + +/** + * WSI1110. + * Any conformance claims MUST adhere to the WS-I conformance + * claim schema defined in the Basic Profile. + */ +public class WSI1110 extends AssertionProcess +{ + private final BaseMessageValidator validator; + + /** + * @param BaseMessageValidator + */ + public WSI1110(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + /** + * @see org.eclipse.wst.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(TestAssertion, EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + + Document doc; + if (entryContext.getMessageEntry() != null + && !this.validator.isOneWayResponse(entryContext) + && (doc = entryContext.getMessageEntryDocument()) != null) + { + Element root = doc.getDocumentElement(); + // find "Claim" element + NodeList claimList = + root.getElementsByTagNameNS(WSIConstants.NS_URI_CLAIM, "Claim"); + if (claimList == null || claimList.getLength() == 0) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + else + { + for (int i = 0; i < claimList.getLength(); i++) + { + Element elem = (Element) claimList.item(i); + // check "conformsTo" attribute + Node node = elem.getAttributeNode("conformsTo"); + if (node == null) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = + this.validator.createFailureDetail( + "\nSOAP message:\n" + + entryContext.getMessageEntry().getMessage(), + entryContext); + break; + } + /* This is checked in WSI1111 + // check "mustUnderstand" attribute + node = elem.getAttributeNodeNS(WSIConstants.NS_URI_SOAP, "mustUnderstand"); + if (node != null) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = createFailureDetail("\nSOAP message:\n" + entryContext.getMessageEntry().getMessage(), entryContext); + break; + } + */ + } + } + } + else + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + + // Return assertion result + return validator.createAssertionResult(testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1111.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1111.java new file mode 100644 index 000000000..285c5e831 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1111.java @@ -0,0 +1,111 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + + +/** + * WSI1111. + * Any conformance claims MUST NOT use soap:mustUnderstand='1'. + */ +public class WSI1111 extends AssertionProcess +{ + private final BaseMessageValidator validator; + + /** + * @param BaseMessageValidator + */ + public WSI1111(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + /** + * @see org.eclipse.wst.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(TestAssertion, EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + + Document doc; + if (entryContext.getMessageEntry() != null + && !this.validator.isOneWayResponse(entryContext) + && (doc = entryContext.getMessageEntryDocument()) != null) + { + Element root = doc.getDocumentElement(); + // find "Claim" element + NodeList claimList = + root.getElementsByTagNameNS(WSIConstants.NS_URI_CLAIM, "Claim"); + if (claimList != null && claimList.getLength() != 0) + { + // if contains "Claim" element find all "Header" elements + NodeList headerList = + root.getElementsByTagNameNS(WSIConstants.NS_URI_SOAP, "Header"); + if (headerList != null && headerList.getLength() != 0) + { + for (int iHeader = 0; iHeader < headerList.getLength(); iHeader++) + { + // find all "Header" child elements + Node child = headerList.item(iHeader).getFirstChild(); + while (child != null) + { + if (child.getNodeType() == Node.ELEMENT_NODE) + { + // if contains "mustUnderstand" -> fail + String attrVal = + ((Element) child).getAttributeNS( + WSIConstants.NS_URI_SOAP, + "mustUnderstand"); + if (attrVal != null && !"".equals(attrVal)) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = + this.validator.createFailureDetail( + "\nSOAP message:\n" + + entryContext.getMessageEntry().getMessage(), + entryContext); + iHeader = headerList.getLength(); + break; + } + } + child = child.getNextSibling(); + } + } + } + } + else + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + } + else + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + + // Return assertion result + return validator.createAssertionResult(testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1116.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1116.java new file mode 100644 index 000000000..dc97e0365 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1116.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; + +/** + * WSI1116 + */ +public class WSI1116 extends BP1116 +{ + + /** + * @param BaseMessageValidator + */ + public WSI1116(BaseMessageValidator impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1121.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1121.java new file mode 100644 index 000000000..f2c16c7a9 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1121.java @@ -0,0 +1,162 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import javax.wsdl.Binding; +import javax.wsdl.BindingOperation; +import javax.xml.namespace.QName; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionFailException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionNotApplicableException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionPassException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + + +/** + * BPWSI4. + */ +public class WSI1121 extends AssertionProcess +{ + private final BaseMessageValidator validator; + + /** + * @param BaseMessageValidator + */ + public WSI1121(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + + try + { + // GT: -- start: base on wsi1011 - should refactor this + + Binding[] bindings = validator.analyzerContext.getCandidateInfo().getBindings(); + + // get soap message child name + // Get the DOM contents of the message soap:body (if non-empty) + Document messageDoc = null; + + QName messagePartElementQName = null; + if (!entryContext.getMessageEntry().getMessage().equals("")) + { + messageDoc = + XMLUtils.parseXML(entryContext.getMessageEntry().getMessage()); + // get soap operation name from the soap:body + + // NOTE: getSoapBodyChild() may return null, if the soap:body did not contain any child elements + Element soapMessageElement = this.validator.getSoapBodyChild(messageDoc); + + // for doc-lit... find the wsdl:part from one of the specified operations that has + // the soap element used in the message. + // we are looking for a part with an element attrib val matching the soap message element + if (soapMessageElement != null) + { + messagePartElementQName = + new QName( + soapMessageElement.getNamespaceURI(), + soapMessageElement.getLocalName()); + } + } + + if ((messageDoc == null) || this.validator.isFault(messageDoc)) + { + // empty messages and messages containing soap:Faults do not qualify for this TA + throw new AssertionNotApplicableException(); + } + + BindingOperation[] docBindingOperations = + this.validator.getMatchingBindingOps( + WSIConstants.ATTRVAL_SOAP_BIND_STYLE_DOC, + bindings); + // list of operations that match the or (depending on entryType) + // for part element="..." + // (ISSUE: what about part type="..."?) + BindingOperation[] potentialDocLitOps = + this.validator.getDocLitOperations( + entryContext.getEntry().getEntryType(), + messagePartElementQName, + docBindingOperations); + // GT: --- end: base on wsi1011 + + // + if (potentialDocLitOps.length == 0) + { + // not doc-lit so quit + throw new AssertionNotApplicableException(); + } + + // We know there is a doc-lit match, so now try to validate the soap message against the + // referenced schema + + // GT - how to reference the schema document?? need to use the , or do it purely + // from the soap message elements? + // ie body, envelope or wsdl?? + + // + + boolean isSchemaValid; + + try { + isSchemaValid = this.validator.messageIsDocLitSchemaValid(entryContext); + } catch (Exception e) { + throw new AssertionFailException(); + } + // + + + //isSchemaValid = true; // for now, getting this far does it + + if (isSchemaValid) + { + throw new AssertionPassException(); + } + else + { + throw new AssertionFailException(); + } + + } + catch (AssertionPassException e) + { + result = AssertionResult.RESULT_PASSED; + } + catch (AssertionFailException e) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = this.validator.createFailureDetail(e.getMessage(), entryContext); + } + catch (AssertionNotApplicableException e) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + + } + + // Return assertion result + return validator.createAssertionResult(testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1201.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1201.java new file mode 100644 index 000000000..62748bf54 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1201.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.profile.validator.impl.envelope.BP1201; + +/** + * WSI1201 + */ +public class WSI1201 extends BP1201 +{ + + /** + * @param BaseMessageValidator + */ + public WSI1201(BaseMessageValidator impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1202.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1202.java new file mode 100644 index 000000000..e0e6bd836 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1202.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.profile.validator.impl.envelope.BP1202; + +/** + * WSI1202 + */ +public class WSI1202 extends BP1202 +{ + + /** + * @param BaseMessageValidator + */ + public WSI1202(BaseMessageValidator impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1203.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1203.java new file mode 100644 index 000000000..ffe38a3a6 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1203.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.profile.validator.impl.envelope.BP1203; + +/** + * WSI1203 + */ +public class WSI1203 extends BP1203 +{ + + /** + * @param BaseMessageValidator + */ + public WSI1203(BaseMessageValidator impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1204.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1204.java new file mode 100644 index 000000000..49056e86d --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1204.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.profile.validator.impl.envelope.BP1204; + +/** + * WSI1204 + */ +public class WSI1204 extends BP1204 +{ + + /** + * @param BaseMessageValidator + */ + public WSI1204(BaseMessageValidator impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1208.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1208.java new file mode 100644 index 000000000..e90ea3cb2 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1208.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.profile.validator.impl.envelope.BP1208; + +/** + * WSI1208 + */ +public class WSI1208 extends BP1208 +{ + + /** + * @param BaseMessageValidator + */ + public WSI1208(BaseMessageValidator impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1211.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1211.java new file mode 100644 index 000000000..907c7cf09 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1211.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.profile.validator.impl.envelope.BP1211; + +/** + * WSI1211 + */ +public class WSI1211 extends BP1211 +{ + + /** + * @param BaseMessageValidator + */ + public WSI1211(BaseMessageValidator impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1301.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1301.java new file mode 100644 index 000000000..f781e1175 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1301.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.profile.validator.impl.envelope.BP1301; + +/** + * WSI1301 + */ +public class WSI1301 extends BP1301 +{ + + /** + * @param BaseMessageValidator + */ + public WSI1301(BaseMessageValidator impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1302.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1302.java new file mode 100644 index 000000000..5f30493ef --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1302.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.profile.validator.impl.envelope.BP1302; + +/** + * WSI1302 + */ +public class WSI1302 extends BP1302 +{ + + /** + * @param BaseMessageValidator + */ + public WSI1302(BaseMessageValidator impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1305.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1305.java new file mode 100644 index 000000000..72f0684db --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1305.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.profile.validator.impl.envelope.BP1305; + +/** + * WSI1305 + */ +public class WSI1305 extends BP1305 +{ + + /** + * @param BaseMessageValidator + */ + public WSI1305(BaseMessageValidator impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1306.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1306.java new file mode 100644 index 000000000..389cd964f --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1306.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.profile.validator.impl.envelope.BP1306; + +/** + * WSI1306 + */ +public class WSI1306 extends BP1306 +{ + + /** + * @param BaseMessageValidator + */ + public WSI1306(BaseMessageValidator impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1307.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1307.java new file mode 100644 index 000000000..e900b6a5b --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1307.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.profile.validator.impl.envelope.BP1307; + +/** + * WSI1307 + */ +public class WSI1307 extends BP1307 +{ + + /** + * @param BaseMessageValidator + */ + public WSI1307(BaseMessageValidator impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1308.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1308.java new file mode 100644 index 000000000..e41b290ff --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1308.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.profile.validator.impl.envelope.BP1308; + +/** + * WSI1308 + */ +public class WSI1308 extends BP1308 +{ + + /** + * @param BaseMessageValidator + */ + public WSI1308(BaseMessageValidator impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1309.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1309.java new file mode 100644 index 000000000..36d599010 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1309.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.profile.validator.impl.envelope.BP1309; + +/** + * WSI1309 + */ +public class WSI1309 extends BP1309 +{ + + /** + * @param BaseMessageValidator + */ + public WSI1309(BaseMessageValidator impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1311.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1311.java new file mode 100644 index 000000000..30d403155 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1311.java @@ -0,0 +1,204 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import java.util.Iterator; +import java.util.List; + +import javax.wsdl.Binding; +import javax.wsdl.BindingOperation; +import javax.wsdl.Message; +import javax.wsdl.Operation; +import javax.wsdl.extensions.soap.SOAPBinding; +import javax.xml.namespace.QName; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionFailException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionPassException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.HTTPUtils; +import org.eclipse.wst.wsi.internal.util.OperationSignature; +import org.eclipse.wst.wsi.internal.util.TypesRegistry; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + + +/** + * BPWSI4. + * The response (SOAP envelope) should be carried by an HTTP + * response, over same HTTP connection as the Request. + */ +public class WSI1311 extends AssertionProcess +{ + private final BaseMessageValidator validator; + + /** + * @param BaseMessageValidator + */ + public WSI1311(BaseMessageValidator impl) + { + super(impl); + this.validator = impl; + } + + /** + * @see org.eclipse.wst.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(TestAssertion, EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + + result = AssertionResult.RESULT_PASSED; + boolean isOneWayResponse = this.validator.isOneWayResponse(entryContext); + + Document docResponse = null; + if (!isOneWayResponse) + docResponse = entryContext.getResponseDocument(); + + //if fault + if (!isOneWayResponse && this.validator.isFault(docResponse)) + { + result = AssertionResult.RESULT_PASSED; + } + else + { // not fault + // 1. get an operation from request + // Parse request message + Document docRequest = entryContext.getRequestDocument(); + + // get SOAPAction + String headers = entryContext.getRequest().getHTTPHeaders(); + String action = null; + if (headers != null) + action = (String) HTTPUtils.getHttpHeaderTokens(headers, ":").get("SOAPAction".toUpperCase()); + Binding binding = validator.analyzerContext.getCandidateInfo().getBindings()[0]; + TypesRegistry registry = + new TypesRegistry( + this.validator.getWSDLDocument().getDefinitions(), + validator); + OperationSignature.OperationMatch match = + OperationSignature.matchOperation( + docRequest, + action, + binding, + registry); + + if (match == null) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + else + { + try + { + + BindingOperation bindingOperation = match.getOperation(); + Operation operation = null; + + // Check whether the transport attribute has the value + // "http://schemas.xmlsoap.org/soap/http". + List extElem = binding.getExtensibilityElements(); + for (Iterator index = extElem.iterator(); index.hasNext();) + { + Object o = (Object) index.next(); + if (o instanceof SOAPBinding) + { + SOAPBinding soapBinding = (SOAPBinding) o; + if (!WSIConstants + .NS_URI_SOAP_HTTP + .equals(soapBinding.getTransportURI())) + { + throw new AssertionFailException(); + } + + } + } + + //find operation in port type + operation = bindingOperation.getOperation(); + if (operation == null) + { + throw new AssertionFailException(); + } + + if (isOneWayResponse) + { + if (operation.getOutput() == null) + throw new AssertionPassException(); + else + throw new AssertionFailException(); + } + + // check whether the response message from the log + // contains the output message + NodeList soapBodyList = + docResponse.getElementsByTagNameNS( + WSIConstants.NS_URI_SOAP, + XMLUtils.SOAP_ELEM_BODY); + if ((soapBodyList == null) || (soapBodyList.getLength() == 0)) + { + // Response does not contain any soap Body elements + throw new AssertionFailException(); + } + for (int i = 0; i < soapBodyList.getLength(); i++) + { + Element nextBodyElem = (Element) soapBodyList.item(i); + Element soapMessageElement = XMLUtils.getFirstChild(nextBodyElem); + while (soapMessageElement != null) + { + // check whether the operation output has message from SOAP response + Message message = operation.getOutput().getMessage(); + QName soapMessageQName = + new QName( + soapMessageElement.getNamespaceURI(), + soapMessageElement.getLocalName()); + + if (message != null + && soapMessageQName.equals(message.getQName())) + { + throw new AssertionPassException(); + } + + soapMessageElement = + XMLUtils.getNextSibling(soapMessageElement); + } + } + + } + catch (AssertionPassException e) + { + result = AssertionResult.RESULT_PASSED; + } + catch (AssertionFailException e) + { + result = AssertionResult.RESULT_FAILED; + } + + } + } + + if (result == AssertionResult.RESULT_FAILED) + { + failureDetail = this.validator.createFailureDetail(null, entryContext); + } + + return validator.createAssertionResult(testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1316.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1316.java new file mode 100644 index 000000000..60da45bf6 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1316.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.profile.validator.impl.envelope.BP1316; + +/** + * WSI1316 + */ +public class WSI1316 extends BP1316 +{ + + /** + * @param BaseMessageValidator + */ + public WSI1316(BaseMessageValidator impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1318.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1318.java new file mode 100644 index 000000000..90b951e25 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1318.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.profile.validator.impl.envelope.BP1318; + +/** + * WSI1318 + */ +public class WSI1318 extends BP1318 +{ + + /** + * @param BaseMessageValidator + */ + public WSI1318(BaseMessageValidator impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1601.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1601.java new file mode 100644 index 000000000..69d110709 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1601.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.profile.validator.impl.envelope.BP1601; + +/** + * WSI1601 + */ +public class WSI1601 extends BP1601 +{ + + /** + * @param BaseMessageValidator + */ + public WSI1601(BaseMessageValidator impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1701.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1701.java new file mode 100644 index 000000000..8aed3c0a2 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI1701.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.profile.validator.impl.envelope.BP1701; + +/** + * WSI1701 + */ +public class WSI1701 extends BP1701 +{ + + /** + * @param BaseMessageValidator + */ + public WSI1701(BaseMessageValidator impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI4100.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI4100.java new file mode 100644 index 000000000..7dfda3c4f --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI4100.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.profile.validator.impl.envelope.BP4100; + +/** + * WSI4100 + */ +public class WSI4100 extends BP4100 +{ + + /** + * @param BaseMessageValidator + */ + public WSI4100(BaseMessageValidator impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI4101.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI4101.java new file mode 100644 index 000000000..11af4760c --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI4101.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.profile.validator.impl.envelope.BP4101; + +/** + * WSI4101 + */ +public class WSI4101 extends BP4101 +{ + + /** + * @param BaseMessageValidator + */ + public WSI4101(BaseMessageValidator impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI4102.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI4102.java new file mode 100644 index 000000000..691af49e5 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI4102.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; +import org.eclipse.wst.wsi.internal.profile.validator.impl.envelope.BP4102; + +/** + * WSI4102 + */ +public class WSI4102 extends BP4102 +{ + + /** + * @param BaseMessageValidator + */ + public WSI4102(BaseMessageValidator impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI4103.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI4103.java new file mode 100644 index 000000000..44f4de30d --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI4103.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; + +/** + * WSI4103 + */ +public class WSI4103 extends BP4103 +{ + + /** + * @param BaseMessageValidator + */ + public WSI4103(BaseMessageValidator impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI4104.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI4104.java new file mode 100644 index 000000000..9b061b32b --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI4104.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; + +/** + * WSI4104 + */ +public class WSI4104 extends BP4104 +{ + + /** + * @param BaseMessageValidator + */ + public WSI4104(BaseMessageValidator impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI4105.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI4105.java new file mode 100644 index 000000000..8d05de86c --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI4105.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; + +/** + * WSI4105 + */ +public class WSI4105 extends BP4105 +{ + + /** + * @param BaseMessageValidator + */ + public WSI4105(BaseMessageValidator impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI4106.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI4106.java new file mode 100644 index 000000000..99ffa992f --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI4106.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; + +/** + * WSI4106 + */ +public class WSI4106 extends BP4106 +{ + + /** + * @param BaseMessageValidator + */ + public WSI4106(BaseMessageValidator impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI4107.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI4107.java new file mode 100644 index 000000000..e530407a0 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/message/WSI4107.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.message; + +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseMessageValidator; + +/** + * WSI4107 + */ +public class WSI4107 extends BP4107 +{ + + /** + * @param BaseMessageValidator + */ + public WSI4107(BaseMessageValidator impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/uddi/BP3001.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/uddi/BP3001.java new file mode 100644 index 000000000..7f8db4229 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/uddi/BP3001.java @@ -0,0 +1,160 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.uddi; + +import java.util.Map; + +import javax.wsdl.Binding; +import javax.wsdl.Definition; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.wsdl.WSDLDocument; +import org.uddi4j.datatype.OverviewDoc; +import org.uddi4j.datatype.tmodel.TModel; + + +/** + * BP3001 - The tModel element uses WSDL as the description language: + * the uddi:overviewDoc/uddi:overviewURL element contains a reference + * to a WSDL definition, which uses a namespace + * of http://schemas.xmlsoap.org/wsdl/. + * The uddi:overviewURL may use the fragment notation to resolve + * to a wsdl:binding. + */ +public class BP3001 extends AssertionProcess +{ + private final UDDIValidatorImpl validator; + + /** + * @param UDDIValidatorImpl + */ + public BP3001(UDDIValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + /** + * Sets the result variable to AssertionResult.RESULT_FAILED value and + * places a tModel key in the fault detail message. + * @param tModelKey + */ + private void setFaultMessage(String tModelKey) + { + result = AssertionResult.RESULT_FAILED; + failureDetailMessage = "The tModel key is: [" + tModelKey + "]."; + } + + /** + * Validates the test assertion. + * @see org.eclipse.wst.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + result = AssertionResult.RESULT_PASSED; + + Binding binding = null; + + // Get the tModel from the entryContext + TModel tModel = (TModel) entryContext.getEntry().getEntryDetail(); + + // If the tModel does not exist, then fail + if (tModel == null) + { + result = AssertionResult.RESULT_FAILED; + failureDetailMessage = "Could not locate a tModel."; + return validator.createAssertionResult( + testAssertion, + result, + failureDetailMessage); + } + + String key = tModel.getTModelKey(); + + OverviewDoc doc = tModel.getOverviewDoc(); + if (doc != null) + { + String urlText = doc.getOverviewURLString(); + + // Try to resolve the URL & check the WSDL + try + { + WSDLDocument wsdlDocument = new WSDLDocument(urlText); + Definition definition = wsdlDocument.getDefinitions(); + Map namespaces = definition.getNamespaces(); + if (!namespaces.containsValue(WSIConstants.NS_URI_WSDL)) + { + urlText = null; + } + + // Get binding + binding = validator.getBinding(urlText, wsdlDocument); + + // See if the binding is in the WSDL document + if (binding == null + || definition.getBinding(binding.getQName()) == null) + { + urlText = null; + } + } + + catch (Exception e) + { + urlText = null; + } + + if (urlText != null) + { + String fragmentID = null; + int index = urlText.indexOf("#"); + if (index > -1) + { + fragmentID = urlText.substring(index + 1); + } + + if ((fragmentID != null) + && (fragmentID.length() != 0) + && (fragmentID.toUpperCase().indexOf("xpointer(".toUpperCase()) == -1 + || fragmentID.lastIndexOf(")") != fragmentID.length() - 1)) + { + setFaultMessage(key); + } + } + + else + { + setFaultMessage(key); + } + } + + else + { + setFaultMessage(key); + } + + if (result == AssertionResult.RESULT_PASSED) + { + // Set the binding that will be used + validator.setWSDLBinding(binding); + } + + // Return assertion result + return validator.createAssertionResult(testAssertion, result, failureDetailMessage); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/uddi/BP3002.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/uddi/BP3002.java new file mode 100644 index 000000000..fb536d989 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/uddi/BP3002.java @@ -0,0 +1,81 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.uddi; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.uddi4j.datatype.binding.BindingTemplate; + + +/** + * BP3002 - The uddi:bindingTemplate element contains a uddi:accessPoint element, + * with a non-empty value. + */ +public class BP3002 extends AssertionProcess +{ + private final UDDIValidatorImpl validator; + + /** + * @param UDDIValidatorImpl + */ + public BP3002(UDDIValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + /** + * Validates the test assertion. + * @see org.eclipse.wst.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + String serviceLocation = null; + + result = AssertionResult.RESULT_PASSED; + + // Get the bindingTemplate from the entryContext + BindingTemplate bindingTemplate = + (BindingTemplate) entryContext.getEntry().getEntryDetail(); + + // If the bindingTemplate does not contain an accessPoint, then fail + if ((bindingTemplate.getAccessPoint() == null) + || ((serviceLocation = bindingTemplate.getAccessPoint().getText()) + == null)) + { + result = AssertionResult.RESULT_FAILED; + failureDetailMessage = + "The bindingTempate key is: [" + + bindingTemplate.getBindingKey() + + "]."; + } + + // Else save the service location in the assertion result + else + { + // Save service location in analyzer context + entryContext + .getAnalyzerContext() + .getServiceReference() + .setServiceLocation( + serviceLocation); + } + + // Return assertion result + return validator.createAssertionResult(testAssertion, result, failureDetailMessage); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/uddi/BP3003.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/uddi/BP3003.java new file mode 100644 index 000000000..1fde9b18a --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/uddi/BP3003.java @@ -0,0 +1,84 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.uddi; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.uddi4j.datatype.tmodel.TModel; + + +/** + * BP3003 - The uddi:tModel is categorized using the uddi:types taxonomy, + * as "wsdlSpec": the uddi:keyedReference element has an attribute keyValue + * equal to "wsdlSpec", and keyName equal to "uddi-org:types" or "types". + */ +public class BP3003 extends AssertionProcess +{ + private final UDDIValidatorImpl validator; + + /** + * @param UDDIValidatorImpl + */ + public BP3003(UDDIValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + /** + * Validates the test assertion. + * @see org.eclipse.wst.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + result = AssertionResult.RESULT_PASSED; + + // Get the tModel from the entryContext + TModel tModel = (TModel) entryContext.getEntry().getEntryDetail(); + + // If the tModel does not exist, then fail + if (tModel == null) + { + result = AssertionResult.RESULT_FAILED; + failureDetailMessage = + "Could not locate a tModel with a categorization of 'wsdlSpec'."; + } + + // If there is a tModel and it is not categorized as "wsdlSpec", then fail + else if (!(validator.isWsdlSpec(tModel))) + { + result = AssertionResult.RESULT_FAILED; + failureDetailMessage = + "The tModel key is: [" + + tModel.getTModelKey() + + "]\n" + + "The categoryBag is: [" + + this.validator.categoryBagToString(tModel.getCategoryBag()) + + "]"; + } + + // Else get the WSDL document location and set it and the binding element in analyzer context + else + { + // set WSDL location in analyzer context + validator.setWSDLLocation(validator.getWSDLLocation(validator.getOverviewURL(tModel))); + } + + // Return assertion result + return validator.createAssertionResult(testAssertion, result, failureDetailMessage); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/uddi/UDDIValidatorImpl.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/uddi/UDDIValidatorImpl.java new file mode 100644 index 000000000..2178a8029 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/uddi/UDDIValidatorImpl.java @@ -0,0 +1,594 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.uddi; + +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.UnknownHostException; +import java.util.Iterator; +import java.util.Vector; + +import javax.wsdl.Binding; +import javax.wsdl.*; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.analyzer.AnalyzerContext; +import org.eclipse.wst.wsi.internal.analyzer.ServiceReference; +import org.eclipse.wst.wsi.internal.analyzer.config.UDDIReference; +import org.eclipse.wst.wsi.internal.analyzer.config.WSDLElement; +import org.eclipse.wst.wsi.internal.analyzer.config.impl.WSDLElementImpl; +import org.eclipse.wst.wsi.internal.profile.ProfileArtifact; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.UDDIValidator; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseValidatorImpl; +import org.eclipse.wst.wsi.internal.report.Entry; +import org.eclipse.wst.wsi.internal.report.ReportArtifact; +import org.eclipse.wst.wsi.internal.report.Reporter; +import org.eclipse.wst.wsi.internal.util.EntryType; +import org.eclipse.wst.wsi.internal.util.UDDIUtils; +import org.eclipse.wst.wsi.internal.wsdl.WSDLDocument; +import org.uddi4j.client.UDDIProxy; +import org.uddi4j.datatype.binding.BindingTemplate; +import org.uddi4j.datatype.binding.TModelInstanceInfo; +import org.uddi4j.datatype.tmodel.TModel; +import org.uddi4j.response.BindingDetail; +import org.uddi4j.response.TModelDetail; +import org.uddi4j.util.CategoryBag; +import org.uddi4j.util.KeyedReference; +import com.ibm.wsdl.util.StringUtils; + +/** + * The UDDI validator will verify that a web service description was published correctly in a UDDI registry. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public class UDDIValidatorImpl + extends BaseValidatorImpl + implements UDDIValidator +{ + /** + * UDDI reference. + */ + protected UDDIReference uddiReference; + /** + * UDDI proxy. + */ + protected UDDIProxy uddiProxy; + + /** + * WSDL binding. + */ + private Binding binding = null; + + /* (non-Javadoc) + * @see org.wsi.test.profile.validator.UDDIValidator#init(org.wsi.test.analyzer.AnalyzerContext, org.wsi.test.profile.ProfileArtifact, org.wsi.test.report.ReportArtifact, org.wsi.test.analyzer.config.UDDIReference, org.wsi.test.report.Reporter) + */ + public void init( + AnalyzerContext analyzerContext, + ProfileArtifact profileArtifact, + ReportArtifact reportArtifact, + UDDIReference uddiReference, + Reporter reporter) + throws WSIException + { + // BaseValidatorImpl + super.init(analyzerContext, profileArtifact, reportArtifact, reporter); + + // Save input references + this.uddiReference = uddiReference; + } + + /* (non-Javadoc) + * @see org.wsi.test.profile.validator.UDDIValidator#validate() + */ + public String validate() throws WSIException + { + String wsdlURL = null; + Entry entry = null; + + BindingTemplate bindingTemplate = null; + TModel tModel = null; + + // it depricated after refactoring + // now the inner classes moved out from validator + //String classPrefix = this.getClass().getName() + "$"; + String classPrefix = this.getClass().getPackage().getName()+"."; + + try + { + // Set up a reference to the UDDI registry + uddiProxy = new UDDIProxy(); + + //new Socket(new InetAddress(uddiReference.getInquiryURL())); + uddiProxy.setInquiryURL(uddiReference.getInquiryURL()); + boolean wasEx = false; + InputStream stream; + try + { + URL url = StringUtils.getURL(null, uddiReference.getInquiryURL()); + stream = url.openStream(); + stream.close(); + } + + catch (UnknownHostException ex) + { + wasEx = true; + } + + catch (IOException ex) + { + } + + if (!wasEx) + { + + // If the UDDI reference is to a bindingTemplate then get it + if (uddiReference.getKeyType().equals(UDDIReference.BINDING_KEY)) + { + // Get binding detail which will contain the bindingTemplate + BindingDetail bindingDetail = + uddiProxy.get_bindingDetail(uddiReference.getKey()); + + // Get bindingTemplate + bindingTemplate = + (BindingTemplate) bindingDetail + .getBindingTemplateVector() + .elementAt( + 0); + + if (verboseOption) + { + System.err.println( + " BindingTemplate - " + + UDDIUtils.bindingTemplateToString(bindingTemplate)); + } + + // Get the wsdlSpec tModel + tModel = findTModel(uddiProxy, bindingTemplate); + } + + // Else it has to be a tModel + else + { + TModelDetail tModelDetail = + uddiProxy.get_tModelDetail(uddiReference.getKey()); + tModel = (TModel) tModelDetail.getTModelVector().elementAt(0); + } + + if (verboseOption) + { + System.err.println( + " TModel specified or found in bindingTemplate - " + + UDDIUtils.tModelToString(tModel)); + } + } + + if (bindingTemplate == null) + { + setMissingInput( + EntryType.getEntryType(EntryType.TYPE_DISCOVERY_BINDINGTEMPLATE)); + } + + // If there is a bindingTemplate, then process test assertions for it + else + { + // Create entry + entry = this.reporter.getReport().createEntry(); + entry.setEntryType( + EntryType.getEntryType(EntryType.TYPE_DISCOVERY_BINDINGTEMPLATE)); + entry.setReferenceID(bindingTemplate.getBindingKey()); + entry.setEntryDetail(bindingTemplate); + + // Process test assertions + processAssertions( + classPrefix, + new EntryContext(entry, this.analyzerContext)); + } + + // NOTE: From this point forward, if a bindingTemplate does NOT have a wsdlSpec tModel, + // the tModel will be NULL. + + //Parse WSDL document, and get WSDL document url, binding name and namespace + try + { + String overviewURL = getOverviewURL(tModel); + wsdlURL = getWSDLLocation(overviewURL); + WSDLDocument wsdlDocument = getWSDLDocument(wsdlURL); + + // ADD: The WSDL binding is used in WSI3001 and should be moved to the entryContext + binding = getBinding(overviewURL, wsdlDocument); + } + + catch (Exception e) + { + // ADD: + if (verboseOption) + { + System.err.println(" EXCEPTION: " + e.toString()); + } + } + + // Create entry + entry = this.reporter.getReport().createEntry(); + entry.setEntryType( + EntryType.getEntryType(EntryType.TYPE_DISCOVERY_TMODEL)); + entry.setReferenceID( + (tModel == null ? "[tModel]" : tModel.getTModelKey())); + entry.setEntryDetail(tModel); + + // Process test assertions + processAssertions( + classPrefix, + new EntryContext(entry, this.analyzerContext)); + } + + catch (Exception e) + { + // Throw WSIException + if (e instanceof WSIException) + throw (WSIException) e; + else + throw new WSIException( + "An exception occurred while processing the discovery test assertions.", + e); + } + + // Cleanup + cleanup(); + + // Get WSDL location + wsdlURL = this.analyzerContext.getServiceReference().getWSDLLocation(); + + // Return WSDL URL + return wsdlURL; + } + + /** + * Set WSDL binding in the service reference portion of the analyzer context. + */ + protected void setWSDLBinding(Binding binding) + { + String bindingName = + binding == null ? null : binding.getQName().getLocalPart(); + String namespace = + binding == null ? null : binding.getQName().getNamespaceURI(); + + // Set the WSDL document location in analyzerContext + ServiceReference serviceReference = + this.analyzerContext.getServiceReference(); + + // If the wsdlElement does not exist, then set it + WSDLElement wsdlElement; + if ((wsdlElement = serviceReference.getWSDLElement()) == null) + { + // Get the WSDL binding from the overviewURL and set in analyzerContext + wsdlElement = new WSDLElementImpl(); + wsdlElement.setName(bindingName); + wsdlElement.setNamespace(namespace); + wsdlElement.setType(EntryType.TYPE_DESCRIPTION_BINDING); + } + + // Set the wsdlElement in the service reference + serviceReference.setWSDLElement(wsdlElement); + + // Set the service reference back into the analyzerContext + analyzerContext.setServiceReference(serviceReference); + } + + /** + * Set the WSDL location in the service reference portion of the analyzer context. + */ + protected void setWSDLLocation(String wsdlURL) + { + // Set the WSDL document location in analyzerContext + ServiceReference serviceReference = + this.analyzerContext.getServiceReference(); + serviceReference.setWSDLLocation(wsdlURL); + + // Set the service reference back into the analyzerContext + analyzerContext.setServiceReference(serviceReference); + } + + /** + * Find the wsdlSpec tModel associated with a binding. + */ + private TModel findTModel( + UDDIProxy uddiProxy, + BindingTemplate bindingTemplate) + throws WSIException + { + TModel tModel = null; + + // Get the list of tModel references associated with this bindingTemplate + Iterator iterator = + bindingTemplate + .getTModelInstanceDetails() + .getTModelInstanceInfoVector() + .iterator(); + + // Process each tModel reference + Vector tModelKeyList = new Vector(); + while (iterator.hasNext()) + { + // Get tModelInstanceInfo + TModelInstanceInfo tModelInstanceInfo = + (TModelInstanceInfo) iterator.next(); + + // Add key to list + tModelKeyList.add(tModelInstanceInfo.getTModelKey()); + } + + // Get the tModels associated with the bindingTemplate + if (tModelKeyList.size() > 0) + { + try + { + // Get the tModel details + TModelDetail tModelDetail = uddiProxy.get_tModelDetail(tModelKeyList); + + // Get the list of tModels + Iterator tModelIterator = tModelDetail.getTModelVector().iterator(); + + //boolean tModelFound = false; + TModel nextTModel = null; + + // Go through the list of tModels + while ((tModelIterator.hasNext()) && (tModel == null)) + { + // Get next tModel in list + nextTModel = (TModel) tModelIterator.next(); + + if (verboseOption) + { + System.err.println( + " TModel referenced from bindingTemplate - " + + UDDIUtils.tModelToString(nextTModel)); + } + + // If this is a wsdlSpec tModel, then this is the tModel we want + if (isWsdlSpec(nextTModel)) + tModel = nextTModel; + } + } + + catch (Exception e) + { + // Throw WSIException + throw new WSIException("Could not get tModel details.", e); + } + } + + else + { + // Throw exception + //throw new WSIException("UDDI bindingTemplate did not contain any tModel references."); + } + + return tModel; + } + + /** + * Determine if this is a wsdlSpec tModel. + */ + protected boolean isWsdlSpec(TModel tModel) + { + boolean tModelFound = false; + CategoryBag categoryBag = null; + Iterator categoryBagIterator = null; + + // Determine if the catetgoryBag contains wsdlSpec + if ((categoryBag = tModel.getCategoryBag()) != null) + { + // Get the list of keyed references + categoryBagIterator = categoryBag.getKeyedReferenceVector().iterator(); + + KeyedReference keyedReference = null; + + // Go through the list of keyed references + while (categoryBagIterator.hasNext() && !(tModelFound)) + { + // Get next keyed reference + keyedReference = (KeyedReference) categoryBagIterator.next(); + + // If this is a types taxonomy tModel and the value is wsdlSpec, then this is the tModel we want + // REMOVE: It is not necessary to check the key name + //if (keyedReference.getTModelKey().equalsIgnoreCase(TModel.TYPES_TMODEL_KEY) && + // "wsdlSpec".equals(keyedReference.getKeyValue()) && + // ("types".equals(keyedReference.getKeyName()) || + // "uddi-org:types".equals(keyedReference.getKeyName()))) { + // tModelFound = true; + //} + if (keyedReference + .getTModelKey() + .equalsIgnoreCase(TModel.TYPES_TMODEL_KEY) + && "wsdlSpec".equals(keyedReference.getKeyValue())) + { + tModelFound = true; + } + } + } + + return tModelFound; + } + + /** + * Get an OverviewURL from tModel. + */ + protected String getOverviewURL(TModel tModel) + { + if (tModel != null + && tModel.getOverviewDoc() != null + && tModel.getOverviewDoc().getOverviewURL() != null) + { + return tModel.getOverviewDoc().getOverviewURL().getText(); + } + return null; + } + + /** + * Get WSDL document. + */ + protected String getWSDLLocation(String wsdlLocation) + { + int index; + + // Check if the overviewURL contains a fragment identifier + if ((index = wsdlLocation.indexOf("#")) > -1) + { + wsdlLocation = wsdlLocation.substring(0, index); + } + return wsdlLocation; + } + + /** + * Get WSDL document. + */ + protected WSDLDocument getWSDLDocument(String wsdlLocation) + throws MalformedURLException, WSDLException + { + return new WSDLDocument(getWSDLLocation(wsdlLocation)); + } + + /** + * Get WSDL binding from the overviewURL in the tModel. + */ + protected Binding getBinding(String overviewURL, WSDLDocument wsdlDocument) + { + int index; + int nameIndex; + + Binding[] bindings = wsdlDocument.getBindings(); + if (bindings == null || bindings.length == 0) + return null; + + if (overviewURL != null) + { + // Check if the overviewURL contains a fragment identifier + if ((index = overviewURL.indexOf("#")) > -1) + { + // TEMP: Need to use a real XPath evaluator like Xalan + String nameAttribute = "@name="; + + // Locate name reference + if ((nameIndex = + overviewURL.substring(index + 1).indexOf(nameAttribute)) + > -1) + { + // Get the next character which should be a quote + int firstQuoteIndex = index + 1 + nameIndex + nameAttribute.length(); + String quote = + overviewURL.substring(firstQuoteIndex, firstQuoteIndex + 1); + + // Get the part of the URL which should contain the binding name + String urlPart = overviewURL.substring(firstQuoteIndex + 1); + + // Find the next quote + int nextQuoteIndex; + if ((nextQuoteIndex = urlPart.indexOf(quote)) > -1) + { + String bindingName = urlPart.substring(0, nextQuoteIndex); + //look for binding with the specified name + for (int i = 0; i < bindings.length; i++) + { + if (bindingName.equals(bindings[i].getQName().getLocalPart())) + return bindings[i]; + } + } + } + } + } + + return bindings[0]; + } + + /** + * Get string representation of categoryBag. + * @param categoryBag a CategoryBag object. + * @return string representation of categoryBag. + */ + protected String categoryBagToString(CategoryBag categoryBag) + { + String toString = ""; + + if (categoryBag != null) + { + Vector keyedReferenceList = null; + if (((keyedReferenceList = categoryBag.getKeyedReferenceVector()) + == null) + || (keyedReferenceList.size() == 0)) + { + toString += "No KeyedReferences"; + } + + else + { + int count = 1; + KeyedReference keyedReference; + Iterator iterator = keyedReferenceList.iterator(); + while (iterator.hasNext()) + { + keyedReference = (KeyedReference) iterator.next(); + toString += "\n [" + + count++ + + "] tModelKey: " + + keyedReference.getTModelKey() + + ", keyName: " + + keyedReference.getKeyName() + + ", keyValue: " + + keyedReference.getKeyValue(); + } + } + } + else + { + toString = "null"; + } + + return toString; + } + + /* (non-Javadoc) + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl#isPrimaryEntryTypeMatch(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + protected boolean isPrimaryEntryTypeMatch( + TestAssertion testAssertion, + EntryContext targetContext) + { + boolean match = false; + + // If the test assertion entry type matches the target context entry type, then contine + if (testAssertion + .getEntryTypeName() + .equals(targetContext.getEntry().getEntryType().getTypeName())) + { + match = true; + } + + return match; + } + + /* (non-Javadoc) + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl#isNotApplicable(org.wsi.test.profile.TestAssertion) + */ + protected boolean isNotApplicable(TestAssertion testAssertion) + { + boolean notApplicable = false; + + // ADD: + + return notApplicable; + } + +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/uddi/WSI3001.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/uddi/WSI3001.java new file mode 100644 index 000000000..e259842ad --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/uddi/WSI3001.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.uddi; + +/** + * WSI3001 + */ +public class WSI3001 extends BP3001 +{ + + /** + * @param UDDIValidatorImpl + */ + public WSI3001(UDDIValidatorImpl impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/uddi/WSI3002.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/uddi/WSI3002.java new file mode 100644 index 000000000..4f464684c --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/uddi/WSI3002.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.uddi; + +/** + * WSI3002 + */ +public class WSI3002 extends BP3002 +{ + + /** + * @param UDDIValidatorImpl + */ + public WSI3002(UDDIValidatorImpl impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/uddi/WSI3003.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/uddi/WSI3003.java new file mode 100644 index 000000000..18c8624c4 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/uddi/WSI3003.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.uddi; + +/** + * WSI3003 + */ +public class WSI3003 extends BP3003 +{ + + /** + * @param UDDIValidatorImpl + */ + public WSI3003(UDDIValidatorImpl impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/uddi/WSI3004.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/uddi/WSI3004.java new file mode 100644 index 000000000..3aa3c350a --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/uddi/WSI3004.java @@ -0,0 +1,290 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.uddi; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Map; +import java.util.Vector; + +import javax.wsdl.Binding; +import javax.wsdl.Port; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.WSITag; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcessVisitor; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.UDDIUtils; +import org.eclipse.wst.wsi.internal.wsdl.WSDLDocument; +import org.eclipse.wst.wsi.internal.wsdl.traversal.WSDLTraversal; +import org.eclipse.wst.wsi.internal.wsdl.traversal.WSDLTraversalContext; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; +import org.uddi4j.datatype.tmodel.TModel; +import org.uddi4j.util.CategoryBag; +import org.uddi4j.util.KeyedReference; +import org.w3c.dom.Element; + + +/** + * WSI3004 - The conformance claims in the uddi:tModel are the same + * as those in the wsdl:binding which is referenced by the uddi:tModel. + */ +public class WSI3004 extends AssertionProcessVisitor implements WSITag +{ + private final UDDIValidatorImpl validator; + + /** + * @param UDDIValidatorImpl + */ + public WSI3004(UDDIValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + private static final String PORTS_PARAM = "ports"; + private static final String BINDING_PARAM = "binding"; + + /** + * Gets WSI conformance claims from a tModel. + * @param tModel + * @return HashSet + * @throws WSIException + */ + private HashSet getConformanceClaimsFromUDDI(TModel tModel) + throws WSIException + { + String conformanceKey = UDDIUtils.getWSIConformanceTModelKey(validator.uddiProxy); + + HashSet result = new HashSet(); + + CategoryBag bag = tModel.getCategoryBag(); + if (bag != null) + { + Vector references = bag.getKeyedReferenceVector(); + for (int i = 0; i < references.size(); i++) + { + KeyedReference ref = (KeyedReference) references.get(i); + + if (ref.getTModelKey().equalsIgnoreCase(conformanceKey)) + { + result.add(ref.getKeyValue()); + } + } + } + + return result; + } + + /** + * Gets WSI conformance claims from WSDL binding + * that references specified tModel. Additionally, + * WSDL ports, which uses the binding, are processed. + * + * @param tModel + * @return HashSet + */ + private HashSet getConformanceClaimsFromWSDL(TModel tModel) + { + HashSet result = new HashSet(); + + try + { + // Read the WSDL document + String overviewURL = validator.getOverviewURL(tModel); + WSDLDocument wsdlDocument = validator.getWSDLDocument(overviewURL); + + // Get binding + Binding binding = validator.getBinding(overviewURL, wsdlDocument); + String bindingName = binding.getQName().getLocalPart(); + + // Get claims + result = + getClaimsFromElement(binding.getDocumentationElement(), result); + + // Get ports, which reference this binding, because: + // "A claim on a wsdl:port is inherited by the referenced wsdl:bindings." + Vector ports = getPorts(wsdlDocument, bindingName); + for (int i = 0; i < ports.size(); i++) + { + Port port = (Port) ports.get(i); + + result = getClaimsFromElement(port.getDocumentationElement(), result); + } + } + catch (Exception e) + { + // ADD: + } + + return result; + } + + /** + * Gets WSI conformance claims from the 'documentation' XML element + * and puts them into the HashSet. + * @param docElement + * @param result + * @return HashSet + */ + private HashSet getClaimsFromElement(Element docElement, HashSet result) + { + if (result == null) + { + result = new HashSet(); + } + + if (docElement != null) + { + Element claimElement = XMLUtils.findChildElement(docElement, WSI_CLAIM); + while (claimElement != null) + { + /* + Node attr = XMLUtils.getAttribute(claimElement, ATTR_CLAIM_CONFORMSTO); + if (attr != null) + result.add(attr.getNodeValue()); + */ + String value = + claimElement.getAttribute(ATTR_CLAIM_CONFORMSTO.getLocalPart()); + if (value != null) + result.add(value); + + claimElement = XMLUtils.findElement(claimElement, WSI_CLAIM); + } + } + + return result; + } + + /** + * Gets wsdl:ports, which use specified binding. + * @param wsdlDocument + * @param bindingName + * @return Vector + */ + private Vector getPorts(WSDLDocument wsdlDocument, String bindingName) + { + Vector ports = new Vector(); + + Map params = new HashMap(); + params.put(PORTS_PARAM, ports); + params.put(BINDING_PARAM, bindingName); + + WSDLTraversal traversal = new WSDLTraversal(); + //VisitorAdaptor.adapt(this); + traversal.setVisitor(this); + traversal.visitPort(true); + traversal.ignoreReferences(); + traversal.ignoreImport(); + traversal.traverse(wsdlDocument.getDefinitions(), params); + + return ports; + } + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.Port, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit(Port port, Object parent, WSDLTraversalContext ctx) + { + if (port + .getBinding() + .getQName() + .getLocalPart() + .equals(ctx.getParameter(BINDING_PARAM).toString())) + { + ((Vector) ctx.getParameter(PORTS_PARAM)).add(port); + } + } + + /* (non-Javadoc) + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + result = AssertionResult.RESULT_PASSED; + + // Get the tModel from the entryContext + TModel tModel = (TModel) entryContext.getEntry().getEntryDetail(); + + // If the tModel does not exist, then fail + if (tModel == null) + { + result = AssertionResult.RESULT_FAILED; + failureDetailMessage = "Could not locate a tModel."; + } + + // If there is a tModel + else + { + try + { + HashSet claimsFromUDDI = getConformanceClaimsFromUDDI(tModel); + HashSet claimsFromWSDL = getConformanceClaimsFromWSDL(tModel); + + if (claimsFromUDDI.size() == 0) + { + result = AssertionResult.RESULT_PASSED; + } + else if (claimsFromUDDI.size() == claimsFromWSDL.size()) + { + int counter = 0; + for (Iterator iter = claimsFromWSDL.iterator(); iter.hasNext();) + { + String claim = (String) iter.next(); + + for (Iterator iter2 = claimsFromUDDI.iterator(); + iter2.hasNext(); + ) + { + String uddiClaim = (String) iter2.next(); + if (claim.equalsIgnoreCase(uddiClaim)) + { + counter++; + break; + } + } + } + + if (counter != claimsFromWSDL.size()) + { + // failed + result = AssertionResult.RESULT_FAILED; + failureDetailMessage = + "The tModel key is: [" + tModel.getTModelKey() + "]."; + } + } + else + { + // failed + result = AssertionResult.RESULT_FAILED; + failureDetailMessage = + "The tModel key is: [" + tModel.getTModelKey() + "]."; + } + } + catch (IllegalStateException e) + { + result = AssertionResult.RESULT_FAILED; + failureDetailMessage = + "The tModel key is: [" + tModel.getTModelKey() + "]."; + } + + } + + // Return assertion result + return validator.createAssertionResult(testAssertion, result, failureDetailMessage); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/uddi/WSI3005_OBSOLETE.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/uddi/WSI3005_OBSOLETE.java new file mode 100644 index 000000000..2a76f5318 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/uddi/WSI3005_OBSOLETE.java @@ -0,0 +1,119 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.uddi; + +import java.util.Vector; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.UDDIUtils; +import org.uddi4j.client.UDDIProxy; +import org.uddi4j.datatype.tmodel.TModel; +import org.uddi4j.util.CategoryBag; +import org.uddi4j.util.KeyedReference; + + +/** + * WSI3005_OBSOLETE - A uddi:tModel which claims conformance with a WS-I profile + * must be categorized using the ws-i-org:conformsTo taxonomy. + */ +public class WSI3005_OBSOLETE extends AssertionProcess +{ + private final UDDIValidatorImpl validator; + + /** + * @param UDDIValidatorImpl + */ + public WSI3005_OBSOLETE(UDDIValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + /** + * Validates the test assertion. + * @see org.eclipse.wst.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + + result = AssertionResult.RESULT_PASSED; + + // Get the tModel from the entryContext + TModel tModel = (TModel) entryContext.getEntry().getEntryDetail(); + + // If the tModel does not exist, then fail + if (tModel == null) + { + result = AssertionResult.RESULT_FAILED; + failureDetailMessage = "Could not locate a tModel."; + } + + // If there is a tModel + else + { + CategoryBag bag = tModel.getCategoryBag(); + + try + { + if (!checkCategoryBag(this.validator.uddiProxy, bag)) + { + // failed + result = AssertionResult.RESULT_FAILED; + failureDetailMessage = + "The tModel key is: [" + tModel.getTModelKey() + "]."; + } + } + catch (IllegalStateException e) + { + result = AssertionResult.RESULT_FAILED; + failureDetailMessage = + "The UDDI registry does not contain WSI conformance taxonomy" + + " tModel (\"ws-i-org:conformsTo:2002_12\")."; + } + } + + // Return assertion result + return validator.createAssertionResult(testAssertion, result, failureDetailMessage); + } + + /** + * Checks a category bag. + * @param proxy + * @param bag + * @return boolean + */ + private boolean checkCategoryBag(UDDIProxy proxy, CategoryBag bag) + { + String conformanceKey = UDDIUtils.getWSIConformanceTModelKey(proxy); + + boolean result = false; + + if (bag != null) + { + Vector references = bag.getKeyedReferenceVector(); + for (int i = 0; i < references.size() && !result; i++) + { + KeyedReference ref = (KeyedReference) references.get(i); + + result = ref.getTModelKey().equalsIgnoreCase(conformanceKey); + } + } + + return result; + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/uddi/WSI3006.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/uddi/WSI3006.java new file mode 100644 index 000000000..66e334379 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/uddi/WSI3006.java @@ -0,0 +1,165 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.uddi; + +import java.util.Vector; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionResultException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.UDDIUtils; +import org.uddi4j.client.UDDIProxy; +import org.uddi4j.datatype.tmodel.TModel; +import org.uddi4j.util.CategoryBag; +import org.uddi4j.util.KeyedReference; + + +/** + * WSI3006 - The uddi:tModel uses the ws-i-org:conformsTo:2002_12 categorization + * value of "http://ws-i.org/profiles/base/1.0". The categoryBag in the tModel + * contains a keyedReference with a tModelKey that contains the key value + * uuid:65719168-72c6-3f29-8c20-62defb0961c0 for the ws-i-org:conformsTo:2002_12 + * tModel. + */ +public class WSI3006 extends AssertionProcess +{ + private final UDDIValidatorImpl validator; + /** + * @param UDDIValidatorImpl + */ + public WSI3006(UDDIValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + /** + * Validates the test assertion. + * @see org.eclipse.wst.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + + result = AssertionResult.RESULT_PASSED; + failureDetailMessage = null; + KeyedReference claimKeyedRef = null; + + // check whether a UDDI conformance claim is being made... + + // Get the tModel from the entryContext + TModel tModel = (TModel) entryContext.getEntry().getEntryDetail(); + try + { + if ((claimKeyedRef = conformanceClaimMade(tModel)) == null) + { + throw new AssertionResultException( + AssertionResult.RESULT_NOT_APPLICABLE); + } + + // we have a conformance claim, so check the keyedReference keyValue + if (!claimKeyedRef + .getKeyValue() + .equals(WSIConstants.ATTRVAL_UDDI_CLAIM_KEYVALUE)) + { + throw new AssertionResultException( + AssertionResult.RESULT_FAILED, + "The tModel key is: [" + + tModel.getTModelKey() + + "].\nThe categoryBag is: [" + + tModel.getCategoryBag() + + "]."); + } + } + catch (AssertionResultException e) + { + result = e.getMessage(); + failureDetailMessage = e.getDetailMessage(); + } + + // Return assertion result + return validator.createAssertionResult(testAssertion, result, failureDetailMessage); + } + + /** + * Checks a category bag and extracts KeyedReference containing + * the conformance claim. + * @param proxy + * @param bag + * @return boolean + */ + private KeyedReference checkCategoryBag(UDDIProxy proxy, CategoryBag bag) + { + String conformanceKey = null; + try + { + conformanceKey = UDDIUtils.getWSIConformanceTModelKey(proxy); + } + catch (IllegalStateException ex) + { + return null; + } + + boolean result = true; + KeyedReference conformanceRef = null; + + if (bag != null) + { + Vector references = bag.getKeyedReferenceVector(); + for (int i = 0; i < references.size() && result; i++) + { + KeyedReference ref = (KeyedReference) references.get(i); + + if (ref + .getTModelKey() + .equalsIgnoreCase(conformanceKey) //&& ref.getKeyValue().equals(WSIConstants.ATTRVAL_UDDI_CLAIM_KEYVALUE) + // we need only tModel key + ) + { + result = true; + conformanceRef = ref; + } + } + } + + return conformanceRef; + } + /** + * Gets KeyedReference containing the conformance claim. + * @param tModel + * @return + * @throws WSIException + */ + private KeyedReference conformanceClaimMade(TModel tModel) + throws WSIException + { + + // If the tModel does not exist, then fail + if (tModel == null) + { + throw new IllegalArgumentException("tModel cannot be null"); + } + + // If there is a tModel + else + { + CategoryBag bag = tModel.getCategoryBag(); + return checkCategoryBag(this.validator.uddiProxy, bag); + } + + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/uddi/WSI3007.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/uddi/WSI3007.java new file mode 100644 index 000000000..fbd6c7fcd --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/uddi/WSI3007.java @@ -0,0 +1,157 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.uddi; + +import java.util.Vector; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.UDDIUtils; +import org.uddi4j.client.UDDIProxy; +import org.uddi4j.datatype.binding.BindingTemplate; +import org.uddi4j.datatype.business.BusinessEntity; +import org.uddi4j.datatype.service.BusinessService; +import org.uddi4j.util.CategoryBag; +import org.uddi4j.util.KeyedReference; + + +/** + * WSI3007 - A uddi:businessEntity or uddi:businessService associated + * with this uddi:bindingTemplate is not categorized using + * the ws-i-org:conformsTo:2002_12 taxonomy. + */ +public class WSI3007 extends AssertionProcess +{ + private final UDDIValidatorImpl validator; + + /** + * @param UDDIValidatorImpl + */ + public WSI3007(UDDIValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + /** + * Validates the test assertion. + * @see org.eclipse.wst.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + String serviceLocation = null; + + result = AssertionResult.RESULT_PASSED; + + // Get the bindingTemplate from the entryContext + BindingTemplate bindingTemplate = + (BindingTemplate) entryContext.getEntry().getEntryDetail(); + + boolean validService = false; + boolean validBusiness = false; + + String serviceKey = null; + String businessKey = null; + try + { + serviceKey = bindingTemplate.getServiceKey(); + BusinessService service = + UDDIUtils.getBusinessServiceByKey(this.validator.uddiProxy, serviceKey); + + businessKey = service.getBusinessKey(); + BusinessEntity business = + UDDIUtils.getBusinessByKey(this.validator.uddiProxy, businessKey); + + validService = checkCategoryBag(this.validator.uddiProxy, service.getCategoryBag()); + validBusiness = checkCategoryBag(this.validator.uddiProxy, business.getCategoryBag()); + + if (!validBusiness || !validService) + { + result = AssertionResult.RESULT_FAILED; + + if (!validBusiness) + { + failureDetailMessage = + "The businessEntity key is: [" + businessKey + "]."; + } + + if (!validService) + { + if (!validBusiness) + failureDetailMessage += " "; + else + failureDetailMessage = ""; + + failureDetailMessage += "The businessService key is: [" + + serviceKey + + "]."; + } + } + } + catch (IllegalStateException e) + { + result = AssertionResult.RESULT_FAILED; + failureDetailMessage = + "The UDDI registry does not contain WSI conformance taxonomy" + + " tModel (\"ws-i-org:conformsTo:2002_12\")."; + } + catch (Throwable e) + { + throw new WSIException( + "An exception occurred while processing the discovery test assertions.", + e); + } + + // Return assertion result + return validator.createAssertionResult(testAssertion, result, failureDetailMessage); + } + + /** + * Checks whether the category bag contains the conformance claim. + * Returns true if the bag does not contain the conformance claim. + * @param proxy + * @param bag + * @return boolean + */ + private boolean checkCategoryBag(UDDIProxy proxy, CategoryBag bag) + { + String conformanceKey = null; + try + { + conformanceKey = UDDIUtils.getWSIConformanceTModelKey(proxy); + } + catch (IllegalStateException ex) + { + return false; + } + + boolean result = true; + + if (bag != null) + { + Vector references = bag.getKeyedReferenceVector(); + for (int i = 0; i < references.size() && result; i++) + { + KeyedReference ref = (KeyedReference) references.get(i); + + result = !ref.getTModelKey().equalsIgnoreCase(conformanceKey); + } + } + + return result; + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/uddi/WSI3021.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/uddi/WSI3021.java new file mode 100644 index 000000000..56e2befa7 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/uddi/WSI3021.java @@ -0,0 +1,115 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.uddi; + +import java.util.Vector; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.UDDIUtils; +import org.uddi4j.datatype.tmodel.TModel; +import org.uddi4j.util.CategoryBag; +import org.uddi4j.util.KeyedReference; + + +/** +* WSI3021 - The uddi:tModel has a "name" element of value "ws-i-org:conformsTo:2002_12" , +* has an overviewURL value of "http://ws-i.org/schemas/conformanceClaim/", and has +* a keyedReference element with keyName attribute value of "uddi-org:types:categorization". +*/ +public class WSI3021 extends AssertionProcess +{ + private final UDDIValidatorImpl validator; + + /** + * @param UDDIValidatorImpl + */ + public WSI3021(UDDIValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + /** + * Validates the test assertion. + * @see org.eclipse.wst.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + result = AssertionResult.RESULT_FAILED; + + TModel tModel = + UDDIUtils.getTModelByKey( + this.validator.uddiProxy, + UDDIUtils.getWSIConformanceTModelKey(this.validator.uddiProxy)); + + // If the tModel does not exist, then fail + if (tModel == null) + { + result = AssertionResult.RESULT_FAILED; + failureDetailMessage = "Could not locate a tModel."; + } + else + { + boolean validURL = + tModel.getOverviewDoc() != null + && "http://ws-i.org/schemas/conformanceClaim/".equals( + tModel.getOverviewDoc().getOverviewURLString()); + boolean validCategory = checkCategoryBag(tModel.getCategoryBag()); + + if (validURL && validCategory) + { + result = AssertionResult.RESULT_PASSED; + } + else + { + result = AssertionResult.RESULT_FAILED; + failureDetailMessage = this.validator.uddiReference.getInquiryURL(); + } + } + + // Return assertion result + return validator.createAssertionResult(testAssertion, result, failureDetailMessage); + } + + /** + * Checks whether the category bag meets the WSI's requirements. + * @param bag + * @return + */ + private boolean checkCategoryBag(CategoryBag bag) + { + boolean result = false; + + if (bag != null) + { + Vector references = bag.getKeyedReferenceVector(); + for (int i = 0; i < references.size() && !result; i++) + { + KeyedReference ref = (KeyedReference) references.get(i); + + result = + "uddi-org:types:categorization".equals(ref.getKeyName()) + && "categorization".equals(ref.getKeyValue()) + && "uuid:C1ACF26D-9672-4404-9D70-39B756E62AB4".equals( + ref.getTModelKey()); + } + } + + return result; + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/AP2901.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/AP2901.java new file mode 100644 index 000000000..3a09c9107 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/AP2901.java @@ -0,0 +1,146 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +import java.util.Collection; +import java.util.HashSet; +import java.util.List; + +import javax.wsdl.Binding; +import javax.wsdl.BindingInput; +import javax.wsdl.BindingOperation; +import javax.wsdl.BindingOutput; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.xml.namespace.QName; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.WSITag; +import org.eclipse.wst.wsi.internal.analyzer.AssertionFailException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.report.AssertionResult; + +/** + * AP2901 + * + * For a candidate wsdl:binding element + * A description uses either the WSDL MIME Binding as described in WSDL 1.1 Section 5 + * or WSDL SOAP binding as described in WSDL 1.1 Section 3 + * on each of the wsdl:input or wsdl:output elements of a wsdl:binding. + */ +public class AP2901 extends AssertionProcess implements WSITag +{ + /** + * WSDLValidator + */ + private final WSDLValidatorImpl validator; + + private Collection mimeElements; + + /** + * @param WSDLValidatorImpl + */ + public AP2901(WSDLValidatorImpl impl) + { + super(impl); + this.validator = impl; + + mimeElements = new HashSet(); + mimeElements.add(WSDL_MIME_CONTENT); + mimeElements.add(WSDL_MIME_XML); + mimeElements.add(WSDL_MIME_MULTIPART); + } + + /* Validates the test assertion. + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + try + { + // Getting a wsdl:binding + Binding binding = (Binding) entryContext.getEntry().getEntryDetail(); + + // Getting its wsdl:operation elements + List ops = binding.getBindingOperations(); + + // Going through the operation elements + for (int i = 0; i < ops.size(); i++) + { + BindingOperation bindingOperation = (BindingOperation) ops.get(i); + + // Getting wsdl:input and wsdl:output elements of an operation + BindingInput bindingInput = bindingOperation.getBindingInput(); + BindingOutput bindingOutput = bindingOperation.getBindingOutput(); + + QName inapplicableElement = null; + // Getting an inapplicable extensibility element of wsdl:input + // If such element exists, the assertion failed + if (bindingInput != null) + { + // Getting an inapplicable extensibility element of wsdl:input + // If such element exists, the assertion failed + inapplicableElement = getInapplicableElement(bindingInput.getExtensibilityElements()); + + if (inapplicableElement != null) + throw new AssertionFailException(inapplicableElement.toString()); + } + + // Getting an inapplicable extensibility element of wsdl:output + // If such element exists, the assertion failed + if (bindingOutput != null) + { + inapplicableElement = + getInapplicableElement(bindingOutput.getExtensibilityElements()); + if (inapplicableElement != null) + throw new AssertionFailException(inapplicableElement.toString()); + } + } + } + catch (AssertionFailException afe) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = validator.createFailureDetail( + afe.getMessage(), entryContext); + } + // Return assertion result + return validator.createAssertionResult( + testAssertion, result, failureDetail); + } + + /** + * Looks for any extensibility element of wsdl:input or wsdl:output + * that does not conform to the SOAP binding or the MIME binding. + * @param extElems a list of extensibility elements + * @return the QName of an inapplicable element + */ + private QName getInapplicableElement(List extElems) + { + for (int i = 0; i < extElems.size(); i++) + { + QName elementName = + ((ExtensibilityElement) extElems.get(i)).getElementType(); + + if (!mimeElements.contains(elementName) && + !elementName.equals(WSDL_SOAP_BODY) && + !elementName.equals(WSDL_SOAP_HEADER)) + { + return elementName; + } + } + + return null; + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/AP2903.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/AP2903.java new file mode 100644 index 000000000..a64d434e8 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/AP2903.java @@ -0,0 +1,241 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +import java.util.ArrayList; +import java.util.List; + +import javax.wsdl.Binding; +import javax.wsdl.BindingInput; +import javax.wsdl.BindingOperation; +import javax.wsdl.BindingOutput; +import javax.wsdl.Input; +import javax.wsdl.Message; +import javax.wsdl.Output; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.mime.MIMEContent; +import javax.wsdl.extensions.mime.MIMEMultipartRelated; +import javax.wsdl.extensions.mime.MIMEPart; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.WSITag; +import org.eclipse.wst.wsi.internal.analyzer.AssertionFailException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionNotApplicableException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.report.AssertionResult; + +/** + * AP2903 + * + * For a candidate wsdl:binding with at least one mime:content element + * The part attribute of each mime:content element in a wsdl:binding references + * a wsdl:part element of a wsdl:message that is present in the respective wsdl:input or wsdl:output of the + * corresponding wsdl:operation of the corresponding wsdl:portType. + */ +public class AP2903 extends AssertionProcess implements WSITag +{ + private final WSDLValidatorImpl validator; + + /** + * @param WSDLValidatorImpl + */ + public AP2903(WSDLValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + /* Validates the test assertion. + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + try + { + // A variable that indicates a binding contains at least one + // mime:content element + boolean mimeContentsFound = false; + + // Getting a wsdl:binding + Binding binding = (Binding) entryContext.getEntry().getEntryDetail(); + + // Getting its wsdl:operation elements + List ops = binding.getBindingOperations(); + + // Going through the operation elements + for (int i = 0; i < ops.size(); i++) + { + BindingOperation bindingOperation = (BindingOperation) ops.get(i); + + // Getting wsdl:input and wsdl:output elements of an operation + BindingInput bindingInput = bindingOperation.getBindingInput(); + BindingOutput bindingOutput = bindingOperation.getBindingOutput(); + + // Collecting all the mime:content elements from wsdl:input and wsdl:output + List inputMimeContents = getMimeContentElements( + bindingInput == null ? null : bindingInput.getExtensibilityElements()); + List outputMimeContents = getMimeContentElements( + bindingOutput == null ? null : bindingOutput.getExtensibilityElements()); + + // If the wsdl:input contains mime:content elements + if (!inputMimeContents.isEmpty()) + { + mimeContentsFound = true; + Input portTypeInput = bindingOperation.getOperation().getInput(); + // If there is no the corresponding wsdl:input in wsdl:portType, + // the assertion failed + if (portTypeInput == null) + throw new AssertionFailException( + "There is no the corresponging wsdl:input in the wsdl:portType" + + " operation for the wsdl:input of the \"" + + bindingOperation.getName() + "\" binding operation."); + + // If the wsdl:portType input does not reference any wsdl:message, + // the assertion failed + if (portTypeInput.getMessage() == null) + throw new AssertionFailException("The wsdl:input of the \"" + + bindingOperation.getOperation().getName() + "\" wsdl:portType " + + "operation does not reference any wsdl:message."); + + // Getting the part name that is not specified in the wsdl:message + // the input of wsdl:portType refers to + String part = getInvalidMimeContentPart( + inputMimeContents, portTypeInput.getMessage()); + + // If such part is found, the assertion failed + if (part != null) + throw new AssertionFailException("part=\"" + part + + "\", the input of the binding operation \"" + + bindingOperation.getName() + "\""); + } + + // If the wsdl:output contains mime:content elements + if (!outputMimeContents.isEmpty()) + { + mimeContentsFound = true; + Output portTypeOutput = bindingOperation.getOperation().getOutput(); + // If there is no the corresponding wsdl:input in wsdl:portType, + // the assertion failed + if (portTypeOutput == null) + throw new AssertionFailException( + "There is no the corresponging wsdl:output in the wsdl:portType" + + " operation for the wsdl:output of the \"" + + bindingOperation.getName() + "\" binding operation."); + + // If the wsdl:portType output does not reference any wsdl:message, + // the assertion failed + if (portTypeOutput.getMessage() == null) + throw new AssertionFailException("The wsdl:output of the \"" + + bindingOperation.getOperation().getName() + "\" wsdl:portType " + + "operation does not reference any wsdl:message."); + + // Getting the part name that is not specified in the wsdl:message + // the output of wsdl:portType refers to + String part = getInvalidMimeContentPart( + outputMimeContents, portTypeOutput.getMessage()); + + // If such part is found, the assertion failed + if (part != null) + throw new AssertionFailException("part=\"" + part + + "\", the output of the binding operation \"" + + bindingOperation.getName() + "\""); + } + } + + // If the binding contains no mime:content elements, + // the assertion is not applicable + if (!mimeContentsFound) + throw new AssertionNotApplicableException(); + } + catch (AssertionNotApplicableException anae) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + catch (AssertionFailException afe) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = validator.createFailureDetail( + afe.getMessage(), entryContext); + } + + // Return assertion result + return validator.createAssertionResult( + testAssertion, result, failureDetail); + } + + /** + * Collects all mime:content elements. + * @param extElems a list of extensibility elements that can contain mime:contentS. + * @return the list of mime:content elements found. + */ + private List getMimeContentElements(List extElems) + { + List mimeContentElements = new ArrayList(); + + if (extElems != null) + { + // Going through all the extensibility elements + for (int i = 0; i < extElems.size(); i++) + { + ExtensibilityElement extElem = (ExtensibilityElement) extElems.get(i); + // If the element is mime:multipartRelated + if (extElem.getElementType().equals(WSDL_MIME_MULTIPART)) + { + // Getting the mime:part elements of the mime:multipartRelated + List mimeParts = ((MIMEMultipartRelated) extElem).getMIMEParts(); + // Going through all the mime:part elements + for (int j = 0; j < mimeParts.size(); j++) + { + // Collecting all the mime:content elements of this mime:part + List elems = getMimeContentElements( + ((MIMEPart) mimeParts.get(j)).getExtensibilityElements()); + // Adding the elements to the list being returned + mimeContentElements.addAll(elems); + } + } + // Else if the element is mime:content + else if (extElem.getElementType().equals(WSDL_MIME_CONTENT)) + { + // Adding the element to the list being returned + mimeContentElements.add(extElem); + } + } + } + + return mimeContentElements; + } + + /** + * Returns part name specified in mime:content element that is not presented in wsdl:message + * @param mimeContents a list of mime:content elements which part attributes are validated + * @param message a wsdl:message + * @return a part name + */ + private String getInvalidMimeContentPart(List mimeContents, Message message) + { + // Going throug all the mime:content elements + for (int i = 0; i < mimeContents.size(); i++) + { + // Getting the part name of a mime:element + String part = ((MIMEContent) mimeContents.get(i)).getPart(); + // If the wsdl:message does not contain such part, return the part + if (!message.getParts().keySet().contains(part)) + return part; + } + // Return null if no one part is found + return null; + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/AP2904.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/AP2904.java new file mode 100644 index 000000000..17ccb7452 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/AP2904.java @@ -0,0 +1,50 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.report.AssertionResult; + +/** + * AP2904 + * For a candidate wsdl:binding with at least one mime:content element + * The part attribute of each mime:content element in a wsdl:binding + * does not reference a sub-component of a wsdl:part of the wsdl:message that is present in the + * respective wsdl:input or wsdl:output of the corresponding wsdl:operation of the corresponding + * wsdl:portType. + */ +public class AP2904 extends AP2903 +{ + private final WSDLValidatorImpl validator; + + /** + * @param WSDLValidatorImpl + */ + public AP2904(WSDLValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + /* Validates the test assertion. + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + // Return assertion result + return super.validate(testAssertion, entryContext); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/AP2906.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/AP2906.java new file mode 100644 index 000000000..88d6e8422 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/AP2906.java @@ -0,0 +1,216 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +import java.util.ArrayList; +import java.util.List; + +import javax.wsdl.Binding; +import javax.wsdl.BindingInput; +import javax.wsdl.BindingOperation; +import javax.wsdl.BindingOutput; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.mime.MIMEMultipartRelated; +import javax.wsdl.extensions.mime.MIMEPart; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.WSITag; +import org.eclipse.wst.wsi.internal.analyzer.AssertionFailException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionNotApplicableException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.report.AssertionResult; + +/** + * AP2906 + * + * For a candidate wsdl:binding containing a mime:multipartRelated element + * A non-root MIME part in a wsdl:binding does not contain a soapbind:header element. + */ +public class AP2906 extends AssertionProcess implements WSITag +{ + private final WSDLValidatorImpl validator; + + /** + * @param WSDLValidatorImpl + */ + public AP2906(WSDLValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + /* Validates the test assertion. + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + try + { + // A variable that indicates a binding contains at least one + // mime:multipartRelated element + boolean multipartsFound = false; + + // Getting a wsdl:binding + Binding binding = (Binding) entryContext.getEntry().getEntryDetail(); + + // Getting its wsdl:operation elements + List ops = binding.getBindingOperations(); + + // Going through the operation elements + for (int i = 0; i < ops.size(); i++) + { + BindingOperation bindingOperation = (BindingOperation) ops.get(i); + + // Getting wsdl:input and wsdl:output elements of an operation + BindingInput bindingInput = bindingOperation.getBindingInput(); + BindingOutput bindingOutput = bindingOperation.getBindingOutput(); + + // Collecting all the mime:multipartRelated elements from wsdl:input and wsdl:output + List inputMultiparts = getMimeMultipartElements( + bindingInput == null ? null : bindingInput.getExtensibilityElements()); + List outputMultiparts = getMimeMultipartElements( + bindingOutput == null ? null : bindingOutput.getExtensibilityElements()); + + // If the wsdl:input contains mime:multipartRelated elements + if (!inputMultiparts.isEmpty()) + { + multipartsFound = true; + + // If there is a soap:header in the non-root mime:part, + // the assertion failed + if (containsInvalidMimePart(inputMultiparts)) + { + throw new AssertionFailException("The invalid mime:part element " + + "is in the wsdl:input of the \"" + bindingOperation.getName() + + "\" binding operation."); + } + } + + // If the wsdl:output contains mime:multipartRelated elements + if (!outputMultiparts.isEmpty()) + { + multipartsFound = true; + + // If there is a soap:header in the non-root mime:part, + // the assertion failed + if (containsInvalidMimePart(outputMultiparts)) + { + throw new AssertionFailException("The invalid mime:part element " + + "is in the wsdl:output of the \"" + bindingOperation.getName() + + "\" binding operation."); + } + } + } + // If the binding contains no one mime:multipartRelated element, + // the assertion is not applicable + if (!multipartsFound) + throw new AssertionNotApplicableException(); + } + catch (AssertionNotApplicableException anae) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + catch (AssertionFailException afe) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = validator.createFailureDetail( + afe.getMessage(), entryContext); + } + + // Return assertion result + return validator.createAssertionResult( + testAssertion, result, failureDetail); + } + + /** + * Looks for such non-root mime:part element from a list of mime:multipartRelated elements + * that contains a soap:header element. + * @param multiparts a list of mime:multipartRelated elements + * @return true, if such element is found, false otherwise + */ + private boolean containsInvalidMimePart(List multiparts) + { + // Going through a list of mime:multipartRelated elements + for (int i = 0; i < multiparts.size(); i++) + { + // Getting a list of mime:part elements + List mimeParts = + ((MIMEMultipartRelated) multiparts.get(i)).getMIMEParts(); + + // Looking for non-root mime:partS + if (mimeParts.size() > 1) + { + for (int j = 1; j < mimeParts.size(); j++) + { + // Getting a list of extensibility elements of a mime:part + List extElems = + ((MIMEPart) mimeParts.get(j)).getExtensibilityElements(); + // Going through the extensibility elements + for (int k = 0; k < extElems.size(); k++) + { + // If an extensibility element is a soap:header, + // return true + if (((ExtensibilityElement)extElems.get(k)) + .getElementType().equals(WSDL_SOAP_HEADER)) + { + return true; + } + } + } + } + } + // return false, if the element is not found + return false; + } + + /** + * Collects all mime:multipartRelated elements. + * @param extElems a list of extensibility elements that can contain mime:multipartRelated elements. + * @return the list of mime:multipartRelated elements found. + */ + private List getMimeMultipartElements(List extElems) + { + List mimeMultipartElements = new ArrayList(); + + if (extElems != null) + { + // Going through all the extensibility elements + for (int i = 0; i < extElems.size(); i++) + { + ExtensibilityElement extElem = (ExtensibilityElement) extElems.get(i); + // If the element is mime:multipartRelated + if (extElem.getElementType().equals(WSDL_MIME_MULTIPART)) + { + // Adding the element to the list being returned + mimeMultipartElements.add(extElem); + // Getting the mime:part elements of the mime:multipartRelated + List mimeParts = ((MIMEMultipartRelated) extElem).getMIMEParts(); + // Going through all the mime:part elements + for (int j = 0; j < mimeParts.size(); j++) + { + // Collecting all the mime:multipartRelated elements of this mime:part + List elems = getMimeMultipartElements( + ((MIMEPart) mimeParts.get(j)).getExtensibilityElements()); + // Adding the elements to the list being returned + mimeMultipartElements.addAll(elems); + } + } + } + } + + return mimeMultipartElements; + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/AP2907.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/AP2907.java new file mode 100644 index 000000000..f0c7cb442 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/AP2907.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.report.AssertionResult; + +/** + * AP2907 + * + * For a candidate wsdl:binding + * Each MIME part in a description is defined using + * an element with a local name of part in the namespace of the + * WSDL MIME Binding extension. + */ +public class AP2907 extends AssertionProcess +{ + private final WSDLValidatorImpl validator; + + /** + * @param WSDLValidatorImpl + */ + public AP2907(WSDLValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + /* Validates the test assertion. + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + // Return assertion result + return validator.createAssertionResult( + testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/AP2908.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/AP2908.java new file mode 100644 index 000000000..44916e4e7 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/AP2908.java @@ -0,0 +1,297 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import javax.wsdl.Binding; +import javax.xml.namespace.QName; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.WSITag; +import org.eclipse.wst.wsi.internal.analyzer.AssertionFailException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionNotApplicableException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +/** + * AP2908 + * + * For a candidate wsdl:binding + * The mime:part element in a DESCRIPTION does not have a name attribute. + */ +public class AP2908 extends AssertionProcess implements WSITag +{ + private final WSDLValidatorImpl validator; + + /** + * @param WSDLValidatorImpl + */ + public AP2908(WSDLValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + /* Validates the test assertion. + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + try + { + // Getting a wsdl:binding + Binding wsdlBinding = (Binding) entryContext.getEntry().getEntryDetail(); + + // Since WSDL4J 1.4 ignores any attributes of mime:part, use Xerces 2.6.2 instead + Document doc = XMLUtils.parseXMLDocument(validator.wsdlURL); + + // Finding the wsdl:binding element being processed + Element binding = getBindingElement( + doc.getDocumentElement(), wsdlBinding.getQName().getLocalPart()); + + List ops = getChildElements(binding, WSDL_OPERATION); + + // A variable that indicates a binding contains at least one + // mime:multipartRelated element + boolean multipartsFound = false; + + // Going through the operation elements + for (int i = 0; i < ops.size(); i++) + { + Element bindingOperation = (Element) ops.get(i); + + // Getting wsdl:input and wsdl:output elements of an operation + Element bindingInput = getChildElement(bindingOperation, WSDL_INPUT); + Element bindingOutput = getChildElement(bindingOperation, WSDL_OUTPUT); + + // Collecting all the mime:multipartRelated elements from wsdl:input and wsdl:output + List inputMultiparts = getMimeMultipartElements(bindingInput); + List outputMultiparts = getMimeMultipartElements(bindingOutput); + + // If the wsdl:input contains mime:multipartRelated elements + if (!inputMultiparts.isEmpty()) + { + multipartsFound = true; + + // If there is a mime:part element containing a name attribute, + // the assertion failed + if (containsInvalidMimePart(inputMultiparts)) + { + throw new AssertionFailException("The invalid " + + "mime:part element is in the wsdl:input of the \"" + + bindingOperation.getAttribute(WSIConstants.ATTR_NAME) + + "\" binding operation."); + } + } + + // If the wsdl:output contains mime:multipartRelated elements + if (!outputMultiparts.isEmpty()) + { + multipartsFound = true; + + // If there is a mime:part element containing a name attribute, + // the assertion failed + if (containsInvalidMimePart(outputMultiparts)) + { + throw new AssertionFailException("The invalid " + + "mime:part element is in the wsdl:output of the \"" + + bindingOperation.getAttribute(WSIConstants.ATTR_NAME) + + "\" binding operation."); + } + } + } + // If the binding contains no one mime:multipartRelated element, + // the assertion is not applicable + if (!multipartsFound) + throw new AssertionNotApplicableException(); + } + catch (IOException ioe) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + catch (AssertionNotApplicableException anae) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + catch (AssertionFailException afe) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = validator.createFailureDetail( + afe.getMessage(), entryContext); + } + // Return assertion result + return validator.createAssertionResult( + testAssertion, result, failureDetail); + } + + /** + * Validates mime:part elements for each of mime:multipartRelated element. + * @param multiparts a list of mime:multipartRelated elements. + * @return true, if any mime:part contains a name attribute, false otherwise. + */ + private boolean containsInvalidMimePart(List multiparts) { + // Going through a list of mime:multipartRelated elements + for (int i = 0; i < multiparts.size(); i++) + { + // Getting a list of mime:part elements + List mimeParts = + getChildElements((Element) multiparts.get(i), WSDL_MIME_PART); + // Going through all the mime:part elements + for (int j = 0; j < mimeParts.size(); j++) + { + Element mimePart = (Element) mimeParts.get(j); + // If the mime:part element contains a name attribute, + // return true + if (mimePart.getAttributeNode(WSIConstants.ATTR_NAME) != null) + { + return true; + } + } + } + // No one invalid mime:part element is found, return false + return false; + } + + /** + * Collects all mime:multipartRelated elements. + * @param parent an element which the child elements are gathered from. + * @return the list of mime:multipartRelated elements found. + */ + private List getMimeMultipartElements(Element parent) + { + List mimeMultipartElements = new ArrayList(); + // If the parent is not null + if (parent != null) + { + // Getting the first parent's child + Element child = XMLUtils.getFirstChild(parent); + while (child != null) + { + // If the child is a mime:multipartRelated element + if (child.getNamespaceURI().equals(WSDL_MIME_MULTIPART.getNamespaceURI()) + && child.getLocalName().equals(WSDL_MIME_MULTIPART.getLocalPart())) + { + // Adding the element to the list being returned + mimeMultipartElements.add(child); + + // Getting mime:partS from the element + List mimeParts = getChildElements(child, WSDL_MIME_PART); + // Going through all the mime:part elements + for (int i = 0; i < mimeParts.size(); i++) + { + // Collecting all the mime:multipartRelated elements of this mime:part + List elems = getMimeMultipartElements((Element) mimeParts.get(i)); + // Adding the elements to the list being returned + mimeMultipartElements.addAll(elems); + } + } + // Getting the next child + child = XMLUtils.getNextSibling(child); + } + } + + return mimeMultipartElements; + } + + /** + * Looks for an element's child element. + * @param parent a parent element. + * @param childName a qualified element name being found. + * @return an element or null if it is not found. + */ + private Element getChildElement(Element parent, QName childName) + { + // Getting the first parent's child + Element child = XMLUtils.getFirstChild(parent); + while (child != null) + { + // If the child has the required qualified name + if (child.getNamespaceURI().equals(childName.getNamespaceURI()) + && child.getLocalName().equals(childName.getLocalPart())) + { + // return the child + return child; + } + // Getting the next child + child = XMLUtils.getNextSibling(child); + } + return null; + } + + /** + * Collects element's child elements. + * @param parent a parent element. + * @param childName a qualified element name being found. + * @return a list of elements found. + */ + private List getChildElements(Element parent, QName childName) + { + List children = new ArrayList(); + if (parent != null) + { + // Getting the first parent's child + Element child = XMLUtils.getFirstChild(parent); + while (child != null) + { + // If the child has the required qualified name + if (child.getNamespaceURI().equals(childName.getNamespaceURI()) + && child.getLocalName().equals(childName.getLocalPart())) + { + // Adding the child to the list + children.add(child); + } + // Getting the next binding's child + child = XMLUtils.getNextSibling(child); + } + } + return children; + } + + /** + * Looks for wsdl:binding element. + * @param definitions a wsdl:definitions element. + * @param bindingName a name of wsdl:binding element. + * @return a wsdl:binding element or null if it is not found. + */ + private Element getBindingElement(Element definitions, String bindingName) + { + // Getting the first definitions' child + Element child = XMLUtils.getFirstChild(definitions); + while (child != null) + { + // If definitions' child is wsdl:binding element + // and is the same that is being processed by WSDLValidator + if (child.getNamespaceURI().equals(WSDL_BINDING.getNamespaceURI()) + && child.getLocalName().equals(WSDL_BINDING.getLocalPart()) + && child.getAttribute(WSIConstants.ATTR_NAME).equals(bindingName)) + { + // return the wsdl:binding element + return child; + } + // Getting the next definitions' child + child = XMLUtils.getNextSibling(child); + } + // return null, is there is no such wsdl:binding + return null; + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/AP2909.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/AP2909.java new file mode 100644 index 000000000..b9cc4bab8 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/AP2909.java @@ -0,0 +1,215 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +import java.util.ArrayList; +import java.util.List; + +import javax.wsdl.Binding; +import javax.wsdl.BindingInput; +import javax.wsdl.BindingOperation; +import javax.wsdl.BindingOutput; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.mime.MIMEContent; +import javax.wsdl.extensions.mime.MIMEMultipartRelated; +import javax.wsdl.extensions.mime.MIMEPart; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.WSITag; +import org.eclipse.wst.wsi.internal.analyzer.AssertionFailException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionNotApplicableException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.report.AssertionResult; + +/** + * AP2909 + * + * For a candidate wsdl:binding + * Multiple mime:content child elements of a mime:part element + * in a desciption reference the same wsdl:part. + */ +public class AP2909 extends AssertionProcess implements WSITag +{ + private final WSDLValidatorImpl validator; + + // A variable that indicates a binding contains + // multiple mime:content elements + private boolean multipleContentFound; + + /** + * @param WSDLValidatorImpl + */ + public AP2909(WSDLValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + /* Validates the test assertion. + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + // Resetting the variable + multipleContentFound = false; + + try + { + // Getting a wsdl:binding + Binding binding = (Binding) entryContext.getEntry().getEntryDetail(); + + // Getting its wsdl:operation elements + List ops = binding.getBindingOperations(); + + // Going through the operation elements + for (int i = 0; i < ops.size(); i++) + { + BindingOperation bindingOperation = (BindingOperation) ops.get(i); + + // Getting wsdl:input and wsdl:output elements of an operation + BindingInput bindingInput = bindingOperation.getBindingInput(); + BindingOutput bindingOutput = bindingOperation.getBindingOutput(); + + // Collecting all the mime:part elements from wsdl:input and wsdl:output + List inputMimeParts = getMimeParts( + bindingInput == null ? null : bindingInput.getExtensibilityElements()); + List outputMimeParts = getMimeParts( + bindingOutput == null ? null : bindingOutput.getExtensibilityElements()); + + // If there is a mime:part containing multiple mime:contentS + // which reference different wsdl:partS, the assertion failed + if (containsInvalidMimePart(inputMimeParts)) + { + throw new AssertionFailException("The invalid mime:part element " + + "is in the wsdl:input of the \"" + bindingOperation.getName() + + "\" binding operation."); + } + + // If there is a mime:part containing multiple mime:contentS + // which reference different wsdl:partS, the assertion failed + if (containsInvalidMimePart(outputMimeParts)) + { + throw new AssertionFailException("The invalid mime:part element " + + "is in the wsdl:output of the \"" + bindingOperation.getName() + + "\" binding operation."); + } + + } + // If the binding does not contain a mime:part with multiple + // mime:content elements, the assertion is not applicable + if (!multipleContentFound) + throw new AssertionNotApplicableException(); + } + catch (AssertionNotApplicableException anae) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + catch (AssertionFailException afe) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = validator.createFailureDetail( + afe.getMessage(), entryContext); + } + // Return assertion result + return validator.createAssertionResult( + testAssertion, result, failureDetail); + } + + /** + * Validates mime:part elements. + * @param mimeParts a list of mime:part elements. + * @return true if multiple mime:contentS of a mime:part + * reference different wsdl:partS, false otherwise. + */ + private boolean containsInvalidMimePart(List mimeParts) + { + // Going through a list of mime:part elements + for (int i = 0; i < mimeParts.size(); i++) + { + // A variable that indicates the mime:part contains + // at least one mime:content element + boolean mimeContentFound = false; + String mimeContentPart = null; + + // Going through mime:part extensibility elements + List extElems = ((MIMEPart) mimeParts.get(i)).getExtensibilityElements(); + for (int j = 0; j < extElems.size(); j++) + { + // If an extensibility element is mime:content + if (((ExtensibilityElement)extElems.get(j)) + .getElementType().equals(WSDL_MIME_CONTENT)) + { + MIMEContent mimeContent = (MIMEContent) extElems.get(j); + // If a mime:content element was already found in this mime:part + if (mimeContentFound) + { + multipleContentFound = true; + // If a mime:content references other wsdl:part than the + // previous mime:content do, return true + if (mimeContent.getPart() == null + || !mimeContent.getPart().equals(mimeContentPart)) + { + return true; + } + } + // This is the first mime:content element of mime:part + else + { + mimeContentFound = true; + mimeContentPart = mimeContent.getPart(); + } + } + } + } + // There are no invalid mime:part elements, return false + return false; + } + + /** + * Collects all mime:part elements. + * @param extElems a list of extensibility elements that can contain mime:part elements. + * @return the list of mime:part elements found. + */ + private List getMimeParts(List extElems) + { + List mimeParts = new ArrayList(); + + if (extElems != null) + { + // Going through all the extensibility elements + for (int i = 0; i < extElems.size(); i++) + { + ExtensibilityElement extElem = (ExtensibilityElement) extElems.get(i); + // If the element is mime:multipartRelated + if (extElem.getElementType().equals(WSDL_MIME_MULTIPART)) + { + // Getting the mime:part elements of the mime:multipartRelated + List mParts = ((MIMEMultipartRelated) extElem).getMIMEParts(); + mimeParts.addAll(mParts); + // Going through all the mime:part elements + for (int j = 0; j < mParts.size(); j++) + { + List elems = getMimeParts( + ((MIMEPart) mParts.get(j)).getExtensibilityElements()); + // Adding the elements to the list being returned + mimeParts.addAll(elems); + } + } + } + } + return mimeParts; + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/AP2910.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/AP2910.java new file mode 100644 index 000000000..4ce3a66b0 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/AP2910.java @@ -0,0 +1,230 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +import java.util.ArrayList; +import java.util.List; + +import javax.wsdl.Binding; +import javax.wsdl.BindingInput; +import javax.wsdl.BindingOperation; +import javax.wsdl.BindingOutput; +import javax.wsdl.Input; +import javax.wsdl.Message; +import javax.wsdl.Output; +import javax.wsdl.Part; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.mime.MIMEContent; +import javax.wsdl.extensions.mime.MIMEMultipartRelated; +import javax.wsdl.extensions.mime.MIMEPart; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.WSITag; +import org.eclipse.wst.wsi.internal.analyzer.AssertionFailException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionNotApplicableException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.report.AssertionResult; + +/** + * AP2910 + * + * For a candidate wsdl:binding + * A mime:content in a DESCRIPTION references + * a wsdl:part that is defined using either the type attribute + * or the element attribute. + */ +public class AP2910 extends AssertionProcess implements WSITag +{ + private final WSDLValidatorImpl validator; + + /** + * @param WSDLValidatorImpl + */ + public AP2910(WSDLValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + /* Validates the test assertion. + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + try + { + // A variable that indicates a binding contains at least one + // mime:content element + boolean mimeContentsFound = false; + + // Getting a wsdl:binding + Binding binding = (Binding) entryContext.getEntry().getEntryDetail(); + + // Getting its wsdl:operation elements + List ops = binding.getBindingOperations(); + + // Going through the operation elements + for (int i = 0; i < ops.size(); i++) + { + BindingOperation bindingOperation = (BindingOperation) ops.get(i); + + // Getting wsdl:input and wsdl:output elements of an operation + BindingInput bindingInput = bindingOperation.getBindingInput(); + BindingOutput bindingOutput = bindingOperation.getBindingOutput(); + + // Collecting all the mime:content elements from wsdl:input and wsdl:output + List inputMimeContents = getMimeContentElements( + bindingInput == null ? null : bindingInput.getExtensibilityElements()); + List outputMimeContents = getMimeContentElements( + bindingOutput == null ? null : bindingOutput.getExtensibilityElements()); + + // If the wsdl:input contains mime:content elements + if (!inputMimeContents.isEmpty()) + { + mimeContentsFound = true; + Input portTypeInput = bindingOperation.getOperation().getInput(); + // If there is no the corresponding wsdl:input in wsdl:portType + // or the wsdl:input does not specify a message attribute, + // the assertion failed + if (portTypeInput == null || portTypeInput.getMessage() == null) + throw new AssertionFailException( + "The corresponging operation in the wsdl:portType for the \"" + + bindingOperation.getName() + "\" binding operation is invalid."); + // Getting a mime:content referencing an invalid wsdl:part + String part = getInvalidMimeContentPart( + inputMimeContents, portTypeInput.getMessage()); + // If such part is found, the assertion failed + if (part != null) + throw new AssertionFailException("part=\"" + part + + "\", the input of the binding operation \"" + + bindingOperation.getName() + "\""); + } + + // If the wsdl:output contains mime:content elements + if (!outputMimeContents.isEmpty()) + { + mimeContentsFound = true; + Output portTypeOutput = bindingOperation.getOperation().getOutput(); + // If there is no the corresponding wsdl:output in wsdl:portType + // or the wsdl:output does not specify a message attribute, + // the assertion failed + if (portTypeOutput == null || portTypeOutput.getMessage() == null) + throw new AssertionFailException( + "The corresponging operation in the wsdl:portType for the \"" + + bindingOperation.getName() + "\" binding operation is invalid."); + // Getting a mime:content referencing an invalid wsdl:part + String part = getInvalidMimeContentPart( + outputMimeContents, portTypeOutput.getMessage()); + // If such part is found, the assertion failed + if (part != null) + throw new AssertionFailException("part=\"" + part + + "\", the output of the binding operation \"" + + bindingOperation.getName() + "\""); + } + } + + // If the binding does not contain mime:content elements, + // the assertion is not applicable + if (!mimeContentsFound) + throw new AssertionNotApplicableException(); + } + catch (AssertionNotApplicableException anae) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + catch (AssertionFailException afe) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = validator.createFailureDetail( + afe.getMessage(), entryContext); + } + // Return assertion result + return validator.createAssertionResult( + testAssertion, result, failureDetail); + } + + /** + * Validates every mime:content element. If it references a wsdl:part that + * is defined using neither the type attribute nor the element attribute + * or using them together, it is invalid. + * @param mimeContents a list of mime:content elements. + * @param message the corresponding wsdl:message element for mime:contentS. + * @return a value of the part attribute of an invalid mime:content + * or null if all the mime:content elements are valid. + */ + private String getInvalidMimeContentPart(List mimeContents, Message message) { + // Going throug all the mime:content elements + for (int i = 0; i < mimeContents.size(); i++) + { + // Getting a value of the part attribute from a mime:element + String partName = ((MIMEContent) mimeContents.get(i)).getPart(); + // Getting the corresponging wsdl:part + Part part = message.getPart(partName); + // if it is defined and use neither the type attribute + // nor the element attribute or use them together, return part value + if (part != null + && ((part.getTypeName() == null && part.getElementName() == null) + || (part.getTypeName() != null && part.getElementName() != null))) + { + return partName; + } + } + // Return null if no one part is found + return null; + } + + /** + * Collects all mime:content elements. + * @param extElems a list of extensibility elements that can contain mime:contentS. + * @return the list of mime:content elements found. + */ + private List getMimeContentElements(List extElems) + { + List mimeContentElements = new ArrayList(); + + if (extElems != null) + { + // Going through all the extensibility elements + for (int i = 0; i < extElems.size(); i++) + { + ExtensibilityElement extElem = (ExtensibilityElement) extElems.get(i); + // If the element is mime:multipartRelated + if (extElem.getElementType().equals(WSDL_MIME_MULTIPART)) + { + // Getting the mime:part elements of the mime:multipartRelated + List mimeParts = ((MIMEMultipartRelated) extElem).getMIMEParts(); + // Going through all the mime:part elements + for (int j = 0; j < mimeParts.size(); j++) + { + // Collecting all the mime:content elements of this mime:part + List elems = getMimeContentElements( + ((MIMEPart) mimeParts.get(j)).getExtensibilityElements()); + // Adding the elements to the list being returned + mimeContentElements.addAll(elems); + } + } + // Else if the element is mime:content + else if (extElem.getElementType().equals(WSDL_MIME_CONTENT)) + { + // Adding the element to the list being returned + mimeContentElements.add(extElem); + } + } + } + + return mimeContentElements; + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/AP2911.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/AP2911.java new file mode 100644 index 000000000..8ea214944 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/AP2911.java @@ -0,0 +1,228 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +import java.util.ArrayList; +import java.util.List; + +import javax.wsdl.Binding; +import javax.wsdl.BindingInput; +import javax.wsdl.BindingOperation; +import javax.wsdl.BindingOutput; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.mime.MIMEMultipartRelated; +import javax.wsdl.extensions.mime.MIMEPart; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.WSITag; +import org.eclipse.wst.wsi.internal.analyzer.AssertionFailException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionNotApplicableException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.report.AssertionResult; + +/** + * AP2911 + * + * For a candidate wsdl:binding + * The mime:multipartRelated elements in wsdl:input and wsdl:ouput elements + * of operations in a wsdl:binding, contain exactly one mime:part child element that contains + * a soapbind:body child element. + */ +public class AP2911 extends AssertionProcess implements WSITag +{ + private final WSDLValidatorImpl validator; + + /** + * @param WSDLValidatorImpl + */ + public AP2911(WSDLValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + /* Validates the test assertion. + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + try + { + // A variable that indicates a binding contains at least one + // mime:multipartRelated element + boolean multipartsFound = false; + + // Getting a wsdl:binding + Binding binding = (Binding) entryContext.getEntry().getEntryDetail(); + + // Getting its wsdl:operation elements + List ops = binding.getBindingOperations(); + + // Going through the operation elements + for (int i = 0; i < ops.size(); i++) + { + BindingOperation bindingOperation = (BindingOperation) ops.get(i); + + // Getting wsdl:input and wsdl:output elements of an operation + BindingInput bindingInput = bindingOperation.getBindingInput(); + BindingOutput bindingOutput = bindingOperation.getBindingOutput(); + + // Collecting all the mime:multipartRelated elements from wsdl:input and wsdl:output + List inputMultiparts = getMimeMultipartElements( + bindingInput == null ? null : bindingInput.getExtensibilityElements()); + List outputMultiparts = getMimeMultipartElements( + bindingOutput == null ? null : bindingOutput.getExtensibilityElements()); + + // If the wsdl:input contains mime:multipartRelated elements + if (!inputMultiparts.isEmpty()) + { + multipartsFound = true; + + // If there is not exactly one mime:part element containing + // a soapbind:body child, the assertion failed + if (!containsOneSoapBody(inputMultiparts)) + { + throw new AssertionFailException("The invalid " + + "mime:multipartRelated element is in the wsdl:input of the \"" + + bindingOperation.getName() + "\" binding operation."); + } + } + + // If the wsdl:output contains mime:multipartRelated elements + if (!outputMultiparts.isEmpty()) + { + multipartsFound = true; + + // If there is not exactly one mime:part element containing + // a soapbind:body child, the assertion failed + if (!containsOneSoapBody(outputMultiparts)) + { + throw new AssertionFailException("The invalid " + + "mime:multipartRelated element is in the wsdl:output of the \"" + + bindingOperation.getName() + "\" binding operation."); + } + } + + } + // If the binding contains no one mime:multipartRelated element, + // the assertion is not applicable + if (!multipartsFound) + throw new AssertionNotApplicableException(); + } + catch (AssertionNotApplicableException anae) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + catch (AssertionFailException afe) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = validator.createFailureDetail( + afe.getMessage(), entryContext); + } + // Return assertion result + return validator.createAssertionResult( + testAssertion, result, failureDetail); + } + + /** + * Looks for mime:part elements containing a soap:body child + * for each of mime:multipartRelated element. + * @param multiparts a list of mime:multipartRelated elements. + * @return true if there is exactly one mime:part containing a soap:body + * child, false otherwise. + */ + private boolean containsOneSoapBody(List multiparts) + { + // A variable indicates that a soap:body element is found + boolean soapBodyFound = false; + + // Going through a list of mime:multipartRelated elements + for (int i = 0; i < multiparts.size(); i++) + { + // Getting a list of mime:part elements + List mimeParts = + ((MIMEMultipartRelated) multiparts.get(i)).getMIMEParts(); + + // Going through all the mime:part elements + for (int j = 0; j < mimeParts.size(); j++) + { + // Getting a list of extensibility elements of a mime:part + List extElems = + ((MIMEPart) mimeParts.get(j)).getExtensibilityElements(); + // Going through the extensibility elements + for (int k = 0; k < extElems.size(); k++) + { + // If an extensibility element is a soap:body + if (((ExtensibilityElement)extElems.get(k)) + .getElementType().equals(WSDL_SOAP_BODY)) + { + // If a soap:body element was already found, + // return true + if (soapBodyFound) + { + return false; + } + // else set the variable to the true value + else + { + soapBodyFound = true; + } + } + } + } + } + + return soapBodyFound; + } + + /** + * Collects all mime:multipartRelated elements. + * @param extElems a list of extensibility elements that can contain mime:multipartRelated elements. + * @return the list of mime:multipartRelated elements found. + */ + private List getMimeMultipartElements(List extElems) + { + List mimeMultipartElements = new ArrayList(); + + if (extElems != null) + { + // Going through all the extensibility elements + for (int i = 0; i < extElems.size(); i++) + { + ExtensibilityElement extElem = (ExtensibilityElement) extElems.get(i); + // If the element is mime:multipartRelated + if (extElem.getElementType().equals(WSDL_MIME_MULTIPART)) + { + // Adding the element to the list being returned + mimeMultipartElements.add(extElem); + // Getting the mime:part elements of the mime:multipartRelated + List mimeParts = ((MIMEMultipartRelated) extElem).getMIMEParts(); + // Going through all the mime:part elements + for (int j = 0; j < mimeParts.size(); j++) + { + // Collecting all the mime:multipartRelated elements of this mime:part + List elems = getMimeMultipartElements( + ((MIMEPart) mimeParts.get(j)).getExtensibilityElements()); + // Adding the elements to the list being returned + mimeMultipartElements.addAll(elems); + } + } + } + } + + return mimeMultipartElements; + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/AP2930.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/AP2930.java new file mode 100644 index 000000000..912ff6416 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/AP2930.java @@ -0,0 +1,136 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +import java.util.Collection; +import java.util.Iterator; +import java.util.List; + +import javax.wsdl.Binding; +import javax.wsdl.BindingFault; +import javax.wsdl.BindingOperation; +import javax.wsdl.extensions.ExtensibilityElement; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.WSITag; +import org.eclipse.wst.wsi.internal.analyzer.AssertionFailException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionNotApplicableException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.report.AssertionResult; + +/** + * AP2930 + * + * For a candidate wsdl:binding + * A wsdl:fault element in a description does not have + * mime:multipartRelated element as its child element. + */ +public class AP2930 extends AssertionProcess implements WSITag +{ + private final WSDLValidatorImpl validator; + + /** + * @param WSDLValidatorImpl + */ + public AP2930(WSDLValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + /* Validates the test assertion. + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + try + { + // A variable that indicates a binding contains at least one + // wsdl:fault element + boolean faultsFound = false; + + // Getting a wsdl:binding + Binding binding = (Binding) entryContext.getEntry().getEntryDetail(); + + // Getting its wsdl:operation elements + List ops = binding.getBindingOperations(); + + // Going through the operation elements + for (int i = 0; i < ops.size(); i++) + { + BindingOperation bindingOperation = (BindingOperation) ops.get(i); + + // Getting wsdl:fault elements + Collection faults = bindingOperation.getBindingFaults().values(); + if (!faults.isEmpty()) + { + faultsFound = true; + // If there is at least one mime:multipartRelated element, + // the assertion failed + if (containsMimeMultiparts(faults)) + throw new AssertionFailException("The binding operation is \"" + + bindingOperation.getName() + "\"."); + } + } + + // If the binding does not contain wsdl:fault elements, + // the assertion is not applicable + if (!faultsFound) + throw new AssertionNotApplicableException(); + } + catch (AssertionNotApplicableException anae) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + catch (AssertionFailException afe) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = validator.createFailureDetail( + afe.getMessage(), entryContext); + } + // Return assertion result + return validator.createAssertionResult( + testAssertion, result, failureDetail); + } + + /** + * Validates wsdl:fault elements. + * @param faults a collection of wsdl:fault elements. + * @return true if any wsdl:fault has a mime:multipartRelated child + * element, false otherwise. + */ + private boolean containsMimeMultiparts(Collection faults) + { + // Going through all the wsdl:faultS + Iterator i = faults.iterator(); + while (i.hasNext()) + { + // Getting wsdl:fault's extensibility elements + List extElems = ((BindingFault) i.next()).getExtensibilityElements(); + for (int j = 0; j < extElems.size(); j++) + { + // If there is a mime:multipartRelated element, return true + if (((ExtensibilityElement)extElems.get(j)) + .getElementType().equals(WSDL_MIME_MULTIPART)) + { + return true; + } + } + } + // There are no mime:multipartRelated elements, return false + return false; + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/AP2940.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/AP2940.java new file mode 100644 index 000000000..39ef32745 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/AP2940.java @@ -0,0 +1,450 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import javax.wsdl.Binding; +import javax.wsdl.BindingInput; +import javax.wsdl.BindingOperation; +import javax.wsdl.BindingOutput; +import javax.wsdl.Input; +import javax.wsdl.Message; +import javax.wsdl.Output; +import javax.wsdl.Part; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.UnknownExtensibilityElement; +import javax.wsdl.extensions.mime.MIMEMultipartRelated; +import javax.wsdl.extensions.mime.MIMEPart; +import javax.wsdl.extensions.soap.SOAPBody; +import javax.wsdl.extensions.soap.SOAPHeader; +import javax.xml.namespace.QName; + +import org.apache.xerces.impl.dv.XSSimpleType; +import org.apache.xerces.xs.XSAttributeUse; +import org.apache.xerces.xs.XSComplexTypeDefinition; +import org.apache.xerces.xs.XSConstants; +import org.apache.xerces.xs.XSElementDeclaration; +import org.apache.xerces.xs.XSModel; +import org.apache.xerces.xs.XSModelGroup; +import org.apache.xerces.xs.XSObjectList; +import org.apache.xerces.xs.XSParticle; +import org.apache.xerces.xs.XSTerm; +import org.apache.xerces.xs.XSTypeDefinition; +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.WSITag; +import org.eclipse.wst.wsi.internal.analyzer.AssertionFailException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionNotApplicableException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.w3c.dom.Element; + +/** + * AP2940 + * + * For a candidate wsdl:binding + * In a description, a wsdl:part defined with the + * ref:swaRef schema type is bound to a soapbind:body, or a soapbind:header + * in a MIME binding. + */ +public class AP2940 extends AssertionProcess implements WSITag +{ + private final WSDLValidatorImpl validator; + + /** + * @param WSDLValidatorImpl + */ + public AP2940(WSDLValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + /* Validates the test assertion. + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + try + { + // A variable that indicates wsdl:portType references at least one + // wsdl:part defined with the ref:swaRef schema type + boolean swaRefFound = false; + + // Getting a wsdl:binding + Binding binding = (Binding) entryContext.getEntry().getEntryDetail(); + + // Getting its wsdl:operation elements + List ops = binding.getBindingOperations(); + + // Going through the operation elements + for (int i = 0; i < ops.size(); i++) + { + BindingOperation bindingOperation = (BindingOperation) ops.get(i); + + // Getting wsdl:input and wsdl:output elements of an operation + BindingInput bindingInput = bindingOperation.getBindingInput(); + BindingOutput bindingOutput = bindingOperation.getBindingOutput(); + + Input portTypeInput = bindingOperation.getOperation().getInput(); + Output portTypeOutput = bindingOperation.getOperation().getOutput(); + // If the corresponding wsdl:input exists in wsdl:portType + // and includes the message attribute + if (portTypeInput != null && portTypeInput.getMessage() != null) + { + // Collecting all the message's parts defined with ref:swaRef + List swaRefParts = getSwaRefParts(portTypeInput.getMessage()); + if (!swaRefParts.isEmpty()) + { + swaRefFound = true; + // Getting a wsdl:part that is unbound + String unboundPart = getUnboundPart(swaRefParts, + portTypeInput.getMessage().getQName(), + bindingInput == null ? null : bindingInput.getExtensibilityElements()); + // If such wsdl:part exists, assertion failed + if (unboundPart != null) + throw new AssertionFailException("The part \"" + unboundPart + + "\" is not bound properly to the wsdl:input of the \"" + + bindingOperation.getName() + "\" binding operation."); + } + } + + // If the corresponding wsdl:output exists in wsdl:portType + // and includes the message attribute + if (portTypeOutput != null && portTypeOutput.getMessage() != null) + { + // Collecting all the message's parts defined with ref:swaRef + List swaRefParts = getSwaRefParts(portTypeOutput.getMessage()); + if (!swaRefParts.isEmpty()) + { + swaRefFound = true; + // Getting a wsdl:part that is unbound + String unboundPart = getUnboundPart(swaRefParts, + portTypeOutput.getMessage().getQName(), + bindingOutput == null ? null : bindingOutput.getExtensibilityElements()); + // If such wsdl:part exists, assertion failed + if (unboundPart != null) + throw new AssertionFailException("The part \"" + unboundPart + + "\" is not bound properly to the wsdl:input of the \"" + + bindingOperation.getName() + "\" binding operation."); + } + } + } + + // If there is no wsdl:partS defined with the ref:swaRef + // schema type, the assertion is not applicable + if (!swaRefFound) + throw new AssertionNotApplicableException(); + } + catch (AssertionNotApplicableException anae) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + catch (AssertionFailException afe) + { + // The assertion is "recommended", using the "warning" result + result = AssertionResult.RESULT_WARNING; + failureDetail = validator.createFailureDetail( + afe.getMessage(), entryContext); + } + + // Return assertion result + return validator.createAssertionResult( + testAssertion, result, failureDetail); + } + + /** + * Looks for a wsdl:part that is not bound to either soap:body or soap:header + * in a MIME binding. + * @param swaRefParts a list of wsdl:part names that are defined with the + * ref:swaRef schema type. + * @param messageName the qualified name of the wsdl:message being validated. + * @param extElems a list of extensibility elements of either wsdl:input or + * wsdl:output of the corresponding binding operation. + * @return a wsdl:part name that is not bound properly, or null. + */ + private String getUnboundPart(List swaRefParts, QName messageName, List extElems) { + // Going through wsdl:part names + for (int i = 0; i < swaRefParts.size(); i++) + { + String part = (String) swaRefParts.get(i); + boolean boundProperly = false; + if (extElems != null) + { + // Going through extensibility elements + for (int j = 0; j < extElems.size() && !boundProperly; j++) + { + ExtensibilityElement extElem = (ExtensibilityElement) extElems.get(j); + // If the element is mime:multipartRelated + if (extElem.getElementType().equals(WSDL_MIME_MULTIPART)) + { + // Getting the mime:part elements of the mime:multipartRelated + List mimeParts = ((MIMEMultipartRelated) extElem).getMIMEParts(); + // Getting the first mime:part element where soap:body + // and soap:header could appear + if (mimeParts.size() > 0) + { + List elems = ((MIMEPart) mimeParts.get(0)).getExtensibilityElements(); + // Going through all the MIME part's extensibility elements + for (int k = 0; k < elems.size(); k ++) + { + ExtensibilityElement elem = (ExtensibilityElement) elems.get(k); + // If that is a soap:body + if (elem.getElementType().equals(WSDL_SOAP_BODY)) + { + List pts = ((SOAPBody) elem).getParts(); + // If the part is bound by this element + if (pts == null || pts.contains(part)) + { + boundProperly = true; + break; + } + } + // else if that is a soap:header + else if (elem.getElementType().equals(WSDL_SOAP_HEADER)) + { + if (elem instanceof SOAPHeader) + { + SOAPHeader header = (SOAPHeader) elem; + // If the part is bound by this element + if (messageName.equals(header.getMessage()) + && header.getPart() != null + && header.getPart().equals(part)) + { + boundProperly = true; + break; + } + } + // WSDL4J 1.4 does not recognize soap:header elements that + // are enclosed in mime:multipartRelated, so using a workaround + else + { + Element header = + ((UnknownExtensibilityElement) elem).getElement(); + // If a header references the corresponding message + // and the part is bound by this element + if (referencesMessage(header, messageName) + && header.getAttribute("part").equals(part)) + { + boundProperly = true; + break; + } + } + } + } + } + } + } + } + // If this part is unbound properly, return it + if (!boundProperly) + return part; + } + // All the parts are bound properly, return null + return null; + } + + /** + * Validates whether an element contains a message attribute that references + * a message that have the qualified name specified. + * @param elem an element to be validated. + * @param messageName the qualified name of a message. + * @return true if an element is valid, false otherwise. + */ + private boolean referencesMessage(Element elem, QName messageName) + { + // Getting the element's message attribute + String message = elem.getAttribute("message"); + // finding the colon delimiter + int colonPos = message.indexOf(":"); + String ns = null; + // Getting a local part + String lp = colonPos > -1 ? message.substring(colonPos + 1) : message; + // If the delimiter is found + if (colonPos > -1) + { + // Retrieving a namespace URI + ns = validator.wsdlDocument.getDefinitions() + .getNamespace(message.substring(0, colonPos)); + } + // If the local part and the namespace URI are the same as a message have + if (messageName.getLocalPart().equals(lp) + && messageName.getNamespaceURI().equals(ns)) + { + // element is valid, return true + return true; + } + // element is not valid, return false + return false; + } + + /** + * Collects all the wsdl:part defined with the ref:swaRef schema type. + * @param message a message containig wsdl:part elements. + * @return a list of wsdl:part names. + */ + private List getSwaRefParts(Message message) + { + List swaRefParts = new ArrayList(); + + // Going through message's parts + Iterator it = message.getParts().values().iterator(); + while (it.hasNext()) + { + Part part = (Part) it.next(); + QName ref; + short type; + // Getting either part's element reference or type reference + if ((ref = part.getTypeName()) != null) + { + type = XSConstants.TYPE_DEFINITION; + } + else if ((ref = part.getElementName()) != null) + { + type = XSConstants.ELEMENT_DECLARATION; + } + // The part does conatins neither element nor type attribute, + // proceeding with the next part + else + { + continue; + } + // Getting a list of schemas defined + Map schemas = validator.wsdlDocument.getSchemas(); + // Going through the schemas + Iterator it2 = schemas.values().iterator(); + while (it2.hasNext()) + { + XSModel xsModel = (XSModel) it2.next(); + XSTypeDefinition partType = null; + // Getting the corresponding part type + if (type == XSConstants.ELEMENT_DECLARATION) + { + XSElementDeclaration elem = xsModel.getElementDeclaration( + ref.getLocalPart(), ref.getNamespaceURI()); + if (elem != null) + partType = elem.getTypeDefinition(); + } + else + { + partType = xsModel.getTypeDefinition( + ref.getLocalPart(), ref.getNamespaceURI()); + } + // If the part type is defined using the ref:swaRef schema type + if (referencesSwaRef(partType, new ArrayList())) + { + // Adding the part's name to the list being returned + swaRefParts.add(part.getName()); + } + } + } + // Return the list + return swaRefParts; + } + + /** + * Check schema type whether it contains ref:swaRef simple schema type + * or has an attribute of this schema type. + * @param xsType a schema type definition element + * @return true, if schema type contains ref:swaRef, false otherwise. + */ + private boolean referencesSwaRef(XSTypeDefinition xsType, List types) + { + if ((xsType != null) && (!types.contains(xsType))) + { + types.add(xsType); + // If this is a complex type + if (xsType.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE) + { + XSComplexTypeDefinition xsComplexType = + (XSComplexTypeDefinition) xsType; + // If it contains mixed context + // check whether the context contains ref:swaRef + if (xsComplexType.getParticle() != null + && referencesSwaRef(xsComplexType.getParticle().getTerm(), types)) + { + return true; + } + // Getting the type's attributes + XSObjectList attrList = xsComplexType.getAttributeUses(); + for (int i = 0; i < attrList.getLength(); i++) + { + XSAttributeUse xsAttrUse = (XSAttributeUse) attrList.item(i); + // If an attribute is defined using ref:swaRef, return true + if (referencesSwaRef( + xsAttrUse.getAttrDeclaration().getTypeDefinition(), types)) + { + return true; + } + } + } + // else if this is a simple type + else if (xsType.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE) + { + XSSimpleType xsSimpleType = (XSSimpleType) xsType; + // If this type is ref:swaRef, return true + if (xsSimpleType.getNamespace().equals(WSIConstants.NS_URI_SWA_REF) + && xsSimpleType.getName().equals(WSIConstants.SCHEMA_TYPE_SWA_REF)) + { + return true; + } + } + } + // The schema type does not contain any element defined with the ref:swaRef + // return false + return false; + } + + /** + * Checks a term whether it is defined with ref:swaRef. + * @param term a term that can be one of a model group or an + * element declaration. + * @return true if a term is defined with ref:swaRef, false otherwise. + */ + private boolean referencesSwaRef(XSTerm term, List types) + { + // If a term is an element declaration + if (term.getType() == XSConstants.ELEMENT_DECLARATION) + { + // If element's type is defined with the ref:swaRef, return true + if (referencesSwaRef( + ((XSElementDeclaration) term).getTypeDefinition(), types)) + { + return true; + } + } + // else if a term is a model group + else if(term.getType() == XSConstants.MODEL_GROUP) + { + // Getting a list of Particle schema components + XSObjectList list = ((XSModelGroup) term).getParticles(); + for (int i = 0; i < list.getLength(); i++) + { + // If the term of a particle is defined with the ref:swaRef, + // return true + if (referencesSwaRef(((XSParticle) list.item(i)).getTerm(), types)) + { + return true; + } + } + } + return false; + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/AP2941.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/AP2941.java new file mode 100644 index 000000000..da00ec185 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/AP2941.java @@ -0,0 +1,341 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; + +import javax.wsdl.Binding; +import javax.wsdl.BindingFault; +import javax.wsdl.BindingOperation; +import javax.wsdl.Input; +import javax.wsdl.Message; +import javax.wsdl.Output; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.UnknownExtensibilityElement; +import javax.wsdl.extensions.mime.MIMEContent; +import javax.wsdl.extensions.mime.MIMEMultipartRelated; +import javax.wsdl.extensions.mime.MIMEPart; +import javax.wsdl.extensions.soap.SOAPBody; +import javax.wsdl.extensions.soap.SOAPFault; +import javax.wsdl.extensions.soap.SOAPHeader; +import javax.wsdl.extensions.soap.SOAPHeaderFault; +import javax.xml.namespace.QName; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.WSITag; +import org.eclipse.wst.wsi.internal.analyzer.AssertionFailException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; +import org.w3c.dom.Element; + +/** + * AP2941 + * + * For a candidate wsdl:binding + * A wsdl:binding in a description binds every wsdl:part + * of a wsdl:message in the wsdl:portType to which it refers to one of + * soapbind:body, soapbind:header, soapbind:fault , soapbind:headerfault, + * or mime:content. + */ +public class AP2941 extends AssertionProcess implements WSITag +{ + private final WSDLValidatorImpl validator; + + /** + * @param WSDLValidatorImpl + */ + public AP2941(WSDLValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + /* Validates the test assertion. + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + try + { + // Getting a wsdl:binding + Binding binding = (Binding) entryContext.getEntry().getEntryDetail(); + + // Getting its wsdl:operation elements + List ops = binding.getBindingOperations(); + + // Going through the operation elements + for (int i = 0; i < ops.size(); i++) + { + BindingOperation bindingOperation = (BindingOperation) ops.get(i); + Input portTypeInput = bindingOperation.getOperation().getInput(); + Output portTypeOutput = bindingOperation.getOperation().getOutput(); + // If the corresponding wsdl:input exists in wsdl:portType + // and includes the message attribute + if (portTypeInput != null && portTypeInput.getMessage() != null) + { + // Getting the list of all the parts bound by wsdl:input's child elements + List inputParts = getBindingParts( + bindingOperation.getBindingInput().getExtensibilityElements(), + portTypeInput.getMessage()); + // If not true that all the wsdl:partS are bound, + // the assertion failed + if (!inputParts + .containsAll(portTypeInput.getMessage().getParts().keySet())) + { + throw new AssertionFailException("The wsdl:input of the \"" + + bindingOperation.getName() + "\" binding operation does not " + + "bind all the corresponding wsdl:partS."); + } + } + + // If the corresponding wsdl:output exists in wsdl:portType + // and includes the message attribute + if (portTypeOutput != null && portTypeOutput.getMessage() != null) + { + // Getting the list of all the parts bound by wsdl:output's child elements + List outputParts = getBindingParts( + bindingOperation.getBindingOutput().getExtensibilityElements(), + portTypeOutput.getMessage()); + // If not true that all the wsdl:partS are bound, + // the assertion failed + if (!outputParts + .containsAll(portTypeOutput.getMessage().getParts().keySet())) + { + throw new AssertionFailException("The wsdl:output of the \"" + + bindingOperation.getName() + "\" binding operation does not " + + "bind all the corresponding wsdl:partS."); + } + } + + // IF there are wsdl:faultS in the wsdl:portType operation + if (!bindingOperation.getOperation().getFaults().isEmpty()) + { + // Collecting all the soap:fault names + List faultNames = new ArrayList(); + Collection faults = bindingOperation.getBindingFaults().values(); + // Going through all the wsdl:faultS + Iterator it = faults.iterator(); + while (it.hasNext()) + { + // Getting wsdl:fault's extensibility elements + List extElems = ((BindingFault) it.next()).getExtensibilityElements(); + for (int j = 0; j < extElems.size(); j++) + { + if (((ExtensibilityElement)extElems.get(j)) + .getElementType().equals(WSDL_SOAP_FAULT)) + { + faultNames.add(((SOAPFault)extElems.get(j)).getName()); + } + } + } + // If not true that all the wsdl:faultS are bound, + // the assertion failed + if (!faultNames.containsAll( + bindingOperation.getOperation().getFaults().keySet())) + { + throw new AssertionFailException("The binding operation \"" + + bindingOperation.getName() + "\" does not " + + "bind all the corresponding wsdl:faultS."); + } + } + } + } + catch (AssertionFailException afe) + { + // The assertion is "recommended", using the "warning" result + result = AssertionResult.RESULT_WARNING; + failureDetail = validator.createFailureDetail( + afe.getMessage(), entryContext); + } + // Return assertion result + return validator.createAssertionResult( + testAssertion, result, failureDetail); + } + + /** + * Collects all the parts bound by extensibility elements. + * @param extElems a lit of extensibility elements. + * @param message the wsdl:message element corresponging + * to the extensibility elements. + * @return a list of wsdl:part names bound. + */ + private List getBindingParts(List extElems, Message message) + { + List parts = new ArrayList(); + if (extElems != null) + { + // Going through the extensibility elements + for (int i = 0; i < extElems.size(); i++) + { + ExtensibilityElement extElem = (ExtensibilityElement) extElems.get(i); + // If that is a soap:body + if (extElem.getElementType().equals(WSDL_SOAP_BODY)) + { + // Adding all the parts bound to the list + List pts = ((SOAPBody) extElem).getParts(); + if (pts != null) + { + parts.addAll(pts); + } + // else the parts attribute is omitted, + // all parts defined by the message are assumed to be included + // in the SOAP Body portion. + else + { + parts.addAll(message.getParts().keySet()); + } + } + // else if that is a soap:header + else if (extElem.getElementType().equals(WSDL_SOAP_HEADER)) + { + List headerFaults = null; + if (extElem instanceof SOAPHeader) + { + SOAPHeader header = (SOAPHeader) extElem; + // If a header references the corresponding message, + // adding part name to the list + if (message.getQName().equals(header.getMessage())) + parts.add(header.getPart()); + + headerFaults = header.getSOAPHeaderFaults(); + } + // WSDL4J 1.4 does not recognize soap:header elements that are enclosed + // in mime:multipartRelated, so using a workaround + else + { + Element header = + ((UnknownExtensibilityElement) extElem).getElement(); + // If a header references the corresponding message, + // adding part name to the list + if (referencesMessage(header, message.getQName())) + parts.add(header.getAttribute("part")); + // Collecting soap:headerfault elements for the header + headerFaults = getHeaderFaults(header); + } + // Going through the soap:headerfaultS + for (int j = 0; j < headerFaults.size(); j++) + { + if (headerFaults.get(j) instanceof SOAPHeaderFault) + { + SOAPHeaderFault shf = (SOAPHeaderFault) headerFaults.get(j); + // If a soap:headerfault references the corresponding + // message, adding part name to the list + if (message.equals(shf.getMessage())) + parts.add(shf.getPart()); + } + // the same workaround... + else + { + Element shf = (Element) headerFaults.get(j); + // If a soap:headerfault references the corresponding + // message, adding part name to the list + if (referencesMessage(shf, message.getQName())) + parts.add(shf.getAttribute("part")); + } + } + } + // else if that is a mime:content + else if (extElem.getElementType().equals(WSDL_MIME_CONTENT)) + { + // adding part name to the list + parts.add(((MIMEContent) extElem).getPart()); + } + // else if that is a mime:multipartRelated + else if (extElem.getElementType().equals(WSDL_MIME_MULTIPART)) + { + // Getting the mime:part elements of the mime:multipartRelated + List mimeParts = ((MIMEMultipartRelated) extElem).getMIMEParts(); + // Going through all the mime:part elements + for (int j = 0; j < mimeParts.size(); j++) + { + // Collecting all the values of part attributes + // of mime:part's extensibility elements + parts.addAll(getBindingParts( + ((MIMEPart) mimeParts.get(j)).getExtensibilityElements(), + message)); + } + } + } + } + return parts; + } + + /** + * Validates whether an element contains a message attribute that references + * a message that have the qualified name specified. + * @param elem an element to be validated. + * @param messageName the qualified name of a message. + * @return true if an element is valid, false otherwise. + */ + private boolean referencesMessage(Element elem, QName messageName) + { + // Getting the element's message attribute + String message = elem.getAttribute("message"); + // finding the colon delimiter + int colonPos = message.indexOf(":"); + String ns = null; + // Getting a local part + String lp = colonPos > -1 ? message.substring(colonPos + 1) : message; + // If the delimiter is found + if (colonPos > -1) + { + // Retrieving a namespace URI + ns = validator.wsdlDocument.getDefinitions() + .getNamespace(message.substring(0, colonPos)); + } + // If the local part and the namespace URI are the same as a message have + if (messageName.getLocalPart().equals(lp) + && messageName.getNamespaceURI().equals(ns)) + { + // element is valid, return true + return true; + } + // element is not valid, return false + return false; + } + + /** + * Collects all the element's child elements of the soap:headerfault type. + * @param element an element that can have soap:headerfault elements. + * @return the list of soap:headerfault elements found. + */ + private List getHeaderFaults(Element element) + { + List headerFaults = new ArrayList(); + if (element != null) + { + // Getting the first header's child + Element child = XMLUtils.getFirstChild(element); + while (child != null) + { + // If the child is soap:headerfault + if (child.getNamespaceURI().equals(WSDL_SOAP_HEADERFAULT.getNamespaceURI()) + && child.getLocalName().equals(WSDL_SOAP_HEADERFAULT.getLocalPart())) + { + // Adding the child to the list + headerFaults.add(child); + } + // Getting the next header's child + child = XMLUtils.getNextSibling(child); + } + } + return headerFaults; + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/AP2944.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/AP2944.java new file mode 100644 index 000000000..8ed6c1809 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/AP2944.java @@ -0,0 +1,234 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +import java.util.ArrayList; +import java.util.List; + +import javax.wsdl.Binding; +import javax.wsdl.BindingInput; +import javax.wsdl.BindingOperation; +import javax.wsdl.BindingOutput; +import javax.wsdl.Input; +import javax.wsdl.Message; +import javax.wsdl.Output; +import javax.wsdl.Part; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.mime.MIMEContent; +import javax.wsdl.extensions.mime.MIMEMultipartRelated; +import javax.wsdl.extensions.mime.MIMEPart; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.WSITag; +import org.eclipse.wst.wsi.internal.analyzer.AssertionFailException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionNotApplicableException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.report.AssertionResult; + +/** + * AP2944 + * + * For a candidate wsdl:binding + * In a DESCRIPTION, if a wsdl:part element refers to a + * global element declaration (via the element attribute of the wsdl:part element) + * then the value of the type attribute of a mime:content element that binds that part + * is a content type suitable for carrying an XML serialization. + */ +public class AP2944 extends AssertionProcess implements WSITag +{ + private final WSDLValidatorImpl validator; + + // A variable that indicates a binding contains mime:content elements + // that bind wsdl:partS defined with the element attribute + private boolean mimeContentFound; + /** + * @param WSDLValidatorImpl + */ + public AP2944(WSDLValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + /* Validates the test assertion. + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + // Resetting the variable + mimeContentFound = false; + + try + { + // Getting a wsdl:binding + Binding binding = (Binding) entryContext.getEntry().getEntryDetail(); + + // Getting its wsdl:operation elements + List ops = binding.getBindingOperations(); + + // Going through the operation elements + for (int i = 0; i < ops.size(); i++) + { + BindingOperation bindingOperation = (BindingOperation) ops.get(i); + + // Getting wsdl:input and wsdl:output elements of an operation + BindingInput bindingInput = bindingOperation.getBindingInput(); + BindingOutput bindingOutput = bindingOperation.getBindingOutput(); + + // Collecting all the mime:content elements from wsdl:input and wsdl:output + List inputMimeContents = getMimeContentElements( + bindingInput == null ? null : bindingInput.getExtensibilityElements()); + List outputMimeContents = getMimeContentElements( + bindingOutput == null ? null : bindingOutput.getExtensibilityElements()); + + // If the wsdl:input contains mime:content elements + if (!inputMimeContents.isEmpty()) + { + Input portTypeInput = bindingOperation.getOperation().getInput(); + // If the corresponding wsdl:input exists in wsdl:portType + // and includes the message attribute + if (portTypeInput != null && portTypeInput.getMessage() != null) + { + // If there is an invalid mime:content element + MIMEContent imc = getInvalidMimeContent( + inputMimeContents, portTypeInput.getMessage()); + if (imc != null) + { + throw new AssertionFailException("The mime:content element in " + + "the wsdl:input of the \"" + bindingOperation.getName() + + "\" that binds the \"" + imc.getPart() + + "\" wsdl:part uses the invalid content type \"" + + imc.getType() + "\". "); + } + } + } + + // If the wsdl:output contains mime:content elements + if (!outputMimeContents.isEmpty()) + { + Output portTypeOutput = bindingOperation.getOperation().getOutput(); + // If the corresponding wsdl:output exists in wsdl:portType + // and includes the message attribute + if (portTypeOutput != null && portTypeOutput.getMessage() != null) + { + // If there is an invalid mime:content element + MIMEContent imc = getInvalidMimeContent( + outputMimeContents, portTypeOutput.getMessage()); + if (imc != null) + { + throw new AssertionFailException("The mime:content element in " + + "the wsdl:output of the \"" + bindingOperation.getName() + + "\" that binds the \"" + imc.getPart() + + "\" wsdl:part uses the invalid content type \"" + + imc.getType() + "\". "); + } + } + } + } + // If mime:content elements are not found, + // the assertion is not applicable + if (!mimeContentFound) + throw new AssertionNotApplicableException(); + } + catch (AssertionNotApplicableException anae) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + catch (AssertionFailException afe) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = validator.createFailureDetail( + afe.getMessage(), entryContext); + } + // Return assertion result + return validator.createAssertionResult( + testAssertion, result, failureDetail); + } + + /** + * Checks whether any mime:content element binds wsdl:part that is defined + * with the element attribute and uses the content type "text/xml". + * @param mimeContents a list of mime:content elements of binding operation. + * @param message the corresponding wsdl:message element. + * @return a mime:content element that uses a content type other than + * "text/xml", null if no one such element is found. + */ + private MIMEContent getInvalidMimeContent(List mimeContents, Message message) + { + // Going through a list of mime:content elements + for (int i = 0; i < mimeContents.size(); i++) + { + MIMEContent mimeContent = (MIMEContent) mimeContents.get(i); + // Getting the corresponding wsdl:part + Part part = message.getPart(mimeContent.getPart()); + // If the part is defined with the element attribute + if (part != null && part.getElementName() != null) + { + mimeContentFound = true; + // If the type attribute value is other than "text/xml" + if (!WSIConstants.CONTENT_TYPE_TEXT_XML.equals(mimeContent.getType())) + { + // return the invalid element + return mimeContent; + } + } + } + return null; + } + + /** + * Collects all mime:content elements. + * @param extElems a list of extensibility elements that can contain mime:contentS. + * @return the list of mime:content elements found. + */ + private List getMimeContentElements(List extElems) + { + List mimeContentElements = new ArrayList(); + + if (extElems != null) + { + // Going through all the extensibility elements + for (int i = 0; i < extElems.size(); i++) + { + ExtensibilityElement extElem = (ExtensibilityElement) extElems.get(i); + // If the element is mime:multipartRelated + if (extElem.getElementType().equals(WSDL_MIME_MULTIPART)) + { + // Getting the mime:part elements of the mime:multipartRelated + List mimeParts = ((MIMEMultipartRelated) extElem).getMIMEParts(); + // Going through all the mime:part elements + for (int j = 0; j < mimeParts.size(); j++) + { + // Collecting all the mime:content elements of this mime:part + List elems = getMimeContentElements( + ((MIMEPart) mimeParts.get(j)).getExtensibilityElements()); + // Adding the elements to the list being returned + mimeContentElements.addAll(elems); + } + } + // Else if the element is mime:content + else if (extElem.getElementType().equals(WSDL_MIME_CONTENT)) + { + // Adding the element to the list being returned + mimeContentElements.add(extElem); + } + } + } + + return mimeContentElements; + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/AP2946.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/AP2946.java new file mode 100644 index 000000000..54c4f99d4 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/AP2946.java @@ -0,0 +1,194 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +import java.util.ArrayList; +import java.util.List; + +import javax.wsdl.Binding; +import javax.wsdl.BindingInput; +import javax.wsdl.BindingOperation; +import javax.wsdl.BindingOutput; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.mime.MIMEContent; +import javax.wsdl.extensions.mime.MIMEMultipartRelated; +import javax.wsdl.extensions.mime.MIMEPart; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.WSITag; +import org.eclipse.wst.wsi.internal.analyzer.AssertionFailException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionNotApplicableException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.report.AssertionResult; + +/** + * AP2946 + * + * For a candidate wsdl:binding with at least one mime:content element + * In a DESCRIPTION, a mime:content element + * includes the part attribute. + */ +public class AP2946 extends AssertionProcess implements WSITag +{ + private final WSDLValidatorImpl validator; + + /** + * @param WSDLValidatorImpl + */ + public AP2946(WSDLValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + /* Validates the test assertion. + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + try + { + // A variable that indicates a binding contains at least one + // mime:content element + boolean mimeContentsFound = false; + + // Getting a wsdl:binding + Binding binding = (Binding) entryContext.getEntry().getEntryDetail(); + + // Getting its wsdl:operation elements + List ops = binding.getBindingOperations(); + + // Going through the operation elements + for (int i = 0; i < ops.size(); i++) + { + BindingOperation bindingOperation = (BindingOperation) ops.get(i); + + // Getting wsdl:input and wsdl:output elements of an operation + BindingInput bindingInput = bindingOperation.getBindingInput(); + BindingOutput bindingOutput = bindingOperation.getBindingOutput(); + + // Collecting all the mime:content elements from wsdl:input and wsdl:output + List inputMimeContents = getMimeContentElements( + bindingInput == null ? null : bindingInput.getExtensibilityElements()); + List outputMimeContents = getMimeContentElements( + bindingOutput == null ? null : bindingOutput.getExtensibilityElements()); + + // If the wsdl:input contains mime:content elements + if (!inputMimeContents.isEmpty()) + { + mimeContentsFound = true; + // If there is a mime:content that does not include + // the part attribute, the assertion failed + if (hasInvalidMimeContent(inputMimeContents)) + throw new AssertionFailException("The invalid mime:content element" + + " is in the wsdl:input of the \"" + bindingOperation.getName() + + "\" binding operation."); + } + + // If the wsdl:output contains mime:content elements + if (!outputMimeContents.isEmpty()) + { + mimeContentsFound = true; + // If there is a mime:content that does not include + // the part attribute, the assertion failed + if (hasInvalidMimeContent(outputMimeContents)) + throw new AssertionFailException("The invalid mime:content element" + + " is in the wsdl:output of the \"" + bindingOperation.getName() + + "\" binding operation."); + } + } + + // If the binding contains no mime:content elements, + // the assertion is not applicable + if (!mimeContentsFound) + throw new AssertionNotApplicableException(); + } + catch (AssertionNotApplicableException anae) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + catch (AssertionFailException afe) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = validator.createFailureDetail( + afe.getMessage(), entryContext); + } + // Return assertion result + return validator.createAssertionResult( + testAssertion, result, failureDetail); + } + + /** + * Collects all mime:content elements. + * @param extElems a list of extensibility elements that can contain mime:contentS. + * @return the list of mime:content elements found. + */ + private List getMimeContentElements(List extElems) + { + List mimeContentElements = new ArrayList(); + + if (extElems != null) + { + // Going through all the extensibility elements + for (int i = 0; i < extElems.size(); i++) + { + ExtensibilityElement extElem = (ExtensibilityElement) extElems.get(i); + // If the element is mime:multipartRelated + if (extElem.getElementType().equals(WSDL_MIME_MULTIPART)) + { + // Getting the mime:part elements of the mime:multipartRelated + List mimeParts = ((MIMEMultipartRelated) extElem).getMIMEParts(); + // Going through all the mime:part elements + for (int j = 0; j < mimeParts.size(); j++) + { + // Collecting all the mime:content elements of this mime:part + List elems = getMimeContentElements( + ((MIMEPart) mimeParts.get(j)).getExtensibilityElements()); + // Adding the elements to the list being returned + mimeContentElements.addAll(elems); + } + } + // Else if the element is mime:content + else if (extElem.getElementType().equals(WSDL_MIME_CONTENT)) + { + // Adding the element to the list being returned + mimeContentElements.add(extElem); + } + } + } + + return mimeContentElements; + } + + /** + * Validates mime:content elements. + * @param mimeContents a list of mime:content elements. + * @return true if any mime:content does not include the part attribute, + * false otherwise + */ + private boolean hasInvalidMimeContent(List mimeContents) + { + // Going through a list of mime:content elements + for (int i = 0; i < mimeContents.size(); i++) + { + // If a mime:content does not include the part attribute, return true + if (((MIMEContent) mimeContents.get(i)).getPart() == null) + return true; + } + // There are no invalid mime:contentS, return false + return false; + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2010.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2010.java new file mode 100644 index 000000000..8e585f8ed --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2010.java @@ -0,0 +1,119 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; + +import javax.wsdl.Operation; +import javax.wsdl.PortType; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionFailException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.report.AssertionResult; + + +/** +* BP2010. +* "Name" attributes of Operations are unique across the wsdl:portType definition +* +* @version 1.0.1 27.06.2003 +* @author Vitali Fedosenko +**/ +public class BP2010 extends AssertionProcess +{ + private final WSDLValidatorImpl validator; + + /** + * @param WSDLValidatorImpl + */ + public BP2010(WSDLValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + /* Validates the test assertion. + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + + // Get the portType from the entry context + PortType portType = (PortType) entryContext.getEntry().getEntryDetail(); + + // Check the operations names for uniqueness within the candidate Port Type in the WSDL + Iterator ops; + HashSet namesSeen = new HashSet(); + HashSet duplicates = new HashSet(); + try + { + List opsList = portType.getOperations(); + if (opsList == null) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + // no operations found in portType + } + else + { + ops = opsList.iterator(); // will use Candidate.getOperations() + while (ops.hasNext()) + { + Operation op = (Operation) ops.next(); + String opName = op.getName(); + if (namesSeen.contains(opName)) + { + duplicates.add(opName); + } + else + { + namesSeen.add(opName); + } + } + } + + if (!duplicates.isEmpty()) + { + StringBuffer failInfo = + new StringBuffer( + "Duplicate operation names in portType " + + portType.getQName() + + ": "); + Iterator i = duplicates.iterator(); + while (i.hasNext()) + { + failInfo.append((String) i.next() + "; "); + } + throw new AssertionFailException(failInfo.toString()); + } + } + catch (NullPointerException e) + { // ?? no operations found, but does not fail the assertion. + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + catch (AssertionFailException e) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = + this.validator.createFailureDetail(e.getMessage(), entryContext, portType); + } + + // Return assertion result + return validator.createAssertionResult(testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2011.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2011.java new file mode 100644 index 000000000..f81d23c2f --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2011.java @@ -0,0 +1,343 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +import java.io.FileInputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.Enumeration; +import java.util.Iterator; +import java.util.List; + +import javax.wsdl.Definition; +import javax.wsdl.Types; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.UnknownExtensibilityElement; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.WSITag; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.ErrorList; +import org.eclipse.wst.wsi.internal.util.StringTokenizer; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; +import org.w3c.dom.Attr; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; + + +/** + * BP2011. + * The imported XML schema is a well-formed XML 1.0 document and if it contains an + * XML declaration, it is version 1.0. + * + * @version 1.0.1 27.06.2003 + * @author Vitali Fedosenko +**/ +public class BP2011 extends AssertionProcess implements WSITag +{ + private final WSDLValidatorImpl validator; + + /** + * @param WSDLValidatorImpl + */ + public BP2011(WSDLValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + private ErrorList errors = new ErrorList(); + + private final char[] OMMITED_XML_DECLARATION_DELIMITERS = + new char[] { 0x20, 0x9, 0xD, 0xA, '\'', '\"' }; + private final char[] XML_DECLARATION_DELIMITERS = new char[] { '=' }; + private final String VERSION_TOKEN = "version"; + private final String VERSION = "1.0"; + + /* Validates the test assertion. + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + result = result = AssertionResult.RESULT_NOT_APPLICABLE; + + //Definition def = (Definition) entryContext.getEntry().getEntryDetail(); + Types types = (Types) entryContext.getEntry().getEntryDetail(); + + List exts = null; + //if (def.getTypes()!=null) + if (types != null) + { + exts = types.getExtensibilityElements(); + } + if (exts != null) + { + Definition definition = null; + if ((definition = + validator.analyzerContext.getCandidateInfo().getDefinition(types)) + == null) + { + throw new WSIException("Could not find types definition in any WSDL document."); + } + + Iterator it = exts.iterator(); + while (it.hasNext()) + { + ExtensibilityElement el = (ExtensibilityElement) it.next(); + if (el instanceof UnknownExtensibilityElement) + searchForSchema(((UnknownExtensibilityElement) el).getElement(), + definition.getDocumentBaseURI()); + } + } + + if (!errors.isEmpty()) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = this.validator.createFailureDetail(errors.toString(), entryContext); + } /*else + result = AssertionResult.RESULT_PASSED;*/ + + return validator.createAssertionResult(testAssertion, result, failureDetail); + } + + /* Search xsd schema or xsd import from node. If node is xsd import it's loading schema. + * @param n - UnknownExtencibilityElement + */ + private void searchForSchema(Node n, String context) + { + while (n != null) + { + // searches for xsd:import element + if (Node.ELEMENT_NODE == n.getNodeType()) + { + // if xsd:schema element is found -> process schema + if (XMLUtils.equals(n, ELEM_XSD_SCHEMA)) + processSchema(n, context); + else + // if xsd:import element is found -> load schema and process schema + // FIXED: if xsd:import is found and parent element is xsd:schema + if (XMLUtils.equals(n, ELEM_XSD_IMPORT) + && XMLUtils.equals(n.getParentNode(), ELEM_XSD_SCHEMA)) + loadSchema(n, context); + else + // else iterate element recursively + searchForSchema(n.getFirstChild(), context); + } + n = n.getNextSibling(); + } + } + + /* + * It loads xsd schema and then check the version 1.0 and looking for xsd:schema element for next process. + * @param importNode xsd schema + */ + private void loadSchema(Node importNode, String context) + { + Element im = (Element) importNode; + Attr schemaLocation = XMLUtils.getAttribute(im, ATTR_XSD_SCHEMALOCATION); + // try to parse imported XSD + if (schemaLocation != null && schemaLocation.getValue() != null) + { + try + { + // if any error or root element is not XSD schema -> error + String decl = + readXMLDeclarationStatement(schemaLocation.getValue(), context); + if (!validVersion(decl)) + { + Attr a = XMLUtils.getAttribute(im, ATTR_XSD_NAMESPACE); + errors.add((a != null) ? a.getValue() : ""); + } + Document schema = + validator.parseXMLDocumentURL(schemaLocation.getValue(), context); + if (XMLUtils.equals(schema.getDocumentElement(), ELEM_XSD_SCHEMA)) + { + Attr a = XMLUtils.getAttribute(im, ATTR_XSD_NAMESPACE); + String namespace = (a != null) ? a.getValue() : ""; + processSchema(schema.getDocumentElement(), + XMLUtils.createURLString(schemaLocation.getValue(), context)); + } + result = AssertionResult.RESULT_PASSED; + } + catch (Throwable t) + { + } + } + // else if there is only the namespace attribute, the import relates to inline schema + else if (XMLUtils.getAttribute(im, ATTR_XSD_NAMESPACE) != null) + { + result = AssertionResult.RESULT_PASSED; + } + } + + /** + * Reads an XML declaration statement. + * @param location + * @return String + */ + private String readXMLDeclarationStatement(String location, String baseURI) + { + String result = null; + try + { + new URL(location); + } + catch (Throwable t) + { + // nothing + int i = baseURI.lastIndexOf('/'); + int j = baseURI.lastIndexOf('\\'); + if (j > i) + i = j; + location = baseURI.substring(0, i + 1) + location; + } + + if (location != null) + { + URL url = null; + Reader reader = null; + + try + { + try + { + url = new URL(location); + } + catch (MalformedURLException e) + { + // we should try to access location as file + } + + if (url != null) + { + reader = new InputStreamReader(url.openStream()); + } + else + { + reader = new InputStreamReader(new FileInputStream(location)); + } + + int charCode; + boolean end = false; + if (reader.ready()) + { + charCode = reader.read(); + + while (reader.ready() && !(charCode == '<')) + { + charCode = reader.read(); + } + + StringBuffer buf = new StringBuffer(); + if (charCode == '<') + { + buf.append((char) charCode); + while (reader.ready() && !end) + { + charCode = reader.read(); + buf.append((char) charCode); + + end = charCode == '>'; + } + } + else + { + // NOTE: This result does not get propogated back! + result = AssertionResult.RESULT_FAILED; + failureDetailMessage = + "Cannot read the XML declaration statement."; + } + + result = buf.toString(); + } + } + catch (Exception e) + { + } + finally + { + if (reader != null) + { + try + { + reader.close(); + } + catch (Throwable e) + { + } + } + } + } + + return result; + } + + /* + * @param xmlDecl - xml declaration + * @return if xml declaration contains version="1.0" it retirns true. + */ + private boolean validVersion(String xmlDecl) + { + //boolean result = false; + boolean result = true; + if (xmlDecl != null) + { + StringTokenizer st = + new StringTokenizer( + OMMITED_XML_DECLARATION_DELIMITERS, + XML_DECLARATION_DELIMITERS); + Enumeration tokens = st.parse(xmlDecl); + boolean found = false; + while (tokens.hasMoreElements() && !found) + { + String token = (String) tokens.nextElement(); + + if (token.equalsIgnoreCase(VERSION_TOKEN)) + { + found = true; + + tokens.nextElement(); + String ver = (String) tokens.nextElement(); + + result = VERSION.equals(ver); + } + } + } + + return result; + } + + /* + * It's loking for xsd import and load it if find. + * @param schema xsd schema + */ + private void processSchema(Node schema, String context) + { + Node n = schema.getFirstChild(); + while (n != null) + { + if (Node.ELEMENT_NODE == n.getNodeType() + && XMLUtils.equals(n, ELEM_XSD_IMPORT)) + loadSchema(n, context); + + n = n.getNextSibling(); + } + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2012.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2012.java new file mode 100644 index 000000000..c25e7ba65 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2012.java @@ -0,0 +1,123 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +import javax.wsdl.Binding; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionFailException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl.WSDLValidatorImpl.BindingMatch; +import org.eclipse.wst.wsi.internal.report.AssertionResult; + + +/** + * BP2012. + * Example: + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * ..... + * ...... + * + * + * + * Above, the test for this assertion might be that the element attribute is specified in the "refresh" + * part of the getConfigurationOptionsRequest message. + * + * Context : for "ConfiguratorBinding", style=document; use=literal + * for the of binding operation "getConfigurationOptions". + * ( is an example. Could be or equally). + * Action: check the part(s) of the message specified in the element (in example) of the , + * namely tns:getConfigurationOptionsRequest, that the element attribute is specified. In this case we have + * , so the test passes. + * All such parts associated with the assertion candidate binding(s) must be similarly checked for this assertion + * to pass. + */ +public class BP2012 extends AssertionProcess +{ + private final WSDLValidatorImpl validator; + + /** + * @param WSDLValidatorImpl + */ + public BP2012(WSDLValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + /* + * Validates the test assertion. + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + // Get binding from entry context + + // Oleg's & Graham's version: + Binding binding = (Binding) entryContext.getEntry().getEntryDetail(); + + // to use original version require a binding array + //Binding[] binding = {(Binding) entryContext.getEntry().getEntryDetail()}; + + // get list of candidate matches + BindingMatch[] bindingMatch = + this.validator.getBindingMatches( + binding, + WSIConstants.ATTRVAL_SOAP_BIND_STYLE_DOC, + WSIConstants.ATTRVAL_SOAP_BODY_USE_LIT); + if (bindingMatch.length == 0) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + else + try + { + if (!this.validator.checkPartAttributes(bindingMatch, "useInput", "useElement") + || !this.validator.checkPartAttributes(bindingMatch, "useOutput", "useElement")) + { + // this should never happen + throw new AssertionFailException("diagnostic: internal processing error!"); + } + } + catch (AssertionFailException e) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = + this.validator.createFailureDetail(e.getMessage(), entryContext, binding); + } + + // Return assertion result + return validator.createAssertionResult(testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2013.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2013.java new file mode 100644 index 000000000..054b03ea1 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2013.java @@ -0,0 +1,91 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +import javax.wsdl.Binding; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionFailException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl.WSDLValidatorImpl.BindingMatch; +import org.eclipse.wst.wsi.internal.report.AssertionResult; + + +/** + * BP2013. + * The binding (in soapbind:body elements) only refers to part elements that have been defined using the "type" attribute. + * + * @version 1.0.1 27.06.2003 + * @author Vitali Fedosenko + */ +public class BP2013 extends AssertionProcess +{ + private final WSDLValidatorImpl validator; + + /** + * @param WSDLValidatorImpl + */ + public BP2013(WSDLValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + /* Validates the test assertion. + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + // Get binding from entry context + + // Oleg's & Graham's version: + Binding binding = (Binding) entryContext.getEntry().getEntryDetail(); + + // to use original version require a binding array + //Binding[] binding = {(Binding) entryContext.getEntry().getEntryDetail()}; + + // get list of candidate matches + BindingMatch[] bindingMatch = + this.validator.getBindingMatches( + binding, + WSIConstants.ATTRVAL_SOAP_BIND_STYLE_RPC, + WSIConstants.ATTRVAL_SOAP_BODY_USE_LIT); + if (bindingMatch.length == 0) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + else + try + { + if (!this.validator.checkPartAttributes(bindingMatch, "useInput", "useType") + || !this.validator.checkPartAttributes(bindingMatch, "useOutput", "useType")) + { + // this should never happen + throw new AssertionFailException("diagnostic: internal processing error!"); + } + } + catch (AssertionFailException e) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = + this.validator.createFailureDetail(e.getMessage(), entryContext, binding); + } + + // Return assertion result + return validator.createAssertionResult(testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2014.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2014.java new file mode 100644 index 000000000..d553f1103 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2014.java @@ -0,0 +1,286 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import javax.wsdl.Binding; +import javax.wsdl.BindingOperation; +import javax.wsdl.Message; +import javax.wsdl.Operation; +import javax.wsdl.Output; +import javax.wsdl.extensions.soap.SOAPBinding; +import javax.wsdl.extensions.soap.SOAPBody; +import javax.wsdl.extensions.soap.SOAPOperation; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.WSITag; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcessVisitor; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.ErrorList; +import org.eclipse.wst.wsi.internal.wsdl.traversal.WSDLTraversal; +import org.eclipse.wst.wsi.internal.wsdl.traversal.WSDLTraversalContext; + + +/** + * BP2014. + * Context: + * For a candidate wsdl:operation, if referred to by a candidate rpc-literal wsdl:binding element + * If the parameterOrder attribute is present, it omits at most 1 part from output wsdl:message. + **/ +public class BP2014 extends AssertionProcessVisitor implements WSITag +{ + private final WSDLValidatorImpl validator; + + /** + * @param WSDLValidatorImpl + */ + public BP2014(WSDLValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + private ErrorList errors = new ErrorList(); + + /* + * @param binding - binding + * @return It returns style of soap binding of binding. If style omitted returns "document" style. + */ + private String getSOAPBindingStyle(Binding binding) + { + String style = null; + List list = binding.getExtensibilityElements(); + for (int i = 0; i < list.size(); i++) + { + if (list.get(i) instanceof SOAPBinding) + { + style = ((SOAPBinding) list.get(i)).getStyle(); + break; + } + } + if (style == null) + style = WSIConstants.ATTRVAL_SOAP_BIND_STYLE_DOC; + return style; + } + + /* + * @param list - List of extencibility elements from binding output + * @return first soap body in list. + */ + private SOAPBody getSOAPBody(List list) + { + for (int i = 0; i < list.size(); i++) + if (list.get(i) instanceof SOAPBody) + return (SOAPBody) list.get(i); + return null; + } + + /* + * @param list - List of extencibility elements of binding operation + * @return First soap operation in list. + */ + private SOAPOperation getSOAPOperation(List list) + { + for (int i = 0; i < list.size(); i++) + if (list.get(i) instanceof SOAPOperation) + return (SOAPOperation) list.get(i); + return null; + } + + /* + * @param oper - operation + * @param binding - binding + * @return if style of soap binding of binding is rpc and use of soap body of binding output of binding operation is literal then it returns true. + */ + private boolean checkRpcLiteral(BindingOperation oper, Binding binding) + { + List list = oper.getExtensibilityElements(); + SOAPOperation sop = getSOAPOperation(list); + if (sop == null) + return false; + String style = + (sop.getStyle() == null + ? getSOAPBindingStyle(binding) + : sop.getStyle()); + if (!style.equals(WSIConstants.ATTRVAL_SOAP_BIND_STYLE_RPC)) + return false; + list = oper.getBindingOutput().getExtensibilityElements(); + SOAPBody body = getSOAPBody(list); + if (body == null) + return false; + String use = body.getUse(); + if (use == null) + return false; + + return use.equals(WSIConstants.ATTRVAL_SOAP_BODY_USE_LIT); + } + + /* It checks operation contains more than one part in parameter order + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.Operation, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit(Operation obj, Object parent, WSDLTraversalContext ctx) + { + Binding[] bindings = validator.analyzerContext.getCandidateInfo().getBindings(); + if (obj.getParameterOrdering() == null) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + return; + } + + if (bindings == null || obj == null) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + return; + } + + if (obj.getOutput() == null) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + return; + } + + if (obj.getOutput().getMessage() == null) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + return; + } + + // For each binding + for (int i = 0; i < bindings.length; i++) + { + List list = bindings[i].getBindingOperations(); + // For each binding operation + for (int j = 0; j < list.size(); j++) + { + BindingOperation oper = (BindingOperation) list.get(j); + + // If the input operation name and binding operatino name are not null + if (obj.getName() != null && oper.getName() != null) + { + // If the operation names are equal + if (obj.getName().equals(oper.getName())) + { + // If the operation is RPC literal + if (checkRpcLiteral(oper, bindings[i])) + { + // Get the list of parts in the parameterOrder attribute + List parts = obj.getParameterOrdering(); + + Output output = null; + Message message = null; + Map messageParts = null; + + // Get the list of parts for the output message + if ((output = obj.getOutput()) != null) + { + if ((message = output.getMessage()) != null) + { + messageParts = message.getParts(); + } + } + + // If there are parts in the parameterOrder attribute + // and there are output message parts, then process assertion + if (parts != null && messageParts != null) + { + int partCount = 0; + + String partName; + Iterator iterator = parts.iterator(); + while (iterator.hasNext()) + { + // Get part name from parameterOrder list + partName = (String) iterator.next(); + + // Check each output message part to see if there is a match + if (messageParts.containsKey(partName)) + partCount++; + } + + if ((partCount == messageParts.size()) + || (partCount == messageParts.size() - 1)) + result = AssertionResult.RESULT_PASSED; + else + { + errors.add(obj.getName()); + ctx.cancelOperationProcessing(); + } + return; + } + + else + { + if (parts == null) + result = AssertionResult.RESULT_NOT_APPLICABLE; + else + result = AssertionResult.RESULT_PASSED; + return; + } + } + + else + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + return; + } + } + } + + else + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + return; + } + } + } + result = AssertionResult.RESULT_NOT_APPLICABLE; + + } + + /** + * Validates the test assertion. + * @see org.eclipse.wst.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + result = AssertionResult.RESULT_FAILED; + + WSDLTraversal traversal = new WSDLTraversal(); + //VisitorAdaptor.adapt(this); + traversal.setVisitor(this); + traversal.visitOperation(true); + traversal.ignoreImport(); + traversal.traverse((Operation) entryContext.getEntry().getEntryDetail()); + + if (!errors.isEmpty()) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = + this.validator.createFailureDetail( + errors.toString(), + entryContext, + entryContext.getEntry().getEntryDetail()); + } + //else + // result = AssertionResult.RESULT_PASSED; + + return validator.createAssertionResult(testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2017.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2017.java new file mode 100644 index 000000000..8586e3589 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2017.java @@ -0,0 +1,142 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Vector; + +import javax.wsdl.Binding; +import javax.wsdl.extensions.soap.SOAPBinding; +import javax.wsdl.extensions.soap.SOAPOperation; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.report.AssertionResult; + + +/** + * BP2017. + * For a candidate wsdl:binding + * The "style" attribute of each operation in the contained soap:binding has the same value of "document" or "rpc", for all operations of the wsdl:binding. + */ +public class BP2017 extends AssertionProcess +{ + private final WSDLValidatorImpl validator; + + /** + * @param WSDLValidatorImpl + */ + public BP2017(WSDLValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + /* Validates the test assertion. + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + //String firstStyle = null; // GT: is this needed?? + Vector failureDetailList = new Vector(); + + // Get the binding from the entry context + Binding binding = (Binding) entryContext.getEntry().getEntryDetail(); + if (binding == null) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + return validator.createAssertionResult(testAssertion, result, failureDetailList); + } + SOAPBinding soapB = WSDLValidatorImpl.getSoapBinding(binding); + if (soapB == null) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + return validator.createAssertionResult(testAssertion, result, failureDetailList); + } + String styleB = + (soapB.getStyle() == null + ? WSIConstants.ATTRVAL_SOAP_BIND_STYLE_DOC + : soapB.getStyle()); + + // Try to get the SOAP operations + HashMap soapOperationList = validator.getSoapOperations(binding); + + if (soapOperationList.isEmpty()) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + else + { + // check that they all have the same style element value + String style = null; + String checkStyle; + SOAPOperation soapOperation; + Iterator iterator = soapOperationList.keySet().iterator(); + while (iterator.hasNext()) + { + soapOperation = (SOAPOperation) iterator.next(); + checkStyle = soapOperation.getStyle(); + if (checkStyle == null) + checkStyle = styleB; + if (checkStyle != null + && !checkStyle.equals(WSIConstants.ATTRVAL_SOAP_BIND_STYLE_DOC) + && !checkStyle.equals(WSIConstants.ATTRVAL_SOAP_BIND_STYLE_RPC)) + { + result = AssertionResult.RESULT_FAILED; + failureDetailList.add( + this.validator.createFailureDetail( + "Operation Name: " + + soapOperationList.get(soapOperation) + + "\nSOAP Operation: " + + soapOperation.toString(), + entryContext, + soapOperation)); + // REMOVE: Need to process all operations + //break; + } + + if (style == null) + { + style = checkStyle; + } + else if (!style.equals(checkStyle) || !style.equals(styleB)) + { + result = AssertionResult.RESULT_FAILED; + failureDetailList.add( + this.validator.createFailureDetail( + "Operation Name: " + + soapOperationList.get(soapOperation) + + "\nSOAP Operation: " + + soapOperation.toString(), + entryContext, + soapOperation)); + // REMOVE: Need to process all operations + //break; + } + } + + if (style == null) + { + // no style attribute was found in the SOAP operation(s) of the binding. + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + } + // Return assertion result + return validator.createAssertionResult(testAssertion, result, failureDetailList); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2018.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2018.java new file mode 100644 index 000000000..55d2702a3 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2018.java @@ -0,0 +1,195 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +import javax.wsdl.Definition; +import javax.xml.namespace.QName; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.WSITag; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.Utils; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + + +/** + * BP2018. + * For a candidate Web service definition + * The wsdl:types element occurs either as the first child in the WSDL namespace of the wsdl:definitions element if no wsdl:documentation or wsdl:import element is present; or immediately following the wsdl:documentation element(s) if they are present but wsdl:import(s) are not, or immediately following both the wsdl:documentation and wsdl:import elemen(s) if present. + */ +public class BP2018 extends AssertionProcess implements WSITag +{ + private final WSDLValidatorImpl validator; + + /** + * @param WSDLValidatorImpl + */ + public BP2018(WSDLValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + /* + * @param el - xml element + * @return if element is extensibility element returns true. + */ + private boolean isExtensibilityElement(Element el) + { + boolean isEx = true; + isEx = isEx && !XMLUtils.equals(el, WSDL_BINDING); + isEx = isEx && !XMLUtils.equals(el, WSDL_DEFINITIONS); + isEx = isEx && !XMLUtils.equals(el, WSDL_DOCUMENTATION); + isEx = isEx && !XMLUtils.equals(el, WSDL_FAULT); + isEx = isEx && !XMLUtils.equals(el, WSDL_IMPORT); + isEx = isEx && !XMLUtils.equals(el, WSDL_INPUT); + isEx = isEx && !XMLUtils.equals(el, WSDL_MESSAGE); + isEx = isEx && !XMLUtils.equals(el, WSDL_OPERATION); + isEx = isEx && !XMLUtils.equals(el, WSDL_OUTPUT); + isEx = isEx && !XMLUtils.equals(el, WSDL_PART); + isEx = isEx && !XMLUtils.equals(el, WSDL_PORT); + isEx = isEx && !XMLUtils.equals(el, WSDL_PORTTYPE); + isEx = isEx && !XMLUtils.equals(el, WSDL_SERVICE); + isEx = isEx && !XMLUtils.equals(el, WSDL_TYPES); + + return isEx; + } + + /* + * Create failed report. + * @param el - xml element + * @param entryContext - Entry context + */ + private void createFailed( + String message, + Element el, + EntryContext entryContext) + { + QName context = + (el != null) + ? new QName(el.getNamespaceURI(), el.getLocalName()) + : new QName("definition"); + result = AssertionResult.RESULT_FAILED; + failureDetail = this.validator.createFailureDetail(message, entryContext); + } + + /** + * Validates the test assertion. + * @see org.eclipse.wst.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + result = AssertionResult.RESULT_PASSED; + + // Get the location of the WSDL document + Definition definition = + (Definition) entryContext.getEntry().getEntryDetail(); + try + { + // Parse the WSDL document as an XML file + Document doc = + validator.parseXMLDocumentURL(definition.getDocumentBaseURI(), null); + + Element root = doc.getDocumentElement(); // get definition + + Element types = XMLUtils.findChildElement((Element) root, WSDL_TYPES); + + if (types != null) + { + Element el = XMLUtils.findPreviousSibling(types); + while (isExtensibilityElement(el) && el != null) + if (el != null) + el = XMLUtils.findPreviousSibling(el); + + boolean documentIsPresent = + (XMLUtils.findChildElement((Element) root, WSDL_DOCUMENTATION) + != null); + boolean importIsPresent = + (XMLUtils.findChildElement((Element) root, WSDL_IMPORT) != null); + + if (importIsPresent) + if (!XMLUtils.equals(el, WSDL_IMPORT)) + { + createFailed( + "Types element can not follow import element.", + el, + entryContext); + return validator.createAssertionResult( + testAssertion, + result, + failureDetail); + } + else + el = XMLUtils.findPreviousSibling(el); + + while (isExtensibilityElement(el) && el != null) + if (el != null) + el = XMLUtils.findPreviousSibling(el); + + if (documentIsPresent) + if (!XMLUtils.equals(el, WSDL_DOCUMENTATION)) + { + createFailed( + "Types element must follow only a documentation element.", + el, + entryContext); + return validator.createAssertionResult( + testAssertion, + result, + failureDetail); + } + else + el = XMLUtils.findPreviousSibling(el); + + if (!importIsPresent && !documentIsPresent && el != null) + createFailed( + "Types element must follow only a documentation element.", + el, + entryContext); + + if (importIsPresent + && documentIsPresent + && el != null + && !XMLUtils.equals(el, WSDL_DEFINITIONS) + && el.getNamespaceURI().equals(WSIConstants.NS_URI_WSDL)) + createFailed( + "Types element must not follow the " + + el.getTagName() + + " element.", + el, + entryContext); + } + } + + catch (Throwable t) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + failureDetail = + this.validator.createFailureDetail( + "An error occurred while processing the document at " + + definition.getDocumentBaseURI() + + ".\n\n" + + Utils.getExceptionDetails(t), + entryContext); + } + + return validator.createAssertionResult(testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2019.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2019.java new file mode 100644 index 000000000..206802fc7 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2019.java @@ -0,0 +1,124 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +import java.util.Iterator; +import java.util.Vector; + +import javax.wsdl.Binding; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.soap.SOAPBinding; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.Utils; + + +/** + * BP2019. + * For a candidate wsdl:binding element, if the contained soap:binding element has a "style" attribute equal to "document" and soap:operations have "use" attribute equal to "literal": + * The "namespace" attribute is not specified in any contained soapbind:body, soapbind:header, soapbind::headerfault, soapbind:fault elements + * @version 1.0.1 27.06.2003 + * @author Vitali Fedosenko + */ +public class BP2019 extends AssertionProcess +{ + private final WSDLValidatorImpl validator; + + /** + * @param WSDLValidatorImpl + */ + public BP2019(WSDLValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + /* Validates the test assertion. + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + boolean docLitFound = false; + String errantElements = new String(""); + String soapExtensibleWithNamespace = null; + + // Get the binding from the entry context + Binding binding = (Binding) entryContext.getEntry().getEntryDetail(); + + // Try to get the SOAP binding + SOAPBinding soapBinding = WSDLValidatorImpl.getSoapBinding(binding); + + if (soapBinding != null) + { + String style = + (soapBinding.getStyle() == null) + ? WSIConstants.ATTRVAL_SOAP_BIND_STYLE_DOC + : soapBinding.getStyle(); + if (style.equals(WSIConstants.ATTRVAL_SOAP_BIND_STYLE_DOC)) + { + Vector soapElements = Utils.arrayToVector(this.validator.getSoapBodies(binding)); + soapElements.addAll(Utils.arrayToVector(this.validator.getSoapFaults(binding))); + soapElements.addAll(Utils.arrayToVector(this.validator.getSoapHeaders(binding))); + soapElements.addAll( + Utils.arrayToVector(this.validator.getSoapHeaderFaults(binding))); + + Iterator i = soapElements.iterator(); + while (i.hasNext()) + { + ExtensibilityElement soapElement = + (ExtensibilityElement) (i.next()); + try + { + if (this.validator.isLiteral(soapElement)) + { + docLitFound = true; + if (this.validator.namespaceFoundInSoapLiteral(soapElement)) + { + errantElements += "\n--- " + (soapElement.toString()); + } + } + } + catch (Exception e) + { + } // continue with clenched teeth + } + } + } + + if (!docLitFound) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + else + { + // If a namespace was not found then test assertion passed + if (errantElements.length() != 0) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = + this.validator.createFailureDetail( + "Failing elements:" + errantElements, + entryContext); + } + } + + // Return assertion result + return validator.createAssertionResult(testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2020.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2020.java new file mode 100644 index 000000000..4d76f5972 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2020.java @@ -0,0 +1,162 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +import javax.wsdl.Binding; +import javax.wsdl.extensions.soap.SOAPBinding; +import javax.wsdl.extensions.soap.SOAPBody; + +import org.apache.xerces.util.URI; +import org.apache.xerces.util.URI.MalformedURIException; +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.report.AssertionResult; + + +/** +* BP2020. +* For a candidate wsdl:binding element, if the style attribute of the contained soapbind:binding is "rpc" +* and the use attribute is "literal". +* The namespace attribute is specified on all soapbind:body elements and the value of the +* namespace attribute is an absolute URI. +* @version 1.0.1 27.06.2003 +* @author Vitali Fedosenko +**/ +public class BP2020 extends AssertionProcess +{ + private final WSDLValidatorImpl validator; + + /** + * @param WSDLValidatorImpl + */ + public BP2020(WSDLValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + /* Validates the test assertion. + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + result = AssertionResult.RESULT_FAILED; + boolean rpcLitFound = false; + + // Get the binding from the entry context + Binding binding = (Binding) entryContext.getEntry().getEntryDetail(); + + // Try to get the SOAP binding + SOAPBinding soapBinding = WSDLValidatorImpl.getSoapBinding(binding); + + // Test the assertion + // Check style to make sure that it is rpc - the subject of the assertion + String style = WSIConstants.ATTRVAL_SOAP_BIND_STYLE_DOC; + if (soapBinding != null) + style = + (soapBinding.getStyle() == null + ? WSIConstants.ATTRVAL_SOAP_BIND_STYLE_DOC + : soapBinding.getStyle()); + + if ((soapBinding != null) + && (style.equals(WSIConstants.ATTRVAL_SOAP_BIND_STYLE_RPC))) + { + // Get the list of SOAP body elements + SOAPBody[] soapBodies = this.validator.getSoapBodies(binding); + + // Check for Soap operation namespace + boolean assertionFailure = false; + String namespaceURI = null; + for (int i = 0; i < soapBodies.length && !(assertionFailure); i++) + { + SOAPBody soapBody = soapBodies[i]; + // Added check for null use value, since the default value is literal + if (soapBody.getUse() == null + || soapBody.getUse().equals(WSIConstants.ATTRVAL_SOAP_BODY_USE_LIT)) + { + rpcLitFound = true; + // If there is no namespace, then flag as a failure + if ((namespaceURI = soapBody.getNamespaceURI()) == null) + { + assertionFailure = true; + failureDetail = + this.validator.createFailureDetail( + "--- SOAP BODY:\n" + + soapBody.toString() + + "\n--- BINDING QNAME:\n" + + binding.getQName(), + entryContext); + } + + // Else, verify that the namespace is an absolute URI + else + { + try + { + //URL url = new URL(namespaceURI); + URI uri = new URI(namespaceURI); + if (uri.getScheme() == null) + { + // no scheme implies not an absolute URI + assertionFailure = true; + failureDetail = + this.validator.createFailureDetail( + "--- SOAP BODY:\n" + + soapBody.toString() + + "\n--- BINDING QNAME:\n" + + binding.getQName(), + entryContext); + } + } + catch (MalformedURIException mue) + { + assertionFailure = true; + failureDetail = + this.validator.createFailureDetail( + "--- SOAP BODY:\n" + + soapBody.toString() + + "\n--- BINDING QNAME:\n" + + binding.getQName(), + entryContext); + } + + } + } + } + if (!rpcLitFound) + { + // style is rpc but no document use elements + result = AssertionResult.RESULT_NOT_APPLICABLE; + failureDetail = null; + } + else if (!assertionFailure) + { // If no assertion failure, then set result to passed + result = AssertionResult.RESULT_PASSED; + failureDetail = null; + } + } + else + { + // style is not rpc + result = AssertionResult.RESULT_NOT_APPLICABLE; + failureDetail = null; + } + + // Return assertion result + return validator.createAssertionResult(testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2021.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2021.java new file mode 100644 index 000000000..924484e52 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2021.java @@ -0,0 +1,112 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +import java.util.Iterator; +import java.util.List; + +import javax.wsdl.Binding; +import javax.wsdl.extensions.soap.SOAPHeader; +import javax.wsdl.extensions.soap.SOAPHeaderFault; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; + + +/** +* BP2021. +* For a candidate wsdl:binding element +* The wsdl:input element and wsdl:output element of each operation uses the attribute name "part" with a Schema type of "NMTOKEN" and does not use "parts", for both soapbind:header elements and soapbind:headerfault elements. +* +* @version 1.0.1 27.06.2003 +* @author Vitali Fedosenko +**/ +public class BP2021 extends AssertionProcess +{ + private final WSDLValidatorImpl validator; + + /** + * @param WSDLValidatorImpl + */ + public BP2021(WSDLValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + /* Validates the test assertion. + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + //Operation operation = null; + + // Get the binding from the entry context + Binding binding = (Binding) entryContext.getEntry().getEntryDetail(); + + // Get SOAP headers for this binding + SOAPHeader[] soapHeaders = this.validator.getSoapHeaders(binding); + + if (soapHeaders.length == 0) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + else + { + // Check each header to see if it has part element with NMTOKEN type + for (int header = 0; + header < soapHeaders.length + && result.equals(AssertionResult.RESULT_PASSED); + header++) + { + if ((soapHeaders[header].getPart() == null) + || (!XMLUtils.isNmtoken(soapHeaders[header].getPart()))) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = + this.validator.createFailureDetail(soapHeaders[header].toString(), entryContext); + } + // Else, check the headerfault if there is one + else + { + List soapHeaderFaultList = + soapHeaders[header].getSOAPHeaderFaults(); + Iterator iterator = soapHeaderFaultList.iterator(); + + // Check each header fault to see if it has part element with NMTOKEN type + while (iterator.hasNext() + && result.equals(AssertionResult.RESULT_PASSED)) + { + SOAPHeaderFault soapHeaderFault = + (SOAPHeaderFault) iterator.next(); + if ((soapHeaderFault.getPart() == null) + || (!XMLUtils.isNmtoken(soapHeaderFault.getPart()))) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = + this.validator.createFailureDetail(soapHeaderFault.toString(), entryContext); + } + } + } + } + } + + // Return assertion result + return validator.createAssertionResult(testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2022.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2022.java new file mode 100644 index 000000000..ecb173596 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2022.java @@ -0,0 +1,82 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +import javax.wsdl.Binding; +import javax.wsdl.extensions.soap.SOAPFault; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.report.AssertionResult; + + +/** + * BP2022. + * For a candidate wsdl:binding element + * the name attribute is specified on the soapbind:fault element. +**/ +public class BP2022 extends AssertionProcess +{ + private final WSDLValidatorImpl validator; + + /** + * @param WSDLValidatorImpl + */ + public BP2022(WSDLValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + /* Validates the test assertion. + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + // Get the binding from the entry context + Binding binding = (Binding) entryContext.getEntry().getEntryDetail(); + + // Get list of SOAP faults for the binding + SOAPFault[] soapFaults = this.validator.getSoapFaults(binding); + + if (soapFaults == null || soapFaults.length == 0) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + + else + { + // check all soap:faults. + // MUST have a name attribute + for (int i = 0; i < soapFaults.length; i++) + { + SOAPFault soapFault = soapFaults[i]; + if (soapFault.getName() == null) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = + this.validator.createFailureDetail( + "soapbind:fault element : " + soapFault.toString(), + entryContext); + break; + } + } + } + + // Return assertion result + return validator.createAssertionResult(testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2023.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2023.java new file mode 100644 index 000000000..172544bdd --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2023.java @@ -0,0 +1,85 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +import javax.wsdl.Binding; +import javax.wsdl.extensions.soap.SOAPFault; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.report.AssertionResult; + + +/** + * BP2023. + * For a candidate wsdl:binding element, with the "use" attribute present on the soapbind:fault element + * The value of the attribute is "literal". + */ +public class BP2023 extends AssertionProcess +{ + private final WSDLValidatorImpl validator; + + /** + * @param WSDLValidatorImpl + */ + public BP2023(WSDLValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + /* Validates the test assertion. + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + // Get the binding from the entry context + Binding binding = (Binding) entryContext.getEntry().getEntryDetail(); + + // Get list of SOAP faults for the binding + SOAPFault[] soapFaults = this.validator.getSoapFaults(binding); + + if (soapFaults == null || soapFaults.length == 0) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + + else + { + // check all soap:faults. + // MUST have a name attribute, and if a use attribute is specified, it MUST be value "literal" + for (int i = 0; i < soapFaults.length; i++) + { + SOAPFault soapFault = soapFaults[i]; + if ((soapFault.getUse() != null) + && (!soapFault + .getUse() + .equals(WSIConstants.ATTRVAL_SOAP_BODY_USE_LIT))) + { + result = AssertionResult.RESULT_FAILED; + + failureDetail = + this.validator.createFailureDetail(soapFault.toString(), entryContext); + break; + } + } + } + + // Return assertion result + return validator.createAssertionResult(testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2032.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2032.java new file mode 100644 index 000000000..2149341d7 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2032.java @@ -0,0 +1,86 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +import javax.wsdl.Binding; +import javax.wsdl.BindingFault; +import javax.wsdl.extensions.soap.SOAPFault; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.report.AssertionResult; + + +/** + * BP2032. + * For a candidate wsdl:binding element + * the name attribute that is specified on the soapbind:fault element matches the value specified on the parent element wsdl:fault. + */ +public class BP2032 extends AssertionProcess +{ + private final WSDLValidatorImpl validator; + + /** + * @param WSDLValidatorImpl + */ + public BP2032(WSDLValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + /* Validates the test assertion. + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + // Get the binding from the entry context + Binding binding = (Binding) entryContext.getEntry().getEntryDetail(); + + // Get list of Binding faults for the binding + BindingFault[] bindingFaults = this.validator.getAllBindingFaults(binding); + + if (bindingFaults == null || bindingFaults.length == 0) + { + result = AssertionResult.RESULT_PASSED; + } + + else + { + // for each binding fault, compare the child soap:fault name with the binding fault name + + for (int i = 0; i < bindingFaults.length; i++) + { + BindingFault bindingFault = bindingFaults[i]; + SOAPFault soapFault = this.validator.getSoapFault(bindingFault); + if (soapFault == null + || soapFault.getName() == null + || bindingFault.getName() == null + || !bindingFault.getName().equals(soapFault.getName())) + { + result = AssertionResult.RESULT_FAILED; + + failureDetail = this.validator.createFailureDetail( + soapFault == null ? null : soapFault.toString(), entryContext); + break; + } + } + } + + // Return assertion result + return validator.createAssertionResult(testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2034.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2034.java new file mode 100644 index 000000000..75d84c0a1 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2034.java @@ -0,0 +1,94 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +import java.util.List; + +import javax.wsdl.Definition; +import javax.wsdl.Types; +import javax.wsdl.extensions.UnknownExtensibilityElement; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.report.AssertionResult; + +/** + * BP2034 + * + * For a candidate description within a WSDL document + * The candidate description does not contain the namespace declaration xmlns:xml="http://www.w3.org/XML/1998/namespace". + */ +public class BP2034 extends AssertionProcess +{ + private final WSDLValidatorImpl validator; + + /** + * @param WSDLValidatorImpl + */ + public BP2034(WSDLValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + /* Validates the test assertion. + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + // Getting wsdl:definition element + Definition def = (Definition) entryContext.getEntry().getEntryDetail(); + Types types; + // Getting the namespace declaration xmlns:xml + String xmlNs = (String) def.getNamespaces().get("xml"); + // If it exists and equals to "http://www.w3.org/XML/1998/namespace" + if (xmlNs != null && xmlNs.equals(WSIConstants.NS_URI_XML)) + { + // setting assertion result to warning + result = AssertionResult.RESULT_WARNING; + } + // there is no namespace declaration xmlns:xml in the wsdl:definition + // element, checking whether the definition has wsdl:type element + else if ((types = def.getTypes()) != null) + { + // Getting the list of wsdl:schemaS + List extElems = types.getExtensibilityElements(); + for (int i = 0; i < extElems.size(); i++) + { + // Getting wsdl:schema element + UnknownExtensibilityElement schema = + (UnknownExtensibilityElement) extElems.get(i); + // Getting a value of the attribute xmlns:xml + String attrValue = schema.getElement().getAttributeNS( + WSIConstants.NS_URI_XMLNS, "xml"); + // If it equals to "http://www.w3.org/XML/1998/namespace", + if (WSIConstants.NS_URI_XML.equals(attrValue)) + { + // setting assertion result to warning + result = AssertionResult.RESULT_WARNING; + failureDetail = validator.createFailureDetail("The namespace " + + "declaration nested in wsdl:schema element.", entryContext); + break; + } + } + } + + // Return assertion result + return validator.createAssertionResult( + testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2098.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2098.java new file mode 100644 index 000000000..8edec5603 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2098.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +import javax.wsdl.Import; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.WSITag; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.ErrorList; + + +/** + * BP2098. + * For a candidate wsdl:import element + * The "location" attribute is specified for the wsdl:import element, and has a non-empty value. + */ +public class BP2098 extends AssertionProcess implements WSITag +{ + private final WSDLValidatorImpl validator; + + /** + * @param WSDLValidatorImpl + */ + public BP2098(WSDLValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + private ErrorList errors = new ErrorList(); + + /* Validates the test assertion. + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + result = AssertionResult.RESULT_FAILED; + + Import im = (Import) entryContext.getEntry().getEntryDetail(); + // suppose that if location is invalid, the definition equals to null + if (im.getLocationURI() == null || im.getLocationURI() == "") + errors.add(im.getNamespaceURI(), im.getLocationURI()); + + if (!errors.isEmpty()) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = this.validator.createFailureDetail(errors.toString(), entryContext); + } + else + result = AssertionResult.RESULT_PASSED; + + return validator.createAssertionResult(testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2101.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2101.java new file mode 100644 index 000000000..27e5736fb --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2101.java @@ -0,0 +1,118 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +import javax.wsdl.Definition; +import javax.wsdl.Import; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.WSITag; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcessVisitor; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.ErrorList; +import org.eclipse.wst.wsi.internal.util.TestUtils; +import org.eclipse.wst.wsi.internal.util.Utils; +import org.eclipse.wst.wsi.internal.wsdl.traversal.WSDLTraversal; +import org.eclipse.wst.wsi.internal.wsdl.traversal.WSDLTraversalContext; +import org.w3c.dom.Document; + + +/** + * BP2101. + * For a candidate wsdl:definition, if it contains wsdl:import statements + * Each wsdl:import statement is only used to import another WSDL description. + */ +public class BP2101 extends AssertionProcessVisitor implements WSITag +{ + private final WSDLValidatorImpl validator; + + /** + * @param WSDLValidatorImpl + */ + public BP2101(WSDLValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + private ErrorList errors = new ErrorList(); + + boolean importFound = false; + + /* Create falure report if import contains reference to non WSDL description. + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.Import, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit(Import im, Object parent, WSDLTraversalContext ctx) + { + importFound = true; + + // by the way : WSDL4J throws Exception if imported WSDL is not resolved + // but documentation says that im.getDefinition() will be equal to null + if (im.getDefinition() == null) + errors.add( + im.getNamespaceURI() + + ":" + + im.getLocationURI() + + "\nImport element does not reference a WSDL definition."); + else + try + { + // try to parse WSDL according to the WSDL schema + Document doc = + validator.parseXMLDocumentURL( + im.getLocationURI(), + ((Definition)parent).getDocumentBaseURI(), + TestUtils.getWSDLSchemaLocation()); + } + catch (Throwable t) + { + errors.add( + im.getNamespaceURI() + + ":" + + im.getLocationURI() + + "\n" + + Utils.getExceptionDetails(t)); + } + } + + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + result = AssertionResult.RESULT_FAILED; + + WSDLTraversal traversal = new WSDLTraversal(); + //VisitorAdaptor.adapt(this); + traversal.setVisitor(this); + traversal.visitImport(true); + traversal.ignoreReferences(); + traversal.traverse((Definition) entryContext.getEntry().getEntryDetail()); + + if (!errors.isEmpty()) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = this.validator.createFailureDetail(errors.toString(), entryContext); + } + + else if (!importFound) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + + else + result = AssertionResult.RESULT_PASSED; + + return validator.createAssertionResult(testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2102.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2102.java new file mode 100644 index 000000000..3bf34b417 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2102.java @@ -0,0 +1,203 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import javax.wsdl.Definition; +import javax.wsdl.Types; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.UnknownExtensibilityElement; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.WSITag; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; +import org.w3c.dom.Attr; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; + + +/** + * BP2102. + * For a candidate wsdl:types element, with XML schema import elements + * Each XML schema import statement (xsd:import) is only used to directly reference an XML schema definition, which has "schema" from XML namespace "http://www.w3.org/2001/XMLSchema" as root element. It does not contain a reference to another document embedding the XML schema definition (e.g. WSDL). + */ +public class BP2102 extends AssertionProcess implements WSITag +{ + private final WSDLValidatorImpl validator; + + /** + * @param WSDLValidatorImpl + */ + public BP2102(WSDLValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + private boolean importFound = false; + + /* Validates the test assertion. + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + result = AssertionResult.RESULT_PASSED; + + // parse WSDL as XML + try + { + Types t = (Types) entryContext.getEntry().getEntryDetail(); + List exts = t.getExtensibilityElements(); + + Definition definition = null; + if ((definition = validator.analyzerContext.getCandidateInfo().getDefinition(t)) + == null) + { + throw new WSIException("Could not find types definition in any WSDL document."); + } + + if (exts != null) + { + Iterator it = exts.iterator(); + while (it.hasNext()) + { + ExtensibilityElement el = (ExtensibilityElement) it.next(); + if (el instanceof UnknownExtensibilityElement + && el.getElementType().equals(ELEM_XSD_SCHEMA)) + testNode(((UnknownExtensibilityElement) el).getElement(), + definition.getDocumentBaseURI()); + + if (result.equals(AssertionResult.RESULT_FAILED)) + { + failureDetail = + this.validator.createFailureDetail(failureDetailMessage, entryContext); + } + } + } + + if (!importFound) + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + + catch (Throwable tt) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + failureDetail = + this.validator.createFailureDetail( + "WSDL document can not be processed", + entryContext); + } + + return validator.createAssertionResult(testAssertion, result, failureDetail); + } + + /* + * Check node is xsd import and it is + * only used to directly reference an XML schema definition, which has "schema" + * from XML namespace "http://www.w3.org/2001/XMLSchema" as root element. + * And it does not contain a reference to another document embedding the XML schema + * definition (e.g. WSDL). + * @param n - Unknown extensibility element + */ + private void testNode(Node n, String context) + { + while (n != null) + { + // searches for xsd:import element + if (Node.ELEMENT_NODE == n.getNodeType()) + { + if (XMLUtils.equals(n, ELEM_XSD_IMPORT)) + { + importFound = true; + + Element im = (Element) n; + // Getting the schemaLocation and the namespace attributes + Attr schemaLocation = + XMLUtils.getAttribute(im, ATTR_XSD_SCHEMALOCATION); + Attr namespace = XMLUtils.getAttribute(im, ATTR_XSD_NAMESPACE); + // If there is only the namespace attribute of import element + if (schemaLocation == null && namespace != null) + { + // Getting all the inline schemas of the wsdl definition + Map schemasMap = validator.wsdlDocument.getSchemas(); + // If an inline schema imported is defined + if (schemasMap.keySet().contains(namespace.getValue())) + { + // If an inline schema imported is defined + // (that means the schema is valid), + // continue with the next element + n = n.getNextSibling(); + continue; + } + + // no schemaLocation so try the namespace + schemaLocation = namespace; + } + + // try to parse imported XSD + if (schemaLocation != null && schemaLocation.getValue() != null) + { + try + { + // if any error or root element is not XSD schema -> error + // !! ATTENTION + // root XSD SCHEMA SCHEMA is not valid + //Document schema = XMLUtils.parseXMLDocumentURL(schemaLocation.getValue(), XSD_SCHEMALOCATION, context); + Document schema = + validator.parseXMLDocumentURL(schemaLocation.getValue(), context); + + // If the import is valid, then check its contents + if (XMLUtils + .equals(schema.getDocumentElement(), ELEM_XSD_SCHEMA)) + { + // Check content of imported document + testNode(schema.getDocumentElement().getFirstChild(), + XMLUtils.createURLString(schemaLocation.getValue(), context)); + } + + else + { + throw new Exception(); + } + } + catch (Throwable t) + { + result = AssertionResult.RESULT_FAILED; + failureDetailMessage = schemaLocation.getValue(); + break; + } + } + else + { + //result = AssertionResult.RESULT_FAILED; + result = AssertionResult.RESULT_NOT_APPLICABLE; + failureDetailMessage = + "schemaLocation == null and namespace == null"; + break; + } + } + testNode(n.getFirstChild(), context); + } + n = n.getNextSibling(); + } + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2103.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2103.java new file mode 100644 index 000000000..c3d9e2f26 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2103.java @@ -0,0 +1,130 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +import javax.wsdl.Definition; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.UnknownExtensibilityElement; +import javax.xml.namespace.QName; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.WSITag; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcessVisitor; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.ErrorList; +import org.eclipse.wst.wsi.internal.wsdl.traversal.WSDLTraversal; +import org.eclipse.wst.wsi.internal.wsdl.traversal.WSDLTraversalContext; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; +import org.w3c.dom.Attr; +import org.w3c.dom.Element; +import org.w3c.dom.Node; + + +/** + * BP2103. + * For each a candidate wsdl:definitions + * For the referenced definitions as well as all imported + * descriptions, The XML schema import statement is only used within an xsd:schema + * element. + */ +public class BP2103 extends AssertionProcessVisitor implements WSITag +{ + private final WSDLValidatorImpl validator; + + /** + * @param WSDLValidatorImpl + */ + public BP2103(WSDLValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + private ErrorList errors = new ErrorList(); + + /* Check all unknown extensibility elements it is not xsd import. + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.extensions.ExtensibilityElement, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit( + ExtensibilityElement el, + Object parent, + WSDLTraversalContext ctx) + { + if (el instanceof UnknownExtensibilityElement) + searchForImport(((UnknownExtensibilityElement) el).getElement()); + } + + /* Validates the test assertion. + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + result = AssertionResult.RESULT_FAILED; + + //processWSDL(entryContext.getWSDLDocument().getFilename()); + WSDLTraversal traversal = new WSDLTraversal(); + //VisitorAdaptor.adapt(this); + traversal.setVisitor(this); + traversal.ignoreImport(); + traversal.visitExtensibilityElement(true); + + traversal.ignoreReferences(); + traversal.traverse((Definition) entryContext.getEntry().getEntryDetail()); + + if (!errors.isEmpty()) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = this.validator.createFailureDetail(errors.toString(), entryContext); + } + else + result = AssertionResult.RESULT_PASSED; + + return validator.createAssertionResult(testAssertion, result, failureDetail); + } + + /* + * Create falure report if node is xsd import. + * @param n - node + */ + private void searchForImport(Node n) + { + while (n != null) + { + // searches for xsd:import element + if (Node.ELEMENT_NODE == n.getNodeType()) + { + if (XMLUtils.equals(n, ELEM_XSD_IMPORT)) + { + Attr a = + XMLUtils.getAttribute((Element) n, ATTR_XSD_SCHEMALOCATION); + String schemaLocation = (a != null) ? a.getValue() : ""; + a = XMLUtils.getAttribute((Element) n, ATTR_XSD_NAMESPACE); + String namespace = (a != null) ? a.getValue() : ""; + errors.add(new QName(namespace, schemaLocation)); + } + + else + { + // if xsd:schema element is found -> process schema + if (!XMLUtils.equals(n, ELEM_XSD_SCHEMA)) + searchForImport(n.getFirstChild()); + } + } + + n = n.getNextSibling(); + } + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2104.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2104.java new file mode 100644 index 000000000..309e09e87 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2104.java @@ -0,0 +1,100 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +import javax.wsdl.Definition; +import javax.wsdl.Import; +import javax.xml.namespace.QName; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.WSITag; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcessVisitor; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.ErrorList; +import org.eclipse.wst.wsi.internal.util.NullUtil; +import org.eclipse.wst.wsi.internal.wsdl.traversal.WSDLTraversal; +import org.eclipse.wst.wsi.internal.wsdl.traversal.WSDLTraversalContext; + + +/** + * BP2104. + * For a candidate wsdl:import + * The targetNamespace attribute on the wsdl:definitions element for the imported WSDL description has the same value as the namespace attribute on the wsdl:import element that imported the WSDL description. + */ +public class BP2104 extends AssertionProcessVisitor implements WSITag +{ + private final WSDLValidatorImpl validator; + + /** + * @param WSDLValidatorImpl + */ + public BP2104(WSDLValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + private ErrorList errors = new ErrorList(); + + private boolean importFound = false; + + /* Create falure report if namespace of wsdl:import does not equal targetnamespace in referenced wsdl. + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.Import, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit(Import im, Object parent, WSDLTraversalContext ctx) + { + importFound = true; + Definition def = im.getDefinition(); + if (def != null) + { + if (!NullUtil.equals(im.getNamespaceURI(), def.getTargetNamespace())) + errors.add( + new QName(im.getNamespaceURI(), im.getLocationURI()), + new QName(def.getTargetNamespace(), def.getDocumentBaseURI())); + } + } + + /* + * Validates the test assertion. + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + result = AssertionResult.RESULT_FAILED; + + WSDLTraversal traversal = new WSDLTraversal(); + //VisitorAdaptor.adapt(this); + traversal.setVisitor(this); + traversal.visitImport(true); + traversal.ignoreReferences(); + traversal.traverse((Definition) entryContext.getEntry().getEntryDetail()); + + if (!errors.isEmpty()) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = this.validator.createFailureDetail(errors.toString(), entryContext); + } + + else if (!importFound) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + else + result = AssertionResult.RESULT_PASSED; + + return validator.createAssertionResult(testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2105.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2105.java new file mode 100644 index 000000000..775a47463 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2105.java @@ -0,0 +1,232 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +import javax.wsdl.Definition; +import javax.wsdl.Import; +import javax.xml.namespace.QName; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.WSITag; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcessVisitor; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.ErrorList; +import org.eclipse.wst.wsi.internal.wsdl.traversal.WSDLTraversal; +import org.eclipse.wst.wsi.internal.wsdl.traversal.WSDLTraversalContext; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; +import org.w3c.dom.Attr; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; + + +/** + * BP2105. + * For a candidate wsdl:definitions + * For the referenced definitions, as well as all imported descriptions, in the WSDL namespace under the wsdl:defintitions element, the wsdl:import element is either directly after the wsdl:documentation element or is the first child element if the wsdl:documentation element is not present. + */ +public class BP2105 extends AssertionProcessVisitor implements WSITag +{ + private final WSDLValidatorImpl validator; + + /** + * @param WSDLValidatorImpl + */ + public BP2105(WSDLValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + private ErrorList errors = new ErrorList(); + + private boolean importFound = false; + + /* + * Check wsld import element is either directly after the wsdl:documentation element + * or is the first child element if the wsdl:documentation element is not present. + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.Import, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit(Import im, Object parent, WSDLTraversalContext ctx) + { + importFound = true; + if (im.getDefinition() != null && im.getLocationURI() != null) + processWSDL(im.getDefinition().getDocumentBaseURI()); + } + + /* + * Check element is extensibility. + * @param el - xml element + * @return boolean + */ + private boolean isExtensibilityElement(Element el) + { + boolean isEx = true; + isEx = isEx && !XMLUtils.equals(el, WSDL_BINDING); + isEx = isEx && !XMLUtils.equals(el, WSDL_DEFINITIONS); + isEx = isEx && !XMLUtils.equals(el, WSDL_DOCUMENTATION); + isEx = isEx && !XMLUtils.equals(el, WSDL_FAULT); + isEx = isEx && !XMLUtils.equals(el, WSDL_IMPORT); + isEx = isEx && !XMLUtils.equals(el, WSDL_INPUT); + isEx = isEx && !XMLUtils.equals(el, WSDL_MESSAGE); + isEx = isEx && !XMLUtils.equals(el, WSDL_OPERATION); + isEx = isEx && !XMLUtils.equals(el, WSDL_OUTPUT); + isEx = isEx && !XMLUtils.equals(el, WSDL_PART); + isEx = isEx && !XMLUtils.equals(el, WSDL_PORT); + isEx = isEx && !XMLUtils.equals(el, WSDL_PORTTYPE); + isEx = isEx && !XMLUtils.equals(el, WSDL_SERVICE); + isEx = isEx && !XMLUtils.equals(el, WSDL_TYPES); + + return isEx; + } + + /* Validates the test assertion. + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + result = AssertionResult.RESULT_FAILED; + + // Get the definition element that will be analyzed + Definition definition = + (Definition) entryContext.getEntry().getEntryDetail(); + + // If it doesn't contain any imports, then the result is notApplicable + if ((definition.getImports() == null) + || (definition.getImports().size() == 0)) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + + // Else analyze the + else + { + processWSDL(definition.getDocumentBaseURI()); + + WSDLTraversal traversal = new WSDLTraversal(); + //VisitorAdaptor.adapt(this); + traversal.setVisitor(this); + traversal.visitImport(true); + + traversal.ignoreReferences(); + traversal.ignoreImport(); + traversal.traverse( + (Definition) entryContext.getEntry().getEntryDetail()); + + if (!errors.isEmpty()) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = this.validator.createFailureDetail(errors.toString(), entryContext); + } + + else if (!importFound) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + + else + { + result = AssertionResult.RESULT_PASSED; + } + } + + return validator.createAssertionResult(testAssertion, result, failureDetail); + } + + /* + * the method loads WSDL and check structure + * @param location + */ + private void processWSDL(String location) + { + try + { + // parses WSDL + Document doc = validator.parseXMLDocumentURL(location, null); + checkWSDL(doc.getDocumentElement()); // get definition + } + catch (Throwable t) + { + // ADD: add exception handling + //System.err.println("2105 - WSDL load failed"); + errors.add(t.toString()); + } + } + + /* + * Create falure report contains information of node. + * @param root + */ + private void createFailed(Node root) + { + Attr a = XMLUtils.getAttribute((Element) root, ATTR_WSDL_LOCATION); + String schemaLocation = (a != null) ? a.getValue() : ""; + a = XMLUtils.getAttribute((Element) root, ATTR_WSDL_NAMESPACE); + String namespace = (a != null) ? a.getValue() : ""; + errors.add(new QName(namespace, schemaLocation)); + } + + /* + * Check wsdl correspons assertion description. + * @param root - definition + */ + private void checkWSDL(Node root) + { + if (root != null) + { + // Find the first import element + Element im = XMLUtils.findChildElement((Element) root, WSDL_IMPORT); + + // Determine if a documentation element is present in the WSDL document + boolean documentIsPresent = + (XMLUtils.findChildElement((Element) root, WSDL_DOCUMENTATION) + != null); + + // Verify that all import elements occur after a documentation element + while (im != null) + { + // Find elements that are previous to the import element + Element el = XMLUtils.findPreviousSibling(im); + if (el != null) + while (isExtensibilityElement(el) && el != null) + if (el != null) + el = XMLUtils.findPreviousSibling(el); + + // If the wsdl:document elemnt is present + if (documentIsPresent && el != null) + { + if (!XMLUtils.equals(el, WSDL_DOCUMENTATION) && !XMLUtils.equals(el, WSDL_IMPORT)) + createFailed(root); + } + + // Else check if it is another wsdl: element + else if (el != null) + { + // If not the definitions element, then check for other wsdl: element + if (!XMLUtils.equals(el, WSDL_DEFINITIONS) && !XMLUtils.equals(el, WSDL_IMPORT)) + { + if (el.getNamespaceURI().equals(WSIConstants.NS_URI_WSDL)) + createFailed(root); + } + } + + // Get the next import element + im = XMLUtils.findElement(im, WSDL_IMPORT); + } + } + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2107.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2107.java new file mode 100644 index 000000000..ace270048 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2107.java @@ -0,0 +1,202 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +import java.util.Iterator; +import java.util.List; + +import javax.wsdl.Types; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.UnknownExtensibilityElement; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.WSITag; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.ErrorList; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; +import org.w3c.dom.Attr; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; + + +/** + * BP2107. + * For a candidate wsdl:types element containing an xsd:schema element + * The xsd:schema element contains a targetNamespace attribute with a valid and non-null value unless the xsd:schema element has xsd:import and/or xsd:annotation as its only child element(s). + */ +public class BP2107 extends AssertionProcess implements WSITag +{ + private final WSDLValidatorImpl validator; + + /** + * @param WSDLValidatorImpl + */ + public BP2107(WSDLValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + private boolean schemaFound = false; + private ErrorList errors = new ErrorList(); + private String context; + + /* + * Validates the test assertion. + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + result = AssertionResult.RESULT_FAILED; + + Types t = (Types) entryContext.getEntry().getEntryDetail(); + List exts = t.getExtensibilityElements(); + if (exts != null) + { + context = + entryContext.getWSDLDocument().getDefinitions().getDocumentBaseURI(); + Iterator it = exts.iterator(); + while (it.hasNext()) + { + ExtensibilityElement el = (ExtensibilityElement) it.next(); + if (el instanceof UnknownExtensibilityElement) + searchForSchema(((UnknownExtensibilityElement) el).getElement()); + } + } + + // context = entryContext.getWSDLDocument().getDefinitions().getDocumentBaseURI(); + // processWSDL(entryContext.getWSDLDocument().getFilename()); + + if (!errors.isEmpty()) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = this.validator.createFailureDetail(errors.toString(), entryContext); + } + + else if (!schemaFound) + result = AssertionResult.RESULT_NOT_APPLICABLE; + + else + result = AssertionResult.RESULT_PASSED; + + return validator.createAssertionResult(testAssertion, result, failureDetail); + } + + /* + * Check node schema or load schema from inmport if it exists and process it. + * @param n - node + */ + private void searchForSchema(Node n) + { + while (n != null) + { + // searches for xsd:import element + if (Node.ELEMENT_NODE == n.getNodeType()) + { + // if xsd:schema element is found -> process schema + if (XMLUtils.equals(n, ELEM_XSD_SCHEMA)) + { + schemaFound = true; + processSchema(n, null); + } + + else + { + // if xsd:import element is found -> load schema and process schema + //if (XMLUtils.equals(n, ELEM_XSD_IMPORT)) + // loadSchema(n); + //else + // else iterate element recursively + searchForSchema(n.getFirstChild()); + } + } + + n = n.getNextSibling(); + } + } + + /* + * Load schema and process it. + * @param importNode - xsd:import element + */ + private void loadSchema(Node importNode) + { + Element im = (Element) importNode; + Attr schemaLocation = XMLUtils.getAttribute(im, ATTR_XSD_SCHEMALOCATION); + // try to parse imported XSD + if (schemaLocation != null && schemaLocation.getValue() != null) + try + { + // if any error or root element is not XSD schema -> error + Document schema = + validator.parseXMLDocumentURL(schemaLocation.getValue(), context); + if (XMLUtils.equals(schema.getDocumentElement(), ELEM_XSD_SCHEMA)) + { + Attr a = XMLUtils.getAttribute(im, ATTR_XSD_NAMESPACE); + String namespace = (a != null) ? a.getValue() : ""; + processSchema(schema.getDocumentElement(), namespace); + } + } + catch (Throwable t) + { + // nothing. it's not a schema + } + } + + /* + * Create falure report if it's not correspons assertion description. + * @param schema - xsd:schema + * @param namespace - namespace of schema + */ + private void processSchema(Node schema, String namespace) + { + Attr a = + XMLUtils.getAttribute((Element) schema, ATTR_XSD_TARGETNAMESPACE); + String targetNamespace = (a != null) ? a.getValue() : null; + + Node n = schema.getFirstChild(); + // !! we suppose that xsd:import element is occured only within xsd:schema element + boolean containsOnlyImportAndAnnotation = true; + while (n != null) + { + if (n.getNodeType() == Node.ELEMENT_NODE) + { + containsOnlyImportAndAnnotation + &= (XMLUtils.equals(n, ELEM_XSD_IMPORT) + || XMLUtils.equals(n, ELEM_XSD_ANNOTATION)); + } + + //if (Node.ELEMENT_NODE == n.getNodeType() && XMLUtils.equals(n, ELEM_XSD_IMPORT)) + // loadSchema(n); + + n = n.getNextSibling(); + } + + // If the target namespace is not set and there are elements in addition to import and annotation, then error + if ((targetNamespace == null || targetNamespace.length() == 0) + && (!containsOnlyImportAndAnnotation)) + { + errors.add(targetNamespace, XMLUtils.serialize((Element) schema)); + } + + if (namespace != null && !namespace.equals(targetNamespace)) + { + errors.add(namespace, XMLUtils.serialize((Element) schema)); + } + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2108.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2108.java new file mode 100644 index 000000000..cb203ce78 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2108.java @@ -0,0 +1,94 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +import java.util.Iterator; + +import javax.wsdl.Definition; +import javax.wsdl.Types; +import javax.xml.namespace.QName; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.WSITag; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.ErrorList; +import org.eclipse.wst.wsi.internal.util.TypesRegistry; + + +/** + * BP2108. + * For a candidate wsdl:types, with Array declarations either locally defined or from an imported description + * The type soapenc:Array does not appear in these declarations, and the wsdl:arrayType attribute is not used in the type declaration. + */ +public class BP2108 extends AssertionProcess implements WSITag +{ + private final WSDLValidatorImpl validator; + + /** + * @param WSDLValidatorImpl + */ + public BP2108(WSDLValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + private ErrorList errors = new ErrorList(); + + /* + * Validates the test assertion. + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + result = AssertionResult.RESULT_FAILED; + + Types t = (Types) entryContext.getEntry().getEntryDetail(); + + // Search the definitions in CandidateInfo to locate the definition element that contains the specified types element + Definition definition = null; + if ((definition = validator.analyzerContext.getCandidateInfo().getDefinition(t)) + == null) + { + // This should never happen, but if it does then throw an execption + throw new WSIException("Could not locate types element definition."); + } + + else + { + TypesRegistry registry = + new TypesRegistry( + t, + definition.getDocumentBaseURI(), + validator); + + Iterator it = registry.getArrayTypes().iterator(); + while (it.hasNext()) + errors.add((QName) it.next()); + + if (!errors.isEmpty()) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = this.validator.createFailureDetail(errors.toString(), entryContext); + } + else + result = AssertionResult.RESULT_PASSED; + } + + return validator.createAssertionResult(testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2110.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2110.java new file mode 100644 index 000000000..6ed79109a --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2110.java @@ -0,0 +1,98 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +import java.util.Iterator; + +import javax.wsdl.Definition; +import javax.wsdl.Types; +import javax.xml.namespace.QName; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.WSITag; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.ErrorList; +import org.eclipse.wst.wsi.internal.util.TypesRegistry; + + +/** + * BP2110. + * For a candidate wsdl:types + * Array declaration wrapper elements does not use the naming convention ArrayOfXXX. + */ +public class BP2110 extends AssertionProcess implements WSITag +{ + private final WSDLValidatorImpl validator; + + /** + * @param WSDLValidatorImpl + */ + public BP2110(WSDLValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + private ErrorList errors = new ErrorList(); + + /* Validates the test assertion. + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + result = AssertionResult.RESULT_WARNING; + + Types t = (Types) entryContext.getEntry().getEntryDetail(); + + // Search the definitions in CandidateInfo to locate the definition element that contains the specified types element + Definition definition = null; + if ((definition = validator.analyzerContext.getCandidateInfo().getDefinition(t)) + == null) + { + // This should never happen, but if it does then throw an execption + throw new WSIException("Could not locate types element definition."); + } + + else + { + TypesRegistry registry = + new TypesRegistry( + t, + definition.getDocumentBaseURI(), + validator); + + Iterator it = registry.getElementList().iterator(); + while (it.hasNext()) + { + QName type = (QName) it.next(); + if (type.getLocalPart().startsWith("ArrayOf")) + errors.add(type); + } + + if (!errors.isEmpty()) + { + result = AssertionResult.RESULT_WARNING; + failureDetail = this.validator.createFailureDetail(errors.toString(), entryContext); + } + + else + result = AssertionResult.RESULT_PASSED; + } + + return validator.createAssertionResult(testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2111.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2111.java new file mode 100644 index 000000000..4d641dbfb --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2111.java @@ -0,0 +1,142 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +import java.util.List; + +import javax.wsdl.Binding; +import javax.wsdl.extensions.soap.SOAPBinding; +import javax.wsdl.extensions.soap.SOAPBody; +import javax.wsdl.extensions.soap.SOAPOperation; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.WSITag; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcessVisitor; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.ErrorList; +import org.eclipse.wst.wsi.internal.wsdl.traversal.WSDLTraversal; +import org.eclipse.wst.wsi.internal.wsdl.traversal.WSDLTraversalContext; + + +/** + * BP2111. + * For a candidate wsdl:binding, which contains a document-literal soap:binding + * + * If the "parts" attribute is present, then the soapbind:body element(s) have at most one part listed in the parts attribute. + */ +public class BP2111 extends AssertionProcessVisitor implements WSITag +{ + private final WSDLValidatorImpl validator; + + /** + * @param WSDLValidatorImpl + */ + public BP2111(WSDLValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + private boolean docLiteralFound = false; + private ErrorList errors = new ErrorList(); + + /* + * Put in context soap binding's style + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.extensions.soap.SOAPBinding, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + + public void visit( + SOAPBinding binding, + Object parent, + WSDLTraversalContext ctx) + { + String style = + (binding.getStyle() == null) + ? WSIConstants.ATTRVAL_SOAP_BIND_STYLE_DOC + : binding.getStyle(); + ctx.addParameter("style", style); + } + + /* + * Verify style of soap operation is "document" if not then it's canceled process. + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.extensions.soap.SOAPOperation, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit( + SOAPOperation operation, + Object parent, + WSDLTraversalContext ctx) + { + String style = operation.getStyle(); + if (style == null) + style = (String) ctx.getParameter("style"); + // assert style != null + if (!WSIConstants.ATTRVAL_SOAP_BIND_STYLE_DOC.equals(style)) + ctx.cancelBindingOperationProcessing(); + } + + /* + * If use of soap body is "literal" and parts of soap body is more than one it creates falure report. + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.extensions.soap.SOAPBody, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit(SOAPBody body, Object parent, WSDLTraversalContext ctx) + { + // assert style == "document" + if (WSIConstants.ATTRVAL_SOAP_BODY_USE_LIT.equals(body.getUse())) + { + docLiteralFound = true; + + List parts = body.getParts(); + if (parts != null && parts.size() > 1) + //how to pick out one body from another one ? + errors.add(body.getElementType(), body.getNamespaceURI()); + } + } + + /* + * Validates the test assertion. + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + result = AssertionResult.RESULT_FAILED; + + WSDLTraversal traversal = new WSDLTraversal(); + //VisitorAdaptor.adapt(this);; + traversal.setVisitor(this); + traversal.visitSOAPBinding(true); + traversal.visitSOAPBody(true); + traversal.visitSOAPOperation(true); + + traversal.ignoreReferences(); + traversal.ignoreImport(); + traversal.traverse((Binding) entryContext.getEntry().getEntryDetail()); + + if (!errors.isEmpty()) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = this.validator.createFailureDetail(errors.toString(), entryContext); + } + + else if (!docLiteralFound) + result = AssertionResult.RESULT_NOT_APPLICABLE; + + else + result = AssertionResult.RESULT_PASSED; + + return validator.createAssertionResult(testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2112.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2112.java new file mode 100644 index 000000000..494d8bbc9 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2112.java @@ -0,0 +1,204 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +import java.util.Iterator; +import java.util.List; + +import javax.wsdl.Binding; +import javax.wsdl.BindingInput; +import javax.wsdl.BindingOperation; +import javax.wsdl.BindingOutput; +import javax.wsdl.Message; +import javax.wsdl.Operation; +import javax.wsdl.Part; +import javax.wsdl.extensions.soap.SOAPBinding; +import javax.wsdl.extensions.soap.SOAPBody; +import javax.wsdl.extensions.soap.SOAPOperation; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.WSITag; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcessVisitor; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.ErrorList; +import org.eclipse.wst.wsi.internal.util.WSDLUtil; +import org.eclipse.wst.wsi.internal.wsdl.traversal.WSDLTraversal; +import org.eclipse.wst.wsi.internal.wsdl.traversal.WSDLTraversalContext; + + +/** + * BP2112. + * For a candidate wsdl:binding, with a style "rpc" attribute and containing at least a soapbind:body element + * No wsdl:part referred by such a soapbind:body element is defined using the "element" attribute. + */ +public class BP2112 extends AssertionProcessVisitor implements WSITag +{ + private final WSDLValidatorImpl validator; + + /** + * @param WSDLValidatorImpl + */ + public BP2112(WSDLValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + private boolean rpcLiteralFound = false; + private ErrorList errors = new ErrorList(); + private Message message = null; + + /* + * Put in context soap binding's style + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.extensions.soap.SOAPBinding, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + + public void visit( + SOAPBinding binding, + Object parent, + WSDLTraversalContext ctx) + { + String style = + (binding.getStyle() == null) + ? WSIConstants.ATTRVAL_SOAP_BIND_STYLE_DOC + : binding.getStyle(); + ctx.addParameter("bindingStyle", style); + } + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.BindingOperation, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit( + BindingOperation op, + Object parent, + WSDLTraversalContext ctx) + { + ctx.removeParameter("operationStyle"); + } + + /* + * Verify style of soap operation is "rpc" if not then it's canceled process. + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.extensions.soap.SOAPOperation, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit( + SOAPOperation operation, + Object parent, + WSDLTraversalContext ctx) + { + ctx.addParameter("operationStyle", operation.getStyle()); + } + + /* + * If use of soap body is "literal" and if at least one part is define using "element" attribute it creates falure report. + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.extensions.soap.SOAPBody, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit(SOAPBody body, Object parent, WSDLTraversalContext ctx) + { + String opStyle = (String) ctx.getParameter("operationStyle"); + String bStyle = (String) ctx.getParameter("bindingStyle"); + + if ((opStyle == null + && !WSIConstants.ATTRVAL_SOAP_BIND_STYLE_RPC.equals(bStyle)) + || (opStyle != null + && !WSIConstants.ATTRVAL_SOAP_BIND_STYLE_RPC.equals(opStyle))) + { + ctx.cancelBindingOperationProcessing(); + return; + } + // assert use == "literal" + if (WSIConstants.ATTRVAL_SOAP_BODY_USE_LIT.equals(body.getUse())) + { + rpcLiteralFound = true; + + // find corresponding message + Operation op = ctx.getBindingOperation().getOperation(); + // if some links are broken, cancel processing + if (op == null + || (parent instanceof BindingInput && op.getInput() == null) + || (parent instanceof BindingOutput && op.getOutput() == null)) + return; + + Message m = + (parent instanceof BindingInput) + ? op.getInput().getMessage() + : op.getOutput().getMessage(); + // REMOVE: current message should equals to message given as entry + //if (m == null || message != m) + if (m == null) + return; + + List parts = + WSDLUtil.getParts( + op, + m, + body, + WSIConstants.ATTRVAL_SOAP_BIND_STYLE_RPC); + if (parts == null) + return; + + /* check whether parts list contains a parts which uses + * element attribute. If so, part name will be added into + * errors set. + */ + Iterator it = parts.iterator(); + while (it.hasNext()) + { + Part part = (Part) it.next(); + if (part.getElementName() != null) + errors.add(part.getName()); + } + } + } + + /* + * Validates the test assertion. + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + result = AssertionResult.RESULT_FAILED; + // save message + //message = (Message)entryContext.getEntry().getEntryDetail(); + + WSDLTraversal traversal = new WSDLTraversal(); + //VisitorAdaptor.adapt(this);; + traversal.setVisitor(this); + traversal.visitSOAPBinding(true); + traversal.visitBindingOperation(true); + traversal.visitSOAPOperation(true); + traversal.visitSOAPBody(true); + + traversal.ignoreReferences(); + traversal.ignoreImport(); + + traversal.traverse((Binding) entryContext.getEntry().getEntryDetail()); + + if (!errors.isEmpty()) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = this.validator.createFailureDetail(errors.toString(), entryContext); + } + + else if (!rpcLiteralFound) + result = AssertionResult.RESULT_NOT_APPLICABLE; + + else + result = AssertionResult.RESULT_PASSED; + + return validator.createAssertionResult(testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2113.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2113.java new file mode 100644 index 000000000..7aef537ca --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2113.java @@ -0,0 +1,159 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +import java.util.HashMap; +import java.util.Map; + +import javax.wsdl.Binding; +import javax.wsdl.Definition; +import javax.wsdl.Fault; +import javax.wsdl.Message; +import javax.wsdl.Operation; +import javax.wsdl.Part; +import javax.wsdl.extensions.soap.SOAPFault; +import javax.wsdl.extensions.soap.SOAPHeader; +import javax.wsdl.extensions.soap.SOAPHeaderFault; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.WSITag; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcessVisitor; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.ErrorList; +import org.eclipse.wst.wsi.internal.util.WSDLUtil; +import org.eclipse.wst.wsi.internal.wsdl.traversal.WSDLTraversal; +import org.eclipse.wst.wsi.internal.wsdl.traversal.WSDLTraversalContext; + + +/** + * BP2113. + * For a candidate wsdl:binding element + * The soapbind:header, soapbind:headerfault and soapbind:fault elements only refer to wsdl:part element(s) that have been defined using the "element" attribute. + */ +public class BP2113 extends AssertionProcessVisitor implements WSITag +{ + private final WSDLValidatorImpl validator; + + /** + * @param WSDLValidatorImpl + */ + public BP2113(WSDLValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + private ErrorList errors = new ErrorList(); + + /* + * Verify soap header uses part is define using "element" attribute + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.extensions.soap.SOAPHeader, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit( + SOAPHeader header, + Object parent, + WSDLTraversalContext ctx) + { + Definition d = (Definition) ctx.getParameter("definition"); + Message m = d.getMessage(header.getMessage()); + if (m != null) + checkPart(m.getPart(header.getPart()), ctx.getBinding()); + } + + /* + * Verify soap headerfault uses part is define using "element" attribute + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.extensions.soap.SOAPHeaderFault, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit( + SOAPHeaderFault fault, + Object parent, + WSDLTraversalContext ctx) + { + Definition d = (Definition) ctx.getParameter("definition"); + Message m = d.getMessage(fault.getMessage()); + // if message or part is not found - NOT_APPLICABLE ???? + if (m != null) + checkPart(m.getPart(fault.getPart()), ctx.getBinding()); + } + + /* + * Verify soap fault uses part is define using "element" attribute + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.extensions.soap.SOAPFault, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit(SOAPFault fault, Object parent, WSDLTraversalContext ctx) + { + String faultName = fault.getName(); + if (faultName == null) + faultName = ctx.getBindingFault().getName(); + Operation op = ctx.getBindingOperation().getOperation(); + if (op == null /* || faultName == null*/ + ) // may be it's possible to have legal fault with null name + return; + // we suppose that SOAPFault.getName() corresponds to the abstract operation's fault name + Fault f = op.getFault(faultName); + if (f == null) + return; + Message m = f.getMessage(); + // message should have only one part + if (m == null || m.getParts() == null || m.getParts().size() != 1) + return; + checkPart((Part) m.getOrderedParts(null).get(0), ctx.getBinding()); + } + + /* + * Verify part is define using "element" attribute. + * @param p - part + * @param b - binding + */ + // refactoring + private void checkPart(Part p, Binding b) + { + if (p != null && p.getElementName() == null) + errors.add(b.getQName(), p.getName()); + } + + /* + * Validates the test assertion. + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + result = AssertionResult.RESULT_FAILED; + + WSDLTraversal traversal = new WSDLTraversal(); + //VisitorAdaptor.adapt(this);; + traversal.setVisitor(this); + traversal.visitSOAPHeader(true); + traversal.visitSOAPHeaderFault(true); + traversal.visitSOAPFault(true); + + Map m = new HashMap(); + Definition def = entryContext.getWSDLDocument().getDefinitions(); + WSDLUtil.expandDefinition(def); + m.put("definition", def); + traversal.traverse((Binding) entryContext.getEntry().getEntryDetail(), m); + + if (!errors.isEmpty()) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = this.validator.createFailureDetail(errors.toString(), entryContext); + } + else + result = AssertionResult.RESULT_PASSED; + + return validator.createAssertionResult(testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2114.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2114.java new file mode 100644 index 000000000..7987053cb --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2114.java @@ -0,0 +1,278 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import javax.wsdl.Binding; +import javax.wsdl.BindingInput; +import javax.wsdl.BindingOutput; +import javax.wsdl.Fault; +import javax.wsdl.Message; +import javax.wsdl.Operation; +import javax.wsdl.Part; +import javax.wsdl.extensions.soap.SOAPBinding; +import javax.wsdl.extensions.soap.SOAPBody; +import javax.wsdl.extensions.soap.SOAPFault; +import javax.wsdl.extensions.soap.SOAPHeader; +import javax.wsdl.extensions.soap.SOAPHeaderFault; +import javax.wsdl.extensions.soap.SOAPOperation; +import javax.xml.namespace.QName; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.WSITag; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcessVisitor; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.ErrorList; +import org.eclipse.wst.wsi.internal.util.WSDLUtil; +import org.eclipse.wst.wsi.internal.wsdl.traversal.WSDLTraversal; +import org.eclipse.wst.wsi.internal.wsdl.traversal.WSDLTraversalContext; + + +/** + * BP2114. + * For a candidate wsdl:binding element + * + * + * Every wsdl:part from each wsdl:message in the associated + * wsdl:portType is referenced either by the soapbind:body, soapbind:header, + * soapbind:fault, or soapbind:headerfault. + */ +public class BP2114 extends AssertionProcessVisitor implements WSITag +{ + private final WSDLValidatorImpl validator; + + /** + * @param WSDLValidatorImpl + */ + public BP2114(WSDLValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + private ErrorList errors = new ErrorList(); + // map Message QName -> set(Part name) + public Map messages = new HashMap(); + + /* + * Add to Map parts which used by message + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.Message, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit(Message m, Object parent, WSDLTraversalContext ctx) + { + if (m != null + && !messages.containsKey(m) + && m.getOrderedParts(null) != null) + { + Set s = new HashSet(); + Iterator it = m.getOrderedParts(null).iterator(); + while (it.hasNext()) + s.add(((Part) it.next()).getName()); + + //messages.put(m.getQName(), s); + if (s.size() > 0) + { + messages.put(m.getQName(), s); + } + } + } + + /* + * Put in context style of soap binding + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.extensions.soap.SOAPBinding, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit( + SOAPBinding binding, + Object parent, + WSDLTraversalContext ctx) + { + String style = + (binding.getStyle() == null) + ? WSIConstants.ATTRVAL_SOAP_BIND_STYLE_DOC + : binding.getStyle(); + ctx.addParameter("style", style); + } + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.extensions.soap.SOAPOperation, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit( + SOAPOperation operation, + Object parent, + WSDLTraversalContext ctx) + { + String style = operation.getStyle(); + if (style != null) + ctx.addParameter("style", style); + } + + /* + * Remove parts of soap body from Map. + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.extensions.soap.SOAPBody, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit(SOAPBody body, Object parent, WSDLTraversalContext ctx) + { + // String style = (String)ctx.getParameter("style"); + + // find corresponding message + Operation op = ctx.getBindingOperation().getOperation(); + // if some links are broken, cancel processing + if (op == null) + return; + Message m = null; + if (parent instanceof BindingInput) + { + if (op.getInput() == null) + return; + m = op.getInput().getMessage(); + } + else if (parent instanceof BindingOutput) + { + if (op.getOutput() == null) + return; + m = op.getOutput().getMessage(); + } + if (m == null) + return; + + // get parts + List parts = WSDLUtil.getParts(op, m, body, null); + if (parts == null) + return; + + // iterate all parts and check + Iterator it = parts.iterator(); + while (it.hasNext()) + removePart(m.getQName(), ((Part) it.next()).getName()); + } + + /* + * Remove parts of soap header from Map. + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.extensions.soap.SOAPHeader, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit( + SOAPHeader header, + Object parent, + WSDLTraversalContext ctx) + { + // we suppose that it possible to have legal message and part with null names + // ATTENTION + // should we add message which is referenced by header or headerfault to messages ? + removePart(header.getMessage(), header.getPart()); + } + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.extensions.soap.SOAPHeaderFault, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit( + SOAPHeaderFault fault, + Object parent, + WSDLTraversalContext ctx) + { + // we suppose that it possible to have legal message and patr with null names + QName messageName = fault.getMessage(); + if (messageName == null) + messageName = ctx.getSOAPHeader().getMessage(); + removePart(messageName, fault.getPart()); + } + + /* + * Remove parts of soap fault from Map. + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.extensions.soap.SOAPFault, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit(SOAPFault fault, Object parent, WSDLTraversalContext ctx) + { + String faultName = fault.getName(); + if (faultName == null) + faultName = ctx.getBindingFault().getName(); + Operation op = ctx.getBindingOperation().getOperation(); + if (op == null) + return; + + // we suppose that SOAPFault.getName() corresponds to the abstract operation's fault name + Fault f = op.getFault(faultName); + + // fault message should have 1 part + if (f == null + || f.getMessage() == null + || f.getMessage().getParts().size() != 1) + return; + + Part p = (Part) f.getMessage().getOrderedParts(null).get(0); + removePart(f.getMessage().getQName(), p.getName()); + } + + /* + * Remove part from Map. + * @param messageName - message + * @param partName - part + */ + // refatoring + private void removePart(QName messageName, String partName) + { + Set parts = (Set) messages.get(messageName); + if (parts != null) + { + parts.remove(partName); + if (parts.size() == 0) + messages.remove(messageName); + } + } + + /* + * Validates the test assertion. + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + result = AssertionResult.RESULT_WARNING; + + WSDLTraversal traversal = new WSDLTraversal(); + //VisitorAdaptor.adapt(this); + traversal.setVisitor(this); + traversal.visitMessage(true); + traversal.visitSOAPBinding(true); + traversal.visitSOAPBody(true); + traversal.visitSOAPHeader(true); + traversal.visitSOAPHeaderFault(true); + traversal.visitSOAPFault(true); + traversal.visitSOAPOperation(true); + + Binding b = (Binding) entryContext.getEntry().getEntryDetail(); + traversal.traverse(b); + + if (messages.size() > 0) + errors.add(b.getQName()); + + if (!errors.isEmpty()) + { + result = AssertionResult.RESULT_WARNING; + failureDetail = this.validator.createFailureDetail(errors.toString(), entryContext); + } + + else + result = AssertionResult.RESULT_PASSED; + + return validator.createAssertionResult(testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2115.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2115.java new file mode 100644 index 000000000..85626a071 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2115.java @@ -0,0 +1,97 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +import javax.wsdl.Message; +import javax.wsdl.Part; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.WSITag; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcessVisitor; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.ErrorList; +import org.eclipse.wst.wsi.internal.util.TypesRegistry; +import org.eclipse.wst.wsi.internal.wsdl.traversal.WSDLTraversal; +import org.eclipse.wst.wsi.internal.wsdl.traversal.WSDLTraversalContext; + + +/** + * BP2115. + * For a candidate wsdl:message + * An "element" attribute on any wsdl:part element refers to a global element declaration. + */ +public class BP2115 extends AssertionProcessVisitor implements WSITag +{ + private final WSDLValidatorImpl validator; + + /** + * @param WSDLValidatorImpl + */ + public BP2115(WSDLValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + private ErrorList errors = new ErrorList(); + private TypesRegistry registry = null; + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.Part, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit(Part part, Object parent, WSDLTraversalContext ctx) + { + if (part.getElementName() != null + && registry.getType(part.getElementName()) == null) + { + errors.add(ctx.getMessage().getQName()); + ctx.cancelMessageProcessing(); + } + } + + /* Validates the test assertion. + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + result = AssertionResult.RESULT_FAILED; + + registry = + new TypesRegistry( + entryContext.getWSDLDocument().getDefinitions(), + validator); + + WSDLTraversal traversal = new WSDLTraversal(); + //VisitorAdaptor.adapt(this); + traversal.setVisitor(this); + traversal.visitPart(true); + + traversal.ignoreReferences(); + traversal.ignoreImport(); + traversal.traverse((Message) entryContext.getEntry().getEntryDetail()); + + if (!errors.isEmpty()) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = this.validator.createFailureDetail(errors.toString(), entryContext); + } + + else + result = AssertionResult.RESULT_PASSED; + + return validator.createAssertionResult(testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2116.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2116.java new file mode 100644 index 000000000..810e74d60 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2116.java @@ -0,0 +1,88 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +import javax.wsdl.Message; +import javax.wsdl.Part; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.WSITag; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcessVisitor; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.ErrorList; +import org.eclipse.wst.wsi.internal.wsdl.traversal.WSDLTraversal; +import org.eclipse.wst.wsi.internal.wsdl.traversal.WSDLTraversalContext; + + +/** + * BP2116. + * For a candidate wsdl:message element + * The wsdl:message element does not contain part elements that use both "type" and "element" attributes. + */ +public class BP2116 extends AssertionProcessVisitor implements WSITag +{ + + private final WSDLValidatorImpl validator; + + /** + * @param WSDLValidatorImpl + */ + public BP2116(WSDLValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + private ErrorList errors = new ErrorList(); + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.Part, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit(Part part, Object parent, WSDLTraversalContext ctx) + { + if (part.getElementName() != null && part.getTypeName() != null) + { + errors.add(ctx.getMessage().getQName()); + ctx.cancelMessageProcessing(); + } + } + + /* Validates the test assertion. + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + result = AssertionResult.RESULT_FAILED; + + WSDLTraversal traversal = new WSDLTraversal(); + //VisitorAdaptor.adapt(this); + traversal.setVisitor(this); + traversal.visitPart(true); + traversal.ignoreReferences(); + traversal.ignoreImport(); + traversal.traverse((Message) entryContext.getEntry().getEntryDetail()); + + if (!errors.isEmpty()) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = this.validator.createFailureDetail(errors.toString(), entryContext); + } + else + result = AssertionResult.RESULT_PASSED; + + return validator.createAssertionResult(testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2117.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2117.java new file mode 100644 index 000000000..00fa22c46 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2117.java @@ -0,0 +1,183 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +import javax.wsdl.Binding; +import javax.wsdl.extensions.soap.SOAPBinding; +import javax.wsdl.extensions.soap.SOAPBody; +import javax.wsdl.extensions.soap.SOAPFault; +import javax.wsdl.extensions.soap.SOAPHeader; +import javax.wsdl.extensions.soap.SOAPHeaderFault; +import javax.wsdl.extensions.soap.SOAPOperation; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.WSITag; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcessVisitor; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.ErrorList; +import org.eclipse.wst.wsi.internal.wsdl.traversal.WSDLTraversal; +import org.eclipse.wst.wsi.internal.wsdl.traversal.WSDLTraversalContext; + + +/** + * BP2117. + * For a candidate wsdl:binding element, referred to by an rpc-literal soap:binding + * The rpc-literal binding does not have a namespace attribute specified on a contained soapbind:header, soapbind:headerfault, and soapbind:fault element. + */ +public class BP2117 extends AssertionProcessVisitor implements WSITag +{ + private final WSDLValidatorImpl validator; + + /** + * @param WSDLValidatorImpl + */ + public BP2117(WSDLValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + private boolean rpcLiteralFound = false; + private ErrorList errors = new ErrorList(); + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.extensions.soap.SOAPBinding, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit( + SOAPBinding binding, + Object parent, + WSDLTraversalContext ctx) + { + String style = + (binding.getStyle() == null) + ? WSIConstants.ATTRVAL_SOAP_BIND_STYLE_DOC + : binding.getStyle(); + ctx.addParameter("style", style); + } + + /* + * If use of soap body is "literal" and if at least one part is define using "element" attribute it creates falure report. + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.extensions.soap.SOAPBody, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit(SOAPBody body, Object parent, WSDLTraversalContext ctx) + { + // assert use == "literal" + if (WSIConstants.ATTRVAL_SOAP_BODY_USE_LIT.equals(body.getUse()) + && ((String) ctx.getParameter("style")).equals( + WSIConstants.ATTRVAL_SOAP_BIND_STYLE_RPC)) + { + rpcLiteralFound = true; + } + } + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.extensions.soap.SOAPOperation, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit( + SOAPOperation operation, + Object parent, + WSDLTraversalContext ctx) + { + String style = operation.getStyle(); + if (style == null) + style = (String) ctx.getParameter("style"); + + // assert style != null + if (!WSIConstants.ATTRVAL_SOAP_BIND_STYLE_RPC.equals(style)) + ctx.cancelBindingOperationProcessing(); + } + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.extensions.soap.SOAPHeader, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit( + SOAPHeader header, + Object parent, + WSDLTraversalContext ctx) + { + check(header.getUse(), header.getNamespaceURI(), ctx); + } + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.extensions.soap.SOAPHeaderFault, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit( + SOAPHeaderFault fault, + Object parent, + WSDLTraversalContext ctx) + { + check(fault.getUse(), fault.getNamespaceURI(), ctx); + } + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.extensions.soap.SOAPFault, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit(SOAPFault fault, Object parent, WSDLTraversalContext ctx) + { + check(fault.getUse(), fault.getNamespaceURI(), ctx); + } + + // refactoring + // check LITERAL use and != namespace + // canceling further processing + private void check(String use, String namespace, WSDLTraversalContext ctx) + { + if (WSIConstants.ATTRVAL_SOAP_BODY_USE_LIT.equals(use) + && namespace != null) + { + errors.add(ctx.getBinding().getQName()); + // suppresses subsequent processing, because error list contains only failed binding + ctx.cancelProcessing(); + } + } + + /* Validates the test assertion. + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + result = AssertionResult.RESULT_FAILED; + + WSDLTraversal traversal = new WSDLTraversal(); + //VisitorAdaptor.adapt(this); + traversal.setVisitor(this); + traversal.visitSOAPBinding(true); + traversal.visitSOAPBody(true); + traversal.visitSOAPHeader(true); + traversal.visitSOAPHeaderFault(true); + traversal.visitSOAPFault(true); + traversal.visitSOAPOperation(true); + + traversal.ignoreReferences(); + traversal.ignoreImport(); + traversal.traverse((Binding) entryContext.getEntry().getEntryDetail()); + + if (!errors.isEmpty()) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = this.validator.createFailureDetail(errors.toString(), entryContext); + } + + else if (!rpcLiteralFound) + result = AssertionResult.RESULT_NOT_APPLICABLE; + + else + result = AssertionResult.RESULT_PASSED; + + return validator.createAssertionResult(testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2118.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2118.java new file mode 100644 index 000000000..ef814613d --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2118.java @@ -0,0 +1,98 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +import javax.wsdl.Binding; +import javax.wsdl.Operation; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.WSITag; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcessVisitor; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.ErrorList; +import org.eclipse.wst.wsi.internal.wsdl.traversal.WSDLTraversal; +import org.eclipse.wst.wsi.internal.wsdl.traversal.WSDLTraversalContext; + + +/** + * BP2118. + * For a candidate wsdl:binding element + * The list (or set) of wsdl:operation elements for the contained wsdl:binding is the same as the list of wsdl:operations for the referred wsdl:portType. + */ +public class BP2118 extends AssertionProcessVisitor implements WSITag +{ + + private final WSDLValidatorImpl validator; + + /** + * @param WSDLValidatorImpl + */ + public BP2118(WSDLValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + private ErrorList errors = new ErrorList(); + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.Operation, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit(Operation op, Object parent, WSDLTraversalContext ctx) + { + // assert parent instanceof BindingOperation + if (op == null) + { + errors.add(ctx.getBinding().getQName()); + // suppresses subsequent processing, because error list contains only failed binding + ctx.cancelBindingProcessing(); + ctx.cancelBindingOperationProcessing(); + } + } + + /* Validates the test assertion. + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + result = AssertionResult.RESULT_FAILED; + + Binding b = (Binding) entryContext.getEntry().getEntryDetail(); + // if operations count in port type and binding is differ -> error + if (b.getPortType() == null + || b.getPortType().getOperations().size() + != b.getBindingOperations().size()) + errors.add(b.getQName()); + else + { + WSDLTraversal traversal = new WSDLTraversal(); + //VisitorAdaptor.adapt(this); + traversal.setVisitor(this); + traversal.visitOperation(true); + traversal.traverse(b); + } + + if (!errors.isEmpty()) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = this.validator.createFailureDetail(errors.toString(), entryContext); + } + else + result = AssertionResult.RESULT_PASSED; + + return validator.createAssertionResult(testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2119.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2119.java new file mode 100644 index 000000000..94aff8c62 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2119.java @@ -0,0 +1,165 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +import java.util.Map; + +import javax.wsdl.Binding; +import javax.wsdl.BindingInput; +import javax.wsdl.BindingOutput; +import javax.wsdl.Operation; +import javax.wsdl.extensions.soap.SOAPBinding; +import javax.wsdl.extensions.soap.SOAPBody; +import javax.wsdl.extensions.soap.SOAPOperation; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.WSITag; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcessVisitor; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.ErrorList; +import org.eclipse.wst.wsi.internal.wsdl.traversal.WSDLTraversal; +import org.eclipse.wst.wsi.internal.wsdl.traversal.WSDLTraversalContext; + + +/** + * BP2119. + * For a candidate wsdl:binding, which is of type document-literal + * If it does not specify the parts attribute on a soapbind:body element, the corresponding abstract wsdl:message defines zero or one wsdl:part. + */ +public class BP2119 extends AssertionProcessVisitor implements WSITag +{ + private final WSDLValidatorImpl validator; + + /** + * @param WSDLValidatorImpl + */ + public BP2119(WSDLValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + private boolean docLiteralFound = false; + private ErrorList errors = new ErrorList(); + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.extensions.soap.SOAPBinding, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit( + SOAPBinding binding, + Object parent, + WSDLTraversalContext ctx) + { + String style = + (binding.getStyle() == null) + ? WSIConstants.ATTRVAL_SOAP_BIND_STYLE_DOC + : binding.getStyle(); + ctx.addParameter("style", style); + } + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.extensions.soap.SOAPOperation, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit( + SOAPOperation operation, + Object parent, + WSDLTraversalContext ctx) + { + String style = operation.getStyle(); + if (style == null) + style = (String) ctx.getParameter("style"); + // assert style != null + if (!WSIConstants.ATTRVAL_SOAP_BIND_STYLE_DOC.equals(style)) + ctx.cancelBindingOperationProcessing(); + } + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.extensions.soap.SOAPBody, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit(SOAPBody body, Object parent, WSDLTraversalContext ctx) + { + String use = + (body.getUse() == null) + ? WSIConstants.ATTRVAL_SOAP_BODY_USE_LIT + : body.getUse(); + + // assert style == "document" + if (WSIConstants.ATTRVAL_SOAP_BODY_USE_LIT.equals(use)) + { + docLiteralFound = true; + if (body.getParts() == null) + { + Operation op = ctx.getBindingOperation().getOperation(); + if (op == null) + return; + + Map parts = null; + if (parent instanceof BindingInput) + { + if (op.getInput() == null || op.getInput().getMessage() == null) + return; + parts = op.getInput().getMessage().getParts(); + } + else if (parent instanceof BindingOutput) + { + if (op.getOutput() == null || op.getOutput().getMessage() == null) + return; + parts = op.getOutput().getMessage().getParts(); + } + + if (parts != null && parts.size() > 1) + { + errors.add(ctx.getBinding().getQName()); + // suppresses subsequent processing, because error list contains only failed binding + ctx.cancelBindingProcessing(); + ctx.cancelBindingOperationProcessing(); + ctx.cancelBindingInputProcessing(); + ctx.cancelBindingOutputProcessing(); + } + } + } + } + + /* Validates the test assertion. + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + result = AssertionResult.RESULT_FAILED; + + WSDLTraversal traversal = new WSDLTraversal(); + //VisitorAdaptor.adapt(this); + traversal.setVisitor(this); + traversal.visitSOAPBinding(true); + traversal.visitSOAPBody(true); + traversal.visitSOAPOperation(true); + traversal.ignoreImport(); + traversal.traverse((Binding) entryContext.getEntry().getEntryDetail()); + + if (!errors.isEmpty()) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = this.validator.createFailureDetail(errors.toString(), entryContext); + } + + else if (!docLiteralFound) + result = AssertionResult.RESULT_NOT_APPLICABLE; + + else + result = AssertionResult.RESULT_PASSED; + + return validator.createAssertionResult(testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2120.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2120.java new file mode 100644 index 000000000..5416e6e2a --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2120.java @@ -0,0 +1,247 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; + +import javax.wsdl.Binding; +import javax.wsdl.Message; +import javax.wsdl.Operation; +import javax.wsdl.Part; +import javax.wsdl.extensions.soap.SOAPBinding; +import javax.wsdl.extensions.soap.SOAPBody; +import javax.wsdl.extensions.soap.SOAPOperation; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.WSITag; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcessVisitor; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.ErrorList; +import org.eclipse.wst.wsi.internal.util.WSDLUtil; +import org.eclipse.wst.wsi.internal.wsdl.traversal.WSDLTraversal; +import org.eclipse.wst.wsi.internal.wsdl.traversal.WSDLTraversalContext; + + +/** + * BP2120. + * For a candidate wsdl:binding + * Each operation referenced by the binding results in a unique wire signature. + */ +public class BP2120 extends AssertionProcessVisitor implements WSITag +{ + private final WSDLValidatorImpl validator; + + /** + * @param WSDLValidatorImpl + */ + public BP2120(WSDLValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + private ErrorList errors = new ErrorList(); + private Set wares = new HashSet(); + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.extensions.soap.SOAPBinding, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit( + SOAPBinding binding, + Object parent, + WSDLTraversalContext ctx) + { + String style = + (binding.getStyle() == null) + ? WSIConstants.ATTRVAL_SOAP_BIND_STYLE_DOC + : binding.getStyle(); + ctx.addParameter("style", style); + } + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.extensions.soap.SOAPOperation, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit( + SOAPOperation operation, + Object parent, + WSDLTraversalContext ctx) + { + String style = operation.getStyle(); + if (style != null) + ctx.addParameter("style", style); + } + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.extensions.soap.SOAPBody, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit(SOAPBody body, Object parent, WSDLTraversalContext ctx) + { + List signature = new LinkedList(); + + String style = (String) ctx.getParameter("style"); + + // find corresponding message + Operation op = ctx.getBindingOperation().getOperation(); + + // if some links are broken, cancel processing + if (op == null + || op.getInput() == null + || op.getInput().getMessage() == null) + return; + Message m = op.getInput().getMessage(); + + List parts = WSDLUtil.getParts(op, m, body, style); + if (parts == null) + return; + // !! ATTENTION + // may be required to add types instead of part into signature ? + + // create signature + signature.addAll(parts); + + // suppose that wire signature for + // - rpc style = operation name + parts' qname + // - document style = parts' qname + if (WSIConstants.ATTRVAL_SOAP_BIND_STYLE_RPC.equals(style)) + signature.add(0, op.getName()); + + if (sameSignature(wares, signature)) + errors.add(op.getName()); + else + wares.add(signature); + } + + /** + * Check if the signature is in the set match. + */ + private boolean sameSignature(Set signatureSet, List signature) + { + boolean same = false; + + // Get iterator for set + Iterator set = signatureSet.iterator(); + while (set.hasNext() && !same) + { + // Get next signature from the set + List nextSignature = (List) set.next(); + + // Only continue if the signatures are the same size + if (nextSignature.size() == signature.size()) + { + Iterator iterator1 = nextSignature.iterator(); + Iterator iterator2 = signature.iterator(); + + // Assume same until a difference is found + same = true; + + // Process each list until a difference is found + while (iterator1.hasNext() && iterator2.hasNext() && same) + { + // Get the next elements + Object element1 = iterator1.next(); + Object element2 = iterator2.next(); + + // If the element is a string, then if equal check parts + if ((element1 instanceof String) + && (element2 instanceof String) + && (((String) element1).equals((String) element2))) + { + same = true; + } + + // If the elements are parts, then check if they are equal + else if ((element1 instanceof Part) && (element2 instanceof Part)) + { + same = sameParts((Part) element1, (Part) element2); + } + + else + { + same = false; + } + } + } + } + + return same; + } + + /** + * Check if two parts are the same. + */ + private boolean sameParts(Part part1, Part part2) + { + boolean same = false; + + // If the part has an element then see if they are the same + if (part1.getElementName() != null + && part2.getElementName() != null + && part1.getElementName().equals(part2.getElementName())) + { + same = true; + } + + // If the part has an type then see if they are the same + else if ( + part1.getTypeName() != null + && part2.getTypeName() != null + && part1.getTypeName().equals(part2.getTypeName())) + { + same = true; + } + + else + { + same = false; + } + + return same; + } + + /* Validates the test assertion. + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + result = AssertionResult.RESULT_FAILED; + + WSDLTraversal traversal = new WSDLTraversal(); + //VisitorAdaptor.adapt(this); + traversal.setVisitor(this); + traversal.visitSOAPBinding(true); + traversal.visitSOAPBody(true); + traversal.visitSOAPOperation(true); + traversal.ignoreBindingOutput(); + traversal.traverse((Binding) entryContext.getEntry().getEntryDetail()); + + // !! ATTENTION + // Analyze soapbind:body:namespace and service targetNamespace + if (!errors.isEmpty()) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = this.validator.createFailureDetail(errors.toString(), entryContext); + } + else + result = AssertionResult.RESULT_PASSED; + + return validator.createAssertionResult(testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2121.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2121.java new file mode 100644 index 000000000..8cb92ee8c --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2121.java @@ -0,0 +1,174 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +import java.util.Iterator; +import java.util.List; + +import javax.wsdl.Binding; +import javax.wsdl.BindingInput; +import javax.wsdl.BindingOutput; +import javax.wsdl.Message; +import javax.wsdl.Operation; +import javax.wsdl.Part; +import javax.wsdl.extensions.soap.SOAPBinding; +import javax.wsdl.extensions.soap.SOAPBody; +import javax.wsdl.extensions.soap.SOAPOperation; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.WSITag; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcessVisitor; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.ErrorList; +import org.eclipse.wst.wsi.internal.util.TypesRegistry; +import org.eclipse.wst.wsi.internal.util.WSDLUtil; +import org.eclipse.wst.wsi.internal.wsdl.traversal.WSDLTraversal; +import org.eclipse.wst.wsi.internal.wsdl.traversal.WSDLTraversalContext; + + +/** + * BP2121. + * Context: + * For a wsdl:binding element which is referenced directly or associated + * with a specified wsdl:port. + * + * Assertion Description: + * Each operation referenced by a document-literal binding must have a + * message definition where the wsdl:part references a global element + * definition. + */ +public class BP2121 extends AssertionProcessVisitor implements WSITag +{ + + private final WSDLValidatorImpl validator; + + /** + * @param WSDLValidatorImpl + */ + public BP2121(WSDLValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + private ErrorList errors = new ErrorList(); + private TypesRegistry registry = null; + + public void visit( + SOAPBinding binding, + Object parent, + WSDLTraversalContext ctx) + { + String style = + (binding.getStyle() == null) + ? WSIConstants.ATTRVAL_SOAP_BIND_STYLE_DOC + : binding.getStyle(); + ctx.addParameter("style", style); + } + public void visit( + SOAPOperation operation, + Object parent, + WSDLTraversalContext ctx) + { + String style = operation.getStyle(); + if (style == null) + style = (String) ctx.getParameter("style"); + // assert style != null + if (!WSIConstants.ATTRVAL_SOAP_BIND_STYLE_DOC.equals(style)) + ctx.cancelBindingOperationProcessing(); + } + + public void visit(SOAPBody body, Object parent, WSDLTraversalContext ctx) + { + // !! ATTENTION + // we suppose that soapbody child elements is its parts. + // assert style == "document" + if (WSIConstants.ATTRVAL_SOAP_BODY_USE_LIT.equals(body.getUse())) + { + // find corresponding message + Operation op = ctx.getBindingOperation().getOperation(); + // if some links are broken, cancel processing + if (op == null + || (parent instanceof BindingInput && op.getInput() == null) + || (parent instanceof BindingOutput && op.getOutput() == null)) + return; + + Message m = + (parent instanceof BindingInput) + ? op.getInput().getMessage() + : op.getOutput().getMessage(); + if (m == null) + return; + + // find parts which are involved in the given body + List parts = + WSDLUtil.getParts( + op, + m, + body, + WSIConstants.ATTRVAL_SOAP_BIND_STYLE_DOC); + if (parts == null) + return; + + // check parts + Iterator it = parts.iterator(); + while (it.hasNext()) + { + Part p = (Part) it.next(); + // check whether p declared as global element + if (p.getElementName() == null + || registry.getType(p.getElementName()) == null) + { + errors.add(op.getName()); + // suppresses subsequent processing, because error list contains only failed operation + ctx.cancelBindingOperationProcessing(); + } + } + } + } + + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + result = AssertionResult.RESULT_FAILED; + + registry = + new TypesRegistry( + entryContext.getWSDLDocument().getDefinitions(), + validator); + + // collect all types from messages to checkedParts map + WSDLTraversal traversal = new WSDLTraversal(); + //VisitorAdaptor.adapt(this); + traversal.setVisitor(this); + traversal.visitSOAPBinding(true); + traversal.visitSOAPBody(true); + traversal.visitSOAPOperation(true); + traversal.ignoreReferences(); + traversal.ignoreImport(); + traversal.traverse((Binding) entryContext.getEntry().getEntryDetail()); + + if (!errors.isEmpty()) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = this.validator.createFailureDetail(errors.toString(), entryContext); + } + else + result = AssertionResult.RESULT_PASSED; + + return validator.createAssertionResult(testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2122.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2122.java new file mode 100644 index 000000000..c4a5afb16 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2122.java @@ -0,0 +1,109 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +import java.util.List; + +import javax.wsdl.Definition; +import javax.wsdl.Types; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.UnknownExtensibilityElement; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.WSITag; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.ErrorList; + + +/** + * BP2122. + * For a candidate wsdl:types element + * The data type definition if any within the wsdl:types element is an XML schema definition defined in the XML Schema 1.0 Recommendation with the namespace URI "http://www.w3.org/2001/XMLSchema". + */ +public class BP2122 extends AssertionProcess +{ + private final WSDLValidatorImpl validator; + + /** + * @param WSDLValidatorImpl + */ + public BP2122(WSDLValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + private String context; + + /** + * @see org.eclipse.wst.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(TestAssertion, EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + result = AssertionResult.RESULT_PASSED; + ErrorList errorList = new ErrorList(); + + // Get the types from the entry context + Types types = (Types) entryContext.getEntry().getEntryDetail(); + + Definition definition = null; + + if (types != null) + { + if ((definition = + validator.analyzerContext.getCandidateInfo().getDefinition(types)) + == null) + { + throw new WSIException("Could not find types definition in any WSDL document."); + } + + context = definition.getDocumentBaseURI(); + + ExtensibilityElement extElement; + List extElements = types.getExtensibilityElements(); + + // Process each ext. element + for (int i = 0; i < extElements.size(); i++) + { + // If it is an unknown ext. element and it is a schema, then check it + if ((extElement = (ExtensibilityElement) extElements.get(i)) + instanceof UnknownExtensibilityElement) + { + if (!extElement.getElementType().equals(WSITag.ELEM_XSD_SCHEMA)) + { + // If it is not a schema definition, then it is an error + errorList.add( + extElement.getElementType().toString() + + " can not be a child of the wsdl:types element."); + } + } + } + } + + // If XMLSchemaValidator could not find any errors, check errors from the inline schema validator + if (errorList.isEmpty()) + errorList.add(validator.wsdlDocument.getSchemasValidationErrors()); + + if (!errorList.isEmpty()) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = this.validator.createFailureDetail(errorList.toString(), entryContext); + } + + return validator.createAssertionResult(testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2123.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2123.java new file mode 100644 index 000000000..392d06f4e --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2123.java @@ -0,0 +1,357 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +import javax.wsdl.Binding; +import javax.wsdl.BindingFault; +import javax.wsdl.BindingInput; +import javax.wsdl.BindingOperation; +import javax.wsdl.BindingOutput; +import javax.wsdl.Definition; +import javax.wsdl.Fault; +import javax.wsdl.Input; +import javax.wsdl.Message; +import javax.wsdl.Operation; +import javax.wsdl.Output; +import javax.wsdl.Part; +import javax.wsdl.Port; +import javax.wsdl.PortType; +import javax.wsdl.extensions.ExtensibilityElement; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.WSITag; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcessVisitor; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.wsdl.traversal.WSDLTraversal; +import org.eclipse.wst.wsi.internal.wsdl.traversal.WSDLTraversalContext; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; +import org.w3c.dom.Element; + + +/** + * BP2123. + * For a candidate wsdl:definitions, if it contains a wsdl:port, wsdl:binding, wsdl:portType, wsdl:operation, or wsdl:message + * Contained WSDL extension elements do not use the wsdl:required attribute value of "true". + */ +public class BP2123 extends AssertionProcessVisitor implements WSITag +{ + private final WSDLValidatorImpl validator; + + /** + * @param WSDLValidatorImpl + */ + public BP2123(WSDLValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + private boolean claimFound = false; + + private static final String PORT_KEY = "port"; + private static final String BINDING_KEY = "binding"; + private static final String PORT_TYPE_KEY = "port type"; + private static final String OPERATION_KEY = "operation"; + private static final String MESSAGE_KEY = "message"; + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.Port, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit(Port port, Object parent, WSDLTraversalContext ctx) + { + if (port != null) + { + if (containsLegalClaim(port.getDocumentationElement())) + { + claimFound = true; + ctx.addParameter(PORT_KEY, Boolean.TRUE); + } + else + { + ctx.addParameter(PORT_KEY, Boolean.FALSE); + } + } + } + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.Binding, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit(Binding binding, Object parent, WSDLTraversalContext ctx) + { + if (binding != null) + { + Boolean port = (Boolean) ctx.getParameter(PORT_KEY); + + if (port.booleanValue()) + { + ctx.addParameter(BINDING_KEY, Boolean.TRUE); + } + else + { + claimFound = containsClaim(binding.getDocumentationElement()); + ctx.addParameter( + BINDING_KEY, + new Boolean(containsLegalClaim(binding.getDocumentationElement()))); + } + } + } + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.PortType, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit(PortType type, Object parent, WSDLTraversalContext ctx) + { + if (type != null) + { + Boolean binding = (Boolean) ctx.getParameter(BINDING_KEY); + + if (binding.booleanValue()) + { + ctx.addParameter(PORT_TYPE_KEY, Boolean.TRUE); + } + else + { + claimFound = containsClaim(type.getDocumentationElement()); + ctx.addParameter( + PORT_TYPE_KEY, + new Boolean(containsLegalClaim(type.getDocumentationElement()))); + } + } + } + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.Operation, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit( + Operation operation, + Object parent, + WSDLTraversalContext ctx) + { + if (operation != null) + { + Boolean type = (Boolean) ctx.getParameter(PORT_TYPE_KEY); + + if (type.booleanValue()) + { + ctx.addParameter(OPERATION_KEY, Boolean.TRUE); + } + else + { + claimFound = containsClaim(operation.getDocumentationElement()); + ctx.addParameter( + OPERATION_KEY, + new Boolean( + containsLegalClaim(operation.getDocumentationElement()))); + } + } + } + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.Message, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit(Message message, Object parent, WSDLTraversalContext ctx) + { + if (message != null) + { + Boolean operation = (Boolean) ctx.getParameter(OPERATION_KEY); + + if (operation.booleanValue()) + { + ctx.addParameter(MESSAGE_KEY, Boolean.TRUE); + } + else + { + claimFound = containsClaim(message.getDocumentationElement()); + ctx.addParameter( + MESSAGE_KEY, + new Boolean(containsLegalClaim(message.getDocumentationElement()))); + } + } + } + + /* + public void visit(BindingOperation operation, Object parent, WSDLTraversalContext ctx) { + if (operation != null) { + if (containsLegalClaim(operation.getDocumentationElement())) { + System.out.println("binding operation found"); + } else { + + } + } + } + */ + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.extensions.ExtensibilityElement, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + + public void visit( + ExtensibilityElement el, + Object parent, + WSDLTraversalContext ctx) + { + boolean required = + el != null + && el.getRequired() != null + && el.getRequired().booleanValue(); + + if (isParentConforms(parent, ctx)) + { + if (required) + { + result = AssertionResult.RESULT_WARNING; + failureDetailMessage = el.toString(); + } + } + } + + /** + * Indicates whether the parent element conforms to the basic profile. + * @param parent + * @param ctx + * @return boolean + */ + private boolean isParentConforms(Object parent, WSDLTraversalContext ctx) + { + boolean result = false; + + if (parent instanceof Port) + { + result = ((Boolean) ctx.getParameter(PORT_KEY)).booleanValue(); + } + else if ( + parent instanceof Binding + || parent instanceof BindingOperation + || parent instanceof BindingInput + || parent instanceof BindingOutput + || parent instanceof BindingFault) + { + result = ((Boolean) ctx.getParameter(BINDING_KEY)).booleanValue(); + } + else if (parent instanceof PortType) + { + result = ((Boolean) ctx.getParameter(PORT_TYPE_KEY)).booleanValue(); + } + else if ( + parent instanceof Operation + || parent instanceof Input + || parent instanceof Output + || parent instanceof Fault) + { + result = ((Boolean) ctx.getParameter(OPERATION_KEY)).booleanValue(); + } + else if (parent instanceof Message || parent instanceof Part) + { + result = ((Boolean) ctx.getParameter(MESSAGE_KEY)).booleanValue(); + } + + return result; + } + + /** + * @see org.eclipse.wst.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(TestAssertion, EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + result = AssertionResult.RESULT_PASSED; + + // Expect wsdl:defintions + Definition def = (Definition) entryContext.getEntry().getEntryDetail(); + //((Service)def.getServices().values().toArray()[0]).getPorts() + // Traverse WSDL + WSDLTraversal traversal = new WSDLTraversal(); + // VisitorAdaptor.adapt(this); + traversal.setVisitor(this); + traversal.visitOperation(true); + traversal.visitBinding(true); + traversal.visitMessage(true); + traversal.visitPort(true); + traversal.visitPortType(true); + traversal.visitExtensibilityElement(true); + + traversal.ignoreImport(); + traversal.ignoreDefinition2Binding(); + traversal.ignoreDefinition2Element(); + traversal.ignoreDefinition2ExtensibilityElement(); + traversal.ignoreDefinition2Message(); + traversal.ignoreDefinition2PortType(); + traversal.ignoreDefinition2Types(); + + traversal.traverse(def); + + if (!claimFound) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + + else if (result.equals(AssertionResult.RESULT_WARNING)) + { + failureDetail = this.validator.createFailureDetail(failureDetailMessage, entryContext); + } + + return validator.createAssertionResult(testAssertion, result, failureDetail); + } + + /** + * Check the documentation element whether contains conformance claims. + * Returns true if documentation element contains conformance claim with + * legal schema definition URI. + * legal is 'http://ws-i.org/schemas/conformanceClaim/' + * @param el + * @return boolean + */ + private boolean containsClaim(Element el) + { + if (el == null) + return false; + // find claim + el = XMLUtils.findChildElement(el, WSI_CLAIM); + if (el != null) + { + return true; + } + return false; + } + + /** + * Check the documentation element whether contains conformance claims. + * Returns true if documentation element contains conformance claim with + * legal schema definition URI. + * legal is 'http://ws-i.org/schemas/conformanceClaim/' + * @param el + * @return boolean + */ + private boolean containsLegalClaim(Element el) + { + if (el == null) + return false; + // find claim + el = XMLUtils.findChildElement(el, WSI_CLAIM); + while (el != null) + { + String value = el.getAttribute(ATTR_CLAIM_CONFORMSTO.getLocalPart()); + if (value != null + && value.equalsIgnoreCase(WSIConstants.ATTRVAL_UDDI_CLAIM_KEYVALUE)) + { + return true; + } + + el = XMLUtils.findElement(el, WSI_CLAIM); + } + return false; + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2201.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2201.java new file mode 100644 index 000000000..fdabb10ce --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2201.java @@ -0,0 +1,189 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; +import java.io.FileInputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.Enumeration; + +import javax.wsdl.Definition; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.StringTokenizer; + +/** + * BP2201. + * For a candidate Web service definition within a WSDL document with a XML declaration statement. + * The XML declaration statement uses UTF-8 or UTF-16 for the encoding. + */ +public class BP2201 extends AssertionProcess +{ + private final WSDLValidatorImpl validator; + + /** + * @param WSDLValidatorImpl + */ + public BP2201(WSDLValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + private final char[] OMMITED_XML_DECLARATION_DELIMITERS = new char[]{0x20, + 0x9, 0xD, 0xA, '\'', '\"'}; + private final char[] XML_DECLARATION_DELIMITERS = new char[]{'='}; + private final String UTF_8_ENCODING = "UTF-8"; + private final String UTF_16_ENCODING = "UTF-16"; + private final String ENCODING_TOKEN = "encoding"; + /* + * (non-Javadoc) + * + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, + * org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate(TestAssertion testAssertion, + EntryContext entryContext) throws WSIException + { + result = AssertionResult.RESULT_PASSED; + Definition definition = (Definition) entryContext.getEntry() + .getEntryDetail(); + String location = definition.getDocumentBaseURI(); + String xmlDecl = readXMLDeclarationStatement(location); + if (xmlDecl == null) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } else + { + if (!validEncoding(xmlDecl)) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = validator.createFailureDetail(xmlDecl, entryContext); + } + } + // Return assertion result + return validator.createAssertionResult(testAssertion, result, failureDetail); + } + /** + * Reads an XML declaration statement. + * + * @param location + * @return String + */ + private String readXMLDeclarationStatement(String location) + { + String result = null; + if (location != null) + { + URL url = null; + Reader reader = null; + try + { + try + { + url = new URL(location); + } catch (MalformedURLException e) + { + // we should try to access location as file + } + if (url != null) + { + reader = new InputStreamReader(url.openStream()); + } else + { + reader = new InputStreamReader(new FileInputStream(location)); + } + int charCode; + boolean end = false; + if (reader.ready()) + { + charCode = reader.read(); + while (reader.ready() && !(charCode == '<')) + { + charCode = reader.read(); + } + char[] c = new char[4]; + reader.read(c); + StringBuffer buf = new StringBuffer(); + if (new String(c).toLowerCase().equals("?xml")) + { + buf.append("'; + } + } else + { + // NOTE: This result does not get propogated back! + this.result = AssertionResult.RESULT_NOT_APPLICABLE; + return null; + } + result = buf.toString(); + } + } catch (Exception e) + { + //VERBOSE + if (validator.verboseOption) + { + System.err.println(" [WSI2201] Exception: " + e.getMessage()); + } + } finally + { + if (reader != null) + { + try + { + reader.close(); + } catch (Throwable e) + { + } + } + } + } + return result; + } + /* + * Verify xml declaration contains utf-16 or utf-8 encoding. @param xmlDecl - + * xml declaration @return + */ + private boolean validEncoding(String xmlDecl) + { + //boolean result = false; + boolean result = true; + if (xmlDecl != null) + { + StringTokenizer st = new StringTokenizer( + OMMITED_XML_DECLARATION_DELIMITERS, XML_DECLARATION_DELIMITERS); + Enumeration tokens = st.parse(xmlDecl); + boolean found = false; + while (tokens.hasMoreElements() && !found) + { + String token = (String) tokens.nextElement(); + if (token.equals(ENCODING_TOKEN)) + { + found = true; + tokens.nextElement(); + String enc = (String) tokens.nextElement(); + result = UTF_8_ENCODING.equalsIgnoreCase(enc) + || UTF_16_ENCODING.equalsIgnoreCase(enc); + } + } + } + return result; + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2202.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2202.java new file mode 100644 index 000000000..1078c7be2 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2202.java @@ -0,0 +1,423 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +import java.io.FileInputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.Enumeration; +import java.util.Iterator; +import java.util.List; + +import javax.wsdl.Definition; +import javax.wsdl.Types; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.UnknownExtensibilityElement; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.WSITag; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.ErrorList; +import org.eclipse.wst.wsi.internal.util.StringTokenizer; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; +import org.w3c.dom.Attr; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; + + +/** + * BP2202. + * For a candidate wsdl:types element within a WSDL document which imports an XML schema directly or indirectly. + * The imported schema uses UTF-8 or UTF-16 for the encoding. + */ +public class BP2202 extends AssertionProcess implements WSITag +{ + private final WSDLValidatorImpl validator; + + /** + * @param WSDLValidatorImpl + */ + public BP2202(WSDLValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + private ErrorList errors = new ErrorList(); + private boolean importFound = false; + + private final char[] OMMITED_XML_DECLARATION_DELIMITERS = + new char[] { 0x20, 0x9, 0xD, 0xA, '\'', '\"' }; + private final char[] XML_DECLARATION_DELIMITERS = new char[] { '=' }; + private final String UTF_8_ENCODING = "UTF-8"; + private final String UTF_16_ENCODING = "UTF-16"; + + private final String ENCODING_TOKEN = "encoding"; + private final String VERSION_TOKEN = "version"; + + /* (non-Javadoc) + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + result = result = AssertionResult.RESULT_NOT_APPLICABLE; + + //Definition def = (Definition) entryContext.getEntry().getEntryDetail(); + Types types = (Types) entryContext.getEntry().getEntryDetail(); + List exts = null; + //if (def.getTypes() != null) + if (types != null) + //exts = def.getTypes().getExtensibilityElements(); + exts = types.getExtensibilityElements(); + if (exts != null) + { + Definition definition = null; + if ((definition = + validator.analyzerContext.getCandidateInfo().getDefinition(types)) + == null) + { + throw new WSIException("Could not find types definition in any WSDL document."); + } + + Iterator it = exts.iterator(); + while (it.hasNext()) + { + ExtensibilityElement el = (ExtensibilityElement) it.next(); + if (el instanceof UnknownExtensibilityElement + && el.getElementType().equals(ELEM_XSD_SCHEMA)) + searchForSchema(((UnknownExtensibilityElement) el).getElement(), + definition.getDocumentBaseURI()); + } + } + + if (!errors.isEmpty()) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = this.validator.createFailureDetail(errors.toString(), entryContext); + } + + else if (!importFound) + result = AssertionResult.RESULT_NOT_APPLICABLE; + + else + result = AssertionResult.RESULT_PASSED; + + return validator.createAssertionResult(testAssertion, result, failureDetail); + } + + /* + * Search xsd schema or xsd import from node. If node is xsd import it's loading schema. + * @param n - node + */ + private void searchForSchema(Node n, String context) + { + while (n != null) + { + // searches for xsd:import element + if (Node.ELEMENT_NODE == n.getNodeType()) + { + // if xsd:schema element is found -> process schema + if (XMLUtils.equals(n, ELEM_XSD_SCHEMA)) + { + processSchema(n, context); + } + else + { + // if xsd:import element is found -> load schema and process schema + if (XMLUtils.equals(n, ELEM_XSD_IMPORT)) + { + importFound = true; + loadSchema(n, context); + } + else + // else iterate element recursively + searchForSchema(n.getFirstChild(), context); + } + } + n = n.getNextSibling(); + } + } + + /* + * It loads xsd schema and then check valid encoding and looking for xsd:schema element for next process. + * @param importNode - xsd schema + */ + private void loadSchema(Node importNode, String context) + { + Element im = (Element) importNode; + Attr schemaLocation = XMLUtils.getAttribute(im, ATTR_XSD_SCHEMALOCATION); + // try to parse imported XSD + if (schemaLocation != null && schemaLocation.getValue() != null) + try + { + // if any error or root element is not XSD schema -> error + String decl = + readXMLDeclarationStatement(schemaLocation.getValue(), context); + if (!validDeclaration(decl, + ENCODING_TOKEN, + new String[] { UTF_8_ENCODING, UTF_16_ENCODING })) + { + Attr a = XMLUtils.getAttribute(im, ATTR_XSD_NAMESPACE); + errors.add((a != null) ? a.getValue() : ""); + } + + if (!validDeclaration(decl, "version", new String[] { "1.0" })) + { + errors.add( + "Version number in XML declaration is not 1.0. XML schema file: " + + schemaLocation.getValue()); + } + + // DEBUG: + // System.out.println(schemaLocation.getValue() + ":" + context); + + Document schema = + validator.parseXMLDocumentURL(schemaLocation.getValue(), context); + + if (XMLUtils.equals(schema.getDocumentElement(), ELEM_XSD_SCHEMA)) + { + Attr a = XMLUtils.getAttribute(im, ATTR_XSD_NAMESPACE); + String namespace = (a != null) ? a.getValue() : ""; + processSchema(schema.getDocumentElement(), + XMLUtils.createURLString(schemaLocation.getValue(), context)); + } + result = result = AssertionResult.RESULT_PASSED; + } + catch (Throwable t) + { + } + } + + /** + * Reads an XML declaration statement. + * @param location + * @return String + */ + private String readXMLDeclarationStatement(String location, String baseURI) + { + String result = null; + try + { + new URL(location); + } + catch (Throwable t) + { + // nothing + int i = baseURI.lastIndexOf('/'); + int j = baseURI.lastIndexOf('\\'); + if (j > i) + i = j; + location = baseURI.substring(0, i + 1) + location; + } + + if (location != null) + { + URL url = null; + Reader reader = null; + + try + { + try + { + url = new URL(location); + } + catch (MalformedURLException e) + { + // we should try to access location as file + } + + if (url != null) + { + reader = new InputStreamReader(url.openStream()); + } + else + { + reader = new InputStreamReader(new FileInputStream(location)); + } + + int charCode; + boolean end = false; + if (reader.ready()) + { + charCode = reader.read(); + + while (reader.ready() && !(charCode == '<')) + { + charCode = reader.read(); + } + + StringBuffer buf = new StringBuffer(); + if (charCode == '<') + { + buf.append((char) charCode); + while (reader.ready() && !end) + { + charCode = reader.read(); + buf.append((char) charCode); + + end = charCode == '>'; + } + } + else + { + // NOTE: This result does not get propogated back! + result = AssertionResult.RESULT_FAILED; + failureDetailMessage = + "Cannot read the XML declaration statement."; + } + + result = buf.toString(); + } + } + catch (Exception e) + { + errors.add(e.getMessage()); + } + finally + { + if (reader != null) + { + try + { + reader.close(); + } + catch (Throwable e) + { + } + } + } + } + + return result; + } + + /* + * @param xmlDecl - xml declaration + * @return if xml declaration contains encoding="utf-16" or encoding="utf-8" it retirns true. + */ + + private boolean validEncoding(String xmlDecl) + { + //boolean result = false; + boolean result = true; + if (xmlDecl != null) + { + StringTokenizer st = + new StringTokenizer( + OMMITED_XML_DECLARATION_DELIMITERS, + XML_DECLARATION_DELIMITERS); + Enumeration tokens = st.parse(xmlDecl); + boolean found = false; + while (tokens.hasMoreElements() && !found) + { + String token = (String) tokens.nextElement(); + + if (token.equals(ENCODING_TOKEN)) + { + found = true; + + tokens.nextElement(); + String enc = (String) tokens.nextElement(); + + result = + UTF_8_ENCODING.equalsIgnoreCase(enc) + || UTF_16_ENCODING.equalsIgnoreCase(enc); + } + } + } + + return result; + } + + /** + * @param xmlDecl - xml declaration + * @return if xml declaration contains valid version number then true is returned. + */ + private boolean validDeclaration( + String xmlDecl, + String tokenName, + String[] checkValueList) + { + //boolean result = false; + boolean result = true; + if (xmlDecl != null) + { + StringTokenizer st = + new StringTokenizer( + OMMITED_XML_DECLARATION_DELIMITERS, + XML_DECLARATION_DELIMITERS); + Enumeration tokens = st.parse(xmlDecl); + + if (tokens.hasMoreElements()) + { + boolean found = false; + while (tokens.hasMoreElements() && !found) + { + String token = (String) tokens.nextElement(); + + if (token.equals(tokenName)) + { + found = true; + result = false; + + tokens.nextElement(); + String tokenValue = (String) tokens.nextElement(); + + for (int i = 0; i < checkValueList.length && !result; i++) + { + if (checkValueList[i].equalsIgnoreCase(tokenValue)) + result = true; + } + } + } + } + + // If there are no tokens then it is not a valid declaraction + else + { + result = false; + } + } + + return result; + } + + /* + * It's looking for xsd import and load it if find. + * @param schema - xsd schema + * @param namespace - namespace of schema + */ + private void processSchema(Node schema, String context) + { + Node n = schema.getFirstChild(); + while (n != null) + { + if (Node.ELEMENT_NODE == n.getNodeType() + && XMLUtils.equals(n, ELEM_XSD_IMPORT)) + { + importFound = true; + loadSchema(n, context); + } + + n = n.getNextSibling(); + } + } + +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2208.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2208.java new file mode 100644 index 000000000..57fc3fa99 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2208.java @@ -0,0 +1,72 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +import javax.wsdl.Operation; +import javax.wsdl.OperationType; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.report.AssertionResult; + + +/** + * BP2208. + * For a candidate wsdl:operation in a wsdl:portType definition + * The wsdl:operation element is either a WSDL request/response or a one-way operation (no Notification or Sollicit-Response). + */ +public class BP2208 extends AssertionProcess +{ + private final WSDLValidatorImpl validator; + + /** + * @param WSDLValidatorImpl + */ + public BP2208(WSDLValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + /* (non-Javadoc) + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + + Operation operation = + (Operation) entryContext.getEntry().getEntryDetail(); + OperationType opType = operation.getStyle(); + if ((opType == null) + || (!opType.equals(OperationType.ONE_WAY) + && !opType.equals(OperationType.REQUEST_RESPONSE))) + { + result = AssertionResult.RESULT_FAILED; + if (opType == null) + failureDetail = + this.validator.createFailureDetail( + "Could not determine the operation type for " + + operation.getName() + + ".", + entryContext); + else + failureDetail = null; // none defined in TAD at present + } + + // Return assertion result + return validator.createAssertionResult(testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2402.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2402.java new file mode 100644 index 000000000..6068be631 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2402.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +import javax.wsdl.Binding; +import javax.wsdl.extensions.soap.SOAPBinding; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.report.AssertionResult; + + +/** + * BP2402. + * For a candidate wsdl:binding element + * The wsdl:binding element has a soapbind:binding child element. + */ +public class BP2402 extends AssertionProcess +{ + private final WSDLValidatorImpl validator; + + /** + * @param WSDLValidatorImpl + */ + public BP2402(WSDLValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + /* (non-Javadoc) + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + result = AssertionResult.RESULT_FAILED; + + // Get the port from the entry context + //Port port = (Port) entryContext.getEntry().getEntryDetail(); + Binding binding = (Binding) entryContext.getEntry().getEntryDetail(); + + // Try to get the SOAP binding + SOAPBinding soapBinding = WSDLValidatorImpl.getSoapBinding(binding); + + // Test the assertion + // Check that there is at least one SOAP Binding + if (soapBinding != null) + { + result = AssertionResult.RESULT_PASSED; + failureDetail = null; + } + + // Return assertion result + return validator.createAssertionResult(testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2404.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2404.java new file mode 100644 index 000000000..9e60fa0b6 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2404.java @@ -0,0 +1,76 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +import javax.wsdl.Binding; +import javax.wsdl.extensions.soap.SOAPBinding; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.report.AssertionResult; + + +/** + * BP2404. + * For a candidate wsdl:binding element + * The contained soap:binding element has a "transport" attribute, which has value: http://schemas.xmlsoap.org/soap/http. + */ +public class BP2404 extends AssertionProcess +{ + private final WSDLValidatorImpl validator; + + /** + * @param WSDLValidatorImpl + */ + public BP2404(WSDLValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + /* (non-Javadoc) + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + + result = AssertionResult.RESULT_PASSED; + + // Get the binding from the entry context + Binding binding = (Binding) entryContext.getEntry().getEntryDetail(); + + // Try to get the SOAP binding + SOAPBinding soapBinding = WSDLValidatorImpl.getSoapBinding(binding); + + // Test the assertion + // Check for Soap binding namespace + if ((soapBinding == null) + || (soapBinding.getTransportURI() == null) + || !soapBinding.getTransportURI().equals(WSIConstants.NS_URI_SOAP_HTTP)) + { + result = AssertionResult.RESULT_FAILED; + this.validator.createFailureDetail( + soapBinding == null + ? "WSDL document does not contain SOAP binding element." + : soapBinding.toString(), + entryContext); + } + + // Return assertion result + return validator.createAssertionResult(testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2406.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2406.java new file mode 100644 index 000000000..cd3917d6e --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2406.java @@ -0,0 +1,166 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +import javax.wsdl.Binding; +import javax.wsdl.extensions.soap.SOAPBody; +import javax.wsdl.extensions.soap.SOAPFault; +import javax.wsdl.extensions.soap.SOAPHeader; +import javax.wsdl.extensions.soap.SOAPHeaderFault; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.report.AssertionResult; + + +/** + * BP2406. + * For a candidate wsdl:binding element, if the use attribute is specified on the soapbind:body, soapbind:fault, soapbind:header, or soapbind:headerfault elements. + * The use attribute has a value of "literal". + */ +public class BP2406 extends AssertionProcess +{ + private final WSDLValidatorImpl validator; + + /** + * @param WSDLValidatorImpl + */ + public BP2406(WSDLValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + /* (non-Javadoc) + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + + // Get the binding from the entry context + Binding binding = (Binding) entryContext.getEntry().getEntryDetail(); + + // Get SOAP body elements + SOAPBody[] soapBodies = this.validator.getSoapBodies(binding); + + // ADD: What happens if there are no soap body elements? Right now the TA result is NA. + + // Test the assertion + // Check for correct use value + for (int i = 0; i < soapBodies.length; i++) + { + SOAPBody soapBody = soapBodies[i]; + if (soapBody.getUse() != null + && !soapBody.getUse().equals(WSIConstants.ATTRVAL_SOAP_BODY_USE_LIT)) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = + this.validator.createFailureDetail(soapBody.toString(), entryContext); + break; + } + } + + // Get SOAP fault elements + SOAPFault[] soapFaults = this.validator.getSoapFaults(binding); + + // Test the assertion + // Check for correct use value + for (int i = 0; i < soapFaults.length; i++) + { + SOAPFault soapFault = soapFaults[i]; + if (soapFault.getUse() != null + && !soapFault.getUse().equals(WSIConstants.ATTRVAL_SOAP_BODY_USE_LIT)) + { + result = AssertionResult.RESULT_FAILED; + failureDetailMessage = + (failureDetailMessage == null + ? soapFault.toString() + : failureDetailMessage + "\n\n" + soapFault.toString()); + if (failureDetail == null) + failureDetail = + this.validator.createFailureDetail(failureDetailMessage, entryContext); + else + failureDetail.setFailureMessage(failureDetailMessage); + break; + } + } + + // Get SOAP header elements + SOAPHeader[] soapHeaders = this.validator.getSoapHeaders(binding); + + // Test the assertion + // Check for correct use value + for (int i = 0; i < soapHeaders.length; i++) + { + SOAPHeader soapHeader = soapHeaders[i]; + if (soapHeader.getUse() != null + && !soapHeader.getUse().equals(WSIConstants.ATTRVAL_SOAP_BODY_USE_LIT)) + { + result = AssertionResult.RESULT_FAILED; + failureDetailMessage = + (failureDetailMessage == null + ? soapHeader.toString() + : failureDetailMessage + "\n\n" + soapHeader.toString()); + if (failureDetail == null) + failureDetail = + this.validator.createFailureDetail(failureDetailMessage, entryContext); + else + failureDetail.setFailureMessage(failureDetailMessage); + break; + } + } + + // Get SOAP header fault elements + SOAPHeaderFault[] soapHeaderFaults = this.validator.getSoapHeaderFaults(binding); + + // Test the assertion + // Check for correct use value + for (int i = 0; i < soapHeaderFaults.length; i++) + { + SOAPHeaderFault soapHeaderFault = soapHeaderFaults[i]; + if (soapHeaderFault.getUse() != null + && !soapHeaderFault.getUse().equals( + WSIConstants.ATTRVAL_SOAP_BODY_USE_LIT)) + { + result = AssertionResult.RESULT_FAILED; + failureDetailMessage = + (failureDetailMessage == null + ? soapHeaderFault.toString() + : failureDetailMessage + "\n\n" + soapHeaderFault.toString()); + if (failureDetail == null) + failureDetail = + this.validator.createFailureDetail(failureDetailMessage, entryContext); + else + failureDetail.setFailureMessage(failureDetailMessage); + break; + } + } + + // If the result is passed, but there was nothing to check then set to notApplicable + if (result == AssertionResult.RESULT_PASSED + && (soapBodies == null || soapBodies.length == 0) + && (soapFaults == null || soapFaults.length == 0) + && (soapHeaders == null || soapHeaders.length == 0) + && (soapHeaderFaults == null || soapHeaderFaults.length == 0)) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + + // Return assertion result + return validator.createAssertionResult(testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2416.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2416.java new file mode 100644 index 000000000..9db9cd284 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2416.java @@ -0,0 +1,209 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import javax.wsdl.Binding; +import javax.wsdl.Definition; +import javax.wsdl.Fault; +import javax.wsdl.Input; +import javax.wsdl.Operation; +import javax.wsdl.Output; +import javax.wsdl.Port; +import javax.wsdl.PortType; +import javax.xml.namespace.QName; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcessVisitor; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.wsdl.traversal.WSDLTraversal; +import org.eclipse.wst.wsi.internal.wsdl.traversal.WSDLTraversalContext; + + +/** +* BP2416. +* For a candidate wsdl:definitions +* Every QName in the WSDL document and its imports, is referencing an element in a namespace that has either been imported or defined in the WSDL document that contains the reference. +*/ +public class BP2416 extends AssertionProcessVisitor +{ + private final WSDLValidatorImpl validator; + + /** + * @param WSDLValidatorImpl + */ + public BP2416(WSDLValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + private static final String NS_LIST_KEY = "namespaces"; + + /** + * Checks whether the namespace is defined or imported in the definition. + * @param qname + * @param ctx + */ + private void checkNamespace(QName qname, WSDLTraversalContext ctx) + { + if (qname != null) + { + String namespace = qname.getNamespaceURI(); + + if (namespace != null) + { + List namespaces = (List) ctx.getParameter(NS_LIST_KEY); + + if (!namespaces.contains(namespace)) + { + result = AssertionResult.RESULT_FAILED; + failureDetailMessage = namespace; + + ctx.cancelProcessing(); + } + } // ??? should we do something otherwise + } + } + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.Port, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit(Port port, Object parent, WSDLTraversalContext ctx) + { + if (port != null) + { + Binding binding = port.getBinding(); + if (binding != null) + { + checkNamespace(binding.getQName(), ctx); + } + } + } + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.Binding, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit(Binding binding, Object parent, WSDLTraversalContext ctx) + { + if (binding != null) + { + PortType pType = binding.getPortType(); + if (pType != null) + { + checkNamespace(pType.getQName(), ctx); + } + } + } + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.Operation, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit( + Operation operation, + Object parent, + WSDLTraversalContext ctx) + { + if (operation != null) + { + Input input = operation.getInput(); + if (input != null && input.getMessage() != null) + { + checkNamespace(input.getMessage().getQName(), ctx); + } + + Output output = operation.getOutput(); + if (output != null && output.getMessage() != null) + { + checkNamespace(output.getMessage().getQName(), ctx); + } + + Map faults = operation.getFaults(); + for (Iterator iter = faults.values().iterator(); iter.hasNext();) + { + Fault fault = (Fault) iter.next(); + + if (fault.getMessage() != null) + { + checkNamespace(fault.getMessage().getQName(), ctx); + } + } + } + } + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.Message, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + /* REMOVE: This is already done in WSI2417 + public void visit(Message message, Object parent, WSDLTraversalContext ctx) { + if (message != null) { + Map parts = message.getParts(); + for (Iterator iter = parts.values().iterator(); iter.hasNext();) { + Part part = (Part) iter.next(); + + checkNamespace(part.getElementName(), ctx); + checkNamespace(part.getTypeName(), ctx); + } + } + } + */ + + /* (non-Javadoc) + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + result = AssertionResult.RESULT_PASSED; + + // Get the definition from the entry context + Definition definition = + (Definition) entryContext.getEntry().getEntryDetail(); + + // get list of namespaces imported and defined in the definition + List namespaces = this.validator.getWSDLTargetNamespaceList(definition); + + // REMOVE: + //Map namespaces = definition.getNamespaces(); + + // traverse definition to check namespaces + Map params = new HashMap(); + params.put(NS_LIST_KEY, namespaces); + + WSDLTraversal traversal = new WSDLTraversal(); + // VisitorAdaptor.adapt(this); + traversal.setVisitor(this); + traversal.visitOperation(true); + traversal.visitBinding(true); + traversal.visitMessage(true); + traversal.visitPort(true); + + traversal.ignoreImport(); + traversal.ignoreReferences(); + traversal.traverse(definition, params); + + if (result.equals(AssertionResult.RESULT_FAILED)) + { + this.validator.createFailureDetail(failureDetailMessage, entryContext); + } + + // Return assertion result + return validator.createAssertionResult(testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2417.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2417.java new file mode 100644 index 000000000..f5ec3b4d0 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2417.java @@ -0,0 +1,160 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Vector; + +import javax.wsdl.Definition; +import javax.wsdl.Message; +import javax.wsdl.Part; +import javax.xml.namespace.QName; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcessVisitor; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.ErrorList; +import org.eclipse.wst.wsi.internal.wsdl.traversal.WSDLTraversal; +import org.eclipse.wst.wsi.internal.wsdl.traversal.WSDLTraversalContext; + + +/** + * BP2417. + * For a candidate wsdl:definitions + * Every QName in the WSDL document and its imports and that + * is referring to a schema component, uses the namespace defined in the targetNamespace + * attribute on the xs:schema element, or a namespace defined in the namespace attribute + * on an xs:import element within the xs:schema element. + */ +public class BP2417 extends AssertionProcessVisitor +{ + private final WSDLValidatorImpl validator; + + /** + * @param WSDLValidatorImpl + */ + public BP2417(WSDLValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + private ErrorList errorList = new ErrorList(); + private static final String NS_LIST_KEY = "namespaces"; + + /** + * Checks whether the namespace is defined or imported in the definition. + * @param qname + * @param ctx + */ + private void checkNamespace(QName qname, WSDLTraversalContext ctx) + { + if (qname != null) + { + String namespace = qname.getNamespaceURI(); + + if (namespace != null) + { + List namespaceList = (List) ctx.getParameter(NS_LIST_KEY); + + if ((namespaceList != null) && !namespaceList.contains(namespace)) + { + errorList.add(qname); + } + } + } + } + + /** + * @see org.eclipse.wst.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.Message, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit(Message message, Object parent, WSDLTraversalContext ctx) + { + if (message != null) + { + Map parts = message.getParts(); + + for (Iterator iter = parts.values().iterator(); iter.hasNext();) + { + Part part = (Part) iter.next(); + + checkNamespace(part.getElementName(), ctx); + checkNamespace(part.getTypeName(), ctx); + } + } + } + + /** + * @see org.eclipse.wst.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + result = AssertionResult.RESULT_PASSED; + + // Get the definition from the entry context + Definition definition = + (Definition) entryContext.getEntry().getEntryDetail(); + + // Get a list of all schema targetNamespaces + List tnsList = null; + try + { + if ((tnsList = this.validator.getSchemaNamespaceList(definition)) == null) + tnsList = new Vector(); + } + + catch (WSIException e) + { + // This exception would indicate that the schema definition had a problem + tnsList = new Vector(); + } + + // Always add XML schema namespace to cover built-in types + tnsList.add(WSIConstants.NS_URI_XSD); + + // Traverse definition to check schema namespaces + Map params = new HashMap(); + params.put(NS_LIST_KEY, tnsList); + + WSDLTraversal traversal = new WSDLTraversal(); + traversal.setVisitor(this); + traversal.visitMessage(true); + + traversal.ignoreImport(); + traversal.ignoreReferences(); + traversal.traverse(definition, params); + + // If there were no errors, then the assertion passed + if (errorList.isEmpty()) + { + result = AssertionResult.RESULT_PASSED; + } + + // Otherwise it failed / create the failure detail using the QNames that were in error + else + { + result = AssertionResult.RESULT_FAILED; + failureDetail = this.validator.createFailureDetail(errorList.toString(), entryContext); + } + + // Return assertion result + return validator.createAssertionResult(testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2700.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2700.java new file mode 100644 index 000000000..e3837ed4e --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2700.java @@ -0,0 +1,82 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.Utils; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; +import org.xml.sax.SAXException; + +/** + * BP2700. + * For a candidate wsdl:definitions element within a WSDL document. + * The wsdl:definitions is a well-formed XML 1.0 document. + */ +public class BP2700 extends AssertionProcess +{ + private final WSDLValidatorImpl validator; + + /** + * @param WSDLValidatorImpl + */ + public BP2700(WSDLValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + /* (non-Javadoc) + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + + result = AssertionResult.RESULT_PASSED; + + try + { + //String wsdlURI = entryContext.getWSDLDocument().getDefinitions().getDocumentBaseURI(); + // TEMP: Need to define a better way to get the WSDL URI + String wsdlURI = entryContext.getEntry().getReferenceID(); + // non-validating parse + XMLUtils.parseXMLDocument(wsdlURI); + } + + catch (WSIException e) + { + if (e.getTargetException() instanceof SAXException) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = + this.validator.createFailureDetail( + Utils.getExceptionDetails(e.getTargetException()), + entryContext); + } + } + + catch (Exception e) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = + this.validator.createFailureDetail(Utils.getExceptionDetails(e), entryContext); + } + + // Return assertion result + return validator.createAssertionResult(testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2701.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2701.java new file mode 100644 index 000000000..9797964f2 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2701.java @@ -0,0 +1,89 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +import javax.wsdl.Definition; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionFailException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.report.AssertionResult; + + +/** + * BP2701. + * For a candidate wsdl:definitions element within a WSDL document. + * The wsdl:definitions namespace has value: http://schemas.xmlsoap.org/wsdl/. + */ +public class BP2701 extends AssertionProcess +{ + private final WSDLValidatorImpl validator; + + /** + * @param WSDLValidatorImpl + */ + public BP2701(WSDLValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + /* (non-Javadoc) + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + + Definition def = (Definition) entryContext.getEntry().getEntryDetail(); + + /* + if (def != null) { + QName qname = def.getQName(); + + if (qname != null) { + //if (def.getNamespace("").equals(WSIConstants.NS_URI_WSDL) { + if (qname.getNamespaceURI().equals(WSIConstants.NS_URI_WSDL)) { + result = AssertionResult.RESULT_PASSED; + } + } + } + */ + + try + { + String schemaUsed = this.validator.getSchemaUsed(def); + if (schemaUsed.equals(WSIConstants.NS_URI_WSDL)) + { + result = AssertionResult.RESULT_PASSED; + } + + else + { + result = AssertionResult.RESULT_FAILED; + } + } + + catch (AssertionFailException e) + { + result = AssertionResult.RESULT_FAILED; + //ADD: failure description? + } + + // Return assertion result + return validator.createAssertionResult(testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2703.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2703.java new file mode 100644 index 000000000..5557d21f6 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2703.java @@ -0,0 +1,111 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +import java.util.Iterator; +import java.util.Map; + +import javax.wsdl.Definition; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionFailException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.TestUtils; +import org.eclipse.wst.wsi.internal.util.Utils; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; +import org.xml.sax.SAXException; + + +/** + * BP2703. + * For a candidate description within a WSDL document, if it uses the WSDL namespace + * The definition conforms to the WSDL schema located at http://schemas.xmlsoap.org/wsdl/2003-02-11.xsd + */ +public class BP2703 extends AssertionProcess +{ + private final WSDLValidatorImpl validator; + + /** + * @param WSDLValidatorImpl + */ + public BP2703(WSDLValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + /* (non-Javadoc) + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + + result = AssertionResult.RESULT_PASSED; + + try + { + Definition def = (Definition) entryContext.getEntry().getEntryDetail(); + + if (def == null) + { + throw new AssertionFailException("Definition null"); + } + + String wsdlURI = entryContext.getEntry().getReferenceID(); + + Map namespaces = def.getNamespaces(); + for (Iterator iter = namespaces.values().iterator(); iter.hasNext();) + { + String ns = (String) iter.next(); + + if (WSIConstants.NS_URI_WSDL.equalsIgnoreCase(ns)) + { + XMLUtils.parseXMLDocument(wsdlURI, TestUtils.getWSDLSchemaLocation()); + } + + if (WSIConstants.NS_URI_WSDL_SOAP.equalsIgnoreCase(ns)) + { + XMLUtils.parseXMLDocument(wsdlURI, TestUtils.getWSDLSOAPSchemaLocation()); + } + } + } + + catch (WSIException e) + { + if (e.getTargetException() instanceof SAXException) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = + this.validator.createFailureDetail( + Utils.getExceptionDetails(e.getTargetException()), + entryContext); + } + } + + catch (Exception e) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = + this.validator.createFailureDetail(Utils.getExceptionDetails(e), entryContext); + } + + // Return assertion result + return validator.createAssertionResult(testAssertion, result, failureDetail); + } + +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2803.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2803.java new file mode 100644 index 000000000..ce9bf9509 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP2803.java @@ -0,0 +1,87 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +import java.net.URI; + +import javax.wsdl.Import; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionFailException; +import org.eclipse.wst.wsi.internal.analyzer.AssertionNotApplicableException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcess; +import org.eclipse.wst.wsi.internal.report.AssertionResult; + + +/** + * BP2803 + * For a candidate wsdl:import element + * The "namespace" attribute is specified for the wsdl:import element, and the attribute's value is not a relative URI. + */ +public class BP2803 extends AssertionProcess +{ + private final WSDLValidatorImpl validator; + + /** + * @param WSDLValidatorImpl + */ + public BP2803(WSDLValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + /* Validates the test assertion. + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + + // Getting wsdl:import + Import im = (Import) entryContext.getEntry().getEntryDetail(); + + try + { + // If there is no the "namespace" attribute in the import, + // the assertion is not applicable + if (im.getNamespaceURI() == null) + { + throw new AssertionNotApplicableException(); + } + + // If a namespace URI is relative or invalid, the assertion failed + URI uri = new URI(im.getNamespaceURI()); + if (!uri.isAbsolute()) + { + throw new AssertionFailException( + im.getNamespaceURI() + " is relative URI."); + } + } + catch (AssertionNotApplicableException anae) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + catch (Exception e) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = validator.createFailureDetail( + e.getMessage(), entryContext); + } + + return validator.createAssertionResult( + testAssertion, result, failureDetail); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP4200.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP4200.java new file mode 100644 index 000000000..23cb4b783 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP4200.java @@ -0,0 +1,162 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +import javax.wsdl.Definition; +import javax.wsdl.Types; +import javax.wsdl.extensions.ExtensibilityElement; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.WSITag; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcessVisitor; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.ErrorList; +import org.eclipse.wst.wsi.internal.wsdl.traversal.WSDLTraversal; +import org.eclipse.wst.wsi.internal.wsdl.traversal.WSDLTraversalContext; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; +import org.w3c.dom.Attr; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NamedNodeMap; + +/** + * BP4200. + * For a candidate wsdl:definitions that contains a wsdl extension element or attribute from a namespace other than "http://schemas.xmlsoap.org/wsdl/soap/". + * Contained WSDL extension elements that do not belong to the "http://schemas.xmlsoap.org/wsdl/soap/" namespaces may require out of band negotiation. +*/ +public class BP4200 extends AssertionProcessVisitor implements WSITag +{ + private final WSDLValidatorImpl validator; + private ErrorList errorList = new ErrorList(); + + /** + * @param WSDLValidatorImpl + */ + public BP4200(WSDLValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.extensions.ExtensibilityElement, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit(ExtensibilityElement obj, Object parent, + WSDLTraversalContext ctx) + { + // If a child element of wsdl:types is from a namespace other than + // "http://www.w3.org/2001/XMLSchema" + if (parent instanceof Types) + { + //if (!obj.getElementType().getNamespaceURI().equals( + // WSIConstants.NS_URI_XSD)) + //{ + // Add element name to error list + // errorList.add(obj.getElementType()); + //} + } + // or any other ext element coming from a namespace other than + // "http://schemas.xmlsoap.org/wsdl/soap/" + else if (!obj.getElementType().getNamespaceURI().equals(WSIConstants.NS_URI_WSDL_SOAP) + && !obj.getElementType().getNamespaceURI().equals(WSIConstants.NS_URI_WSDL)) + { + // Add element name to error list + errorList.add(obj.getElementType()); + } + } + + /** + * (non-Javadoc) + * @see org.eclipse.wst.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate(TestAssertion testAssertion, + EntryContext entryContext) throws WSIException + { + // Get the definition from the entry context + Definition definition = + (Definition) entryContext.getEntry().getEntryDetail(); + + WSDLTraversal traversal = new WSDLTraversal(); + traversal.setVisitor(this); + + traversal.visitExtensibilityElement(true); + traversal.visitElement(true); + + traversal.ignoreImport(); + traversal.ignoreReferences(); + traversal.traverse(definition); + + try + { + // getting WSDL document. + Document doc = XMLUtils.parseXMLDocument(definition.getDocumentBaseURI()); + if (doc != null) + { + checkElement(doc.getDocumentElement()); + + if (errorList.isEmpty()) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + else + { + failureDetail = validator.createFailureDetail( + testAssertion.getDetailDescription() + "\n\n" + errorList.toString(), + entryContext); + } + } + } + catch (Throwable t) + { + } + // Return assertion result + return validator.createAssertionResult( + testAssertion, result, failureDetail); + } + + /** + * Checking on wsdl elements recursively whether they contain extension attributes. + * @param elem Element. + */ + private void checkElement(Element elem) + { + while (elem != null) + { + String elemNS = elem.getNamespaceURI(); + NamedNodeMap attrs = elem.getAttributes(); + if (attrs != null) + { + for (int i = 0; i < attrs.getLength(); i++) + { + Attr attr = (Attr) attrs.item(i); + String attrNS = attr.getNamespaceURI(); + if (attrNS != null + && !attrNS.equals(WSIConstants.NS_URI_XMLNS) + && !attrNS.equals(WSIConstants.NS_URI_WSDL) + && !attrNS.equals(WSIConstants.NS_URI_WSDL_SOAP)) + { + errorList.add("Extensibility attribute " + attr.getName() + + "for the " + elem.getNodeName() + " element is found."); + } + } + } + + if (!elemNS.equals(WSIConstants.NS_URI_XSD)) + { + checkElement(XMLUtils.getFirstChild(elem)); + } + elem = XMLUtils.getNextSibling(elem); + } + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP4201.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP4201.java new file mode 100644 index 000000000..81aaa5991 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP4201.java @@ -0,0 +1,144 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +import java.net.URISyntaxException; +import java.util.Iterator; + +import javax.wsdl.Definition; +import javax.wsdl.Import; +import javax.wsdl.Port; +import javax.wsdl.extensions.soap.SOAPAddress; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcessVisitor; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.ErrorList; +import org.eclipse.wst.wsi.internal.wsdl.traversal.WSDLTraversal; +import org.eclipse.wst.wsi.internal.wsdl.traversal.WSDLTraversalContext; + + +/** +* BP4201. +* For a candidate wsdl:import element, where the location attribute or the namespace attribute has a value that is a relative URI, or a for soap:address element where the location attribute is a relative URI. +* The use of a relative URI as the value for a wsdl:import location or namespace attribute, or for a soap:address location attribute may require out of band coordination. +*/ +public class BP4201 extends AssertionProcessVisitor +{ + private final WSDLValidatorImpl validator; + + /** + * @param WSDLValidatorImpl + */ + public BP4201(WSDLValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + private ErrorList errorList = new ErrorList(); + + /** + * (non-Javadoc) + * @see org.eclipse.wst.wsi.wsdl.traversal.WSDLVisitor#visit(Import, Object, WSDLTraversalContext) + */ + public void visit(Import obj, Object parent, WSDLTraversalContext ctx) + { + if(obj != null) + { + if(isRelativeURI(obj.getNamespaceURI()) || + isRelativeURI(obj.getLocationURI())) + { + errorList.add(obj.getNamespaceURI(), obj.getLocationURI()); + } + } + } + + /** + * (non-Javadoc) + * @see org.eclipse.wst.wsi.wsdl.traversal.WSDLVisitor#visit(Port, Object, WSDLTraversalContext) + */ + public void visit(Port obj, Object parent, WSDLTraversalContext ctx) + { + if(obj != null) + { + Iterator it = obj.getExtensibilityElements().iterator(); + while (it.hasNext()) + { + Object e = (Object) it.next(); + // for each SOAPAddress elements check LocationURI + if(e instanceof SOAPAddress) { + if(isRelativeURI(((SOAPAddress) e).getLocationURI())) + { + errorList.add(((SOAPAddress) e).getElementType() + + ":" + ((SOAPAddress) e).getLocationURI()); + } + } + } + } + } + + /** + * (non-Javadoc) + * @see org.eclipse.wst.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + result = AssertionResult.RESULT_PASSED; + + // Get the definition from the entry context + Definition definition = + (Definition) entryContext.getEntry().getEntryDetail(); + + WSDLTraversal traversal = new WSDLTraversal(); + traversal.setVisitor(this); + traversal.visitImport(true); + traversal.visitPort(true); + traversal.ignoreReferences(); + traversal.traverse(definition); + + if (errorList.isEmpty()) + { + return validator.createAssertionResult(testAssertion, + AssertionResult.RESULT_NOT_APPLICABLE, (String) null); + } + + failureDetail = this.validator.createFailureDetail(testAssertion.getFailureMessage() + + "\n\n" + errorList.toString(), entryContext); + // Return assertion result + return validator.createAssertionResult(testAssertion, result, failureDetail); + } + /** + * Returns true if URI is relative + * @param s - URI + * @return true - if URI is relative, false - in other case + */ + private boolean isRelativeURI(String s) + { + if(s == null) + return false; + try + { + if(new java.net.URI(s).isAbsolute()) + { + return false; + } + } catch (URISyntaxException e) + { + return false; + } + return true; + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP4202.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP4202.java new file mode 100644 index 000000000..715c20726 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/BP4202.java @@ -0,0 +1,135 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +import javax.wsdl.Types; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.UnknownExtensibilityElement; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.WSITag; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcessVisitor; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.ErrorList; +import org.eclipse.wst.wsi.internal.wsdl.traversal.WSDLTraversal; +import org.eclipse.wst.wsi.internal.wsdl.traversal.WSDLTraversalContext; +import org.eclipse.wst.wsi.internal.xml.XMLDocumentCache; +import org.eclipse.wst.wsi.internal.xml.schema.XMLSchemaProcessor; +import org.w3c.dom.Element; +import org.w3c.dom.Node; + + +/** + * BP4202. + * For an XML schema definition defined in the wsdl:types element, or imported directly or indirectly by a schema definition defined in the wsdl:types element, which contains any schema annotation elements. + * An XML schema definition defined in the wsdl:types element, or imported directly or indirectly by a schema definition defined in the wsdl:types element, may use schema annotation elements as an extensibility mechanism. + */ + public class BP4202 extends AssertionProcessVisitor implements WSITag + { + private final WSDLValidatorImpl validator; + + /** + * @param WSDLValidatorImpl + */ + public BP4202(WSDLValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + private static final String ANNOTATION_KEY = "annotation"; + + private ErrorList errorList = new ErrorList(); + private AnnotationProcessor processor; + + /** + * (non-Javadoc) + * @see org.eclipse.wst.wsi.wsdl.traversal.WSDLVisitor#visit(Message, Object, WSDLTraversalContext) + */ + public void visit(ExtensibilityElement obj, Object parent, WSDLTraversalContext ctx) + { + if((obj != null) && (obj instanceof UnknownExtensibilityElement)) + { + UnknownExtensibilityElement el = (UnknownExtensibilityElement) obj; + try { + processor.processAllSchema(el.getElement()); + } catch (WSIException e) {} + } + } + + /** + * (non-Javadoc) + * @see org.eclipse.wst.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + result = AssertionResult.RESULT_PASSED; + + // Get the types from the entry context + Types types = + (Types) entryContext.getEntry().getEntryDetail(); + + processor = new AnnotationProcessor( + entryContext.getWSDLDocument().getDefinitions().getDocumentBaseURI(), + validator.getDocumentList()); + + WSDLTraversal traversal = new WSDLTraversal(); + traversal.setVisitor(this); + traversal.visitExtensibilityElement(true); + traversal.ignoreReferences(); + traversal.traverse(types); + + if (errorList.isEmpty()) + { + return validator.createAssertionResult(testAssertion, + AssertionResult.RESULT_NOT_APPLICABLE, (String) null); + } + + failureDetail = this.validator.createFailureDetail(testAssertion.getFailureMessage() + + "\n\n" + errorList.toString(), entryContext); + // Return assertion result + return validator.createAssertionResult(testAssertion, result, failureDetail); + } + + /** + * Class for parse schema and search annotation elements + */ + class AnnotationProcessor extends XMLSchemaProcessor + { + public AnnotationProcessor( + String context, + XMLDocumentCache documentList) + { + super(context, documentList, false); + } + + protected void processSchema(Element element) + { + checkForAnnotation(element); + } + + private void checkForAnnotation(Node node) + { + if((node.getLocalName() != null) && (node.getLocalName().equals(ANNOTATION_KEY))) { + errorList.add(node.toString()); + } + for (int i = 0; i < node.getChildNodes().getLength(); i++) + { + checkForAnnotation(node.getChildNodes().item(i)); + } + } + } + } \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/SSBP2209.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/SSBP2209.java new file mode 100644 index 000000000..85d602375 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/SSBP2209.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + + +/** + * SSBP2209 + * + * For a candidate wsdl:binding element + * The wsdl:binding binds every wsdl:part of a wsdl:message in the wsdl:portType to which it refers to one of soapbind:body, soapbind:header, soapbind:fault or soapbind:headerfault. + */ +public class SSBP2209 extends BP2114 +{ + /** + * @param WSDLValidatorImpl + */ + public SSBP2209(WSDLValidatorImpl impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/SSBP2402.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/SSBP2402.java new file mode 100644 index 000000000..ee49a3f68 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/SSBP2402.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +/** + * SSBP2402 + */ +public class SSBP2402 extends BP2402 +{ + + /** + * @param WSDLValidatorImpl + */ + public SSBP2402(WSDLValidatorImpl impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/SSBP2403.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/SSBP2403.java new file mode 100644 index 000000000..f5c0bdce5 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/SSBP2403.java @@ -0,0 +1,191 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +import javax.wsdl.Binding; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.UnknownExtensibilityElement; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.WSITag; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcessVisitor; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.ErrorList; +import org.eclipse.wst.wsi.internal.wsdl.traversal.WSDLTraversal; +import org.eclipse.wst.wsi.internal.wsdl.traversal.WSDLTraversalContext; +import org.eclipse.wst.wsi.internal.xml.XMLTraversal; +import org.w3c.dom.Attr; +import org.w3c.dom.Element; +import org.w3c.dom.Node; + + +/** + * SSBP2403. + * For a candidate wsdl:binding element + * Descendant elements and attributes in the wsdl:binding are not from the namespaces for the WSDL MIME, HTTP GET/POST or DIME binding extensions. + */ +public class SSBP2403 extends AssertionProcessVisitor implements WSITag +{ + private final WSDLValidatorImpl validator; + + /** + * @param WSDLValidatorImpl + */ + public SSBP2403(WSDLValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + + private ErrorList errors = new ErrorList(); + + /** + * Returns true if the the namespace specifies any WSDL MIME, + * HTTP GET/POST or DIME binding extensions. + * @param namespace a namespace. + * @return true if the the namespace specifies any WSDL MIME, + * HTTP GET/POST or DIME binding extensions. + */ + private boolean isNonConformantBindingExtension(String namespace) + { + boolean result = false; + if (namespace != null) + { + if (namespace.equals(WSIConstants.NS_NAME_WSDL_MIME) + || namespace.equals(WSIConstants.NS_NAME_WSDL_HTTP) + || namespace.equals(WSIConstants.NS_NAME_WSDL_DIME)) + result = true; + } + return result; + } + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.extensions.ExtensibilityElement, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit( + ExtensibilityElement exel, + Object parent, + WSDLTraversalContext ctx) + { + if (isNonConformantBindingExtension(exel + .getElementType() + .getNamespaceURI())) + errors.add(exel.getElementType()); + else + { + // extensibility element is ok, check the descendants + if (exel instanceof UnknownExtensibilityElement) + { + Element el = ((UnknownExtensibilityElement) exel).getElement(); + + // traverse all of the descendants and check for non compliant binding extensions + XMLTraversalCheckingExtensions traversal = + new XMLTraversalCheckingExtensions(); + traversal.visit(el); + } + } + } + + /* (non-Javadoc) + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + result = AssertionResult.RESULT_FAILED; + + WSDLTraversal traversal = new WSDLTraversal(); + traversal.setVisitor(this); + traversal.visitElement(true); + traversal.visitExtensibilityElement(true); + + traversal.ignoreReferences(); + traversal.ignoreImport(); + traversal.traverse((Binding) entryContext.getEntry().getEntryDetail()); + + if (!errors.isEmpty()) + { + result = AssertionResult.RESULT_FAILED; + failureDetail = this.validator.createFailureDetail(errors.toString(), entryContext); + } + + else + result = AssertionResult.RESULT_PASSED; + + return validator.createAssertionResult(testAssertion, result, failureDetail); + } + + + /** + * A specialized XMLTraversal class to check if the wsdl:binding element has any + * descendant elements/attributes from the namespaces for the WSDL MIME, + * HTTP GET/POST or DIME binding extensions. + */ + private class XMLTraversalCheckingExtensions extends XMLTraversal + { + boolean nonConformantExtensionFound = false; + + /* (non-Javadoc) + * @see org.wsi.xml.XMLTraversal#action(org.w3c.dom.Node) + */ + public boolean action(Node n) + { + return !nonConformantExtensionFound; + } + + /* (non-Javadoc) + * @see org.wsi.xml.XMLVisitor#visit(org.w3c.dom.Attr) + */ + public void visit(Attr node) + { + if (action(node)) + { + if (isNonConformantBindingExtension(node.getNamespaceURI())) + { + errors.add(node.getName()); + nonConformantExtensionFound = true; + } + } + } + + /* (non-Javadoc) + * @see org.wsi.xml.XMLVisitor#visit(org.w3c.dom.Element) + */ + public void visit(Element node) + { + if (action(node)) + { + if (isNonConformantBindingExtension(node.getNamespaceURI())) + { + errors.add(node.getNodeName()); + nonConformantExtensionFound = true; + } + else + { + // element is compliant, check attributes and descendants + visit(node.getAttributes()); + for (Node n = node.getFirstChild(); + n != null; + n = n.getNextSibling()) + { + doVisit(n); + } + } + } + } + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSDLValidatorImpl.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSDLValidatorImpl.java new file mode 100644 index 000000000..7293901cf --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSDLValidatorImpl.java @@ -0,0 +1,2319 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Vector; + +import javax.wsdl.Binding; +import javax.wsdl.BindingFault; +import javax.wsdl.BindingInput; +import javax.wsdl.BindingOperation; +import javax.wsdl.BindingOutput; +import javax.wsdl.Definition; +import javax.wsdl.Fault; +import javax.wsdl.Import; +import javax.wsdl.Message; +import javax.wsdl.Operation; +import javax.wsdl.Part; +import javax.wsdl.Port; +import javax.wsdl.PortType; +import javax.wsdl.Service; +import javax.wsdl.Types; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.UnknownExtensibilityElement; +import javax.wsdl.extensions.soap.SOAPBinding; +import javax.wsdl.extensions.soap.SOAPBody; +import javax.wsdl.extensions.soap.SOAPFault; +import javax.wsdl.extensions.soap.SOAPHeader; +import javax.wsdl.extensions.soap.SOAPHeaderFault; +import javax.wsdl.extensions.soap.SOAPOperation; +import javax.xml.namespace.QName; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.WSIRuntimeException; +import org.eclipse.wst.wsi.internal.analyzer.AnalyzerContext; +import org.eclipse.wst.wsi.internal.analyzer.AssertionFailException; +import org.eclipse.wst.wsi.internal.analyzer.CandidateInfo; +import org.eclipse.wst.wsi.internal.analyzer.ServiceReference; +import org.eclipse.wst.wsi.internal.analyzer.config.WSDLElement; +import org.eclipse.wst.wsi.internal.profile.ProfileArtifact; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.WSDLValidator; +import org.eclipse.wst.wsi.internal.profile.validator.impl.BaseValidatorImpl; +import org.eclipse.wst.wsi.internal.report.Entry; +import org.eclipse.wst.wsi.internal.report.EntryContainer; +import org.eclipse.wst.wsi.internal.report.FailureDetail; +import org.eclipse.wst.wsi.internal.report.ReportArtifact; +import org.eclipse.wst.wsi.internal.report.Reporter; +import org.eclipse.wst.wsi.internal.util.EntryType; +import org.eclipse.wst.wsi.internal.wsdl.WSDLDocument; +import org.eclipse.wst.wsi.internal.wsdl.WSDLElementList; +import org.eclipse.wst.wsi.internal.wsdl.WSDLUtils; +import org.eclipse.wst.wsi.internal.xml.dom.ElementLocation; +import org.eclipse.wst.wsi.internal.xml.schema.TargetNamespaceProcessor; +import org.eclipse.wst.wsi.internal.xml.schema.XMLSchemaValidator; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + + +/** + * The WSDL validator will verify that the WSDL and associated XML schema definitions + * are in conformance with the profile. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + * @author Graham Turrell (gturrell@uk.ibm.com) + */ +public class WSDLValidatorImpl + extends BaseValidatorImpl + implements WSDLValidator +{ + /** + * WSDL URL. + */ + protected String wsdlURL; + + /** + * WSDL document. + */ + protected WSDLDocument wsdlDocument = null; + + /** + * Entry container map. + */ + protected HashMap containerMap = new HashMap(); + + /* (non-Javadoc) + * @see org.wsi.test.profile.validator.WSDLValidator#init(org.wsi.test.analyzer.AnalyzerContext, org.wsi.test.profile.ProfileArtifact, org.wsi.test.report.ReportArtifact, java.lang.String, org.wsi.wsdl.WSDLDocument, org.wsi.test.report.Reporter) + */ + public void init( + AnalyzerContext analyzerContext, + ProfileArtifact profileArtifact, + ReportArtifact reportArtifact, + String wsdlURL, + WSDLDocument wsdlDocument, + Reporter reporter) + throws WSIException + { + // BaseValidatorImpl + super.init(analyzerContext, profileArtifact, reportArtifact, reporter); + + this.wsdlDocument = wsdlDocument; + if (wsdlDocument != null) + this.wsdlURL = wsdlDocument.getLocation(); + + if (wsdlURL != null) + this.wsdlURL = wsdlURL; + } + + /* (non-Javadoc) + * @see org.wsi.test.profile.validator.WSDLValidator#validate() + */ + public WSDLDocument validate() throws WSIException + { + //WSDLDocument wsdlDocument = null; + Entry entry = null; + + Service service = null; + Port port = null; + Binding binding = null; + PortType portType = null; + Operation operation = null; + Message message = null; + + // it depricated after refactoring + // now the inner classes moved out from validator + //String classPrefix = this.getClass().getName() + "$"; + String classPrefix = this.getClass().getPackage().getName()+"."; + + try + { + // Validate the WSDL service description + if (this.wsdlDocument == null) + this.wsdlDocument = new WSDLDocument(wsdlURL); + } + + catch (Exception e) + { + // ADD: Certain exceptions should result in validation errors + + throw new WSIException(e.getMessage(), e); + } + + // Get the definition element + Definition definition = wsdlDocument.getDefinitions(); + + // Get service reference from analyzer context + ServiceReference serviceReference = analyzerContext.getServiceReference(); + + // Create normalized data about the service under test. + CandidateInfo candidate = new CandidateInfo(serviceReference, wsdlDocument); + + analyzerContext.setCandidateInfo(candidate); + + // Set prereq type to entry container + reporter.setPrereqType(Reporter.PREREQ_TYPE_ENTRY_CONTAINER); + + // always process Import, Definitions & Types assertions + // TEMP: + processDefinitionAssertions(classPrefix, candidate); + processTypesAssertions(classPrefix, candidate); + processImportAssertions(classPrefix, candidate); + + // Process the element hierarchy in the WSDL document starting with the one that was specified + // FIX: Element finding already completed by CandidateInfo constructor - so use that rather than retest here + + // --------------------------- + // wsdl:port + // --------------------------- + if (serviceReference.getWSDLElement().isPort()) + { + // Find the service element + if ((service = + definition.getService( + serviceReference.getWSDLElement().getParentElementQName())) + == null) + { + throw new WSIRuntimeException( + "Could not locate WSDL service: " + + serviceReference.getWSDLElement().getParentElementName()); + } + + // Find the port element + if ((port = service.getPort(serviceReference.getWSDLElement().getName())) + == null) + { + throw new WSIRuntimeException( + "Could not locate WSDL port: " + + serviceReference.getWSDLElement().getName()); + } + + // TEMP: Remove until there are port test assertions + //processPortAssertions(port, serviceReference, classPrefix, wsdlDocument); + + // Next, process the binding + if (((binding = port.getBinding()) == null) || (binding.isUndefined())) + { + //throw new WSIRuntimeException("Could not locate WSDL binding for port: " + port.getName()); + // Set missingInput for all binding, portType, operation and message test assertions + setMissingInput( + EntryType.getEntryType(EntryType.TYPE_DESCRIPTION_BINDING)); + setMissingInput( + EntryType.getEntryType(EntryType.TYPE_DESCRIPTION_PORTTYPE)); + setMissingInput( + EntryType.getEntryType(EntryType.TYPE_DESCRIPTION_OPERATION)); + setMissingInput( + EntryType.getEntryType(EntryType.TYPE_DESCRIPTION_MESSAGE)); + } + + else + { + processBindingAssertions( + binding, + serviceReference, + classPrefix, + wsdlDocument); + + // Next, process the portType + if (((portType = binding.getPortType()) == null) + || (portType.isUndefined())) + { + //throw new WSIRuntimeException("Could not locate WSDL portType for binding: " + binding.getQName().getLocalPart()); + // Set missingInput for all portType, operation and message test assertions + setMissingInput( + EntryType.getEntryType(EntryType.TYPE_DESCRIPTION_PORTTYPE)); + setMissingInput( + EntryType.getEntryType(EntryType.TYPE_DESCRIPTION_OPERATION)); + setMissingInput( + EntryType.getEntryType(EntryType.TYPE_DESCRIPTION_MESSAGE)); + } + + else + { + processMessageAssertions( + binding, + serviceReference, + classPrefix, + wsdlDocument); + processPortTypeAssertions( + portType, + serviceReference, + classPrefix, + wsdlDocument); + processOperationAssertions( + portType, + serviceReference, + classPrefix, + wsdlDocument); + processMessageAssertions( + portType, + serviceReference, + classPrefix, + wsdlDocument); + } + } + + } + + // --------------------------- + // wsdl:binding + // --------------------------- + else if (serviceReference.getWSDLElement().isBinding()) + { + WSDLElement wsdlElement = serviceReference.getWSDLElement(); + // Find the binding element + if (wsdlElement.getQName() != null + && wsdlElement.getQName().getLocalPart() != null + && wsdlElement.getQName().getLocalPart().length() > 0) + { + if (((binding = + definition.getBinding(serviceReference.getWSDLElement().getQName())) + == null) + || (binding.isUndefined())) + { + throw new WSIRuntimeException( + "Could not locate WSDL binding: " + + serviceReference.getWSDLElement().getName()); + } + + processBindingAssertions( + binding, + serviceReference, + classPrefix, + wsdlDocument); + processMessageAssertions( + binding, + serviceReference, + classPrefix, + wsdlDocument); + + // Next, process the portType + if (((portType = binding.getPortType()) == null) + || (portType.isUndefined())) + { + //throw new WSIRuntimeException("Could not locate WSDL PortType for Binding: " + binding.getQName().getLocalPart()); + + // Set missingInput for all portType, operation and message test assertions + setMissingInput( + EntryType.getEntryType(EntryType.TYPE_DESCRIPTION_PORTTYPE)); + setMissingInput( + EntryType.getEntryType(EntryType.TYPE_DESCRIPTION_OPERATION)); + setMissingInput( + EntryType.getEntryType(EntryType.TYPE_DESCRIPTION_MESSAGE)); + } + + else + { + processPortTypeAssertions( + portType, + serviceReference, + classPrefix, + wsdlDocument); + processOperationAssertions( + portType, + serviceReference, + classPrefix, + wsdlDocument); + + // Process each message within each operation of the portType associated with the binding + processMessageAssertions( + portType, + serviceReference, + classPrefix, + wsdlDocument); + } + } + + // There was a problem with the binding element specification. This can + // happen when a UDDI tModel did not have a valid binding reference. + else + { + // Set missingInput for all binding, portType, operation and message test assertions + setMissingInput( + EntryType.getEntryType(EntryType.TYPE_DESCRIPTION_BINDING)); + setMissingInput( + EntryType.getEntryType(EntryType.TYPE_DESCRIPTION_PORTTYPE)); + setMissingInput( + EntryType.getEntryType(EntryType.TYPE_DESCRIPTION_OPERATION)); + setMissingInput( + EntryType.getEntryType(EntryType.TYPE_DESCRIPTION_MESSAGE)); + } + } + + // --------------------------- + // wsdl:portType + // --------------------------- + else if (serviceReference.getWSDLElement().isPortType()) + { + // Find the PortType element + if (((portType = + definition.getPortType(serviceReference.getWSDLElement().getQName())) + == null) + || (portType.isUndefined())) + { + throw new WSIRuntimeException( + "Could not locate WSDL PortType: " + + serviceReference.getWSDLElement().getName()); + } + + // Set missingInput for all binding test assertions + setMissingInput( + EntryType.getEntryType(EntryType.TYPE_DESCRIPTION_BINDING)); + + processPortTypeAssertions( + portType, + serviceReference, + classPrefix, + wsdlDocument); + processOperationAssertions( + portType, + serviceReference, + classPrefix, + wsdlDocument); + + // Process each message within each operation of the portType + processMessageAssertions( + portType, + serviceReference, + classPrefix, + wsdlDocument); + } + + // --------------------------- + // wsdl:operation + // --------------------------- + else if (serviceReference.getWSDLElement().isOperation()) + { + // Find the operation + // get portType from config parent element + if (((portType = + definition.getPortType( + serviceReference.getWSDLElement().getParentElementQName())) + == null) + || (portType.isUndefined())) + { + throw new WSIRuntimeException( + "Could not locate WSDL portType: " + + serviceReference.getWSDLElement().getParentElementQName()); + } + + if (((operation = + getOperationFromPortType( + portType, + serviceReference.getWSDLElement().getName())) + == null) + || (operation.isUndefined())) + { + throw new WSIRuntimeException( + "Could not locate WSDL Operation: " + + serviceReference.getWSDLElement().getName() + + "in portType: " + + portType.getQName()); + } + + // Set missingInput for all binding and portType test assertions + setMissingInput( + EntryType.getEntryType(EntryType.TYPE_DESCRIPTION_BINDING)); + setMissingInput( + EntryType.getEntryType(EntryType.TYPE_DESCRIPTION_PORTTYPE)); + + processOperationAssertions( + operation, + portType, + serviceReference, + classPrefix, + wsdlDocument); + processMessageAssertions( + operation, + serviceReference, + classPrefix, + wsdlDocument); + } + + // --------------------------- + // wsdl:message + // --------------------------- + else if (serviceReference.getWSDLElement().isMessage()) + { + // Find the message + if (((message = + definition.getMessage(serviceReference.getWSDLElement().getQName())) + == null) + || (message.isUndefined())) + { + throw new WSIRuntimeException( + "Could not locate WSDL Message: " + + serviceReference.getWSDLElement().getName()); + } + + // Set missingInput for all binding, portType, and operation test assertions + setMissingInput( + EntryType.getEntryType(EntryType.TYPE_DESCRIPTION_BINDING)); + setMissingInput( + EntryType.getEntryType(EntryType.TYPE_DESCRIPTION_PORTTYPE)); + setMissingInput( + EntryType.getEntryType(EntryType.TYPE_DESCRIPTION_OPERATION)); + + processMessageAssertions( + message, + serviceReference, + classPrefix, + wsdlDocument); + } + + else + { + throw new WSIRuntimeException( + "The following WSDL type is not supported: " + + serviceReference.getWSDLElement().getType()); + } + + // Cleanup + cleanup(); + + // Return WSDL document + return this.wsdlDocument; + } + + /** + * Get entry container using the filename for WSDL document. + * @param filename a file name. + * @return entry container using the filename for WSDL document. + */ + protected EntryContainer getEntryContainer(String filename) + { + EntryContainer entryContainer = null; + + // If the entry container already exists, then use it + if ((entryContainer = (EntryContainer) containerMap.get(filename)) == null) + { + // Create new entry container + entryContainer = this.reporter.createEntryContainer(); + + // Set container id using the filename for the WSDL document + entryContainer.setId(filename); + + // Put the new entry container into the container map + containerMap.put(filename, entryContainer); + } + + return entryContainer; + } + + /** + * Get operation from port type. + * @param portType port type. + * @param operationName operation name. + * @return operation from port type. + */ + protected Operation getOperationFromPortType( + PortType portType, + String operationName) + { + // FIX: wsdl4j available method call below implies that only + // name+inputname+outputname uniquely defines operation + // Use this instead for now: - get the first operation we find... + Operation op = null; + if (portType.getOperations() != null) + { + Iterator opIt = portType.getOperations().iterator(); + + while (opIt.hasNext()) + { + op = (Operation) opIt.next(); + if (operationName.equals(op.getName())) + { + return op; + } + } + } + + return null; // no matching operation found + } + + /** + * Process definition assertions. + * @param classPrefix class prefix. + * @param candidate candidate. + * @throws WSIException if problems occur during processing. + */ + protected void processDefinitionAssertions( + String classPrefix, + CandidateInfo candidate) + throws WSIException + { + + Entry entry = null; + + Definition[] wsdlDefinitions = candidate.getDefinitions(); + + for (int i = 0; i < wsdlDefinitions.length; i++) + { + Definition definition = wsdlDefinitions[i]; + if (definition == null) + continue; + // Create entry + entry = this.reporter.getReport().createEntry(); + entry.setEntryType( + EntryType.getEntryType(EntryType.TYPE_DESCRIPTION_DEFINITIONS)); + entry.setReferenceID(definition.getDocumentBaseURI()); + entry.setEntryDetail(definition); + + // Set entry container + entry.setEntryContainer( + getEntryContainer(definition.getDocumentBaseURI())); + + // Process all of the definition related test assertions + processAssertions( + classPrefix, + new EntryContext(entry, candidate.getWsdlDocument())); + // ADD: need to use here the specific document corresponding to the definition?? + + } + } + + /** + * Process types assertions. + * @param classPrefix class prefix. + * @param candidate candidate. + * @throws WSIException if problem occurs during processing + * type assertions. + */ + protected void processTypesAssertions( + String classPrefix, + CandidateInfo candidate) + throws WSIException + { + Entry entry = null; + + Types[] wsdlTypes = candidate.getTypes(); + Definition[] wsdlDefinitions = candidate.getDefinitions(); + + // If there are no types elements, then set all results to missingInput + if (wsdlTypes == null || wsdlTypes.length == 0) + { + // Set missingInput for all test assertions with this entry type + setMissingInput(EntryType.getEntryType(EntryType.TYPE_DESCRIPTION_TYPES)); + } + + else + { + for (int i = 0; i < wsdlTypes.length; i++) + { + Types types = wsdlTypes[i]; + if (types == null) + { + // no Types element in i-th document + continue; + } + + // Create entry + entry = this.reporter.getReport().createEntry(); + entry.setEntryType( + EntryType.getEntryType(EntryType.TYPE_DESCRIPTION_TYPES)); + entry.setReferenceID( + candidate.getDefinition(types).getDocumentBaseURI() + "-Types"); + entry.setEntryDetail(types); + + // Set entry container + entry.setEntryContainer( + getEntryContainer(wsdlDefinitions[i].getDocumentBaseURI())); + + // Process all of the Types related test assertions + processAssertions( + classPrefix, + new EntryContext(entry, candidate.getWsdlDocument())); + } + } + } + + /** + * Process import assertions. + * @param classPrefix class prefix. + * @param candidate candidate. + * @throws WSIException if problem occurs during processing + * import assertions. + */ + protected void processImportAssertions( + String classPrefix, + CandidateInfo candidate) + throws WSIException + { + + Entry entry = null; + + Import[] wsdlImports = candidate.getImports(); + + // If there are no import elements, then set all results to missingInput + if (wsdlImports == null || wsdlImports.length == 0) + { + // Set missingInput for all test assertions with this entry type + setMissingInput( + EntryType.getEntryType(EntryType.TYPE_DESCRIPTION_IMPORT)); + } + + else + { + for (int i = 0; i < wsdlImports.length; i++) + { + Import wsdlImport = wsdlImports[i]; + // Create entry + entry = this.reporter.getReport().createEntry(); + entry.setEntryType( + EntryType.getEntryType(EntryType.TYPE_DESCRIPTION_IMPORT)); + entry.setReferenceID(wsdlImport.getNamespaceURI()); + entry.setEntryDetail(wsdlImport); + + // Set entry container + entry.setEntryContainer(getEntryContainer(wsdlImport.getLocationURI())); + + // Process all of the import related test assertions + processAssertions( + classPrefix, + new EntryContext(entry, candidate.getWsdlDocument())); + // ADD: need to use here the specific document corresponding to the import!! + } + } + } + + /** + * Process port assertions. + * @param port a port. + * @param serviceReference service reference. + * @param classPrefix class prefix. + * @param wsdlDocument WSDL document. + * @throws WSIException if problem occurs during processing + * port assertions. + */ + protected void processPortAssertions( + Port port, + ServiceReference serviceReference, + String classPrefix, + WSDLDocument wsdlDocument) + throws WSIException + { + Entry entry = null; + + // Create entry + entry = this.reporter.getReport().createEntry(); + entry.setEntryType(EntryType.getEntryType(EntryType.TYPE_DESCRIPTION_PORT)); + entry.setReferenceID(port.getName()); + entry.setParentElementName( + serviceReference.getWSDLElement().getParentElementName()); + entry.setEntryDetail(port); + + // Process assertions for this artifact against the target context + processAssertions(classPrefix, new EntryContext(entry, wsdlDocument)); + } + + /** + * Process binding assertions. + * @param binding binding. + * @param serviceReference service reference. + * @param classPrefix class prefix. + * @param wsdlDocument WSDL document. + * @throws WSIException if problem occurs during processing + * binding assertions. + */ + protected void processBindingAssertions( + Binding binding, + ServiceReference serviceReference, + String classPrefix, + WSDLDocument wsdlDocument) + throws WSIException + { + Entry entry = null; + QName bindingQName = binding.getQName(); + + // Create entry + entry = this.reporter.getReport().createEntry(); + entry.setEntryType( + EntryType.getEntryType(EntryType.TYPE_DESCRIPTION_BINDING)); + entry.setReferenceID(bindingQName.toString()); + entry.setEntryDetail(binding); + + // Set entry container + Definition definition = + analyzerContext.getCandidateInfo().getDefinition(binding); + entry.setEntryContainer( + getEntryContainer( + (definition == null ? null : definition.getDocumentBaseURI()))); + + // Process binding test assertions + processAssertions(classPrefix, new EntryContext(entry, wsdlDocument)); + } + + /** + * Process port type assertions. + * @param portType port type. + * @param serviceReference service reference. + * @param classPrefix class prefix. + * @param wsdlDocument WSDL document. + * @throws WSIException if problem occurs during processing + * port type assertions. + */ + protected void processPortTypeAssertions( + PortType portType, + ServiceReference serviceReference, + String classPrefix, + WSDLDocument wsdlDocument) + throws WSIException + { + + Entry entry = null; + QName portTypeQName = portType.getQName(); + + // Create entry + entry = this.reporter.getReport().createEntry(); + entry.setEntryType( + EntryType.getEntryType(EntryType.TYPE_DESCRIPTION_PORTTYPE)); + entry.setReferenceID(portTypeQName.toString()); + entry.setEntryDetail(portType); + + // Set entry container + Definition definition = + analyzerContext.getCandidateInfo().getDefinition(portType); + entry.setEntryContainer( + getEntryContainer( + (definition == null ? null : definition.getDocumentBaseURI()))); + + // Process test assertions + processAssertions(classPrefix, new EntryContext(entry, wsdlDocument)); + } + + /** + * Process operation assertions. + * @param operation an operation. + * @param portType port type. + * @param serviceReference service reference. + * @param classPrefix class prefix. + * @param wsdlDocument WSDL document. + * @throws WSIException if problem occurs during processing + * operation assertions. + */ + protected void processOperationAssertions( + Operation operation, + PortType portType, + ServiceReference serviceReference, + String classPrefix, + WSDLDocument wsdlDocument) + throws WSIException + { + // qualify operation with service location from config. + Entry entry = null; + + // Create entry + entry = this.reporter.getReport().createEntry(); + entry.setEntryType( + EntryType.getEntryType(EntryType.TYPE_DESCRIPTION_OPERATION)); + entry.setReferenceID(operation.getName()); + entry.setParentElementName(portType.getQName().getLocalPart()); + entry.setEntryDetail(operation); + + // Set entry container + Definition definition = + analyzerContext.getCandidateInfo().getDefinition(portType); + entry.setEntryContainer( + getEntryContainer( + (definition == null ? null : definition.getDocumentBaseURI()))); + + // Process test assertions + processAssertions(classPrefix, new EntryContext(entry, wsdlDocument)); + } + + /** + * Process operation assertions. + * @param portType port type. + * @param serviceReference service reference. + * @param classPrefix class prefix. + * @param wsdlDocument WSDL document. + * @throws WSIException if problem occurs during processing + * operation assertions. + */ + protected void processOperationAssertions( + PortType portType, + ServiceReference serviceReference, + String classPrefix, + WSDLDocument wsdlDocument) + throws WSIException + { + // For each operation, + if (portType.getOperations() == null) + { + setMissingInput( + EntryType.getEntryType(EntryType.TYPE_DESCRIPTION_OPERATION)); + } + + else + { + Operation operation; + Iterator opIt = portType.getOperations().iterator(); + while (opIt.hasNext()) + { + operation = (Operation) opIt.next(); + if (operation == null || operation.isUndefined()) + setMissingInput( + EntryType.getEntryType(EntryType.TYPE_DESCRIPTION_OPERATION)); + else + processOperationAssertions( + operation, + portType, + serviceReference, + classPrefix, + wsdlDocument); + } + } + } + + /** + * Process message assertions. + * @param message a message. + * @param serviceReference service reference. + * @param classPrefix class prefix. + * @param wsdlDocument WSDL document. + * @throws WSIException if problem occurs during processing + * message assertions. + */ + protected void processMessageAssertions( + Message message, + ServiceReference serviceReference, + String classPrefix, + WSDLDocument wsdlDocument) + throws WSIException + { + + Entry entry = null; + QName messageQName = message.getQName(); + + // Create entry + entry = this.reporter.getReport().createEntry(); + entry.setEntryType( + EntryType.getEntryType(EntryType.TYPE_DESCRIPTION_MESSAGE)); + entry.setReferenceID(messageQName.toString()); + entry.setEntryDetail(message); + + // Set entry container + Definition definition = + analyzerContext.getCandidateInfo().getDefinition(message); + entry.setEntryContainer( + getEntryContainer( + (definition == null ? null : definition.getDocumentBaseURI()))); + + // Process binding test assertions + processAssertions(classPrefix, new EntryContext(entry, wsdlDocument)); + } + + /** + * Process message assertions. + * @param binding a binding. + * @param serviceReference service reference. + * @param classPrefix class prefix. + * @param wsdlDocument WSDL document. + * @throws WSIException if problem occurs during processing + * message assertions. + */ + protected void processMessageAssertions( + Binding binding, + ServiceReference serviceReference, + String classPrefix, + WSDLDocument wsdlDocument) + throws WSIException + { + HashSet messageSet; + + if (binding.getBindingOperations() != null) + { // can do nothing if have no operations defined + messageSet = + WSDLUtils.findMessages(wsdlDocument.getDefinitions(), binding); + + // Process any messages that were found + if (messageSet.size() > 0) + { + Iterator messageIt = messageSet.iterator(); + while (messageIt.hasNext()) + { + Message message = (Message) messageIt.next(); + if (!message.isUndefined()) + processMessageAssertions( + message, + serviceReference, + classPrefix, + wsdlDocument); + } + } + } + } + + /** + * Process message assertions. + * @param portType port type. + * @param serviceReference service reference. + * @param classPrefix class prefix. + * @param wsdlDocument WSDL document. + * @throws WSIException if problem occurs during processing + * message assertions. + */ + protected void processMessageAssertions( + PortType portType, + ServiceReference serviceReference, + String classPrefix, + WSDLDocument wsdlDocument) + throws WSIException + { + + HashSet messageSet = new HashSet(); + + if (portType.getOperations() != null) + { + // can do nothing if have no operations defined + + Iterator opIt = portType.getOperations().iterator(); + + while (opIt.hasNext()) + { + Operation op = (Operation) opIt.next(); + + // Since there is no guarantee that we have both and input and output message, + // check for its existence before adding it + if (op.getInput() != null && !op.getInput().getMessage().isUndefined()) + messageSet.add(op.getInput().getMessage()); + + if (op.getOutput() != null + && !op.getOutput().getMessage().isUndefined()) + messageSet.add(op.getOutput().getMessage()); + + // also messages from any Faults defined within the operation + if (op.getFaults() != null) + { + Iterator faultIt = op.getFaults().values().iterator(); + Message message; + while (faultIt.hasNext()) + { + message = ((Fault) faultIt.next()).getMessage(); + if (!message.isUndefined()) + messageSet.add(message); + } + } + } + + if (messageSet.size() == 0) + { + // Set all message test assertion results to missingInput + setMissingInput( + EntryType.getEntryType(EntryType.TYPE_DESCRIPTION_MESSAGE)); + } + + else + { + // now step through each derived Message + Iterator messageIt = messageSet.iterator(); + while (messageIt.hasNext()) + { + processMessageAssertions( + (Message) (messageIt.next()), + serviceReference, + classPrefix, + wsdlDocument); + } + } + } + } + + /** + * Process message assertions. + * @param op - operation. + * @param serviceReference service reference. + * @param classPrefix class prefix. + * @param wsdlDocument WSDL document. + * @throws WSIException if problem occurs during processing + * message assertions. + */ + protected void processMessageAssertions( + Operation op, + ServiceReference serviceReference, + String classPrefix, + WSDLDocument wsdlDocument) + throws WSIException + { + + HashSet messageSet = new HashSet(); + if (op.getInput() != null && !op.getInput().getMessage().isUndefined()) + messageSet.add(op.getInput().getMessage()); + + if (op.getOutput() != null && !op.getOutput().getMessage().isUndefined()) + messageSet.add(op.getOutput().getMessage()); + + // also messages from any Faults defined within the operation + Iterator faultIt = op.getFaults().values().iterator(); + Message message; + while (faultIt.hasNext()) + { + message = ((Fault) faultIt.next()).getMessage(); + if (!message.isUndefined()) + messageSet.add(message); + } + + if (messageSet.size() == 0) + { + // Set all message test assertion results to missingInput + setMissingInput( + EntryType.getEntryType(EntryType.TYPE_DESCRIPTION_MESSAGE)); + } + + else + { + // now step through each derived Message + Iterator messageIt = messageSet.iterator(); + while (messageIt.hasNext()) + { + processMessageAssertions( + (Message) (messageIt.next()), + serviceReference, + classPrefix, + wsdlDocument); + } + } + } + + /* (non-Javadoc) + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl#isPrimaryEntryTypeMatch(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + protected boolean isPrimaryEntryTypeMatch( + TestAssertion testAssertion, + EntryContext targetContext) + { + boolean match = false; + + // If the test assertion entry type matches the target context entry type, then contine + if (testAssertion + .getEntryTypeName() + .equals(targetContext.getEntry().getEntryType().getTypeName())) + { + match = true; + } + + return match; + } + + /* (non-Javadoc) + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl#isNotApplicable(org.wsi.test.profile.TestAssertion) + */ + protected boolean isNotApplicable(TestAssertion testAssertion) + { + boolean notApplicable = false; + + // ADD: + + return notApplicable; + } + + /** + * Method getSoapFaults. + * + * @param inBinding in binding. + * @return soap faults. + * @throws WSIException if problems occur while processing binding faults. + */ + protected SOAPFault[] getSoapFaults(Binding inBinding) throws WSIException + { + + Vector soapFaults = new Vector(); + + // Go through each bindingFault one at a time + BindingFault[] bindingFaults = getAllBindingFaults(inBinding); + for (int fault = 0; fault < bindingFaults.length; fault++) + { + SOAPFault soapFault = getSoapFault(bindingFaults[fault]); + if (soapFault != null) + { + soapFaults.add(soapFault); + } + } + + SOAPFault[] soapFaultArray = new SOAPFault[soapFaults.size()]; + soapFaults.copyInto(soapFaultArray); + + return soapFaultArray; + } + + /** + * Method getAllBindingFaults. + * + * @param inBinding binding. + * @return all binding faults. + * @throws WSIException if problems occur during processing. + */ + protected BindingFault[] getAllBindingFaults(Binding inBinding) + throws WSIException + { + + Vector faults = new Vector(); + + try + { + + Iterator bindingOperations = inBinding.getBindingOperations().iterator(); + + while (bindingOperations.hasNext()) + { + + try + { + BindingOperation bo = (BindingOperation) bindingOperations.next(); + Iterator bindingFaults = bo.getBindingFaults().values().iterator(); + while (bindingFaults.hasNext()) + { + + faults.add((BindingFault) bindingFaults.next()); + } + } + catch (NullPointerException e) + { + + } + } + } + catch (NullPointerException e) + { + // no binding operations in this binding - ignore & continue + } + + BindingFault[] faultArray = new BindingFault[faults.size()]; + faults.copyInto(faultArray); + + return faultArray; + } + + /** + * Method getWSDLFaults. + * + * @param bindingFault a binding fault. + * @return WSDL faults. + * @throws WSIException if problems occur during processing. + */ + protected SOAPFault getSoapFault(BindingFault bindingFault) + throws WSIException + { + + SOAPFault soapFault = null; + try + { + Iterator faultExtensibles = + bindingFault.getExtensibilityElements().iterator(); + + while (faultExtensibles.hasNext() && soapFault == null) + { + try + { + soapFault = (SOAPFault) faultExtensibles.next(); + } + catch (ClassCastException e) + { // ignore everything but SOAP Fault elements. + } + } + } + catch (NullPointerException e) + { + } + + return soapFault; + } + + /** + * Method getSoapHeader. + * + * @param inBinding a binding. + * @return SOAP headers. + * @throws WSIException if problems occur during processing. + */ + protected SOAPHeader[] getSoapHeaders(Binding inBinding) throws WSIException + { + // Get all bindings + Binding[] bindingList = new Binding[1]; + bindingList[0] = inBinding; + + Vector soapHeaderList = new Vector(); + + // Go through each binding one at a time + for (int binding = 0; binding < bindingList.length; binding++) + { + try + { + // get the list of binding Operations + BindingOperation[] bindingOperations = + (BindingOperation[]) bindingList[binding] + .getBindingOperations() + .toArray( + new BindingOperation[0]); + + // get references to the extensible elements within the and elements of this binding . + for (int bo = 0; bo < bindingOperations.length; bo++) + { + + // Iterate over all input/output extensibles, looking for elements. + try + { + BindingInput bindingInput = bindingOperations[bo].getBindingInput(); + BindingOutput bindingOutput = + bindingOperations[bo].getBindingOutput(); + + Iterator extElements = + bindingInput.getExtensibilityElements().iterator(); + while (extElements.hasNext()) + { + try + { + soapHeaderList.add((SOAPHeader) extElements.next()); + } + catch (ClassCastException e) + { // ignore everything but SOAP Header. + } + } + + extElements = bindingOutput.getExtensibilityElements().iterator(); + while (extElements.hasNext()) + { + try + { + soapHeaderList.add((SOAPHeader) extElements.next()); + } + catch (ClassCastException e) + { // ignore everything but SOAP Header. + } + } + } + catch (NullPointerException e) + { // no extensibility elements for or - ignore : not checking this here. + } + } + } + catch (NullPointerException e) + { + // no binding operations in this binding - ignore & continue + } + } + + SOAPHeader[] soapHeaderArray = new SOAPHeader[soapHeaderList.size()]; + soapHeaderList.copyInto(soapHeaderArray); + + return soapHeaderArray; + } + + /** + * Method getSoapHeaderFaults. + * + * WSDLDocument getter method - maybe better off in class WSDLDocument... + * + * @param inBinding a binding. + * @return SOAP header faults. + * @throws WSIException if problems occur during processing. + */ + protected SOAPHeaderFault[] getSoapHeaderFaults(Binding inBinding) + throws WSIException + { + Vector soapHeaderFaultList = new Vector(); + + // Get the list of SOAP headers + SOAPHeader[] soapHeaderArray = getSoapHeaders(inBinding); + + // Go through the list and get the header faults + List list = null; + for (int header = 0; header < soapHeaderArray.length; header++) + { + // Get list for this header + if ((list = soapHeaderArray[header].getSOAPHeaderFaults()) != null) + { + // Add to primary list + soapHeaderFaultList.addAll(list); + } + } + + SOAPHeaderFault[] soapHeaderFaultArray = + new SOAPHeaderFault[soapHeaderFaultList.size()]; + soapHeaderFaultList.copyInto(soapHeaderFaultArray); + + return soapHeaderFaultArray; + } + + /** + * Method getSoapBodies. + * + * WSDLDocument getter method - maybe better off in class WSDLDocument... + * + * @param inBinding a binding. + * @return SOAP bodies. + * @throws WSIException if if problems occur during processing. + */ + protected SOAPBody[] getSoapBodies(Binding inBinding) throws WSIException + { + // REMOVE: Get all bindings + //Binding[] bindingList = wsdlDocument.getBindings(); + Binding[] bindingList = new Binding[1]; + bindingList[0] = inBinding; + + Vector soapBodies = new Vector(); + + // Go through each binding one at a time + for (int binding = 0; binding < bindingList.length; binding++) + { + // get the list of binding Operations + BindingOperation[] bindingOperations = + (BindingOperation[]) bindingList[binding] + .getBindingOperations() + .toArray( + new BindingOperation[0]); + + // get references to the extensible elements within the and elements of this binding . + for (int bo = 0; bo < bindingOperations.length; bo++) + { + + // Iterate over all input/output extensibles, looking for elements. + try + { + Iterator inputExtensibles = + bindingOperations[bo] + .getBindingInput() + .getExtensibilityElements() + .iterator(); + while (inputExtensibles.hasNext()) + { + try + { + soapBodies.add((SOAPBody) inputExtensibles.next()); + } + catch (ClassCastException e) + { // ignore everything but SOAP Body elements. + } + } + } + catch (NullPointerException e) + { // no extensibility elements for - ignore : not checking this here. + } + + try + { + Iterator outputExtensibles = + bindingOperations[bo] + .getBindingOutput() + .getExtensibilityElements() + .iterator(); + while (outputExtensibles.hasNext()) + { + try + { + soapBodies.add((SOAPBody) outputExtensibles.next()); + } + catch (ClassCastException e) + { // ignore everything but SOAP Body elements. + } + } + } + catch (NullPointerException e) + { // no extensibility elements for . + } + } + } + + SOAPBody[] soapBodyArray = new SOAPBody[soapBodies.size()]; + soapBodies.copyInto(soapBodyArray); + + return soapBodyArray; + } + + /** + * Method getSoapBody. + * + * @param bindingInput a BindingInput object. + * @return body. + * @throws WSIException if problems occur during processing. + */ + protected SOAPBody getSoapBody(BindingInput bindingInput) throws WSIException + { + + SOAPBody soapBody = null; + + Iterator extensibles = bindingInput.getExtensibilityElements().iterator(); + while (extensibles.hasNext()) + { + Object extensible = extensibles.next(); + if (extensible instanceof SOAPBody) + { + soapBody = (SOAPBody) extensible; + break; + } + } + return soapBody; + } + + /** + * Method getSoapBody. + * + * @param bindingOutput a BindingOutput object. + * @return SOAP body. + * @throws WSIException if problems occur during processing. + */ + protected SOAPBody getSoapBody(BindingOutput bindingOutput) + throws WSIException + { + + SOAPBody soapBody = null; + + Iterator extensibles = bindingOutput.getExtensibilityElements().iterator(); + while (extensibles.hasNext()) + { + Object extensible = extensibles.next(); + if (extensible instanceof SOAPBody) + { + soapBody = (SOAPBody) extensible; + break; + } + } + return soapBody; + } + + /** + * Get schema used. + * @param def definition. + * @return Schema used. + * @throws AssertionFailException if problem getting WSDL defintions + * namespace. + */ + protected String getSchemaUsed(Definition def) throws AssertionFailException + { + String schemaUsed = ""; + + try + { + // Need to read the file directly, since WSDL4J always puts in the default WSDL namespace + Document document = parseXMLDocumentURL(def.getDocumentBaseURI(), null); + + if (document != null) + { + // Get the root element + Element element = document.getDocumentElement(); + + // Get the namespace for this element + if (element != null) + schemaUsed = element.getNamespaceURI(); + } + } + + catch (WSIException we) + { + throw new AssertionFailException("problem getting WSDL defintions namespace"); + } + + /* + // Get the default namespace + String schemaUsed = def.getNamespace(""); + + // If the default was set, then process it to get the namespace + if (schemaUsed == null) { + // do it the hard way (still better than another DOM parse)... + //WSDLWriter w = new WSDLWriterImpl(); + try { + WSDLWriter w = WSDLFactory.newInstance().newWSDLWriter(); + Document doc = w.getDocument(def); + Element e = doc.getDocumentElement(); + schemaUsed = e.getNamespaceURI(); + } + catch (NullPointerException e) { + throw new AssertionFailException("problem getting WSDL defintions namespace"); + } + catch (WSDLException e) { + throw new AssertionFailException("problem getting document defintion"); + } + } + */ + + return schemaUsed; + } + + /** + * Method getSoapBinding. + * + * Get the SOAP binding for a Binding. + * + * @param binding a binding. + * @return a SOAP binding. + * @throws WSIException if problems occur during processing. + */ + public static SOAPBinding getSoapBinding(Binding binding) throws WSIException + { + SOAPBinding soapBinding = null; + + // Get the list of extensibility elements + List exElements = binding.getExtensibilityElements(); + if (exElements != null) + { + Iterator iterator = binding.getExtensibilityElements().iterator(); + + // Check for element + while ((iterator.hasNext()) && (soapBinding == null)) + { + try + { + soapBinding = (SOAPBinding) iterator.next(); + } + catch (ClassCastException e) + { // ignore everything but SOAP Binding element + } + } + } + + return soapBinding; + } + + /** + * Create XML schema validator. This is done here because some compilers do not allow + * the documentList field to be accessed from within an inner class. + * @param documentBaseURI the base URL. + * @return newly created XML schema validator. + */ + protected XMLSchemaValidator createXMLSchemaValidator(String documentBaseURI) + { + // Create XML schema validator + return new XMLSchemaValidator(documentBaseURI, documentList); + } + + /** + * Search xsd schema or xsd import from node. If node is xsd import it's loading schema. + * @param definition a Definition object. + * @return a list of schema target namespaces. + * @throws WSIException if problem during processing method. + */ + protected List getSchemaTargetNamespaceList(Definition definition) + throws WSIException + { + List list = null, nextList = null; + + // Get list of extension elements within the types element + Types types = null; + if ((types = definition.getTypes()) != null) + { + Iterator iterator = types.getExtensibilityElements().iterator(); + + ExtensibilityElement extElement = null; + while (iterator.hasNext()) + { + // Get next ext. element + extElement = (ExtensibilityElement) iterator.next(); + // If this is an unknown ext. element, then see if it is a schema element + TargetNamespaceProcessor tnsProcessor = null; + if (extElement instanceof UnknownExtensibilityElement) + { + tnsProcessor = + new TargetNamespaceProcessor( + definition.getDocumentBaseURI(), + documentList); + + if ((nextList = + tnsProcessor.processAllSchema( + ((UnknownExtensibilityElement) extElement).getElement())) + != null) + if (list == null) + list = new Vector(); + list.addAll(nextList); + } + } + } + + return list; + } + /** + * Search xsd schema or xsd import from node. If node is xsd import it's loading schema. + * @param definition a Definition object. + * @return a list of schema target namespaces. + * @throws WSIException if problem during processing method. + */ + protected List getSchemaNamespaceList(Definition definition) + throws WSIException + { + List list = new Vector(); + + // Always add current document targetNamespace + List targetNamespaceList = getSchemaTargetNamespaceList(definition); + + if ((targetNamespaceList != null) && !targetNamespaceList.isEmpty()) + list.addAll(targetNamespaceList); + + // Get list of imported WSDL documents + Map importMap = definition.getImports(); + + Import imp; + + // Add each imports targetNamespace to the list + if (importMap != null && !importMap.isEmpty()) + { + Iterator values = importMap.values().iterator(); + List importList; + while (values.hasNext()) + { + importList = (List) values.next(); + Iterator imports = importList.iterator(); + while (imports.hasNext()) + { + imp = (Import) imports.next(); + if (imp != null && imp.getDefinition() != null) + list.addAll(getSchemaNamespaceList(imp.getDefinition())); + } + } + } + + return list; + } + + /** + * Build list of WSDL targetNamespaces. + * @param definition a Definition object. + * @return list of WSDL targetNamespaces. + */ + protected List getWSDLTargetNamespaceList(Definition definition) + { + List list = new Vector(); + + // Always add current document targetNamespace + if (definition.getTargetNamespace() != null) + list.add(definition.getTargetNamespace()); + + // Get list of imported WSDL documents + Map importMap = definition.getImports(); + + Import imp; + + // Add each imports targetNamespace to the list + if (importMap != null && !importMap.isEmpty()) + { + Iterator values = importMap.values().iterator(); + List importList; + while (values.hasNext()) + { + importList = (List) values.next(); + Iterator imports = importList.iterator(); + while (imports.hasNext()) + { + imp = (Import) imports.next(); + if (imp != null && imp.getDefinition() != null) + list.addAll(getWSDLTargetNamespaceList(imp.getDefinition())); + // list.add(imp.getDefinition().getTargetNamespace()); + } + } + } + + return list; + } + + protected class BindingMatch + { + private Binding binding; + private BindingOperation bindingOperation; + private SOAPBinding soapBinding; + //private Vector bindingArgs; // set of BindingInputs and BindingOutputs + private BindingInput bindingInput; + private BindingOutput bindingOutput; + + // ADD: need to include BindingFault support... + public BindingMatch( + Binding b, + BindingOperation bo, + SOAPBinding sb, + BindingInput bin, + BindingOutput bout) + { + binding = b; + bindingOperation = bo; + soapBinding = sb; + //bindingArgs = new Vector(); + //if (bin != null) { bindingArgs.add(bin); } + //if (bout != null) { bindingArgs.add(bout); } + bindingInput = bin; + bindingOutput = bout; + } + + public BindingMatch( + Binding b, + BindingOperation bo, + SOAPBinding sb, + BindingInput bin) + { + this(b, bo, sb, bin, null); + } + + public BindingMatch( + Binding b, + BindingOperation bo, + SOAPBinding sb, + BindingOutput bout) + { + this(b, bo, sb, null, bout); + } + + /** + * Returns the soapBinding. + * @return SOAPBinding + */ + public SOAPBinding getSoapBinding() + { + return soapBinding; + } + + /** + * Returns the bindingOperation. + * @return BindingOperation + */ + public BindingOperation getBindingOperation() + { + return bindingOperation; + } + + /** + * Returns the bindingInput. + * @return BindingInput + */ + public BindingInput getBindingInput() + { + return bindingInput; + } + + /** + * Returns the bindingOutput. + * @return BindingOutput + */ + public BindingOutput getBindingOutput() + { + return bindingOutput; + } + + public boolean hasBindingInput() + { + return (this.bindingInput != null); + } + + public boolean hasBindingOutput() + { + return (this.bindingOutput != null); + } + + /** + * Returns the binding. + * @return Binding + */ + public Binding getBinding() + { + return binding; + } + + } + + /** + * Get binding matches. + * @param binding a binding. + * @param soapBindingStyle soap binding style. + * @param soapBodyUse soap body use. + * @return binding matches. + * @throws WSIException if problems occur during processing. + */ + public BindingMatch[] getBindingMatches( + Binding binding, + String soapBindingStyle, + String soapBodyUse) + throws WSIException + { + + Vector bindingMatches = new Vector(); + + // Check binding + SOAPBinding soapBinding = getSoapBinding(binding); + + // check that the soap:binding for this WSDL binding is the specified style + // ADD: check for null pointer + if (soapBinding != null) + { + String defaultStyle = soapBinding.getStyle(); + + if (defaultStyle == null) + { + defaultStyle = WSIConstants.ATTRVAL_SOAP_BIND_STYLE_DOC; + } + + // Get the set of operations for this WSDL binding + List bindingOpsList = binding.getBindingOperations(); + if (bindingOpsList != null) + { + Iterator bindingOps = bindingOpsList.iterator(); + // for each binding operation: + while (bindingOps.hasNext()) + { + BindingOperation bindingOp = (BindingOperation) bindingOps.next(); + + SOAPOperation soapOp = getSoapOperation(bindingOp); + + if ((soapOp == null && defaultStyle.equals(soapBindingStyle)) + || (soapOp != null + && soapOp.getStyle() == null + && defaultStyle.equals(soapBindingStyle)) + || (soapOp != null + && soapOp.getStyle() != null + && soapOp.getStyle().equals(soapBindingStyle))) + { + // check binding input & output + BindingInput bInput = bindingOp.getBindingInput(); + if (bInput != null) + { + SOAPBody inputSoapBody = getSoapBody(bInput); + if (inputSoapBody == null + || (inputSoapBody.getUse() != null + && !inputSoapBody.getUse().equals(soapBodyUse))) + { + bInput = null; + } + } + + BindingOutput bOutput = bindingOp.getBindingOutput(); + if (bOutput != null) + { + SOAPBody outputSoapBody = getSoapBody(bOutput); + + if (outputSoapBody == null + || (outputSoapBody.getUse() != null + && !outputSoapBody.getUse().equals(soapBodyUse))) + { + bOutput = null; + } + } + + if ((bOutput != null) || (bInput != null)) + { + // we have a match, add to the vector + bindingMatches.add( + new BindingMatch( + binding, + bindingOp, + soapBinding, + bInput, + bOutput)); + } + } + } + } + } + + BindingMatch[] BindingMatchArray = new BindingMatch[bindingMatches.size()]; + bindingMatches.copyInto(BindingMatchArray); + return BindingMatchArray; + } + + /** + * Method getSoapOperation. + * + * @param bindingOperation a binding operation. + * @return a soap operation. + * @throws WSIException if problems while processing. + */ + public static SOAPOperation getSoapOperation(BindingOperation bindingOperation) + throws WSIException + { + + if (bindingOperation.getExtensibilityElements() == null) + { + return null; + } + + Iterator extensibles = + bindingOperation.getExtensibilityElements().iterator(); + while (extensibles.hasNext()) + { + Object extensible = extensibles.next(); + if (extensible instanceof SOAPOperation) + { + return (SOAPOperation) extensible; + } + } + return null; + } + + /* + * Returns an array of SOAPOperations corresponding to the wsdl:binding supplied. + */ + protected HashMap getSoapOperations(Binding binding) throws WSIException + { + HashMap soapOperationList = new HashMap(); + + if (binding.getBindingOperations() == null) + { + return null; + } + + //Vector soapOpVector = new Vector(); + + // Get the list of binding operations + Iterator operations = binding.getBindingOperations().iterator(); + + // Check each binding operation to see if it has a soap operation element + BindingOperation bindingOperation = null; + while (operations.hasNext()) + { + bindingOperation = (BindingOperation) operations.next(); + Iterator extensibles = + bindingOperation.getExtensibilityElements().iterator(); + while (extensibles.hasNext()) + { + Object extensible = extensibles.next(); + if (extensible instanceof SOAPOperation) + { + soapOperationList.put(extensible, bindingOperation.getName()); + } + } + } + + //return (SOAPOperation[])soapOpVector.toArray(new SOAPOperation[] {}); + return soapOperationList; + } + + /** + * Check part attributes. + * @param bindingMatch an array of BindingMatch objects. + * @param inOrOut a String object. + * @param attrib attribute. + * @return a boolean. + * @throws AssertionFailException if the part is not compliant. + */ + // GT - rework this method with a better way of parameterizing the getters required for the invocation. + protected boolean checkPartAttributes( + BindingMatch[] bindingMatch, + String inOrOut, + String attrib) + throws AssertionFailException + { + + if (!(inOrOut.equals("useInput") || inOrOut.equals("useOutput")) + || !(attrib.equals("useType") || attrib.equals("useElement"))) + { + // invalid argument value supplied by calling method - "internal error" + return false; + } + + for (int i = 0; i < bindingMatch.length; i++) + { + BindingMatch nextMatch = bindingMatch[i]; + + // check the associated parts + Message msg; + Map parts; + Iterator partIteration; + + BindingOperation bindingOp = nextMatch.getBindingOperation(); + if (bindingOp == null) + { + continue; // no Binding Operation for some reason + } + + Operation op = bindingOp.getOperation(); + + /* ADD: handle soap:faults in similar way + try { + // check faults - remarkably similar.... (need to retain operation id for failuredetail msg) + if (nextMatch.hasBindingFault()) { + + msg = op.getFault().getMessage(); + parts = msg.getParts(); + + //check that each part has an element attribute + partIteration = parts.values().iterator(); + while (partIteration.hasNext()) { + Part part = (Part)partIteration.next(); + if (part.getElementName() == null) { + throw new AssertionFailException("OPERATION: " + op + "MESSAGE: " + msg); + } + } + } + } + catch (NullPointerException n) { + // no parts found - this qualifies an assertion failure + throw new AssertionFailException(n.getMessage()); + } + */ + + try + { + + QName attributeName; + + //GT: Do we need to check BindingInput / Output here ?? + + if (inOrOut.equals("useInput")) + { + if (op.getInput() == null || !nextMatch.hasBindingInput()) + { + // No Input so nothing to check + continue; + } + + msg = op.getInput().getMessage(); + + } + else + { // Looking for Output + if (op.getOutput() == null || !nextMatch.hasBindingOutput()) + { + // No Output so nothing to check + continue; + } + + msg = op.getOutput().getMessage(); + } + + if (msg == null) + { + continue; // nothing to check from this Binding Match (?) + } + + // Get the list of parts + parts = msg.getParts(); + + // If there is a parts attribute, then only process those parts + List partsNameList = null; + if ((partsNameList = getPartsList(nextMatch, inOrOut)) != null) + { + Vector partsList = new Vector(); + Iterator partsNameIterator = partsNameList.iterator(); + while (partsNameIterator.hasNext()) + { + partsList.add(parts.get((String) partsNameIterator.next())); + } + partIteration = partsList.iterator(); + } + + // Otherwise use the complete list of parts + else + { + partIteration = parts.values().iterator(); + } + + //check that each part has an element or type attribute + while (partIteration.hasNext()) + { + Part part = (Part) partIteration.next(); + if (attrib.equals("useElement")) + { + attributeName = part.getElementName(); + } + else + { // "useType" + attributeName = part.getTypeName(); + } + + if (attributeName == null) + { + throw new AssertionFailException( + "Name of operation that failed: " + + op.getName() + + "\n" + + op.toString() + + "\n" + + "\nName of message that failed: " + + msg.getQName() + + "\n" + + msg.toString()); + } + } + } + catch (NullPointerException n) + { + // no parts found - this qualifies an assertion failure + throw new AssertionFailException(n.toString()); + } + } + return true; // tests successful + } + + /** + * Get parts list from a soapbind:body element. + */ + private List getPartsList(BindingMatch bindingMatch, String type) + { + List partsList = null; + Iterator iterator = null; + + BindingOperation bindingOp; + + try + { + // Get the binding operation + bindingOp = bindingMatch.getBindingOperation(); + + // Determine if the binding operation contains a soapbind:body with a parts attribute + if (type.equals("useInput")) + { + iterator = + bindingOp.getBindingInput().getExtensibilityElements().iterator(); + } + else + { + iterator = + bindingOp.getBindingOutput().getExtensibilityElements().iterator(); + } + } + catch (NullPointerException e) + { + return null; + // either no binding operation, binding input/output, or SOAP element + } + + // Determine if the binding operation contains a soapbind:body with a parts attribute + while ((iterator.hasNext()) && (partsList == null)) + { + try + { + SOAPBody soapBody = (SOAPBody) iterator.next(); + partsList = soapBody.getParts(); + } + catch (ClassCastException cce) + { // not a SOAPBody extensibility element so ignore + } + } + + return partsList; + } + + /** + * Get element location. + * @param wsdlDocument WSDL document. + * @param wsdlElement WSDL element. + * @return element location. + */ + protected ElementLocation getElementLocation( + WSDLDocument wsdlDocument, + Object wsdlElement) + { + ElementLocation elementLocation = null; + WSDLElementList wsdlElementList; + + if ((wsdlElementList = wsdlDocument.getElementList()) != null) + { + elementLocation = wsdlElementList.getElementLocation(wsdlElement); + } + + return elementLocation; + } + + /** + * Create failure detail. + * @param message a message. + * @param entryContext entry context. + * @return failure detail. + */ + protected FailureDetail createFailureDetail( + String message, + EntryContext entryContext) + { + return createFailureDetail( + message, + entryContext, + entryContext.getEntry().getEntryDetail()); + } + + /** + * Create failure detail. + * @param message a message. + * @param entryContext entry context. + * @param wsdlElement WSDL element. + * @return failure detail. + */ + protected FailureDetail createFailureDetail( + String message, + EntryContext entryContext, + Object wsdlElement) + { + FailureDetail failureDetail = reporter.createFailureDetail(); + failureDetail.setFailureMessage(message); + failureDetail.setElementLocation( + getElementLocation(entryContext.getWSDLDocument(), wsdlElement)); + return failureDetail; + } + + /** + * SOAPBody, SOAPFault, SOAPHeader and SOAPHeaderFault class + * interfaces have compatible getUse() and getNamespaceURI() + * methods, but wsdl4j does not declare them at the parent interface. + * Therefore use reflection to access these common methods. + * + * @param extElement extensibility element. + * @return true if namespace is found in SOAP literal. + * @throws NoSuchMethodException if this method cannot be found. + * @throws InvocationTargetException if problems occur in an invoked method or constructor + * @throws IllegalAccessException if there is am attempt to load a + * class that it does not have access to. + */ + protected boolean namespaceFoundInSoapLiteral(ExtensibilityElement extElement) + throws NoSuchMethodException, InvocationTargetException, IllegalAccessException + { + Class c = extElement.getClass(); + Method getUseMethod = c.getMethod("getUse", new Class[0]); + Method getNamespaceURIMethod = c.getMethod("getNamespaceURI", new Class[0]); + + // (use attribute is mandatory but the null case is checked for since a missing use is not + // checked with this TA. If its missing its invalid but we don't know whether we have doc-lit). + if (getUseMethod.invoke(extElement, null) == null + || !getUseMethod.invoke(extElement, null).equals( + WSIConstants.ATTRVAL_SOAP_BODY_USE_LIT)) + { + return false; + } + + // return true if namespace found + boolean namespaceFound = + (getNamespaceURIMethod.invoke(extElement, null) != null); + + // return true if namespace found + return namespaceFound; + + } + + /** + * Verify extensibility element uses literal. + * @param extensible - extensibility element + * @return boolean + * @throws NoSuchMethodException if this method cannot be found. + * @throws InvocationTargetException if problems occur in an invoked method or constructor + * @throws IllegalAccessException if there is am attempt to load a + * class that it does not have access to. + */ + protected boolean isLiteral(ExtensibilityElement extensible) + throws NoSuchMethodException, InvocationTargetException, IllegalAccessException + { + + Class c = extensible.getClass(); + Method getUseMethod = c.getMethod("getUse", new Class[0]); + + // (use attribute is mandatory but the null case is checked for since a missing use is not + // checked with this TA. If its missing its invalid but we don't know whether we have doc-lit). + if (getUseMethod.invoke(extensible, null) == null + || !getUseMethod.invoke(extensible, null).equals( + WSIConstants.ATTRVAL_SOAP_BODY_USE_LIT)) + { + return false; + } + + // return true if shown to have use="literal" + return true; + + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2010.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2010.java new file mode 100644 index 000000000..d35d8ea8e --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2010.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +/** + * WSI2010 + */ +public class WSI2010 extends BP2010 +{ + + /** + * @param WSDLValidatorImpl + */ + public WSI2010(WSDLValidatorImpl impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2011.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2011.java new file mode 100644 index 000000000..8e0e3a777 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2011.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +/** + * WSI2011 + */ +public class WSI2011 extends BP2011 +{ + + /** + * @param WSDLValidatorImpl + */ + public WSI2011(WSDLValidatorImpl impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2012.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2012.java new file mode 100644 index 000000000..68c36b304 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2012.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +/** + * WSI2012 + */ +public class WSI2012 extends BP2012 +{ + + /** + * @param WSDLValidatorImpl + */ + public WSI2012(WSDLValidatorImpl impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2013.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2013.java new file mode 100644 index 000000000..11d354dab --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2013.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +/** + * WSI2013 + */ +public class WSI2013 extends BP2013 +{ + + /** + * @param WSDLValidatorImpl + */ + public WSI2013(WSDLValidatorImpl impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2014.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2014.java new file mode 100644 index 000000000..c08fba6dd --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2014.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +/** + * WSI2014 + */ +public class WSI2014 extends BP2014 +{ + + /** + * @param WSDLValidatorImpl + */ + public WSI2014(WSDLValidatorImpl impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2017.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2017.java new file mode 100644 index 000000000..8cd7492a1 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2017.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +/** + * WSI2017 + */ +public class WSI2017 extends BP2017 +{ + + /** + * @param WSDLValidatorImpl + */ + public WSI2017(WSDLValidatorImpl impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2018.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2018.java new file mode 100644 index 000000000..abc259f6b --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2018.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +/** + * WSI2018 + */ +public class WSI2018 extends BP2018 +{ + + /** + * @param WSDLValidatorImpl + */ + public WSI2018(WSDLValidatorImpl impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2019.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2019.java new file mode 100644 index 000000000..884d62639 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2019.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +/** + * WSI2019 + */ +public class WSI2019 extends BP2019 +{ + + /** + * @param WSDLValidatorImpl + */ + public WSI2019(WSDLValidatorImpl impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2020.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2020.java new file mode 100644 index 000000000..016d5bda4 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2020.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +/** + * WSI2020 + */ +public class WSI2020 extends BP2020 +{ + + /** + * @param WSDLValidatorImpl + */ + public WSI2020(WSDLValidatorImpl impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2021.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2021.java new file mode 100644 index 000000000..2899f9e77 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2021.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +/** + * WSI2021 + */ +public class WSI2021 extends BP2021 +{ + + /** + * @param WSDLValidatorImpl + */ + public WSI2021(WSDLValidatorImpl impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2022.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2022.java new file mode 100644 index 000000000..ba2dbb6c2 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2022.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +/** + * WSI2022 + */ +public class WSI2022 extends BP2022 +{ + + /** + * @param WSDLValidatorImpl + */ + public WSI2022(WSDLValidatorImpl impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2032.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2032.java new file mode 100644 index 000000000..ea036951e --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2032.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +/** + * WSI2032 + */ +public class WSI2032 extends BP2032 +{ + + /** + * @param WSDLValidatorImpl + */ + public WSI2032(WSDLValidatorImpl impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2098.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2098.java new file mode 100644 index 000000000..db8fd74f0 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2098.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +/** + * WSI2098 + */ +public class WSI2098 extends BP2098 +{ + + /** + * @param WSDLValidatorImpl + */ + public WSI2098(WSDLValidatorImpl impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2099.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2099.java new file mode 100644 index 000000000..34b6b6c1c --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2099.java @@ -0,0 +1,157 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +import javax.wsdl.BindingFault; +import javax.wsdl.BindingInput; +import javax.wsdl.BindingOperation; +import javax.wsdl.BindingOutput; +import javax.wsdl.Definition; +import javax.wsdl.Fault; +import javax.wsdl.Import; +import javax.wsdl.Input; +import javax.wsdl.Output; +import javax.wsdl.Part; +import javax.wsdl.Service; +import javax.wsdl.Types; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.WSITag; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcessVisitor; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.ErrorList; +import org.eclipse.wst.wsi.internal.wsdl.traversal.WSDLTraversal; +import org.eclipse.wst.wsi.internal.wsdl.traversal.WSDLTraversalContext; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; +import org.w3c.dom.Element; + + +/** + * WSI2099. + * For a candidate wsdl:definitions, + * A WS-I conformance annotation does not appear outside a wsdl:port, wsdl:binding, wsdl:portType, wsdl:operation, or wsdl:message element. + */ +public class WSI2099 extends AssertionProcessVisitor implements WSITag +{ + private final WSDLValidatorImpl validator; + + /** + * @param WSDLValidatorImpl + */ + public WSI2099(WSDLValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + private ErrorList errors = new ErrorList(); + private boolean containsClaims = false; + + /** + * Check a WS-I conformance annotation does not appear outside a wsdl:port, wsdl:binding, wsdl:portType, wsdl:operation, or wsdl:message element if not it creates failure report. + * @see org.eclipse.wst.wsi.internal.wsdl.traversal.WSDLVisitor#visit(org.w3c.dom.Element, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit(Element el, Object parent, WSDLTraversalContext ctx) + { + // conformance claim should be within : port, binding, porttype, operation, message + if (containsConformanceClaim(el)) + { + containsClaims = true; + + if (parent instanceof BindingFault) + errors.add(WSDL_FAULT, ((BindingFault) parent).getName()); + else if (parent instanceof BindingInput) + errors.add(WSDL_INPUT, ((BindingInput) parent).getName()); + else if (parent instanceof BindingOperation) + errors.add(WSDL_OPERATION, ((BindingOperation) parent).getName()); + else if (parent instanceof BindingOutput) + errors.add(WSDL_OUTPUT, ((BindingOutput) parent).getName()); + else if (parent instanceof Definition) + errors.add(WSDL_DEFINITIONS, ((Definition) parent).getQName()); + else if (parent instanceof Service) + errors.add(WSDL_SERVICE, ((Service) parent).getQName()); + else if (parent instanceof Fault) + errors.add(WSDL_FAULT, ((Fault) parent).getName()); + else if (parent instanceof Output) + errors.add(WSDL_INPUT, ((Output) parent).getName()); + else if (parent instanceof Import) + errors.add(WSDL_IMPORT, ((Import) parent).getNamespaceURI()); + else if (parent instanceof Input) + errors.add(WSDL_INPUT, ((Input) parent).getName()); + else if (parent instanceof Part) + errors.add(WSDL_PART, ((Part) parent).getName()); + else if (parent instanceof Types) + errors.add(WSDL_TYPES); + } + } + + /* Validates the test assertion. + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + result = AssertionResult.RESULT_FAILED; + + WSDLTraversal traversal = new WSDLTraversal(); + //VisitorAdaptor.adapt(this); + traversal.setVisitor(this); + traversal.visitElement(true); + /* + traversal. + ignorePort2Element(). + ignoreMessage2Element(). + ignoreBinding2Element(). + ignorePortType2Element(). + ignoreOperation2Element(); + */ + traversal.ignoreReferences(); + traversal.ignoreImport(); + traversal.traverse((Definition) entryContext.getEntry().getEntryDetail()); + + // create detail message with the list of error elements + if (!errors.isEmpty()) + { + failureDetail = this.validator.createFailureDetail(errors.toString(), entryContext); + result = AssertionResult.RESULT_FAILED; + } + + else if (!containsClaims) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + + else + { + result = AssertionResult.RESULT_PASSED; + } + + return validator.createAssertionResult(testAssertion, result, failureDetail); + } + + /** + * Check the documentation element whether contains conformance claims. + * Returns true if documentation element contains conformance claim. + * @param el + * @return boolean + */ + private boolean containsConformanceClaim(Element el) + { + if (el == null) + return false; + el = XMLUtils.findChildElement(el, WSI_CLAIM); + return (el != null); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2100.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2100.java new file mode 100644 index 000000000..8aa5bf986 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2100.java @@ -0,0 +1,171 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +import javax.wsdl.Binding; +import javax.wsdl.Definition; +import javax.wsdl.Message; +import javax.wsdl.Operation; +import javax.wsdl.Port; +import javax.wsdl.PortType; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.WSITag; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.profile.validator.EntryContext; +import org.eclipse.wst.wsi.internal.profile.validator.impl.AssertionProcessVisitor; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.util.ErrorList; +import org.eclipse.wst.wsi.internal.wsdl.traversal.WSDLTraversal; +import org.eclipse.wst.wsi.internal.wsdl.traversal.WSDLTraversalContext; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; +import org.w3c.dom.Element; + + +/** + * WSI2100. + * For a candidate wsdl:definitions, if it contains a wsdl:port, wsdl:binding, wsdl:portType, wsdl:operation, or wsdl:message, which in turn contains a conformance annotation + * The conformance annotation of the wsdl:port, wsdl:binding, wsdl:portType, wsdl:operation, or wsdl:message, validates to the schema defined in the Basic Profile, and is direct child of the documentation element for the WSDL element. The schema definition uses "http://ws-i.org/schemas/conformanceClaim/" as the targetNamespace. + */ +public class WSI2100 extends AssertionProcessVisitor implements WSITag +{ + private final WSDLValidatorImpl validator; + + /** + * @param WSDLValidatorImpl + */ + public WSI2100(WSDLValidatorImpl impl) + { + super(impl); + this.validator = impl; + } + + private boolean containsClaims = false; + private ErrorList errors = new ErrorList(); + + /* Create falure report if port contains illegal claim. + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.Port, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit(Port port, Object parent, WSDLTraversalContext ctx) + { + if (port != null && !containsLegalClaim(port.getDocumentationElement())) + errors.add(WSDL_PORT, port.getName()); + } + + /* Create falure report if binding contains illegal claim. + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.Binding, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit(Binding binding, Object parent, WSDLTraversalContext ctx) + { + if (binding != null + && !containsLegalClaim(binding.getDocumentationElement())) + errors.add(WSDL_BINDING, binding.getQName()); + } + + /* Create falure report if port type contains illegal claim. + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.PortType, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit(PortType type, Object parent, WSDLTraversalContext ctx) + { + if (type != null && !containsLegalClaim(type.getDocumentationElement())) + errors.add(WSDL_PORTTYPE, type.getQName()); + } + + /* Create falure report if operation contains illegal claim. + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.Operation, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit( + Operation operation, + Object parent, + WSDLTraversalContext ctx) + { + if (operation != null + && !containsLegalClaim(operation.getDocumentationElement())) + errors.add(WSDL_OPERATION, operation.getName()); + } + + /* Create falure report if message contains illegal claim. + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.Message, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit(Message message, Object parent, WSDLTraversalContext ctx) + { + if (message != null + && !containsLegalClaim(message.getDocumentationElement())) + errors.add(WSDL_MESSAGE, message.getQName()); + } + + /* Validates the test assertion. + * @see org.wsi.test.profile.validator.impl.BaseValidatorImpl.AssertionProcess#validate(org.wsi.test.profile.TestAssertion, org.wsi.test.profile.validator.EntryContext) + */ + public AssertionResult validate( + TestAssertion testAssertion, + EntryContext entryContext) + throws WSIException + { + result = AssertionResult.RESULT_FAILED; + + WSDLTraversal traversal = new WSDLTraversal(); + //VisitorAdaptor.adapt(this); + traversal.setVisitor(this); + traversal.visitOperation(true); + traversal.visitBinding(true); + traversal.visitMessage(true); + traversal.visitPort(true); + traversal.visitPortType(true); + traversal.ignoreReferences(); + traversal.ignoreImport(); + traversal.traverse((Definition) entryContext.getEntry().getEntryDetail()); + + // create detail message with the list of error elements + if (!errors.isEmpty()) + { + failureDetail = this.validator.createFailureDetail(errors.toString(), entryContext); + result = AssertionResult.RESULT_FAILED; + } + + else if (!containsClaims) + { + result = AssertionResult.RESULT_NOT_APPLICABLE; + } + else + result = AssertionResult.RESULT_PASSED; + + return validator.createAssertionResult(testAssertion, result, failureDetail); + } + + /** + * Check the documentation element whether contains conformance claims. + * Returns true if documentation element contains conformance claim with + * illegal schema definition URI. + * legal is 'http://ws-i.org/schemas/conformanceClaim/' + * @param el + * @return boolean + */ + private boolean containsLegalClaim(Element el) + { + if (el == null) + return true; + // find claim + el = XMLUtils.findChildElement(el, WSI_CLAIM); + + if (el != null) + containsClaims = true; + + while (el != null) + { + if (XMLUtils.getAttribute(el, ATTR_CLAIM_CONFORMSTO) == null + || XMLUtils.getAttribute(el, ATTR_SOAP_MUSTUNDERSTAND) != null) + return false; + el = XMLUtils.findElement(el, WSI_CLAIM); + } + return true; + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2101.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2101.java new file mode 100644 index 000000000..e1b828c5b --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2101.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +/** + * WSI2101 + */ +public class WSI2101 extends BP2101 +{ + + /** + * @param WSDLValidatorImpl + */ + public WSI2101(WSDLValidatorImpl impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2102.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2102.java new file mode 100644 index 000000000..78f732c00 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2102.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +/** + * WSI2102 + */ +public class WSI2102 extends BP2102 +{ + + /** + * @param WSDLValidatorImpl + */ + public WSI2102(WSDLValidatorImpl impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2103.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2103.java new file mode 100644 index 000000000..c920a9312 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2103.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +/** + * WSI2103 + */ +public class WSI2103 extends BP2103 +{ + + /** + * @param WSDLValidatorImpl + */ + public WSI2103(WSDLValidatorImpl impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2104.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2104.java new file mode 100644 index 000000000..a55819446 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2104.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +/** + * WSI2104 + */ +public class WSI2104 extends BP2104 +{ + + /** + * @param WSDLValidatorImpl + */ + public WSI2104(WSDLValidatorImpl impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2105.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2105.java new file mode 100644 index 000000000..497a2cbfb --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2105.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +/** + * WSI2105 + */ +public class WSI2105 extends BP2105 +{ + + /** + * @param WSDLValidatorImpl + */ + public WSI2105(WSDLValidatorImpl impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2107.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2107.java new file mode 100644 index 000000000..bc470c18e --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2107.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +/** + * WSI2107 + */ +public class WSI2107 extends BP2107 +{ + + /** + * @param WSDLValidatorImpl + */ + public WSI2107(WSDLValidatorImpl impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2108.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2108.java new file mode 100644 index 000000000..6c206bb6a --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2108.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +/** + * WSI2108 + */ +public class WSI2108 extends BP2108 +{ + + /** + * @param WSDLValidatorImpl + */ + public WSI2108(WSDLValidatorImpl impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2110.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2110.java new file mode 100644 index 000000000..81cf1ca56 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2110.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +/** + * WSI2110 + */ +public class WSI2110 extends BP2110 +{ + + /** + * @param WSDLValidatorImpl + */ + public WSI2110(WSDLValidatorImpl impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2111.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2111.java new file mode 100644 index 000000000..3359b5f4a --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2111.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +/** + * WSI2111 + */ +public class WSI2111 extends BP2111 +{ + + /** + * @param WSDLValidatorImpl + */ + public WSI2111(WSDLValidatorImpl impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2112.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2112.java new file mode 100644 index 000000000..b76f752b8 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2112.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +/** + * WSI2112 + */ +public class WSI2112 extends BP2112 +{ + + /** + * @param WSDLValidatorImpl + */ + public WSI2112(WSDLValidatorImpl impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2113.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2113.java new file mode 100644 index 000000000..3b7687c81 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2113.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +/** + * WSI2113 + */ +public class WSI2113 extends BP2113 +{ + + /** + * @param WSDLValidatorImpl + */ + public WSI2113(WSDLValidatorImpl impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2114.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2114.java new file mode 100644 index 000000000..1e53f7b1f --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2114.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +/** + * WSI2114 + */ +public class WSI2114 extends BP2114 +{ + + /** + * @param WSDLValidatorImpl + */ + public WSI2114(WSDLValidatorImpl impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2115.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2115.java new file mode 100644 index 000000000..0f8457680 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2115.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +/** + * WSI2115 + */ +public class WSI2115 extends BP2115 +{ + + /** + * @param WSDLValidatorImpl + */ + public WSI2115(WSDLValidatorImpl impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2116.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2116.java new file mode 100644 index 000000000..f83fecabb --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2116.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +/** + * WSI2116 + */ +public class WSI2116 extends BP2116 +{ + + /** + * @param WSDLValidatorImpl + */ + public WSI2116(WSDLValidatorImpl impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2117.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2117.java new file mode 100644 index 000000000..54485c5b5 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2117.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +/** + * WSI2117 + */ +public class WSI2117 extends BP2117 +{ + + /** + * @param WSDLValidatorImpl + */ + public WSI2117(WSDLValidatorImpl impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2118.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2118.java new file mode 100644 index 000000000..57abd7bca --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2118.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +/** + * WSI2118 + */ +public class WSI2118 extends BP2118 +{ + + /** + * @param WSDLValidatorImpl + */ + public WSI2118(WSDLValidatorImpl impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2119.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2119.java new file mode 100644 index 000000000..49203e280 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2119.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +/** + * WSI2119 + */ +public class WSI2119 extends BP2119 +{ + + /** + * @param WSDLValidatorImpl + */ + public WSI2119(WSDLValidatorImpl impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2120.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2120.java new file mode 100644 index 000000000..61b329ca9 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2120.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +/** + * WSI2120 + */ +public class WSI2120 extends BP2120 +{ + + /** + * @param WSDLValidatorImpl + */ + public WSI2120(WSDLValidatorImpl impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2122.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2122.java new file mode 100644 index 000000000..0e750479c --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2122.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +/** + * WSI2122 + */ +public class WSI2122 extends BP2122 +{ + + /** + * @param WSDLValidatorImpl + */ + public WSI2122(WSDLValidatorImpl impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2123.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2123.java new file mode 100644 index 000000000..f921782b4 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2123.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +/** + * WSI2123 + */ +public class WSI2123 extends BP2123 +{ + + /** + * @param WSDLValidatorImpl + */ + public WSI2123(WSDLValidatorImpl impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2201.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2201.java new file mode 100644 index 000000000..d45262990 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2201.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +/** + * WSI2201 + */ +public class WSI2201 extends BP2201 +{ + + /** + * @param WSDLValidatorImpl + */ + public WSI2201(WSDLValidatorImpl impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2202.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2202.java new file mode 100644 index 000000000..fbcc6f448 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2202.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +/** + * WSI2202 + */ +public class WSI2202 extends BP2202 +{ + + /** + * @param WSDLValidatorImpl + */ + public WSI2202(WSDLValidatorImpl impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2208.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2208.java new file mode 100644 index 000000000..3782d58ec --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2208.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +/** + * WSI2208 + */ +public class WSI2208 extends BP2208 +{ + + /** + * @param WSDLValidatorImpl + */ + public WSI2208(WSDLValidatorImpl impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2402.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2402.java new file mode 100644 index 000000000..7b3f43512 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2402.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +/** + * WSI2402 + */ +public class WSI2402 extends BP2402 +{ + + /** + * @param WSDLValidatorImpl + */ + public WSI2402(WSDLValidatorImpl impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2403.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2403.java new file mode 100644 index 000000000..cbdf0e097 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2403.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +/** + * WSI2403 + */ +public class WSI2403 extends SSBP2403 +{ + + /** + * @param WSDLValidatorImpl + */ + public WSI2403(WSDLValidatorImpl impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2404.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2404.java new file mode 100644 index 000000000..c5852ad95 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2404.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +/** + * WSI2404 + */ +public class WSI2404 extends BP2404 +{ + + /** + * @param WSDLValidatorImpl + */ + public WSI2404(WSDLValidatorImpl impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2406.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2406.java new file mode 100644 index 000000000..ecbf7808e --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2406.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +/** + * WSI2406 + */ +public class WSI2406 extends BP2406 +{ + + /** + * @param WSDLValidatorImpl + */ + public WSI2406(WSDLValidatorImpl impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2416.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2416.java new file mode 100644 index 000000000..64f08cfcd --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2416.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +/** + * WSI2416 + */ +public class WSI2416 extends BP2416 +{ + + /** + * @param WSDLValidatorImpl + */ + public WSI2416(WSDLValidatorImpl impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2417.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2417.java new file mode 100644 index 000000000..a7efc43e7 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2417.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +/** + * WSI2417 + */ +public class WSI2417 extends BP2417 +{ + + /** + * @param WSDLValidatorImpl + */ + public WSI2417(WSDLValidatorImpl impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2700.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2700.java new file mode 100644 index 000000000..7e203a9f8 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2700.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +/** + * WSI2700 + */ +public class WSI2700 extends BP2700 +{ + + /** + * @param WSDLValidatorImpl + */ + public WSI2700(WSDLValidatorImpl impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2701.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2701.java new file mode 100644 index 000000000..17ae8ab10 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2701.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +/** + * WSI2701 + */ +public class WSI2701 extends BP2701 +{ + + /** + * @param WSDLValidatorImpl + */ + public WSI2701(WSDLValidatorImpl impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2703.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2703.java new file mode 100644 index 000000000..20dcef1ad --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI2703.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +/** + * WSI2703 + */ +public class WSI2703 extends BP2703 +{ + + /** + * @param WSDLValidatorImpl + */ + public WSI2703(WSDLValidatorImpl impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI4200.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI4200.java new file mode 100644 index 000000000..2d85a691e --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI4200.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +/** + * WSI4200 + */ +public class WSI4200 extends BP4200 +{ + + /** + * @param WSDLValidatorImpl + */ + public WSI4200(WSDLValidatorImpl impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI4201.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI4201.java new file mode 100644 index 000000000..9ff484487 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI4201.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +/** + * WSI4201 + */ +public class WSI4201 extends BP4201 +{ + + /** + * @param WSDLValidatorImpl + */ + public WSI4201(WSDLValidatorImpl impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI4202.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI4202.java new file mode 100644 index 000000000..9155872c2 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/profile/validator/impl/wsdl/WSI4202.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.profile.validator.impl.wsdl; + +/** + * WSI4202 + */ +public class WSI4202 extends BP4202 +{ + + /** + * @param WSDLValidatorImpl + */ + public WSI4202(WSDLValidatorImpl impl) + { + super(impl); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/ArtifactReference.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/ArtifactReference.java new file mode 100644 index 000000000..ef33dfc13 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/ArtifactReference.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.report; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.document.DocumentElement; + +import javax.xml.namespace.QName; + +/** + * An artifact reference. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public interface ArtifactReference extends DocumentElement +{ + /** + * Element name. + */ + public static final String ELEM_NAME = WSIConstants.ELEM_ARTIFACT_REFERENCE; + + /** + * QName. + */ + public static final QName QNAME = + new QName(WSIConstants.NS_URI_WSI_REPORT, ELEM_NAME); + + /** + * Get timestamp. + * @return timestamp. + * @see #setTimestamp + */ + public String getTimestamp(); + + /** + * Set timestamp. + * @param timestamp a timestamp. + * @see #getTimestamp + */ + public void setTimestamp(String timestamp); + + /** + * Get document element. + * @return document element. + * @see #setDocumentElement + */ + public DocumentElement getDocumentElement(); + + /** + * Set document element. + * @param documentElement document element. + * @param namespaceName namespace prefix. + * @see #getDocumentElement + */ + public void setDocumentElement( + DocumentElement documentElement, + String namespaceName); +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/AssertionError.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/AssertionError.java new file mode 100644 index 000000000..3e0ec824e --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/AssertionError.java @@ -0,0 +1,131 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ + package org.eclipse.wst.wsi.internal.report; + +/** + * AssertionError + * + * Object to hold an assertion error generated by the WS-I Test Tools. + * Provides access to all the information about the error including the + * id, message and location in the file. + */ +public class AssertionError +{ + + protected String message; + protected String assertionid; + protected int column; + protected int line; + /** + * Constructor for AssertionError. + */ + public AssertionError() + { + message = assertionid = ""; + line = column = 0; + } + + /** + * Constructor for AssertionError. + * @param id assertion id. + * @param message a error message. + * @param line a line number. + * @param column a column number. + */ + public AssertionError(String id, String message, int line, int column) + { + this.assertionid = id; + this.message = message; + this.line = line; + this.column = column; + } + + /** + * Method setAssertionID. + * @param id assertion id. + * @see #getAssertionID + */ + public void setAssertionID(String id) + { + assertionid = id; + } + + /** + * Method getAssertionID. + * @return asserion id. + * @see #setAssertionID + */ + public String getAssertionID() + { + return assertionid; + } + + /** + * Method setErrorMessage. + * @param message a error message. + * @see #getErrorMessage + */ + public void setErrorMessage(String message) + { + this.message = message; + } + + /** + * Method getErrorMessage. + * @return error message. + * @see #setErrorMessage + */ + public String getErrorMessage() + { + return message; + } + + /** + * Method setLine. + * @param line line number. + * @see #getLine + */ + public void setLine(int line) + { + this.line = line; + } + + /** + * Method getLine. + * @return line number. + * @see #setLine + */ + public int getLine() + { + return line; + } + + /** + * Method setColumn. + * @param column column number. + * @see #getColumn + */ + public void setColumn(int column) + { + this.column = column; + } + + /** + * Method getColumn. + * @return column number. + * @see #setColumn + */ + public int getColumn() + { + return column; + } + +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/AssertionResult.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/AssertionResult.java new file mode 100644 index 000000000..681d9173d --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/AssertionResult.java @@ -0,0 +1,148 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.report; + +import java.util.Vector; + +import javax.xml.namespace.QName; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.analyzer.config.AssertionResultsOption; +import org.eclipse.wst.wsi.internal.document.DocumentElement; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; + +/** + * Test assertion result. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public interface AssertionResult extends DocumentElement +{ + /** + * Element name. + */ + public static final String ELEM_NAME = WSIConstants.ELEM_ASSERTION_RESULT; + + /** + * QName. + */ + public static final QName QNAME = + new QName(WSIConstants.NS_URI_WSI_REPORT, ELEM_NAME); + + /** + * Result values. + */ + public static final String RESULT_PASSED = "passed"; + public static final String RESULT_FAILED = "failed"; + public static final String RESULT_PREREQ_FAILED = "prereqFailed"; + public static final String RESULT_MISSING_INPUT = "missingInput"; + public static final String RESULT_WARNING = "warning"; + public static final String RESULT_NOT_APPLICABLE = "notApplicable"; + + /** + * Get result. + * @return result. + * @see #setResult + */ + public String getResult(); + + /** + * Set result. + * @param result the result value. + * @see #getResult + */ + public void setResult(String result); + + /** + * Get assertion. + * @return profile test assertion. + * @see #setAssertion + */ + public TestAssertion getAssertion(); + + /** + * Set assertion. + * @param profileAssertion profile test assertion. + * @see #getAssertion + */ + public void setAssertion(TestAssertion profileAssertion); + + /** + * Get entry. + * @return entry. + * @see #setEntry + */ + public Entry getEntry(); + + /** + * Set entry. + * @param entry an entry. + * @see #getEntry + */ + public void setEntry(Entry entry); + + /** + * Get failure detail messages. + * @return failure detail messages. + * @see #setFailureDetailList + */ + public Vector getFailureDetailList(); + + /** + * Set failure detail messages. + * @param failureDetailList failure detail messages. + * @see #getFailureDetailList + */ + public void setFailureDetailList(Vector failureDetailList); + + /** + * Get warning messages. + * @return warning messages. + * @see #setWarningMessages + */ + //public Vector getWarningMessages(); + + /** + * Set warning messages. + * @param warningMessages warning messages. + * @see #getWarningMessages + */ + //public void setWarningMessages(Vector warningMessages); + + /** + * Get assertion results option. + * @return ssertion results option. + * @see #setAssertionResultsOption + */ + public AssertionResultsOption getAssertionResultsOption(); + + /** + * Set assertion results option. + * @param assertionResultsOption assertion results option. + * @see #getAssertionResultsOption + */ + public void setAssertionResultsOption(AssertionResultsOption assertionResultsOption); + + /** + * Get prereq failed list. + * @return prereq failed list. + * @see #setPrereqFailedList + */ + public PrereqFailedList getPrereqFailedList(); + + /** + * Set prereq failed list. + * @param prereqFailedList prereq failed list. + * @see #getPrereqFailedList + */ + public void setPrereqFailedList(PrereqFailedList prereqFailedList); +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/BuildReport.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/BuildReport.java new file mode 100644 index 000000000..e29ba0a5a --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/BuildReport.java @@ -0,0 +1,125 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.report; + +import org.eclipse.wst.wsi.internal.WSIException; + +/** + * This interface is used to build the Profile report. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public interface BuildReport +{ + /** + * Prereq type - entry. + */ + public static final String PREREQ_TYPE_ENTRY = "entry"; + + /** + * Prereq type - entry container. + */ + public static final String PREREQ_TYPE_ENTRY_CONTAINER = "entryContainer"; + + /** + * Start current artifact. + * @param reportArtifact current report artifact. + * @throws WSIException the base WS-I exception. + */ + public void setCurrentArtifact(ReportArtifact reportArtifact) + throws WSIException; + + /** + * Add artifact refererence. + * @param artifactReference artifact reference. + * @throws WSIException the base WS-I exception. + */ + public void addArtifactReference(ArtifactReference artifactReference) + throws WSIException; + + /** + * End current artifact. + * @throws WSIException the base WS-I exception. + */ + public void endCurrentArtifact() throws WSIException; + + /** + * Start current entry. + * @param entry the current entry. + * @throws WSIException the base WS-I exception. + */ + public void setCurrentEntry(Entry entry) throws WSIException; + + /** + * Start current entry. + * @param entry the current entry. + * @throws WSIException the base WS-I exception. + */ + public void setCurrentEnvelopeEntry(Entry entry) throws WSIException; + /** + * End current entry. + * @throws WSIException the base WS-I exception. + */ + public void endCurrentEntry() throws WSIException; + + /** + * Add test assertion result. + * @param assertionResult test assertion result. + * @throws WSIException the base WS-I exception. + */ + public void addAssertionResult(AssertionResult assertionResult) + throws WSIException; + + /** + * Get the assertion result for a specific test assertion. + * @param assertionId the test assertion ID. + * @return the assertion result for the specified test assertion ID. + * If an assertion result was not found, then null is returned. + */ + public AssertionResult getAssertionResult(String assertionId); + + /** + * Create assertion result. + * @return newly created assertion result. + */ + public AssertionResult createAssertionResult(); + + /** + * Create entry. + * @return newly created entry. + */ + public Entry createEntry(); + + /** + * Create entry container. + * @return newly created entry container. + */ + public EntryContainer createEntryContainer(); + + /** + * Create artifact. + * @return newly created artifact. + */ + public ReportArtifact createArtifact(); + + /** + * Create failure detail. + * @return newly created failure detail. + */ + public FailureDetail createFailureDetail(); + + /** + * Set type of prereq processing - either entry or document. + * @param prereqType type of prereq processing - either entry or document. + */ + public void setPrereqType(String prereqType); +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/Entry.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/Entry.java new file mode 100644 index 000000000..92819ca74 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/Entry.java @@ -0,0 +1,153 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.report; + +import javax.xml.namespace.QName; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.document.DocumentElement; +import org.eclipse.wst.wsi.internal.util.EntryType; + +/** + * Test assertion target. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public interface Entry extends EntryResult, DocumentElement +{ + /** + * Element name. + */ + public static final String ELEM_NAME = WSIConstants.ELEM_ENTRY; + + /** + * QName. + */ + public static final QName QNAME = + new QName(WSIConstants.NS_URI_WSI_REPORT, ELEM_NAME); + + /** + * Get assertion results option. + */ + //public AssertionResultsOption getAssertionResultsOption(); + + /** + * Set assertion results option. + */ + //public void setAssertionResultsOption(AssertionResultsOption assertionResultsOption); + + /** + * Get entry type. + * @return entry type. + * @see #setEntryType + */ + public EntryType getEntryType(); + + /** + * Set entry type. + * @param entryType entry type. + * @see #getEntryType + */ + public void setEntryType(EntryType entryType); + + /** + * Get artifact name. + * @return artifact name. + * @see #setArtifactName + */ + public String getArtifactName(); + + /** + * Set artifact name. + * @param artifactName artifact name. + * @see #getArtifactName + */ + public void setArtifactName(String artifactName); + + /** + * Get reference ID. + * @return reference ID. + * @see #setReferenceID + */ + public String getReferenceID(); + + /** + * Set reference ID. + * @param referenceID referenceID. + * @see #getReferenceID + */ + public void setReferenceID(String referenceID); + + /** + * Get parent element name. + * @return parent element name. + * @see #setParentElementName + */ + public String getParentElementName(); + + /** + * Set parent element name. + * @param parentElementName parent element name. + * @see #getParentElementName + */ + public void setParentElementName(String parentElementName); + + /** + * Get entry detail. + * @return entry detail. + * @see #setEntryDetail + */ + public Object getEntryDetail(); + + /** + * Set entry detail. + * @param detail entry detail. + * @see #getEntryDetail + */ + public void setEntryDetail(Object detail); + + /** + * Get entry container. + * @return entry container. + * @see #setEntryContainer + */ + public EntryContainer getEntryContainer(); + + /** + * Set entry container. + * @param entryContainer entry container. + * @see #getEntryContainer + */ + public void setEntryContainer(EntryContainer entryContainer); + + /** + * Get start element string. + * @param namespaceName namespace prefix. + * @param showLogEntry show log entry option. + * @return start XML element string. + */ + public String getStartXMLString(String namespaceName, boolean showLogEntry); + + /** + * Get start element string. + * @param namespaceName namespace prefix. + * @param showLogEntry show log entry option. + * @return start XML element string. + */ + public String getStartXMLString(String namespaceName, boolean showLogEntry, boolean envelopeArtifactType); + /** + * Get end element string. + * @param namespaceName namespace prefix. + * @return end XML element string. + */ + public String getEndXMLString(String namespaceName); +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/EntryContainer.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/EntryContainer.java new file mode 100644 index 000000000..85478b67f --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/EntryContainer.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.report; + +/** + * This class represents a container which has one or more entries. + * For example, a WSDL document contains one or more elements. + * + * @author Peter Brittenham (peterbr@us.ibm.com) + * @version 1.0.1 + */ +public interface EntryContainer extends EntryResult +{ + /** + * Get container id. + * @return container id. + * @see #setId + */ + public String getId(); + + /** + * Set container id. + * @param id container id. + * @see #getId + */ + public void setId(String id); +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/EntryResult.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/EntryResult.java new file mode 100644 index 000000000..19898f2a1 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/EntryResult.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.report; + +import java.util.TreeMap; + +/** + * Result for a specific test assertion. + * + * @author Peter Brittenham (peterbr@us.ibm.com) + * @version 1.0.1 + */ +public interface EntryResult +{ + /** + * Add assertion result. + * @param assertionResult assertion result. + */ + public void addAssertionResult(AssertionResult assertionResult); + + /** + * Get assertion results. + * @return assertion results. + */ + public TreeMap getAssertionResultList(); + + /** + * Get the assertion result for a specific test assertion. + * @param assertionId test assertion id. + * @return the assertion result for the specified test assertion ID. + * If an assertion result was not found, then null is returned. + */ + public AssertionResult getAssertionResult(String assertionId); +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/FailureDetail.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/FailureDetail.java new file mode 100644 index 000000000..f786a73e5 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/FailureDetail.java @@ -0,0 +1,94 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.report; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.document.DocumentElement; +import org.eclipse.wst.wsi.internal.xml.dom.ElementLocation; + +import javax.xml.namespace.QName; + +/** + * Failure detail. + * + * @author Peter Brittenham (peterbr@us.ibm.com) + * @version 1.0.1 + */ +public interface FailureDetail extends DocumentElement +{ + /** + * Element name. + */ + public static final String ELEM_NAME = WSIConstants.ELEM_FAILURE_DETAIL; + + /** + * QName. + */ + public static final QName QNAME = + new QName(WSIConstants.NS_URI_WSI_REPORT, ELEM_NAME); + + /** + * Get failure detail message. + * @return failure detail message. + * @see #setFailureMessage + */ + public String getFailureMessage(); + + /** + * Set failure detail message. + * @param failureMessage failure detail message. + * @see #getFailureMessage + */ + public void setFailureMessage(String failureMessage); + + /** + * Get reference type. + * @return reference type. + * @see #setReferenceType + */ + public String getReferenceType(); + + /** + * Set reference type. + * @param referenceType reference type. + * @see #getReferenceType + */ + public void setReferenceType(String referenceType); + + /** + * Get reference ID. + * @return reference ID. + * @see #setReferenceIDn + */ + public String getReferenceID(); + + /** + * Set reference ID. + * @param referenceID reference ID. + * @see #getReferenceID + */ + public void setReferenceIDn(String referenceID); + + /** + * Get element location. + * @return element location. + * @see #setElementLocation + */ + public ElementLocation getElementLocation(); + + /** + * Set element location. + * @param elementLocation element location. + * @see #getElementLocation + */ + public void setElementLocation(ElementLocation elementLocation); + +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/PrereqFailedList.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/PrereqFailedList.java new file mode 100644 index 000000000..d0aeb3535 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/PrereqFailedList.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.report; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.document.DocumentElement; + +import javax.xml.namespace.QName; + +/** + * This interface is used to maintain and access the Prerequisite Failed List. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public interface PrereqFailedList extends DocumentElement +{ + /** + * Element name. + */ + public static final String ELEM_NAME = WSIConstants.ELEM_PREREQ_FAILED_LIST; + + /** + * QName. + */ + public static final QName QNAME = + new QName(WSIConstants.NS_URI_WSI_REPORT, ELEM_NAME); + + /** + * Add test assertion ID. + * @param assertionID test assertion ID. + */ + public void addTestAssertionID(String assertionID); + +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/Report.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/Report.java new file mode 100644 index 000000000..f657843fc --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/Report.java @@ -0,0 +1,105 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.report; + +import java.util.List; + +import javax.xml.namespace.QName; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.document.WSIDocument; + +/** + * Conformance test report. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public interface Report extends WSIDocument, BuildReport +{ + /** + * Element name. + */ + public static final String ELEM_NAME = WSIConstants.ELEM_REPORT; + + /** + * QName. + */ + public static final QName QNAME = + new QName(WSIConstants.NS_URI_WSI_REPORT, ELEM_NAME); + + /** + * Get report context. + * @return report context. + * @see #setReportContext + */ + public ReportContext getReportContext(); + + /** + * Set report context. + * @param reportContext report context. + * @see #getReportContext + */ + public void setReportContext(ReportContext reportContext); + + /** + * Get current artifact. + * @return current artifact. + */ + public ReportArtifact getCurrentArtifact(); + + /** + * Get current entry. + * @return current entry. + */ + public Entry getCurrentEntry(); + + /** + * Method getEntries. + * @return entry list. + */ + public List getEntries(); + + /** + * Method getArtifacts. + * @return artifacts. + */ + public List getArtifacts(); + + /** + * Get start element string. + * @param namespaceName namespace prefix + * @return start element string. + */ + public String getStartXMLString(String namespaceName); + + /** + * Get end element string. + * @param namespaceName namespace prefix + * @return end element string. + */ + public String getEndXMLString(String namespaceName); + + /** + * Get error XML string. + * @param namespaceName namespace prefix. + * @param errorDetail an error detail. + * @return error XML string. + */ + public String getErrorXMLString(String namespaceName, String errorDetail); + + /** + * Get summary result. + * @return summary result. + */ + public String getSummaryResult(); + +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/ReportArtifact.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/ReportArtifact.java new file mode 100644 index 000000000..87f5b233e --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/ReportArtifact.java @@ -0,0 +1,79 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.report; + +import java.util.TreeMap; + +import javax.xml.namespace.QName; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.document.DocumentElement; +import org.eclipse.wst.wsi.internal.util.ArtifactType; + +/** + * Report artifact. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public interface ReportArtifact extends DocumentElement +{ + /** + * Element name. + */ + public static final String ELEM_NAME = WSIConstants.ELEM_ARTIFACT; + + /** + * QName. + */ + public static final QName QNAME = + new QName(WSIConstants.NS_URI_WSI_REPORT, ELEM_NAME); + + /** + * Get artifact type. + * @return artifact type. + * @see #setType + */ + public ArtifactType getType(); + + /** + * Set artifact type. + * @param artifactType artifact type. + * @see #getType + */ + public void setType(ArtifactType artifactType); + + /** + * Add entry. + * @param entry an entry. + */ + public void addEntry(Entry entry); + + /** + * Get entry list. + * @return entry list. + */ + public TreeMap getEntryList(); + + /** + * Get start element string. + * @param namespaceName namespace prefix. + * @return start element string. + */ + public String getStartXMLString(String namespaceName); + + /** + * Get end element string. + * @param namespaceName namespace prefix. + * @return end element string. + */ + public String getEndXMLString(String namespaceName); +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/ReportContext.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/ReportContext.java new file mode 100644 index 000000000..9a424ea5c --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/ReportContext.java @@ -0,0 +1,116 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.report; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.analyzer.Analyzer; +import org.eclipse.wst.wsi.internal.profile.ProfileAssertions; + +/** + * Report context. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public class ReportContext +{ + /** + * Report title. + */ + protected String reportTitle = WSIConstants.DEFAULT_REPORT_TITLE; + + /** + * Profile definition. + */ + protected ProfileAssertions profileAssertions; + + /** + * Analyzer. + */ + protected Analyzer analyzer; + + /** + * Create report context. + * @param reportTitle report title. + * @param profileAssertions profile test assertions. + * @param analyzer an Analyzer object. + */ + public ReportContext( + String reportTitle, + ProfileAssertions profileAssertions, + Analyzer analyzer) + { + this.reportTitle = reportTitle; + this.profileAssertions = profileAssertions; + this.analyzer = analyzer; + } + + /** + * Get report title. + * @return report title. + * @see #setReportTitle + */ + public String getReportTitle() + { + return this.reportTitle; + } + + /** + * Set report title. + * @param reportTitle report title. + * @see #getReportTitle + */ + public void setReportTitle(String reportTitle) + { + this.reportTitle = reportTitle; + } + + /** + * Get profile definition. + * @return profile definition. + * @see #setProfileAssertions + */ + public ProfileAssertions getProfileAssertions() + { + return this.profileAssertions; + } + + /** + * Set profile definition. + * @param profileAssertions profile definition. + * @see #getProfileAssertions + */ + public void setProfileAssertions(ProfileAssertions profileAssertions) + { + this.profileAssertions = profileAssertions; + } + + /** + * Get analyzer. + * @return analyzer. + * @see #setAnalyzer + */ + public Analyzer getAnalyzer() + { + return this.analyzer; + } + + /** + * Set analyzer. + * @param analyzer an Analyzer object. + * @see #getAnalyzer + * + */ + public void setAnalyzer(Analyzer analyzer) + { + this.analyzer = analyzer; + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/ReportWriter.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/ReportWriter.java new file mode 100644 index 000000000..d12c2c4f0 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/ReportWriter.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.report; + +import java.io.Writer; + +import org.eclipse.wst.wsi.internal.document.DocumentWriter; + +/** + * Defines the interface used to write the report documents. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public interface ReportWriter extends DocumentWriter +{ + /** + * Write the entire contents of the document using the location + * that was previously set using the setLocation method. + * @param report a report. + * @throws IllegalStateException if this operation has been invoked + * at an illegal or inappropriate time + */ + public void write(Report report) throws IllegalStateException; + + /** + * Write the entire contents of the document. + * @param report a report. + * @param writer a Writer object. + */ + public void write(Report report, Writer writer); +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/Reporter.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/Reporter.java new file mode 100644 index 000000000..c79cd5a39 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/Reporter.java @@ -0,0 +1,21 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.report; + +/** + * Conformance test reporter interface. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public interface Reporter extends BuildReport, WriteReport +{ +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/WriteReport.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/WriteReport.java new file mode 100644 index 000000000..476dd6510 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/WriteReport.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.report; + +import org.eclipse.wst.wsi.internal.WSIException; + +/** + * This class .. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public interface WriteReport +{ + /** + * Start conformance report. + * @throws WSIException the base WS-I exception. + */ + public void startReport() throws WSIException; + + /** + * Finish the conformance report by adding the summary and test coverage information. + * @throws WSIException the base WS-I exception. + */ + public void finishReport() throws WSIException; + + /** + * Finish the conformance report because of an analyzer error. + * @param errorDetail analyzer error. + * @throws WSIException the base WS-I exception. + */ + public void finishReportWithError(String errorDetail) throws WSIException; + + /** + * Get report. + * @return report. + */ + public Report getReport(); +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/impl/ArtifactReferenceImpl.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/impl/ArtifactReferenceImpl.java new file mode 100644 index 000000000..aba07001f --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/impl/ArtifactReferenceImpl.java @@ -0,0 +1,124 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.report.impl; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.document.DocumentElement; +import org.eclipse.wst.wsi.internal.report.ArtifactReference; + +import java.io.*; + +/** + * An artifact reference. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public class ArtifactReferenceImpl implements ArtifactReference +{ + /** + * Timestamp. + */ + protected String timestamp = null; + + /** + * Optional document element. + */ + protected DocumentElement documentElement = null; + + /** + * Optional document element namespace name. + */ + protected String elementNamespaceName = null; + + /* (non-Javadoc) + * @see org.wsi.test.report.ArtifactReference#getTimestamp() + */ + public String getTimestamp() + { + return this.timestamp; + } + + /* (non-Javadoc) + * @see org.wsi.test.report.ArtifactReference#setTimestamp(String) + */ + public void setTimestamp(String timestamp) + { + this.timestamp = timestamp; + } + + /* (non-Javadoc) + * @see org.wsi.test.report.ArtifactReference#getDocumentElement() + */ + public DocumentElement getDocumentElement() + { + return this.documentElement; + } + + /* (non-Javadoc) + * @see org.wsi.test.report.ArtifactReference#setDocumentElement(DocumentElement, String) + */ + public void setDocumentElement( + DocumentElement documentElement, + String namespaceName) + { + this.documentElement = documentElement; + this.elementNamespaceName = namespaceName; + } + + /* (non-Javadoc) + * Get string representation of this object. + */ + public String toString() + { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + + pw.println(" Artifact Reference: "); + pw.println(" timestamp ........... " + this.timestamp); + + if (this.documentElement != null) + pw.println( + " documentElement ..... " + + this.documentElement.toXMLString(this.elementNamespaceName)); + + return sw.toString(); + } + + /* (non-Javadoc) + * @see org.wsi.test.document.DocumentElement#toXMLString(String) + */ + public String toXMLString(String namespaceName) + { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + + String nsName = namespaceName; + if ((!nsName.equals("") && (!nsName.endsWith(":")))) + nsName += ":"; + + // Create element + pw.print(" <" + nsName + ELEM_NAME + " "); + pw.println(WSIConstants.ATTR_TIMESTAMP + "=\"" + getTimestamp() + "\">"); + + // If there is a document element, then add it + if (this.documentElement != null) + { + pw.print(documentElement.toXMLString(this.elementNamespaceName)); + } + + // End element + pw.println(" "); + + return sw.toString(); + } + +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/impl/AssertionResultImpl.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/impl/AssertionResultImpl.java new file mode 100644 index 000000000..af54b046b --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/impl/AssertionResultImpl.java @@ -0,0 +1,236 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.report.impl; + +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.Iterator; +import java.util.Vector; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.analyzer.config.AssertionResultsOption; +import org.eclipse.wst.wsi.internal.analyzer.config.impl.AssertionResultsOptionImpl; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.report.Entry; +import org.eclipse.wst.wsi.internal.report.FailureDetail; +import org.eclipse.wst.wsi.internal.report.PrereqFailedList; + +import com.ibm.wsdl.util.xml.DOMUtils; + +/** + * Test assertion result. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public class AssertionResultImpl implements AssertionResult +{ + /** + * Assertion result. + */ + protected String result = null; + + /** + * Entry. + */ + protected Entry entry = null; + + /** + * Profile test assertion. + */ + protected TestAssertion testAssertion = null; + + /** + * Failure detail messages. + */ + protected Vector failureDetailList = null; + + /** + * Assertion results option. + */ + protected AssertionResultsOption assertionResultsOption = + new AssertionResultsOptionImpl(); + + /** + * Prereq failed list. + */ + protected PrereqFailedList prereqFailedList = null; + + /** + * Create a new assertion result. + */ + public AssertionResultImpl() + { + } + + /* (non-Javadoc) + * @see org.wsi.test.report.AssertionResult#getResult() + */ + public String getResult() + { + return this.result; + } + + /* (non-Javadoc) + * @see org.wsi.test.report.AssertionResult#setResult(java.lang.String) + */ + public void setResult(String result) + { + this.result = result; + } + + /* (non-Javadoc) + * @see org.wsi.test.report.AssertionResult#getAssertion() + */ + public TestAssertion getAssertion() + { + return this.testAssertion; + } + + /* (non-Javadoc) + * @see org.wsi.test.report.AssertionResult#setAssertion(org.wsi.test.profile.TestAssertion) + */ + public void setAssertion(TestAssertion testAssertion) + { + this.testAssertion = testAssertion; + } + + /* (non-Javadoc) + * @see org.wsi.test.report.AssertionResult#getEntry() + */ + public Entry getEntry() + { + return this.entry; + } + + /* (non-Javadoc) + * @see org.wsi.test.report.AssertionResult#setEntry(org.wsi.test.report.Entry) + */ + public void setEntry(Entry entry) + { + this.entry = entry; + } + + /* (non-Javadoc) + * @see org.wsi.test.report.AssertionResult#getFailureDetailList() + */ + public Vector getFailureDetailList() + { + return this.failureDetailList; + } + + /* (non-Javadoc) + * @see org.wsi.test.report.AssertionResult#setFailureDetailList(java.util.Vector) + */ + public void setFailureDetailList(Vector failureDetailList) + { + this.failureDetailList = failureDetailList; + } + + /* (non-Javadoc) + * @see org.wsi.test.report.AssertionResult#getAssertionResultsOption() + */ + public AssertionResultsOption getAssertionResultsOption() + { + return this.assertionResultsOption; + } + + /* (non-Javadoc) + * @see org.wsi.test.report.AssertionResult#setAssertionResultsOption(org.wsi.test.analyzer.config.AssertionResultsOption) + */ + public void setAssertionResultsOption(AssertionResultsOption assertionResultsOption) + { + this.assertionResultsOption = assertionResultsOption; + } + + /* (non-Javadoc) + * @see org.wsi.test.report.AssertionResult#getPrereqFailedList() + */ + public PrereqFailedList getPrereqFailedList() + { + return this.prereqFailedList; + } + + /* (non-Javadoc) + * @see org.wsi.test.report.AssertionResult#setPrereqFailedList(org.wsi.test.report.PrereqFailedList) + */ + public void setPrereqFailedList(PrereqFailedList prereqFailedList) + { + this.prereqFailedList = prereqFailedList; + } + + /* (non-Javadoc) + * @see org.wsi.test.document.DocumentElement#toXMLString(java.lang.String) + */ + public String toXMLString(String namespaceName) + { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + + String nsName = namespaceName; + if ((!nsName.equals("") && (!nsName.endsWith(":")))) + nsName += ":"; + + // Create element + pw.print(" <" + nsName + ELEM_NAME + " "); + pw.print(WSIConstants.ATTR_ID + "=\"" + this.testAssertion.getId() + "\" "); + pw.println(WSIConstants.ATTR_RESULT + "=\"" + this.result + "\">"); + + // ADD: Add support for additional targets + + // Add prereq failed list + if (this.prereqFailedList != null) + { + pw.print(prereqFailedList.toXMLString(nsName)); + } + + // ADD: Add support for multiple languages + // If result is failed or warning, then add failure message + if ((result.equals(RESULT_FAILED) || result.equals(RESULT_WARNING)) + && (assertionResultsOption.getShowFailureMessage())) + { + pw.print( + " <" + + nsName + + WSIConstants.ELEM_FAILURE_MESSAGE + + " xml:lang=\"en\">"); + pw.print(DOMUtils.cleanString(this.testAssertion.getFailureMessage())); + pw.println(""); + } + + // ADD: Add support for multiple languages + // If any failure detail messages were specified, then add them + if ((failureDetailList != null) + && (assertionResultsOption.getShowFailureDetail())) + { + Iterator iterator = failureDetailList.iterator(); + while (iterator.hasNext()) + { + pw.print(((FailureDetail) iterator.next()).toXMLString(nsName)); + } + } + + // End the element + pw.println(" "); + + // Return string + return sw.toString(); + } + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + public String toString() + { + return result; + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/impl/DefaultReporter.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/impl/DefaultReporter.java new file mode 100644 index 000000000..64a6678f0 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/impl/DefaultReporter.java @@ -0,0 +1,287 @@ +/******************************************************************************* + * Copyright (c) 2002-2003 IBM Corporation, Parasoft and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + * Parasoft - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.report.impl; + +import java.io.StringReader; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.analyzer.config.AnalyzerConfig; +import org.eclipse.wst.wsi.internal.analyzer.config.AssertionResultType; +import org.eclipse.wst.wsi.internal.profile.TestAssertion; +import org.eclipse.wst.wsi.internal.report.ArtifactReference; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.report.Entry; +import org.eclipse.wst.wsi.internal.report.EntryContainer; +import org.eclipse.wst.wsi.internal.report.FailureDetail; +import org.eclipse.wst.wsi.internal.report.Report; +import org.eclipse.wst.wsi.internal.report.ReportArtifact; +import org.eclipse.wst.wsi.internal.report.ReportWriter; +import org.eclipse.wst.wsi.internal.report.Reporter; + +/** + * Base class for reporting errors from the analyzer. + * Extend this class for specific types of reporting, such as reporting + * in different formats, reporting to files, reporting to a GUI. + * + * @version 1.0.1 + * @author Jim Clune + * @author Peter Brittenham + */ +public class DefaultReporter implements Reporter +{ + /** + * Conformance report. + */ + protected Report report; + + /** + * Document writer. + */ + protected ReportWriter reportWriter; + + /** + * Analyzer config. + */ + protected AnalyzerConfig analyzerConfig; + + /** + * Assertoin result type. + */ + protected AssertionResultType assertionResultType; + + /** + * Do not allow the reporter to be created with null constructor. + */ + private DefaultReporter() + { + } + + /** + * Create result reporter. + * @param report a Report object. + * @param reportWriter a ReportWriterObject. + */ + public DefaultReporter(Report report, ReportWriter reportWriter) + { + this.report = report; + this.reportWriter = reportWriter; + + // ADD: Verify that writer set in reportWriter + + // Get report context + this.analyzerConfig = + report.getReportContext().getAnalyzer().getAnalyzerConfig(); + this.assertionResultType = + this.analyzerConfig.getAssertionResultsOption().getAssertionResultType(); + } + + /* (non-Javadoc) + * @see org.wsi.test.report.BuildReport#setCurrentArtifact(org.wsi.test.report.ReportArtifact) + */ + public void setCurrentArtifact(ReportArtifact reportArtifact) + throws WSIException + { + report.setCurrentArtifact(reportArtifact); + reportWriter.write(new StringReader(reportArtifact.getStartXMLString(""))); + } + + /* (non-Javadoc) + * @see org.wsi.test.report.BuildReport#endCurrentArtifact() + */ + public void endCurrentArtifact() throws WSIException + { + reportWriter.write( + new StringReader(report.getCurrentArtifact().getEndXMLString(""))); + report.endCurrentArtifact(); + } + + /* (non-Javadoc) + * @see org.wsi.test.report.BuildReport#addArtifactReference(org.wsi.test.report.ArtifactReference) + */ + public void addArtifactReference(ArtifactReference artifactReference) + throws WSIException + { + reportWriter.write(new StringReader(artifactReference.toXMLString(""))); + + // Add artifact reference to report + report.addArtifactReference(artifactReference); + } + + /* (non-Javadoc) + * @see org.wsi.test.report.BuildReport#setCurrentEntry(org.wsi.test.report.Entry) + */ + public void setCurrentEntry(Entry entry) throws WSIException + { + report.setCurrentEntry(entry); + reportWriter.write( + new StringReader( + entry.getStartXMLString( + "", + this + .report + .getReportContext() + .getAnalyzer() + .getAnalyzerConfig() + .getAssertionResultsOption() + .getShowMessageEntry()))); + } + + /* (non-Javadoc) + * @see org.wsi.test.report.BuildReport#setCurrentEntry(org.wsi.test.report.Entry) + */ + public void setCurrentEnvelopeEntry(Entry entry) throws WSIException + { + report.setCurrentEntry(entry); + reportWriter.write( + new StringReader( + entry.getStartXMLString( + "", + this + .report + .getReportContext() + .getAnalyzer() + .getAnalyzerConfig() + .getAssertionResultsOption() + .getShowMessageEntry(), + true))); + } +/* (non-Javadoc) + * @see org.wsi.test.report.BuildReport#endCurrentEntry() + */ + public void endCurrentEntry() throws WSIException + { + reportWriter.write( + new StringReader(report.getCurrentEntry().getEndXMLString(""))); + report.endCurrentEntry(); + } + + /* (non-Javadoc) + * @see org.wsi.test.report.BuildReport#addAssertionResult(org.wsi.test.report.AssertionResult) + */ + public void addAssertionResult(AssertionResult assertionResult) + throws WSIException + { + // Based on the config options, write out assertion result + if ((assertionResultType.isAll()) + || ((assertionResultType.isFailedOnly()) + && (assertionResult.getResult().equals(AssertionResult.RESULT_FAILED))) + || ((assertionResultType.isNotPassed()) + && (!assertionResult.getResult().equals(AssertionResult.RESULT_PASSED))) + || ((assertionResultType.isNotInfo()) + && (!assertionResult.getAssertion().getType().equals(TestAssertion.TYPE_INFORMATIONAL)))) + { + reportWriter.write(new StringReader(assertionResult.toXMLString(""))); + } + + // Add assertion to report + report.addAssertionResult(assertionResult); + } + + /* (non-Javadoc) + * @see org.wsi.test.report.BuildReport#getAssertionResult(java.lang.String) + */ + public AssertionResult getAssertionResult(String assertionId) + { + // Get the assertion result from the current assertion target + return report.getAssertionResult(assertionId); + } + + /* (non-Javadoc) + * @see org.wsi.test.report.WriteReport#startReport() + */ + public void startReport() throws WSIException + { + // Write out start of report + reportWriter.write(new StringReader(report.getStartXMLString(""))); + } + + /* (non-Javadoc) + * @see org.wsi.test.report.WriteReport#finishReport() + */ + public void finishReport() throws WSIException + { + // End the report file + reportWriter.write(new StringReader(report.getEndXMLString(""))); + } + + /* (non-Javadoc) + * @see org.wsi.test.report.WriteReport#finishReportWithError(java.lang.String) + */ + public void finishReportWithError(String errorDetail) throws WSIException + { + // Check if entry or artifact need to be closed + if (this.report.getCurrentEntry() != null) + endCurrentEntry(); + if (this.report.getCurrentArtifact() != null) + endCurrentArtifact(); + + // End the report file + reportWriter.write( + new StringReader(report.getErrorXMLString("", errorDetail))); + } + + /* (non-Javadoc) + * @see org.wsi.test.report.BuildReport#createAssertionResult() + */ + public AssertionResult createAssertionResult() + { + return report.createAssertionResult(); + } + + /* (non-Javadoc) + * @see org.wsi.test.report.BuildReport#createArtifact() + */ + public ReportArtifact createArtifact() + { + return report.createArtifact(); + } + + /* (non-Javadoc) + * @see org.wsi.test.report.BuildReport#createEntry() + */ + public Entry createEntry() + { + return report.createEntry(); + } + + /* (non-Javadoc) + * @see org.wsi.test.report.BuildReport#createEntryContainer() + */ + public EntryContainer createEntryContainer() + { + return report.createEntryContainer(); + } + + /* (non-Javadoc) + * @see org.wsi.test.report.BuildReport#createFailureDetail() + */ + public FailureDetail createFailureDetail() + { + return report.createFailureDetail(); + } + + /* (non-Javadoc) + * @see org.wsi.test.report.WriteReport#getReport() + */ + public Report getReport() + { + return this.report; + } + + /* (non-Javadoc) + * @see org.wsi.test.report.BuildReport#setPrereqType(java.lang.String) + */ + public void setPrereqType(String prereqType) + { + this.report.setPrereqType(prereqType); + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/impl/EntryContainerImpl.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/impl/EntryContainerImpl.java new file mode 100644 index 000000000..79d08c1c4 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/impl/EntryContainerImpl.java @@ -0,0 +1,56 @@ +/******************************************************************************* + * Copyright (c) 2002-2003 IBM Corporation, Parasoft and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + * Parasoft - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.report.impl; + +import org.eclipse.wst.wsi.internal.report.EntryContainer; + +/** + * This class represents a container for one or more entries. + * An example would be a WSDL document. + * + * @author Peter Brittenham (peterbr@us.ibm.com) + * @version 1.0.1 + */ +public class EntryContainerImpl + extends EntryResultImpl + implements EntryContainer +{ + /** + * Container ID. + */ + protected String id; + + /* (non-Javadoc) + * @see org.wsi.test.report.EntryContainer#getId() + */ + public String getId() + { + return this.id; + } + + /* (non-Javadoc) + * @see org.wsi.test.report.EntryContainer#setId(String) + */ + public void setId(String id) + { + this.id = id; + } + + /** + * Return string representation of this object. + */ + public String toString() + { + return "[" + this.id + "] " + this.assertionResultList; + } + +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/impl/EntryImpl.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/impl/EntryImpl.java new file mode 100644 index 000000000..671c6de47 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/impl/EntryImpl.java @@ -0,0 +1,276 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.report.impl; + +import java.io.PrintWriter; +import java.io.StringWriter; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.log.MessageEntry; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.report.Entry; +import org.eclipse.wst.wsi.internal.report.EntryContainer; +import org.eclipse.wst.wsi.internal.util.EntryType; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; + +/** + * This class represents an entry in a report. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public class EntryImpl extends EntryResultImpl implements Entry +{ + /** + * Entry type. + */ + protected EntryType entryType = null; + + /** + * Artifact name (optional). + */ + protected String artifactName = null; + + /** + * Reference ID. + */ + protected String referenceID = null; + + /** + * Parent element name (only used when entry type is "port" or "operation"). + */ + protected String parentElementName = null; + + /** + * Entry detail object. + */ + protected Object entryDetail = null; + + /** + * Entry container. + */ + protected EntryContainer entryContainer = null; + + /* (non-Javadoc) + * @see org.wsi.test.report.Entry#getEntryType() + */ + public EntryType getEntryType() + { + return this.entryType; + } + + /* (non-Javadoc) + * @see org.wsi.test.report.Entry#setEntryType(EntryType) + */ + public void setEntryType(EntryType entryType) + { + this.entryType = entryType; + } + + /* (non-Javadoc) + * @see org.wsi.test.report.Entry#getArtifactName() + */ + public String getArtifactName() + { + return this.artifactName; + } + + /* (non-Javadoc) + * @see org.wsi.test.report.Entry#setArtifactName(java.lang.String) + */ + public void setArtifactName(String artifactName) + { + this.artifactName = artifactName; + } + + /* (non-Javadoc) + * @see org.wsi.test.report.Entry#getReferenceID() + */ + public String getReferenceID() + { + return this.referenceID; + } + + /* (non-Javadoc) + * @see org.wsi.test.report.Entry#setReferenceID(String) + */ + public void setReferenceID(String referenceID) + { + this.referenceID = referenceID; + } + + /* (non-Javadoc) + * @see org.wsi.test.report.Entry#getParentElementName() + */ + public String getParentElementName() + { + return this.parentElementName; + } + + /* (non-Javadoc) + * @see org.wsi.test.report.Entry#setParentElementName(String) + */ + public void setParentElementName(String parentElementName) + { + this.parentElementName = parentElementName; + } + + /* (non-Javadoc) + * @see org.wsi.test.report.Entry#getEntryDetail() + */ + public Object getEntryDetail() + { + return this.entryDetail; + } + + /* (non-Javadoc) + * @see org.wsi.test.report.Entry#setEntryDetail(Object) + */ + public void setEntryDetail(Object entryDetail) + { + this.entryDetail = entryDetail; + } + + /* (non-Javadoc) + * @see org.wsi.test.report.Entry#getEntryContainer() + */ + public EntryContainer getEntryContainer() + { + return this.entryContainer; + } + + /* (non-Javadoc) + * @see org.wsi.test.report.Entry#setEntryContainer(org.wsi.test.report.EntryContainer) + */ + public void setEntryContainer(EntryContainer entryContainer) + { + this.entryContainer = entryContainer; + } + + /* (non-Javadoc) + * @see org.wsi.test.report.EntryResult#addAssertionResult(AssertionResult) + */ + public void addAssertionResult(AssertionResult assertionResult) + { + super.addAssertionResult(assertionResult); + + if (this.entryContainer != null) + this.entryContainer.addAssertionResult(assertionResult); + } + + /* (non-Javadoc) + * @see org.wsi.test.report.Entry#getStartXMLString(String) + */ + public String getStartXMLString(String namespaceName, boolean showLogEntry, boolean envelopeArtifactType) + { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + + String nsName = namespaceName; + if ((!nsName.equals("") && (!nsName.endsWith(":")))) + nsName += ":"; + + // Create element + pw.print(" <" + nsName + ELEM_NAME + " "); + + if (this.entryType != null) + { + if (envelopeArtifactType) + { + // we use the same actual entry for both message and envelope artifacts + // we now need to output entry type names that actually pertain to the artifact type + pw.print( + WSIConstants.ATTR_TYPE + "=\"" + getCorrespondingEnvelopeEntryTypeName(this.entryType.getTypeName()) + "\" "); + } + else + { + pw.print( + WSIConstants.ATTR_TYPE + "=\"" + this.entryType.getTypeName() + "\" "); + } + } + + else if (this.artifactName != null) + { + pw.print(WSIConstants.ATTR_TYPE + "=\"[" + this.artifactName + "]\" "); + } + + if (this.referenceID != null) + pw.print( + WSIConstants.ATTR_REFERENCE_ID + "=\"" + XMLUtils.xmlEscapedString(this.referenceID) + "\""); + + // If service name was set then add it + //if (parentElementName != null) { + // pw.print(" " + WSIConstants.ATTR_PARENT_ELEMENT_NAME + "=\"" + this.parentElementName + "\""); + //} + + // End element + pw.println(">"); + + // ADD: Need to check for config option that specifies + // that log entries should be added + + // If target is a log entry, then add reference to it + if ((entryType != null) + && (entryType.getArtifactType().isMessages()) + && (showLogEntry)) + { + MessageEntry logEntry = (MessageEntry) entryDetail; + pw.println(logEntry.toXMLString(WSIConstants.NS_NAME_WSI_LOG)); + } + + return sw.toString(); + } + + /* (non-Javadoc) + * @see org.wsi.test.report.Entry#getStartXMLString(String) + */ + public String getStartXMLString(String namespaceName, boolean showLogEntry) + { + return getStartXMLString(namespaceName, showLogEntry, false); + } + + /* (non-Javadoc) + * @see org.wsi.test.report.Entry#getEndXMLString(String) + */ + public String getEndXMLString(String namespaceName) + { + String nsName = namespaceName; + if ((!nsName.equals("") && (!nsName.endsWith(":")))) + nsName += ":"; + + return " "; + } + + /* (non-Javadoc) + * @see org.wsi.test.document.DocumentElement#toXMLString(String) + */ + public String toXMLString(String namespaceName) + { + // Return string + return getStartXMLString("", false) + getEndXMLString(""); + } + + public String getCorrespondingEnvelopeEntryTypeName(String messageEntryTypeName) + { + String envelopeEntryTypeName = messageEntryTypeName; + if (messageEntryTypeName != null) + { + if (messageEntryTypeName.equals(EntryType.TYPE_MESSAGE_ANY)) + envelopeEntryTypeName = EntryType.TYPE_ENVELOPE_ANY; + else if (messageEntryTypeName.equals(EntryType.TYPE_MESSAGE_REQUEST)) + envelopeEntryTypeName = EntryType.TYPE_ENVELOPE_REQUEST; + else if (messageEntryTypeName.equals(EntryType.TYPE_MESSAGE_RESPONSE)) + envelopeEntryTypeName = EntryType.TYPE_ENVELOPE_RESPONSE; + } + + return envelopeEntryTypeName; + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/impl/EntryResultImpl.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/impl/EntryResultImpl.java new file mode 100644 index 000000000..56f872fb8 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/impl/EntryResultImpl.java @@ -0,0 +1,56 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.report.impl; + +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.report.EntryResult; + +import java.util.TreeMap; + +/** + * Result for a specific test assertion. + * + * @author Peter Brittenham (peterbr@us.ibm.com) + * @version 1.0.1 + */ +public abstract class EntryResultImpl implements EntryResult +{ + /** + * Assertion result list. + */ + protected TreeMap assertionResultList = new TreeMap(); + + /* (non-Javadoc) + * @see org.wsi.test.report.EntryResult#addAssertionResult(org.wsi.test.report.AssertionResult) + */ + public void addAssertionResult(AssertionResult assertionResult) + { + this.assertionResultList.put( + assertionResult.getAssertion().getId(), + assertionResult); + } + + /* (non-Javadoc) + * @see org.wsi.test.report.EntryResult#getAssertionResultList() + */ + public TreeMap getAssertionResultList() + { + return assertionResultList; + } + + /* (non-Javadoc) + * @see org.wsi.test.report.EntryResult#getAssertionResult(String) + */ + public AssertionResult getAssertionResult(String assertionId) + { + return (AssertionResult) assertionResultList.get(assertionId); + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/impl/FailureDetailImpl.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/impl/FailureDetailImpl.java new file mode 100644 index 000000000..b2e8f55b1 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/impl/FailureDetailImpl.java @@ -0,0 +1,150 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.report.impl; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.report.FailureDetail; +import org.eclipse.wst.wsi.internal.xml.dom.ElementLocation; + +import com.ibm.wsdl.util.xml.DOMUtils; + +import java.io.*; + +/** + * This class will ... + * + * @author Peter Brittenham (peterbr@us.ibm.com) + * @version 1.0.1 + */ +public class FailureDetailImpl implements FailureDetail +{ + protected String failureMessage = null; + protected String referenceType = null; + protected String referenceID = null; + protected ElementLocation elementLocation = null; + + /* (non-Javadoc) + * @see org.wsi.test.report.FailureDetail#getFailureMessage() + */ + public String getFailureMessage() + { + return this.failureMessage; + } + + /* (non-Javadoc) + * @see org.wsi.test.report.FailureDetail#setFailureMessage(String) + */ + public void setFailureMessage(String failureMessage) + { + this.failureMessage = failureMessage; + } + + /* (non-Javadoc) + * @see org.wsi.test.report.FailureDetail#getReferenceType() + */ + public String getReferenceType() + { + return this.referenceType; + } + + /* (non-Javadoc) + * @see org.wsi.test.report.FailureDetail#setReferenceType(String) + */ + public void setReferenceType(String referenceType) + { + this.referenceType = referenceType; + } + + /* (non-Javadoc) + * @see org.wsi.test.report.FailureDetail#getReferenceID() + */ + public String getReferenceID() + { + return this.referenceID; + } + + /* (non-Javadoc) + * @see org.wsi.test.report.FailureDetail#setReferenceIDn(String) + */ + public void setReferenceIDn(String referenceID) + { + this.referenceID = referenceID; + } + + /* (non-Javadoc) + * @see org.wsi.test.report.FailureDetail#getElementLocation() + */ + public ElementLocation getElementLocation() + { + return this.elementLocation; + } + + /* (non-Javadoc) + * @see org.wsi.test.report.FailureDetail#setElementLocation(ElementLocation) + */ + public void setElementLocation(ElementLocation elementLocation) + { + this.elementLocation = elementLocation; + } + + /* (non-Javadoc) + * @see org.wsi.test.document.DocumentElement#toXMLString(String) + */ + public String toXMLString(String namespaceName) + { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + + String nsName = namespaceName; + if ((!nsName.equals("") && (!nsName.endsWith(":")))) + nsName += ":"; + + // Create element + pw.print(" <" + nsName + ELEM_NAME + " xml:lang=\"en\" "); + + if (this.referenceType != null) + pw.print( + WSIConstants.ATTR_REFERENCE_TYPE + "=\"" + this.referenceType + "\" "); + + if (this.referenceID != null) + pw.print( + WSIConstants.ATTR_REFERENCE_ID + "=\"" + this.referenceID + "\" "); + + // ADD: Need to use a different namespace + /* + if (this.elementLocation != null) { + String nsNameExt = "reportext"; + pw.print("xmlns:" + nsNameExt + "=\"" + WSIConstants.NS_URI_WSI_REPORT + "/ext/\""); + pw.print(nsNameExt + ":" + WSIConstants.ATTR_LINE_NUMBER + "=\"" + this.elementLocation.getLineNumber() + "\" "); + pw.print(nsNameExt + ":" + WSIConstants.ATTR_COLUMN_NUMBER + "=\"" + this.elementLocation.getColumnNumber() + "\" "); + } + */ + + // Close start element + pw.print(">"); + + if (this.failureMessage != null) + pw.println(DOMUtils.cleanString(this.failureMessage)); + + if (this.elementLocation != null) + { + pw.println(" "); + pw.print(this.elementLocation.toString()); + } + + // End the element + pw.println(" "); + + // Return string + return sw.toString(); + } + +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/impl/PrereqFailedListImpl.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/impl/PrereqFailedListImpl.java new file mode 100644 index 000000000..9f98b0de1 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/impl/PrereqFailedListImpl.java @@ -0,0 +1,74 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.report.impl; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.report.PrereqFailedList; + +import java.io.*; +import java.util.*; + +/** + * This interface is used to maintain and access the Prerequisite Failed List. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public class PrereqFailedListImpl implements PrereqFailedList +{ + /** + * List of test assertion IDs. + */ + protected Vector idList = new Vector(); + + /* (non-Javadoc) + * @see org.wsi.test.report.PrereqFailedList#addTestAssertionID(java.lang.String) + */ + public void addTestAssertionID(String assertionID) + { + idList.add(assertionID); + } + + /* (non-Javadoc) + * @see org.wsi.test.document.DocumentElement#toXMLString(String) + */ + public String toXMLString(String namespaceName) + { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + + String nsName = namespaceName; + if ((!nsName.equals("") && (!nsName.endsWith(":")))) + nsName += ":"; + + if (this.idList.size() > 0) + { + // Create element + pw.println(" <" + nsName + ELEM_NAME + ">"); + + // Include each test assertion ID + Iterator iterator = idList.iterator(); + while (iterator.hasNext()) + { + pw.print( + " <" + nsName + WSIConstants.ELEM_TEST_ASSERTION_ID + ">"); + pw.print((String) iterator.next()); + pw.println(""); + } + + // End element + pw.println(" "); + } + + return sw.toString(); + } + +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/impl/ReportArtifactImpl.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/impl/ReportArtifactImpl.java new file mode 100644 index 000000000..f63e1620f --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/impl/ReportArtifactImpl.java @@ -0,0 +1,115 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.report.impl; + +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.TreeMap; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.report.Entry; +import org.eclipse.wst.wsi.internal.report.ReportArtifact; +import org.eclipse.wst.wsi.internal.util.ArtifactType; + +/** + * This class contains a report artifact. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public class ReportArtifactImpl implements ReportArtifact +{ + /** + * Artifact type. + */ + protected ArtifactType artifactType = null; + + /** + * Entries. + */ + protected TreeMap entryList = new TreeMap(); + + /* (non-Javadoc) + * @see org.wsi.test.report.ReportArtifact#getType() + */ + public ArtifactType getType() + { + return this.artifactType; + } + + /* (non-Javadoc) + * @see org.wsi.test.report.ReportArtifact#setType(ArtifactType) + */ + public void setType(ArtifactType artifactType) + { + this.artifactType = artifactType; + } + + /* (non-Javadoc) + * @see org.wsi.test.report.ReportArtifact#addEntry(Entry) + */ + public void addEntry(Entry entry) + { + // Add entry + if (entry.getEntryType() != null) + this.entryList.put(entry.getEntryType().getTypeName(), entry); + } + + /* (non-Javadoc) + * @see org.wsi.test.report.ReportArtifact#getEntryList() + */ + public TreeMap getEntryList() + { + return this.entryList; + } + + /* (non-Javadoc) + * @see org.wsi.test.report.ReportArtifact#getStartXMLString(String) + */ + public String getStartXMLString(String namespaceName) + { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + + String nsName = namespaceName; + if ((!nsName.equals("") && (!nsName.endsWith(":")))) + nsName += ":"; + + // Create element + pw.print(" <" + nsName + ELEM_NAME + " "); + pw.print( + WSIConstants.ATTR_TYPE + "=\"" + this.artifactType.getTypeName() + "\">"); + + return sw.toString(); + } + + /* (non-Javadoc) + * @see org.wsi.test.report.ReportArtifact#getEndXMLString(String) + */ + public String getEndXMLString(String namespaceName) + { + String nsName = namespaceName; + if ((!nsName.equals("") && (!nsName.endsWith(":")))) + nsName += ":"; + + return " "; + } + + /* (non-Javadoc) + * @see org.wsi.test.document.DocumentElement#toXMLString(String) + */ + public String toXMLString(String namespaceName) + { + // Return string + return getStartXMLString("") + getEndXMLString(""); + } + +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/impl/ReportImpl.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/impl/ReportImpl.java new file mode 100644 index 000000000..66c4dc19c --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/impl/ReportImpl.java @@ -0,0 +1,514 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.report.impl; + +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.List; +import java.util.Vector; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.log.Log; +import org.eclipse.wst.wsi.internal.report.ArtifactReference; +import org.eclipse.wst.wsi.internal.report.AssertionResult; +import org.eclipse.wst.wsi.internal.report.Entry; +import org.eclipse.wst.wsi.internal.report.EntryContainer; +import org.eclipse.wst.wsi.internal.report.FailureDetail; +import org.eclipse.wst.wsi.internal.report.Report; +import org.eclipse.wst.wsi.internal.report.ReportArtifact; +import org.eclipse.wst.wsi.internal.report.ReportContext; +import org.eclipse.wst.wsi.internal.util.TestUtils; +import org.eclipse.wst.wsi.internal.util.Utils; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; + +/** + * WS-I conformance test report. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public class ReportImpl implements Report +{ + /** + * Report filename. + */ + protected String filename = null; + + /** + * Report context. + */ + protected ReportContext reportContext = null; + + /** + * Log file. + */ + protected Log log = null; + + /** + * Summary all passed flag. + */ + protected boolean allPassed = true; + + /** + * Test coverage. + */ + //protected TestCoverage testCoverage; + + /** + * Artifact list. + */ + protected Vector artifactList = new Vector(); + + /** + * Entry list. + */ + protected Vector entryList = new Vector(); + + /** + * Current artifact. + */ + protected ReportArtifact currentArtifact = null; + + /** + * Current entry. + */ + protected Entry currentEntry = null; + + /** + * Prereq type. + */ + protected String prereqType; + + /** + * Create a new conformance report. + */ + public ReportImpl() + { + } + + /* (non-Javadoc) + * @see org.wsi.test.document.WSIDocument#getLocation() + */ + public String getLocation() + { + // Get report URI + //return reportURI; + return this.filename; + } + + /* (non-Javadoc) + * @see org.wsi.test.document.WSIDocument#setLocation(java.lang.String) + */ + public void setLocation(String reportURI) + { + this.filename = reportURI; + } + + /* (non-Javadoc) + * @see org.wsi.test.report.Report#getReportContext() + */ + public ReportContext getReportContext() + { + return this.reportContext; + } + + /* (non-Javadoc) + * @see org.wsi.test.report.Report#setReportContext(org.wsi.test.report.ReportContext) + */ + public void setReportContext(ReportContext reportContext) + { + // Save input references + this.reportContext = reportContext; + } + + /* (non-Javadoc) + * @see org.wsi.test.report.Report#getCurrentArtifact() + */ + public ReportArtifact getCurrentArtifact() + { + // Return artifact + return this.currentArtifact; + } + + /* (non-Javadoc) + * @see org.wsi.test.report.BuildReport#setCurrentArtifact(org.wsi.test.report.ReportArtifact) + */ + public void setCurrentArtifact(ReportArtifact artifact) throws WSIException + { + // Save reference to artifact + artifactList.add(artifact); + + // Set as current artifact + this.currentArtifact = artifact; + + // Set default prereq processing + this.prereqType = PREREQ_TYPE_ENTRY; + } + + /* (non-Javadoc) + * @see org.wsi.test.report.BuildReport#endCurrentArtifact() + */ + public void endCurrentArtifact() throws WSIException + { + // Remove current artifact + this.currentArtifact = null; + } + + /* (non-Javadoc) + * @see org.wsi.test.report.BuildReport#addArtifactReference(org.wsi.test.report.ArtifactReference) + */ + public void addArtifactReference(ArtifactReference artifactReference) + throws WSIException + { + // ADD: How should this be saved? Should it be added to the current artifact? + } + + /* (non-Javadoc) + * @see org.wsi.test.report.Report#getCurrentEntry() + */ + public Entry getCurrentEntry() + { + // Return entry + return this.currentEntry; + } + /* (non-Javadoc) + * @see org.wsi.test.report.Report#getCurrentEntry() + */ + public void setCurrentEnvelopeEntry(Entry entry) throws WSIException + { + + } + + /* (non-Javadoc) + * @see org.wsi.test.report.BuildReport#setCurrentEntry(org.wsi.test.report.Entry) + */ + public void setCurrentEntry(Entry entry) throws WSIException + { + // Save reference to entry + entryList.add(entry); + + // Set as current entry + this.currentEntry = entry; + } + + /** + * Method getEntries. + * @return entry list. + */ + public List getEntries() + { + return entryList; + } + + /** + * Method getArtifacts. + * @return artifacts. + */ + public List getArtifacts() + { + return artifactList; + } + + /* (non-Javadoc) + * @see org.wsi.test.report.BuildReport#endCurrentEntry() + */ + public void endCurrentEntry() throws WSIException + { + // Remove current entry + this.currentEntry = null; + } + + /* (non-Javadoc) + * @see org.wsi.test.report.BuildReport#addAssertionResult(org.wsi.test.report.AssertionResult) + */ + public void addAssertionResult(AssertionResult assertionResult) + { + // ADD: Need to keep just a summary + + // Add result to current entry + if (currentEntry != null) + { + currentEntry.addAssertionResult(assertionResult); + } + + // If the result was not passed, then set summary flag + if (assertionResult.getResult().equals(AssertionResult.RESULT_FAILED)) + { + allPassed = false; + } + } + + /* (non-Javadoc) + * @see org.wsi.test.report.BuildReport#getAssertionResult(java.lang.String) + */ + public AssertionResult getAssertionResult(String assertionId) + { + AssertionResult result = null; + + // Determine where to get the assertion result from + if (this.prereqType.equals(PREREQ_TYPE_ENTRY)) + result = currentEntry.getAssertionResult(assertionId); + else + result = currentEntry.getEntryContainer().getAssertionResult(assertionId); + + // the assertion result is not found at the current entry, going through all the entries + if (result == null) + { + for (int i = 0; i < entryList.size(); i ++) + { + Entry entry = (Entry) entryList.get(i); + if ((result = entry.getAssertionResult(assertionId)) != null) + break; + } + } + return result; + } + + /* (non-Javadoc) + * @see org.wsi.test.report.BuildReport#createAssertionResult() + */ + public AssertionResult createAssertionResult() + { + AssertionResult assertionResult = new AssertionResultImpl(); + assertionResult.setAssertionResultsOption( + reportContext + .getAnalyzer() + .getAnalyzerConfig() + .getAssertionResultsOption()); + return assertionResult; + } + + /* (non-Javadoc) + * @see org.wsi.test.report.BuildReport#createEntry() + */ + public Entry createEntry() + { + Entry entry = new EntryImpl(); + //entry.setAssertionResultsOption(reportContext.getAnalyzer().getAnalyzerConfig().getAssertionResultsOption()); + return entry; + } + + /* (non-Javadoc) + * @see org.wsi.test.report.BuildReport#createEntryContainer() + */ + public EntryContainer createEntryContainer() + { + EntryContainer entryContainer = new EntryContainerImpl(); + return entryContainer; + } + + /* (non-Javadoc) + * @see org.wsi.test.report.BuildReport#createArtifact() + */ + public ReportArtifact createArtifact() + { + ReportArtifact reportArtifact = new ReportArtifactImpl(); + return reportArtifact; + } + + /* (non-Javadoc) + * @see org.wsi.test.report.BuildReport#createFailureDetail() + */ + public FailureDetail createFailureDetail() + { + FailureDetail failureDetail = new FailureDetailImpl(); + return failureDetail; + } + + /* (non-Javadoc) + * @see org.wsi.test.report.Report#getSummaryResult() + */ + public String getSummaryResult() + { + return ( + allPassed + ? AssertionResult.RESULT_PASSED + : AssertionResult.RESULT_FAILED); + } + + /* (non-Javadoc) + * @see org.wsi.test.report.BuildReport#setPrereqType(java.lang.String) + */ + public void setPrereqType(String prereqType) + { + this.prereqType = prereqType; + } + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + public String toString() + { + // ADD: + return "Report: "; + } + + /* (non-Javadoc) + * @see org.wsi.test.report.Report#getStartXMLString(java.lang.String) + */ + public String getStartXMLString(String namespaceName) + { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + + String nsName = namespaceName; + if ((!nsName.equals("") && (!nsName.endsWith(":")))) + nsName += ":"; + + // Create report element + pw.println(WSIConstants.XML_DECL); + pw.println( + reportContext + .getAnalyzer() + .getAnalyzerConfig() + .getAddStyleSheet() + .getStyleSheetString()); + + // Add XML comment + String comment; + if ((comment = TestUtils.getXMLComment()) != null) + pw.print(comment); + + // report + pw.print( + "<" + + nsName + + ELEM_NAME + + " " + + WSIConstants.ATTR_NAME + + "=\"" + + reportContext.getReportTitle() + + "\""); + pw.println( + " " + + WSIConstants.ATTR_TIMESTAMP + + "=\"" + + Utils.getTimestamp() + + "\""); + pw.println(" xmlns=\"" + WSIConstants.NS_URI_WSI_REPORT + "\""); + pw.println( + " xmlns:" + + WSIConstants.NS_NAME_WSI_REPORT + + "=\"" + + WSIConstants.NS_URI_WSI_REPORT + + "\""); + pw.println( + " xmlns:" + + WSIConstants.NS_NAME_WSI_LOG + + "=\"" + + WSIConstants.NS_URI_WSI_LOG + + "\""); + //pw.println(" xmlns:" + WSIConstants.NS_NAME_WSI_COMMON + "=\"" + WSIConstants.NS_URI_WSI_COMMON + "\""); + pw.println( + " xmlns:" + + WSIConstants.NS_NAME_WSI_ANALYZER_CONFIG + + "=\"" + + WSIConstants.NS_URI_WSI_ANALYZER_CONFIG + + "\""); + pw.println( + " xmlns:" + + WSIConstants.NS_NAME_WSI_MONITOR_CONFIG + + "=\"" + + WSIConstants.NS_URI_WSI_MONITOR_CONFIG + + "\""); + pw.println( + " xmlns:" + + WSIConstants.NS_NAME_WSI_ASSERTIONS + + "=\"" + + WSIConstants.NS_URI_WSI_ASSERTIONS + + "\""); + pw.println( + " xmlns:" + + WSIConstants.NS_NAME_XSI + + "=\"" + + WSIConstants.NS_URI_XSI + + "\">"); + + // Add analyzer tool info + pw.print(reportContext.getAnalyzer().toXMLString(nsName)); + + // Return XML string + return sw.toString(); + } + + /* (non-Javadoc) + * @see org.wsi.test.report.Report#getEndXMLString(java.lang.String) + */ + public String getEndXMLString(String namespaceName) + { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + + String nsName = namespaceName; + if ((!nsName.equals("") && (!nsName.endsWith(":")))) + nsName += ":"; + + // Build summary + pw.print(" <" + nsName + WSIConstants.ELEM_SUMMARY + " "); + pw.println(WSIConstants.ATTR_RESULT + "=\"" + getSummaryResult() + "\">"); + + // ADD: Detail summary + /* + pw.print(" <" + nsName + WSIConstants.ELEM_ARTIFACT_SUMMARY + " "); + pw.println(WSIConstants.ATTR_RESULT + "=\"xxxx\">"); + + pw.println(" "); + */ + + // End element + pw.println(" "); + + // End report element + pw.println(""); + + // Return XML string + return sw.toString(); + } + + /* (non-Javadoc) + * @see org.wsi.test.report.Report#getErrorXMLString(java.lang.String, java.lang.String) + */ + public String getErrorXMLString(String namespaceName, String errorDetail) + { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + + String nsName = namespaceName; + if ((!nsName.equals("") && (!nsName.endsWith(":")))) + nsName += ":"; + + // Build analyzer failure + pw.println(" <" + nsName + WSIConstants.ELEM_ANALYZER_FAILURE + ">"); + + // Add error detail + pw.print(" <" + nsName + WSIConstants.ELEM_FAILURE_DETAIL + ">"); + pw.print(XMLUtils.xmlEscapedString(errorDetail)); + pw.println(" "); + + // End report element + pw.println(""); + + // End report element + pw.println(""); + + // Return XML string + return sw.toString(); + } + + /* (non-Javadoc) + * @see org.wsi.test.document.DocumentElement#toXMLString(java.lang.String) + */ + public String toXMLString(String namespaceName) + { + return getStartXMLString(namespaceName) + getEndXMLString(namespaceName); + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/impl/ReportNoWriterImpl.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/impl/ReportNoWriterImpl.java new file mode 100644 index 000000000..38a3fd734 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/impl/ReportNoWriterImpl.java @@ -0,0 +1,84 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.report.impl; + +import java.io.IOException; +import java.io.Reader; +import java.io.Writer; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.report.Report; +import org.w3c.dom.Document; + +/** + * WS-I conformance test ReportWriter for wsi plugin. + * This ReportWriter writes nothing so no report file will be created. + */ +public class ReportNoWriterImpl implements org.eclipse.wst.wsi.internal.report.ReportWriter +{ + + /** + * @see java.lang.Object#Object() + */ + public ReportNoWriterImpl() + { + } + + /* (non-Javadoc) + * @see org.wsi.test.document.DocumentWriter#getDocument() + */ + public Document getDocument() throws UnsupportedOperationException + { + throw new UnsupportedOperationException(); + } + + /* (non-Javadoc) + * @see org.wsi.test.document.DocumentWriter#setWriter(String) + */ + public void setWriter(String documentLocation) throws IOException + { + } + + /* (non-Javadoc) + * @see org.wsi.test.document.DocumentWriter#write(Reader) + */ + public void write(Reader reader) throws WSIException, IllegalStateException + { + } + + /* (non-Javadoc) + * @see org.wsi.test.document.DocumentWriter#write(Reader, Writer) + */ + public void write(Reader reader, Writer writer) throws WSIException + { + } + + /* (non-Javadoc) + * @see org.wsi.test.report.ReportWriter#write(Report) + */ + public void write(Report report) throws IllegalStateException + { + } + + /* (non-Javadoc) + * @see org.wsi.test.report.ReportWriter#write(Report, Writer) + */ + public void write(Report report, Writer writer) + { + } + + /* (non-Javadoc) + * @see org.wsi.test.document.DocumentWriter#close() + */ + public void close() throws WSIException, IllegalStateException + { + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/impl/ReportWriterImpl.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/impl/ReportWriterImpl.java new file mode 100644 index 000000000..7a054bc90 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/report/impl/ReportWriterImpl.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.report.impl; + +import java.io.PrintWriter; +import java.io.Writer; + +import org.eclipse.wst.wsi.internal.document.impl.DocumentWriterImpl; +import org.eclipse.wst.wsi.internal.report.Report; +import org.eclipse.wst.wsi.internal.report.ReportWriter; + +/** + * Defines the interface used to write the Conformance XML documents. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public class ReportWriterImpl + extends DocumentWriterImpl + implements ReportWriter +{ + /** + * Report writer. + */ + public ReportWriterImpl() + { + } + + /** + * Write the entire contents of the document using the writer + * that was previously set using the setWriter method. + */ + public void write(Report report) throws IllegalStateException + { + // If writer was not set previously, then throw exception + if (writer == null) + { + throw new IllegalStateException("Report writer must be set before writing report."); + } + + // Write report + write(report, this.writer); + } + + /** + * Write the entire contents of the document. + */ + public void write(Report report, Writer writer) + { + // Create print writer + PrintWriter printWriter = new PrintWriter(writer); + + // ADD: Write out complete report + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/toolinfo.properties b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/toolinfo.properties new file mode 100644 index 000000000..6751d3a8c --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/toolinfo.properties @@ -0,0 +1,18 @@ +# /** +# * +# * +# * Copyright (c) 2002-2003 IBM Corporation and others. +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * IBM - Initial API and implementation +# * +# */ + +wsi.tool.version=1.1 +wsi.tool.release.date=2004-11-30 +wsi.tool.implementer=Eclipse.org Organization +wsi.tool.location=http://www.eclipse.org/wsvt diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/ArtifactType.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/ArtifactType.java new file mode 100644 index 000000000..9ef56826a --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/ArtifactType.java @@ -0,0 +1,140 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.util; + +/** + * This class ... + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public class ArtifactType +{ + /** + * This type. + */ + private String type; + + /** + * ReportArtifact types. + */ + public static final String TYPE_ENVELOPE = "envelope"; + public static final String TYPE_MESSAGE = "message"; + public static final String TYPE_DESCRIPTION = "description"; + public static final String TYPE_DISCOVERY = "discovery"; + + /** + * ReportArtifact types. + */ + public static final ArtifactType ARTIFACT_TYPE_ENVELOPE = + new ArtifactType(TYPE_ENVELOPE); + public static final ArtifactType ARTIFACT_TYPE_MESSAGE = + new ArtifactType(TYPE_MESSAGE); + public static final ArtifactType ARTIFACT_TYPE_DESCRIPTION = + new ArtifactType(TYPE_DESCRIPTION); + public static final ArtifactType ARTIFACT_TYPE_DISCOVERY = + new ArtifactType(TYPE_DISCOVERY); + + /** + * Create artifact type. + */ + private ArtifactType(String type) + { + this.type = type; + } + + /** + * Is artifact type envelope. + * @return true if artifact type envelope. + */ + public boolean isEnvelope() + { + return type.equals(TYPE_ENVELOPE); + } + + /** + * Is artifact type messages. + * @return true if artifact type messages. + */ + public boolean isMessages() + { + return type.equals(TYPE_MESSAGE); + } + + /** + * Is artifact type description. + * @return true if artifact type description. + */ + public boolean isDescription() + { + return type.equals(TYPE_DESCRIPTION); + } + + /** + * Is artifact type discovery. + * @return true if artifact type discovery. + */ + public boolean isDiscovery() + { + return type.equals(TYPE_DISCOVERY); + } + + /** + * Get artifact type. + * @return artifact type. + */ + public String getTypeName() + { + return type; + } + + /** + * Create artifact type. + * @param typeName artifact type name. + * @return newly created artifact type. + * @throws RuntimeException if artifact type name is invalid or inappropriate. + */ + public static final ArtifactType newArtifactType(String typeName) + throws RuntimeException + { + ArtifactType artifactType = null; + + if (typeName.equals(TYPE_DESCRIPTION)) + { + artifactType = ARTIFACT_TYPE_DESCRIPTION; + } + + else if (typeName.equals(TYPE_MESSAGE)) + { + artifactType = ARTIFACT_TYPE_MESSAGE; + } + + else if (typeName.equals(TYPE_ENVELOPE)) + { + artifactType = ARTIFACT_TYPE_ENVELOPE; + } + + else if (typeName.equals(TYPE_DISCOVERY)) + { + artifactType = ARTIFACT_TYPE_DISCOVERY; + } + + else + { + throw new RuntimeException( + "Could not create new artifact type using invalid type name: " + + typeName + + "."); + } + + return artifactType; + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/BasicRules.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/BasicRules.java new file mode 100644 index 000000000..44167fb3f --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/BasicRules.java @@ -0,0 +1,479 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.util; + +/** + * This class validates basic constructs of RFC 2616. + * + * @author Volodin + */ +public class BasicRules +{ + + public static final char CR = 13; + public static final char LF = 10; + public static final char SP = 32; + public static final char HT = 9; + public static final char DQ = 34; + public static final String CRLF = "" + CR + LF; + + public static final char[] SEPARATORS = + { + '(', + ')', + '<', + '>', + '@', + ',', + ';', + ':', + '\\', + '\"', + '/', + '[', + ']', + '?', + '=', + '{', + '}', + SP, + HT }; + + /** + * Checking rule. + * OCTET = <any 8-bit sequence of data> + * @param ch character. + * @return boolean true if ch is conform to rule, false otherwise. + */ + public static boolean isOCTET(char ch) + { + return true; + } + + /** + * Checking rule: + * CHAR = <any US-ASCII character (octets 0 - 127)>. + * @param ch character. + * @return boolean true if ch is conform to rule, false otherwise. + */ + public static boolean isCHAR(char ch) + { + return (ch >= 0 && ch <= 127) ? true : false; + } + + /** + * Checking rule: + * UPALPHA = <any US-ASCII uppercase letter "A".."Z">. + * @param ch character. + * @return boolean true if ch is conform to rule, false otherwise. + */ + public static boolean isUPALPHA(char ch) + { + return (ch >= 'A' && ch <= 'Z') ? true : false; + } + + /** + * Checking rule: + * LOALPHA = <any US-ASCII lowercase letter "a".."z">. + * @param ch character. + * @return boolean true if ch is conform to rule, false otherwise. + */ + public static boolean isLOALPHA(char ch) + { + return (ch >= 'a' && ch <= 'z') ? true : false; + } + + /** + * Checking rule: + * ALPHA = UPALPHA | LOALPHA. + * @param ch character. + * @return boolean true if ch is conform to rule, false otherwise. + */ + public static boolean isALPHA(char ch) + { + return (isLOALPHA(ch) || isUPALPHA(ch)) ? true : false; + } + + /** + * Checking rule: + * DIGIT = <any US-ASCII digit "0".."9">. + * @param ch character. + * @return boolean true if ch is conform to rule, false otherwise. + */ + public static boolean isDIGIT(char ch) + { + return (ch >= '0' && ch <= '9') ? true : false; + } + + /** + * Checking rule: + * CTL = <any US-ASCII control character (octets 0 - 31) and DEL (127)>. + * @param ch character. + * @return boolean true if ch is conform to rule, false otherwise. + */ + public static boolean isCTL(char ch) + { + return ((ch >= 0 && ch <= 31) || ch == 127) ? true : false; + } + + /** + * Checking rule: + * CR = <US-ASCII CR, carriage return (13)>. + * @param ch character. + * @return boolean true if ch is conform to rule, false otherwise. + */ + public static boolean isCR(char ch) + { + return (ch == CR) ? true : false; + } + + /** + * Checking rule: + * LF = <US-ASCII LF, linefeed (10)>. + * @param ch character + * @return boolean true if ch is conform to rule, false otherwise + */ + public static boolean isLF(char ch) + { + return (ch == LF) ? true : false; + } + + /** + * Checking rule: + * SP = <US-ASCII SP, space (32)>. + * @param ch character. + * @return boolean true if ch is conform to rule, false otherwise. + */ + public static boolean isSP(char ch) + { + return (ch == SP) ? true : false; + } + + /** + * Checking rule: + * HT = <US-ASCII HT, horizontal-tab (9)>. + * @param ch character + * @return boolean true if ch is conform to rule, false otherwise + */ + public static boolean isHT(char ch) + { + return (ch == HT) ? true : false; + } + + /** + * Checking rule: + * <"> = <US-ASCII double-quote mark (34)>. + * @param ch character. + * @return boolean true if ch is conform to rule, false otherwise. + */ + public static boolean isDoubleQuote(char ch) + { + return (ch == DQ) ? true : false; + } + + /** + * Checking rule: + * CRLF = CR LF. + * @param str string. + * @return boolean true if ch is conform to rule, false otherwise. + */ + public static boolean isCRLF(String str) + { + return CRLF.equals(str); + } + + /** + * Checking rule: + * LWS = [CRLF] 1*( SP | HT ). + * @param str string. + * @return boolean true if str is conform to rule, false otherwise. + */ + public static boolean isLWS(String str) + { + + int index = getLastIndexLWS(str, 0); + if (index == -1 || index != str.length()) + return false; + + return true; + } + + /** + * Gets last index of the LWS string. + * @param str string. + * @param startIndex start index. + * @return int an index of the first symbol which isn't LWS. + */ + public static int getLastIndexLWS(String str, int startIndex) + { + int index = str.indexOf(CRLF, startIndex); + if (index == -1) + index = startIndex; + else if (index == startIndex) + index += CRLF.length(); + else + return -1; + + if (!isSP(str.charAt(index)) && isHT(str.charAt(index))) + return -1; + + index++; + for (; index < str.length(); index++) + if (!isSP(str.charAt(index)) && isHT(str.charAt(index))) + return index; + return index; + } + + /** + * Gets last index of the TEXT string. + * TEXT = <any OCTET except CTLs, but including LWS> + * @param str string. + * @param startIndex start index. + * @return int an index of the first symbol which isn't TEXT. + */ + public static int getLastTEXT(String str, int startIndex) + { + int index; + for (index = startIndex; index < str.length(); index++) + { + if (!isOCTET(str.charAt(index))) + return index; + if (isCTL(str.charAt(index))) + { + int lastLWS = getLastIndexLWS(str, index); + if (lastLWS == -1) + return index; + index = lastLWS - 1; + } + } + return index; + } + + /** + * Checking rule: + * HEX = "A" | "B" | "C" | "D" | "E" | "F" | "a" | "b" | "c" | "d" | "e" | "f" | DIGIT. + * @param ch character. + * @return boolean true if ch is conform to rule, false otherwise. + */ + public static boolean isHEX(char ch) + { + return ( + (ch >= 'A' && ch <= 'F') || (ch >= 'a' && ch <= 'f') || isDIGIT(ch)) + ? true + : false; + } + + /** + * Checking rule: + * token = 1*<any CHAR except CTLs or separators>. + * @param str string. + * @return boolean true if str is conform to rule, false otherwise. + */ + public static boolean isToken(String str) + { + if (str.length() == 0) + return false; + + for (int index = 0; index < str.length(); index++) + { + char ch = str.charAt(index); + if (!isCHAR(ch) || isSEPARATOR(ch) || isCTL(ch)) + return false; + + } + + return true; + } + + /** + * Gets last index of the "token" string. + * @param str string. + * @param startIndex start index. + * @return int an index of the first symbol which isn't "token". + */ + public static int getLastToken(String str, int startIndex) + { + int index = startIndex; + for (; index < str.length(); index++) + { + char ch = str.charAt(index); + if (!isCHAR(ch) || isSEPARATOR(ch) || isCTL(ch)) + return index; + + } + return index; + } + + /** + * Checking rule: + * separators = "(" | ")" | "<" | ">" | "@" + * | "," | ";" | ":" | "\" | <"> + * | "/" | "[" | "]" | "?" | "=" + * | "{" | "}" | SP | HT. + * @param ch character. + * @return boolean true if ch is conform to rule, false otherwise. + */ + public static boolean isSEPARATOR(char ch) + { + for (int index = 0; index < SEPARATORS.length; index++) + { + if (ch == SEPARATORS[index]) + return true; + } + return false; + } + + /** + * Gets last index of the "comment" string. + * comment = "(" *( ctext | quoted-pair | comment ) ")". + * @param str string. + * @param startIndex start index. + * @return int an index of the first symbol which isn't "comment". + */ + public static int getLastComment(String str, int startIndex) + { + + int index = startIndex; + if (str.length() <= startIndex) + return startIndex; + if (str.charAt(index) != '(') + return startIndex; + + boolean bExit = false; + boolean bQuotedPair = false; + int idx = startIndex + 1; + while (bExit == false) + { + while (bQuotedPair == false) + { + idx = getLastCtext(str, idx); + if (idx == str.length()) + return idx; + if (!isQuotedPair(str, idx - 1)) + bQuotedPair = true; + else + idx++; + } + if (str.charAt(idx) == '(') + { + int idxNew = getLastComment(str, idx); + } + else if (str.charAt(idx) == ')') + { + return idx + 1; + } + } + + return idx; + } + + /** + * Gets last index of the "ctext" string. + * ctext = <any TEXT excluding "(" and ")"> + * @param str string. + * @param startIndex start index. + * @return int an index of the first symbol which isn't "ctext". + */ + private static int getLastCtext(String str, int startIndex) + { + int idx = getLastTEXT(str, startIndex); + int iBracket = startIndex; + for (; iBracket < idx; iBracket++) + { + if (str.charAt(iBracket) == '(' || str.charAt(iBracket) == ')') + break; + } + if (iBracket < idx) + idx = iBracket; + return idx; + } + + /** + * Gets last index of the "qdtext" string. + * qdtext = <any TEXT except <">> + * @param str string. + * @param startIndex start index. + * @return int an index of the first symbol which isn't "qdtext". + */ + private static int getLastQdtext(String str, int startIndex) + { + int idx = getLastTEXT(str, startIndex); + int iBracket = startIndex; + for (; iBracket < idx; iBracket++) + { + if (str.charAt(iBracket) == '\"') + break; + } + if (iBracket < idx) + idx = iBracket; + return idx; + } + + /** + * Checking rule: + * quoted-pair = "\" CHAR. + * @param str string. + * @param startIndex start index. + * @return boolean true if str is conform to rule, false otherwise. + */ + public static boolean isQuotedPair(String str, int startIndex) + { + if (str.length() >= startIndex + 2 + && str.charAt(startIndex) == '\\' + && isCHAR(str.charAt(startIndex + 1))) + return true; + else + return false; + } + + /** + * Gets last index of the "quoted-string" string. + * quoted-string = ( <"> *(qdtext | quoted-pair ) <"> ) + * @param str string. + * @param startIndex start index. + * @return int an index of the first symbol which isn't "quoted-string". + */ + public static int getLastQuotedString(String str, int startIndex) + { + + int index = startIndex; + int newIndex = 0; + + // if end if the string + if (startIndex == str.length()) + return startIndex; + // if the begin is not '"' + if (str.charAt(index) != DQ) + return startIndex; + + index++; + while (true) + { + index = getLastQdtext(str, index); + if (index == str.length()) + return startIndex; + if (isQuotedPair(str, index - 1)) + { + index++; + if (index == str.length()) + return startIndex; + } + else + break; + } + // if the end is not '"' + if (str.charAt(index) != DQ) + return startIndex; + + index++; + return index; + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/EntryType.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/EntryType.java new file mode 100644 index 000000000..b8fa09238 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/EntryType.java @@ -0,0 +1,278 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.util; + +import java.util.TreeMap; +import java.util.Vector; + +/** + * This class ... + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public class EntryType +{ + /** + * ReportArtifact type. + */ + private ArtifactType artifactType; + + /** + * This type. + */ + private String typeName; + + /** + * Entry types accessible by type name. + */ + protected static final TreeMap entryTypeMap = new TreeMap(); + + /** + * Entry type names accessible by artifact. + */ + protected static final TreeMap entryTypeNameMap = new TreeMap(); + static { + entryTypeNameMap.put(ArtifactType.TYPE_ENVELOPE, new Vector()); + entryTypeNameMap.put(ArtifactType.TYPE_MESSAGE, new Vector()); + entryTypeNameMap.put(ArtifactType.TYPE_DESCRIPTION, new Vector()); + entryTypeNameMap.put(ArtifactType.TYPE_DISCOVERY, new Vector()); + } + + /** + * Envelope entry types. + */ + public static final String TYPE_ENVELOPE_REQUEST = "requestEnvelope"; + public static final String TYPE_ENVELOPE_RESPONSE = "responseEnvelope"; + public static final String TYPE_ENVELOPE_ANY = "anyEnvelope"; + + /** + * Message entry types. + */ + public static final String TYPE_MESSAGE_REQUEST = "requestMessage"; + public static final String TYPE_MESSAGE_RESPONSE = "responseMessage"; + public static final String TYPE_MESSAGE_ANY = "anyMessage"; + + /** + * MIME entry types. + */ + public static final String TYPE_MIME_PART = "part"; + public static final String TYPE_MIME_ROOT_PART = "root-part"; + + /** + * Description entry types. + */ + public static final String TYPE_DESCRIPTION_DEFINITIONS = "definitions"; + public static final String TYPE_DESCRIPTION_IMPORT = "import"; + public static final String TYPE_DESCRIPTION_TYPES = "types"; + public static final String TYPE_DESCRIPTION_MESSAGE = "message"; + public static final String TYPE_DESCRIPTION_OPERATION = "operation"; + public static final String TYPE_DESCRIPTION_PORTTYPE = "portType"; + public static final String TYPE_DESCRIPTION_BINDING = "binding"; + public static final String TYPE_DESCRIPTION_PORT = "port"; + + /** + * Discovery entry types. + */ + public static final String TYPE_DISCOVERY_BINDINGTEMPLATE = "bindingTemplate"; + public static final String TYPE_DISCOVERY_TMODEL = "tModel"; + + /** + * Envelope entry types. + */ + public static final EntryType ENTRY_TYPE_REQUESTENV = + newEntryType(ArtifactType.ARTIFACT_TYPE_ENVELOPE, TYPE_ENVELOPE_REQUEST); + public static final EntryType ENTRY_TYPE_RESPONSEENV = + newEntryType(ArtifactType.ARTIFACT_TYPE_ENVELOPE, TYPE_ENVELOPE_RESPONSE); + + /** + * Message entry types. + */ + public static final EntryType ENTRY_TYPE_REQUEST = + newEntryType(ArtifactType.ARTIFACT_TYPE_MESSAGE, TYPE_MESSAGE_REQUEST); + public static final EntryType ENTRY_TYPE_RESPONSE = + newEntryType(ArtifactType.ARTIFACT_TYPE_MESSAGE, TYPE_MESSAGE_RESPONSE); + // public static final EntryType ENTRY_TYPE_ANYENTRY = + // new EntryType(ArtifactType.ARTIFACT_TYPE_MESSAGES, TYPE_MESSAGE_ANYENTRY); + + /** + * Description entry types. + */ + public static final EntryType ENTRY_TYPE_DEFINITIONS = + newEntryType( + ArtifactType.ARTIFACT_TYPE_DESCRIPTION, + TYPE_DESCRIPTION_DEFINITIONS); + public static final EntryType ENTRY_TYPE_IMPORT = + newEntryType( + ArtifactType.ARTIFACT_TYPE_DESCRIPTION, + TYPE_DESCRIPTION_IMPORT); + public static final EntryType ENTRY_TYPE_TYPES = + newEntryType( + ArtifactType.ARTIFACT_TYPE_DESCRIPTION, + TYPE_DESCRIPTION_TYPES); + public static final EntryType ENTRY_TYPE_MESSAGE = + newEntryType( + ArtifactType.ARTIFACT_TYPE_DESCRIPTION, + TYPE_DESCRIPTION_MESSAGE); + public static final EntryType ENTRY_TYPE_OPERATION = + newEntryType( + ArtifactType.ARTIFACT_TYPE_DESCRIPTION, + TYPE_DESCRIPTION_OPERATION); + public static final EntryType ENTRY_TYPE_PORTTYPE = + newEntryType( + ArtifactType.ARTIFACT_TYPE_DESCRIPTION, + TYPE_DESCRIPTION_PORTTYPE); + public static final EntryType ENTRY_TYPE_BINDING = + newEntryType( + ArtifactType.ARTIFACT_TYPE_DESCRIPTION, + TYPE_DESCRIPTION_BINDING); + public static final EntryType ENTRY_TYPE_PORT = + newEntryType(ArtifactType.ARTIFACT_TYPE_DESCRIPTION, TYPE_DESCRIPTION_PORT); + + /** + * Discovery entry types. + */ + public static final EntryType ENTRY_TYPE_BINDINGTEMPLATE = + newEntryType( + ArtifactType.ARTIFACT_TYPE_DISCOVERY, + TYPE_DISCOVERY_BINDINGTEMPLATE); + public static final EntryType ENTRY_TYPE_TMODEL = + newEntryType(ArtifactType.ARTIFACT_TYPE_DISCOVERY, TYPE_DISCOVERY_TMODEL); + + /** + * Create entry type. + */ + private EntryType(ArtifactType artifactType, String typeName) + { + this.artifactType = artifactType; + this.typeName = typeName; + } + + /** + * Is entry type equal to specified type. + * @param typeName entry type name. + * @return true if entry type equal to specified type. + */ + public boolean isType(String typeName) + { + return this.typeName.equals(typeName); + } + + /** + * Is entry type equal to specified type. + * @param entryType entry type. + * @return true if entry type equal to specified type. + */ + public boolean isType(EntryType entryType) + { + return typeName.equals(entryType.getTypeName()); + } + + /** + * Get artifact type. + * @return artifact type. + */ + public ArtifactType getArtifactType() + { + return artifactType; + } + + /** + * Get entry type name. + * @return entry type name. + */ + public String getTypeName() + { + return typeName; + } + + /** + * Is valid entry type. + * @param typeName entry type name. + * @return true if entry type name is valid. + */ + public static final boolean isValidEntryType(String typeName) + { + return (entryTypeMap.get(typeName) == null ? false : true); + } + + /** + * Create entry type. + * @param typeName entry type name. + * @return entry type. + * @throws RuntimeException if entry type name is invalid or inappropriate. + */ + public static final EntryType getEntryType(String typeName) + throws RuntimeException + { + // Get the entry type by type name + EntryType entryType = (EntryType) entryTypeMap.get(typeName); + + if (entryType == null) + { + throw new RuntimeException( + "Could not get entry type because type name is invalid: " + + typeName + + "."); + } + + return entryType; + } + + /** + * Get list of entry type names for a specified artifact type name. + * @param artifactTypeName artifact type name. + * @return list of entry type names for a specified artifact type name. + * @throws RuntimeException if entry type name is invalid or inappropriate. + */ + public static final Vector getEntryTypeNameList(String artifactTypeName) + throws RuntimeException + { + // Get list + Vector entryTypeNameList = (Vector) entryTypeNameMap.get(artifactTypeName); + + // If the list was not found, then throw an exception + if (entryTypeNameList == null) + { + throw new RuntimeException( + "Could not get entry type name list because artifact type name is invalid: " + + artifactTypeName + + "."); + } + + return entryTypeNameList; + } + + /** + * Get list of type names for a specified artifact type name. + */ + private static final EntryType newEntryType( + ArtifactType artifactType, + String typeName) + { + EntryType entryType = null; + + // Create entry type + entryType = new EntryType(artifactType, typeName); + + // Add to entry type map + entryTypeMap.put(typeName, entryType); + + // Get the entry type name vector for the artifact type + Vector entryTypeNameList = + (Vector) entryTypeNameMap.get(artifactType.getTypeName()); + + // Add the type name to the list + entryTypeNameList.add(typeName); + + return entryType; + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/ErrorList.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/ErrorList.java new file mode 100644 index 000000000..fb530ae7e --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/ErrorList.java @@ -0,0 +1,156 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.util; + +import java.text.FieldPosition; +import java.text.MessageFormat; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +import javax.xml.namespace.QName; + +/** + * The class accumulates all error strings into string buffer. + * + * @author Kulik + */ +public final class ErrorList +{ + private Set errors = new HashSet(); + private MessageFormat format = new MessageFormat("{0}:{1}"); + private FieldPosition pos = new FieldPosition(0); + + /** + * Default constructor. + * @see java.lang.Object#Object() + */ + public ErrorList() + { + } + + /** + * Construct error list using contents of a list. + * @param list a List object. + * @see java.lang.Object#Object() + */ + public ErrorList(List list) + { + add(list); + } + + /** + * Constructor with the specified message format. + * @param f a message format. + */ + public ErrorList(MessageFormat f) + { + if (f != null) + format = f; + } + + /** + * Add list. + * @param list list of errors. + */ + public void add(List list) + { + Iterator iterator = list.iterator(); + while (iterator.hasNext()) + { + add((String) iterator.next()); + } + } + + /** + * Adds error description into the list. + * @param s1 a string. + * @param s2 a string. + */ + public void add(String s1, String s2) + { + errors.add(new Pair(s1, s2)); + } + + /** + * Adds error description into the list. + * @param q a QName object. + * @param s a string. + */ + public void add(QName q, String s) + { + errors.add(new Pair(NullUtil.toString(q), s)); + } + + /** + * Adds error description into the list. + * @param q1 a QName object. + * @param q2 a string. + */ + public void add(QName q1, QName q2) + { + errors.add(new Pair(NullUtil.toString(q1), NullUtil.toString(q2))); + } + + /** + * Adds error description into the list... + * @param q a QName object. + */ + public void add(QName q) + { + errors.add(new Pair(NullUtil.toString(q), null)); + } + + /** + * Adds error description into the list. + * @param s a string. + */ + public void add(String s) + { + errors.add(new Pair(s, null)); + } + + /** + * Returns the error list string representation. + * @return the error list string representation. + * @see java.lang.Object#toString() + */ + public String toString() + { + StringBuffer buf = new StringBuffer(); + + Iterator it = errors.iterator(); + while (it.hasNext()) + { + Pair p = (Pair) it.next(); + if (p.getFirst() != null && p.getSecond() != null) + format.format(new Object[] { p.getFirst(), p.getSecond()}, buf, pos); + else if (p.getFirst() != null) + buf.append(p.getFirst()); + else + buf.append(p.getSecond()); + if (it.hasNext()) + buf.append(",\n"); + } + + return buf.toString(); + } + + /** + * Indicates whether error list is empty or not. + * @return true if error list is empty. + */ + public boolean isEmpty() + { + return errors.size() == 0; + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/HTTPConstants.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/HTTPConstants.java new file mode 100644 index 000000000..473ed1741 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/HTTPConstants.java @@ -0,0 +1,600 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.util; + +import java.util.Arrays; +import java.util.List; + +/** + * A set of HTTP values that are defined by Network Working Group. + * http://www.ietf.org/ + * + * @version 1.0 + * @author Ilya Kanonirov (kio@isg.axmor.com) + */ +public class HTTPConstants { + // The standardized HTTP Header field-names + // http://www.mnot.net/drafts/draft-nottingham-http-header-reg-00.txt + + // Hypertext Transfer Protocol -- HTTP/1.1 (obsoletes RFC2068) + public static final String HEADER_ACCEPT = "Accept"; + public static final String HEADER_ACCEPT_CHARSET = "Accept-Charset"; + public static final String HEADER_ACCEPT_ENCODING = "Accept-Encoding"; + public static final String HEADER_ACCEPT_LANGUAGE = "Accept-Language"; + public static final String HEADER_ACCEPT_RANGES = "Accept-Ranges"; + public static final String HEADER_AGE = "Age"; + public static final String HEADER_ALLOW = "Allow"; + public static final String HEADER_AUTHORIZATION = "Authorization"; + public static final String HEADER_CACHE_CONTROL = "Cache-Control"; + public static final String HEADER_CONNECT = "Connect"; + public static final String HEADER_CONTENT_ENCODING = "Content-Encoding"; + public static final String HEADER_CONTENT_LANGUAGE = "Content-Language"; + public static final String HEADER_CONTENT_LENGTH = "Content-Length"; + public static final String HEADER_CONTENT_LOCATION = "Content-Location"; + public static final String HEADER_CONTENT_MD5 = "Content-MD5"; + public static final String HEADER_CONTENT_RANGE = "Content-Range"; + public static final String HEADER_CONTENT_TYPE = "Content-Type"; + public static final String HEADER_DATE = "Date"; + public static final String HEADER_ETAG = "ETag"; + public static final String HEADER_EXPECT = "Expect"; + public static final String HEADER_EXPIRES = "Expires"; + public static final String HEADER_FROM = "From"; + public static final String HEADER_HOST = "Host"; + public static final String HEADER_IF_MATCH = "If-Match"; + public static final String HEADER_IF_MODIFIED_SINCE = "If-Modified-Since"; + public static final String HEADER_IF_NONE_MATCH = "If-None-Match"; + public static final String HEADER_IF_RANGE = "If-Range"; + public static final String HEADER_IF_UNMODIFIED_SINCE = "If-Unmodified-Since"; + public static final String HEADER_LAST_MODIFIED = "Last-Modified"; + public static final String HEADER_LOCATION = "Location"; + public static final String HEADER_MAX_FORWARDS = "Max-Forwards"; + public static final String HEADER_PRAGMA = "Pragma"; + public static final String HEADER_PROXY_AUTHENTICATE = "Proxy-Authenticate"; + public static final String HEADER_PROXY_AUTHORIZATION = "Proxy-Authorization"; + public static final String HEADER_RANGE = "Range"; + public static final String HEADER_REFERER = "Referer"; + public static final String HEADER_RETRY_AFTER = "Retry-After"; + public static final String HEADER_SERVER = "Server"; + public static final String HEADER_TE = "TE"; + public static final String HEADER_TRAILER = "Trailer"; + public static final String HEADER_TRANSFER_ENCODING = "Transfer-Encoding"; + public static final String HEADER_UPGRADE = "Upgrade"; + public static final String HEADER_USER_AGENT = "User-Agent"; + public static final String HEADER_VARY = "Vary"; + public static final String HEADER_VIA = "Via"; + public static final String HEADER_WARNING = "Warning"; + public static final String HEADER_WWW_AUTHENTICATE = "WWW-Authenticate"; + public static final String HEADER_MIME_VERSION = "MIME-Version"; + public static final String HEADER_CONTENT_DISPOSITION = "Content-Disposition"; + + // HTTP Authentication: Basic and Digest Access Authentication + public static final String HEADER_AUTHENTICATION_INFO = "Authentication-Info"; + + // HTTP State Management Mechanism + public static final String HEADER_SET_COOKIE = "Set-Cookie"; + + // HTTP State Management Mechanism (obsoletes RFC2109) + public static final String HEADER_COOKIE = "Cookie"; + public static final String HEADER_COOKIE2 = "Cookie2"; + public static final String HEADER_SET_COOKIE2 = "Set-Cookie2"; + + // Web Distributed Authoring and Versioning + public static final String HEADER_DAV = "DAV"; + public static final String HEADER_DEPTH = "Depth"; + public static final String HEADER_DESTINATION = "Destination"; + public static final String HEADER_IF = "If"; + public static final String HEADER_LOCK_TOKEN = "Lock-Token"; + public static final String HEADER_OVERWRITE = "Overwrite"; + public static final String HEADER_STATUS_URI = "Status-URI"; + public static final String HEADER_TIMEOUT = "Timeout"; + + // Hypertext Transfer Protocol -- HTTP/1.1 (Proposed Standard - these field-names are now considered obsolete) + public static final String HEADER_CONTENT_BASE = "Content-Base"; + public static final String HEADER_PUBLIC = "Public"; + public static final String HEADER_CONTENT_VERSION = "Content-Version"; + public static final String HEADER_DERIVED_FROM = "Derived-From"; + public static final String HEADER_LINK = "Link"; + public static final String HEADER_URI = "URI"; + public static final String HEADER_KEEP_ALIVE = "Keep-Alive"; + + // Delta Encoding in HTTP + public static final String HEADER_A_IM = "A-IM"; + public static final String HEADER_DELTA_BASE = "Delta-Base"; + public static final String HEADER_IM = "IM"; + + // Instance Digests in HTTP + public static final String HEADER_DIGEST = "Digest"; + public static final String HEADER_WANT_DIGEST = "Want-Digest"; + + // Simple Hit-Metering and Usage-Limiting for HTTP + public static final String HEADER_METER = "Meter"; + + // The Known Non-Standardized HTTP Header field-names + + // Transparent Content Negotiation in HTTP + public static final String HEADER_ACCEPT_FEATURES = "Accept-Features"; + public static final String HEADER_ALTERNATES = "Alternates"; + public static final String HEADER_NEGOTIATE = "Negotiate"; + public static final String HEADER_TCN = "TCN"; + public static final String HEADER_VARIANT_VARY = "Variant-Vary"; + + // The Safe Response Header Field + public static final String HEADER_SAFE = "Safe"; + + // Hyper Text Coffee Pot Control Protocol (HTCPCP/1.0) + public static final String HEADER_ACCEPT_ADDITIONS = "Accept-Additions"; + + // The Secure HyperText Transfer Protocol + public static final String HEADER_CONTENT_PRIVACY_DOMAIN = "Content-Privacy-Domain"; + public static final String HEADER_MAC_INFO = "MAC-Info"; + public static final String HEADER_PREARRANGED_KEY_INFO = "Prearranged-Key-Info"; + + // An HTTP Extension Framework + public static final String HEADER_C_EXT = "C-Ext"; + public static final String HEADER_C_MAN = "C-Man"; + public static final String HEADER_C_OPT = "C-Opt"; + public static final String HEADER_EXT = "Ext"; + public static final String HEADER_MAN = "Man"; + public static final String HEADER_OPT = "Opt"; + + // PICS Label Distribution Label Syntax and Communication Protocols + public static final String HEADER_PICS_LABEL = "PICS-Label"; + + // Platform For Privacy Preferences 1.0 + public static final String HEADER_P3P = "P3P"; + + // PEP - an Extension Mechanism for HTTP + public static final String HEADER_C_PEP = "C-PEP"; + public static final String HEADER_C_PEP_INFO = "C-PEP-Info"; + public static final String HEADER_PEP = "PEP"; + public static final String HEADER_PEP_INFO = "Pep-Info"; + + // The HTTP Distribution and Replication Protocol + public static final String HEADER_CONTENT_ID = "Content-ID"; + public static final String HEADER_DIFFERENTIAL_ID = "Differential-ID"; + + // ESI Architecture + public static final String HEADER_SURROGATE_CAPABILITY = "Surrogate-Capability"; + public static final String HEADER_SURROGATE_CONTROL = "Surrogate-Control"; + + // Selecting Payment Mechanisms Over HTTP + public static final String HEADER_PROTOCOL = "Protocol"; + public static final String HEADER_PROTOCOL_INFO = "Protocol-Info"; + public static final String HEADER_PROTOCOL_QUERY = "Protocol-Query"; + public static final String HEADER_PROTOCOL_REQUEST = "Protocol-Request"; + + // Implementation of OPS Over HTTP + public static final String HEADER_GETPROFILE = "GetProfile"; + public static final String HEADER_PROFILEOBJECT = "ProfileObject"; + public static final String HEADER_SETPROFILE = "SetProfile"; + + // Notification for Proxy Caches + public static final String HEADER_PROXY_FEATURES = "Proxy-Features"; + public static final String HEADER_PROXY_INSTRUCTION = "Proxy-Instruction"; + + // Object Header lines in HTTP + public static final String HEADER_CONTENT_TRANSFER_ENCODING = "Content-Transfer-Encoding"; + public static final String HEADER_COST = "Cost"; + public static final String HEADER_MESSAGE_ID = "Message-ID"; + public static final String HEADER_TITLE = "Title"; + public static final String HEADER_VERSION = "Version"; + + // A Proposed Extension Mechanism for HTTP + public static final String HEADER_EXTENSION = "Extension"; + + // WIRE - W3 Identifier Resolution Extensions + public static final String HEADER_OPTIONAL = "Optional"; + public static final String HEADER_RESOLUTION_HINT = "Resolution-Hint"; + + // Duplicate Suppression in HTTP + public static final String HEADER_SUBOK = "SubOK"; + public static final String HEADER_SUBST = "Subst"; + + // Specification of HTTP/1.1 OPTIONS messages + public static final String HEADER_COMPLIANCE = "Compliance"; + public static final String HEADER_NON_COMPLIANCE = "Non-Compliance"; + + // Widely-used undocumented headers + public static final String HEADER_REQUEST_RANGE = "Request-Range"; + public static final String HEADER_UA_COLOR = "UA-Color"; + public static final String HEADER_UA_CPU = "UA-CPU"; + public static final String HEADER_UA_OS = "UA-OS"; + public static final String HEADER_UA_PIXELS = "UA-Pixels"; + + // Implementation errors + public static final String HEADER_REFERRER = "Referrer"; + + // Private features + public static final String HEADER_COPYRIGHT = "Copyright"; + public static final String HEADER_CONTENT = "Content"; + public static final String HEADER_AUTHOR = "Author"; + public static final String HEADER_CONTACT = "Contact"; + public static final String HEADER_KEYWORDS = "Keywords"; + public static final String HEADER_GENERATOR = "Generator"; + public static final String HEADER_DESCRIPTION = "Description"; + public static final String HEADER_COMMAND = "Command"; + public static final String HEADER_SESSION = "Session"; + public static final String HEADER_TYPE = "Type"; + public static final String HEADER_MESSAGE = "Message"; + + // Abandoned proposals + public static final String HEADER_UNLESS_MODIFIED_SINCE = "Unless-Modified-Since"; + + /** + * Returns all the standardized HTTP header names presented as List + * @return The list of standardized HTTP header names + */ + public static List getStandardizedHeaderNames() { + return Arrays.asList(new Object[] { + HEADER_ACCEPT.toUpperCase(), + HEADER_ACCEPT_CHARSET.toUpperCase(), + HEADER_ACCEPT_ENCODING.toUpperCase(), + HEADER_ACCEPT_LANGUAGE.toUpperCase(), + HEADER_ACCEPT_RANGES.toUpperCase(), + HEADER_AGE.toUpperCase(), + HEADER_ALLOW.toUpperCase(), + HEADER_AUTHORIZATION.toUpperCase(), + HEADER_CACHE_CONTROL.toUpperCase(), + HEADER_CONNECT.toUpperCase(), + HEADER_CONTENT_ENCODING.toUpperCase(), + HEADER_CONTENT_LANGUAGE.toUpperCase(), + HEADER_CONTENT_LENGTH.toUpperCase(), + HEADER_CONTENT_LOCATION.toUpperCase(), + HEADER_CONTENT_MD5.toUpperCase(), + HEADER_CONTENT_RANGE.toUpperCase(), + HEADER_CONTENT_TYPE.toUpperCase(), + HEADER_DATE.toUpperCase(), + HEADER_ETAG.toUpperCase(), + HEADER_EXPECT.toUpperCase(), + HEADER_EXPIRES.toUpperCase(), + HEADER_FROM.toUpperCase(), + HEADER_HOST.toUpperCase(), + HEADER_IF_MATCH.toUpperCase(), + HEADER_IF_MODIFIED_SINCE.toUpperCase(), + HEADER_IF_NONE_MATCH.toUpperCase(), + HEADER_IF_RANGE.toUpperCase(), + HEADER_IF_UNMODIFIED_SINCE.toUpperCase(), + HEADER_LAST_MODIFIED.toUpperCase(), + HEADER_LOCATION.toUpperCase(), + HEADER_MAX_FORWARDS.toUpperCase(), + HEADER_PRAGMA.toUpperCase(), + HEADER_PROXY_AUTHENTICATE.toUpperCase(), + HEADER_PROXY_AUTHORIZATION.toUpperCase(), + HEADER_RANGE.toUpperCase(), + HEADER_REFERER.toUpperCase(), + HEADER_RETRY_AFTER.toUpperCase(), + HEADER_SERVER.toUpperCase(), + HEADER_TE.toUpperCase(), + HEADER_TRAILER.toUpperCase(), + HEADER_TRANSFER_ENCODING.toUpperCase(), + HEADER_UPGRADE.toUpperCase(), + HEADER_USER_AGENT.toUpperCase(), + HEADER_VARY.toUpperCase(), + HEADER_VIA.toUpperCase(), + HEADER_WARNING.toUpperCase(), + HEADER_WWW_AUTHENTICATE.toUpperCase(), + HEADER_MIME_VERSION.toUpperCase(), + HEADER_CONTENT_DISPOSITION.toUpperCase(), + + HEADER_AUTHENTICATION_INFO.toUpperCase(), + + HEADER_SET_COOKIE.toUpperCase(), + + HEADER_COOKIE.toUpperCase(), + HEADER_COOKIE2.toUpperCase(), + HEADER_SET_COOKIE2.toUpperCase(), + + HEADER_DAV.toUpperCase(), + HEADER_DEPTH.toUpperCase(), + HEADER_DESTINATION.toUpperCase(), + HEADER_IF.toUpperCase(), + HEADER_LOCK_TOKEN.toUpperCase(), + HEADER_OVERWRITE.toUpperCase(), + HEADER_STATUS_URI.toUpperCase(), + HEADER_TIMEOUT.toUpperCase(), + + HEADER_CONTENT_BASE.toUpperCase(), + HEADER_PUBLIC.toUpperCase(), + HEADER_CONTENT_VERSION.toUpperCase(), + HEADER_DERIVED_FROM.toUpperCase(), + HEADER_LINK.toUpperCase(), + HEADER_URI.toUpperCase(), + HEADER_KEEP_ALIVE.toUpperCase(), + + HEADER_A_IM.toUpperCase(), + HEADER_DELTA_BASE.toUpperCase(), + HEADER_IM.toUpperCase(), + + HEADER_DIGEST.toUpperCase(), + HEADER_WANT_DIGEST.toUpperCase(), + + HEADER_METER.toUpperCase() + }); + } + + /** + * Returns all the non-standardized HTTP header names presented as List + * @return The list of non-standardized HTTP header names + */ + public static List getNonStandardizedHeaderNames() { + return Arrays.asList(new Object[] { + HEADER_ACCEPT_FEATURES.toUpperCase(), + HEADER_ALTERNATES.toUpperCase(), + HEADER_NEGOTIATE.toUpperCase(), + HEADER_TCN.toUpperCase(), + HEADER_VARIANT_VARY.toUpperCase(), + + HEADER_SAFE.toUpperCase(), + + HEADER_ACCEPT_ADDITIONS.toUpperCase(), + + HEADER_CONTENT_PRIVACY_DOMAIN.toUpperCase(), + HEADER_MAC_INFO.toUpperCase(), + HEADER_PREARRANGED_KEY_INFO.toUpperCase(), + + HEADER_C_EXT.toUpperCase(), + HEADER_C_MAN.toUpperCase(), + HEADER_C_OPT.toUpperCase(), + HEADER_EXT.toUpperCase(), + HEADER_MAN.toUpperCase(), + HEADER_OPT.toUpperCase(), + + HEADER_PICS_LABEL.toUpperCase(), + HEADER_PROTOCOL.toUpperCase(), + HEADER_PROTOCOL_REQUEST.toUpperCase(), + + HEADER_P3P.toUpperCase(), + + HEADER_C_PEP.toUpperCase(), + HEADER_C_PEP_INFO.toUpperCase(), + HEADER_PEP.toUpperCase(), + HEADER_PEP_INFO.toUpperCase(), + + HEADER_CONTENT_ID.toUpperCase(), + HEADER_DIFFERENTIAL_ID.toUpperCase(), + + HEADER_SURROGATE_CAPABILITY.toUpperCase(), + HEADER_SURROGATE_CONTROL.toUpperCase(), + + HEADER_PROTOCOL.toUpperCase(), + HEADER_PROTOCOL_INFO.toUpperCase(), + HEADER_PROTOCOL_QUERY.toUpperCase(), + HEADER_PROTOCOL_REQUEST.toUpperCase(), + + HEADER_GETPROFILE.toUpperCase(), + HEADER_PROFILEOBJECT.toUpperCase(), + HEADER_SETPROFILE.toUpperCase(), + + HEADER_PROXY_FEATURES.toUpperCase(), + HEADER_PROXY_INSTRUCTION.toUpperCase(), + + HEADER_CONTENT_TRANSFER_ENCODING.toUpperCase(), + HEADER_COST.toUpperCase(), + HEADER_MESSAGE_ID.toUpperCase(), + HEADER_TITLE.toUpperCase(), + HEADER_VERSION.toUpperCase(), + + HEADER_EXTENSION.toUpperCase(), + + HEADER_OPTIONAL.toUpperCase(), + HEADER_RESOLUTION_HINT.toUpperCase(), + + HEADER_SUBOK.toUpperCase(), + HEADER_SUBST.toUpperCase(), + + HEADER_COMPLIANCE.toUpperCase(), + HEADER_NON_COMPLIANCE.toUpperCase(), + + HEADER_REQUEST_RANGE.toUpperCase(), + HEADER_UA_COLOR.toUpperCase(), + HEADER_UA_CPU.toUpperCase(), + HEADER_UA_OS.toUpperCase(), + HEADER_UA_PIXELS.toUpperCase(), + + HEADER_REFERRER.toUpperCase(), + + HEADER_COPYRIGHT.toUpperCase(), + HEADER_CONTENT.toUpperCase(), + HEADER_AUTHOR.toUpperCase(), + HEADER_CONTACT.toUpperCase(), + HEADER_KEYWORDS.toUpperCase(), + HEADER_GENERATOR.toUpperCase(), + HEADER_DESCRIPTION.toUpperCase(), + HEADER_COMMAND.toUpperCase(), + HEADER_SESSION.toUpperCase(), + HEADER_TYPE.toUpperCase(), + HEADER_MESSAGE.toUpperCase(), + + HEADER_UNLESS_MODIFIED_SINCE.toUpperCase() + }); + } + + /** + * Returns all known HTTP header names presented as List + * @return The list of all known HTTP header names + */ + public static List getAllKnownHeaderNames() { + return Arrays.asList(new Object[] { + HEADER_ACCEPT.toUpperCase(), + HEADER_ACCEPT_CHARSET.toUpperCase(), + HEADER_ACCEPT_ENCODING.toUpperCase(), + HEADER_ACCEPT_LANGUAGE.toUpperCase(), + HEADER_ACCEPT_RANGES.toUpperCase(), + HEADER_AGE.toUpperCase(), + HEADER_ALLOW.toUpperCase(), + HEADER_AUTHORIZATION.toUpperCase(), + HEADER_CACHE_CONTROL.toUpperCase(), + HEADER_CONNECT.toUpperCase(), + HEADER_CONTENT_ENCODING.toUpperCase(), + HEADER_CONTENT_LANGUAGE.toUpperCase(), + HEADER_CONTENT_LENGTH.toUpperCase(), + HEADER_CONTENT_LOCATION.toUpperCase(), + HEADER_CONTENT_MD5.toUpperCase(), + HEADER_CONTENT_RANGE.toUpperCase(), + HEADER_CONTENT_TYPE.toUpperCase(), + HEADER_DATE.toUpperCase(), + HEADER_ETAG.toUpperCase(), + HEADER_EXPECT.toUpperCase(), + HEADER_EXPIRES.toUpperCase(), + HEADER_FROM.toUpperCase(), + HEADER_HOST.toUpperCase(), + HEADER_IF_MATCH.toUpperCase(), + HEADER_IF_MODIFIED_SINCE.toUpperCase(), + HEADER_IF_NONE_MATCH.toUpperCase(), + HEADER_IF_RANGE.toUpperCase(), + HEADER_IF_UNMODIFIED_SINCE.toUpperCase(), + HEADER_LAST_MODIFIED.toUpperCase(), + HEADER_LOCATION.toUpperCase(), + HEADER_MAX_FORWARDS.toUpperCase(), + HEADER_PRAGMA.toUpperCase(), + HEADER_PROXY_AUTHENTICATE.toUpperCase(), + HEADER_PROXY_AUTHORIZATION.toUpperCase(), + HEADER_RANGE.toUpperCase(), + HEADER_REFERER.toUpperCase(), + HEADER_RETRY_AFTER.toUpperCase(), + HEADER_SERVER.toUpperCase(), + HEADER_TE.toUpperCase(), + HEADER_TRAILER.toUpperCase(), + HEADER_TRANSFER_ENCODING.toUpperCase(), + HEADER_UPGRADE.toUpperCase(), + HEADER_USER_AGENT.toUpperCase(), + HEADER_VARY.toUpperCase(), + HEADER_VIA.toUpperCase(), + HEADER_WARNING.toUpperCase(), + HEADER_WWW_AUTHENTICATE.toUpperCase(), + HEADER_MIME_VERSION.toUpperCase(), + HEADER_CONTENT_DISPOSITION.toUpperCase(), + + HEADER_AUTHENTICATION_INFO.toUpperCase(), + + HEADER_SET_COOKIE.toUpperCase(), + + HEADER_COOKIE.toUpperCase(), + HEADER_COOKIE2.toUpperCase(), + HEADER_SET_COOKIE2.toUpperCase(), + + HEADER_DAV.toUpperCase(), + HEADER_DEPTH.toUpperCase(), + HEADER_DESTINATION.toUpperCase(), + HEADER_IF.toUpperCase(), + HEADER_LOCK_TOKEN.toUpperCase(), + HEADER_OVERWRITE.toUpperCase(), + HEADER_STATUS_URI.toUpperCase(), + HEADER_TIMEOUT.toUpperCase(), + + HEADER_CONTENT_BASE.toUpperCase(), + HEADER_PUBLIC.toUpperCase(), + HEADER_CONTENT_VERSION.toUpperCase(), + HEADER_DERIVED_FROM.toUpperCase(), + HEADER_LINK.toUpperCase(), + HEADER_URI.toUpperCase(), + HEADER_KEEP_ALIVE.toUpperCase(), + + HEADER_A_IM.toUpperCase(), + HEADER_DELTA_BASE.toUpperCase(), + HEADER_IM.toUpperCase(), + + HEADER_DIGEST.toUpperCase(), + HEADER_WANT_DIGEST.toUpperCase(), + + HEADER_METER.toUpperCase(), + + HEADER_ACCEPT_FEATURES.toUpperCase(), + HEADER_ALTERNATES.toUpperCase(), + HEADER_NEGOTIATE.toUpperCase(), + HEADER_TCN.toUpperCase(), + HEADER_VARIANT_VARY.toUpperCase(), + + HEADER_SAFE.toUpperCase(), + + HEADER_ACCEPT_ADDITIONS.toUpperCase(), + + HEADER_CONTENT_PRIVACY_DOMAIN.toUpperCase(), + HEADER_MAC_INFO.toUpperCase(), + HEADER_PREARRANGED_KEY_INFO.toUpperCase(), + + HEADER_C_EXT.toUpperCase(), + HEADER_C_MAN.toUpperCase(), + HEADER_C_OPT.toUpperCase(), + HEADER_EXT.toUpperCase(), + HEADER_MAN.toUpperCase(), + HEADER_OPT.toUpperCase(), + + HEADER_PICS_LABEL.toUpperCase(), + HEADER_PROTOCOL.toUpperCase(), + HEADER_PROTOCOL_REQUEST.toUpperCase(), + + HEADER_P3P.toUpperCase(), + + HEADER_C_PEP.toUpperCase(), + HEADER_C_PEP_INFO.toUpperCase(), + HEADER_PEP.toUpperCase(), + HEADER_PEP_INFO.toUpperCase(), + + HEADER_CONTENT_ID.toUpperCase(), + HEADER_DIFFERENTIAL_ID.toUpperCase(), + + HEADER_SURROGATE_CAPABILITY.toUpperCase(), + HEADER_SURROGATE_CONTROL.toUpperCase(), + + HEADER_PROTOCOL.toUpperCase(), + HEADER_PROTOCOL_INFO.toUpperCase(), + HEADER_PROTOCOL_QUERY.toUpperCase(), + HEADER_PROTOCOL_REQUEST.toUpperCase(), + + HEADER_GETPROFILE.toUpperCase(), + HEADER_PROFILEOBJECT.toUpperCase(), + HEADER_SETPROFILE.toUpperCase(), + + HEADER_PROXY_FEATURES.toUpperCase(), + HEADER_PROXY_INSTRUCTION.toUpperCase(), + + HEADER_CONTENT_TRANSFER_ENCODING.toUpperCase(), + HEADER_COST.toUpperCase(), + HEADER_MESSAGE_ID.toUpperCase(), + HEADER_TITLE.toUpperCase(), + HEADER_VERSION.toUpperCase(), + + HEADER_EXTENSION.toUpperCase(), + + HEADER_OPTIONAL.toUpperCase(), + HEADER_RESOLUTION_HINT.toUpperCase(), + + HEADER_SUBOK.toUpperCase(), + HEADER_SUBST.toUpperCase(), + + HEADER_COMPLIANCE.toUpperCase(), + HEADER_NON_COMPLIANCE.toUpperCase(), + + HEADER_REQUEST_RANGE.toUpperCase(), + HEADER_UA_COLOR.toUpperCase(), + HEADER_UA_CPU.toUpperCase(), + HEADER_UA_OS.toUpperCase(), + HEADER_UA_PIXELS.toUpperCase(), + + HEADER_REFERRER.toUpperCase(), + + HEADER_COPYRIGHT.toUpperCase(), + HEADER_CONTENT.toUpperCase(), + HEADER_AUTHOR.toUpperCase(), + HEADER_CONTACT.toUpperCase(), + HEADER_KEYWORDS.toUpperCase(), + HEADER_GENERATOR.toUpperCase(), + HEADER_DESCRIPTION.toUpperCase(), + HEADER_COMMAND.toUpperCase(), + HEADER_SESSION.toUpperCase(), + HEADER_TYPE.toUpperCase(), + HEADER_MESSAGE.toUpperCase(), + + HEADER_UNLESS_MODIFIED_SINCE.toUpperCase() + }); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/HTTPUtils.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/HTTPUtils.java new file mode 100644 index 000000000..d92697d54 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/HTTPUtils.java @@ -0,0 +1,182 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.util; + +import java.util.HashMap; +import java.util.Map; +import java.util.StringTokenizer; + +import org.eclipse.wst.wsi.internal.WSIException; + +/** + * Set of HTTPL related utilities. + * + * @version 1.0.1 + * @author Peter Brittenham + */ + +public final class HTTPUtils +{ + + /** + * Find the URL string in a HTTP POST header. + * @param httpPostHeader a HTTP POST header. + * @return the URL string in a HTTP POST header. + */ + public static String getURLString(String httpPostHeader) + { + String urlString = null; + int start, end; + + // If POST, then continue + if (httpPostHeader.startsWith("POST") || httpPostHeader.startsWith("GET")) + { + // Start after first space + start = httpPostHeader.indexOf(' ') + 1; + + // Look for next non-space character + while (httpPostHeader.charAt(start) == ' ') + start++; + + // Find next space character + end = httpPostHeader.indexOf(' ', start); + + // Get URL string which is located in between start and end + urlString = httpPostHeader.substring(start, end); + } + + // Else throw exception + else + { + throw new IllegalArgumentException( + "HTTP header does not contain POST data (was: " + httpPostHeader + ")"); + } + + // Return URL string + return urlString; + } + /** + * Utility to present HTTP header information as attribute-value pairs, + * based on ':' as attribute-value separator. + * @param httpHeaderString an HTTP header string. + * @param separators attribute-value separator list. + * @return HTTP header information as attribute-value pairs. + * @throws WSIException if unable to create HTTP header information + * as attribute-value pairs. + */ + public static Map getHttpHeaderTokens(String httpHeaderString, String separators) + throws WSIException + { + StringTokenizer tokenizer = new StringTokenizer(httpHeaderString, "\n\r\f"); + Map map = new HashMap(); + String name = null; + while (tokenizer.hasMoreTokens()) + { + String line = tokenizer.nextToken(); + int index = line.indexOf(separators); + if (index > 0 && index < line.length() - 1) + { + name = line.substring(0, index).toUpperCase(); + map.put(name, line.substring(index + 1).trim()); + } + else + { + if ((name != null) && (line.length()>0) && Character.isWhitespace(line.charAt(0))) + map.put(name, map.get(name) + " " + line.trim()); + } + } + return map; + } + + /** + * Utility to take sub attribute value from HTTP header + * @param httpHeaderString an HTTP header string. + * @param attributeName attribute name. + * @param subAttributeName sub attribute name. + * @return sub attribute value from HTTP header. + * @throws WSIException if unable to get sub attribute value from HTTP header. + */ + public static String getHttpHeaderSubAttribute(String httpHeaderString, + String attributeName, String subAttributeName) + throws WSIException + { + // get attribute value + String value = + (String) getHttpHeaderTokens(httpHeaderString,":").get(attributeName.toUpperCase()); + if(value != null) + { + // search sub attribute token + int idxQ = value.toUpperCase().indexOf(subAttributeName.toUpperCase()+"=\""); + int idx = value.toUpperCase().indexOf(subAttributeName.toUpperCase()+"="); + // if attribute is quoted + if (idxQ != -1) + { + idxQ += (subAttributeName+"=\"").length(); + int eIdxQ = value.indexOf("\"", idxQ); + if (eIdxQ != -1) + { + return value.substring(idxQ, eIdxQ); + } + else + { + return null; + } + } + // if attribute do not quoted + else if (idx != -1) + { + idx += (subAttributeName+"=").length(); + int eIdx = -1; + // find end space separator + if ((eIdx = value.indexOf(" ", idx)) != -1) + { + return value.substring(idx, eIdx); + } + // find coma separator + else if ((eIdx = value.indexOf(";", idx)) != -1) + { + return value.substring(idx, eIdx); + } + // this is last attribute + else + { + return value.substring(idx); + } + } + // if attribute do not found + else + { + return null; + } + } + return value; + } + + /** + * Utility to take attribute value from HTTP header + * @param httpHeaderString an HTTP header string. + * @param attributeName attribute name. + * @return attribute value from HTTP header. + * @throws WSIException if unable to get attribute value from HTTP header. + */ + public static String getHttpHeaderAttribute(String httpHeaderString, + String attributeName) + throws WSIException + { + String attributeValue = + (String) getHttpHeaderTokens(httpHeaderString,":").get(attributeName.toUpperCase()); + // get first token + if((attributeValue != null) && (attributeValue.indexOf(";") != -1)) { + attributeValue = attributeValue.substring(0, attributeValue.indexOf(";")); + } + return attributeValue; + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/HttpHeadersValidator.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/HttpHeadersValidator.java new file mode 100644 index 000000000..eaf68a4d4 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/HttpHeadersValidator.java @@ -0,0 +1,1739 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.util; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Locale; +import java.util.StringTokenizer; + +import sun.net.www.MessageHeader; + +/** + * This class checks HTTP request headers about RFC 2616. + * + * @author Volodin + */ +public class HttpHeadersValidator +{ + + private static final String HEADER_ALLOW = "Allow"; + private static final String HEADER_CONTENT_TYPE = "Content-Type"; + private static final String HEADER_CONTENT_ENCODING = "Content-Encoding"; + private static final String HEADER_CONTENT_LANGUAGE = "Content-Language"; + private static final String HEADER_CONTENT_LENGHT = "Content-Length"; + private static final String HEADER_CONTENT_LOCATION = "Content-Location"; + private static final String HEADER_CONTENT_MD5 = "Content-MD5"; + private static final String HEADER_CONTENT_RANGE = "Content-Range"; + private static final String HEADER_EXPIRES = "Expires"; + private static final String HEADER_LAST_MODIFIED = "Last-Modified"; + private static final String HEADER_CACHE_CONTROL = "Cache-Control"; + private static final String HEADER_CONNECTION = "Connection"; + private static final String HEADER_DATE = "Date"; + private static final String HEADER_PRAGMA = "Pragma"; + private static final String HEADER_TRAILER = "Trailer"; + private static final String HEADER_TRANSFER_ENCODING = "Transfer-Encoding"; + + private static final String HEADER_UPGRADE = "Upgrade"; + private static final String HEADER_VIA = "Via"; + private static final String HEADER_WARNING = "Warning"; + + private static final String HEADER_ACCEPT = "Accept"; + private static final String HEADER_ACCEPT_CHARSET = "Accept-Charset"; + private static final String HEADER_ACCEPT_ENCODING = "Accept-Encoding"; + private static final String HEADER_ACCEPT_LANGUAGE = "Accept-Language"; + private static final String HEADER_AUTHORIZATION = "Authorization"; + private static final String HEADER_EXPECT = "Expect"; + private static final String HEADER_FROM = "From"; + private static final String HEADER_HOST = "Host"; + private static final String HEADER_IF_MATCH = "If-Match"; + private static final String HEADER_IF_MODIFIED_SINCE = "If-Modified-Since"; + private static final String HEADER_IF_NONE_MATCH = "If-None-Match"; + private static final String HEADER_IF_RANGE = "If-Range"; + private static final String HEADER_IF_UNMODIFIED_SINCE = + "If-Unmodified-Since"; + private static final String HEADER_MAX_FORWARDS = "Max-Forwards"; + private static final String HEADER_PROXY_AUTHORIZATION = + "Proxy-Authorization"; + private static final String HEADER_RANGE = "Range"; + private static final String HEADER_REFERER = "Referer"; + private static final String HEADER_TE = "TE"; + private static final String HEADER_USER_AGENT = "User-Agent"; + + /** + * This class checks e-mail string about RFC 822. + */ + public static class MailboxValidator + { + private static final char[] SPECIAL = + { '(', ')', '<', '>', '@', ',', ';', ':', '\\', '\"', '.', '[', ']' }; + + /** + * Validates e-mail string. + * @param mailbox e-mail string + * @return boolean true if e-mail string is conform to RFC 822, false otherwise. + */ + + public static boolean validateMailbox(String mailbox) + { + + if (!isFullAddr(mailbox) && !isShortAddr(mailbox)) + return false; + + return true; + } + + /** + * Method isSimpleAddr. + * @param mailbox + * @return boolean + */ + private static boolean isShortAddr(String mailbox) + { + int indexAt = mailbox.indexOf('@'); + if (indexAt == -1) + return false; + + if (!isLocalPart(mailbox.substring(0, indexAt)) + || !isDomain(mailbox.substring(indexAt + 1))) + return false; + + return true; + } + + /** + * Method isDomaim. + * @param string + * return boolean + */ + private static boolean isDomain(String string) + { + if (string.trim().length() == 0) + return false; + StringTokenizer st = new StringTokenizer(string, "."); + while (st.hasMoreTokens()) + { + String subDomain = st.nextToken(); + if (!isAtom(subDomain) && !isDomainLiteral(subDomain)) + return false; + + } + return true; + } + + /** + * Method isDomainLiteral. + * @param subDomain + * @return boolean + */ + private static boolean isDomainLiteral(String subDomain) + { + if (getLastDomainLiteral(subDomain, 0) == subDomain.length()) + { + return true; + } + else + { + return false; + } + } + + private static int getLastDomainLiteral(String str, int startIndex) + { + + int index = startIndex; + //int newIndex = 0; + + // if end if the string + if (startIndex == str.length()) + return startIndex; + // if the begin is not '[' + if (str.charAt(index) != '[') + return startIndex; + + index++; + while (true) + { + index = getLastDtext(str, index); + if (index == str.length()) + return startIndex; + if (BasicRules.isQuotedPair(str, index - 1)) + { + index++; + if (index == str.length()) + return startIndex; + } + else + break; + } + // if the end is not ']' + if (str.charAt(index) != ']') + return startIndex; + + index++; + return index; + } + + private static int getLastDtext(String str, int startIndex) + { + if (str.length() == startIndex) + return startIndex; + int i = 0; + for (; i < str.length(); i++) + { + char ch = str.charAt(i); + i = BasicRules.getLastIndexLWS(str, i); + if (!BasicRules.isCHAR(ch) + || str.charAt(i) == '[' + || str.charAt(i) == ']' + || str.charAt(i) == '\\' + || str.charAt(i) == BasicRules.CR) + { + return i + 1; + } + } + return i + 1; + } + + /** + * Method isLocalPart. + * @param string + * @return boolean + */ + private static boolean isLocalPart(String string) + { + if (string.trim().length() == 0) + return false; + StringTokenizer st = new StringTokenizer(string, "."); + while (st.hasMoreTokens()) + { + if (!isWord(st.nextToken())) + return false; + } + return true; + } + + /** + * Method isWord. + * @param string + * @return boolean + */ + private static boolean isWord(String string) + { + if (!isAtom(string) && !isQuotedString(string)) + return false; + return true; + } + + /** + * Method isAtom. + * @param string + * @return boolean + */ + private static boolean isAtom(String string) + { + if (string.length() == 0) + return false; + for (int i = 0; i < string.length(); i++) + { + if (!BasicRules.isCHAR(string.charAt(i)) + || isSpecial(string.charAt(i)) + || string.charAt(i) == ' ' + || BasicRules.isCTL(string.charAt(i))) + { + return false; + } + } + return true; + } + + /** + * Method isSpecial. + * @param c + * @return boolean + */ + private static boolean isSpecial(char ch) + { + for (int index = 0; index < SPECIAL.length; index++) + { + if (ch == SPECIAL[index]) + return true; + } + return false; + } + + /** + * Method isFullAddr. + * @param mailbox + * @return boolean + */ + private static boolean isFullAddr(String mailbox) + { + if (mailbox.length() == 0) + return false; + int idxLT = mailbox.indexOf('<'); + if (idxLT == -1) + return false; + + //is phrase + String phrase = mailbox.substring(0, idxLT); + StringTokenizer st = new StringTokenizer(phrase, " "); + if (st.countTokens() == 0) + return false; + while (st.hasMoreTokens()) + { + if (!isWord(st.nextToken())) + return false; + } + if (phrase.charAt(phrase.length() - 1) != BasicRules.SP) + { + return false; + } + + //is route-addr + String routeAddr = mailbox.substring(idxLT + 1); + // is route + int idxTwoSpot = routeAddr.indexOf(':'); + if (idxTwoSpot != -1) + { + StringTokenizer stRouteAddr = + new StringTokenizer(routeAddr.substring(0, idxTwoSpot), ","); + if (!stRouteAddr.hasMoreTokens()) + return false; + while (stRouteAddr.hasMoreTokens()) + { + if (!isDomain(stRouteAddr.nextToken())) + return false; + } + } + + //is addr spec + int idxGT = routeAddr.indexOf('>'); + if (idxGT == -1 || idxGT != (routeAddr.length() - 1)) + return false; + + if (!isShortAddr(routeAddr.substring(idxTwoSpot + 1, idxGT))) + return false; + + return true; + } + + } + + /** + * Validates HTTP request headers. + * @param headers HTTP request headers + * @return boolean true if all HTTP headers string is conform to RFC 2616, false otherwise. + */ + + public static boolean validateHttpRequestHeaders(String headers) + { + + MessageHeader mh = new MessageHeader(); + try + { + mh.parseHeader(new ByteArrayInputStream(headers.getBytes())); + } + catch (IOException e) + { + return false; + } + + String header = null; + String value = null; + + header = mh.getKey(0); + if (header != null) + return false; + + value = mh.getValue(0); + if (value == null) + return false; + + //method + StringTokenizer st = new StringTokenizer(value, " "); + if (!st.hasMoreElements()) + return false; + String str = st.nextToken(); + if (!isToken(str)) + return false; + + if (!st.hasMoreElements()) + return false; + str = st.nextToken(); + if (!isURI(str) && !str.equals("*")) + return false; + + if (!st.hasMoreElements()) + return false; + str = st.nextToken(); + if (!isHTTPVersion(str)) + return false; + + int i = 1; + try + { + while ((header = mh.getKey(i)) != null) + { + value = mh.getValue(i); + i++; + + // is message-header token + if (!isToken(header)) + return false; + + //---- entity-headers + + if (header.equals(HEADER_ALLOW)) + { + if (!isValidAllow(value)) + return false; + else + continue; + } + + if (header.equals(HEADER_CONTENT_TYPE)) + { + if (!isMediaType(value)) + return false; + else + continue; + } + if (header.equals(HEADER_CONTENT_ENCODING)) + { + if (!isToken(value)) + return false; + else + continue; + } + if (header.equals(HEADER_CONTENT_LANGUAGE)) + { + if (!isLanguageTag(value)) + return false; + else + continue; + } + if (header.equals(HEADER_CONTENT_LENGHT)) + { + if (!isDidgit(value)) + return false; + else + continue; + } + if (header.equals(HEADER_CONTENT_LOCATION)) + { + if (!isURI(value)) + return false; + else + continue; + } + + if (header.equals(HEADER_CONTENT_RANGE)) + { + if (!isValidContentRange(value)) + return false; + else + continue; + } + + if (header.equals(HEADER_EXPIRES) + || header.equals(HEADER_LAST_MODIFIED)) + { + if (!isHTTPDate(value)) + return false; + else + continue; + } + + //---- general-headers + if (header.equals(HEADER_CACHE_CONTROL)) + { + if (!isValidCacheControl(value)) + return false; + + continue; + //return true; + } + + if (header.equals(HEADER_CONNECTION)) + { + if (!isToken(value)) + return false; + else + continue; + } + + if (header.equals(HEADER_DATE)) + { + if (!isHTTPDate(value)) + return false; + else + continue; + } + + if (header.equals(HEADER_PRAGMA)) + { + if (!isPragmaDerective(value)) + return false; + else + continue; + } + + if (header.equals(HEADER_TRAILER)) + { + if (!isToken(value)) + return false; + else + continue; + } + + if (header.equals(HEADER_TRANSFER_ENCODING)) + { + if (!isTransferCoding(value)) + return false; + else + continue; + } + + if (header.equals(HEADER_UPGRADE)) + { + if (!isValidUpgrade(value)) + return false; + else + continue; + } + + if (header.equals(HEADER_VIA)) + { + if (!isValidVia(value)) + return false; + else + continue; + } + + if (header.equals(HEADER_WARNING)) + { + if (!isValidWarning(value)) + return false; + else + continue; + } + + if (header.equals(HEADER_ACCEPT)) + { + if (!isValidAccept(value)) + return false; + else + continue; + } + + if (header.equals(HEADER_ACCEPT_CHARSET)) + { + if (!isValidAcceptCharSet(value)) + return false; + else + continue; + } + + if (header.equals(HEADER_ACCEPT_ENCODING)) + { + if (!isValidAcceptEncoding(value)) + return false; + else + continue; + } + + if (header.equals(HEADER_ACCEPT_LANGUAGE)) + { + if (!isValidAcceptLanguage(value)) + return false; + else + continue; + } + + if (header.equals(HEADER_AUTHORIZATION) + || header.equals(HEADER_PROXY_AUTHORIZATION)) + { + if (!isCredentials(value)) + return false; + else + continue; + } + if (header.equals(HEADER_EXPECT)) + { + if (!isExpectation(value)) + return false; + else + continue; + } + + if (header.equals(HEADER_FROM)) + { + if (!MailboxValidator.validateMailbox(value)) + return false; + else + continue; + } + + if (header.equals(HEADER_IF_MATCH) + || header.equals(HEADER_IF_NONE_MATCH)) + { + if (!isValidIfMatch(value)) + return false; + else + continue; + } + if (header.equals(HEADER_IF_RANGE)) + { + if (!isEntityTag(value) && !isHTTPDate(value)) + return false; + else + continue; + } + + //--- + if (header.equals(HEADER_IF_MODIFIED_SINCE)) + { + if (!isHTTPDate(value)) + return false; + else + continue; + } + if (header.equals(HEADER_IF_UNMODIFIED_SINCE)) + { + if (!isHTTPDate(value)) + return false; + else + continue; + } + if (header.equals(HEADER_MAX_FORWARDS)) + { + if (!isDidgit(value)) + return false; + else + continue; + } + + if (header.equals(HEADER_USER_AGENT)) + { + if (!isValidUserAgent(value)) + return false; + else + continue; + } + + if (header.equals(HEADER_TE)) + { + if (!isValidTE(value)) + return false; + else + continue; + } + + if (header.equals(HEADER_RANGE)) + { + if (!isRange(value)) + return false; + else + continue; + } + if (header.equals(HEADER_HOST)) + { + if (!isHost(value)) + return false; + else + continue; + } + if (header.equals(HEADER_REFERER)) + { + if (!isURI(value)) + return false; + else + continue; + } + + } + } + catch (Exception e) + { + return false; + } + return true; + } + + /** + * Method isValidIfMatch. + * @param value + * @return boolean + */ + private static boolean isValidIfMatch(String value) + { + if (value.trim().length() == 0) + return true; + if ("*".equals(value.trim())) + return true; + + StringTokenizer st = new StringTokenizer(value, ","); + while (st.hasMoreElements()) + { + String str = st.nextToken().trim(); + if (!isEntityTag(str)) + return false; + + } + + return true; + } + + /** + * Method isValidUpgrade. + * @param value + * @return boolean + */ + private static boolean isValidUpgrade(String value) + { + if (value.trim().length() == 0) + return false; + StringTokenizer st = new StringTokenizer(value, ","); + while (st.hasMoreElements()) + { + String str = st.nextToken().trim(); + if (!isProduct(str)) + return false; + + } + return true; + } + + /** + * Method isValidCacheControl. + * @param value + * @return boolean + */ + private static boolean isValidCacheControl(String value) + { + + if (value.trim().length() == 0) + return false; + + StringTokenizer st = new StringTokenizer(value, ","); + while (st.hasMoreElements()) + { + String str = st.nextToken().trim(); + int index = str.indexOf('='); + if (index == -1) + { + + } + else + { + if (!isToken(str.substring(0, index))) + return false; + String strAfterEq = str.substring(index + 1); + if (!isToken(strAfterEq) && !isQuotedString(strAfterEq)) + { + return false; + } + } + } + + return true; + } + + /** + * Method isHTTPVersion. + * @param str + * @return boolean + */ + private static boolean isHTTPVersion(String str) + { + if (!str.startsWith("HTTP/")) + return false; + int idx = "HTTP/".length(); + + int idx2 = str.indexOf("."); + + // 1*DIGIT + String s = str.substring(idx, idx2); + if (!isDidgit(s)) + return false; + + s = str.substring(idx2 + 1); + if (!isDidgit(s)) + return false; + + return true; + } + + /** + * Method isValidWarning. + * @param value + * @return boolean + */ + private static boolean isValidWarning(String value) + { + if (value.length() == 0) + return false; + value = value.trim(); + StringTokenizer st = new StringTokenizer(value, " "); + String str = st.nextToken(); + + if (str.length() > 3 || !isDidgit(str)) + return false; + + if (!st.hasMoreTokens()) + return false; + str = st.nextToken(); + if (!isHost(str) && !isToken(str)) + return false; + + //if(!st.hasMoreTokens()) return false; + str = st.nextToken("").trim(); + //??? + + int lastQuotedString = BasicRules.getLastQuotedString(str, 0); + if (lastQuotedString == str.length()) + { + return true; + } + else + { + String data = str.substring(lastQuotedString); + if (data.charAt(data.length()) != '\"') + return false; + if (str.charAt(0) != '\"') + return false; + if (!isHTTPDate(str.substring(1, data.length() - 1))) + return false; + } + + return true; + } + + /** + * Method isValidVia. + * @param value + * @return boolean + */ + private static boolean isValidVia(String value) + { + if (value.trim().length() == 0) + return false; + + StringTokenizer st = new StringTokenizer(value, ","); + while (st.hasMoreElements()) + { + + String str = st.nextToken().trim(); + + StringTokenizer st2 = new StringTokenizer(str, " "); + + // protocol/version + str = st2.nextToken(); + int idx = str.indexOf("/"); + if (idx == -1) + { + if (!isToken(str)) + return false; + } + else + { + if (!isToken(str.substring(0, idx)) + || !isToken(str.substring(idx + 1))) + return false; + } + + //host + str = st2.nextToken(); + if (!isHost(str) && !isToken(str)) + return false; + + //comment + if (st2.hasMoreTokens()) + { + str = st2.nextToken(""); + if (!isComment(str.trim())) + return false; + } + } + return true; + } + + /** + * Method isHost. + * @param value + * @return boolean + */ + private static boolean isHost(String value) + { + + try + { + URL url = new URL("http://" + value); + } + catch (MalformedURLException e) + { + return false; + } + return true; + } + + /** + * Method isValidAllow. + * @param value + * @return boolean + */ + private static boolean isValidAllow(String value) + { + if (value.trim().length() == 0) + return true; + + StringTokenizer st = new StringTokenizer(value, ","); + while (st.hasMoreElements()) + { + String str = st.nextToken().trim(); + if (!isToken(str)) + return false; + } + return true; + } + + /** + * Method isValidContentRange. + * @param value + * @return boolean + */ + private static boolean isValidContentRange(String value) + { + if (value.length() == 0) + return false; + if (!value.startsWith("bytes")) + return false; + String str = value.substring("bytes".length()).trim(); + + int idx = str.indexOf("/"); + if (idx == -1) + return false; + + String byteRange = str.substring(0, idx); + int idx2 = byteRange.indexOf("-"); + if (idx2 == -1) + { + if (!byteRange.equals("*")) + return false; + } + else + { + if (!isDidgit(byteRange.substring(0, idx2)) + || !isDidgit(byteRange.substring(idx2 + 1))) + return false; + } + + if (!isDidgit(str.substring(idx + 1)) + && !str.substring(idx + 1).equals("*")) + return false; + + return true; + } + + /** + * Method isRange. + * @param value + * @return boolean + */ + private static boolean isRange(String value) + { + if (value.length() == 0) + return false; + if (!value.startsWith("bytes=")) + return false; + String strByteRange = value.substring("bytes=".length()); + + StringTokenizer st = new StringTokenizer(strByteRange, ","); + while (st.hasMoreElements()) + { + String str = st.nextToken(); + int idx = str.indexOf("-"); + if (idx == -1) + return false; + if (idx == 0) + { + if (!isDidgit(str.substring(1))) + return false; + } + else + { + if (idx == (str.length() - 1)) + { + if (!isDidgit(str.substring(0, str.length() - 1))) + return false; + } + else + { + if (!isDidgit(str.substring(0, idx)) + || !isDidgit(str.substring(idx + 1))) + return false; + } + + } + + } + return true; + } + + /** + * Method isValidTE. + * @param value + * @return boolean + */ + private static boolean isValidTE(String value) + { + if (value.trim().length() == 0) + return true; + + StringTokenizer st = new StringTokenizer(value, ","); + while (st.hasMoreElements()) + { + String str = st.nextToken().trim(); + if (st.equals("trailers")) + return true; + + int idx = str.indexOf(";"); + if (idx == -1) + { + if (!isLanguageRange(str)) + return false; + } + else + { + String _1 = str.substring(0, idx).trim(); + String _2 = str.substring(idx + 1).trim(); + if (!isLanguageRange(_1)) + return false; + if (!isQAndQValue(_2)) + return false; + } + + } + + return true; + } + + /** + * Method isValidUserAgent. + * @param value + * @return boolean + */ + private static boolean isValidUserAgent(String value) + { + if (value.length() == 0) + return false; + StringTokenizer st = new StringTokenizer(value, " "); + while (st.hasMoreElements()) + { + String str = st.nextToken(); + if (!isProduct(str) && !isComment(str)) + return false; + + } + + return true; + } + + /** + * Method isComment. + * @param str + * @return boolean + */ + private static boolean isComment(String str) + { + if (BasicRules.getLastComment(str, 0) != str.length()) + return false; + return true; + } + + /** + * Method isValidAcceptLanguage. + * @param value + * @return boolean + */ + private static boolean isValidAcceptLanguage(String value) + { + if (value.trim().length() == 0) + return false; + + StringTokenizer st = new StringTokenizer(value, ","); + while (st.hasMoreElements()) + { + String str = st.nextToken().trim(); + int idx = str.indexOf(";"); + if (idx == -1) + { + if (!isToken(str)) + return false; + } + else + { + String _1 = str.substring(0, idx).trim(); + String _2 = str.substring(idx + 1).trim(); + if (!isToken(_1)) + return false; + if (!isAcceptParams(_2)) + return false; + } + + } + + return true; + } + + /** + * Method isLanguageRange. + * @param str + * @return boolean + */ + private static boolean isLanguageRange(String str) + { + if (str.trim().equals("*")) + return true; + StringTokenizer st = new StringTokenizer(str, "-"); + while (st.hasMoreElements()) + { + if (!is8ALPHA(st.nextToken())) + return false; + } + return true; + } + + /** + * Method isValidAcceptEncoding. + * @param value + * @return boolean + */ + private static boolean isValidAcceptEncoding(String value) + { + if (value.trim().length() == 0) + return false; + + StringTokenizer st = new StringTokenizer(value, ","); + while (st.hasMoreElements()) + { + String str = st.nextToken().trim(); + int idx = str.indexOf(";"); + if (idx == -1) + { + if (!isToken(str) && !str.equals("*")) + return false; + } + else + { + String _1 = str.substring(0, idx).trim(); + String _2 = str.substring(idx + 1).trim(); + + if ((!isToken(_1) && !_1.equals("*"))) + return false; + if (!isQAndQValue(_2)) + return false; + } + + } + + return true; + } + + /** + * Method isValidAcceptCharSet. + * @param value + * @return boolean + */ + private static boolean isValidAcceptCharSet(String value) + { + if (value.trim().length() == 0) + return false; + + StringTokenizer st = new StringTokenizer(value, ","); + while (st.hasMoreElements()) + { + String str = st.nextToken().trim(); + int idx = str.indexOf(";"); + if (idx == -1) + { + if (!isToken(str) && !str.equals("*")) + return false; + } + else + { + String _1 = str.substring(0, idx).trim(); + String _2 = str.substring(idx + 1).trim(); + + if ((!isToken(_1) && !_1.equals("*"))) + return false; + if (!isQAndQValue(_2)) + return false; + } + + } + + return true; + } + + /** + * Method isValidAccept. + * @param value + * @return boolean + */ + private static boolean isValidAccept(String value) + { + if (value.trim().length() == 0) + return true; + + StringTokenizer st = new StringTokenizer(value, ","); + while (st.hasMoreElements()) + { + String str = st.nextToken().trim(); + int idx = str.indexOf(";"); + if (idx == -1) + { + if (!isMediaRange(str)) + return false; + } + else + { + if (!isMediaRange(str.substring(0, idx).trim()) + || !isAcceptParams(str.substring(idx + 1).trim())) + return false; + + } + + } + return true; + } + + /** + * Method isAcceptParams. + * @param string + * @return boolean + */ + private static boolean isAcceptParams(String string) + { + if (string.trim().length() == 0) + return false; + + StringTokenizer st = new StringTokenizer(string, ";"); + String str = st.nextToken(); + + int idx = str.indexOf("="); + if (idx == -1) + { + if (str.equals("q") || !isToken(str)) + return false; + } + else + { + if (str.substring(0, idx).equals("q")) + { + if (!isQValue(str.substring(idx + 1))) + return false; + } + else + { + if (!isParameterWithoutValue(str)) + return false; + } + } + + while (st.hasMoreElements()) + { + str = st.nextToken(); + if (!isParameterWithoutValue(str)) + return false; + } + return true; + } + + /** + * Method isQAndQValue. + * @param str + * @return boolean + */ + private static boolean isQAndQValue(String str) + { + str = str.trim(); + if (!str.trim().startsWith("q=")) + return false; + if (!isQValue(str.substring("q=".length()))) + return false; + return true; + } + + /** + * Method isQValue. + * @param string + * @return boolean + */ + private static boolean isQValue(String string) + { + if (string.trim().length() == 0) + return false; + + int idx = string.indexOf("."); + if (idx == -1) + { + if (!"0".equals(string) && !"1".equals(string)) + return false; + } + else + { + String strDig = string.substring(idx + 1); + if (strDig.length() > 3) + return false; + + if (string.substring(0, idx).equals("0")) + { + if (!isDidgit(strDig)) + return false; + + } + else + { + if (!string.substring(0, idx).equals("1")) + return false; + + for (int i = 0; i < strDig.length(); i++) + { + if (strDig.charAt(i) != '0') + return false; + } + } + + } + return true; + } + + /** + * Method isMediaRange. + * @param str + * @return boolean + */ + private static boolean isMediaRange(String str) + { + if (str.trim().length() == 0) + return false; + + int idx = str.indexOf("/"); + if (idx == -1) + return false; + + if (!isToken(str.substring(0, idx)) && !str.substring(0, idx).equals("*")) + return false; + if (!isToken(str.substring(idx + 1)) + && !str.substring(idx + 1).equals("*")) + return false; + + return true; + } + + /** + * Method isEntityTag. + * @param value + * @return boolean + */ + private static boolean isEntityTag(String value) + { + + int idx = 0; + if (value.startsWith("W/")) + idx = 2; + if (!isQuotedString(value.substring(idx))) + return false; + return true; + } + + /** + * Method isExpectation. + * @param value + * @return boolean + */ + private static boolean isExpectation(String value) + { + if (value.equals("100-continue")) + return true; + + StringTokenizer st = new StringTokenizer(value, ";"); + while (st.hasMoreElements()) + { + if (!isParameterWithoutValue(st.nextToken())) + return false; + } + + return true; + } + + /** + * Method isCredentials. + * @param value + * @return boolean + */ + private static boolean isCredentials(String value) + { + StringTokenizer st = new StringTokenizer(value, " "); + if (!isToken(st.nextToken())) + return false; + + while (st.hasMoreElements()) + { + String param = st.nextToken(","); + if (!isParameter(param)) + return false; + } + return true; + } + + /** + * Method isProduct. + * @param value + * @return boolean + */ + private static boolean isProduct(String value) + { + int idx = value.indexOf("/"); + if (idx == -1) + { + if (!isToken(value)) + return false; + } + else + { + if (!isToken(value.substring(0, idx)) + || !isToken(value.substring(idx + 1))) + return false; + } + return true; + } + + /** + * Method isTransferCoding. + * @param value + * @return boolean + */ + private static boolean isTransferCoding(String value) + { + if (value.equals("chunked")) + { + return true; + } + else + { + StringTokenizer st = new StringTokenizer(value, ";"); + if (!isToken(st.nextToken())) + return false; + + while (st.hasMoreElements()) + { + if (!isParameter(st.nextToken())) + return false; + } + + } + + return true; + } + + /** + * Method isParameter. + * @param string + * @return boolean + */ + private static boolean isParameter(String string) + { + + // check parameter + int idx = string.indexOf("="); + if (!isToken(string.substring(0, idx))) + return false; + + String parValue = string.substring(idx + 1); + if (!isToken(parValue) && !isQuotedString(parValue)) + return false; + + return true; + } + + /** + * Method isParameterWithoutValue. + * @param string + * @return boolean + */ + private static boolean isParameterWithoutValue(String string) + { + + // check parameter + int idx = string.indexOf("="); + if (idx != -1) + { + if (!isToken(string.substring(0, idx))) + return false; + String parValue = string.substring(idx + 1); + if (!isToken(parValue) && !isQuotedString(parValue)) + return false; + + } + else + { + if (!isToken(string)) + return false; + } + + return true; + } + + /** + * Method isPragmaDerective. + * @param value + * @return boolean + */ + private static boolean isPragmaDerective(String value) + { + if (value.equals("no-cache")) + return true; + else + { + int idx = value.indexOf("="); + if (idx == -1) + { + if (isToken(value)) + return true; + } + else + { + String str = value.substring(idx + 1); + if (isToken(value.substring(0, idx)) + && (isToken(str) || isQuotedString(str))) + return true; + } + } + return true; + } + + /** + * Method isHTTPDate. + * @param value + * @return boolean + */ + private static boolean isHTTPDate(String value) + { + + String rfc1123_date = "EEE, dd MMM yyyy hh:mm:ss 'GMT'"; + String rfc850_date = "EEEE, dd-MMM-yy hh:mm:ss 'GMT'"; + String asctime_date = "EEE MMM d hh:mm:ss yyyy"; + + try + { + SimpleDateFormat sdf = new SimpleDateFormat(rfc1123_date, Locale.US); + if (sdf.parse(value) != null) + return true; + } + catch (ParseException e) + { + } + + try + { + SimpleDateFormat sdf = new SimpleDateFormat(rfc850_date, Locale.US); + if (sdf.parse(value) != null) + return true; + } + catch (ParseException e) + { + } + + try + { + SimpleDateFormat sdf = new SimpleDateFormat(asctime_date, Locale.US); + if (sdf.parse(value) != null) + return true; + } + catch (ParseException e) + { + } + + return false; + + } + + /** + * Method isURI. + * @param value + * @return boolean + */ + private static boolean isURI(String value) + { + URL url; + + try + { + url = new URL(value); + } + catch (MalformedURLException e) + { + try + { + url = new URL("http://localhost" + value); + } + catch (MalformedURLException e2) + { + return false; + } + } + + return true; + } + + /** + * Method isLanguageTag. + * @param value + * @return boolean + */ + private static boolean isLanguageTag(String value) + { + int idx = value.indexOf("-"); + if (idx == -1) + { + return is8ALPHA(value); + } + else + { + if (!is8ALPHA(value.substring(0, idx)) + || !is8ALPHA(value.substring(idx + 1))) + return false; + else + return true; + + } + } + + /** + * Method is8ALPHA. + * @param string + * @return boolean + */ + private static boolean is8ALPHA(String string) + { + if (string.length() > 8 || !isALPHA(string)) + return false; + else + return true; + } + + /** + * Method isALPHA. + * @param string + * @return boolean + */ + private static boolean isALPHA(String string) + { + for (int i = 0; i < string.length(); i++) + { + if (!BasicRules.isCHAR(string.charAt(i))) + return false; + } + + return true; + } + + /** + * Method isDidgit. + * @param value + * @return boolean + */ + private static boolean isDidgit(String value) + { + if (value.length() == 0) + return false; + char[] chs = value.toCharArray(); + for (int i = 0; i < chs.length; i++) + { + if (chs[i] < '0' || chs[i] > '9') + return false; + } + + return true; + } + + /** + * Method isMediaType. + * @param value + * @return boolean + */ + private static boolean isMediaType(String value) + { + StringTokenizer st = new StringTokenizer(value, ";"); + String mediaType = st.nextToken(); + + int idx = mediaType.indexOf("/"); + if (!isToken(mediaType.substring(0, idx)) + || !isToken(mediaType.substring(idx + 1))) + { + return false; + } + + while (st.hasMoreElements()) + { + if (!isParameter(st.nextToken(";").trim())) + return false; + } + return true; + } + + /** + * Method isQuotedString. + * @param parValue + * @return boolean + */ + private static boolean isQuotedString(String parValue) + { + if (BasicRules.getLastQuotedString(parValue, 0) != parValue.length()) + { + return false; + } + return true; + } + + /** + * Method isText. + * @param text + * @return boolean + */ + private static boolean isText(String text) + { + char[] chs = text.toCharArray(); + for (int i = 0; i < chs.length; i++) + { + if (chs[i] == '\"') + return false; + } + return true; + } + + /** + * Method isToken. + * @param value + * @return boolean + */ + private static boolean isToken(String value) + { + return BasicRules.isToken(value); + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/JavaEncoding.properties b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/JavaEncoding.properties new file mode 100644 index 000000000..42935366a --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/JavaEncoding.properties @@ -0,0 +1,31 @@ +# /** +# * +# * +# * Copyright (c) 2002-2003 IBM Corporation, Beacon Information Technology Inc. and others. +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * IBM - Initial API and implementation +# * BeaconIT - Initial API and implementation +# * +# */ +## I18N: 2003.02.26 modified by K.Nakagome@BeaconIT +## Property file used to get JavaVM supported character encoding. + +ISO8859_1=ISO8859_1 +ISO8859-1=ISO8859_1 +utf8=UTF8 +utf-8=UTF8 +UTF-8=UTF8 +utf16=UTF-16 +utf-16=UTF-16 +UTF16=UTF-16 + +## +Shift_JIS=Windows-31J + +MS932=Windows-31J +#SJIS=Shift_JIS \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/MIMEConstants.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/MIMEConstants.java new file mode 100644 index 000000000..29385ee51 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/MIMEConstants.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.util; + +/** + * A set of HTTP values that are defined by Network Working Group. + * http://www.ietf.org/ + * + * @version 1.0 + * @author Ilya Kanonirov (kio@isg.axmor.com) + */ +public class MIMEConstants { + public static final String HEADER_CONTENT_ID = "Content-ID"; + public static final String HEADER_CONTENT_TRANSFER_ENCODING = "Content-Transfer-Encoding"; + public static final String HEADER_CONTENT_TYPE = "Content-Type"; +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/MIMEUtils.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/MIMEUtils.java new file mode 100644 index 000000000..755f0d58d --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/MIMEUtils.java @@ -0,0 +1,138 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.util; + +import java.util.HashMap; +import java.util.Map; +import java.util.StringTokenizer; + +import org.eclipse.wst.wsi.internal.WSIException; + +/** + * Set of HTTPL related utilities. + * + * @version 1.0.1 + * @author Peter Brittenham + */ + +public final class MIMEUtils +{ + + /** + * Utility to present MIME header information as attribute-value pairs, + * based on ':' as attribute-value separator. + * @param mimeHeaderString an MIME header string. + * @param separators attribute-value separator list. + * @return MIME header information as attribute-value pairs. + * @throws WSIException if unable to create MIME header information + * as attribute-value pairs. + */ + public static Map getMimeHeaderTokens(String mimeHeaderString, String separators) + throws WSIException + { + StringTokenizer tokenizer = new StringTokenizer(mimeHeaderString, "\n\r\f"); + Map map = new HashMap(); + while (tokenizer.hasMoreTokens()) + { + String line = tokenizer.nextToken(); + int index = line.indexOf(separators); + if (index > 0 && index < line.length() - 1) + { + map.put(line.substring(0, index).toUpperCase(), line.substring(index + 1).trim()); + } + } + return map; + } + + /** + * Utility to take sub attribute value from MIME header + * @param mimeHeaderString an MIME header string. + * @param attributeName attribute name. + * @param subAttributeName sub attribute name. + * @return sub attribute value from MIME header. + * @throws WSIException if unable to get sub attribute value from MIME header. + */ + public static String getMimeHeaderSubAttribute(String mimeHeaderString, + String attributeName, String subAttributeName) + throws WSIException + { + // get attribute value + String value = + (String) getMimeHeaderTokens(mimeHeaderString,":").get(attributeName.toUpperCase()); + if(value != null) + { + // search sub attribute token + int idxQ = value.toUpperCase().indexOf(subAttributeName.toUpperCase()+"=\""); + int idx = value.toUpperCase().indexOf(subAttributeName.toUpperCase()+"="); + // if attribute is quoted + if (idxQ != -1) + { + idxQ += (subAttributeName+"=\"").length(); + int eIdxQ = value.indexOf("\"", idxQ); + if (eIdxQ != -1) + { + return value.substring(idxQ, eIdxQ); + } + else + { + return null; + } + } + // if attribute is not quoted + else if (idx != -1) + { + idx += (subAttributeName+"=").length(); + int eIdx = -1; + // find end space separator + if ((eIdx = value.indexOf(" ", idx)) != -1) + { + return value.substring(idx, eIdx); + } + // find coma separator + else if ((eIdx = value.indexOf(";", idx)) != -1) + { + return value.substring(idx, eIdx); + } + // this is last attribute + else + { + return value.substring(idx); + } + } + // if attribute do not found + else + { + return null; + } + } + return value; + } + + /** + * Utility to take attribute value from MIME header + * @param mimeHeaderString an MIME header string. + * @param attributeName attribute name. + * @return attribute value from MIME header. + * @throws WSIException if unable to get attribute value from MIME header. + */ + public static String getMimeHeaderAttribute(String mimeHeaderString, + String attributeName) + throws WSIException + { + String attributeValue = + (String) getMimeHeaderTokens(mimeHeaderString,":").get(attributeName.toUpperCase()); + // get first token + if((attributeValue != null) && (attributeValue.indexOf(";") != -1)) { + attributeValue = attributeValue.substring(0, attributeValue.indexOf(";")); + } + return attributeValue; + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/MessageList.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/MessageList.java new file mode 100644 index 000000000..f2f8eb7a8 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/MessageList.java @@ -0,0 +1,171 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.util; + +import java.util.ResourceBundle; + +/** + * This class creates and maintains a message list. + * + * @author Peter Brittenham (peterbr@us.ibm.com) + * @version 1.0.1 + */ +public class MessageList +{ + /** + * Message resource bundle. + */ + private ResourceBundle messageResourceBundle = null; + + /** + * Do not allow this object to be created with null constructor. + */ + private MessageList() + { + } + + /** + * Constructor for MessageList. + * @param resourceBundleName a resource bundle name. + */ + public MessageList(String resourceBundleName) + { + this.messageResourceBundle = ResourceBundle.getBundle(resourceBundleName); + } + + /** + * Get a message from the resource bundle. + * @param key a key. + * @param defaultMessage a default message. + * @return message from the resource bundle. + */ + public String getMessage(String key, String defaultMessage) + { + return getMessage(key, null, defaultMessage); + } + + /** + * Get a message from the resource bundle. + * @param key a key. + * @param messageData message data. + * @param defaultMessage a default message. + * @return message from the resource bundle. + */ + public String getMessage( + String key, + String messageData, + String defaultMessage) + { + String message = defaultMessage; + + try + { + // Get message + message = messageResourceBundle.getString(key); + } + + catch (Exception e) + { + // Ignore and just use default message + } + + if (messageData != null) + message += " " + messageData; + + // Return message + return message; + } + + /** + * Print a message from the resource bundle. + * @param key a key. + * @param defaultMessage a default message. + */ + public void printMessage(String key, String defaultMessage) + { + printMessage(key, null, defaultMessage); + } + + /** + * Print a message from the resource bundle. + * @param key a key. + * @param messageData message data. + * @param defaultMessage a default message. + */ + public void printMessage( + String key, + String messageData, + String defaultMessage) + { + // Print message + System.out.println(getMessage(key, messageData, defaultMessage)); + } + + /** + * Static get message. + * @param resourceBundleName resource bundle name. + * @param key a key. + * @param messageData message data. + * @param defaultMessage a default message. + * @return message. + */ + public static String getMessage( + String resourceBundleName, + String key, + String messageData, + String defaultMessage) + { + String message = defaultMessage; + ResourceBundle messageResourceBundle = null; + + try + { + // Get resource bundle + messageResourceBundle = ResourceBundle.getBundle(resourceBundleName); + + // Get message + message = messageResourceBundle.getString(key); + } + + catch (Exception e) + { + // Ignore and just use default message + } + + if (messageData != null) + message += " " + messageData; + + if (!message.endsWith(".")) + message += "."; + + // Return message + return message; + } + + /** + * Print message. + * @param resourceBundleName resource bundle name. + * @param key a key. + * @param messageData message data. + * @param defaultMessage a default message. + */ + public static void printMessage( + String resourceBundleName, + String key, + String messageData, + String defaultMessage) + { + // Print message + System.out.println( + getMessage(resourceBundleName, key, messageData, defaultMessage)); + } + +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/NullUtil.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/NullUtil.java new file mode 100644 index 000000000..e8f5cfc35 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/NullUtil.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.util; + +/** + * The utility class to automate null checking. + * + * @author Kulik + */ +public final class NullUtil +{ + /** + * The method checks objects on existence and compare with equals method. + * @param o1 first object. + * @param o2 second object. + * @return true if first object is equal to the second object. + */ + public static boolean equals(Object o1, Object o2) + { + return ((o1 == null && o2 == null) || (o1 != null && o1.equals(o2))); + } + + /** + * The method checks object on existence and returns its string representation with toString() method. + * @param o source object. + * @return string representation of object. + */ + public static String toString(Object o) + { + return (o == null) ? null : o.toString(); + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/OperationSignature.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/OperationSignature.java new file mode 100644 index 000000000..98c20496b --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/OperationSignature.java @@ -0,0 +1,772 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.util; + +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; + +import javax.wsdl.Binding; +import javax.wsdl.BindingOperation; +import javax.wsdl.Message; +import javax.wsdl.*; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.soap.*; +import javax.wsdl.extensions.soap.SOAPBody; +import javax.wsdl.extensions.soap.SOAPOperation; +import javax.xml.namespace.QName; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSITag; +import org.eclipse.wst.wsi.internal.wsdl.traversal.WSDLTraversal; +import org.eclipse.wst.wsi.internal.wsdl.traversal.WSDLTraversalContext; +import org.eclipse.wst.wsi.internal.wsdl.traversal.WSDLVisitor; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; + +/** + * The class implements mechanism for creating unique signature of operation. + * + * @author Kulik + */ +public final class OperationSignature +{ + // the flag indicates whether the messages is represented as document style + // vice versa is not generally true + private boolean isDocumentStyle = false; + private boolean isCreated = false; + private boolean isFault = false; + + protected List signature = new LinkedList(); + private Element firstBody = null; + + /** + * Class operates as container for matched operation. + * @author Kulik + */ + public final static class OperationMatch + { + final private String style; + final private BindingOperation operation; + final private List signature; + + /** + * Constructor. + * @param style operation style. + * @param signature a signature. + * @param operation a binding operation. + */ + protected OperationMatch( + String style, + List signature, + BindingOperation operation) + { + this.style = style; + this.signature = signature; + this.operation = operation; + } + /** + * Gets operation style. + * @return operation style. + */ + public String getOperationStyle() + { + return style; + } + /** + * Gets WSDL binding operation object. + * @return WSDL binding operation object. + */ + public BindingOperation getOperation() + { + return operation; + } + + /** + * Gets operation signature as list. + * @return operation signature as list. + */ + public List getSignature() + { + return signature; + } + } + + /** + * The class searches BindingOperation by the given OperationSigbnature. + * @author Kulik + */ + public final class Visitor implements WSDLVisitor + { + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.Part, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit(Part obj, Object parent, WSDLTraversalContext ctx) + { + } + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.Service, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit(Service obj, Object parent, WSDLTraversalContext ctx) + { + } + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.Types, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit(Types obj, Object parent, WSDLTraversalContext ctx) + { + } + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.Operation, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit(Operation obj, Object parent, WSDLTraversalContext ctx) + { + } + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.Input, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit(Input obj, Object parent, WSDLTraversalContext ctx) + { + } + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.Output, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit(Output obj, Object parent, WSDLTraversalContext ctx) + { + } + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.Fault, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit(Fault obj, Object parent, WSDLTraversalContext ctx) + { + } + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.Binding, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit(Binding obj, Object parent, WSDLTraversalContext ctx) + { + } + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.BindingOperation, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit( + BindingOperation obj, + Object parent, + WSDLTraversalContext ctx) + { + } + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.BindingInput, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit( + BindingInput obj, + Object parent, + WSDLTraversalContext ctx) + { + } + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.BindingOutput, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit( + BindingOutput obj, + Object parent, + WSDLTraversalContext ctx) + { + } + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(BindingFault, Object, WSDLTraversalContext) + */ + public void visit( + BindingFault obj, + Object parent, + WSDLTraversalContext ctx) + { + } + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(Import, Object, WSDLTraversalContext) + */ + public void visit(Import obj, Object parent, WSDLTraversalContext ctx) + { + } + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(Element, Object, WSDLTraversalContext) + */ + public void visit(Element obj, Object parent, WSDLTraversalContext ctx) + { + } + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(Message, Object, WSDLTraversalContext) + */ + public void visit(Message obj, Object parent, WSDLTraversalContext ctx) + { + } + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(Port, Object, WSDLTraversalContext) + */ + public void visit(Port obj, Object parent, WSDLTraversalContext ctx) + { + } + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(PortType, Object, WSDLTraversalContext) + */ + public void visit(PortType obj, Object parent, WSDLTraversalContext ctx) + { + } + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(Definition, Object, WSDLTraversalContext) + */ + public void visit(Definition obj, Object parent, WSDLTraversalContext ctx) + { + } + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(ExtensibilityElement, Object, WSDLTraversalContext) + */ + public void visit( + ExtensibilityElement obj, + Object parent, + WSDLTraversalContext ctx) + { + } + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(SOAPHeader, Object, WSDLTraversalContext) + */ + public void visit(SOAPHeader obj, Object parent, WSDLTraversalContext ctx) + { + } + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(SOAPHeaderFault, Object, WSDLTraversalContext) + */ + public void visit( + SOAPHeaderFault obj, + Object parent, + WSDLTraversalContext ctx) + { + } + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(SOAPFault, Object, WSDLTraversalContext) + */ + public void visit(SOAPFault obj, Object parent, WSDLTraversalContext ctx) + { + } + + private String requiredStyle = null; + private String soapAction = null; + private BindingOperation operation = null; + private TypesRegistry registry = null; + private boolean isSOAPActionRequired = false; + + /** + * Constructor. + */ + public Visitor() + { + super(); + // TODO Auto-generated constructor stub + } + + /** + * Constructor. + * @param requiredStyle required style. + * @param registry types registry. + */ + public Visitor(String requiredStyle, TypesRegistry registry) + { + this.requiredStyle = requiredStyle; + this.registry = registry; + } + + /** + * The method returns matched binding operation. + * @return BindingOperation + */ + public BindingOperation getMatchedOperation() + { + return operation; + } + + /** + * The method sets up required operation to be found. + * The possible values is rpc and document. + * @param requiredStyle operation style. + */ + public void setRequiredStyle(String requiredStyle) + { + this.requiredStyle = requiredStyle; + } + + /** + * The method indicates whether SOAP Action be included into operation. + * signature. + * @return true if SOAP Action isd required. + */ + public boolean isSOAPActionRequired() + { + return isSOAPActionRequired; + } + + /** + * Sets SOAP action to be included into signature. + */ + public void setSOAPActionRequired() + { + isSOAPActionRequired = true; + } + + /** + * internal method. + */ + public void visit( + SOAPBinding binding, + Object parent, + WSDLTraversalContext ctx) + { + String style = + (binding.getStyle() == null) + ? WSIConstants.ATTRVAL_SOAP_BIND_STYLE_DOC + : binding.getStyle(); + ctx.addParameter("style", style); + } + + /** + * internal method. + */ + public void visit( + SOAPOperation operation, + Object parent, + WSDLTraversalContext ctx) + { + soapAction = null; + String style = operation.getStyle(); + if (style == null) + style = (String) ctx.getParameter("style"); + if (!requiredStyle.equals(style)) + ctx.cancelBindingOperationProcessing(); + else + //if (isSOAPActionRequired) + soapAction = operation.getSoapActionURI(); + } + + /** + * internal method. + */ + public void visit(SOAPBody body, Object parent, WSDLTraversalContext ctx) + { + // assert parent instanceof BindingInput + BindingOperation bop = ctx.getBindingOperation(); + if (bop.getOperation() == null + || bop.getOperation().getInput() == null + || bop.getOperation().getInput().getMessage() == null) + return; + + Message msg = bop.getOperation().getInput().getMessage(); + List parts = + WSDLUtil.getParts(bop.getOperation(), msg, body, requiredStyle); + + QName additionalName = null; + // if operation is rpc, add to parts qname qith function name + if (WSIConstants.ATTRVAL_SOAP_BIND_STYLE_RPC.equals(requiredStyle)) + { + // found out target namespace + String namespace = body.getNamespaceURI(); + if (namespace == null || namespace.length() == 0) + // !! ATTENTION + // namespace should be retrieved from service target nameapce + namespace = ctx.getBinding().getQName().getNamespaceURI(); + + // insert operation name as first signature part + additionalName = + new QName(namespace, ctx.getBindingOperation().getName()); + } + + OperationSignature op = + new OperationSignature(parts, null, registry, false); + + if (additionalName != null) + op.getSignature().add(0, additionalName); + //if (isSOAPActionRequired) + //if (soapAction != null) + if (isSOAPActionRequired && soapAction != null) + op.getSignature().add(0, soapAction); + if (op.getSignature().equals(signature)) + { + // required operation is found + operation = ctx.getBindingOperation(); + ctx.cancelBindingOperationProcessing(); + ctx.cancelBindingProcessing(); + } + + else + { + op = new OperationSignature(parts, null, registry, true); + if (additionalName != null) + op.getSignature().add(0, additionalName); + + //if (isSOAPActionRequired) + //if (soapAction != null) + if (isSOAPActionRequired && soapAction != null) + op.getSignature().add(0, soapAction); + + if (op.getSignature().equals(signature)) + { + // required operation is found + operation = ctx.getBindingOperation(); + ctx.cancelBindingOperationProcessing(); + ctx.cancelBindingProcessing(); + } + } + } + } + + /** + * The constructor creates OperationSignature for SOAP message. + * @param doc a Document object. + */ + public OperationSignature(Document doc) + { + Element body = + XMLUtils.findChildElement( + doc.getDocumentElement(), + WSITag.ELEM_SOAP_BODY); + processParts(body, false); + isDocumentStyle |= (signature.size() > 1); + } + + /** + * The constructor creates OperationSIgnature for + * list of Part objects and given WSDL document within these + * parts are defined. + * + * @param parts a list of Part objects. + * @param wsdlDocument a WSDL document. + * @param registry a types registry. + * @param partial a partial status. + */ + public OperationSignature( + List parts, + Document wsdlDocument, + TypesRegistry registry, + boolean partial) + { + if (parts != null) + { + Iterator it = parts.iterator(); + + while (it.hasNext()) + { + Part part = (Part) it.next(); + String localName = (partial) ? part.getName() : null; + QName typeName = part.getTypeName(); + QName elementName = part.getElementName(); + + String namespace = ""; + + // If type name is not null, then a type element was used so it should be an RPC style signature + if (typeName != null) + { + // Part wrappers do not have namespaces + namespace = ""; + + if (localName == null) + localName = typeName.getLocalPart(); + } + + // If element name is not null, then it should be a document style signature + else if (elementName != null) + { + namespace = elementName.getNamespaceURI(); + + if (localName == null) + localName = elementName.getLocalPart(); + } + + signature.add(new QName(namespace, localName)); + } + } + + isCreated = true; + } + + /** + * The method recreates OperationSignature with assumption that operation is + * RPC. + */ + public void createRPCSignature() + { + isCreated = false; + if (firstBody == null) + return; + processParts(firstBody, true); + isDocumentStyle = false; + } + + /** + * Internal method processes WSDL parts and creates operation signature. + * @param parent + */ + private void processParts(Node parent, boolean processWrapper) + { + if (parent != null) + { + Node n = parent.getFirstChild(); + + // variable indicates that first tag is processed + boolean isFirst = true; + // iterate all bodies + while (n != null) + { + if (Node.ELEMENT_NODE == n.getNodeType()) + { + if (isFirst && firstBody == null) + { + isFirst = false; + firstBody = (Element) n; + // check soapenv:fault + if (XMLUtils.equals(n, WSITag.ELEM_SOAP_FAULT)) + { + isFault = true; + isCreated = false; + return; + } + } + + String namespace = n.getNamespaceURI(); + String localName = n.getLocalName(); + + /*I have no idea why this code is in here since it makes no sense at all, so I am commenting it out + // try to get xsi:tag + if (XMLUtils.getAttribute((Element) n, WSITag.ATTR_XSI_TYPE) != null) { + // we suppose that RPC style does not use xsi:type attribute + isDocumentStyle = true; + Attr xsiType = XMLUtils.getAttribute((Element) n, WSITag.ATTR_XSI_TYPE); + + String xsiValue = xsiType.getNodeValue(); + int i = xsiValue.indexOf(':'); + if (i != -1) + { + namespace = XMLUtils.findNamespaceURI(n, xsiValue.substring(0, i)); + localName = xsiValue.substring(i+1); + } + } + */ + + // If this is rpc-literal and processing a part (not the wrapper), then the part should not have a namespace + // And if it does, then one of the test assertions will detect it + if (!isDocumentStyle && processWrapper) + { + namespace = ""; + } + + if (namespace == null || namespace.length() == 0) + { + if (isDocumentStyle) + { + //Element firstChild = null; + Node it = n.getFirstChild(); + while (it != null && !(it instanceof Element)) + it = it.getNextSibling(); + if (it != null) + namespace = it.getNamespaceURI(); + } + } + + // normalize namespaces. All empty namespaces -> null + if (namespace != null && namespace.length() == 0) + namespace = null; + + // put part into signature + signature.add(new QName(namespace, localName)); + } + + n = n.getNextSibling(); + } + } + else + { + isCreated = false; // not found ? + return; + } + + isCreated = true; + } + + /** + * Indicates whether operation has document style or RPC. + * @return true if operation has document style. + */ + public boolean isDocumentStyle() + { + return isDocumentStyle; + } + + /** + * Indicates whether WSDL fault parts should be included into signature or + * not. + * @return true if WSDL fault parts should be included into signature. + */ + public boolean isFault() + { + return isFault; + } + + /** + * Indicates that operation signature was created. + * @return true if operation signature was created. + */ + public boolean isCreated() + { + return isCreated; + } + + /** + * Gets operation signature created for SOAP message. + * @return operation signature created for SOAP message. + */ + public List getSignature() + { + return signature; + } + + /** + * @see java.lang.Object#hashCode() + */ + public int hashCode() + { + return signature.hashCode(); + } + + /** + * @see java.lang.Object#equals(Object) + */ + public boolean equals(Object o) + { + if (o instanceof OperationSignature) + return signature.equals(((OperationSignature) o).getSignature()); + return false; + } + + /** + * The method matches operation based on the given SOAP message request, + * WSDL binding, and soapAction. + * + * @param inputMessage an SOAP message request. + * @param soapAction a soap action. + * @param binding a WSDL binding. + * @param registry a types registry. + * @return OperationMatch object. + */ + public static OperationMatch matchOperation( + Document inputMessage, + String soapAction, + Binding binding, + TypesRegistry registry) + { + return matchOperation(inputMessage, soapAction, binding, registry, true); + } + + /** + * The method matches operation based on the given SOAP message request, + * WSDL binding, and soapAction. + * + * @param inputMessage SOAP message request. + * @param soapAction a soap action. + * @param binding a WSDL binding. + * @param registry a types registry. + * @param soapActionRequired must process the soapAction value even if it is null + * @return OperationMatch object. + */ + public static OperationMatch matchOperation( + Document inputMessage, + String soapAction, + Binding binding, + TypesRegistry registry, + boolean soapActionRequired) + { + // Parse request message + OperationSignature signature = new OperationSignature(inputMessage); + if (!signature.isCreated()) + return null; + + // first of all looking for document style + // because rpc style is subset of document style + OperationSignature.Visitor resolver = + signature.new Visitor(WSIConstants.ATTRVAL_SOAP_BIND_STYLE_DOC, registry); + + // normalize SOAPAction + if (soapAction != null + && soapAction.length() > 1 + && soapAction.charAt(0) == '"' + && soapAction.charAt(soapAction.length() - 1) == '"') + soapAction = soapAction.substring(1, soapAction.length() - 1); + + // if soap action URI processing required + // if soap action URI processing required + // analyze SOAPAction after parts being processed + // put SOAPAction into signature + //if (soapAction != null && soapAction.length() > 0) { + if (soapAction != null) + { + signature.getSignature().add(0, soapAction); + } + + if (soapActionRequired) + resolver.setSOAPActionRequired(); + + WSDLTraversal traversal = new WSDLTraversal(); + //VisitorAdaptor.adapt(resolver); + traversal.setVisitor(resolver); + traversal.visitSOAPBinding(true); + traversal.visitSOAPBody(true); + traversal.visitSOAPOperation(true); + + traversal.ignoreReferences(); + traversal.ignoreBindingOutput(); + traversal.traverse(binding); + + BindingOperation operation = resolver.getMatchedOperation(); + if (operation == null && !signature.isDocumentStyle()) + { + resolver.setRequiredStyle(WSIConstants.ATTRVAL_SOAP_BIND_STYLE_RPC); + signature.createRPCSignature(); + traversal.traverse(binding); + operation = resolver.getMatchedOperation(); + if (operation == null) + return null; + } + + return new OperationMatch( + resolver.requiredStyle, + signature.getSignature(), + resolver.getMatchedOperation()); + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/Pair.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/Pair.java new file mode 100644 index 000000000..f59425c0a --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/Pair.java @@ -0,0 +1,77 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.util; + +/** + * The class represents pair of values. + * + * @author Kulik + */ +public final class Pair +{ + final private Object first; + final private Object second; + + /** + * Constructor. + * @param first object + * @param second object. + */ + public Pair(Object first, Object second) + { + this.first = first; + this.second = second; + } + + /** + * Gets first object. + * @return Object + */ + public Object getFirst() + { + return first; + } + + /** + * Gets second object. + * @return Object + */ + public Object getSecond() + { + return second; + } + + /** + * @see java.lang.Object#equals(Object) + */ + public boolean equals(Object o) + { + if (o == null || !(o instanceof Pair)) + return false; + Pair p = (Pair) o; + return ( + NullUtil.equals(p.getFirst(), first) + && NullUtil.equals(p.getSecond(), second)); + } + + /** + * @see java.lang.Object#hashCode() + */ + public int hashCode() + { + int code = 0; + if (first != null) + code += first.hashCode(); + if (second != null) + code += second.hashCode(); + return code; + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/SetCookie2Validator.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/SetCookie2Validator.java new file mode 100644 index 000000000..75b3c07fc --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/SetCookie2Validator.java @@ -0,0 +1,649 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.util; + +import java.net.MalformedURLException; +import java.net.URL; +import java.util.Vector; + +/** + * This class checks the cookies conform to RFC2965. + * + * @author Baltak + */ +public class SetCookie2Validator +{ + + private Vector commentVect = new Vector(); + private Vector commentURLVect = new Vector(); + private Vector domainVect = new Vector(); + private Vector max_AgeVect = new Vector(); + private Vector pathVect = new Vector(); + private Vector portVect = new Vector(); + private Vector versionVect = new Vector(); + + private boolean comment = false; + private boolean commentURL = false; + private boolean domain = false; + private boolean max_age = false; + private boolean path = false; + private boolean port = false; + private boolean version = false; + + /** + * Method resetFlags. + */ + private void resetFlags() + { + comment = false; + commentURL = false; + domain = false; + max_age = false; + path = false; + port = false; + version = false; + } + + /** + * Check if the string satisfy the "Set-Cookie2" header value. + * @param str String + * @return boolean + */ + public boolean isSetCookie2(String str) + { + + try + { + int index = 0; + int newIndex = 0; + while (true) + { + newIndex = getLastCookie(str, index); + if (index == newIndex) + return false; + // skip spaces + index = newIndex; + index = skipSpaces(str, index); + if (index == str.length()) + { + return true; + } + else + { + if (str.charAt(index) != ',') + return false; + index++; + // skip spaces + index = skipSpaces(str, index); + } + + } + } + catch (Throwable th) + { + return false; + } + + } + + /** + * Method getLastCookie. + * @param str + * @param startIndex + * @return int + */ + private int getLastCookie(String str, int startIndex) + { + + resetFlags(); + + int index = startIndex; + // find token + int newIndex = BasicRules.getLastToken(str, index); + if (index == newIndex) + return startIndex; + + index = newIndex; + if (index == str.length()) + return startIndex; + + // if not '=' - error + if (str.charAt(index) != '=') + return startIndex; + + index++; + if (index == str.length()) + return startIndex; + + // get value + newIndex = getLastValue(str, index); + if (index == newIndex) + return startIndex; + + while (true) + { + index = newIndex; + if (index == str.length()) + return index; + + if (str.charAt(index) != ';') + return index; + index++; + // skip spaces + index = skipSpaces(str, index); + + if (index == str.length()) + return startIndex; + newIndex = getLastSetCookieAv(str, index); + if (index == newIndex) + return startIndex; + } + } + + /** + * Method getLastValue. + * @param str + * @param startIndex + * @return int + */ + private int getLastValue(String str, int startIndex) + { + + int index = BasicRules.getLastToken(str, startIndex); + if (index != startIndex) + return index; + index = BasicRules.getLastQuotedString(str, startIndex); + if (index != startIndex) + return index; + + return startIndex; + } + + /** + * Method getLastSetCookieAv. + * @param str + * @param startIndex + * @return int + */ + private int getLastSetCookieAv(String str, int startIndex) + { + + int index = startIndex; + int newIndex = 0; + + String token = str.substring(index, BasicRules.getLastToken(str, index)); + + if (str.startsWith("Comment=", index)) + { + index += "Comment=".length(); + newIndex = getLastValue(str, index); + if (index == newIndex) + return startIndex; + // debug -> + String qqq = getValue(str, index, newIndex); + commentVect.add(qqq); + // debug <- + comment = true; + return newIndex; + } + else if (str.startsWith("CommentURL=", index)) + { + index += "CommentURL=".length(); + + if (str.charAt(index) != '\"') + return startIndex; + + newIndex = str.indexOf('\"', index + 1); + if (newIndex == -1) + return startIndex; + try + { + URL url = new URL(str.substring(index + 1, newIndex)); + } + catch (MalformedURLException mue) + { + return startIndex; + } + // debug -> + String qqq = getValue(str, index + 1, newIndex); + commentURLVect.add(qqq); + // debug <- + newIndex++; + commentURL = true; + return newIndex; + } + else if (str.startsWith("Discard", index)) + { + return startIndex + "Discard".length(); + } + else if (str.startsWith("Domain=", index)) + { + index += "Domain=".length(); + + newIndex = getLastValue(str, index); + if (index == newIndex) + return startIndex; + + // debug -> + String qqq = getValue(str, index, newIndex); + domainVect.add(qqq); + // debug <- + domain = true; + return newIndex; + } + else if (str.startsWith("Max-Age=", index)) + { + index += "Max-Age=".length(); + + newIndex = getLastValue(str, index); + if (index == newIndex) + return startIndex; + + String qqq = getValue(str, index, newIndex); + try + { + Integer.parseInt(qqq); + } + catch (NumberFormatException nfe) + { + return startIndex; + } + // debug -> + max_AgeVect.add(qqq); + // debug <- + max_age = true; + return newIndex; + } + else if (str.startsWith("Path=", index)) + { + index += "Path=".length(); + + newIndex = getLastValue(str, index); + if (index == newIndex) + return startIndex; + + String qqq = getValue(str, index, newIndex); + if (path == false) + pathVect.add(qqq); + path = true; + return newIndex; + } + else if (str.startsWith("Port", index)) + { + index += "Port".length(); + port = true; + if (str.charAt(index) != '=') + return index; + + index++; + if (str.charAt(index) != '\"') + return startIndex; + + index++; + newIndex = getLastPortList(str, index); + if (index == newIndex) + return startIndex; + + // debug -> + String qqq = getValue(str, index, newIndex); + portVect.add(qqq); + // debug <- + + index = newIndex; + if (str.charAt(index) != '\"') + return startIndex; + index++; + return index; + + } + else if (str.startsWith("Secure", index)) + { + return startIndex + "Secure".length(); + } + else if (str.startsWith("Version=", index)) + { + index += "Version=".length(); + + newIndex = getLastDIGIT(str, index); + if (index == newIndex) + return startIndex; + + // debug -> + String qqq = getValue(str, index, newIndex); + versionVect.add(qqq); + // debug <- + version = true; + return newIndex; + } + else + { + return startIndex; + } + } + + /** + * Method getLastPortList. + * @param str + * @param startIndex + * @return int + */ + private int getLastPortList(String str, int startIndex) + { + int index = startIndex; + int newIndex = 0; + + while (true) + { + newIndex = getLastDIGIT(str, index); + if (index == newIndex) + return startIndex; + + index = newIndex; + if (str.charAt(index) != ',') + return index; + index++; + } + } + + /** + * Method getLastDIGIT. + * @param str + * @param startIndex + * @return int + */ + private int getLastDIGIT(String str, int startIndex) + { + int index = startIndex; + for (; index < str.length(); index++) + { + if (!BasicRules.isDIGIT(str.charAt(index))) + return index; + } + return index; + } + + /** + * Check if the string satisfy the "Cookie" header value. + * @param str String + * @return boolean + */ + public boolean isCookie(String str) + { + int index = 0; + int newIndex = 0; + + try + { + newIndex = getLastVersion(str, index); + if (index == newIndex) + return false; + + index = newIndex; + index = skipSpaces(str, index); + if (str.charAt(index) != ';' && str.charAt(index) != ',') + return false; + + index++; + index = skipSpaces(str, index); + + while (true) + { + newIndex = getLastCookiesValue(str, index); + if (index == newIndex) + return false; + + index = newIndex; + if (index == str.length()) + return true; + + if (str.charAt(index) != ';' && str.charAt(index) != ',') + return false; + index++; + index = skipSpaces(str, index); + } + } + catch (Throwable th) + { + return false; + } + } + + /** + * Method getLastVersion. + * @param str + * @param startIndex + * @return int + */ + private int getLastVersion(String str, int startIndex) + { + int index = startIndex; + int newIndex = 0; + if (!str.startsWith("$Version=")) + return startIndex; + index += "$Version=".length(); + newIndex = getLastValue(str, index); + if (index == newIndex) + return startIndex; + + return newIndex; + } + + /** + * Method getLastCookiesValue. + * @param str + * @param startIndex + * @return int + */ + private int getLastCookiesValue(String str, int startIndex) + { + int index = startIndex; + int newIndex = 0; + int oldIndex = 0; + + // find token + newIndex = BasicRules.getLastToken(str, index); + if (index == newIndex) + return startIndex; + + index = newIndex; + if (index == str.length()) + return startIndex; + + // if not '=' - error + if (str.charAt(index) != '=') + return startIndex; + + index++; + if (index == str.length()) + return startIndex; + + // get value + newIndex = getLastValue(str, index); + if (index == newIndex) + return startIndex; + + index = newIndex; + if (index == str.length()) + return index; + + if (str.charAt(index) != ';') + return index; + + // process [";" path] [";" domain] [";" port] + oldIndex = index; + index++; + if (index == str.length()) + return startIndex; + + index = skipSpaces(str, index); + if (index == str.length()) + return startIndex; + + // process path + newIndex = getLastPath(str, index); + if (index != newIndex) + { + index = newIndex; + if (index == str.length()) + return index; + + if (str.charAt(index) != ';') + return index; + + oldIndex = index; + index++; + if (index == str.length()) + return startIndex; + + index = skipSpaces(str, index); + if (index == str.length()) + return startIndex; + + } + + // process domain + newIndex = getLastDomain(str, index); + if (index != newIndex) + { + index = newIndex; + if (index == str.length()) + return index; + + if (str.charAt(index) != ';') + return index; + + oldIndex = index; + index++; + if (index == str.length()) + return startIndex; + + index = skipSpaces(str, index); + if (index == str.length()) + return startIndex; + + } + + // process port + newIndex = getLastPort(str, index); + if (index != newIndex) + return newIndex; + else + return oldIndex; + } + + /** + * Method getLastPath. + * @param str + * @param startIndex + * @return int + */ + private int getLastPath(String str, int startIndex) + { + int index = startIndex; + int newIndex = 0; + + if (!str.startsWith("$Path=", index)) + return startIndex; + index += "$Path=".length(); + newIndex = getLastValue(str, index); + if (index == newIndex) + return startIndex; + + return newIndex; + } + + /** + * Method getLastDomain. + * @param str + * @param startIndex + * @return int + */ + private int getLastDomain(String str, int startIndex) + { + int index = startIndex; + int newIndex = 0; + + if (!str.startsWith("$Domain=", index)) + return startIndex; + index += "$Domain=".length(); + newIndex = getLastValue(str, index); + if (index == newIndex) + return startIndex; + + return newIndex; + } + + /** + * Method getLastPort. + * @param str + * @param startIndex + * @return int + */ + private int getLastPort(String str, int startIndex) + { + int index = startIndex; + int newIndex = 0; + + if (!str.startsWith("$Port", index)) + return startIndex; + + index += "$Port".length(); + if (str.charAt(index) != '=') + return index; + + index++; + if (str.charAt(index) != '\"') + return startIndex; + + index++; + newIndex = getLastPortList(str, index); + if (index == newIndex) + return startIndex; + + index = newIndex; + if (str.charAt(index) != '\"') + return startIndex; + index++; + return index; + } + + /** + * Method skipSpaces. + * @param str + * @param index + * @return int + */ + private int skipSpaces(String str, int index) + { + for (; index < str.length(); index++) + if (!BasicRules.isSP(str.charAt(index))) + break; + return index; + } + + /** + * Method getValue. + * @param str + * @param beg + * @param end + * @return String + */ + private String getValue(String str, int beg, int end) + { + String qqq = null; + if (str.charAt(beg) == '\"') + qqq = str.substring(beg + 1, end - 1); + else + qqq = str.substring(beg, end); + return qqq; + } + +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/StringTokenizer.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/StringTokenizer.java new file mode 100644 index 000000000..d537c7ffe --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/StringTokenizer.java @@ -0,0 +1,213 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + ********************************************************************************/ +package org.eclipse.wst.wsi.internal.util; + +/** + * String tokenizer. + * + * @author: Kulik + */ +final public class StringTokenizer +{ + private char[] spaceDel; + private char[] del; + private char[] allDel; + + /** + * Enumeration of strings. + * @author Kulik + */ + private class StringTokenizerEnumeration implements java.util.Enumeration + { + private final char[] str; + private final int size; + private int index; + private String next; + + /** + * Constructor. + * @param s + */ + StringTokenizerEnumeration(char[] s) + { + str = s; + size = str.length; + index = 0; + + // skip space delimiters + while (index < size && contain(str[index], spaceDel)) + index++; + } + + /** + * @see java.util.Enumeration#hasMoreElements() + */ + public boolean hasMoreElements() + { + return (index < size); + } + + /** + * @see java.util.Enumeration#nextElement() + */ + public Object nextElement() + { + if (index >= size) + throw new java.util.NoSuchElementException( + "StringTokenizer enumeration"); + + // skip delimiters + int begStr = index; + if (index < size && contain(str[index], del)) + index++; + + // skip word + if (begStr == index) + while (index < size && !contain(str[index], allDel)) + index++; + + int endStr = index; + + // skip space delimiters + while (index < size && contain(str[index], spaceDel)) + index++; + + return String.copyValueOf(str, begStr, endStr - begStr); + } + + /** + * @see java.lang.Object#toString() + */ + public String toString() + { + int i = index; + String s = (String) nextElement(); + index = i; + return s; + } + } + + /** + * StringTokenizer constructor. + * @param spaceDelimiters the set of delimiters to be ignored + * @param delimiters the set of delimiters to be remained. + */ + public StringTokenizer(char[] spaceDelimiters, char[] delimiters) + { + super(); + + if (spaceDelimiters != null) + { + spaceDel = new char[spaceDelimiters.length]; + System.arraycopy(spaceDelimiters, 0, spaceDel, 0, spaceDelimiters.length); + sort(spaceDel); + } + else + spaceDel = null; + + if (delimiters != null) + { + del = new char[delimiters.length]; + System.arraycopy(delimiters, 0, del, 0, delimiters.length); + sort(del); + } + else + del = null; + + if (del != null && spaceDel != null) + { + allDel = new char[del.length + spaceDel.length]; + System.arraycopy(del, 0, allDel, 0, del.length); + System.arraycopy(spaceDel, 0, allDel, del.length, spaceDel.length); + } + else if (del != null) + allDel = del; + else + allDel = spaceDel; + + sort(allDel); + } + /** + * Parses string. + * @return java.util.Enumeration + * @param s java.lang.String + */ + public java.util.Enumeration parse(String s) + { + if (s == null) + throw new IllegalArgumentException("StringTokenizer : String cannot be NULL"); + + return new StringTokenizerEnumeration(s.toCharArray()); + } + + /** + * Binary search. + * @return boolean + * @param c char + */ + private static boolean contain(char c, char[] a) + { + if (a == null) + return false; + + int l = 0, r = a.length - 1, center; + while (l < r) + { + center = (l + r) / 2; + if (c > a[center]) + l = center + 1; + else + r = center; + } + + return a[l] == c; + } + /** + * Heap sort + * @param c char[] + */ + static private void sort(char[] c) + { + if (c != null) + { + int j, k; + char ci; + + // push heap + for (int i = 1; i < c.length; i++) + { + j = ((k = i) - 1) / 2; + ci = c[i]; + while (k > 0 && c[j] < ci) + { + c[k] = c[j]; + j = ((k = j) - 1) / 2; + } + c[k] = ci; + } + + // pop heap + for (int i = c.length - 1; i > 0; i--) + { + j = 2; + k = 0; + ci = c[0]; + while (j <= i) + { + c[k] = (c[j - 1] > c[j]) ? c[--j] : c[j]; + j = ((k = j) + 1) * 2; + } + c[k] = c[i]; + c[i] = ci; + } + } + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/TestUtils.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/TestUtils.java new file mode 100644 index 000000000..2c37b22b7 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/TestUtils.java @@ -0,0 +1,192 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.util; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.common.AddStyleSheet; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; +import org.eclipse.wst.wsi.internal.ToolInfo; + +import org.w3c.dom.Element; + +import java.io.*; + +/** + * Test Utility class. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public final class TestUtils +{ + /** + * Format a style sheet declaration from the addStyleSheet element. + * @param element an Element object. + * @param addStyleSheet an addStyleSheet element. + * @param defaultHref default href. + */ + public static final void parseAddStyleSheet( + Element element, + AddStyleSheet addStyleSheet, + String defaultHref) + { + addStyleSheet.setHref( + XMLUtils.getAttributeValue(element, WSIConstants.ATTR_HREF, defaultHref)); + addStyleSheet.setType( + XMLUtils.getAttributeValue( + element, + WSIConstants.ATTR_TYPE, + WSIConstants.DEFAULT_XSL_TYPE)); + addStyleSheet.setTitle( + XMLUtils.getAttributeValue(element, WSIConstants.ATTR_TITLE)); + addStyleSheet.setMedia( + XMLUtils.getAttributeValue(element, WSIConstants.ATTR_MEDIA)); + addStyleSheet.setCharset( + XMLUtils.getAttributeValue(element, WSIConstants.ATTR_CHARSET)); + addStyleSheet.setAlternate( + XMLUtils.getAttributeValue(element, WSIConstants.ATTR_ALTERNATE)); + } + + /** + * Display tool name and copyright notice. + * @param toolInfo a ToolInfo object. + */ + public static void printToolInfo(ToolInfo toolInfo) + { + System.out.println( + "Conformance " + + toolInfo.getName() + + " Tool" + + ", Version: " + + toolInfo.getVersion() + + ", Release Date: " + + toolInfo.getReleaseDate()); + System.out.println(WSIConstants.COPYRIGHT); + System.out.println(" "); + } + + /** + * Get XML comment used in log and report file. + * @return XML comment used in log and report file. + */ + public static String getXMLComment() + { + String comment = null; + String readLine = null; + + try + { + // Add required comments (copyright, etc.) + BufferedReader bufferedReader = + new BufferedReader( + new InputStreamReader( + Utils.getInputStream(WSIConstants.COMMENTS_FILE))); + + // Initialize string to empty string + comment = ""; + + while (bufferedReader.ready()) + { + if ((readLine = bufferedReader.readLine()) != null) + comment += readLine + WSIConstants.LINE_SEPARATOR; + } + } + + catch (Exception e) + { + // Ignore exception and just return null + } + + return comment; + } + + /** + * Get schema location for XML schema. + * @return schema location for XML schema. + */ + public static String getXMLSchemaLocation() + { + return getSchemaLocation( + WSIProperties.PROP_XML_SCHEMA, + WSIProperties.DEF_XML_SCHEMA); + } + + /** + * Get SOAP schema location. + * @return SOAP schema location. + */ + public static String getSOAPSchemaLocation() + { + return getSchemaLocation( + WSIProperties.PROP_SOAP_SCHEMA, + WSIProperties.DEF_SOAP_SCHEMA); + } + + /** + * Get WSDL schema location. + * @return WSDL schema location. + */ + public static String getWSDLSchemaLocation() + { + return getSchemaLocation( + WSIProperties.PROP_WSDL_SCHEMA, + WSIProperties.DEF_WSDL_SCHEMA); + } + + /** + * Get WSDL SOAP schema location. + * @return WSDL SOAP schema location. + */ + public static String getWSDLSOAPSchemaLocation() + { + return getSchemaLocation( + WSIProperties.PROP_WSDL_SOAP_SCHEMA, + WSIProperties.DEF_WSDL_SOAP_SCHEMA); + } + /** + * Get WSDL schema location. + * @return WSDL schema location. + */ + private static String getSchemaLocation( + String propertyName, + String defaultValue) + { + String schemaLocation = null; + + // Get the wsi.home system property + String wsiHome = System.getProperty(WSIProperties.PROP_WSI_HOME); + String fileLocation = WSIProperties.getProperty(propertyName, defaultValue); + + // If the file location is specified in the wsi.properties file then build location + if (fileLocation != null) + { + // If wsi.home is set, then use it + if (wsiHome != null) + { + schemaLocation = wsiHome; + } + if (schemaLocation == null) + { + schemaLocation = fileLocation; + } + else + { + if (!schemaLocation.endsWith("/")) + { + schemaLocation += "/"; + } + + schemaLocation += fileLocation; + } + } + return schemaLocation; + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/TypesRegistry.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/TypesRegistry.java new file mode 100644 index 000000000..0edbada69 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/TypesRegistry.java @@ -0,0 +1,559 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.util; + +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import javax.wsdl.*; +import javax.wsdl.Import; +import javax.wsdl.Types; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.UnknownExtensibilityElement; +import javax.wsdl.extensions.soap.*; +import javax.xml.namespace.QName; + +import org.eclipse.wst.wsi.internal.WSITag; +import org.eclipse.wst.wsi.internal.profile.validator.BaseValidator; +import org.eclipse.wst.wsi.internal.wsdl.traversal.WSDLTraversal; +import org.eclipse.wst.wsi.internal.wsdl.traversal.WSDLTraversalContext; +import org.eclipse.wst.wsi.internal.wsdl.traversal.WSDLVisitor; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; +import org.w3c.dom.Attr; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; + + +/** + * The class extracts XSD schema information from the given WSDL. + * + * @author Kulik + */ +public final class TypesRegistry implements WSITag, WSDLVisitor +{ + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.Part, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit(Part obj, Object parent, WSDLTraversalContext ctx) + { + } + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.Service, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit(Service obj, Object parent, WSDLTraversalContext ctx) + { + } + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(Types, Object, + * WSDLTraversalContext) + */ + public void visit(Types obj, Object parent, WSDLTraversalContext ctx) + { + } + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(Operation, Object, + * WSDLTraversalContext) + */ + public void visit(Operation obj, Object parent, WSDLTraversalContext ctx) + { + } + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(Input, Object, + * WSDLTraversalContext) + */ + public void visit(Input obj, Object parent, WSDLTraversalContext ctx) + { + } + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(Output, Object, + * WSDLTraversalContext) + */ + public void visit(Output obj, Object parent, WSDLTraversalContext ctx) + { + } + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(Fault, Object, + * WSDLTraversalContext) + */ + public void visit(Fault obj, Object parent, WSDLTraversalContext ctx) + { + } + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(Binding, Object, + * WSDLTraversalContext) + */ + public void visit(Binding obj, Object parent, WSDLTraversalContext ctx) + { + } + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(BindingOperation, Object, + * WSDLTraversalContext) + */ + public void visit( + BindingOperation obj, + Object parent, + WSDLTraversalContext ctx) + { + } + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(BindingInput, Object, + * WSDLTraversalContext) + */ + public void visit(BindingInput obj, Object parent, WSDLTraversalContext ctx) + { + } + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(BindingOutput, Object, + * WSDLTraversalContext) + */ + public void visit(BindingOutput obj, Object parent, WSDLTraversalContext ctx) + { + } + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(BindingFault, Object, + * WSDLTraversalContext) + */ + public void visit(BindingFault obj, Object parent, WSDLTraversalContext ctx) + { + } + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(Element, Object, + * WSDLTraversalContext) + */ + public void visit(Element obj, Object parent, WSDLTraversalContext ctx) + { + } + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(Message, Object, + * WSDLTraversalContext) + */ + public void visit(Message obj, Object parent, WSDLTraversalContext ctx) + { + } + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(Port, Object, + * WSDLTraversalContext) + */ + public void visit(Port obj, Object parent, WSDLTraversalContext ctx) + { + } + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(PortType, Object, + * WSDLTraversalContext) + */ + public void visit(PortType obj, Object parent, WSDLTraversalContext ctx) + { + } + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(Definition, Object, + * WSDLTraversalContext) + */ + public void visit(Definition obj, Object parent, WSDLTraversalContext ctx) + { + } + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(ExtensibilityElement, + * Object, WSDLTraversalContext) + */ + public void visit( + ExtensibilityElement obj, + Object parent, + WSDLTraversalContext ctx) + { + } + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(SOAPBinding, Object, + * WSDLTraversalContext) + */ + public void visit(SOAPBinding obj, Object parent, WSDLTraversalContext ctx) + { + } + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(SOAPBody, Object, + * WSDLTraversalContext) + */ + public void visit(SOAPBody obj, Object parent, WSDLTraversalContext ctx) + { + } + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(SOAPHeader, Object, + * WSDLTraversalContext) + */ + public void visit(SOAPHeader obj, Object parent, WSDLTraversalContext ctx) + { + } + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(SOAPHeaderFault, Object, + * WSDLTraversalContext) + */ + public void visit( + SOAPHeaderFault obj, + Object parent, + WSDLTraversalContext ctx) + { + } + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(SOAPFault, Object, + * WSDLTraversalContext) + */ + public void visit(SOAPFault obj, Object parent, WSDLTraversalContext ctx) + { + } + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(SOAPOperation, Object, + * WSDLTraversalContext) + */ + public void visit(SOAPOperation obj, Object parent, WSDLTraversalContext ctx) + { + } + + private Map element2Type = new HashMap(); + private Set extendsArray = new HashSet(); + private Set usesWsdlArrayType = new HashSet(); + + protected BaseValidator baseValidator = null; + + /** + * Constructor creates the types registry. by the given WSDL definition + * object. + * + * @param def a WSDL definition. + * @param baseValidator a base validator. + */ + public TypesRegistry(Definition def, BaseValidator baseValidator) + { + this.baseValidator = baseValidator; + if (def == null) + throw new IllegalArgumentException("Definition can not be null"); + + WSDLTraversal traversal = new WSDLTraversal(); + //VisitorAdaptor.adapt(this); + traversal.setVisitor(this); + traversal.visitImport(true); + + processTypes(def.getTypes(), def.getDocumentBaseURI()); + traversal.traverse(def); + } + + /** + * Constructor creates the types registry by given WSDL types object and + * location context URI. + * @param types WSDL types object. + * @param context location context URI. + * @param baseValidator a base validator. + */ + public TypesRegistry( + Types types, + String context, + BaseValidator baseValidator) + { + this.baseValidator = baseValidator; + processTypes(types, context); + } + + /** + * The method returns type's qname by given element's qname. + * @param elementName a qualified element name. + * @return type's qname by given element's qname. + */ + public QName getType(QName elementName) + { + return (QName) element2Type.get(elementName); + } + + /** + * The method returns set of types which is array attribute. + * @return set of types which is array attribute. + */ + public Set getArrayTypes() + { + Set s = new HashSet(); + s.addAll((Collection) usesWsdlArrayType); + s.addAll((Collection) extendsArray); + return s; + } + + /** + * The method returns set of elements defined in types element. + * @return set of elements defined in types element. + */ + public Set getElementList() + { + return this.element2Type.keySet(); + } + + /** + * The method returns true if the given type declares wsdl:arrayType + * attribute within declaration. + * @param type a type. + * @return true if the given type declares wsdl:arrayType + * attribute within declaration. + */ + public boolean isUsesWSDLArrayType(QName type) + { + return usesWsdlArrayType.contains(type); + } + + /** + * The method returns true if given type extends soapenc:Array type. + * @param type a type. + * @return true if given type extends soapenc:Array type. + */ + public boolean isExtendsArray(QName type) + { + return extendsArray.contains(type); + } + + /* (non-Javadoc) + * @see org.wsi.wsdl.traversal.WSDLVisitor#visit(javax.wsdl.Import, java.lang.Object, org.wsi.wsdl.traversal.WSDLTraversalContext) + */ + public void visit(Import im, Object parent, WSDLTraversalContext ctx) + { + if (im.getDefinition() != null) + processWSDL(im.getDefinition()); + } + + /** + * Internal method processes WSDL definition. + * @param def a WSDL definition. + */ + private void processWSDL(Definition def) + { + if (def.getTypes() != null) + processTypes(def.getTypes(), def.getDocumentBaseURI()); + } + + /** + * Internal method processes WSDL types. + * @param types WSDL types. + * @param context a context. + */ + private void processTypes(Types types, String context) + { + if (types == null) + return; + List exts = types.getExtensibilityElements(); + if (exts != null) + { + Iterator it = exts.iterator(); + while (it.hasNext()) + { + ExtensibilityElement el = (ExtensibilityElement) it.next(); + if (el instanceof UnknownExtensibilityElement) + searchForSchema( + ((UnknownExtensibilityElement) el).getElement(), + context); + } + } + } + + /** + * Internal method searches XSD schema declaration and XSD import + * statements. + * @param n + * @param context + */ + private void searchForSchema(Node n, String context) + { + while (n != null) + { + // searches for xsd:import element + if (Node.ELEMENT_NODE == n.getNodeType()) + { + // if xsd:schema element is found -> process schema + if (XMLUtils.equals(n, ELEM_XSD_SCHEMA)) + processSchema(n, context); + else + // if xsd:import element is found -> load schema and process schema + if (XMLUtils.equals(n, ELEM_XSD_IMPORT)) + loadSchema(n, context); + // if xsd:include element is found -> load schema and process schema + else if (XMLUtils.equals(n, ELEM_XSD_INCLUDE)) + loadSchema(n, context); + else + // else iterate element recursively + searchForSchema(n.getFirstChild(), context); + } + n = n.getNextSibling(); + } + } + + /** + * Internal method loads XSD schema by using schema location and + * location context. + * @param importNode + * @param context + */ + private void loadSchema(Node importNode, String context) + { + Element im = (Element) importNode; + Attr schemaLocation = XMLUtils.getAttribute(im, ATTR_XSD_SCHEMALOCATION); + // try to parse imported XSD + if (schemaLocation != null && schemaLocation.getValue() != null) + try + { + // if any error or root element is not XSD schema -> error + Document schema = + baseValidator.parseXMLDocumentURL( + schemaLocation.getValue(), + context, + null); + if (XMLUtils.equals(schema.getDocumentElement(), ELEM_XSD_SCHEMA)) + processSchema( + schema.getDocumentElement(), + XMLUtils.createURLString(schemaLocation.getValue(), context)); + } + catch (Throwable t) + { + //t.printStackTrace(); + // nothing. it's not a schema + } + } + + /** + * Internal method processes XSD schema and retrieves types declaration from + * it. + * @param schema + * @param context + */ + private void processSchema(Node schema, String context) + { + Attr a = XMLUtils.getAttribute((Element) schema, ATTR_XSD_TARGETNAMESPACE); + String targetNamespace = (a != null) ? a.getValue() : ""; + // iterate schema + Node n = schema.getFirstChild(); + // !! we suppose that xsd:import element is occured only within xsd:schema element + while (n != null) + { + if (Node.ELEMENT_NODE == n.getNodeType()) + { + if (XMLUtils.equals(n, ELEM_XSD_ELEMENT)) + { + Element el = (Element) n; + a = XMLUtils.getAttribute(el, ATTR_XSD_NAME); + QName element = + new QName(targetNamespace, (a != null) ? a.getValue() : ""); + + a = XMLUtils.getAttribute(el, ATTR_XSD_TYPE); + QName type = null; + if (a != null) + { + String t = a.getValue(); + // if type contains ':', it means that it contains qname + int i = t.indexOf(':'); + if (i != -1) + { + String prefix = t.substring(0, i); + String nsURI = XMLUtils.findNamespaceURI(n, prefix); + type = new QName(nsURI, t.substring(i + 1)); + } + else + type = new QName(targetNamespace, t); + } + else + { + // suppose that element directly contains type declaration + type = element; + checkType(n, type); + } + + element2Type.put(element, type); + } + else if (XMLUtils.equals(n, ELEM_XSD_IMPORT)) + loadSchema(n, context); + else if (XMLUtils.equals(n, ELEM_XSD_INCLUDE)) + loadSchema(n, context); + else if (XMLUtils.equals(n, ELEM_XSD_COMPLEXTYPE)) + { + Element el = (Element) n; + a = XMLUtils.getAttribute(el, ATTR_XSD_NAME); + QName type = + new QName(targetNamespace, (a != null) ? a.getValue() : ""); + checkType(n, type); + } + + } + + n = n.getNextSibling(); + } + } + + /** + * Internal method checks whether specified type has WSDL array type + * attribute in the XSD declaration. + * @param n + * @param name + */ + private void checkType(Node n, QName name) + { + while (n != null) + { + if (Node.ELEMENT_NODE == n.getNodeType()) + { + // check such sentence + // xsd:attribute ref="soapenc:arrayType" wsdl:arrayType="tns:MyArray2Type[]"/> + if (XMLUtils.equals(n, ELEM_XSD_ATTRIBUTE)) + { + Attr a = XMLUtils.getAttribute((Element) n, ATTR_WSDL_ARRAYTYPE); + if (a != null) + usesWsdlArrayType.add(name); + } + + // retrieve base attribute may be from restriction or extension + Attr a = XMLUtils.getAttribute((Element) n, ATTR_XSD_BASE); + if (a != null) + { + String base = a.getValue(); + int i = base.indexOf(":"); + if (i != -1) + { + String prefix = base.substring(0, i); + String local = base.substring(i + 1); + String namespace = XMLUtils.findNamespaceURI(n, prefix); + if (SOAPENC_ARRAY.equals(new QName(namespace, local))) + extendsArray.add(name); + } + } + checkType(n.getFirstChild(), name); + } + n = n.getNextSibling(); + } + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/UDDIUtils.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/UDDIUtils.java new file mode 100644 index 000000000..3446ce63c --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/UDDIUtils.java @@ -0,0 +1,336 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.util; + +import java.util.Hashtable; +import java.util.Iterator; +import java.util.Vector; + +import org.uddi4j.UDDIException; +import org.uddi4j.client.UDDIProxy; +import org.uddi4j.datatype.binding.BindingTemplate; +import org.uddi4j.datatype.binding.TModelInstanceInfo; +import org.uddi4j.datatype.business.BusinessEntity; +import org.uddi4j.datatype.service.BusinessService; +import org.uddi4j.datatype.tmodel.TModel; +import org.uddi4j.response.BusinessDetail; +import org.uddi4j.response.ServiceDetail; +import org.uddi4j.response.TModelDetail; +import org.uddi4j.response.TModelInfo; +import org.uddi4j.response.TModelList; +import org.uddi4j.transport.TransportException; +import org.uddi4j.util.CategoryBag; +import org.uddi4j.util.FindQualifier; +import org.uddi4j.util.FindQualifiers; +import org.uddi4j.util.KeyedReference; + +/** + * This class provide some service functions used by UDDIValidator. + * + * @version 1.0.1 + * @author Peter Brittenham + */ +public final class UDDIUtils +{ + static public final FindQualifiers EXACT_NAME_MATCH_QUALIFIER; + static { + Vector vector = new Vector(); + EXACT_NAME_MATCH_QUALIFIER = new FindQualifiers(); + vector.add(new FindQualifier(FindQualifier.exactNameMatch)); + vector.add(new FindQualifier(FindQualifier.sortByNameAsc)); + EXACT_NAME_MATCH_QUALIFIER.setFindQualifierVector(vector); + } + + static final String WS_I_CONFORMANCE_TMODEL_NAME = + "ws-i-org:conformsTo:2002_12"; + + static private Hashtable wsiConformanceTable = new Hashtable(); + + /** + * Gets a business service by key. + * @param proxy a UDDI proxy. + * @param key a key to a business service. + * @return a business service specified by the given key. + * @throws TransportException if error originating within the SOAP transport. + * @throws UDDIException if the return value of a UDDI API cannot indicate an error condition. + */ + public static BusinessService getBusinessServiceByKey( + UDDIProxy proxy, + String key) + throws TransportException, UDDIException + { + BusinessService result = null; + + ServiceDetail sd = proxy.get_serviceDetail(key); + + if (sd != null) + { + Vector v = sd.getBusinessServiceVector(); + + if (v != null && v.size() > 0) + { + result = (BusinessService) v.firstElement(); + } + } + + return result; + } + + /** + * Gets business entity by key. + * @param proxy a UDDI proxy. + * @param key a key to a business entiy. + * @return a business entity specified by the given key. + * @throws TransportException if error originating within the SOAP transport. + * @throws UDDIException if the return value of a UDDI API cannot indicate + * an error condition. + */ + public static BusinessEntity getBusinessByKey(UDDIProxy proxy, String key) + throws TransportException, UDDIException + { + BusinessEntity result = null; + + BusinessDetail bd = proxy.get_businessDetail(key); + + if (bd != null) + { + Vector v = bd.getBusinessEntityVector(); + + if (v != null && v.size() > 0) + { + result = (BusinessEntity) v.firstElement(); + } + } + + return result; + } + + /** + * Gets a tModel by key. + * @param proxy a UDDI proxy. + * @param key a key to a tModel. + * @return a tModel specified by the given key. + * @throws TransportException if error originating within the SOAP transport. + * @throws UDDIException if the return value of a UDDI API cannot indicate + * an error condition. + */ + public static TModel getTModelByKey(UDDIProxy proxy, String key) + { + TModel result = null; + + try + { + TModelDetail bd = proxy.get_tModelDetail(key); + + if (bd != null) + { + Vector v = bd.getTModelVector(); + + if (v != null && v.size() > 0) + { + result = (TModel) v.firstElement(); + } + } + } + catch (Throwable e) + { + } + + return result; + } + + /** + * Gets key of the WSI Conformance tModel. + * @param proxy a UDDI proxy. + * @return the key of the WSI Conformance tModel. + */ + public static String getWSIConformanceTModelKey(UDDIProxy proxy) + { + if (proxy == null) + throw new IllegalArgumentException("UDDI proxy cannot be null."); + + String result = null; + + if (wsiConformanceTable.containsKey(proxy)) + { + result = wsiConformanceTable.get(proxy).toString(); + } + else + { + result = getTModelKeyByName(proxy, WS_I_CONFORMANCE_TMODEL_NAME); + + if (result == null) + { + throw new IllegalStateException("WS-I conformance taxonomy tModel was not found"); + } + + wsiConformanceTable.put(proxy, result); + } + + return result; + } + + /** + * Gets a tModel key by tModel name. + * @param proxy a UDDI proxy. + * @param name a tModel name. + * @return a tModel key specified by the given tModel name. + */ + public static String getTModelKeyByName(UDDIProxy proxy, String name) + { + String result = null; + try + { + TModelList list = + proxy.find_tModel(name, null, null, EXACT_NAME_MATCH_QUALIFIER, 1); + TModelInfo info = + (TModelInfo) list.getTModelInfos().getTModelInfoVector().firstElement(); + result = info.getTModelKey(); + } + catch (Throwable e) + { + } + + return result; + } + + /** + * Get string representation of bindingTemplate. + * @param bindingTemplate a BindingTemplate object. + * @return a string representation of bindingTemplate. + */ + public static String bindingTemplateToString(BindingTemplate bindingTemplate) + { + String returnString = ""; + + if (bindingTemplate == null) + returnString = "null"; + + else + { + returnString = + "accessPoint: " + + (bindingTemplate.getAccessPoint() == null + ? "null" + : bindingTemplate.getAccessPoint().getText()); + + if (bindingTemplate.getTModelInstanceDetails() == null + || bindingTemplate + .getTModelInstanceDetails() + .getTModelInstanceInfoVector() + == null) + { + returnString += ", [no tModel reference]"; + } + + else + { + Iterator iterator = + bindingTemplate + .getTModelInstanceDetails() + .getTModelInstanceInfoVector() + .iterator(); + + int infoCount = 1; + TModelInstanceInfo info; + while (iterator.hasNext()) + { + info = (TModelInstanceInfo) iterator.next(); + returnString += ", [" + + infoCount++ + + "] tModelKey: " + + info.getTModelKey(); + } + } + } + + return returnString; + } + + /** + * Get string representation of tModel. + * @param tModel a TModel object. + * @return a string representation of tModel. + */ + public static String tModelToString(TModel tModel) + { + String returnString = ""; + + if (tModel == null) + returnString = "null"; + + else + { + returnString = + "name: " + + tModel.getNameString() + + ", categoryBag: " + + (tModel.getCategoryBag() == null + ? "null" + : categoryBagToString(tModel.getCategoryBag())) + + ", overviewURL: " + + (tModel.getOverviewDoc() == null + ? "null" + : tModel.getOverviewDoc().getOverviewURLString()); + } + + return returnString; + } + + /** + * Get string representation of categoryBag. + * @param categoryBag a CategoryBag object. + * @return a tring representation of categoryBag. + */ + public static String categoryBagToString(CategoryBag categoryBag) + { + String returnString = ""; + + if (categoryBag == null) + { + returnString += "null"; + } + + else + { + returnString += "KeyedReferenceList: "; + + Vector krList = null; + if ((krList = categoryBag.getKeyedReferenceVector()) == null) + { + returnString += "null"; + } + + else if (krList.size() == 0) + { + returnString += "empty"; + } + + else + { + KeyedReference kr = null; + Iterator iterator = krList.iterator(); + while (iterator.hasNext()) + { + kr = (KeyedReference) iterator.next(); + returnString += "tModelKey: " + + kr.getTModelKey() + + ", keyName: " + + kr.getKeyName() + + ", keyValue: " + + kr.getKeyValue(); + } + } + } + + return returnString; + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/Utils.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/Utils.java new file mode 100644 index 000000000..9b09e51a7 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/Utils.java @@ -0,0 +1,1418 @@ +/******************************************************************************* + * + * Copyright (c) 2002-2003 IBM Corporation, Beacon Information Technology Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + * BeaconIT - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.util; + +import java.io.BufferedInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.io.UnsupportedEncodingException; +import java.net.ConnectException; +import java.net.InetAddress; +import java.net.MalformedURLException; +import java.net.URL; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Date; +import java.util.Iterator; +import java.util.ResourceBundle; +import java.util.TimeZone; +import java.util.Vector; +import java.util.StringTokenizer; + +import org.eclipse.wst.wsi.internal.WSIConstants; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.log.MimePart; +import org.eclipse.wst.wsi.internal.log.MimeParts; +import org.eclipse.wst.wsi.internal.log.impl.MimePartImpl; +import org.eclipse.wst.wsi.internal.log.impl.MimePartsImpl; +import org.eclipse.wst.wsi.internal.profile.ProfileAssertions; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; + +/** + * General set of utilities. + */ +public final class Utils +{ + public static final byte CR = (byte) '\r'; + public static final byte LF = (byte) '\n'; + + /** + * Common timestamp format. + */ + // public static final SimpleDateFormat timestampFormat = new SimpleDateFormat ("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); + public static final SimpleDateFormat timestampFormat = + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"); + + /** + * Basic date format. + */ + public static final SimpleDateFormat dateFormat = + new SimpleDateFormat("yyyy-MM-dd"); + + /** + * Wrapper method for error logging; + * for now it just goes to stderr. + * @param inError an error message. + */ + public final static void logError(String inError) + { + System.err.println("Error: " + inError); + } + + /** + * Get exception information as a string. + * @param throwable a Throwable object. + * @return exception information as a string. + */ + public final static String getExceptionDetails(Throwable throwable) + { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + + pw.println("Exception: "); + throwable.printStackTrace(pw); + + return sw.toString(); + } + + /** + * Get current date and time as a timestamp. + * @return urrent date and time as a timestamp. + */ + public static String getTimestamp() + { + // Use GMT timezone + //timestampFormat.setTimeZone(TimeZone.getTimeZone("GMT")); + timestampFormat.setTimeZone(TimeZone.getDefault()); + + // Return timestamp + return timestampFormat.format(new Date()); + } + + /** + * Get current date for default time zone. + * @return current date for default time zone. + */ + public static String getDate() + { + // Use GMT timezone + dateFormat.setTimeZone(TimeZone.getDefault()); + + // Return date + return dateFormat.format(new Date()); + } + + /** + * Get HTTP status code. + * @param httpHeaders HTTP headers. + * @return HTTP status code. + * @throws WSIException if the status code in http headers was not found. + */ + public static String getHTTPStatusCode(String httpHeaders) + throws WSIException + { + String statusCode = null; + + if (httpHeaders.startsWith("HTTP")) + { + // Get location of status code + int index = httpHeaders.indexOf(" "); + int index2 = httpHeaders.indexOf(" ", index + 1); + + if ((index == -1) || (index2 == -1)) + { + throw new WSIException( + "Could not find status code in http headers: [" + httpHeaders + "]."); + } + + else + { + statusCode = httpHeaders.substring(index + 1, index2); + } + } + + else + { + throw new WSIException( + "Could not find status code in http headers: [" + httpHeaders + "]."); + } + + // Return status code + return statusCode; + } + + /** + * Get HTTP headers from a full message. + * @param fullMessage a message. + * @return HTTP headers from a full message. + */ + public static String getHTTPHeaders(String fullMessage) + { + //String httpHeaders = null; + + // Try looking for the double newline + int index = fullMessage.indexOf("\r\n\r\n"); + if (index != -1) + { + index += 4; + } + else + { + // check for case "\r\r...\r\n\r\r...\n" + // Note the index that is returned points to the first character + // immediatedly following the first occurence of the CRLFCRLF. + index = getFirstCRLFCRLF(fullMessage); + if (index == -1) + { + logError( + "Unable to parse HTTP message to find headers. Full message: " + + fullMessage); + return "x-WSI-Test-Tool-Error: Couldn't find headers. Full message: [" + + fullMessage + + "]."; + } + } + + // Return HTTP headers + return fullMessage.substring(0, index); + } + + /** + * Get SOAP message from a full message. + * @param fullMessage a message. + * @return SOAP message from a full message. + */ + public static String getContent(String fullMessage) + { + String message = ""; + + // Find start of message + int index = fullMessage.indexOf("\r\n\r\n"); + if (index != -1) + { + index += 4; + } + else + { + // check for case "\r\r...\r\n\r\r...\n" + // Note the index that is returned points to the first character + // immediatedly following the first occurence of the CRLFCRLF. + index = getFirstCRLFCRLF(fullMessage); + } + + if (index < 0) + { + // If we couldn't find the end of the HTTP headers or the start of the message, then show error + logError( + "Unable to parse message to get content. Full message: " + + fullMessage); + message = + "x-WSI-Test-Tool-Error: Couldn't find message content. Full message: [" + + fullMessage + + "]."; + } + // If the index is greater than the length, then there is no message content + else if (index >= fullMessage.length()) + { + message = ""; + } + + // Else get the message content + else + { + message = fullMessage.substring(index); + } + + // Return SOAP message + return message; + } + + /** + * Get HTTP headers from a full message. + * @param fullMessage a message. + * @return HTTP headers from a full message. + */ + public static byte[] getHTTPHeaders(byte[] fullMessage) + { + //String httpHeaders = null; + int index = getFirstCRLFCRLF(fullMessage, 0); + if (index == -1) + { + logError( + "Unable to parse HTTP message to find headers. Full message: " + + fullMessage); + return ("x-WSI-Test-Tool-Error: Couldn't find headers. Full message: [" + + fullMessage + "].").getBytes(); + } + + // Return HTTP headers + byte[] b = new byte[index]; + System.arraycopy(fullMessage, 0, b, 0, index); + + return b; + } + + /** + * Get HTTP headers from a full message. + * @param fullMessage a message. + * @return HTTP headers from a full message. + */ + public static String getHTTPHeadersAsString(byte[] fullMessage, String encoding) + { + //String httpHeaders = null; + int index = getFirstCRLFCRLF(fullMessage, 0); + if (index == -1) + { + logError( + "Unable to parse HTTP message to find headers. Full message: " + + fullMessage); + return "x-WSI-Test-Tool-Error: Couldn't find headers. Full message: [" + + fullMessage + "]."; + } + + // Return HTTP headers + try + { + return new String(fullMessage, 0, index, encoding); + } + catch (UnsupportedEncodingException e) + { + logError( + "Unsupported Encoding: " + encoding + ". Full message: " + + fullMessage); + return "x-WSI-Test-Tool-Error: Unsupported Encoding \"" + encoding + "\". Full message: [" + + fullMessage + "]."; + } + } + + /** + * Get SOAP message from a full message. + * @param fullMessage a message. + * @return SOAP message from a full message. + */ + public static String getContentAsString(byte[] message) + { + String content = ""; + //String httpHeaders = null; + int index = getFirstCRLFCRLF(message, 0); + + // If we couldn't find the end of the HTTP headers or the start of the message, then show error + if (index < 0) + { + logError( + "Unable to parse message to get content. Full message: " + + message); + content = + "x-WSI-Test-Tool-Error: Couldn't find message content. Full message: [" + + message.toString() + + "]."; + } + + // Else get the message content + else if (index < message.length) + { + try + { + content = new String(message, index, message.length - index); + } + catch (Exception e) + { + logError( + "Unable to parse message to get content. Full message: " + + message); + content = + "x-WSI-Test-Tool-Error: Couldn't find message content. Full message: [" + + message.toString() + + "]."; + } + } + + // Return SOAP message + return content; + } + + /** + * Get SOAP message from a full message. + * @param fullMessage a message. + * @return SOAP message from a full message. + */ + public static byte[] getContent(byte[] message) + { + byte[] content = new byte [0]; + + //String httpHeaders = null; + int index = getFirstCRLFCRLF(message, 0); + + // If we couldn't find the end of the HTTP headers or the start of the message, then show error + if (index < 0) + { + logError( + "Unable to parse message to get content. Full message: " + + message); + message = + ("x-WSI-Test-Tool-Error: Couldn't find message content. Full message: [" + + message.toString() + + "].").getBytes(); + } + + // If the index is greater than the length, then there is no message content + //else if (index >= fullMessage.length()) + //{ + // message = ""; + //} + + // Else get the message content + else if (index < message.length) + { + byte[] b = new byte[message.length - index]; + System.arraycopy(message, index, b, 0, message.length - index); + + content = b; + } + + // Return SOAP message + return content; + } + + + /** + * Returns the first location of a CRLF. + * + * @return int + */ + public static int getFirstCRLF(byte[] buffer, int index) + { + int size = buffer.length; + int i = index; + while (i < size - 1) { + if (buffer[i] == CR && buffer[i+1] == LF) + return i; + i++; + } + return -1; + } + + /** + * Returns the first location of a CRLF followed imediately by another CRLF. + * + * @return int + */ + public static int getFirstCRLFCRLF(byte[] buffer, int index) + { + int size = buffer.length; + int i = index; + while (i < size - 3) + { + if (buffer[i] == CR && buffer[i+1] == LF && buffer[i+2] == CR) + { + if (buffer[i+3] == LF) + { + return i+4; + } + else + { + int j = i + 3; + while (j < buffer.length && buffer[j] == CR) + { + j++; + } + if (j < buffer.length && buffer[j] == LF) + { + return j + 1; + } + } + } + i++; + } + return -1; + } + + /** + * Returns the first location of a CRLF followed imediately by another CRLF. + * + * @return int + */ + public static int getFirstCRLFCRLF(String buffer) + { + int index = buffer.indexOf("\r\n\r"); + if (index != -1) + { + int i = index +3; + while (i < buffer.length() && buffer.startsWith("\r", i)) + i++; + + if (i < buffer.length() && buffer.startsWith("\n", i)) + return i+1; + else + return getFirstCRLFCRLF(buffer.substring(index + 3)); + } + else + { + return -1; + } + } + + /** + * Returns the list of indices which marks the separation of parts. + */ + public static int[] getBoundaryIndices(byte[] message, String boundaryStr) + { + int[] indices = new int[256]; + int indicesIndex = 0; + try + { + byte[] boundary = ("\r\n--" + boundaryStr).getBytes("US-ASCII"); + + int index = 0; + int start = 0; + int end = message.length; + while (index != -1) + { + index = indexOf(message, boundary, start); + + if (index != -1) + { + start = index + boundary.length; + indices[indicesIndex] = index; + indicesIndex++; + } + } + int[] b = new int[indicesIndex]; + System.arraycopy(indices, 0, b, 0, indicesIndex); + indices = b; + } + catch (Exception e) + {} + return indices; + } + + /** + * Returns the index of the first occurrence of key in the buffer. + */ + public static int indexOf(byte[] buffer, byte[] key, int start) + { + int bufferLen = buffer.length; + int keyLen = key.length; + int i,j,k = 0; + + if (keyLen > bufferLen - start) + { + return -1; + } + + for (k = start + keyLen - 1; k < bufferLen; k++) + { + for (j = keyLen - 1, i = k; (j >= 0) && (buffer[i] == key[j]); j--) + { + i--; + } + + if (j == (-1)) { + return i + 1; + } + } + + return -1; + } + /** + * Get contents of a resource and return as a input stream. + * + * @param resourceName the name of the resource to get and return as + * an input stream. + * @return contents of a resource as an input stream. + * @throws IOException if the resource could not be located. + */ + public static InputStream getInputStream(String resourceName) + throws IOException + { + InputStream is = null; + + // If resource reference is a URL, then input stream from URL + try + { + // Try to create URL + URL urlResource = new URL(resourceName); + + // If successful, then get URL input stream + is = getInputStream(urlResource); + } + + // Else try to read resource directly + catch (MalformedURLException mue) + { + boolean bTryClassLoader = false; + + try + { + // Open file input stream + is = new BufferedInputStream(new FileInputStream(resourceName)); + } + catch (FileNotFoundException fnfe) + { + // Set try class loader flag + bTryClassLoader = true; + } + catch (SecurityException se) + { + // Set try class loader flag + bTryClassLoader = true; + } + catch (Exception e) + { + // DEBUG: + System.out.println("Exception in getInputStream :" + e.toString()); + } + + // If try class loader, then use it to get input stream + if (bTryClassLoader) + { + // Use class loader to load resource + is = ClassLoader.getSystemResourceAsStream(resourceName); + } + } + + // If the input stream is null, then throw FileNotFoundException + if (is == null) + { + //try this + is = + Thread.currentThread().getContextClassLoader().getResourceAsStream( + resourceName); + } + + // If the input stream is null, then throw FileNotFoundException + if (is == null) + { + //try this + URL aURL = + Thread.currentThread().getContextClassLoader().getResource( + resourceName); + if (aURL != null) + is = getInputStream(aURL); + } + + if (is == null) + // Throw execption + throw new FileNotFoundException( + "Could not locate resource file: " + resourceName); + + // Return input stream + return is; + } + + /** + * Get the input stream from a URL. + * @param urlFile the URL to get the input stream from. + * @return the input stream corresponding to the given URL. + * @throws IOException if attempt to open the file denoted by URL has failed. + * @throws ConnectException if trouble connecting to URL. + */ + public static InputStream getInputStream(URL urlFile) + throws IOException, ConnectException + { + InputStream is = null; + + // ADD: how are URLs that are password protected handled???? + + try + { + // Open file input stream + is = new BufferedInputStream(urlFile.openStream()); + } + + catch (ConnectException e) + { + // Re-throw this excpetion with additional information + throw new java.net.ConnectException( + "Could not connect to URL: " + urlFile.toExternalForm() + "."); + } + + // Return input stream + return is; + } + + /** + * Get contents of a resource and return as a input stream. + * @param fileLocation the location of the file. + * @return contents of a resource as a input stream. + */ + public static boolean fileExists(String fileLocation) + { + boolean fileExists = false; + + // If resource reference is a URL, then input stream from URL + try + { + // Try to create URL + URL url = new URL(fileLocation); + + // If successful, then try to open connection + InputStream is = url.openStream(); + + fileExists = true; + } + + // Else try to read resource directly + catch (MalformedURLException mue) + { + try + { + File file = new File(fileLocation); + + fileExists = file.exists(); + } + + catch (Exception e2) + { + fileExists = false; + } + } + + catch (FileNotFoundException fnfe) + { + fileExists = false; + } + + catch (Exception e) + { + fileExists = false; + } + + // Return file exists indicator + return fileExists; + } + + /** + * Get local host name. + * @return the local host name. + */ + public static String getLocalHostName() + { + String sLocalHostName; + + try + { + // Get local host name + sLocalHostName = InetAddress.getLocalHost().getHostName(); + } + catch (Exception e) + { + // Set default local host name + sLocalHostName = "127.0.0.1"; + } + + // Return local host name + return sLocalHostName; + } + + /** + * Build a URL string from hostname, port and URN. + * + * @param hostname the hostname. + * @param port the port. + * @param urn the URN. + * @return formatted URL string. + */ + public static String formatURL(String hostname, String port, String urn) + { + // Build URN + String formatURN = urn; + + // If URN doesn't start with "/", then add it + if (!(formatURN.startsWith("/"))) + { + // Add "/" to beginning of the string + formatURN = "/" + urn; + } + + // Return URL string + return "http://" + hostname + ":" + port + formatURN; + } + + /** + * This method will replace all of the occurances of a string + * with a substitution string. + * + * @param sText String to udpate. + * @param sFind String to find. + * @param sReplace String to use for substitution. + * @return updated string. + */ + public static String replaceString( + String sText, + String sFind, + String sReplace) + { + int iPrevIndex = 0; + + int iFindLen = sFind.length(); + int iReplaceLen = sReplace.length(); + + String sUpdatedText = sText; + + // Replace all occurances of the find string + for (int iIndex = sUpdatedText.indexOf(sFind); + iIndex < (sUpdatedText.length() - 1) && iIndex != -1; + iIndex = sUpdatedText.indexOf(sFind, iPrevIndex + iReplaceLen)) + { + // Set updated text from the front portion + replacement text + back portion + sUpdatedText = + sUpdatedText.substring(0, iIndex) + + sReplace + + sUpdatedText.substring(iIndex + iFindLen); + + // Set the previous index field + iPrevIndex = iIndex; + } + + // Return updated text string + return sUpdatedText; + } + + /** + * Convert string to hex string. + * @param data a String object. + * @return hex string. + */ + public static String toHexString(String data) + { + char[] HEX_CHARS = + { + '0', + '1', + '2', + '3', + '4', + '5', + '6', + '7', + '8', + '9', + 'A', + 'B', + 'C', + 'D', + 'E', + 'F' }; + + // Get string as byte array + byte[] byteData = data.getBytes(); + + // Get length + int length = byteData.length; + + // Create Char buffer + char[] charBuffer = new char[length * 2]; + + int next; + for (int byteCnt = 0, charCnt = 0; byteCnt < length;) + { + next = byteData[byteCnt++]; + charBuffer[charCnt++] = HEX_CHARS[(next >>> 4) & 0x0F]; + charBuffer[charCnt++] = HEX_CHARS[next & 0x0F]; + } + + return new String(charBuffer); + } + + /** + * Convert byte buffer to hex string. + * @param data a byte array. + * @return hex string. + */ + public static String toHexString(byte[] byteData) + { + char[] HEX_CHARS = + { + '0', + '1', + '2', + '3', + '4', + '5', + '6', + '7', + '8', + '9', + 'A', + 'B', + 'C', + 'D', + 'E', + 'F' }; + + + // Get length + int length = byteData.length; + + // Create Char buffer + char[] charBuffer = new char[length * 2]; + + int next; + for (int byteCnt = 0, charCnt = 0; byteCnt < length;) + { + next = byteData[byteCnt++]; + charBuffer[charCnt++] = HEX_CHARS[(next >>> 4) & 0x0F]; + charBuffer[charCnt++] = HEX_CHARS[next & 0x0F]; + } + + return new String(charBuffer); + } + + // I18N: 2003.02.26 modified by K.Nakagome@BeaconIT + /** + * Get MIME charset from a HTTP headers. + * @param httpHeaders String of HTTP header. + * @return the MIME charset string. + * @author K.Nakagome@BeaconIT Japan SIG + */ + public static String getHTTPCharset(String httpHeaders) + { + String mimeCharset = null; + + mimeCharset = httpHeaders.toUpperCase(); + int[] index = { -1, -1, -1 }; + int indexS = mimeCharset.indexOf("CHARSET"); + int indexE = Integer.MAX_VALUE; + if (indexS < 17) + { + return ""; + } + indexS = mimeCharset.indexOf("=", indexS + 7); + if (indexS == -1) + { + return ""; + } + indexS++; + index[0] = mimeCharset.indexOf("'", indexS); + index[1] = mimeCharset.indexOf("\r\n", indexS); + index[2] = mimeCharset.indexOf("\"", indexS); + for (int i = 0; i < 3; i++) + { + if (index[i] != -1 & indexE > index[i]) + { + indexE = index[i]; + } + } + + if (indexE != Integer.MAX_VALUE) + { + mimeCharset = httpHeaders.substring(indexS, indexE); + mimeCharset.trim(); + } + else + { + mimeCharset = ""; + } + return mimeCharset; + } + + /** + * Checks to see if the message is a simple SOAP message or whether it is a SOAP messagwe with attachments. + */ + public static boolean isMultipartRelatedMessage(String httpHeaders) + { + boolean result = false; + try + { + // check header for mime version and boundary + String contentType = HTTPUtils.getHttpHeaderAttribute(httpHeaders, HTTPConstants.HEADER_CONTENT_TYPE); + if (contentType == null) + { + // there is no contentType, check if there is a boundary attribute + String boundary = Utils.getHttpHeaderSubAttribute(httpHeaders, HTTPConstants.HEADER_CONTENT_TYPE, "boundary"); + if ((boundary != null) && (!boundary.equals(""))) + result = true; + } + else + { + result = contentType.equalsIgnoreCase("multipart/related"); + } + } + catch (WSIException e) + { + result = false; + } + return result; + } + + public static String getHttpHeaderAttribute(String httpHeaders, String attributeName) + { String result = null; + try + { + result = HTTPUtils.getHttpHeaderAttribute(httpHeaders, attributeName); + } + catch (WSIException e) + { + result = null; + } + return result; + } + + public static String getHttpHeaderSubAttribute(String httpHeaders, String attributeName, String subAttributeName) + { String result = null; + try + { + result = HTTPUtils.getHttpHeaderSubAttribute(httpHeaders, attributeName, subAttributeName); + } + catch (WSIException e) + { + result = null; + } + return result; + } + + public static String getMimeHeaderAttribute(String mimeHeaders, String attributeName) + { String result = null; + try + { + result = MIMEUtils.getMimeHeaderAttribute(mimeHeaders, attributeName); + } + catch (WSIException e) + { + result = null; + } + return result; + } + + public static String getMimeHeaderSubAttribute(String mimeHeaders, String attributeName, String subAttributeName) + { String result = null; + try + { + result = MIMEUtils.getMimeHeaderSubAttribute(mimeHeaders, attributeName, subAttributeName); + } + catch (WSIException e) + { + result = null; + } + return result; + } + // I18N: 2003.02.26 modified by K.Nakagome@BeaconIT + /** + * Get XML encoding from a SOAP Messages. + * @param message SOAP Message String. + * @return character encoding of XML. + * @author K.Nakagome@BeaconIT Japan SIG + */ + public static String getXMLEncoding(String message) + { + String xmlDef = null; + + int indexS = message.indexOf("", indexS); + if (indexE > indexS) + { + xmlDef = message.substring(indexS, indexE); + } + } + + if (xmlDef != null) + { + indexS = xmlDef.indexOf("encoding"); + if (indexS == -1) + { + xmlDef = ""; + } + else + { + xmlDef = xmlDef.substring(indexS + 8); + xmlDef = xmlDef.trim(); + } + } + else + { + return ""; + } + + if (xmlDef.length() > 3) + { + indexS = xmlDef.indexOf("="); + if (indexS == 0) + { + xmlDef = xmlDef.substring(1); + } + else + { + return ""; + } + } + + if (xmlDef.length() > 3) + { + String end = "\""; + indexS = xmlDef.indexOf(end); + if (indexS != 0) + { + indexS = xmlDef.indexOf((end = "'")); + } + if (indexS == 0) + { + indexE = xmlDef.indexOf(end, 3); + if (indexE != -1) + { + xmlDef = xmlDef.substring(1, indexE); + } + else + { + xmlDef = ""; + } + } + else + { + xmlDef = ""; + } + } + return xmlDef; + } + + // I18N: 2003.02.26 modified by K.Nakagome@BeaconIT + private static ResourceBundle javaEncodingResource = null; + private static final String JAVA_ENCODING_RESOURCE = + "org.wsi.test.util.JavaEncoding"; + private static final String JAVA_ENCODING_DEFAULT = "UTF-8"; + + // I18N: 2003.02.26 modified by K.Nakagome@BeaconIT + /** + * Get Java VM supported character encoding. + * + * @param mimeEncoding string of MIME(IANA) character encoding. + * @return string of character encoding supported by Java VM. + * @author K.Nakagome@BeaconIT Japan SIG + */ + public static String getJavaEncoding(String mimeEncoding) + { + if (mimeEncoding == null || mimeEncoding.length() == 0) + { + return JAVA_ENCODING_DEFAULT; + } + try + { + if (javaEncodingResource == null) + { + javaEncodingResource = ResourceBundle.getBundle(JAVA_ENCODING_RESOURCE); + } + return javaEncodingResource.getString(mimeEncoding); + } + catch (Throwable t) + { + return mimeEncoding; + } + } + + /** + * Convert an array to a Vector. + * + * @param array the array to be converted . + * @return converted Vector (null if array is null, empty if empty). + * @author Graham Turrell IBM + */ + public static Vector arrayToVector(Object[] array) + { + if (array == null) + return null; + Vector v = new Vector(array.length); + for (int i = 0; i < array.length; i++) + v.add(array[i]); + return v; + } + /** + * Checks to ensure that version of the profile test assertion + * document is supported in this version of the test tools. + * @param profileAssertions - a profile TAD. + * @return true if the version of the profile test assertion + * docuement is supported in this version of the test tools. + */ + public static boolean isValidProfileTADVersion(ProfileAssertions profileAssertions) + { + boolean result = false; + + String name = profileAssertions.getTADName(); + String version = profileAssertions.getTADVersion(); + + if (WSIConstants.BASIC_PROFILE_TAD_NAME.equals(name)) + { + result = + checkVersionNumber(WSIConstants.BASIC_PROFILE_TAD_VERSION, version); + } else if (WSIConstants.BASIC_PROFILE_1_1_TAD_NAME.equals(name)) + { + result = + checkVersionNumber(WSIConstants.BASIC_PROFILE_1_1_TAD_VERSION, version); + } else if (WSIConstants.SIMPLE_SOAP_BINDINGS_PROFILE_TAD_NAME.equals(name)) + { + result = + checkVersionNumber(WSIConstants.SIMPLE_SOAP_BINDINGS_PROFILE_TAD_VERSION, version); + } else if (WSIConstants.ATTACHMENTS_PROFILE_TAD_NAME.equals(name)) + { + result = + checkVersionNumber(WSIConstants.ATTACHMENTS_PROFILE_TAD_VERSION, version); + } + return result; + } + + /** + * Checks to ensure that version number of the actual profile test assertion + * document is supported in this version of the test tools. + * @param supportedVersion - supported version number of profile TAD. + * @param actualVersion - actual version number of profile TAD. + * @return true if the version number of the actual profile test assertion + * document is supported in this version of the test tools. + */ + private static boolean checkVersionNumber( + String supportedVersion, + String actualVersion) + { + boolean validVersion = true; + + try + { + StringTokenizer supportedVersionTokenizer = + new StringTokenizer(supportedVersion, "."); + StringTokenizer actualVersionTokenizer = + new StringTokenizer(actualVersion, "."); + + while (supportedVersionTokenizer.hasMoreTokens() && validVersion) + { + int supportedVersionToken = + Integer.parseInt(supportedVersionTokenizer.nextToken()); + if (actualVersionTokenizer.hasMoreTokens()) + { + int actualVersionToken = + Integer.parseInt(actualVersionTokenizer.nextToken()); + if (supportedVersionToken > actualVersionToken) break; + else validVersion = (supportedVersionToken >= actualVersionToken); + } + } + } + catch (Exception e) + { + validVersion = false; + } + return validVersion; + } + + /** + * Identifies the root part in the list using the "start" attribute. + * If the "start" attribute does not exist then the first part is designated the root. + */ + public static MimePart findRootPart(String httpHeaders, Collection parts) + { + MimePart root = null; + String start = Utils.getHttpHeaderSubAttribute(httpHeaders, HTTPConstants.HEADER_CONTENT_TYPE, "start"); + if (!parts.isEmpty()) + { + // default to the first part in the collection + root = (MimePart)parts.iterator().next(); + + if ((start != null) && (!start.equals(""))) + { + Iterator i = parts.iterator(); + boolean rootNotFound = true; + while (i.hasNext() && rootNotFound) + { + MimePart part = (MimePart)i.next(); + String headers = part.getHeaders(); + if (headers != null) + { + String contentId = Utils.getMimeHeaderAttribute(headers, MIMEConstants.HEADER_CONTENT_ID); + if (start.equals(contentId)) + { + root = part; + rootNotFound = false; + } + } + } + } + } + return root; + } + + /** + * Decodes the given encoded string. + */ + public static byte[] decodeBase64(String str) + { + try + { + sun.misc.BASE64Decoder decoder = new sun.misc.BASE64Decoder(); + return decoder.decodeBuffer(str); + } + catch (Exception e) + { + return new byte[0]; + } + } + + /** + * Encodes the given byte array. + */ + public static String encodeBase64(byte[] buffer) + { + sun.misc.BASE64Encoder encoder = new sun.misc.BASE64Encoder(); + return encoder.encodeBuffer(buffer); + } + + public static MimeParts parseMultipartRelatedMessage(String message, String httpHeaders, String encoding) + { + byte[] buffer = null; + try + { + buffer = message.getBytes(encoding); + } + catch (Exception e) + { + return null; + } + return parseMultipartRelatedMessage(buffer, httpHeaders, encoding); + } + public static MimeParts parseMultipartRelatedMessage(byte[] message, String httpHeaders, String encoding) + { + MimeParts mimeParts = new MimePartsImpl(); + String boundary = Utils.getHttpHeaderSubAttribute(httpHeaders, HTTPConstants.HEADER_CONTENT_TYPE, "boundary"); + ArrayList parts = new ArrayList(); + + if (boundary == null) + { + // assume it is a simple SOAP message + return null; + } + else + { + String start = Utils.getHttpHeaderSubAttribute(httpHeaders, HTTPConstants.HEADER_CONTENT_TYPE, "start"); + int[] indices = Utils.getBoundaryIndices(message, boundary); + boolean rootNotFound = true; + + for (int i= indices.length - 2; i>=0; i--) + { + try + { + MimePart part = new MimePartImpl(); + int index = Utils.getFirstCRLFCRLF(message, indices[i]); + if ((index > indices[i]) && (index < indices[i+1])) + { + // the boundary string & mime headers (include the trailing CRLF CRLF) + String str = new String(message, indices[i], (index - indices[i]), "US-ASCII"); + String delimiter = str.substring(0, str.indexOf("\r\n", 2) + 2); + + if (i == indices.length -2) + { + String endDelimiter = new String(message, indices[i + 1], message.length - indices[i + 1], "US-ASCII"); + int j = str.indexOf("\r\n", 2); + if (j != -1) + endDelimiter = str.substring(0, str.indexOf("\r\n", 2) + 2); + part.setBoundaryStrings(new String[]{delimiter, endDelimiter}); + } + else + part.setBoundaryStrings(new String[]{delimiter}); + + // the headers + String headers = str.substring(delimiter.length()); + if (headers.startsWith("\r\n")) + { + // no headers present + part.setHeaders(""); + } + else + { + part.setHeaders(headers); + } + + // the content + String contentId = Utils.getMimeHeaderAttribute(headers, MIMEConstants.HEADER_CONTENT_ID); + int size = indices[i+1] - (index); + byte[] content = new byte[size]; + System.arraycopy(message, index, content, 0, size); + + if ((rootNotFound && (i == 0)) || + ((start != null) && (!start.equals("")) && (start.equals(contentId)))) + { + // root part -- do not encode + part.setContent(new String(content, encoding)); + mimeParts.setRootPart(part); + } + else + { + String transferEncoding = Utils.getMimeHeaderAttribute(headers, MIMEConstants.HEADER_CONTENT_TRANSFER_ENCODING); + + if ((transferEncoding != null) && transferEncoding.equalsIgnoreCase("base64")) + part.setContent(new String(content, encoding)); + else + part.setContent(Utils.encodeBase64(content)); + } + parts.add(part); + } + } + catch (Exception e) + { + return null; + } + } + int size = parts.size(); + for (int i = size-1; i>=0; i--) + mimeParts.addPart((MimePart)parts.get(i)); + } + return mimeParts; + } + + public static String toXMLString(MimeParts mimeParts) + { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + + // Add message content with attachments element + pw.print("<" + WSIConstants.ELEM_MESSAGE_CONTENT_WITH_ATTACHMENTS); + pw.print(">"); + + Collection partList = mimeParts.getParts(); + if (!partList.isEmpty()) + { + Iterator iMimeParts = partList.iterator(); + while (iMimeParts.hasNext()) + { + MimePart mimePart = (MimePart)iMimeParts.next(); + pw.print(mimePart.toXMLString("")); + } + } + + // Add end message element + pw.println(""); + // Return string + return sw.toString(); + } + + public static void main (String[] args) + { + try + { + FileInputStream inputStream = new FileInputStream("d:\\b.xml"); + int i = inputStream.available(); + byte[] buffer = new byte[i]; + inputStream.read(buffer); + String message = new String(buffer); + message = XMLUtils.xmlRemoveEscapedString(message); + String headers = Utils.getHTTPHeaders(message); + String content = Utils.getContent(message); + MimeParts parts = Utils.parseMultipartRelatedMessage(message, headers, Utils.JAVA_ENCODING_DEFAULT); + System.out.println(Utils.toXMLString(parts)); + } + catch (Exception e){} + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/WSDLUtil.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/WSDLUtil.java new file mode 100644 index 000000000..137635141 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/WSDLUtil.java @@ -0,0 +1,154 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.util; + +import java.util.Iterator; +import java.util.List; + +import javax.wsdl.Binding; +import javax.wsdl.Definition; +import javax.wsdl.Import; +import javax.wsdl.Message; +import javax.wsdl.Operation; +import javax.wsdl.Part; +import javax.wsdl.PortType; +import javax.wsdl.Service; +import javax.wsdl.extensions.soap.SOAPBody; + +import org.eclipse.wst.wsi.internal.WSIConstants; + +/** + * The utility class to automate WSDL processing. + * + * @author Kulik + */ +public final class WSDLUtil +{ + + /** + * The method extracts list of parts for the given soapbind:body, + * binding operation, message, and style. + * + * @param op an operation. + * @param m a message. + * @param body a SOAP body. + * @param style an operation style. + * @return list of parts for the given soapbind:body, + * binding operation, message, and style. + */ + static public List getParts( + Operation op, + Message m, + SOAPBody body, + String style) + { + // if null, get parts from message + if (body.getParts() == null) + // if rpc style is used, try to use partOrder attribute from operation + if (WSIConstants.ATTRVAL_SOAP_BIND_STYLE_RPC.equals(style)) + return m.getOrderedParts(op.getParameterOrdering()); + else + return m.getOrderedParts(null); + else + // converse parts name to parts objects + return m.getOrderedParts(body.getParts()); + } + + /** + * The method iterates all imports from the given definition and expands all + * imported messages, service, portTypes, and bindings to the definition. + * + * @param def a WSDL definition. + */ + static public void expandDefinition(Definition def) + { + if (def != null && def.getImports() != null) + { + Iterator it = def.getImports().values().iterator(); + while (it.hasNext()) + { + List v = (List) it.next(); + if (v != null) + { + Iterator it2 = v.iterator(); + while (it2.hasNext()) + expandDefinition(def, (Import) it2.next()); + } + } + } + } + + /** + * The internal method to expand definition. + * @param target WSDL definition. + * @param im internal method. + */ + static private void expandDefinition(Definition target, Import im) + { + if (im != null && im.getDefinition() != null) + { + Definition d = im.getDefinition(); + if (d.getMessages() != null) + { + Iterator it = d.getMessages().values().iterator(); + while (it.hasNext()) + target.addMessage((Message) it.next()); + } + if (d.getPortTypes() != null) + { + Iterator it = d.getPortTypes().values().iterator(); + while (it.hasNext()) + target.addPortType((PortType) it.next()); + } + if (d.getBindings() != null) + { + Iterator it = d.getBindings().values().iterator(); + while (it.hasNext()) + target.addBinding((Binding) it.next()); + } + if (d.getServices() != null) + { + Iterator it = d.getServices().values().iterator(); + while (it.hasNext()) + target.addService((Service) it.next()); + } + + Iterator it = d.getImports().values().iterator(); + while (it.hasNext()) + { + List v = (List) it.next(); + if (v != null) + { + Iterator it2 = v.iterator(); + while (it2.hasNext()) + expandDefinition(target, (Import) it2.next()); + } + } + } + } + + /** + * The method extracts part from the message. + * + * @param message a SOAP message. + * @param part a part name. + * @return part from the specified message. + */ + static public Part getPart(Message message, String part) + { + Part mesPart = null; + if (part == null) + mesPart = (Part) message.getOrderedParts(null).get(0); + else + mesPart = message.getPart(part); + return mesPart; + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/WSIProperties.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/WSIProperties.java new file mode 100644 index 000000000..67aeb88d7 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/WSIProperties.java @@ -0,0 +1,344 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.util; + +import org.uddi4j.transport.TransportFactory; + +import java.util.*; + +/** + * The WSI properties can be defined in one of three locations. + * + * 1. The wsi.properties file which can be located anywhere in the classpath. + * 2. The system property settings. + * 3. The thread local property settings. + * + * The properties are set based on this ordering. For example, the properties + * from the wsi.properties file will be replaced by properties from the system + * property settings, which will be replaced by the thread local property settings. + * + * The properties that are used to define the implementation classes can be + * specified as system properties or as properties that are set in a thread + * local variable. System properties should be used if only one implementation + * is needed per JVM. If two or more implementations are needed per JVM, then + * the properties should be set using the thread local variable. + * + * @version 1.0.1 + * @author: Peter Brittenham + */ +public final class WSIProperties +{ + /** + * Properties object. + */ + protected static Properties wsiProperties = new Properties(); + + /** + * Default ProfileValidatorFactory class name. + */ + public static final String DEF_VALIDATOR_FACTORY = + "org.wsi.test.profile.validator.impl.ProfileValidatorFactoryImpl"; + + /** + * Property that contains ProfileValidatorFactory class name. + */ + public static final String PROP_VALIDATOR_FACTORY = + "wsi.profile.validator.factory"; + + /** + * Default document factory class name. + */ + public static final String DEF_DOCUMENT_FACTORY = + "org.wsi.test.document.impl.DocumentFactoryImpl"; + + /** + * Property that contains document factory class name. + */ + public static final String PROP_DOCUMENT_FACTORY = "wsi.document.factory"; + + /** + * Default JAXP XML parser document factory builder. + */ + public static final String DEF_JAXP_DOCUMENT_FACTORY = + "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl"; + + /** + * Property that contains JAXP XML parser document factory builder. + */ + public static final String PROP_JAXP_DOCUMENT_FACTORY = + "javax.xml.parsers.DocumentBuilderFactory"; + + /** + * Default WSDL schema location. + */ + public static final String DEF_WSDL_SCHEMA = "common/schemas/wsdl11.xsd"; + + /** + * Property that contains WSDL schema location. + */ + public static final String PROP_WSDL_SCHEMA = "wsi.analyzer.wsdl.schema"; + + /** + * Default WSDL SOAP schema location. + */ + public static final String DEF_WSDL_SOAP_SCHEMA = + "common/schemas/wsdlsoap.xsd"; + + /** + * Property that contains WSDL SOAP schema location. + */ + public static final String PROP_WSDL_SOAP_SCHEMA = + "wsi.analyzer.wsdlsoap.schema"; + + /** + * Default WSDL MIME schema location. + */ + public static final String DEF_WSDL_MIME_SCHEMA = + "common/schemas/wsdlMime.xsd"; + + /** + * Property that contains WSDL SOAP schema location. + */ + public static final String PROP_WSDL_MIME_SCHEMA = + "wsi.analyzer.wsdlmime.schema"; + + /** + * Default SOAP schema location. + */ + public static final String DEF_SOAP_SCHEMA = + "common/schemas/soapEnvelope.xsd"; + + /** + * Property that contains SOAP schema location. + */ + public static final String PROP_SOAP_SCHEMA = "wsi.analyzer.soap.schema"; + + /** + * Default SOAP schema location. + */ + public static final String DEF_XML_SCHEMA = "common/schemas/XMLSchema.xsd"; + + /** + * Property that contains SOAP schema location. + */ + public static final String PROP_XML_SCHEMA = "wsi.analyzer.xmlschema.schema"; + + /** + * Property which contains WSI_HOME value. + */ + public static final String PROP_WSI_HOME = "wsi.home"; + + /** + * Property file name. + */ + protected static final String PROP_FILENAME = "org.wsi.util.wsi"; + + /** + * Thread local variable. + */ + private static ThreadLocal threadLocal = new ThreadLocal(); + + // Load profiles file + static { + loadPropertiesFile(); + } + + /** + * Load properties from wsi.properties file. + */ + private static void loadPropertiesFile() + { + try + { + // Try to load properties from wsi.properties + //InputStream is = Utils.getInputStream(PROP_FILENAME); + + // Load properties from file + //wsiPropertiesFile.load(is); + + ResourceBundle resourceBundle = ResourceBundle.getBundle(PROP_FILENAME); + + String nextKey; + Enumeration enumeration = resourceBundle.getKeys(); + while (enumeration.hasMoreElements()) + { + nextKey = (String) enumeration.nextElement(); + wsiProperties.put(nextKey, resourceBundle.getString(nextKey)); + } + } + + catch (MissingResourceException mre) + { + // DEBUG: + System.err.println( + "WARNING: Could not read " + + PROP_FILENAME + + ". " + + "Verify that it is in the CLASSPATH."); + + // Set up default values + wsiProperties.put(PROP_VALIDATOR_FACTORY, DEF_VALIDATOR_FACTORY); + wsiProperties.put(PROP_DOCUMENT_FACTORY, DEF_DOCUMENT_FACTORY); + wsiProperties.put(PROP_JAXP_DOCUMENT_FACTORY, DEF_JAXP_DOCUMENT_FACTORY); + wsiProperties.put( + TransportFactory.PROPERTY_NAME, + "org.uddi4j.transport.ApacheAxisTransport"); + } + } + + /** + * Do not allow this object to be instantiated. + */ + private WSIProperties() + { + } + + /** + * Get properties that were set for this thread only. + * @return the properties that were set for this thread only. + * + * @see #setThreadLocalProperties + */ + public static Properties getThreadLocalProperties() + { + // Return properties + return (Properties) threadLocal.get(); + } + + /** + * Set properties for this thread only. + * @param props a Properties object. + * + * @see #getThreadLocalProperties + */ + public static void setThreadLocalProperties(Properties props) + { + // Save the properties as thread local variables + threadLocal.set(props); + } + + /** + * Get the property value given the property name. + * @param propertyName a property name. + * @return the corresponding property value. If not found return null. + */ + public static String getProperty(String propertyName) + { + String propertyValue = null; + Properties threadLocalProps = null; + + // 1. Look in thread local properties first + if ((threadLocalProps = getThreadLocalProperties()) != null) + { + propertyValue = threadLocalProps.getProperty(propertyName); + } + + // 2. Next look in system properties + if (propertyValue == null) + { + propertyValue = System.getProperty(propertyName); + } + + // 3. Last look in the properties file + if (propertyValue == null) + { + propertyValue = wsiProperties.getProperty(propertyName); + } + + // Return property value + return propertyValue; + } + + /** + * Get the property value given the property name. + * @param propertyName a property name. + * @param defaultValue a default value for the property. + * @return the corresponding property value. If not found return the default value. + */ + public static String getProperty(String propertyName, String defaultValue) + { + String propertyValue = null; + + // If the propertyValue was not found, then return default value + if ((propertyValue = getProperty(propertyName)) == null) + { + propertyValue = defaultValue; + } + + // Return property value + return propertyValue; + } + + /** + * This method is used to unit test this class. + * @param args the arguments for main. + */ + public static void main(String[] args) + { + try + { + // Set property for this thread + Properties props = new Properties(); + props.setProperty(PROP_VALIDATOR_FACTORY, "main"); + WSIProperties.setThreadLocalProperties(props); + + // Start four threads to verify that the multithreaded use of tread local vars works + for (int i = 0; i < 5; i++) + { + // Create new thread + (new Thread(new ThreadTest("test" + i))).start(); + + try + { + // Sleep + Thread.sleep(200); + + // Display properties, which should be main + System.out.println( + "PROP_VALIDATOR_FACTORY: " + + WSIProperties.getProperty(PROP_VALIDATOR_FACTORY)); + } + + catch (Exception e) + { + } + } + } + + catch (Exception e) + { + // e.printStackTrace(); + } + } + + /** + * Inner class used for unit test. + */ + static private class ThreadTest extends Thread + { + String name; + + ThreadTest(String name) + { + this.name = name; + } + + public void run() + { + Properties props = new Properties(); + props.setProperty(PROP_VALIDATOR_FACTORY, name); + WSIProperties.setThreadLocalProperties(props); + System.out.println( + "PROP_VALIDATOR_FACTORY: " + + WSIProperties.getProperty(PROP_VALIDATOR_FACTORY)); + } + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/XMLInfo.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/XMLInfo.java new file mode 100644 index 000000000..e86591cba --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/XMLInfo.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.util; + +/** + * This class ... + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public interface XMLInfo +{ + /** + * Get addtional tool environment information as an XML string. + * @param namespaceName a namespace prefix. + * @return addtional tool environment information as an XML string. + */ + public String toXMLString(String namespaceName); +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/wsi.properties b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/wsi.properties new file mode 100644 index 000000000..7c68933fc --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/util/wsi.properties @@ -0,0 +1,46 @@ +# /** +# * +# * +# * Copyright (c) 2002-2003 IBM Corporation and others. +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * IBM - Initial API and implementation +# * +# */ +# +# Property file used to set parameters for Conformance Tools + +# ----------------------------------------------------------------------- +# Document factory. +# ----------------------------------------------------------------------- +wsi.document.factory=org.wsi.test.document.impl.DocumentFactoryImpl + +# ----------------------------------------------------------------------- +# Profile validation factory. +# ----------------------------------------------------------------------- +wsi.profile.validator.factory=org.wsi.test.profile.validator.impl.ProfileValidatorFactoryImpl + +# ----------------------------------------------------------------------- +# Reference to JAXP document builder +# ----------------------------------------------------------------------- +javax.xml.parsers.DocumentBuilderFactory=org.apache.xerces.jaxp.DocumentBuilderFactoryImpl +#javax.xml.parsers.DocumentBuilderFactory=org.wsi.xml.jaxp.DocumentBuilderFactoryImpl + +# ----------------------------------------------------------------------- +# Transport class used by UDDI4J +# ----------------------------------------------------------------------- +org.uddi4j.TransportClassName=org.uddi4j.transport.ApacheAxisTransport + + +# ----------------------------------------------------------------------- +# Location of XML schema documents relative to the plugin directory +# ----------------------------------------------------------------------- +wsi.analyzer.xmlschema.schema=common/schemas/XMLSchema.xsd +wsi.analyzer.soap.schema=common/schemas/soapEnvelope.xsd +wsi.analyzer.wsdl.schema=common/schemas/wsdl11.xsd +wsi.analyzer.wsdlsoap.schema=common/schemas/wsdlSoap.xsd +wsi.analyzer.wsdlmime.schema=common/schemas/wsdlMime.xsd diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/WSDLDocument.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/WSDLDocument.java new file mode 100644 index 000000000..3273caad2 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/WSDLDocument.java @@ -0,0 +1,290 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.wsdl; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import javax.wsdl.Binding; +import javax.wsdl.Definition; +import javax.wsdl.PortType; +import javax.wsdl.Service; +import javax.wsdl.WSDLException; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.xml.WSDLReader; + +import org.eclipse.wst.wsi.internal.wsdl.xsd.InlineSchemaValidator; +import org.eclipse.wst.wsi.internal.xml.XMLTags; + +/** + * This class provides a interface to a single WSDL document. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public class WSDLDocument +{ + /** + * WSDL document location. + */ + protected String fileName = null; + + /** + * Definition element. + */ + protected Definition definitions = null; + + /** + * WSDL element list with line and column numbers. + */ + protected WSDLElementList wsdlElementList = null; + + /** + * Map of targetNamespaces to the corresponding org.apache.xerces.xs.XSModel of schema elements. + */ + private Map schemas = new HashMap(); + + /** + * List of schemas validation errors. + */ + private List schemasValidationErrors = new ArrayList(); + + /** + * Read WSDL document from the specified file. + * @param fileName WSDL document location. + * @throws WSDLException if problem reading WSDL document. + */ + public WSDLDocument(String fileName) throws WSDLException + { + this.fileName = fileName; + ClassLoader currentLoader = Thread.currentThread().getContextClassLoader(); + + try + { + Thread.currentThread().setContextClassLoader(WSDLDocument.class.getClassLoader()); + + // Get the WSDLReader + WSDLReader wsdlReader = new WSDLReaderImpl(); + + // Set features + wsdlReader.setFeature(com.ibm.wsdl.Constants.FEATURE_VERBOSE, false); + // DEBUG: + //wsdlReader.setFeature(com.ibm.wsdl.Constants.FEATURE_VERBOSE, true); + wsdlReader.setFeature( + com.ibm.wsdl.Constants.FEATURE_IMPORT_DOCUMENTS, + true); + // DEBUG: + //wsdlReader.setFeature(com.ibm.wsdl.Constants.FEATURE_IMPORT_DOCUMENTS,true); + + // Parse the WSDL document + this.definitions = wsdlReader.readWSDL(null, fileName); + + // Since inline schema validator is used by several assertions, validate all + // schemas right after WSDL validation + validateSchemas(); + + // Get the line and column number references + this.wsdlElementList = ((WSDLReaderImpl) wsdlReader).getElementList(); + + // DEBUG: + //System.err.println(wsdlElementList.toString()); + } + catch (ClassCastException cce) + { + // Set element list to null + this.wsdlElementList = null; + } + finally + { + Thread.currentThread().setContextClassLoader(currentLoader); + } + } + + /** + * Create WSDL document from existing Definition object. + * + * @param fileName WSDL document location. + * @param definitions Definition object. + */ + public WSDLDocument(String fileName, Definition definitions) + { + this.fileName = fileName; + this.definitions = definitions; + schemas.clear(); + schemasValidationErrors.clear(); + } + + /** + * Get the WSDL document location. + * @return he WSDL document location. + */ + public String getLocation() + { + // Return the document location + return this.fileName; + } + + /** + * Get the definition element of the WSDL document. + * @return the definition element + */ + public Definition getDefinitions() + { + // Return the definition element + return definitions; + } + + /** + * Get all the portType elements from the WSDL document. + * @return the list of portType elements. + */ + public PortType[] getPortTypes() + { + // Generate an array of PortTypes from the PortType map for this Definition + return (PortType[]) definitions.getPortTypes().values().toArray( + new PortType[0]); + } + + /** + * Get all the binding elements from the WSDL document. + * @return the list of binding elements. + */ + public Binding[] getBindings() + { + // Generate an array of Bindings from the Binding map for this Definition + return (Binding[]) definitions.getBindings().values().toArray( + new Binding[0]); + } + + /** + * Get all the service elements from the WSDL document. + * @return the list of service elements. + */ + public Service[] getServices() + { + // Generate an array of Services from the Service map for this Definition + return (Service[]) definitions.getServices().values().toArray( + new Service[0]); + } + + /* Return string representation of this object. + * @see java.lang.Object#toString() + */ + public String toString() + { + // Return string + return (definitions == null) + ? "WSDL definition element not found." + : definitions.toString(); + } + + /** + * Get the element list. + * @return the element list. + */ + public WSDLElementList getElementList() + { + return this.wsdlElementList; + } + + /** + * Returns a schemas map. + * @return a map of targetNamespace attribute values of the schema elements + * to the corresponding org.apache.xerces.xs.XSModel object of that schema. + */ + public Map getSchemas() + { + return schemas; + } + + /** + * Returns a list of schemas validation errors caused by the validateSchemas() procedure. + * @return a list of schemas validation errors. + */ + public List getSchemasValidationErrors() + { + return schemasValidationErrors; + } + + /** + * The method invokes the inline schema validator which validates every schema element of the WSDL. + */ + private void validateSchemas() + { + schemas.clear(); + schemasValidationErrors.clear(); + + /* INLINE SCHEMA VALIDATOR */ + if (definitions != null + && definitions.getTypes() != null + && definitions.getTypes().getExtensibilityElements() != null) + { + InlineSchemaValidator schemaValidator = new InlineSchemaValidator(); + + // Collecting schema's parent elements + List parents = new ArrayList(2); + parents.add(definitions.getTypes()); + parents.add(definitions); + // Going through all the ExtensibilityElementS of wsdl:types + // since they are potential schemas + // See Java APIs for WSDL V1.0 (JSR110), section 4 + Iterator i = this.definitions.getTypes().getExtensibilityElements().iterator(); + while (i.hasNext()) + { + ExtensibilityElement extEl = (ExtensibilityElement) i.next(); + if (extEl.getElementType().equals(XMLTags.ELEM_XSD_SCHEMA)) + { + Map map = null; + try + { + // Validating schema element + map = schemaValidator.validate(extEl, parents, fileName); + } + catch (Exception e) + { + // Adding an exception to the errors list + schemasValidationErrors.add(e.getMessage()); + } + + if (map != null) + { + // Adding returned XSModel to schemas map + schemas.putAll(map); + } + } + } + } + } + + /** + * Command line interface. + * @param args from command line. + */ + public static void main(String[] args) + { + try + { + WSDLDocument wsdlDocument = new WSDLDocument(args[0]); + System.out.println(wsdlDocument.toString()); + } + + catch (Exception e) + { + e.toString(); + e.printStackTrace(); + } + + System.exit(0); + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/WSDLElementList.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/WSDLElementList.java new file mode 100644 index 000000000..589726a87 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/WSDLElementList.java @@ -0,0 +1,98 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.wsdl; + +import org.eclipse.wst.wsi.internal.xml.dom.ElementLocation; + +import java.util.*; + +/** + * This class maintains a WSDL element list. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public class WSDLElementList +{ + /** + * List of WSDL elements with their location. + */ + HashMap wsdlElementList = new HashMap(); + + /** + * WSDL element locator. + */ + public WSDLElementList() + { + } + + /** + * Add element with location information. + * @param wsdlElement a WSDL element artifact. + * @param elementLocation the location information for the element. + */ + public void addElement(Object wsdlElement, ElementLocation elementLocation) + { + this.wsdlElementList.put(wsdlElement, elementLocation); + } + + /** + * Get element location. + * @param wsdlElement a WSDL element artifact. + * @return the location information for the element. + */ + public ElementLocation getElementLocation(Object wsdlElement) + { + return (ElementLocation) this.wsdlElementList.get(wsdlElement); + } + + /* Return string representation of this object. + * @see java.lang.Object#toString() + */ + public String toString() + { + String string = "WSDLElementList: \n"; + + // Get list entries (values?) + Iterator iterator = this.wsdlElementList.keySet().iterator(); + + // Add each entry in the list to the string + ElementLocation wsdlElementLocation; + while (iterator.hasNext()) + { + Object wsdlElement = iterator.next(); + + if (wsdlElement != null) + { + string += " " + wsdlElement.getClass().getName() + ": "; + if ((wsdlElementLocation = + (ElementLocation) wsdlElementList.get(wsdlElement)) + == null) + { + string += "null\n"; + } + + else + { + string += " " + + wsdlElement.getClass().getName() + + ": " + + wsdlElementLocation.getLineNumber() + + ", " + + wsdlElementLocation.getColumnNumber() + + "\n"; + } + } + } + + return string; + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/WSDLReaderImpl.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/WSDLReaderImpl.java new file mode 100644 index 000000000..44de87ec3 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/WSDLReaderImpl.java @@ -0,0 +1,766 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.wsdl; + +import org.apache.xerces.dom.ElementImpl; +import org.eclipse.wst.wsi.internal.xml.dom.ElementLocation; + +import com.ibm.wsdl.*; +import com.ibm.wsdl.util.StringUtils; +import com.ibm.wsdl.util.xml.*; + +import org.w3c.dom.*; +import org.xml.sax.*; + +import javax.wsdl.*; +import javax.wsdl.extensions.*; +import javax.wsdl.factory.*; +import javax.xml.namespace.*; +import javax.xml.parsers.*; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.*; + +/** + * This class is a specialization of com.ibm.wsdl.xml.WSDLReaderImpl in WSDL4J. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public class WSDLReaderImpl extends com.ibm.wsdl.xml.WSDLReaderImpl +{ + // WSDL element list. + protected WSDLElementList wsdlElementList = new WSDLElementList(); + + /* (non-Javadoc) + * @see com.ibm.wsdl.xml.WSDLReaderImpl#parseDefinitions(java.lang.String, org.w3c.dom.Element, java.util.Map) + */ + protected Definition parseDefinitions( + String documentBaseURI, + Element defEl, + Map importedDefs) + throws WSDLException + { + Definition def = + super.parseDefinitions(documentBaseURI, defEl, importedDefs); + + // Try to add element to list + addElementToList(defEl, def); + + return def; + } + + /* (non-Javadoc) + * @see com.ibm.wsdl.xml.WSDLReaderImpl#parseImport(org.w3c.dom.Element, javax.wsdl.Definition, java.util.Map) + */ + protected Import parseImport(Element element, Definition definition, Map map) + throws WSDLException + { + /*boolean wasEx = false; + if (def.getDocumentBaseURI()!=null){ + File f = new File(def.getDocumentBaseURI()); + if (f.getParent()!=null && importEl.getAttribute("location")!=null){ + f = new File(f.getParent()+"/"+importEl.getAttribute("location")); + + } + } else wasEx = false; + + Import importDef = super.parseImport(importEl, def, importedDefs); + + // Try to add element to list + addElementToList(importEl, importDef); + + return importDef;*/ + + /*Import import1 = definition.createImport(); + String s = DOMUtils.getAttribute(element, "namespace"); + String s1 = DOMUtils.getAttribute(element, "location"); + if (s != null) + import1.setNamespaceURI(s); + if (s1 != null) { + if (importDocuments) { + String s2 = definition.getDocumentBaseURI(); + try { + + URL url1 = s2 == null ? null : StringUtils.getURL(null, s2); + URL url = StringUtils.getURL(url1, s1); + InputStream inputstream = + StringUtils.getContentAsInputStream(url); + inputstream.close(); + } catch (IOException ex) { + //import1.setLocationURI(null); + addElementToList(element, import1); + return import1; + } catch (Throwable ex) { + throw new WSDLException( + "OTHER_ERROR", + "Unable to resolve imported document at '" + s1 + "'.", + ex); + } + + } + } + Import importDef = super.parseImport(element, definition, map); + addElementToList(element, importDef);*/ + Import import1 = definition.createImport(); + String s = DOMUtils.getAttribute(element, "namespace"); + String s1 = DOMUtils.getAttribute(element, "location"); + if (s != null) + import1.setNamespaceURI(s); + // ADD: check "location" attribute for empty + // string to prevent self-defenition assigning + if ((s1 != null) && (s1.length() > 0)) + { + import1.setLocationURI(s1); + if (importDocuments) + try + { + String s2 = definition.getDocumentBaseURI(); + Definition definition1 = null; + InputStream inputstream = null; + InputSource inputsource = null; + URL url = null; + if (loc != null) + { + inputsource = loc.getImportInputSource(s2, s1); + String s3 = loc.getLatestImportURI(); + definition1 = (Definition) map.get(s3); + } + else + { + URL url1 = s2 == null ? null : StringUtils.getURL(null, s2); + url = StringUtils.getURL(url1, s1); + definition1 = (Definition) map.get(url.toString()); + if (definition1 == null) + { + try + { + + inputstream = url.openStream(); + } + catch (IOException ex) + { + //import1.setLocationURI(null); + addElementToList(element, import1); + return import1; + } + if (inputstream != null) + inputsource = new InputSource(inputstream); + } + } + if (definition1 == null) + { + if (inputsource == null) + throw new WSDLException( + "OTHER_ERROR", + "Unable to locate imported document at '" + + s1 + + "'" + + (s2 != null ? ", relative to '" + s2 + "'." : ".")); + Document document = null; + try + { + document = getDocument(inputsource, s1); + } + catch (WSDLException ex) + { + addElementToList(element, import1); + return import1; + } + if (inputstream != null) + inputstream.close(); + Element element2 = document.getDocumentElement(); + if (QNameUtils.matches(Constants.Q_ELEM_DEFINITIONS, element2)) + { + if (verbose) + System.out.println( + "Retrieving document at '" + + s1 + + "'" + + (s2 != null ? ", relative to '" + s2 + "'." : ".")); + String s4 = + loc == null + ? url == null + ? s1 + : url.toString() : loc.getLatestImportURI(); + definition1 = readWSDL(s4, element2, map); + } + else + { + QName qname = QNameUtils.newQName(element2); + if (Constants.XSD_QNAME_LIST.contains(qname)) + { + WSDLFactory wsdlfactory = + factoryImplName == null + ? WSDLFactory.newInstance() + : WSDLFactory.newInstance(factoryImplName); + definition1 = wsdlfactory.newDefinition(); + if (extReg != null) + definition1.setExtensionRegistry(extReg); + String s5 = + loc == null + ? url == null + ? s1 + : url.toString() : loc.getLatestImportURI(); + definition1.setDocumentBaseURI(s5); + /* Don't add types element since it doesn't exist. Adding it causes problems + * since it will add a types element for processing that does not exist. + Types types = definition1.createTypes(); + UnknownExtensibilityElement unknownextensibilityelement = + new UnknownExtensibilityElement(); + unknownextensibilityelement.setElement(element2); + types.addExtensibilityElement( + unknownextensibilityelement); + definition1.setTypes(types); + */ + } + } + } + if (definition1 != null) + import1.setDefinition(definition1); + } + catch (WSDLException wsdlexception) + { + wsdlexception.setLocation(XPathUtils.getXPathExprFromNode(element)); + throw wsdlexception; + } + catch (Throwable throwable) + { + throw new WSDLException( + "OTHER_ERROR", + "Unable to resolve imported document at '" + s1 + "'.", + throwable); + } + } + for (Element element1 = DOMUtils.getFirstChildElement(element); + element1 != null; + element1 = DOMUtils.getNextSiblingElement(element1)) + if (QNameUtils.matches(Constants.Q_ELEM_DOCUMENTATION, element1)) + import1.setDocumentationElement(element1); + else + DOMUtils.throwWSDLException(element1); + + return import1; + + } + + /* (non-Javadoc) + * @see com.ibm.wsdl.xml.WSDLReaderImpl#parseTypes(org.w3c.dom.Element, javax.wsdl.Definition) + */ + protected Types parseTypes(Element typesEl, Definition def) + throws WSDLException + { + Types types = super.parseTypes(typesEl, def); + + // Try to add element to list + addElementToList(typesEl, types); + + return types; + } + + /* (non-Javadoc) + * @see com.ibm.wsdl.xml.WSDLReaderImpl#parseBinding(org.w3c.dom.Element, javax.wsdl.Definition) + */ + protected Binding parseBinding(Element bindingEl, Definition def) + throws WSDLException + { + Binding binding = super.parseBinding(bindingEl, def); + + // Try to add element to list + addElementToList(bindingEl, binding); + + return binding; + } + + /* (non-Javadoc) + * @see com.ibm.wsdl.xml.WSDLReaderImpl#parseBindingOperation(org.w3c.dom.Element, javax.wsdl.PortType, javax.wsdl.Definition) + */ + protected BindingOperation parseBindingOperation( + Element bindingOperationEl, + PortType portType, + Definition def) + throws WSDLException + { + BindingOperation bindingOperation = null; + + // The follow try-catch was added to detect when a duplicate operation name was detected + try + { + bindingOperation = + super.parseBindingOperation(bindingOperationEl, portType, def); + } + + catch (IllegalArgumentException iae) + { + if (iae.getMessage().startsWith("Duplicate")) + { + bindingOperation = + parseBindingOperationWithDuplicateNames( + bindingOperationEl, + portType, + def); + } + + else + { + throw iae; + } + } + + // Try to add element to list + if (bindingOperation != null) + { + addElementToList(bindingOperationEl, bindingOperation); + } + + return bindingOperation; + } + + /* (non-Javadoc) + * @see com.ibm.wsdl.xml.WSDLReaderImpl#parseBindingInput(org.w3c.dom.Element, javax.wsdl.Definition) + */ + protected BindingInput parseBindingInput( + Element bindingInputEl, + Definition def) + throws WSDLException + { + BindingInput bindingInput = super.parseBindingInput(bindingInputEl, def); + + // Try to add element to list + addElementToList(bindingInputEl, bindingInput); + + return bindingInput; + } + + /* (non-Javadoc) + * @see com.ibm.wsdl.xml.WSDLReaderImpl#parseBindingOutput(org.w3c.dom.Element, javax.wsdl.Definition) + */ + protected BindingOutput parseBindingOutput( + Element bindingOutputEl, + Definition def) + throws WSDLException + { + BindingOutput bindingOutput = + super.parseBindingOutput(bindingOutputEl, def); + + // Try to add element to list + addElementToList(bindingOutputEl, bindingOutput); + + return bindingOutput; + } + + /* (non-Javadoc) + * @see com.ibm.wsdl.xml.WSDLReaderImpl#parseBindingFault(org.w3c.dom.Element, javax.wsdl.Definition) + */ + protected BindingFault parseBindingFault( + Element bindingFaultEl, + Definition def) + throws WSDLException + { + BindingFault bindingFault = super.parseBindingFault(bindingFaultEl, def); + + // Try to add element to list + addElementToList(bindingFaultEl, bindingFault); + + return bindingFault; + } + + /* (non-Javadoc) + * @see com.ibm.wsdl.xml.WSDLReaderImpl#parseMessage(org.w3c.dom.Element, javax.wsdl.Definition) + */ + protected Message parseMessage(Element msgEl, Definition def) + throws WSDLException + { + Message msg = super.parseMessage(msgEl, def); + + // Try to add element to list + addElementToList(msgEl, msg); + + return msg; + } + + /* (non-Javadoc) + * @see com.ibm.wsdl.xml.WSDLReaderImpl#parsePart(org.w3c.dom.Element, javax.wsdl.Definition) + */ + protected Part parsePart(Element partEl, Definition def) throws WSDLException + { + //Part part = super.parsePart(partEl, def); + + Part part = def.createPart(); + String name = DOMUtils.getAttribute(partEl, Constants.ATTR_NAME); + + // WS-I: The try-catch was added for WSI2416 + QName elementName; + + try + { + elementName = + DOMUtils.getQualifiedAttributeValue( + partEl, + Constants.ATTR_ELEMENT, + Constants.ELEM_MESSAGE, + false); + } + + catch (WSDLException we) + { + String prefixedValue = + DOMUtils.getAttribute(partEl, Constants.ATTR_ELEMENT); + int index = prefixedValue.indexOf(':'); + String prefix = (index != -1) ? prefixedValue.substring(0, index) : null; + String localPart = prefixedValue.substring(index + 1); + + elementName = new QName(localPart); + } + + QName typeName = + DOMUtils.getQualifiedAttributeValue( + partEl, + Constants.ATTR_TYPE, + Constants.ELEM_MESSAGE, + false); + + if (name != null) + { + part.setName(name); + } + + if (elementName != null) + { + part.setElementName(elementName); + } + + if (typeName != null) + { + part.setTypeName(typeName); + } + + Element tempEl = DOMUtils.getFirstChildElement(partEl); + + while (tempEl != null) + { + if (QNameUtils.matches(Constants.Q_ELEM_DOCUMENTATION, tempEl)) + { + part.setDocumentationElement(tempEl); + } + else + { + DOMUtils.throwWSDLException(tempEl); + } + + tempEl = DOMUtils.getNextSiblingElement(tempEl); + } + + Map extensionAttributes = part.getExtensionAttributes(); + + extensionAttributes.putAll(getPartAttributes(partEl, def)); + + // Need to do something here to locate part definition. + + // Try to add element to list + addElementToList(partEl, part); + + return part; + } + + /* (non-Javadoc) + * @see com.ibm.wsdl.xml.WSDLReaderImpl#parsePortType(org.w3c.dom.Element, javax.wsdl.Definition) + */ + protected PortType parsePortType(Element portTypeEl, Definition def) + throws WSDLException + { + PortType portType = super.parsePortType(portTypeEl, def); + + // Try to add element to list + addElementToList(portTypeEl, portType); + + return portType; + } + + /* (non-Javadoc) + * @see com.ibm.wsdl.xml.WSDLReaderImpl#parseOperation(org.w3c.dom.Element, javax.wsdl.PortType, javax.wsdl.Definition) + */ + protected Operation parseOperation( + Element opEl, + PortType portType, + Definition def) + throws WSDLException + { + Operation op = super.parseOperation(opEl, portType, def); + + // Try to add element to list + addElementToList(opEl, op); + + return op; + } + + /* (non-Javadoc) + * @see com.ibm.wsdl.xml.WSDLReaderImpl#parseService(org.w3c.dom.Element, javax.wsdl.Definition) + */ + protected Service parseService(Element serviceEl, Definition def) + throws WSDLException + { + Service service = super.parseService(serviceEl, def); + + // Try to add element to list + addElementToList(serviceEl, service); + + return service; + } + + /* (non-Javadoc) + * @see com.ibm.wsdl.xml.WSDLReaderImpl#parsePort(org.w3c.dom.Element, javax.wsdl.Definition) + */ + protected Port parsePort(Element portEl, Definition def) throws WSDLException + { + Port port = super.parsePort(portEl, def); + + // Try to add element to list + addElementToList(portEl, port); + + return port; + } + + /* (non-Javadoc) + * @see com.ibm.wsdl.xml.WSDLReaderImpl#parseExtensibilityElement(java.lang.Class, org.w3c.dom.Element, javax.wsdl.Definition) + */ + protected ExtensibilityElement parseExtensibilityElement( + Class parentType, + Element el, + Definition def) + throws WSDLException + { + ExtensibilityElement extElement = + super.parseExtensibilityElement(parentType, el, def); + + // Try to add element to list + addElementToList(el, extElement); + + return extElement; + } + + /* (non-Javadoc) + * @see com.ibm.wsdl.xml.WSDLReaderImpl#parseInput(org.w3c.dom.Element, javax.wsdl.Definition) + */ + protected Input parseInput(Element inputEl, Definition def) + throws WSDLException + { + Input input = super.parseInput(inputEl, def); + + // Try to add element to list + addElementToList(inputEl, input); + + return input; + } + + /* (non-Javadoc) + * @see com.ibm.wsdl.xml.WSDLReaderImpl#parseOutput(org.w3c.dom.Element, javax.wsdl.Definition) + */ + protected Output parseOutput(Element outputEl, Definition def) + throws WSDLException + { + Output output = super.parseOutput(outputEl, def); + + // Try to add element to list + addElementToList(outputEl, output); + + return output; + } + + /* (non-Javadoc) + * @see com.ibm.wsdl.xml.WSDLReaderImpl#parseFault(org.w3c.dom.Element, javax.wsdl.Definition) + */ + protected Fault parseFault(Element faultEl, Definition def) + throws WSDLException + { + Fault fault = super.parseFault(faultEl, def); + + // Try to add element to list + addElementToList(faultEl, fault); + + return fault; + } + + /* (non-Javadoc) + * @see com.ibm.wsdl.xml.WSDLReaderImpl#getDocument(org.xml.sax.InputSource, java.lang.String) + */ + protected Document getDocument(InputSource inputSource, String desc) + throws WSDLException + { + ClassLoader currentLoader = Thread.currentThread().getContextClassLoader(); + try + { + Thread.currentThread().setContextClassLoader(WSDLReaderImpl.class.getClassLoader()); + + //DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilderFactory factory = + new org.eclipse.wst.wsi.internal.xml.jaxp.DocumentBuilderFactoryImpl(); + + factory.setNamespaceAware(true); + factory.setValidating(false); + + DocumentBuilder builder = factory.newDocumentBuilder(); + Document doc = builder.parse(inputSource); + + return doc; + } + catch (Throwable t) + { + throw new WSDLException( + WSDLException.PARSER_ERROR, + "Problem parsing '" + desc + "'.", + t); + } + finally + { + Thread.currentThread().setContextClassLoader(currentLoader); + } + } + + /** + * Get element list. + * @return the element list. + */ + public WSDLElementList getElementList() + { + return this.wsdlElementList; + } + + /** + * Add WSDL element to element list. + */ + private void addElementToList(Element element, Object wsdlElement) + { + ElementLocation elementLocation = null; + + try + { + // See if the element object is an instanceof org.apache.xerces.dom.ElementImpl + ElementImpl elementImpl = (ElementImpl) element; + + // If it is, then get the element location information + elementLocation = + (ElementLocation) elementImpl.getUserData(ElementLocation.KEY_NAME); + + // Add it to the list + this.wsdlElementList.addElement(wsdlElement, elementLocation); + } + + catch (ClassCastException cce) + { + // ADD: Should we add the element with a null or zero location? + } + } + + /** + * This method is used when a WSDL document contains duplicate operation names. + * It is the same as the original parseBindingOperation method, except that it will + * just find the first operation that matches instead of throwing an exception. + */ + private BindingOperation parseBindingOperationWithDuplicateNames( + Element bindingOperationEl, + PortType portType, + Definition def) + throws WSDLException + { + BindingOperation bindingOperation = def.createBindingOperation(); + String name = + DOMUtils.getAttribute(bindingOperationEl, Constants.ATTR_NAME); + + if (name != null) + { + bindingOperation.setName(name); + } + + Element tempEl = DOMUtils.getFirstChildElement(bindingOperationEl); + + while (tempEl != null) + { + if (QNameUtils.matches(Constants.Q_ELEM_DOCUMENTATION, tempEl)) + { + bindingOperation.setDocumentationElement(tempEl); + } + else if (QNameUtils.matches(Constants.Q_ELEM_INPUT, tempEl)) + { + bindingOperation.setBindingInput(parseBindingInput(tempEl, def)); + } + else if (QNameUtils.matches(Constants.Q_ELEM_OUTPUT, tempEl)) + { + bindingOperation.setBindingOutput(parseBindingOutput(tempEl, def)); + } + else if (QNameUtils.matches(Constants.Q_ELEM_FAULT, tempEl)) + { + bindingOperation.addBindingFault(parseBindingFault(tempEl, def)); + } + else + { + bindingOperation.addExtensibilityElement( + parseExtensibilityElement(BindingOperation.class, tempEl, def)); + } + + tempEl = DOMUtils.getNextSiblingElement(tempEl); + } + + if (portType != null) + { + BindingInput bindingInput = bindingOperation.getBindingInput(); + BindingOutput bindingOutput = bindingOperation.getBindingOutput(); + String inputName = (bindingInput != null ? bindingInput.getName() : null); + String outputName = + (bindingOutput != null ? bindingOutput.getName() : null); + + //Operation op = portType.getOperation(name, inputName, outputName); + // Get all operations, and then find the first one that matches + Operation op = null, checkOperation; + Iterator iterator = portType.getOperations().iterator(); + while (iterator.hasNext() && op == null) + { + // Get the next operation + checkOperation = (Operation) iterator.next(); + + // Get the operation name, input name, and output name + String checkName = checkOperation.getName(); + String checkInputName = + (checkOperation.getInput() == null + ? null + : checkOperation.getInput().getName()); + String checkOutputName = + (checkOperation.getOutput() == null + ? null + : checkOperation.getOutput().getName()); + + // If the names match, then that operation + if ((checkName != null && checkName.equals(name)) + && ((checkInputName != null && checkInputName.equals(inputName)) + || (checkInputName == null && inputName == null)) + && ((checkOutputName != null && checkOutputName.equals(outputName)) + || (checkOutputName == null && outputName == null))) + { + op = checkOperation; + } + } + + if (op == null) + { + op = def.createOperation(); + op.setName(name); + portType.addOperation(op); + } + + bindingOperation.setOperation(op); + } + + return bindingOperation; + } + +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/WSDLUtils.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/WSDLUtils.java new file mode 100644 index 000000000..947c2a977 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/WSDLUtils.java @@ -0,0 +1,383 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.wsdl; + +import org.eclipse.wst.wsi.internal.WSIConstants; + +import javax.wsdl.Binding; +import javax.wsdl.BindingOperation; +import javax.wsdl.Definition; +import javax.wsdl.Fault; +import javax.wsdl.Message; +import javax.wsdl.Operation; +import javax.wsdl.PortType; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.soap.SOAPBinding; +import javax.wsdl.extensions.soap.SOAPBody; +import javax.wsdl.extensions.soap.SOAPHeader; +import javax.wsdl.extensions.soap.SOAPHeaderFault; +import javax.wsdl.extensions.soap.SOAPOperation; +import javax.xml.namespace.QName; + +import java.util.*; + +/** + * Set of XML related utilities. + * + * @author Peter Brittenham (peterbr@us.ibm.com) + * @version 1.0.1 + */ +public final class WSDLUtils +{ + + /** + * Method isRpcLiteral. + * @param bindingStyle a binding style. + * @param operation a WSDL binding operation artifact. + * @return true if binding is rpc literal. + */ + public static boolean isRpcLiteral( + String bindingStyle, + BindingOperation operation) + { + return checkStyleAndUse( + WSIConstants.ATTRVAL_SOAP_BIND_STYLE_RPC, + WSIConstants.ATTRVAL_SOAP_BODY_USE_LIT, + bindingStyle, + operation); + } + + /** + * Method isDocLiteral. + * @param bindingStyle the binding style. + * @param operation a WSDL binding operation. + * @return true if binding is document literal. + */ + public static boolean isDocLiteral( + String bindingStyle, + BindingOperation operation) + { + return checkStyleAndUse( + WSIConstants.ATTRVAL_SOAP_BIND_STYLE_DOC, + WSIConstants.ATTRVAL_SOAP_BODY_USE_LIT, + bindingStyle, + operation); + } + + /** + * Method checkStyleAndUse. + */ + private static boolean checkStyleAndUse( + String checkStyle, + String checkUse, + String bindingStyle, + BindingOperation bindingOperation) + { + boolean styleFound = false; + boolean styleAndUseFound = false; + + // Find the soapbind:operation element + SOAPOperation soapOperation = getSoapOperation(bindingOperation); + + // If there are no ext elements, then check against binding style + if ((soapOperation == null) || (soapOperation.getStyle() == null)) + { + if (checkStyle.equals(bindingStyle)) + styleFound = true; + } + + else + { + if (checkStyle.equals(soapOperation.getStyle())) + styleFound = true; + } + + // If style found then check use + if (styleFound) + { + // Find the soapbind:body element + SOAPBody soapBody = getInputSoapBody(bindingOperation); + + // If there are no soapbind:body, then check against default use value + if ((soapBody == null) || (soapBody.getUse() == null)) + { + if (checkUse.equals(WSIConstants.ATTRVAL_SOAP_BODY_USE_LIT)) + styleAndUseFound = true; + } + + else + { + if (checkUse.equals(soapBody.getUse())) + styleAndUseFound = true; + } + } + + return styleAndUseFound; + } + + /** + * Get soapbind:binding. + * @param binding a Binding object. + * @return soapbind:binding. + */ + public static SOAPBinding getSoapBinding(Binding binding) + { + SOAPBinding soapBinding = null; + + List extElements = null; + + // Find the soapbind:operation element + if ((extElements = binding.getExtensibilityElements()) != null) + { + for (Iterator iterator = extElements.iterator(); + iterator.hasNext() && (soapBinding == null); + ) + { + Object obj = iterator.next(); + + if (obj instanceof SOAPBinding) + { + soapBinding = (SOAPBinding) obj; + } + } + } + + return soapBinding; + } + + /** + * Get soapbind:operation. + * @param bindingOperation a BindingOperation object. + * @return soapbind:operation. + */ + public static SOAPOperation getSoapOperation(BindingOperation bindingOperation) + { + SOAPOperation soapOperation = null; + + List extElements = null; + + // Find the soapbind:operation element + if ((extElements = bindingOperation.getExtensibilityElements()) != null) + { + for (Iterator iterator = extElements.iterator(); + iterator.hasNext() && (soapOperation == null); + ) + { + Object obj = iterator.next(); + + if (obj instanceof SOAPOperation) + { + soapOperation = (SOAPOperation) obj; + } + } + } + + return soapOperation; + } + + /** + * Get soapbind:body from input element. + * @param bindingOperation the BindingOperation object. + * @return soapbind:body from input element. + */ + public static SOAPBody getInputSoapBody(BindingOperation bindingOperation) + { + SOAPBody soapBody = null; + + List extElements = null; + + // Find the soapbind:body element + if ((extElements = + bindingOperation.getBindingInput().getExtensibilityElements()) + != null) + { + for (Iterator iterator = extElements.iterator(); + iterator.hasNext() && (soapBody == null); + ) + { + Object obj = iterator.next(); + + if (obj instanceof SOAPBody) + { + soapBody = (SOAPBody) obj; + } + } + } + + return soapBody; + } + + /** + * Find messages referenced by a header or headerfault. + * @param definition a Definition object. + * @param binding a Binding object. + * @return messages referenced by a header or headerfault. + */ + public static HashSet findMessages(Definition definition, Binding binding) + { + BindingOperation bindingOperation; + + HashSet tempMessages, bindingMessages = new HashSet(); + + HashSet portTypeMessages = findMessages(binding.getPortType()); + + // Process each operation + Iterator iterator = binding.getBindingOperations().iterator(); + while (iterator.hasNext()) + { + bindingOperation = (BindingOperation) iterator.next(); + + // Process the input and then the output + if (bindingOperation.getBindingInput() != null) + { + tempMessages = + findMessages( + bindingOperation + .getBindingInput() + .getExtensibilityElements() + .iterator(), + portTypeMessages, + definition); + + // Add messages to binding message set + bindingMessages.addAll(tempMessages); + } + + // Process output + if (bindingOperation.getBindingOutput() != null) + { + tempMessages = + findMessages( + bindingOperation + .getBindingOutput() + .getExtensibilityElements() + .iterator(), + portTypeMessages, + definition); + + // Add messages to binding message set + bindingMessages.addAll(tempMessages); + } + } + + return bindingMessages; + } + + /** + * Find the messages that are referenced by a header or headerfault. + * @param portType a PortType object. + * @return he messages that are referenced by a header or headerfault. + */ + public static HashSet findMessages(PortType portType) + { + HashSet messageSet = new HashSet(); + ExtensibilityElement extElement; + Operation operation; + + Iterator iterator = portType.getOperations().iterator(); + while (iterator.hasNext()) + { + // Get next operation to process + operation = (Operation) iterator.next(); + + // Get input and output message + if (operation.getInput() != null) + messageSet.add(operation.getInput().getMessage()); + if (operation.getOutput() != null) + messageSet.add(operation.getOutput().getMessage()); + + // Process any faults + Iterator faults = operation.getFaults().values().iterator(); + while (faults.hasNext()) + { + messageSet.add(((Fault) faults.next()).getMessage()); + } + } + + return messageSet; + } + + /** + * Find the messages that are referenced by a header or headerfault. + * @param extElementList a list of external elements. + * @param messageSet a set of messages. + * @param definition a Definition object. + * @return the messages that are referenced by a header or headerfault. + */ + protected static HashSet findMessages( + Iterator extElementList, + HashSet messageSet, + Definition definition) + { + HashSet returnSet = new HashSet(); + ExtensibilityElement extElement; + Message saveMessage = null; + + while (extElementList.hasNext()) + { + // Get ext. element + extElement = (ExtensibilityElement) extElementList.next(); + + QName messageQName; + Message message; + + // If this is a soap:header element, then check for message reference + if (extElement instanceof SOAPHeader) + { + SOAPHeader soapHeader = (SOAPHeader) extElement; + if ((messageQName = soapHeader.getMessage()) != null) + { + // If message not found, then create a dummy message element + if ((message = definition.getMessage(messageQName)) == null) + { + message = definition.createMessage(); + message.setQName(messageQName); + message.setUndefined(true); + } + + if (!messageSet.contains(message)) + { + returnSet.add(message); + saveMessage = message; + } + } + + // Process any header faults within this header + Iterator headerFaultList = soapHeader.getSOAPHeaderFaults().iterator(); + while (headerFaultList.hasNext()) + { + // Get soap header fault + SOAPHeaderFault soapHeaderFault = + (SOAPHeaderFault) headerFaultList.next(); + if ((messageQName = soapHeaderFault.getMessage()) != null) + { + // If message not found, then create a dummy message element + if ((message = definition.getMessage(messageQName)) == null) + { + message = definition.createMessage(); + message.setQName(messageQName); + message.setUndefined(true); + } + + // If message not in message set and return set, then add it + if (!messageSet.contains(message) + && ((saveMessage == null) + || (saveMessage != null + && !saveMessage.getQName().equals(message.getQName())))) + returnSet.add(message); + } + } + } + } + + return returnSet; + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/traversal/VisitorAdaptor.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/traversal/VisitorAdaptor.java new file mode 100644 index 000000000..9c9ea1fe0 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/traversal/VisitorAdaptor.java @@ -0,0 +1,205 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.wsdl.traversal; + +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; +import java.util.HashMap; +import java.util.Map; + +import javax.wsdl.Binding; +import javax.wsdl.BindingFault; +import javax.wsdl.BindingInput; +import javax.wsdl.BindingOperation; +import javax.wsdl.BindingOutput; +import javax.wsdl.Definition; +import javax.wsdl.Fault; +import javax.wsdl.Import; +import javax.wsdl.Input; +import javax.wsdl.Message; +import javax.wsdl.Operation; +import javax.wsdl.Output; +import javax.wsdl.Part; +import javax.wsdl.Port; +import javax.wsdl.PortType; +import javax.wsdl.Service; +import javax.wsdl.Types; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.soap.SOAPBinding; +import javax.wsdl.extensions.soap.SOAPBody; +import javax.wsdl.extensions.soap.SOAPFault; +import javax.wsdl.extensions.soap.SOAPHeader; +import javax.wsdl.extensions.soap.SOAPHeaderFault; +import javax.wsdl.extensions.soap.SOAPOperation; + +import org.w3c.dom.Element; + +/** + * The class adapts the given object with the implemented + * WSDLVisitor methods. + * + * @author Kulik + */ +public class VisitorAdaptor implements InvocationHandler +{ + + // optimization hint + static final private Class[] nullClass = new Class[] { + }; + static final private Object[] nullObject = new Object[] { + }; + static final private Class[] visitorClass = new Class[] { WSDLVisitor.class }; + + /** + * The array is used for determination of actual javax.wsdl class + */ + private static Class[] wsdl = + new Class[] { + Part.class, + Service.class, + Types.class, + Operation.class, + Input.class, + Output.class, + Fault.class, + Binding.class, + BindingOperation.class, + BindingInput.class, + BindingOutput.class, + BindingFault.class, + Import.class, + Element.class, + Message.class, + Port.class, + PortType.class, + Definition.class, + ExtensibilityElement.class, + SOAPBinding.class, + SOAPBody.class, + SOAPHeader.class, + SOAPHeaderFault.class, + SOAPFault.class, + SOAPOperation.class }; + + final private Object visitor; + + private Map methods = new HashMap(); + + /** + * Constructor. + * @param o a visitor object. + */ + private VisitorAdaptor(Object o) + { + this.visitor = o; + } + + /** + * Adds method to method binding. + * @param wsdlMethod a WSDL method. + * @param targetMethod a target method. + */ + private void addMethodBinding(Method wsdlMethod, Method targetMethod) + { + methods.put(wsdlMethod, targetMethod); + } + + /** + * The method proxies all "visit(XXX)" methods to the corresponding + * "visit(XXX)" methods of the target visitor object. + * @see java.lang.reflect.InvocationHandler#invoke(Object, Method, Object[]) + */ + public Object invoke(Object proxy, Method m, Object[] params) + { + try + { + Method target = (Method) methods.get(m); + // assert target != null + return target.invoke(visitor, params); + } + catch (Throwable t) + { + t.printStackTrace(); + } + return null; + } + + /** + * The method extract the short class name. + * @param c a class. + * @return the short class name. + */ + static private String getName(Class c) + { + if (c != null) + { + String name = c.getName(); + return name.substring(name.lastIndexOf(".") + 1); + } + return null; + } + + /** + * The method generates proxy for the given visitor. + * Proxy redirects all visit(XXX) callback to the implemented in visitor + * object. + * @param visitor a vistor object. + * @return a proxy for the given visitor. + */ + public static WSDLTraversal adapt(Object visitor) + { + WSDLTraversal traversal = new WSDLTraversal(); + + if (visitor == null) + throw new IllegalArgumentException("Visitor object can not be NULL"); + + VisitorAdaptor adaptor = new VisitorAdaptor(visitor); + + // check whether methods are implemented + // get real class of the object + Class c = visitor.getClass(); + // iterates through wsdl artifacts and looking for + // void visit(XXX) implemented methods. + for (int i = 0; i < wsdl.length; i++) + try + { + // if method is not found the exception will be thrown + Method m = + c.getMethod( + "visit", + new Class[] { wsdl[i], Object.class, WSDLTraversalContext.class }); + // register binding WSDLVisitor method -> target visitor method + adaptor.addMethodBinding( + WSDLVisitor.class.getMethod( + "visit", + new Class[] { wsdl[i], Object.class, WSDLTraversalContext.class }), + m); + // register visitXXX in WSDLTraversalBuilder + m = + WSDLTraversal.class.getMethod( + "visit" + getName(wsdl[i]), + new Class[] { boolean.class }); + m.invoke(traversal, new Object[] { Boolean.TRUE }); + } + catch (Exception e) + { + } + + // construct the WSDLVisitor by using java.lang.reflect.Proxy + ClassLoader loader = Thread.currentThread().getContextClassLoader(); + WSDLVisitor wsdlVisitor = + (WSDLVisitor) Proxy.newProxyInstance(loader, visitorClass, adaptor); + // traverse WSDL document + traversal.setVisitor(wsdlVisitor); + return traversal; + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/traversal/WSDLTraversal.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/traversal/WSDLTraversal.java new file mode 100644 index 000000000..3296eedb9 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/traversal/WSDLTraversal.java @@ -0,0 +1,3270 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.wsdl.traversal; +import javax.wsdl.Part; +import javax.wsdl.Service; +import javax.wsdl.Types; +import javax.wsdl.Operation; +import javax.wsdl.Input; +import javax.wsdl.Output; +import javax.wsdl.Fault; +import javax.wsdl.Binding; +import javax.wsdl.BindingOperation; +import javax.wsdl.BindingInput; +import javax.wsdl.BindingOutput; +import javax.wsdl.BindingFault; +import javax.wsdl.Import; +import org.w3c.dom.Element; +import javax.wsdl.Message; +import javax.wsdl.Port; +import javax.wsdl.PortType; +import javax.wsdl.Definition; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.soap.SOAPBinding; +import javax.wsdl.extensions.soap.SOAPBody; +import javax.wsdl.extensions.soap.SOAPFault; +import javax.wsdl.extensions.soap.SOAPHeader; +import javax.wsdl.extensions.soap.SOAPHeaderFault; +import javax.wsdl.extensions.soap.SOAPOperation; + +import java.util.Iterator; +import java.util.Map; +import java.util.Vector; + +/** + * The class implements plain traverse over WSDL artifacts. + * WSDLTraversal is context-driven traversal. + * + * @author Andrey Kulik + */ +public class WSDLTraversal +{ + + /** + * Current WSDL visitor (callback). + */ + private WSDLVisitor visitor; + + /** + * Flags which specify whether traversal will travers from one WSDL artifact + * to another. + */ + private boolean traverseBinding2BindingOperation = true; + private boolean traverseBinding2Element = true; + private boolean traverseBinding2ExtensibilityElement = true; + private boolean traverseBinding2PortType = true; // reference + private boolean traverseBindingFault2Element = true; + private boolean traverseBindingFault2ExtensibilityElement = true; + private boolean traverseBindingInput2Element = true; + private boolean traverseBindingInput2ExtensibilityElement = true; + private boolean traverseBindingOperation2BindingFault = true; + private boolean traverseBindingOperation2BindingInput = true; + private boolean traverseBindingOperation2BindingOutput = true; + private boolean traverseBindingOperation2Element = true; + private boolean traverseBindingOperation2ExtensibilityElement = true; + private boolean traverseBindingOperation2Operation = true; // reference + private boolean traverseBindingOutput2Element = true; + private boolean traverseBindingOutput2ExtensibilityElement = true; + private boolean traverseDefinition2Binding = true; + private boolean traverseDefinition2Element = true; + private boolean traverseDefinition2ExtensibilityElement = true; + private boolean traverseDefinition2Import = true; + private boolean traverseDefinition2Message = true; + private boolean traverseDefinition2PortType = true; + private boolean traverseDefinition2Service = true; + private boolean traverseDefinition2Types = true; + private boolean traverseFault2Element = true; + private boolean traverseFault2Message = true; // reference + private boolean traverseImport2Definition = true; + private boolean traverseImport2Element = true; + private boolean traverseInput2Element = true; + private boolean traverseInput2Message = true; // reference + private boolean traverseMessage2Element = true; + private boolean traverseMessage2Part = true; + private boolean traverseOperation2Element = true; + private boolean traverseOperation2Fault = true; + private boolean traverseOperation2Input = true; + private boolean traverseOperation2Output = true; + private boolean traverseOutput2Element = true; + private boolean traverseOutput2Message = true; // reference + private boolean traversePart2Element = true; + private boolean traversePort2Binding = true; // reference + private boolean traversePort2Element = true; + private boolean traversePort2ExtensibilityElement = true; + private boolean traversePortType2Element = true; + private boolean traversePortType2Operation = true; + private boolean traverseService2Element = true; + private boolean traverseService2ExtensibilityElement = true; + private boolean traverseService2Port = true; + private boolean traverseTypes2Element = true; + private boolean traverseTypes2ExtensibilityElement = true; + //private boolean traverseSOAPBody2Part = true; + private boolean traverseSOAPHeader2SOAPHeaderFault = true; + private boolean traverseBinding2SOAPBinding = true; + private boolean traverseBindingOperation2SOAPOperation = true; + private boolean traverseBindingInput2SOAPHeader = true; + private boolean traverseBindingInput2SOAPBody = true; + private boolean traverseBindingOutput2SOAPHeader = true; + private boolean traverseBindingOutput2SOAPBody = true; + private boolean traverseBindingFault2SOAPFault = true; + + /** + * Flags which specify whether traversal will visit corresponding WSDL + * artifact. + */ + private boolean visitBinding = false; + private boolean visitBindingFault = false; + private boolean visitBindingInput = false; + private boolean visitBindingOperation = false; + private boolean visitBindingOutput = false; + private boolean visitDefinition = false; + private boolean visitElement = false; + private boolean visitExtensibilityElement = false; + private boolean visitFault = false; + private boolean visitImport = false; + private boolean visitInput = false; + private boolean visitMessage = false; + private boolean visitOperation = false; + private boolean visitOutput = false; + private boolean visitPart = false; + private boolean visitPort = false; + private boolean visitPortType = false; + private boolean visitService = false; + private boolean visitTypes = false; + private boolean visitSOAPBinding = false; + private boolean visitSOAPBody = false; + private boolean visitSOAPFault = false; + private boolean visitSOAPHeader = false; + private boolean visitSOAPHeaderFault = false; + private boolean visitSOAPOperation = false; + + /** + * Default constructor. + * @see java.lang.Object#Object() + */ + public WSDLTraversal() + { + } + + /** + * The method specifies that traversal will ignore indirect references between + * WSDL artifacts. For example: + *
    + *
  1. binding to port type
  2. + *
  3. binding operation to operation
  4. + *
  5. fault to message
  6. + *
  7. input to message
  8. + *
  9. output to message
  10. + *
  11. port to binding
  12. + *
+ */ + public void ignoreReferences() + { + ignoreBinding2PortType(); + ignoreBindingOperation2Operation(); + ignoreFault2Message(); + ignoreInput2Message(); + ignoreOutput2Message(); + ignorePort2Binding(); + //ignoreSOAPBody2Part(); + } + + /** + * The method sets visitor. + * @param visitor a WSDL visitor. + */ + public void setVisitor(WSDLVisitor visitor) + { + this.visitor = visitor; + } + + /** + * Instructs traversal to ignore reference between WSDL elements. + * @return the traversal. + */ + public WSDLTraversal ignoreBinding2SOAPBinding() + { + traverseBinding2SOAPBinding = false; + return this; + } + /** + * Instructs traversal to ignore reference between WSDL elements. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreBindingOperation2SOAPOperation() + { + traverseBindingOperation2SOAPOperation = false; + return this; + } + /** + * Instructs traversal to ignore reference between WSDL elements. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreBindingInput2SOAPHeader() + { + traverseBindingInput2SOAPHeader = false; + return this; + } + /** + * Instructs traversal to ignore reference between WSDL elements. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreBindingInput2SOAPBody() + { + traverseBindingInput2SOAPBody = false; + return this; + } + /** + * Instructs traversal to ignore reference between WSDL elements. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreBindingOutput2SOAPHeader() + { + traverseBindingOutput2SOAPHeader = false; + return this; + } + /** + * Instructs traversal to ignore reference between WSDL elements. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreBindingOutput2SOAPBody() + { + traverseBindingOutput2SOAPBody = false; + return this; + } + /** + * Instructs traversal to ignore reference between WSDL elements. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreBindingFault2SOAPFault() + { + traverseBindingFault2SOAPFault = false; + return this; + } + /** + * Instructs traversal to ignore reference between WSDL elements. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreSOAPHeader2SOAPHeaderFault() + { + traverseSOAPHeader2SOAPHeaderFault = false; + return this; + } + /** + * Instructs traversal to ignore reference between WSDL elements. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreBinding2BindingOperation() + { + traverseBinding2BindingOperation = false; + return this; + } + /** + * Instructs traversal to ignore reference between WSDL elements. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreBinding2Element() + { + traverseBinding2Element = false; + return this; + } + /** + * Instructs traversal to ignore reference between WSDL elements. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreBinding2ExtensibilityElement() + { + traverseBinding2ExtensibilityElement = false; + return this; + } + /** + * Instructs traversal to ignore reference between WSDL elements. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreBinding2PortType() + { + traverseBinding2PortType = false; + return this; + } + /** + * Instructs traversal to ignore reference between WSDL elements. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreBindingFault2Element() + { + traverseBindingFault2Element = false; + return this; + } + /** + * Instructs traversal to ignore reference between WSDL elements. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreBindingFault2ExtensibilityElement() + { + traverseBindingFault2ExtensibilityElement = false; + return this; + } + /** + * Instructs traversal to ignore reference between WSDL elements. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreBindingInput2Element() + { + traverseBindingInput2Element = false; + return this; + } + /** + * Instructs traversal to ignore reference between WSDL elements. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreBindingInput2ExtensibilityElement() + { + traverseBindingInput2ExtensibilityElement = false; + return this; + } + /** + * Instructs traversal to ignore reference between WSDL elements. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreBindingOperation2BindingFault() + { + traverseBindingOperation2BindingFault = false; + return this; + } + /** + * Instructs traversal to ignore reference between WSDL elements. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreBindingOperation2BindingInput() + { + traverseBindingOperation2BindingInput = false; + return this; + } + /** + * Instructs traversal to ignore reference between WSDL elements. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreBindingOperation2BindingOutput() + { + traverseBindingOperation2BindingOutput = false; + return this; + } + /** + * Instructs traversal to ignore reference between WSDL elements. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreBindingOperation2Element() + { + traverseBindingOperation2Element = false; + return this; + } + /** + * Instructs traversal to ignore reference between WSDL elements. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreBindingOperation2ExtensibilityElement() + { + traverseBindingOperation2ExtensibilityElement = false; + return this; + } + /** + * Instructs traversal to ignore reference between WSDL elements. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreBindingOperation2Operation() + { + traverseBindingOperation2Operation = false; + return this; + } + /** + * Instructs traversal to ignore reference between WSDL elements. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreBindingOutput2Element() + { + traverseBindingOutput2Element = false; + return this; + } + /** + * Instructs traversal to ignore reference between WSDL elements. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreBindingOutput2ExtensibilityElement() + { + traverseBindingOutput2ExtensibilityElement = false; + return this; + } + /** + * Instructs traversal to ignore reference between WSDL elements. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreDefinition2Binding() + { + traverseDefinition2Binding = false; + return this; + } + /** + * Instructs traversal to ignore reference between WSDL elements. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreDefinition2Element() + { + traverseDefinition2Element = false; + return this; + } + /** + * Instructs traversal to ignore reference between WSDL elements. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreDefinition2ExtensibilityElement() + { + traverseDefinition2ExtensibilityElement = false; + return this; + } + /** + * Instructs traversal to ignore reference between WSDL elements. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreDefinition2Import() + { + traverseDefinition2Import = false; + return this; + } + /** + * Instructs traversal to ignore reference between WSDL elements. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreDefinition2Message() + { + traverseDefinition2Message = false; + return this; + } + /** + * Instructs traversal to ignore reference between WSDL elements. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreDefinition2PortType() + { + traverseDefinition2PortType = false; + return this; + } + /** + * Instructs traversal to ignore reference between WSDL elements. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreDefinition2Service() + { + traverseDefinition2Service = false; + return this; + } + /** + * Instructs traversal to ignore reference between WSDL elements. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreDefinition2Types() + { + traverseDefinition2Types = false; + return this; + } + /** + * Instructs traversal to ignore reference between WSDL elements. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreFault2Element() + { + traverseFault2Element = false; + return this; + } + /** + * Instructs traversal to ignore reference between WSDL elements. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreFault2Message() + { + traverseFault2Message = false; + return this; + } + /** + * Instructs traversal to ignore reference between WSDL elements. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreImport2Definition() + { + traverseImport2Definition = false; + return this; + } + /** + * Instructs traversal to ignore reference between WSDL elements. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreImport2Element() + { + traverseImport2Element = false; + return this; + } + /** + * Instructs traversal to ignore reference between WSDL elements. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreInput2Element() + { + traverseInput2Element = false; + return this; + } + /** + * Instructs traversal to ignore reference between WSDL elements. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreInput2Message() + { + traverseInput2Message = false; + return this; + } + /** + * Instructs traversal to ignore reference between WSDL elements. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreMessage2Element() + { + traverseMessage2Element = false; + return this; + } + /** + * Instructs traversal to ignore reference between WSDL elements. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreMessage2Part() + { + traverseMessage2Part = false; + return this; + } + /** + * Instructs traversal to ignore reference between WSDL elements. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreOperation2Element() + { + traverseOperation2Element = false; + return this; + } + /** + * Instructs traversal to ignore reference between WSDL elements. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreOperation2Fault() + { + traverseOperation2Fault = false; + return this; + } + /** + * Instructs traversal to ignore reference between WSDL elements. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreOperation2Input() + { + traverseOperation2Input = false; + return this; + } + /** + * Instructs traversal to ignore reference between WSDL elements. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreOperation2Output() + { + traverseOperation2Output = false; + return this; + } + /** + * Instructs traversal to ignore reference between WSDL elements. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreOutput2Element() + { + traverseOutput2Element = false; + return this; + } + /** + * Instructs traversal to ignore reference between WSDL elements. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreOutput2Message() + { + traverseOutput2Message = false; + return this; + } + /** + * Instructs traversal to ignore reference between WSDL elements. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignorePart2Element() + { + traversePart2Element = false; + return this; + } + /** + * Instructs traversal to ignore reference between WSDL elements. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignorePort2Binding() + { + traversePort2Binding = false; + return this; + } + /** + * Instructs traversal to ignore reference between WSDL elements. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignorePort2Element() + { + traversePort2Element = false; + return this; + } + /** + * Instructs traversal to ignore reference between WSDL elements. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignorePort2ExtensibilityElement() + { + traversePort2ExtensibilityElement = false; + return this; + } + /** + * Instructs traversal to ignore reference between WSDL elements. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignorePortType2Element() + { + traversePortType2Element = false; + return this; + } + /** + * Instructs traversal to ignore reference between WSDL elements. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignorePortType2Operation() + { + traversePortType2Operation = false; + return this; + } + /** + * Instructs traversal to ignore reference between WSDL elements. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreService2Element() + { + traverseService2Element = false; + return this; + } + /** + * Instructs traversal to ignore reference between WSDL elements. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreService2ExtensibilityElement() + { + traverseService2ExtensibilityElement = false; + return this; + } + /** + * Instructs traversal to ignore reference between WSDL elements. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreService2Port() + { + traverseService2Port = false; + return this; + } + /** + * Instructs traversal to ignore reference between WSDL elements. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreTypes2Element() + { + traverseTypes2Element = false; + return this; + } + /** + * Instructs traversal to ignore reference between WSDL elements... + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreTypes2ExtensibilityElement() + { + traverseTypes2ExtensibilityElement = false; + return this; + } + + /** + * Instructs traversal to visit or not the corresponding WSDL element. + * @param value true if the WSDL element should be visited, otherwise - false. + * @return a WSDLTraversal object. + */ + public WSDLTraversal visitSOAPBinding(boolean value) + { + visitSOAPBinding = value; + return this; + } + /** + * Instructs traversal to visit or not the corresponding WSDL element. + * @param value true if the WSDL element should be visited, otherwise - false. + * @return a WSDLTraversal object. + */ + public WSDLTraversal visitSOAPBody(boolean value) + { + visitSOAPBody = value; + return this; + } + /** + * Instructs traversal to visit or not the corresponding WSDL element. + * @param value true if the WSDL element should be visited, otherwise - false. + * @return a WSDLTraversal object. + */ + public WSDLTraversal visitSOAPFault(boolean value) + { + visitSOAPFault = value; + return this; + } + /** + * Instructs traversal to visit or not the corresponding WSDL element. + * @param value true if the WSDL element should be visited, otherwise - false. + * @return a WSDLTraversal object. + */ + public WSDLTraversal visitSOAPHeader(boolean value) + { + visitSOAPHeader = value; + return this; + } + /** + * Instructs traversal to visit or not the corresponding WSDL element. + * @param value true if the WSDL element should be visited, otherwise - false. + * @return a WSDLTraversal object. + */ + public WSDLTraversal visitSOAPHeaderFault(boolean value) + { + visitSOAPHeaderFault = value; + return this; + } + /** + * Instructs traversal to visit or not the corresponding WSDL element. + * @param value true if the WSDL element should be visited, otherwise - false. + * @return a WSDLTraversal object. + */ + public WSDLTraversal visitSOAPOperation(boolean value) + { + visitSOAPOperation = value; + return this; + } + /** + * Instructs traversal to visit or not the corresponding WSDL element. + * @param value true if the WSDL element should be visited, otherwise - false. + * @return a WSDLTraversal object. + */ + public WSDLTraversal visitBinding(boolean value) + { + visitBinding = value; + return this; + } + /** + * Instructs traversal to visit or not the corresponding WSDL element. + * @param value true if the WSDL element should be visited, otherwise - false. + * @return a WSDLTraversal object. + */ + public WSDLTraversal visitBindingFault(boolean value) + { + visitBindingFault = value; + return this; + } + /** + * Instructs traversal to visit or not the corresponding WSDL element. + * @param value true if the WSDL element should be visited, otherwise - false. + * @return a WSDLTraversal object. + */ + public WSDLTraversal visitBindingInput(boolean value) + { + visitBindingInput = value; + return this; + } + /** + * Instructs traversal to visit or not the corresponding WSDL element. + * @param value true if the WSDL element should be visited, otherwise - false. + * @return a WSDLTraversal object. + */ + public WSDLTraversal visitBindingOperation(boolean value) + { + visitBindingOperation = value; + return this; + } + /** + * Instructs traversal to visit or not the corresponding WSDL element. + * @param value true if the WSDL element should be visited, otherwise - false. + * @return a WSDLTraversal object. + */ + public WSDLTraversal visitBindingOutput(boolean value) + { + visitBindingOutput = value; + return this; + } + /** + * Instructs traversal to visit or not the corresponding WSDL element. + * @param value true if the WSDL element should be visited, otherwise - false. + * @return a WSDLTraversal object. + */ + public WSDLTraversal visitDefinition(boolean value) + { + visitDefinition = value; + return this; + } + /** + * Instructs traversal to visit or not the corresponding WSDL element. + * @param value true if the WSDL element should be visited, otherwise - false. + * @return a WSDLTraversal object. + */ + public WSDLTraversal visitElement(boolean value) + { + visitElement = value; + return this; + } + /** + * Instructs traversal to visit or not the corresponding WSDL element. + * @param value true if the WSDL element should be visited, otherwise - false. + * @return a WSDLTraversal object. + */ + public WSDLTraversal visitExtensibilityElement(boolean value) + { + visitExtensibilityElement = value; + return this; + } + /** + * Instructs traversal to visit or not the corresponding WSDL element. + * @param value true if the WSDL element should be visited, otherwise - false. + * @return a WSDLTraversal object. + */ + public WSDLTraversal visitFault(boolean value) + { + visitFault = value; + return this; + } + /** + * Instructs traversal to visit or not the corresponding WSDL element. + * @param value true if the WSDL element should be visited, otherwise - false. + * @return a WSDLTraversal object. + */ + public WSDLTraversal visitImport(boolean value) + { + visitImport = value; + return this; + } + /** + * Instructs traversal to visit or not the corresponding WSDL element. + * @param value true if the WSDL element should be visited, otherwise - false. + * @return a WSDLTraversal object. + */ + public WSDLTraversal visitInput(boolean value) + { + visitInput = value; + return this; + } + /** + * Instructs traversal to visit or not the corresponding WSDL element. + * @param value true if the WSDL element should be visited, otherwise - false. + * @return a WSDLTraversal object. + */ + public WSDLTraversal visitMessage(boolean value) + { + visitMessage = value; + return this; + } + /** + * Instructs traversal to visit or not the corresponding WSDL element. + * @param value true if the WSDL element should be visited, otherwise - false. + * @return a WSDLTraversal object. + */ + public WSDLTraversal visitOperation(boolean value) + { + visitOperation = value; + return this; + } + /** + * Instructs traversal to visit or not the corresponding WSDL element. + * @param value true if the WSDL element should be visited, otherwise - false. + * @return a WSDLTraversal object. + */ + public WSDLTraversal visitOutput(boolean value) + { + visitOutput = value; + return this; + } + /** + * Instructs traversal to visit or not the corresponding WSDL element. + * @param value true if the WSDL element should be visited, otherwise - false. + * @return a WSDLTraversal object. + */ + public WSDLTraversal visitPart(boolean value) + { + visitPart = value; + return this; + } + /** + * Instructs traversal to visit or not the corresponding WSDL element. + * @param value true if the WSDL element should be visited, otherwise - false. + * @return a WSDLTraversal object. + */ + public WSDLTraversal visitPort(boolean value) + { + visitPort = value; + return this; + } + /** + * Instructs traversal to visit or not the corresponding WSDL element. + * @param value true if the WSDL element should be visited, otherwise - false. + * @return a WSDLTraversal object. + */ + public WSDLTraversal visitPortType(boolean value) + { + visitPortType = value; + return this; + } + /** + * Instructs traversal to visit or not the corresponding WSDL element. + * @param value true if the WSDL element should be visited, otherwise - false. + * @return a WSDLTraversal object. + */ + public WSDLTraversal visitService(boolean value) + { + visitService = value; + return this; + } + /** + * Instructs traversal to visit or not the corresponding WSDL element. + * @param value true if the WSDL element should be visited, otherwise - false. + * @return a WSDLTraversal object. + */ + public WSDLTraversal visitTypes(boolean value) + { + visitTypes = value; + return this; + } + + /** + * Instructs traversal to ignore all references to the corresponding WSDL + * element. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreBinding() + { + traverseDefinition2Binding = false; + traversePort2Binding = false; + return this; + } + /** + * Instructs traversal to ignore all references to the corresponding WSDL + * element. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreBindingFault() + { + traverseBindingOperation2BindingFault = false; + return this; + } + /** + * Instructs traversal to ignore all references to the corresponding WSDL + * element. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreBindingInput() + { + traverseBindingOperation2BindingInput = false; + return this; + } + /** + * Instructs traversal to ignore all references to the corresponding WSDL + * element. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreBindingOperation() + { + traverseBinding2BindingOperation = false; + return this; + } + /** + * Instructs traversal to ignore all references to the corresponding WSDL + * element. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreBindingOutput() + { + traverseBindingOperation2BindingOutput = false; + return this; + } + /** + * Instructs traversal to ignore all references to the corresponding WSDL + * element. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreDefinition() + { + traverseImport2Definition = false; + return this; + } + /** + * Instructs traversal to ignore all references to the corresponding WSDL + * element. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreElement() + { + traverseBinding2Element = false; + traverseBindingFault2Element = false; + traverseBindingInput2Element = false; + traverseBindingOperation2Element = false; + traverseBindingOutput2Element = false; + traverseDefinition2Element = false; + traversePort2Element = false; + traverseService2Element = false; + traverseFault2Element = false; + traverseOutput2Element = false; + traverseImport2Element = false; + traverseInput2Element = false; + traverseOperation2Element = false; + traverseMessage2Element = false; + traversePart2Element = false; + traversePortType2Element = false; + traverseTypes2Element = false; + return this; + } + /** + * Instructs traversal to ignore all references to the corresponding WSDL + * element. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreExtensibilityElement() + { + traverseService2ExtensibilityElement = false; + traversePort2ExtensibilityElement = false; + traverseDefinition2ExtensibilityElement = false; + traverseBindingOutput2ExtensibilityElement = false; + traverseBinding2ExtensibilityElement = false; + traverseBindingFault2ExtensibilityElement = false; + traverseBindingInput2ExtensibilityElement = false; + traverseBindingOperation2ExtensibilityElement = false; + traverseTypes2ExtensibilityElement = false; + return this; + } + /** + * Instructs traversal to ignore all references to the corresponding WSDL + * element. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreSOAPBinding() + { + traverseBinding2SOAPBinding = false; + return this; + } + /** + * Instructs traversal to ignore all references to the corresponding WSDL + * element. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreSOAPOperation() + { + traverseBindingOperation2SOAPOperation = false; + return this; + } + /** + * Instructs traversal to ignore all references to the corresponding WSDL + * element. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreSOAPBody() + { + traverseBindingInput2SOAPBody = false; + traverseBindingOutput2SOAPBody = false; + return this; + } + /** + * Instructs traversal to ignore all references to the corresponding WSDL + * element. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreSOAPHeader() + { + traverseBindingInput2SOAPHeader = false; + traverseBindingOutput2SOAPHeader = false; + return this; + } + /** + * Instructs traversal to ignore all references to the corresponding WSDL + * element. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreSOAPHeaderFault() + { + traverseSOAPHeader2SOAPHeaderFault = false; + return this; + } + /** + * Instructs traversal to ignore all references to the corresponding WSDL + * element. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreSOAPFault() + { + traverseBindingFault2SOAPFault = false; + return this; + } + /** + * Instructs traversal to ignore all references to the corresponding WSDL + * element. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreFault() + { + traverseOperation2Fault = false; + return this; + } + /** + * Instructs traversal to ignore all references to the corresponding WSDL + * element. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreImport() + { + traverseImport2Definition = false; // fix + return this; + } + /** + * Instructs traversal to ignore all references to the corresponding WSDL + * element. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreInput() + { + traverseOperation2Input = false; + return this; + } + /** + * Instructs traversal to ignore all references to the corresponding WSDL + * element. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreMessage() + { + traverseFault2Message = false; + traverseDefinition2Message = false; + traverseInput2Message = false; + traverseOutput2Message = false; + return this; + } + /** + * Instructs traversal to ignore all references to the corresponding WSDL + * element. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreOperation() + { + traverseBindingOperation2Operation = false; + traversePortType2Operation = false; + return this; + } + /** + * Instructs traversal to ignore all references to the corresponding WSDL + * element. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreOutput() + { + traverseOperation2Output = false; + return this; + } + /** + * Instructs traversal to ignore all references to the corresponding WSDL + * element. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignorePart() + { + traverseMessage2Part = false; + //traverseSOAPBody2Part = false; + return this; + } + /** + * Instructs traversal to ignore all references to the corresponding WSDL + * element. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignorePort() + { + traverseService2Port = false; + return this; + } + /** + * Instructs traversal to ignore all references to the corresponding WSDL + * element. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignorePortType() + { + traverseBinding2PortType = false; + traverseDefinition2PortType = false; + return this; + } + /** + * Instructs traversal to ignore all references to the corresponding WSDL + * element. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreService() + { + traverseDefinition2Service = false; + return this; + } + /** + * Instructs traversal to ignore all references to the corresponding WSDL + * element. + * @return a WSDLTraversal object. + */ + public WSDLTraversal ignoreTypes() + { + traverseDefinition2Types = false; + return this; + } + + /** + * The method adjusts traveseXXX variables according to the visitXXX variables + */ + private void adjust() + { + adjustPart(); + adjustService(); + adjustTypes(); + adjustOperation(); + adjustInput(); + adjustOutput(); + adjustFault(); + adjustBinding(); + adjustBindingOperation(); + adjustBindingInput(); + adjustBindingOutput(); + adjustBindingFault(); + adjustImport(); + adjustElement(); + adjustMessage(); + adjustPort(); + adjustPortType(); + adjustDefinition(); + adjustExtensibilityElement(); + adjustSOAPBinding(); + adjustSOAPBody(); + adjustSOAPHeader(); + adjustSOAPHeaderFault(); + adjustSOAPFault(); + adjustSOAPOperation(); + } + + /** + * The method adjusts traversal ignore flags according to the + * corresponding visit flags. + * @return boolean + */ + private boolean adjustExtensibilityElement() + { + boolean value = visitExtensibilityElement; + if (!value) + ignoreExtensibilityElement(); + return value; + } + /** + * The method adjusts traversal ignore flags according to the + * corresponding visit flags. + * @return boolean + */ + private boolean adjustPart() + { + boolean value = visitPart || (traversePart2Element && adjustElement()); + if (!value) + ignorePart(); + return value; + } + /** + * The method adjusts traversal ignore flags according to the + * corresponding visit flags. + * @return boolean + */ + private boolean adjustSOAPHeader() + { + boolean value = + visitSOAPHeader + || (traverseSOAPHeader2SOAPHeaderFault && adjustSOAPHeaderFault()); + if (!value) + ignoreSOAPHeader(); + return value; + } + /** + * The method adjusts traversal ignore flags according to the + * corresponding visit flags. + * @return boolean + */ + private boolean adjustBindingOutput() + { + boolean value = + visitBindingOutput + || (traverseBindingOutput2Element && adjustElement()) + || (traverseBindingOutput2ExtensibilityElement + && adjustExtensibilityElement()) + || (traverseBindingOutput2SOAPBody + && adjustSOAPBody() + || (traverseBindingOutput2SOAPHeader && adjustSOAPHeader())); + if (!value) + ignoreBindingOutput(); + return value; + } + /** + * The method adjusts traversal ignore flags according to the + * corresponding visit flags. + * @return boolean + */ + private boolean adjustElement() + { + boolean value = visitElement; + if (!value) + ignoreElement(); + return value; + } + /** + * The method adjusts traversal ignore flags according to the + * corresponding visit flags. + * @return boolean + */ + private boolean adjustTypes() + { + boolean value = + visitTypes + || (traverseTypes2Element && adjustElement()) + || (traverseTypes2ExtensibilityElement && adjustExtensibilityElement()); + if (!value) + ignoreTypes(); + return value; + } + /** + * The method adjusts traversal ignore flags according to the + * corresponding visit flags. + * @return boolean + */ + private boolean adjustSOAPBinding() + { + boolean value = visitSOAPBinding; + if (!value) + ignoreSOAPBinding(); + return value; + } + /** + * The method adjusts traversal ignore flags according to the + * corresponding visit flags. + * @return boolean + */ + private boolean adjustPort() + { + boolean value = + visitPort + || (traversePort2Element && adjustElement()) + || (traversePort2ExtensibilityElement && adjustExtensibilityElement()) + || (traversePort2Binding && adjustBinding()); + if (!value) + ignorePort(); + return value; + } + /** + * The method adjusts traversal ignore flags according to the + * corresponding visit flags. + * @return boolean + */ + private boolean adjustOperation() + { + boolean value = + visitOperation + || (traverseOperation2Element && adjustElement()) + || (traverseOperation2Input && adjustInput()) + || (traverseOperation2Output && adjustOutput()) + || (traverseOperation2Fault && adjustFault()); + if (!value) + ignoreOperation(); + return value; + } + /** + * The method adjusts traversal ignore flags according to the + * corresponding visit flags. + * @return boolean + */ + private boolean adjustBindingOperation() + { + boolean value = + visitBindingOperation + || (traverseBindingOperation2Element && adjustElement()) + || (traverseBindingOperation2BindingFault && adjustBindingFault()) + || (traverseBindingOperation2BindingOutput && adjustBindingOutput()) + || (traverseBindingOperation2Operation && adjustOperation()) + || (traverseBindingOperation2BindingInput && adjustBindingInput()) + || (traverseBindingOperation2ExtensibilityElement + && adjustExtensibilityElement()) + || (traverseBindingOperation2SOAPOperation && adjustSOAPOperation()); + if (!value) + ignoreBindingOperation(); + return value; + } + /** + * The method adjusts traversal ignore flags according to the + * corresponding visit flags. + * @return boolean + */ + private boolean adjustInput() + { + boolean value = + visitInput + || (traverseInput2Element && adjustElement()) + || (traverseInput2Message && adjustMessage()); + if (!value) + ignoreInput(); + return value; + } + /** + * The method adjusts traversal ignore flags according to the + * corresponding visit flags. + * @return boolean + */ + private boolean adjustBinding() + { + boolean value = + visitBinding + || (traverseBinding2Element && adjustElement()) + || (traverseBinding2BindingOperation && adjustBindingOperation()) + || (traverseBinding2ExtensibilityElement && adjustExtensibilityElement()) + || (traverseBinding2PortType && adjustPortType()) + || (traverseBinding2SOAPBinding && adjustSOAPBinding()); + if (!value) + ignoreBinding(); + return value; + } + /** + * The method adjusts traversal ignore flags according to the + * corresponding visit flags. + * @return boolean + */ + private boolean adjustSOAPBody() + { + boolean value = visitSOAPBody; + /* || + (traverseSOAPBody2Part && adjustPart());*/ + if (!value) + ignoreSOAPBody(); + return value; + } + /** + * The method adjusts traversal ignore flags according to the + * corresponding visit flags. + * @return boolean + */ + private boolean adjustSOAPHeaderFault() + { + boolean value = visitSOAPHeaderFault; + if (!value) + ignoreSOAPHeaderFault(); + return value; + } + /** + * The method adjusts traversal ignore flags according to the + * corresponding visit flags. + * @return boolean + */ + private boolean adjustBindingInput() + { + boolean value = + visitBindingInput + || (traverseBindingInput2Element && adjustElement()) + || (traverseBindingInput2ExtensibilityElement + && adjustExtensibilityElement()) + || (traverseBindingInput2SOAPBody + && adjustSOAPBody() + || (traverseBindingInput2SOAPHeader && adjustSOAPHeader())); + if (!value) + ignoreBindingInput(); + return value; + } + /** + * The method adjusts traversal ignore flags according to the + * corresponding visit flags. + * @return boolean + */ + private boolean adjustOutput() + { + boolean value = + visitOutput + || (traverseOutput2Element && adjustElement()) + || (traverseOutput2Message && adjustMessage()); + if (!value) + ignoreOutput(); + return value; + } + /** + * The method adjusts traversal ignore flags according to the + * corresponding visit flags. + * @return boolean + */ + private boolean adjustBindingFault() + { + boolean value = + visitBindingFault + || (traverseBindingFault2Element && adjustElement()) + || (traverseBindingFault2ExtensibilityElement + && adjustExtensibilityElement()) + || (traverseBindingFault2SOAPFault && adjustSOAPFault()); + if (!value) + ignoreBindingFault(); + return value; + } + /** + * The method adjusts traversal ignore flags according to the + * corresponding visit flags. + * @return boolean + */ + private boolean adjustSOAPOperation() + { + boolean value = visitSOAPOperation; + if (!value) + ignoreSOAPOperation(); + return value; + } + /** + * The method adjusts traversal ignore flags according to the + * corresponding visit flags. + * @return boolean + */ + private boolean adjustDefinition() + { + boolean value = + visitDefinition + || (traverseDefinition2Element && adjustElement()) + || (traverseDefinition2Import && adjustImport()) + || (traverseDefinition2Types && adjustTypes()) + || (traverseDefinition2Message && adjustMessage()) + || (traverseDefinition2ExtensibilityElement + && adjustExtensibilityElement()) + || (traverseDefinition2PortType && adjustPortType()) + || (traverseDefinition2Binding && adjustBinding()) + || (traverseDefinition2Service && adjustService()); + if (!value) + ignoreDefinition(); + return value; + } + /** + * The method adjusts traversal ignore flags according to the + * corresponding visit flags. + * @return boolean + */ + private boolean adjustSOAPFault() + { + boolean value = visitSOAPFault; + if (!value) + ignoreSOAPFault(); + return value; + } + /** + * The method adjusts traversal ignore flags according to the + * corresponding visit flags. + * @return boolean + */ + private boolean adjustImport() + { + boolean value = visitImport || (traverseImport2Definition + /* && adjustDefinition()*/ + ) + || // avoid cycling problem. Thus, you should call ignoreImport manually + (traverseImport2Element && adjustElement()); + if (!value) + ignoreImport(); + return value; + } + /** + * The method adjusts traversal ignore flags according to the + * corresponding visit flags. + * @return boolean + */ + private boolean adjustFault() + { + boolean value = + visitFault + || (traverseFault2Element && adjustElement()) + || (traverseFault2Message && adjustMessage()); + if (!value) + ignoreFault(); + return value; + } + /** + * The method adjusts traversal ignore flags according to the + * corresponding visit flags. + * @return boolean + */ + private boolean adjustPortType() + { + boolean value = + visitPortType + || (traversePortType2Element && adjustElement()) + || (traversePortType2Operation && adjustOperation()); + if (!value) + ignorePortType(); + return value; + } + /** + * The method adjusts traversal ignore flags according to the + * corresponding visit flags. + * @return boolean + */ + private boolean adjustService() + { + boolean value = + visitService + || (traverseService2Element && adjustElement()) + || (traverseService2ExtensibilityElement && adjustExtensibilityElement()) + || (traverseService2Port && adjustPort()); + if (!value) + ignoreService(); + return value; + } + /** + * The method adjusts traversal ignore flags according to the + * corresponding visit flags. + * @return boolean + */ + private boolean adjustMessage() + { + boolean value = + visitMessage + || (traverseMessage2Element && adjustElement()) + || (traverseMessage2Part && adjustPart()); + if (!value) + ignoreMessage(); + return value; + } + + /** + * The method traverses given WSDL extensibility element according to the + * settings in the traversal context. + * + * @param objExtensibilityElement a WSDL extensibility element artifact. + * @param parent parent of the WSDL extensibility element artifact. + * @param ctx the traversal contex. + */ + private void traverse( + ExtensibilityElement objExtensibilityElement, + Object parent, + WSDLTraversalContext ctx) + { + ctx.resumeExtensibilityElementProcessing(); + ctx.setExtensibilityElement(objExtensibilityElement); + if (visitExtensibilityElement) + visitor.visit(objExtensibilityElement, parent, ctx); + } + + /** + * The method traverses given WSDL part artifact according to the settings in + * the traversal context. + * + * @param objPart the WSDL part artifact. + * @param parent parent of the WSDL part artifact. + * @param ctx the traversal contex. + */ + private void traverse(Part objPart, Object parent, WSDLTraversalContext ctx) + { + ctx.resumePartProcessing(); + ctx.setPart(objPart); + if (visitPart) + { + visitor.visit(objPart, parent, ctx); + if (!ctx.processPart()) + return; + } + if (objPart == null) + return; + if (traversePart2Element) + traverse(objPart.getDocumentationElement(), objPart, ctx); + } + + /** + * The method traverses given WSDL SOAP header artifact according to the + * settings in the traversal context. + * + * @param objSOAPHeader a WSDL SOAP header artifact. + * @param parent parent of the WSDL SOAP header artifact. + * @param ctx the traversal contex. + */ + private void traverse( + SOAPHeader objSOAPHeader, + Object parent, + WSDLTraversalContext ctx) + { + ctx.resumeSOAPHeaderProcessing(); + ctx.setSOAPHeader(objSOAPHeader); + if (visitSOAPHeader) + { + visitor.visit(objSOAPHeader, parent, ctx); + if (!ctx.processSOAPHeader()) + return; + } + if (objSOAPHeader == null) + return; + if (traverseSOAPHeader2SOAPHeaderFault + && objSOAPHeader.getSOAPHeaderFaults() != null) + { + Iterator it = objSOAPHeader.getSOAPHeaderFaults().iterator(); + while (it.hasNext()) + { + traverse((SOAPHeaderFault) it.next(), objSOAPHeader, ctx); + if (!ctx.processSOAPHeader()) + return; + } + } + } + + /** + * The method traverses given WSDL element artifact according to the settings in + * the traversal context. + * + * @param objElement a WSDL element artifact. + * @param parent parent of the WSDL element artifact. + * @param ctx the traversal contex. + */ + private void traverse( + Element objElement, + Object parent, + WSDLTraversalContext ctx) + { + ctx.setElement(objElement); + if (visitElement) + visitor.visit(objElement, parent, ctx); + } + + /** + * The method traverses given WSDL types artifact according to the settings in + * the traversal context. + * + * @param objTypes a WSDL types artifact. + * @param parent parent of the WSDL types artifact. + * @param ctx the traversal contex. + */ + private void traverse( + Types objTypes, + Object parent, + WSDLTraversalContext ctx) + { + ctx.resumeTypesProcessing(); + ctx.setTypes(objTypes); + if (visitTypes) + { + visitor.visit(objTypes, parent, ctx); + if (!ctx.processTypes()) + return; + } + if (objTypes == null) + return; + if (traverseTypes2Element) + { + traverse(objTypes.getDocumentationElement(), objTypes, ctx); + if (!ctx.processTypes()) + return; + } + if (traverseTypes2ExtensibilityElement + && objTypes.getExtensibilityElements() != null) + { + Iterator it = objTypes.getExtensibilityElements().iterator(); + while (it.hasNext()) + { + traverse((ExtensibilityElement) it.next(), objTypes, ctx); + if (!ctx.processTypes()) + return; + } + } + } + + /** + * The method traverses given WSDL SOAP binding artifact according to the + * settings in the traversal context. + * + * @param objSOAPBinding a WSDL SOAP binding artifact. + * @param parent parent of the WSDL SOAP binding artifact. + * @param ctx the traversal contex. + */ + private void traverse( + SOAPBinding objSOAPBinding, + Object parent, + WSDLTraversalContext ctx) + { + ctx.setSOAPBinding(objSOAPBinding); + if (visitSOAPBinding) + visitor.visit(objSOAPBinding, parent, ctx); + } + + /** + * The method traverses given WSDL definition artifact according to the + * settings in the traversal context. + * + * @param objDefinition a WSDL definition artifact. + * @param parent parent of the WSDL definition artifact. + * @param ctx the traversal contex. + */ + private void traverse( + Definition objDefinition, + Object parent, + WSDLTraversalContext ctx) + { + ctx.resumeDefinitionProcessing(); + ctx.setDefinition(objDefinition); + if (visitDefinition) + { + visitor.visit(objDefinition, parent, ctx); + if (!ctx.processDefinition()) + return; + } + if (objDefinition == null) + return; + if (traverseDefinition2Import && objDefinition.getImports() != null) + { + Iterator it = objDefinition.getImports().values().iterator(); + while (it.hasNext()) + { + Vector v = (Vector) it.next(); + if (v != null) + { + Iterator it2 = v.iterator(); + while (it2.hasNext()) + { + traverse((Import) it2.next(), objDefinition, ctx); + if (!ctx.processDefinition()) + return; + } + } + } + } + if (traverseDefinition2Element) + { + traverse(objDefinition.getDocumentationElement(), objDefinition, ctx); + if (!ctx.processDefinition()) + return; + } + if (traverseDefinition2Types) + { + traverse(objDefinition.getTypes(), objDefinition, ctx); + if (!ctx.processDefinition()) + return; + } + if (traverseDefinition2Message && objDefinition.getMessages() != null) + { + Iterator it = objDefinition.getMessages().values().iterator(); + while (it.hasNext()) + { + traverse((Message) it.next(), objDefinition, ctx); + if (!ctx.processDefinition()) + return; + } + } + if (traverseDefinition2PortType && objDefinition.getPortTypes() != null) + { + Iterator it = objDefinition.getPortTypes().values().iterator(); + while (it.hasNext()) + { + traverse((PortType) it.next(), objDefinition, ctx); + if (!ctx.processDefinition()) + return; + } + } + if (traverseDefinition2Binding && objDefinition.getBindings() != null) + { + Iterator it = objDefinition.getBindings().values().iterator(); + while (it.hasNext()) + { + traverse((Binding) it.next(), objDefinition, ctx); + if (!ctx.processDefinition()) + return; + } + } + if (traverseDefinition2Service && objDefinition.getServices() != null) + { + Iterator it = objDefinition.getServices().values().iterator(); + while (it.hasNext()) + { + traverse((Service) it.next(), objDefinition, ctx); + if (!ctx.processDefinition()) + return; + } + } + if (traverseDefinition2ExtensibilityElement + && objDefinition.getExtensibilityElements() != null) + { + Iterator it = objDefinition.getExtensibilityElements().iterator(); + while (it.hasNext()) + { + traverse((ExtensibilityElement) it.next(), objDefinition, ctx); + if (!ctx.processDefinition()) + return; + } + } + } + + /** + * The method traverses given WSDL port artifact according to the settings in + * the traversal context. + * + * @param objPort a WSDL port artifact. + * @param parent parent of the WSDL port artifact. + * @param ctx the traversal contex. + */ + private void traverse(Port objPort, Object parent, WSDLTraversalContext ctx) + { + ctx.resumePortProcessing(); + ctx.setPort(objPort); + if (visitPort) + { + visitor.visit(objPort, parent, ctx); + if (!ctx.processPort()) + return; + } + if (objPort == null) + return; + if (traversePort2Element) + { + traverse(objPort.getDocumentationElement(), objPort, ctx); + if (!ctx.processPort()) + return; + } + if (traversePort2Binding) + { + traverse(objPort.getBinding(), objPort, ctx); + if (!ctx.processPort()) + return; + } + if (traversePort2ExtensibilityElement + && objPort.getExtensibilityElements() != null) + { + Iterator it = objPort.getExtensibilityElements().iterator(); + while (it.hasNext()) + { + traverse((ExtensibilityElement) it.next(), objPort, ctx); + if (!ctx.processPort()) + return; + } + } + } + + /** + * The method traverses given WSDL operation artifact according to the settings in + * the traversal context. + * + * @param objOperation a WSDL operation artifact. + * @param parent parent of the WSDL operation artifactt. + * @param ctx the traversal contex. + */ + private void traverse( + Operation objOperation, + Object parent, + WSDLTraversalContext ctx) + { + ctx.resumeOperationProcessing(); + ctx.setOperation(objOperation); + if (visitOperation) + { + visitor.visit(objOperation, parent, ctx); + if (!ctx.processOperation()) + return; + } + if (objOperation == null) + return; + if (traverseOperation2Element) + { + traverse(objOperation.getDocumentationElement(), objOperation, ctx); + if (!ctx.processOperation()) + return; + } + if (traverseOperation2Input) + { + traverse(objOperation.getInput(), objOperation, ctx); + if (!ctx.processOperation()) + return; + } + if (traverseOperation2Output) + { + traverse(objOperation.getOutput(), objOperation, ctx); + if (!ctx.processOperation()) + return; + } + if (traverseOperation2Fault && objOperation.getFaults() != null) + { + Iterator it = objOperation.getFaults().values().iterator(); + while (it.hasNext()) + { + traverse((Fault) it.next(), objOperation, ctx); + if (!ctx.processOperation()) + return; + } + } + } + + /** + * The method traverses given WSDL input artifact according to the settings in + * the traversal context. + * + * @param objInput a WSDL input artifact. + * @param parent parent of the WSDL input artifact. + * @param ctx the traversal contex. + */ + private void traverse( + Input objInput, + Object parent, + WSDLTraversalContext ctx) + { + ctx.resumeInputProcessing(); + ctx.setInput(objInput); + if (visitInput) + { + visitor.visit(objInput, parent, ctx); + if (!ctx.processInput()) + return; + } + if (objInput == null) + return; + if (traverseInput2Element) + { + traverse(objInput.getDocumentationElement(), objInput, ctx); + if (!ctx.processInput()) + return; + } + if (traverseInput2Message) + traverse(objInput.getMessage(), objInput, ctx); + } + + /** + * The method traverses given WSDL SOAP body artifact according to the + * settings in the traversal context. + * + * @param objSOAPBody a WSDL SOAP body artifact. + * @param parent parent of the WSDL SOAP body artifact. + * @param ctx the traversal contex. + */ + private void traverse( + SOAPBody objSOAPBody, + Object parent, + WSDLTraversalContext ctx) + { + // ctx.resumeSOAPBodyProcessing(); + ctx.setSOAPBody(objSOAPBody); + if (visitSOAPBody) + // { + visitor.visit(objSOAPBody, parent, ctx); + /* if (!ctx.processSOAPBody()) + return; + } + if (objSOAPBody == null) + return; + if (traverseSOAPBody2Part && objSOAPBody.getParts() != null) { + if (ctx) + Iterator it = objSOAPBody.getParts().iterator(); + while (it.hasNext()) { + + traverse((Part)it.next(), objSOAPBody, ctx); + if (!ctx.processSOAPBody()) + return; + } + } + */ + } + + /** + * The method traverses given WSDL SOAP header fault artifact according to + * the settings in the traversal context. + * + * @param objSOAPHeaderFault a WSDL SOAP header fault artifact. + * @param parent parent of the WSDL SOAP header fault artifact. + * @param ctx the traversal contex. + */ + private void traverse( + SOAPHeaderFault objSOAPHeaderFault, + Object parent, + WSDLTraversalContext ctx) + { + ctx.setSOAPHeaderFault(objSOAPHeaderFault); + if (visitSOAPHeaderFault) + visitor.visit(objSOAPHeaderFault, parent, ctx); + } + + /** + * The method traverses given WSDL output artifact according to the settings in + * the traversal context. + * + * @param objOutput a WSDL output artifact. + * @param parent parent of the WSDL output artifact. + * @param ctx the traversal contex. + * @param parent + * @param ctx + */ + private void traverse( + Output objOutput, + Object parent, + WSDLTraversalContext ctx) + { + ctx.resumeOutputProcessing(); + ctx.setOutput(objOutput); + if (visitOutput) + { + visitor.visit(objOutput, parent, ctx); + if (!ctx.processOutput()) + return; + } + if (objOutput == null) + return; + if (traverseOutput2Element) + { + traverse(objOutput.getDocumentationElement(), objOutput, ctx); + if (!ctx.processOutput()) + return; + } + if (traverseOutput2Message) + traverse(objOutput.getMessage(), objOutput, ctx); + } + + /** + * The method traverses given WSDL binding fault artifact according to the + * settings in the traversal context. + * + * @param objBindingFault a WSDL binding fault artifact. + * @param parent parent of the WSDL binding fault artifact. + * @param ctx the traversal contex. + */ + private void traverse( + BindingFault objBindingFault, + Object parent, + WSDLTraversalContext ctx) + { + ctx.resumeBindingFaultProcessing(); + ctx.setBindingFault(objBindingFault); + if (visitBindingFault) + { + visitor.visit(objBindingFault, parent, ctx); + if (!ctx.processBindingFault()) + return; + } + if (objBindingFault == null) + return; + if (traverseBindingFault2Element) + { + traverse(objBindingFault.getDocumentationElement(), objBindingFault, ctx); + if (!ctx.processBindingFault()) + return; + } + if (traverseBindingFault2SOAPFault + && objBindingFault.getExtensibilityElements() != null) + { + Iterator it = objBindingFault.getExtensibilityElements().iterator(); + while (it.hasNext()) + { + Object o = it.next(); + if (o instanceof SOAPFault) + traverse((SOAPFault) o, objBindingFault, ctx); + if (!ctx.processBindingFault()) + return; + } + } + if (traverseBindingFault2ExtensibilityElement + && objBindingFault.getExtensibilityElements() != null) + { + Iterator it = objBindingFault.getExtensibilityElements().iterator(); + while (it.hasNext()) + { + traverse((ExtensibilityElement) it.next(), objBindingFault, ctx); + if (!ctx.processBindingFault()) + return; + } + } + } + + /** + * The method traverses given WSDL SOAP operation artifact according to + * the settings in the traversal context. + * + * @param objSOAPOperation a WSDL SOAP operation artifact. + * @param parent parent of the WSDL SOAP operation artifact. + * @param ctx the traversal contex. + */ + private void traverse( + SOAPOperation objSOAPOperation, + Object parent, + WSDLTraversalContext ctx) + { + ctx.setSOAPOperation(objSOAPOperation); + if (visitSOAPOperation) + visitor.visit(objSOAPOperation, parent, ctx); + } + + /** + * The method traverses given WSDL binding input artifact according to + * the settings in the traversal context. + * + * @param objBindingInput a WSDL binding input artifact. + * @param parent parent of the WSDL binding input artifact. + * @param ctx the traversal contex. + */ + private void traverse( + BindingInput objBindingInput, + Object parent, + WSDLTraversalContext ctx) + { + ctx.resumeBindingInputProcessing(); + ctx.setBindingInput(objBindingInput); + if (visitBindingInput) + { + visitor.visit(objBindingInput, parent, ctx); + if (!ctx.processBindingInput()) + return; + } + if (objBindingInput == null) + return; + if (traverseBindingInput2Element) + { + traverse(objBindingInput.getDocumentationElement(), objBindingInput, ctx); + if (!ctx.processBindingInput()) + return; + } + if ((traverseBindingInput2SOAPBody || traverseBindingInput2SOAPHeader) + && objBindingInput.getExtensibilityElements() != null) + { + Iterator it = objBindingInput.getExtensibilityElements().iterator(); + while (it.hasNext()) + { + Object o = it.next(); + if (traverseBindingInput2SOAPBody && (o instanceof SOAPBody)) + traverse((SOAPBody) o, objBindingInput, ctx); + else if (traverseBindingInput2SOAPHeader && (o instanceof SOAPHeader)) + traverse((SOAPHeader) o, objBindingInput, ctx); + if (!ctx.processBindingInput()) + return; + } + } + if (traverseBindingInput2ExtensibilityElement + && objBindingInput.getExtensibilityElements() != null) + { + Iterator it = objBindingInput.getExtensibilityElements().iterator(); + while (it.hasNext()) + { + traverse((ExtensibilityElement) it.next(), objBindingInput, ctx); + if (!ctx.processBindingInput()) + return; + } + } + } + + /** + * The method traverses given WSDL binding operation artifact according to + * the settings in the traversal context. + * + * @param objBindingOperation a WSDL binding operation artifact. + * @param parent parent of the WSDL binding operation artifact. + * @param ctx the traversal contex. + */ + private void traverse( + BindingOperation objBindingOperation, + Object parent, + WSDLTraversalContext ctx) + { + ctx.resumeBindingOperationProcessing(); + ctx.setBindingOperation(objBindingOperation); + if (visitBindingOperation) + { + visitor.visit(objBindingOperation, parent, ctx); + if (!ctx.processBindingOperation()) + return; + } + if (objBindingOperation == null) + return; + if (traverseBindingOperation2Element) + { + traverse( + objBindingOperation.getDocumentationElement(), + objBindingOperation, + ctx); + if (!ctx.processBindingOperation()) + return; + } + if (traverseBindingOperation2SOAPOperation + && objBindingOperation.getExtensibilityElements() != null) + { + Iterator it = objBindingOperation.getExtensibilityElements().iterator(); + while (it.hasNext()) + { + Object o = it.next(); + if (o instanceof SOAPOperation) + traverse((SOAPOperation) o, objBindingOperation, ctx); + if (!ctx.processBindingOperation()) + return; + } + } + if (traverseBindingOperation2ExtensibilityElement + && objBindingOperation.getExtensibilityElements() != null) + { + Iterator it = objBindingOperation.getExtensibilityElements().iterator(); + while (it.hasNext()) + { + traverse((ExtensibilityElement) it.next(), objBindingOperation, ctx); + if (!ctx.processBindingOperation()) + return; + } + } + if (traverseBindingOperation2Operation) + { + traverse(objBindingOperation.getOperation(), objBindingOperation, ctx); + if (!ctx.processBindingOperation()) + return; + } + if (traverseBindingOperation2BindingInput) + { + traverse(objBindingOperation.getBindingInput(), objBindingOperation, ctx); + if (!ctx.processBindingOperation()) + return; + } + if (traverseBindingOperation2BindingOutput) + { + traverse( + objBindingOperation.getBindingOutput(), + objBindingOperation, + ctx); + if (!ctx.processBindingOperation()) + return; + } + if (traverseBindingOperation2BindingFault + && objBindingOperation.getBindingFaults() != null) + { + Iterator it = objBindingOperation.getBindingFaults().values().iterator(); + while (it.hasNext()) + { + traverse((BindingFault) it.next(), objBindingOperation, ctx); + if (!ctx.processBindingOperation()) + return; + } + } + } + + /** + * The method traverses given WSDL SOAP fault artifact according to the + * settings in the traversal context. + * + * @param objSOAPFault a WSDL SOAP fault artifact. + * @param parent parent of the WSDL SOAP fault artifact. + * @param ctx the traversal contex. + */ + private void traverse( + SOAPFault objSOAPFault, + Object parent, + WSDLTraversalContext ctx) + { + ctx.setSOAPFault(objSOAPFault); + if (visitSOAPFault) + visitor.visit(objSOAPFault, parent, ctx); + } + + /** + * The method traverses given WSDL binding artifact according to the settings in + * the traversal context. + * + * @param objBinding a WSDL binding artifact. + * @param parent parent of the WSDL binding artifact. + * @param ctx the traversal contex. + */ + private void traverse( + Binding objBinding, + Object parent, + WSDLTraversalContext ctx) + { + ctx.resumeBindingProcessing(); + ctx.setBinding(objBinding); + if (visitBinding) + { + visitor.visit(objBinding, parent, ctx); + if (!ctx.processBinding()) + return; + } + if (objBinding == null) + return; + if (traverseBinding2Element) + { + traverse(objBinding.getDocumentationElement(), objBinding, ctx); + if (!ctx.processBinding()) + return; + } + if (traverseBinding2SOAPBinding + && objBinding.getExtensibilityElements() != null) + { + Iterator it = objBinding.getExtensibilityElements().iterator(); + while (it.hasNext()) + { + Object o = it.next(); + if (o instanceof SOAPBinding) + traverse((SOAPBinding) o, objBinding, ctx); + if (!ctx.processBinding()) + return; + } + } + if (traverseBinding2PortType) + { + traverse(objBinding.getPortType(), objBinding, ctx); + if (!ctx.processBinding()) + return; + } + if (traverseBinding2BindingOperation + && objBinding.getBindingOperations() != null) + { + Iterator it = objBinding.getBindingOperations().iterator(); + while (it.hasNext()) + { + traverse((BindingOperation) it.next(), objBinding, ctx); + if (!ctx.processBinding()) + return; + } + } + if (traverseBinding2ExtensibilityElement + && objBinding.getExtensibilityElements() != null) + { + Iterator it = objBinding.getExtensibilityElements().iterator(); + while (it.hasNext()) + { + traverse((ExtensibilityElement) it.next(), objBinding, ctx); + if (!ctx.processBinding()) + return; + } + } + } + + /** + * The method traverses given WSDL fault artifact according to the settings in + * the traversal context. + * + * @param objFault a WSDL fault artifact. + * @param parent parent of the WSDL fault artifact. + * @param ctx the traversal contex. + */ + private void traverse( + Fault objFault, + Object parent, + WSDLTraversalContext ctx) + { + ctx.resumeFaultProcessing(); + ctx.setFault(objFault); + if (visitFault) + { + visitor.visit(objFault, parent, ctx); + if (!ctx.processFault()) + return; + } + if (objFault == null) + return; + if (traverseFault2Element) + { + traverse(objFault.getDocumentationElement(), objFault, ctx); + if (!ctx.processFault()) + return; + } + if (traverseFault2Message) + traverse(objFault.getMessage(), objFault, ctx); + } + + /** + * The method traverses given WSDL service artifact according to the settings in + * the traversal context. + * + * @param objService a WSDL service artifact. + * @param parent parent of the WSDL service artifact. + * @param ctx the traversal contex. + */ + private void traverse( + Service objService, + Object parent, + WSDLTraversalContext ctx) + { + ctx.resumeServiceProcessing(); + ctx.setService(objService); + if (visitService) + { + visitor.visit(objService, parent, ctx); + if (!ctx.processService()) + return; + } + if (objService == null) + return; + if (traverseService2Element) + { + traverse(objService.getDocumentationElement(), objService, ctx); + if (!ctx.processService()) + return; + } + if (traverseService2ExtensibilityElement + && objService.getExtensibilityElements() != null) + { + Iterator it = objService.getExtensibilityElements().iterator(); + while (it.hasNext()) + { + traverse((ExtensibilityElement) it.next(), objService, ctx); + if (!ctx.processService()) + return; + } + } + if (traverseService2Port && objService.getPorts() != null) + { + Iterator it = objService.getPorts().values().iterator(); + while (it.hasNext()) + { + traverse((Port) it.next(), objService, ctx); + if (!ctx.processService()) + return; + } + } + } + + /** + * The method traverses given WSDL import artifact according to the settings in + * the traversal context. + * + * @param objImport a WSDL import artifact. + * @param parent parent of the WSDL import artifact. + * @param ctx the traversal contex. + */ + private void traverse( + Import objImport, + Object parent, + WSDLTraversalContext ctx) + { + ctx.resumeImportProcessing(); + ctx.setImport(objImport); + if (visitImport) + { + visitor.visit(objImport, parent, ctx); + if (!ctx.processImport()) + return; + } + if (objImport == null) + return; + if (traverseImport2Element) + { + traverse(objImport.getDocumentationElement(), objImport, ctx); + if (!ctx.processImport()) + return; + } + if (traverseImport2Definition) + traverse(objImport.getDefinition(), objImport, ctx); + } + + /** + * The method traverses given WSDL binding output artifact according to the + * settings in the traversal context. + * + * @param objBindingOutput a WSDL binding output artifact. + * @param parent parent of the WSDL binding output artifact. + * @param ctx the traversal contex. + */ + private void traverse( + BindingOutput objBindingOutput, + Object parent, + WSDLTraversalContext ctx) + { + ctx.resumeBindingOutputProcessing(); + ctx.setBindingOutput(objBindingOutput); + if (visitBindingOutput) + { + visitor.visit(objBindingOutput, parent, ctx); + if (!ctx.processBindingOutput()) + return; + } + if (objBindingOutput == null) + return; + if (traverseBindingOutput2Element) + { + traverse( + objBindingOutput.getDocumentationElement(), + objBindingOutput, + ctx); + if (!ctx.processBindingOutput()) + return; + } + if ((traverseBindingOutput2SOAPBody || traverseBindingOutput2SOAPHeader) + && objBindingOutput.getExtensibilityElements() != null) + { + Iterator it = objBindingOutput.getExtensibilityElements().iterator(); + while (it.hasNext()) + { + Object o = it.next(); + if (traverseBindingOutput2SOAPBody && (o instanceof SOAPBody)) + traverse((SOAPBody) o, objBindingOutput, ctx); + else if (traverseBindingOutput2SOAPHeader && (o instanceof SOAPHeader)) + traverse((SOAPHeader) o, objBindingOutput, ctx); + if (!ctx.processBindingOutput()) + return; + } + } + if (traverseBindingOutput2ExtensibilityElement + && objBindingOutput.getExtensibilityElements() != null) + { + Iterator it = objBindingOutput.getExtensibilityElements().iterator(); + while (it.hasNext()) + { + traverse((ExtensibilityElement) it.next(), objBindingOutput, ctx); + if (!ctx.processBindingOutput()) + return; + } + } + } + + /** + * The method traverses given WSDL port type artifact according to the settings in + * the traversal context. + * + * @param objPortType a WSDL port type artifact. + * @param parent parent of the WSDL port type. + * @param ctx the traversal contex. + */ + private void traverse( + PortType objPortType, + Object parent, + WSDLTraversalContext ctx) + { + ctx.resumePortTypeProcessing(); + ctx.setPortType(objPortType); + if (visitPortType) + { + visitor.visit(objPortType, parent, ctx); + if (!ctx.processPortType()) + return; + } + if (objPortType == null) + return; + if (traversePortType2Element) + { + traverse(objPortType.getDocumentationElement(), objPortType, ctx); + if (!ctx.processPortType()) + return; + } + if (traversePortType2Operation && objPortType.getOperations() != null) + { + Iterator it = objPortType.getOperations().iterator(); + while (it.hasNext()) + { + traverse((Operation) it.next(), objPortType, ctx); + if (!ctx.processPortType()) + return; + } + } + } + + /** + * The method traverses given WSDL message artifact according to the settings in + * the traversal context. + * + * @param objMessage a WSDL message. + * @param parent parent of the WSDL message. + * @param ctx the traversal contex. + */ + private void traverse( + Message objMessage, + Object parent, + WSDLTraversalContext ctx) + { + ctx.resumeMessageProcessing(); + ctx.setMessage(objMessage); + if (visitMessage) + { + visitor.visit(objMessage, parent, ctx); + if (!ctx.processMessage()) + return; + } + if (objMessage == null) + return; + if (traverseMessage2Element) + { + traverse(objMessage.getDocumentationElement(), objMessage, ctx); + if (!ctx.processMessage()) + return; + } + if (traverseMessage2Part && objMessage.getParts() != null) + { + Iterator it = objMessage.getParts().values().iterator(); + while (it.hasNext()) + { + traverse((Part) it.next(), objMessage, ctx); + if (!ctx.processMessage()) + return; + } + } + } + + /** + * The method traverses given WSDL part artifact according to the settings. + * @param a a WSDL part artifact. + */ + public void traverse(Part a) + { + adjust(); + traverse(a, null, new WSDLTraversalContext(this)); + } + /** + * The method traverses given WSDL service artifact according to the settings. + * @param a a WSDL service artifact. + */ + public void traverse(Service a) + { + adjust(); + traverse(a, null, new WSDLTraversalContext(this)); + } + /** + * The method traverses given WSDL types artifact according to the settings. + * @param a WSDL types artifact. + */ + public void traverse(Types a) + { + adjust(); + traverse(a, null, new WSDLTraversalContext(this)); + } + /** + * The method traverses given WSDL operation artifact according to the settings. + * @param a a WSDL operation artifact. + */ + public void traverse(Operation a) + { + adjust(); + traverse(a, null, new WSDLTraversalContext(this)); + } + /** + * The method traverses given WSDL input artifact according to the settings. + * @param a a WSDL input artifact. + */ + public void traverse(Input a) + { + adjust(); + traverse(a, null, new WSDLTraversalContext(this)); + } + /** + * The method traverses given WSDL output artifact according to the settings. + * @param a a WSDL output artifact. + */ + public void traverse(Output a) + { + adjust(); + traverse(a, null, new WSDLTraversalContext(this)); + } + /** + * The method traverses given WSDL fault artifact according to the settings. + * @param a a WSDL fault artifact. + */ + public void traverse(Fault a) + { + adjust(); + traverse(a, null, new WSDLTraversalContext(this)); + } + /** + * The method traverses given WSDL binding artifact according to the settings. + * @param a a WSDL binding artifact. + */ + public void traverse(Binding a) + { + adjust(); + traverse(a, null, new WSDLTraversalContext(this)); + } + /** + * The method traverses given WSDL binding operation artifact according to the + * settings. + * @param a a WSDL binding operation artifact. + */ + public void traverse(BindingOperation a) + { + adjust(); + traverse(a, null, new WSDLTraversalContext(this)); + } + /** + * The method traverses given WSDL binding input artifact according to + * the settings. + * @param a a WSDL binding input artifact. + */ + public void traverse(BindingInput a) + { + adjust(); + traverse(a, null, new WSDLTraversalContext(this)); + } + /** + * The method traverses given WSDL binding output artifact according to + * the settings. + * @param a a WSDL binding output artifact. + */ + public void traverse(BindingOutput a) + { + adjust(); + traverse(a, null, new WSDLTraversalContext(this)); + } + /** + * The method traverses given WSDL binding fault artifact according to + * the settings. + * @param a a WSDL binding fault artifact. + */ + public void traverse(BindingFault a) + { + adjust(); + traverse(a, null, new WSDLTraversalContext(this)); + } + /** + * The method traverses given WSDL import artifact according to the settings. + * @param a a WSDL import artifact. + */ + public void traverse(Import a) + { + adjust(); + traverse(a, null, new WSDLTraversalContext(this)); + } + /** + * The method traverses given WSDL element artifact according to the settings. + * @param a a WSDL element artifact. + */ + public void traverse(Element a) + { + adjust(); + traverse(a, null, new WSDLTraversalContext(this)); + } + /** + * The method traverses given WSDL message artifact according to the settings. + * @param a a WSDL message artifact. + */ + public void traverse(Message a) + { + adjust(); + traverse(a, null, new WSDLTraversalContext(this)); + } + /** + * The method traverses given WSDL port artifact according to the settings. + * @param a a WSDL port artifact. + */ + public void traverse(Port a) + { + adjust(); + traverse(a, null, new WSDLTraversalContext(this)); + } + /** + * The method traverses given WSDL port type artifact according to the settings. + * @param a a WSDL port type artifact. + */ + public void traverse(PortType a) + { + adjust(); + traverse(a, null, new WSDLTraversalContext(this)); + } + /** + * The method traverses given WSDL definition artifact according to the settings. + * @param a a WSDL definition artifact. + */ + public void traverse(Definition a) + { + adjust(); + traverse(a, null, new WSDLTraversalContext(this)); + } + /** + * The method traverses given WSDL extensibility elment artifact according + * to the settings. + * @param a a WSDL extensibility element artifact. + */ + public void traverse(ExtensibilityElement a) + { + adjust(); + traverse(a, null, new WSDLTraversalContext(this)); + } + /** + * The method traverses given WSDL SOAP binding artifact according to + * the settings. + * @param a a WSDL SOAP binding artifact. + */ + public void traverse(SOAPBinding a) + { + adjust(); + traverse(a, null, new WSDLTraversalContext(this)); + } + /** + * The method traverses given WSDL SOAP body artifact according to the settings. + * @param a a WSDL SOAP body artifact. + */ + public void traverse(SOAPBody a) + { + adjust(); + traverse(a, null, new WSDLTraversalContext(this)); + } + /** + * The method traverses given WSDL SOAP header artifact according to the settings. + * @param a a WSDL SOAP header artifact. + */ + public void traverse(SOAPHeader a) + { + adjust(); + traverse(a, null, new WSDLTraversalContext(this)); + } + /** + * The method traverses given WSDL SOAP header fault artifact according to + * the settings. + * @param a a WSDL SOAP header fault artifact. + */ + public void traverse(SOAPHeaderFault a) + { + adjust(); + traverse(a, null, new WSDLTraversalContext(this)); + } + /** + * The method traverses given WSDL SOAP fault artifact according to the settings. + * @param a a WSDL SOAP fault artifact. + */ + public void traverse(SOAPFault a) + { + adjust(); + traverse(a, null, new WSDLTraversalContext(this)); + } + /** + * The method traverses given WSDL SOAP operation artifact according to + * the settings. + * @param a a WSDL SOAP operation artifact. + */ + public void traverse(SOAPOperation a) + { + adjust(); + traverse(a, null, new WSDLTraversalContext(this)); + } + + /** + * The method traverses given WSDL part artifact according to the settings. + * @param a a WSDL part artifact. + * @param params a Map object representing settings. + */ + public void traverse(Part a, Map params) + { + adjust(); + WSDLTraversalContext ctx = new WSDLTraversalContext(this); + if (params != null) + ctx.params.putAll(params); + traverse(a, null, ctx); + } + /** + * The method traverses given WSDL service artifact according to the settings. + * @param a a WSDL service artifact. + * @param params a Map object representing settings. + */ + public void traverse(Service a, Map params) + { + adjust(); + WSDLTraversalContext ctx = new WSDLTraversalContext(this); + if (params != null) + ctx.params.putAll(params); + traverse(a, null, ctx); + } + /** + * The method traverses given WSDL types artifact according to the settings. + * @param a a WSDL types artifact. + * @param params a Map object representing settings. + */ + public void traverse(Types a, Map params) + { + adjust(); + WSDLTraversalContext ctx = new WSDLTraversalContext(this); + if (params != null) + ctx.params.putAll(params); + traverse(a, null, ctx); + } + /** + * The method traverses given WSDL operation artifact according to the settings. + * @param a a WSDL operation artifact. + * @param params a Map object representing settings. + */ + public void traverse(Operation a, Map params) + { + adjust(); + WSDLTraversalContext ctx = new WSDLTraversalContext(this); + if (params != null) + ctx.params.putAll(params); + traverse(a, null, ctx); + } + /** + * The method traverses given WSDL input artifact according to the settings. + * @param a a WSDL input artifact. + * @param params a Map object representing settings. + */ + public void traverse(Input a, Map params) + { + adjust(); + WSDLTraversalContext ctx = new WSDLTraversalContext(this); + if (params != null) + ctx.params.putAll(params); + traverse(a, null, ctx); + } + /** + * The method traverses given WSDL output artifact according to the settings. + * @param a a WSDL output artifact. + * @param params a Map object representing settings. + */ + public void traverse(Output a, Map params) + { + adjust(); + WSDLTraversalContext ctx = new WSDLTraversalContext(this); + if (params != null) + ctx.params.putAll(params); + traverse(a, null, ctx); + } + /** + * The method traverses given WSDL fault artifact according to the settings. + * @param a a WSDL fault artifact. + * @param params a Map object representing settings. + */ + public void traverse(Fault a, Map params) + { + adjust(); + WSDLTraversalContext ctx = new WSDLTraversalContext(this); + if (params != null) + ctx.params.putAll(params); + traverse(a, null, ctx); + } + /** + * The method traverses given WSDL binding artifact according to the settings. + * @param a a WSDL binding artifact. + * @param params a Map object representing settings. + */ + public void traverse(Binding a, Map params) + { + adjust(); + WSDLTraversalContext ctx = new WSDLTraversalContext(this); + if (params != null) + ctx.params.putAll(params); + traverse(a, null, ctx); + } + /** + * The method traverses given WSDL binding operation artifact according + * to the settings. + * @param a a WSDL binding operation artifact. + * @param params a Map object representing settings. + */ + public void traverse(BindingOperation a, Map params) + { + adjust(); + WSDLTraversalContext ctx = new WSDLTraversalContext(this); + if (params != null) + ctx.params.putAll(params); + traverse(a, null, ctx); + } + /** + * The method traverses given WSDL binding input artifact according + * to the settings. + * @param a a WSDL binding input artifact. + * @param params a Map object representing settings. + */ + public void traverse(BindingInput a, Map params) + { + adjust(); + WSDLTraversalContext ctx = new WSDLTraversalContext(this); + if (params != null) + ctx.params.putAll(params); + traverse(a, null, ctx); + } + /** + * The method traverses given WSDL binding output artifact according to + * the settings. + * @param a a WSDL binding output artifact. + * @param params a Map object representing settings. + */ + public void traverse(BindingOutput a, Map params) + { + adjust(); + WSDLTraversalContext ctx = new WSDLTraversalContext(this); + if (params != null) + ctx.params.putAll(params); + traverse(a, null, ctx); + } + /** + * The method traverses given WSDL binding fault artifact according to + * the settings. + * @param a a WSDL binding fault artifact. + * @param params a Map object representing settings. + */ + public void traverse(BindingFault a, Map params) + { + adjust(); + WSDLTraversalContext ctx = new WSDLTraversalContext(this); + if (params != null) + ctx.params.putAll(params); + traverse(a, null, ctx); + } + /** + * The method traverses given WSDL import artifact according to the settings. + * @param a a WSDL import artifact. + * @param params a Map object representing settings. + */ + public void traverse(Import a, Map params) + { + adjust(); + WSDLTraversalContext ctx = new WSDLTraversalContext(this); + if (params != null) + ctx.params.putAll(params); + traverse(a, null, ctx); + } + /** + * The method traverses given WSDL element artifact according to the settings. + * @param a a WSDL element artifact. + * @param params a Map object representing settings. + */ + public void traverse(Element a, Map params) + { + adjust(); + WSDLTraversalContext ctx = new WSDLTraversalContext(this); + if (params != null) + ctx.params.putAll(params); + traverse(a, null, ctx); + } + /** + * The method traverses given WSDL message artifact according to the settings. + * @param a a WSDL message. + * @param params a Map object representing settings. + */ + public void traverse(Message a, Map params) + { + adjust(); + WSDLTraversalContext ctx = new WSDLTraversalContext(this); + if (params != null) + ctx.params.putAll(params); + traverse(a, null, ctx); + } + /** + * The method traverses given WSDL port artifact according to the settings. + * @param a a WSDL port. + * @param params a Map object representing settings. + */ + public void traverse(Port a, Map params) + { + adjust(); + WSDLTraversalContext ctx = new WSDLTraversalContext(this); + if (params != null) + ctx.params.putAll(params); + traverse(a, null, ctx); + } + /** + * The method traverses given WSDL port type artifact according to the settings. + * @param a a WSDL port type artifact. + * @param params a Map object representing settings. + */ + public void traverse(PortType a, Map params) + { + adjust(); + WSDLTraversalContext ctx = new WSDLTraversalContext(this); + if (params != null) + ctx.params.putAll(params); + traverse(a, null, ctx); + } + /** + * The method traverses given WSDL definition artifact according to the settings. + * @param a a WSDL definition artifact. + * @param params a Map object representing settings. + */ + public void traverse(Definition a, Map params) + { + adjust(); + WSDLTraversalContext ctx = new WSDLTraversalContext(this); + if (params != null) + ctx.params.putAll(params); + traverse(a, null, ctx); + } + /** + * The method traverses given WSDL extensibility element artifact according to the settings. + * @param a a WSDL extensibility element artifact. + * @param params a Map object representing settings. + */ + public void traverse(ExtensibilityElement a, Map params) + { + adjust(); + WSDLTraversalContext ctx = new WSDLTraversalContext(this); + if (params != null) + ctx.params.putAll(params); + traverse(a, null, ctx); + } + /** + * The method traverses given WSDL SOAP binding artifact according to the settings. + * @param a a WSDL SOAP binding artifact. + * @param params a Map object representing settings. + */ + public void traverse(SOAPBinding a, Map params) + { + adjust(); + WSDLTraversalContext ctx = new WSDLTraversalContext(this); + if (params != null) + ctx.params.putAll(params); + traverse(a, null, ctx); + } + /** + * The method traverses given WSDL SOAP body artifact according to the settings. + * @param a a WSDL SOAP body artifact. + * @param params a Map object representing settings. + */ + public void traverse(SOAPBody a, Map params) + { + adjust(); + WSDLTraversalContext ctx = new WSDLTraversalContext(this); + if (params != null) + ctx.params.putAll(params); + traverse(a, null, ctx); + } + /** + * The method traverses given WSDL SOAP header artifact according to the settings. + * @param a a WSDL SOAP header artifact. + * @param params a Map object representing settings. + */ + public void traverse(SOAPHeader a, Map params) + { + adjust(); + WSDLTraversalContext ctx = new WSDLTraversalContext(this); + if (params != null) + ctx.params.putAll(params); + traverse(a, null, ctx); + } + /** + * The method traverses given WSDL hearder fault artifact according to the settings. + * @param a a WSDL SOAP header fault artifact. + * @param params a Map object representing settings. + */ + public void traverse(SOAPHeaderFault a, Map params) + { + adjust(); + WSDLTraversalContext ctx = new WSDLTraversalContext(this); + if (params != null) + ctx.params.putAll(params); + traverse(a, null, ctx); + } + /** + * The method traverses given WSDL SOAP fault artifact according to the settings. + * @param a a WSDL SOAP fault artifact. + * @param params a Map object representing settings. + */ + public void traverse(SOAPFault a, Map params) + { + adjust(); + WSDLTraversalContext ctx = new WSDLTraversalContext(this); + if (params != null) + ctx.params.putAll(params); + traverse(a, null, ctx); + } + /** + * The method traverses given WSDL SOAP operation artifact according to the settings. + * @param a a WSDL SOAP operation artifact. + * @param params a Map object representing settings. + */ + public void traverse(SOAPOperation a, Map params) + { + adjust(); + WSDLTraversalContext ctx = new WSDLTraversalContext(this); + if (params != null) + ctx.params.putAll(params); + traverse(a, null, ctx); + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/traversal/WSDLTraversalContext.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/traversal/WSDLTraversalContext.java new file mode 100644 index 000000000..aa1e7aabe --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/traversal/WSDLTraversalContext.java @@ -0,0 +1,1125 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.wsdl.traversal; + +import java.util.Map; +import java.util.TreeMap; + +import javax.wsdl.Part; +import javax.wsdl.Service; +import javax.wsdl.Types; +import javax.wsdl.Operation; +import javax.wsdl.Input; +import javax.wsdl.Output; +import javax.wsdl.Fault; +import javax.wsdl.Binding; +import javax.wsdl.BindingOperation; +import javax.wsdl.BindingInput; +import javax.wsdl.BindingOutput; +import javax.wsdl.BindingFault; +import javax.wsdl.Import; +import org.w3c.dom.Element; +import javax.wsdl.Message; +import javax.wsdl.Port; +import javax.wsdl.PortType; +import javax.wsdl.Definition; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.soap.SOAPBinding; +import javax.wsdl.extensions.soap.SOAPBody; +import javax.wsdl.extensions.soap.SOAPHeader; +import javax.wsdl.extensions.soap.SOAPHeaderFault; +import javax.wsdl.extensions.soap.SOAPFault; +import javax.wsdl.extensions.soap.SOAPOperation; + +/** + * The class represents runtime context for the traversal process. + * Context stores artifacts being processed. + * + * @author Andrey Kulik + */ +public class WSDLTraversalContext +{ + /** + * Flags which indicate whether corresponding WSDL element should be processed + * or not. + */ + private boolean processPart = true; + private boolean processService = true; + private boolean processTypes = true; + private boolean processOperation = true; + private boolean processInput = true; + private boolean processOutput = true; + private boolean processFault = true; + private boolean processBinding = true; + private boolean processBindingOperation = true; + private boolean processBindingInput = true; + private boolean processBindingOutput = true; + private boolean processBindingFault = true; + private boolean processImport = true; + private boolean processElement = true; + private boolean processMessage = true; + private boolean processPort = true; + private boolean processPortType = true; + private boolean processDefinition = true; + private boolean processExtensibilityElement = true; + private boolean processSOAPBinding = true; + private boolean processSOAPHeader = true; + private boolean processSOAPHeaderFault = true; + private boolean processSOAPFault = true; + private boolean processSOAPOperation = true; + + /** + * Last processed WSDL elements. + */ + private Part activePart = null; + private Service activeService = null; + private Types activeTypes = null; + private Operation activeOperation = null; + private Input activeInput = null; + private Output activeOutput = null; + private Fault activeFault = null; + private Binding activeBinding = null; + private BindingOperation activeBindingOperation = null; + private BindingInput activeBindingInput = null; + private BindingOutput activeBindingOutput = null; + private BindingFault activeBindingFault = null; + private Import activeImport = null; + private Element activeElement = null; + private Message activeMessage = null; + private Port activePort = null; + private PortType activePortType = null; + private Definition activeDefinition = null; + private ExtensibilityElement activeExtensibilityElement = null; + private SOAPBinding activeSOAPBinding = null; + private SOAPBody activeSOAPBody = null; + private SOAPHeader activeSOAPHeader = null; + private SOAPHeaderFault activeSOAPHeaderFault = null; + private SOAPFault activeSOAPFault = null; + private SOAPOperation activeSOAPOperation = null; + + /** + * Parameters map + */ + Map params = new TreeMap(); + + /** + * Active traversal. + */ + final private WSDLTraversal traversal; + + /** + * The default constructor. + * @param traversal + */ + WSDLTraversalContext(WSDLTraversal traversal) + { + this.traversal = traversal; + } + + /** + * Gets the active traversal. + * @return tha active traversal. + */ + public WSDLTraversal getTraversal() + { + return traversal; + } + + /** + * Gets parameter from context by the given key. + * @param key a key value. + * @return a parameter corresponding to the given key. + */ + public Object getParameter(Object key) + { + return params.get(key); + } + + /** + * Adds parameter into context with the given key. + * @param key the key. + * @param value the value. + */ + public void addParameter(Object key, Object value) + { + params.put(key, value); + } + + /** + * Removes the parameter from context by the given key. + * @param key a key value. + */ + public void removeParameter(Object key) + { + params.remove(key); + } + + /** + * Cancels processing of the corresponding WSDL part. + */ + public void cancelPartProcessing() + { + processPart = false; + } + /** + * Cancels processing of the corresponding WSDL service. + */ + public void cancelServiceProcessing() + { + processService = false; + } + /** + * Cancels processing of the corresponding WSDL types. + */ + public void cancelTypesProcessing() + { + processTypes = false; + } + /** + * Cancels processing of the corresponding WSDL operation. + */ + public void cancelOperationProcessing() + { + processOperation = false; + } + /** + * Cancels processing of the corresponding WSDL input. + */ + public void cancelInputProcessing() + { + processInput = false; + } + /** + * Cancels processing of the corresponding WSDL output. + */ + public void cancelOutputProcessing() + { + processOutput = false; + } + /** + * Cancels processing of the corresponding WSDL fault. + */ + public void cancelFaultProcessing() + { + processFault = false; + } + /** + * Cancels processing of the corresponding WSDL binding. + */ + public void cancelBindingProcessing() + { + processBinding = false; + } + /** + * Cancels processing of the corresponding WSDL binding operation. + */ + public void cancelBindingOperationProcessing() + { + processBindingOperation = false; + } + /** + * Cancels processing of the corresponding WSDL binding input. + */ + public void cancelBindingInputProcessing() + { + processBindingInput = false; + } + /** + * Cancels processing of the corresponding WSDL binding output. + */ + public void cancelBindingOutputProcessing() + { + processBindingOutput = false; + } + /** + * Cancels processing of the corresponding WSDL binding fault. + */ + public void cancelBindingFaultProcessing() + { + processBindingFault = false; + } + /** + * Cancels processing of the corresponding WSDL import. + */ + public void cancelImportProcessing() + { + processImport = false; + } + /** + * Cancels processing of the corresponding WSDL element. + */ + public void cancelElementProcessing() + { + processElement = false; + } + /** + * Cancels processing of the corresponding WSDL message. + */ + public void cancelMessageProcessing() + { + processMessage = false; + } + /** + * Cancels processing of the corresponding WSDL port. + */ + public void cancelPortProcessing() + { + processPort = false; + } + /** + * Cancels processing of the corresponding WSDL port type. + */ + public void cancelPortTypeProcessing() + { + processPortType = false; + } + /** + * Cancels processing of the corresponding WSDL definition. + */ + public void cancelDefinitionProcessing() + { + processDefinition = false; + } + /** + * Cancels processing of the corresponding WSDL extensibility element. + */ + public void cancelExtensibilityElementProcessing() + { + processExtensibilityElement = false; + } + /** + * Cancels processing of the corresponding WSDL SOAP binding. + */ + public void cancelSOAPBindingProcessing() + { + processSOAPBinding = false; + } + /** + * Cancels processing of the corresponding WSDL SOAP header. + */ + public void cancelSOAPHeaderProcessing() + { + processSOAPHeader = false; + } + /** + * Cancels processing of the corresponding WSDL SOAP header fault. + */ + public void cancelSOAPHeaderFaultProcessing() + { + processSOAPHeaderFault = false; + } + /** + * Cancels processing of the corresponding WSDL SOAP fault. + */ + public void cancelSOAPFaultProcessing() + { + processSOAPFault = false; + } + /** + * Cancels processing of the corresponding WSDL operation. + */ + public void cancelSOAPOperationProcessing() + { + processSOAPOperation = false; + } + + /** + * Cancels WSDL elements processing. + */ + public void cancelProcessing() + { + cancelPartProcessing(); + cancelServiceProcessing(); + cancelTypesProcessing(); + cancelOperationProcessing(); + cancelInputProcessing(); + cancelOutputProcessing(); + cancelFaultProcessing(); + cancelBindingProcessing(); + cancelBindingOperationProcessing(); + cancelBindingInputProcessing(); + cancelBindingOutputProcessing(); + cancelBindingFaultProcessing(); + cancelImportProcessing(); + cancelElementProcessing(); + cancelMessageProcessing(); + cancelPortProcessing(); + cancelPortTypeProcessing(); + cancelDefinitionProcessing(); + cancelExtensibilityElementProcessing(); + cancelSOAPBindingProcessing(); + cancelSOAPHeaderProcessing(); + cancelSOAPHeaderFaultProcessing(); + cancelSOAPFaultProcessing(); + cancelSOAPOperationProcessing(); + } + + /** + * Resumes processing of the corresponding WSDL part. + */ + public void resumePartProcessing() + { + processPart = true; + } + /** + * Resumes processing of the corresponding WSDL service. + */ + public void resumeServiceProcessing() + { + processService = true; + } + /** + * Resumes processing of the corresponding WSDL types. + */ + public void resumeTypesProcessing() + { + processTypes = true; + } + /** + * Resumes processing of the corresponding WSDL operation. + */ + public void resumeOperationProcessing() + { + processOperation = true; + } + /** + * Resumes processing of the corresponding WSDL input. + */ + public void resumeInputProcessing() + { + processInput = true; + } + /** + * Resumes processing of the corresponding WSDL output. + */ + public void resumeOutputProcessing() + { + processOutput = true; + } + /** + * Resumes processing of the corresponding WSDL fault. + */ + public void resumeFaultProcessing() + { + processFault = true; + } + /** + * Resumes processing of the corresponding WSDL binding. + */ + public void resumeBindingProcessing() + { + processBinding = true; + } + /** + * Resumes processing of the corresponding WSDL binding operation. + */ + public void resumeBindingOperationProcessing() + { + processBindingOperation = true; + } + /** + * Resumes processing of the corresponding WSDL binding input. + */ + public void resumeBindingInputProcessing() + { + processBindingInput = true; + } + /** + * Resumes processing of the corresponding WSDL binding output. + */ + public void resumeBindingOutputProcessing() + { + processBindingOutput = true; + } + /** + * Resumes processing of the corresponding WSDL binding fault. + */ + public void resumeBindingFaultProcessing() + { + processBindingFault = true; + } + /** + * Resumes processing of the corresponding WSDL import. + */ + public void resumeImportProcessing() + { + processImport = true; + } + /** + * Resumes processing of the corresponding WSDL element. + */ + public void resumeElementProcessing() + { + processElement = true; + } + /** + * Resumes processing of the corresponding WSDL message. + */ + public void resumeMessageProcessing() + { + processMessage = true; + } + /** + * Resumes processing of the corresponding WSDL port. + */ + public void resumePortProcessing() + { + processPort = true; + } + /** + * Resumes processing of the corresponding WSDL port type. + */ + public void resumePortTypeProcessing() + { + processPortType = true; + } + /** + * Resumes processing of the corresponding WSDL definition. + */ + public void resumeDefinitionProcessing() + { + processDefinition = true; + } + /** + * Resumes processing of the corresponding WSDL extensibility element. + */ + public void resumeExtensibilityElementProcessing() + { + processExtensibilityElement = true; + } + /** + * Resumes processing of the corresponding WSDL SOAP binding. + */ + public void resumeSOAPBindingProcessing() + { + processSOAPBinding = true; + } + /** + * Resumes processing of the corresponding WSDL SOAP header. + */ + public void resumeSOAPHeaderProcessing() + { + processSOAPHeader = true; + } + /** + * Resumes processing of the corresponding WSDL SOAP header fault. + */ + public void resumeSOAPHeaderFaultProcessing() + { + processSOAPHeaderFault = true; + } + /** + * Resumes processing of the corresponding WSDL SOAP fault. + */ + public void resumeSOAPFaultProcessing() + { + processSOAPFault = true; + } + /** + * Resumes processing of the corresponding WSDL SOAP operation. + */ + public void resumeSOAPOperationProcessing() + { + processSOAPOperation = true; + } + /** + * Indicates whether the corresponding WSDL part should be processed. + * @return true if the corresponding WSDL part should be processed. + */ + public boolean processPart() + { + return processPart; + } + /** + * Indicates whether the corresponding WSDL service should be processed. + * @return true if the corresponding WSDL service should be processed. + */ + public boolean processService() + { + return processService; + } + /** + * Indicates whether the corresponding WSDL types should be processed. + * @return true if the corresponding WSDL types should be processed. + */ + public boolean processTypes() + { + return processTypes; + } + /** + * Indicates whether the corresponding WSDL operation should be processed. + * @return true if the corresponding WSDL operation should be processed. + */ + public boolean processOperation() + { + return processOperation; + } + /** + * Indicates whether the corresponding WSDL input should be processed. + * @return true if the corresponding WSDL input should be processed. + */ + public boolean processInput() + { + return processInput; + } + /** + * Indicates whether the corresponding WSDL output should be processed. + * @return true if the corresponding WSDL output should be processed. + */ + public boolean processOutput() + { + return processOutput; + } + /** + * Indicates whether the corresponding WSDL fault should be processed. + * @return true if the corresponding WSDL fault should be processed. + */ + public boolean processFault() + { + return processFault; + } + /** + * Indicates whether the corresponding WSDL binding should be processed. + * @return true if the corresponding WSDL binding should be processed. + */ + public boolean processBinding() + { + return processBinding; + } + /** + * Indicates whether the corresponding WSDL binding operation should be processed. + * @return true if the corresponding WSDL binding operation should be processed. + */ + public boolean processBindingOperation() + { + return processBindingOperation; + } + /** + * Indicates whether the corresponding WSDL binding input should be processed. + * @return true if the corresponding WSDL binding input should be processed. + */ + public boolean processBindingInput() + { + return processBindingInput; + } + /** + * Indicates whether the corresponding WSDL binding output should be processed. + * @return true if the corresponding WSDL binding output should be processed. + */ + public boolean processBindingOutput() + { + return processBindingOutput; + } + /** + * Indicates whether the corresponding WSDL binding fault should be processed. + * @return true if the corresponding WSDL binding fault should be processed. + */ + public boolean processBindingFault() + { + return processBindingFault; + } + /** + * Indicates whether the corresponding WSDL import should be processed. + * @return true if the corresponding WSDL import should be processed. + */ + public boolean processImport() + { + return processImport; + } + /** + * Indicates whether the corresponding WSDL element should be processed. + * @return true if the corresponding WSDL element should be processed. + */ + public boolean processElement() + { + return processElement; + } + /** + * Indicates whether the corresponding WSDL message should be processed. + * @return true if the corresponding WSDL message should be processed. + */ + public boolean processMessage() + { + return processMessage; + } + /** + * Indicates whether the corresponding WSDL port should be processed. + * @return true if the corresponding WSDL port should be processed. + */ + public boolean processPort() + { + return processPort; + } + /** + * Indicates whether the corresponding WSDL port type should be processed. + * @return true if the corresponding WSDL port type should be processed. + */ + public boolean processPortType() + { + return processPortType; + } + /** + * Indicates whether the corresponding WSDL definition should be processed. + * @return true if the corresponding WSDL definition should be processed. + */ + public boolean processDefinition() + { + return processDefinition; + } + /** + * Indicates whether the corresponding WSDL extensibility element should be processed. + * @return true if the corresponding WSDL extensibility element should be processed. + */ + public boolean processExtensibilityElement() + { + return processExtensibilityElement; + } + /** + * Indicates whether the corresponding WSDL SOAP binding should be processed. + * @return true if the corresponding WSDL SOAP binding should be processed. + */ + public boolean processSOAPBinding() + { + return processSOAPBinding; + } + /** + * Indicates whether the corresponding WSDL SOAP header should be processed. + * @return true if the corresponding WSDL SOAP header should be processed.n + */ + public boolean processSOAPHeader() + { + return processSOAPHeader; + } + /** + * Indicates whether the corresponding WSDL SOAP header fault should be processed. + * @return true if the corresponding WSDL SOA header fault should be processed. + */ + public boolean processSOAPHeaderFault() + { + return processSOAPHeaderFault; + } + /** + * Indicates whether the corresponding WSDL SOAP fault should be processed. + * @return true if the corresponding WSDL SOAP fault should be processed. + */ + public boolean processSOAPFault() + { + return processSOAPFault; + } + /** + * Indicates whether the corresponding WSDL operation should be processed. + * @return true if the corresponding WSDL operation should be processed. + */ + public boolean processSOAPOperation() + { + return processSOAPOperation; + } + /** + * Sets WSDL part to be processed. + * @param value the WSDL part to be processed. + */ + void setPart(Part value) + { + activePart = value; + } + /** + * Gets last processed WSDL part. + * @return the last processed WSDL part. + */ + public Part getPart() + { + return activePart; + } + /** + * Sets WSDL service to be processed. + * @param value the WSDL service to be processed. + */ + void setService(Service value) + { + activeService = value; + } + /** + * Gets last processed WSDL service. + * @return the last processed WSDL service. + */ + public Service getService() + { + return activeService; + } + /** + * Sets WSDL types to be processed. + * @param value the WSDL types to be processed. + */ + void setTypes(Types value) + { + activeTypes = value; + } + /** + * Gets last processed WSDL types. + * @return the last processed WSDL types. + */ + public Types getTypes() + { + return activeTypes; + } + /** + * Sets WSDL operation to be processed. + * @param value the WSDL operation to be processed. + */ + void setOperation(Operation value) + { + activeOperation = value; + } + /** + * Gets last processed WSDL operation. + * @return the last processed WSDL operation. + */ + public Operation getOperation() + { + return activeOperation; + } + /** + * Sets WSDL input to be processed + * @param the WSDL input to be processed. + */ + void setInput(Input value) + { + activeInput = value; + } + /** + * Gets last processed WSDL input. + * @return last processed WSDL input. + */ + public Input getInput() + { + return activeInput; + } + /** + * Sets WSDL output to be processed. + * @param value the WSDL output to be processed. + */ + void setOutput(Output value) + { + activeOutput = value; + } + /** + * Gets last processed WSDL output. + * @return the last processed WSDL output. + */ + public Output getOutput() + { + return activeOutput; + } + /** + * Sets WSDL fault to be processed. + * @param value the WSDL fault to be processed. + */ + void setFault(Fault value) + { + activeFault = value; + } + /** + * Gets last processed WSDL fault. + * @return the last processed WSDL fault. + */ + public Fault getFault() + { + return activeFault; + } + /** + * Sets WSDL binding to be processed. + * @param value the WSDL binding to be processed. + */ + void setBinding(Binding value) + { + activeBinding = value; + } + /** + * Gets last processed WSDL binding. + * @return the last processed WSDL binding. + */ + public Binding getBinding() + { + return activeBinding; + } + /** + * Sets WSDL binding operation to be processed. + * @param value the SDL binding operation to be processed. + */ + void setBindingOperation(BindingOperation value) + { + activeBindingOperation = value; + } + /** + * Gets last processed WSDL binding operation. + * @return the last processed WSDL binding operation. + */ + public BindingOperation getBindingOperation() + { + return activeBindingOperation; + } + /** + * Sets WSDL binding input to be processed. + * @param value the WSDL binding input to be processed. + */ + void setBindingInput(BindingInput value) + { + activeBindingInput = value; + } + /** + * Gets last processed WSDL binding input. + * @return the last processed WSDL binding input. + */ + public BindingInput getBindingInput() + { + return activeBindingInput; + } + /** + * Sets WSDL binding output to be processed. + * @param value the WSDL binding output to be processed. + */ + void setBindingOutput(BindingOutput value) + { + activeBindingOutput = value; + } + /** + * Gets last processed WSDL binding output. + * @return the last processed WSDL binding output. + */ + public BindingOutput getBindingOutput() + { + return activeBindingOutput; + } + /** + * Sets WSDL binding fault to be processed. + * @param value the WSDL binding fault to be processed. + */ + void setBindingFault(BindingFault value) + { + activeBindingFault = value; + } + /** + * Gets last processed WSDL binding fault. + * @return the last processed WSDL binding fault. + */ + public BindingFault getBindingFault() + { + return activeBindingFault; + } + /** + * Sets WSDL import to be processed. + * @param value the WSDL import to be processed. + */ + void setImport(Import value) + { + activeImport = value; + } + /** + * Gets last processed WSDL import. + * @return the last processed WSDL import. + */ + public Import getImport() + { + return activeImport; + } + /** + * Sets WSDL element to be processed. + * @param value the WSDL element to be processed. + */ + void setElement(Element value) + { + activeElement = value; + } + /** + * Gets last processed WSDL element. + * @return the last processed WSDL element. + */ + public Element getElement() + { + return activeElement; + } + /** + * Sets WSDL message to be processed. + * @param value the WSDL message to be processed. + */ + void setMessage(Message value) + { + activeMessage = value; + } + /** + * Gets last processed WSDL message. + * @return the last processed WSDL message. + */ + public Message getMessage() + { + return activeMessage; + } + /** + * Sets WSDL port to be processed. + * @param value the WSDL port to be processed. + */ + void setPort(Port value) + { + activePort = value; + } + /** + * Gets last processed WSDL port. + * @return the last processed WSDL port. + */ + public Port getPort() + { + return activePort; + } + /** + * Sets WSDL port type to be processed. + * @param value the WSDL port type to be processed. + */ + void setPortType(PortType value) + { + activePortType = value; + } + /** + * Gets last processed WSDL port type. + * @return the last processed WSDL port type. + */ + public PortType getPortType() + { + return activePortType; + } + /** + * Sets WSDL definition to be processed. + * @param value the WSDL definition to be processed. + */ + void setDefinition(Definition value) + { + activeDefinition = value; + } + /** + * Gets last processed WSDL definition. + * @return the last processed WSDL definition. + */ + public Definition getDefinition() + { + return activeDefinition; + } + /** + * Sets WSDL extensibility element to be processed. + * @param value the WSDL extensibility element to be processed. + */ + void setExtensibilityElement(ExtensibilityElement value) + { + activeExtensibilityElement = value; + } + /** + * Gets last processed WSDL extensibility element. + * @return the last processed WSDL extensibility element. + */ + public ExtensibilityElement getExtensibilityElement() + { + return activeExtensibilityElement; + } + /** + * Sets WSDL element to be processed. + * @param value the WSDL element to be processed. + */ + void setSOAPBinding(SOAPBinding value) + { + activeSOAPBinding = value; + } + /** + * Gets last processed WSDL SOAP binding. + * @return the last processed WSDL SOAP binding. + */ + public SOAPBinding getSOAPBinding() + { + return activeSOAPBinding; + } + /** + * Sets WSDL element to be processed. + * @param value WSDL element to be processed. + */ + void setSOAPBody(SOAPBody value) + { + activeSOAPBody = value; + } + /** + * Gets last processed WSDL SOAP body. + * @return the last processed WSDL SOAP body. + */ + public SOAPBody getSOAPBody() + { + return activeSOAPBody; + } + /** + * Sets WSDL element to be processed. + * @param value the WSDL element to be processed. + */ + void setSOAPHeader(SOAPHeader value) + { + activeSOAPHeader = value; + } + /** + * Gets last processed WSDL SOAP header. + * @return the last processed WSDL SOAP header. + */ + public SOAPHeader getSOAPHeader() + { + return activeSOAPHeader; + } + /** + * Sets WSDL element to be processed. + * @param value the WSDL element to be processed. + */ + void setSOAPHeaderFault(SOAPHeaderFault value) + { + activeSOAPHeaderFault = value; + } + /** + * Gets last processed WSDL SOAP header fault. + * @return the last processed WSDL SOAP header fault. + */ + public SOAPHeaderFault getSOAPHeaderFault() + { + return activeSOAPHeaderFault; + } + /** + * Sets WSDL element to be processed. + * @param value the WSDL element to be processed. + */ + void setSOAPFault(SOAPFault value) + { + activeSOAPFault = value; + } + /** + * Gets last processed WSDL SOAP fault. + * @return the last processed WSDL SOAP fault. + */ + public SOAPFault getSOAPFault() + { + return activeSOAPFault; + } + /** + * Sets WSDL element to be processed. + * @param value theWSDL element to be processed + */ + void setSOAPOperation(SOAPOperation value) + { + activeSOAPOperation = value; + } + /** + * Gets last processed WSDL SOAP operation. + * @return the last processed WSDL SOAP operation. + */ + public SOAPOperation getSOAPOperation() + { + return activeSOAPOperation; + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/traversal/WSDLVisitor.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/traversal/WSDLVisitor.java new file mode 100644 index 000000000..34d6431b5 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/traversal/WSDLVisitor.java @@ -0,0 +1,232 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.wsdl.traversal; + +import javax.wsdl.Part; +import javax.wsdl.Service; +import javax.wsdl.Types; +import javax.wsdl.Operation; +import javax.wsdl.Input; +import javax.wsdl.Output; +import javax.wsdl.Fault; +import javax.wsdl.Binding; +import javax.wsdl.BindingOperation; +import javax.wsdl.BindingInput; +import javax.wsdl.BindingOutput; +import javax.wsdl.BindingFault; +import javax.wsdl.Import; +import org.w3c.dom.Element; +import javax.wsdl.Message; +import javax.wsdl.Port; +import javax.wsdl.PortType; +import javax.wsdl.Definition; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.soap.SOAPBinding; +import javax.wsdl.extensions.soap.SOAPBody; +import javax.wsdl.extensions.soap.SOAPFault; +import javax.wsdl.extensions.soap.SOAPHeader; +import javax.wsdl.extensions.soap.SOAPHeaderFault; +import javax.wsdl.extensions.soap.SOAPOperation; + +/** + * The interface defines callback methods during traverse WSDL. + * WSDLVisitor could cancel artifact processing by using traversal context + * cancelXXXProcessing methods. + * + * @author Kulik + */ +public interface WSDLVisitor +{ + /** + * Method visits WSDL part object. + * @param obj WSDL element to be visited. + * @param parent WSDL element. + * @param ctx current traversal context. + */ + public void visit(Part obj, Object parent, WSDLTraversalContext ctx); + /** + * Method visits WSDL service object. + * @param obj WSDL element to be visited. + * @param parent WSDL element. + * @param ctx current traversal context. + */ + public void visit(Service obj, Object parent, WSDLTraversalContext ctx); + /** + * Method visits WSDL types object. + * @param obj WSDL element to be visited. + * @param parent WSDL element. + * @param ctx current traversal context. + */ + public void visit(Types obj, Object parent, WSDLTraversalContext ctx); + /** + * Method visits WSDL operation object. + * @param obj WSDL element to be visited. + * @param parent WSDL element. + * @param ctx current traversal context. + */ + public void visit(Operation obj, Object parent, WSDLTraversalContext ctx); + /** + * Method visits WSDL input object. + * @param obj WSDL element to be visited. + * @param parent WSDL element. + * @param ctx current traversal context. + */ + public void visit(Input obj, Object parent, WSDLTraversalContext ctx); + /** + * Method visits WSDL output object. + * @param obj WSDL element to be visited. + * @param parent WSDL element. + * @param ctx current traversal context. + */ + public void visit(Output obj, Object parent, WSDLTraversalContext ctx); + /** + * Method visits WSDL fault object. + * @param obj WSDL element to be visited. + * @param parent WSDL element. + * @param ctx current traversal context. + */ + public void visit(Fault obj, Object parent, WSDLTraversalContext ctx); + /** + * Method visits WSDL binding object. + * @param obj WSDL element to be visited. + * @param parent WSDL element. + * @param ctx current traversal context. + */ + public void visit(Binding obj, Object parent, WSDLTraversalContext ctx); + /** + * Method visits WSDL binding operation object. + * @param obj WSDL element to be visited. + * @param parent WSDL element. + * @param ctx current traversal context. + */ + public void visit( + BindingOperation obj, + Object parent, + WSDLTraversalContext ctx); + /** + * Method visits WSDL binding input object. + * @param obj WSDL element to be visited. + * @param parent WSDL element. + * @param ctx current traversal context. + */ + public void visit(BindingInput obj, Object parent, WSDLTraversalContext ctx); + /** + * Method visits WSDL binding output object. + * @param obj WSDL element to be visited. + * @param parent WSDL element. + * @param ctx current traversal context. + */ + public void visit(BindingOutput obj, Object parent, WSDLTraversalContext ctx); + /** + * Method visits WSDL binding fault object. + * @param obj WSDL element to be visited. + * @param parent WSDL element. + * @param ctx current traversal context. + */ + public void visit(BindingFault obj, Object parent, WSDLTraversalContext ctx); + /** + * Method visits WSDL import object. + * @param obj WSDL element to be visited. + * @param parent WSDL element. + * @param ctx current traversal context. + */ + public void visit(Import obj, Object parent, WSDLTraversalContext ctx); + /** + * Method visits WSDL element object. + * @param obj WSDL element to be visited. + * @param parent WSDL element. + * @param ctx current traversal context. + */ + public void visit(Element obj, Object parent, WSDLTraversalContext ctx); + /** + * Method visits WSDL message object. + * @param obj WSDL element to be visited. + * @param parent WSDL element. + * @param ctx current traversal context. + */ + public void visit(Message obj, Object parent, WSDLTraversalContext ctx); + /** + * Method visits WSDL port object. + * @param obj WSDL element to be visited. + * @param parent WSDL element. + * @param ctx current traversal context. + */ + public void visit(Port obj, Object parent, WSDLTraversalContext ctx); + /** + * Method visits WSDL port type object. + * @param obj WSDL element to be visited. + * @param parent WSDL element. + * @param ctx current traversal context. + */ + public void visit(PortType obj, Object parent, WSDLTraversalContext ctx); + /** + * Method visits WSDL definition object. + * @param obj WSDL element to be visited. + * @param parent WSDL element. + * @param ctx current traversal context. + */ + public void visit(Definition obj, Object parent, WSDLTraversalContext ctx); + /** + * Method visits WSDL extensibility element object. + * @param obj WSDL element to be visited. + * @param parent WSDL element. + * @param ctx current traversal context. + */ + public void visit( + ExtensibilityElement obj, + Object parent, + WSDLTraversalContext ctx); + /** + * Method visits WSDL SOAP binding object. + * @param obj WSDL element to be visited. + * @param parent WSDL element. + * @param ctx current traversal context. + */ + public void visit(SOAPBinding obj, Object parent, WSDLTraversalContext ctx); + /** + * Method visits WSDL SOAP body object. + * @param obj WSDL element to be visited. + * @param parent WSDL element. + * @param ctx current traversal context. + */ + public void visit(SOAPBody obj, Object parent, WSDLTraversalContext ctx); + /** + * Method visits WSDL SOAP header object. + * @param obj WSDL element to be visited. + * @param parent WSDL element. + * @param ctx current traversal context. + */ + public void visit(SOAPHeader obj, Object parent, WSDLTraversalContext ctx); + /** + * Method visits WSDL SOAP header fault object. + * @param obj WSDL element to be visited. + * @param parent WSDL element. + * @param ctx current traversal context. + */ + public void visit( + SOAPHeaderFault obj, + Object parent, + WSDLTraversalContext ctx); + /** + * Method visits WSDL SOAP fault object. + * @param obj WSDL element to be visited. + * @param parent WSDL element. + * @param ctx current traversal context. + */ + public void visit(SOAPFault obj, Object parent, WSDLTraversalContext ctx); + /** + * Method visits WSDL SOAP operation object. + * @param obj WSDL element to be visited. + * @param parent WSDL element.. + * @param ctx current traversal context. + */ + public void visit(SOAPOperation obj, Object parent, WSDLTraversalContext ctx); +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/xsd/FileEntityResolver.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/xsd/FileEntityResolver.java new file mode 100644 index 000000000..945a8fc2d --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/xsd/FileEntityResolver.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.wsdl.xsd; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; + +import org.apache.xerces.xni.XMLResourceIdentifier; +import org.apache.xerces.xni.XNIException; +import org.apache.xerces.xni.parser.XMLEntityResolver; +import org.apache.xerces.xni.parser.XMLInputSource; + +/** + * Entity resolve to resolve file entities. + * + * @author Lawrence Mandel, IBM + */ +public class FileEntityResolver implements XMLEntityResolver +{ + + /** + * @see org.apache.xerces.xni.parser.XMLEntityResolver#resolveEntity(org.apache.xerces.xni.XMLResourceIdentifier) + */ + public XMLInputSource resolveEntity(XMLResourceIdentifier resource) throws XNIException, IOException + { + String publicId = resource.getPublicId(); + String systemId = resource.getExpandedSystemId(); + String namespace = resource.getNamespace(); + URL url = null; + if(systemId != null) + { + url = new URL(systemId); + } + else if(publicId != null) + { + url = new URL(publicId); + } + else if(namespace != null) + { + url = new URL(namespace); + } + if(url != null) + { + InputStream is = url.openStream(); + return new XMLInputSource(publicId, resource.getExpandedSystemId(), resource.getExpandedSystemId(), is, null); + } + return null; + } + +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/xsd/InlineSchemaGenerator.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/xsd/InlineSchemaGenerator.java new file mode 100644 index 000000000..001516342 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/xsd/InlineSchemaGenerator.java @@ -0,0 +1,591 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.wsdl.xsd; + +import java.util.Enumeration; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.List; +import java.util.Vector; + +import org.w3c.dom.Element; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import com.ibm.wsdl.Constants; + +/** + * Generate a String representation of a schema for an inline schema. Will add imports for unresolved + * namespaces. + * + * @author Lawrence Mandel, IBM + */ +public class InlineSchemaGenerator +{ + protected final String SOAP_ENCODING_URI = "http://schemas.xmlsoap.org/soap/encoding/"; + protected final String FILE_PREFIX = "file:///"; + protected final String XMLNS = "xmlns"; + protected final String TARGETNAMESPACE = "targetNamespace"; + protected final String NAMESPACE = "namespace"; + protected final String IMPORT = "import"; + protected final String INCLUDE = "include"; + protected final String SCHEMA = "schema"; + protected final String SCHEMALOCATION = "schemaLocation"; + protected final String TYPE = "type"; + protected final String NAME = "name"; + protected final String[] ignoreNamespaces = + { Constants.NS_URI_XSD_1999, Constants.NS_URI_XSD_2000, Constants.NS_URI_XSD_2001 }; + + protected static InlineSchemaGenerator instance = null; + + /** + * Constructor. + */ + protected InlineSchemaGenerator() + { + } + + /** + * Get the instance of the InlineSchemaGenerator. + * + * @return The instance of the inline schema generator. + */ + protected static InlineSchemaGenerator getInstance() + { + if (instance == null) + { + instance = new InlineSchemaGenerator(); + } + return instance; + } + + /** + * Create a string representation of a schema from the element provided. + * + * @param element The root element of the schema. + * @param elements A list of the elements in the schema in order. + * @param filelocation The URI of the file that contains the schema. + * @return A string representation of a schema. + */ + public static String createXSDString(Element element, List elements, String filelocation) + { + return InlineSchemaGenerator.createXSDString(element, elements, filelocation, new Hashtable()); + } + + /** + * Creates a String representing the schema model with the root element of + * extElem. Calls createXSDStringRecursively to take care of building the String + * after it obtains the Element from the UnknownExtensibilityElement. + * + * @param element The root element of the schema. + * @param elements A list to contain the elements in the schema in order. + * @param filelocation The location of the file the schema is located in. + * @param parentNSs A hashtable of parent namespaces to used to resolve prefixes. + * @return A string representation of the schema with the root element 'element'. + */ + public static String createXSDString(Element element, List elements, String filelocation, Hashtable parentNSs) + { + InlineSchemaGenerator schemaGenerator = InlineSchemaGenerator.getInstance(); + Hashtable nsResolver = schemaGenerator.getNSResolver(element); + List reqns = schemaGenerator.getRequiredNamespaces(element); + Hashtable reqNSDecl = schemaGenerator.resolveNamespaces(reqns, nsResolver, parentNSs); + //Hashtable reqNSDecl = schemaGenerator.getRequiredNSDeclarations(reqns, nsResolver, parentNSs); + List importNS = schemaGenerator.getImportNamespaces(element); + reqns = schemaGenerator.removeImports(reqns, importNS); + reqns = schemaGenerator.removeLocalNamespaces(reqns, element); + return schemaGenerator.createXSDStringRecursively(element, elements, reqns, reqNSDecl, filelocation); + } + /** + * Returns true if the SOAP encoding namespace is required but not imported. + * + * @param element The root element of the schema. + * @param filelocation The location of the file containing the schema. + * @param parentNSs A hashtable of the parent namespaces. + * @return True if the soap encoding namespace is required but not imported, false otherwise. + */ + public static boolean soapEncodingRequiredNotImported(Element element, String filelocation, Hashtable parentNSs) + { + InlineSchemaGenerator schemaGenerator = InlineSchemaGenerator.getInstance(); + Hashtable nsResolver = schemaGenerator.getNSResolver(element); + List reqns = null; + + reqns = schemaGenerator.getRequiredNamespaces(element); + schemaGenerator.resolveNamespaces(reqns, nsResolver, parentNSs); + //schemaGenerator.resolveUndeclaredNamespaces(reqns, parentNSs); + List importNS = schemaGenerator.getImportNamespaces(element); + reqns = schemaGenerator.removeImports(reqns, importNS); + reqns = schemaGenerator.removeLocalNamespaces(reqns, element); + + return schemaGenerator.checkSOAPEncodingRequired(reqns); + } + + /** + * This recursive method creates the schema String from the root Element. + * + * @param elem The root element of the schema. + * @param elements A list to be created of the elements in the schema in order. + * @param requiredNamespaces A list of required namespaces. + * @param reqNSDecl A hashtable of required namespace declarations. + * @param filelocation The uri of the file that contains this schema. + * @return A string representation of this schema. + */ + protected String createXSDStringRecursively( + Element elem, + List elements, + List requiredNamespaces, + Hashtable reqNSDecl, + String filelocation) + { + if (elem == null) + return ""; // just in case + + elements.add(elem); + + StringBuffer xsdString = new StringBuffer(); + String elementName = elem.getTagName(); + xsdString.append("<").append(elementName); + + boolean foundSchemaLocation = false; // flag if schemalocation is defined + String namespace = ""; // the namespace if we're checking an import or include + String namePrefix = ""; // the xmlns prefix used for the elements + // Get all of the attributes for this element and append them to the xsdString + NamedNodeMap atts = elem.getAttributes(); + for (int i = 0; i < atts.getLength(); i++) + { + Node n = atts.item(i); + xsdString.append(" ").append(n.getNodeName()).append("=\""); + String nodeName = n.getNodeName(); + if (nodeName.equalsIgnoreCase(SCHEMALOCATION) && filelocation != null) + { + foundSchemaLocation = true; + String relativePath = n.getNodeValue(); + xsdString.append(relativePath).append("\""); + } + else + { + String nodeValue = n.getNodeValue(); + if (nodeName.equalsIgnoreCase(NAMESPACE)) + { + namespace = nodeValue; + } + // get the name prefix for this schema to use in generating import statements + else if (nodeName.indexOf(XMLNS) != -1) + { + + if (nodeValue.equalsIgnoreCase(elem.getNamespaceURI())) + { + namePrefix = nodeName; + if (namePrefix.equalsIgnoreCase(XMLNS)) + { + namePrefix = ""; + } + else + { + namePrefix = namePrefix.substring(6) + ":"; + } + } + } + // Replace old schema namespaces with the new schema namespace. + if(nodeValue.equals(Constants.NS_URI_XSD_1999) || nodeValue.equals(Constants.NS_URI_XSD_2000)) + { + nodeValue = Constants.NS_URI_XSD_2001; + } + xsdString.append(nodeValue).append("\""); + } + } + if (elementName.equalsIgnoreCase("import") && !foundSchemaLocation) + { + xsdString.append(" ").append(SCHEMALOCATION).append("=\"").append(namespace).append("\""); + } + // add in any required NS declarations from parent elements + if (reqNSDecl != null) + { + Enumeration keys = reqNSDecl.keys(); + while (keys.hasMoreElements()) + { + String key = (String)keys.nextElement(); + String declNS = (String)reqNSDecl.get(key); + if(declNS.equals(Constants.NS_URI_XSD_1999) || declNS.equals(Constants.NS_URI_XSD_2000)) + { + declNS = Constants.NS_URI_XSD_2001; + } + xsdString.append(" ").append(key).append("=\"").append(declNS).append("\""); + } + + } + xsdString.append(">"); + if (requiredNamespaces != null) + { + Iterator iRequiredNamespaces = requiredNamespaces.iterator(); + while (iRequiredNamespaces.hasNext()) + { + String ns = (String)iRequiredNamespaces.next(); + + xsdString + .append("<") + .append(namePrefix) + .append(IMPORT) + .append(" ") + .append(NAMESPACE) + .append("=\"") + .append(ns) + .append("\" ") + .append(SCHEMALOCATION) + .append("=\"") + .append(ns) + .append("\"/>"); + } + + } + xsdString.append("\n"); + + // call the method recursively for each child element + NodeList childNodes = elem.getChildNodes(); + + for (int i = 0; i < childNodes.getLength() || i < 5; i++) + { + Node n = childNodes.item(i); + // we only want nodes that are Elements + if (n instanceof Element) + { + Element child = (Element)n; + xsdString.append(createXSDStringRecursively(child, elements, null, null, filelocation)); + } + } + + xsdString.append(""); + + return xsdString.toString(); + + } + /** + * Get a list of all the namespaces that are used for elements or types in the schema. + * These are the required namespaces in order to ensure that all the elments are valid. + * + * @param elem The element to check for required namespaces. + * @return A list of required namespaces for the element and all its children. + */ + protected List getRequiredNamespaces(Element elem) + { + List namespace = new Vector(); + + // call the method recursively for each child element + // register all the child types first + NodeList childNodes = elem.getChildNodes(); + int numChildren = childNodes.getLength(); + // TODO: why is there a < 5 condition? + for (int i = 0; i < numChildren /*|| i < 5*/; i++) + { + Node n = childNodes.item(i); + // we only want nodes that are Elements + if (n instanceof Element) + { + Element child = (Element)n; + List childns = getRequiredNamespaces(child); + for (int j = childns.size() - 1; j >= 0; j--) + { + String ns = (String)childns.get(j); + + if (!namespace.contains(ns)) + { + namespace.add(ns); + } + } + } + } + // Add the namespace of the current element + String elemNS = elem.getPrefix(); + // if there is no namespace prefix set it to the empty prefix. + if(elemNS == null) + { + elemNS = ""; + } + if (!namespace.contains(elemNS.intern())) + { + namespace.add(elemNS.intern()); + } + // now add all of the current element's namespaces + // don't include import and schema elements + String localname = elem.getLocalName(); + if (!localname.equals(IMPORT) && !localname.equals(INCLUDE) && !localname.equals(SCHEMA)) + { + NamedNodeMap atts = elem.getAttributes(); + for (int i = 0; i < atts.getLength(); i++) + { + Node n = atts.item(i); + + String nodeName = n.getNodeName(); + // removed restriction that we're only looking at types + // if (nodeName.equalsIgnoreCase(TYPE)) + // { + // don't take namespace info from attributes defining namespaces. + // that includes xmlns, targetNamespace + // don't take namespace info from name attributes + if (nodeName.indexOf(XMLNS) != -1 || nodeName.equals(TARGETNAMESPACE) || nodeName.equals(NAME)) + { + continue; + } + String nodeValue = n.getNodeValue(); + + + int colonIndex = nodeValue.indexOf(":"); + // Don't take namespace info from attributes with the default namespace, that is attributes + // that are not prefixed. (colonIndex == -1) + // If the colonIndex is followed by a / then it is a URI and not + // namespace qualified. + if (colonIndex == -1 || nodeValue.charAt(colonIndex + 1) == '/') + { + continue; + } + // here we have found a colon delimiter so we need the namespace defined here + else + { + nodeValue = nodeValue.substring(0, colonIndex); + } + if (!namespace.contains(nodeValue.intern())) + { + + namespace.add(nodeValue.intern()); + } + // } + } + } + + return namespace; + + } + + /** + * Get a list of all the namespaces that have an import statement. + * + * @param elem The root element of the schema. + * @return A list of all the namespaces that are imported. + */ + protected List getImportNamespaces(Element elem) + { + List namespace = new Vector(); + + // call the method recursively for each child element + // register all the child types first + NodeList childNodes = elem.getChildNodes(); + + for (int i = 0; i < childNodes.getLength() || i < 5; i++) + { + Node n = childNodes.item(i); + // we only want nodes that are Elements + if (n instanceof Element) + { + Element child = (Element)n; + List childns = getImportNamespaces(child); + for (int j = childns.size() - 1; j >= 0; j--) + { + String ns = (String)childns.get(j); + if (!namespace.contains(ns)) + { + namespace.add(ns); + } + } + } + } + // if this is an import element get the namespace and add it to the list + if (elem.getLocalName().equalsIgnoreCase(IMPORT)) + { + NamedNodeMap atts = elem.getAttributes(); + for (int i = 0; i < atts.getLength(); i++) + { + Node n = atts.item(i); + + String nodeName = n.getNodeName(); + if (nodeName.equalsIgnoreCase(NAMESPACE)) + { + String nodeValue = n.getNodeValue(); + if (!namespace.contains(nodeValue.intern())) + { + + namespace.add(nodeValue.intern()); + } + } + } + } + + return namespace; + + } + + /** + * Return a Hashtable with namespace prefixes as keys from the given element. + * + * @param elem The root element of the schema. + * @return A hashtable with namespace prefixes mapped to namespaces. + */ + protected Hashtable getNSResolver(Element elem) + { + Hashtable nsResolver = new Hashtable(); + + NamedNodeMap atts = elem.getAttributes(); + for (int i = 0; i < atts.getLength(); i++) + { + Node n = atts.item(i); + + String nodeName = n.getNodeName(); + if (nodeName.indexOf(XMLNS) != -1) + { + String nodeValue = n.getNodeValue(); + String namePrefix = nodeName; + + if (namePrefix.equalsIgnoreCase(XMLNS)) + { + namePrefix = ""; + } + else + { + namePrefix = namePrefix.substring(6); + } + nsResolver.put(namePrefix, nodeValue); + + } + } + return nsResolver; + + } + + /** + * Resolve the namespaces in the given namespaces list with the two namespace + * resolver hashtables provided. Return a list of all the namespace that need + * to be declared. + * First resolve against the local namespaces with nsResolver. + * Next resolve against the parent namespace with parentNSResolver. + * A side affect of this method is the namespaces list is left with only those + * namespaces that are resolved and the resolved entities are placed in the + * list instead of the original entries. + * For ex. If you provide a list such as {xsd, intf} and only xsd can be resolved + * you will end up with the list {http://www.w3.org/2001/XMLSchema} + * + * @param namespaces The list of namespaces to resolve. + * @param nsResolver The hashtable to be used as the local resolver. + * @param parentNSResolver The hashtable to be used as the parent namespace resolver. + * @return A Hashtable of namespaces that must be declared. + */ + protected Hashtable resolveNamespaces(List namespaces, Hashtable nsResolver, Hashtable parentNSResolver) + { + Hashtable reqNSDecl = new Hashtable(); + if (namespaces != null && !namespaces.isEmpty() && nsResolver != null) + { + for (int i = namespaces.size() - 1; i >= 0; i--) + { + String ns = (String)namespaces.get(i); + // Remove the namespace from the list. + namespaces.remove(i); + // First try to resolve against the local namespace resolver. + if (nsResolver.containsKey(ns)) + { + Object resolvedNS = nsResolver.get(ns); + // Only add the namespace if it's not already in the list. + if(!namespaces.contains(resolvedNS)) + { + namespaces.add(i, nsResolver.get(ns)); + } + } + // Next try to resolve against the parent namespace resolver. + else + { + if (ns.equals("")) + { + ns = XMLNS; + } + else + { + ns = XMLNS + ":" + ns; + } + if (parentNSResolver.containsKey(ns)) + { + Object resolvedNS = parentNSResolver.get(ns); + // Only add the namespace if it's not already in the list. + if(!namespaces.contains(resolvedNS)) + { + namespaces.add(i, resolvedNS); + } + // Still need to declare the namespace though. + reqNSDecl.put(ns, resolvedNS); + } + } + + } + } + return reqNSDecl; + } + + /** + * Remove any namespace from the namespaces list if it is in the import list. + * + * @param namespaces The namespaces list. + * @param importedNamespaces A list of imported namespaces. + * @return The list of namespaces without the imported namespaces. + */ + protected List removeImports(List namespaces, List importedNamespaces) + { + if (namespaces != null && importedNamespaces != null && !importedNamespaces.isEmpty()) + { + Iterator iImportedNS = importedNamespaces.iterator(); + while (iImportedNS.hasNext()) + { + String iNS = (String)iImportedNS.next(); + + namespaces.remove(iNS); + } + } + return namespaces; + } + + /** + * Remove the local namespace for the schema and the namespaces listed in the ignoreNamespaces + * list from the namespaces list provided. + * + * @param namespaces The list of local namespaces. + * @param elem The root element of the schema. + * @return The list of namespaces with the local namespaces removed. + */ + protected List removeLocalNamespaces(List namespaces, Element elem) + { + if (namespaces != null && elem != null) + { + String ns = elem.getAttribute(TARGETNAMESPACE); + namespaces.remove(ns); + + for (int i = ignoreNamespaces.length - 1; i >= 0; i--) + { + // keep removing the namespace until it is not in the list + if (namespaces.remove(ignoreNamespaces[i])) + { + i++; + } + } + } + return namespaces; + } + + /** + * Returns true if the SOAP encoding namespace is in the list of required namespaces, + * false otherwise. + * + * @param reqns The list of namespaces to check for the SOAP encoding namespace. + * @return True if the SOAP encoding namespaces is in the list, false otherwise. + */ + protected boolean checkSOAPEncodingRequired(List reqns) + { + if (reqns.contains(SOAP_ENCODING_URI)) + { + return true; + } + return false; + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/xsd/InlineSchemaValidator.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/xsd/InlineSchemaValidator.java new file mode 100644 index 000000000..12fffb78a --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/xsd/InlineSchemaValidator.java @@ -0,0 +1,242 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.wsdl.xsd; + +import java.util.HashMap; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Vector; + +import javax.wsdl.Definition; +import javax.wsdl.Types; +import javax.wsdl.extensions.UnknownExtensibilityElement; + +import org.w3c.dom.Element; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; + +import com.ibm.wsdl.Constants; + +/** + * Plugin validator for the WSDL Validation framework. Validates inline schema found in a WSDL document. + * + * @author Lawrence Mandel (lmandel@ca.ibm.com) + */ +public class InlineSchemaValidator +{ + List elements = null; + + + public Map validate(Object element, List parents, String filename) throws Exception + { + elements = new Vector(); + UnknownExtensibilityElement elem = (UnknownExtensibilityElement) element; + Definition wsdlDefinition = (Definition) parents.get(parents.size() - 1); + // Add in the namespaces defined in the doc already that aren't defined locally in this schema. + // There is no need to check for namespaces other then in the defintions and types elements as + // inline schema can not have any other parents and must have there two parents. + // First take care of the definitions element + + // create the inline schema string + Element w3celement = elem.getElement(); + Hashtable parentnamespaces = getNamespaceDeclarationsFromParents(wsdlDefinition,w3celement); + String targetNamespace = w3celement.getAttribute(Constants.ATTR_TARGET_NAMESPACE); + // if the targetNamespace hasn't been defined for the schema use the + // targetNamespace of the definitions element + /*if(targetNamespace == null || targetNamespace.equals("")) + { + targetNamespace = wsdlDefinition.getTargetNamespace(); + w3celement.setAttribute(Constants.ATTR_TARGET_NAMESPACE,targetNamespace); + }*/ + + String xsd = InlineSchemaGenerator.createXSDString(w3celement, elements, filename, parentnamespaces); + + // If the namespace given is one of the old schema namespaces produce a warning. + String namespace = w3celement.getNamespaceURI(); + if(namespace.equals(Constants.NS_URI_XSD_1999) || namespace.equals(Constants.NS_URI_XSD_2000)) + { + throw new Exception("An old version of the schema namespace is specified."); + } + + // now create and call the validator for the inline schema + XSDValidator schemav = new XSDValidator(); + + //String fileLocation = new URL(validatormanager.getFilename()).getPath(); + InlineXSDResolver inlineEntityResolver = + getEntityResolver(wsdlDefinition, (Types) parents.get(0), filename, targetNamespace); + // add in the external XSD Catalog to resolve schemas offline + XMLEntityResolverChain entityResolverChain = new XMLEntityResolverChain(); + entityResolverChain.addEntityResolver(inlineEntityResolver); + entityResolverChain.addEntityResolver(new FileEntityResolver()); + entityResolverChain.addEntityResolver(XMLCatalogResolver.getInstance()); + schemav.validateInlineSchema(xsd, targetNamespace, filename, entityResolverChain, inlineEntityResolver); + + // check if the SOAP Encoding namespace is required but not imported + if (InlineSchemaGenerator.soapEncodingRequiredNotImported(elem.getElement(), filename,parentnamespaces)) + { + throw new Exception("The inline schema uses an element or type from " + + "the SOAP encoding namespace but the namespace has not been imported. " + + "The SOAP encoding namespace should be imported with an import " + + "statement before it is used."); + } + + // If the schema isn't valid + if (!schemav.isValid()) + { + // Gathering all the errors + StringBuffer exception = new StringBuffer(); + Iterator i = schemav.getErrors().iterator(); + while (i.hasNext()) + { + exception.append(i.next()).append('\n'); + } + // throw an exception + throw new Exception(exception.toString()); + } + // if the schema is valid + else + { + Map map = new HashMap(1); + map.put(targetNamespace, schemav.getXSModel()); + return map; + } + } + + /** + * Get an entity resolver that will resolve inline schemas. Every inline schema is preregistered with + * the resolver. + * + * @param wsdlDefinition The WSDL definitions element. + * @param types The types element. + * @param referenceLocation The location of the file that contains this schema. + * @param targetNamespace The targetNamespace of the schema. + * @return An entity resolver that can resolve inline schemas. + */ + protected InlineXSDResolver getEntityResolver(Definition wsdlDefinition, Types types, String referenceLocation, String targetNamespace) + { + InlineXSDResolver entityResolver = new InlineXSDResolver(); +// entityResolver.setReferenceLocation(referenceLocation); + List schemas = types.getExtensibilityElements(); + if (schemas != null) + { + Iterator iSchemas = schemas.iterator(); + while (iSchemas.hasNext()) + { + UnknownExtensibilityElement extElem = (UnknownExtensibilityElement) iSchemas.next(); + String thisNamespace = extElem.getElement().getAttribute(Constants.ATTR_TARGET_NAMESPACE); + if (thisNamespace != null && !thisNamespace.equalsIgnoreCase(targetNamespace)) + { + + Element element = extElem.getElement(); + +// create the inline schema string + //Element w3celement = elem.getElement(); + Hashtable parentnamespaces = getNamespaceDeclarationsFromParents(wsdlDefinition,element); + String xsd = InlineSchemaGenerator.createXSDString(element, elements, referenceLocation, parentnamespaces); + //addNamespaceDeclarationsFromParents(wsdlDefinition,element); + entityResolver.add(thisNamespace, xsd); + } + + } + } + return entityResolver; + } + + /** + * Get the namespace declarations as in the form + * xmlns="somenamespace" + * from the definitions and types elements and add them to the schema element so the schema + * validator will have access to them. + * + * @param wsdlDefinition The WSDL definitions element. + * @param element The types element. + * @return A hashtable with the namespace elements from the elements provided. + */ + protected Hashtable getNamespaceDeclarationsFromParents(Definition wsdlDefinition, Element element) + { + Hashtable nss = new Hashtable(); + Iterator nameSpaces = wsdlDefinition.getNamespaces().keySet().iterator(); + + String XMLNS = Constants.ATTR_XMLNS; + + String schemaLocation = ""; + while (nameSpaces.hasNext()) + { + String nsprefix = XMLNS; + String ns = (String) nameSpaces.next(); + if (!ns.equalsIgnoreCase("")) + { + nsprefix += ":"; + } + if (!element.hasAttribute(nsprefix + ns)) + { + nss.put(nsprefix + ns, wsdlDefinition.getNamespace(ns)); +// element.setAttribute(nsprefix + ns, wsdlDefinition.getNamespace(ns)); + } + + } + // Next handle the parent types element + NamedNodeMap atts = element.getParentNode().getAttributes(); + int attslength = atts.getLength(); + for (int i = 0; i < attslength; i++) + { + Node tempnode = atts.item(i); + String nodename = tempnode.getNodeName(); + // if this is a namespace attribute + if (nodename.indexOf(XMLNS) != -1) + { + nss.put(nodename, tempnode.getNodeValue()); + //element.setAttribute(nodename, tempnode.getNodeValue()); + } + } + return nss; + } + + /** + * Given a line number for the schema returns the element found on that line. + * Useful for obtaining elements from schema Strings. + * + * @param line The line number for the schema. + * @return The object located at the line or at line 0 if the line is invalid. + */ + public Object getObjectAtLine(int line) + { + if(line < 0 || line >= elements.size()) + { + line = 0; + } + return elements.get(line); + } + + /** + * Replace any instance of the 2001 schema namespace in the given message with + * the given namespace. + * + * @param message The message to replace the namespace in. + * @param namespace The namespace used for replacement. + * @return The message with the 2001 schema namespace replaced by the given namespace. + */ + private String replaceNamespace(String message, String namespace) + { + String xsd2001 = Constants.NS_URI_XSD_2001; + int start = message.indexOf(xsd2001); + int end = start + xsd2001.length(); + if(start < 0) + { + return message; + } + String startString = message.substring(0,start); + String endString = message.substring(end,message.length()); + return startString + namespace + endString; + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/xsd/InlineXSDResolver.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/xsd/InlineXSDResolver.java new file mode 100644 index 000000000..1cd56eed3 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/xsd/InlineXSDResolver.java @@ -0,0 +1,112 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.wsdl.xsd; + +import java.io.IOException; +import java.io.Reader; +import java.io.StringReader; +import java.util.Hashtable; + +import org.apache.xerces.xni.XMLResourceIdentifier; +import org.apache.xerces.xni.XNIException; +import org.apache.xerces.xni.parser.XMLEntityResolver; +import org.apache.xerces.xni.parser.XMLInputSource; + +/** + * An XMLEntityResolver that allows inline schemas to resolve each other through imports. + * + * @author Lawrence Mandel (lmandel@ca.ibm.com) + */ +public class InlineXSDResolver implements XMLEntityResolver +{ + protected Hashtable entities = new Hashtable(); + protected XMLInputSource referringSchemaInputSource = null; + protected String referringSchemaNamespace = null; + + /** + * Constuctor. + */ + public InlineXSDResolver() + { + } + + /* (non-Javadoc) + * @see org.apache.xerces.xni.parser.XMLEntityResolver#resolveEntity(org.apache.xerces.xni.XMLResourceIdentifier) + */ + public XMLInputSource resolveEntity(XMLResourceIdentifier resourceIdentifier) + throws XNIException, IOException { + String systemId = resourceIdentifier.getExpandedSystemId(); + String publicId = resourceIdentifier.getPublicId(); + String namespace = resourceIdentifier.getNamespace(); + XMLInputSource is = null; + Reader reader = null; + String schema = null; + if (systemId == null) + { + if(publicId == null) + { + if(namespace == null) + { + return null; + } + else + { + systemId = namespace; + } + } + else + { + systemId = publicId; + } + } + + if(referringSchemaNamespace != null && referringSchemaNamespace.equals(systemId)) + { + if(referringSchemaInputSource!=null) + { + return referringSchemaInputSource; + } + } + else if ((schema = (String) entities.get(systemId)) != null && !schema.equals("")) + { + is = new XMLInputSource(publicId, systemId, systemId,new StringReader(schema),null); + } + + //if(is == null) + //{ + // throw new IOException(); + //} + return is; + } + + /** + * Add an inline schema. + * + * @param targetNamespace - the target namespace of the schema + * @param schema - a string representation of the schema + */ + public void add(String targetNamespace, String schema) + { + entities.put(targetNamespace, schema); + } + + /** + * Add the referring inline schema. + * + * @param inputSource - a representation of the inline schema + * @param namespace - the namespace of the inline schema + */ + public void addReferringSchema(XMLInputSource inputSource, String namespace) + { + referringSchemaInputSource = inputSource; + referringSchemaNamespace = namespace; + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/xsd/SchemaAttributeTable.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/xsd/SchemaAttributeTable.java new file mode 100644 index 000000000..74674336e --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/xsd/SchemaAttributeTable.java @@ -0,0 +1,105 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.wsdl.xsd; + +import org.apache.xerces.impl.xs.SchemaSymbols; +import org.apache.xerces.util.SymbolTable; +/** + * This class will allow the calling code to see if the attribute is defined in schema. + * This serves as schema for schema. + * + * @author Lawrence Mandel (lmandel@ca.ibm.com) + */ +public class SchemaAttributeTable extends SymbolTable +{ + + /** + * Constructor. + */ + public SchemaAttributeTable() + { + // add all of the sybols to the table. SchemaSymbols probably should have + // a SymbolTable for these but it doesn't + + super.addSymbol(SchemaSymbols.ATTVAL_TWOPOUNDANY); + super.addSymbol(SchemaSymbols.ATTVAL_TWOPOUNDLOCAL); + super.addSymbol(SchemaSymbols.ATTVAL_TWOPOUNDOTHER); + super.addSymbol(SchemaSymbols.ATTVAL_TWOPOUNDTARGETNS); + super.addSymbol(SchemaSymbols.ATTVAL_POUNDALL); + super.addSymbol(SchemaSymbols.ATTVAL_FALSE_0); + super.addSymbol(SchemaSymbols.ATTVAL_TRUE_1); + super.addSymbol(SchemaSymbols.ATTVAL_ANYSIMPLETYPE); + super.addSymbol(SchemaSymbols.ATTVAL_ANYTYPE); + super.addSymbol(SchemaSymbols.ATTVAL_ANYURI); + super.addSymbol(SchemaSymbols.ATTVAL_BASE64BINARY); + super.addSymbol(SchemaSymbols.ATTVAL_BOOLEAN); + super.addSymbol(SchemaSymbols.ATTVAL_BYTE); + super.addSymbol(SchemaSymbols.ATTVAL_COLLAPSE); + super.addSymbol(SchemaSymbols.ATTVAL_DATE); + super.addSymbol(SchemaSymbols.ATTVAL_DATETIME); + super.addSymbol(SchemaSymbols.ATTVAL_DAY); + super.addSymbol(SchemaSymbols.ATTVAL_DECIMAL); + super.addSymbol(SchemaSymbols.ATTVAL_DOUBLE); + super.addSymbol(SchemaSymbols.ATTVAL_DURATION); + super.addSymbol(SchemaSymbols.ATTVAL_ENTITY); + super.addSymbol(SchemaSymbols.ATTVAL_ENTITIES); + super.addSymbol(SchemaSymbols.ATTVAL_EXTENSION); + super.addSymbol(SchemaSymbols.ATTVAL_FALSE); + super.addSymbol(SchemaSymbols.ATTVAL_FLOAT); + super.addSymbol(SchemaSymbols.ATTVAL_HEXBINARY); + super.addSymbol(SchemaSymbols.ATTVAL_ID); + super.addSymbol(SchemaSymbols.ATTVAL_IDREF); + super.addSymbol(SchemaSymbols.ATTVAL_IDREFS); + super.addSymbol(SchemaSymbols.ATTVAL_INT); + super.addSymbol(SchemaSymbols.ATTVAL_INTEGER); + super.addSymbol(SchemaSymbols.ATTVAL_LANGUAGE); + super.addSymbol(SchemaSymbols.ATTVAL_LAX); + super.addSymbol(SchemaSymbols.ATTVAL_LIST); + super.addSymbol(SchemaSymbols.ATTVAL_LONG); + super.addSymbol(SchemaSymbols.ATTVAL_NAME); + super.addSymbol(SchemaSymbols.ATTVAL_NEGATIVEINTEGER); + super.addSymbol(SchemaSymbols.ATTVAL_MONTH); + super.addSymbol(SchemaSymbols.ATTVAL_MONTHDAY); + super.addSymbol(SchemaSymbols.ATTVAL_NCNAME); + super.addSymbol(SchemaSymbols.ATTVAL_NMTOKEN); + super.addSymbol(SchemaSymbols.ATTVAL_NMTOKENS); + super.addSymbol(SchemaSymbols.ATTVAL_NONNEGATIVEINTEGER); + super.addSymbol(SchemaSymbols.ATTVAL_NONPOSITIVEINTEGER); + super.addSymbol(SchemaSymbols.ATTVAL_NORMALIZEDSTRING); + super.addSymbol(SchemaSymbols.ATTVAL_NOTATION); + super.addSymbol(SchemaSymbols.ATTVAL_OPTIONAL); + super.addSymbol(SchemaSymbols.ATTVAL_POSITIVEINTEGER); + super.addSymbol(SchemaSymbols.ATTVAL_PRESERVE); + super.addSymbol(SchemaSymbols.ATTVAL_PROHIBITED); + super.addSymbol(SchemaSymbols.ATTVAL_QNAME); + super.addSymbol(SchemaSymbols.ATTVAL_QUALIFIED); + super.addSymbol(SchemaSymbols.ATTVAL_REPLACE); + super.addSymbol(SchemaSymbols.ATTVAL_REQUIRED); + super.addSymbol(SchemaSymbols.ATTVAL_RESTRICTION); + super.addSymbol(SchemaSymbols.ATTVAL_SHORT); + super.addSymbol(SchemaSymbols.ATTVAL_SKIP); + super.addSymbol(SchemaSymbols.ATTVAL_STRICT); + super.addSymbol(SchemaSymbols.ATTVAL_STRING); + super.addSymbol(SchemaSymbols.ATTVAL_SUBSTITUTION); + super.addSymbol(SchemaSymbols.ATTVAL_TIME); + super.addSymbol(SchemaSymbols.ATTVAL_TOKEN); + super.addSymbol(SchemaSymbols.ATTVAL_TRUE); + super.addSymbol(SchemaSymbols.ATTVAL_UNBOUNDED); + super.addSymbol(SchemaSymbols.ATTVAL_UNION); + super.addSymbol(SchemaSymbols.ATTVAL_UNQUALIFIED); + super.addSymbol(SchemaSymbols.ATTVAL_UNSIGNEDBYTE); + super.addSymbol(SchemaSymbols.ATTVAL_UNSIGNEDINT); + super.addSymbol(SchemaSymbols.ATTVAL_UNSIGNEDLONG); + super.addSymbol(SchemaSymbols.ATTVAL_UNSIGNEDSHORT); + super.addSymbol(SchemaSymbols.ATTVAL_YEAR); + super.addSymbol(SchemaSymbols.ATTVAL_YEARMONTH); + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/xsd/ValidateErrorHandler.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/xsd/ValidateErrorHandler.java new file mode 100644 index 000000000..deac93911 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/xsd/ValidateErrorHandler.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.wsdl.xsd; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.xerces.xni.XNIException; +import org.apache.xerces.xni.parser.XMLErrorHandler; +import org.apache.xerces.xni.parser.XMLParseException; + +/** + * An implementation of XMLErrorHandler that captures error from Xerces. + * + * @author Lawrence Mandel (lmandel@ca.ibm.com) + */ +public class ValidateErrorHandler implements XMLErrorHandler +{ + ArrayList errorList = new ArrayList(); + + /** + * Get the error messages created by Xerces. + * + * @return The errors list. + */ + public List getErrorMessages() + { + return errorList; + } + + /** + * @see org.apache.xerces.xni.parser.XMLErrorHandler#error(java.lang.String, java.lang.String, org.apache.xerces.xni.parser.XMLParseException) + */ + public void error(String arg0, String arg1, XMLParseException exception) throws XNIException + { + errorList.add("Error: " + exception.getMessage()); + } + + /** + * @see org.apache.xerces.xni.parser.XMLErrorHandler#fatalError(java.lang.String, java.lang.String, org.apache.xerces.xni.parser.XMLParseException) + */ + public void fatalError(String arg0, String arg1, XMLParseException exception) throws XNIException + { + errorList.add("Fatal error: " + exception.getMessage()); + } + + /** + * @see org.apache.xerces.xni.parser.XMLErrorHandler#warning(java.lang.String, java.lang.String, org.apache.xerces.xni.parser.XMLParseException) + */ + public void warning(String arg0, String arg1, XMLParseException exception) throws XNIException + { + errorList.add("Warning: " + exception.getMessage()); + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/xsd/XMLCatalog.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/xsd/XMLCatalog.java new file mode 100644 index 000000000..7571a226c --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/xsd/XMLCatalog.java @@ -0,0 +1,90 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.wsdl.xsd; + +/** + * XMLCatalog + * This class can be used to register, obtain and delete an instance of an + * XML catalog. Method definitions are provided for the catalog to set + * a location in the catalog and resolve an entity from the catalog. + * + * @author Lawrence Mandel (lmandel@ca.ibm.com) + */ +public abstract class XMLCatalog +{ + private static XMLCatalog instance = null; + private static Class xmlcatalogclass = null; + + /** + * Return an instance of the XML catalog. If no instance is registered, + * returns a default instance. + * + * @return the instance of the XML catalog + */ + public static XMLCatalog getInstance() + { + if (instance == null) + { + if (xmlcatalogclass != null) + { + try + { + instance = (XMLCatalog)xmlcatalogclass.newInstance(); + } + catch (Exception e) + { + instance = new XMLCatalogImpl(); + } + } + else + { + instance = new XMLCatalogImpl(); + } + } + return instance; + } + + /** + * Set the class of the XML catalog to be used. + * + * @param xmlcatalog - the class of the XML catalog to be used + */ + public static void setXMLCatalog(Class xmlcatalog) + { + xmlcatalogclass = xmlcatalog; + } + + /** + * Resets the instance of the XML catalog to null. Allows switching XML catalogs. + */ + public static void reset() + { + instance = null; + xmlcatalogclass = null; + } + + /** + * Add a public id and a location to the catalog. + * + * @param publicId - the public id of the entry + * @param systemId - the system id of the entry + */ + public abstract void addEntryToCatalog(String publicId, String systemId); + + /** + * Resolve the location of an entity given public and system ids. + * + * @param publicId - the public id of the entity to be resolved + * @param systemId - the system id of the entity to be resolved + * @return the location of the entity + */ + public abstract String resolveEntityLocation(String publicId, String systemId); +} \ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/xsd/XMLCatalogImpl.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/xsd/XMLCatalogImpl.java new file mode 100644 index 000000000..ec5b48149 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/xsd/XMLCatalogImpl.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.wsdl.xsd; + +import java.util.Hashtable; +import java.util.Map; + +/** + * The default implementation of the XML Catalog. + * + * @author Lawrence Mandel (lmandel@ca.ibm.com) + */ +public class XMLCatalogImpl extends XMLCatalog +{ + protected Map catalog = new Hashtable(); + + /* (non-Javadoc) + * @see org.eclipse.wsdl.validate.xmlconformance.XMLCatalog#addEntryToCatalog(java.lang.String, java.lang.String) + */ + public void addEntryToCatalog(String publicId, String systemId) + { + catalog.put(publicId, systemId); + } + + /* (non-Javadoc) + * @see org.eclipse.wsdl.validate.xmlconformance.XMLCatalog#resolveEntityLocation(java.lang.String, java.lang.String) + */ + public String resolveEntityLocation(String publicId, String systemId) + { + // if there's no system id use the public id + if (systemId == null || systemId.equals("")) + { + systemId = publicId; + } + return (String)catalog.get(systemId); + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/xsd/XMLCatalogResolver.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/xsd/XMLCatalogResolver.java new file mode 100644 index 000000000..91cfd04cd --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/xsd/XMLCatalogResolver.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.wsdl.xsd; + +import java.io.IOException; +import java.io.StringReader; + +import org.apache.xerces.xni.XMLResourceIdentifier; +import org.apache.xerces.xni.XNIException; +import org.apache.xerces.xni.parser.XMLEntityResolver; +import org.apache.xerces.xni.parser.XMLInputSource; + +/** + * A resolver to resolve entities from the XML catalog. + * + * @author Lawrence Mandel (lmandel@ca.ibm.com) + */ +public class XMLCatalogResolver implements XMLEntityResolver +{ + protected static XMLCatalogResolver xmlCatalog; + + /** + * Constructor. + */ + protected XMLCatalogResolver() + { + } + + /** + * Get the instance of this resolver. + * + * @return the instance of this resolver + */ + public static XMLCatalogResolver getInstance() + { + if (xmlCatalog == null) + { + xmlCatalog = new XMLCatalogResolver(); + } + return xmlCatalog; + } + + /** + * @see org.xml.sax.EntityResolver#resolveEntity(java.lang.String, java.lang.String) + */ + public XMLInputSource resolveEntity(XMLResourceIdentifier resourceIdentifier) throws XNIException, IOException + { + String publicId = resourceIdentifier.getPublicId(); + String systemId = resourceIdentifier.getExpandedSystemId(); + String location = XMLCatalog.getInstance().resolveEntityLocation(publicId, systemId); + if (location == null) + { + XMLInputSource inputSource = new XMLInputSource(publicId, systemId, systemId, new StringReader(location), null); + return inputSource; + } + // otherwise return null to tell the parser to locate the systemId as a URI + return null; + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/xsd/XMLEntityResolverChain.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/xsd/XMLEntityResolverChain.java new file mode 100644 index 000000000..2364fe747 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/xsd/XMLEntityResolverChain.java @@ -0,0 +1,74 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.wsdl.xsd; + +import java.io.IOException; +import java.util.Iterator; +import java.util.List; +import java.util.Vector; + +import org.apache.xerces.xni.XMLResourceIdentifier; +import org.apache.xerces.xni.XNIException; +import org.apache.xerces.xni.parser.XMLEntityResolver; +import org.apache.xerces.xni.parser.XMLInputSource; + +/** + * Handle a chain of entity resolvers. + * + * @author Lawrence Mandel (lmandel@ca.ibm.com) + */ +public class XMLEntityResolverChain implements XMLEntityResolver +{ + private List entityResolvers = new Vector(); + + /** + * @see org.apache.xerces.xni.parser.XMLEntityResolver#resolveEntity(org.apache.xerces.xni.XMLResourceIdentifier) + */ + public XMLInputSource resolveEntity(XMLResourceIdentifier xmlResourceIdentifier) throws XNIException, IOException + { + XMLInputSource is = null; + Iterator entityResolverIter = entityResolvers.iterator(); + while (entityResolverIter.hasNext()) + { + XMLEntityResolver entityResolver = (XMLEntityResolver)entityResolverIter.next(); + try + { + is = entityResolver.resolveEntity(xmlResourceIdentifier); + } + catch (XNIException e) + { + } + catch (IOException e) + { + } + if (is != null) + { + break; + } + } + // Throw and IOException if the file isn't found + if (is == null) + { + throw new IOException("Unable to locate file"); + } + return is; + } + + /** + * Add an entity resolver to this chain. + * + * @param entityResolver The resolver to add to the chain. + */ + public void addEntityResolver(XMLEntityResolver entityResolver) + { + entityResolvers.add(entityResolver); + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/xsd/XSDValidator.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/xsd/XSDValidator.java new file mode 100644 index 000000000..925ab50d2 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/wsdl/xsd/XSDValidator.java @@ -0,0 +1,191 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.wsdl.xsd; + +import java.io.Reader; +import java.io.StringReader; +import java.util.ArrayList; +import java.util.List; + +import org.apache.xerces.parsers.XMLGrammarPreparser; +import org.apache.xerces.util.XMLGrammarPoolImpl; +import org.apache.xerces.xni.grammars.XMLGrammarDescription; +import org.apache.xerces.xni.grammars.XMLGrammarLoader; +import org.apache.xerces.xni.grammars.XMLGrammarPool; +import org.apache.xerces.xni.grammars.XSGrammar; +import org.apache.xerces.xni.parser.XMLEntityResolver; +import org.apache.xerces.xni.parser.XMLInputSource; +import org.apache.xerces.xs.XSModel; + + +/** + * Validate schemas from files or String. + * + * @author Lawrence Mandel (lmandel@ca.ibm.com) + */ +public class XSDValidator +{ + private XSModel xsModel; + private boolean isValidXSD; + private List errors; + private String filelocation; + + /** + * Constructor. + */ + public XSDValidator() + { + xsModel = null; + isValidXSD = false; + errors = new ArrayList(); + } + /** + * Validate an inline schema. + * + * @param schema A schema represented as a string. + * @param targetNamespace The target namespace of the schema. + * @param fileloc The uri of the file that contains the schema. + */ + public void validateInlineSchema(String schema, String targetNamespace, String fileloc) + { + validateInlineSchema(schema, targetNamespace, fileloc, null, null); + } + + /** + * Validate an inline schema and specify an entity resolver. + * + * @param schema This schema represented as a string. + * @param targetNamespace The target namespace of the schema. + * @param fileloc The uri of the file that contains this schema. + * @param entityResolverChain The entity resolver chain. + * @param inlineSchemaEntityResolver An inline schema resolver for this schema. + */ + public void validateInlineSchema( + String schema, + String targetNamespace, + String fileloc, + XMLEntityResolver entityResolverChain, + XMLEntityResolver inlineSchemaEntityResolver) + { + filelocation = fileloc; + + validateXSD(schema, true, entityResolverChain,targetNamespace, inlineSchemaEntityResolver); + } + + /** + * Validate the file located at the uri specified with the given entity resolver. + * + * @param uri An absolute uri for the schema location. + * @param entityResolver An entity resolver to be used. + */ + public void validate(String uri, XMLEntityResolver entityResolver) + { + validateXSD(uri, false, entityResolver, null, null); + } + + /** + * Validate the schema. + * + * @param schema The schema or it's location. + * @param inlineXSD True if an inline schema, false otherwise. + * @param entityResolver An entity resolver to use. + * @param targetNamespace The target namespace of the schema being validated. + * @param inlineSchemaEntityResolver An inline schema entity resolver. + */ + protected void validateXSD(String schema, boolean inlineXSD, XMLEntityResolver entityResolver, String targetNamespace, XMLEntityResolver inlineSchemaEntityResolver) + { + ValidateErrorHandler errorHandler = new ValidateErrorHandler(); + errorHandler.getErrorMessages().clear(); + try + { + XMLGrammarPreparser grammarPreparser = new XMLGrammarPreparser(); + XMLGrammarPool grammarPool = new XMLGrammarPoolImpl(); + grammarPreparser.setGrammarPool(grammarPool); + + grammarPreparser.setErrorHandler(errorHandler); + if (entityResolver != null) + { + grammarPreparser.setEntityResolver(entityResolver); + } + + try + { + XMLInputSource is = null; + // this allows support for the inline schema in WSDL documents + if (inlineXSD) + { + + Reader reader = new StringReader(schema); + is = new XMLInputSource(null,filelocation,filelocation,reader,null); + + ((InlineXSDResolver)inlineSchemaEntityResolver).addReferringSchema(is,targetNamespace); + + } + // get the input source for an external schema file + else + { + is = new XMLInputSource(null,schema,schema); + } + + grammarPreparser.registerPreparser(XMLGrammarDescription.XML_SCHEMA,null/*schemaLoader*/); + XMLGrammarLoader schemaLoader = grammarPreparser.getLoader(XMLGrammarDescription.XML_SCHEMA); + + XSGrammar grammar = (XSGrammar)grammarPreparser.preparseGrammar(XMLGrammarDescription.XML_SCHEMA,is); + xsModel = grammar.toXSModel(); + } + catch (Exception e) + { + //parser will return null pointer exception if the document is structurally invalid + errors.add("Schema is structurally invalid."); + } + + errors.addAll(errorHandler.getErrorMessages()); + } + catch (Exception e) + { + System.out.println(e); + } + if (errors.isEmpty()) + { + isValidXSD = true; + } + } + + /** + * Returns the XSModel created. + * + * @return The XSModel created. + */ + + public XSModel getXSModel() + { + return xsModel; + } + /** + * Returns true if the schema is valid, false otherwise. + * + * @return True if the schema is valid, false otherwise. + */ + public boolean isValid() + { + return isValidXSD; + } + + /** + * Return the error list. + * + * @return A list of error from the schema. + */ + public List getErrors() + { + return errors; + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/xml/XMLConvertor.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/xml/XMLConvertor.java new file mode 100644 index 000000000..a95cf71c2 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/xml/XMLConvertor.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.xml; + +import java.io.FileOutputStream; + +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.stream.StreamResult; +import javax.xml.transform.stream.StreamSource; + +/** + * This class converts a XML document using an XSL file. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public class XMLConvertor +{ + + /** + * Transforms an XML document using an XSL file. + * @param args arguments for main. + */ + public static void main(String[] args) + { + try + { + if (args.length < 3) + { + System.out.println( + "Usage: XMLConvertor "); + } + + else + { + // Get transformer + Transformer transformer = + TransformerFactory.newInstance().newTransformer( + new StreamSource(args[0])); + + // Transform the XML document using the specificed XSL file + transformer.transform( + new StreamSource(args[1]), + new StreamResult(new FileOutputStream(args[2]))); + + // Display results + System.out.println( + "Created " + args[2] + " from " + args[0] + " and " + args[1] + "."); + } + } + + catch (Exception e) + { + e.printStackTrace(); + } + + System.exit(0); + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/xml/XMLDocumentCache.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/xml/XMLDocumentCache.java new file mode 100644 index 000000000..e34e541b3 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/xml/XMLDocumentCache.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.xml; + +import java.util.HashMap; +import java.util.Map; + +/** + * This class creates a HashMap to cache XML documents. + * @author Peter Brittenham (peterbr@us.ibm.com) + * @version 1.0.1 + */ +public class XMLDocumentCache extends HashMap +{ + + /** + * Comment for serialVersionUID + */ + private static final long serialVersionUID = 3834028043709657401L; + + /** + * Constructor for XMLDocumentCache. + * @param initialCapacity the initial capacity. + * @param loadFactor the load factor. + */ + public XMLDocumentCache(int initialCapacity, float loadFactor) + { + super(initialCapacity, loadFactor); + } + + /** + * Constructor for XMLDocumentCache. + * @param initialCapacity the initial capacity. + */ + public XMLDocumentCache(int initialCapacity) + { + super(initialCapacity); + } + + /** + * Constructor for XMLDocumentCache. + */ + public XMLDocumentCache() + { + super(); + } + + /** + * Constructor for XMLDocumentCache. + * @param t the map whose mappings are to be placed in this map. + */ + public XMLDocumentCache(Map t) + { + super(t); + } + +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/xml/XMLDocumentCacheUser.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/xml/XMLDocumentCacheUser.java new file mode 100644 index 000000000..0944519f6 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/xml/XMLDocumentCacheUser.java @@ -0,0 +1,122 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.xml; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.w3c.dom.Document; + +import java.net.URL; + +/** + * This is an abstract class that takes advantage of cached XML documents. + * @author Peter Brittenham (peterbr@us.ibm.com) + * @version 1.0.1 + */ + +public abstract class XMLDocumentCacheUser +{ + /** + * Cache of parsed documents. + */ + protected XMLDocumentCache documentList = null; + + /** + * Get document from cache. + * @see #setDocument + * + * @param key a String. + * @return a Document object corresponding to the key. + */ + protected Document getDocument(String key) + { + return (Document) documentList.get(key); + } + + /** + * Put document with corresponding key in cache. + * @see #getDocument + * + * @param key a String used as a key to identify specified document. + * @param document a document. + */ + protected void setDocument(String key, Object document) + { + documentList.put(key, document); + } + + /** + * Get document list. + * @return a XMLDocumentCache object representing the document list value. + */ + public XMLDocumentCache getDocumentList() + { + return documentList; + } + + /** + * Parse XML document. + * @param urlString a String locating the XML document. + * @param baseURI a base url to assist in locating the XML document. + * @return a Document object. + * @throws WSIException if document cannot be parsed. + */ + public Document parseXMLDocumentURL(String urlString, String baseURI) + throws WSIException + { + return parseXMLDocumentURL(urlString, baseURI, null); + } + + /** + * Parse XML document and validate with a schema document. + * @param urlString a String locating the XML document. + * @param baseURI a base url to assist in locating the XML document. + * @param schema a String identifying related schema document. + * @return a Document object. + * @throws WSIException if document cannot be parsed. + */ + public Document parseXMLDocumentURL( + String urlString, + String baseURI, + String schema) + throws WSIException + { + Document document = null; + + try + { + // Create URL reference to document + URL url = XMLUtils.createURL(urlString, baseURI); + + // TODO: Add schema to the xml document cache, so that you can detect when it has already + // been parsed using a specific schema definition + + // If the document is not in the cache, then read and parse it + if ((document = getDocument(urlString)) == null) + { + document = XMLUtils.parseXMLDocumentURL(url, schema); + // Add document to cache + setDocument(urlString, document); + } + } + + catch (WSIException e) + { + throw e; + } + + catch (Exception e) + { + throw new WSIException(e.getMessage(), e); + } + + return document; + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/xml/XMLTags.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/xml/XMLTags.java new file mode 100644 index 000000000..d00c73dc3 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/xml/XMLTags.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.xml; + +import javax.xml.namespace.QName; + +/** + * This class contains information on XML tags. + * + * @author Peter Brittenham (peterbr@us.ibm.com) + * @version 1.0.1 + */ +public interface XMLTags +{ + /** + * Namespaces. + */ + public final static String NS_URI_XSI = + "http://www.w3.org/2001/XMLSchema-instance"; + public final static String NS_URI_XMLNS = "http://www.w3.org/2000/xmlns/"; + public final static String NS_URI_XSD = "http://www.w3.org/2001/XMLSchema"; + public final static String XSD_SCHEMALOCATION = + "http://www.w3.org/2001/XMLSchema.xsd"; + + /** + * Qualified names of XSD elements and attributes. + */ + public final static QName ELEM_XSD_ANNOTATION = + new QName(NS_URI_XSD, "annotation"); + public final static QName ELEM_XSD_IMPORT = new QName(NS_URI_XSD, "import"); + public final static QName ELEM_XSD_INCLUDE = new QName(NS_URI_XSD, "include"); + public final static QName ELEM_XSD_SCHEMA = new QName(NS_URI_XSD, "schema"); + public final static QName ELEM_XSD_ELEMENT = new QName(NS_URI_XSD, "element"); + public final static QName ELEM_XSD_ATTRIBUTE = + new QName(NS_URI_XSD, "attribute"); + public final static QName ELEM_XSD_COMPLEXTYPE = + new QName(NS_URI_XSD, "complexType"); + + public final static QName ATTR_XSI_TYPE = new QName(NS_URI_XSI, "type"); + public final static QName ATTR_XSI_NIL = new QName(NS_URI_XSI, "nil"); + + public final static QName ATTR_XSD_NAME = new QName(NS_URI_XSD, "name"); + public final static QName ATTR_XSD_TYPE = new QName(NS_URI_XSD, "type"); + public final static QName ATTR_XSD_BASE = new QName(NS_URI_XSD, "base"); + public final static QName ATTR_XSD_NAMESPACE = + new QName(NS_URI_XSD, "namespace"); + public final static QName ATTR_XSD_SCHEMALOCATION = + new QName(NS_URI_XSD, "schemaLocation"); + public final static QName ATTR_XSD_TARGETNAMESPACE = + new QName(NS_URI_XSD, "targetNamespace"); + +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/xml/XMLTraversal.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/xml/XMLTraversal.java new file mode 100644 index 000000000..af6091203 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/xml/XMLTraversal.java @@ -0,0 +1,129 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.xml; + +import org.w3c.dom.Attr; +import org.w3c.dom.CDATASection; +import org.w3c.dom.Comment; +import org.w3c.dom.Document; +import org.w3c.dom.DocumentType; +import org.w3c.dom.Element; +import org.w3c.dom.Entity; +import org.w3c.dom.EntityReference; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; +import org.w3c.dom.Notation; +import org.w3c.dom.ProcessingInstruction; +import org.w3c.dom.Text; + +/** + * We don't have access to the node source code, so this does + * our double-dispatch the hard way. + */ +public abstract class XMLTraversal extends XMLVisitor +{ + /** + * Returning false from action would terminates traversal. + * However, this always returns true. -- a no-op. + * @param n - an XML node. + * @return always true. + */ + public boolean action(Node n) + { + return true; + } + + public void visit(CDATASection s) + { + action(s); + } + + public void visit(Document e) + { + if (action(e)) + { + // This does visit DocumentType, which is considered a child Node. + for (Node n = e.getFirstChild(); n != null; n = n.getNextSibling()) + { + doVisit(n); + } + } + } + + public void visit(DocumentType type) + { + if (action(type)) + { + visit(type.getEntities()); + visit(type.getNotations()); + } + } + + public void visit(Attr e) + { + action(e); + } + + public void visit(Element node) + { + if (action(node)) + { + visit(node.getAttributes()); + for (Node n = node.getFirstChild(); n != null; n = n.getNextSibling()) + { + doVisit(n); + } + } + } + + public void visit(Comment e) + { + action(e); + } + + public void visit(Text e) + { + action(e); + } + + public void visit(EntityReference e) + { + action(e); + } + + public void visit(Entity e) + { + action(e); + } + + public void visit(Notation n) + { + action(n); + } + + public void visit(ProcessingInstruction i) + { + action(i); + } + + public void visit(NamedNodeMap map) + { + if (map != null) + { + for (int i = 0; i < map.getLength(); ++i) + { + doVisit(map.item(i)); + } + } + } +} + +// END OF FILE diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/xml/XMLUtils.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/xml/XMLUtils.java new file mode 100644 index 000000000..69d21db85 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/xml/XMLUtils.java @@ -0,0 +1,1503 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.xml; + +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.io.StringReader; +import java.io.StringWriter; +import java.io.Writer; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URL; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.Vector; + +import javax.xml.namespace.QName; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import org.apache.xml.serialize.OutputFormat; +import org.apache.xml.serialize.XMLSerializer; +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.WSITag; +import org.eclipse.wst.wsi.internal.util.NullUtil; +import org.w3c.dom.Attr; +import org.w3c.dom.CharacterData; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.ErrorHandler; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; +import org.xml.sax.SAXParseException; +import org.xml.sax.XMLReader; + +import com.ibm.wsdl.util.StringUtils; + +/** + * Set of XML related utilities. + * + * @version 1.0.1 + * @author Peter Brittenham + */ +public final class XMLUtils +{ + /** + * Some sax features that need to be set. + */ + public static final String FEATURE_NAMESPACE_PREFIXES = "http://xml.org/sax/features/namespace-prefixes"; + public static final String FEATURE_NAMESPACES = "http://xml.org/sax/features/namespaces"; + public static final String FEATURE_VALIDATION_SCHEMA = "http://apache.org/xml/features/validation/schema"; + public static final String JAXP_SCHEMA_LANGUAGE = "http://java.sun.com/xml/jaxp/properties/schemaLanguage"; + public static final String W3C_XML_SCHEMA = "http://www.w3.org/2001/XMLSchema"; + public static final String W3C_SOAP_12_SCHEMA = "http://schemas.xmlsoap.org/soap/envelope/"; + public static final String JAXP_SCHEMA_SOURCE = "http://java.sun.com/xml/jaxp/properties/schemaSource"; + public static final String PROPERTY_EXTERNAL_SCHEMA_LOCATION = "http://apache.org/xml/properties/schema/external-schemaLocation"; + + public static final String SOAP_ELEM_ENVELOPE = "Envelope"; + public static final String SOAP_ELEM_HEADER = "Header"; + public static final String SOAP_ELEM_BODY = "Body"; + public static final String SOAP_ELEM_FAULT = "Fault"; + public static final String SOAP_ELEM_FAULT_CODE = "faultcode"; + public static final String SOAP_ELEM_FAULT_STRING = "faultstring"; + public static final String SOAP_ELEM_FAULT_DETAIL = "detail"; + public static final String SOAP_ELEM_FAULT_ACTOR = "faultactor"; + public static final String SOAP_ATTR_MUST_UNDERSTAND = "mustUnderstand"; + public static final String SOAP_ATTR_ACTOR = "actor"; + + /** + * Get XMLReader. + * + * @return the XMLReader value + * @throws WSIException if there are problems getting the XMLReader + * implementation. + */ + public static XMLReader getXMLReader() throws WSIException { + XMLReader xmlReader = null; + + try + { + xmlReader = (new org.apache.xerces.jaxp.SAXParserFactoryImpl()) + .newSAXParser().getXMLReader(); + + // Set namespace aware + xmlReader.setFeature(FEATURE_NAMESPACE_PREFIXES, true); + xmlReader.setFeature(FEATURE_NAMESPACES, true); + } + + catch (Exception e) + { + throw new WSIException("Could not get XMLReader implementation.", e); + } + + return xmlReader; + } + + /** + * Parse text string as an XML document and return the document element. + * + * @param text XML document text. + * @param validate true if the document will be validate, false otherwise + * @return a Document object. + * @throws WSIException if there is a problem parsing the XML document. + */ + public static Document parseXML(String text, boolean validate) + throws WSIException { + return parseXML(new StringReader(text), validate); + } + + /** + * Parse text string as an XML document and return the document element. + * + * @param text XML document text. + * @return a Document object. + * @throws WSIException if there is a problem parsing the XML document. + */ + public static Document parseXML(String text) throws WSIException { + return parseXML(new StringReader(text)); + } + + /** + * Parse the XML document and return the document element. + * + * @param uri the location of the XML document. + * @return a Document object. + * @throws WSIException if there is a problem parsing the XML document. + * @throws IOException if an I/O exception of some sort has occurred. + */ + public static Document parseXMLDocument(String uri) + throws WSIException, IOException + { + return parseXMLDocument(uri, null); + } + + /** + * Parse the XML document and return the document element. + * + * @param uri the location of the XML document. + * @param schema a String identifying related schema document. + * @return a Document object. + * @throws WSIException if there is a problem parsing the XML document. + * @throws IOException if an I/O exception of some sort has occurred. + */ + public static Document parseXMLDocument(String uri, String schema) + throws WSIException, IOException + { + URL url = StringUtils.getURL(null, uri); + InputStream inputStream = StringUtils.getContentAsInputStream(url); + InputSource inputSource = new InputSource(inputStream); + inputSource.setSystemId(url.toString()); + + if (schema == null) + return parseXML(inputSource, false); + else + return parseXML(inputSource, schema); + } + + /** + * Parses an XML document from a reader and returns the document object. + * + * @param url a String locating the XML document. + * @param schema a String identifying related schema document. + * @param baseURI a base url to assist in locating the XML document. + * @return Document. + * @throws WSIException if there is a problem parsing the XML document. + */ + public static Document parseXMLDocumentURL(String url, String schema, + String baseURI) throws WSIException { + Document document = null; + + try + { + document = parseXMLDocumentURL(createURL(url, baseURI), schema); + } + + catch (Exception e) + { + throw new WSIException(e.getMessage(), e); + } + + return parseXMLDocumentURL(url, schema); + } + + /** + * Parses an XML document from a reader and returns the document object. + * + * @param url a URL object identifying the XML document. + * @param schema a String identifying related schema document. + * @return Document. + * @throws WSIException if there is a problem parsing the XML document. + */ + public static Document parseXMLDocumentURL(URL url, String schema) + throws WSIException { + try + { + InputStream inputStream = StringUtils.getContentAsInputStream(url); + InputSource inputSource = new InputSource(inputStream); + inputSource.setSystemId(url.toString()); + + Document doc = null; + + if (schema == null) + doc = parseXML(inputSource); + else + doc = parseXML(inputSource, schema); + + inputStream.close(); + return doc; + } + + catch (WSIException e) + { + throw e; + } + + catch (Throwable t) + { + throw new WSIException(t.getMessage()); + } + } + + /** + * Parses an XML document from a reader and returns the document object. + * + * @param urlString a String locating the XML document. + * @param baseURI a base url to assist in locating the XML document. + * @return Document object. + * @throws WSIException if there is a problem parsing the XML document. + */ + public static Document parseXMLDocumentURL(String urlString, String baseURI) + throws WSIException { + Document document = null; + + try + { + URL url = createURL(urlString, baseURI); + + document = parseXMLDocumentURL(url); + } + + catch (WSIException we) + { + throw we; + } + + catch (Exception e) + { + throw new WSIException(e.getMessage(), e); + } + + return document; + } + + /** + * Parses an XML document from a reader and returns the document object. + * + * @param url a URL object identifying the XML document. + * @return Document. + * @throws WSIException if there is a problem parsing the XML document. + */ + public static Document parseXMLDocumentURL(URL url) throws WSIException { + Document document = null; + + try + { + Reader reader = new InputStreamReader(url.openStream()); + InputSource source = new InputSource(reader); + source.setSystemId(url.toString()); + document = parseXML(source); + + reader.close(); + } + + catch (Exception e) + { + throw new WSIException(e.getMessage(), e); + } + + return document; + } + + /** + * Parse an XML document from a reader and return the document object. + * + * @param reader a Reader object. + * @param validate true if the document will be validate, false otherwise + * @return a Document object. + * @throws WSIException if there is a problem parsing the XML document. + */ + public static Document parseXML(InputSource source, boolean validate) + throws WSIException { + Document doc = null; + + // Get the document factory + DocumentBuilderFactory factory = new org.eclipse.wst.wsi.internal.xml.jaxp.DocumentBuilderFactoryImpl(); + + // Set namespace aware, but for now do not validate + factory.setNamespaceAware(true); + factory.setIgnoringElementContentWhitespace(true); + + // ADD: This should be set to true when we have access to the schema + // document + factory.setValidating(validate); + + try + { + // Parse the document + DocumentBuilder builder = factory.newDocumentBuilder(); + doc = builder.parse(source); + // workaround for compatibility Xerces 2.2.1 with Xerces 2.6.2, + // Xerces 2.6.2 supported XML 1.1 but WSI-tool and Xerces 2.2.1 + // supported only XML 1.0 + if (doc instanceof org.apache.xerces.dom.DocumentImpl) + { + if (((org.apache.xerces.dom.DocumentImpl) doc).getXmlVersion().equals( + "1.1")) + { + throw new WSIException("Fatal Error: XML version "1.1" " + + "is not supported, only XML 1.0 is supported."); + } + } + } + + catch (Exception e) + { + throw new WSIException("Could not parse XML document.", e); + } + + // Return document + return doc; + } + + /** + * Parse an XML document from a reader and return the document object. + * + * @param reader a Reader object. + * @param validate true if the document will be validate, false otherwise + * @return a Document object. + * @throws WSIException if there is a problem parsing the XML document. + */ + public static Document parseXML(Reader reader, boolean validate) + throws WSIException { + Document doc = null; + ClassLoader currentLoader = Thread.currentThread().getContextClassLoader(); + try + { + Thread.currentThread().setContextClassLoader(XMLUtils.class.getClassLoader()); + ClassLoader tempLoader = Thread.currentThread().getContextClassLoader(); + + // Create input source + InputSource inputSource = new InputSource(reader); + + // Get the document factory + DocumentBuilderFactory factory = new org.eclipse.wst.wsi.internal.xml.jaxp.DocumentBuilderFactoryImpl(); + + // Set namespace aware, but for now do not validate + factory.setNamespaceAware(true); + factory.setIgnoringElementContentWhitespace(true); + + // ADD: This should be set to true when we have access to the schema + // document + factory.setValidating(validate); + + // Parse the document + DocumentBuilder builder = factory.newDocumentBuilder(); + doc = builder.parse(inputSource); + // workaround for compatibility Xerces 2.2.1 with Xerces 2.6.2, + // Xerces 2.6.2 supported XML 1.1 but WSI-tool and Xerces 2.2.1 + // supported only XML 1.0 + if (doc instanceof org.apache.xerces.dom.DocumentImpl) + { + if (((org.apache.xerces.dom.DocumentImpl) doc).getXmlVersion().equals( + "1.1")) + { + throw new WSIException("Fatal Error: XML version "1.1" " + + "is not supported, only XML 1.0 is supported."); + } + } + } + catch (Exception e) + { + throw new WSIException("Could not parse XML document.", e); + } + finally + { + Thread.currentThread().setContextClassLoader(currentLoader); + } + + // Return document + return doc; + } + + /** + * Parse an XML document from a input source and return the document object. + * + * @param source a InputSource object. + * @return a Document object. + * @throws WSIException if there is a problem parsing the XML document. + */ + public static Document parseXML(Reader reader) throws WSIException { + return parseXML(reader, false); + } + + /** + * Parse an XML document from a input source and return the document object. + * + * @param source a InputSource object. + * @return a Document object. + * @throws WSIException if there is a problem parsing the XML document. + */ + public static Document parseXML(InputSource source) throws WSIException { + return parseXML(source, false); + } + + /** + * Parse text string as an XML document and return the document element. + * + * @param text XML document text. + * @param schema a String identifying related schema document. + * @return a Document object. + * @throws WSIException if there is a problem parsing the XML document. + */ + public static Document parseXML(String text, String schema) + throws WSIException { + return parseXML(new StringReader(text), schema); + } + + /** + * Parse text string as an XML document and return the document element. + * + * @param text XML document text. + * @param schemas a collection of related schema documents. + * @return a Document object. + * @throws WSIException if there is a problem parsing the XML document. + */ + public static Document parseXML(String text, Collection schemas) + throws WSIException { + return parseXML(new StringReader(text), schemas); + } + + + /** + * Parse the XML document and return the document element. + * + * @param text XML document text. + * @param schemaString a StringReader object. + * @return a Document object. + * @throws WSIException if there is a problem parsing the XML document. + * @throws IOException if an I/O exception of some sort has occurred. + */ + public static Document parseXML(String text, StringReader schemaString) + throws WSIException, IOException { + return parseXML(new StringReader(text), schemaString); + } + + /** + * Parse the XML document and return the document element. + * + * @param reader a Reader object. + * @param schema a String identifying related schema document. + * @return a Document object. + * @throws WSIException if there is a problem parsing the XML document. + */ + public static Document parseXML(Reader reader, String schema) + throws WSIException { + Document doc = null; + ClassLoader currentLoader = Thread.currentThread().getContextClassLoader(); + try + { + Thread.currentThread().setContextClassLoader(XMLUtils.class.getClassLoader()); + // Create input source + InputSource inputSource = new InputSource(reader); + + // Get the document factory + DocumentBuilderFactory factory = new org.eclipse.wst.wsi.internal.xml.jaxp.DocumentBuilderFactoryImpl(); + + // Set namespace aware, but for now do not validate + factory.setNamespaceAware(true); + factory.setIgnoringElementContentWhitespace(true); + + try + { + factory.setValidating(true); + factory.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA); + } + catch (IllegalArgumentException e) + { + String errMessage = "Error: JAXP DocumentBuilderFactory attribute not recognized: " + + JAXP_SCHEMA_LANGUAGE + + "\n" + + "Check to see if parser conforms to JAXP 1.2 spec."; + throw new WSIException(errMessage, e); + } + factory.setAttribute(JAXP_SCHEMA_SOURCE, new InputSource(schema)); + + // Parse the document + DocumentBuilder builder = factory.newDocumentBuilder(); + builder.setErrorHandler(new ErrHandler()); + doc = builder.parse(inputSource); + + // workaround for compatibility Xerces 2.2.1 with Xerces 2.6.2, + // Xerces 2.6.2 supported XML 1.1 but WSI-tool and Xerces 2.2.1 + // supported only XML 1.0 + if (doc instanceof org.apache.xerces.dom.DocumentImpl) + { + if (((org.apache.xerces.dom.DocumentImpl) doc).getXmlVersion().equals("1.1")) + { + throw new WSIException("Fatal Error: XML version "1.1" " + + "is not supported, only XML 1.0 is supported."); + } + } + } + catch (Exception e) + { + throw new WSIException("Could not parse XML document.", e); + } + finally + { + Thread.currentThread().setContextClassLoader(currentLoader); + } + // Return document + return doc; + } + + /** + * Parse the XML document and return the document element. + * + * @param reader a Reader object. + * @param schema a String identifying related schema document. + * @return a Document object. + * @throws WSIException if there is a problem parsing the XML document. + */ + public static Document parseXML(InputSource source, String schema) + throws WSIException { + Document doc = null; + // Get the document factory + DocumentBuilderFactory factory = new org.eclipse.wst.wsi.internal.xml.jaxp.DocumentBuilderFactoryImpl(); + + // Set namespace aware, but for now do not validate + factory.setNamespaceAware(true); + factory.setIgnoringElementContentWhitespace(true); + + factory.setValidating(true); + try + { + factory.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA); + } + + catch (IllegalArgumentException e) + { + String errMessage = "Error: JAXP DocumentBuilderFactory attribute not recognized: " + + JAXP_SCHEMA_LANGUAGE + + "\n" + + "Check to see if parser conforms to JAXP 1.2 spec."; + throw new WSIException(errMessage, e); + } + factory.setAttribute(JAXP_SCHEMA_SOURCE, new InputSource(schema)); + + try + { + // Parse the document + DocumentBuilder builder = factory.newDocumentBuilder(); + builder.setErrorHandler(new ErrHandler()); + doc = builder.parse(source); + + // workaround for compatibility Xerces 2.2.1 with Xerces 2.6.2, + // Xerces 2.6.2 supported XML 1.1 but WSI-tool and Xerces 2.2.1 + // supported only XML 1.0 + if (doc instanceof org.apache.xerces.dom.DocumentImpl) + { + if (((org.apache.xerces.dom.DocumentImpl) doc).getXmlVersion().equals( + "1.1")) + { + throw new WSIException("Fatal Error: XML version "1.1" " + + "is not supported, only XML 1.0 is supported."); + } + } + } + + catch (Exception e) + { + throw new WSIException("Could not parse XML document.", e); + } + + // Return document + return doc; + + } + + /** + * Parse the XML document and return the document element. + * + * @param filename a Reader object. + * @param schemaString a StringReader object. + * @return a Document object. + * @throws WSIException if there is a problem parsing the XML document. + */ + public static Document parseXML(Reader filename, StringReader schemaString) + throws WSIException { + + Document doc = null; + + // Create input source + InputSource inputSource = new InputSource(filename); + + // Get the document factory + DocumentBuilderFactory factory = new org.eclipse.wst.wsi.internal.xml.jaxp.DocumentBuilderFactoryImpl(); + + // Set namespace aware, but for now do not validate + factory.setNamespaceAware(true); + factory.setIgnoringElementContentWhitespace(true); + + factory.setValidating(true); + try + { + factory.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA); + } catch (IllegalArgumentException e) + { + String errMessage = "Error: JAXP DocumentBuilderFactory attribute not recognized: " + + JAXP_SCHEMA_LANGUAGE + + "\n" + + "Check to see if parser conforms to JAXP 1.2 spec."; + throw new WSIException(errMessage, e); + } + factory.setAttribute(JAXP_SCHEMA_SOURCE, new InputSource(schemaString)); + try + { + // Parse the document + DocumentBuilder builder = factory.newDocumentBuilder(); + builder.setErrorHandler(new ErrHandler()); + doc = builder.parse(inputSource); + } catch (Exception e) + { + throw new WSIException("Could not parse XML document.", e); + } + + // Return document + return doc; + + } + + /** + * Parse the XML document and return the document element. + * + * @param filename a Reader object + * @param schemaStrings a collection of related schema documents. + * @return a Document object. + * @throws WSIException if there is a problem parsing the XML document. + */ + public static Document parseXML(Reader filename, Collection schemaStrings) + throws WSIException { + + Document doc = null; + + // Create input source + InputSource inputSource = new InputSource(filename); + + // Get the document factory + DocumentBuilderFactory factory = new org.eclipse.wst.wsi.internal.xml.jaxp.DocumentBuilderFactoryImpl(); + + // Set namespace aware, but for now do not validate + factory.setNamespaceAware(true); + factory.setIgnoringElementContentWhitespace(true); + + factory.setValidating(true); + try + { + factory.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA); + } catch (IllegalArgumentException e) + { + String errMessage = "Error: JAXP DocumentBuilderFactory attribute not recognized: " + + JAXP_SCHEMA_LANGUAGE + + "\n" + + "Check to see if parser conforms to JAXP 1.2 spec."; + throw new WSIException(errMessage, e); + } + // convert schema strings to array of InputSources + Iterator i = schemaStrings.iterator(); + Vector readers = new Vector(); + while (i.hasNext()) + { + String nextSchema = (String) i.next(); + readers.add(new InputSource(new StringReader(nextSchema))); + } + InputSource[] inputSources = (InputSource[]) readers + .toArray(new InputSource[]{}); + // pass an array of schema strings (each of which contains a schema) + factory.setAttribute(JAXP_SCHEMA_SOURCE, inputSources); + + try + { + // Parse the document + DocumentBuilder builder = factory.newDocumentBuilder(); + builder.setErrorHandler(new ErrHandler()); + doc = builder.parse(inputSource); + } catch (Exception e) + { + throw new WSIException("Could not parse XML document.", e); + } + + // Return document + return doc; + + } + + /** + * Get attribute value with the given name defined for the specified element. + * + * @param element an Element object. + * @param attrName a name of an attribute + * @return the attribute value. + */ + public static String getAttributeValue(Element element, String attrName) { + String attrValue = null; + Attr attr = null; + + // Get the attribute using its name + if ((attr = element.getAttributeNode(attrName)) != null) + { + attrValue = attr.getValue().trim(); + } + + // Return attribute value + return attrValue; + } + + /** + * Get attribute value. + * + * @param element an Element object. + * @param attrName a name of an attribute + * @param defaultValue a default value for the specified attribute. + * @return the attribute value if found. Otherwise the specified default + * value. + */ + public static String getAttributeValue(Element element, String attrName, + String defaultValue) { + String returnValue = defaultValue; + String attrValue = null; + + if ((attrValue = getAttributeValue(element, attrName)) != null) + returnValue = attrValue; + + return returnValue; + } + + /** + * Get attribute value. + * + * @param element an Element object. + * @param namespace a namespace. + * @param attrName a name of an attribute + * @return the attribute value. + */ + public static String getAttributeValueNS(Element element, String namespace, + String attrName) { + String attrValue = null; + Attr attr = null; + + // Get the attribute using its name + if ((attr = element.getAttributeNodeNS(namespace, attrName)) != null) + { + attrValue = attr.getValue().trim(); + } + + // Return attribute value + return attrValue; + } + + /** + * Get the first child element from the input elment. + * + * @param element an Element object. + * @return the firstchild element. + */ + public static Element getFirstChild(Element element) { + // Return the first child element + return findNextSibling(element.getFirstChild()); + } + + /** + * Get the next sibling element. + * + * @param element - an Element object. + * @return the next sibling element. + */ + public static Element getNextSibling(Element element) { + // Return next sibling element + return findNextSibling(element.getNextSibling()); + } + + /** + * Find the next sibling element. + * + * @param startNode XML start node. + * @return the next sibling element. + */ + protected static Element findNextSibling(Node startNode) { + Node node = null; + Element returnElement = null; + + // Find the next sibling element + for (node = startNode; node != null && returnElement == null; node = node + .getNextSibling()) + { + // If this node is an element node, then return it + if (node.getNodeType() == Node.ELEMENT_NODE) + { + returnElement = (Element) node; + } + } + + // Return next sibling element + return (Element) returnElement; + } + + /** + * Find the previous sibling element. + * + * @param startNode XML start node. + * @return the previous sibling element. + */ + public static Element findPreviousSibling(Node startNode) { + if (startNode == null) + return null; + + while (startNode != null) + { + startNode = startNode.getPreviousSibling(); + if (startNode == null) + return null; + if (startNode.getNodeType() == Node.ELEMENT_NODE) + return (Element) startNode; + } + + return null; + } + + /** + * Get the text that is associated with this element. + * + * @param element an Element object. + * @return the text that is associated with this element. + */ + public static String getText(Element element) { + String text = null; + + // Get first child element + Node node = element.getFirstChild(); + + // NodeList nodeList = element.getChildNodes(); + + // int length = nodeList.getLength(); + + // Process while there are nodes and the text hasn't been found + while ((node != null) && (text == null)) + { + // If a text node or cdata section is found, then get text + if ((node.getNodeType() == Node.TEXT_NODE) + || (node.getNodeType() == Node.CDATA_SECTION_NODE)) + { + text = ((CharacterData) node).getData(); + } + + // Get next sibling + node = node.getNextSibling(); + } + + if (text != null) + text = text.trim(); + + return text; + } + + /** + * Determine if an element is represented by the QName. + * + * @param qname a QName object. + * @param element an Element object. + * @return true if an element is represented by the QName. + */ + public static boolean equals(QName qname, Element element) { + boolean equals = false; + + // If both the namespace URI and local name are the same, then they are + // equal + if ((qname.getNamespaceURI().equals(element.getNamespaceURI())) + && (qname.getLocalPart().equals(element.getLocalName()))) + { + equals = true; + } + + return equals; + } + + /** + * XML encode a text string. + * + * @param text - a String. + * @return an XML encoded text string. + */ + public static String xmlEscapedString(String text) + { + if (text == null) return text; + else + { + StringBuffer sb = new StringBuffer(text.length()*2); + int size = text.length(); + for (int i=0; i': + sb.append(">"); + break; + case '&': + sb.append("&"); + break; + case '"': + sb.append("""); + break; + case '\'': + sb.append("'"); + break; + case '\r': + sb.append(" "); + break; + default: + sb.append(c); + } + } + return sb.toString(); + } + } + + /** + * XML encode a text string. + * + * @param text - a String. + * @return an XML encoded text string. + */ + public static String xmlRemoveEscapedString(String text) + { + if (text == null) return text; + else + { + StringBuffer sb = new StringBuffer(text); + + int i = sb.indexOf(" "); + while(i != -1) + { + sb.replace(i, i+5, "\r"); + i = sb.indexOf(" "); + } + + i = sb.indexOf("<"); + while(i != -1) + { + sb.replace(i, i+4, "<"); + i = sb.indexOf("<"); + } + + i = sb.indexOf(">"); + while(i != -1) + { + sb.replace(i, i+4, ">"); + i = sb.indexOf(">"); + } + + i = sb.indexOf("""); + while(i != -1) + { + sb.replace(i, i+6, "\""); + i = sb.indexOf("""); + } + + i = sb.indexOf("'"); + while(i != -1) + { + sb.replace(i, i+6, "\'"); + i = sb.indexOf("'"); + } + + i = sb.indexOf("&"); + while(i != -1) + { + sb.replace(i, i+5, "&"); + i = sb.indexOf("&"); + } + return sb.toString(); + } + } + /** + * Get the specified element from a parent element. + * + * @param elementName the element tag to serach for. + * @param parentElement the parent element. + * @return an element given the name and the parent element. + */ + public static Element getElement(String elementName, Element parentElement) { + Element returnElement = null; + NodeList nl; + + // Get the list of elements + if ((nl = parentElement.getElementsByTagName(elementName)) != null) + { + // Return first element found + returnElement = (Element) nl.item(0); + } + + // Return element + return returnElement; + } + + /** + * Determine if this element matches specified local name in the specified + * namespace. + * + * @param element an Element object. + * @param namespaceURI a namespace. + * @param localName a local name. + * @return true if this element matches specified local name in the specified + * namespace. + */ + public static boolean isElement(Element element, String namespaceURI, + String localName) { + boolean isElement = false; + + if (element != null) + { + // Check is + if (element.getNamespaceURI().equals(namespaceURI) + && element.getLocalName().equals(localName)) + { + isElement = true; + } + } + + return isElement; + } + + /** + * Determine if this element matches specified local name in the specified + * namespace. + * + * @param element an Element object. + * @param namespaceURIs a list of valid namespaces. + * @param localName a local name. + * @return true if this element matches specified local name in the specified + * namespace. + */ + public static boolean isElement(Element element, List namespaceURIs, + String localName) { + boolean isElement = false; + + if (element != null) + { + // Check is + if (namespaceURIs.contains(element.getNamespaceURI()) + && element.getLocalName().equals(localName)) + { + isElement = true; + } + } + + return isElement; + } + + /** + * Get element text as a boolean. + * + * @param element an Element object. + * @param defaultValue a boolean to be used as a default value. + * @return element text as a boolean value. + */ + public static boolean getBooleanValue(Element element, boolean defaultValue) { + boolean returnValue = defaultValue; + String booleanValue = null; + + // Get value as a string + if ((booleanValue = XMLUtils.getText(element)) != null) + { + returnValue = Boolean.valueOf(booleanValue).booleanValue(); + } + + // Return boolean + return returnValue; + } + + /** + * Get attribute value as a boolean. + * + * @param element an Element object. + * @param attrName a name of an attribute. + * @param defaultValue a boolean to be used as a default value. + * @return attribute value as a boolean. + */ + public static boolean getBooleanValue(Element element, String attrName, + boolean defaultValue) { + boolean returnValue = defaultValue; + String booleanValue = null; + + // Get value as a string + if ((booleanValue = XMLUtils.getAttributeValue(element, attrName)) != null) + { + returnValue = Boolean.valueOf(booleanValue).booleanValue(); + } + + // Return boolean + return returnValue; + } + + /** + * Create QName. + * + * @param qnameString a qualified name. + * @return a QName object. + */ + public static QName createQName(String qnameString) { + QName qname = null; + + // Locate local part + int index = qnameString.lastIndexOf(":"); + + // Create new QName + if (index != -1) + { + qname = new QName(qnameString.substring(0, index), qnameString + .substring(index + 1)); + } + + else + { + qname = new QName(qnameString); + } + + return qname; + } + + /** + * Error Handler + */ + private static class ErrHandler implements ErrorHandler + { + /** + * Warning + */ + public void warning(SAXParseException spe) throws SAXException { + String message = "Warning: " + spe.getMessage(); + throw new SAXException(message); + } + + /** + * Error + */ + public void error(SAXParseException spe) throws SAXException { + String message = "Error: " + spe.getMessage(); + throw new SAXException(message); + } + + /** + * Fatal Error + */ + public void fatalError(SAXParseException spe) throws SAXException { + String message = "Fatal Error: " + spe.getMessage(); + throw new SAXException(message); + } + } + + /** + * Determine if the string is a NMTOKEN data type. + * + * @param text a string value. + * @return true if the string is a NMTOKEN data type. + */ + public static boolean isNmtoken(String text) { + boolean nmtoken = true; + + // ADD: Need to find a utility function that does this or write it from + // scratch + + return nmtoken; + } + + /** + * The method searches the first direct descendant element with the given + * qname. + * + * @param parent parent DOM element. + * @param elementName QName of the element to be searched. + * @return DOM element if the required element found, and null otherwise. + */ + static public Element findChildElement(Element parent, QName elementName) { + if (parent == null) + throw new IllegalArgumentException("Parent element can not be NULL"); + if (elementName == null) + throw new IllegalArgumentException("Element name can not be NULL"); + if (elementName.getLocalPart() == null) + throw new IllegalArgumentException( + "Local part of the element name can not be NULL"); + + Node n = parent.getFirstChild(); + String local = elementName.getLocalPart(); + String ns = elementName.getNamespaceURI(); + while (n != null) + { + if (Node.ELEMENT_NODE == n.getNodeType() + && local.equals(n.getLocalName()) + && NullUtil.equals(ns, n.getNamespaceURI())) + return (Element) n; + n = n.getNextSibling(); + } + + return null; + } + + /** + * The method searches the first sibling element with the given qname. + * + * @param active DOM element. + * @param elementName QName of the element to be searched. + * @return DOM element if the required element found, and null otherwise. + */ + static public Element findElement(Element active, QName elementName) { + if (active == null) + throw new IllegalArgumentException("Active element can not be NULL"); + if (elementName == null) + throw new IllegalArgumentException("Element name can not be NULL"); + if (elementName.getLocalPart() == null) + throw new IllegalArgumentException( + "Local part of the element name can not be NULL"); + + Node n = active.getNextSibling(); + String local = elementName.getLocalPart(); + String ns = elementName.getNamespaceURI(); + while (n != null) + { + if (Node.ELEMENT_NODE == n.getNodeType() + && local.equals(n.getLocalName()) + && NullUtil.equals(ns, n.getNamespaceURI())) + return (Element) n; + n = n.getNextSibling(); + } + + return null; + } + + /** + * The method returns attribute node by the given qname. + * + * @param el owner element. + * @param attributeName QName of the attribute node to be searched. + * @return attribute node by the given qname. + */ + static public Attr getAttribute(Element el, QName attributeName) { + if (el == null) + throw new IllegalArgumentException("Element can not be NULL"); + if (attributeName == null) + throw new IllegalArgumentException("Attribute name can not be NULL"); + if (attributeName.getLocalPart() == null) + throw new IllegalArgumentException( + "Local part of the attribute name can not be NULL"); + + Attr a = el.getAttributeNodeNS(attributeName.getNamespaceURI(), + attributeName.getLocalPart()); + if (a == null) + // try to get with null namespace + a = el.getAttributeNodeNS(null, attributeName.getLocalPart()); + return a; + } + + /** + * The method compares node's name to the given qname. + * + * @param n a node. + * @param name a QName object. + * @return true if the node's name is the same as the given qname. + */ + static public boolean equals(Node n, QName name) { + if (n == null || name == null) + return false; + return (NullUtil.equals(name.getLocalPart(), n.getLocalName()) && NullUtil + .equals(name.getNamespaceURI(), n.getNamespaceURI())); + } + + /** + * The method searches namespace URI for the given prefix. The searching + * mechanism is implemented according to the "XML Namespaces resolution" + * algorithm ('http://www.w3.org/TR/2003/WD-DOM-Level-3- + * Core-20030226/namespaces-algorithms.html'). + * + * @param n a node. + * @param prefix a prefix. + * @return the namespace URI for the given prefix. + */ + static public String findNamespaceURI(Node n, String prefix) { + if (prefix == null) + return null; + + while (n != null) + { + if (prefix.equals(n.getPrefix())) + return n.getNamespaceURI(); + + if (Node.ELEMENT_NODE == n.getNodeType()) + { + NamedNodeMap m = n.getAttributes(); + if (m != null) + for (int i = 0; i < m.getLength(); i++) + { + Node a = m.item(i); + if (WSITag.NS_URI_XMLNS.equals(a.getNamespaceURI()) + && prefix.equals(a.getLocalName())) + return a.getNodeValue(); + } + } + + n = n.getParentNode(); + } + + return null; + } + + /** + * Serializes element. + * + * @param n a DOM element. + * @return the serialized element. + */ + public static String serialize(Element n) { + String value = null; + try + { + StringWriter writer = new StringWriter(); + XMLSerializer s = new XMLSerializer(writer, new OutputFormat("xml", + "UTF-8", true)); + s.serialize(n); + value = writer.toString(); + writer.close(); + } catch (Throwable t) + { + // nothing + value = "EXCEPTION : " + t.getMessage(); + } + + return value; + } + + /** + * The method return list of child elements. + * + * @param parent an org.w3c.dom.Element object. + * @return list of child elements. + */ + static public Vector getChildElements(Element parent) { + if (parent == null) + throw new IllegalArgumentException("Element can not be NULL"); + + Vector vect = new Vector(); + Element elem = getFirstChild(parent); + while (elem != null) + { + vect.add(elem); + elem = getNextSibling(elem); + } + return vect; + } + + /** + * Serializes document. + * + * @param doc an org.w3c.dom.Document object. + * @param writer a java.io.Writer object. + * @throws Exception if unable to serialize the document. + */ + public static void serializeDoc(Document doc, Writer writer) + throws java.lang.Exception { + XMLSerializer s = new XMLSerializer(writer, new OutputFormat("xml", + "UTF-8", true)); + s.serialize(doc); + } + + /** + * Serealizes element. + * + * @param elem an org.w3c.dom.Element object. + * @param writer a java.io.Writer object. + * @throws Exception if unable to serialize the DOM element. + */ + public static void serializeElement(Element elem, Writer writer) + throws java.lang.Exception { + XMLSerializer s = new XMLSerializer(writer, new OutputFormat("xml", + "UTF-8", true)); + s.serialize(elem); + } + + /** + * Remove all elements from list without namespace. + * + * @param vect a list of elements. + */ + public static void removeAllElementsWithoutNS(Vector vect) { + for (int i = 0; i < vect.size();) + { + if (((Element) vect.get(i)).getNamespaceURI() == null + || ((Element) vect.get(i)).getNamespaceURI().equals("")) + vect.remove(i); + else + i++; + } + } + + /** + * Create URL using base URI. + * + * @param url a URL string. + * @param baseURI a base url string to assist in creating a URL. + * @return newly created URL. + * @throws MalformedURLException if a malformed URL has occurred. + */ + public static URL createURL(String url, String baseURI) + throws MalformedURLException { + URL returnURL = null; + URI uri = null; + try + { + returnURL = new URL(url); + uri = new URI(url); + uri.normalize(); + returnURL = new URL(uri.toString()); + } + + catch (Exception mue) + { + int i = baseURI.lastIndexOf('/'); + int j = baseURI.lastIndexOf('\\'); + if (j > i) + i = j; + try + { + uri = new URI(baseURI.substring(0, i + 1) + url); + uri.normalize(); + returnURL = uri.toURL(); + } + catch (Exception e) + { + return new URL(baseURI.substring(0, i + 1) + url); + } + } + return returnURL; + } + + /** + * Create URL using base URI. + * + * @param url a URL string. + * @param baseURI a base url string to assist in creating a URL. + * @return newly created URL string. + * @throws MalformedURLException if a malformed URL has occurred. + */ + public static String createURLString(String url, String baseURI) + throws MalformedURLException { + return createURL(url, baseURI).toExternalForm(); + } + + /** + * This method is used only for unit testing. + * + * @param args arguments for main. + */ + public static void main(String[] args) { + try + { + System.out.println("Filename: " + args[0] + ", schema: " + args[1]); + Document doc = parseXMLDocument(args[0], args[1]); + System.out.println("Done."); + } + + catch (Exception e) + { + System.err.println(e.toString()); + } + + System.exit(0); + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/xml/XMLVisitor.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/xml/XMLVisitor.java new file mode 100644 index 000000000..c3af1e7cb --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/xml/XMLVisitor.java @@ -0,0 +1,175 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.xml; + +import org.w3c.dom.*; + +/** + * We don't have access to the node source code, so this does + * our double-dispatch the hard way. + */ +public class XMLVisitor +{ + /** + * Visit XML CDATASection node. + * @param s an XML CDATASection node. + */ + public void visit(CDATASection s) + { + } + + /** + * Visit XML Document node. + * @param e an XML Document node. + */ + public void visit(Document e) + { + } + + /** + * Visit XML DocumentType node. + * @param e an ML DocumentType node. + */ + public void visit(DocumentType e) + { + } + + /** + * Visit XML Attribute node. + * @param e an XML Atrribute node. + */ + public void visit(Attr e) + { + } + + /** + * Visit XML Element node. + * @param e an XML Element node. + */ + public void visit(Element e) + { + } + + /** + * Visit XML Comment node. + * @param e an XML Comment node. + */ + public void visit(Comment e) + { + } + + /** + * Visit XML Text node. + * @param e an XML Text node. + */ + public void visit(Text e) + { + } + + /** + * Visit XML EntityReference node. + * @param e an XML EntityReference node. + */ + public void visit(EntityReference e) + { + } + + /** + * Visit XML Entity node. + * @param e an XML Entity node. + */ + public void visit(Entity e) + { + } + + /** + * Visit XML Notation node. + * @param n an XML Notation node. + */ + public void visit(Notation n) + { + } + + /** + * Visit XML ProcessingInstruction node. + * @param i an XML ProcessingInstruction node. + */ + public void visit(ProcessingInstruction i) + { + } + + /** + * Visit XML NamedNodeMap node. + * @param i an XML NamedNodeMap node. + */ + public void visit(NamedNodeMap i) + { + } + + /** + * Visit XML node. + * @param node an XML node. + */ + public void doVisit(Object node) + { + if (node instanceof Element) + { + visit((Element) node); + } + else if (node instanceof Comment) + { + visit((Comment) node); + } + else if (node instanceof CDATASection) + { + // CDATASection extends Text, so it must come first + visit((CDATASection) node); + } + else if (node instanceof Text) + { + visit((Text) node); + } + else if (node instanceof Attr) + { + visit((Attr) node); + } + else if (node instanceof Document) + { + visit((Document) node); + } + else if (node instanceof EntityReference) + { + visit((EntityReference) node); + } + else if (node instanceof Entity) + { + visit((Entity) node); + } + else if (node instanceof DocumentType) + { + visit((DocumentType) node); + } + else if (node instanceof Notation) + { + visit((Notation) node); + } + else if (node instanceof ProcessingInstruction) + { + visit((ProcessingInstruction) node); + } + else if (node instanceof NamedNodeMap) + { + visit((NamedNodeMap) node); + } + } +} + +// END OF FILE diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/xml/dom/DOMParser.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/xml/dom/DOMParser.java new file mode 100644 index 000000000..fe1a3ef7b --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/xml/dom/DOMParser.java @@ -0,0 +1,96 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.xml.dom; + +import org.w3c.dom.Element; + +import org.xml.sax.SAXNotSupportedException; +import org.xml.sax.SAXNotRecognizedException; + +import org.apache.xerces.dom.ElementImpl; +import org.apache.xerces.xni.Augmentations; +import org.apache.xerces.xni.NamespaceContext; +import org.apache.xerces.xni.QName; +import org.apache.xerces.xni.XMLLocator; +import org.apache.xerces.xni.XMLAttributes; +import org.apache.xerces.xni.XNIException; + +/** + * This class specializes org.apache.xerces.parsers.DOMParser. + * + * @author Peter Brittenham (peterbr@us.ibm.com) + * @version 1.0.1 + */ +public class DOMParser extends org.apache.xerces.parsers.DOMParser +{ + /** + * Locator. + */ + XMLLocator locator = null; + + /* (non-Javadoc) + * @see org.apache.xerces.xni.XMLDocumentHandler#startDocument(org.apache.xerces.xni.XMLLocator, java.lang.String, org.apache.xerces.xni.NamespaceContext, org.apache.xerces.xni.Augmentations) + */ + public void startDocument( + XMLLocator locator, + String encoding, + NamespaceContext context, + Augmentations augs) + throws XNIException + { + this.locator = locator; + super.startDocument(locator, encoding, context, augs); + } + + /* (non-Javadoc) + * @see org.apache.xerces.xni.XMLDocumentHandler#startElement(org.apache.xerces.xni.QName, org.apache.xerces.xni.XMLAttributes, org.apache.xerces.xni.Augmentations) + */ + public void startElement( + QName qname, + XMLAttributes attributes, + Augmentations augs) + throws XNIException + { + Element element; + ElementImpl elementImpl; + + // DEBUG: + //System.err.println("1-line: " + locator.getLineNumber() + ", column: " + locator.getColumnNumber()); + + super.startElement(qname, attributes, augs); + + // DEBUG: + //System.err.println("2-line: " + locator.getLineNumber() + ", column: " + locator.getColumnNumber()); + + try + { + element = (Element) getProperty(CURRENT_ELEMENT_NODE); + + elementImpl = (ElementImpl) element; + + elementImpl.setUserData( + ElementLocation.KEY_NAME, + (ElementLocation)new ElementLocation(locator.getLineNumber(), locator.getColumnNumber()), + null); + } + catch (ClassCastException cce) + { + } + catch (SAXNotSupportedException snse) + { + // DEBUG: + //System.err.println(snse.toString()); + } + catch (SAXNotRecognizedException snre) + { + } + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/xml/dom/ElementLocation.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/xml/dom/ElementLocation.java new file mode 100644 index 000000000..5e62fa015 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/xml/dom/ElementLocation.java @@ -0,0 +1,92 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.xml.dom; + +import org.eclipse.wst.wsi.internal.WSIConstants; + +import org.xml.sax.Locator; + +/** + * This class provides line and column information for a node within an XML document. + * + * @version 1.0.1 + * @author Peter Brittenham (peterbr@us.ibm.com) + */ +public class ElementLocation +{ + /** + * Line number. + */ + public static final String KEY_NAME = ElementLocation.class.getName(); + + /** + * Line number. + */ + protected int lineNumber = 0; + + /** + * Column number. + */ + protected int columnNumber = 0; + + /** + * Element location. + * @param lineNumber a line number. + * @param columnNumber a column number. + */ + public ElementLocation(int lineNumber, int columnNumber) + { + this.lineNumber = lineNumber; + this.columnNumber = columnNumber; + } + + /** + * Element location. + * @param locator a Locator object. + */ + public ElementLocation(Locator locator) + { + this.lineNumber = locator.getLineNumber(); + this.columnNumber = locator.getColumnNumber(); + } + + /** + * Get the line number. + * @return an int representing the line number value. + */ + public int getLineNumber() + { + return this.lineNumber; + } + + /** + * Get the column number. + * @return an int representing the column number value. + */ + public int getColumnNumber() + { + return this.columnNumber; + } + + /** + * Get string representation of this object. + */ + public String toString() + { + return "Element Location:\n" + + " " + + WSIConstants.ATTR_LINE_NUMBER + + "=" + + this.lineNumber + + "\n"; + //+ " " + WSIConstants.ATTR_COLUMN_NUMBER + "=" + this.columnNumber + "\n"; + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/xml/jaxp/DocumentBuilderFactoryImpl.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/xml/jaxp/DocumentBuilderFactoryImpl.java new file mode 100644 index 000000000..eae64c790 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/xml/jaxp/DocumentBuilderFactoryImpl.java @@ -0,0 +1,86 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.xml.jaxp; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; + +import java.util.Hashtable; + +/** + * This class defines a factory API that enables us to obtain a parser + * that produces DOM object trees from XML documents. Note this class + * specializes javax.xml.parsers.DocumentBuilderFactory. + * + * @author Peter Brittenham (peterbr@us.ibm.com) + * @version 1.0.1 + */ +public class DocumentBuilderFactoryImpl extends DocumentBuilderFactory +{ + + protected Hashtable attributes = new Hashtable(); + + /** + * Creates a new instance of a DocumentBuilder using the currently + * configured parameters. + * + * @return a new instance of a DocumentBuilder. + * @throws ParserConfigurationException if a DocumentBuilder cannot + * be created which satisfies the configuration requested. + */ + public DocumentBuilder newDocumentBuilder() + throws ParserConfigurationException + { + DocumentBuilder documentBuilder = null; + + try + { + documentBuilder = new DocumentBuilderImpl(this, attributes); + } + + catch (Exception e) + { + throw new ParserConfigurationException(e.getMessage()); + } + + return documentBuilder; + } + + /** + * Allows the user to retrieve specific attributes on the underlying + * implementation. + * + * @param name the name of the attribute. + * @return the value of the attribute. + * @throws IllegalArgumentException f the underlying implementation + * doesn't recognize the attribute. + */ + public Object getAttribute(String name) throws IllegalArgumentException + { + return attributes.get(name); + } + + /** + * Allows the user to set specific attributes on the underlying + * implementation. + * + * @param name the name of the attribute. + * @param value the value of the attribute. + * @throws IllegalArgumentException if the underlying implementation + * doesn't recognize the attribute. + */ + public void setAttribute(String name, Object value) + throws IllegalArgumentException + { + attributes.put(name, value); + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/xml/jaxp/DocumentBuilderImpl.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/xml/jaxp/DocumentBuilderImpl.java new file mode 100644 index 000000000..e4f2679a1 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/xml/jaxp/DocumentBuilderImpl.java @@ -0,0 +1,249 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.xml.jaxp; + + +import org.apache.xerces.impl.Constants; +import org.apache.xerces.dom.DocumentImpl; +import org.apache.xerces.dom.DOMImplementationImpl; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; +import org.eclipse.wst.wsi.internal.xml.dom.DOMParser; + +import org.w3c.dom.DOMImplementation; +import org.w3c.dom.Document; +import org.xml.sax.EntityResolver; +import org.xml.sax.ErrorHandler; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.DefaultHandler; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; + +import java.io.IOException; +import java.util.Hashtable; +import java.util.Enumeration; + +/** + * Using this class, we can obtain a Document from XML. This class is a + * specialization of javax.xml.parsers.DocumentBuilder. + * + * An instance of this class can be obtained from the + * DocumentBuilderFactory.newDocumentBuilder method. Once an instance + * of this class is obtained, XML can be parsed from a variety of input + * sources. These input sources are InputStreams, Files, URLs, and SAX + * InputSources. + +This class will javax.xml.parsers.DocumentBuilderFactory... + * + * @author Peter Brittenham (peterbr@us.ibm.com) + * @version 1.0.1 + */ +public class DocumentBuilderImpl extends DocumentBuilder +{ + protected DOMParser domParser = null; + + protected EntityResolver entityResolver = null; + protected ErrorHandler errorHandler = new DefaultHandler(); + + protected static final String NAMESPACES_FEATURE = + Constants.SAX_FEATURE_PREFIX + Constants.NAMESPACES_FEATURE; + protected static final String VALIDATION_FEATURE = + Constants.SAX_FEATURE_PREFIX + Constants.VALIDATION_FEATURE; + + /** + * Constructor for DocumentBuilderImpl2. + * + * @param dbFactory a DocumentBuilderFactory object. + * @throws SAXException if any parse errors occur. + */ + public DocumentBuilderImpl(DocumentBuilderFactory dbFactory, Hashtable attributes) + throws SAXException + { + // Create parser + domParser = new DOMParser(); + + // Set namespace aware + domParser.setFeature(NAMESPACES_FEATURE, dbFactory.isNamespaceAware()); + + // Set validating + domParser.setFeature(VALIDATION_FEATURE, dbFactory.isValidating()); + if (dbFactory.isValidating()) domParser.setFeature(XMLUtils.FEATURE_VALIDATION_SCHEMA, true); + + // Do not defer node expansion + domParser.setFeature( + Constants.XERCES_FEATURE_PREFIX + Constants.DEFER_NODE_EXPANSION_FEATURE, + false); + + // Set other features from the document factory builder + domParser.setFeature( + Constants.XERCES_FEATURE_PREFIX + Constants.INCLUDE_IGNORABLE_WHITESPACE, + !dbFactory.isIgnoringElementContentWhitespace()); + domParser.setFeature( + Constants.XERCES_FEATURE_PREFIX + + Constants.CREATE_ENTITY_REF_NODES_FEATURE, + !dbFactory.isExpandEntityReferences()); + domParser.setFeature( + Constants.XERCES_FEATURE_PREFIX + Constants.INCLUDE_COMMENTS_FEATURE, + !dbFactory.isIgnoringComments()); + domParser.setFeature( + Constants.XERCES_FEATURE_PREFIX + Constants.CREATE_CDATA_NODES_FEATURE, + !dbFactory.isCoalescing()); + + // set features and properties specified at factory level + if (attributes != null) + { + for (Enumeration i=attributes.keys(); i.hasMoreElements();) + { + String attribute = (String)i.nextElement(); + if (attribute.equals(XMLUtils.JAXP_SCHEMA_SOURCE)) + { + // for multiple schema validation may be array of InputSource + if(attributes.get(attribute) instanceof InputSource[]) + domParser.setProperty(attribute, (InputSource[])attributes.get(attribute)); + else + domParser.setProperty(attribute, (InputSource)attributes.get(attribute)); + } + else + { + domParser.setProperty(attribute, attributes.get(attribute)); + } + } + } + } + + /** + * Parse the content of the given input source as an XML document and return a new DOM. + * @param is InputStream containing the content to be parsed. + * @throws SAXException if any parse errors occur. + * @throws IOException if any IO errors occur. + */ + public Document parse(InputSource is) throws SAXException, IOException + { + ClassLoader currentLoader = Thread.currentThread().getContextClassLoader(); + try + { + Thread.currentThread().setContextClassLoader(XMLUtils.class.getClassLoader()); + + // Set entity resolver + if (this.entityResolver != null) + domParser.setEntityResolver(this.entityResolver); + + // Set error handler + if (this.errorHandler != null) + domParser.setErrorHandler(this.errorHandler); + + // Parse input source + domParser.parse(is); + + // Return the document that was created + return domParser.getDocument(); + } + finally + { + Thread.currentThread().setContextClassLoader(currentLoader); + } + } + + /** + * Indicates whether or not this parser is configured to understand namespaces. + * @return true if this parser is configured to understand namespaces; false otherwise. + */ + public boolean isNamespaceAware() + { + boolean namespaceAware = false; + + try + { + namespaceAware = domParser.getFeature(NAMESPACES_FEATURE); + } + + catch (SAXException se) + { + throw new RuntimeException(se.toString()); + } + + return namespaceAware; + } + + /** + * Indicates whether or not this parser is configured to validate XML documents. + * @return true if this parser is configured to validate XML documents; false otherwise. + */ + public boolean isValidating() + { + boolean validating = false; + + try + { + validating = domParser.getFeature(VALIDATION_FEATURE); + } + + catch (SAXException se) + { + throw new RuntimeException(se.toString()); + } + + return validating; + } + + /** + * Specify the EntityResolver to be used to resolve entities present + * in the XML document to be parsed. Setting this to null will result + * in the underlying implementation using it's own default + * implementation and behavior. + * + * @param er the EntityResolver to be used to resolve entities + * present in the XML document to be parsed. + */ + public void setEntityResolver(EntityResolver entityResolver) + { + this.entityResolver = entityResolver; + } + + /** + * Specify the ErrorHandler to be used to report errors present in + * the XML document to be parsed. Setting this to null will result + * in the underlying implementation using it's own default + * implementation and behavior. + * + * param eh the ErrorHandler to be used to report errors present in + * the XML document to be parsed. + */ + public void setErrorHandler(ErrorHandler errorHandler) + { + this.errorHandler = errorHandler; + } + + /** + * Obtain a new instance of a DOM Document object to build a DOM + * tree with. An alternative way to create a DOM Document object + * is to use the getDOMImplementation method to get a DOM Level 2 + * DOMImplementation object and then use DOM Level 2 methods on + * that object to create a DOM Document object. + * + * @return a new instance of a DOM Document object. + */ + public Document newDocument() + { + return new DocumentImpl(); + } + + /** + * Obtain an instance of a DOMImplementation object. + * @return a new instance of a DOMImplementation. + */ + public DOMImplementation getDOMImplementation() + { + return new DOMImplementationImpl(); + } + +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/xml/schema/TargetNamespaceProcessor.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/xml/schema/TargetNamespaceProcessor.java new file mode 100644 index 000000000..95a61a5ea --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/xml/schema/TargetNamespaceProcessor.java @@ -0,0 +1,136 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.xml.schema; + +import java.util.List; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.util.TestUtils; +import org.eclipse.wst.wsi.internal.xml.XMLDocumentCache; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; + +import org.w3c.dom.Attr; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; + +/** + * This class processes target namespaces. Note this class is a specialization + * of org.wsi.xml.schema.XMLSchemaProcessor. + * + * @author Peter Brittenham (peterbr@us.ibm.com) + * @version 1.0.1 + */ +public class TargetNamespaceProcessor extends XMLSchemaProcessor +{ + + /** + * Constructor for TargetNamespaceProcess. + * + * @param context + * document context + * @param documentList + * cache of previously parsed documents + */ + public TargetNamespaceProcessor( + String context, + XMLDocumentCache documentList) + { + super(context, documentList, false); + } + + protected void processSchema(Element element) + { + String tns = null; + Attr attr = XMLUtils.getAttribute(element, ATTR_XSD_TARGETNAMESPACE); + + // If the attribute was found and value is not null, then add it to the list + if ((attr != null) && ((tns = attr.getValue()) != null)) + { + // Add the targetNamespace to the return list + returnList.add(tns); + } + } + + /** + * Search for all schema elements, load the xsd documents, and then process + * them. + * + * @param node + * node. + * @return a list. + * @throws WSIException + * if the XML schema file is not found or if it is not formatted + * correctly. + */ + public List processAllSchema(Node node) throws WSIException + { + return processAllSchema(node, context); + } + + /** + * Search for all schema elements, load the xsd documents, and then process + * them. + * + * @param node + * node. + * @return a list. + * @throws WSIException + * if the XML schema file is not found or if it is not formatted + * correctly. + */ + private List processAllSchema(Node node, String ctx) throws WSIException + { + // if xsd:schema element is found -> process schema + if (XMLUtils.equals(node, ELEM_XSD_SCHEMA)) + { + processSchema((Element) node); + + Node n = node.getFirstChild(); + while (n != null) + { + if (Node.ELEMENT_NODE == n.getNodeType()&& XMLUtils.equals(n, ELEM_XSD_IMPORT)) + { + Attr schemaLocation = XMLUtils.getAttribute((Element) n, ATTR_XSD_SCHEMALOCATION); + + // Try to parse imported XSD + if (schemaLocation != null && schemaLocation.getValue() != null) + { + if (!schemaLocations.contains(schemaLocation.getValue())) + { + schemaLocations.add(schemaLocation.getValue()); + try + { + // Read and pParse the XML schema document + Document document = parseXMLDocumentURL(schemaLocation.getValue(), ctx, TestUtils.getXMLSchemaLocation()); + processAllSchema(document.getDocumentElement(), XMLUtils.createURLString(schemaLocation.getValue(), ctx)); + } + catch (WSIException e) + { + if (throwException) throw e; + } + catch (Throwable t) + { + // NOTE: An exception will occur if the XML schema file is not + // found or if it is not formatted correctly + if (throwException) throw new WSIException(t.getMessage(), t); + } + } + } + } + n = n.getNextSibling(); + } + } + + // Return list created by the class that extends this class + return returnList; + } +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/xml/schema/XMLSchemaProcessor.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/xml/schema/XMLSchemaProcessor.java new file mode 100644 index 000000000..7b9508e54 --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/xml/schema/XMLSchemaProcessor.java @@ -0,0 +1,163 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.xml.schema; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.util.TestUtils; +import org.eclipse.wst.wsi.internal.xml.XMLDocumentCache; +import org.eclipse.wst.wsi.internal.xml.XMLDocumentCacheUser; +import org.eclipse.wst.wsi.internal.xml.XMLTags; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; + +import org.w3c.dom.Attr; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; + +import java.util.List; +import java.util.Vector; + +/** + * This abstract class is used to process an XML Schema. + * + * @author Peter Brittenham (peterbr@us.ibm.com) + * @version 1.0.1 + */ +public abstract class XMLSchemaProcessor + extends XMLDocumentCacheUser + implements XMLTags +{ + protected List returnList = new Vector(); + protected String context; + protected boolean throwException = true; + protected List schemaLocations = new Vector(); + + /** + * Constructor for XMLSchemaProcessor. + * @param context document context. + * @param documentList cache of previously parsed documents. + */ + public XMLSchemaProcessor(String context, XMLDocumentCache documentList) + { + this(context, documentList, true); + } + + /** + * Constructor for XMLSchemaProcessor. + * @param context document context. + * @param documentList cache of previously parsed documents. + * @param throwException indicates if an exception should be thrown if there is a parsing problem. + */ + public XMLSchemaProcessor( + String context, + XMLDocumentCache documentList, + boolean throwException) + { + super(); + + this.context = context; + this.documentList = documentList; + this.throwException = throwException; + } + + /** + * Search for all schema elements, load the xsd documents, and then process them. + * @param node node. + * @return a list. + * @throws WSIException if the XML schema file is not found or if it is not formatted correctly. + */ + public List processAllSchema(Node node) throws WSIException + { + return processAllSchema(node, context); + } + + /** + * Search for all schema elements, load the xsd documents, and then process them. + * @param node node. + * @return a list. + * @throws WSIException if the XML schema file is not found or if it is not formatted correctly. + */ + private List processAllSchema(Node node, String ctx) throws WSIException + { + // Process all nodes + while (node != null) + { + // If this is an element node, then continue + if (Node.ELEMENT_NODE == node.getNodeType()) + { + // if xsd:schema element is found -> process schema + if (XMLUtils.equals(node, ELEM_XSD_SCHEMA)) + { + processSchema((Element) node); + + // Process all children of the schema element + processAllSchema(node.getFirstChild(), ctx); + } + + // if xsd:import element is found -> load schema and process schema + else if (XMLUtils.equals(node, ELEM_XSD_IMPORT)) + { + + Attr schemaLocation = + XMLUtils.getAttribute((Element) node, ATTR_XSD_SCHEMALOCATION); + + // Try to parse imported XSD + if (schemaLocation != null && schemaLocation.getValue() != null) + { + if (!schemaLocations.contains(schemaLocation.getValue())) + { + schemaLocations.add(schemaLocation.getValue()); + try + { + // Read and pParse the XML schema document + Document document = + parseXMLDocumentURL( + schemaLocation.getValue(), + ctx, + TestUtils.getXMLSchemaLocation()); + + processAllSchema(document.getDocumentElement(), + XMLUtils.createURLString(schemaLocation.getValue(), ctx)); + } + catch (WSIException e) + { + if (throwException) + throw e; + } + + catch (Throwable t) + { + // NOTE: An exception will occur if the XML schema file is not found or if it is not formatted correctly + if (throwException) + throw new WSIException(t.getMessage(), t); + } + } + } + } + + else + { + // else iterate element recursively + processAllSchema(node.getFirstChild(), ctx); + } + } + + // Get next sibiling + node = node.getNextSibling(); + } + + // Return list created by the class that extends this class + return returnList; + } + + protected abstract void processSchema(Element element); + +} diff --git a/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/xml/schema/XMLSchemaValidator.java b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/xml/schema/XMLSchemaValidator.java new file mode 100644 index 000000000..0bb0b8a5c --- /dev/null +++ b/bundles/org.eclipse.wst.wsi/wsitools/org/eclipse/wst/wsi/internal/xml/schema/XMLSchemaValidator.java @@ -0,0 +1,156 @@ +/******************************************************************************* + * Copyright (c) 2002-2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.wsi.internal.xml.schema; + +import org.eclipse.wst.wsi.internal.WSIException; +import org.eclipse.wst.wsi.internal.util.TestUtils; +import org.eclipse.wst.wsi.internal.xml.XMLDocumentCache; +import org.eclipse.wst.wsi.internal.xml.XMLUtils; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; +import com.ibm.wsdl.util.xml.DOM2Writer; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +/** + * This class is used to validate an XML Schema. + * + * @author Peter Brittenham (peterbr@us.ibm.com) + * @version 1.0.1 + */ +public class XMLSchemaValidator extends XMLSchemaProcessor +{ + private static final String XMLNS_PREFIX = "xmlns:"; + + /** + * Constructor for XMLSchemaValidator. + * @param context document context. + * @param documentList cache of previously parsed documents. + */ + public XMLSchemaValidator(String context, XMLDocumentCache documentList) + { + super(context, documentList); + } + + protected void processSchema(Element element) + { + NamedNodeMap attrList; + String elementPrefix = null; + + HashMap elementMap = new HashMap(); + HashMap nsMap = new HashMap(); + + try + { + // Get schema content as a string + String schema = DOM2Writer.nodeToString(element); + + // Get list of element namespaces + if ((attrList = element.getAttributes()) != null) + { + addNamespaces(attrList, elementMap, null); + } + + // If elementMap does not contain entry for it's own namespace, then add it + if (elementMap.get(XMLNS_PREFIX + element.getPrefix()) == null) + { + elementMap.put( + XMLNS_PREFIX + element.getPrefix(), + element.getNamespaceURI()); + } + + // Get first parent node and then process all of them until you hit the top of the document + Node parentNode = element.getParentNode(); + while (parentNode != null) + { + // Only process Element nodes + if (parentNode.getNodeType() == Node.ELEMENT_NODE) + { + // Get the list of attributes for the parent node + attrList = parentNode.getAttributes(); + + // If there are attributes, look for the xmlns: attributes + if (attrList != null) + { + addNamespaces(attrList, nsMap, elementMap); + } + } + + parentNode = parentNode.getParentNode(); + } + + // Build namespace list + if (nsMap.size() > 0) + { + String attr; + String namespaceList = ""; + Iterator iterator = nsMap.keySet().iterator(); + while (iterator.hasNext()) + { + attr = (String) iterator.next(); + namespaceList += " " + attr + "=\"" + nsMap.get(attr) + "\""; + } + + // Add namespace settings, since the DOM2Writer will miss any that are used as attribute values + int index = schema.indexOf(">"); + if (index > 0) + { + String start = schema.substring(0, index); + String end = schema.substring(index); + + schema = start + namespaceList + end; + } + } + + // Schema validate the XML schema document + Document doc = + XMLUtils.parseXML(schema, TestUtils.getXMLSchemaLocation()); + } + + catch (WSIException we) + { + Throwable t = we.getTargetException(); + if (t != null) + { + returnList.add(t.getMessage()); + } + } + } + + private void addNamespaces(NamedNodeMap attrList, Map nsMap, Map elementMap) + { + Node attr; + String nodeName; + + for (int i = 0; i < attrList.getLength(); i++) + { + attr = attrList.item(i); + + // Get the attribute node name + nodeName = attr.getNodeName(); + + // If it starts with xmlns:, then determine if it should be added to the list of namespaces + if (nodeName.startsWith(XMLNS_PREFIX) + && ((elementMap == null + || (elementMap != null && elementMap.get(nodeName) == null)))) + { + if (nsMap.get(nodeName) == null) + nsMap.put(nodeName, attr.getNodeValue()); + } + } + } + +} -- cgit v1.2.3