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

at.spardat.xma.boot.comp.AppContainer Maven / Gradle / Ivy

/*******************************************************************************
 * Copyright (c) 2003, 2007 s IT Solutions AT Spardat GmbH .
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     s IT Solutions AT Spardat GmbH - initial API and implementation
 *******************************************************************************/

/*
 * Created on : 20.06.2003
 * Created by : s3595
 */
package at.spardat.xma.boot.comp;

import java.util.HashMap;

import at.spardat.xma.boot.cache.VersionNumber;
import at.spardat.xma.boot.comp.data.XMAApp;
import at.spardat.xma.boot.comp.data.XMAComponent;
import at.spardat.xma.boot.comp.data.XMAPluginImpl;
import at.spardat.xma.boot.component.IBootRuntime;
import at.spardat.xma.boot.component.IComponent;
import at.spardat.xma.boot.component.IRtXMASessionClient;

/**
 * AppContainer is a data-object that holds information about a running application
 * and it?s components.
 *
 * @author s3595 Chr. Schaefer (CGS)
 * @version $Id: AppContainer.java 2084 2007-11-27 14:53:31Z s3460 $
 *
 */
public class AppContainer implements IBootRuntime {

    /** application description */
    private XMAApp app_;

    /** custom class-loader */
    private CCLoader ccl_;

    /** the xma session for this application */
    private IRtXMASessionClient session_;

    /** running components
     * one or more components of an application can be instantiated.
     */
    private HashMap runcmp_;

    /** the application manager */
    private AppManager appManager_;

    /** the application hash */
    private byte[] digest_;

    /** the runtime version number send from the server */
    private VersionNumber serverVers_;

    public AppContainer () {
        app_     = null;
        ccl_     = null;
        session_ = null;
        runcmp_  = new HashMap();
        digest_  = null;
    }

    /** set application manager */
    public void setAppManager( AppManager in) {
        appManager_ = in;
    }

    /** get application manager */
    public AppManager getAppManager() {
        return appManager_;
    }

    /**
     * @return XMAApp  xma application description
     */
    public XMAApp getApp() {
        return app_;
    }

    /**
     * get the the xma session for this application
     */
    public IRtXMASessionClient getSession( ) {
        return session_;
    }

    /**
     * @return CCLoader
     */
    public CCLoader getCcl() {
        return ccl_;
    }

    /**
     * @param app
     */
    public void setApp(XMAApp app) {
        app_ = app;
    }

    /**
     * @param loader
     */
    public void setCcl(CCLoader loader) {
        ccl_ = loader;
    }

    /**
     * @return CCLoader
     */
    public CCLoader getCcl_() {
        return ccl_;
    }

    /**
     * @param app
     */
    public void setApp_(XMAApp app) {
        app_ = app;
    }

    /**
     * @param loader
     */
    public void setCcl_(CCLoader loader) {
        ccl_ = loader;
    }

    /**
     * @param client
     */
    public void setSession(IRtXMASessionClient client) {
        session_ = client;
    }

    /**
     * @return IRtXMASessionClient
     */
    public IRtXMASessionClient getSession_() {
        return session_;
    }

    /**
     * @param client
     */
    public void setSession_(IRtXMASessionClient client) {
        session_ = client;
    }

    /**
     * @return HashMap
     */
    public HashMap getRuncmp_() {
        return runcmp_;
    }

    /**
     * @param map
     */
    public void setRuncmp_(HashMap map) {
        runcmp_ = map;
    }


    /**
     * @return Returns the serverVers_.
     */
    public VersionNumber getServerVers() {
        return serverVers_;
    }
    /**
     * @param serverVers The serverVers to set.
     */
    public void setServerVers(VersionNumber serverVers) {
        this.serverVers_ = serverVers;
    }

    public boolean isRunningCmp( XMAComponent cmp ) {

        XMAComponent res = getRunningCmp(cmp);
        if (res != null)
          return true;
        return false;
    }

    public XMAComponent getRunningCmp( XMAComponent cmp ) {
        return getRunningCmp(cmp.getName_());
    }

    public XMAComponent getRunningCmp( String strCmpName ) {
        return (XMAComponent)getRuncmp_().get( strCmpName );
    }

    public void addRunningCmp( XMAComponent cmp ) {
        getRuncmp_().put( cmp.getName_(), cmp );
    }

    public XMAComponent remRunningCmp( String name ) {

      XMAComponent cmp = (XMAComponent)getRuncmp_().remove(name);
      return cmp;
    }

    public int runningCmp() {
        return getRuncmp_().size();
    }

    /**
     * @return application descriptor digest value
     */
    public byte[] getDigest() {
        return digest_;
    }

    /**
     * @param bs application descriptor digest value
     */
    public void setDigest(byte[] bs) {
        digest_ = bs;
    }

    public String getDigestAsString() {

        StringBuffer checksumSb = new StringBuffer();
        for (int i = 0; i < digest_.length; i++) {
            String hexStr = Integer.toHexString(0x00ff & digest_[i]);
            if (hexStr.length() < 2) {
                checksumSb.append("0");
            }
            checksumSb.append(hexStr);
        }
        String checksum = checksumSb.toString();
        return checksum;
    }

    /* (non-Javadoc)
     * @see at.spardat.xma.boot.component.IBootRuntime#getComponent(java.lang.String)
     */
    public IComponent getComponent(String component) throws Exception {
        return getAppManager().getComponent(component);
    }

    /* (non-Javadoc)
     * @see at.spardat.xma.boot.component.IBootRuntime#endComponent(at.spardat.xma.boot.component.IComponent)
     */
    public void endComponent(IComponent rtc) {
        getAppManager().endComponent(rtc);
    }

    /* (non-Javadoc)
     * @see at.spardat.xma.boot.component.IBootRuntime#getPluginImplClient(java.lang.String)
     */
    public String getPluginImplClient(String interfaceName) {

        XMAPluginImpl impl = app_.getPluginImpl( interfaceName );
        if( impl == null ) {
            throw new RuntimeException ("no implementation for plug-in-interface " + interfaceName);
        }

        String strImpl = impl.getImplClient_();
        if( strImpl == null )
            throw new RuntimeException ("no implementation for plug-in-interface " + interfaceName);

        return strImpl;
    }

}












© 2015 - 2024 Weber Informatics LLC | Privacy Policy