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.toolbar;
18  
19  import java.util.Iterator;
20  import java.util.List;
21  
22  import olr.om.RdfToolbar;
23  import olr.om.RdfToolbarPeer;
24  import olr.om.RdfUser;
25  import olr.statementpool.OlrStatementPool;
26  
27  /***
28   * @version $Id: DBToolbarSession.java,v 1.18 2004/08/02 18:38:53 roku Exp $
29   */
30  public final class DBToolbarSession extends AbstractToolbarSession {
31  
32      private RdfUser user = null;
33  
34      DBToolbarSession(RdfUser user, OlrStatementPool statementPool) throws Exception {
35          super(statementPool);
36          this.user = user;
37          List modelUris = RdfToolbarPeer.getAllToolbars(getUser());
38  
39          for (Iterator it = modelUris.iterator(); it.hasNext();) {
40              RdfToolbar modelUri = (RdfToolbar) it.next();
41              if (modelUri.getIsSchema())
42                  super.addSchema(modelUri.getUri(), modelUri.getTitle());
43              else
44                  super.addInstanceFile(modelUri.getUri(), modelUri.getTitle());
45          }
46      }
47  
48      public boolean addSchema(String uri, String title) throws Exception {
49          boolean ok = super.addSchema(uri, title);
50          if (ok)
51              RdfToolbarPeer.addSchema(getUser(), uri, title);
52          return ok;
53      }
54  
55      public boolean addInstanceFile(String uri, String title) throws Exception {
56          boolean ok = super.addInstanceFile(uri, title);
57          if (ok)
58              RdfToolbarPeer.addInstanceFile(getUser(), uri, title);
59          return ok;
60      }
61  
62      public String removeModelAt(int n) throws Exception {
63          String uri = super.removeModelAt(n);
64          if (uri != null)
65              RdfToolbarPeer.delete(getUser(), uri);
66          return uri;
67      }
68  
69      private RdfUser getUser() {
70          return this.user;
71      }
72  }