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.util.HashMap;
045: import java.util.Map;
046:
047: import org.openide.util.NbBundle;
048:
049: import org.netbeans.lib.ddl.DDLException;
050: import org.netbeans.lib.ddl.util.CommandFormatter;
051:
052: /**
053: * Describes trigger. Encapsulates name, timing (when it fires; when user INSERTs of
054: * some data, after UPDATE or DELETE). In trigger descriptor this values should be
055: * combined together.
056: */
057: public class TriggerEvent {
058: public static final int INSERT = 1;
059: public static final int UPDATE = 2;
060: public static final int DELETE = 3;
061:
062: /** Converts code into string representation */
063: public static String getName(int code) {
064: switch (code) {
065: case INSERT:
066: return "INSERT"; // NOI18N
067: case UPDATE:
068: return "UPDATE"; // NOI18N
069: case DELETE:
070: return "DELETE"; // NOI18N
071: }
072:
073: return null;
074: }
075:
076: /** Event */
077: private String name;
078:
079: /** Column */
080: private String col;
081:
082: /** Format */
083: private String format;
084:
085: /** Returns name */
086: public String getName() {
087: return name;
088: }
089:
090: /** Sets name */
091: public void setName(String aname) {
092: name = aname;
093: }
094:
095: /** Returns name of column */
096: public String getFormat() {
097: return format;
098: }
099:
100: /** Sets name of column */
101: public void setFormat(String fmt) {
102: format = fmt;
103: }
104:
105: /** Returns name of column */
106: public String getColumn() {
107: return col;
108: }
109:
110: /** Sets name of column */
111: public void setColumn(String column) {
112: col = column;
113: }
114:
115: /**
116: * Returns properties and it's values supported by this object.
117: * event.name Name of event
118: * event.column Name of column
119: * Throws DDLException if object name is not specified.
120: */
121: public Map getColumnProperties(AbstractCommand cmd)
122: throws DDLException {
123: HashMap args = new HashMap();
124: args.put("event.name", cmd.quote(name)); // NOI18N
125: args.put("event.column", cmd.quote(col)); // NOI18N
126:
127: return args;
128: }
129:
130: /** Returns string representation of event
131: * @param cmd Command context
132: */
133: public String getCommand(AbstractCommand cmd) throws DDLException {
134: Map cprops;
135: if (format == null)
136: throw new DDLException(NbBundle.getBundle(
137: "org.netbeans.lib.ddl.resources.Bundle").getString(
138: "EXC_NoFormatSpec")); //NOI18N
139: try {
140: cprops = getColumnProperties(cmd);
141: return CommandFormatter.format(format, cprops);
142: } catch (Exception e) {
143: throw new DDLException(e.getMessage());
144: }
145: }
146: }
|