use of com.webcohesion.enunciate.modules.jaxb.model.SchemaInfo in project enunciate by stoicflame.
the class ObjCXMLClientModule method usesUnmappableElements.
protected boolean usesUnmappableElements() {
boolean usesUnmappableElements = false;
if (this.jaxbModule != null && this.jaxbModule.getJaxbContext() != null && !this.jaxbModule.getJaxbContext().getSchemas().isEmpty()) {
for (SchemaInfo schemaInfo : this.jaxbModule.getJaxbContext().getSchemas().values()) {
for (TypeDefinition complexType : schemaInfo.getTypeDefinitions()) {
for (Attribute attribute : complexType.getAttributes()) {
if (attribute.isXmlList()) {
info("%s: The Objective-C client code won't serialize xml lists as an array, instead passing the list as a string that will need to be parsed. This may cause confusion to C consumers.", positionOf(attribute));
}
if (attribute.isCollectionType() && attribute.isBinaryData()) {
warn("%s: The Objective-C client code doesn't support a collection of items that are binary data. You'll have to define separate accessors for each item or disable the C module.", positionOf(attribute));
usesUnmappableElements = true;
}
}
if (complexType.getValue() != null) {
if (complexType.getValue().isXmlList()) {
info("%s: The Objective-C client code won't serialize xml lists as an array, instead passing the list as a string that will need to be parsed. This may cause confusion to C consumers.", positionOf(complexType.getValue()));
}
if (complexType.getValue().isCollectionType() && complexType.getValue().isBinaryData()) {
warn("%s: The Objective-C client code doesn't support a collection of items that are binary data.", positionOf(complexType.getValue()));
usesUnmappableElements = true;
}
}
for (Element element : complexType.getElements()) {
if (element.isXmlList()) {
info("%s: The Objective-C client code won't serialize xml lists as an array, instead passing the list as a string that will need to be parsed. This may cause confusion to C consumers.", positionOf(element));
}
if (element.getAccessorType() instanceof MapType && !element.isAdapted()) {
warn("%s: The Objective-C client doesn't have a built-in way of serializing a Map. Use @XmlJavaTypeAdapter to supply your own adapter for the Map.", positionOf(element));
usesUnmappableElements = true;
}
if (element.isCollectionType()) {
if (element.getChoices().size() > 1) {
info("%s: The Objective-C client code doesn't fully support multiple choices for a collection. It has to separate each choice into its own array. " + "This makes the C API a bit awkward to use and makes it impossible to preserve the order of the collection. If order is relevant, consider breaking out " + "the choices into their own collection or otherwise refactoring the API.", positionOf(element));
}
if (element.isBinaryData()) {
warn("%s: The Objective-C client code doesn't support a collection of items that are binary data.", positionOf(element));
usesUnmappableElements = true;
}
for (Element choice : element.getChoices()) {
if (choice.isNillable()) {
info("%s: The Objective-C client code doesn't support nillable items in a collection (the nil items will be skipped). This may cause confusion to C consumers.", positionOf(choice));
}
}
}
}
}
}
}
return usesUnmappableElements;
}
use of com.webcohesion.enunciate.modules.jaxb.model.SchemaInfo in project enunciate by stoicflame.
the class PHPXMLClientModule 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: PHP XML client will not be generated.");
return;
}
if (usesUnmappableElements()) {
warn("Web service API makes use of elements that cannot be handled by the PHP XML client. PHP 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.");
}
Map<String, String> packageToNamespaceConversions = getPackageToNamespaceConversions();
List<TypeDefinition> schemaTypes = new ArrayList<TypeDefinition>();
ExtensionDepthComparator comparator = new ExtensionDepthComparator();
EnunciateJaxbContext jaxbContext = this.jaxbModule.getJaxbContext();
for (SchemaInfo schemaInfo : jaxbContext.getSchemas().values()) {
for (TypeDefinition typeDefinition : schemaInfo.getTypeDefinitions()) {
String pckg = typeDefinition.getPackage().getQualifiedName().toString();
if (!packageToNamespaceConversions.containsKey(pckg)) {
packageToNamespaceConversions.put(pckg, packageToNamespace(pckg));
}
int position = Collections.binarySearch(schemaTypes, typeDefinition, comparator);
if (position < 0) {
position = -position - 1;
}
schemaTypes.add(position, typeDefinition);
}
}
File srcDir = getSourceDir();
Map<String, Object> model = new HashMap<String, Object>();
model.put("schemaTypes", schemaTypes);
model.put("namespaceFor", new ClientPackageForMethod(packageToNamespaceConversions, this.context));
ClientClassnameForMethod classnameFor = new ClientClassnameForMethod(packageToNamespaceConversions, jaxbContext);
model.put("classnameFor", classnameFor);
model.put("typeNameFor", new TypeNameForMethod(packageToNamespaceConversions, jaxbContext));
model.put("simpleNameFor", new SimpleNameWithParamsMethod(classnameFor));
model.put("phpFileName", getSourceFileName());
model.put("findRootElement", new FindRootElementMethod(jaxbContext));
model.put("referencedNamespaces", new ReferencedNamespacesMethod(jaxbContext));
model.put("prefix", new PrefixMethod(jaxbContext.getNamespacePrefixes()));
model.put("file", new FileDirective(srcDir, this.enunciate.getLogger()));
model.put("generatedCodeLicense", this.enunciate.getConfiguration().readGeneratedCodeLicenseFile());
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 PHP XML data classes...");
URL apiTemplate = isSingleFilePerClass() ? getTemplateURL("api-multiple-files.fmt") : getTemplateURL("api.fmt");
try {
processTemplate(apiTemplate, model);
} catch (IOException e) {
throw new EnunciateException(e);
} catch (TemplateException e) {
throw new EnunciateException(e);
}
} else {
info("Skipping PHP XML code generation because everything appears up-to-date.");
}
File packageDir = getPackageDir();
packageDir.mkdirs();
File bundle = new File(packageDir, getBundleFileName());
boolean anyFiles = bundle.exists();
if (!isUpToDateWithSources(packageDir)) {
try {
anyFiles = enunciate.zip(bundle, srcDir);
} catch (IOException e) {
throw new EnunciateException(e);
}
}
if (anyFiles) {
ClientLibraryArtifact artifactBundle = new ClientLibraryArtifact(getName(), "php.xml.client.library", "PHP XML Client Library");
artifactBundle.setPlatform("PHP");
FileArtifact sourceScript = new FileArtifact(getName(), "php.xml.client", bundle);
// binaries and sources are the same thing in php
sourceScript.setArtifactType(ArtifactType.binaries);
sourceScript.setPublic(false);
// read in the description from file
String description = readResource("library_description.fmt", model);
artifactBundle.setDescription(description);
artifactBundle.addArtifact(sourceScript);
this.enunciate.addArtifact(artifactBundle);
}
}
use of com.webcohesion.enunciate.modules.jaxb.model.SchemaInfo in project enunciate by stoicflame.
the class PHPXMLClientModule method usesUnmappableElements.
protected boolean usesUnmappableElements() {
boolean usesUnmappableElements = false;
if (this.jaxbModule != null && this.jaxbModule.getJaxbContext() != null && !this.jaxbModule.getJaxbContext().getSchemas().isEmpty()) {
for (SchemaInfo schemaInfo : this.jaxbModule.getJaxbContext().getSchemas().values()) {
for (TypeDefinition complexType : schemaInfo.getTypeDefinitions()) {
if (!Character.isUpperCase(complexType.getClientSimpleName().charAt(0))) {
warn("%s: PHP requires your class name to be upper-case. Please rename the class or apply the @org.codehaus.enunciate.ClientName annotation to the class.", positionOf(complexType));
usesUnmappableElements = true;
}
for (Element element : complexType.getElements()) {
if (element instanceof ElementRef && element.isElementRefs()) {
info("%s: The PHP client library doesn't fully support the @XmlElementRefs annotation. The items in the collection will be read-only and will only be available to PHP clients in the form of a Hash. Consider redesigning using a collection of a single type.", positionOf(element));
} else if (element.getAnnotation(XmlElements.class) != null) {
info("%s: The PHP client library doesn't fully support the @XmlElements annotation. The items in the collection will be read-only and will only be available to PHP clients in the form of a Hash. Consider redesigning using a collection of a single type.", positionOf(element));
}
}
}
}
}
return usesUnmappableElements;
}
use of com.webcohesion.enunciate.modules.jaxb.model.SchemaInfo in project enunciate by stoicflame.
the class JavaXMLClientModule method copyResources.
protected File copyResources() {
File resourcesDir = getResourcesDir();
resourcesDir.mkdirs();
try {
if (this.jaxwsModule != null) {
for (WsdlInfo wsdlInfo : this.jaxwsModule.getJaxwsContext().getWsdls().values()) {
if (wsdlInfo.getWsdlFile() != null) {
wsdlInfo.getWsdlFile().writeTo(resourcesDir);
}
}
}
for (SchemaInfo schemaInfo : this.jaxbModule.getJaxbContext().getSchemas().values()) {
if (schemaInfo.getSchemaFile() != null) {
schemaInfo.getSchemaFile().writeTo(resourcesDir);
}
}
} catch (IOException e) {
throw new EnunciateException(e);
}
return resourcesDir;
}
use of com.webcohesion.enunciate.modules.jaxb.model.SchemaInfo in project enunciate by stoicflame.
the class CXMLClientModule 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: C XML client will not be generated.");
return;
}
if (usesUnmappableElements()) {
warn("Web service API makes use of elements that cannot be handled by the C XML client. 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.");
}
File srcDir = getSourceDir();
srcDir.mkdirs();
Map<String, Object> model = new HashMap<String, Object>();
String slug = getSlug();
Map<String, String> ns2prefix = this.jaxbModule.getJaxbContext().getNamespacePrefixes();
NameForTypeDefinitionMethod nameForTypeDefinition = new NameForTypeDefinitionMethod(getTypeDefinitionNamePattern(), slug, ns2prefix);
model.put("nameForTypeDefinition", nameForTypeDefinition);
model.put("nameForEnumConstant", new NameForEnumConstantMethod(getEnumConstantNamePattern(), slug, ns2prefix));
TreeMap<String, String> conversions = new TreeMap<String, String>();
for (SchemaInfo schemaInfo : this.jaxbModule.getJaxbContext().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(), "struct " + nameForTypeDefinition.calculateName(typeDefinition));
}
}
}
ClientClassnameForMethod classnameFor = new ClientClassnameForMethod(conversions, this.jaxbModule.getJaxbContext());
model.put("classnameFor", classnameFor);
String sourceFileName = getSourceFileName(slug);
model.put("cFileName", sourceFileName);
model.put("separateCommonCode", isSeparateCommonCode());
model.put("findRootElement", new FindRootElementMethod(this.jaxbModule.getJaxbContext()));
model.put("referencedNamespaces", new ReferencedNamespacesMethod(this.jaxbModule.getJaxbContext()));
model.put("prefix", new PrefixMethod(ns2prefix));
model.put("xmlFunctionIdentifier", new XmlFunctionIdentifierMethod(ns2prefix));
model.put("accessorOverridesAnother", new AccessorOverridesAnotherMethod());
model.put("filename", sourceFileName);
model.put("file", new FileDirective(srcDir, this.enunciate.getLogger()));
model.put("schemas", this.jaxbModule.getJaxbContext().getSchemas().values());
model.put("generatedCodeLicense", this.enunciate.getConfiguration().readGeneratedCodeLicenseFile());
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(), "c.client.library", "C Client Library");
FileArtifact sourceScript = new FileArtifact(getName(), "c.client", new File(srcDir, sourceFileName));
sourceScript.setArtifactType(ArtifactType.sources);
sourceScript.setPublic(false);
// read in the description from file
String description = readResource("library_description.fmt", model, nameForTypeDefinition);
artifactBundle.setDescription(description);
artifactBundle.addArtifact(sourceScript);
if (isSeparateCommonCode()) {
FileArtifact commonSourceHeader = new FileArtifact(getName(), "c.common.client", new File(srcDir, "enunciate-common.c"));
commonSourceHeader.setPublic(false);
commonSourceHeader.setArtifactType(ArtifactType.sources);
commonSourceHeader.setDescription("Common code needed for all projects.");
artifactBundle.addArtifact(commonSourceHeader);
}
this.enunciate.addArtifact(artifactBundle);
}
Aggregations