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