private static void registerNamespace(SchemaCompiler sc, String namespace, String pkgName) throws Exception { Document doc = XMLUtils.newDocument(); Element rootElement = doc.createElement("schema"); rootElement.setAttribute("xmlns", "http://www.w3.org/2001/XMLSchema"); rootElement.setAttribute("xmlns:jaxb", "http://java.sun.com/xml/ns/jaxb"); rootElement.setAttribute("jaxb:version", "2.0"); rootElement.setAttribute("targetNamespace", namespace); Element annoElement = doc.createElement("annotation"); Element appInfo = doc.createElement("appinfo"); Element schemaBindings = doc.createElement("jaxb:schemaBindings"); Element pkgElement = doc.createElement("jaxb:package"); pkgElement.setAttribute("name", pkgName); annoElement.appendChild(appInfo); appInfo.appendChild(schemaBindings); schemaBindings.appendChild(pkgElement); rootElement.appendChild(annoElement); File file = File.createTempFile("customized", ".xsd"); FileOutputStream stream = new FileOutputStream(file); try { Result result = new StreamResult(stream); Transformer xformer = TransformerFactory.newInstance().newTransformer(); xformer.transform(new DOMSource(rootElement), result); stream.flush(); stream.close(); } catch (Exception e) { log.error(e); } InputSource ins = new InputSource(file.toURI().toString()); sc.parseSchema(ins); // file.delete(); deleteFile(file); }
/** * @param omElement * @return * @throws XMLParserException */ public static Element convertOMToDOM(OMElement omElement) throws XMLParserException { try { return XMLUtils.toDOM(omElement); } catch (Exception ex) { throw new XMLParserException("Unable to convert OMElement to Element: " + ex.getMessage()); } }
private void populateGetRequestProcessors() throws AxisFault { try { OMElement docEle = XMLUtils.toOM(ServerConfiguration.getInstance().getDocumentElement()); if (docEle != null) { SimpleNamespaceContext nsCtx = new SimpleNamespaceContext(); nsCtx.addNamespace("wsas", ServerConstants.CARBON_SERVER_XML_NAMESPACE); XPath xp = new AXIOMXPath("//wsas:HttpGetRequestProcessors/wsas:Processor"); xp.setNamespaceContext(nsCtx); List nodeList = xp.selectNodes(docEle); for (Object aNodeList : nodeList) { OMElement processorEle = (OMElement) aNodeList; OMElement itemEle = processorEle.getFirstChildWithName(ITEM_QN); if (itemEle == null) { throw new ServletException("Required element, 'Item' not found!"); } OMElement classEle = processorEle.getFirstChildWithName(CLASS_QN); org.wso2.carbon.core.transports.HttpGetRequestProcessor processor; if (classEle == null) { throw new ServletException("Required element, 'Class' not found!"); } else { processor = (org.wso2.carbon.core.transports.HttpGetRequestProcessor) Class.forName(classEle.getText().trim()).newInstance(); } getRequestProcessors.put(itemEle.getText().trim(), processor); } } } catch (Exception e) { handleException("Error populating GetRequestProcessors", e); } }
/** * @param element * @return * @throws XMLParserException */ public static OMElement convertDOMtoOM(Element element) throws XMLParserException { try { return XMLUtils.toOM(element); } catch (Exception ex) { throw new XMLParserException( "Unable to convert from Element to OMElement: " + ex.getMessage()); } }