01: package org.apache.ojb.tools.mapping.reversedb2.actions;
02:
03: /* Copyright 2002-2005 The Apache Software Foundation
04: *
05: * Licensed under the Apache License, Version 2.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: import org.apache.ojb.broker.metadata.DescriptorRepository;
19:
20: /**
21: * Saves the given DescriptorRepository to a file selected by the use
22: * @author Administrator
23: */
24: public class ActionSaveOJBRepository extends javax.swing.AbstractAction {
25: DescriptorRepository aRepository;
26: java.io.File theFile;
27:
28: /** Creates a new instance of ActionSaveOJBRepository */
29: public ActionSaveOJBRepository(DescriptorRepository paRepository,
30: java.io.File fileSaveTo) {
31: super ("Save");
32: putValue(MNEMONIC_KEY,
33: new Integer(java.awt.event.KeyEvent.VK_S));
34: aRepository = paRepository;
35: theFile = fileSaveTo;
36: }
37:
38: public void actionPerformed(java.awt.event.ActionEvent evt) {
39: String xmlString = aRepository.toXML();
40: try {
41: if (!theFile.exists())
42: theFile.createNewFile();
43: java.io.PrintWriter pw = new java.io.PrintWriter(
44: new java.io.FileOutputStream(theFile));
45: pw.println(xmlString);
46: pw.close();
47: }
48: // catches java.io.IOException and java.io.FileNotFoundException
49: catch (Throwable t) {
50: javax.swing.JOptionPane.showMessageDialog(
51: (java.awt.Component) evt.getSource(), t
52: .getMessage(), "Save repository.xml",
53: javax.swing.JOptionPane.ERROR_MESSAGE);
54: }
55: }
56: }
|