Search in sources :

Example 1 with RootElementDeclaration

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;
}
Also used : TemplateModelException(freemarker.template.TemplateModelException) ImplicitSchemaElement(com.webcohesion.enunciate.modules.jaxb.model.ImplicitSchemaElement) LocalElementDeclaration(com.webcohesion.enunciate.modules.jaxb.model.LocalElementDeclaration) RootElementDeclaration(com.webcohesion.enunciate.modules.jaxb.model.RootElementDeclaration) TemplateModel(freemarker.template.TemplateModel)

Example 2 with RootElementDeclaration

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();
}
Also used : FileWriter(java.io.FileWriter) RootElementDeclaration(com.webcohesion.enunciate.modules.jaxb.model.RootElementDeclaration) Registry(com.webcohesion.enunciate.modules.jaxb.model.Registry) File(java.io.File) SchemaInfo(com.webcohesion.enunciate.modules.jaxb.model.SchemaInfo)

Aggregations

RootElementDeclaration (com.webcohesion.enunciate.modules.jaxb.model.RootElementDeclaration)2 ImplicitSchemaElement (com.webcohesion.enunciate.modules.jaxb.model.ImplicitSchemaElement)1 LocalElementDeclaration (com.webcohesion.enunciate.modules.jaxb.model.LocalElementDeclaration)1 Registry (com.webcohesion.enunciate.modules.jaxb.model.Registry)1 SchemaInfo (com.webcohesion.enunciate.modules.jaxb.model.SchemaInfo)1 TemplateModel (freemarker.template.TemplateModel)1 TemplateModelException (freemarker.template.TemplateModelException)1 File (java.io.File)1 FileWriter (java.io.FileWriter)1