at.spardat.xma.boot.comp.AppLoaderBase 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 : 09.07.2003
* Created by : s3595
*/
package at.spardat.xma.boot.comp;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Iterator;
import java.util.Properties;
import at.spardat.xma.boot.comp.data.XMAApp;
import at.spardat.xma.boot.comp.data.XMAPluginImpl;
import at.spardat.xma.boot.comp.data.XMAResource;
import at.spardat.xma.boot.logger.LogLevel;
import at.spardat.xma.boot.logger.Logger;
/**
* AppLoaderTools
*
* @author s3595 Chr. Schaefer (CGS)
* @version $Id: AppLoaderBase.java 2084 2007-11-27 14:53:31Z s3460 $
*
*/
public class AppLoaderBase {
/** logger for parser */
protected Logger log_;
/** logger for parser */
protected Logger parseLog_;
/** configuration properties */
protected Properties props;
/**
* constructs a AppLoaderBase
* @param pnew the boot runtime properties
*/
protected AppLoaderBase( Properties pnew ) {
if( pnew !=null){
props = pnew;
} else
props = new Properties();
log_ = Logger.getLogger( "boot.appLoader"); //$NON-NLS-1$
parseLog_ = Logger.getLogger( "boot.parser"); //$NON-NLS-1$
}
/**
* merge plugin information into the main descriptor.
*
* @param main application descriptor
* @param plugins import this
*/
protected void mergeInto( XMAApp main, XMAApp plugins ) {
if( plugins.components_.size() > 0 ) {
log_.warning("Plug-In Descriptor contains components. They will be ignored"); //$NON-NLS-1$
}
if( plugins.pluginspec_.size() > 0 ) {
log_.warning("Plug-In Descriptor contains plugin-specs. It should only contain plugin implementations. They will be ignored"); //$NON-NLS-1$
}
// this.pluginimpl_.put( pi.getStrImplements_(), pi);
for (Iterator iter = plugins.pluginimpl_.values().iterator(); iter.hasNext();) {
XMAPluginImpl el = (XMAPluginImpl)iter.next();
XMAPluginImpl old = (XMAPluginImpl)main.pluginimpl_.get( el.getStrImplements_() );
if( old != null ) {
log_.warning("Application Descriptor already contains a plug-in implementation for: " + el.getStrImplements_() + " it will be replaced the implementation of this plugins.xml" ); //$NON-NLS-1$ //$NON-NLS-2$
}
main.pluginimpl_.put( el.getStrImplements_(), el );
}
for (Iterator iter = plugins.res_.values().iterator() ; iter.hasNext();) {
XMAResource el = (XMAResource)iter.next();
XMAResource old = (XMAResource)main.res_.get( el.getHref_() );
if( old != null ) {
log_.warning("Application Descriptor already contains a resource for: " + el.getHref_() + " it will be replaced the resource of this plugins.xml" ); //$NON-NLS-1$ //$NON-NLS-2$
}
main.addResource(el);
}
} // mergeInto
/**
* creates the has value for the application. This is done by concatenating the content of
* the two given input streams and calculating the MD5-hash over this combined content.
* @param isApp first description file (xma-app.xml)
* @param isPi second description file (plugin.xml)
* @return the calculated hash value
* @throws IOException in case of errors reading the streams
*/
protected byte[] createApplicationHash(InputStream isApp, InputStream isPi ) throws IOException {
MessageDigest md;
try {
md = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException e) {
log_.log(LogLevel.SEVERE,"error preventing hash calculations: ",e);
throw new RuntimeException(e);
}
int b = -1;
ByteArrayOutputStream os = new ByteArrayOutputStream();
while( (b = isApp.read())!= -1 ) {
os.write(b);
}
while( (b = isPi.read())!= -1 ) {
os.write(b);
}
md.update( os.toByteArray() );
byte[] digest = md.digest();
return digest;
}
}