JMXConfiguration.java revision 658
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;
1327N/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
639N/A @SuppressWarnings("PMD.CollapsibleIfStatements")
708N/A public void setConfiguration(String config) throws IOException {
639N/A Configuration configuration = Configuration.makeXMLStringAsConfiguration(config);
639N/A RuntimeEnvironment.getInstance().setConfiguration(configuration);
639N/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()) {
658N/A if (file.createNewFile()) {
1327N/A throw new IOException("could not create configuration file " + configfile);
658N/A }
658N/A }
672N/A RuntimeEnvironment.getInstance().writeConfiguration(file);
1327N/A } catch (IOException ioe) {
1327N/A throw new IOException("Could not create configuration file " + configfile,ioe);
658N/A }
639N/A }
639N/A}