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