01: /*
02: * JBoss, Home of Professional Open Source.
03: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
04: * as indicated by the @author tags. See the copyright.txt file in the
05: * distribution for a full listing of individual contributors.
06: *
07: * This is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU Lesser General Public License as
09: * published by the Free Software Foundation; either version 2.1 of
10: * the License, or (at your option) any later version.
11: *
12: * This software is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this software; if not, write to the Free
19: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21: */
22: package org.jboss.mx.persistence;
23:
24: import java.io.File;
25: import java.io.FileInputStream;
26: import java.io.FileOutputStream;
27: import java.io.IOException;
28: import java.io.ObjectInputStream;
29: import java.io.ObjectOutputStream;
30: import javax.management.MBeanInfo;
31: import java.io.FileNotFoundException;
32:
33: import org.jboss.logging.Logger;
34:
35: /**
36: * MBean Info Object Database. <p>
37: *
38: * @author Matt Munz
39: */
40: public class MBeanInfoOdb extends Object {
41: protected Logger fLogger;
42:
43: // Constructors --------------------------------------------------
44:
45: public MBeanInfoOdb() {
46: super ();
47: }
48:
49: // Protected -----------------------------------------------------
50:
51: protected void store(MBeanInfo metadata, File location)
52: throws IOException {
53: location.createNewFile();
54: FileOutputStream fos = new FileOutputStream(location);
55: ObjectOutputStream oos = new ObjectOutputStream(fos);
56: oos.writeObject(metadata);
57: }
58:
59: protected MBeanInfo load(File location) throws IOException,
60: FileNotFoundException, ClassNotFoundException {
61: logger().info(
62: "Loading mbean info from location: "
63: + location.getAbsolutePath());
64: FileInputStream fis = new FileInputStream(location);
65: ObjectInputStream ois = new ObjectInputStream(fis);
66: MBeanInfo obj = (MBeanInfo) ois.readObject();
67: ois.close();
68: return obj;
69: }
70:
71: protected Logger logger() {
72: if (fLogger == null) {
73: fLogger = Logger.getLogger("" + getClass().getName());
74: }
75: return fLogger;
76: }
77: }
|