KickJava   Java API By Example, From Geeks To Geeks.

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


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 import org.openide.util.NbBundle;
25
26 import org.netbeans.lib.ddl.Argument;
27 import org.netbeans.lib.ddl.DatabaseSpecification;
28 import org.netbeans.lib.ddl.DDLException;
29 import org.netbeans.lib.ddl.util.CommandFormatter;
30
31 /**
32 * Argument of procedure. Encapsulates name, type (in/out) and datatype.
33 */

34 public class ProcedureArgument implements Argument {
35     /** Argument name */
36     private String JavaDoc name;
37
38     /** Argument type */
39     private int type;
40
41     /** Argument datatype */
42     private int dtype;
43
44     /** Format */
45     private String JavaDoc format;
46
47     /** Additional properties */
48     private Map JavaDoc addprops;
49
50     public static String JavaDoc getArgumentTypeName(int type)
51     {
52         String JavaDoc typename = null;
53         switch (type) {
54         case java.sql.DatabaseMetaData.procedureColumnIn: typename = "IN"; break; // NOI18N
55
case java.sql.DatabaseMetaData.procedureColumnOut: typename = "OUT"; break; // NOI18N
56
case java.sql.DatabaseMetaData.procedureColumnInOut: typename = "INOUT"; break; // NOI18N
57
}
58
59         return typename;
60     }
61
62     /** Returns name */
63     public String JavaDoc getName()
64     {
65         return name;
66     }
67
68     /** Sets name */
69     public void setName(String JavaDoc aname)
70     {
71         name = aname;
72     }
73
74     /** Returns name of column */
75     public String JavaDoc getFormat()
76     {
77         return format;
78     }
79
80     /** Sets name of column */
81     public void setFormat(String JavaDoc fmt)
82     {
83         format = fmt;
84     }
85
86     /** Returns general property */
87     public Object JavaDoc getProperty(String JavaDoc pname)
88     {
89         return addprops.get(pname);
90     }
91
92     /** Sets general property */
93     public void setProperty(String JavaDoc pname, Object JavaDoc pval)
94     {
95         if (addprops == null) addprops = new HashMap JavaDoc();
96         addprops.put(pname, pval);
97     }
98
99     /** Describes type of argument: in, out, in/out or return value
100     * of procedure. Particular values you can find in DatabaseMetadata;
101     */

102     public int getType()
103     {
104         return type;
105     }
106
107     /** Translates numeric representation of type into IN/OUT/INOUT strings.
108     */

109     public String JavaDoc getTypeName()
110     {
111         return getArgumentTypeName(type);
112     }
113
114     /** Sets type of argument */
115     public void setType(int atype)
116     {
117         type = atype;
118     }
119
120     /** Returns datatype of argument */
121     public int getDataType()
122     {
123         return dtype;
124     }
125
126     /** Sets datatype of argument */
127     public void setDataType(int atype)
128     {
129         dtype = atype;
130     }
131
132     /**
133     * Returns properties and it's values supported by this object.
134     * argument.name Name of argument
135     * argument.type Type of argument
136     * argument.datatype Datatype of argument
137     * Throws DDLException if object name is not specified.
138     */

139     public Map JavaDoc getColumnProperties(AbstractCommand cmd) throws DDLException {
140         HashMap JavaDoc args = new HashMap JavaDoc();
141         DatabaseSpecification spec = cmd.getSpecification();
142         Map JavaDoc typemap = (Map JavaDoc)spec.getProperties().get("ProcedureArgumentMap"); // NOI18N
143
String JavaDoc typename = (String JavaDoc)typemap.get(getArgumentTypeName(type));
144         args.put("argument.name", cmd.quote(name)); // NOI18N
145
args.put("argument.type", typename); // NOI18N
146
args.put("argument.datatype", spec.getType(dtype)); // NOI18N
147
return args;
148     }
149
150     /**
151     * Returns full string representation of argument.
152     */

153     public String JavaDoc getCommand(CreateProcedure cmd)
154     throws DDLException
155     {
156         Map JavaDoc cprops;
157         if (format == null) throw new DDLException(NbBundle.getBundle("org.netbeans.lib.ddl.resources.Bundle").getString("EXC_NoFormatSpec")); // NOI18N
158
try {
159             cprops = getColumnProperties(cmd);
160             return CommandFormatter.format(format, cprops);
161         } catch (Exception JavaDoc e) {
162             throw new DDLException(e.getMessage());
163         }
164     }
165 }
166
Popular Tags