use of com.webcohesion.enunciate.modules.jaxrs.model.RootResource in project enunciate by stoicflame.
the class EnunciateJaxrsContext method add.
/**
* Add a root resource to the model.
*
* @param rootResource The root resource to add to the model.
*/
public void add(RootResource rootResource) {
if (rootResource.isInterface()) {
// if the root resource is an interface, don't add it if its implementation has already been added (avoid duplication).
for (RootResource resource : this.rootResources) {
if (((DecoratedTypeMirror) (resource.asType())).isInstanceOf(rootResource)) {
debug("%s was identified as a JAX-RS root resource, but will be ignored because root resource %s implements it.", rootResource.getQualifiedName(), resource.getQualifiedName());
return;
}
}
} else {
// remove any interfaces of this root resource that have been identified as root resources (avoid duplication)
DecoratedTypeMirror rootResourceType = (DecoratedTypeMirror) rootResource.asType();
Iterator<RootResource> it = this.rootResources.iterator();
while (it.hasNext()) {
RootResource resource = it.next();
if (resource.isInterface() && rootResourceType.isInstanceOf(resource)) {
debug("%s was identified as a JAX-RS root resource, but will be ignored because root resource %s implements it.", resource.getQualifiedName(), rootResource.getQualifiedName());
it.remove();
}
}
}
this.rootResources.add(rootResource);
debug("Added %s as a JAX-RS root resource.", rootResource.getQualifiedName());
if (getContext().getProcessingEnvironment().findSourcePosition(rootResource) == null) {
OneTimeLogMessage.SOURCE_FILES_NOT_FOUND.log(getContext());
if (OneTimeLogMessage.SOURCE_FILES_NOT_FOUND.getLogged() <= 3) {
info("Unable to find source file for %s.", rootResource.getQualifiedName());
} else {
debug("Unable to find source file for %s.", rootResource.getQualifiedName());
}
}
}
use of com.webcohesion.enunciate.modules.jaxrs.model.RootResource in project enunciate by stoicflame.
the class EnunciateJaxrsContext method getResourceGroupsByPath.
public List<ResourceGroup> getResourceGroupsByPath(ApiRegistrationContext registrationContext) {
Map<String, PathBasedResourceGroupImpl> resourcesByPath = new HashMap<String, PathBasedResourceGroupImpl>();
FacetFilter facetFilter = registrationContext.getFacetFilter();
for (RootResource rootResource : rootResources) {
if (!facetFilter.accept(rootResource)) {
continue;
}
for (ResourceMethod method : rootResource.getResourceMethods(true)) {
if (facetFilter.accept(method)) {
com.webcohesion.enunciate.metadata.rs.ServiceContextRoot context = method.getAnnotation(com.webcohesion.enunciate.metadata.rs.ServiceContextRoot.class);
com.webcohesion.enunciate.modules.jaxrs.model.Resource resource = method.getParent();
while (context == null && resource != null) {
context = resource.getAnnotation(com.webcohesion.enunciate.metadata.rs.ServiceContextRoot.class);
resource = resource.getParent();
}
String path = method.getFullpath();
PathBasedResourceGroupImpl resourceGroup = resourcesByPath.get(path);
if (resourceGroup == null) {
String contextPath = context != null ? JaxrsModule.sanitizeContextPath(context.value()) : this.relativeContextPath;
resourceGroup = new PathBasedResourceGroupImpl(contextPath, path, new ArrayList<Resource>());
resourcesByPath.put(path, resourceGroup);
}
resourceGroup.getResources().add(new ResourceImpl(method, resourceGroup, registrationContext));
}
}
}
ArrayList<ResourceGroup> resourceGroups = new ArrayList<ResourceGroup>(resourcesByPath.values());
Collections.sort(resourceGroups, new ResourceGroupComparator(this.pathSortStrategy));
return resourceGroups;
}
use of com.webcohesion.enunciate.modules.jaxrs.model.RootResource in project enunciate by stoicflame.
the class EnunciateJaxrsContext method getResourceGroupsByClass.
public List<ResourceGroup> getResourceGroupsByClass(ApiRegistrationContext registrationContext) {
List<ResourceGroup> resourceGroups = new ArrayList<ResourceGroup>();
Set<String> slugs = new TreeSet<String>();
FacetFilter facetFilter = registrationContext.getFacetFilter();
for (RootResource rootResource : rootResources) {
if (!facetFilter.accept(rootResource)) {
continue;
}
String slug = rootResource.getSimpleName().toString();
if (slugs.contains(slug)) {
slug = "";
String[] qualifiedNameTokens = rootResource.getQualifiedName().toString().split("\\.");
for (int i = qualifiedNameTokens.length - 1; i >= 0; i--) {
slug = slug.isEmpty() ? qualifiedNameTokens[i] : slug + "_" + qualifiedNameTokens[i];
if (!slugs.contains(slug)) {
break;
}
}
}
slugs.add(slug);
com.webcohesion.enunciate.metadata.rs.ServiceContextRoot context = rootResource.getAnnotation(com.webcohesion.enunciate.metadata.rs.ServiceContextRoot.class);
com.webcohesion.enunciate.modules.jaxrs.model.Resource resource = rootResource.getParent();
while (context == null && resource != null) {
context = resource.getAnnotation(com.webcohesion.enunciate.metadata.rs.ServiceContextRoot.class);
resource = resource.getParent();
}
String contextPath = context != null ? JaxrsModule.sanitizeContextPath(context.value()) : this.relativeContextPath;
ResourceGroup group = new ResourceClassResourceGroupImpl(rootResource, slug, contextPath, registrationContext);
if (!group.getResources().isEmpty()) {
resourceGroups.add(group);
}
}
Collections.sort(resourceGroups, new ResourceGroupComparator(this.pathSortStrategy));
return resourceGroups;
}
use of com.webcohesion.enunciate.modules.jaxrs.model.RootResource in project enunciate by stoicflame.
the class EnunciateJaxrsContext method getResourceGroupsByAnnotation.
public List<ResourceGroup> getResourceGroupsByAnnotation(ApiRegistrationContext registrationContext) {
Map<String, AnnotationBasedResourceGroupImpl> resourcesByAnnotation = new HashMap<String, AnnotationBasedResourceGroupImpl>();
FacetFilter facetFilter = registrationContext.getFacetFilter();
for (RootResource rootResource : rootResources) {
if (!facetFilter.accept(rootResource)) {
continue;
}
for (ResourceMethod method : rootResource.getResourceMethods(true)) {
if (facetFilter.accept(method)) {
com.webcohesion.enunciate.metadata.rs.ResourceGroup annotation = AnnotationUtils.getResourceGroup(method);
com.webcohesion.enunciate.modules.jaxrs.model.Resource resource = method.getParent();
while (annotation == null && resource != null) {
annotation = AnnotationUtils.getResourceGroup(resource);
resource = resource.getParent();
}
com.webcohesion.enunciate.metadata.rs.ServiceContextRoot context = method.getAnnotation(com.webcohesion.enunciate.metadata.rs.ServiceContextRoot.class);
resource = method.getParent();
while (context == null && resource != null) {
context = resource.getAnnotation(com.webcohesion.enunciate.metadata.rs.ServiceContextRoot.class);
resource = resource.getParent();
}
String label = annotation == null ? "Other" : annotation.value();
String description = annotation == null ? null : annotation.description();
if ("##default".equals(description)) {
description = null;
}
AnnotationBasedResourceGroupImpl resourceGroup = resourcesByAnnotation.get(label);
if (resourceGroup == null) {
String contextPath = context != null ? JaxrsModule.sanitizeContextPath(context.value()) : this.relativeContextPath;
resourceGroup = new AnnotationBasedResourceGroupImpl(contextPath, label, new SortedList<Resource>(new ResourceComparator(this.pathSortStrategy)), this.pathSortStrategy);
resourcesByAnnotation.put(label, resourceGroup);
}
resourceGroup.setDescriptionIfNull(description);
resourceGroup.getResources().add(new ResourceImpl(method, resourceGroup, registrationContext));
}
}
}
ArrayList<ResourceGroup> resourceGroups = new ArrayList<ResourceGroup>(resourcesByAnnotation.values());
Collections.sort(resourceGroups, new ResourceGroupComparator(this.pathSortStrategy));
return resourceGroups;
}
use of com.webcohesion.enunciate.modules.jaxrs.model.RootResource in project enunciate by stoicflame.
the class JaxrsRootResourceClassListArtifact method exportTo.
@Override
public void exportTo(File fileOrDirectory, Enunciate enunciate) throws IOException {
FileWriter out = new FileWriter(fileOrDirectory.isDirectory() ? new File(fileOrDirectory, getName()) : fileOrDirectory);
Set<String> written = new HashSet<String>();
for (RootResource resource : this.jaxrsContext.getRootResources()) {
if (written.add(resource.getQualifiedName().toString())) {
out.write(resource.getQualifiedName() + "\n");
}
}
out.flush();
out.close();
}
Aggregations