use of com.webcohesion.enunciate.modules.jaxb.model.RootElementDeclaration in project enunciate by stoicflame.
the class IsDefinedGloballyMethod 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 isDefinedGlobally method must have a local element declaration as a parameter.");
}
TemplateModel from = (TemplateModel) list.get(0);
Object unwrapped = FreemarkerUtil.unwrap(from);
String namespace;
String name;
if (LocalElementDeclaration.class.isInstance(unwrapped)) {
LocalElementDeclaration decl = (LocalElementDeclaration) unwrapped;
namespace = decl.getNamespace();
name = decl.getName();
} else if (ImplicitSchemaElement.class.isInstance(unwrapped)) {
ImplicitSchemaElement ise = (ImplicitSchemaElement) unwrapped;
namespace = ise.getTargetNamespace();
name = ise.getElementName();
} else {
throw new TemplateModelException("The isDefinedGlobally method must have a local element declaration or an implicit schema element as a parameter.");
}
namespace = namespace == null ? "" : namespace;
String schemaNamespace = schemaInfo.getNamespace() == null ? "" : schemaInfo.getNamespace();
if (namespace.equals(schemaNamespace)) {
for (RootElementDeclaration rootElementDeclaration : schemaInfo.getRootElements()) {
if (rootElementDeclaration.getName().equals(name)) {
return true;
}
}
if (LocalElementDeclaration.class.isInstance(unwrapped)) {
// local element declarations have to check implicit schema elements, too.
for (ImplicitSchemaElement implicitSchemaElement : schemaInfo.getImplicitSchemaElements()) {
if (implicitSchemaElement.getElementName().equals(name)) {
return true;
}
}
}
}
return false;
}
use of com.webcohesion.enunciate.modules.jaxb.model.RootElementDeclaration in project enunciate by stoicflame.
the class JaxbContextClassListArtifact method exportTo.
@Override
public void exportTo(File fileOrDirectory, Enunciate enunciate) throws IOException {
FileWriter out = new FileWriter(fileOrDirectory.isDirectory() ? new File(fileOrDirectory, getName()) : fileOrDirectory);
for (SchemaInfo schemaInfo : this.jaxbContext.getSchemas().values()) {
for (Registry registry : schemaInfo.getRegistries()) {
out.write(registry.getQualifiedName() + "\n");
}
Collection<RootElementDeclaration> elements = schemaInfo.getRootElements();
for (RootElementDeclaration element : elements) {
out.write(element.getQualifiedName() + "\n");
}
}
out.flush();
out.close();
}
Aggregations