View Javadoc

1   /*
2    * Copyright 2004 University of Hannover
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5    * in compliance with the License. You may obtain a copy of the License at
6    * 
7    * http://www.apache.org/licenses/LICENSE-2.0
8    * 
9    * Unless required by applicable law or agreed to in writing, software distributed under the License
10   * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11   * or implied. See the License for the specific language governing permissions and limitations under
12   * the License.
13   */
14  
15  package olr.viewer;
16  
17  import java.util.ArrayList;
18  import java.util.Iterator;
19  import java.util.List;
20  
21  import olr.rdf.AbstractStatementPool;
22  import olr.rdf.Model;
23  import olr.rdf.OLR3Definitions;
24  import olr.rdf.Resource;
25  import olr.statementpool.OlrStatementPool;
26  
27  /*** 
28   * @version $Id: CourseViewers.java,v 1.9 2004/08/03 08:33:53 roku Exp $
29   */
30  public final class CourseViewers {
31  
32      private final OlrStatementPool statementPool;
33  
34      private final String root;
35  
36      private final boolean isAuthor;
37  
38      public CourseViewers(OlrStatementPool statementPool, String root, boolean isAuthor) {
39          this.viewers = new ArrayList();
40          this.activeViewer = null;
41          this.statementPool = statementPool;
42          this.root = root;
43          this.isAuthor = isAuthor;
44      }
45  
46      private boolean isAuthor() {
47          return this.isAuthor;
48      }
49  
50      private String getRoot() {
51          return this.root;
52      }
53  
54      public OlrStatementPool getStatementPool() {
55          return this.statementPool;
56      }
57  
58      public void addSchema(Model model, String title) {
59          viewers.add(new CourseViewer(model, getRoot(), title, isAuthor()));
60      }
61  
62      public int getCount() {
63          return viewers.size();
64      }
65  
66      public CourseViewer getViewerAt(int pos) {
67          if (pos >= 0 && pos < viewers.size())
68              return (CourseViewer) viewers.get(pos);
69          else
70              return null;
71      }
72  
73      public void setActiveViewer(int pos) {
74          activeViewer = getViewerAt(pos);
75      }
76  
77      public CourseViewer getActiveViewer() {
78          return activeViewer;
79      }
80  
81      public void save() throws Exception {
82          Resource courseClass = getStatementPool().getResource(OLR3Definitions.OLR3_ROOT);
83          if (AbstractStatementPool.isClass(courseClass)) {
84              for (Iterator it = courseClass.getInstance().iterator(); it.hasNext(); getStatementPool()
85                      .saveCourseToDB(it.next().toString()))
86                  ;
87          }
88      }
89  
90      private List viewers;
91  
92      private CourseViewer activeViewer;
93  }