openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gerdo...@apache.org
Subject svn commit: r732803 [4/17] - in /incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans: ./ annotation/ component/ component/ejb/ component/jms/ component/xml/ config/ container/ context/ context/type/ decorator/ decorator/xml/ de...
Date Thu, 08 Jan 2009 19:41:33 GMT
Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansScanner.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansScanner.java?rev=732803&r1=732802&r2=732803&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansScanner.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansScanner.java Thu Jan  8 11:41:30 2009
@@ -1,18 +1,15 @@
 /*
- *  Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  See the NOTICE file distributed with
- *  this work for additional information regarding copyright ownership.
- *  The ASF licenses this file to You under the Apache License, Version 2.0
- *  (the "License"); you may not use this file except in compliance with
- *  the License.  You may obtain a copy of the License at
- * 
- *       http://www.apache.org/licenses/LICENSE-2.0
- * 
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
+ * or agreed to in writing, software distributed under the License is
+ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the specific language
+ * governing permissions and limitations under the License.
  */
 package org.apache.webbeans.config;
 
@@ -33,209 +30,205 @@
 import org.scannotation.ClasspathUrlFinder;
 import org.scannotation.WarUrlFinder;
 
-
 /**
  * Configures the <b>Web Beans Container</b> at the enterprise application
- * deployment time. 
- * 
+ * deployment time.
  * <p>
- * See the web beans specification section-10 for further details of how to configure
- * web beans container.
+ * See the web beans specification section-10 for further details of how to
+ * configure web beans container.
  * </p>
+ * 
  * @author <a href="mailto:gurkanerdogdu@yahoo.com">Gurkan Erdogdu</a>
  * @since 1.0
  */
 public final class WebBeansScanner
-{	
-	private WebBeansLogger logger = WebBeansLogger.getLogger(WebBeansScanner.class);
-	
-	/**Location of the web-beans.xml files.*/
-	private  Map<String, InputStream>  WEBBEANS_XML_LOCATIONS = new HashMap<String, InputStream>(); 
-	
-	/**Location of the ejb-jar.xml files*/
-	private  Map<String, InputStream> EJB_XML_LOCATIONS = new HashMap<String, InputStream>();
- 
-	/**Annotation Database*/
-	private AnnotationDB ANNOTATION_DB = null;
-	
-	/**It is configured or not*/
-	private boolean configure = false;
-	
-	private ServletContext servletContext = null;
-	
-	public WebBeansScanner()
-	{
-		
-	}
-		
-	/**
-	 * Configure the Web Beans Container with deployment information and fills
-	 * annotation database and web-beans.xml stream database.
-	 * 
-	 * @throws WebBeansConfigurationException if any run time exception occurs
-	 */
-	public void scan(ServletContext servletContext) throws WebBeansConfigurationException
-	{
-		if(!configure)
-		{
-			this.servletContext = servletContext;
-			 
-			configureAnnotationDB();
-			configure = true;
-			
-		}
-		
-	}
-		
-	/*Configures annotation database*/
-	private void configureAnnotationDB() throws WebBeansConfigurationException
-	{
-		try
-		{
-			Set<URL> arcs = getArchieves();
-			URL[] urls = new URL[arcs.size()];
-			arcs.toArray(urls);
-			
-			if(ANNOTATION_DB  == null)
-			{
-				ANNOTATION_DB = new AnnotationDB();
-
-				ANNOTATION_DB.setScanClassAnnotations(true);
-				ANNOTATION_DB.scanArchives(urls);
-				ANNOTATION_DB.crossReferenceMetaAnnotations();
-
-			}
-						
-		}catch(Throwable e)
-		{
-			logger.error("Initializing of the WebBeans container is failed.", e);
-			throw new WebBeansConfigurationException(e);
-		}
-				
-	}
-	
-	/*Collects all URLs*/
-	private Set<URL> getArchieves() throws Throwable
-	{
-		Set<URL> lists = createURLFromMarkerFile();
-		URL warUrl = createURLFromWARFile();
-		
-		if(warUrl != null)
-		{
-			lists.add(warUrl);
-		}
-		
-		return lists;
-	}
-
-	/*Creates URLs from the marker file*/
-	private Set<URL> createURLFromMarkerFile() throws Throwable
-	{
-		Set<URL> listURL = new HashSet<URL>();
-		URL[] urls = null;
-		
-		//Root with web-beans.xml marker.
-		urls = ClasspathUrlFinder.findResourceBases("META-INF/web-beans.xml", WebBeansUtil.getCurrentClassLoader());
-		
-		if(urls != null)
-		{
-			for(URL url : urls)
-			{
-				
-				URL addPath = null;
-				
-				String fileDir = url.getFile();
-				if(fileDir.endsWith(".jar!/"))
-				{
-					fileDir = fileDir.substring(0, fileDir.lastIndexOf("/")) + "/META-INF/web-beans.xml";
-					addPath = new URL("jar:" + fileDir);	
-				}
-				else
-				{
-					addPath = new URL("file:" + url.getFile() + "META-INF/web-beans.xml");	
-				}
-				
-				listURL.add(url);
-				WEBBEANS_XML_LOCATIONS.put(addPath.getFile(), addPath.openStream());
-			}
-		}
-		
-		//Scan for ejb-jar.xml
-		URL[] ejbUrls = ClasspathUrlFinder.findResourceBases("META-INF/ejb-jar.xml",WebBeansUtil.getCurrentClassLoader());
-		
-		if(ejbUrls != null && ejbUrls.length > 0)
-		{
-			for(URL ejbUrl : ejbUrls)
-			{
-				//ok, web-beans.xml and ejb-jar.xml is in the same root
-				if(listURL.contains(ejbUrl))
-				{
-					URL addPath = null;
-				
-					String fileDir = ejbUrl.getFile();
-					
-					if(fileDir.endsWith(".jar!/"))
-					{
-						fileDir = fileDir.substring(0, fileDir.lastIndexOf("/")) + "/META-INF/ejb-jar.xml";
-						addPath = new URL("jar:" + fileDir);	
-					}
-					else
-					{
-						addPath = new URL("file:" + ejbUrl.getFile() + "META-INF/ejb-jar.xml");	
-					}
-										
-					EJB_XML_LOCATIONS.put(addPath.getFile(),addPath.openStream());
-				}
-			}
-		}
-		
-		
-		return listURL;
-	}
-	
-	private URL createURLFromWARFile() throws Throwable
-	{
-		URL url = this.servletContext.getResource("/WEB-INF/web-beans.xml");
-
-		if(url != null)
-		{
-			WEBBEANS_XML_LOCATIONS.put(url.getFile(), url.openStream());
-			
-			return WarUrlFinder.findWebInfClassesPath(this.servletContext);
-		}
-		
-		return null;
-	}
-	
-	/**
-	 * Gets list of stream that points to the web-beans.xml file in
-	 * the specific locations.
-	 * 
-	 * @return list of stream
-	 */
-	public Map<String,InputStream> getWEBBEANS_XML_LOCATIONS()
-	{
-		return WEBBEANS_XML_LOCATIONS;
-	}
-	
-	/**
-	 * Gets list of stream that points to the ejb-jar.xml file in
-	 * the specific locations.
-	 * 
-	 * @return list of stream
-	 */
-	public Map<String,InputStream> getEJB_XML_LOCATIONS()
-	{
-		return EJB_XML_LOCATIONS;
-	}
-	
-
-	/**
-	 * Gets annotated classes.
-	 * @return annotation database
-	 */
-	public AnnotationDB getANNOTATION_DB()
-	{	
-		return ANNOTATION_DB;
-	}	
+{
+    private WebBeansLogger logger = WebBeansLogger.getLogger(WebBeansScanner.class);
+
+    /** Location of the web-beans.xml files. */
+    private Map<String, InputStream> WEBBEANS_XML_LOCATIONS = new HashMap<String, InputStream>();
+
+    /** Location of the ejb-jar.xml files */
+    private Map<String, InputStream> EJB_XML_LOCATIONS = new HashMap<String, InputStream>();
+
+    /** Annotation Database */
+    private AnnotationDB ANNOTATION_DB = null;
+
+    /** It is configured or not */
+    private boolean configure = false;
+
+    private ServletContext servletContext = null;
+
+    public WebBeansScanner()
+    {
+
+    }
+
+    /**
+     * Configure the Web Beans Container with deployment information and fills
+     * annotation database and web-beans.xml stream database.
+     * 
+     * @throws WebBeansConfigurationException if any run time exception occurs
+     */
+    public void scan(ServletContext servletContext) throws WebBeansConfigurationException
+    {
+        if (!configure)
+        {
+            this.servletContext = servletContext;
+
+            configureAnnotationDB();
+            configure = true;
+
+        }
+
+    }
+
+    /* Configures annotation database */
+    private void configureAnnotationDB() throws WebBeansConfigurationException
+    {
+        try
+        {
+            Set<URL> arcs = getArchieves();
+            URL[] urls = new URL[arcs.size()];
+            arcs.toArray(urls);
+
+            if (ANNOTATION_DB == null)
+            {
+                ANNOTATION_DB = new AnnotationDB();
+
+                ANNOTATION_DB.setScanClassAnnotations(true);
+                ANNOTATION_DB.scanArchives(urls);
+                ANNOTATION_DB.crossReferenceMetaAnnotations();
+
+            }
+
+        } catch (Throwable e)
+        {
+            logger.error("Initializing of the WebBeans container is failed.", e);
+            throw new WebBeansConfigurationException(e);
+        }
+
+    }
+
+    /* Collects all URLs */
+    private Set<URL> getArchieves() throws Throwable
+    {
+        Set<URL> lists = createURLFromMarkerFile();
+        URL warUrl = createURLFromWARFile();
+
+        if (warUrl != null)
+        {
+            lists.add(warUrl);
+        }
+
+        return lists;
+    }
+
+    /* Creates URLs from the marker file */
+    private Set<URL> createURLFromMarkerFile() throws Throwable
+    {
+        Set<URL> listURL = new HashSet<URL>();
+        URL[] urls = null;
+
+        // Root with web-beans.xml marker.
+        urls = ClasspathUrlFinder.findResourceBases("META-INF/web-beans.xml", WebBeansUtil.getCurrentClassLoader());
+
+        if (urls != null)
+        {
+            for (URL url : urls)
+            {
+
+                URL addPath = null;
+
+                String fileDir = url.getFile();
+                if (fileDir.endsWith(".jar!/"))
+                {
+                    fileDir = fileDir.substring(0, fileDir.lastIndexOf("/")) + "/META-INF/web-beans.xml";
+                    addPath = new URL("jar:" + fileDir);
+                } else
+                {
+                    addPath = new URL("file:" + url.getFile() + "META-INF/web-beans.xml");
+                }
+
+                listURL.add(url);
+                WEBBEANS_XML_LOCATIONS.put(addPath.getFile(), addPath.openStream());
+            }
+        }
+
+        // Scan for ejb-jar.xml
+        URL[] ejbUrls = ClasspathUrlFinder.findResourceBases("META-INF/ejb-jar.xml", WebBeansUtil.getCurrentClassLoader());
+
+        if (ejbUrls != null && ejbUrls.length > 0)
+        {
+            for (URL ejbUrl : ejbUrls)
+            {
+                // ok, web-beans.xml and ejb-jar.xml is in the same root
+                if (listURL.contains(ejbUrl))
+                {
+                    URL addPath = null;
+
+                    String fileDir = ejbUrl.getFile();
+
+                    if (fileDir.endsWith(".jar!/"))
+                    {
+                        fileDir = fileDir.substring(0, fileDir.lastIndexOf("/")) + "/META-INF/ejb-jar.xml";
+                        addPath = new URL("jar:" + fileDir);
+                    } else
+                    {
+                        addPath = new URL("file:" + ejbUrl.getFile() + "META-INF/ejb-jar.xml");
+                    }
+
+                    EJB_XML_LOCATIONS.put(addPath.getFile(), addPath.openStream());
+                }
+            }
+        }
+
+        return listURL;
+    }
+
+    private URL createURLFromWARFile() throws Throwable
+    {
+        URL url = this.servletContext.getResource("/WEB-INF/web-beans.xml");
+
+        if (url != null)
+        {
+            WEBBEANS_XML_LOCATIONS.put(url.getFile(), url.openStream());
+
+            return WarUrlFinder.findWebInfClassesPath(this.servletContext);
+        }
+
+        return null;
+    }
+
+    /**
+     * Gets list of stream that points to the web-beans.xml file in the specific
+     * locations.
+     * 
+     * @return list of stream
+     */
+    public Map<String, InputStream> getWEBBEANS_XML_LOCATIONS()
+    {
+        return WEBBEANS_XML_LOCATIONS;
+    }
+
+    /**
+     * Gets list of stream that points to the ejb-jar.xml file in the specific
+     * locations.
+     * 
+     * @return list of stream
+     */
+    public Map<String, InputStream> getEJB_XML_LOCATIONS()
+    {
+        return EJB_XML_LOCATIONS;
+    }
+
+    /**
+     * Gets annotated classes.
+     * 
+     * @return annotation database
+     */
+    public AnnotationDB getANNOTATION_DB()
+    {
+        return ANNOTATION_DB;
+    }
 }

Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionResolver.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionResolver.java?rev=732803&r1=732802&r2=732803&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionResolver.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionResolver.java Thu Jan  8 11:41:30 2009
@@ -34,251 +34,251 @@
 @SuppressWarnings("unchecked")
 public class InjectionResolver
 {
-	public InjectionResolver()
-	{
+    public InjectionResolver()
+    {
 
-	}
+    }
 
-	public static InjectionResolver getInstance()
-	{
-		InjectionResolver instance = (InjectionResolver) WebBeansFinder.getSingletonInstance(WebBeansFinder.SINGLETON_INJECTION_RESOLVER);
-		return instance;
-	}
-
-	public Set<Bean<?>> implResolveByName(String name)
-	{
-		Asserts.assertNotNull(name, "name parameter can not be null");
-
-		ManagerImpl manager = ManagerImpl.getManager();
-
-		Set<Bean<?>> resolvedComponents = new HashSet<Bean<?>>();
-		Bean<?> resolvedComponent = null;
-		Set<Bean<?>> deployedComponents = manager.getBeans();
-
-		Iterator<Bean<?>> it = deployedComponents.iterator();
-		while (it.hasNext())
-		{
-			Bean<?> component = it.next();
-
-			if (component.getName() != null)
-			{
-				if (component.getName().equals(name))
-				{
-					if (resolvedComponent == null)
-					{
-						resolvedComponent = component;
-						resolvedComponents.add(resolvedComponent);
-					} else
-					{
-						if (DeploymentTypeManager.getInstance().comparePrecedences(component.getDeploymentType(), resolvedComponent.getDeploymentType()) > 0)
-						{
-							resolvedComponents.clear();
-							resolvedComponent = component;
-							resolvedComponents.add(resolvedComponent);
-						} else if (DeploymentTypeManager.getInstance().comparePrecedences(component.getDeploymentType(), resolvedComponent.getDeploymentType()) == 0)
-						{
-							resolvedComponents.add(component);
-						}
-					}
-				}
-			}
-		}
-
-		return resolvedComponents;
-	}
-
-	public <T> Set<Bean<T>> implResolveByType(Class<?> apiType, Type[] actualTypeArguments, Annotation... binding)
-	{
-		Asserts.assertNotNull(apiType, "apiType parameter can not be null");
-		Asserts.assertNotNull(binding, "binding parameter can not be null");
-
-		ManagerImpl manager = ManagerImpl.getManager();
-
-		boolean currentBinding = false;
-		boolean returnAll = false;
-
-		if (binding.length == 0)
-		{
-			binding = new Annotation[1];
-			binding[0] = new CurrentLiteral();
-			currentBinding = true;
-		}
-
-		Set<Bean<T>> results = new HashSet<Bean<T>>();
-		Set<Bean<?>> deployedComponents = manager.getBeans();
-
-		if (apiType.equals(Object.class) && currentBinding)
-		{
-			returnAll = true;
-		}
-
-		Iterator<Bean<?>> it = deployedComponents.iterator();
-
-		while (it.hasNext())
-		{
-			Bean<?> component = it.next();
-
-			if (returnAll)
-			{
-				results.add((Bean<T>) component);
-				continue;
-			}
-
-			else
-			{
-				Set<Class<?>> componentApiTypes = component.getTypes();
-				Iterator<Class<?>> itComponentApiTypes = componentApiTypes.iterator();
-				while (itComponentApiTypes.hasNext())
-				{
-					Class<?> componentApiType = itComponentApiTypes.next();
-
-					if (actualTypeArguments.length > 0)
-					{
-						Type[] actualArgs = null;
-						if (ClassUtil.isAssignable(apiType, componentApiType))
-						{
-							/*
-							 * Annotated Producer method or XML Defined Producer
-							 * Method
-							 */
-							if (ProducerComponentImpl.class.isAssignableFrom(component.getClass()))
-							{
-								actualArgs = ((ProducerComponentImpl<?>) component).getActualTypeArguments();
-								if (Arrays.equals(actualArgs, actualTypeArguments))
-								{
-									results.add((Bean<T>) component);
-									break;
-								}
-
-							}
-
-							else
-							{
-								actualArgs = ClassUtil.getGenericSuperClassTypeArguments(componentApiType);
-								if (Arrays.equals(actualArgs, actualTypeArguments))
-								{
-									results.add((Bean<T>) component);
-									break;
-								} else
-								{
-									List<Type[]> listActualArgs = ClassUtil.getGenericSuperInterfacesTypeArguments(componentApiType);
-									Iterator<Type[]> itListActualArgs = listActualArgs.iterator();
-									while (itListActualArgs.hasNext())
-									{
-										actualArgs = itListActualArgs.next();
-
-										if (Arrays.equals(actualArgs, actualTypeArguments))
-										{
-											results.add((Bean<T>) component);
-											break;
-										}
-
-									}
-								}
-
-							}
-
-						}
-					} else
-					{
-						if (apiType instanceof Class)
-						{
-							if (ClassUtil.isAssignable((Class<?>) apiType, componentApiType))
-							{
-								results.add((Bean<T>) component);
-								break;
-							}
-						}
-					}
-				}
-			}
-		}
-
-		results = findByBindingType(results, binding);
-
-		if (results != null && !results.isEmpty())
-		{
-			results = findByPrecedence(results);
-		}
-
-		return results;
-	}
-
-	private <T> Set<Bean<T>> findByPrecedence(Set<Bean<T>> result)
-	{
-		Bean<T> resolvedComponent = null;
-		Iterator<Bean<T>> it = result.iterator();
-		Set<Bean<T>> res = new HashSet<Bean<T>>();
-
-		while (it.hasNext())
-		{
-			Bean<T> component = it.next();
-
-			if (resolvedComponent == null)
-			{
-				resolvedComponent = component;
-				res.add(resolvedComponent);
-			} else
-			{
-				DeploymentTypeManager typeManager = DeploymentTypeManager.getInstance();
-
-				if (typeManager.comparePrecedences(component.getDeploymentType(), resolvedComponent.getDeploymentType()) < 0)
-				{
-					continue;
-				} else if (typeManager.comparePrecedences(component.getDeploymentType(), resolvedComponent.getDeploymentType()) > 0)
-				{
-					res.clear();
-					resolvedComponent = component;
-					res.add(resolvedComponent);
-
-				} else
-				{
-					res.add(component);
-				}
-			}
-		}
-
-		return res;
-	}
-
-	private <T> Set<Bean<T>> findByBindingType(Set<Bean<T>> remainingSet, Annotation... annotations)
-	{
-		Iterator<Bean<T>> it = remainingSet.iterator();
-		Set<Bean<T>> result = new HashSet<Bean<T>>();
-
-		while (it.hasNext())
-		{
-			Bean<T> component = it.next();
-			Set<Annotation> bTypes = component.getBindingTypes();
-
-			int i = 0;
-			for (Annotation annot : annotations)
-			{
-				Iterator<Annotation> itBindingTypes = bTypes.iterator();
-				while (itBindingTypes.hasNext())
-				{
-					Annotation bindingType = itBindingTypes.next();
-					if (annot.annotationType().equals(bindingType.annotationType()))
-					{
-						if (AnnotationUtil.isAnnotationMemberExist(bindingType.annotationType(), bindingType, annot))
-						{
-							i++;
-						}
-					}
-
-				}
-			}
-
-			if (i == annotations.length)
-			{
-				result.add(component);
-				i = 0;
-			}
+    public static InjectionResolver getInstance()
+    {
+        InjectionResolver instance = (InjectionResolver) WebBeansFinder.getSingletonInstance(WebBeansFinder.SINGLETON_INJECTION_RESOLVER);
+        return instance;
+    }
+
+    public Set<Bean<?>> implResolveByName(String name)
+    {
+        Asserts.assertNotNull(name, "name parameter can not be null");
+
+        ManagerImpl manager = ManagerImpl.getManager();
+
+        Set<Bean<?>> resolvedComponents = new HashSet<Bean<?>>();
+        Bean<?> resolvedComponent = null;
+        Set<Bean<?>> deployedComponents = manager.getBeans();
+
+        Iterator<Bean<?>> it = deployedComponents.iterator();
+        while (it.hasNext())
+        {
+            Bean<?> component = it.next();
+
+            if (component.getName() != null)
+            {
+                if (component.getName().equals(name))
+                {
+                    if (resolvedComponent == null)
+                    {
+                        resolvedComponent = component;
+                        resolvedComponents.add(resolvedComponent);
+                    } else
+                    {
+                        if (DeploymentTypeManager.getInstance().comparePrecedences(component.getDeploymentType(), resolvedComponent.getDeploymentType()) > 0)
+                        {
+                            resolvedComponents.clear();
+                            resolvedComponent = component;
+                            resolvedComponents.add(resolvedComponent);
+                        } else if (DeploymentTypeManager.getInstance().comparePrecedences(component.getDeploymentType(), resolvedComponent.getDeploymentType()) == 0)
+                        {
+                            resolvedComponents.add(component);
+                        }
+                    }
+                }
+            }
+        }
+
+        return resolvedComponents;
+    }
+
+    public <T> Set<Bean<T>> implResolveByType(Class<?> apiType, Type[] actualTypeArguments, Annotation... binding)
+    {
+        Asserts.assertNotNull(apiType, "apiType parameter can not be null");
+        Asserts.assertNotNull(binding, "binding parameter can not be null");
+
+        ManagerImpl manager = ManagerImpl.getManager();
+
+        boolean currentBinding = false;
+        boolean returnAll = false;
+
+        if (binding.length == 0)
+        {
+            binding = new Annotation[1];
+            binding[0] = new CurrentLiteral();
+            currentBinding = true;
+        }
+
+        Set<Bean<T>> results = new HashSet<Bean<T>>();
+        Set<Bean<?>> deployedComponents = manager.getBeans();
+
+        if (apiType.equals(Object.class) && currentBinding)
+        {
+            returnAll = true;
+        }
+
+        Iterator<Bean<?>> it = deployedComponents.iterator();
+
+        while (it.hasNext())
+        {
+            Bean<?> component = it.next();
+
+            if (returnAll)
+            {
+                results.add((Bean<T>) component);
+                continue;
+            }
+
+            else
+            {
+                Set<Class<?>> componentApiTypes = component.getTypes();
+                Iterator<Class<?>> itComponentApiTypes = componentApiTypes.iterator();
+                while (itComponentApiTypes.hasNext())
+                {
+                    Class<?> componentApiType = itComponentApiTypes.next();
+
+                    if (actualTypeArguments.length > 0)
+                    {
+                        Type[] actualArgs = null;
+                        if (ClassUtil.isAssignable(apiType, componentApiType))
+                        {
+                            /*
+                             * Annotated Producer method or XML Defined Producer
+                             * Method
+                             */
+                            if (ProducerComponentImpl.class.isAssignableFrom(component.getClass()))
+                            {
+                                actualArgs = ((ProducerComponentImpl<?>) component).getActualTypeArguments();
+                                if (Arrays.equals(actualArgs, actualTypeArguments))
+                                {
+                                    results.add((Bean<T>) component);
+                                    break;
+                                }
+
+                            }
+
+                            else
+                            {
+                                actualArgs = ClassUtil.getGenericSuperClassTypeArguments(componentApiType);
+                                if (Arrays.equals(actualArgs, actualTypeArguments))
+                                {
+                                    results.add((Bean<T>) component);
+                                    break;
+                                } else
+                                {
+                                    List<Type[]> listActualArgs = ClassUtil.getGenericSuperInterfacesTypeArguments(componentApiType);
+                                    Iterator<Type[]> itListActualArgs = listActualArgs.iterator();
+                                    while (itListActualArgs.hasNext())
+                                    {
+                                        actualArgs = itListActualArgs.next();
+
+                                        if (Arrays.equals(actualArgs, actualTypeArguments))
+                                        {
+                                            results.add((Bean<T>) component);
+                                            break;
+                                        }
+
+                                    }
+                                }
+
+                            }
+
+                        }
+                    } else
+                    {
+                        if (apiType instanceof Class)
+                        {
+                            if (ClassUtil.isAssignable((Class<?>) apiType, componentApiType))
+                            {
+                                results.add((Bean<T>) component);
+                                break;
+                            }
+                        }
+                    }
+                }
+            }
+        }
+
+        results = findByBindingType(results, binding);
+
+        if (results != null && !results.isEmpty())
+        {
+            results = findByPrecedence(results);
+        }
+
+        return results;
+    }
+
+    private <T> Set<Bean<T>> findByPrecedence(Set<Bean<T>> result)
+    {
+        Bean<T> resolvedComponent = null;
+        Iterator<Bean<T>> it = result.iterator();
+        Set<Bean<T>> res = new HashSet<Bean<T>>();
+
+        while (it.hasNext())
+        {
+            Bean<T> component = it.next();
+
+            if (resolvedComponent == null)
+            {
+                resolvedComponent = component;
+                res.add(resolvedComponent);
+            } else
+            {
+                DeploymentTypeManager typeManager = DeploymentTypeManager.getInstance();
+
+                if (typeManager.comparePrecedences(component.getDeploymentType(), resolvedComponent.getDeploymentType()) < 0)
+                {
+                    continue;
+                } else if (typeManager.comparePrecedences(component.getDeploymentType(), resolvedComponent.getDeploymentType()) > 0)
+                {
+                    res.clear();
+                    resolvedComponent = component;
+                    res.add(resolvedComponent);
+
+                } else
+                {
+                    res.add(component);
+                }
+            }
+        }
+
+        return res;
+    }
+
+    private <T> Set<Bean<T>> findByBindingType(Set<Bean<T>> remainingSet, Annotation... annotations)
+    {
+        Iterator<Bean<T>> it = remainingSet.iterator();
+        Set<Bean<T>> result = new HashSet<Bean<T>>();
+
+        while (it.hasNext())
+        {
+            Bean<T> component = it.next();
+            Set<Annotation> bTypes = component.getBindingTypes();
+
+            int i = 0;
+            for (Annotation annot : annotations)
+            {
+                Iterator<Annotation> itBindingTypes = bTypes.iterator();
+                while (itBindingTypes.hasNext())
+                {
+                    Annotation bindingType = itBindingTypes.next();
+                    if (annot.annotationType().equals(bindingType.annotationType()))
+                    {
+                        if (AnnotationUtil.isAnnotationMemberExist(bindingType.annotationType(), bindingType, annot))
+                        {
+                            i++;
+                        }
+                    }
+
+                }
+            }
+
+            if (i == annotations.length)
+            {
+                result.add(component);
+                i = 0;
+            }
 
-		}
+        }
 
-		remainingSet = null;
+        remainingSet = null;
 
-		return result;
-	}
+        return result;
+    }
 }
\ No newline at end of file

Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/ManagerImpl.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/ManagerImpl.java?rev=732803&r1=732802&r2=732803&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/ManagerImpl.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/ManagerImpl.java Thu Jan  8 11:41:30 2009
@@ -1,18 +1,15 @@
 /*
- *  Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  See the NOTICE file distributed with
- *  this work for additional information regarding copyright ownership.
- *  The ASF licenses this file to You under the Apache License, Version 2.0
- *  (the "License"); you may not use this file except in compliance with
- *  the License.  You may obtain a copy of the License at
- * 
- *       http://www.apache.org/licenses/LICENSE-2.0
- * 
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
+ * or agreed to in writing, software distributed under the License is
+ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the specific language
+ * governing permissions and limitations under the License.
  */
 package org.apache.webbeans.container;
 
@@ -62,320 +59,317 @@
 import org.apache.webbeans.util.ClassUtil;
 import org.apache.webbeans.util.WebBeansUtil;
 
-
 /**
  * Implementation of the {@link WebBeansManager} contract of the web beans
  * container.
  * 
  * @author <a href="mailto:gurkanerdogdu@yahoo.com">Gurkan Erdogdu</a>
  * @since 1.0
- * 
  * @see java.webbeans.WebBeansManager
  */
 @SuppressWarnings("unchecked")
 public class ManagerImpl implements Manager, Referenceable
 {
-	private Map<Class<? extends Annotation>, Context> contextMap = new ConcurrentHashMap<Class<? extends Annotation>, Context>();
-	
-	private Set<Bean<?>> components = new CopyOnWriteArraySet<Bean<?>>();
-	
-	private Set<Interceptor> webBeansInterceptors = new CopyOnWriteArraySet<Interceptor>();
-	
-	private Set<Decorator> webBeansDecorators = new CopyOnWriteArraySet<Decorator>();
-
-	private NotificationManager notificationManager = null;
-	
-	private InjectionResolver injectionResolver = null;
-	
-	private Map<Bean<?>, Object> proxyMap = Collections.synchronizedMap(new IdentityHashMap<Bean<?>, Object>());
-	
-	public ManagerImpl()
-	{		
-		injectionResolver = InjectionResolver.getInstance();
-		notificationManager = NotificationManager.getInstance();
-	}
-	
-	public static ManagerImpl getManager()
-	{
-		ManagerImpl instance = (ManagerImpl) WebBeansFinder.getSingletonInstance(WebBeansFinder.SINGLETON_MANAGER);
-		
-		return instance;
-	}
-	
-	public Context getContext(Class<? extends Annotation> scopType)
-	{
-		Asserts.assertNotNull(scopType, "scopeType paramter can not be null");		
-		
-		Context ctx = null;
-		
-		ctx = ContextFactory.getStandartContext(scopType);
-		
-		if(ctx == null)
-		{
-			ctx = getManager().contextMap.get(scopType);
-		}
-
-		//Still null
-		if(ctx == null)
-		{
-			throw new ContextNotActiveException("WebBeans context with scope type annotation @" + scopType.getSimpleName() +  " is not exist within current thread");	
-		}			
-
-		return ctx;
-	}
-
-	public Manager addBean(Bean<?> component)
-	{
-		getManager().components.add(component);
-		
-		return this;
-	}
-
-	public Manager addContext(Context context)
-	{
-		addContext(context.getScopeType(), context);
-		
-		return this;
-		
-	}
-
-	public void fireEvent(Object event, Annotation... bindings)
-	{
-		if(ClassUtil.isParametrized(event.getClass()))
-		{
-			throw new WebBeansConfigurationException("Event class : " + event.getClass().getName() + " can not be defined as generic type");
-		}
-		
-		this.notificationManager.fireEvent(event, bindings);
-	}
-
-	public Object getInstanceByName(String name)
-	{
-		AbstractComponent<?> component = null;
-		Object object = null;
-
-		Set<Bean<?>> set = this.injectionResolver.implResolveByName(name);
-		if(set.isEmpty())
-		{
-			return null;
-		}
-		
-		if(set.size() > 1)
-		{
-			throw new AmbiguousDependencyException("There are more than one WebBeans with name : " + name);
-		}			
-		
-		component = (AbstractComponent<?>) set.iterator().next();
-		
-		object = getInstance(component);
-			
-		return object;
-	}
-
-	public <T> T getInstanceByType(Class<T> type, Annotation... bindingTypes)
-	{	
-		ResolutionUtil.getInstanceByTypeConditions(bindingTypes);
-		Set<Bean<T>> set = resolveByType(type, bindingTypes);
-		
-		ResolutionUtil.checkResolvedBeans(set, type);
-		
-		return getInstance(set.iterator().next());
-	}
-
-	public <T> T getInstanceByType(TypeLiteral<T> type, Annotation... bindingTypes)
-	{
-		ResolutionUtil.getInstanceByTypeConditions(bindingTypes);
-		Set<Bean<T>> set = resolveByType(type, bindingTypes);
-		
-		ResolutionUtil.checkResolvedBeans(set, type.getRawType());
-		
-		return getInstance(set.iterator().next());
-	}
-
-	public Set<Bean<?>> resolveByName(String name)
-	{
-		return this.injectionResolver.implResolveByName(name);
-	}
-
-	public <T> Set<Bean<T>> resolveByType(Class<T> apiType, Annotation... bindingTypes)
-	{
-		return this.injectionResolver.implResolveByType(apiType, new Type[0], bindingTypes);
-	}
-
-	public <T> Set<Bean<T>> resolveByType(TypeLiteral<T> apiType, Annotation... bindingTypes)
-	{
-		ParameterizedType ptype = (ParameterizedType)apiType.getType();
-		ResolutionUtil.resolveByTypeConditions(ptype);
-		
-		Type[] args = ptype.getActualTypeArguments();
-		return this.injectionResolver.implResolveByType(apiType.getRawType(),args , bindingTypes);
-	}
-
-	public <T> Set<Observer<T>> resolveObservers(T event, Annotation... bindings)
-	{
-		return this.notificationManager.resolveObservers(event, bindings);
-	}
-
-	public  Set<Bean<?>> getComponents()
-	{
-		return getManager().components;
-	}
-
-	public Manager addDecorator(Decorator decorator)
-	{
-		getManager().webBeansDecorators.add(decorator);
-		return this;
-	}
-
-	public Manager addInterceptor(Interceptor interceptor)
-	{
-		getManager().webBeansInterceptors.add(interceptor);
-		return this;
-	}
-
-	public <T> Manager addObserver(Observer<T> observer, Class<T> eventType, Annotation... bindings)
-	{
-		this.notificationManager.addObserver(observer, eventType, bindings);
-		return this;
-	}
-
-	public <T> Manager addObserver(Observer<T> observer, TypeLiteral<T> eventType, Annotation... bindings)
-	{	
-		this.notificationManager.addObserver(observer, eventType, bindings);
-		return this;
-	}
-
-	public <T> T getInstance(Bean<T> bean)
-	{
-		Context context = null;
-		DependentContext dependentContext = null;
-		T instance = null;
-		boolean isSetOnThis = false;
-		
-		try
-		{
-			dependentContext = (DependentContext)getContext(Dependent.class);
-			if(!dependentContext.isActive())
-			{
-				dependentContext.setActive(true);	
-				isSetOnThis = true;
-			}
-			
-			
-			/*@ScopeType is normal*/
-			if(WebBeansUtil.isScopeTypeNormal(bean.getScopeType()))
-			{
-				if(this.proxyMap.containsKey(bean))
-				{
-					instance = (T)this.proxyMap.get(bean);
-				}
-				else
-				{
-					instance =(T) JavassistProxyFactory.createNewProxyInstance(bean);
-					
-					this.proxyMap.put(bean, instance);
-				}
-			}
-			/*@ScopeType is not normal*/
-			else
-			{
-				context = getContext(bean.getScopeType());
-				instance = context.get(bean, true);					
-			}
-						
-		}finally
-		{
-			if(isSetOnThis)
-			{
-				dependentContext.setActive(false);	
-			}
-		}
-		
-		return instance;
-	}
-
-	public <T> Manager removeObserver(Observer<T> observer, Class<T> eventType, Annotation... bindings)
-	{
-		this.notificationManager.removeObserver(observer, eventType, bindings);
-		return this;
-	}
-
-	public <T> Manager removeObserver(Observer<T> observer, TypeLiteral<T> eventType, Annotation... bindings)
-	{
-		this.notificationManager.removeObserver(observer, eventType, bindings);
-		return this;
-	}
-
-	public List<Decorator> resolveDecorators(Set<Class<?>> types, Annotation... bindingTypes)
-	{
-		WebBeansUtil.checkDecoratorResolverParams(types, bindingTypes);
-		Set<Decorator> intsSet = WebBeansDecoratorConfig.findDeployedWebBeansDecorator(types, bindingTypes);
-		Iterator<Decorator> itSet = intsSet.iterator();
-		
-		List<Decorator> decoratorList = new ArrayList<Decorator>();
-		while(itSet.hasNext())
-		{
-			WebBeansDecorator decorator = (WebBeansDecorator)itSet.next();
-			decoratorList.add(decorator);
-			
-		}
-		
-		Collections.sort(decoratorList, new DecoratorComparator());
-		
-		return decoratorList;
-		
-	}
-
-	public List<Interceptor> resolveInterceptors(InterceptionType type, Annotation... interceptorBindings)
-	{
-		WebBeansUtil.checkInterceptorResolverParams(interceptorBindings);
-		
-		Set<Interceptor> intsSet = WebBeansInterceptorConfig.findDeployedWebBeansInterceptor(interceptorBindings);
-		Iterator<Interceptor> itSet = intsSet.iterator();
-		
-		List<Interceptor> interceptorList = new ArrayList<Interceptor>();
-		while(itSet.hasNext())
-		{
-			WebBeansInterceptor interceptor = (WebBeansInterceptor)itSet.next();
-			
-			if(interceptor.getMethod(type) != null)
-			{
-				interceptorList.add(interceptor);	
-			}
-			
-		}
-		
-		Collections.sort(interceptorList, new InterceptorComparator());
-		
-		return interceptorList;
-	}
-		
-	public Set<Bean<?>> getBeans()
-	{
-		return getManager().components;
-	}
-	
-	public Set<Interceptor> getInterceptors()
-	{
-		return getManager().webBeansInterceptors;
-	}
-	
-	public Set<Decorator> getDecorators()
-	{
-		return getManager().webBeansDecorators;
-	}
-	
-	private void addContext(Class<? extends Annotation> scopeType, javax.webbeans.manager.Context context)
-	{
-		Asserts.assertNotNull(scopeType, "scopeType parameter can not be null");
-		Asserts.assertNotNull(context, "context parameter can not be null");
-		
-		getManager().contextMap.put(scopeType, context);
-	}
-
-	public Reference getReference() throws NamingException
-	{
-		return new Reference(ManagerImpl.class.getName(),new StringRefAddr("ManagerImpl","ManagerImpl"),ManagerObjectFactory.class.getName(),null);
-	}
-	
+    private Map<Class<? extends Annotation>, Context> contextMap = new ConcurrentHashMap<Class<? extends Annotation>, Context>();
+
+    private Set<Bean<?>> components = new CopyOnWriteArraySet<Bean<?>>();
+
+    private Set<Interceptor> webBeansInterceptors = new CopyOnWriteArraySet<Interceptor>();
+
+    private Set<Decorator> webBeansDecorators = new CopyOnWriteArraySet<Decorator>();
+
+    private NotificationManager notificationManager = null;
+
+    private InjectionResolver injectionResolver = null;
+
+    private Map<Bean<?>, Object> proxyMap = Collections.synchronizedMap(new IdentityHashMap<Bean<?>, Object>());
+
+    public ManagerImpl()
+    {
+        injectionResolver = InjectionResolver.getInstance();
+        notificationManager = NotificationManager.getInstance();
+    }
+
+    public static ManagerImpl getManager()
+    {
+        ManagerImpl instance = (ManagerImpl) WebBeansFinder.getSingletonInstance(WebBeansFinder.SINGLETON_MANAGER);
+
+        return instance;
+    }
+
+    public Context getContext(Class<? extends Annotation> scopType)
+    {
+        Asserts.assertNotNull(scopType, "scopeType paramter can not be null");
+
+        Context ctx = null;
+
+        ctx = ContextFactory.getStandartContext(scopType);
+
+        if (ctx == null)
+        {
+            ctx = getManager().contextMap.get(scopType);
+        }
+
+        // Still null
+        if (ctx == null)
+        {
+            throw new ContextNotActiveException("WebBeans context with scope type annotation @" + scopType.getSimpleName() + " is not exist within current thread");
+        }
+
+        return ctx;
+    }
+
+    public Manager addBean(Bean<?> component)
+    {
+        getManager().components.add(component);
+
+        return this;
+    }
+
+    public Manager addContext(Context context)
+    {
+        addContext(context.getScopeType(), context);
+
+        return this;
+
+    }
+
+    public void fireEvent(Object event, Annotation... bindings)
+    {
+        if (ClassUtil.isParametrized(event.getClass()))
+        {
+            throw new WebBeansConfigurationException("Event class : " + event.getClass().getName() + " can not be defined as generic type");
+        }
+
+        this.notificationManager.fireEvent(event, bindings);
+    }
+
+    public Object getInstanceByName(String name)
+    {
+        AbstractComponent<?> component = null;
+        Object object = null;
+
+        Set<Bean<?>> set = this.injectionResolver.implResolveByName(name);
+        if (set.isEmpty())
+        {
+            return null;
+        }
+
+        if (set.size() > 1)
+        {
+            throw new AmbiguousDependencyException("There are more than one WebBeans with name : " + name);
+        }
+
+        component = (AbstractComponent<?>) set.iterator().next();
+
+        object = getInstance(component);
+
+        return object;
+    }
+
+    public <T> T getInstanceByType(Class<T> type, Annotation... bindingTypes)
+    {
+        ResolutionUtil.getInstanceByTypeConditions(bindingTypes);
+        Set<Bean<T>> set = resolveByType(type, bindingTypes);
+
+        ResolutionUtil.checkResolvedBeans(set, type);
+
+        return getInstance(set.iterator().next());
+    }
+
+    public <T> T getInstanceByType(TypeLiteral<T> type, Annotation... bindingTypes)
+    {
+        ResolutionUtil.getInstanceByTypeConditions(bindingTypes);
+        Set<Bean<T>> set = resolveByType(type, bindingTypes);
+
+        ResolutionUtil.checkResolvedBeans(set, type.getRawType());
+
+        return getInstance(set.iterator().next());
+    }
+
+    public Set<Bean<?>> resolveByName(String name)
+    {
+        return this.injectionResolver.implResolveByName(name);
+    }
+
+    public <T> Set<Bean<T>> resolveByType(Class<T> apiType, Annotation... bindingTypes)
+    {
+        return this.injectionResolver.implResolveByType(apiType, new Type[0], bindingTypes);
+    }
+
+    public <T> Set<Bean<T>> resolveByType(TypeLiteral<T> apiType, Annotation... bindingTypes)
+    {
+        ParameterizedType ptype = (ParameterizedType) apiType.getType();
+        ResolutionUtil.resolveByTypeConditions(ptype);
+
+        Type[] args = ptype.getActualTypeArguments();
+        return this.injectionResolver.implResolveByType(apiType.getRawType(), args, bindingTypes);
+    }
+
+    public <T> Set<Observer<T>> resolveObservers(T event, Annotation... bindings)
+    {
+        return this.notificationManager.resolveObservers(event, bindings);
+    }
+
+    public Set<Bean<?>> getComponents()
+    {
+        return getManager().components;
+    }
+
+    public Manager addDecorator(Decorator decorator)
+    {
+        getManager().webBeansDecorators.add(decorator);
+        return this;
+    }
+
+    public Manager addInterceptor(Interceptor interceptor)
+    {
+        getManager().webBeansInterceptors.add(interceptor);
+        return this;
+    }
+
+    public <T> Manager addObserver(Observer<T> observer, Class<T> eventType, Annotation... bindings)
+    {
+        this.notificationManager.addObserver(observer, eventType, bindings);
+        return this;
+    }
+
+    public <T> Manager addObserver(Observer<T> observer, TypeLiteral<T> eventType, Annotation... bindings)
+    {
+        this.notificationManager.addObserver(observer, eventType, bindings);
+        return this;
+    }
+
+    public <T> T getInstance(Bean<T> bean)
+    {
+        Context context = null;
+        DependentContext dependentContext = null;
+        T instance = null;
+        boolean isSetOnThis = false;
+
+        try
+        {
+            dependentContext = (DependentContext) getContext(Dependent.class);
+            if (!dependentContext.isActive())
+            {
+                dependentContext.setActive(true);
+                isSetOnThis = true;
+            }
+
+            /* @ScopeType is normal */
+            if (WebBeansUtil.isScopeTypeNormal(bean.getScopeType()))
+            {
+                if (this.proxyMap.containsKey(bean))
+                {
+                    instance = (T) this.proxyMap.get(bean);
+                } else
+                {
+                    instance = (T) JavassistProxyFactory.createNewProxyInstance(bean);
+
+                    this.proxyMap.put(bean, instance);
+                }
+            }
+            /* @ScopeType is not normal */
+            else
+            {
+                context = getContext(bean.getScopeType());
+                instance = context.get(bean, true);
+            }
+
+        } finally
+        {
+            if (isSetOnThis)
+            {
+                dependentContext.setActive(false);
+            }
+        }
+
+        return instance;
+    }
+
+    public <T> Manager removeObserver(Observer<T> observer, Class<T> eventType, Annotation... bindings)
+    {
+        this.notificationManager.removeObserver(observer, eventType, bindings);
+        return this;
+    }
+
+    public <T> Manager removeObserver(Observer<T> observer, TypeLiteral<T> eventType, Annotation... bindings)
+    {
+        this.notificationManager.removeObserver(observer, eventType, bindings);
+        return this;
+    }
+
+    public List<Decorator> resolveDecorators(Set<Class<?>> types, Annotation... bindingTypes)
+    {
+        WebBeansUtil.checkDecoratorResolverParams(types, bindingTypes);
+        Set<Decorator> intsSet = WebBeansDecoratorConfig.findDeployedWebBeansDecorator(types, bindingTypes);
+        Iterator<Decorator> itSet = intsSet.iterator();
+
+        List<Decorator> decoratorList = new ArrayList<Decorator>();
+        while (itSet.hasNext())
+        {
+            WebBeansDecorator decorator = (WebBeansDecorator) itSet.next();
+            decoratorList.add(decorator);
+
+        }
+
+        Collections.sort(decoratorList, new DecoratorComparator());
+
+        return decoratorList;
+
+    }
+
+    public List<Interceptor> resolveInterceptors(InterceptionType type, Annotation... interceptorBindings)
+    {
+        WebBeansUtil.checkInterceptorResolverParams(interceptorBindings);
+
+        Set<Interceptor> intsSet = WebBeansInterceptorConfig.findDeployedWebBeansInterceptor(interceptorBindings);
+        Iterator<Interceptor> itSet = intsSet.iterator();
+
+        List<Interceptor> interceptorList = new ArrayList<Interceptor>();
+        while (itSet.hasNext())
+        {
+            WebBeansInterceptor interceptor = (WebBeansInterceptor) itSet.next();
+
+            if (interceptor.getMethod(type) != null)
+            {
+                interceptorList.add(interceptor);
+            }
+
+        }
+
+        Collections.sort(interceptorList, new InterceptorComparator());
+
+        return interceptorList;
+    }
+
+    public Set<Bean<?>> getBeans()
+    {
+        return getManager().components;
+    }
+
+    public Set<Interceptor> getInterceptors()
+    {
+        return getManager().webBeansInterceptors;
+    }
+
+    public Set<Decorator> getDecorators()
+    {
+        return getManager().webBeansDecorators;
+    }
+
+    private void addContext(Class<? extends Annotation> scopeType, javax.webbeans.manager.Context context)
+    {
+        Asserts.assertNotNull(scopeType, "scopeType parameter can not be null");
+        Asserts.assertNotNull(context, "context parameter can not be null");
+
+        getManager().contextMap.put(scopeType, context);
+
+    }
+
+    public Reference getReference() throws NamingException
+    {
+        return new Reference(ManagerImpl.class.getName(), new StringRefAddr("ManagerImpl", "ManagerImpl"), ManagerObjectFactory.class.getName(), null);
+    }
+
 }
\ No newline at end of file

Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/ManagerObjectFactory.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/ManagerObjectFactory.java?rev=732803&r1=732802&r2=732803&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/ManagerObjectFactory.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/ManagerObjectFactory.java Thu Jan  8 11:41:30 2009
@@ -1,18 +1,15 @@
 /*
- *  Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  See the NOTICE file distributed with
- *  this work for additional information regarding copyright ownership.
- *  The ASF licenses this file to You under the Apache License, Version 2.0
- *  (the "License"); you may not use this file except in compliance with
- *  the License.  You may obtain a copy of the License at
- * 
- *       http://www.apache.org/licenses/LICENSE-2.0
- * 
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
+ * or agreed to in writing, software distributed under the License is
+ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the specific language
+ * governing permissions and limitations under the License.
  */
 package org.apache.webbeans.container;
 
@@ -25,9 +22,9 @@
 public class ManagerObjectFactory implements ObjectFactory
 {
 
-	public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception
-	{
-		return ManagerImpl.getManager();
-	}
+    public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception
+    {
+        return ManagerImpl.getManager();
+    }
 
 }

Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/ResolutionUtil.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/ResolutionUtil.java?rev=732803&r1=732802&r2=732803&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/ResolutionUtil.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/ResolutionUtil.java Thu Jan  8 11:41:30 2009
@@ -1,18 +1,15 @@
 /*
- *  Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  See the NOTICE file distributed with
- *  this work for additional information regarding copyright ownership.
- *  The ASF licenses this file to You under the Apache License, Version 2.0
- *  (the "License"); you may not use this file except in compliance with
- *  the License.  You may obtain a copy of the License at
- * 
- *       http://www.apache.org/licenses/LICENSE-2.0
- * 
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
+ * or agreed to in writing, software distributed under the License is
+ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the specific language
+ * governing permissions and limitations under the License.
  */
 package org.apache.webbeans.container;
 
@@ -32,41 +29,41 @@
 
 public final class ResolutionUtil
 {
-	private ResolutionUtil()
-	{
-		
-	}
-
-	public static void resolveByTypeConditions(ParameterizedType type)
-	{
-		Asserts.assertNotNull(type, "type parameter can not be null");
-		boolean result = ClassUtil.checkParametrizedType(type);
-		
-		if(!result)
-		{
-			throw new IllegalArgumentException("Parametrized type : " + type + " can not contain type variable or wildcard type arguments");
-		}
-	}
-	
-	public static void getInstanceByTypeConditions(Annotation[] bindingTypes)
-	{
-		AnnotationUtil.checkBindingTypeConditions(bindingTypes);
-	}
-	
-	public static <T> void checkResolvedBeans(Set<Bean<T>> resolvedSet, Class<?> type)
-	{
-		if(resolvedSet.isEmpty())
-		{
-			throw new UnsatisfiedDependencyException("Api type : " + type.getName() + " is not found");
-		}
-		
-		if(resolvedSet.size() > 1)
-		{
-			throw new AmbiguousDependencyException("There is more than one api type with : " + type.getName());
-		}
-		
-		Bean<T> bean = resolvedSet.iterator().next();
-		WebBeansUtil.checkUnproxiableApiType(bean, bean.getScopeType().getAnnotation(ScopeType.class));
-		
-	}
+    private ResolutionUtil()
+    {
+
+    }
+
+    public static void resolveByTypeConditions(ParameterizedType type)
+    {
+        Asserts.assertNotNull(type, "type parameter can not be null");
+        boolean result = ClassUtil.checkParametrizedType(type);
+
+        if (!result)
+        {
+            throw new IllegalArgumentException("Parametrized type : " + type + " can not contain type variable or wildcard type arguments");
+        }
+    }
+
+    public static void getInstanceByTypeConditions(Annotation[] bindingTypes)
+    {
+        AnnotationUtil.checkBindingTypeConditions(bindingTypes);
+    }
+
+    public static <T> void checkResolvedBeans(Set<Bean<T>> resolvedSet, Class<?> type)
+    {
+        if (resolvedSet.isEmpty())
+        {
+            throw new UnsatisfiedDependencyException("Api type : " + type.getName() + " is not found");
+        }
+
+        if (resolvedSet.size() > 1)
+        {
+            throw new AmbiguousDependencyException("There is more than one api type with : " + type.getName());
+        }
+
+        Bean<T> bean = resolvedSet.iterator().next();
+        WebBeansUtil.checkUnproxiableApiType(bean, bean.getScopeType().getAnnotation(ScopeType.class));
+
+    }
 }

Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/AbstractContext.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/AbstractContext.java?rev=732803&r1=732802&r2=732803&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/AbstractContext.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/AbstractContext.java Thu Jan  8 11:41:30 2009
@@ -1,18 +1,15 @@
 /*
- *  Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  See the NOTICE file distributed with
- *  this work for additional information regarding copyright ownership.
- *  The ASF licenses this file to You under the Apache License, Version 2.0
- *  (the "License"); you may not use this file except in compliance with
- *  the License.  You may obtain a copy of the License at
- * 
- *       http://www.apache.org/licenses/LICENSE-2.0
- * 
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
+ * or agreed to in writing, software distributed under the License is
+ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the specific language
+ * governing permissions and limitations under the License.
  */
 package org.apache.webbeans.context;
 
@@ -34,8 +31,6 @@
 import org.apache.webbeans.context.type.ContextTypes;
 import org.apache.webbeans.exception.ContextRemoveException;
 
-
-
 /**
  * Abstract implementation of the {@link WebBeansContext} interfaces.
  * 
@@ -44,198 +39,188 @@
  */
 public abstract class AbstractContext implements WebBeansContext
 {
-	protected boolean active;
-	
-	protected ContextTypes type;
-	
-	protected  Map<Bean<?>, Object> componentInstanceMap = null;
-	
-	protected Class<? extends Annotation> scopeType;
-	
-	protected AbstractContext()
-	{
-		
-	}
-	
-	protected AbstractContext(Class<? extends Annotation> scopeType)
-	{
-		this.scopeType = scopeType;
-		setComponentInstanceMap();
-		
-	}
-	
-	protected AbstractContext(ContextTypes type)
-	{
-		this.type = type;
-		configureScopeType(type);
-		setComponentInstanceMap();
-	}
-	
-	
-	private void configureScopeType(ContextTypes type)
-	{
-		if(type.equals(ContextTypes.APPLICATION))
-		{
-			this.scopeType = ApplicationScoped.class;
-		}
-		else if(type.equals(ContextTypes.SESSION))
-		{
-			this.scopeType = SessionScoped.class;
-		}
-		else if(type.equals(ContextTypes.REQUEST))
-		{
-			this.scopeType = RequestScoped.class;
-		}
-		else if(type.equals(ContextTypes.DEPENDENT))
-		{
-			this.scopeType = Dependent.class;
-		}
-		else if(type.equals(ContextTypes.CONVERSATION))
-		{
-			this.scopeType = ConversationScoped.class;
-		}
-		
-	}
-
-	public <T> T get(Bean<T> component, boolean create)
-	{
-		if(!active)
-		{
-			throw new ContextNotActiveException("WebBeans context with scope type annotation @" + getScopeType().getName() +  " is not active with respect to the current thread");			
-		}
-		
-		return getInstance(component, create);
-	}
-	
-	
-	@SuppressWarnings("unchecked")
-	protected <T> T getInstance(Bean<T> component, boolean create)
-	{
-		Object instance = null;
-		
-		if((instance = componentInstanceMap.get(component)) != null)
-		{
-			return (T)instance;	
-		}
-		else
-		{
-			if(create)
-			{
-				instance = component.create();
-				if(instance != null)
-				{
-					componentInstanceMap.put(component, instance);	
-				}
-				
-				return (T)instance;
-			}
-		}
-		
-		return null;
-	}
-	
-
-	public <T> void remove(Bean<T> component)
-	{
-		removeInstance(component);
-	}
-
-	/**
-	 * Destroy the given web beans component instance.
-	 * 
-	 * @param <T> 
-	 * @param component web beans component
-	 * @param instance component instance
-	 */
-	private <T> void destroyInstance(Bean<T> component,T instance)
-	{
-		component.destroy(instance);
-	}
-	
-	/**
-	 * Destroys the context.
-	 * 
-	 * @param <T>
-	 */
-	@SuppressWarnings("unchecked")
-	public <T> void destroy()
-	{
-		Set<Entry<Bean<?>, Object>> entrySet = componentInstanceMap.entrySet();
-		Iterator<Entry<Bean<?>, Object>> it = entrySet.iterator();
-		
-		Bean<?> component = null;
-		while(it.hasNext())
-		{
-			component = it.next().getKey();
-			T instance = (T)componentInstanceMap.get(component);
-			
-			it.remove();
-			
-			destroyInstance((Bean<T>)component, instance);
-		}		
-	}
-	
-	protected <T> void removeInstance(Bean<T> component)
-	{
-		if(componentInstanceMap.get(component) != null)
-		{
-			componentInstanceMap.remove(component);
-			removeInstance(component);
-		}
-		else
-		{
-			throw new ContextRemoveException("Given component with " + component + " is not found in the current context with type : " + getType().getTypeName());
-		}
-				
-	}
-
-	/**
-	 * Gets context active flag.
-	 * 
-	 * @return active flag
-	 */
-	public boolean isActive()
-	{
-		return active;
-	}
-
-	/**
-	 * Set component active flag.
-	 * 
-	 * @param active active flag
-	 */
-	public void setActive(boolean active)
-	{
-		this.active = active;
-	}
-
-	/**
-	 * Type of the context
-	 * 
-	 * @return type
-	 */
-	public ContextTypes getType()
-	{
-		return type;
-	}
-
-	public Map<Bean<?>, Object> getComponentInstanceMap()
-	{
-		return componentInstanceMap;
-	}
-	
-	public Class<? extends Annotation> getScopeType()
-	{
-		
-		return this.scopeType;
-	}
-
-	public <T> void remove(Manager container, Bean<T> component)
-	{
-		remove((Bean<T>)component);
-	}
-	
-	public abstract void setComponentInstanceMap();
+    protected boolean active;
+
+    protected ContextTypes type;
+
+    protected Map<Bean<?>, Object> componentInstanceMap = null;
+
+    protected Class<? extends Annotation> scopeType;
+
+    protected AbstractContext()
+    {
+
+    }
+
+    protected AbstractContext(Class<? extends Annotation> scopeType)
+    {
+        this.scopeType = scopeType;
+        setComponentInstanceMap();
+
+    }
+
+    protected AbstractContext(ContextTypes type)
+    {
+        this.type = type;
+        configureScopeType(type);
+        setComponentInstanceMap();
+    }
+
+    private void configureScopeType(ContextTypes type)
+    {
+        if (type.equals(ContextTypes.APPLICATION))
+        {
+            this.scopeType = ApplicationScoped.class;
+        } else if (type.equals(ContextTypes.SESSION))
+        {
+            this.scopeType = SessionScoped.class;
+        } else if (type.equals(ContextTypes.REQUEST))
+        {
+            this.scopeType = RequestScoped.class;
+        } else if (type.equals(ContextTypes.DEPENDENT))
+        {
+            this.scopeType = Dependent.class;
+        } else if (type.equals(ContextTypes.CONVERSATION))
+        {
+            this.scopeType = ConversationScoped.class;
+        }
+
+    }
+
+    public <T> T get(Bean<T> component, boolean create)
+    {
+        if (!active)
+        {
+            throw new ContextNotActiveException("WebBeans context with scope type annotation @" + getScopeType().getName() + " is not active with respect to the current thread");
+        }
+
+        return getInstance(component, create);
+    }
+
+    @SuppressWarnings("unchecked")
+    protected <T> T getInstance(Bean<T> component, boolean create)
+    {
+        Object instance = null;
+
+        if ((instance = componentInstanceMap.get(component)) != null)
+        {
+            return (T) instance;
+        } else
+        {
+            if (create)
+            {
+                instance = component.create();
+                if (instance != null)
+                {
+                    componentInstanceMap.put(component, instance);
+                }
+
+                return (T) instance;
+            }
+        }
+
+        return null;
+    }
+
+    public <T> void remove(Bean<T> component)
+    {
+        removeInstance(component);
+    }
+
+    /**
+     * Destroy the given web beans component instance.
+     * 
+     * @param <T>
+     * @param component web beans component
+     * @param instance component instance
+     */
+    private <T> void destroyInstance(Bean<T> component, T instance)
+    {
+        component.destroy(instance);
+    }
+
+    /**
+     * Destroys the context.
+     * 
+     * @param <T>
+     */
+    @SuppressWarnings("unchecked")
+    public <T> void destroy()
+    {
+        Set<Entry<Bean<?>, Object>> entrySet = componentInstanceMap.entrySet();
+        Iterator<Entry<Bean<?>, Object>> it = entrySet.iterator();
+
+        Bean<?> component = null;
+        while (it.hasNext())
+        {
+            component = it.next().getKey();
+            T instance = (T) componentInstanceMap.get(component);
+
+            it.remove();
+
+            destroyInstance((Bean<T>) component, instance);
+        }
+    }
+
+    protected <T> void removeInstance(Bean<T> component)
+    {
+        if (componentInstanceMap.get(component) != null)
+        {
+            componentInstanceMap.remove(component);
+            removeInstance(component);
+        } else
+        {
+            throw new ContextRemoveException("Given component with " + component + " is not found in the current context with type : " + getType().getTypeName());
+        }
+
+    }
+
+    /**
+     * Gets context active flag.
+     * 
+     * @return active flag
+     */
+    public boolean isActive()
+    {
+        return active;
+    }
+
+    /**
+     * Set component active flag.
+     * 
+     * @param active active flag
+     */
+    public void setActive(boolean active)
+    {
+        this.active = active;
+    }
+
+    /**
+     * Type of the context
+     * 
+     * @return type
+     */
+    public ContextTypes getType()
+    {
+        return type;
+    }
+
+    public Map<Bean<?>, Object> getComponentInstanceMap()
+    {
+        return componentInstanceMap;
+    }
+
+    public Class<? extends Annotation> getScopeType()
+    {
+
+        return this.scopeType;
+    }
+
+    public <T> void remove(Manager container, Bean<T> component)
+    {
+        remove((Bean<T>) component);
+    }
 
+    public abstract void setComponentInstanceMap();
 
 }

Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/ApplicationContext.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/ApplicationContext.java?rev=732803&r1=732802&r2=732803&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/ApplicationContext.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/ApplicationContext.java Thu Jan  8 11:41:30 2009
@@ -1,18 +1,15 @@
 /*
- *  Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  See the NOTICE file distributed with
- *  this work for additional information regarding copyright ownership.
- *  The ASF licenses this file to You under the Apache License, Version 2.0
- *  (the "License"); you may not use this file except in compliance with
- *  the License.  You may obtain a copy of the License at
- * 
- *       http://www.apache.org/licenses/LICENSE-2.0
- * 
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
+ * or agreed to in writing, software distributed under the License is
+ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the specific language
+ * governing permissions and limitations under the License.
  */
 package org.apache.webbeans.context;
 
@@ -22,7 +19,6 @@
 
 import org.apache.webbeans.context.type.ContextTypes;
 
-
 /**
  * Application context implementation.
  * 
@@ -31,16 +27,16 @@
  */
 public class ApplicationContext extends AbstractContext
 {
-	protected ApplicationContext()
-	{
-		super(ContextTypes.APPLICATION);
-	}
-	
-	@Override
-	public void setComponentInstanceMap()
-	{
-		this.componentInstanceMap = new ConcurrentHashMap<Bean<?>, Object>();
-		
-	}
+    protected ApplicationContext()
+    {
+        super(ContextTypes.APPLICATION);
+    }
+
+    @Override
+    public void setComponentInstanceMap()
+    {
+        this.componentInstanceMap = new ConcurrentHashMap<Bean<?>, Object>();
+
+    }
 
 }

Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/ContextFactory.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/ContextFactory.java?rev=732803&r1=732802&r2=732803&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/ContextFactory.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/ContextFactory.java Thu Jan  8 11:41:30 2009
@@ -1,18 +1,15 @@
 /*
- *  Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  See the NOTICE file distributed with
- *  this work for additional information regarding copyright ownership.
- *  The ASF licenses this file to You under the Apache License, Version 2.0
- *  (the "License"); you may not use this file except in compliance with
- *  the License.  You may obtain a copy of the License at
- * 
- *       http://www.apache.org/licenses/LICENSE-2.0
- * 
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
+ * or agreed to in writing, software distributed under the License is
+ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the specific language
+ * governing permissions and limitations under the License.
  */
 package org.apache.webbeans.context;
 
@@ -31,9 +28,8 @@
 import org.apache.webbeans.context.type.ContextTypes;
 import org.apache.webbeans.jsf.ConversationManager;
 
-
 /**
- * Gets current {@link WebBeansContext} instances on the current thread context.   
+ * Gets current {@link WebBeansContext} instances on the current thread context.
  * 
  * @author <a href="mailto:gurkanerdogdu@yahoo.com">Gurkan Erdogdu</a>
  * @since 1.0
@@ -42,308 +38,297 @@
  */
 public final class ContextFactory
 {
-	private static ThreadLocal<RequestContext> requestContext = null;
-	
-	private static ThreadLocal<SessionContext> sessionContext = null;
-	
-	private static ThreadLocal<ApplicationContext> applicationContext = null;
-	
-	private static ThreadLocal<ConversationContext> conversationContext = null;
-	
-	private static ThreadLocal<DependentContext> dependentContext = null;
-		
-	private static ApplicationContext currentApplicationContext = null;
-	
-	private static SessionContextManager sessionCtxManager = SessionContextManager.getInstance();
-	
-	private static ConversationManager conversationManager = ConversationManager.getInstance();
-	
-	static
-	{
-		requestContext = new ThreadLocal<RequestContext>();		
-		sessionContext = new ThreadLocal<SessionContext>();
-		applicationContext = new ThreadLocal<ApplicationContext>();
-		conversationContext = new ThreadLocal<ConversationContext>();	
-		dependentContext = new ThreadLocal<DependentContext>();
-	}
-		
-	private ContextFactory()
-	{
-		throw new UnsupportedOperationException();
-	}
-	
-	/**
-	 * Initialize requext context with the given
-	 * request object.
-	 * 
-	 * @param request http servlet request object
-	 */
-	public static void initRequestContext(HttpServletRequest request)
-	{
-		requestContext.set(new RequestContext());//set thread local
-		requestContext.get().setActive(true);
-		
-		if(request != null)
-		{
-			HttpSession session = request.getSession();
-			initSessionContext(session);			
-		}		
-	}
-	
-	/**
-	 * Destroys the request context and all of its
-	 * components.
-	 * 
-	 * @param request http servlet request object
-	 */
-	public static void destroyRequestContext(HttpServletRequest request)
-	{
-		if(requestContext != null)
-		{
-			RequestContext context = getRequestContext();
-			
-			if(context != null)
-			{
-				context.destroy();
-			}
-
-			requestContext.remove();//unset thread local			
-		}
-	}
-	
-	/**
-	 * Creates the session context at the session start.
-	 * 
-	 * @param session http session object
-	 */
-	public static void initSessionContext(HttpSession session)
-	{
-		String sessionId = session.getId();
-		SessionContext currentSessionContext = sessionCtxManager.getSessionContextWithSessionId(sessionId);
-		
-		if(currentSessionContext == null)
-		{
-			currentSessionContext = new SessionContext();
-			sessionCtxManager.addNewSessionContext(sessionId, currentSessionContext);
-		}
-		
-		currentSessionContext.setActive(true);
-		
-		sessionContext.set(currentSessionContext);
-	}
-	
-	/**
-	 * Destroys the session context and all of its
-	 * components at the end of the session.
-	 * 
-	 * @param session http session object
-	 */
-	public static void destroySessionContext(HttpSession session)
-	{
-		if(sessionContext != null)
-		{
-			SessionContext context = getSessionContext();
-			
-			if(context != null)
-			{
-				context.destroy();
-			}
-			
-			sessionContext.remove();//unset thread local
-			
-		}
-		
-		sessionCtxManager.destroySessionContextWithSessionId(session.getId());
-		
-	}
-	
-
-	/**
-	 * Creates the application context at the
-	 * application startup
-	 * 
-	 * @param servletContext servlet context object
-	 */
-	public static void initApplicationContext(ServletContext servletContext)
-	{
-		if(currentApplicationContext == null)
-		{
-			currentApplicationContext = new ApplicationContext();
-			currentApplicationContext.setActive(true);
-		}
-		
-		applicationContext.set(currentApplicationContext);
-		
-	}
-	
-	/**
-	 * Destroys the application context and all of its
-	 * components at the end of the application.
-	 * 
-	 *@param servletContext servlet context object
-	 */
-	public static void destroyApplicationContext(ServletContext servletContext)
-	{
-		if(applicationContext != null)
-		{
-			ApplicationContext context = getApplicationContext();
-
-			if(context != null)
-			{
-				context.destroy();
-			}
-
-			applicationContext.remove();//unset thread local
-			
-		}
-		
-		currentApplicationContext = null;
-		sessionCtxManager.destroyAllSessions();
-		conversationManager.destroyAllConversations();
-	}
-	
-	
-	public static void initConversationContext(ConversationContext context)
-	{
-		if(context == null)
-		{
-			conversationContext.set(new ConversationContext());	
-		}
-		else
-		{
-			conversationContext.set(context);
-		}
-	}
-	
-	public static void destroyConversationContext()
-	{
-		if(conversationContext != null)
-		{
-			ConversationContext context = getConversationContext();
-
-			if(context != null)
-			{
-				context.destroy();
-			}
-
-			conversationContext.remove();			
-		}
-	}
-	
-	
-	/**
-	 * Gets the current context with given type.
-	 * 
-	 * @return the current context
-	 * @throws ContextNotActiveException if context is not active
-	 */
-	public static WebBeansContext getStandartContext(ContextTypes type) throws ContextNotActiveException
-	{
-		WebBeansContext context = null;
-		
-		switch (type.getName())
-		{
-		case 0:
-			context = getRequestContext();
-			break;
-		
-		case 1:
-			context = getSessionContext();
-			break;
-			
-		case 2:
-			context = getApplicationContext();
-			break;
-			
-		case 3:
-			context = getConversationContext();
-			
-		case 4:
-			context = getDependentContext();
-			
-		}
-		
-		return context;
-	}
-	
-	/**
-	 * Gets the current context with given scope type.
-	 * 
-	 * @return the current context
-	 * @throws ContextNotActiveException if context is not active
-	 */
-	public static WebBeansContext getStandartContext(Class<? extends Annotation> scopeType) throws ContextNotActiveException
-	{
-		WebBeansContext context = null;
-		
-		if(scopeType.equals(RequestScoped.class))
-		{
-			context = getRequestContext();	
-		}
-		else if(scopeType.equals(SessionScoped.class))
-		{
-			context = getSessionContext();			
-		}
-		else if(scopeType.equals(ApplicationScoped.class))
-		{
-			context = getApplicationContext();			
-		}
-		else if (scopeType.equals(ConversationScoped.class))
-		{
-			context = getConversationContext();
-			
-		}else if(scopeType.equals(Dependent.class))
-		{
-			context = getDependentContext();
-		}
-		
-		return context;
-	}
-	
-	
-	/*
-	 * Get current request ctx.
-	 */
-	private static RequestContext getRequestContext()
-	{
-		return requestContext.get();
-	}
-	
-	/*
-	 * Get current session ctx.
-	 */
-	private static SessionContext getSessionContext()
-	{
-		return sessionContext.get();
-	}
-	
-	/*
-	 * Get current application ctx.
-	 */
-	private static ApplicationContext getApplicationContext()
-	{
-		return currentApplicationContext;
-	}
-	
-	/*
-	 * Get current conversation ctx.
-	 */
-	private static ConversationContext getConversationContext()
-	{
-		return conversationContext.get();
-	}
-	
-	private static DependentContext getDependentContext()
-	{
-		DependentContext dependentCtx = dependentContext.get();
-		
-		if(dependentCtx == null)
-		{
-			dependentCtx = new DependentContext();
-			dependentContext.set(dependentCtx);
-		}
-	
-		return dependentCtx;
-	}
+    private static ThreadLocal<RequestContext> requestContext = null;
+
+    private static ThreadLocal<SessionContext> sessionContext = null;
+
+    private static ThreadLocal<ApplicationContext> applicationContext = null;
+
+    private static ThreadLocal<ConversationContext> conversationContext = null;
+
+    private static ThreadLocal<DependentContext> dependentContext = null;
+
+    private static ApplicationContext currentApplicationContext = null;
+
+    private static SessionContextManager sessionCtxManager = SessionContextManager.getInstance();
+
+    private static ConversationManager conversationManager = ConversationManager.getInstance();
+
+    static
+    {
+        requestContext = new ThreadLocal<RequestContext>();
+        sessionContext = new ThreadLocal<SessionContext>();
+        applicationContext = new ThreadLocal<ApplicationContext>();
+        conversationContext = new ThreadLocal<ConversationContext>();
+        dependentContext = new ThreadLocal<DependentContext>();
+    }
+
+    private ContextFactory()
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * Initialize requext context with the given request object.
+     * 
+     * @param request http servlet request object
+     */
+    public static void initRequestContext(HttpServletRequest request)
+    {
+        requestContext.set(new RequestContext());// set thread local
+        requestContext.get().setActive(true);
+
+        if (request != null)
+        {
+            HttpSession session = request.getSession();
+            initSessionContext(session);
+        }
+    }
+
+    /**
+     * Destroys the request context and all of its components.
+     * 
+     * @param request http servlet request object
+     */
+    public static void destroyRequestContext(HttpServletRequest request)
+    {
+        if (requestContext != null)
+        {
+            RequestContext context = getRequestContext();
+
+            if (context != null)
+            {
+                context.destroy();
+            }
+
+            requestContext.remove();// unset thread local
+        }
+    }
+
+    /**
+     * Creates the session context at the session start.
+     * 
+     * @param session http session object
+     */
+    public static void initSessionContext(HttpSession session)
+    {
+        String sessionId = session.getId();
+        SessionContext currentSessionContext = sessionCtxManager.getSessionContextWithSessionId(sessionId);
+
+        if (currentSessionContext == null)
+        {
+            currentSessionContext = new SessionContext();
+            sessionCtxManager.addNewSessionContext(sessionId, currentSessionContext);
+        }
+
+        currentSessionContext.setActive(true);
+
+        sessionContext.set(currentSessionContext);
+    }
+
+    /**
+     * Destroys the session context and all of its components at the end of the
+     * session.
+     * 
+     * @param session http session object
+     */
+    public static void destroySessionContext(HttpSession session)
+    {
+        if (sessionContext != null)
+        {
+            SessionContext context = getSessionContext();
+
+            if (context != null)
+            {
+                context.destroy();
+            }
+
+            sessionContext.remove();// unset thread local
+
+        }
+
+        sessionCtxManager.destroySessionContextWithSessionId(session.getId());
+
+    }
+
+    /**
+     * Creates the application context at the application startup
+     * 
+     * @param servletContext servlet context object
+     */
+    public static void initApplicationContext(ServletContext servletContext)
+    {
+        if (currentApplicationContext == null)
+        {
+            currentApplicationContext = new ApplicationContext();
+            currentApplicationContext.setActive(true);
+        }
+
+        applicationContext.set(currentApplicationContext);
+
+    }
+
+    /**
+     * Destroys the application context and all of its components at the end of
+     * the application.
+     * 
+     * @param servletContext servlet context object
+     */
+    public static void destroyApplicationContext(ServletContext servletContext)
+    {
+        if (applicationContext != null)
+        {
+            ApplicationContext context = getApplicationContext();
+
+            if (context != null)
+            {
+                context.destroy();
+            }
+
+            applicationContext.remove();// unset thread local
+
+        }
+
+        currentApplicationContext = null;
+        sessionCtxManager.destroyAllSessions();
+        conversationManager.destroyAllConversations();
+    }
+
+    public static void initConversationContext(ConversationContext context)
+    {
+        if (context == null)
+        {
+            conversationContext.set(new ConversationContext());
+        } else
+        {
+            conversationContext.set(context);
+        }
+    }
+
+    public static void destroyConversationContext()
+    {
+        if (conversationContext != null)
+        {
+            ConversationContext context = getConversationContext();
+
+            if (context != null)
+            {
+                context.destroy();
+            }
+
+            conversationContext.remove();
+        }
+    }
+
+    /**
+     * Gets the current context with given type.
+     * 
+     * @return the current context
+     * @throws ContextNotActiveException if context is not active
+     */
+    public static WebBeansContext getStandartContext(ContextTypes type) throws ContextNotActiveException
+    {
+        WebBeansContext context = null;
+
+        switch (type.getName())
+        {
+        case 0:
+            context = getRequestContext();
+            break;
+
+        case 1:
+            context = getSessionContext();
+            break;
+
+        case 2:
+            context = getApplicationContext();
+            break;
+
+        case 3:
+            context = getConversationContext();
+
+        case 4:
+            context = getDependentContext();
+
+        }
+
+        return context;
+    }
+
+    /**
+     * Gets the current context with given scope type.
+     * 
+     * @return the current context
+     * @throws ContextNotActiveException if context is not active
+     */
+    public static WebBeansContext getStandartContext(Class<? extends Annotation> scopeType) throws ContextNotActiveException
+    {
+        WebBeansContext context = null;
+
+        if (scopeType.equals(RequestScoped.class))
+        {
+            context = getRequestContext();
+        } else if (scopeType.equals(SessionScoped.class))
+        {
+            context = getSessionContext();
+        } else if (scopeType.equals(ApplicationScoped.class))
+        {
+            context = getApplicationContext();
+        } else if (scopeType.equals(ConversationScoped.class))
+        {
+            context = getConversationContext();
+
+        } else if (scopeType.equals(Dependent.class))
+        {
+            context = getDependentContext();
+        }
+
+        return context;
+    }
+
+    /*
+     * Get current request ctx.
+     */
+    private static RequestContext getRequestContext()
+    {
+        return requestContext.get();
+    }
+
+    /*
+     * Get current session ctx.
+     */
+    private static SessionContext getSessionContext()
+    {
+        return sessionContext.get();
+    }
+
+    /*
+     * Get current application ctx.
+     */
+    private static ApplicationContext getApplicationContext()
+    {
+        return currentApplicationContext;
+    }
+
+    /*
+     * Get current conversation ctx.
+     */
+    private static ConversationContext getConversationContext()
+    {
+        return conversationContext.get();
+    }
+
+    private static DependentContext getDependentContext()
+    {
+        DependentContext dependentCtx = dependentContext.get();
+
+        if (dependentCtx == null)
+        {
+            dependentCtx = new DependentContext();
+            dependentContext.set(dependentCtx);
+        }
+
+        return dependentCtx;
+    }
 
 }
\ No newline at end of file



Mime
View raw message