KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > lib > ddl > impl > ColumnListCommand


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.lib.ddl.impl;
21
22 import java.text.MessageFormat JavaDoc;
23 import java.util.Enumeration JavaDoc;
24 import java.util.Map JavaDoc;
25 import java.util.Vector JavaDoc;
26
27 import org.openide.util.NbBundle;
28
29 import org.netbeans.lib.ddl.DDLException;
30
31 /**
32 * Instances of this command operates with column list (e.g. create column).
33 * To process command with one column use ColumnCommand.
34 *
35 * @author Slavek Psenicka
36 */

37
38 public class ColumnListCommand extends AbstractCommand
39 {
40     /** Used columns */
41     private Vector JavaDoc columns;
42
43     static final long serialVersionUID =3646663278680222131L;
44     /** Constructor */
45     public ColumnListCommand()
46     {
47         columns = new Vector JavaDoc();
48     }
49
50     /** Returns list of columns */
51     public Vector JavaDoc getColumns()
52     {
53         return columns;
54     }
55
56     /** Creates specification of command
57     * @param type Type of column
58     * @param name Name of column
59     * @param cmd Command
60     */

61     public TableColumn specifyColumn(String JavaDoc type, String JavaDoc name, String JavaDoc cmd)
62     throws ClassNotFoundException JavaDoc, IllegalAccessException JavaDoc, InstantiationException JavaDoc
63     {
64         TableColumn column;
65         Map JavaDoc gprops = (Map JavaDoc)getSpecification().getProperties();
66         Map JavaDoc props = (Map JavaDoc)getSpecification().getCommandProperties(cmd);
67         Map JavaDoc bindmap = (Map JavaDoc)props.get("Binding"); // NOI18N
68
String JavaDoc tname = (String JavaDoc)bindmap.get(type);
69         if (tname != null) {
70             Map JavaDoc typemap = (Map JavaDoc)gprops.get(tname);
71             if (typemap != null) {
72                 Class JavaDoc typeclass = Class.forName((String JavaDoc)typemap.get("Class")); // NOI18N
73
String JavaDoc format = (String JavaDoc)typemap.get("Format"); // NOI18N
74
column = (TableColumn)typeclass.newInstance();
75                 column.setObjectName(name);
76                 column.setObjectType(type);
77                 column.setColumnName(name);
78                 column.setFormat(format);
79                 columns.add(column);
80             } else throw new InstantiationException JavaDoc(
81                     MessageFormat.format(
82                         NbBundle.getBundle("org.netbeans.lib.ddl.resources.Bundle").getString("EXC_UnableLocateType"), // NOI18N
83
new String JavaDoc[] {tname, props.keySet().toString() } ));
84         } else throw new InstantiationException JavaDoc(
85                     MessageFormat.format(
86                         NbBundle.getBundle("org.netbeans.lib.ddl.resources.Bundle").getString("EXC_UnableToBind"), // NOI18N
87
new String JavaDoc[] {type, bindmap.toString() } ));
88         return column;
89     }
90
91     /**
92     * Returns properties and it's values supported by this object.
93     * columns Specification of columns served by this object
94     */

95     public Map JavaDoc getCommandProperties()
96     throws DDLException
97     {
98         Map JavaDoc props = (Map JavaDoc)getSpecification().getProperties();
99         String JavaDoc cols = (String JavaDoc)props.get("ColumnListHeader"); // NOI18N
100
String JavaDoc coldelim = (String JavaDoc)props.get("ColumnListDelimiter"); // NOI18N
101
Map JavaDoc args = super.getCommandProperties();
102
103         // Construct string
104

105         Enumeration JavaDoc col_e = columns.elements();
106         while (col_e.hasMoreElements()) {
107             AbstractTableColumn col = (AbstractTableColumn)col_e.nextElement();
108             boolean inscomma = col_e.hasMoreElements();
109             cols = cols + col.getCommand(this)+(inscomma ? coldelim : "");
110         }
111
112         args.put("columns", cols); // NOI18N
113
return args;
114     }
115
116     /** Reads object from stream */
117     public void readObject(java.io.ObjectInputStream JavaDoc in)
118     throws java.io.IOException JavaDoc, ClassNotFoundException JavaDoc
119     {
120         super.readObject(in);
121         columns = (Vector JavaDoc)in.readObject();
122     }
123
124     /** Writes object to stream */
125     public void writeObject(java.io.ObjectOutputStream JavaDoc out)
126     throws java.io.IOException JavaDoc
127     {
128         super.writeObject(out);
129         out.writeObject(columns);
130     }
131 }
132
Popular Tags