チェンジセット 208
- コミット日時:
- 2008/04/10 17:23:04 (14 年前)
- ファイル:
凡例:
- 変更無し
- 追加
- 削除
- 更新
- コピー
- 移動
trunk/im-jssp-extention/src/main/java/org/intra_mart/jssp/script/api/SOAPClientObject.java
r207 r208 37 37 import javax.xml.xpath.XPathFactory; 38 38 39 import org.apache.axis2.AxisFault; 39 40 import org.apache.axis2.description.AxisService; 40 41 import org.apache.axis2.util.CommandLineOptionConstants; … … 73 74 74 75 private static StubGenerationMode _stubGenMode = StubGenerationMode.Once; 75 private static File _soapClientWorkDir; 76 private static File _soapClientWorkDir = ScriptScopeBuilderManager.getBuilder().getOutputDirectory(); 77 private static String _jsPath4SOAPClientHelper = "jssp/script/api/soap_client_helper"; 76 78 77 79 private static Method _method4getConfiguration; … … 80 82 static { 81 83 createCodeGenConfigurationGetterByJavassist(); 82 initializeSOAPClientWorkDir(); 83 initializeStubGenerationMode(); 84 85 initializeSOAPClientWorkDir(null); 86 initializeStubGenerationMode(null); 87 initializeJsPath4SOAPClientHelper(null); 84 88 } 85 89 … … 88 92 return "SOAPClient"; 89 93 } 94 90 95 91 96 public static Object jsConstructor(Context cx, Object[] args, Function ctorObj, boolean inNewExpr) { … … 189 194 } 190 195 191 // JS Sutbの実行196 // JS Stubの実行 192 197 executeStubJS(stubClassName, _soapClientWorkDir, targetEndpoint); 193 198 } … … 217 222 218 223 /** 219 * 224 * @param arg 220 225 */ 221 protected static void initializeSOAPClientWorkDir( ) {226 protected static void initializeSOAPClientWorkDir(File arg) { 222 227 String tagName = "work-dir"; 223 String workDir = getTagsTextContentFormNodeList(tagName); 224 if(workDir != null){ 225 File dir = new File(workDir); 226 227 if(dir.isAbsolute() == true){ 228 _soapClientWorkDir = dir; 229 } 230 else{ 231 _soapClientWorkDir = new File(HomeDirectory.instance(), dir.getPath()); 232 } 233 } 234 else{ 235 _soapClientWorkDir = ScriptScopeBuilderManager.getBuilder().getOutputDirectory(); 228 229 if(arg != null){ 230 _soapClientWorkDir = arg; 231 } 232 else { 233 String workDir = getTagsTextContentFormNodeList(tagName); 234 if(workDir != null){ 235 File dir = new File(workDir); 236 237 if(dir.isAbsolute() == true){ 238 _soapClientWorkDir = dir; 239 } 240 else{ 241 _soapClientWorkDir = new File(HomeDirectory.instance(), dir.getPath()); 242 } 243 } 236 244 } 237 245 … … 241 249 242 250 /** 243 * 251 * @param arg 244 252 */ 245 protected static void initializeStubGenerationMode( ) {253 protected static void initializeStubGenerationMode(StubGenerationMode arg) { 246 254 String tagName = "mode"; 247 String specifiedMode = getTagsTextContentFormNodeList("mode"); 248 249 if(specifiedMode != null){ 250 specifiedMode = specifiedMode.toUpperCase(); // 大文字・小文字を区別しない 251 252 StubGenerationMode[] modes = StubGenerationMode.values(); 253 for(StubGenerationMode mode : modes){ 254 String modeString = mode.toString().toUpperCase(); // 大文字・小文字を区別しない 255 if(specifiedMode.equals(modeString)){ 256 _stubGenMode = mode; 257 _logger.debug("{} -> {}", tagName, _stubGenMode); 258 return; 259 } 260 } 261 } 255 256 if(arg != null){ 257 _stubGenMode = arg; 258 } 259 else{ 260 String configValue = getTagsTextContentFormNodeList(tagName); 261 262 if(configValue != null){ 263 configValue = configValue.toUpperCase(); // 大文字・小文字を区別しない 264 265 StubGenerationMode[] modes = StubGenerationMode.values(); 266 for(StubGenerationMode mode : modes){ 267 String modeString = mode.toString().toUpperCase(); // 大文字・小文字を区別しない 268 if(configValue.equals(modeString)){ 269 _stubGenMode = mode; 270 break; 271 } 272 } 273 } 274 } 275 276 _logger.debug("{} -> {}", tagName, _stubGenMode); 277 } 278 279 /** 280 * @param arg 281 */ 282 protected static void initializeJsPath4SOAPClientHelper(String arg) { 283 String tagName = "helper"; 284 285 if(arg != null){ 286 _jsPath4SOAPClientHelper = arg; 287 } 288 else{ 289 String configValue = getTagsTextContentFormNodeList(tagName); 290 291 if(configValue != null){ 292 _jsPath4SOAPClientHelper = configValue; 293 } 294 } 295 296 _logger.debug("{} -> {}", tagName, _jsPath4SOAPClientHelper); 262 297 } 263 298 … … 545 580 generateFunc4printUsage(strBuilder4source, strBuilder4usage); 546 581 547 // JavaオブジェクトをJSオブジェクトに正規化する関数 548 generateFunc4nomalize(strBuilder4source); 549 582 550 583 File jsFile = new File(destDir, stubClassName.replace(".", File.separator) + ".js"); 551 584 jsFile.delete(); … … 562 595 */ 563 596 private void generateFunc4Header(String wsdlUri, StringBuilder source, Class<?> stubClass) { 564 source.append("var wsdlUri = \"" + wsdlUri + "\";") .append(LINE_SEP);565 566 source.append(LINE_SEP);567 597 source.append("/** ") .append(LINE_SEP); 568 598 source.append(" * This is " + this.getClassName() + ": \"" + stubClass.getName() + "\"") .append(LINE_SEP); … … 570 600 source.append(" * This file was generated automatically on " + new Date()) .append(LINE_SEP); 571 601 source.append(" */") .append(LINE_SEP); 602 source.append(LINE_SEP); 603 source.append("var wsdlUri = \"" + wsdlUri + "\";") .append(LINE_SEP); 604 source.append("load('" + _jsPath4SOAPClientHelper + "');") .append(LINE_SEP); 572 605 } 573 606 … … 576 609 */ 577 610 private void generateFunc4init(String stubClassName, StringBuilder source) { 611 source.append(LINE_SEP); 578 612 source.append("function init( targetEndpoint ) {") .append(LINE_SEP); 579 613 source.append(" if( !isBlank(targetEndpoint) ) {") .append(LINE_SEP); … … 649 683 Class<?> returnType = operation.getReturnType(); 650 684 651 source.append(LINE_SEP);652 source.append("function " + operatinoName + "() {").append(LINE_SEP);685 source.append(LINE_SEP); 686 source.append("function " + operatinoName + "() {") .append(LINE_SEP); 653 687 654 688 // ---------------- … … 668 702 String paramTypeName = operationParamType.getName(); 669 703 670 source.append(" var operationParam = new Packages." + paramTypeName + "();").append(LINE_SEP);671 source.append(" var classLoader = " + code4ClassLoader).append(LINE_SEP);704 source.append(" var operationParam = new Packages." + paramTypeName + "();") .append(LINE_SEP); 705 source.append(" var classLoader = " + code4ClassLoader) .append(LINE_SEP); 672 706 673 707 // WSDLより、Webサービスのパラメータクラスのプロパティ順を取得。 … … 698 732 String setterParamTypeName = setterParamType.getName(); 699 733 700 source.append(LINE_SEP);701 source.append(" var jsArg_" + propName + " = ");702 source.append( "(arguments[" + idx + "] == undefined)");703 source.append( " ? null : arguments[" + idx + "];") .append(LINE_SEP);704 705 source.append(" var beanType_" + propName + " = '");706 source.append( setterParamTypeName + "';") .append(LINE_SEP);707 708 source.append(" var javaArg_" + propName + " = ");709 source.append( name4JavaScriptUtility + ".convertJsObject2JavaBeans");710 source.append( "(jsArg_" + propName + ", beanType_" + propName + ", classLoader);") .append(LINE_SEP);734 source.append(LINE_SEP); 735 source.append(" var jsArg_" + propName + " = "); 736 source.append( "(arguments[" + idx + "] == undefined)"); 737 source.append( " ? null : arguments[" + idx + "];") .append(LINE_SEP); 738 739 source.append(" var beanType_" + propName + " = '"); 740 source.append( setterParamTypeName + "';") .append(LINE_SEP); 741 742 source.append(" var javaArg_" + propName + " = "); 743 source.append( name4JavaScriptUtility + ".convertJsObject2JavaBeans"); 744 source.append( "(jsArg_" + propName + ", beanType_" + propName + ", classLoader);") .append(LINE_SEP); 711 745 712 746 if(setterParamTypeName.equals("boolean")){ 713 747 source.append(" operationParam." + setter.getName() + "("); 714 748 source.append( "( new Packages.java.lang.Boolean(javaArg_" + propName + ") ).booleanValue()"); 715 source.append( ");") .append(LINE_SEP);749 source.append( ");") .append(LINE_SEP); 716 750 } 717 751 // TODO その他のPrimitive型対応 718 752 else{ 719 source.append(" operationParam." + setter.getName() + "(javaArg_" + propName + ");") .append(LINE_SEP);753 source.append(" operationParam." + setter.getName() + "(javaArg_" + propName + ");") .append(LINE_SEP); 720 754 } 721 755 … … 737 771 usage4Body.append(" var bean_" + propName + " = "); 738 772 usage4Body.append( name4JavaScriptUtility + ".newInstanceFilledProperty"); 739 usage4Body.append( "(beanType_" + propName + ", classLoader, \"" + propName + "\");").append(LINE_SEP); 773 usage4Body.append( "(beanType_" + propName + ","); 774 usage4Body.append( " classLoader,"); 775 usage4Body.append( " \"" + propName + "\");") .append(LINE_SEP); 740 776 741 777 usage4Body.append(" var js_" + propName + " = "); … … 746 782 usage4Body.append( "normalize(js_" + propName + ");") .append(LINE_SEP); 747 783 748 usage4Body.append(" str += \"var " + propName + " = \" + \"" + JS_LF + "\";") ;784 usage4Body.append(" str += \"var " + propName + " = \" + \"" + JS_LF + "\";") .append(LINE_SEP); 749 785 usage4Body.append(" str += ImJson.toJSONString(js_" + propName + ", " + debugFlg + ") + \";\" + "); 750 786 usage4Body.append( "\"" + JS_LF + "\";") .append(LINE_SEP); … … 768 804 usage.append(usage4Body); 769 805 770 source.append(LINE_SEP); 806 source.append(LINE_SEP); 807 source.append(" try {") .append(LINE_SEP); 808 771 809 if(returnType.equals(void.class)){ 772 810 if(operationParamTypes.length != 0){ 773 source.append(" this.stub." + operatinoName + "(operationParam);") .append(LINE_SEP);811 source.append(" this.stub." + operatinoName + "(operationParam);") .append(LINE_SEP); 774 812 } 775 813 else{ 776 source.append(" this.stub." + operatinoName + "();") .append(LINE_SEP); 777 } 778 source.append(" return;") .append(LINE_SEP); 779 source.append("}") .append(LINE_SEP); 814 source.append(" this.stub." + operatinoName + "();") .append(LINE_SEP); 815 } 816 source.append(" return;") .append(LINE_SEP); 780 817 } 781 818 else{ … … 794 831 795 832 if(operationParamTypes.length != 0){ 796 source.append(" var javaResult = this.stub." + operatinoName + "(operationParam);") .append(LINE_SEP);833 source.append(" var javaResult = this.stub." + operatinoName + "(operationParam);") .append(LINE_SEP); 797 834 } 798 835 else{ 799 source.append(" var javaResult = this.stub." + operatinoName + "();") .append(LINE_SEP); 800 } 801 source.append(" var jsResult = " + name4JavaScriptUtility + ".convertJavaBeans2JsObject"); 802 source.append( "(javaResult." + getterName + "());") .append(LINE_SEP); 803 804 source.append(" jsResult = normalize(jsResult);") .append(LINE_SEP); 805 source.append(" return jsResult;") .append(LINE_SEP); 806 source.append("}") .append(LINE_SEP); 807 } 836 source.append(" var javaResult = this.stub." + operatinoName + "();") .append(LINE_SEP); 837 } 838 source.append(" var jsResult = " + name4JavaScriptUtility + ".convertJavaBeans2JsObject"); 839 source.append( "(javaResult." + getterName + "());") .append(LINE_SEP); 840 841 source.append(" jsResult = normalize(jsResult);") .append(LINE_SEP); 842 source.append(" return jsResult;") .append(LINE_SEP); 843 } 844 845 source.append(" }") .append(LINE_SEP); 846 source.append(" catch(e){") .append(LINE_SEP); 847 source.append(" if(e.javaException == undefined ") .append(LINE_SEP); 848 source.append(" ||").append(LINE_SEP); 849 source.append(" e.javaException.getClass().getName() != '" + AxisFault.class.getName()+ "'){").append(LINE_SEP); 850 source.append(" throw e;") .append(LINE_SEP); 851 source.append(" }") .append(LINE_SEP); 852 source.append(" else{") .append(LINE_SEP); 853 source.append(" throw new SOAPFaultError(e);") .append(LINE_SEP); 854 source.append(" }") .append(LINE_SEP); 855 source.append(" }") .append(LINE_SEP); 856 source.append("}") .append(LINE_SEP); 808 857 } 809 858 } … … 825 874 source.append( usage); // Usageを追加 826 875 source.append(LINE_SEP); 827 source.append(" Debug.print(\"Operation '\" + operationName + \"()' is not defined.\");") 876 source.append(" Debug.print(\"Operation '\" + operationName + \"()' is not defined.\");").append(LINE_SEP); 828 877 source.append(" return;") .append(LINE_SEP); 829 878 source.append("}") .append(LINE_SEP); 830 879 } 831 832 /**833 * JavaオブジェクトをJSオブジェクトに正規化する関数834 */835 private void generateFunc4nomalize(StringBuilder source) {836 source.append(LINE_SEP);837 source.append("function normalize(value){") .append(LINE_SEP);838 source.append(" if(!isJavaInstance(value)){") .append(LINE_SEP);839 source.append(" return value;") .append(LINE_SEP);840 source.append(" }") .append(LINE_SEP);841 source.append(" else if(value instanceof Packages.java.lang.String){") .append(LINE_SEP);842 source.append(" return value + \"\";") .append(LINE_SEP);843 source.append(" }") .append(LINE_SEP);844 source.append(" else if(value instanceof Packages.java.lang.Number){") .append(LINE_SEP);845 source.append(" return value - 0;") .append(LINE_SEP);846 source.append(" }") .append(LINE_SEP);847 source.append(" else if(value instanceof Packages.java.lang.Boolean){") .append(LINE_SEP);848 source.append(" return value == true;") .append(LINE_SEP);849 source.append(" }") .append(LINE_SEP);850 source.append(" else{") .append(LINE_SEP);851 source.append(" return value;") .append(LINE_SEP);852 source.append(" }") .append(LINE_SEP);853 source.append("}") .append(LINE_SEP);854 }855 856 880 857 881 protected void executeStubJS(String stubClassName, File srcDir, String targetEndpoint) throws JavaScriptException, FileNotFoundException, InstantiationException, IllegalAccessException, IOException, ClassNotFoundException {