View Javadoc

1   /*
2    *  Copyright 2004 University of Hannover
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License");
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License.
15   */
16  
17  package olr.relations;
18  
19  import java.util.ArrayList;
20  import java.util.Collection;
21  import java.util.Iterator;
22  import java.util.List;
23  
24  import olr.rdf.Model;
25  import olr.rdf.Resource;
26  import olr.rdf.StatementPool;
27  
28  /***
29   * @version $Id: RelationViewer.java,v 1.9 2004/08/02 18:36:53 roku Exp $
30   */
31  public final class RelationViewer {
32      /***
33       * Initializes an instance of this class.
34       * 
35       * @param model
36       */
37      public RelationViewer(Model model) {
38          this.model = model;
39      }
40  
41      public List getRelationTypes() {
42          ArrayList properties = new ArrayList();
43          Collection resources = model.getSubjects();
44          Iterator it = resources.iterator();
45          do {
46              if (!it.hasNext())
47                  break;
48              Resource property = getStatementPool().getResource(it.next().toString());
49              if (getStatementPool().isProperty(property)
50                      && property.getNS().equals(model.getNamespace()))
51                  properties.add(property);
52          } while (true);
53          return properties;
54      }
55  
56      public List getSpecificRelations(String aboutURI, String predicate) {
57          List relations = new ArrayList();
58          Resource resource = getStatementPool().getResource(aboutURI);
59          if (resource != null) {
60              Iterator it = resource.getObjects(predicate).iterator();
61              do {
62                  if (!it.hasNext())
63                      break;
64                  Resource object = getStatementPool().getResource(it.next().toString());
65                  if (object != null)
66                      relations.add(object);
67              } while (true);
68          }
69          return relations;
70      }
71  
72      private StatementPool getStatementPool() {
73          return model.getStatementPool();
74      }
75  
76      Model model;
77  }