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

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

import java.io.PrintStream;
import java.util.Locale;

import org.xml.sax.SAXException;

import at.spardat.xma.boot.cache.IFileCacheResource;
import at.spardat.xma.boot.comp.DTDStatics;

/**
 *
 * @author s3595 Chris Sch?fer (CGS)
 * @version $Id: XMAResource.java 6993 2010-12-14 14:23:42Z webok $
 */

public class XMAResource {

    /** Specifies the location of the resource */
    private String href_;

    /** Describes the version = hashValue of the .jar file */
    private Version version_;

    /** resource type */
    private TypeID  type_;

    /** locale of the resource */
    private Locale  locale_;

    /** reference to a file cache resource object */
    private IFileCacheResource res_;

    /** is the resource shared between applications */
    private boolean shared_;

    /** will this recource be loaded in fast development mode if contained in a component */
    private boolean fdmload_;

    /**
     *  Optional, defines the OS a resource is for, as in JNLP, see http://lopica.sourceforge.net/ref.html#resources
     */
    private String os_;

    /**
     * Optional, defines the Architecture a resource is for, as in JNLP, see http://lopica.sourceforge.net/ref.html#resources
     */
    private String arch_;

    public XMAResource( String href, Version version, XMAResource.TypeID type, Locale locale, boolean shared, String os, String arch ) {
        this.href_    = href;
        this.version_ = version;
        this.locale_  = locale;
        this.type_    = type;
        this.shared_  = shared;
        this.os_ 	  = os;
        this.arch_ 	  = arch;
    }

    /**
     * write this object to a xml print stream.
     *
     * @param ps the PrintStream to write to
     */
    public void writeXML( PrintStream ps ) {

       ps.print( DTDStatics.OPEN + DTDStatics.RESOURCE );
         ps.print( DTDStatics.SP + DTDStatics.RESOURCE_HREF + DTDStatics.QUOTE + this.href_ + DTDStatics.E_QUOTE );
         ps.print( DTDStatics.SP + DTDStatics.RESOURCE_TYPE + DTDStatics.QUOTE + this.type_.getStringID() + DTDStatics.E_QUOTE );
         ps.print( DTDStatics.SP + DTDStatics.RESOURCE_VERSION + DTDStatics.QUOTE + this.version_.getVersion() + DTDStatics.E_QUOTE );
       if( locale_ != null ) {
         ps.print( DTDStatics.SP + DTDStatics.RESOURCE_LOCALE + DTDStatics.QUOTE + this.locale_.toString() + DTDStatics.E_QUOTE );
       }
       if(shared_) {
           ps.print(DTDStatics.SP + DTDStatics.RESOURCE_SHARED + DTDStatics.QUOTE + this.shared_ + DTDStatics.E_QUOTE);
       }
       if(fdmload_) {
           ps.print(DTDStatics.SP + DTDStatics.RESOURCE_FDMLOAD + DTDStatics.QUOTE + this.fdmload_ + DTDStatics.E_QUOTE);
       }
       if( os_ != null ) {
           ps.print( DTDStatics.SP + DTDStatics.RESOURCE_OSNAME + DTDStatics.QUOTE + this.os_.toString() + DTDStatics.E_QUOTE );
       }
       if( arch_ != null ) {
           ps.print( DTDStatics.SP + DTDStatics.RESOURCE_OSARCH + DTDStatics.QUOTE + this.arch_.toString() + DTDStatics.E_QUOTE );
       }

       ps.print( DTDStatics.SP + DTDStatics.CLOSE_SIMPLES );
    }

    public static class TypeID {
      private String strID;

      public static String TYPE_JAR          = "jar"; //$NON-NLS-1$
      public static String TYPE_NATIVELIB    = "lib"; //$NON-NLS-1$
      // public String TYPE_FILE         = "file";

      public TypeID( String id ) {
          strID = id;
      }
      public String getStringID() {
          return strID;
      }

      public static TypeID getID( String id ) throws SAXException{
        if ( id.equals(TypeID.TYPE_JAR ) ) {
            return new TypeID(TypeID.TYPE_JAR);
        } else if( id.equals(TypeID.TYPE_NATIVELIB)) {
            return new TypeID(TypeID.TYPE_NATIVELIB);
        } else
          throw new SAXException( "parse error"); //$NON-NLS-1$
      }
    }

    /**
     * @return String href
     */
    public String getHref_() {
        return href_;
    }

    /**
     * @return Locale locale
     */
    public Locale getLocale_() {
        return locale_;
    }

    /**
     * @return TypeID typeid
     */
    public TypeID getType_() {
        return type_;
    }

    /**
     * @return Version
     */
    public Version getVersion_() {
        return version_;
    }

    /**
     * @return Returns if shared.
     */
    public boolean isShared_() {
        return shared_;
    }

    /**
     * @param string href to set
     */
    public void setHref_(String string) {
        href_ = string;
    }

    /**
     * @param locale locale to set
     */
    public void setLocale_(Locale locale) {
        locale_ = locale;
    }

    /**
     * @param typeID
     */
    public void setType_(TypeID typeID) {
        type_ = typeID;
    }

    /**
     * @param version
     */
    public void setVersion_(Version version) {
        version_ = version;
    }

    /**
     * @return IFileCacheResource
     */
    public IFileCacheResource getRes_() {
        return res_;
    }

    /**
     * @param resource
     */
    public void setRes_(IFileCacheResource resource) {
        res_ = resource;
    }

    /**
     * @param shared The shared to set.
     */
    public void setShared_(boolean shared) {
        shared_ = shared;
    }

     /**
     * @return true if this resource describes a jar-file
     * @since 1.3.0
     * @author s2877
     */
    public boolean isJar() {
        return TypeID.TYPE_JAR.equals(type_.strID);
    }

    /**
     * @return true if this resource describes a dll-file
     * @since 1.3.0
     * @author s2877
     */
    public boolean isNativeLib() {
        return TypeID.TYPE_NATIVELIB.equals(type_.strID);
    }


    public boolean isFdmload() {
        return fdmload_;
    }

    public void setFdmload(boolean fdmload) {
        this.fdmload_ = fdmload;
    }

    /**
     * Test if the property 'arch' fits to the current platform
     * @return true if the arch property does not exist (null) or matches the value of the Java "os.arch", otherwise false
     */
    public boolean isValidArch(){
    	String arch = System.getProperty("os.arch");
    	if(arch_ == null || arch_.equalsIgnoreCase(arch)){
    		return true;
    	}else {
    		return false;
    	}
    }
    
    /**
    *
    * Test if the property 'os' fits to the current platform
    * see: http://lopica.sourceforge.net/ref.html#resources
    * @return true if the os property does not exist (null) or matches the beginning of the value of the Java "os.name", otherwise false
    */
    public boolean isValidOs(){
    	String os = System.getProperty("os.name");
    	if(os_ == null || os.startsWith(os_)){
    		return true;
    	}else {
    		return false;
    	}
    }
}







© 2015 - 2024 Weber Informatics LLC | Privacy Policy