KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > db > explorer > infos > DatabaseNodeInfo


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
20 package org.netbeans.modules.db.explorer.infos;
21
22 import java.beans.PropertyChangeListener JavaDoc;
23 import java.beans.PropertyChangeSupport JavaDoc;
24 import java.lang.ref.WeakReference JavaDoc;
25 import java.io.InputStream JavaDoc;
26 import java.io.IOException JavaDoc;
27 import java.sql.Connection JavaDoc;
28 import java.text.MessageFormat JavaDoc;
29 import java.util.*;
30
31 import org.openide.nodes.Node;
32 import org.openide.util.NbBundle;
33 import org.openide.util.actions.SystemAction;
34
35 import org.netbeans.lib.ddl.DatabaseSpecification;
36 import org.netbeans.lib.ddl.DatabaseSpecificationFactory;
37 import org.netbeans.lib.ddl.DBConnection;
38 import org.netbeans.lib.ddl.impl.DriverSpecification;
39 import org.netbeans.lib.ddl.util.PListReader;
40 import org.netbeans.api.db.explorer.DatabaseException;
41 import org.netbeans.modules.db.explorer.ConnectionList;
42 import org.netbeans.modules.db.explorer.DatabaseConnection;
43 import org.netbeans.modules.db.explorer.DatabaseDriver;
44 import org.netbeans.modules.db.explorer.DatabaseNodeChildren;
45 import org.netbeans.modules.db.explorer.DbMetaDataListenerSupport;
46 import org.netbeans.modules.db.explorer.actions.DatabaseAction;
47 import org.netbeans.modules.db.explorer.nodes.DatabaseNode;
48 import org.netbeans.modules.db.explorer.nodes.RootNode;
49 import org.openide.nodes.Children;
50
51 public class DatabaseNodeInfo extends Hashtable implements Node.Cookie {
52     public static final String JavaDoc SPECIFICATION_FACTORY = "specfactory"; //NOI18N
53
public static final String JavaDoc SPECIFICATION = "spec"; //NOI18N
54
public static final String JavaDoc DRIVER_SPECIFICATION = "drvspec"; //NOI18N
55
public static final String JavaDoc DBPRODUCT = "dbproduct"; //NOI18N
56
public static final String JavaDoc DBVERSION = "dbversion"; //NOI18N
57
public static final String JavaDoc SUPPORTED_DBS = "suppdbs"; //NOI18N
58
public static final String JavaDoc DRIVER = "driver"; //NOI18N
59
public static final String JavaDoc DBDRIVER = "dbdriver"; //NOI18N
60
public static final String JavaDoc DATABASE = "db"; //NOI18N
61
public static final String JavaDoc URL = "url"; //NOI18N
62
public static final String JavaDoc PREFIX = "prefix"; //NOI18N
63
public static final String JavaDoc CONNECTION = "connection"; //NOI18N
64
public static final String JavaDoc CODE = "code"; //NOI18N
65
public static final String JavaDoc NODE = "node"; //NOI18N
66
public static final String JavaDoc CLASS = "class"; //NOI18N
67
public static final String JavaDoc INFOCLASS = "infoclass"; //NOI18N
68
public static final String JavaDoc NAME = "name"; //NOI18N
69
public static final String JavaDoc USER = "user"; //NOI18N
70
public static final String JavaDoc SCHEMA = "schema"; //NOI18N
71
public static final String JavaDoc PASSWORD = "password"; //NOI18N
72
public static final String JavaDoc CHILDREN = "children"; //NOI18N
73
public static final String JavaDoc ACTIONS = "actions"; //NOI18N
74
public static final String JavaDoc ICONBASE = "iconbase"; //NOI18N
75
public static final String JavaDoc PROPERTIES = "properties"; //NOI18N
76
public static final String JavaDoc RESULTSET = "resultset"; //NOI18N
77
public static final String JavaDoc REMEMBER_PWD = "rememberpwd"; //NOI18N
78
public static final String JavaDoc WRITABLE = "writable"; //NOI18N
79
public static final String JavaDoc DELETABLE = "deletable"; //NOI18N
80
public static final String JavaDoc DESCRIPTION = "description"; //NOI18N
81
public static final String JavaDoc READONLYDB = "readonlydatabase"; //NOI18N
82
public static final String JavaDoc GROUPSUP = "groupbysupport"; //NOI18N
83
public static final String JavaDoc OJOINSUP = "outerjoinsupport"; //NOI18N
84
public static final String JavaDoc UNIONSUP = "unionsupport"; //NOI18N
85
public static final String JavaDoc SYSTEM_ACTION = "system"; //NOI18N
86
public static final String JavaDoc CHILDREN_ORDERING = "children_ordering"; //NOI18N
87
public static final String JavaDoc READONLY = "readOnly"; //NOI18N
88
public static final String JavaDoc PERM = "perm"; //NOI18N
89
public static final String JavaDoc ADAPTOR = "adaptor"; //NOI18N
90
public static final String JavaDoc ADAPTOR_CLASSNAME = "adaptorClass"; //NOI18N
91

92     private static Map gtab = null;
93     static final String JavaDoc gtabfile = "org/netbeans/modules/db/resources/explorer.plist"; //NOI18N
94

95     private boolean connected = false;
96
97     transient boolean passwordWasSet = false;
98     
99     protected static ResourceBundle bundle() {
100         return NbBundle.getBundle("org.netbeans.modules.db.resources.Bundle");
101     }
102
103     public static Map getGlobalNodeInfo() {
104         if (gtab == null)
105             gtab = readInfo();
106         
107         return gtab;
108     }
109     
110     public static Map readInfo() {
111         Map data;
112         try {
113             ClassLoader JavaDoc cl = DatabaseNodeInfo.class.getClassLoader();
114             InputStream JavaDoc stream = cl.getResourceAsStream(gtabfile);
115             if (stream == null) {
116                 String JavaDoc message = MessageFormat.format(bundle().getString("EXC_UnableToOpenStream"), new String JavaDoc[] {gtabfile}); // NOI18N
117
throw new Exception JavaDoc(message);
118             }
119             PListReader reader = new PListReader(stream);
120             data = reader.getData();
121             stream.close();
122         } catch (Exception JavaDoc e) {
123             e.printStackTrace();
124             data = null;
125         }
126         
127         return data;
128     }
129
130     public static Object JavaDoc getGlobalNodeInfo(String JavaDoc key) {
131         return getGlobalNodeInfo().get(key);
132     }
133
134     public static DatabaseNodeInfo createNodeInfo(DatabaseNodeInfo parent, String JavaDoc nodecode) throws DatabaseException {
135         DatabaseNodeInfo e_ni = null;
136         try {
137             String JavaDoc nodec = (String JavaDoc)((Map)DatabaseNodeInfo.getGlobalNodeInfo().get(nodecode)).get(INFOCLASS);
138             if (nodec != null)
139                 e_ni = (DatabaseNodeInfo)Class.forName(nodec).newInstance();
140             else {
141                 String JavaDoc message = MessageFormat.format(bundle().getString("EXC_UnableToFindClassInfo"), new String JavaDoc[] {nodecode}); // NOI18N
142
throw new Exception JavaDoc(message);
143             }
144         } catch (Exception JavaDoc exc) {
145             throw new DatabaseException(exc.getMessage());
146         }
147
148         if (e_ni != null)
149             e_ni.setParentInfo(parent, nodecode);
150         else {
151             String JavaDoc message = MessageFormat.format(bundle().getString("EXC_UnableToCreateNodeInfo"), new String JavaDoc[] {nodecode}); // NOI18N
152
throw new DatabaseException(message);
153         }
154         return e_ni;
155     }
156     
157     public static DatabaseNodeInfo createNodeInfo(DatabaseNodeInfo parent, String JavaDoc nodecode, HashMap rset) throws DatabaseException {
158         int colidx = 1;
159         String JavaDoc key = null;
160         DatabaseNodeInfo nfo = createNodeInfo(parent, nodecode);
161         Vector rsnames = (Vector)nfo.get(DatabaseNodeInfo.RESULTSET);
162         Iterator rsnames_i = rsnames.iterator();
163         Hashtable data = new Hashtable();
164         while (rsnames_i.hasNext()) {
165             key = (String JavaDoc)rsnames_i.next();
166             if (!key.equals("unused")) { //NOI18N
167
Object JavaDoc value = rset.get(new Integer JavaDoc(colidx));
168                 if (value != null) data.put(key, value);
169             }
170             colidx++;
171         }
172
173         nfo.putAll(data);
174         nfo.put(nodecode, nfo.getName());
175         if (parent != null && parent.isReadOnly()) nfo.setReadOnly(true);
176         return nfo;
177     }
178
179     /* Parent of info in node hierarchy */
180     private DatabaseNodeInfo parent = null;
181
182     /* Owning node */
183     WeakReference JavaDoc nodewr = null;
184     private PropertyChangeSupport JavaDoc pcs = null;
185     private Set connectionpcsKeys = null;
186
187     private PropertyChangeSupport JavaDoc driverpcs = null;
188     private Set driverpcsKeys = null;
189
190     static final long serialVersionUID =1176243907461868244L;
191     public DatabaseNodeInfo()
192     {
193         super();
194     }
195
196     public DatabaseNodeInfo(DatabaseNodeInfo parent, String JavaDoc sname)
197     throws DatabaseException
198     {
199         DatabaseNodeInfo nfo = new DatabaseNodeInfo();
200         nfo.setParentInfo(parent, sname);
201     }
202
203     public void setParentInfo(DatabaseNodeInfo parent, String JavaDoc sname)
204     throws DatabaseException
205     {
206         if (parent != null) {
207             putAll(parent);
208             this.parent = parent;
209         }
210         Map ltab = (Map)getGlobalNodeInfo(sname);
211         if (ltab != null)
212             putAll(ltab);
213         else {
214             String JavaDoc message = MessageFormat.format(bundle().getString("EXC_UnableToReadInfo"), new String JavaDoc[] {sname}); // NOI18N
215
throw new DatabaseException(message);
216         }
217         put(CODE, sname);
218         if (parent != null && parent.isReadOnly()) setReadOnly(true);
219     }
220
221     public DatabaseNodeInfo getParent()
222     {
223         return parent;
224     }
225
226     /** Returns parent of nodeinfo defined by <code>parent</code> variable.
227     * If no info was found, it returns null.
228     */

229     public DatabaseNodeInfo getParent(String JavaDoc code)
230     {
231         DatabaseNodeInfo iinfo = this;
232         if (code != null) {
233             while (iinfo != null) {
234                 String JavaDoc iicode = iinfo.getCode();
235                 if (iicode.equals(code)) return iinfo;
236                 else iinfo = iinfo.getParent();
237             }
238         }
239
240         return iinfo;
241     }
242
243     public boolean canAdd(Map propmap, String JavaDoc propname)
244     {
245         return true;
246     }
247
248     public boolean canWrite(Map propmap, String JavaDoc propname, boolean defa)
249     {
250         if (isReadOnly()) return false;
251         String JavaDoc wflag = (String JavaDoc)propmap.get(DatabaseNodeInfo.WRITABLE);
252         if (wflag != null) return wflag.toUpperCase().equals("YES"); //NOI18N
253
return defa;
254     }
255
256     public DatabaseNode getNode()
257     {
258         if (nodewr != null) return (DatabaseNode)nodewr.get();
259         return null;
260     }
261
262     public void setNode(DatabaseNode node)
263     {
264         nodewr = new WeakReference JavaDoc(node);
265     }
266
267     private PropertyChangeSupport JavaDoc getConnectionPCS()
268     {
269         if (pcs == null)
270             pcs = new PropertyChangeSupport JavaDoc(this);
271
272         return pcs;
273     }
274
275     /** Returns PropertyChangeSupport used for driver change monitoring */
276     private PropertyChangeSupport JavaDoc getDriverPCS()
277     {
278         if (driverpcs == null)
279             driverpcs = new PropertyChangeSupport JavaDoc(this);
280
281         return driverpcs;
282     }
283
284     /** Returns PropertyChangeSupport used for driver change monitoring */
285     private Set getDriverPCSKeys()
286     {
287         if (driverpcsKeys == null) {
288             driverpcsKeys = new HashSet();
289             driverpcsKeys.add(NAME);
290             driverpcsKeys.add(URL);
291             driverpcsKeys.add(PREFIX);
292             driverpcsKeys.add(ADAPTOR_CLASSNAME);
293         }
294
295         return driverpcsKeys;
296     }
297
298     /** Returns PropertyChangeSupport used for connection change monitoring */
299     private Set getConnectionPCSKeys()
300     {
301         if (connectionpcsKeys == null) {
302             connectionpcsKeys = new HashSet();
303             connectionpcsKeys.add(SCHEMA);
304             connectionpcsKeys.add(USER);
305             connectionpcsKeys.add(DATABASE);
306
307         }
308
309         return connectionpcsKeys;
310     }
311
312     public Object JavaDoc put(Object JavaDoc key, Object JavaDoc obj)
313     {
314         Object JavaDoc old = get(key);
315         
316         if (key == null)
317             throw new NullPointerException JavaDoc();
318
319         if (obj != null)
320             super.put(key, obj);
321         else
322             remove(key);
323
324         // TEMP HACK FOR JDBC
325
if(key.equals(DatabaseNodeInfo.PASSWORD))
326             passwordWasSet = true;
327
328         if (getDriverPCSKeys().contains(key)){
329             getDriverPCS().firePropertyChange((String JavaDoc)key, old, obj);
330         }
331         if (getConnectionPCSKeys().contains(key))
332             getConnectionPCS().firePropertyChange((String JavaDoc)key, null, obj);
333
334         return old;
335     }
336
337     public void delete() throws IOException JavaDoc
338     {
339     }
340
341     public void refreshChildren() throws DatabaseException {
342         // create list (infos)
343
Vector charr = new Vector();
344         put(DatabaseNodeInfo.CHILDREN, charr);
345         initChildren(charr);
346         
347         // create sub-tree (by infos)
348
try {
349             final Node[] subTreeNodes = new Node[charr.size()];
350             
351             // current sub-tree
352
final DatabaseNodeChildren children = (DatabaseNodeChildren) getNode().getChildren();
353             
354             // build refreshed sub-tree
355
for(int i = 0; i < charr.size(); i++)
356                 subTreeNodes[i] = children.createNode((DatabaseNodeInfo) charr.elementAt(i));
357
358             Children.MUTEX.postWriteRequest(new Runnable JavaDoc() {
359                 public void run() {
360                     // remove current sub-tree
361
children.remove(children.getNodes());
362
363                     // add built sub-tree
364
children.add(subTreeNodes);
365                 }
366             });
367             
368             fireRefresh();
369         } catch (ClassCastException JavaDoc ex) {
370             //PENDING
371
} catch (Exception JavaDoc ex) {
372             org.openide.ErrorManager.getDefault().notify(org.openide.ErrorManager.INFORMATIONAL, ex);
373         }
374     }
375
376     protected void fireRefresh() {
377         boolean allTables = true;
378
379         if (!(this instanceof TableListNodeInfo)) {
380             allTables = false;
381             if (!(this instanceof TableNodeInfo)) {
382                 return;
383             }
384         }
385
386         ConnectionNodeInfo cnnfo = (ConnectionNodeInfo)getParent(DatabaseNode.CONNECTION);
387         if (cnnfo == null) {
388             return;
389         }
390
391         DatabaseConnection dbconn = ConnectionList.getDefault().getConnection(cnnfo.getDatabaseConnection());
392         if (dbconn != null) {
393             if (allTables) {
394                 DbMetaDataListenerSupport.fireTablesChanged(dbconn.getDatabaseConnection());
395             } else {
396                 String JavaDoc tableName = (String JavaDoc)get(DatabaseNode.TABLE);
397                 DbMetaDataListenerSupport.fireTableChanged(dbconn.getDatabaseConnection(), tableName);
398             }
399         }
400     }
401
402     /** Called by property editor */
403     public Object JavaDoc getProperty(String JavaDoc key)
404     {
405         return get(key);
406     }
407
408     /** Called by property editor */
409     public void setProperty(String JavaDoc key, Object JavaDoc obj)
410     {
411         put(key, obj);
412     }
413
414     /** Add property change listener */
415     public void addConnectionListener(PropertyChangeListener JavaDoc l)
416     {
417         getConnectionPCS().addPropertyChangeListener(l);
418     }
419
420     /** Remove property change listener */
421     public void removeConnectionListener(PropertyChangeListener JavaDoc l)
422     {
423         pcs.removePropertyChangeListener(l);
424     }
425
426     public void addDriverListener(PropertyChangeListener JavaDoc l)
427     {
428         getDriverPCS().addPropertyChangeListener(l);
429     }
430
431     public void removeDriverListener(PropertyChangeListener JavaDoc l)
432     {
433         getDriverPCS().removePropertyChangeListener(l);
434     }
435
436     public DatabaseSpecificationFactory getSpecificationFactory()
437     {
438         return (DatabaseSpecificationFactory)get(SPECIFICATION_FACTORY);
439     }
440
441     public void setSpecificationFactory(DatabaseSpecificationFactory fac)
442     {
443         put(SPECIFICATION_FACTORY, fac);
444         put(SUPPORTED_DBS, fac.supportedDatabases());
445     }
446
447     protected String JavaDoc getDatabaseAdaptorClassName() {
448         return "org.netbeans.lib.ddl.adaptors.DefaultAdaptor"; //NOI18N
449
}
450
451     public DatabaseSpecification getSpecification()
452     {
453         DatabaseSpecification spec = (DatabaseSpecification)get(SPECIFICATION);
454         if (spec == null) return spec;
455         String JavaDoc adaname = getDatabaseAdaptorClassName();
456         if (!spec.getMetaDataAdaptorClassName().equals(adaname)) {
457             spec.setMetaDataAdaptorClassName(adaname);
458         }
459
460         return spec;
461     }
462
463     public void setSpecification(DatabaseSpecification spec)
464     {
465         put(SPECIFICATION, spec);
466     }
467
468     public String JavaDoc getDriver()
469     {
470         return (String JavaDoc)get(DRIVER);
471     }
472
473     public void setDriver(String JavaDoc drv)
474     {
475         put(DRIVER, drv);
476     }
477
478     public Connection JavaDoc getConnection()
479     {
480         return (Connection JavaDoc)get(CONNECTION);
481     }
482
483     public void setConnection(Connection JavaDoc con) throws DatabaseException
484     {
485         Connection JavaDoc oldval = getConnection();
486         if (con != null) {
487             if (oldval != null && oldval.equals(con)) return;
488             put(CONNECTION, con);
489             setConnected(true);
490         } else {
491             remove(CONNECTION);
492             setConnected(false);
493         }
494
495         // Check if node is readonly or not.
496

497         if (con != null && isReadOnly()) {
498             Enumeration enu = getChildren().elements();
499             while(enu.hasMoreElements()) {
500                 DatabaseNodeInfo ninfo = (DatabaseNodeInfo)enu.nextElement();
501                 ninfo.setReadOnly(true);
502             }
503         }
504
505         getConnectionPCS().firePropertyChange(CONNECTION, oldval, con);
506
507     }
508
509     public void setConnected(boolean connected) {
510         this.connected = connected;
511     }
512     
513     public boolean isConnected() {
514         return connected;
515     }
516
517     public DatabaseConnection getDatabaseConnection()
518     {
519         DatabaseConnection con = new DatabaseConnection(getDriver(), getDatabase(), getUser(), getPassword());
520         if(get(REMEMBER_PWD)!=null)
521             con.setRememberPassword(((Boolean JavaDoc)get(REMEMBER_PWD)).booleanValue());
522         else
523             con.setRememberPassword(Boolean.FALSE.booleanValue());
524         con.setSchema(getSchema());
525         con.setDriverName((String JavaDoc)get("drivername"));
526         return con;
527     }
528
529     public DatabaseDriver getDatabaseDriver()
530     {
531         return (DatabaseDriver)get(DBDRIVER);
532     }
533
534     public void setDatabaseConnection(DBConnection cinfo)
535     {
536         String JavaDoc pwd = cinfo.getPassword();
537         put(DRIVER, cinfo.getDriver());
538         put(DATABASE, cinfo.getDatabase());
539         put(USER, cinfo.getUser());
540         put(SCHEMA, cinfo.getSchema());
541         if (pwd != null)
542             put(PASSWORD, pwd);
543         put(REMEMBER_PWD, (cinfo.rememberPassword() ? Boolean.TRUE : Boolean.FALSE));
544         put("drivername", cinfo.getDriverName());
545     }
546
547     public String JavaDoc getCode()
548     {
549         return (String JavaDoc)get(CODE);
550     }
551
552     public void setCode(String JavaDoc nam)
553     {
554         put(CODE, nam);
555     }
556
557     public String JavaDoc getName()
558     {
559         return (String JavaDoc)get(NAME);
560     }
561
562     public void setName(String JavaDoc nam)
563     {
564         put(NAME, nam);
565     }
566
567     public String JavaDoc getUser()
568     {
569         return (String JavaDoc)get(USER);
570     }
571
572     public void setUser(String JavaDoc usr)
573     {
574         put(USER, usr);
575     }
576     
577     public String JavaDoc getSchema() {
578         return (String JavaDoc) get(SCHEMA);
579     }
580
581     public void setSchema(String JavaDoc schema) {
582         put(SCHEMA, schema);
583     }
584
585     public String JavaDoc getDatabase()
586     {
587         return (String JavaDoc)get(DATABASE);
588     }
589
590     public void setDatabase(String JavaDoc db)
591     {
592         put(DATABASE, db);
593     }
594
595     public String JavaDoc getPassword()
596     {
597         return (String JavaDoc)get(PASSWORD);
598     }
599
600     public void setPassword(String JavaDoc pwd)
601     {
602         put(PASSWORD, pwd);
603     }
604
605     public String JavaDoc getTable()
606     {
607         return (String JavaDoc)get("table"); //NOI18N
608
}
609
610     public String JavaDoc getView()
611     {
612         return (String JavaDoc)get("view"); //NOI18N
613
}
614
615     public void setTable(String JavaDoc nam)
616     {
617         put("table", nam); //NOI18N
618
}
619
620     public String JavaDoc getIconBase() {
621         return (String JavaDoc) get("iconbase"); //NOI18N
622
}
623
624     public void setIconBase(String JavaDoc base) {
625         put("iconbase", base); //NOI18N
626
}
627
628     public String JavaDoc getDisplayname()
629     {
630         return (String JavaDoc)get("displayname"); //NOI18N
631
}
632
633     public void setDisplayname(String JavaDoc name)
634     {
635         put("displayname", name); //NOI18N
636
}
637
638     public String JavaDoc getURL()
639     {
640         return (String JavaDoc)get(URL);
641     }
642
643     public void setURL(String JavaDoc url)
644     {
645         put(URL, url);
646     }
647
648     /** Returns connection properties (login name and password)
649     * Returns null if name or password isn't specified yet.
650     */

651     public Properties getConnectionProperties()
652     {
653         Properties props = new Properties();
654         try {
655             props.put("user", getUser()); //NOI18N
656
props.put("password", getPassword()); //NOI18N
657
props.put("schema", getSchema()); //NOI18N
658
} catch (Exception JavaDoc e) { props = null; }
659
660         return props;
661     }
662
663     protected void initChildren(Vector children)
664     throws DatabaseException
665     {
666     }
667
668     public Vector getChildren()
669     throws DatabaseException
670     {
671         Vector children = (Vector)get(CHILDREN);
672         if (children.size() > 0 && children.elementAt(0) instanceof DatabaseNodeInfo) return children;
673
674         Vector chalt = new Vector();
675         initChildren(chalt);
676         chalt.addAll(children);
677
678         try {
679             for (int i=0; i<chalt.size();i++) {
680                 Object JavaDoc e_child = chalt.elementAt(i);
681                 if (e_child instanceof String JavaDoc) {
682                     DatabaseNodeInfo e_ni = createNodeInfo(this, (String JavaDoc)e_child);
683                     chalt.setElementAt(e_ni,i);
684                 }
685             }
686
687             children = chalt;
688             put(CHILDREN, children);
689
690         } catch (Exception JavaDoc exc) {
691             String JavaDoc message = MessageFormat.format(bundle().getString("EXC_UnableToCreateChildren"), new String JavaDoc[] {exc.getMessage()}); // NOI18N
692
throw new DatabaseException(message);
693         }
694
695         return children;
696     }
697
698     public void setChildren(Vector chvec)
699     {
700         put(CHILDREN, chvec);
701     }
702
703     public Vector getActions()
704     {
705         Vector actions = (Vector)get(ACTIONS);
706         actions = (Vector)actions.clone();
707         if (actions == null) {
708             actions = new Vector();
709             put(ACTIONS, actions);
710         }
711
712         if (actions.size() == 0) return actions;
713         boolean ro = isReadOnly();
714         for (int i=0; i<actions.size();i++) {
715
716             Object JavaDoc e_act = actions.elementAt(i);
717             SystemAction action = null;
718             if (e_act instanceof Map) {
719                 Map e_action = (Map)e_act;
720                 try {
721
722                     // Try permissions
723

724                     String JavaDoc perm = (String JavaDoc)e_action.get(PERM);
725                     if (ro && perm != null && perm instanceof String JavaDoc && perm.indexOf("write") != -1) { //NOI18N
726
actions.setElementAt(null, i);
727                         continue;
728                     }
729
730                     boolean systemact = false;
731                     String JavaDoc sysactstr = (String JavaDoc)e_action.get(SYSTEM_ACTION);
732                     if (sysactstr != null) systemact = sysactstr.toUpperCase().equals("YES"); //NOI18N
733
String JavaDoc actnode = (String JavaDoc)e_action.get(NODE);
734                     String JavaDoc actcn = (String JavaDoc)e_action.get(CLASS);
735
736                     if (!systemact) {
737                         String JavaDoc locname, xname = (String JavaDoc)e_action.get(NAME);
738                         try {
739                             locname = bundle().getString(xname);
740                         } catch (MissingResourceException e) {
741                             locname = xname;
742                             
743                             String JavaDoc message = MessageFormat.format(bundle().getString("ERR_UnableToLocateLocalizedMenuItem"), new String JavaDoc[] {xname}); // NOI18N
744
System.out.println(message);
745                         }
746
747                         //action = (SystemAction)Class.forName(actcn).newInstance();
748
//action = (SystemAction)SharedClassObject.findObject(Class.forName(actcn), true);
749
action = SystemAction.get(Class.forName(actcn));
750                         ((DatabaseAction)action).setName(locname);
751                         ((DatabaseAction)action).setNode(actnode);
752                     } else {
753                         ClassLoader JavaDoc l = (ClassLoader JavaDoc)org.openide.util.Lookup.getDefault().lookup(ClassLoader JavaDoc.class);
754                         if (l == null) {
755                             l = getClass().getClassLoader();
756                         }
757                         action = SystemAction.get(Class.forName(actcn, true, l));
758                     }
759
760                 } catch (Exception JavaDoc e) {
761                     e.printStackTrace();
762                 }
763             }
764
765             actions.setElementAt(action, i);
766         }
767
768         return actions;
769     }
770
771     public String JavaDoc toString()
772     {
773         String JavaDoc result = ""; //NOI18N
774
Enumeration keys = keys();
775         while (keys.hasMoreElements()) {
776             Object JavaDoc key = keys.nextElement();
777             result = result + key+": "+get(key)+ "\n"; //NOI18N
778
}
779
780         return result;
781     }
782
783     public boolean isDebugMode()
784     {
785         return RootNode.getOption().getDebugMode();
786     }
787
788     public void setDebugMode(boolean mode)
789     {
790         RootNode.getOption().setDebugMode(mode);
791     }
792
793     public boolean isReadOnly()
794     {
795         Boolean JavaDoc roobj = (Boolean JavaDoc)get(READONLY);
796         if (roobj != null) return roobj.booleanValue();
797         return false;
798     }
799
800     public void setReadOnly(boolean flag)
801     {
802         put(READONLY, flag ? Boolean.TRUE : Boolean.FALSE);
803     }
804
805     /** Getter for property driverSpecification.
806      *@return Value of property driverSpecification.
807      */

808     public DriverSpecification getDriverSpecification() {
809         return (DriverSpecification) get(DRIVER_SPECIFICATION);
810     }
811
812     /** Setter for property driverSpecification.
813      *@param driverSpecification New value of property driverSpecification.
814      */

815     public void setDriverSpecification(DriverSpecification driverSpecification) {
816         put(DRIVER_SPECIFICATION, driverSpecification);
817     }
818     
819     public boolean isPasswordSet() {
820         return passwordWasSet;
821     }
822
823 }
824
Popular Tags