Package org.picocontainer

Examples of org.picocontainer.ComponentAdapter


      return Collections.unmodifiableSet(componentAdapters);
   }

   public final ComponentAdapter getComponentAdapter(Object componentKey) throws AmbiguousComponentResolutionException
   {
      ComponentAdapter adapter = componentKeyToAdapterCache.get(componentKey);
      if (adapter == null && parent != null)
      {
         adapter = parent.getComponentAdapter(componentKey);
      }
      return adapter;
View Full Code Here


   }

   public ComponentAdapter getComponentAdapterOfType(Class componentType)
   {
      // See http://jira.codehaus.org/secure/ViewIssue.jspa?key=PICO-115
      ComponentAdapter adapterByKey = getComponentAdapter(componentType);
      if (adapterByKey != null)
      {
         return adapterByKey;
      }

      List found = getComponentAdaptersOfType(componentType);

      if (found.size() == 1)
      {
         return ((ComponentAdapter)found.get(0));
      }
      else if (found.size() == 0)
      {
         if (parent != null)
         {
            return parent.getComponentAdapterOfType(componentType);
         }
         else
         {
            return null;
         }
      }
      else
      {
         Class[] foundClasses = new Class[found.size()];
         for (int i = 0; i < foundClasses.length; i++)
         {
            ComponentAdapter componentAdapter = (ComponentAdapter)found.get(i);
            foundClasses[i] = componentAdapter.getComponentImplementation();
         }

         throw new AmbiguousComponentResolutionException(componentType, foundClasses);
      }
   }
View Full Code Here

         return Collections.EMPTY_LIST;
      }
      List<ComponentAdapter> found = new ArrayList<ComponentAdapter>();
      for (Iterator<ComponentAdapter> iterator = componentAdapters.iterator(); iterator.hasNext();)
      {
         ComponentAdapter componentAdapter = iterator.next();

         if (componentType.isAssignableFrom(componentAdapter.getComponentImplementation()))
         {
            found.add(componentAdapter);
         }
      }
      return found;
View Full Code Here

   {
      SecurityManager security = System.getSecurityManager();
      if (security != null)
         security.checkPermission(ContainerPermissions.MANAGE_COMPONENT_PERMISSION);    
     
      ComponentAdapter adapter = componentKeyToAdapterCache.remove(componentKey);
      componentAdapters.remove(adapter);
      orderedComponentAdapters.remove(adapter);
      return adapter;
   }
View Full Code Here

         {
            pc.unregisterComponent(contrivedKey);
         }

      }
      ComponentAdapter componentAdapter = new InstanceComponentAdapter(componentKey, componentInstance);
      registerComponent(componentAdapter);
      return componentAdapter;
   }
View Full Code Here

    * passed to the container's constructor.
    */
   public ComponentAdapter registerComponentImplementation(Object componentKey, Class componentImplementation,
      Parameter[] parameters) throws PicoRegistrationException
   {
      ComponentAdapter componentAdapter =
         componentAdapterFactory.createComponentAdapter(componentKey, componentImplementation, parameters);
      registerComponent(componentAdapter);
      return componentAdapter;
   }
View Full Code Here

      }

      Map<ComponentAdapter, Object> adapterToInstanceMap = new HashMap<ComponentAdapter, Object>();
      for (Iterator<ComponentAdapter> iterator = componentAdapters.iterator(); iterator.hasNext();)
      {
         ComponentAdapter componentAdapter = iterator.next();
         if (componentType.isAssignableFrom(componentAdapter.getComponentImplementation()))
         {
            Object componentInstance = getInstance(componentAdapter);
            adapterToInstanceMap.put(componentAdapter, componentInstance);

            // This is to ensure all are added. (Indirect dependencies will be added
View Full Code Here

      return result;
   }

   public Object getComponentInstance(Object componentKey) throws PicoException
   {
      ComponentAdapter componentAdapter = getComponentAdapter(componentKey);
      if (componentAdapter != null)
      {
         return getInstance(componentAdapter);
      }
      else
View Full Code Here

    * be found we get the instance from the {@link ComponentAdapter}.
    * @see org.picocontainer.PicoContainer#getComponentInstanceOfType(java.lang.Class)
    */
   public Object getComponentInstanceOfType(Class componentType)
   {
      final ComponentAdapter componentAdapter = getComponentAdapterOfType(componentType);
      if (componentAdapter == null)
         return null;
      Map<Object, Object> map = depResolutionCtx.get();
      if (map != null)
      {
View Full Code Here

   public ComponentAdapter unregisterComponentByInstance(Object componentInstance)
   {
      for (Iterator<ComponentAdapter> iterator = componentAdapters.iterator(); iterator.hasNext();)
      {
         ComponentAdapter componentAdapter = iterator.next();
         Object o;
         try
         {
            o = getInstance(componentAdapter);
         }
         catch (Exception e)
         {
            // Ignore me,
            // may be caused by lazy initialization mechanism
            continue;
         }
         if (componentInstance.equals(o))
         {
            return unregisterComponent(componentAdapter.getComponentKey());
         }
      }
      return null;
   }
View Full Code Here

TOP

Related Classes of org.picocontainer.ComponentAdapter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.