Author: xcoulon
Date: 2011-06-07 18:25:07 -0400 (Tue, 07 Jun 2011)
New Revision: 31892
Added:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/utils/CollectionFilterUtils.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/utils/ObjectUtils.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/EnumElementChange.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/ResourceMapping.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/ResourceMethodMapping.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/ResourceMethodNode.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Route.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/RouteEndpoint.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Routes.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/icons/systemprocess.gif
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/WaitWhileBuildingElement.java
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/metamodel/
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/metamodel/MediaTypeCapabilitiesTestCase.java
Log:
Added missing files...
Added:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/utils/CollectionFilterUtils.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/utils/CollectionFilterUtils.java
(rev 0)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/utils/CollectionFilterUtils.java 2011-06-07
22:25:07 UTC (rev 31892)
@@ -0,0 +1,57 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Xavier Coulon - Initial API and implementation
+ ******************************************************************************/
+
+package org.jboss.tools.ws.jaxrs.core.internal.utils;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.jdt.core.IMember;
+import org.jboss.tools.ws.jaxrs.core.metamodel.BaseElement;
+import org.jboss.tools.ws.jaxrs.core.metamodel.BaseElement.EnumKind;
+
+/**
+ * Collection filter utility class.
+ * @author xcoulon
+ *
+ */
+public final class CollectionFilterUtils {
+
+ /**
+ * Private constructor of the utility class.
+ */
+ private CollectionFilterUtils() {
+
+ }
+
+ /**
+ * Filter elements in the given collection, given their JAX-RS kind.
+ * @param <T> the java type of the elements in the collection
+ * @param elements > the collection of elements to filter
+ * @param kind the JAX-RS kind to match in the filter
+ * @return the matching elements
+ */
+ public static <T extends BaseElement<? extends IMember>> List<T>
filterElementsByKind(final Collection<T> elements,
+ final BaseElement.EnumKind... kind) {
+ List<T> matches = new ArrayList<T>();
+ List<EnumKind> kinds = Arrays.asList(kind);
+ for (T element : elements) {
+ if (kinds.contains(element.getKind())) {
+ matches.add(element);
+ }
+ }
+ return Collections.unmodifiableList(matches);
+ }
+
+}
Added:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/utils/ObjectUtils.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/utils/ObjectUtils.java
(rev 0)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/utils/ObjectUtils.java 2011-06-07
22:25:07 UTC (rev 31892)
@@ -0,0 +1,20 @@
+package org.jboss.tools.ws.jaxrs.core.internal.utils;
+
+public class ObjectUtils {
+
+ private ObjectUtils() {
+
+ }
+
+ /**
+ * @param nextHTTPMethod
+ * @return
+ */
+ public static boolean compare(Object o1, Object o2) {
+ if ((o1 != null && !o1.equals(o2)) || (o2 != null && !o2.equals(o1)))
{
+ Logger.debug(" Value changed: " + o1 + " -> " + o2);
+ return true;
+ }
+ return false;
+ }
+}
Added:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/EnumElementChange.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/EnumElementChange.java
(rev 0)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/EnumElementChange.java 2011-06-07
22:25:07 UTC (rev 31892)
@@ -0,0 +1,7 @@
+package org.jboss.tools.ws.jaxrs.core.metamodel;
+
+public enum EnumElementChange {
+
+ NONE, KIND, MAPPING;
+
+}
Added:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/ResourceMapping.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/ResourceMapping.java
(rev 0)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/ResourceMapping.java 2011-06-07
22:25:07 UTC (rev 31892)
@@ -0,0 +1,174 @@
+package org.jboss.tools.ws.jaxrs.core.metamodel;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.jboss.tools.ws.jaxrs.core.internal.builder.JAXRSAnnotationsScanner;
+import org.jboss.tools.ws.jaxrs.core.internal.utils.ObjectUtils;
+import org.jboss.tools.ws.jaxrs.core.utils.JdtUtils;
+import org.jboss.tools.ws.jaxrs.core.utils.ResourceMethodAnnotatedParameter;
+
+public class ResourceMapping {
+
+ private final Resource resource;
+
+ /**
+ * the default consumed media type capabilities offered by this resource.
+ * May be overridden at method level
+ */
+ private final MediaTypeCapabilities consumedMediaTypes;
+
+ /**
+ * the default produced media type capabilities offered by this resource.
+ * May be overridden at method level
+ */
+ private final MediaTypeCapabilities producedMediaTypes;
+
+ /**
+ * The URI Path Template Fragment resolve from the type-level
+ * <code>javax.ws.rs.Path</code> annotation.
+ */
+ private String uriPathTemplateFragment = null;
+
+ private final List<ResourceMethodAnnotatedParameter> pathParams = null;
+
+ private final List<ResourceMethodAnnotatedParameter> queryParams = null;
+
+ /**
+ * Full constructor using the inner 'MediaTypeCapabilitiesBuilder' static
+ * class.
+ *
+ * @param builder
+ */
+ public ResourceMapping(final Resource resource) {
+ this.resource = resource;
+ this.consumedMediaTypes = new MediaTypeCapabilities(resource.getJavaElement());
+ this.producedMediaTypes = new MediaTypeCapabilities(resource.getJavaElement());
+ }
+
+ /**
+ * @return the resourceMethod
+ */
+ public Resource getResource() {
+ return resource;
+ }
+
+ /**
+ * @param javaMethod
+ * @param compilationUnit
+ * @throws JavaModelException
+ * @throws CoreException
+ */
+ public Set<EnumElementChange> merge(CompilationUnit compilationUnit) throws
JavaModelException, CoreException {
+ Set<EnumElementChange> changes = new HashSet<EnumElementChange>();
+ IType javaType = resource.getJavaElement();
+ // resource method
+ String newValue = (String) JdtUtils.resolveAnnotationAttributeValue(javaType,
compilationUnit, Path.class,
+ "value");
+ if (ObjectUtils.compare(uriPathTemplateFragment, newValue)) {
+ if (uriPathTemplateFragment == null || newValue == null) {
+ changes.add(EnumElementChange.KIND);
+ } else {
+ changes.add(EnumElementChange.MAPPING);
+ }
+ this.uriPathTemplateFragment = newValue;
+ }
+ if
(this.consumedMediaTypes.merge(JAXRSAnnotationsScanner.resolveMediaTypeCapabilities(javaType,
+ compilationUnit, Consumes.class))) {
+ changes.add(EnumElementChange.MAPPING);
+ }
+ if
(this.producedMediaTypes.merge(JAXRSAnnotationsScanner.resolveMediaTypeCapabilities(javaType,
+ compilationUnit, Produces.class))) {
+ changes.add(EnumElementChange.MAPPING);
+ }
+ return changes;
+ }
+
+ /*
+ * private static final String resolveBaseURIPathTemplate(Resource resource)
+ * { if (resource.isRootResource()) { return uriPathTemplateBufferTemplate;
+ * } return new StringBuffer(resolveBaseURIPathTemplate(resource.get));
+ * uriPathTemplateBuffer.append("/").append(resourceUriPathTemplate); return
+ * uriPathTemplateBuffer.toString(); }
+ *
+ * private static String computeFullUriPathTemplate(ResourceMethodMapping
+ * mapping) { String uriPathTemplate = mapping.getUriPathTemplateFragment();
+ * List<ResourceMethodAnnotatedParameter> queryParams =
+ * mapping.getQueryParams(); String baseURIPathTemplate =
+ * resolveBaseURIPathTemplate
+ * (mapping.getResourceMethod().getParentResource()); StringBuffer
+ * uriPathTemplateBuffer = new StringBuffer(baseURIPathTemplate);
+ * uriPathTemplateBuffer.append(uriPathTemplate); if (queryParams != null &&
+ * !queryParams.isEmpty()) { uriPathTemplateBuffer.append("?"); for
+ * (Iterator<ResourceMethodAnnotatedParameter> queryParamIterator =
+ * queryParams.iterator(); queryParamIterator .hasNext();) {
+ * ResourceMethodAnnotatedParameter queryParam = queryParamIterator.next();
+ * uriPathTemplateBuffer
+ * .append(queryParam.getAnnotationValue()).append("={")
+ * .append(queryParam.getParameterType()).append("}"); if
+ * (queryParamIterator.hasNext()) { uriPathTemplateBuffer.append("&"); }
+ *
+ * }
+ *
+ * } return uriPathTemplateBuffer.toString().replaceAll("/\\*",
+ * "/").replaceAll("///", "/").replaceAll("//",
"/"); }
+ */
+
+ /**
+ * @return the uriPathTemplateFragment
+ */
+ public final String getUriPathTemplateFragment() {
+ return uriPathTemplateFragment;
+ }
+
+ @Override
+ public final String toString() {
+ StringBuffer buffer = new StringBuffer();
+ String uriPathTemplate = getUriPathTemplateFragment();
+ if (uriPathTemplate != null) {
+ buffer.append(uriPathTemplate);
+ buffer.append(" ");
+ }
+ buffer.append("{consumes:").append(consumedMediaTypes).append("
produces:").append(producedMediaTypes)
+ .append("}");
+ return buffer.toString();
+ }
+
+ /**
+ * @return the Consumed MediaTypes
+ */
+ public final MediaTypeCapabilities getConsumedMediaTypes() {
+ return consumedMediaTypes;
+ }
+
+ /**
+ * @return the Produced MediaTypes
+ */
+ public final MediaTypeCapabilities getProcucedMediaTypes() {
+ return producedMediaTypes;
+ }
+
+ /**
+ * @return the queryParams
+ */
+ public final List<ResourceMethodAnnotatedParameter> getQueryParams() {
+ return queryParams;
+ }
+
+ /**
+ * @return the pathParams
+ */
+ public final List<ResourceMethodAnnotatedParameter> getPathParams() {
+ return pathParams;
+ }
+
+}
Added:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/ResourceMethodMapping.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/ResourceMethodMapping.java
(rev 0)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/ResourceMethodMapping.java 2011-06-07
22:25:07 UTC (rev 31892)
@@ -0,0 +1,364 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Xavier Coulon - Initial API and implementation
+ ******************************************************************************/
+
+package org.jboss.tools.ws.jaxrs.core.metamodel;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jdt.core.IMethod;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.IAnnotationBinding;
+import org.eclipse.osgi.util.NLS;
+import org.jboss.tools.ws.jaxrs.core.internal.builder.JAXRSAnnotationsScanner;
+import org.jboss.tools.ws.jaxrs.core.internal.builder.JaxrsMetamodelBuilder;
+import org.jboss.tools.ws.jaxrs.core.internal.utils.ObjectUtils;
+import org.jboss.tools.ws.jaxrs.core.internal.utils.ValidationMessages;
+import org.jboss.tools.ws.jaxrs.core.utils.JdtUtils;
+import org.jboss.tools.ws.jaxrs.core.utils.ResourceMethodAnnotatedParameter;
+
+public class ResourceMethodMapping {
+
+ private final ResourceMethod resourceMethod;
+
+ private HTTPMethod httpMethod;
+
+ private final MediaTypeCapabilities consumedMediaTypes;
+
+ private final MediaTypeCapabilities producedMediaTypes;
+
+ private String uriPathTemplateFragment = null;
+
+ private List<ResourceMethodAnnotatedParameter> pathParams = null;
+
+ private List<ResourceMethodAnnotatedParameter> queryParams = null;
+
+ /**
+ * Full constructor using the inner 'MediaTypeCapabilitiesBuilder' static
+ * class.
+ *
+ * @param builder
+ */
+ public ResourceMethodMapping(final ResourceMethod resourceMethod) {
+ this.resourceMethod = resourceMethod;
+ this.consumedMediaTypes = new MediaTypeCapabilities(resourceMethod.getJavaElement());
+ this.producedMediaTypes = new MediaTypeCapabilities(resourceMethod.getJavaElement());
+ }
+
+ /**
+ * @return the resourceMethod
+ */
+ public ResourceMethod getResourceMethod() {
+ return resourceMethod;
+ }
+
+ /**
+ * @param javaMethod
+ * @param compilationUnit
+ * @throws JavaModelException
+ * @throws CoreException
+ * @throws InvalidModelElementException
+ */
+ public boolean merge(CompilationUnit compilationUnit) throws JavaModelException,
CoreException,
+ InvalidModelElementException {
+ boolean changed = false;
+ IMethod javaMethod = resourceMethod.getJavaElement();
+ HTTPMethod nextHTTPMethod = resolveHTTPMethod(compilationUnit);
+ if (ObjectUtils.compare(this.httpMethod, nextHTTPMethod)) {
+ this.httpMethod = nextHTTPMethod;
+ changed = true;
+ }
+ // resource method
+ String nextValue = (String) JdtUtils.resolveAnnotationAttributeValue(javaMethod,
compilationUnit, Path.class,
+ "value");
+ if (ObjectUtils.compare(this.uriPathTemplateFragment, nextValue)) {
+ this.uriPathTemplateFragment = nextValue;
+ changed = true;
+ }
+ List<ResourceMethodAnnotatedParameter> nextPathParams =
JdtUtils.resolveMethodParameters(javaMethod,
+ compilationUnit, PathParam.class);
+ if (ObjectUtils.compare(this.pathParams, nextPathParams)) {
+ this.pathParams = nextPathParams;
+ changed = true;
+ }
+ List<ResourceMethodAnnotatedParameter> nextQueryParams =
JdtUtils.resolveMethodParameters(javaMethod,
+ compilationUnit, QueryParam.class);
+ if (ObjectUtils.compare(this.queryParams, nextQueryParams)) {
+ this.queryParams = nextQueryParams;
+ changed = true;
+ }
+ changed = (changed |
this.consumedMediaTypes.merge(JAXRSAnnotationsScanner.resolveMediaTypeCapabilities(
+ javaMethod, compilationUnit, Consumes.class)));
+ changed = (changed |
this.producedMediaTypes.merge(JAXRSAnnotationsScanner.resolveMediaTypeCapabilities(
+ javaMethod, compilationUnit, Produces.class)));
+ return changed;
+ }
+
+ /*
+ * private static final String resolveBaseURIPathTemplate(Resource resource)
+ * { String resourceUriPathTemplate =
+ * resource.getMapping().getUriPathTemplateFragment(); if
+ * (resource.isRootResource()) { return resourceUriPathTemplate; }
+ * StringBuffer uriPathTemplateBuffer = new
+ * StringBuffer(resolveBaseURIPathTemplate());
+ * uriPathTemplateBuffer.append("/").append(resourceUriPathTemplate); return
+ * uriPathTemplateBuffer.toString(); }
+ *
+ * private static String computeFullUriPathTemplate(ResourceMethodMapping
+ * mapping) { String uriPathTemplate = mapping.getUriPathTemplateFragment();
+ * List<ResourceMethodAnnotatedParameter> queryParams =
+ * mapping.getQueryParams(); String baseURIPathTemplate =
+ * resolveBaseURIPathTemplate
+ * (mapping.getResourceMethod().getParentResource()); StringBuffer
+ * uriPathTemplateBuffer = new StringBuffer(baseURIPathTemplate);
+ * uriPathTemplateBuffer.append(uriPathTemplate); if (queryParams != null &&
+ * !queryParams.isEmpty()) { uriPathTemplateBuffer.append("?"); for
+ * (Iterator<ResourceMethodAnnotatedParameter> queryParamIterator =
+ * queryParams.iterator(); queryParamIterator .hasNext();) {
+ * ResourceMethodAnnotatedParameter queryParam = queryParamIterator.next();
+ * uriPathTemplateBuffer
+ * .append(queryParam.getAnnotationValue()).append("={")
+ * .append(queryParam.getParameterType()).append("}"); if
+ * (queryParamIterator.hasNext()) { uriPathTemplateBuffer.append("&"); }
+ *
+ * }
+ *
+ * } return uriPathTemplateBuffer.toString().replaceAll("/\\*",
+ * "/").replaceAll("///", "/").replaceAll("//",
"/"); }
+ */
+ private HTTPMethod resolveHTTPMethod(CompilationUnit compilationUnit) {
+ for (String httpMethodName :
resourceMethod.getMetamodel().getHttpMethods().getTypeNames()) {
+ IAnnotationBinding httpMethodAnnotationBinding = JdtUtils.resolveAnnotationBinding(
+ resourceMethod.getJavaElement(), compilationUnit, httpMethodName);
+ if (httpMethodAnnotationBinding != null) {
+ // stop iterating
+ return resourceMethod.getMetamodel().getHttpMethods().getByTypeName(httpMethodName);
+ }
+ }
+ return null;
+ }
+
+ /*
+ * private static final MediaTypeCapabilities resolveMediaTypes(final
+ * MediaTypeCapabilities resourceMediaTypes, final MediaTypeCapabilities
+ * methodMediaTypes) { if (!methodMediaTypes.isEmpty()) { return
+ * methodMediaTypes; } else if (resourceMediaTypes != null) { return
+ * resourceMediaTypes; } return null; }
+ */
+
+ /**
+ * Validates the URI Mapping by checking that all
+ * <code>javax.ws.rs.PathParam</code> annotation values match a parameter
in
+ * the URI Path Template fragment defined by the value of the
+ * <code>java.ws.rs.Path</code> annotation value.
+ *
+ * @throws CoreException
+ *
+ */
+ public void validate() throws CoreException {
+ if (uriPathTemplateFragment != null) {
+ List<String> uriTemplateParams =
extractParamsFromUriTemplateFragment(uriPathTemplateFragment);
+ for (ResourceMethodAnnotatedParameter pathParam : pathParams) {
+ String param = pathParam.getAnnotationValue();
+ if (!uriTemplateParams.contains(param)) {
+ IMarker marker = resourceMethod.getJavaElement().getResource()
+ .createMarker(JaxrsMetamodelBuilder.JAXRS_PROBLEM);
+ marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
+ String message = NLS.bind(ValidationMessages.unbound_parameter, "'" +
param + "'"); //$NON-NLS-1$
+ marker.setAttribute(IMarker.MESSAGE, message);
+ marker.setAttribute(IMarker.LINE_NUMBER, pathParam.getLineNumber());
+ marker.setAttribute(IMarker.CHAR_START, pathParam.getCharStart());
+ marker.setAttribute(IMarker.CHAR_END, pathParam.getCharEnd());
+ }
+ }
+ }
+ }
+
+ private static List<String> extractParamsFromUriTemplateFragment(String fragment)
{
+ List<String> params = new ArrayList<String>();
+ int beginIndex = -1;
+ while ((beginIndex = fragment.indexOf("{", beginIndex + 1)) != -1) {
+ int semicolonIndex = fragment.indexOf(":", beginIndex);
+ int closingCurlyBraketIndex = fragment.indexOf("}", beginIndex);
+ int endIndex = semicolonIndex != -1 ? semicolonIndex : closingCurlyBraketIndex;
+ params.add(fragment.substring(beginIndex + 1, endIndex).trim());
+ }
+ return params;
+ }
+
+ /**
+ * @return the httpMethod
+ */
+ public final HTTPMethod getHTTPMethod() {
+ return httpMethod;
+ }
+
+ /**
+ * @return the uriPathTemplateFragment
+ */
+ public final String getUriPathTemplateFragment() {
+ return uriPathTemplateFragment;
+ }
+
+ public boolean matches(HTTPMethod httpMethod, String uriPathTemplateFragment, String
consumes, String produces) {
+ if (httpMethod != null && !httpMethod.equals(this.httpMethod)) {
+ return false;
+ }
+ if (this.httpMethod != null && !this.httpMethod.equals(httpMethod)) {
+ return false;
+ }
+ if (uriPathTemplateFragment != null &&
!uriPathTemplateFragment.equals(this.uriPathTemplateFragment)) {
+ return false;
+ }
+ if (this.uriPathTemplateFragment != null &&
!this.uriPathTemplateFragment.equals(uriPathTemplateFragment)) {
+ return false;
+ }
+ if (consumedMediaTypes != null && consumes != null &&
!consumedMediaTypes.contains(consumes)) {
+ return false;
+ }
+ if (producedMediaTypes != null && produces != null &&
!producedMediaTypes.contains(produces)) {
+ return false;
+ }
+ return true;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public final String toString() {
+ StringBuffer buffer = new StringBuffer();
+ if (httpMethod != null) {
+ buffer.append(httpMethod.getHttpVerb());
+ buffer.append(" ");
+ }
+ String uriPathTemplate = getUriPathTemplateFragment();
+ if (uriPathTemplate != null) {
+ buffer.append(uriPathTemplate);
+ buffer.append(" ");
+ }
+ buffer.append("{Accept:").append(consumedMediaTypes).append("
Content-type: ").append(producedMediaTypes)
+ .append("}");
+ return buffer.toString();
+ }
+
+ /**
+ * @return the Consumed MediaTypes
+ */
+ public final MediaTypeCapabilities getConsumedMediaTypes() {
+ return consumedMediaTypes;
+ }
+
+ /**
+ * @return the Produced MediaTypes
+ */
+ public final MediaTypeCapabilities getProcucedMediaTypes() {
+ return producedMediaTypes;
+ }
+
+ /**
+ * @return the queryParams
+ */
+ public final List<ResourceMethodAnnotatedParameter> getQueryParams() {
+ return queryParams;
+ }
+
+ /**
+ * @return the pathParams
+ */
+ public final List<ResourceMethodAnnotatedParameter> getPathParams() {
+ return pathParams;
+ }
+
+ /**
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public final int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((httpMethod == null) ? 0 : httpMethod.hashCode());
+ result = prime * result + ((consumedMediaTypes == null) ? 0 :
consumedMediaTypes.hashCode());
+ result = prime * result + ((producedMediaTypes == null) ? 0 :
producedMediaTypes.hashCode());
+ result = prime * result + ((queryParams == null) ? 0 : queryParams.hashCode());
+ result = prime * result + ((uriPathTemplateFragment == null) ? 0 :
uriPathTemplateFragment.hashCode());
+ return result;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public final boolean equals(final Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ ResourceMethodMapping other = (ResourceMethodMapping) obj;
+ if (httpMethod == null) {
+ if (other.httpMethod != null) {
+ return false;
+ }
+ } else if (!httpMethod.equals(other.httpMethod)) {
+ return false;
+ }
+ if (producedMediaTypes == null) {
+ if (other.producedMediaTypes != null) {
+ return false;
+ }
+ } else if (!producedMediaTypes.equals(other.producedMediaTypes)) {
+ return false;
+ }
+ if (consumedMediaTypes == null) {
+ if (other.consumedMediaTypes != null) {
+ return false;
+ }
+ } else if (!consumedMediaTypes.equals(other.consumedMediaTypes)) {
+ return false;
+ }
+ if (queryParams == null) {
+ if (other.queryParams != null) {
+ return false;
+ }
+ } else if (!queryParams.equals(other.queryParams)) {
+ return false;
+ }
+ if (uriPathTemplateFragment == null) {
+ if (other.uriPathTemplateFragment != null) {
+ return false;
+ }
+ } else if (!uriPathTemplateFragment.equals(other.uriPathTemplateFragment)) {
+ return false;
+ }
+ return true;
+ }
+
+}
Added:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/ResourceMethodNode.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/ResourceMethodNode.java
(rev 0)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/ResourceMethodNode.java 2011-06-07
22:25:07 UTC (rev 31892)
@@ -0,0 +1,92 @@
+/**
+ *
+ */
+package org.jboss.tools.ws.jaxrs.core.metamodel;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * @author xcoulon
+ *
+ */
+public class ResourceMethodNode {
+
+ private final ResourceMethod element;
+
+ private final ResourceMethodNode parent;
+
+ private final List<ResourceMethodNode> children = new
ArrayList<ResourceMethodNode>();
+
+ public ResourceMethodNode(ResourceMethodNode parent, ResourceMethod element) {
+ this.parent = parent;
+ this.element = element;
+ }
+
+ /**
+ * @return the element
+ */
+ public ResourceMethod getElement() {
+ return element;
+ }
+
+ /**
+ * @return the parent
+ */
+ public ResourceMethodNode getParent() {
+ return parent;
+ }
+
+ /**
+ * @return the children
+ */
+ public List<ResourceMethodNode> getChildren() {
+ return children;
+ }
+
+ /**
+ * @return true if this node is a Leaf (ie, it has no child node).
+ */
+ public boolean isLeaf() {
+ return children.isEmpty();
+ }
+
+ /**
+ * @return True if this node is is the root node (ie, it has no parent
+ * node).
+ */
+ public boolean isRoot() {
+ return (parent == null);
+ }
+
+ public Set<ResourceMethodNode> remove() {
+ Set<ResourceMethodNode> removedNodes = new HashSet<ResourceMethodNode>();
+ removedNodes.add(this);
+ for (Iterator<ResourceMethodNode> iterator = children.iterator();
iterator.hasNext();) {
+ ResourceMethodNode child = iterator.next();
+ removedNodes.addAll(child.remove());
+ iterator.remove();
+ }
+ return removedNodes;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ StringBuilder buffer = new StringBuilder(element.toString());
+ if (!children.isEmpty()) {
+ buffer.append("\nchildren:\n");
+ for (ResourceMethodNode child : children) {
+ buffer.append(" ").append(child).append("\n");
+ }
+ }
+ return buffer.toString();
+ }
+}
Added:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Route.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Route.java
(rev 0)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Route.java 2011-06-07
22:25:07 UTC (rev 31892)
@@ -0,0 +1,97 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Xavier Coulon - Initial API and implementation
+ ******************************************************************************/
+
+package org.jboss.tools.ws.jaxrs.core.metamodel;
+
+import java.util.LinkedList;
+import java.util.List;
+
+public class Route implements Comparable<Route> {
+
+ private final LinkedList<ResourceMethod> resourceMethods = new
LinkedList<ResourceMethod>();
+
+ private final RouteEndpoint routeEndpoint;
+
+ /**
+ * Full constructor
+ *
+ * @throws InvalidModelElementException
+ */
+ public Route(List<ResourceMethod> resourceMethods) throws
InvalidModelElementException {
+ super();
+ this.resourceMethods.addAll(resourceMethods);
+ this.routeEndpoint = new RouteEndpoint(this);
+ }
+
+ /**
+ * @return the resourceMethods
+ */
+ public LinkedList<ResourceMethod> getResourceMethods() {
+ return resourceMethods;
+ }
+
+ /**
+ * @return the routeEndpoint
+ */
+ public RouteEndpoint getEndpoint() {
+ return routeEndpoint;
+ }
+
+ /**
+ * {inheritDoc
+ */
+ @Override
+ public final String toString() {
+ return new
StringBuffer().append(routeEndpoint.toString()).append("\n").append(this.resourceMethods.getLast())
+ .toString();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((resourceMethods == null) ? 0 :
resourceMethods.hashCode());
+ return result;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ Route other = (Route) obj;
+ if (resourceMethods == null) {
+ if (other.resourceMethods != null)
+ return false;
+ } else if (!resourceMethods.equals(other.resourceMethods))
+ return false;
+ return true;
+ }
+
+ @Override
+ public int compareTo(Route other) {
+ return routeEndpoint.compareTo(other.getEndpoint());
+ }
+
+}
Added:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/RouteEndpoint.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/RouteEndpoint.java
(rev 0)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/RouteEndpoint.java 2011-06-07
22:25:07 UTC (rev 31892)
@@ -0,0 +1,199 @@
+package org.jboss.tools.ws.jaxrs.core.metamodel;
+
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.jboss.tools.ws.jaxrs.core.utils.ResourceMethodAnnotatedParameter;
+
+public class RouteEndpoint implements Comparable<RouteEndpoint> {
+
+ private HTTPMethod httpMethod = null;
+
+ private String uriPathTemplate = null;
+
+ private final MediaTypeCapabilities consumedMediaTypes;
+
+ private final MediaTypeCapabilities producedMediaTypes;
+
+ private final Route route;
+
+ public RouteEndpoint(Route route) throws InvalidModelElementException {
+ this.route = route;
+ consumedMediaTypes = new MediaTypeCapabilities(null);
+ producedMediaTypes = new MediaTypeCapabilities(null);
+ merge();
+ }
+
+ public void merge() throws InvalidModelElementException {
+ this.httpMethod = computeHttpMethod(route.getResourceMethods());
+ this.uriPathTemplate = computeUriPathTemplate(route.getResourceMethods());
+ this.consumedMediaTypes.merge(computeConsumedMediaTypes(route.getResourceMethods()));
+ this.producedMediaTypes.merge(computeProducedMediaTypes(route.getResourceMethods()));
+ }
+
+ /**
+ * @return the httpMethod
+ */
+ public HTTPMethod getHttpMethod() {
+ return httpMethod;
+ }
+
+ /**
+ * @return the uriPathTemplate
+ */
+ public String getUriPathTemplate() {
+ return uriPathTemplate;
+ }
+
+ /**
+ * @return the consumedMediaTypes
+ */
+ public MediaTypeCapabilities getConsumedMediaTypes() {
+ return consumedMediaTypes;
+ }
+
+ /**
+ * @return the producedMediaTypes
+ */
+ public MediaTypeCapabilities getProducedMediaTypes() {
+ return producedMediaTypes;
+ }
+
+ public boolean matches(HTTPMethod otherHttpMethod, String otherUriPathTemplate, String
otherConsumes,
+ String otherProduces) {
+ if (otherHttpMethod != null &&
!this.httpMethod.getHttpVerb().equals(otherHttpMethod.getHttpVerb())) {
+ return false;
+ }
+ if (otherUriPathTemplate != null &&
!this.uriPathTemplate.equals(otherUriPathTemplate)) {
+ return false;
+ }
+ if (otherConsumes != null && !otherConsumes.equals("*/*") &&
!this.consumedMediaTypes.contains(otherConsumes)) {
+ return false;
+ }
+ if (otherProduces != null && !otherProduces.equals("*/*") &&
!this.producedMediaTypes.contains(otherProduces)) {
+ return false;
+ }
+
+ return true;
+ }
+
+ private static HTTPMethod computeHttpMethod(LinkedList<ResourceMethod>
resourceMethods)
+ throws InvalidModelElementException {
+ for (Iterator<ResourceMethod> iterator = resourceMethods.descendingIterator();
iterator.hasNext();) {
+ ResourceMethod resourceMethod = iterator.next();
+ HTTPMethod h = resourceMethod.getMapping().getHTTPMethod();
+ if (h != null) {
+ return h;
+ }
+ }
+ throw new InvalidModelElementException("No HttpMethod annotation found for this
endpoint: " + resourceMethods);
+ }
+
+ private static String computeUriPathTemplate(LinkedList<ResourceMethod>
resourceMethods) {
+ StringBuffer templateBuffer = new StringBuffer();
+ for (Iterator<ResourceMethod> iterator = resourceMethods.iterator();
iterator.hasNext();) {
+ ResourceMethod resourceMethod = iterator.next();
+ Resource resource = resourceMethod.getParentResource();
+ if (resource.isRootResource()) {
+ templateBuffer.append("/").append(resource.getMetamodel().getServiceUri());
+ }
+ if (resource.getMapping().getUriPathTemplateFragment() != null) {
+ templateBuffer.append("/").append(resource.getMapping().getUriPathTemplateFragment());
+ }
+ if (resourceMethod.getMapping().getUriPathTemplateFragment() != null) {
+ templateBuffer.append("/").append(resourceMethod.getMapping().getUriPathTemplateFragment());
+ }
+ }
+ ResourceMethod lastMethod = resourceMethods.getLast();
+ List<ResourceMethodAnnotatedParameter> queryParams =
lastMethod.getMapping().getQueryParams();
+ if (queryParams != null && !queryParams.isEmpty()) {
+ templateBuffer.append("?");
+ for (Iterator<ResourceMethodAnnotatedParameter> queryParamIterator =
queryParams.iterator(); queryParamIterator
+ .hasNext();) {
+ ResourceMethodAnnotatedParameter queryParam = queryParamIterator.next();
+ templateBuffer.append(queryParam.getAnnotationValue()).append("={")
+ .append(queryParam.getParameterType()).append("}");
+ if (queryParamIterator.hasNext()) {
+ templateBuffer.append("&");
+ }
+
+ }
+
+ }
+ return templateBuffer.toString().replaceAll("/\\*",
"/").replaceAll("///", "/").replaceAll("//",
"/");
+
+ }
+
+ private static MediaTypeCapabilities
computeConsumedMediaTypes(LinkedList<ResourceMethod> resourceMethods) {
+ for (Iterator<ResourceMethod> iterator = resourceMethods.descendingIterator();
iterator.hasNext();) {
+ ResourceMethod resourceMethod = iterator.next();
+ MediaTypeCapabilities mediaTypeCapabilities =
resourceMethod.getMapping().getConsumedMediaTypes();
+ if (!mediaTypeCapabilities.isEmpty()) {
+ return mediaTypeCapabilities;
+ }
+
+ Resource parentResource = resourceMethod.getParentResource();
+ mediaTypeCapabilities = parentResource.getMapping().getConsumedMediaTypes();
+ if (!mediaTypeCapabilities.isEmpty()) {
+ return mediaTypeCapabilities;
+ }
+ }
+ return new MediaTypeCapabilities(resourceMethods.getLast().getJavaElement(),
Arrays.asList("*/*"));
+ }
+
+ private static MediaTypeCapabilities
computeProducedMediaTypes(LinkedList<ResourceMethod> resourceMethods) {
+ for (Iterator<ResourceMethod> iterator = resourceMethods.descendingIterator();
iterator.hasNext();) {
+ ResourceMethod resourceMethod = iterator.next();
+ MediaTypeCapabilities mediaTypeCapabilities =
resourceMethod.getMapping().getProcucedMediaTypes();
+ if (!mediaTypeCapabilities.isEmpty()) {
+ return mediaTypeCapabilities;
+ }
+
+ Resource parentResource = resourceMethod.getParentResource();
+ mediaTypeCapabilities = parentResource.getMapping().getProcucedMediaTypes();
+ if (!mediaTypeCapabilities.isEmpty()) {
+ return mediaTypeCapabilities;
+ }
+ }
+ return new MediaTypeCapabilities(resourceMethods.getLast().getJavaElement(),
Arrays.asList("*/*"));
+ }
+
+ @Override
+ public final int compareTo(final RouteEndpoint other) {
+ int u = uriPathTemplate.compareTo(other.getUriPathTemplate());
+ if (u != 0) {
+ return u;
+ }
+ int h = httpMethod.compareTo(other.getHttpMethod());
+ if (h != 0) {
+ return h;
+ }
+ int c = consumedMediaTypes.compareTo(other.getConsumedMediaTypes());
+ if (c != 0) {
+ return c;
+ }
+ return producedMediaTypes.compareTo(other.getProducedMediaTypes());
+ }
+
+ /**
+ * {inheritDoc
+ */
+ @Override
+ public final String toString() {
+ StringBuffer buffer = new StringBuffer();
+ if (httpMethod != null) {
+ buffer.append(httpMethod.getHttpVerb());
+ buffer.append(" ");
+ }
+ if (uriPathTemplate != null) {
+ buffer.append(uriPathTemplate);
+ buffer.append(" ");
+ }
+ buffer.append("{Consumes:").append(consumedMediaTypes).append("
Produces: ").append(producedMediaTypes)
+ .append("}");
+ return buffer.toString();
+ }
+
+}
Added:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Routes.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Routes.java
(rev 0)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Routes.java 2011-06-07
22:25:07 UTC (rev 31892)
@@ -0,0 +1,216 @@
+/**
+ *
+ */
+package org.jboss.tools.ws.jaxrs.core.metamodel;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.ITypeHierarchy;
+import org.jboss.tools.ws.jaxrs.core.internal.utils.Logger;
+import org.jboss.tools.ws.jaxrs.core.metamodel.BaseElement.EnumKind;
+import org.jboss.tools.ws.jaxrs.core.utils.JdtUtils;
+
+/**
+ * @author xcoulon
+ *
+ */
+public class Routes {
+
+ /** The JAX-RS metamodel. */
+ private final Metamodel metamodel;
+
+ /**
+ * The set of trees. A tree has a root node and has some children. Each path
+ * of the tree is a route.
+ */
+ // private final Set<ResourceMethodNode> trees = new
+ // HashSet<ResourceMethodNode>();
+
+ private final List<Route> routes = new ArrayList<Route>();
+
+ private final Map<ResourceMethod, List<Route>> routesIndex = new
HashMap<ResourceMethod, List<Route>>();
+
+ private final Map<ResourceMethod, ResourceMethodNode> nodesIndex = new
HashMap<ResourceMethod, ResourceMethodNode>();
+
+ /**
+ * @param m
+ */
+ public Routes(Metamodel metamodel) {
+ this.metamodel = metamodel;
+ }
+
+ public void addFrom(ResourceMethod resourceMethod, IProgressMonitor progressMonitor)
throws CoreException {
+ switch (resourceMethod.getParentResource().getKind()) {
+ case ROOT_RESOURCE:
+ computeNodes(null, resourceMethod, progressMonitor);
+ break;
+ case SUBRESOURCE:
+ List<ResourceMethod> subresourceLocators =
metamodel.getResources().findSubresourceLocators(
+ resourceMethod.getParentResource().getJavaElement(), progressMonitor);
+ for (ResourceMethod subresourceLocator : subresourceLocators) {
+ ResourceMethodNode subresourceLocatorNode = nodesIndex.get(subresourceLocator);
+ if (subresourceLocatorNode != null) {
+ computeNodes(subresourceLocatorNode, resourceMethod, progressMonitor);
+ // trees.addAll(addedNodes);
+ }
+ }
+ break;
+ }
+ }
+
+ public void merge(ResourceMethod resourceMethod, IProgressMonitor progressMonitor)
throws CoreException {
+ removeFrom(resourceMethod, progressMonitor);
+ addFrom(resourceMethod, progressMonitor);
+ }
+
+ public void removeFrom(Resource removedResource, IProgressMonitor progressMonitor) {
+ if (removedResource == null) {
+ return;
+ }
+ for (ResourceMethod removedResourceMethod : removedResource.getAllMethods()) {
+ removeFrom(removedResourceMethod, progressMonitor);
+ }
+ }
+
+ public void removeFrom(ResourceMethod removedResourceMethod, IProgressMonitor
progressMonitor) {
+ if (removedResourceMethod == null) {
+ return;
+ }
+ if (this.routesIndex.containsKey(removedResourceMethod)) {
+ List<Route> routesToRemove = routesIndex.get(removedResourceMethod);
+ for (Route route : routesToRemove) {
+ this.routes.remove(route);
+ }
+ this.routesIndex.remove(removedResourceMethod);
+ }
+
+ if (this.nodesIndex.containsKey(removedResourceMethod)) {
+ ResourceMethodNode resourceMethodNode = this.nodesIndex.get(removedResourceMethod);
+ Set<ResourceMethodNode> removedNodes = resourceMethodNode.remove();
+ for (ResourceMethodNode removedNode : removedNodes) {
+ this.nodesIndex.remove(removedNode.getElement());
+ }
+ }
+
+ }
+
+ private List<ResourceMethodNode> computeNodes(final ResourceMethodNode parent,
final ResourceMethod resourceMethod,
+ final IProgressMonitor progressMonitor) throws CoreException {
+ List<ResourceMethodNode> childrenNodes = new
ArrayList<ResourceMethodNode>();
+ ResourceMethodNode node = new ResourceMethodNode(parent, resourceMethod);
+ childrenNodes.add(node);
+ nodesIndex.put(resourceMethod, node);
+ switch (resourceMethod.getKind()) {
+ // leaf node: can compute route from this node back to root parent node
+ case RESOURCE_METHOD:
+ case SUBRESOURCE_METHOD:
+ computeRoute(node);
+ break;
+ case SUBRESOURCE_LOCATOR:
+ IType returnType = resourceMethod.getReturnType();
+ if (returnType == null) {
+ Logger.warn("No return type defined for subresource locator method "
+ + resourceMethod.getJavaElement().getElementName());
+ break;
+ }
+ ITypeHierarchy subresourceTypeHierarchy = JdtUtils.resolveTypeHierarchy(returnType,
false, progressMonitor);
+ for (IType subresourceType : subresourceTypeHierarchy.getSubtypes(returnType)) {
+ Resource subresource = metamodel.getResources().getByType(subresourceType);
+ if (subresource != null &&
!subresource.equals(resourceMethod.getParentResource())
+ && subresource.getKind() == EnumKind.SUBRESOURCE) {
+ for (ResourceMethod subresourceMethod : subresource.getAllMethods()) {
+ node.getChildren().addAll(computeNodes(node, subresourceMethod, progressMonitor));
+ }
+ }
+ }
+ childrenNodes.add(node);
+ }
+ return childrenNodes;
+ }
+
+ /**
+ * Compute the route from the given leaf node.
+ */
+ private Route computeRoute(final ResourceMethodNode leafNode) {
+ LinkedList<ResourceMethod> resourceMethods = new
LinkedList<ResourceMethod>();
+ ResourceMethodNode node = leafNode;
+ while (node != null) {
+ resourceMethods.addFirst(node.getElement());
+ node = node.getParent();
+ }
+ try {
+ Route route = new Route(resourceMethods);
+ if (!routes.contains(route)) {
+ routes.add(route);
+ }
+ for (ResourceMethod rm : resourceMethods) {
+ // avoid duplicates
+ if (!this.routesIndex.containsKey(rm)) {
+ this.routesIndex.put(rm, new ArrayList<Route>());
+ }
+ if (!this.routesIndex.get(rm).contains(route)) {
+ Logger.debug("Added route " + route.toString());
+ this.routesIndex.get(rm).add(route);
+ }
+ }
+ return route;
+ } catch (InvalidModelElementException e) {
+ Logger.error("Failed to compute route", e);
+ }
+ return null;
+ }
+
+ /**
+ * @return the routesIndex
+ */
+ public List<Route> getAll() {
+ Collections.sort(routes);
+ return routes;
+ }
+
+ /**
+ * @return the routes that contain this method or null if none found.
+ */
+ public List<Route> getByResourceMethod(ResourceMethod resourceMethod) {
+ return routesIndex.get(resourceMethod);
+ }
+
+ public final ResourceMethod getByMapping(final HTTPMethod httpMethod, final String
uriPathTemplateFragment,
+ final String consumes, final String produces) {
+ for (Entry<ResourceMethod, List<Route>> entry : routesIndex.entrySet()) {
+ for (Route route : entry.getValue()) {
+ if (route.getEndpoint().matches(httpMethod, uriPathTemplateFragment, consumes,
produces)) {
+ return route.getResourceMethods().getLast();
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * @return the metamodel
+ */
+ public Metamodel getMetamodel() {
+ return metamodel;
+ }
+
+ /**
+ * Clears all data.
+ */
+ public void reset() {
+ this.routes.clear();
+ this.routesIndex.clear();
+ this.nodesIndex.clear();
+ }
+
+}
Added: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/icons/systemprocess.gif
===================================================================
(Binary files differ)
Property changes on: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/icons/systemprocess.gif
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/WaitWhileBuildingElement.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/WaitWhileBuildingElement.java
(rev 0)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/WaitWhileBuildingElement.java 2011-06-07
22:25:07 UTC (rev 31892)
@@ -0,0 +1,15 @@
+/**
+ *
+ */
+package org.jboss.tools.ws.jaxrs.ui.cnf;
+
+
+/**
+ * Element displayed while the project's metamodel is built in background.
+ *
+ * @author xcoulon
+ *
+ */
+public class WaitWhileBuildingElement {
+
+}
Added:
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/metamodel/MediaTypeCapabilitiesTestCase.java
===================================================================
---
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/metamodel/MediaTypeCapabilitiesTestCase.java
(rev 0)
+++
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/metamodel/MediaTypeCapabilitiesTestCase.java 2011-06-07
22:25:07 UTC (rev 31892)
@@ -0,0 +1,25 @@
+package org.jboss.tools.ws.jaxrs.core.metamodel;
+
+import static org.junit.Assert.fail;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class MediaTypeCapabilitiesTestCase {
+
+ @Before
+ public void setup() {
+
+ }
+
+ @Test
+ public void shouldMerge() {
+ MediaTypeCapabilities capabilities = new MediaTypeCapabilities(null);
+ }
+
+ @Test
+ public void testCompareTo() {
+ fail("Not yet implemented");
+ }
+
+}