use of org.apache.ws.commons.schema.XmlSchema in project cxf by apache.
the class CorbaUtils method isElementFormQualified.
// Change this method to access the XmlSchemaCollection.
public static boolean isElementFormQualified(ServiceInfo serviceInfo, String uri) {
if (uri != null) {
SchemaInfo schemaInfo = serviceInfo.getSchema(uri);
if (schemaInfo != null) {
return schemaInfo.isElementFormQualified();
}
Iterator<SchemaInfo> it = serviceInfo.getSchemas().iterator();
while (it.hasNext()) {
XmlSchema schema = it.next().getSchema();
return isElementFormQualified(schema, uri);
}
}
return false;
}
use of org.apache.ws.commons.schema.XmlSchema in project cxf by apache.
the class ParticleInfo method factoryCommon.
private static void factoryCommon(XmlSchemaParticle particle, XmlSchema currentSchema, SchemaCollection schemaCollection, NamespacePrefixAccumulator prefixAccumulator, ParticleInfo elementInfo) {
if (particle instanceof XmlSchemaElement) {
XmlSchemaElement element = (XmlSchemaElement) particle;
QName elementQName = XmlSchemaUtils.getElementQualifiedName(element, currentSchema);
String elementNamespaceURI = elementQName.getNamespaceURI();
boolean elementNoNamespace = "".equals(elementNamespaceURI);
XmlSchema elementSchema = null;
if (!elementNoNamespace) {
elementSchema = schemaCollection.getSchemaByTargetNamespace(elementNamespaceURI);
if (elementSchema == null) {
throw new RuntimeException("Missing schema " + elementNamespaceURI);
}
}
boolean qualified = !elementNoNamespace && XmlSchemaUtils.isElementQualified(element, true, currentSchema, elementSchema);
elementInfo.xmlName = prefixAccumulator.xmlElementString(elementQName, qualified);
// we are assuming here that we are not dealing, in close proximity,
// with elements with identical local names and different
// namespaces.
elementInfo.javascriptName = elementQName.getLocalPart();
String schemaDefaultValue = element.getDefaultValue();
/*
* Schema default values are carried as strings.
* In javascript, for actual strings, we need quotes, but not for
* numbers. The following is a trick.
*/
schemaDefaultValue = protectDefaultValue(schemaDefaultValue);
elementInfo.defaultValue = schemaDefaultValue;
factorySetupType(element, schemaCollection, elementInfo);
elementInfo.isGroup = false;
} else if (particle instanceof XmlSchemaChoice) {
elementInfo.isGroup = true;
} else if (particle instanceof XmlSchemaSequence) {
elementInfo.isGroup = true;
} else {
// any
elementInfo.any = true;
// unknown until runtime.
elementInfo.xmlName = null;
// TODO: multiple 'any'
elementInfo.javascriptName = "any";
// runtime for any.
elementInfo.type = null;
elementInfo.isGroup = false;
}
}
use of org.apache.ws.commons.schema.XmlSchema in project cxf by apache.
the class SchemaJavascriptBuilder method deserializeElement.
private void deserializeElement(XmlSchemaComplexType type, ParticleInfo itemInfo) {
if (itemInfo.isGroup()) {
for (ParticleInfo childElement : itemInfo.getChildren()) {
deserializeElement(type, childElement);
}
return;
}
XmlSchemaType itemType = itemInfo.getType();
boolean simple = itemType instanceof XmlSchemaSimpleType || JavascriptUtils.notVeryComplexType(itemType);
boolean mtomCandidate = JavascriptUtils.mtomCandidateType(itemType);
String accessorName = "set" + StringUtils.capitalize(itemInfo.getJavascriptName());
utils.appendLine("cxfjsutils.trace('processing " + itemInfo.getJavascriptName() + "');");
XmlSchemaElement element = (XmlSchemaElement) itemInfo.getParticle();
QName elementQName = XmlSchemaUtils.getElementQualifiedName(element, xmlSchema);
String elementNamespaceURI = elementQName.getNamespaceURI();
boolean elementNoNamespace = "".equals(elementNamespaceURI);
XmlSchema elementSchema = null;
if (!elementNoNamespace) {
elementSchema = xmlSchemaCollection.getSchemaByTargetNamespace(elementNamespaceURI);
}
boolean qualified = !elementNoNamespace && XmlSchemaUtils.isElementQualified(element, itemInfo.isGlobal(), xmlSchema, elementSchema);
if (!qualified) {
elementNamespaceURI = "";
}
String localName = elementQName.getLocalPart();
String valueTarget = "item";
if (itemInfo.isOptional() || itemInfo.isArray()) {
utils.startIf("curElement != null && cxfjsutils.isNodeNamedNS(curElement, '" + elementNamespaceURI + "', '" + localName + "')");
if (itemInfo.isArray()) {
utils.appendLine("item = [];");
utils.startDo();
valueTarget = "arrayItem";
utils.appendLine("var arrayItem = null;");
}
}
utils.appendLine("var value = null;");
utils.startIf("!cxfjsutils.isElementNil(curElement)");
if (itemInfo.isAnyType()) {
// use our utility
utils.appendLine(valueTarget + " = org_apache_cxf_deserialize_anyType(cxfjsutils, curElement);");
} else if (simple) {
if (mtomCandidate) {
utils.appendLine(valueTarget + " = cxfjsutils.deserializeBase64orMom(curElement);");
} else {
utils.appendLine("value = cxfjsutils.getNodeText(curElement);");
utils.appendLine(valueTarget + " = " + utils.javascriptParseExpression(itemType, "value") + ";");
}
} else {
XmlSchemaComplexType complexType = (XmlSchemaComplexType) itemType;
QName baseQName = complexType.getQName();
if (baseQName == null) {
baseQName = element.getQName();
}
String elTypeJsName = nameManager.getJavascriptName(baseQName);
utils.appendLine(valueTarget + " = " + elTypeJsName + "_deserialize(cxfjsutils, curElement);");
}
// the if for the nil.
utils.endBlock();
if (itemInfo.isArray()) {
utils.appendLine("item.push(arrayItem);");
utils.appendLine("curElement = cxfjsutils.getNextElementSibling(curElement);");
utils.endBlock();
utils.appendLine(" while(curElement != null && cxfjsutils.isNodeNamedNS(curElement, '" + elementNamespaceURI + "', '" + localName + "'));");
}
utils.appendLine("newobject." + accessorName + "(item);");
utils.appendLine("var item = null;");
if (!itemInfo.isArray()) {
utils.startIf("curElement != null");
utils.appendLine("curElement = cxfjsutils.getNextElementSibling(curElement);");
utils.endBlock();
}
if (itemInfo.isOptional() || itemInfo.isArray()) {
utils.endBlock();
}
}
use of org.apache.ws.commons.schema.XmlSchema in project tomee by apache.
the class CommonsSchemaInfoBuilder method buildXmlTypeInfos.
private void buildXmlTypeInfos() {
for (XmlSchema schema : xmlSchemaCollection.getXmlSchemas()) {
// Global Elements
for (Iterator iterator = schema.getElements().getValues(); iterator.hasNext(); ) {
XmlSchemaElement globalElement = (XmlSchemaElement) iterator.next();
addGlobalElement(globalElement);
}
// Global Types
for (Iterator iterator = schema.getSchemaTypes().getValues(); iterator.hasNext(); ) {
XmlSchemaType globalType = (XmlSchemaType) iterator.next();
addType(globalType.getQName(), globalType);
}
}
}
use of org.apache.ws.commons.schema.XmlSchema in project cxf by apache.
the class JAXBDataBinding method validateSchema.
public void validateSchema(Element ele, String uri, final OASISCatalogManager catalog, final SchemaCollection schemaCollection) throws ToolException {
SchemaFactory schemaFact = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
schemaFact.setResourceResolver(new LSResourceResolver() {
public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) {
String s = JAXBDataBinding.mapSchemaLocation(systemId, baseURI, catalog);
LOG.fine("validating: " + namespaceURI + " " + systemId + " " + baseURI + " " + s);
if (s == null) {
XmlSchema sc = schemaCollection.getSchemaByTargetNamespace(namespaceURI);
if (sc != null) {
StringWriter writer = new StringWriter();
sc.write(writer);
InputSource src = new InputSource(new StringReader(writer.toString()));
src.setSystemId(sc.getSourceURI());
return new LSInputSAXWrapper(src);
}
throw new ToolException("Schema not found for namespace: " + namespaceURI);
}
return new LSInputSAXWrapper(new InputSource(s));
}
});
DOMSource domSrc = new DOMSource(ele, uri);
try {
schemaFact.newSchema(domSrc);
} catch (SAXException e) {
if (e.getLocalizedMessage().indexOf("src-resolve.4.2") > -1) {
// Ignore schema resolve error and do nothing
} else {
// e.printStackTrace();
throw new ToolException("Schema Error : " + e.getLocalizedMessage(), e);
}
}
}
Aggregations