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.lib.ddl.impl;
043:
044: import java.text.MessageFormat;
045: import java.util.Enumeration;
046: import java.util.Map;
047: import java.util.Vector;
048:
049: import org.openide.util.NbBundle;
050:
051: import org.netbeans.lib.ddl.DDLException;
052:
053: /**
054: * Instances of this command operates with column list (e.g. create column).
055: * To process command with one column use ColumnCommand.
056: *
057: * @author Slavek Psenicka
058: */
059:
060: public class ColumnListCommand extends AbstractCommand {
061: /** Used columns */
062: private Vector columns;
063:
064: static final long serialVersionUID = 3646663278680222131L;
065:
066: /** Constructor */
067: public ColumnListCommand() {
068: columns = new Vector();
069: }
070:
071: /** Returns list of columns */
072: public Vector getColumns() {
073: return columns;
074: }
075:
076: /** Creates specification of command
077: * @param type Type of column
078: * @param name Name of column
079: * @param cmd Command
080: * @param newObject indicates whether the object for this column
081: * (e.g. a table) is an existing object or a new object. This affects
082: * whether we quote the object or not.
083: * @param newColumn indicates whether this column refers to a column
084: * being created as part of this command or it is an existing column
085: */
086: public TableColumn specifyColumn(String type, String name,
087: String cmd, boolean newObject, boolean newColumn)
088: throws ClassNotFoundException, IllegalAccessException,
089: InstantiationException {
090: TableColumn column;
091: Map gprops = (Map) getSpecification().getProperties();
092: Map props = (Map) getSpecification().getCommandProperties(cmd);
093: Map bindmap = (Map) props.get("Binding"); // NOI18N
094: String tname = (String) bindmap.get(type);
095: if (tname != null) {
096: Map typemap = (Map) gprops.get(tname);
097: if (typemap != null) {
098: Class typeclass = Class.forName((String) typemap
099: .get("Class")); // NOI18N
100: String format = (String) typemap.get("Format"); // NOI18N
101: column = (TableColumn) typeclass.newInstance();
102: column.setObjectName(name);
103: column.setObjectType(type);
104: column.setColumnName(name);
105: column.setFormat(format);
106: column.setNewObject(newObject);
107: column.setNewColumn(newColumn);
108: columns.add(column);
109: } else
110: throw new InstantiationException(
111: MessageFormat
112: .format(
113: NbBundle
114: .getBundle(
115: "org.netbeans.lib.ddl.resources.Bundle")
116: .getString(
117: "EXC_UnableLocateType"), // NOI18N
118: new String[] {
119: tname,
120: props.keySet()
121: .toString() }));
122: } else
123: throw new InstantiationException(MessageFormat.format(
124: NbBundle.getBundle(
125: "org.netbeans.lib.ddl.resources.Bundle")
126: .getString("EXC_UnableToBind"), // NOI18N
127: new String[] { type, bindmap.toString() }));
128: return column;
129: }
130:
131: /**
132: * Returns properties and it's values supported by this object.
133: * columns Specification of columns served by this object
134: */
135: public Map getCommandProperties() throws DDLException {
136: Map props = (Map) getSpecification().getProperties();
137: String cols = (String) props.get("ColumnListHeader"); // NOI18N
138: String coldelim = (String) props.get("ColumnListDelimiter"); // NOI18N
139: Map args = super .getCommandProperties();
140:
141: // Construct string
142:
143: Enumeration col_e = columns.elements();
144: while (col_e.hasMoreElements()) {
145: AbstractTableColumn col = (AbstractTableColumn) col_e
146: .nextElement();
147: boolean inscomma = col_e.hasMoreElements();
148: cols = cols + col.getCommand(this )
149: + (inscomma ? coldelim : "");
150: }
151:
152: args.put("columns", cols); // NOI18N
153: return args;
154: }
155:
156: /** Reads object from stream */
157: public void readObject(java.io.ObjectInputStream in)
158: throws java.io.IOException, ClassNotFoundException {
159: super .readObject(in);
160: columns = (Vector) in.readObject();
161: }
162:
163: /** Writes object to stream */
164: public void writeObject(java.io.ObjectOutputStream out)
165: throws java.io.IOException {
166: super.writeObject(out);
167: out.writeObject(columns);
168: }
169: }
|