private OMElement resolveImports( OMElement grammarsElement, String wadlBaseUri, String wadlVersion) throws RegistryException { String wadlNamespace = grammarsElement.getNamespace().getNamespaceURI(); Iterator<OMElement> grammarElements = grammarsElement.getChildrenWithName(new QName(wadlNamespace, "include")); while (grammarElements.hasNext()) { OMElement childElement = grammarElements.next(); OMAttribute refAttr = childElement.getAttribute(new QName("href")); String importUrl = refAttr.getAttributeValue(); if (importUrl.endsWith(".xsd")) { if (!importUrl.startsWith("http")) { if (registry.resourceExists(importUrl)) { continue; } else { if (wadlBaseUri != null) { importUrl = wadlBaseUri + importUrl; } } } String schemaPath = saveSchema(importUrl, wadlVersion); importedSchemas.add(schemaPath); refAttr.setAttributeValue(schemaPath); childElement.addAttribute(refAttr); } } return grammarsElement; }
/** * Sets content of the given WSDL artifact to the given resource on the registry. * * @param wsdl the WSDL artifact. * @param wsdlResource the content resource. * @throws GovernanceException if the operation failed. */ protected void setContent(Wsdl wsdl, Resource wsdlResource) throws GovernanceException { if (wsdl.getWsdlElement() != null) { OMElement contentElement = wsdl.getWsdlElement().cloneOMElement(); try { for (String importType : new String[] {"import", "include"}) { List<OMElement> wsdlImports = GovernanceUtils.evaluateXPathToElements("//wsdl:" + importType, contentElement); for (OMElement wsdlImport : wsdlImports) { OMAttribute location = wsdlImport.getAttribute(new QName("location")); if (location != null) { String path = location.getAttributeValue(); if (path.indexOf(";version:") > 0) { location.setAttributeValue(path.substring(0, path.lastIndexOf(";version:"))); } } } } for (String importType : new String[] {"import", "include", "redefine"}) { List<OMElement> schemaImports = GovernanceUtils.evaluateXPathToElements("//xsd:" + importType, contentElement); for (OMElement schemaImport : schemaImports) { OMAttribute location = schemaImport.getAttribute(new QName("schemaLocation")); if (location != null) { String path = location.getAttributeValue(); if (path.indexOf(";version:") > 0) { location.setAttributeValue(path.substring(0, path.lastIndexOf(";version:"))); } } } } } catch (JaxenException ignore) { } String wsdlContent = contentElement.toString(); try { wsdlResource.setContent(wsdlContent); } catch (RegistryException e) { String msg = "Error in setting the content from wsdl, wsdl id: " + wsdl.getId() + ", wsdl path: " + wsdl.getPath() + "."; log.error(msg, e); throw new GovernanceException(msg, e); } } // and set all the attributes as properties. String[] attributeKeys = wsdl.getAttributeKeys(); if (attributeKeys != null) { Properties properties = new Properties(); for (String attributeKey : attributeKeys) { String[] attributeValues = wsdl.getAttributes(attributeKey); if (attributeValues != null) { // The list obtained from the Arrays#asList method is // immutable. Therefore, // we create a mutable object out of it before adding it as // a property. properties.put(attributeKey, new ArrayList<String>(Arrays.asList(attributeValues))); } } wsdlResource.setProperties(properties); } wsdlResource.setUUID(wsdl.getId()); }