use of org.apache.cxf.javascript.UnsupportedConstruct in project cxf by apache.
the class SchemaJavascriptBuilder method generateCodeForSchema.
public String generateCodeForSchema(XmlSchema schema) {
xmlSchema = schema;
code = new StringBuilder();
code.append("//\n");
code.append("// Definitions for schema: ").append(schema.getTargetNamespace());
if (schema.getSourceURI() != null) {
code.append("\n// ").append(schema.getSourceURI());
}
code.append("\n//\n");
Map<QName, XmlSchemaType> schemaTypes = schema.getSchemaTypes();
for (Map.Entry<QName, XmlSchemaType> e : schemaTypes.entrySet()) {
XmlSchemaType type = e.getValue();
if (type instanceof XmlSchemaComplexType) {
try {
XmlSchemaComplexType complexType = (XmlSchemaComplexType) type;
if (!JavascriptUtils.notVeryComplexType(complexType) && complexType.getName() != null) {
complexTypeConstructorAndAccessors(complexType.getQName(), complexType);
complexTypeSerializerFunction(complexType.getQName(), complexType);
domDeserializerFunction(complexType.getQName(), complexType);
}
} catch (UnsupportedConstruct usc) {
LOG.warning(usc.toString());
// it could be empty, but the style checker
continue;
// would complain.
}
} else if (type instanceof XmlSchemaSimpleType) {
XmlSchemaSimpleType simpleType = (XmlSchemaSimpleType) type;
if (XmlSchemaUtils.isEumeration(simpleType)) {
List<String> values = XmlSchemaUtils.enumeratorValues(simpleType);
code.append("//\n");
code.append("// Simple type (enumeration) ").append(simpleType.getQName()).append('\n');
code.append("//\n");
for (String value : values) {
code.append("// - ").append(value).append('\n');
}
}
}
}
for (Map.Entry<QName, XmlSchemaElement> e : schema.getElements().entrySet()) {
XmlSchemaElement element = e.getValue();
try {
if (element.getSchemaTypeName() == null && element.getSchemaType() == null) {
Message message = new Message("ELEMENT_MISSING_TYPE", LOG, element.getQName(), element.getSchemaTypeName(), schema.getTargetNamespace());
LOG.warning(message.toString());
continue;
}
XmlSchemaType type;
if (element.getSchemaType() != null) {
type = element.getSchemaType();
} else {
type = schema.getTypeByName(element.getSchemaTypeName());
}
if (!(type instanceof XmlSchemaComplexType)) {
// we never make classes for simple type.
continue;
}
XmlSchemaComplexType complexType = (XmlSchemaComplexType) type;
// element.
if (!JavascriptUtils.notVeryComplexType(complexType) && complexType.getName() == null) {
complexTypeConstructorAndAccessors(element.getQName(), complexType);
complexTypeSerializerFunction(element.getQName(), complexType);
domDeserializerFunction(element.getQName(), complexType);
}
} catch (UnsupportedConstruct usc) {
LOG.warning(usc.getMessage());
// it could be empty, but the style checker
continue;
// would complain.
}
}
String returnValue = code.toString();
LOG.finer(returnValue);
return returnValue;
}
use of org.apache.cxf.javascript.UnsupportedConstruct in project cxf by apache.
the class ServiceJavascriptBuilder method getElementType.
/**
* Follow a chain of references from element to element until we can obtain
* a type.
*
* @param element
*/
public static XmlSchemaType getElementType(SchemaCollection xmlSchemaCollection, String referencingURI, XmlSchemaElement element, XmlSchemaType containingType) {
assert element != null;
if (element.getSchemaTypeName() != null) {
XmlSchemaType type = xmlSchemaCollection.getTypeByQName(element.getSchemaTypeName());
if (type == null) {
Message message = new Message("ELEMENT_TYPE_MISSING", LOG, element.getQName(), element.getSchemaTypeName().toString());
throw new UnsupportedConstruct(message);
}
return type;
}
// The referencing URI only helps if there is a schema that points to
// it.
// It might be the URI for the wsdl TNS, which might have no schema.
// if (xmlSchemaCollection.getSchemaByTargetNamespace(referencingURI) == null) {
// referencingURI = null;
// }
//
// if (referencingURI == null && containingType != null) {
// referencingURI = containingType.getQName().getNamespaceURI();
// }
XmlSchemaElement originalElement = element;
while (element.getSchemaType() == null && element.isRef()) {
/*
* This code assumes that all schemas are in the collection.
*/
XmlSchemaElement nextElement = element.getRef().getTarget();
assert nextElement != null;
element = nextElement;
}
if (element.getSchemaType() == null) {
unsupportedConstruct("ELEMENT_HAS_NO_TYPE", originalElement.getName(), containingType.getQName(), containingType);
}
return element.getSchemaType();
}
use of org.apache.cxf.javascript.UnsupportedConstruct in project cxf by apache.
the class ServiceJavascriptBuilder method unsupportedConstruct.
public static void unsupportedConstruct(String messageKey, String what, QName subjectName, XmlSchemaObject subject) {
Message message = new Message(messageKey, LOG, what, subjectName == null ? "anonymous" : subjectName, cleanedUpSchemaSource(subject));
LOG.severe(message.toString());
throw new UnsupportedConstruct(message);
}
use of org.apache.cxf.javascript.UnsupportedConstruct in project cxf by apache.
the class ServiceJavascriptBuilder method unsupportedConstruct.
public static void unsupportedConstruct(String messageKey, XmlSchemaType subject) {
Message message = new Message(messageKey, LOG, subject.getQName(), cleanedUpSchemaSource(subject));
LOG.severe(message.toString());
throw new UnsupportedConstruct(message);
}
Aggregations