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

at.spardat.xma.boot.comp.data.XMAApp 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 : 04.2003
 * Created by : s3595
 */
package at.spardat.xma.boot.comp.data;

import java.io.PrintStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

import at.spardat.xma.boot.comp.DTDStatics;
import at.spardat.xma.boot.transport.XMA_URI;


/**
 * Encapsulates application description data
 *
 * @author s3595 Chris Sch?fer (CGS)
 * @version $Id: XMAApp.java 10853 2013-06-28 12:02:20Z dschwarz $
 */
public class XMAApp {

    /** application descriptor remote url */
    private XMA_URI applicationDescrURI;

    /**
     *  application components of type XMAComponents
     */
    public HashMap components_;

    /**
     * common, shared resources for this application
     */
    public HashMap res_;

    /**
     * referenced plugin implemenation descriptions
     * of type XMAPluginImpl
     */
    public HashMap pluginimpl_;

    /**
     * this application needs an implementation for these plugin?s
     */
    public ArrayList pluginspec_;
    
    public List sslRestriction_;

    /**
     * holds the description of SWT needed by the application
     */
    public XMASWTDescription swtDescription;

    private void init() {
        components_ = new HashMap(10);
        res_        = new HashMap(25);
        pluginimpl_ = new HashMap(10);
        pluginspec_ = new ArrayList(10);
        sslRestriction_ = new ArrayList();
    }

    public XMAApp( ) {
       init();
    }

    /**
     * Return all resources of this XMAApp in one HashMap. This are all
     * resources described in the corresponding xma-appl.xml file.
     * This contains the top level resources, the resources of all components,
     * the rescources of all pluginimpls and the resources of an optional
     * swt-description.
     */
    public HashMap getAllResources() {
        return getAllResources(false);
    }

    /**
     * Return all resources of this XMAApp to be downloaded.
     * If fdm=true, this are all resources described in the corresponding xma-appl.xml file.
     * If fdm=false, the resources declared in components are omitted unless they have the
     * fmdLoad flag set to true.
     * Top level resources, the rescources of all pluginimpls and the resources of an optional
     * swt-description are contained anyway.
     */
    public HashMap getAllResources(boolean fdm) {

        HashMap map = new HashMap( res_.size() + components_.size()*3 + pluginimpl_.size()*2 );

        map.putAll( res_);

        for (Iterator iter = components_.values().iterator(); iter.hasNext();) {
            XMAComponent element = (XMAComponent)iter.next();

            HashMap res = element.getRes();
            if(fdm) {
                for(Iterator it=res.keySet().iterator();it.hasNext();) {
                    String key = (String)it.next();
                    XMAResource resource = (XMAResource)res.get(key);
                    if(resource.isFdmload()) {
                        map.put(key, resource);
                    }
                }
            } else {
                map.putAll(res);
            }
        }

        for (Iterator iter = pluginimpl_.values().iterator(); iter.hasNext();) {
            XMAPluginImpl element = (XMAPluginImpl)iter.next();

            HashMap res = element.getRes();
            map.putAll(res);
        }

        if(swtDescription!=null) {
            map.putAll(swtDescription.getResources());
        }

        return map;
    }

    public void writeXML( PrintStream ps ) {

       ps.println( DTDStatics.xmlHeader );
       ps.println();

       ps.println( DTDStatics.OPEN + DTDStatics.XMA_Application + DTDStatics.CLOSE );
       ps.println();

       for (Iterator iter = components_.values().iterator(); iter.hasNext();) {
           XMAComponent element = (XMAComponent)iter.next();
           element.writeXML(ps);
           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();
       }
       ps.println();

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

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

       if(swtDescription!=null) {
           ps.print("   "); //$NON-NLS-1$
           swtDescription.writeXML(ps);
           ps.println();
       }
       
       if(sslRestriction_ != null) {
           for (XMASSLRestriction restriction : sslRestriction_) {
               restriction.writeXML(ps);
           }
       }

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



    public XMAComponent getComponent( String name ) {
        return (XMAComponent)this.components_.get(name);
    }

    public void addComponent( XMAComponent c ) {
       this.components_.put( c.getName_(), c);
    }

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

    public void addPluginImpl( XMAPluginImpl pi ) {
       this.pluginimpl_.put( pi.getStrImplements_(), pi);
    }

    public void addPluginSpec( XMAPluginSpec in ) {
       this.pluginspec_.add(in);
    }

    public XMAPluginImpl getPluginImpl( String strName ) {
       return (XMAPluginImpl)this.pluginimpl_.get( strName );
    }

    /**
     * @return String
     */
    public String getName_() {
        return applicationDescrURI.getApplication();
    }

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

    /**
     * @param map
     * @return void
     */
    public void setRes(HashMap map) {
        res_ = map;
    }

    /**
     * @return XMA_URI allication uri
     */
    public XMA_URI getApplicationDescrURI() {
        return applicationDescrURI;
    }

    /**
     * @param xma_uri
     */
    public void setApplicationDescrURI(XMA_URI xma_uri) {
        applicationDescrURI = xma_uri;
    }

    public XMASWTDescription getSwtDescription() {
        return swtDescription;
    }

    public void setSwtDescription(XMASWTDescription swtDescription) {
        this.swtDescription = swtDescription;
    }

    public List getSSLRestriction() {
        return sslRestriction_;
    }
    
    public void addSSLRestriction(XMASSLRestriction restriction) {
        sslRestriction_.add(restriction);
    }


}








© 2015 - 2024 Weber Informatics LLC | Privacy Policy