View Javadoc

1   /* 
2    WSMO Studio - a Semantic Web Service Editor
3    Copyright (c) 2004-2006, OntoText Lab. / SIRMA Group
4    
5    This library is free software; you can redistribute it and/or modify it under
6    the terms of the GNU Lesser General Public License as published by the Free
7    Software Foundation; either version 2.1 of the License, or (at your option)
8    any later version.
9    This library is distributed in the hope that it will be useful, but WITHOUT
10   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   details.
13   You should have received a copy of the GNU Lesser General Public License along
14   with this library; if not, write to the Free Software Foundation, Inc.,
15   59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16   */
17  
18  /***
19   * <p>Title: WSMO Studio</p>
20   * <p>Description: Semantic Web Service Editor</p>
21   * <p>Copyright:  Copyright (c) 2004-2006</p>
22   * <p>Company: OntoText Lab. / SIRMA </p>
23   */
24  
25  package org.wsmostudio.runtime.cache;
26  
27  import org.eclipse.core.resources.*;
28  import org.wsmostudio.runtime.WSMORuntime;
29  
30  /***
31   * A resource change listener which notifies the runtime to update
32   * its internal WSMO entities registry.
33   *
34   * @author not attributable
35   * @version $Revision: 605 $ $Date: 2006-02-23 17:48:15 +0200 $
36   */
37  
38  public class WSMLResourceListener implements IResourceChangeListener {
39  	
40      public void resourceChanged(IResourceChangeEvent event) {
41          if (isResourceMarkerChange(event.getDelta())) {
42              return;
43          }
44          switch (event.getType()) {
45              case IResourceChangeEvent.PRE_CLOSE:
46                  WSMORuntime.getCache().reinit();
47                  break;
48              case IResourceChangeEvent.PRE_DELETE:
49                  WSMORuntime.getCache().reinit();
50                  break;
51              case IResourceChangeEvent.POST_CHANGE:
52                  WSMORuntime.getCache().reinit();
53                  break;
54          }
55      }
56      
57      private boolean isResourceMarkerChange(IResourceDelta delta) {
58          if (delta == null) {
59              return false;
60          }
61          if ((delta.getFlags() & IResourceDelta.MARKERS) == IResourceDelta.MARKERS) {
62              return true;
63          }
64          IResourceDelta[] deltas = delta.getAffectedChildren();
65          if (deltas != null) {
66              for(int i = 0; i < deltas.length; i++) {
67                  if (isResourceMarkerChange(deltas[i])) {
68                      return true;
69                  }
70              }
71          }
72          return false;
73      }
74  }
75  
76  /*
77   * $Log$
78   * Revision 1.8  2006/02/23 15:48:15  alex_simov
79   * minor fix
80   *
81   * Revision 1.7  2006/01/19 10:10:05  alex_simov
82   * workspace resources not scanned when certain events appear
83   *
84   * Revision 1.6  2006/01/09 12:51:12  alex_simov
85   * Copyright message in header updated
86   *
87   * Revision 1.5  2005/12/01 09:26:15  morcen
88   * fixed bug where adding resource markers to an IResource resulted in the entire WSMOCache being reinitialised. Now the cache is only reinitialised if a document is added, removed, moved or the contents of the resource changes.
89   *
90   * Revision 1.4  2005/07/21 14:44:40  alex_simov
91   * added javadoc: class description, footer
92   *
93   */