use of org.apache.ws.commons.schema.XmlSchemaAppInfo in project hale by halestudio.
the class XmlSchemaReader method handleAppInfoTargetElement.
/**
* Handle reference information in XML Schema AppInfo.
*
* @param appInfos the list of AppInfos
* @param definition the property the infos are associated to
* @param index the XML index
*/
private static void handleAppInfoTargetElement(List<XmlSchemaAppInfo> appInfos, ChildDefinition<?> definition, XmlIndex index) {
Set<QName> elementNames = null;
for (final XmlSchemaAppInfo appInfo : appInfos) {
for (int i = 0; i < appInfo.getMarkup().getLength(); i++) {
final Node item = appInfo.getMarkup().item(i);
if ("targetElement".equals(item.getNodeName())) {
// TODO also check for GML namespace?
final String target = item.getTextContent();
String[] parts = target.split(":");
QName elementName = null;
if (parts.length == 1) {
elementName = new QName(parts[0]);
} else if (parts.length == 2) {
Map<String, String> namespaces = index.getPrefixes().inverse();
String ns = namespaces.get(parts[0]);
elementName = new QName(ns, parts[1]);
}
if (elementName != null) {
if (elementNames == null) {
elementNames = new HashSet<>();
}
elementNames.add(elementName);
}
}
}
}
if (elementNames != null) {
// TODO take from existing reference
List<QName> valuePath = null;
// property, if any?
ElementReferenceProperty constraint = new ElementReferenceProperty(index, valuePath, elementNames);
if (definition instanceof DefaultPropertyDefinition) {
((DefaultPropertyDefinition) definition).setConstraint(constraint);
} else if (definition instanceof DefaultGroupPropertyDefinition) {
((DefaultPropertyDefinition) definition).setConstraint(constraint);
}
}
}
use of org.apache.ws.commons.schema.XmlSchemaAppInfo in project cxf by apache.
the class ObjectReferenceVisitor method isDuplicateReference.
private void isDuplicateReference(QName referenceName, QName bindingName, Scope refScope, XmlSchemaType wsaType, AST node) {
XmlSchema refSchema;
if (!mapper.isDefaultMapping()) {
String tns = mapper.map(refScope.getParent());
String refSchemaFileName = getWsdlVisitor().getOutputDir() + System.getProperty("file.separator") + refScope.getParent().toString("_") + ".xsd";
refSchema = manager.getXmlSchema(tns);
if (refSchema == null) {
refSchema = manager.createXmlSchema(tns, wsdlVisitor.getSchemas());
}
addWSAddressingImport(refSchema);
manager.addXmlSchemaImport(schema, refSchema, refSchemaFileName);
} else {
refSchema = schema;
}
// we have, then there is no need to add it to the schema again.
if (!isReferenceSchemaTypeDefined(referenceName, refSchema)) {
// We need to add a new element definition to the schema section of our WSDL.
// For custom endpoint types, this should contain an annotation which points
// to the binding which will be used for this endpoint type.
XmlSchemaElement refElement = new XmlSchemaElement(schema, true);
refElement.setName(referenceName.getLocalPart());
refElement.setSchemaType(wsaType);
refElement.setSchemaTypeName(wsaType.getQName());
// Create an annotation which contains the CORBA binding for the element
XmlSchemaAnnotation annotation = new XmlSchemaAnnotation();
XmlSchemaAppInfo appInfo = new XmlSchemaAppInfo();
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE);
dbf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.newDocument();
Element el = doc.createElement("appinfo");
el.setTextContent("corba:binding=" + bindingName.getLocalPart());
// TODO: This is correct but the appinfo markup is never added to the
// schema. Investigate.
appInfo.setMarkup(el.getChildNodes());
} catch (ParserConfigurationException ex) {
throw new RuntimeException("[ObjectReferenceVisitor: error creating endpoint schema]");
}
annotation.getItems().add(appInfo);
refElement.setAnnotation(annotation);
}
}
Aggregations