KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > internal > indexing > IndexedStoreObjectPolicy


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.core.internal.indexing;
12
13 public class IndexedStoreObjectPolicy extends AbstractObjectPolicy {
14
15     /**
16      * Default constructor
17      */

18     public IndexedStoreObjectPolicy() {
19         super();
20     }
21
22     /**
23      * Creates an IndexedStoreObject from a field. The contents of the field are
24      * used to create the internal structure of the object. The field begins with a
25      * two byte type code that is used to determine the type of object to create.
26      */

27     public StoredObject createObject(Field field, ObjectStore store, ObjectAddress address) throws ObjectStoreException {
28         int offset = StoredObject.TYPE_OFFSET;
29         int length = StoredObject.TYPE_LENGTH;
30         int type = field.subfield(offset, length).getInt();
31         StoredObject object = null;
32         switch (type) {
33             case IndexAnchor.TYPE :
34                 object = new IndexAnchor(field, store, address);
35                 break;
36             case IndexNode.TYPE :
37                 object = new IndexNode(field, store, address);
38                 break;
39             case IndexedStoreContext.TYPE :
40                 object = new IndexedStoreContext(field, store, address);
41                 break;
42             case BinarySmallObject.TYPE :
43                 object = new BinarySmallObject(field, store, address);
44                 break;
45             default :
46                 throw new ObjectStoreException(ObjectStoreException.ObjectTypeFailure);
47         }
48         return object;
49     }
50
51 }
52
Popular Tags