1 7 package com.jofti.core; 8 9 import java.util.Properties ; 10 11 import org.apache.commons.logging.Log; 12 import org.apache.commons.logging.LogFactory; 13 14 15 import com.jofti.btree.BTree; 16 import com.jofti.exception.JoftiException; 17 import com.jofti.introspect.ClassIntrospector; 18 import com.jofti.manager.IndexManagerImpl; 19 import com.jofti.tree.TreeIndex; 20 import com.jofti.util.ReflectionUtil; 21 22 30 public class GenericIndexFactory { 31 32 private static GenericIndexFactory factory = new GenericIndexFactory(); 33 34 35 private static Log log = LogFactory.getLog(IndexManagerImpl.class); 36 37 public static GenericIndexFactory getInstance(){ 38 return factory; 39 } 40 41 50 public InternalIndex createIndex(String indexType, 51 ClassIntrospector parser, Properties props, String name) 52 throws JoftiException { 53 InternalIndex index =null; 54 try { 55 Class indexClass = ReflectionUtil.classForName(indexType); 56 57 if (!(InternalIndex.class.isAssignableFrom(indexClass))) { 58 throw new JoftiException("Class '" + indexClass 59 + "' must implement Index interface "); 60 } 61 62 index = (InternalIndex)indexClass.newInstance(); 63 64 } catch (InstantiationException e) { 65 throw new JoftiException("Problem instantiating Index", e); 66 } catch (ClassNotFoundException e) { 67 throw new JoftiException("Problem finding Index class", e); 68 } catch (IllegalAccessException e) { 69 throw new JoftiException("Problem instantiating Index", e); 70 } catch (Exception e) { 71 throw new JoftiException("Problem calling init() method on Index '" 72 + indexType + "'", e); 73 74 } 75 IStoreManager manager =null; 76 try{ 77 manager = configureOverflowManager(props,name); 78 } catch (InstantiationException e) { 79 throw new JoftiException("Problem instantiating disk-overflow provider " +props, e); 80 } catch (ClassNotFoundException e) { 81 throw new JoftiException("Problem instantiating disk-overflow provider "+props, e); 82 } catch (IllegalAccessException e) { 83 throw new JoftiException("Problem instantiating disk-overflow provider "+props, e); 84 } catch (Exception e) { 85 throw new JoftiException("Problem calling init() method on overflow provider '" 86 + name + "'", e); 87 88 } 89 90 91 92 93 94 if (index instanceof TreeIndex){ 95 96 BTree bTree = new BTree(); 97 ((TreeIndex)index).setTree(bTree); 98 ((TreeIndex)index).setParser(parser); 99 100 if (manager != null){ 101 bTree.setOverflowManager(manager); 102 } 103 104 } 105 ((TreeIndex)index).init(props); 106 107 return index; 108 109 110 111 } 112 113 private IStoreManager configureOverflowManager(Properties props,String name) throws Exception { 114 115 String providerString = props.getProperty("provider"); 116 Class providerClass = null; 117 if (providerString != null){ 118 providerClass =ReflectionUtil.classForName(providerString); 119 } 120 IStoreManager manager = null; 121 122 if (providerClass != null){ 123 manager = (IStoreManager) providerClass.newInstance(); 124 125 if (manager != null){ 126 manager.setName(name); 127 manager.init(props); 128 } 129 130 } 131 return manager; 132 133 } 134 135 } 136 | Popular Tags |