use of com.webcohesion.enunciate.EnunciateException in project enunciate by stoicflame.
the class JavaJSONClientModule method compileClientSources.
protected File compileClientSources(File sourceDir) {
File compileDir = getCompileDir();
compileDir.mkdirs();
// Compile the java files.
if (!isDisableCompile()) {
if (!isUpToDateWithSources(compileDir)) {
List<File> sources = findJavaFiles(sourceDir);
if (sources != null && !sources.isEmpty()) {
String classpath = this.enunciate.writeClasspath(enunciate.getClasspath());
JavaCompiler compiler = JavacTool.create();
List<String> options = Arrays.asList("-source", getJavacSource(), "-target", getJavacTarget(), "-encoding", "UTF-8", "-cp", classpath, "-d", compileDir.getAbsolutePath(), "-nowarn");
JavaCompiler.CompilationTask task = compiler.getTask(null, null, null, options, null, compiler.getStandardFileManager(null, null, null).getJavaFileObjectsFromFiles(sources));
if (!task.call()) {
throw new EnunciateException("Compile failed of Java JSON client-side classes.");
}
} else {
debug("No Java JSON client classes to compile.");
}
} else {
info("Skipping compilation of Java JSON client classes as everything appears up-to-date...");
}
}
return compileDir;
}
use of com.webcohesion.enunciate.EnunciateException in project enunciate by stoicflame.
the class JavaXMLClientModule method compileClientSources.
protected File compileClientSources(File sourceDir) {
File compileDir = getCompileDir();
compileDir.mkdirs();
// Compile the java files.
if (!isDisableCompile()) {
if (!isUpToDateWithSources(compileDir)) {
List<File> sources = findJavaFiles(sourceDir);
if (sources != null && !sources.isEmpty()) {
String classpath = this.enunciate.writeClasspath(enunciate.getClasspath());
JavaCompiler compiler = JavacTool.create();
List<String> options = Arrays.asList("-source", getJavacSource(), "-target", getJavacTarget(), "-encoding", "UTF-8", "-cp", classpath, "-d", compileDir.getAbsolutePath(), "-nowarn");
JavaCompiler.CompilationTask task = compiler.getTask(null, null, null, options, null, compiler.getStandardFileManager(null, null, null).getJavaFileObjectsFromFiles(sources));
if (!task.call()) {
throw new EnunciateException("Compile failed of Java client-side classes.");
}
} else {
debug("No Java XML client classes to compile.");
}
} else {
info("Skipping compilation of Java client classes as everything appears up-to-date...");
}
}
return compileDir;
}
use of com.webcohesion.enunciate.EnunciateException in project enunciate by stoicflame.
the class JavaXMLClientModule method generateClientSources.
protected File generateClientSources() {
File sourceDir = getSourceDir();
sourceDir.mkdirs();
Map<String, Object> model = new HashMap<String, Object>();
Map<String, String> conversions = getClientPackageConversions();
EnunciateJaxbContext jaxbContext = this.jaxbModule.getJaxbContext();
model.put("packageFor", new ClientPackageForMethod(conversions, this.context));
model.put("classnameFor", new ClientClassnameForMethod(conversions, jaxbContext));
model.put("simpleNameFor", new SimpleNameForMethod(new ClientClassnameForMethod(conversions, jaxbContext, true)));
model.put("file", new FileDirective(sourceDir, this.enunciate.getLogger()));
model.put("generatedCodeLicense", this.enunciate.getConfiguration().readGeneratedCodeLicenseFile());
model.put("annotationValue", new AnnotationValueMethod());
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));
boolean upToDate = isUpToDateWithSources(sourceDir);
if (!upToDate) {
try {
debug("Generating the Java client classes...");
HashMap<String, WebFault> allFaults = new HashMap<String, WebFault>();
AntPatternMatcher matcher = new AntPatternMatcher();
matcher.setPathSeparator(".");
if (this.jaxwsModule != null) {
Set<String> seeAlsos = new TreeSet<String>();
// for each endpoint interface.
for (WsdlInfo wsdlInfo : this.jaxwsModule.getJaxwsContext().getWsdls().values()) {
for (EndpointInterface ei : wsdlInfo.getEndpointInterfaces()) {
if (facetFilter.accept(ei)) {
for (WebMethod webMethod : ei.getWebMethods()) {
if (facetFilter.accept(webMethod)) {
for (WebMessage webMessage : webMethod.getMessages()) {
if (webMessage instanceof RequestWrapper) {
model.put("message", webMessage);
processTemplate(getTemplateURL("client-request-bean.fmt"), model);
seeAlsos.add(getBeanName(new ClientClassnameForMethod(conversions, jaxbContext), ((RequestWrapper) webMessage).getRequestBeanName()));
} else if (webMessage instanceof ResponseWrapper) {
model.put("message", webMessage);
processTemplate(getTemplateURL("client-response-bean.fmt"), model);
seeAlsos.add(getBeanName(new ClientClassnameForMethod(conversions, jaxbContext), ((ResponseWrapper) webMessage).getResponseBeanName()));
} else if (webMessage instanceof WebFault) {
WebFault fault = (WebFault) webMessage;
allFaults.put(fault.getQualifiedName().toString(), fault);
}
}
}
}
}
}
}
// gather the annotation information and process the possible beans for each web fault.
for (WebFault webFault : allFaults.values()) {
boolean implicit = webFault.isImplicitSchemaElement();
String faultBean = implicit ? getBeanName(new ClientClassnameForMethod(conversions, jaxbContext), webFault.getImplicitFaultBeanQualifiedName()) : new ClientClassnameForMethod(conversions, jaxbContext).convert(webFault.getExplicitFaultBeanType());
seeAlsos.add(faultBean);
if (implicit) {
model.put("fault", webFault);
processTemplate(getTemplateURL("client-fault-bean.fmt"), model);
}
}
model.put("seeAlsoBeans", seeAlsos);
model.put("baseUri", this.enunciate.getConfiguration().getApplicationRoot());
for (WsdlInfo wsdlInfo : this.jaxwsModule.getJaxwsContext().getWsdls().values()) {
if (wsdlInfo.getWsdlFile() == null) {
throw new EnunciateException("WSDL " + wsdlInfo.getId() + " doesn't have a filename.");
}
for (EndpointInterface ei : wsdlInfo.getEndpointInterfaces()) {
if (facetFilter.accept(ei)) {
model.put("endpointInterface", ei);
model.put("wsdlFileName", wsdlInfo.getFilename());
processTemplate(getTemplateURL("client-endpoint-interface.fmt"), model);
processTemplate(getTemplateURL("client-soap-endpoint-impl.fmt"), model);
}
}
}
for (WebFault webFault : allFaults.values()) {
if (useServerSide(webFault, matcher)) {
copyServerSideType(sourceDir, webFault);
} else {
TypeElement superFault = (TypeElement) ((DeclaredType) webFault.getSuperclass()).asElement();
if (superFault != null && allFaults.containsKey(superFault.getQualifiedName().toString()) && allFaults.get(superFault.getQualifiedName().toString()).isImplicitSchemaElement()) {
model.put("superFault", allFaults.get(superFault.getQualifiedName().toString()));
} else {
model.remove("superFault");
}
model.put("fault", webFault);
processTemplate(getTemplateURL("client-web-fault.fmt"), model);
}
}
}
for (SchemaInfo schemaInfo : this.jaxbModule.getJaxbContext().getSchemas().values()) {
for (TypeDefinition typeDefinition : schemaInfo.getTypeDefinitions()) {
if (facetFilter.accept(typeDefinition)) {
if (useServerSide(typeDefinition, matcher)) {
copyServerSideType(sourceDir, typeDefinition);
} else {
model.put("rootEl", this.jaxbModule.getJaxbContext().findElementDeclaration(typeDefinition));
model.put("type", typeDefinition);
URL template = typeDefinition.isEnum() ? typeDefinition instanceof QNameEnumTypeDefinition ? getTemplateURL("client-qname-enum-type.fmt") : getTemplateURL("client-enum-type.fmt") : typeDefinition.isSimple() ? getTemplateURL("client-simple-type.fmt") : getTemplateURL("client-complex-type.fmt");
processTemplate(template, model);
}
}
}
for (Registry registry : schemaInfo.getRegistries()) {
model.put("registry", registry);
processTemplate(getTemplateURL("client-registry.fmt"), model);
}
}
} catch (IOException e) {
throw new EnunciateException(e);
} catch (TemplateException e) {
throw new EnunciateException(e);
}
} else {
info("Skipping generation of Java client sources as everything appears up-to-date...");
}
context.setProperty(LIRBARY_DESCRIPTION_PROPERTY, readLibraryDescription(model));
return sourceDir;
}
use of com.webcohesion.enunciate.EnunciateException in project enunciate by stoicflame.
the class JavaXMLClientModule method readLibraryDescription.
/**
* Reads a resource into string form.
*
* @return The string form of the resource.
*/
protected String readLibraryDescription(Map<String, Object> model) {
model.put("sample_service_method", findExampleWebMethod());
model.put("sample_resource", findExampleResourceMethod());
model.put("mediaTypeFor", new MediaTypeForMethod());
URL res = JavaXMLClientModule.class.getResource("library_description.fmt");
try {
return processTemplate(res, model);
} catch (TemplateException e) {
throw new EnunciateException(e);
} catch (IOException e) {
throw new EnunciateException(e);
}
}
use of com.webcohesion.enunciate.EnunciateException in project enunciate by stoicflame.
the class EnumTypeDefinition method loadEnumValues.
protected List<EnumValue> loadEnumValues() {
List<VariableElement> enumConstants = enumValues();
List<EnumValue> enumValueMap = new ArrayList<EnumValue>();
HashSet<String> enumValues = new HashSet<String>(enumConstants.size());
for (VariableElement enumConstant : enumConstants) {
if (isIgnored(enumConstant)) {
continue;
}
String value = enumConstant.getSimpleName().toString();
if (context.isHonorJaxb()) {
XmlEnumValue enumValue = enumConstant.getAnnotation(XmlEnumValue.class);
if (enumValue != null) {
value = enumValue.value();
}
}
if (context.isHonorGson()) {
AnnotationValue av = JacksonUtil.findAnnotationValueByName(JacksonUtil.findAnnotationByClassName(enumConstant.getAnnotationMirrors(), JacksonUtil.GSON_SERIALIZED_NAME_CLASS), "value");
if (av != null) {
value = (String) av.getValue();
}
}
JsonProperty jsonProperty = enumConstant.getAnnotation(JsonProperty.class);
if (jsonProperty != null) {
value = jsonProperty.value();
}
if (!enumValues.add(value)) {
throw new EnunciateException(getQualifiedName() + ": duplicate enum value: " + value);
}
enumValueMap.add(new EnumValue(this, enumConstant, enumConstant.getSimpleName().toString(), value));
}
return enumValueMap;
}
Aggregations