/*
 This file is part of the software framework JStatCom, 
 a library for building applications for data based analysis.

 Copyright (C) 2000-2005  Markus Kraetzig

 This library is free software; you can redistribute it and/or modify
 it under the terms of the GNU Lesser General Public License as
 published by the Free Software Foundation; either version 2.1 of the
 License, or (at your option) any later version.

 This library is distributed in the hope that it will be useful, but
 WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 Lesser General Public License for more details.

 You should have received a copy of the GNU Lesser General Public
 License along with this library; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 USA
 */

package com.jstatcom.engine;

import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
import java.io.Writer;

import javolution37.javolution.xml.ObjectReader;
import javolution37.javolution.xml.ObjectWriter;

import org.apache.log4j.Logger;

import com.jstatcom.component.ResultField;
import com.jstatcom.component.StdMessages;

/**
 * Default implementation of AbstractConfigPanel to provide a
 * user input mask for all settings needed to run an engine. It has an editable
 * view to the XML version of the respective ConfigHolder.
 * 

* This default implementation can be used for any engine, because all settings * can directly be edited and validated. However, it might not be the most * convenient solution for the user. * * @author Markus Kraetzig */ public final class DefaultConfigPanel extends AbstractConfigPanel { private static final Logger log = Logger .getLogger(DefaultConfigPanel.class); private ResultField ivjXMLField = null; /** * DefaultConfigPanel constructor comment. */ public DefaultConfigPanel() { super(); initialize(); } /** * Return the XMLField property value. * * @return com.jstatcom.component.ResultField */ /* WARNING: THIS METHOD WILL BE REGENERATED. */ private com.jstatcom.component.ResultField getXMLField() { if (ivjXMLField == null) { try { ivjXMLField = new com.jstatcom.component.ResultField(); ivjXMLField.setName("XMLField"); // user code begin {1} // user code end } catch (Throwable ivjExc) { // user code begin {2} // user code end log.error("Error setting text field", ivjExc); } } return ivjXMLField; } /** * Initialize the class. */ /* WARNING: THIS METHOD WILL BE REGENERATED. */ private void initialize() { try { // user code begin {1} // user code end setName("DefaultConfigPanel"); setLayout(new javax.swing.BoxLayout(this, javax.swing.BoxLayout.X_AXIS)); setSize(687, 479); add(getXMLField(), getXMLField().getName()); } catch (Throwable ivjExc) { log.error("Error initializing", ivjExc); } // user code begin {2} // user code end } /** * @see com.jstatcom.engine.AbstractConfigPanel */ public void setConfig(ConfigHolder configHolder) { ObjectWriter objectWriter = new ObjectWriter(); objectWriter.setPackagePrefix("", "com.jstatcom.engine"); objectWriter.setPackagePrefix("jstatcom", "com.jstatcom"); Writer sWriter = new StringWriter(); try { objectWriter.write(configHolder, sWriter); // Uses UTF-8 encoding. } catch (IOException ex) { String msg = "Configuration settings for engine of type " + configHolder.getEngineType() + " could not be displayed."; log.error(msg, ex); StdMessages.error(msg + "\nPlease check log for further details.", "Error"); } getXMLField().setText(sWriter.toString()); } /** * @see com.jstatcom.engine.AbstractConfigPanel */ public String storeConfig(ConfigHolder configHolder) { ObjectReader constructor = new ObjectReader(); try { configHolder = (ConfigHolder) constructor.read(new StringReader( getXMLField().getText())); } catch (Throwable ex) { return "Configuration settings could not be read.\nThe following error occured:\n\n" + ex.getMessage() + "\n\n"; } return null; } }

Ads help maintain this website.