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;
26  
27  import java.util.HashSet;
28  import java.util.Set;
29  
30  import org.omwg.ontology.Ontology;
31  import org.wsmo.common.*;
32  import org.wsmo.common.exception.SynchronisationException;
33  import org.wsmo.locator.Locator;
34  import org.wsmo.mediator.*;
35  import org.wsmo.service.Goal;
36  import org.wsmo.service.WebService;
37  import org.wsmostudio.runtime.cache.WSMOTopEntity;
38  
39  public class WorkspaceLocator implements Locator {
40      
41      public static final byte PROMPT_FOR_LOADING_IMPORTS = 0;
42      public static final byte ALWAYS_LOAD_IMPORTS = 1;
43      public static final byte NEVER_LOAD_IMPORTS = 2;
44      
45      @SuppressWarnings("unchecked")
46      public Set<Entity> lookup(Identifier id) throws SynchronisationException {
47          Set<Entity> result = new HashSet<Entity>();
48          Class[] classes = new Class[] {Ontology.class, 
49                                         Goal.class, 
50                                         WebService.class, 
51                                         Mediator.class, 
52                                         WGMediator.class, 
53                                         OOMediator.class, 
54                                         GGMediator.class, 
55                                         WWMediator.class};
56          Entity entity;
57          for(int i = 0; i < classes.length; i++) {
58              entity = lookup(id, classes[i]);
59              if (entity != null) {
60                  result.add(entity);
61              }
62          }
63          return result;
64      }
65  
66      @SuppressWarnings("unchecked")
67      public Entity lookup(Identifier id, Class clazz) throws SynchronisationException {
68          if (false == id instanceof IRI) {
69              return null;
70          }
71          if (clazz == Ontology.class) {
72              return WSMORuntime.getIOManager().doLoadOntology(id);
73          }
74          if (clazz == Goal.class) {
75              return WSMORuntime.getIOManager().doLoadGoal(id);
76          }
77          if (clazz == WebService.class) {
78              return WSMORuntime.getIOManager().doLoadWebService(id);
79          }
80          if (clazz == OOMediator.class) {
81              return WSMORuntime.getIOManager().doLoadOOMediator(id);
82          }
83          if (clazz == WWMediator.class) {
84              return WSMORuntime.getIOManager().doLoadWWMediator(id);
85          }
86          if (clazz == WGMediator.class) {
87              return WSMORuntime.getIOManager().doLoadWGMediator(id);
88          }
89          if (clazz == GGMediator.class) {
90              return WSMORuntime.getIOManager().doLoadGGMediator(id);
91          }
92          if (clazz == Mediator.class) {
93              int mediType = WSMORuntime.getCache().getTypeByIRI((IRI)id);
94              switch (mediType) {
95                  case WSMOTopEntity.OO_MEDIATOR:
96                      return WSMORuntime.getIOManager().doLoadOOMediator(id);
97                  case WSMOTopEntity.GG_MEDIATOR:
98                      return WSMORuntime.getIOManager().doLoadGGMediator(id);
99                  case WSMOTopEntity.WG_MEDIATOR:
100                     return WSMORuntime.getIOManager().doLoadWGMediator(id);
101                 case WSMOTopEntity.WW_MEDIATOR:
102                     return WSMORuntime.getIOManager().doLoadWWMediator(id);
103             }
104         }
105         return null;
106     }
107 }
108 
109 /*
110  * $Log$
111  * Revision 1.4  2007/04/17 14:34:09  alex_simov
112  * migration to the latest wsmo4j (java 5)
113  *
114  * Revision 1.3  2006/11/20 17:08:29  alex_simov
115  * no message
116  *
117  * Revision 1.2  2006/11/02 17:28:46  alex_simov
118  * System.out.println() removed
119  *
120  * Revision 1.1  2006/11/02 17:11:56  alex_simov
121  * rfe [1588567]: Workspace's lightweight WSML parser registered as a Locator
122  * in the wsmo4j runtime environment
123  *
124  */