@Override public void start ( final BundleContext context ) throws Exception { super.start ( context ); plugin = this; this.treeRoot = new WritableSet ( DisplayRealm.getRealm ( getWorkbench ().getDisplay () ) ); this.treeRootManager = new ConnectionTreeManager ( this.treeRoot ); this.connectionManager = new ConnectionManager ( context ); for ( final Map.Entry<Class<?>, IAdapterFactory> entry : this.adaperFactories.entrySet () ) { Platform.getAdapterManager ().registerAdapters ( entry.getValue (), entry.getKey () ); } }
@Override public void stop ( final BundleContext context ) throws Exception { for ( final Map.Entry<Class<?>, IAdapterFactory> entry : this.adaperFactories.entrySet () ) { Platform.getAdapterManager ().unregisterAdapters ( entry.getValue (), entry.getKey () ); } if ( this.connectionManager != null ) { this.connectionManager.dispose (); this.connectionManager = null; } this.treeRootManager.dispose (); this.treeRoot.dispose (); this.discoverers.dispose (); plugin = null; super.stop ( context ); }
/** * Returns an adapter of the given type for the provided adapter. * * @param adaptable * the object to adapt * @param adapterType * the type to adapt the object to * @param force * <code>true</code> if the plug-in providing the factory should * be activated if necessary. <code>false</code> if no plugin * activations are desired. */ private Object getAdapter(Object adaptable, String adapterType, boolean force) { IAdapterFactory factory = (IAdapterFactory) getFactories( adaptable.getClass()).get(adapterType); if (force && factory instanceof IAdapterFactoryExt) factory = ((IAdapterFactoryExt) factory).loadFactory(true); Object result = null; if (factory != null) { Class clazz = classForName(factory, adapterType); if (clazz != null) result = factory.getAdapter(adaptable, clazz); } if (result == null && adaptable.getClass().getName().equals(adapterType)) return adaptable; return result; }
public void start ( final BundleContext context ) throws Exception { super.start ( context ); for ( final Map.Entry<Class<?>, IAdapterFactory> entry : this.adaperFactories.entrySet () ) { Platform.getAdapterManager ().registerAdapters ( entry.getValue (), entry.getKey () ); } plugin = this; }
public void stop ( final BundleContext context ) throws Exception { plugin = null; for ( final Map.Entry<Class<?>, IAdapterFactory> entry : this.adaperFactories.entrySet () ) { Platform.getAdapterManager ().registerAdapters ( entry.getValue (), entry.getKey () ); } super.stop ( context ); }
/** * @param limpetAdapters */ public void addAdapterFactory(IAdapterFactory newFactory) { if (_adapters == null) { _adapters = new ArrayList<IAdapterFactory>(); } _adapters.add(newFactory); }
private void cacheClassLookup(IAdapterFactory factory, Class clazz) { synchronized (classLookupLock) { // cache reference to lookup to protect against concurrent flush Map lookup = classLookup; if (lookup == null) classLookup = lookup = new HashMap(4); HashMap classes = (HashMap) lookup.get(factory); if (classes == null) { classes = new HashMap(4); lookup.put(factory, classes); } classes.put(clazz.getName(), clazz); } }
private Class cachedClassForName(IAdapterFactory factory, String typeName) { synchronized (classLookupLock) { Class clazz = null; // cache reference to lookup to protect against concurrent flush Map lookup = classLookup; if (lookup != null) { HashMap classes = (HashMap) lookup.get(factory); if (classes != null) { clazz = (Class) classes.get(typeName); } } return clazz; } }
/** * Returns the class with the given fully qualified name, or null if that * class does not exist or belongs to a plug-in that has not yet been * loaded. */ private Class classForName(IAdapterFactory factory, String typeName) { Class clazz = cachedClassForName(factory, typeName); if (clazz == null) { if (factory instanceof IAdapterFactoryExt) factory = ((IAdapterFactoryExt) factory).loadFactory(false); if (factory != null) { // try { // clazz = factory.getClass().getClassLoader() // .loadClass(typeName); // } catch (ClassNotFoundException e) { // // it is possible that the default bundle classloader is // // unaware of this class // // but the adaptor factory can load it in some other way. // // See bug 200068. // if (typeName == null) // return null; // Class[] adapterList = factory.getAdapterList(); // clazz = null; // for (int i = 0; i < adapterList.length; i++) { // if (typeName.equals(adapterList[i].getName())) { // clazz = adapterList[i]; // break; // } // } // if (clazz == null) // return null; // class not yet loaded // } // cacheClassLookup(factory, clazz); } } return clazz; }
public int queryAdapter(Object adaptable, String adapterTypeName) { IAdapterFactory factory = (IAdapterFactory) getFactories( adaptable.getClass()).get(adapterTypeName); if (factory == null) return NONE; if (factory instanceof IAdapterFactoryExt) { factory = ((IAdapterFactoryExt) factory).loadFactory(false); // don't // force // loading if (factory == null) return NOT_LOADED; } return LOADED; }
public void registerFactory(IAdapterFactory factory, String adaptableType) { List list = (List) factories.get(adaptableType); if (list == null) { list = new ArrayList(5); factories.put(adaptableType, list); } list.add(factory); }
public synchronized void unregisterAdapters(IAdapterFactory factory, Class adaptable) { List factoryList = (List) factories.get(adaptable.getName()); if (factoryList == null) return; factoryList.remove(factory); flushLookup(); }
@SuppressWarnings("unchecked") private static IAdapterFactory stubAdapterFactory( Collection<Object> expected ) { IAdapterFactory result = mock( IAdapterFactory.class ); when( result.getAdapter( anyObject(), any( Class.class ) ) ).thenReturn( expected ); when( result.getAdapterList() ).thenReturn( new Class[] { ADAPTER_TYPE_1, ADAPTER_TYPE_2 } ); return result; }
/** * @return */ public ArrayList<IAdapterFactory> getAdapters() { return _adapters; }
protected void newSelection(final ISelection selection) { if (selection == _curSelection) { return; } else { _curSelection = selection; } final List<IStoreItem> res = new ArrayList<IStoreItem>(); if (selection instanceof StructuredSelection) { final StructuredSelection str = (StructuredSelection) selection; // check if it/they are suitable final Iterator<?> iter = str.iterator(); while (iter.hasNext()) { final Object object = iter.next(); if (object instanceof IAdaptable) { final IAdaptable ad = (IAdaptable) object; final IStoreItem coll = (IStoreItem) ad.getAdapter(IStoreItem.class); if (coll != null) { res.add(coll); } } else { // can we adapt it? final ArrayList<IAdapterFactory> adapters = Activator.getDefault().getAdapters(); if (adapters != null) { final Iterator<IAdapterFactory> aIter = adapters.iterator(); while (aIter.hasNext()) { final IAdapterFactory iAdapterFactory = aIter.next(); final Object match = iAdapterFactory.getAdapter(object, IStoreItem.class); if (match != null) { res.add((IStoreItem) match); break; } } } } } } // have we found any, and are they suitable for us? if ((res.size()) > 0 && appliesToMe(res, getATests())) { // ok, stop listening to the old list clearChangeListeners(); // and start listening to the new ones createChangeListeners(res); // ok, display them display(res); } else { // ok, nothing to display - clear the graph // display(new ArrayList<IStoreItem>()); } }
public synchronized void registerAdapters(IAdapterFactory factory, Class adaptable) { registerFactory(factory, adaptable.getName()); flushLookup(); }
public synchronized void unregisterAdapters(IAdapterFactory factory) { for (Iterator it = factories.values().iterator(); it.hasNext();) ((List) it.next()).remove(factory); flushLookup(); }
public IAdapterFactory getFactory( ) { return factory; }
public void setFactory( IAdapterFactory factory ) { this.factory = factory; }
private void registerAdapterFactory( IAdapterFactory adapterFactory, Class<?> type ) { Platform.getAdapterManager().registerAdapters( adapterFactory, type ); this.adapterFactory = adapterFactory; }
/** * Loads the real adapter factory, but only if its associated plug-in is * already loaded. Returns the real factory if it was successfully loaded. * @param force if <code>true</code> the plugin providing the * factory will be loaded if necessary, otherwise no plugin activations * will occur. */ public IAdapterFactory loadFactory(boolean force);