use of com.webcohesion.enunciate.EnunciateException in project enunciate by stoicflame.
the class AnnotationValueMethod 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 annotationValue method must have a declaration as a parameter.");
}
TemplateModel from = (TemplateModel) list.get(0);
Object unwrapped = DeepUnwrap.unwrap(from);
String method = "value";
if (list.size() > 1) {
method = (String) DeepUnwrap.unwrap((TemplateModel) list.get(1));
}
if (unwrapped instanceof DecoratedAnnotationMirror) {
return invoke(method, ((DecoratedAnnotationMirror) unwrapped));
}
throw new EnunciateException(String.format("Unsupported method %s on %s", method, unwrapped));
}
use of com.webcohesion.enunciate.EnunciateException in project enunciate by stoicflame.
the class JAXBUtil method getAdaptersOfPackage.
/**
* Gets the adapters of the specified package.
*
* @param pckg the package for which to get the adapters.
* @param context The context.
* @return The adapters for the package.
*/
private static Map<String, XmlJavaTypeAdapter> getAdaptersOfPackage(PackageElement pckg, EnunciateJaxbContext context) {
if (pckg == null) {
return null;
}
Map<String, Map<String, XmlJavaTypeAdapter>> adaptersOfAllPackages = (Map<String, Map<String, XmlJavaTypeAdapter>>) context.getContext().getProperty(ADAPTERS_BY_PACKAGE_PROPERTY);
if (adaptersOfAllPackages == null) {
adaptersOfAllPackages = new HashMap<String, Map<String, XmlJavaTypeAdapter>>();
context.getContext().setProperty(ADAPTERS_BY_PACKAGE_PROPERTY, adaptersOfAllPackages);
}
Map<String, XmlJavaTypeAdapter> adaptersOfPackage = adaptersOfAllPackages.get(pckg.getQualifiedName().toString());
if (adaptersOfPackage == null) {
adaptersOfPackage = new HashMap<String, XmlJavaTypeAdapter>();
adaptersOfAllPackages.put(pckg.getQualifiedName().toString(), adaptersOfPackage);
XmlJavaTypeAdapter javaType = pckg.getAnnotation(XmlJavaTypeAdapter.class);
XmlJavaTypeAdapters javaTypes = pckg.getAnnotation(XmlJavaTypeAdapters.class);
if ((javaType != null) || (javaTypes != null)) {
ArrayList<XmlJavaTypeAdapter> allAdaptedTypes = new ArrayList<XmlJavaTypeAdapter>();
if (javaType != null) {
allAdaptedTypes.add(javaType);
}
if (javaTypes != null) {
allAdaptedTypes.addAll(Arrays.asList(javaTypes.value()));
}
for (final XmlJavaTypeAdapter adaptedTypeInfo : allAdaptedTypes) {
DecoratedTypeMirror typeMirror = Annotations.mirrorOf(new Callable<Class<?>>() {
@Override
public Class<?> call() throws Exception {
return adaptedTypeInfo.type();
}
}, context.getContext().getProcessingEnvironment(), XmlJavaTypeAdapter.DEFAULT.class);
if (typeMirror == null) {
throw new EnunciateException("Package " + pckg.getQualifiedName() + ": a type must be specified in " + XmlJavaTypeAdapter.class.getName() + " at the package-level.");
}
if (!(typeMirror instanceof DeclaredType)) {
throw new EnunciateException("Package " + pckg.getQualifiedName() + ": unadaptable type: " + typeMirror);
}
TypeElement typeDeclaration = (TypeElement) ((DeclaredType) typeMirror).asElement();
if (typeDeclaration == null) {
throw new EnunciateException("Element not found: " + typeMirror);
}
adaptersOfPackage.put(typeDeclaration.getQualifiedName().toString(), adaptedTypeInfo);
}
}
}
return adaptersOfPackage;
}
use of com.webcohesion.enunciate.EnunciateException in project enunciate by stoicflame.
the class GWTJSONOverlayModule method packageArtifacts.
protected File packageArtifacts(File sourceDir) {
File packageDir = getPackageDir();
packageDir.mkdirs();
try {
String jarName = getJarName();
File jarFile = new File(packageDir, jarName);
if (!isUpToDateWithSources(jarFile)) {
boolean anyFiles = this.enunciate.jar(jarFile, getManifest(), sourceDir);
if (!anyFiles) {
jarFile = null;
}
} else {
info("Skipping creation of the GWT overlay source jar as everything appears up-to-date...");
}
ClientLibraryJavaArtifact artifactBundle = new ClientLibraryJavaArtifact(getName(), "gwt.json.overlay", "GWT JSON Overlay");
artifactBundle.setGroupId(getGroupId());
artifactBundle.setArtifactId(getArtifactId());
artifactBundle.setVersion(getVersion());
artifactBundle.setPlatform("Google Web Toolkit");
// read in the description from file:
artifactBundle.setDescription((String) context.getProperty(LIRBARY_DESCRIPTION_PROPERTY));
FileArtifact sourcesJar = new FileArtifact(getName(), "gwt.json.overlay.sources", jarFile);
sourcesJar.setDescription("The sources for the GWT JSON overlay.");
sourcesJar.setPublic(false);
sourcesJar.setArtifactType(ArtifactType.sources);
artifactBundle.addArtifact(sourcesJar);
this.enunciate.addArtifact(sourcesJar);
this.enunciate.addArtifact(artifactBundle);
} catch (IOException e) {
throw new EnunciateException(e);
}
return packageDir;
}
use of com.webcohesion.enunciate.EnunciateException in project enunciate by stoicflame.
the class IDLModule method getSchemaConfigs.
public Map<String, SchemaConfig> getSchemaConfigs() {
HashMap<String, SchemaConfig> configs = new HashMap<String, SchemaConfig>();
List<HierarchicalConfiguration> schemas = this.config.configurationsAt("schema");
for (HierarchicalConfiguration schema : schemas) {
SchemaConfig schemaConfig = new SchemaConfig();
schemaConfig.setAppinfo(schema.getString("[@appinfo]", null));
schemaConfig.setFilename(schema.getString("[@filename]", null));
schemaConfig.setJaxbBindingVersion(schema.getString("[@jaxbBindingVersion]", null));
schemaConfig.setLocation(schema.getString("[@location]", null));
String ns = schema.getString("[@namespace]", null);
if ("".equals(ns)) {
// default namspace to be represented as null.
ns = null;
}
schemaConfig.setNamespace(ns);
String useFile = schema.getString("[@useFile]", null);
if (useFile != null) {
File file = resolveFile(useFile);
if (!file.exists()) {
throw new EnunciateException(String.format("Invalid schema config: file %s does not exist.", useFile));
}
schemaConfig.setUseFile(file);
}
configs.put(schemaConfig.getNamespace(), schemaConfig);
}
return configs;
}
use of com.webcohesion.enunciate.EnunciateException in project enunciate by stoicflame.
the class JavaJSONClientModule method packageArtifacts.
protected File packageArtifacts(File sourceDir, File compileDir) {
File packageDir = getPackageDir();
packageDir.mkdirs();
try {
String jarName = getJarName();
File clientJarFile = null;
if (!isDisableCompile()) {
clientJarFile = new File(packageDir, jarName);
if (!isUpToDateWithSources(clientJarFile)) {
if (isBundleSourcesWithClasses()) {
boolean anyFiles = this.enunciate.jar(clientJarFile, getManifest(), sourceDir, compileDir);
if (!anyFiles) {
clientJarFile = null;
}
} else {
boolean anyFiles = this.enunciate.jar(clientJarFile, getManifest(), compileDir);
if (!anyFiles) {
clientJarFile = null;
}
}
} else {
info("Skipping creation of Java client jar as everything appears up-to-date...");
}
}
File clientSourcesJarFile = null;
if (!isBundleSourcesWithClasses()) {
clientSourcesJarFile = new File(packageDir, jarName.replaceFirst("\\.jar", "-json-sources.jar"));
if (!isUpToDateWithSources(clientSourcesJarFile)) {
boolean anyFiles = this.enunciate.zip(clientSourcesJarFile, sourceDir);
if (!anyFiles) {
clientSourcesJarFile = null;
}
} else {
info("Skipping creation of the Java client source jar as everything appears up-to-date...");
}
}
ClientLibraryJavaArtifact artifactBundle = new ClientLibraryJavaArtifact(getName(), "java.json.client.library", "Java JSON Client Library");
artifactBundle.setGroupId(getGroupId());
artifactBundle.setArtifactId(getArtifactId());
artifactBundle.setVersion(getVersion());
artifactBundle.setPlatform("Java (Version 5+)");
// read in the description from file:
artifactBundle.setDescription((String) context.getProperty(LIRBARY_DESCRIPTION_PROPERTY));
if (clientJarFile != null) {
FileArtifact binariesJar = new FileArtifact(getName(), "java.json.client.library.binaries", clientJarFile);
binariesJar.setDescription("The binaries for the Java JSON client library.");
binariesJar.setPublic(false);
binariesJar.setArtifactType(ArtifactType.binaries);
artifactBundle.addArtifact(binariesJar);
this.enunciate.addArtifact(binariesJar);
}
if (clientSourcesJarFile != null) {
FileArtifact sourcesJar = new FileArtifact(getName(), "java.json.client.library.sources", clientSourcesJarFile);
sourcesJar.setDescription("The sources for the Java JSON client library.");
sourcesJar.setPublic(false);
sourcesJar.setArtifactType(ArtifactType.sources);
artifactBundle.addArtifact(sourcesJar);
this.enunciate.addArtifact(sourcesJar);
}
if (clientJarFile != null || clientSourcesJarFile != null) {
this.enunciate.addArtifact(artifactBundle);
}
} catch (IOException e) {
throw new EnunciateException(e);
}
return packageDir;
}
Aggregations