KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > impl > container > DescriptorContainerContext


1 /*
2  * $Id: DescriptorContainerContext.java 3798 2006-11-04 04:07:14Z aperepel $
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 MuleSource MPL
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.MuleManager;
14 import org.mule.config.i18n.Message;
15 import org.mule.config.i18n.Messages;
16 import org.mule.umo.UMODescriptor;
17 import org.mule.umo.manager.ContainerException;
18 import org.mule.umo.manager.ObjectNotFoundException;
19
20 import java.io.Reader JavaDoc;
21
22 /**
23  * will Load the component form the descriptors' own properties
24  *
25  * @author <a HREF="mailto:ross.mason@symphonysoft.com">Ross Mason</a>
26  * @version $Revision: 3798 $
27  */

28 public class DescriptorContainerContext extends AbstractContainerContext
29 {
30     public static final String JavaDoc DESCRIPTOR_CONTAINER_NAME = "descriptor";
31
32     public DescriptorContainerContext()
33     {
34         super(DESCRIPTOR_CONTAINER_NAME);
35     }
36
37     public void configure(Reader JavaDoc configuration) throws ContainerException
38     {
39         throw new UnsupportedOperationException JavaDoc("configure");
40     }
41
42     public void setName(String JavaDoc name)
43     {
44         // no op
45
}
46
47     /**
48      * Queries a component from the underlying container
49      *
50      * @param key the key fo find the component with. Its up to the individual
51      * implementation to check the type of this key and look up objects
52      * accordingly
53      * @return The component found in the container
54      * @throws org.mule.umo.manager.ObjectNotFoundException if the component is not
55      * found
56      */

57     public Object JavaDoc getComponent(Object JavaDoc key) throws ObjectNotFoundException
58     {
59
60         if (key instanceof DescriptorContainerKeyPair)
61         {
62             DescriptorContainerKeyPair dckp = (DescriptorContainerKeyPair)key;
63
64             UMODescriptor d = MuleManager.getInstance().getModel().getDescriptor(dckp.getDescriptorName());
65             if (d == null)
66             {
67                 throw new ObjectNotFoundException(key.toString(), new ContainerException(new Message(
68                     Messages.FAILED_LOAD_X, "descriptor: " + dckp.getDescriptorName())));
69             }
70             Object JavaDoc component = d.getProperties().get(dckp.getKey());
71             if (component == null)
72             {
73                 throw new ObjectNotFoundException(dckp.getKey().toString());
74             }
75             return component;
76         }
77         else
78         {
79             throw new ObjectNotFoundException(key.toString());
80         }
81     }
82
83 }
84
Popular Tags