use of com.webcohesion.enunciate.javac.decorations.element.DecoratedTypeElement in project enunciate by stoicflame.
the class PHPJSONClientModule method call.
@Override
public void call(EnunciateContext context) {
if ((this.jacksonModule == null || this.jacksonModule.getJacksonContext() == null || this.jacksonModule.getJacksonContext().getTypeDefinitions().isEmpty()) && (this.jackson1Module == null || this.jackson1Module.getJacksonContext() == null || this.jackson1Module.getJacksonContext().getTypeDefinitions().isEmpty())) {
info("No Jackson JSON data types: PHP JSON client will not be generated.");
return;
}
detectAccessorNamingErrors();
if (usesUnmappableElements()) {
warn("Web service API makes use of elements that cannot be handled by the PHP JSON client. PHP JSON client will not be generated.");
return;
}
Map<String, String> packageToNamespaceConversions = getPackageToNamespaceConversions();
List<DecoratedTypeElement> schemaTypes = new ArrayList<DecoratedTypeElement>();
ExtensionDepthComparator comparator = new ExtensionDepthComparator();
EnunciateJacksonContext jacksonContext = null;
EnunciateJackson1Context jackson1Context = null;
if (this.jacksonModule != null) {
jacksonContext = this.jacksonModule.getJacksonContext();
for (TypeDefinition typeDefinition : jacksonContext.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);
}
}
if (this.jackson1Module != null) {
jackson1Context = this.jackson1Module.getJacksonContext();
for (com.webcohesion.enunciate.modules.jackson1.model.TypeDefinition typeDefinition : jackson1Context.getTypeDefinitions()) {
String pckg = typeDefinition.getPackage().getQualifiedName().toString();
if (!packageToNamespaceConversions.containsKey(pckg)) {
packageToNamespaceConversions.put(pckg, packageToNamespace(pckg));
}
schemaTypes.add(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, jacksonContext, jackson1Context);
model.put("classnameFor", classnameFor);
model.put("typeNameFor", new TypeNameForMethod(packageToNamespaceConversions, jacksonContext, jackson1Context));
model.put("simpleNameFor", new SimpleNameWithParamsMethod(classnameFor));
model.put("phpFileName", getSourceFileName());
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 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 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.json.client.library", "PHP JSON Client Library");
artifactBundle.setPlatform("PHP");
FileArtifact sourceScript = new FileArtifact(getName(), "php.json.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.javac.decorations.element.DecoratedTypeElement in project enunciate by stoicflame.
the class DecoratedTypes method getDeclaredType.
public DeclaredType getDeclaredType(DeclaredType containing, TypeElement type, TypeMirror... typeArgs) {
while (containing instanceof DecoratedDeclaredType) {
containing = ((DecoratedDeclaredType) containing).getDelegate();
}
while (type instanceof DecoratedTypeElement) {
type = ((DecoratedTypeElement) type).getDelegate();
}
TypeMirror[] copy = new TypeMirror[typeArgs.length];
for (int i = 0; i < typeArgs.length; i++) {
TypeMirror t = typeArgs[i];
while (t instanceof DecoratedTypeMirror) {
t = ((DecoratedTypeMirror) t).getDelegate();
}
copy[i] = t;
}
return delegate.getDeclaredType(containing, type, copy);
}
use of com.webcohesion.enunciate.javac.decorations.element.DecoratedTypeElement in project enunciate by stoicflame.
the class DecoratedTypes method getDeclaredType.
public DeclaredType getDeclaredType(TypeElement type, TypeMirror... typeArgs) {
while (type instanceof DecoratedTypeElement) {
type = ((DecoratedTypeElement) type).getDelegate();
}
TypeMirror[] copy = new TypeMirror[typeArgs.length];
for (int i = 0; i < typeArgs.length; i++) {
TypeMirror t = typeArgs[i];
while (t instanceof DecoratedTypeMirror) {
t = ((DecoratedTypeMirror) t).getDelegate();
}
copy[i] = t;
}
return TypeMirrorDecorator.decorate(delegate.getDeclaredType(type, copy), this.env);
}
use of com.webcohesion.enunciate.javac.decorations.element.DecoratedTypeElement in project enunciate by stoicflame.
the class JavaScriptClientModule method call.
@Override
public void call(EnunciateContext context) {
if ((this.jacksonModule == null || this.jacksonModule.getJacksonContext() == null || this.jacksonModule.getJacksonContext().getTypeDefinitions().isEmpty()) && (this.jackson1Module == null || this.jackson1Module.getJacksonContext() == null || this.jackson1Module.getJacksonContext().getTypeDefinitions().isEmpty())) {
info("No Jackson JSON data types: JavaScript client will not be generated.");
return;
}
detectAccessorNamingErrors();
Map<String, String> packageToNamespaceConversions = getPackageToNamespaceConversions();
List<DecoratedTypeElement> schemaTypes = new ArrayList<DecoratedTypeElement>();
ExtensionDepthComparator comparator = new ExtensionDepthComparator();
EnunciateJacksonContext jacksonContext = null;
EnunciateJackson1Context jackson1Context = null;
if (this.jacksonModule != null) {
jacksonContext = this.jacksonModule.getJacksonContext();
for (TypeDefinition typeDefinition : jacksonContext.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);
}
}
if (this.jackson1Module != null) {
jackson1Context = this.jackson1Module.getJacksonContext();
for (com.webcohesion.enunciate.modules.jackson1.model.TypeDefinition typeDefinition : jackson1Context.getTypeDefinitions()) {
String pckg = typeDefinition.getPackage().getQualifiedName().toString();
if (!packageToNamespaceConversions.containsKey(pckg)) {
packageToNamespaceConversions.put(pckg, packageToNamespace(pckg));
}
schemaTypes.add(typeDefinition);
}
}
File srcDir = getSourceDir();
Map<String, Object> model = new HashMap<String, Object>();
model.put("globalName", this.config.getString("[@global]", "javascriptClient"));
model.put("schemaTypes", schemaTypes);
model.put("namespaceFor", new ClientPackageForMethod(packageToNamespaceConversions, this.context));
ClientClassnameForMethod classnameFor = new ClientClassnameForMethod(packageToNamespaceConversions, jacksonContext, jackson1Context);
model.put("classnameFor", classnameFor);
model.put("typeNameFor", new TypeNameForMethod(packageToNamespaceConversions, jacksonContext, jackson1Context));
model.put("simpleNameFor", new SimpleNameWithParamsMethod(classnameFor));
model.put("jsFileName", getSourceFileName());
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 JavaScript data classes...");
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 JavaScript 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(), "js.client.library", "JavaScript Client Library");
artifactBundle.setPlatform("JavaScript");
FileArtifact sourceScript = new FileArtifact(getName(), "javascript.client", bundle);
// binaries and sources are the same thing in js
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.javac.decorations.element.DecoratedTypeElement in project enunciate by stoicflame.
the class RequestParameterFactory method gatherFormObjectParameters.
private static void gatherFormObjectParameters(TypeMirror type, ArrayList<RequestParameter> params, RequestMapping context) {
if (type instanceof DeclaredType) {
Set<String> methods = context.getHttpMethods();
ResourceParameterType defaultType = methods.contains("POST") ? ResourceParameterType.FORM : ResourceParameterType.QUERY;
DecoratedTypeElement typeDeclaration = (DecoratedTypeElement) ElementDecorator.decorate(((DeclaredType) type).asElement(), context.getContext().getContext().getProcessingEnvironment());
for (VariableElement field : ElementFilter.fieldsIn(typeDeclaration.getEnclosedElements())) {
DecoratedVariableElement decorated = (DecoratedVariableElement) field;
if (!decorated.isFinal() && !decorated.isTransient() && decorated.isPublic()) {
params.add(new SimpleRequestParameter(decorated, context, defaultType));
}
}
for (PropertyElement property : typeDeclaration.getProperties()) {
if (property.getSetter() != null) {
params.add(new SimpleRequestParameter(property, context, defaultType));
}
}
if (typeDeclaration.getKind() == ElementKind.CLASS) {
gatherFormObjectParameters(typeDeclaration.getSuperclass(), params, context);
}
}
}
Aggregations