Search in sources :

Example 1 with ImplicitSchemaElement

use of com.webcohesion.enunciate.modules.jaxb.model.ImplicitSchemaElement 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 ImplicitSchemaElement

use of com.webcohesion.enunciate.modules.jaxb.model.ImplicitSchemaElement in project enunciate by stoicflame.

the class EnunciateJaxwsContext method add.

/**
 * Add an endpoint interface to the model.
 *
 * @param ei The endpoint interface to add to the model.
 */
public void add(EndpointInterface ei) {
    String namespace = ei.getTargetNamespace();
    String prefix = this.jaxbContext.addNamespace(namespace);
    WsdlInfo wsdlInfo = wsdls.get(namespace);
    if (wsdlInfo == null) {
        wsdlInfo = new WsdlInfo(jaxbContext);
        wsdlInfo.setId(prefix);
        wsdls.put(namespace, wsdlInfo);
        wsdlInfo.setTargetNamespace(namespace);
    }
    for (WebMethod webMethod : ei.getWebMethods()) {
        for (WebMessage webMessage : webMethod.getMessages()) {
            for (WebMessagePart messagePart : webMessage.getParts()) {
                if (messagePart.isImplicitSchemaElement()) {
                    ImplicitSchemaElement implicitElement = (ImplicitSchemaElement) messagePart;
                    String particleNamespace = messagePart.getParticleQName().getNamespaceURI();
                    SchemaInfo schemaInfo = this.jaxbContext.getSchemas().get(particleNamespace);
                    if (schemaInfo == null) {
                        schemaInfo = new SchemaInfo(this.jaxbContext);
                        schemaInfo.setId(this.jaxbContext.addNamespace(particleNamespace));
                        schemaInfo.setNamespace(particleNamespace);
                        this.jaxbContext.getSchemas().put(particleNamespace, schemaInfo);
                    }
                    schemaInfo.getImplicitSchemaElements().add(implicitElement);
                }
            }
        }
    }
    wsdlInfo.getEndpointInterfaces().add(ei);
    this.endpointInterfaces.add(ei);
    debug("Added %s as a JAX-WS endpoint interface.", ei.getQualifiedName());
    if (getContext().getProcessingEnvironment().findSourcePosition(ei) == null) {
        OneTimeLogMessage.SOURCE_FILES_NOT_FOUND.log(getContext());
        if (OneTimeLogMessage.SOURCE_FILES_NOT_FOUND.getLogged() <= 3) {
            info("Unable to find source file for %s.", ei.getQualifiedName());
        } else {
            debug("Unable to find source file for %s.", ei.getQualifiedName());
        }
    }
}
Also used : WebMethod(com.webcohesion.enunciate.modules.jaxws.model.WebMethod) ImplicitSchemaElement(com.webcohesion.enunciate.modules.jaxb.model.ImplicitSchemaElement) WebMessagePart(com.webcohesion.enunciate.modules.jaxws.model.WebMessagePart) WebMessage(com.webcohesion.enunciate.modules.jaxws.model.WebMessage) SchemaInfo(com.webcohesion.enunciate.modules.jaxb.model.SchemaInfo)

Aggregations

ImplicitSchemaElement (com.webcohesion.enunciate.modules.jaxb.model.ImplicitSchemaElement)2 LocalElementDeclaration (com.webcohesion.enunciate.modules.jaxb.model.LocalElementDeclaration)1 RootElementDeclaration (com.webcohesion.enunciate.modules.jaxb.model.RootElementDeclaration)1 SchemaInfo (com.webcohesion.enunciate.modules.jaxb.model.SchemaInfo)1 WebMessage (com.webcohesion.enunciate.modules.jaxws.model.WebMessage)1 WebMessagePart (com.webcohesion.enunciate.modules.jaxws.model.WebMessagePart)1 WebMethod (com.webcohesion.enunciate.modules.jaxws.model.WebMethod)1 TemplateModel (freemarker.template.TemplateModel)1 TemplateModelException (freemarker.template.TemplateModelException)1