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/A
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
1470N/A /**
1470N/A * {@inheritDoc}
1470N/A */
1470N/A @Override
639N/A public String getConfiguration() {
1470N/A return RuntimeEnvironment.getConfig().getXMLRepresentationAsString();
639N/A }
639N/A
1470N/A /**
1470N/A * {@inheritDoc}
1470N/A */
1470N/A @Override
708N/A @SuppressWarnings({"PMD.CollapsibleIfStatements", "PMD.PreserveStackTrace"})
639N/A public void setConfiguration(String config) throws IOException {
1470N/A Configuration cfg = Configuration.makeXMLStringAsConfiguration(config);
1470N/A RuntimeEnvironment.setConfig(cfg);
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()) {
1327N/A file.createNewFile();
658N/A }
1470N/A RuntimeEnvironment.writeConfig(file);
672N/A } catch (IOException orig) {
1327N/A throw new IOException("Could not create configuration file '"
1327N/A + configfile + "'", orig);
658N/A }
639N/A }
639N/A}