1 19 20 package org.netbeans.lib.ddl.impl; 21 22 import java.text.MessageFormat ; 23 import java.util.Enumeration ; 24 import java.util.Map ; 25 import java.util.Vector ; 26 27 import org.openide.util.NbBundle; 28 29 import org.netbeans.lib.ddl.Argument; 30 import org.netbeans.lib.ddl.DDLException; 31 import org.netbeans.lib.ddl.ProcedureDescriptor; 32 33 40 41 public class CreateProcedure extends AbstractCommand implements ProcedureDescriptor 42 { 43 44 private String cat; 45 46 47 private String body; 48 49 50 private Vector args; 51 52 static final long serialVersionUID =1316633286943440734L; 53 public CreateProcedure() 54 { 55 args = new Vector (); 56 } 57 58 59 public String getCatalog() 60 { 61 return cat; 62 } 63 64 65 public void setCatalog(String cname) 66 { 67 cat = cname; 68 } 69 70 71 public String getText() 72 { 73 return body; 74 } 75 76 77 public void setText(String text) 78 { 79 body = text; 80 } 81 82 83 public Vector getArguments() 84 { 85 return args; 86 } 87 88 public Argument getArgument(int index) 89 { 90 return (Argument)args.get(index); 91 } 92 93 94 public void setArguments(Vector argarr) 95 { 96 args = argarr; 97 } 98 99 public void setArgument(int index, Argument arg) 100 { 101 args.set(index, arg); 102 } 103 104 public Argument createArgument(String name, int type, int datatype) 105 throws DDLException 106 { 107 try { 108 Map gprops = (Map )getSpecification().getProperties(); 109 Map props = (Map )getSpecification().getCommandProperties(Specification.CREATE_PROCEDURE); 110 Map bindmap = (Map )props.get("Binding"); String tname = (String )bindmap.get("ARGUMENT"); if (tname != null) { 113 Map typemap = (Map )gprops.get(tname); 114 if (typemap == null) throw new InstantiationException ( 115 MessageFormat.format( 116 NbBundle.getBundle("org.netbeans.lib.ddl.resources.Bundle").getString("EXC_UnableLocateObject"), new String [] {tname})); 118 Class typeclass = Class.forName((String )typemap.get("Class")); String format = (String )typemap.get("Format"); ProcedureArgument arg = (ProcedureArgument)typeclass.newInstance(); 121 arg.setName(name); 122 arg.setType(type); 123 arg.setDataType(datatype); 124 arg.setFormat(format); 125 return (Argument)arg; 126 } else throw new InstantiationException ( 127 MessageFormat.format( 128 NbBundle.getBundle("org.netbeans.lib.ddl.resources.Bundle").getString("EXC_UnableLocateType"), new String [] {String.valueOf(type), bindmap.toString() })); 130 } catch (Exception e) { 131 throw new DDLException(e.getMessage()); 132 } 133 } 134 135 public void addArgument(String name, int type, int datatype) 136 throws DDLException 137 { 138 Argument arg = createArgument(name, type, datatype); 139 if (arg != null) args.add(arg); 140 } 141 142 public Map getCommandProperties() 143 throws DDLException 144 { 145 Map props = (Map )getSpecification().getProperties(); 146 String cols = "", argdelim = (String )props.get("ArgumentListDelimiter"); Map cmdprops = super.getCommandProperties(); 148 149 Enumeration col_e = args.elements(); 150 while (col_e.hasMoreElements()) { 151 ProcedureArgument arg = (ProcedureArgument)col_e.nextElement(); 152 boolean inscomma = col_e.hasMoreElements(); 153 cols = cols + arg.getCommand(this)+(inscomma ? argdelim : ""); 154 } 155 156 cmdprops.put("arguments", cols); cmdprops.put("body", body); return cmdprops; 159 } 160 } 161 | Popular Tags |