use of com.webcohesion.enunciate.modules.jaxb.model.Element in project enunciate by stoicflame.
the class ReferencedNamespacesMethod method addReferencedNamespaces.
/**
* Adds the referenced namespaces of the given type definition to the given set.
*
* @param typeDefinition The type definition.
* @param referencedNamespaces The set of referenced namespaces.
*/
private void addReferencedNamespaces(TypeDefinition typeDefinition, Set<String> referencedNamespaces) {
for (Attribute attribute : typeDefinition.getAttributes()) {
QName ref = attribute.getRef();
if (ref != null) {
referencedNamespaces.add(ref.getNamespaceURI());
} else {
addReferencedNamespaces(attribute.getBaseType(), referencedNamespaces);
}
}
for (Element element : typeDefinition.getElements()) {
for (Element choice : element.getChoices()) {
QName ref = choice.getRef();
if (ref != null) {
referencedNamespaces.add(ref.getNamespaceURI());
} else {
addReferencedNamespaces(choice.getBaseType(), referencedNamespaces);
}
}
}
Value value = typeDefinition.getValue();
if (value != null) {
addReferencedNamespaces(value.getBaseType(), referencedNamespaces);
}
if (typeDefinition instanceof QNameEnumTypeDefinition) {
for (EnumValue enumValue : ((QNameEnumTypeDefinition) typeDefinition).getEnumValues()) {
if (enumValue.getValue() != null) {
referencedNamespaces.add(((QName) enumValue.getValue()).getNamespaceURI());
}
}
}
addReferencedNamespaces(typeDefinition.getBaseType(), referencedNamespaces);
}
use of com.webcohesion.enunciate.modules.jaxb.model.Element in project enunciate by stoicflame.
the class ReferencedNamespacesMethod method exec.
public Object exec(List list) throws TemplateModelException {
if (list.size() < 1) {
throw new TemplateModelException("The referencedNamespaces method must have an element as a parameter.");
}
TemplateModel from = (TemplateModel) list.get(0);
Object unwrapped = BeansWrapper.getDefaultInstance().unwrap(from);
if (!(unwrapped instanceof ElementDeclaration)) {
throw new TemplateModelException("The referencedNamespaces method must have an element as a parameter.");
}
ElementDeclaration elementDeclaration = (ElementDeclaration) unwrapped;
Set<String> referencedNamespaces = new HashSet<String>();
referencedNamespaces.add(elementDeclaration.getNamespace());
if (elementDeclaration instanceof RootElementDeclaration) {
TypeDefinition typeDef = ((RootElementDeclaration) elementDeclaration).getTypeDefinition();
addReferencedNamespaces(typeDef, referencedNamespaces);
} else if (elementDeclaration instanceof LocalElementDeclaration) {
TypeElement typeElement = null;
TypeMirror elementType = ((LocalElementDeclaration) elementDeclaration).getElementType();
if (elementType instanceof DeclaredType) {
javax.lang.model.element.Element element = ((DeclaredType) elementType).asElement();
if (element instanceof TypeElement) {
typeElement = (TypeElement) element;
}
}
TypeDefinition typeDefinition = this.context.findTypeDefinition(typeElement);
if (typeDefinition != null) {
addReferencedNamespaces(typeDefinition, referencedNamespaces);
}
}
referencedNamespaces.remove(null);
referencedNamespaces.remove("");
referencedNamespaces.remove("http://www.w3.org/2001/XMLSchema");
return referencedNamespaces;
}
use of com.webcohesion.enunciate.modules.jaxb.model.Element in project enunciate by stoicflame.
the class ObjCXMLClientModule method usesUnmappableElements.
protected boolean usesUnmappableElements() {
boolean usesUnmappableElements = false;
if (this.jaxbModule != null && this.jaxbModule.getJaxbContext() != null && !this.jaxbModule.getJaxbContext().getSchemas().isEmpty()) {
for (SchemaInfo schemaInfo : this.jaxbModule.getJaxbContext().getSchemas().values()) {
for (TypeDefinition complexType : schemaInfo.getTypeDefinitions()) {
for (Attribute attribute : complexType.getAttributes()) {
if (attribute.isXmlList()) {
info("%s: The Objective-C client code won't serialize xml lists as an array, instead passing the list as a string that will need to be parsed. This may cause confusion to C consumers.", positionOf(attribute));
}
if (attribute.isCollectionType() && attribute.isBinaryData()) {
warn("%s: The Objective-C client code doesn't support a collection of items that are binary data. You'll have to define separate accessors for each item or disable the C module.", positionOf(attribute));
usesUnmappableElements = true;
}
}
if (complexType.getValue() != null) {
if (complexType.getValue().isXmlList()) {
info("%s: The Objective-C client code won't serialize xml lists as an array, instead passing the list as a string that will need to be parsed. This may cause confusion to C consumers.", positionOf(complexType.getValue()));
}
if (complexType.getValue().isCollectionType() && complexType.getValue().isBinaryData()) {
warn("%s: The Objective-C client code doesn't support a collection of items that are binary data.", positionOf(complexType.getValue()));
usesUnmappableElements = true;
}
}
for (Element element : complexType.getElements()) {
if (element.isXmlList()) {
info("%s: The Objective-C client code won't serialize xml lists as an array, instead passing the list as a string that will need to be parsed. This may cause confusion to C consumers.", positionOf(element));
}
if (element.getAccessorType() instanceof MapType && !element.isAdapted()) {
warn("%s: The Objective-C client doesn't have a built-in way of serializing a Map. Use @XmlJavaTypeAdapter to supply your own adapter for the Map.", positionOf(element));
usesUnmappableElements = true;
}
if (element.isCollectionType()) {
if (element.getChoices().size() > 1) {
info("%s: The Objective-C client code doesn't fully support multiple choices for a collection. It has to separate each choice into its own array. " + "This makes the C API a bit awkward to use and makes it impossible to preserve the order of the collection. If order is relevant, consider breaking out " + "the choices into their own collection or otherwise refactoring the API.", positionOf(element));
}
if (element.isBinaryData()) {
warn("%s: The Objective-C client code doesn't support a collection of items that are binary data.", positionOf(element));
usesUnmappableElements = true;
}
for (Element choice : element.getChoices()) {
if (choice.isNillable()) {
info("%s: The Objective-C client code doesn't support nillable items in a collection (the nil items will be skipped). This may cause confusion to C consumers.", positionOf(choice));
}
}
}
}
}
}
}
return usesUnmappableElements;
}
use of com.webcohesion.enunciate.modules.jaxb.model.Element in project enunciate by stoicflame.
the class PHPXMLClientModule method usesUnmappableElements.
protected boolean usesUnmappableElements() {
boolean usesUnmappableElements = false;
if (this.jaxbModule != null && this.jaxbModule.getJaxbContext() != null && !this.jaxbModule.getJaxbContext().getSchemas().isEmpty()) {
for (SchemaInfo schemaInfo : this.jaxbModule.getJaxbContext().getSchemas().values()) {
for (TypeDefinition complexType : schemaInfo.getTypeDefinitions()) {
if (!Character.isUpperCase(complexType.getClientSimpleName().charAt(0))) {
warn("%s: PHP requires your class name to be upper-case. Please rename the class or apply the @org.codehaus.enunciate.ClientName annotation to the class.", positionOf(complexType));
usesUnmappableElements = true;
}
for (Element element : complexType.getElements()) {
if (element instanceof ElementRef && element.isElementRefs()) {
info("%s: The PHP client library doesn't fully support the @XmlElementRefs annotation. The items in the collection will be read-only and will only be available to PHP clients in the form of a Hash. Consider redesigning using a collection of a single type.", positionOf(element));
} else if (element.getAnnotation(XmlElements.class) != null) {
info("%s: The PHP client library doesn't fully support the @XmlElements annotation. The items in the collection will be read-only and will only be available to PHP clients in the form of a Hash. Consider redesigning using a collection of a single type.", positionOf(element));
}
}
}
}
}
return usesUnmappableElements;
}
use of com.webcohesion.enunciate.modules.jaxb.model.Element in project enunciate by stoicflame.
the class CXMLClientModule method usesUnmappableElements.
protected boolean usesUnmappableElements() {
boolean usesUnmappableElements = false;
if (this.jaxbModule != null && this.jaxbModule.getJaxbContext() != null && !this.jaxbModule.getJaxbContext().getSchemas().isEmpty()) {
for (SchemaInfo schemaInfo : this.jaxbModule.getJaxbContext().getSchemas().values()) {
for (TypeDefinition complexType : schemaInfo.getTypeDefinitions()) {
for (Attribute attribute : complexType.getAttributes()) {
if (attribute.isXmlList()) {
info("%s: The C client code won't serialize xml lists as an array, instead passing the list as a string that will need to be parsed. This may cause confusion to C consumers.", positionOf(attribute));
}
if (attribute.isCollectionType() && attribute.isBinaryData()) {
warn("%s: The C client code doesn't support a collection of items that are binary data. You'll have to define separate accessors for each item or disable the C module.", positionOf(attribute));
usesUnmappableElements = true;
}
}
if (complexType.getValue() != null) {
if (complexType.getValue().isXmlList()) {
info("%s: The C client code won't serialize xml lists as an array, instead passing the list as a string that will need to be parsed. This may cause confusion to C consumers.", positionOf(complexType.getValue()));
}
if (complexType.getValue().isCollectionType() && complexType.getValue().isBinaryData()) {
warn("%s: The C client code doesn't support a collection of items that are binary data.", positionOf(complexType.getValue()));
usesUnmappableElements = true;
}
}
for (Element element : complexType.getElements()) {
if (element.isXmlList()) {
info("%s: The C client code won't serialize xml lists as an array, instead passing the list as a string that will need to be parsed. This may cause confusion to C consumers.", positionOf(element));
}
if (element.getAccessorType() instanceof MapType && !element.isAdapted()) {
warn("%s: The C client doesn't have a built-in way of serializing a Map. Use @XmlJavaTypeAdapter to supply your own adapter for the Map.", positionOf(element));
usesUnmappableElements = true;
}
if (element.isCollectionType()) {
if (element.getChoices().size() > 1) {
info("%s: The C client code doesn't fully support multiple choices for a collection. It has to separate each choice into its own array. " + "This makes the C API a bit awkward to use and makes it impossible to preserve the order of the collection. If order is relevant, consider breaking out " + "the choices into their own collection or otherwise refactoring the API.", positionOf(element));
}
if (element.isBinaryData()) {
warn("%s: The C client code doesn't support a collection of items that are binary data.", positionOf(element));
usesUnmappableElements = true;
}
for (Element choice : element.getChoices()) {
if (choice.isNillable()) {
info("%s: The C client code doesn't support nillable items in a collection (the nil items will be skipped). This may cause confusion to C consumers.", positionOf(choice));
}
}
}
}
}
}
}
return usesUnmappableElements;
}
Aggregations