private static <T> T doProcessSchema( XmlElementDescriptor[] descriptors, String prefix, SchemaProcessor<T> processor, Set<XmlElementDescriptor> recursionGuard) { for (XmlElementDescriptor each : descriptors) { if (isCollection(each)) continue; if (!recursionGuard.add(each)) continue; try { String name = each.getName(); if (prefix != null) name = prefix + "." + name; T result = processor.process(name, each); if (result != null) return result; result = doProcessSchema(each.getElementsDescriptors(null), name, processor, recursionGuard); if (result != null) return result; } finally { recursionGuard.remove(each); } } return null; }
private String saveSchema(String schemaUrl, String version) throws RegistryException { if (schemaUrl != null) { RequestContext requestContext = new RequestContext(registry, repository, versionRepository); Resource local = requestContext.getRegistry().newResource(); local.setMediaType(xsdMediaType); local.setProperty(CommonConstants.SOURCE_PROPERTY, CommonConstants.SOURCE_AUTO); requestContext.setSourceURL(schemaUrl); requestContext.setResource(local); String xsdName = schemaUrl; if (xsdName.lastIndexOf("/") != -1) { xsdName = xsdName.substring(xsdName.lastIndexOf("/")); } else { xsdName = "/" + xsdName; } String path = RegistryConstants.GOVERNANCE_REGISTRY_BASE_PATH + xsdName; requestContext.setResourcePath(new ResourcePath(path)); WSDLValidationInfo validationInfo; try { validationInfo = SchemaValidator.validate(new XMLInputSource(null, schemaUrl, null)); } catch (Exception e) { throw new RegistryException("Exception occured while validating the schema", e); } SchemaProcessor schemaProcessor = new SchemaProcessor(requestContext, validationInfo); try { return schemaProcessor.importSchemaToRegistry( requestContext, path, getChrootedSchemaLocation(requestContext.getRegistryContext()), true, true); } catch (RegistryException e) { throw new RegistryException("Failed to import the schema", e); } } return null; }