All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.objectweb.petals.component.framework.Bootstrap Maven / Gradle / Ivy

Go to download

The PEtALS component framework. This framework is used to easily create JBI 1.0 compliant components.

The newest version!
/**
 * PETALS - PETALS Services Platform.
 * Copyright (c) 2007 EBM Websourcing, http://www.ebmwebsourcing.com/
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * -------------------------------------------------------------------------
 * $Id$
 * -------------------------------------------------------------------------
 */

package org.objectweb.petals.component.framework;

import java.util.Properties;

import javax.jbi.JBIException;
import javax.jbi.component.InstallationContext;
import javax.management.ObjectName;

import org.objectweb.petals.component.framework.util.Extensions;
import org.objectweb.petals.jbi.descriptor.JBIDescriptorException;

/**
 * A simple bootstrap implementation. This bootstrap simplies copy the JBI
 * extensions in a properties file that will be used by components.
 *
 * @author ofabre chamerling - eBM WebSourcing
 *
 */
public class Bootstrap implements javax.jbi.component.Bootstrap {

    /**
     * The component installation context
     */
    protected InstallationContext installContext;

    /**
     * The component properties manager
     */
    protected ComponentPropertiesManager propertiesManager;

    /*
     * (non-Javadoc)
     *
     * @see javax.jbi.component.Bootstrap#cleanUp()
     */
    public void cleanUp() throws JBIException {
    }

    /**
     * Returns null by default as this class does not provides JMX extension
     * MBean
     *
     * @see javax.jbi.component.ComponentLifeCycle#getExtensionMBeanName()
     */
    public ObjectName getExtensionMBeanName() {
        return null;
    }

    /*
     * (non-Javadoc)
     *
     * @see javax.jbi.component.Bootstrap#init(javax.jbi.component.InstallationContext)
     */
    public void init(InstallationContext installContext) throws JBIException {
        this.installContext = installContext;
        try {
            doInit(installContext);
        } catch (Exception e) {
            throw new JBIException("Initialization exception", e);
        }
    }

    /**
     * The component properties are loaded in this order :
     * 
    *
  1. Get the default values defined in the PCF (thread pool, ...)
  2. *
  3. Get values from the JBI extensions (can override the default ones)
  4. *
  5. Get additional properties defined in the component
  6. *
* * @param installContext * @throws JBIDescriptorException */ private void doInit(InstallationContext installContext) throws JBIDescriptorException { if (this.propertiesManager == null) { this.propertiesManager = new ComponentPropertiesManager(); this.propertiesManager.setRootPath(installContext.getInstallRoot()); // get the default values this.propertiesManager.initDefaultValues(); // get the properties from the jbi extensions. Will override the // default ones org.objectweb.petals.jbi.descriptor.Extensions descExtensions = new org.objectweb.petals.jbi.descriptor.Extensions(); descExtensions.setDocumentFragment(installContext .getInstallationDescriptorExtension()); Extensions extensions = new Extensions(descExtensions); this.propertiesManager.setProperties(extensions .getPetalsExtensions()); // get the properties from an available properties file (from a // previous installation). Override the previous values. Properties props = this.propertiesManager .retrievePersistedProperties(); this.propertiesManager.getProperties().putAll(props); // do additional configuration from component implementation. (this // method is overridden in the default bootstrap) doConfig(); // last step, persist properties this.propertiesManager.save(); } } /** * Do additional configuration during the bootstrap initialization phase. * This method is called at the end of the initialization and can be * overridden to provide specific additional configuration. * */ protected void doConfig() { } /** * * @return */ protected ComponentPropertiesManager getComponentPropertiesManager() { return this.propertiesManager; } /* * (non-Javadoc) * * @see javax.jbi.component.Bootstrap#onInstall() */ public void onInstall() throws JBIException { } /* * (non-Javadoc) * * @see javax.jbi.component.Bootstrap#onUninstall() */ public void onUninstall() throws JBIException { } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy