View Javadoc

1   /*
2    * $Id: OWLFolder.java,v 1.3 2005/05/31 16:26:41 jlerner Exp $
3    *
4    * Copyright (c) 1999-2004, BBN Technologies, LLC.
5    * All rights reserved.
6    * http://www.daml.org/legal/opensource/bbn_license.html
7    */
8   package com.bbn.swede.core.resources;
9   
10  import org.eclipse.core.resources.IContainer;
11  import org.eclipse.core.resources.IFolder;
12  import org.eclipse.core.resources.IResource;
13  
14  import com.bbn.swede.core.IOWLElement;
15  import com.bbn.swede.core.IOWLFolder;
16  
17  /***
18   * Implementation for OWL folder elements.
19   * @author jlerner
20   */
21  public class OWLFolder extends OWLElement implements IOWLFolder
22  {
23     /***
24      * Creates an OWL folder element based on an Eclipse folder resource.
25      * @param folder The Eclipse folder
26      */
27     OWLFolder(IFolder folder)
28     {
29        _resource = folder;
30        setElementName(folder.getName());
31     }
32  
33     /*
34      *  (non-Javadoc)
35      * @see com.bbn.swede.core.IOWLElement#contains(org.eclipse.core.resources.IResource)
36      */
37     public boolean contains(IResource resource)
38     {
39        IOWLElement[] elems = getElementInfo().getChildren();
40        for (int i = 0; i < elems.length; i++)
41        {
42           if (resource.equals(elems[i].getResource()))
43           {
44              return true;
45           }
46           else if (
47              elems[i] instanceof IOWLFolder
48                 && ((IOWLFolder) elems[i]).contains(resource))
49           {
50              return true;
51           }
52  
53        }
54        return false;
55     }
56  
57     /*
58      *  (non-Javadoc)
59      * @see com.bbn.swede.core.IOWLElement#getCorrespondingElement(org.eclipse.core.resources.IResource)
60      */
61     public IOWLElement getCorrespondingElement(IResource resource)
62     {
63        if (_resource.equals(resource))
64        {
65           return this;
66        }
67  
68        IOWLElement[] elems = getElementInfo().getChildren();
69        for (int i = 0; i < elems.length; i++)
70        {
71           IOWLElement elem = elems[i].getCorrespondingElement(resource);
72           if (elem != null)
73           {
74              return elem;
75           }
76        }
77        return null;
78     }
79     
80     /*
81      *  (non-Javadoc)
82      * @see com.bbn.swede.core.IOWLFolder#getContainer()
83      */
84     public IContainer getContainer()
85     {
86        if (getResource() instanceof IContainer)
87        {
88           return (IContainer) getResource();
89        }
90        return null;
91     }
92     
93     /*
94      *  (non-Javadoc)
95      * @see com.bbn.swede.core.IOWLFolder#getFolder()
96      */
97     public IFolder getFolder()
98     {
99        if (getResource() instanceof IFolder)
100       {
101          return (IFolder) getResource();
102       }
103       return null;
104    }
105    /*
106     *  (non-Javadoc)
107     * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
108     */
109    public Object getAdapter(Class adapter)
110    {
111       if (adapter.equals(IFolder.class))
112       {
113          return getFolder();
114       }
115       if (adapter.equals(IContainer.class))
116       {
117          return getContainer();
118       }
119       return super.getAdapter(adapter);
120    }
121 }