001: package hero.util;
002:
003: /**
004: *
005: * Bonita
006: * Copyright (C) 1999 Bull S.A.
007: * Bull 68 route de versailles 78434 Louveciennes Cedex France
008: * Further information: bonita@objectweb.org
009: *
010: * This library is free software; you can redistribute it and/or
011: * modify it under the terms of the GNU Lesser General Public
012: * License as published by the Free Software Foundation; either
013: * version 2.1 of the License, or any later version.
014: *
015: * This library is distributed in the hope that it will be useful,
016: * but WITHOUT ANY WARRANTY; without even the implied warranty of
017: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
018: * Lesser General Public License for more details.
019: *
020: * You should have received a copy of the GNU Lesser General Public
021: * License along with this library; if not, write to the Free Software
022: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
023: * USA
024: *
025: *
026: --------------------------------------------------------------------------
027: * $Id: BonitaConfig.java,v 1.7 2006/05/23 13:41:51 brice Exp $
028: *
029: --------------------------------------------------------------------------
030: */
031:
032: import java.util.List;
033:
034: import javax.management.Attribute;
035: import javax.management.MBeanServer;
036: import javax.management.MBeanServerFactory;
037: import javax.management.ObjectName;
038:
039: public class BonitaConfig {
040:
041: private ObjectName config;
042: private MBeanServer server;
043: private static BonitaConfig bc = null; // Singleton pattern
044:
045: public BonitaConfig() throws HeroException {
046: try {
047: config = new ObjectName(
048: "bonita:type=bonitaservice,name=Config");
049: List list = MBeanServerFactory.findMBeanServer(null);
050: server = (MBeanServer) list.iterator().next();
051: } catch (Exception e) {
052: e.printStackTrace();
053: throw new HeroException(e.getMessage());
054: }
055: }
056:
057: public static BonitaConfig getInstance() throws HeroException {
058: if (bc == null) {
059: bc = new BonitaConfig();
060: }
061: return bc;
062: }
063:
064: public void setJms(boolean jms) throws HeroException {
065: try {
066: server.invoke(config, "updateJms",
067: new Object[] { new Boolean(jms) },
068: new String[] { "boolean" });
069: } catch (Exception e) {
070: throw new HeroException(e.getMessage());
071: }
072: }
073:
074: public void setHistoric(String value) throws HeroException {
075: try {
076: server.invoke(config, "updateHistoric",
077: new Object[] { value }, new String[] { ""
078: .getClass().getName() });
079: } catch (Exception e) {
080: throw new HeroException(e.getMessage());
081: }
082: }
083:
084: public void setLogLevel(String value) throws HeroException {
085: try {
086: server.invoke(config, "updateLogLevel",
087: new Object[] { value }, new String[] { ""
088: .getClass().getName() });
089: } catch (Exception e) {
090: throw new HeroException(e.getMessage());
091: }
092: }
093:
094: public void setTraceLevel(String value) throws HeroException {
095: try {
096: server.invoke(config, "updateTraceLevel",
097: new Object[] { value }, new String[] { ""
098: .getClass().getName() });
099: } catch (Exception e) {
100: throw new HeroException(e.getMessage());
101: }
102: }
103:
104: public void setProperty(String key, String value)
105: throws HeroException {
106: try {
107: server.invoke(config, "updateProperty", new Object[] { key,
108: value }, new String[] { "".getClass().getName(),
109: "".getClass().getName() });
110: } catch (Exception e) {
111: throw new HeroException(e.getMessage());
112: }
113: }
114:
115: public boolean getJms() throws HeroException {
116: try {
117: return (((Boolean) server.getAttribute(config, "Jms"))
118: .booleanValue());
119: } catch (Exception e) {
120: throw new HeroException(e.getMessage());
121: }
122: }
123:
124: public String getHistoric() throws HeroException {
125: try {
126: return ((String) server.getAttribute(config, "Historic"));
127: } catch (Exception e) {
128: throw new HeroException(e.getMessage());
129: }
130: }
131:
132: public String getLogLevel() throws HeroException {
133: try {
134: return ((String) server.getAttribute(config, "LogLevel"));
135: } catch (Exception e) {
136: throw new HeroException(e.getMessage());
137: }
138: }
139:
140: public String getTraceLevel() throws HeroException {
141: try {
142: return ((String) server.getAttribute(config, "TraceLevel"));
143: } catch (Exception e) {
144: throw new HeroException(e.getMessage());
145: }
146: }
147:
148: public String getProperty(String key) throws HeroException {
149: try {
150: return ((String) server.invoke(config, "getProperty",
151: new Object[] { key }, new String[] { "".getClass()
152: .getName() }));
153: } catch (Exception e) {
154: throw new HeroException(e.getMessage());
155: }
156: }
157: }
|