1 17 package org.eclipse.emf.common.notify.impl; 18 19 20 import java.util.Iterator ; 21 22 import org.eclipse.emf.common.notify.Adapter; 23 import org.eclipse.emf.common.notify.AdapterFactory; 24 import org.eclipse.emf.common.notify.Notifier; 25 26 27 30 public class AdapterFactoryImpl implements AdapterFactory 31 { 32 35 public AdapterFactoryImpl() 36 { 37 } 38 39 44 public boolean isFactoryForType(Object type) 45 { 46 return false; 47 } 48 49 60 public Object adapt(Object target, Object type) 61 { 62 if (target instanceof Notifier) 63 { 64 return adapt((Notifier)target, type); 65 } 66 else 67 { 68 return resolve(target, type); 69 } 70 } 71 72 80 protected Object resolve(Object object, Object type) 81 { 82 return object; 83 } 84 85 88 public Adapter adapt(Notifier target, Object type) 89 { 90 for (Iterator adapters = target.eAdapters().iterator(); adapters.hasNext(); ) 91 { 92 Adapter adapter = (Adapter)adapters.next(); 93 if (adapter.isAdapterForType(type)) 94 { 95 return adapter; 96 } 97 } 98 return adaptNew(target, type); 99 } 100 101 110 public Adapter adaptNew(Notifier target, Object type) 111 { 112 Adapter adapter = createAdapter(target, type); 113 associate(adapter, target); 114 return adapter; 115 } 116 117 123 public void adaptAllNew(Notifier target) 124 { 125 Adapter adapter = createAdapter(target); 126 associate(adapter, target); 127 } 128 129 136 protected Adapter createAdapter(Notifier target, Object type) 137 { 138 return createAdapter(target); 139 } 140 141 147 protected Adapter createAdapter(Notifier target) 148 { 149 return new AdapterImpl(); 150 } 151 152 157 protected void associate(Adapter adapter, Notifier target) 158 { 159 if (adapter != null) 160 { 161 target.eAdapters().add(adapter); 162 } 163 } 164 } 165 | Popular Tags |