|
What this is
Other links
The source code
/*
* Sun Public License Notice
*
* The contents of this file are subject to the Sun Public License
* Version 1.0 (the "License"). You may not use this file except in
* compliance with the License. A copy of the License is available at
* http://www.sun.com/
*
* The Original Code is NetBeans. The Initial Developer of the Original
* Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun
* Microsystems, Inc. All Rights Reserved.
*/
package org.netbeans.modules.db.explorer.infos;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.lang.ref.WeakReference;
import java.io.InputStream;
import java.io.IOException;
import java.sql.Connection;
import java.text.MessageFormat;
import java.util.*;
import org.openide.nodes.Node;
import org.openide.util.NbBundle;
import org.openide.util.actions.SystemAction;
import org.netbeans.lib.ddl.DatabaseSpecification;
import org.netbeans.lib.ddl.DatabaseSpecificationFactory;
import org.netbeans.lib.ddl.DBConnection;
import org.netbeans.lib.ddl.impl.DriverSpecification;
import org.netbeans.lib.ddl.util.PListReader;
import org.netbeans.modules.db.DatabaseException;
import org.netbeans.modules.db.explorer.DatabaseConnection;
import org.netbeans.modules.db.explorer.DatabaseDriver;
import org.netbeans.modules.db.explorer.DatabaseNodeChildren;
import org.netbeans.modules.db.explorer.actions.DatabaseAction;
import org.netbeans.modules.db.explorer.nodes.DatabaseNode;
import org.netbeans.modules.db.explorer.nodes.RootNode;
public class DatabaseNodeInfo extends Hashtable implements Node.Cookie {
public static final String SPECIFICATION_FACTORY = "specfactory"; //NOI18N
public static final String SPECIFICATION = "spec"; //NOI18N
public static final String DRIVER_SPECIFICATION = "drvspec"; //NOI18N
public static final String DBPRODUCT = "dbproduct"; //NOI18N
public static final String DBVERSION = "dbversion"; //NOI18N
public static final String SUPPORTED_DBS = "suppdbs"; //NOI18N
public static final String DRIVER = "driver"; //NOI18N
public static final String DBDRIVER = "dbdriver"; //NOI18N
public static final String DATABASE = "db"; //NOI18N
public static final String URL = "url"; //NOI18N
public static final String PREFIX = "prefix"; //NOI18N
public static final String CONNECTION = "connection"; //NOI18N
public static final String CODE = "code"; //NOI18N
public static final String NODE = "node"; //NOI18N
public static final String CLASS = "class"; //NOI18N
public static final String INFOCLASS = "infoclass"; //NOI18N
public static final String NAME = "name"; //NOI18N
public static final String USER = "user"; //NOI18N
public static final String SCHEMA = "schema"; //NOI18N
public static final String PASSWORD = "password"; //NOI18N
public static final String CHILDREN = "children"; //NOI18N
public static final String ACTIONS = "actions"; //NOI18N
public static final String ICONBASE = "iconbase"; //NOI18N
public static final String PROPERTIES = "properties"; //NOI18N
public static final String RESULTSET = "resultset"; //NOI18N
public static final String REMEMBER_PWD = "rememberpwd"; //NOI18N
public static final String WRITABLE = "writable"; //NOI18N
public static final String DELETABLE = "deletable"; //NOI18N
public static final String DESCRIPTION = "description"; //NOI18N
public static final String READONLYDB = "readonlydatabase"; //NOI18N
public static final String GROUPSUP = "groupbysupport"; //NOI18N
public static final String OJOINSUP = "outerjoinsupport"; //NOI18N
public static final String UNIONSUP = "unionsupport"; //NOI18N
public static final String SYSTEM_ACTION = "system"; //NOI18N
public static final String CHILDREN_ORDERING = "children_ordering"; //NOI18N
public static final String READONLY = "readOnly"; //NOI18N
public static final String PERM = "perm"; //NOI18N
public static final String ADAPTOR = "adaptor"; //NOI18N
public static final String ADAPTOR_CLASSNAME = "adaptorClass"; //NOI18N
private static Map gtab = null;
static final String gtabfile = "org/netbeans/modules/db/resources/explorer.plist"; //NOI18N
static final ResourceBundle bundle = NbBundle.getBundle("org.netbeans.modules.db.resources.Bundle"); // NOI18N
private boolean connected = false;
transient boolean passwordWasSet = false;
public static Map getGlobalNodeInfo() {
if (gtab == null)
gtab = readInfo();
return gtab;
}
public static Map readInfo() {
Map data;
try {
ClassLoader cl = DatabaseNodeInfo.class.getClassLoader();
InputStream stream = cl.getResourceAsStream(gtabfile);
if (stream == null) {
String message = MessageFormat.format(bundle.getString("EXC_UnableToOpenStream"), new String[] {gtabfile}); // NOI18N
throw new Exception(message);
}
PListReader reader = new PListReader(stream);
data = reader.getData();
stream.close();
} catch (Exception e) {
e.printStackTrace();
data = null;
}
return data;
}
public static Object getGlobalNodeInfo(String key) {
return getGlobalNodeInfo().get(key);
}
public static DatabaseNodeInfo createNodeInfo(DatabaseNodeInfo parent, String nodecode) throws DatabaseException {
DatabaseNodeInfo e_ni = null;
try {
String nodec = (String)((Map)DatabaseNodeInfo.getGlobalNodeInfo().get(nodecode)).get(INFOCLASS);
if (nodec != null)
e_ni = (DatabaseNodeInfo)Class.forName(nodec).newInstance();
else {
String message = MessageFormat.format(bundle.getString("EXC_UnableToFindClassInfo"), new String[] {nodecode}); // NOI18N
throw new Exception(message);
}
} catch (Exception exc) {
throw new DatabaseException(exc.getMessage());
}
if (e_ni != null)
e_ni.setParentInfo(parent, nodecode);
else {
String message = MessageFormat.format(bundle.getString("EXC_UnableToCreateNodeInfo"), new String[] {nodecode}); // NOI18N
throw new DatabaseException(message);
}
return e_ni;
}
public static DatabaseNodeInfo createNodeInfo(DatabaseNodeInfo parent, String nodecode, HashMap rset) throws DatabaseException {
int colidx = 1;
String key = null;
DatabaseNodeInfo nfo = createNodeInfo(parent, nodecode);
Vector rsnames = (Vector)nfo.get(DatabaseNodeInfo.RESULTSET);
Iterator rsnames_i = rsnames.iterator();
Hashtable data = new Hashtable();
while (rsnames_i.hasNext()) {
key = (String)rsnames_i.next();
if (!key.equals("unused")) { //NOI18N
Object value = rset.get(new Integer(colidx));
if (value != null) data.put(key, value);
}
colidx++;
}
nfo.putAll(data);
nfo.put(nodecode, nfo.getName());
if (parent != null && parent.isReadOnly()) nfo.setReadOnly(true);
return nfo;
}
/* Parent of info in node hierarchy */
private DatabaseNodeInfo parent = null;
/* Owning node */
WeakReference nodewr = null;
private PropertyChangeSupport pcs = null;
private Set connectionpcsKeys = null;
private PropertyChangeSupport driverpcs = null;
private Set driverpcsKeys = null;
static final long serialVersionUID =1176243907461868244L;
public DatabaseNodeInfo()
{
super();
}
public DatabaseNodeInfo(DatabaseNodeInfo parent, String sname)
throws DatabaseException
{
DatabaseNodeInfo nfo = new DatabaseNodeInfo();
nfo.setParentInfo(parent, sname);
}
public void setParentInfo(DatabaseNodeInfo parent, String sname)
throws DatabaseException
{
if (parent != null) {
putAll(parent);
this.parent = parent;
}
Map ltab = (Map)getGlobalNodeInfo(sname);
if (ltab != null)
putAll(ltab);
else {
String message = MessageFormat.format(bundle.getString("EXC_UnableToReadInfo"), new String[] {sname}); // NOI18N
throw new DatabaseException(message);
}
put(CODE, sname);
if (parent != null && parent.isReadOnly()) setReadOnly(true);
}
public DatabaseNodeInfo getParent()
{
return parent;
}
/** Returns parent of nodeinfo defined by |
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.