Search in sources :

Example 6 with SchemaInfo

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

the class WsdlInfo method getImportedSchemas.

/**
 * The list of imported schemas.
 *
 * @return The list of imported schemas.
 */
public List<SchemaInfo> getImportedSchemas() {
    Set<String> importedNamespaces = getImportedNamespaces();
    // the "associated" schema is either inlined or included, but not imported.
    importedNamespaces.remove(getTargetNamespace());
    List<SchemaInfo> schemas = new ArrayList<SchemaInfo>();
    for (String ns : importedNamespaces) {
        SchemaInfo schema = lookupSchema(ns);
        if (schema != null) {
            schemas.add(schema);
        }
    }
    return schemas;
}
Also used : SchemaInfo(com.webcohesion.enunciate.modules.jaxb.model.SchemaInfo)

Example 7 with SchemaInfo

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

the class WsdlInfo method getImportedNamespaces.

/**
 * Get the imported namespaces used by this WSDL.
 *
 * @return The imported namespaces used by this WSDL.
 */
public Set<String> getImportedNamespaces() {
    Set<EndpointInterface> endpointInterfaces = getEndpointInterfaces();
    if ((endpointInterfaces == null) || (endpointInterfaces.size() == 0)) {
        throw new IllegalStateException("WSDL for " + getTargetNamespace() + " has no endpoint interfaces!");
    }
    HashSet<String> importedNamespaces = new HashSet<String>();
    // always import the list of known namespaces.
    importedNamespaces.add("http://schemas.xmlsoap.org/wsdl/");
    importedNamespaces.add("http://schemas.xmlsoap.org/wsdl/http/");
    importedNamespaces.add("http://schemas.xmlsoap.org/wsdl/mime/");
    importedNamespaces.add("http://schemas.xmlsoap.org/wsdl/soap/");
    importedNamespaces.add("http://schemas.xmlsoap.org/wsdl/soap12/");
    importedNamespaces.add("http://schemas.xmlsoap.org/soap/encoding/");
    importedNamespaces.add("http://www.w3.org/2001/XMLSchema");
    for (EndpointInterface endpointInterface : endpointInterfaces) {
        importedNamespaces.addAll(endpointInterface.getReferencedNamespaces());
    }
    if (isInlineSchema()) {
        SchemaInfo associatedSchema = getAssociatedSchema();
        if (associatedSchema != null) {
            importedNamespaces.addAll(associatedSchema.getReferencedNamespaces());
        }
    }
    return importedNamespaces;
}
Also used : EndpointInterface(com.webcohesion.enunciate.modules.jaxws.model.EndpointInterface) SchemaInfo(com.webcohesion.enunciate.modules.jaxb.model.SchemaInfo)

Example 8 with SchemaInfo

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

the class IDLModule method call.

@Override
public void call(EnunciateContext context) {
    Map<String, SchemaInfo> ns2schema = Collections.emptyMap();
    Map<String, String> ns2prefix = Collections.emptyMap();
    if (this.jaxbModule != null) {
        ns2schema = this.jaxbModule.getJaxbContext().getSchemas();
        ns2prefix = this.jaxbModule.getJaxbContext().getNamespacePrefixes();
    }
    Map<String, WsdlInfo> ns2wsdl = Collections.emptyMap();
    if (this.jaxwsModule != null) {
        ns2wsdl = this.jaxwsModule.getJaxwsContext().getWsdls();
    }
    Set<String> facetIncludes = new TreeSet<String>(this.enunciate.getConfiguration().getFacetIncludes());
    facetIncludes.addAll(getFacetIncludes());
    Set<String> facetExcludes = new TreeSet<String>(this.enunciate.getConfiguration().getFacetExcludes());
    facetExcludes.addAll(getFacetExcludes());
    FacetFilter facetFilter = new FacetFilter(facetIncludes, facetExcludes);
    Map<String, SchemaConfig> schemaConfigs = getSchemaConfigs();
    for (SchemaInfo schemaInfo : ns2schema.values()) {
        String defaultFilename = ns2prefix.get(schemaInfo.getNamespace()) + ".xsd";
        SchemaConfig explicitConfig = schemaConfigs.get(schemaInfo.getNamespace());
        if (explicitConfig != null && explicitConfig.getUseFile() != null) {
            schemaInfo.setFilename(explicitConfig.getUseFile().getName());
            schemaInfo.setSchemaFile(new StaticInterfaceDescriptionFile(explicitConfig.getUseFile(), this.enunciate));
        } else if (explicitConfig != null) {
            schemaInfo.setAppinfo(explicitConfig.getAppinfo());
            schemaInfo.setFilename(explicitConfig.getFilename() != null ? explicitConfig.getFilename() : defaultFilename);
            schemaInfo.setExplicitLocation(explicitConfig.getLocation());
            schemaInfo.setJaxbBindingVersion(explicitConfig.getJaxbBindingVersion());
            schemaInfo.setSchemaFile(new JaxbSchemaFile(this.enunciate, defaultFilename, this.jaxbModule.getJaxbContext(), schemaInfo, facetFilter, ns2prefix));
        } else {
            schemaInfo.setFilename(defaultFilename);
            schemaInfo.setSchemaFile(new JaxbSchemaFile(this.enunciate, defaultFilename, this.jaxbModule.getJaxbContext(), schemaInfo, facetFilter, ns2prefix));
        }
    }
    String baseUri = this.enunciate.getConfiguration().getApplicationRoot();
    Map<String, WsdlConfig> wsdlConfigs = getWsdlConfigs();
    for (WsdlInfo wsdlInfo : ns2wsdl.values()) {
        String defaultFilename = ns2prefix.get(wsdlInfo.getTargetNamespace()) + ".wsdl";
        WsdlConfig explicitConfig = wsdlConfigs.get(wsdlInfo.getTargetNamespace());
        if (explicitConfig != null && explicitConfig.getUseFile() != null) {
            wsdlInfo.setFilename(explicitConfig.getUseFile().getName());
            wsdlInfo.setWsdlFile(new StaticInterfaceDescriptionFile(explicitConfig.getUseFile(), this.enunciate));
        } else if (explicitConfig != null) {
            wsdlInfo.setFilename(explicitConfig.getFilename() != null ? explicitConfig.getFilename() : defaultFilename);
            wsdlInfo.setInlineSchema(explicitConfig.isInlineSchema());
            wsdlInfo.setWsdlFile(new JaxwsWsdlFile(this.enunciate, defaultFilename, wsdlInfo, this.jaxbModule.getJaxbContext(), baseUri, ns2prefix, facetFilter));
        } else {
            wsdlInfo.setFilename(defaultFilename);
            wsdlInfo.setWsdlFile(new JaxwsWsdlFile(this.enunciate, defaultFilename, wsdlInfo, this.jaxbModule.getJaxbContext(), baseUri, ns2prefix, facetFilter));
        }
    }
    if (this.jaxrsModule != null && this.jaxbModule != null && !isDisableWadl()) {
        this.jaxrsModule.getJaxrsContext().setWadlFile(new JaxrsWadlFile(this.enunciate, "application.wadl", this.jaxrsModule.getJaxrsContext(), this.jaxbModule.getJaxbContext(), new ArrayList<SchemaInfo>(ns2schema.values()), getWadlStylesheetUri(), baseUri, ns2prefix, facetFilter, isLinkJsonToXml()));
    }
}
Also used : FacetFilter(com.webcohesion.enunciate.facets.FacetFilter) StaticInterfaceDescriptionFile(com.webcohesion.enunciate.util.StaticInterfaceDescriptionFile) WsdlInfo(com.webcohesion.enunciate.modules.jaxws.WsdlInfo) SchemaInfo(com.webcohesion.enunciate.modules.jaxb.model.SchemaInfo)

Example 9 with SchemaInfo

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

the class JaxwsWsdlFile method createModel.

@Override
protected Map<String, Object> createModel() {
    Map<String, Object> model = super.createModel();
    model.put("wsdl", this.wsdlInfo);
    String baseUri = this.baseUri;
    if (baseUri == null) {
        // if the base uri isn't configured, we have to make something up.
        baseUri = "http://localhost:8080/";
    }
    model.put("baseUri", baseUri);
    SchemaInfo schema = context.getSchemas().get(wsdlInfo.getTargetNamespace());
    if (schema != null) {
        model.put("isDefinedGlobally", new IsDefinedGloballyMethod(schema));
    }
    model.put("accessorOverridesAnother", new AccessorOverridesAnotherMethod());
    model.put("qnameForType", new QNameForTypeMethod(context));
    return model;
}
Also used : AccessorOverridesAnotherMethod(com.webcohesion.enunciate.modules.jaxb.util.AccessorOverridesAnotherMethod) SchemaInfo(com.webcohesion.enunciate.modules.jaxb.model.SchemaInfo)

Example 10 with SchemaInfo

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

the class ObjCXMLClientModule method call.

@Override
public void call(EnunciateContext context) {
    if (this.jaxbModule == null || this.jaxbModule.getJaxbContext() == null || this.jaxbModule.getJaxbContext().getSchemas().isEmpty()) {
        info("No JAXB XML data types: Objective-C XML client will not be generated.");
        return;
    }
    if (usesUnmappableElements()) {
        warn("Web service API makes use of elements that cannot be handled by the Objective-C XML client. Objective-C XML client will not be generated.");
        return;
    }
    List<String> namingConflicts = JAXBCodeErrors.findConflictingAccessorNamingErrors(this.jaxbModule.getJaxbContext());
    if (namingConflicts != null && !namingConflicts.isEmpty()) {
        error("JAXB naming conflicts have been found:");
        for (String namingConflict : namingConflicts) {
            error(namingConflict);
        }
        error("These naming conflicts are often between the field and it's associated property, in which case you need to use one or two of the following strategies to avoid the conflicts:");
        error("1. Explicitly exclude one or the other.");
        error("2. Put the annotations on the property instead of the field.");
        error("3. Tell JAXB to use a different process for detecting accessors using the @XmlAccessorType annotation.");
        throw new EnunciateException("JAXB naming conflicts detected.");
    }
    EnunciateJaxbContext jaxbContext = this.jaxbModule.getJaxbContext();
    Map<String, String> packageIdentifiers = getPackageIdentifiers();
    String packageIdentifierPattern = getPackageIdentifierPattern();
    if ((packageIdentifierPattern != null)) {
        for (SchemaInfo schemaInfo : jaxbContext.getSchemas().values()) {
            for (TypeDefinition typeDefinition : schemaInfo.getTypeDefinitions()) {
                String pckg = typeDefinition.getPackage().getQualifiedName().toString();
                if (!packageIdentifiers.containsKey(pckg)) {
                    try {
                        packageIdentifiers.put(pckg, String.format(packageIdentifierPattern, pckg.split("\\.", 9)));
                    } catch (IllegalFormatException e) {
                        warn("Unable to format package %s with format pattern %s (%s)", pckg, packageIdentifierPattern, e.getMessage());
                    }
                }
            }
        }
    }
    Map<String, Object> model = new HashMap<String, Object>();
    String slug = getSlug();
    model.put("slug", slug);
    File srcDir = getSourceDir();
    TreeMap<String, String> translations = new TreeMap<String, String>();
    translations.put("id", getTranslateIdTo());
    model.put("clientSimpleName", new ClientSimpleNameMethod(translations));
    List<TypeDefinition> schemaTypes = new ArrayList<TypeDefinition>();
    ExtensionDepthComparator comparator = new ExtensionDepthComparator();
    for (SchemaInfo schemaInfo : jaxbContext.getSchemas().values()) {
        for (TypeDefinition typeDefinition : schemaInfo.getTypeDefinitions()) {
            int position = Collections.binarySearch(schemaTypes, typeDefinition, comparator);
            if (position < 0) {
                position = -position - 1;
            }
            schemaTypes.add(position, typeDefinition);
        }
    }
    model.put("schemaTypes", schemaTypes);
    NameForTypeDefinitionMethod nameForTypeDefinition = new NameForTypeDefinitionMethod(getTypeDefinitionNamePattern(), slug, jaxbContext.getNamespacePrefixes(), packageIdentifiers);
    model.put("nameForTypeDefinition", nameForTypeDefinition);
    model.put("nameForEnumConstant", new NameForEnumConstantMethod(getEnumConstantNamePattern(), slug, jaxbContext.getNamespacePrefixes(), packageIdentifiers));
    TreeMap<String, String> conversions = new TreeMap<String, String>();
    for (SchemaInfo schemaInfo : jaxbContext.getSchemas().values()) {
        for (TypeDefinition typeDefinition : schemaInfo.getTypeDefinitions()) {
            if (typeDefinition.isEnum()) {
                conversions.put(typeDefinition.getQualifiedName().toString(), "enum " + nameForTypeDefinition.calculateName(typeDefinition));
            } else {
                conversions.put(typeDefinition.getQualifiedName().toString(), (String) nameForTypeDefinition.calculateName(typeDefinition));
            }
        }
    }
    ClientClassnameForMethod classnameFor = new ClientClassnameForMethod(conversions, jaxbContext);
    model.put("classnameFor", classnameFor);
    model.put("functionIdentifierFor", new FunctionIdentifierForMethod(nameForTypeDefinition, jaxbContext));
    model.put("objcBaseName", slug);
    model.put("separateCommonCode", isSeparateCommonCode());
    model.put("findRootElement", new FindRootElementMethod(jaxbContext));
    model.put("referencedNamespaces", new ReferencedNamespacesMethod(jaxbContext));
    model.put("prefix", new PrefixMethod(jaxbContext.getNamespacePrefixes()));
    model.put("accessorOverridesAnother", new AccessorOverridesAnotherMethod());
    model.put("file", new FileDirective(srcDir, this.enunciate.getLogger()));
    Set<String> facetIncludes = new TreeSet<String>(this.enunciate.getConfiguration().getFacetIncludes());
    facetIncludes.addAll(getFacetIncludes());
    Set<String> facetExcludes = new TreeSet<String>(this.enunciate.getConfiguration().getFacetExcludes());
    facetExcludes.addAll(getFacetExcludes());
    FacetFilter facetFilter = new FacetFilter(facetIncludes, facetExcludes);
    model.put("isFacetExcluded", new IsFacetExcludedMethod(facetFilter));
    if (!isUpToDateWithSources(srcDir)) {
        debug("Generating the C data structures and (de)serialization functions...");
        URL apiTemplate = getTemplateURL("api.fmt");
        try {
            processTemplate(apiTemplate, model);
        } catch (IOException e) {
            throw new EnunciateException(e);
        } catch (TemplateException e) {
            throw new EnunciateException(e);
        }
    } else {
        info("Skipping C code generation because everything appears up-to-date.");
    }
    ClientLibraryArtifact artifactBundle = new ClientLibraryArtifact(getName(), "objc.client.library", "Objective C Client Library");
    FileArtifact sourceHeader = new FileArtifact(getName(), "objc.client.h", new File(srcDir, slug + ".h"));
    sourceHeader.setPublic(false);
    sourceHeader.setArtifactType(ArtifactType.sources);
    FileArtifact sourceImpl = new FileArtifact(getName(), "objc.client.m", new File(srcDir, slug + ".m"));
    sourceImpl.setPublic(false);
    sourceImpl.setArtifactType(ArtifactType.sources);
    // read in the description from file
    String description = readResource("library_description.fmt", model, nameForTypeDefinition);
    artifactBundle.setDescription(description);
    artifactBundle.addArtifact(sourceHeader);
    artifactBundle.addArtifact(sourceImpl);
    if (isSeparateCommonCode()) {
        FileArtifact commonSourceHeader = new FileArtifact(getName(), "objc.common.client.h", new File(srcDir, "enunciate-common.h"));
        commonSourceHeader.setPublic(false);
        commonSourceHeader.setArtifactType(ArtifactType.sources);
        commonSourceHeader.setDescription("Common header needed for all projects.");
        FileArtifact commonSourceImpl = new FileArtifact(getName(), "objc.common.client.m", new File(srcDir, "enunciate-common.m"));
        commonSourceImpl.setPublic(false);
        commonSourceImpl.setArtifactType(ArtifactType.sources);
        commonSourceImpl.setDescription("Common implementation code needed for all projects.");
        artifactBundle.addArtifact(commonSourceHeader);
        artifactBundle.addArtifact(commonSourceImpl);
    }
    this.enunciate.addArtifact(artifactBundle);
}
Also used : FacetFilter(com.webcohesion.enunciate.facets.FacetFilter) ClientLibraryArtifact(com.webcohesion.enunciate.artifacts.ClientLibraryArtifact) IsFacetExcludedMethod(com.webcohesion.enunciate.util.freemarker.IsFacetExcludedMethod) URL(java.net.URL) TypeDefinition(com.webcohesion.enunciate.modules.jaxb.model.TypeDefinition) FindRootElementMethod(com.webcohesion.enunciate.modules.jaxb.util.FindRootElementMethod) EnunciateException(com.webcohesion.enunciate.EnunciateException) SchemaInfo(com.webcohesion.enunciate.modules.jaxb.model.SchemaInfo) FileDirective(com.webcohesion.enunciate.util.freemarker.FileDirective) EnunciateJaxbContext(com.webcohesion.enunciate.modules.jaxb.EnunciateJaxbContext) AccessorOverridesAnotherMethod(com.webcohesion.enunciate.modules.jaxb.util.AccessorOverridesAnotherMethod) FileArtifact(com.webcohesion.enunciate.artifacts.FileArtifact)

Aggregations

SchemaInfo (com.webcohesion.enunciate.modules.jaxb.model.SchemaInfo)17 TypeDefinition (com.webcohesion.enunciate.modules.jaxb.model.TypeDefinition)8 EnunciateException (com.webcohesion.enunciate.EnunciateException)5 FacetFilter (com.webcohesion.enunciate.facets.FacetFilter)5 File (java.io.File)5 WsdlInfo (com.webcohesion.enunciate.modules.jaxws.WsdlInfo)4 URL (java.net.URL)4 ClientLibraryArtifact (com.webcohesion.enunciate.artifacts.ClientLibraryArtifact)3 FileArtifact (com.webcohesion.enunciate.artifacts.FileArtifact)3 EnunciateJaxbContext (com.webcohesion.enunciate.modules.jaxb.EnunciateJaxbContext)3 Element (com.webcohesion.enunciate.modules.jaxb.model.Element)3 AccessorOverridesAnotherMethod (com.webcohesion.enunciate.modules.jaxb.util.AccessorOverridesAnotherMethod)3 FindRootElementMethod (com.webcohesion.enunciate.modules.jaxb.util.FindRootElementMethod)3 TemplateException (freemarker.template.TemplateException)3 IOException (java.io.IOException)3 Attribute (com.webcohesion.enunciate.modules.jaxb.model.Attribute)2 Registry (com.webcohesion.enunciate.modules.jaxb.model.Registry)2 MapType (com.webcohesion.enunciate.modules.jaxb.model.util.MapType)2 ReferencedNamespacesMethod (com.webcohesion.enunciate.modules.jaxb.util.ReferencedNamespacesMethod)2 FileDirective (com.webcohesion.enunciate.util.freemarker.FileDirective)2