use of com.webcohesion.enunciate.modules.jaxb.model.TypeDefinition in project enunciate by stoicflame.
the class CXMLClientModule method readResource.
/**
* Reads a resource into string form.
*
* @param resource The resource to read.
* @return The string form of the resource.
*/
protected String readResource(String resource, Map<String, Object> model, NameForTypeDefinitionMethod nameForTypeDefinition) {
Method exampleResource = findExampleResourceMethod();
if (exampleResource != null) {
TypeDefinition typeDefinition = findRequestElement(exampleResource);
if (typeDefinition != null) {
model.put("input_element_name", nameForTypeDefinition.calculateName(typeDefinition));
}
typeDefinition = findResponseElement(exampleResource);
if (typeDefinition != null) {
model.put("output_element_name", nameForTypeDefinition.calculateName(typeDefinition));
}
}
URL res = CXMLClientModule.class.getResource(resource);
try {
return processTemplate(res, model);
} catch (TemplateException e) {
throw new EnunciateException(e);
} catch (IOException e) {
throw new EnunciateException(e);
}
}
use of com.webcohesion.enunciate.modules.jaxb.model.TypeDefinition in project enunciate by stoicflame.
the class NameForTypeDefinitionMethod method exec.
public Object exec(List list) throws TemplateModelException {
if (list.size() < 1) {
throw new TemplateModelException("The nameForTypeDefinition method must have a type definition as a parameter.");
}
TemplateModel from = (TemplateModel) list.get(0);
Object unwrapped = FreemarkerUtil.unwrap(from);
if (!(unwrapped instanceof TypeDefinition)) {
throw new TemplateModelException("The nameForTypeDefinition method must have a type definition as a parameter.");
}
return calculateName((TypeDefinition) unwrapped);
}
use of com.webcohesion.enunciate.modules.jaxb.model.TypeDefinition in project enunciate by stoicflame.
the class XmlFunctionIdentifierMethod method exec.
/**
* Returns the qname of the element that has the first parameter as the namespace, the second as the element.
*
* @param list The arguments.
* @return The qname.
*/
public Object exec(List list) throws TemplateModelException {
if (list.size() < 1) {
throw new TemplateModelException("The xmlFunctionIdentifier method must have a qname, type definition, or xml type as a parameter.");
}
TemplateModel from = (TemplateModel) list.get(0);
Object unwrapped = FreemarkerUtil.unwrap(from);
if (unwrapped instanceof Accessor) {
DecoratedTypeMirror accessorType = ((Accessor) unwrapped).getBareAccessorType();
if (accessorType.isInstanceOf(JAXBElement.class.getName())) {
unwrapped = KnownXmlType.ANY_TYPE.getQname();
} else if (unwrapped instanceof Element && ((Element) unwrapped).getRef() != null) {
unwrapped = ((Element) unwrapped).getRef();
} else {
XmlType xmlType = ((Accessor) unwrapped).getBaseType();
if (xmlType instanceof SpecifiedXmlType) {
// bypass specified types for client code generation.
unwrapped = XmlTypeFactory.getXmlType(((Accessor) unwrapped).getAccessorType(), ((Accessor) unwrapped).getContext());
} else {
unwrapped = xmlType;
}
}
}
if (unwrapped instanceof XmlType) {
if (unwrapped instanceof XmlClassType && ((XmlType) unwrapped).isAnonymous()) {
unwrapped = ((XmlClassType) unwrapped).getTypeDefinition();
} else {
unwrapped = ((XmlType) unwrapped).getQname();
}
}
if (unwrapped instanceof TypeDefinition) {
if (((TypeDefinition) unwrapped).isAnonymous()) {
// if anonymous, we have to come up with a unique (albeit nonstandard) name for the xml type.
unwrapped = new QName(((TypeDefinition) unwrapped).getNamespace(), "anonymous" + ((TypeDefinition) unwrapped).getSimpleName());
} else {
unwrapped = ((TypeDefinition) unwrapped).getQname();
}
}
if (unwrapped instanceof ElementDeclaration) {
unwrapped = ((ElementDeclaration) unwrapped).getQname();
}
if (!(unwrapped instanceof QName)) {
throw new TemplateModelException("The xmlFunctionIdentifier method must have a qname, type definition, or xml type as a parameter.");
}
QName qname = (QName) unwrapped;
String namespace = qname.getNamespaceURI();
if ("".equals(namespace)) {
namespace = null;
}
String prefix = this.ns2prefix.get(namespace);
if (prefix == null || prefix.isEmpty()) {
prefix = "_";
}
prefix = prefix.replace('-', '_');
String localName = qname.getLocalPart();
if ("".equals(localName)) {
return null;
}
StringBuilder identifier = new StringBuilder();
identifier.append(Character.toLowerCase(prefix.charAt(0)));
identifier.append(prefix.substring(1));
identifier.append(Character.toUpperCase(localName.charAt(0)));
identifier.append(localName.substring(1));
return CXMLClientModule.scrubIdentifier(identifier.toString());
}
use of com.webcohesion.enunciate.modules.jaxb.model.TypeDefinition in project enunciate by stoicflame.
the class NamespaceImpl method getTypes.
@Override
public List<? extends DataType> getTypes() {
FacetFilter facetFilter = this.registrationContext.getFacetFilter();
ArrayList<DataType> dataTypes = new ArrayList<DataType>();
for (TypeDefinition typeDefinition : this.schema.getTypeDefinitions()) {
if (!facetFilter.accept(typeDefinition)) {
continue;
}
if (typeDefinition instanceof ComplexTypeDefinition) {
dataTypes.add(new ComplexDataTypeImpl((ComplexTypeDefinition) typeDefinition, registrationContext));
} else if (typeDefinition instanceof EnumTypeDefinition) {
dataTypes.add(new EnumDataTypeImpl((EnumTypeDefinition) typeDefinition, registrationContext));
}
}
return dataTypes;
}
Aggregations