at.spardat.xma.boot.server.ServerAppLoader Maven / Gradle / Ivy
The 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 : 09.07.2003
* Created by : s3595
*/
package at.spardat.xma.boot.server;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Properties;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import at.spardat.xma.boot.Statics;
import at.spardat.xma.boot.comp.AppLoader;
import at.spardat.xma.boot.comp.AppLoaderBase;
import at.spardat.xma.boot.comp.data.XMAApp;
import at.spardat.xma.boot.comp.data.XMAAppParser;
import at.spardat.xma.boot.util.Util;
/**
* ServerAppLoader
*
* @author s3595 Chr. Schaefer (CGS)
* @version $Id: ServerAppLoader.java 11290 2013-12-12 16:00:27Z dschwarz $
*
*/
public class ServerAppLoader extends AppLoaderBase {
/** the application descriptor of this webapplication */
private static XMAApp xmaapp;
/** the hash code of the application descritptor */
private static byte[] digest_;
/**
* @param pnew configuration properties
*/
public ServerAppLoader(Properties pnew) {
super(pnew);
}
/**
* load and parse application descriptors.
*
* @param context servlet context
* @throws Exception
*/
public void loadApplication ( ServletContext context ) throws Exception {
InputStream is=null;
InputStream ispi=null;
try {
is = context.getResourceAsStream( "/" + Statics.APP_DISCRIPTOR); //$NON-NLS-1$
ispi = context.getResourceAsStream( "/" + Statics.PLUGIN_DISCRIPTOR); //$NON-NLS-1$
XMAAppParser parser = new XMAAppParser( super.parseLog_, true, null );
XMAApp xmaapp = parser.parse( is );
if( ispi != null) {
XMAApp plugins = parser.parse( ispi );
super.mergeInto(xmaapp, plugins);
}
AppLoader.checkResourceIntegrity( xmaapp );
ArrayList missing = AppLoader.checkPluginSpecImpl( xmaapp );
if( missing.size() > 0 ){
throw new ServletException("XMA Application Descriptor has missing plugin-resources: " + missing ); //$NON-NLS-1$
}
createApplicationHash(context);
ServerAppLoader.setXmaapp( xmaapp );
} finally {
Util.close(is,Statics.APP_DISCRIPTOR);
Util.close(ispi,Statics.APP_DISCRIPTOR);
}
}
/**
* computes and sets the application hash code
*
* @param context Servlet context
* @throws Exception NoSuchAlgorithm and IOException
*/
private void createApplicationHash( ServletContext context ) throws Exception {
InputStream isApp=null;
InputStream isPi=null;
try {
isApp = context.getResourceAsStream( "/" + Statics.APP_DISCRIPTOR); //$NON-NLS-1$
isPi = context.getResourceAsStream( "/" + Statics.PLUGIN_DISCRIPTOR); //$NON-NLS-1$
setDigest( createApplicationHash(isApp, isPi ) );
} finally {
Util.close(isApp,Statics.APP_DISCRIPTOR);
Util.close(isPi,Statics.APP_DISCRIPTOR);
}
}
/**
* @return XMAApp xma application descriptor
*/
public static XMAApp getXmaapp() {
return xmaapp;
}
/**
* @param app xma application descriptor
*/
private static void setXmaapp(XMAApp app) {
xmaapp = app;
}
/**
* @return application digest (hash code)
*/
public static byte[] getDigest() {
return digest_;
}
/**
* @param bs set application digest
*/
private static void setDigest(byte[] bs) {
digest_ = bs;
}
}