KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.HashMap JavaDoc;
23 import java.util.Map JavaDoc;
24
25 import org.openide.util.NbBundle;
26
27 import org.netbeans.lib.ddl.DDLException;
28 import org.netbeans.lib.ddl.util.CommandFormatter;
29
30 /**
31 * Describes trigger. Encapsulates name, timing (when it fires; when user INSERTs of
32 * some data, after UPDATE or DELETE). In trigger descriptor this values should be
33 * combined together.
34 */

35 public class TriggerEvent {
36     public static final int INSERT = 1;
37     public static final int UPDATE = 2;
38     public static final int DELETE = 3;
39
40     /** Converts code into string representation */
41     public static String JavaDoc getName(int code)
42     {
43         switch (code) {
44         case INSERT: return "INSERT"; // NOI18N
45
case UPDATE: return "UPDATE"; // NOI18N
46
case DELETE: return "DELETE"; // NOI18N
47
}
48
49         return null;
50     }
51
52     /** Event */
53     private String JavaDoc name;
54
55     /** Column */
56     private String JavaDoc col;
57
58     /** Format */
59     private String JavaDoc format;
60
61     /** Returns name */
62     public String JavaDoc getName()
63     {
64         return name;
65     }
66
67     /** Sets name */
68     public void setName(String JavaDoc aname)
69     {
70         name = aname;
71     }
72
73     /** Returns name of column */
74     public String JavaDoc getFormat()
75     {
76         return format;
77     }
78
79     /** Sets name of column */
80     public void setFormat(String JavaDoc fmt)
81     {
82         format = fmt;
83     }
84
85     /** Returns name of column */
86     public String JavaDoc getColumn()
87     {
88         return col;
89     }
90
91     /** Sets name of column */
92     public void setColumn(String JavaDoc column)
93     {
94         col = column;
95     }
96
97     /**
98     * Returns properties and it's values supported by this object.
99     * event.name Name of event
100     * event.column Name of column
101     * Throws DDLException if object name is not specified.
102     */

103     public Map JavaDoc getColumnProperties(AbstractCommand cmd) throws DDLException {
104         HashMap JavaDoc args = new HashMap JavaDoc();
105         args.put("event.name", cmd.quote(name)); // NOI18N
106
args.put("event.column", col); // NOI18N
107

108         return args;
109     }
110
111     /** Returns string representation of event
112     * @param cmd Command context
113     */

114     public String JavaDoc getCommand(AbstractCommand cmd)
115     throws DDLException
116     {
117         Map JavaDoc cprops;
118         if (format == null) throw new DDLException(NbBundle.getBundle("org.netbeans.lib.ddl.resources.Bundle").getString("EXC_NoFormatSpec")); //NOI18N
119
try {
120             cprops = getColumnProperties(cmd);
121             return CommandFormatter.format(format, cprops);
122         } catch (Exception JavaDoc e) {
123             throw new DDLException(e.getMessage());
124         }
125     }
126 }
127
Popular Tags