View Javadoc

1   /*
2    * $Id: MuleContainerContext.java 7963 2007-08-21 08:53:15Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.impl.container;
12  
13  import org.mule.umo.manager.ObjectNotFoundException;
14  import org.mule.util.ClassUtils;
15  
16  import java.io.Reader;
17  
18  /**
19   * <code>MuleContainerContext</code> is a default resolver that doesn't support
20   * external reference resolution. It's function is to provide a complete
21   * implementation when a componenet resolver is not defined. The default behaviour is
22   * to build a component key as a fully qualified class name
23   */
24  public class MuleContainerContext extends AbstractContainerContext
25  {
26      public static final String MULE_CONTAINER_NAME = "mule";
27  
28      public MuleContainerContext()
29      {
30          super(MULE_CONTAINER_NAME);
31      }
32  
33      /*
34       * (non-Javadoc)
35       * 
36       * @see org.mule.model.UMOContainerContext#getComponent(java.lang.Object)
37       */
38      public Object getComponent(Object key) throws ObjectNotFoundException
39      {
40          if (key == null)
41          {
42              throw new ObjectNotFoundException("Component not found for null key");
43          }
44          try
45          {
46              Class clazz;
47              if (key instanceof Class)
48              {
49                  clazz = (Class) key;
50              }
51              else
52              {
53                  clazz = ClassUtils.loadClass(key.toString(), getClass());
54              }
55              return clazz.newInstance();
56          }
57          catch (Exception e)
58          {
59              throw new ObjectNotFoundException(key.toString() + " (" + e.getMessage() + ")", e);
60          }
61      }
62  
63      public void configure(Reader configuration)
64      {
65          throw new UnsupportedOperationException("configure(Reader)");
66      }
67  
68  }