KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jdesktop > dataset > DataCommand


1 /*
2  * $Id: DataCommand.java,v 1.1 2005/02/27 00:24:55 rbair Exp $
3  *
4  * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
5  * Santa Clara, California 95054, U.S.A. All rights reserved.
6  */

7
8 package org.jdesktop.dataset;
9
10 import java.util.HashMap JavaDoc;
11 import java.util.Map JavaDoc;
12
13 /**
14  * Represents a command that can be executed against a data store. Some commands
15  * are for retrieving data for a DataProvider, while others are for persisting
16  * data to the data store. For example, in the provider.sql package there are
17  * SelectCommand, UpdateCommand, InsertCommand, and DeleteCommand instances.
18  *
19  * @author rbair
20  */

21 public abstract class DataCommand {
22     /**
23      * Contains the short description
24      */

25     private String JavaDoc shortDescription;
26
27     /**
28      * A special marker indicating that a parameter has been undefined.
29      */

30     private static final Object JavaDoc UNDEFINED = new Object JavaDoc();
31     
32     /**
33      * Contains all of the params
34      */

35     private Map JavaDoc<String JavaDoc,Object JavaDoc> params = new HashMap JavaDoc<String JavaDoc,Object JavaDoc>();
36
37     /**
38      * Set a short description for this Task. This description is used
39      * within a GUI builder to describe what the Task does, or wherever a short
40      * description might be useful, such as within some logging statements.
41      */

42     public void setShortDescription(String JavaDoc shortDescription) {
43         this.shortDescription = shortDescription == null ? "" : shortDescription;
44     }
45
46     /**
47      * Returns the short description of this DataCommand
48      */

49     public String JavaDoc getShortDescription() {
50         return shortDescription;
51     }
52
53     /**
54      * Sets the given named parameter to the given value. Passing in a value of
55      * "null" will *not* clear the parameter, but will set the parameter to the
56      * null value.
57      */

58     public void setParameter(String JavaDoc name, Object JavaDoc value) {
59         params.put(name, value);
60     }
61
62     /**
63      * Clears the given named parameter of any associated value.
64      */

65     public void clearParameter(String JavaDoc name) {
66         params.put(name, UNDEFINED);
67     }
68     
69     /**
70      * Clears all of the parameters
71      */

72     public void clearParameters() {
73         for (String JavaDoc name : params.keySet()) {
74             params.put(name, UNDEFINED);
75         }
76     }
77     
78     /**
79      * Returns the value for the given named parameter.
80      */

81     public Object JavaDoc getParameter(String JavaDoc name) {
82         return params.get(name);
83     }
84
85     /**
86      * Returns an array containing all of the parameter names for this DataCommand
87      */

88     public abstract String JavaDoc[] getParameterNames();
89     
90     /**
91      * Returns an object array containing all of the parameter values for this
92      * DataCommand.
93      */

94     public Object JavaDoc[] getParameterValues() {
95         return params.values().toArray();
96     }
97 }
Popular Tags