View Javadoc

1   /*
2    *  $Id: OlrStatementPoolImpl.java,v 1.2 2004/07/25 21:44:43 roku Exp $ 
3    *
4    *  Copyright 2004 University of Hannover
5    *
6    *  Licensed under the Apache License, Version 2.0 (the "License");
7    *  you may not use this file except in compliance with the License.
8    *  You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   *  Unless required by applicable law or agreed to in writing, software
13   *  distributed under the License is distributed on an "AS IS" BASIS,
14   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   *  See the License for the specific language governing permissions and
16   *  limitations under the License.
17   */
18  
19  package olr.statementpool;
20  
21  import java.util.ArrayList;
22  import java.util.Iterator;
23  import java.util.List;
24  
25  import olr.om.DBUtils;
26  import olr.om.Model;
27  import olr.rdf.Attribute;
28  import olr.rdf.OLR3Definitions;
29  import olr.rdf.Resource;
30  import olr.rdf.util.SortedStringList;
31  
32  
33  class OlrStatementPoolImpl extends AbstractDbStatementPool implements OlrStatementPool
34  {
35      OlrStatementPoolImpl(Model model)
36      {
37          super(model);
38      }
39  
40      public String createInstanceOf(String namespace, String classResource)
41      {
42          String resource = super.createInstanceOf(namespace, classResource);
43          List allProperties = getAllPropertiesForClass(classResource);
44          Iterator it = allProperties.iterator();
45          do
46          {
47              if(!it.hasNext())
48                  break;
49              String property = it.next().toString();
50              if(isInstanceOf(property, OLR3Definitions.OLR3_UNIQUENECESSARYPROPERTY))
51              {
52                  final List classes = getInstanciableClassesForRange(getAllRanges(property));
53                  if(classes.size() == 1)
54                  {
55                      String clss = classes.get(0).toString();
56                      addAttributeAbout(resource, new Attribute(property, createInstanceOf(namespace, clss)));
57                  }
58              }
59          } while(true);
60          return resource;
61      }
62  
63      public List getInstanciableClassesForRange(List range)
64      {
65          final List classes = getAllSubClasses(range);
66          final List instanciableClasses = new SortedStringList();
67          final Iterator it = classes.iterator();
68          
69          do
70          {
71              if(!it.hasNext())
72                  break;
73              String clss = it.next().toString();
74              if(!isSubClassOf(clss, OLR3Definitions.OLR3_NONINSTANCIABLE))
75                  instanciableClasses.add(clss);
76          } while(true);
77          return instanciableClasses;
78      }
79  
80      public List getResourcesHavingKeyword(List keywords)
81      {
82          List resourcesFound = new ArrayList();
83          if(!keywords.isEmpty())
84          {
85              Iterator it = super.resources.values().iterator();
86  label0:
87              do
88              {
89                  if(!it.hasNext())
90                      break;
91                  Resource resource = (Resource)it.next();
92                  Iterator it2 = keywords.iterator();
93                  do
94                      if(!it2.hasNext())
95                          continue label0;
96                  while(!resource.hasAttribute(OLR3Definitions.OLR3_KEYWORD, it2.next().toString()));
97                  resourcesFound.add(resource.getURI());
98              } while(true);
99          }
100         return resourcesFound;
101     }
102     
103     protected long getInstanceId() 
104     {
105         return DBUtils.getInstanceId();
106     }
107 }