JMXConfiguration.java revision 708
639N/A/*
639N/A * CDDL HEADER START
639N/A *
639N/A * The contents of this file are subject to the terms of the
639N/A * Common Development and Distribution License (the "License").
639N/A * You may not use this file except in compliance with the License.
639N/A *
639N/A * See LICENSE.txt included in this distribution for the specific
639N/A * language governing permissions and limitations under the License.
639N/A *
639N/A * When distributing Covered Code, include this CDDL HEADER in each
639N/A * file and include the License file at LICENSE.txt.
639N/A * If applicable, add the following below this CDDL HEADER, with the
639N/A * fields enclosed by brackets "[]" replaced with your own identifying
639N/A * information: Portions Copyright [yyyy] [name of copyright owner]
639N/A *
639N/A * CDDL HEADER END
639N/A */
639N/A
639N/A/*
639N/A * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
639N/A * Use is subject to license terms.
639N/A */
639N/A
639N/Apackage org.opensolaris.opengrok.management;
639N/A
658N/Aimport java.io.File;
639N/Aimport java.io.IOException;
659N/Aimport java.util.logging.Level;
659N/Aimport org.opensolaris.opengrok.OpenGrokLogger;
639N/Aimport org.opensolaris.opengrok.configuration.Configuration;
639N/Aimport org.opensolaris.opengrok.configuration.RuntimeEnvironment;
639N/A
639N/A/**
639N/A *
639N/A * @author Jan Berg
639N/A */
639N/Apublic class JMXConfiguration implements JMXConfigurationMBean {
639N/A
639N/A public String getConfiguration() {
639N/A return RuntimeEnvironment.getInstance().getConfiguration().getXMLRepresentationAsString();
639N/A }
639N/A
708N/A @SuppressWarnings({"PMD.CollapsibleIfStatements", "PMD.PreserveStackTrace"})
639N/A public void setConfiguration(String config) throws IOException {
639N/A Configuration configuration = Configuration.makeXMLStringAsConfiguration(config);
639N/A RuntimeEnvironment.getInstance().setConfiguration(configuration);
658N/A //write it to file as well
658N/A String configfile = Management.getInstance().getConfigurationFile();
658N/A try {
658N/A File file = new File(configfile);
658N/A if (!file.exists()) {
672N/A if (!file.createNewFile()) {
672N/A throw new IOException("Could not create configuration file: '" + configfile + "'");
658N/A }
658N/A }
658N/A RuntimeEnvironment.getInstance().writeConfiguration(file);
672N/A } catch (IOException orig) {
672N/A IOException ioex = new IOException("Could not create configuration file " + configfile);
672N/A ioex.initCause(orig);
672N/A OpenGrokLogger.getLogger().log(Level.SEVERE,"Could not create configfile " + configfile, ioex);
672N/A throw ioex;
658N/A }
639N/A }
639N/A}