001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.db.explorer.infos;
043:
044: import java.beans.PropertyChangeListener;
045: import java.beans.PropertyChangeSupport;
046: import java.lang.ref.WeakReference;
047: import java.io.InputStream;
048: import java.io.IOException;
049: import java.sql.Connection;
050: import java.text.MessageFormat;
051: import java.util.*;
052: import java.util.logging.Level;
053: import java.util.logging.Logger;
054:
055: import org.openide.nodes.Node;
056: import org.openide.util.NbBundle;
057: import org.openide.util.actions.SystemAction;
058:
059: import org.netbeans.lib.ddl.DatabaseSpecification;
060: import org.netbeans.lib.ddl.DatabaseSpecificationFactory;
061: import org.netbeans.lib.ddl.DBConnection;
062: import org.netbeans.lib.ddl.impl.DriverSpecification;
063: import org.netbeans.lib.ddl.util.PListReader;
064: import org.netbeans.api.db.explorer.DatabaseException;
065: import org.netbeans.modules.db.explorer.ConnectionList;
066: import org.netbeans.modules.db.explorer.DatabaseConnection;
067: import org.netbeans.modules.db.explorer.DatabaseDriver;
068: import org.netbeans.modules.db.explorer.DatabaseNodeChildren;
069: import org.netbeans.modules.db.explorer.DbMetaDataListenerSupport;
070: import org.netbeans.modules.db.explorer.actions.DatabaseAction;
071: import org.netbeans.modules.db.explorer.nodes.DatabaseNode;
072: import org.netbeans.modules.db.explorer.nodes.RootNode;
073: import org.openide.nodes.Children;
074: import org.openide.util.Exceptions;
075:
076: public class DatabaseNodeInfo extends Hashtable implements Node.Cookie {
077: public static final String SPECIFICATION_FACTORY = "specfactory"; //NOI18N
078: public static final String SPECIFICATION = "spec"; //NOI18N
079: public static final String DRIVER_SPECIFICATION = "drvspec"; //NOI18N
080: public static final String DBPRODUCT = "dbproduct"; //NOI18N
081: public static final String DBVERSION = "dbversion"; //NOI18N
082: public static final String SUPPORTED_DBS = "suppdbs"; //NOI18N
083: public static final String DRIVER = "driver"; //NOI18N
084: public static final String DBDRIVER = "dbdriver"; //NOI18N
085: public static final String DATABASE = "db"; //NOI18N
086: public static final String URL = "url"; //NOI18N
087: public static final String PREFIX = "prefix"; //NOI18N
088: public static final String CONNECTION = "connection"; //NOI18N
089: public static final String CODE = "code"; //NOI18N
090: public static final String NODE = "node"; //NOI18N
091: public static final String CLASS = "class"; //NOI18N
092: public static final String INFOCLASS = "infoclass"; //NOI18N
093: public static final String NAME = "name"; //NOI18N
094: public static final String USER = "user"; //NOI18N
095: public static final String SCHEMA = "schema"; //NOI18N
096: public static final String PASSWORD = "password"; //NOI18N
097: public static final String CHILDREN = "children"; //NOI18N
098: public static final String ACTIONS = "actions"; //NOI18N
099: public static final String ICONBASE = "iconbase"; //NOI18N
100: public static final String PROPERTIES = "properties"; //NOI18N
101: public static final String RESULTSET = "resultset"; //NOI18N
102: public static final String REMEMBER_PWD = "rememberpwd"; //NOI18N
103: public static final String WRITABLE = "writable"; //NOI18N
104: public static final String DELETABLE = "deletable"; //NOI18N
105: public static final String DESCRIPTION = "description"; //NOI18N
106: public static final String READONLYDB = "readonlydatabase"; //NOI18N
107: public static final String GROUPSUP = "groupbysupport"; //NOI18N
108: public static final String OJOINSUP = "outerjoinsupport"; //NOI18N
109: public static final String UNIONSUP = "unionsupport"; //NOI18N
110: public static final String SYSTEM_ACTION = "system"; //NOI18N
111: public static final String CHILDREN_ORDERING = "children_ordering"; //NOI18N
112: public static final String READONLY = "readOnly"; //NOI18N
113: public static final String PERM = "perm"; //NOI18N
114: public static final String ADAPTOR = "adaptor"; //NOI18N
115: public static final String ADAPTOR_CLASSNAME = "adaptorClass"; //NOI18N
116:
117: private static Map gtab = null;
118: static final String gtabfile = "org/netbeans/modules/db/resources/explorer.plist"; //NOI18N
119:
120: private boolean connected = false;
121:
122: protected static ResourceBundle bundle() {
123: return NbBundle
124: .getBundle("org.netbeans.modules.db.resources.Bundle");
125: }
126:
127: public static Map getGlobalNodeInfo() {
128: if (gtab == null)
129: gtab = readInfo();
130:
131: return gtab;
132: }
133:
134: public static Map readInfo() {
135: Map data;
136: try {
137: ClassLoader cl = DatabaseNodeInfo.class.getClassLoader();
138: InputStream stream = cl.getResourceAsStream(gtabfile);
139: if (stream == null) {
140: String message = MessageFormat.format(bundle()
141: .getString("EXC_UnableToOpenStream"),
142: new String[] { gtabfile }); // NOI18N
143: throw new Exception(message);
144: }
145: PListReader reader = new PListReader(stream);
146: data = reader.getData();
147: stream.close();
148: } catch (Exception e) {
149: e.printStackTrace();
150: data = null;
151: }
152:
153: return data;
154: }
155:
156: public static Object getGlobalNodeInfo(String key) {
157: return getGlobalNodeInfo().get(key);
158: }
159:
160: public static DatabaseNodeInfo createNodeInfo(
161: DatabaseNodeInfo parent, String nodecode)
162: throws DatabaseException {
163: DatabaseNodeInfo e_ni = null;
164: try {
165: String nodec = (String) ((Map) DatabaseNodeInfo
166: .getGlobalNodeInfo().get(nodecode)).get(INFOCLASS);
167: if (nodec != null)
168: e_ni = (DatabaseNodeInfo) Class.forName(nodec)
169: .newInstance();
170: else {
171: String message = MessageFormat.format(bundle()
172: .getString("EXC_UnableToFindClassInfo"),
173: new String[] { nodecode }); // NOI18N
174: throw new Exception(message);
175: }
176: } catch (Exception exc) {
177: throw new DatabaseException(exc.getMessage());
178: }
179:
180: if (e_ni != null)
181: e_ni.setParentInfo(parent, nodecode);
182: else {
183: String message = MessageFormat.format(bundle().getString(
184: "EXC_UnableToCreateNodeInfo"),
185: new String[] { nodecode }); // NOI18N
186: throw new DatabaseException(message);
187: }
188: return e_ni;
189: }
190:
191: public static DatabaseNodeInfo createNodeInfo(
192: DatabaseNodeInfo parent, String nodecode, HashMap rset)
193: throws DatabaseException {
194: int colidx = 1;
195: String key = null;
196: DatabaseNodeInfo nfo = createNodeInfo(parent, nodecode);
197: Vector rsnames = (Vector) nfo.get(DatabaseNodeInfo.RESULTSET);
198: Iterator rsnames_i = rsnames.iterator();
199: Hashtable data = new Hashtable();
200: while (rsnames_i.hasNext()) {
201: key = (String) rsnames_i.next();
202: if (!key.equals("unused")) { //NOI18N
203: Object value = rset.get(new Integer(colidx));
204: if (value != null)
205: data.put(key, value);
206: }
207: colidx++;
208: }
209:
210: nfo.putAll(data);
211: nfo.put(nodecode, nfo.getName());
212: if (parent != null && parent.isReadOnly())
213: nfo.setReadOnly(true);
214: return nfo;
215: }
216:
217: /* Parent of info in node hierarchy */
218: private DatabaseNodeInfo parent = null;
219:
220: /* Owning node */
221: WeakReference nodewr = null;
222: private PropertyChangeSupport pcs = null;
223: private Set connectionpcsKeys = null;
224:
225: private PropertyChangeSupport driverpcs = null;
226: private Set driverpcsKeys = null;
227:
228: static final long serialVersionUID = 1176243907461868244L;
229:
230: public DatabaseNodeInfo() {
231: super ();
232: }
233:
234: public DatabaseNodeInfo(DatabaseNodeInfo parent, String sname)
235: throws DatabaseException {
236: DatabaseNodeInfo nfo = new DatabaseNodeInfo();
237: nfo.setParentInfo(parent, sname);
238: }
239:
240: public void setParentInfo(DatabaseNodeInfo parent, String sname)
241: throws DatabaseException {
242: if (parent != null) {
243: putAll(parent);
244: this .parent = parent;
245: }
246: Map ltab = (Map) getGlobalNodeInfo(sname);
247: if (ltab != null)
248: putAll(ltab);
249: else {
250: String message = MessageFormat.format(bundle().getString(
251: "EXC_UnableToReadInfo"), new String[] { sname }); // NOI18N
252: throw new DatabaseException(message);
253: }
254: put(CODE, sname);
255: if (parent != null && parent.isReadOnly())
256: setReadOnly(true);
257: }
258:
259: public DatabaseNodeInfo getParent() {
260: return parent;
261: }
262:
263: /** Returns parent of nodeinfo defined by <code>parent</code> variable.
264: * If no info was found, it returns null.
265: */
266: public DatabaseNodeInfo getParent(String code) {
267: DatabaseNodeInfo iinfo = this ;
268: if (code != null) {
269: while (iinfo != null) {
270: String iicode = iinfo.getCode();
271: if (iicode.equals(code))
272: return iinfo;
273: else
274: iinfo = iinfo.getParent();
275: }
276: }
277:
278: return iinfo;
279: }
280:
281: public boolean canAdd(Map propmap, String propname) {
282: return true;
283: }
284:
285: public boolean canWrite(Map propmap, String propname, boolean defa) {
286: if (isReadOnly())
287: return false;
288: String wflag = (String) propmap.get(DatabaseNodeInfo.WRITABLE);
289: if (wflag != null)
290: return wflag.toUpperCase().equals("YES"); //NOI18N
291: return defa;
292: }
293:
294: public DatabaseNode getNode() {
295: if (nodewr != null)
296: return (DatabaseNode) nodewr.get();
297: return null;
298: }
299:
300: public void setNode(DatabaseNode node) {
301: nodewr = new WeakReference(node);
302: }
303:
304: private PropertyChangeSupport getConnectionPCS() {
305: if (pcs == null)
306: pcs = new PropertyChangeSupport(this );
307:
308: return pcs;
309: }
310:
311: /** Returns PropertyChangeSupport used for driver change monitoring */
312: private PropertyChangeSupport getDriverPCS() {
313: if (driverpcs == null)
314: driverpcs = new PropertyChangeSupport(this );
315:
316: return driverpcs;
317: }
318:
319: /** Returns PropertyChangeSupport used for driver change monitoring */
320: private Set getDriverPCSKeys() {
321: if (driverpcsKeys == null) {
322: driverpcsKeys = new HashSet();
323: driverpcsKeys.add(NAME);
324: driverpcsKeys.add(URL);
325: driverpcsKeys.add(PREFIX);
326: driverpcsKeys.add(ADAPTOR_CLASSNAME);
327: }
328:
329: return driverpcsKeys;
330: }
331:
332: /** Returns PropertyChangeSupport used for connection change monitoring */
333: private Set getConnectionPCSKeys() {
334: if (connectionpcsKeys == null) {
335: connectionpcsKeys = new HashSet();
336: connectionpcsKeys.add(SCHEMA);
337: connectionpcsKeys.add(USER);
338: connectionpcsKeys.add(DATABASE);
339:
340: }
341:
342: return connectionpcsKeys;
343: }
344:
345: public Object put(Object key, Object obj) {
346: Object old = get(key);
347:
348: if (key == null)
349: throw new NullPointerException();
350:
351: if (obj != null)
352: super .put(key, obj);
353: else
354: remove(key);
355:
356: if (getDriverPCSKeys().contains(key)) {
357: getDriverPCS().firePropertyChange((String) key, old, obj);
358: }
359: if (getConnectionPCSKeys().contains(key))
360: getConnectionPCS().firePropertyChange((String) key, null,
361: obj);
362:
363: return old;
364: }
365:
366: public void delete() throws IOException {
367: }
368:
369: public void refreshChildren() throws DatabaseException {
370: // create list (infos)
371: Vector charr = new Vector();
372: put(DatabaseNodeInfo.CHILDREN, charr);
373: initChildren(charr);
374:
375: refreshNodes(charr);
376: }
377:
378: protected void refreshNodes(Vector charr) {
379: // create sub-tree (by infos)
380: try {
381: final Node[] subTreeNodes = new Node[charr.size()];
382:
383: // current sub-tree
384: final DatabaseNodeChildren children = (DatabaseNodeChildren) getNode()
385: .getChildren();
386:
387: // build refreshed sub-tree
388: for (int i = 0; i < charr.size(); i++) {
389: Object child = charr.elementAt(i);
390: if (child instanceof DatabaseNodeInfo) {
391: subTreeNodes[i] = children
392: .createNode((DatabaseNodeInfo) child);
393: } else if (child instanceof Node) {
394: subTreeNodes[i] = (Node) child;
395: } else {
396: throw new ClassCastException(child.getClass()
397: .getName());
398: }
399: }
400:
401: Children.MUTEX.postWriteRequest(new Runnable() {
402: public void run() {
403: // remove current sub-tree
404: children.remove(children.getNodes());
405:
406: // add built sub-tree
407: children.add(subTreeNodes);
408: }
409: });
410:
411: fireRefresh();
412: } catch (ClassCastException ex) {
413: Exceptions.printStackTrace(ex);
414: } catch (Exception ex) {
415: Logger.getLogger("global").log(Level.INFO, null, ex);
416: }
417:
418: }
419:
420: protected void fireRefresh() {
421: boolean allTables = true;
422:
423: if (!(this instanceof TableListNodeInfo)) {
424: allTables = false;
425: if (!(this instanceof TableNodeInfo)) {
426: return;
427: }
428: }
429:
430: ConnectionNodeInfo cnnfo = (ConnectionNodeInfo) getParent(DatabaseNode.CONNECTION);
431: if (cnnfo == null) {
432: return;
433: }
434:
435: DatabaseConnection dbconn = ConnectionList.getDefault()
436: .getConnection(cnnfo.getDatabaseConnection());
437: if (dbconn != null) {
438: if (allTables) {
439: DbMetaDataListenerSupport.fireTablesChanged(dbconn
440: .getDatabaseConnection());
441: } else {
442: String tableName = (String) get(DatabaseNode.TABLE);
443: DbMetaDataListenerSupport.fireTableChanged(dbconn
444: .getDatabaseConnection(), tableName);
445: }
446: }
447: }
448:
449: /** Called by property editor */
450: public Object getProperty(String key) {
451: return get(key);
452: }
453:
454: /** Called by property editor */
455: public void setProperty(String key, Object obj) {
456: put(key, obj);
457: }
458:
459: /** Add property change listener */
460: public void addConnectionListener(PropertyChangeListener l) {
461: getConnectionPCS().addPropertyChangeListener(l);
462: }
463:
464: /** Remove property change listener */
465: public void removeConnectionListener(PropertyChangeListener l) {
466: pcs.removePropertyChangeListener(l);
467: }
468:
469: public void addDriverListener(PropertyChangeListener l) {
470: getDriverPCS().addPropertyChangeListener(l);
471: }
472:
473: public void removeDriverListener(PropertyChangeListener l) {
474: getDriverPCS().removePropertyChangeListener(l);
475: }
476:
477: public DatabaseSpecificationFactory getSpecificationFactory() {
478: return (DatabaseSpecificationFactory) get(SPECIFICATION_FACTORY);
479: }
480:
481: public void setSpecificationFactory(DatabaseSpecificationFactory fac) {
482: put(SPECIFICATION_FACTORY, fac);
483: put(SUPPORTED_DBS, fac.supportedDatabases());
484: }
485:
486: protected String getDatabaseAdaptorClassName() {
487: return "org.netbeans.lib.ddl.adaptors.DefaultAdaptor"; //NOI18N
488: }
489:
490: public DatabaseSpecification getSpecification() {
491: DatabaseSpecification spec = (DatabaseSpecification) get(SPECIFICATION);
492: if (spec == null)
493: return spec;
494: String adaname = getDatabaseAdaptorClassName();
495: if (!spec.getMetaDataAdaptorClassName().equals(adaname)) {
496: spec.setMetaDataAdaptorClassName(adaname);
497: }
498:
499: return spec;
500: }
501:
502: public void setSpecification(DatabaseSpecification spec) {
503: put(SPECIFICATION, spec);
504: }
505:
506: public String getDriver() {
507: return (String) get(DRIVER);
508: }
509:
510: public void setDriver(String drv) {
511: put(DRIVER, drv);
512: }
513:
514: public Connection getConnection() {
515: return (Connection) get(CONNECTION);
516: }
517:
518: public void setConnection(Connection con) throws DatabaseException {
519: Connection oldval = getConnection();
520: if (con != null) {
521: if (oldval != null && oldval.equals(con))
522: return;
523: put(CONNECTION, con);
524: setConnected(true);
525: } else {
526: remove(CONNECTION);
527: setConnected(false);
528: }
529:
530: // Check if node is readonly or not.
531:
532: if (con != null && isReadOnly()) {
533: Enumeration enu = getChildren().elements();
534: while (enu.hasMoreElements()) {
535: DatabaseNodeInfo ninfo = (DatabaseNodeInfo) enu
536: .nextElement();
537: ninfo.setReadOnly(true);
538: }
539: }
540:
541: getConnectionPCS().firePropertyChange(CONNECTION, oldval, con);
542:
543: }
544:
545: public void setConnected(boolean connected) {
546: this .connected = connected;
547: }
548:
549: public boolean isConnected() {
550: return connected;
551: }
552:
553: public DatabaseConnection getDatabaseConnection() {
554: DatabaseConnection con = new DatabaseConnection(getDriver(),
555: getDatabase(), getUser(), getPassword());
556: if (get(REMEMBER_PWD) != null) {
557: con.setRememberPassword(((Boolean) get(REMEMBER_PWD))
558: .booleanValue());
559: } else
560: con.setRememberPassword(Boolean.FALSE.booleanValue());
561: con.setSchema(getSchema());
562: con.setDriverName((String) get("drivername"));
563: return con;
564: }
565:
566: public DatabaseDriver getDatabaseDriver() {
567: return (DatabaseDriver) get(DBDRIVER);
568: }
569:
570: public void setDatabaseConnection(DBConnection cinfo) {
571: String pwd = cinfo.getPassword();
572: put(DRIVER, cinfo.getDriver());
573: put(DATABASE, cinfo.getDatabase());
574: put(USER, cinfo.getUser());
575: put(SCHEMA, cinfo.getSchema());
576: if (pwd != null)
577: put(PASSWORD, pwd);
578: put(REMEMBER_PWD, (Boolean.valueOf(cinfo.rememberPassword())));
579: put("drivername", cinfo.getDriverName());
580: }
581:
582: public String getCode() {
583: return (String) get(CODE);
584: }
585:
586: public void setCode(String nam) {
587: put(CODE, nam);
588: }
589:
590: public String getName() {
591: return (String) get(NAME);
592: }
593:
594: public void setName(String nam) {
595: put(NAME, nam);
596: }
597:
598: public String getUser() {
599: return (String) get(USER);
600: }
601:
602: public void setUser(String usr) {
603: put(USER, usr);
604: }
605:
606: public String getSchema() {
607: return (String) get(SCHEMA);
608: }
609:
610: public void setSchema(String schema) {
611: put(SCHEMA, schema);
612: }
613:
614: public String getDatabase() {
615: return (String) get(DATABASE);
616: }
617:
618: public void setDatabase(String db) {
619: put(DATABASE, db);
620: }
621:
622: public String getPassword() {
623: return (String) get(PASSWORD);
624: }
625:
626: public void setPassword(String pwd) {
627: put(PASSWORD, pwd);
628: }
629:
630: public String getTable() {
631: return (String) get("table"); //NOI18N
632: }
633:
634: public String getView() {
635: return (String) get("view"); //NOI18N
636: }
637:
638: public void setTable(String nam) {
639: put("table", nam); //NOI18N
640: }
641:
642: public String getIconBase() {
643: return (String) get("iconbase"); //NOI18N
644: }
645:
646: public void setIconBase(String base) {
647: put("iconbase", base); //NOI18N
648: }
649:
650: public String getDisplayname() {
651: return (String) get("displayname"); //NOI18N
652: }
653:
654: public void setDisplayname(String name) {
655: put("displayname", name); //NOI18N
656: }
657:
658: public String getURL() {
659: return (String) get(URL);
660: }
661:
662: public void setURL(String url) {
663: put(URL, url);
664: }
665:
666: /** Returns connection properties (login name and password)
667: * Returns null if name or password isn't specified yet.
668: */
669: public Properties getConnectionProperties() {
670: Properties props = new Properties();
671: try {
672: props.put("user", getUser()); //NOI18N
673: props.put("password", getPassword()); //NOI18N
674: props.put("schema", getSchema()); //NOI18N
675: } catch (Exception e) {
676: props = null;
677: }
678:
679: return props;
680: }
681:
682: protected void initChildren(Vector children)
683: throws DatabaseException {
684: }
685:
686: public Vector getChildren() throws DatabaseException {
687: Vector children = (Vector) get(CHILDREN);
688: if (children.size() > 0
689: && (children.elementAt(0) instanceof DatabaseNodeInfo || children
690: .elementAt(0) instanceof Node)) {
691: return children;
692: }
693:
694: Vector chalt = new Vector();
695: initChildren(chalt);
696: chalt.addAll(children);
697:
698: try {
699: for (int i = 0; i < chalt.size(); i++) {
700: Object e_child = chalt.elementAt(i);
701: if (e_child instanceof String) {
702: DatabaseNodeInfo e_ni = createNodeInfo(this ,
703: (String) e_child);
704: chalt.setElementAt(e_ni, i);
705: }
706: }
707:
708: children = chalt;
709: put(CHILDREN, children);
710:
711: } catch (Exception exc) {
712: String message = MessageFormat.format(bundle().getString(
713: "EXC_UnableToCreateChildren"), new String[] { exc
714: .getMessage() }); // NOI18N
715: throw new DatabaseException(message);
716: }
717:
718: return children;
719: }
720:
721: public void setChildren(Vector chvec) {
722: put(CHILDREN, chvec);
723: }
724:
725: public Vector getActions() {
726: Vector actions = (Vector) get(ACTIONS);
727: actions = (Vector) actions.clone();
728: if (actions == null) {
729: actions = new Vector();
730: put(ACTIONS, actions);
731: }
732:
733: if (actions.size() == 0)
734: return actions;
735: boolean ro = isReadOnly();
736: for (int i = 0; i < actions.size(); i++) {
737:
738: Object e_act = actions.elementAt(i);
739: SystemAction action = null;
740: if (e_act instanceof Map) {
741: Map e_action = (Map) e_act;
742: try {
743:
744: // Try permissions
745:
746: String perm = (String) e_action.get(PERM);
747: if (ro && perm != null && perm instanceof String
748: && perm.indexOf("write") != -1) { //NOI18N
749: actions.setElementAt(null, i);
750: continue;
751: }
752:
753: boolean systemact = false;
754: String sysactstr = (String) e_action
755: .get(SYSTEM_ACTION);
756: if (sysactstr != null)
757: systemact = sysactstr.toUpperCase().equals(
758: "YES"); //NOI18N
759: String actnode = (String) e_action.get(NODE);
760: String actcn = (String) e_action.get(CLASS);
761:
762: if (!systemact) {
763: String locname, xname = (String) e_action
764: .get(NAME);
765: try {
766: locname = bundle().getString(xname);
767: } catch (MissingResourceException e) {
768: locname = xname;
769:
770: String message = MessageFormat
771: .format(
772: bundle()
773: .getString(
774: "ERR_UnableToLocateLocalizedMenuItem"),
775: new String[] { xname }); // NOI18N
776: System.out.println(message);
777: }
778:
779: //action = (SystemAction)Class.forName(actcn).newInstance();
780: //action = (SystemAction)SharedClassObject.findObject(Class.forName(actcn), true);
781: action = SystemAction.get(Class.forName(actcn)
782: .asSubclass(SystemAction.class));
783: ((DatabaseAction) action).setName(locname);
784: ((DatabaseAction) action).setNode(actnode);
785: } else {
786: ClassLoader l = (ClassLoader) org.openide.util.Lookup
787: .getDefault().lookup(ClassLoader.class);
788: if (l == null) {
789: l = getClass().getClassLoader();
790: }
791: action = SystemAction
792: .get(Class.forName(actcn, true, l)
793: .asSubclass(SystemAction.class));
794: }
795:
796: } catch (Exception e) {
797: e.printStackTrace();
798: }
799: }
800:
801: actions.setElementAt(action, i);
802: }
803:
804: return actions;
805: }
806:
807: public String toString() {
808: String result = ""; //NOI18N
809: Enumeration keys = keys();
810: while (keys.hasMoreElements()) {
811: Object key = keys.nextElement();
812: result = result + key + ": " + get(key) + "\n"; //NOI18N
813: }
814:
815: return result;
816: }
817:
818: public boolean isDebugMode() {
819: return RootNode.getOption().getDebugMode();
820: }
821:
822: public void setDebugMode(boolean mode) {
823: RootNode.getOption().setDebugMode(mode);
824: }
825:
826: public boolean isReadOnly() {
827: Boolean roobj = (Boolean) get(READONLY);
828: if (roobj != null)
829: return roobj.booleanValue();
830: return false;
831: }
832:
833: public void setReadOnly(boolean flag) {
834: put(READONLY, flag ? Boolean.TRUE : Boolean.FALSE);
835: }
836:
837: /** Getter for property driverSpecification.
838: *@return Value of property driverSpecification.
839: */
840: public DriverSpecification getDriverSpecification() {
841: return (DriverSpecification) get(DRIVER_SPECIFICATION);
842: }
843:
844: /** Setter for property driverSpecification.
845: *@param driverSpecification New value of property driverSpecification.
846: */
847: public void setDriverSpecification(
848: DriverSpecification driverSpecification) {
849: put(DRIVER_SPECIFICATION, driverSpecification);
850: }
851:
852: }
|