| 26 | |
---|
| 27 | import javax.xml.namespace.QName; |
---|
| 28 | import javax.xml.parsers.DocumentBuilder; |
---|
| 29 | import javax.xml.parsers.DocumentBuilderFactory; |
---|
| 30 | import javax.xml.parsers.ParserConfigurationException; |
---|
| 31 | import javax.xml.xpath.XPath; |
---|
| 32 | import javax.xml.xpath.XPathConstants; |
---|
| 33 | import javax.xml.xpath.XPathExpression; |
---|
| 34 | import javax.xml.xpath.XPathExpressionException; |
---|
| 35 | import javax.xml.xpath.XPathFactory; |
---|
434 | | protected synchronized void generateStubJS(String stubClassName, File destDir) throws IOException, IntrospectionException, ClassNotFoundException { |
---|
| 448 | protected synchronized void generateStubJS(String wsdlUri, String stubClassName, File destDir) |
---|
| 449 | throws IOException, IntrospectionException, ClassNotFoundException, |
---|
| 450 | NoSuchFieldException, IllegalArgumentException, |
---|
| 451 | IllegalAccessException, XPathExpressionException, |
---|
| 452 | ParserConfigurationException, SAXException { |
---|
484 | | Iterator<Map.Entry<String, PropertyDescriptor>> it = beanPropMap.entrySet().iterator(); |
---|
485 | | |
---|
486 | | // PLAN SOAPClient#オペレーション()に指定した引数の順序(=arguments オブジェクト)と、Webサービスのパラメータクラスのプロパティ取得順が異なる場合は修正が必要。 |
---|
487 | | // Axis2のCodeGenerationEngineで作成されるJavaStubクラス内のパラメータクラスは、 |
---|
488 | | // WSDLの 「definitions/types/schema/element[@name=\"エレメント名\"]/*/sequence/*」 と |
---|
489 | | // 同じ順番でプロパティが生成されているので、現状はOK。 |
---|
490 | | while(it.hasNext()){ |
---|
491 | | Map.Entry<String, PropertyDescriptor> entry = it.next(); |
---|
| 510 | |
---|
| 511 | while(propNameIt.hasNext()){ |
---|
| 512 | String propName = propNameIt.next(); |
---|
| 513 | PropertyDescriptor propDescriptor = beanPropMap.get(propName); |
---|
| 717 | |
---|
| 718 | private static List<String> getPropertyNameListFromWSDL(String wsdlUrl, QName myQName) |
---|
| 719 | throws ParserConfigurationException, IOException, XPathExpressionException, SAXException{ |
---|
| 720 | |
---|
| 721 | List<String> list = new ArrayList<String>(); |
---|
| 722 | |
---|
| 723 | StringBuilder exp = new StringBuilder(); |
---|
| 724 | exp.append("//definitions/types/schema[@targetNamespace=\"" + myQName.getNamespaceURI() + "\"]"); |
---|
| 725 | exp.append("/element[@name=\"" + myQName.getLocalPart() + "\"]/*/sequence/*"); |
---|
| 726 | |
---|
| 727 | URL url = new URL(wsdlUrl); |
---|
| 728 | InputStream is = url.openStream(); |
---|
| 729 | |
---|
| 730 | try{ |
---|
| 731 | DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); |
---|
| 732 | Document doc = builder.parse(is); |
---|
| 733 | |
---|
| 734 | // XPathで取得 |
---|
| 735 | XPathFactory factory = XPathFactory.newInstance(); |
---|
| 736 | XPath xpath = factory.newXPath(); |
---|
| 737 | XPathExpression expr = xpath.compile(exp.toString()); |
---|
| 738 | Object result = expr.evaluate(doc, XPathConstants.NODESET); |
---|
| 739 | |
---|
| 740 | NodeList nodeList = (NodeList) result; |
---|
| 741 | for (int i = 0; i < nodeList.getLength(); i++) { |
---|
| 742 | Element elem = (Element)nodeList.item(i); |
---|
| 743 | NamedNodeMap namedNodeMap = elem.getAttributes(); |
---|
| 744 | |
---|
| 745 | _logger.trace("{}", namedNodeMap.getNamedItem("name")); |
---|
| 746 | _logger.trace("{}", namedNodeMap.getNamedItem("type")); |
---|
| 747 | _logger.trace("{}", namedNodeMap.getNamedItem("minOccurs")); |
---|
| 748 | _logger.trace("{}", namedNodeMap.getNamedItem("nillable")); |
---|
| 749 | _logger.trace("{}", elem.getNodeName()); |
---|
| 750 | |
---|
| 751 | list.add(namedNodeMap.getNamedItem("name").getNodeValue()); |
---|
| 752 | } |
---|
| 753 | |
---|
| 754 | if(list.size() == 0){ |
---|
| 755 | throw new IllegalStateException("Not found '" + myQName + "' element in WSDL(='" + wsdlUrl + "')."); |
---|
| 756 | } |
---|
| 757 | |
---|
| 758 | return list; |
---|
| 759 | } |
---|
| 760 | finally{ |
---|
| 761 | if(is != null){ |
---|
| 762 | is.close(); |
---|
| 763 | } |
---|
| 764 | } |
---|
| 765 | } |
---|