View Javadoc

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