use of com.webcohesion.enunciate.util.AntPatternMatcher 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.util.AntPatternMatcher in project enunciate by stoicflame.
the class GWTJSONOverlayModule method generateClientSources.
protected File generateClientSources() {
File sourceDir = getSourceDir();
sourceDir.mkdirs();
Map<String, Object> model = new HashMap<String, Object>();
Map<String, String> conversions = getClientPackageConversions();
EnunciateJacksonContext jacksonContext = this.jacksonModule != null ? this.jacksonModule.getJacksonContext() : null;
EnunciateJackson1Context jackson1Context = this.jackson1Module != null ? this.jackson1Module.getJacksonContext() : null;
MergedJsonContext jsonContext = new MergedJsonContext(jacksonContext, jackson1Context);
ClientClassnameForMethod classnameFor = new ClientClassnameForMethod(conversions, jsonContext);
model.put("packageFor", new ClientPackageForMethod(conversions, this.context));
model.put("classnameFor", classnameFor);
model.put("simpleNameFor", new SimpleNameForMethod(classnameFor, jsonContext));
model.put("isAccessorOfTypeLong", new IsAccessorOfTypeLongMethod());
model.put("file", new FileDirective(sourceDir, 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));
AntPatternMatcher matcher = new AntPatternMatcher();
matcher.setPathSeparator(".");
boolean upToDate = isUpToDateWithSources(sourceDir);
if (!upToDate) {
try {
debug("Generating the GWT JSON Overlay...");
if (jacksonContext != null) {
for (TypeDefinition typeDefinition : jacksonContext.getTypeDefinitions()) {
if (!typeDefinition.isSimple() && facetFilter.accept(typeDefinition)) {
model.put("type", typeDefinition);
URL template = typeDefinition.isEnum() ? getTemplateURL("gwt-enum-type.fmt") : getTemplateURL("gwt-type.fmt");
processTemplate(template, model);
}
}
}
if (jackson1Context != null) {
for (com.webcohesion.enunciate.modules.jackson1.model.TypeDefinition typeDefinition : jackson1Context.getTypeDefinitions()) {
if (!typeDefinition.isSimple() && facetFilter.accept(typeDefinition)) {
model.put("type", typeDefinition);
URL template = typeDefinition.isEnum() ? getTemplateURL("gwt-enum-type.fmt") : getTemplateURL("gwt-type.fmt");
processTemplate(template, model);
}
}
}
} catch (IOException e) {
throw new EnunciateException(e);
} catch (TemplateException e) {
throw new EnunciateException(e);
}
} else {
info("Skipping generation of GWT JSON Overlay as everything appears up-to-date...");
}
context.setProperty(LIRBARY_DESCRIPTION_PROPERTY, readLibraryDescription(model));
return sourceDir;
}
use of com.webcohesion.enunciate.util.AntPatternMatcher in project enunciate by stoicflame.
the class JavaJSONClientModule method generateClientSources.
protected File generateClientSources() {
File sourceDir = getSourceDir();
sourceDir.mkdirs();
Map<String, Object> model = new HashMap<String, Object>();
Map<String, String> conversions = getClientPackageConversions();
EnunciateJacksonContext jacksonContext = this.jacksonModule != null ? this.jacksonModule.getJacksonContext() : null;
EnunciateJackson1Context jackson1Context = this.jackson1Module != null ? this.jackson1Module.getJacksonContext() : null;
MergedJsonContext jsonContext = new MergedJsonContext(jacksonContext, jackson1Context);
model.put("packageFor", new ClientPackageForMethod(conversions, this.context));
model.put("classnameFor", new ClientClassnameForMethod(conversions, jsonContext));
model.put("simpleNameFor", new SimpleNameForMethod(new ClientClassnameForMethod(conversions, jsonContext, true), jsonContext));
model.put("file", new FileDirective(sourceDir, this.enunciate.getLogger()));
model.put("generatedCodeLicense", this.enunciate.getConfiguration().readGeneratedCodeLicenseFile());
model.put("annotationValue", new AnnotationValueMethod());
model.put("wrapRootValue", this.jacksonModule == null ? this.jackson1Module.isWrapRootValue() : this.jacksonModule.isWrapRootValue());
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));
AntPatternMatcher matcher = new AntPatternMatcher();
matcher.setPathSeparator(".");
boolean upToDate = isUpToDateWithSources(sourceDir);
if (!upToDate) {
try {
debug("Generating the Java client classes...");
if (jacksonContext != null) {
for (TypeDefinition typeDefinition : jacksonContext.getTypeDefinitions()) {
if (facetFilter.accept(typeDefinition)) {
if (useServerSide(typeDefinition, matcher)) {
copyServerSideType(sourceDir, typeDefinition);
} else {
model.put("type", typeDefinition);
URL template = typeDefinition.isEnum() ? getTemplateURL("client-enum-type.fmt") : typeDefinition.isSimple() ? getTemplateURL("client-simple-type.fmt") : getTemplateURL("client-complex-type.fmt");
processTemplate(template, model);
}
}
}
}
if (jackson1Context != null) {
for (com.webcohesion.enunciate.modules.jackson1.model.TypeDefinition typeDefinition : jackson1Context.getTypeDefinitions()) {
if (facetFilter.accept(typeDefinition)) {
if (useServerSide(typeDefinition, matcher)) {
copyServerSideType(sourceDir, typeDefinition);
} else {
model.put("type", typeDefinition);
URL template = typeDefinition.isEnum() ? getTemplateURL("client-enum-type.fmt") : typeDefinition.isSimple() ? getTemplateURL("client-simple-type.fmt") : getTemplateURL("client-complex-type.fmt");
processTemplate(template, 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;
}
Aggregations