1 11 package org.eclipse.core.internal.registry; 12 13 import java.util.Map ; 14 import org.eclipse.core.runtime.InvalidRegistryObjectException; 15 16 19 public class TemporaryObjectManager implements IObjectManager { 20 private Map actualObjects; private RegistryObjectManager parent; 23 public TemporaryObjectManager(Map actualObjects, RegistryObjectManager parent) { 24 this.actualObjects = actualObjects; 25 this.parent = parent; 26 } 27 28 public Handle getHandle(int id, byte type) { 29 switch (type) { 30 case RegistryObjectManager.EXTENSION_POINT : 31 return new ExtensionPointHandle(this, id); 32 33 case RegistryObjectManager.EXTENSION : 34 return new ExtensionHandle(this, id); 35 36 case RegistryObjectManager.CONFIGURATION_ELEMENT : 37 return new ConfigurationElementHandle(this, id); 38 39 case RegistryObjectManager.THIRDLEVEL_CONFIGURATION_ELEMENT : 40 default : return new ThirdLevelConfigurationElementHandle(this, id); 42 } 43 } 44 45 public Handle[] getHandles(int[] ids, byte type) { 46 Handle[] results = null; 47 int nbrId = ids.length; 48 switch (type) { 49 case RegistryObjectManager.EXTENSION_POINT : 50 if (nbrId == 0) 51 return ExtensionPointHandle.EMPTY_ARRAY; 52 results = new ExtensionPointHandle[nbrId]; 53 for (int i = 0; i < nbrId; i++) { 54 results[i] = new ExtensionPointHandle(this, ids[i]); 55 } 56 break; 57 58 case RegistryObjectManager.EXTENSION : 59 if (nbrId == 0) 60 return ExtensionHandle.EMPTY_ARRAY; 61 results = new ExtensionHandle[nbrId]; 62 for (int i = 0; i < nbrId; i++) { 63 results[i] = new ExtensionHandle(this, ids[i]); 64 } 65 break; 66 67 case RegistryObjectManager.CONFIGURATION_ELEMENT : 68 if (nbrId == 0) 69 return ConfigurationElementHandle.EMPTY_ARRAY; 70 results = new ConfigurationElementHandle[nbrId]; 71 for (int i = 0; i < nbrId; i++) { 72 results[i] = new ConfigurationElementHandle(this, ids[i]); 73 } 74 break; 75 76 case RegistryObjectManager.THIRDLEVEL_CONFIGURATION_ELEMENT : 77 if (nbrId == 0) 78 return ConfigurationElementHandle.EMPTY_ARRAY; 79 results = new ThirdLevelConfigurationElementHandle[nbrId]; 80 for (int i = 0; i < nbrId; i++) { 81 results[i] = new ThirdLevelConfigurationElementHandle(this, ids[i]); 82 } 83 break; 84 } 85 return results; 86 } 87 88 synchronized public Object getObject(int id, byte type) { 89 Object result = null; 90 try { 91 result = parent.getObject(id, type); 92 } catch (InvalidRegistryObjectException e) { 93 if (actualObjects != null) { 94 result = actualObjects.get(new Integer (id)); 95 } 96 } 97 if (result == null) 98 throw new InvalidRegistryObjectException(); 99 return result; 100 } 101 102 synchronized public RegistryObject[] getObjects(int[] values, byte type) { 103 if (values.length == 0) { 104 switch (type) { 105 case RegistryObjectManager.EXTENSION_POINT : 106 return ExtensionPoint.EMPTY_ARRAY; 107 case RegistryObjectManager.EXTENSION : 108 return Extension.EMPTY_ARRAY; 109 case RegistryObjectManager.CONFIGURATION_ELEMENT : 110 case RegistryObjectManager.THIRDLEVEL_CONFIGURATION_ELEMENT : 111 return ConfigurationElement.EMPTY_ARRAY; 112 } 113 } 114 115 RegistryObject[] results = null; 116 switch (type) { 117 case RegistryObjectManager.EXTENSION_POINT : 118 results = new ExtensionPoint[values.length]; 119 break; 120 case RegistryObjectManager.EXTENSION : 121 results = new Extension[values.length]; 122 break; 123 case RegistryObjectManager.CONFIGURATION_ELEMENT : 124 case RegistryObjectManager.THIRDLEVEL_CONFIGURATION_ELEMENT : 125 results = new ConfigurationElement[values.length]; 126 break; 127 } 128 for (int i = 0; i < values.length; i++) { 129 results[i] = (RegistryObject) getObject(values[i], type); 130 } 131 return results; 132 } 133 134 public synchronized void close() { 135 actualObjects = null; 136 } 137 } 138 | Popular Tags |