KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > mdr > persistence > btreeimpl > btreestorage > MofidIndex


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.mdr.persistence.btreeimpl.btreestorage;
20
21 import java.io.*;
22 import java.text.*;
23 import java.util.*;
24 import org.netbeans.mdr.persistence.*;
25 import org.netbeans.mdr.persistence.btreeimpl.btreeindex.*;
26
27 /**
28 * This is an index from names (Strings) to MOFIDs. Its primary use is to
29 * store the MOFIDs for secondary indexes.
30 */

31 public class MofidIndex extends NameIndex implements StorageClient {
32
33     /* MOFID generator */
34     BtreeStorage storage;
35
36     /** Create a new MofidIndex */
37     public MofidIndex() {
38     }
39
40     /** Create a new MofidIndex */
41     public MofidIndex(BtreeStorage storage) {
42         super();
43         this.storage = storage;
44     }
45
46     /** get a MOFID by its name. If none exists, throw an exception
47     * @param name the name associated with the MOFID
48     */

49     public synchronized MOFID get(String JavaDoc name)throws StorageException {
50         return (MOFID)getObj(name);
51     }
52
53     /**
54     * Add a name-MOFID pair to the MofidIndex. If one already existed,
55     * throw an exception.
56     * @param name name of object to add to index
57     * @param id MOFID of object to add
58     */

59     public synchronized void add(String JavaDoc name, MOFID id) throws StorageException {
60         addObj(name, id);
61     }
62
63     /**
64     * write object to stream. Used by serialization.
65     * @param obj object to write
66     * @param strm stream to write it to
67     */

68     protected void writeObjectToStream(Object JavaDoc obj, DataOutputStream strm)
69         throws StorageException {
70             this.storage.writeMOFIDData (strm, (MOFID) obj);
71     }
72
73     /**
74     * read object from stream. Used by deserialization.
75     * @param strm stream to read from
76     * @return obj object read
77     */

78     protected Object JavaDoc readObjectFromStream(DataInputStream strm)
79         throws StorageException {
80     return this.storage.readMOFIDData (strm);
81     }
82
83     /** called on deserialization */
84     public void setStorage(Storage storage) {
85         this.storage = ((BtreeStorage)storage);
86     }
87 }
88
89
90
91
Popular Tags