チェンジセット 284
- コミット日時:
- 2008/04/18 12:14:32 (14 年前)
- ファイル:
凡例:
- 変更無し
- 追加
- 削除
- 更新
- コピー
- 移動
trunk/im-jssp/src/main/java/org/intra_mart/jssp/script/api/SOAPClientObject.java
r283 r284 64 64 import org.mozilla.javascript.JavaScriptException; 65 65 import org.mozilla.javascript.ScriptableObject; 66 import org.mozilla.javascript.WrappedException;67 66 import org.w3c.dom.Document; 68 67 import org.w3c.dom.Element; … … 128 127 } 129 128 129 /** 130 * @param object 131 * @return 132 */ 130 133 private static String getURI4WSDL(Object object) { 131 134 String wsdlUri = null; … … 149 152 } 150 153 154 /** 155 * @param wsdlUri 156 * @param targetEndpoint 157 * @param portName 158 * @param serviceName 159 */ 151 160 public SOAPClientObject(String wsdlUri, 152 161 String targetEndpoint, … … 158 167 if(StubGenerationMode.Never.equals(_stubGenMode) == false){ 159 168 169 // 「JSの実行スレッドに紐づくクラスローダ」と「jsToJavaBean()実行時のクラスローダ」を同じにする 160 170 ClassLoader oldExtendedClassLoader = _soapClientClassLoaderThreadLocal.get(); 161 171 if(oldExtendedClassLoader != null){ … … 172 182 173 183 try { 174 // エンジン生成175 CodeGen erationEngine engine = createEngine(wsdlUri, _soapClientWorkDir, portName, serviceName);184 // コンフィグ生成 185 CodeGenConfiguration config = getCodeGenConfiguration(wsdlUri, _soapClientWorkDir, portName, serviceName); 176 186 177 187 // Stubクラス名取得 178 String stubClassName = getStubClassName( engine);188 String stubClassName = getStubClassName(config); 179 189 180 190 if( StubGenerationMode.Everytime.equals(_stubGenMode) … … 183 193 ){ 184 194 // Stubソース生成 185 generateStub( engine, stubClassName);195 generateStub(wsdlUri, _soapClientWorkDir, portName, serviceName, stubClassName); 186 196 187 197 // Stubクラスコンパイル … … 204 214 } 205 215 catch (Exception e) { 206 throw new WrappedException(e);216 throw Context.throwAsScriptRuntimeEx(e); 207 217 } 208 218 finally{ … … 250 260 ClassLoader cl = (classLoader != null) ? classLoader : getCurrentThreadClassLoader4SOAPClient(); 251 261 252 Class stubClass = cl.loadClass(stubClassName);262 Class<?> stubClass = cl.loadClass(stubClassName); 253 263 if(endpoint == null){ 254 264 return stubClass.newInstance(); 255 265 } 256 266 else{ 257 Constructor stubConstructor = stubClass.getConstructor(String.class);267 Constructor<?> stubConstructor = stubClass.getConstructor(String.class); 258 268 return stubConstructor.newInstance(endpoint); 259 269 } … … 270 280 } 271 281 else { 272 String workDir = get TagsTextContentFormNodeList(tagName);282 String workDir = getConfigValue(tagName); 273 283 if(workDir != null){ 274 284 File dir = new File(workDir); … … 297 307 } 298 308 else{ 299 String configValue = get TagsTextContentFormNodeList(tagName);309 String configValue = getConfigValue(tagName); 300 310 301 311 if(configValue != null){ … … 328 338 } 329 339 else{ 330 String configValue = get TagsTextContentFormNodeList(tagName);340 String configValue = getConfigValue(tagName); 331 341 332 342 if(configValue != null){ … … 348 358 } 349 359 else{ 350 String configValue = get TagsTextContentFormNodeList(tagName);360 String configValue = getConfigValue(tagName); 351 361 352 362 if(configValue != null){ … … 359 369 } 360 370 361 private static String getTagsTextContentFormNodeList(String tagName) { 362 JSSPConfigHandler config = JSSPConfigHandlerManager.getConfigHandler(); 363 NodeList list = config.getJavaScriptAPI4ClassConfig(SOAPClientObject.class.getName()); 364 365 for(int idx = 0; idx < list.getLength(); idx++){ 366 Element elem = (Element) list.item(idx); 367 if(tagName.equals(elem.getTagName())){ 368 return elem.getTextContent(); 369 } 370 } 371 372 return null; 373 } 374 375 private static Map<String, CodeGenerationEngine> cache4codeGenEngine = new WeakHashMap<String, CodeGenerationEngine>(); 376 377 private CodeGenerationEngine createEngine(String wsdlLocationURI, 378 File outputLocation, 379 String portName, 380 String serviceName ) throws CodeGenerationException { 371 /** 372 * @param wsdlLocationURI 373 * @param outputLocation 374 * @param portName 375 * @param serviceName 376 * @return 377 */ 378 private CodeGenConfiguration getCodeGenConfiguration(String wsdlLocationURI, 379 File outputLocation, 380 String portName, 381 String serviceName) { 382 383 384 CodeGenConfiguration codeGenConfiguration; 385 try { 386 // エンジン生成 387 CodeGenerationEngine engine = getCachedCodeGenEngine(wsdlLocationURI, _soapClientWorkDir, portName, serviceName); 388 389 // PLAN JavassistでCodeGenerationEngine#getConfiguration()メソッドが生成されなかった場合の処理の追加。 390 codeGenConfiguration = (CodeGenConfiguration) _method4getConfiguration.invoke(engine); 391 } 392 catch (Exception e) { 393 throw Context.throwAsScriptRuntimeEx(e); 394 } 395 396 return codeGenConfiguration; 397 } 398 399 /** 400 * CodeGenerationEngineの取得。(キャッシュあり) 401 * 402 * @param wsdlLocationURI 403 * @param outputLocation 404 * @param portName 405 * @param serviceName 406 * @return 407 * @throws CodeGenerationException 408 */ 409 private CodeGenerationEngine getCachedCodeGenEngine(String wsdlLocationURI, 410 File outputLocation, 411 String portName, 412 String serviceName ) throws CodeGenerationException { 381 413 382 414 CodeGenerationEngine engine = cache4codeGenEngine.get(wsdlLocationURI); … … 385 417 synchronized(cache4codeGenEngine){ 386 418 // 引数を作成 387 String[] args = generateArgs(wsdlLocationURI, outputLocation, portName, serviceName); 419 List<String> argsList = new ArrayList<String>(); 420 argsList.add("-" + CommandLineOptionConstants.WSDL2JavaConstants.OUTPUT_LOCATION_OPTION_LONG); 421 argsList.add(outputLocation.getAbsolutePath()); 422 argsList.add("-" + CommandLineOptionConstants.WSDL2JavaConstants.WSDL_LOCATION_URI_OPTION); 423 argsList.add(wsdlLocationURI); 424 argsList.add("-" + CommandLineOptionConstants.WSDL2JavaConstants.SOURCE_FOLDER_NAME_OPTION_LONG); 425 argsList.add(""); // ←「src」ディレクトリを作らない 426 argsList.add("-" + CommandLineOptionConstants.WSDL2JavaConstants.NO_BUILD_XML_OPTION_LONG); 427 argsList.add("-" + CommandLineOptionConstants.WSDL2JavaConstants.OVERRIDE_OPTION_LONG); 388 428 389 429 if(portName != null){ 430 argsList.add("-" + CommandLineOptionConstants.WSDL2JavaConstants.PORT_NAME_OPTION_LONG); 431 argsList.add(portName); 432 } 433 434 if(serviceName != null){ 435 argsList.add("-" + CommandLineOptionConstants.WSDL2JavaConstants.SERVICE_NAME_OPTION_LONG); 436 argsList.add(serviceName); 437 } 438 439 String[] args = argsList.toArray(new String[argsList.size()]); 440 _logger.trace("argsList: {}", argsList); 441 390 442 // CodeGenerationEngineを生成 () 391 443 CommandLineOptionParser commandLineOptionParser = new CommandLineOptionParser(args); … … 399 451 return engine; 400 452 } 401 402 private boolean isExistStubClass(String stubFQCN) { 403 // スタブクラスの存在チェック 404 boolean isExistStubClass = false; 405 try { 406 Class<?> clazz = getCurrentThreadClassLoader4SOAPClient().loadClass(stubFQCN); 407 if(clazz != null){ 408 isExistStubClass = true; 409 } 410 } 411 catch (ClassNotFoundException e) { /* Do Nothing */ } 412 return isExistStubClass; 413 } 414 415 private boolean isExistStubJS(String stubClassName, File srcDir) { 416 417 ScriptScope scope; 418 try { 419 scope = getScriptScope(stubClassName, srcDir); 420 if(scope != null){ 421 return true; 422 } 423 else{ 424 return false; 425 } 426 } 427 catch (Exception e) { 428 _logger.trace(e.getMessage(), e); 429 return false; 430 } 431 } 432 433 private ScriptScope getScriptScope(String stubClassName, File srcDir) 434 throws FileNotFoundException, 435 InstantiationException, 436 IllegalAccessException, 437 IOException, 438 ClassNotFoundException { 439 440 ScriptScopeBuilder builder = ScriptScopeBuilderManager.getBuilder(); 441 String source = stubClassName.replace(".", File.separator); 442 ScriptScope scope = builder.getScriptScope(source, srcDir); 443 return scope; 444 } 453 private static Map<String, CodeGenerationEngine> cache4codeGenEngine = new WeakHashMap<String, CodeGenerationEngine>(); 445 454 446 455 447 private String getStubClassName(CodeGenerationEngine engine) { 448 449 CodeGenConfiguration codeGenConfiguration; 450 try { 451 // PLAN JavassistでCodeGenerationEngine#getConfiguration()メソッドが生成されなかった場合の処理の追加。 452 codeGenConfiguration = (CodeGenConfiguration) _method4getConfiguration.invoke(engine); 453 } 454 catch (Exception e) { 455 throw Context.throwAsScriptRuntimeEx(e); 456 } 457 456 private String getStubClassName(CodeGenConfiguration codeGenConfiguration) { 457 458 458 // スタブのクラス名を取得 459 459 // AxisServiceが複数存在しても、特定の一つのWebサービスに対するスタブを対象とする。 … … 471 471 } 472 472 473 private String[] generateArgs(String wsdlLocationURI, File outputLocation, 474 String portName, String serviceName) { 475 476 List<String> argsList = new ArrayList<String>(); 477 478 argsList.add("-" + CommandLineOptionConstants.WSDL2JavaConstants.OUTPUT_LOCATION_OPTION_LONG); 479 argsList.add(outputLocation.getAbsolutePath()); 480 argsList.add("-" + CommandLineOptionConstants.WSDL2JavaConstants.WSDL_LOCATION_URI_OPTION); 481 argsList.add(wsdlLocationURI); 482 argsList.add("-" + CommandLineOptionConstants.WSDL2JavaConstants.SOURCE_FOLDER_NAME_OPTION_LONG); 483 argsList.add(""); // ←「src」ディレクトリを作らない 484 argsList.add("-" + CommandLineOptionConstants.WSDL2JavaConstants.NO_BUILD_XML_OPTION_LONG); 485 argsList.add("-" + CommandLineOptionConstants.WSDL2JavaConstants.OVERRIDE_OPTION_LONG); 486 487 if(portName != null){ 488 argsList.add("-" + CommandLineOptionConstants.WSDL2JavaConstants.PORT_NAME_OPTION_LONG); 489 argsList.add(portName); 490 } 491 492 if(serviceName != null){ 493 argsList.add("-" + CommandLineOptionConstants.WSDL2JavaConstants.SERVICE_NAME_OPTION_LONG); 494 argsList.add(serviceName); 495 } 496 497 _logger.trace("argsList: {}", argsList); 498 499 String[] args = argsList.toArray(new String[argsList.size()]); 500 return args; 501 } 502 503 protected synchronized void generateStub(CodeGenerationEngine engine, String stubClassName) throws CodeGenerationException { 473 474 private static String getConfigValue(String tagName) { 475 JSSPConfigHandler config = JSSPConfigHandlerManager.getConfigHandler(); 476 NodeList list = config.getJavaScriptAPI4ClassConfig(SOAPClientObject.class.getName()); 477 478 for(int idx = 0; idx < list.getLength(); idx++){ 479 Element elem = (Element) list.item(idx); 480 if(tagName.equals(elem.getTagName())){ 481 return elem.getTextContent(); 482 } 483 } 484 485 return null; 486 } 487 488 private boolean isExistStubClass(String stubFQCN) { 489 // スタブクラスの存在チェック 490 boolean isExistStubClass = false; 491 try { 492 Class<?> clazz = getCurrentThreadClassLoader4SOAPClient().loadClass(stubFQCN); 493 if(clazz != null){ 494 isExistStubClass = true; 495 } 496 } 497 catch (ClassNotFoundException e) { /* Do Nothing */ } 498 return isExistStubClass; 499 } 500 501 private boolean isExistStubJS(String stubClassName, File srcDir) { 502 503 ScriptScope scope; 504 try { 505 scope = getScriptScope(stubClassName, srcDir); 506 if(scope != null){ 507 return true; 508 } 509 else{ 510 return false; 511 } 512 } 513 catch (Exception e) { 514 _logger.trace(e.getMessage(), e); 515 return false; 516 } 517 } 518 519 private ScriptScope getScriptScope(String stubClassName, File srcDir) 520 throws FileNotFoundException, 521 InstantiationException, 522 IllegalAccessException, 523 IOException, 524 ClassNotFoundException { 525 526 ScriptScopeBuilder builder = ScriptScopeBuilderManager.getBuilder(); 527 String source = stubClassName.replace(".", File.separator); 528 ScriptScope scope = builder.getScriptScope(source, srcDir); 529 return scope; 530 } 531 532 /** 533 * Javaスタブのソースコード生成 534 * 535 * @param wsdlUri 536 * @param stubClassName 537 * @throws CodeGenerationException 538 */ 539 protected synchronized void generateStub(String wsdlLocationURI, 540 File outputLocation, 541 String portName, 542 String serviceName, 543 String stubClassName) throws CodeGenerationException { 504 544 _logger.info("Generate Stub(Java): {}", stubClassName); 545 546 // エンジン生成 547 CodeGenerationEngine engine = getCachedCodeGenEngine(wsdlLocationURI, _soapClientWorkDir, portName, serviceName); 505 548 engine.generate(); 506 549 } 507 550 551 /** 552 * Javaスタブをコンパイル 553 * 554 * @param className 555 * @param srcDir 556 * @param destDir 557 * @return 558 * @throws IOException 559 */ 508 560 protected synchronized int compileStub(String className, File srcDir, File destDir) throws IOException{ 509 561 … … 604 656 private static final String code4ClassLoader = name4SOAPClientObject + ".getCurrentThreadClassLoader4SOAPClient();"; 605 657 658 /** 659 * JSスタブのソースコード生成 660 * 661 * @param wsdlUri 662 * @param stubClassName 663 * @param destDir 664 * @throws IOException 665 * @throws IntrospectionException 666 * @throws ClassNotFoundException 667 * @throws NoSuchFieldException 668 * @throws IllegalArgumentException 669 * @throws IllegalAccessException 670 * @throws XPathExpressionException 671 * @throws ParserConfigurationException 672 * @throws SAXException 673 */ 606 674 protected synchronized void generateStubJS(String wsdlUri, String stubClassName, File destDir) 607 675 throws IOException, IntrospectionException, ClassNotFoundException, … … 965 1033 } 966 1034 1035 /** 1036 * JSスタブのinit()関数実行 1037 * 1038 * @param stubClassName 1039 * @param srcDir 1040 * @param targetEndpoint 1041 * @throws JavaScriptException 1042 * @throws FileNotFoundException 1043 * @throws InstantiationException 1044 * @throws IllegalAccessException 1045 * @throws IOException 1046 * @throws ClassNotFoundException 1047 */ 967 1048 protected void executeStubJS(String stubClassName, File srcDir, String targetEndpoint) throws JavaScriptException, FileNotFoundException, InstantiationException, IllegalAccessException, IOException, ClassNotFoundException { 968 1049 ScriptScope scope = getScriptScope(stubClassName, srcDir); … … 973 1054 } 974 1055 1056 /** 1057 * Axis2のクラスパス解決 1058 * @return 1059 */ 975 1060 protected String getAxis2ClassPath() { 976 1061 if(classPath4Axis2 == null){ … … 1060 1145 } 1061 1146 1147 /** 1148 * 1149 */ 1062 1150 private static void createCodeGenConfigurationGetterByJavassist(){ 1063 1151 try { … … 1086 1174 } 1087 1175 1176 /** 1177 * @return 1178 */ 1088 1179 private static boolean isWindows(){ 1089 1180 String os = System.getProperty("os.name"); … … 1097 1188 } 1098 1189 1190 /** 1191 * @param wsdlUrl 1192 * @param operationParamType 1193 * @return 1194 * @throws ParserConfigurationException 1195 * @throws IOException 1196 * @throws XPathExpressionException 1197 * @throws SAXException 1198 */ 1099 1199 private static List<String> getPropertyNameListFromWSDL(String wsdlUrl, Class<?> operationParamType) 1100 1200 throws ParserConfigurationException, IOException, XPathExpressionException, SAXException{