Author: xcoulon
Date: 2011-05-22 15:44:07 -0400 (Sun, 22 May 2011)
New Revision: 31417
Added:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Application.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Applications.java
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/builder/JaxrsMetamodelBuilder.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/BaseElementContainer.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Metamodel.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Providers.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Resources.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/utils/JdtUtils.java
Log:
Initial support for javax.ws.rs.core.Application subclass annotated with @ApplicationPath
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/builder/JaxrsMetamodelBuilder.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/builder/JaxrsMetamodelBuilder.java 2011-05-22
16:04:56 UTC (rev 31416)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/builder/JaxrsMetamodelBuilder.java 2011-05-22
19:44:07 UTC (rev 31417)
@@ -63,7 +63,7 @@
public static final QualifiedName JAXRS_ELEMENT_CHANGE_LISTENER_NAME = new
QualifiedName(
JBossJaxrsCorePlugin.PLUGIN_ID, "jaxrsPostReconcileListener");
- private List<IJavaElementDelta> changeHints = new
ArrayList<IJavaElementDelta>();
+ private final List<IJavaElementDelta> changeHints = new
ArrayList<IJavaElementDelta>();
// TODO : add support for cancellation
// TODO : report build failed
@@ -178,7 +178,7 @@
metamodel.reset();
}
// FIXME : determine correct service base URI
- metamodel.setServiceURI("/*");
+ metamodel.setServiceUri("/*");
metamodel.addElements(javaProject, monitor);
metamodel.validate(monitor);
long endTime = new Date().getTime();
Added:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Application.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Application.java
(rev 0)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Application.java 2011-05-22
19:44:07 UTC (rev 31417)
@@ -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 org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.jboss.tools.ws.jaxrs.core.utils.JdtUtils;
+
+/**
+ * The optional '@Application' annotation, used to designate the base context
+ * URI of the root resources.
+ *
+ *
+ * @author xcoulon
+ *
+ */
+public class Application extends BaseElement<IType> {
+
+ /**
+ * Internal 'HTTPMethod' element builder.
+ *
+ * @author xcoulon
+ *
+ */
+ public static class Builder {
+
+ private final Metamodel metamodel;
+ private final IType javaType;
+
+ /**
+ * Mandatory attributes of the enclosing 'HTTPMethod' element.
+ *
+ * @param javaType
+ * @param metamodel
+ */
+ public Builder(final IType javaType, final Metamodel metamodel) {
+ this.javaType = javaType;
+ this.metamodel = metamodel;
+ }
+
+ /**
+ * Builds and returns the elements. Internally calls the merge() method.
+ *
+ * @param progressMonitor
+ * @return
+ * @throws InvalidModelElementException
+ * @throws CoreException
+ */
+ public Application build(IProgressMonitor progressMonitor) throws CoreException {
+ Application httpMethod = new Application(this);
+ httpMethod.merge(javaType, progressMonitor);
+ return httpMethod;
+ }
+ }
+
+ /**
+ * Full constructor using the inner 'Builder' static class.
+ *
+ * @param builder
+ */
+ private Application(Builder builder) {
+ super(builder.javaType, builder.metamodel);
+ }
+
+ @Override
+ public void merge(IType element, IProgressMonitor progressMonitor) throws CoreException
{
+ CompilationUnit compilationUnit = getCompilationUnit(progressMonitor);
+ String appPath = (String) JdtUtils.resolveAnnotationAttributeValue(getJavaElement(),
compilationUnit,
+ javax.ws.rs.ApplicationPath.class, "value");
+ if (appPath != null) {
+ getMetamodel().setServiceUri(appPath);
+ }
+ }
+
+ @Override
+ public void validate(IProgressMonitor progressMonitor) throws CoreException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public org.jboss.tools.ws.jaxrs.core.metamodel.BaseElement.EnumType getKind() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
Property changes on:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Application.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Applications.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Applications.java
(rev 0)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Applications.java 2011-05-22
19:44:07 UTC (rev 31417)
@@ -0,0 +1,60 @@
+package org.jboss.tools.ws.jaxrs.core.metamodel;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jdt.core.IJavaElement;
+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.utils.JdtUtils;
+
+/**
+ * Container for all elements extending the
+ * <code>javax.ws.rs.core.Application</code>. There should be only one per
+ * application, so this container will be useful when it comes to detecting
+ * "duplicate" classes.
+ *
+ * @author xcoulon
+ *
+ */
+public class Applications extends BaseElementContainer<Application> {
+
+ /**
+ * Default constructor
+ *
+ * @param metamodel
+ */
+ public Applications(Metamodel metamodel) {
+ super(metamodel);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @throws InvalidModelElementException
+ */
+ @Override
+ public void addFrom(IJavaElement scope, IProgressMonitor progressMonitor) throws
CoreException {
+ IType applicationType =
JdtUtils.resolveType(javax.ws.rs.core.Application.class.getName(),
+ metamodel.getJavaProject(), progressMonitor);
+ ITypeHierarchy applicationTypeHierarchy = JdtUtils
+ .resolveTypeHierarchy(applicationType, false, progressMonitor);
+ IType[] subtypes = applicationTypeHierarchy.getAllSubtypes(applicationType);
+ if (subtypes.length > 1) {
+ List<String> s = new ArrayList<String>();
+ for (IType t : subtypes) {
+ s.add(t.getElementName());
+ }
+ Logger.error("Multiple subclasses of '" + Application.class.getName()
+ + " were found, but only one should be defined: " + s);
+ }
+ for (IType t : subtypes) {
+ Application application = new Application.Builder(t,
metamodel).build(progressMonitor);
+ elements.put(t.getElementName(), application);
+ }
+
+ }
+}
Property changes on:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Applications.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/BaseElementContainer.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/BaseElementContainer.java 2011-05-22
16:04:56 UTC (rev 31416)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/BaseElementContainer.java 2011-05-22
19:44:07 UTC (rev 31417)
@@ -36,8 +36,11 @@
/**
* Adding elements from the given scope.
*
+ * @throws InvalidModelElementException
+ *
*/
- public abstract void addFrom(final IJavaElement scope, final IProgressMonitor
progressMonitor) throws CoreException;
+ public abstract void addFrom(final IJavaElement scope, final IProgressMonitor
progressMonitor)
+ throws CoreException, InvalidModelElementException;
/**
* Remove an element from the container given its underlying (eclipse)
@@ -135,4 +138,9 @@
public void reset() {
this.elements.clear();
}
+
+ @Override
+ public String toString() {
+ return elements.toString();
+ }
}
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Metamodel.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Metamodel.java 2011-05-22
16:04:56 UTC (rev 31416)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Metamodel.java 2011-05-22
19:44:07 UTC (rev 31417)
@@ -15,6 +15,11 @@
import java.util.Arrays;
import java.util.List;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.HttpMethod;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
@@ -43,9 +48,6 @@
*/
public class Metamodel {
- /** the number of steps to add or merge the metamodel. */
- private static final int TOTAL_STEPS = 3;
-
/**
* The qualified name of the metamodel when stored in the project session
* properties.
@@ -53,11 +55,11 @@
private static final QualifiedName METAMODEL_QUALIFIED_NAME = new
QualifiedName(JBossJaxrsCorePlugin.PLUGIN_ID,
"metamodel");
- /** The enclosing Project. */
- private final IProject project;
+ /** The enclosing JavaProject. */
+ private final IJavaProject javaProject;
/** The Service URI. Default is "/" */
- private String serviceURI = "/";
+ private String serviceUri = "/";
/**
* List of JAX-RS annotation qualified names, including both core
@@ -67,6 +69,12 @@
private final List<String> jaxrsAnnotationNames = new ArrayList<String>();
/**
+ * All the subclasses of <code>javax.ws.rs.core.Application</code>,
although
+ * there should be only one.
+ */
+ private final Applications applications;
+
+ /**
* All the resources (both rootresources and subresources) available in the
* service , indexed by their associated java type fully qualified name.
*/
@@ -82,34 +90,6 @@
/** The HTTP ResourceMethod elements container. */
private final HTTPMethods httpMethods;
- /** The <code>javax.ws.rs.ext.Provider</code> annotation qualified name. */
- @Deprecated
- public static final String ANNOTATION_PROVIDER = "javax.ws.rs.ext.Provider";
-
- /** The <code>@Produces</code> annotation qualified name. */
- @Deprecated
- public static final String ANNOTATION_PRODUCES = "javax.ws.rs.Produces";
-
- /** The <code>@Path</code> annotation qualified name. */
- @Deprecated
- public static final String ANNOTATION_PATH = "javax.ws.rs.Path";
-
- /** The <code>@HttpMethod</code> annotation qualified name. */
- @Deprecated
- public static final String ANNOTATION_HTTP_METHOD = "javax.ws.rs.HttpMethod";
-
- /** The <code>@QueryParam</code> annotation qualified name. */
- @Deprecated
- public static final String ANNOTATION_QUERY_PARAM = "javax.ws.rs.QueryParam";
-
- /** The <code>@PathParam</code> annotation qualified name. */
- @Deprecated
- public static final String ANNOTATION_PATH_PARAM = "javax.ws.rs.PathParam";
-
- /** The <code>@Consumes</code> annotation qualified name. */
- @Deprecated
- public static final String ANNOTATION_CONSUMES = "javax.ws.rs.Consumes";
-
/**
* Full constructor.
*
@@ -119,17 +99,24 @@
* in case of underlying exception
*/
public Metamodel(final IJavaProject javaProject) throws CoreException {
- this.project = javaProject.getProject();
+ this.javaProject = javaProject;
+ applications = new Applications(this);
providers = new Providers(javaProject, this);
resources = new Resources(this);
httpMethods = new HTTPMethods(this);
- jaxrsAnnotationNames.addAll(Arrays.asList(new String[] {
Metamodel.ANNOTATION_PROVIDER,
- Metamodel.ANNOTATION_CONSUMES, Metamodel.ANNOTATION_PRODUCES,
Metamodel.ANNOTATION_PATH,
- Metamodel.ANNOTATION_HTTP_METHOD }));
- project.setSessionProperty(METAMODEL_QUALIFIED_NAME, this);
+ jaxrsAnnotationNames.addAll(Arrays.asList(new String[] { Provider.class.getName(),
Consumes.class.getName(),
+ Produces.class.getName(), Path.class.getName(), HttpMethod.class.getName() }));
+ javaProject.getProject().setSessionProperty(METAMODEL_QUALIFIED_NAME, this);
}
/**
+ * @return the javaProject
+ */
+ public IJavaProject getJavaProject() {
+ return javaProject;
+ }
+
+ /**
* Accessor to the metamodel from the given project's session properties.
*
* @param project
@@ -148,8 +135,8 @@
* in case of underlying exception
*/
public final void remove() throws CoreException {
- Logger.info("JAX-RS Metamodel removed for project " + project.getName());
- project.setSessionProperty(METAMODEL_QUALIFIED_NAME, null);
+ Logger.info("JAX-RS Metamodel removed for project " +
javaProject.getElementName());
+ javaProject.getProject().setSessionProperty(METAMODEL_QUALIFIED_NAME, null);
}
/**
@@ -174,24 +161,24 @@
}
/**
- * @return the serviceURI
+ * @return the serviceUri
*/
- public final String getServiceURI() {
- return serviceURI;
+ public final String getServiceUri() {
+ return serviceUri;
}
/**
* Sets the Base URI for the URI mapping templates.
*
* @param uri
- * the serviceURI to set
+ * the serviceUri to set
*/
- public final void setServiceURI(final String uri) {
+ public final void setServiceUri(final String uri) {
// remove trailing "*" character, if present.
if (uri.endsWith("*")) {
- this.serviceURI = uri.substring(0, uri.length() - 1);
+ this.serviceUri = uri.substring(0, uri.length() - 1);
} else {
- this.serviceURI = uri;
+ this.serviceUri = uri;
}
}
@@ -204,12 +191,14 @@
* the progress monitor
* @throws CoreException
* in case of underlying exception
+ * @throws InvalidModelElementException
*/
public final void addElements(final IJavaElement scope, final IProgressMonitor
progressMonitor)
throws CoreException {
try {
-
- progressMonitor.beginTask("Computing JAX-RS metamodel", TOTAL_STEPS);
+ progressMonitor.beginTask("Computing JAX-RS metamodel", 4);
+ applications.addFrom(scope, progressMonitor);
+ progressMonitor.worked(1);
httpMethods.addFrom(scope, progressMonitor);
progressMonitor.worked(1);
providers.addFrom(scope, new SubProgressMonitor(progressMonitor, 1,
@@ -234,7 +223,9 @@
*/
public final void remove(final IResource resource, final IProgressMonitor
progressMonitor) {
try {
- progressMonitor.beginTask("Computing JAX-RS metamodel", TOTAL_STEPS);
+ progressMonitor.beginTask("Computing JAX-RS metamodel", 4);
+ applications.removeElement(resource, progressMonitor);
+ progressMonitor.worked(1);
httpMethods.removeElement(resource, progressMonitor);
progressMonitor.worked(1);
resources.removeElement(resource, progressMonitor);
@@ -314,6 +305,7 @@
* the progress monitor
* @throws CoreException
* in case of underlying exception
+ * @throws InvalidModelElementException
*/
public final void applyDelta(final IResourceDelta delta, final IProgressMonitor
progressMonitor)
throws CoreException {
@@ -353,6 +345,7 @@
* the progress monitor
* @throws CoreException
* in case of underlying exception
+ * @throws InvalidModelElementException
*/
protected final void mergeElement(final ICompilationUnit compilationUnit, final
IProgressMonitor progressMonitor)
throws CoreException {
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Providers.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Providers.java 2011-05-22
16:04:56 UTC (rev 31416)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Providers.java 2011-05-22
19:44:07 UTC (rev 31417)
@@ -46,6 +46,7 @@
* @param metamodel
* @throws CoreException
*/
+ // TODO : use the Builder pattern here ?
public Providers(final IJavaProject javaProject, final Metamodel metamodel) throws
CoreException {
super(metamodel);
providerInterfaces = new HashMap<EnumProviderKind, IType>();
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Resources.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Resources.java 2011-05-22
16:04:56 UTC (rev 31416)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Resources.java 2011-05-22
19:44:07 UTC (rev 31417)
@@ -69,7 +69,8 @@
final IProgressMonitor progressMonitor) throws CoreException {
Map<ResolvedUriMapping, Stack<ResourceMethod>> uriMappings = new
HashMap<ResolvedUriMapping, Stack<ResourceMethod>>();
for (Resource resource : getRootResources()) {
- resolveResourcesUriMappings(resource, "/*", uriMappings, new
Stack<ResourceMethod>(), progressMonitor);
+ resolveResourcesUriMappings(resource, metamodel.getServiceUri(), uriMappings, new
Stack<ResourceMethod>(),
+ progressMonitor);
}
return uriMappings;
}
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/utils/JdtUtils.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/utils/JdtUtils.java 2011-05-22
16:04:56 UTC (rev 31416)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/utils/JdtUtils.java 2011-05-22
19:44:07 UTC (rev 31417)
@@ -386,7 +386,8 @@
* @throws CoreException
* the underlying CoreException thrown by the manipulated JDT
* APIs
- *
+ * @deprecated use resolveAnnotationAttributeValue(IMember, CompilationUnit,
+ * Class<?>, String) instead.
*/
@Deprecated
public static Object resolveAnnotationAttributeValue(final IAnnotationBinding
annotationBinding,