1
+ /**
2
+ * Copyright (c) 2008
3
+ * Changhua Li
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining a
6
+ * copy of this software and associated documentation files (the "Software"),
7
+ * to deal in the Software without restriction, including without limitation
8
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9
+ * and/or sell copies of the Software, and to permit persons to whom the
10
+ * Software is furnished to do so, subject to the following conditions:
11
+ *
12
+ * The above copyright notice and this permission notice shall be included in
13
+ * all copies or substantial portions of the Software.
14
+ *
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21
+ * DEALINGS IN THE SOFTWARE.
22
+ **/
23
+
24
+ if ( ! ORYX . Plugins )
25
+ ORYX . Plugins = new Object ( ) ;
26
+
27
+ ORYX . Plugins . BPEL4Chor2BPELSupport = ORYX . Plugins . AbstractPlugin . extend ( {
28
+
29
+ /**
30
+ * Offers the plugin functionality:
31
+ */
32
+ construct : function ( ) {
33
+ // Call super class constructor
34
+ arguments . callee . $ . construct . apply ( this , arguments ) ;
35
+
36
+ this . dialog2BPELSupport = new ORYX . Plugins . TransformationDownloadDialogForBPEL4Chor ( ) ;
37
+
38
+ this . facade . offer ( {
39
+ 'name' :ORYX . I18N . BPEL4Chor2BPELSupport . exp ,
40
+ 'functionality' : this . exportProcess . bind ( this ) ,
41
+ 'group' : ORYX . I18N . JSONSupport . exp . group ,
42
+ dropDownGroupIcon : ORYX . PATH + "images/export2.png" ,
43
+ 'icon' : ORYX . PATH + "images/bpel4chor2bpel_export_icon.png" ,
44
+ 'description' : ORYX . I18N . BPEL4Chor2BPELSupport . expDesc ,
45
+ 'index' : 0 ,
46
+ 'minShape' : 0 ,
47
+ 'maxShape' : 0
48
+ } ) ;
49
+ } ,
50
+
51
+ /***************************** export **********************************/
52
+
53
+ exportProcess : function ( ) {
54
+
55
+ // raise loading enable event
56
+ this . facade . raiseEvent ( {
57
+ type : ORYX . CONFIG . EVENT_LOADING_ENABLE
58
+ } ) ;
59
+
60
+ // asynchronously ...
61
+ window . setTimeout ( ( function ( ) {
62
+
63
+ // ... save synchronously
64
+ this . exportSynchronously ( ) ;
65
+
66
+ // raise loading disable event.
67
+ this . facade . raiseEvent ( {
68
+ type : ORYX . CONFIG . EVENT_LOADING_DISABLE
69
+ } ) ;
70
+
71
+ } ) . bind ( this ) , 10 ) ;
72
+
73
+ return true ;
74
+ } ,
75
+
76
+ exportSynchronously : function ( ) {
77
+
78
+ var resource = location . href ;
79
+
80
+
81
+ try {
82
+ var serialized_rdf = this . getRDFFromDOM ( ) ;
83
+
84
+ Ext . Msg . show ( {
85
+ title :'RDF Information' ,
86
+ msg : serialized_rdf , // rdf information of this Dom.
87
+ buttons : Ext . Msg . YESNOCANCEL ,
88
+ icon : Ext . MessageBox . QUESTION
89
+ } ) ;
90
+
91
+ if ( ! serialized_rdf . startsWith ( "<?xml" ) ) {
92
+ serialized_rdf = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + serialized_rdf ;
93
+ }
94
+
95
+ // Send the request to the server.
96
+ new Ajax . Request ( ORYX . CONFIG . BPEL4CHOR2BPEL_EXPORT_URL , {
97
+ method : 'POST' ,
98
+ asynchronous : false ,
99
+ parameters : {
100
+ resource : resource ,
101
+ data : serialized_rdf
102
+ } ,
103
+ onSuccess : function ( response ) {
104
+ this . displayResult ( response . responseText ) ;
105
+ } . bind ( this )
106
+ } ) ;
107
+
108
+
109
+ } catch ( error ) {
110
+ this . facade . raiseEvent ( { type :ORYX . CONFIG . EVENT_LOADING_DISABLE } ) ;
111
+ Ext . Msg . alert ( ORYX . I18N . Oryx . title , error ) ;
112
+ }
113
+
114
+ } ,
115
+
116
+
117
+ /**
118
+ * Builds up the data that will be shown in the result dialog of
119
+ * the BPEL4Chor to BPEL transformation.
120
+ * For this purpose the process and wsdl names are determined
121
+ * it is checked if them were generated successfully.
122
+ *
123
+ * @param {String[] } bpelArray The generated process array of bpel processes
124
+ * @param {String[] } wsdlArray The generated wsdl array of bpel processes
125
+ */
126
+ buildTransData : function ( bpelArray , wsdlArray ) {
127
+ var data = new Array ( ) ;
128
+ for ( var i = 0 ; i < bpelArray . length ; i ++ ) {
129
+ var name = this . dialog2BPELSupport . getBPELName ( bpelArray [ i ] ) ;
130
+ if ( name == undefined ) {
131
+ name = "Process " + ( i + 1 ) ;
132
+ }
133
+ data [ i ] = [ name , bpelArray [ i ] , this . dialog2BPELSupport . getResultInfo ( bpelArray [ i ] ) ] ;
134
+ }
135
+
136
+ for ( var i = 0 ; i < wsdlArray . length ; i ++ ) {
137
+ var name = this . dialog2BPELSupport . getBPELName ( bpelArray [ i ] ) ; // name of wsdl file should be same with bpel file
138
+ name = name + "-wsdl" ;
139
+ if ( name == undefined ) {
140
+ name = "WSDL " + ( i + 1 ) ;
141
+ }
142
+ data [ i + bpelArray . length ] = [ name , wsdlArray [ i ] , this . dialog2BPELSupport . getResultInfo ( wsdlArray [ i ] ) ] ;
143
+ }
144
+ return data ;
145
+ } ,
146
+
147
+ /**
148
+ * Analyzes the result of the servlet call.
149
+ *
150
+ * If an fault occured or the answer is undefined, the error is shown
151
+ * using a message dialog.
152
+ *
153
+ * If the first result starts with "ParserError" the error is shown using an
154
+ * error dialog. Otherwise the result is shown using the result dialog.
155
+ *
156
+ * @param {Object } result - the result of the transformation servlet (JSON)
157
+ */
158
+ displayResult : function ( result ) {
159
+ this . facade . raiseEvent ( { type :ORYX . CONFIG . EVENT_LOADING_DISABLE } ) ;
160
+
161
+ var resultString = '(' + result + ')' ;
162
+
163
+ alert ( resultString ) ;
164
+
165
+ var resultObject ;
166
+
167
+ try {
168
+ resultObject = eval ( resultString ) ;
169
+ } catch ( e1 ) {
170
+ alert ( "Error during evaluation of result: " + e1 + "\r\n" + resultString ) ;
171
+ }
172
+
173
+ if ( ( ! resultObject . res ) || ( resultObject . res . length == 0 ) ) {
174
+ this . dialog2BPELSupport . openMessageDialog ( ORYX . I18N . TransformationDownloadDialog . error , ORYX . I18N . TransformationDownloadDialog . noResult ) ;
175
+ } else if ( resultObject . res [ 0 ] . contentBPEL . indexOf ( "Parser Error" ) > 0 ) {
176
+ this . dialog2BPELSupport . openErrorDialog ( resultObject . res [ 0 ] . contentBPEL ) ;
177
+ } else {
178
+ var bpelArray = new Array ( ) ;
179
+ var wsdlArray = new Array ( ) ;
180
+ for ( var i = 0 ; i < resultObject . res . length ; i ++ ) {
181
+ bpelArray [ i ] = resultObject . res [ i ] . contentBPEL ;
182
+ wsdlArray [ i ] = resultObject . res [ i ] . contentWSDL ;
183
+ }
184
+ var data = this . buildTransData ( bpelArray , wsdlArray ) ;
185
+
186
+ alert ( data ) ;
187
+
188
+ this . dialog2BPELSupport . openResultDialog ( data ) ;
189
+ }
190
+ }
191
+ } ) ;
192
+
0 commit comments