View Javadoc

1    /****************************************************************************
2    * Copyright (c) 2005, 2006, 2007, 2008, 2009 Imola Informatica.
3    * All rights reserved. This program and the accompanying materials
4    * are made available under the terms of the LGPL License v2.1
5    * which accompanies this distribution, and is available at
6    * http://www.gnu.org/licenses/lgpl.html
7    ****************************************************************************/
8   
9   package it.imolinfo.jbi4corba.jbi.component.runtime;
10  
11  import it.imolinfo.jbi4corba.jbi.Messages;
12  import javax.jbi.component.Bootstrap;
13  import javax.jbi.component.InstallationContext;
14  import javax.jbi.JBIException;
15  import javax.jbi.component.ComponentContext;
16  import javax.jbi.management.MBeanNames;
17  import javax.management.MBeanServer;
18  import javax.management.ObjectName;
19  import javax.management.StandardMBean;
20  
21  import it.imolinfo.jbi4corba.Logger;
22  import it.imolinfo.jbi4corba.LoggerFactory;
23  
24  
25  /**
26   * This is a default implemenation of the Bootstrap interface.
27   * The component implemenation can extend this class and implement
28   * component specific installation such as configuration and creation of
29   * of the resources.
30   *
31   * @see javax.jbi.Bootstrap
32   *
33   * @author Prem 
34   */
35  public class ComponentInstaller implements Bootstrap {
36      
37      /** The logger. */
38      private static final Logger LOG = 
39      	LoggerFactory.getLogger(ComponentInstaller.class);
40      private static final Messages MESSAGES = 
41      	Messages.getMessages(ComponentInstaller.class);
42  
43      
44      /**
45       * Installation Context .
46       */
47      @SuppressWarnings("unused")
48  	private InstallationContext mContext;
49      
50      // Installer extension mbean 
51      ObjectName mInstallerExtName;   
52      
53      /**
54       * Constructor to create the ComponentInstaller.
55       */
56      public ComponentInstaller() {}
57      
58      /**
59       * default noop implementation of the cleanup.
60       * @see javax.jbi.component.Bootstrap#cleanUp()
61       */
62      public void cleanUp()
63      throws javax.jbi.JBIException {
64      	LOG.info("CRB000431_Component_Installer_Cleaned_up" );
65      }
66      
67      /**
68       * Initializes the installation environment for a component.
69       *
70       * @see javax.jbi.component.Bootstrap#init(javax.jbi.component.InstallationContext)
71       */
72      public void init(InstallationContext installContext)
73      throws javax.jbi.JBIException {
74                
75          if ( installContext == null  ) {
76          	LOG.info("CRB000432_Null_Installation_Context_received_in_init_Component_Bootstrap_initialization");
77          }
78          
79          this.mContext = installContext;
80          
81          ComponentContext ctx = installContext.getContext();
82          MBeanServer mbServer = ctx.getMBeanServer();
83          MBeanNames mbNames = ctx.getMBeanNames();
84          
85          mInstallerExtName = mbNames.createCustomComponentMBeanName(MBeanNames.BOOTSTRAP_EXTENSION);
86          
87          InstallerExtMBean installerExt = new InstallerExt();
88                      
89          try {
90              if (!mbServer.isRegistered(mInstallerExtName)) {
91                  StandardMBean installerExtMBean = new StandardMBean(installerExt, InstallerExtMBean.class);
92                  mbServer.registerMBean(installerExtMBean, mInstallerExtName);
93              }
94          } catch (Exception ex) {
95          	String msg=MESSAGES.getString("CRB000423_InstallerMBean_registration_failed");
96              LOG.error(msg,ex);
97              throw new JBIException(msg,ex);
98          }
99          LOG.info("CRB000433_Received_MBean", new Object[]{mInstallerExtName});
100                
101         LOG.info("CRB000434_Component_Installer_initialized");
102     }
103     
104     /**
105      * default implemenation that does not have extension mbean return null.
106      *
107      * @see javax.jbi.component.Bootstrap#getExtensionMBeanName()
108      */
109     public javax.management.ObjectName getExtensionMBeanName() {
110         return null;
111     }
112     
113     /**
114      * Default implemenation: just logs the method call.
115      * @see javax.jbi.component.Bootstrap#onInstall()
116      */
117     public void onInstall()
118     throws javax.jbi.JBIException {
119     	LOG.info("CRB000435_Component_Installed");
120     }
121     
122     /**
123      * Default implemenation: just logs the method call.
124      *
125      * @see javax.jbi.component.Bootstrap#onUninstall()
126      */
127     public void onUninstall()
128     throws javax.jbi.JBIException {
129     	LOG.info("CRB000436_Component_Uninstalled");
130     }
131     
132 }