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.Map;
046:
047: import org.openide.util.NbBundle;
048:
049: import org.netbeans.lib.ddl.DDLException;
050:
051: /**
052: * Instances of this command operates with one column.
053: *
054: * @author Slavek Psenicka
055: */
056:
057: public class ColumnCommand extends AbstractCommand {
058: /** Column */
059: private TableColumn column;
060:
061: static final long serialVersionUID = -4554975764392047624L;
062:
063: /** Creates specification of command
064: * @param type Type of column
065: * @param name Name of column
066: * @param cmd Command
067: * @param newObject set to true if this column is for a new object (table)
068: * and set to false if this column is for an existing object (table)
069: * @param newColumn set to true if this is a new column, false if this
070: * is an existing column.
071: */
072: public TableColumn specifyColumn(String type, String name,
073: String cmd, boolean newObject, boolean newColumn)
074: throws ClassNotFoundException, IllegalAccessException,
075: InstantiationException {
076: Map gprops = (Map) getSpecification().getProperties();
077: Map props = (Map) getSpecification().getCommandProperties(cmd);
078: Map bindmap = (Map) props.get("Binding"); // NOI18N
079: String tname = (String) bindmap.get(type);
080: if (tname != null) {
081: Map typemap = (Map) gprops.get(tname);
082: if (typemap == null)
083: throw new InstantiationException(
084: MessageFormat
085: .format(
086: NbBundle
087: .getBundle(
088: "org.netbeans.lib.ddl.resources.Bundle")
089: .getString(
090: "EXC_UnableLocateObject"), // NOI18N
091: new String[] { tname }));
092: Class typeclass = Class.forName((String) typemap
093: .get("Class")); // NOI18N
094: String format = (String) typemap.get("Format"); // NOI18N
095: column = (TableColumn) typeclass.newInstance();
096: column.setObjectName(name);
097: column.setObjectType(type);
098: column.setColumnName(name);
099: column.setFormat(format);
100: column.setNewObject(newObject);
101: column.setNewColumn(newColumn);
102: } else
103: throw new InstantiationException(MessageFormat.format(
104: NbBundle.getBundle(
105: "org.netbeans.lib.ddl.resources.Bundle")
106: .getString("EXC_UnableLocateType"), // NOI18N
107: new String[] { type, bindmap.toString() }));
108:
109: return column;
110: }
111:
112: public TableColumn getColumn() {
113: return column;
114: }
115:
116: public void setColumn(TableColumn col) {
117: column = col;
118: }
119:
120: /**
121: * Returns properties and it's values supported by this object.
122: * column Specification of the column
123: */
124: public Map getCommandProperties() throws DDLException {
125: Map args = super .getCommandProperties();
126: args.put("column", column.getCommand(this )); // NOI18N
127: return args;
128: }
129: }
|