KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: RmiContainerContext.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.umo.lifecycle.InitialisationException;
14 import org.mule.umo.manager.ObjectNotFoundException;
15 import org.mule.util.ClassUtils;
16
17 import javax.naming.NamingException JavaDoc;
18
19 /**
20  * <code>RmiContainerContext</code> is a container implementaiton that allows RMi
21  * objects to be referenced either as components or properties on components
22  *
23  * @author <a HREF="mailto:ross.mason@symphonysoft.com">Ross Mason</a>
24  * @version $Revision: 3798 $
25  */

26 public class RmiContainerContext extends JndiContainerContext
27 {
28     protected String JavaDoc securityPolicy = null;
29     protected String JavaDoc securityManager = null;
30
31     protected RmiContainerContext(String JavaDoc name)
32     {
33         super(name);
34     }
35
36     public RmiContainerContext()
37     {
38         super("rmi");
39     }
40
41     public void initialise() throws InitialisationException
42     {
43         super.initialise();
44         if (securityPolicy != null)
45         {
46             if (ClassUtils.getResource(securityPolicy, getClass()) != null)
47             {
48                 System.setProperty("java.security.policy", securityPolicy);
49             }
50         }
51
52         // Set security manager
53
if (System.getSecurityManager() == null)
54         {
55             try
56             {
57                 if (securityManager != null)
58                 {
59                     Class JavaDoc clazz = ClassUtils.loadClass(securityManager, getClass());
60                     System.setSecurityManager((SecurityManager JavaDoc)clazz.newInstance());
61                 }
62             }
63             catch (Exception JavaDoc e)
64             {
65                 throw new InitialisationException(e, this);
66             }
67         }
68     }
69
70     public Object JavaDoc getComponent(Object JavaDoc key) throws ObjectNotFoundException
71     {
72         Object JavaDoc object = null;
73         if (key == null)
74         {
75             throw new ObjectNotFoundException("null");
76         }
77         try
78         {
79             object = context.lookup(key.toString());
80         }
81         catch (NamingException JavaDoc e)
82         {
83             throw new ObjectNotFoundException(key.toString(), e);
84         }
85
86         if (object == null)
87         {
88             throw new ObjectNotFoundException(key.toString());
89         }
90         else
91         {
92             return object;
93         }
94     }
95
96     public String JavaDoc getSecurityPolicy()
97     {
98         return securityPolicy;
99     }
100
101     public void setSecurityPolicy(String JavaDoc securityPolicy)
102     {
103         this.securityPolicy = securityPolicy;
104     }
105
106     public String JavaDoc getSecurityManager()
107     {
108         return securityManager;
109     }
110
111     public void setSecurityManager(String JavaDoc securityManager)
112     {
113         this.securityManager = securityManager;
114     }
115 }
116
Popular Tags