Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "Howto: Register Annotation Routers"

Line 12: Line 12:
  
 
   public class ResourceRouter implements EObjectRouter {
 
   public class ResourceRouter implements EObjectRouter {
       private static final String ANNOTATIONS_FILE_NAME = ".annotations";
+
       private static final String ANNOTATIONS_FILE_NAME = ".ann";
 
       protected URI getUri(IResource res) {
 
       protected URI getUri(IResource res) {
 
           IPath path = res.getProject().getFullPath();
 
           IPath path = res.getProject().getFullPath();

Revision as of 12:17, 20 June 2011

< To: Tigerstripe_APIs
Annotation Framework provide configuration to setting where annotations can be saved. This configuration named Annotation Routers. Annotation Routers map annotation object to corresponding storage. If there is no one router specify for the annotation it will be saved in the default annotations location (located in the plug-in metadata). Annotation Router can be registered with the org.eclipse.tigerstripe.annotation.core.router extension point:

 <extension
       point="org.eclipse.tigerstripe.annotation.core.router">
    <router
          class="org.eclipse.tigerstripe.annotation.example.router.ResourceRouter"/>
 </extension>

ResourceRouter show how we can use router to save resource annotation to the project specific path:

 public class ResourceRouter implements EObjectRouter {
     private static final String ANNOTATIONS_FILE_NAME = ".ann";
     protected URI getUri(IResource res) {
         IPath path = res.getProject().getFullPath();
         if (path != null) {
             path = path.append(ANNOTATIONS_FILE_NAME);
             return URI.createPlatformResourceURI(path.toString(), false);
         }
         return null;
     }
     public URI route(EObject object) {
         if (object instanceof Annotation) {
             Annotation annotation = (Annotation)object;
             Object annotable = Object annotable = AnnotationPlugin.getManager().getAnnotatedObject(annotation);
             if (annotable instanceof IResource) {
                 IResource resource = (IResource)annotable;
                 return getUri(resource);
             }
         }
         return null;
     }
 }

With the route(EObject) method we map object to some URI. If this object can not be routed (annotable object is not a resource), this method return null and will be saved to the default location or location specified with an another router. This URI will be used to get resource with ResourceSet.createResource(URI) and ResourceSet.getResource(URI, boolean) methods

Back to the top