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

at.spardat.xma.boot.comp.data.XMAComponent Maven / Gradle / Ivy

There is a newer version: 1.16.0
Show newest version
/*******************************************************************************
 * 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 : 16.06.2003
 * Created by : s3595
 */
package at.spardat.xma.boot.comp.data;

import java.io.PrintStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;

import at.spardat.xma.boot.BootRuntime;
import at.spardat.xma.boot.comp.DTDStatics;
import at.spardat.xma.boot.component.IComponent;
import at.spardat.xma.boot.component.IComponentHelper;

/**
 * XMAComponent
 *
 * @author s3595, Chris Sch?fer (CGS)
 * @version $Id: XMAComponent.java 2902 2008-11-12 13:59:09Z gub $
 */
public class XMAComponent {

    /** name of the xma component as described in xma-app */
    private String name_;

    /** base package that this component is included in */
    private String implPackage_;

    /** the resources needed by this component */
    private HashMap res_;

    /** shared resources needed by this component */
    private ArrayList resourceLinks_;

    /** contains to this application */
    private XMAApp application_;

    /** interface to the running component */
    // private IComponent rtcmp;

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

    /** File URL of fast develompment mode class directory for this component*/
    private URL fdmUrl_;


    public XMAComponent( String name, String impl ) {
      res_            = new HashMap(15);
      resourceLinks_  = new ArrayList();
      instances_      = new HashMap();
      this.setName_(name);
      this.setImplPackage_(impl);
    }

    public void writeXML( PrintStream ps ) {

       ps.print( DTDStatics.OPEN + DTDStatics.COMPONENT );
         ps.print( DTDStatics.SP + DTDStatics.COMPONENT_NAME + DTDStatics.QUOTE + this.name_ + DTDStatics.E_QUOTE );
        ps.print( DTDStatics.SP + DTDStatics.COMPONENT_IMPLPACKAGE + DTDStatics.QUOTE + this.implPackage_ + DTDStatics.E_QUOTE );
        ps.print( DTDStatics.SP + DTDStatics.CLOSE );
        ps.println();

        for (Iterator iter = res_.values().iterator(); iter.hasNext();) {
            XMAResource element = (XMAResource)iter.next();
            ps.print("   "); //$NON-NLS-1$
            element.writeXML(ps);
            ps.println();

        }

        for (Iterator iter = resourceLinks_.iterator(); iter.hasNext();) {
            XMAResourceLink element = (XMAResourceLink)iter.next();
            ps.print("   ");             //$NON-NLS-1$
            element.writeXML(ps);
            ps.println();
         }

       ps.println( DTDStatics.OPEN + DTDStatics.CLOSE_CHAR + DTDStatics.COMPONENT + DTDStatics.CLOSE );
    }



    public void addResource( XMAResource r ) {
       this.res_.put( r.getHref_(), r);
    }

    public void addResourceLink( XMAResourceLink r ) {
       this.resourceLinks_.add(r);
    }

    /**
     * @return String base impl-package name
     */
    public String getImplPackage_() {
        return implPackage_;
    }

    /**
     * @return String component name
     */
    public String getName_() {
        return name_;
    }

    /**
     * @param string package name
     */
    public void setImplPackage_(String string) {
        implPackage_ = string;
    }

    /**
     * @param string component name
     */
    public void setName_(String string) {
        name_ = string;
    }

    /**
     * @return ArrayList resource links of required shared resources
     */
    public ArrayList getResourceLinks() {
        return resourceLinks_;
    }

    /**
     * @return HashMap component resources
     */
    public HashMap getRes() {
        return res_;
    }

    /**
     * @return XMAApp the xma app
     */
    public XMAApp getApplication() {
        return application_;
    }

    /**
     * @param app  xmaapp
     */
    public void setApplication(XMAApp app) {
        application_ = app;
    }

    /**
     * add a new running instance of this component.
     *
     * @param component
     */
    public void addInstance(IComponent component ){
        instances_.put( Integer.toString( component.hashCode()), component );
    }

    public IComponent remInstance( IComponent component ) {
        Object cmp = instances_.remove( Integer.toString( component.hashCode()) );
        IComponentHelper compHelper = BootRuntime.getInstance().getAppManager().getCompHelper();
        return compHelper!=null?compHelper.castToIComponent(cmp):null;
    }

    public int instanceCount() {
        return instances_.size();
    }

    public void setFdmUrl(URL url) {
        fdmUrl_=url;
    }

    public URL getFdmUrl() {
        return fdmUrl_;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy