KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > kelp > forte > XMLCSettings


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  *
19  * Contributor(s):
20  * Lisa Reese
21  *
22  */

23
24 package org.enhydra.kelp.forte;
25
26 import org.enhydra.kelp.common.node.PropertyKeys;
27 import org.enhydra.kelp.common.PropUtil;
28
29 import org.enhydra.kelp.forte.node.ForteProject;
30
31 import org.openide.options.SystemOption;
32 import org.openide.util.HelpCtx;
33 import org.openide.util.NbBundle;
34
35 import java.io.*;
36 import java.util.Hashtable JavaDoc;
37
38 /** Options for something or other.
39  *
40  * @author rees0234
41  */

42 public class XMLCSettings extends SystemOption implements PropertyKeys
43 {
44     static final long serialVersionUID = -1412625156769505620L;
45     
46     protected Hashtable JavaDoc nodeProps = null;
47         
48    public void writeExternal (ObjectOutput out) throws IOException {
49         out.writeObject(propertyValue(XMLC_DOC_TYPES));
50         out.writeObject(propertyValue(XMLC_BUILD));
51         out.writeObject(propertyValue(XMLC_PRINT_DOM));
52         out.writeObject(propertyValue(XMLC_PRINT_PARSE));
53         out.writeObject(propertyValue(XMLC_PRINT_DOC));
54         out.writeObject(propertyValue(XMLC_VERBOSE));
55         out.writeObject(propertyValue(XMLC_PRINT_ACCESSOR));
56         out.writeObject(propertyValue(XMLC_OUTPUT_FILENAME));
57         out.writeObject(propertyValue(XMLC_MAP_PACKAGE_FROM));
58         out.writeObject(propertyValue(XMLC_MAP_PACKAGE_TO));
59         out.writeObject(propertyValue(XMLC_MAP_PACKAGE_LENGTH));
60         out.writeObject(propertyValue(XMLC_MAP_SCOPE));
61         out.writeObject(propertyValue(NAME_XMLC_OPTION_FILEPATH));
62         out.writeObject(propertyValue(NAME_XMLC_PARAMETERS));
63         out.writeObject(propertyValue(PROP_PROJECT_ROOT));
64         out.writeObject(propertyValue(PROP_SRC_DIR));
65         out.writeObject(nodeProps);
66     }
67
68    public void readExternal (ObjectInput in) throws IOException, ClassNotFoundException JavaDoc {
69         setProperty(XMLC_DOC_TYPES, (String JavaDoc)in.readObject());
70         setProperty(XMLC_BUILD, (String JavaDoc)in.readObject());
71         setProperty(XMLC_PRINT_DOM, (String JavaDoc)in.readObject());
72         setProperty(XMLC_PRINT_PARSE, (String JavaDoc)in.readObject());
73         setProperty(XMLC_PRINT_DOC, (String JavaDoc)in.readObject());
74         setProperty(XMLC_VERBOSE, (String JavaDoc)in.readObject());
75         setProperty(XMLC_PRINT_ACCESSOR, (String JavaDoc)in.readObject());
76         setProperty(XMLC_OUTPUT_FILENAME, (String JavaDoc)in.readObject());
77         setProperty(XMLC_MAP_PACKAGE_FROM, (String JavaDoc)in.readObject());
78         setProperty(XMLC_MAP_PACKAGE_TO, (String JavaDoc)in.readObject());
79         setProperty(XMLC_MAP_PACKAGE_LENGTH, (String JavaDoc)in.readObject());
80         setProperty(XMLC_MAP_SCOPE, (String JavaDoc)in.readObject());
81         setProperty(NAME_XMLC_OPTION_FILEPATH, (String JavaDoc)in.readObject());
82         setProperty(NAME_XMLC_PARAMETERS, (String JavaDoc)in.readObject());
83         setProperty(PROP_PROJECT_ROOT, (String JavaDoc)in.readObject());
84         setProperty(PROP_SRC_DIR, (String JavaDoc)in.readObject());
85  
86         try {
87             nodeProps = (Hashtable JavaDoc)in.readObject();
88         } catch (OptionalDataException e) {
89             if (nodeProps == null)
90                 nodeProps = new Hashtable JavaDoc();
91         }
92    }
93
94
95     public String JavaDoc displayName () {
96         return NbBundle.getMessage (XMLCSettings.class, "LBL_xmlc_settings");
97     }
98
99     public HelpCtx getHelpCtx () {
100         return HelpCtx.DEFAULT_HELP;
101         // If you provide context help then use:
102
// return new HelpCtx (XMLCSettings.class);
103
}
104
105     /** Default instance of this system option, for the convenience of associated classes. */
106     public static XMLCSettings getDefault ()
107     {
108         return (XMLCSettings) findObject (XMLCSettings.class, true);
109     }
110
111     public void setProperty(String JavaDoc key, String JavaDoc value)
112     {
113         putProperty(key, value, true);
114     }
115
116     public String JavaDoc propertyValue(String JavaDoc key)
117     {
118         return (String JavaDoc)getProperty(key);
119     }
120
121     public void setNodeProperty(String JavaDoc key, String JavaDoc prop)
122     {
123         if (nodeProps == null)
124             nodeProps = new Hashtable JavaDoc();
125
126         if (prop != null)
127             try {
128                 nodeProps.put(key, prop);
129             }catch (NullPointerException JavaDoc e) {
130                 System.err.println(e);
131             }
132         else
133             nodeProps.remove(key);
134     }
135
136     public String JavaDoc getNodeProperty(String JavaDoc key)
137     {
138         if (nodeProps != null)
139         {
140             String JavaDoc res = (String JavaDoc)nodeProps.get(key);
141             return res;
142         }
143
144         return null;
145     }
146     
147     public boolean isGlobal(){
148         return false;
149     }
150 //this is going to be absolute
151
public String JavaDoc getRoot()
152     {
153         ForteProject proj = new ForteProject();
154         String JavaDoc cur = propertyValue(PROP_PROJECT_ROOT);
155         if ((cur == null) || (cur.length() <= 0))
156         {
157             cur = proj.getDefaultRoot();
158             if (cur != null)
159                 setRoot(cur);
160         }
161         if (! proj.inProject(cur))
162         {
163             cur = proj.getDefaultRoot();
164             if (cur != null)
165                 setRoot(cur);
166         }
167             
168         return cur;
169     }
170     
171     public void setRoot(String JavaDoc root)
172     {
173         setProperty(PROP_PROJECT_ROOT, root);
174     }
175 //this is relative to root
176
public String JavaDoc getSource()
177     {
178         String JavaDoc res = propertyValue(PROP_SRC_DIR);
179         if ((res == null) || (res.length() <= 0))
180         {
181             res = "src";
182             setSource(res);
183         }
184         return res;
185     }
186     
187     public void setSource(String JavaDoc src)
188     {
189         setProperty(PROP_SRC_DIR, src);
190     }
191     
192 /* public boolean isBuild () {
193
194        return readBooleanProperty(XMLC_BUILD);
195
196     }
197
198     public void setBuild (boolean build) {
199         writeBooleanProperty(XMLC_BUILD, build);
200     }
201     
202        public void writeBooleanProperty(String property, boolean b) {
203         String flag = b ? Boolean.TRUE.toString() : Boolean.FALSE.toString();
204         setProperty(property, flag);
205     } */

206
207 }
208
Popular Tags