View Javadoc

1   /*
2    * Copyright 2004 Charles Blaxland
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  package mnemosyne.core;
17  
18  
19  /***
20   * This class represents the persistentRoot of the persistent graph.
21   * All objects reachable from this object are automatically made persistent.
22   *
23   * @version $Id: PersistentRootImpl.java,v 1.2 2004/08/12 14:01:05 charlesblaxland Exp $
24   */
25  public class PersistentRootImpl extends NonAopPersistable implements PersistentRoot
26  {
27      // TODO - make this a map when java collections are supported
28      private Object persistentRoot;
29  
30      public Object getPersistentRoot(String rootName)
31      {
32          if (isPersistent())
33          {
34              PersistentObject persistentObject = getPersistentObject();
35              PersistentRootImpl target = (PersistentRootImpl) persistentObject.findTargetObject();
36              return target.getPersistentRootNoIntercept(rootName);
37          }
38          else
39          {
40              return persistentRoot;
41          }
42      }
43  
44      public void setPersistentRoot(String rootName, Object persistentRoot)
45      {
46          if (isPersistent())
47          {
48              PersistentObject persistentObject = getPersistentObject();
49              PersistentRootImpl target = (PersistentRootImpl) persistentObject.findTargetObject();
50              target.setPersistentRootNoIntercept(rootName, persistentRoot);
51          }
52          else
53          {
54              this.persistentRoot = persistentRoot;
55          }
56      }
57  
58      Object getPersistentRootNoIntercept(String rootName)
59      {
60          return persistentRoot;
61      }
62  
63      void setPersistentRootNoIntercept(String rootName, Object persistentRoot)
64      {
65          this.persistentRoot = persistentRoot;
66      }
67  }