1 9 package org.eclipse.core.internal.runtime; 10 11 import java.util.ArrayList ; 12 import org.eclipse.core.runtime.*; 13 import org.eclipse.osgi.util.NLS; 14 import org.osgi.framework.Bundle; 15 16 22 class AdapterFactoryProxy implements IAdapterFactory, IAdapterFactoryExt { 23 private IConfigurationElement element; 24 27 private IAdapterFactory factory; 28 private boolean factoryLoaded = false; 29 33 private String ownerId; 34 35 39 public static AdapterFactoryProxy createProxy(IConfigurationElement element) { 40 AdapterFactoryProxy result = new AdapterFactoryProxy(); 41 result.element = element; 42 result.ownerId = element.getDeclaringExtension().getUniqueIdentifier(); 43 if ("factory".equals(element.getName())) return result; 45 result.logError(); 46 return null; 47 } 48 49 String getAdaptableType() { 50 String result = element.getAttribute("adaptableType"); if (result != null) 53 return result; 54 logError(); 55 return ""; } 57 58 public Object getAdapter(Object adaptableObject, Class adapterType) { 59 if (!factoryLoaded) 60 loadFactory(false); 61 return factory == null ? null : factory.getAdapter(adaptableObject, adapterType); 62 } 63 64 public Class [] getAdapterList() { 65 if (!factoryLoaded) 66 loadFactory(false); 67 return factory == null ? null : factory.getAdapterList(); 68 } 69 70 public String [] getAdapterNames() { 71 IConfigurationElement[] children = element.getChildren(); 72 ArrayList adapters = new ArrayList (children.length); 73 for (int i = 0; i < children.length; i++) { 74 if ("adapter".equals(children[i].getName())) { String type = children[i].getAttribute("type"); if (type != null) 78 adapters.add(type); 79 } 80 } 81 if (adapters.isEmpty()) 82 logError(); 83 return (String []) adapters.toArray(new String [adapters.size()]); 84 } 85 86 IExtension getExtension() { 87 return element.getDeclaringExtension(); 88 } 89 90 String getOwnerId() { 91 return ownerId; 92 } 93 94 101 public synchronized IAdapterFactory loadFactory(boolean force) { 102 if (factory != null || factoryLoaded) 103 return factory; 104 String bundleId = element.getContributor().getName(); 105 if (!force && Platform.getBundle(bundleId).getState() != Bundle.ACTIVE) 106 return null; 107 factoryLoaded = true; 109 try { 110 factory = (IAdapterFactory) element.createExecutableExtension("class"); } catch (CoreException e) { 112 InternalPlatform.getDefault().log(e.getStatus()); 113 } 114 return factory; 115 } 116 117 120 private void logError() { 121 String msg = NLS.bind(Messages.adapters_badAdapterFactory, element.getContributor().getName()); 122 InternalPlatform.getDefault().log(new Status(IStatus.ERROR, Platform.PI_RUNTIME, 1, msg, null)); 123 } 124 } 125 | Popular Tags |