1 11 package org.eclipse.ui.internal.components.util; 12 13 import org.eclipse.core.runtime.IAdaptable; 14 import org.eclipse.ui.internal.components.framework.IServiceProvider; 15 16 27 public final class InstanceToServiceProviderAdapter implements IServiceProvider { 28 private Object existingObject; 29 30 public InstanceToServiceProviderAdapter(Object existingObject) { 31 this.existingObject = existingObject; 32 } 33 34 37 public Object getService(Object key) { 38 if (key instanceof Class ) { 39 Class c = (Class )key; 40 41 if (c.isInstance(existingObject)) { 42 return existingObject; 43 } 44 45 if (existingObject instanceof IAdaptable) { 46 return ((IAdaptable)existingObject).getAdapter(c); 47 } 48 } 49 return null; 50 } 51 52 55 public boolean hasService(Object key) { 56 return getService(key) != null; 57 } 58 } 59 | Popular Tags |