KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > tools > mapping > reversedb2 > actions > ActionSaveOJBRepository


1 package org.apache.ojb.tools.mapping.reversedb2.actions;
2
3 /* Copyright 2002-2005 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * 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 JavaDoc
25 {
26     DescriptorRepository aRepository;
27     java.io.File JavaDoc theFile;
28     /** Creates a new instance of ActionSaveOJBRepository */
29     public ActionSaveOJBRepository(DescriptorRepository paRepository, java.io.File JavaDoc fileSaveTo)
30     {
31         super("Save");
32         putValue(MNEMONIC_KEY, new Integer JavaDoc(java.awt.event.KeyEvent.VK_S));
33         aRepository = paRepository;
34         theFile = fileSaveTo;
35     }
36     
37     public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
38     {
39         String JavaDoc xmlString = aRepository.toXML();
40         try
41         {
42             if (!theFile.exists()) theFile.createNewFile();
43             java.io.PrintWriter JavaDoc pw = new java.io.PrintWriter JavaDoc(new java.io.FileOutputStream JavaDoc( theFile ));
44             pw.println(xmlString);
45             pw.close();
46         }
47         // catches java.io.IOException and java.io.FileNotFoundException
48
catch (Throwable JavaDoc t)
49         {
50             javax.swing.JOptionPane.showMessageDialog((java.awt.Component JavaDoc)evt.getSource(), t.getMessage(), "Save repository.xml", javax.swing.JOptionPane.ERROR_MESSAGE);
51         }
52     }
53 }
54
Popular Tags