KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > refactoring > java > RefactoringModule


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.refactoring.java;
20
21 import java.io.IOException JavaDoc;
22 import org.netbeans.api.java.source.ClasspathInfo;
23 import org.openide.ErrorManager;
24 import org.openide.filesystems.FileObject;
25 import org.openide.filesystems.FileSystem;
26 import org.openide.filesystems.Repository;
27 import org.openide.modules.ModuleInstall;
28
29 /**
30  * Module installation class for Refactoring module.
31  *
32  * @author Jan Becicka
33  * @author Pavel Flaska
34  */

35 public class RefactoringModule extends ModuleInstall {
36
37     /** Holds the file objects whose attributes represents options */
38     private static FileObject optionsFile = null;
39
40     /**
41      * Gets the attribute of options fileobject. Attribute name is represented
42      * by key parameter. If attribute value is not found, defaultValue parameter
43      * is used in method return.
44      *
45      * @param key key whose associated value is to be returned.
46      * @param defaultValue value used when attribute is not found
47      *
48      * @return attribute value or defaultValue if attribute is not found
49      */

50     public static Object JavaDoc getOption(String JavaDoc key, Object JavaDoc defaultValue) {
51         if (optionsFile == null) {
52             findOptionsFile();
53         }
54         if (optionsFile == null)
55             return defaultValue;
56         Object JavaDoc o = optionsFile.getAttribute(key);
57         return o != null ? o : defaultValue;
58     }
59
60     /**
61      * Sets the attribute to options fileobject. This attribute is persitent
62      * and allows to re-read it when IDE is restarted. Key and value pair
63      * is used in the same way as Map works.
64      *
65      * @param key key with which the specified value is to be associated.
66      * @param value value to be associated with the specified key.
67      */

68     public static void setOption(String JavaDoc key, Object JavaDoc value) {
69         if (optionsFile == null) {
70             findOptionsFile();
71         }
72         try {
73             optionsFile.setAttribute(key, value);
74         } catch (IOException JavaDoc e) {
75             ErrorManager.getDefault().notify(e);
76         }
77     }
78     
79     private static void findOptionsFile() {
80         FileSystem fs = Repository.getDefault().getDefaultFileSystem();
81         optionsFile = fs.findResource("Services/org-netbeans-modules-refactoring/options"); // NOI18N
82
}
83 }
84
Popular Tags