KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > dods > xslt > XSLTUtil


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  *
19  * Contributor(s):
20  *
21  * $Id: XSLTUtil.java,v 1.1 2004/09/03 13:43:14 sinisa Exp $
22  */

23
24 /*
25  * XSLTUtil.java
26  *
27  * @author Dragan Radeka
28  * @since LBS1.8
29  * @version $Revision: 1.1 $
30  *
31  */

32 package org.enhydra.dods.xslt;
33
34 import java.io.File JavaDoc;
35 import java.io.FileReader JavaDoc;
36 import java.io.FileWriter JavaDoc;
37 import java.text.ParseException JavaDoc;
38 import java.text.SimpleDateFormat JavaDoc;
39 import java.util.HashMap JavaDoc;
40 import java.util.Vector JavaDoc;
41 import org.apache.xalan.extensions.XSLProcessorContext;
42 import org.apache.xalan.templates.ElemExtensionCall;
43 import org.apache.xml.utils.WrappedRuntimeException;
44 import org.apache.xpath.objects.XString;
45 import org.ejen.util.XSLUtil;
46 import org.enhydra.dods.Common;
47
48 /**
49  *
50  * Utility class that xsl template files use during the DODS generation of sql and java files.
51  *
52  */

53 public class XSLTUtil {
54     
55     public String JavaDoc strVectorValues_1 = new String JavaDoc();
56     public String JavaDoc strVectorValues_2 = new String JavaDoc();
57     public String JavaDoc strVectorValues_3 = new String JavaDoc();
58     public String JavaDoc strVectorValues_4 = new String JavaDoc();
59     public static String JavaDoc strAttribut_0 = new String JavaDoc();
60     public static String JavaDoc strAttribut_1 = new String JavaDoc();
61     public String JavaDoc strAttribut_11 = new String JavaDoc();
62     public static String JavaDoc strAttribut_2 = new String JavaDoc();
63     public static String JavaDoc strAttribut_3 = new String JavaDoc();
64     public static String JavaDoc strAttribut_4 = new String JavaDoc();
65     public static String JavaDoc strAttribut_5 = new String JavaDoc();
66     
67     public static Vector JavaDoc vecDropPrimaryKey = new Vector JavaDoc();
68     public static Vector JavaDoc vecDropUnique = new Vector JavaDoc();
69     public static Vector JavaDoc vecDropIndex = new Vector JavaDoc();
70     public static Vector JavaDoc vecDropTable = new Vector JavaDoc();
71     
72     public static Vector JavaDoc vecXSLUtil_01 = new Vector JavaDoc();
73     public static Vector JavaDoc vecXSLUtilDrop_01 = new Vector JavaDoc();
74     public static Vector JavaDoc vecXSLUtilDrop_11 = new Vector JavaDoc();
75     public static Vector JavaDoc vecFKcreate_01 = new Vector JavaDoc();
76     public static Vector JavaDoc vecFKdrop_01 = new Vector JavaDoc();
77     public static Vector JavaDoc vecXSLUtil_02 = new Vector JavaDoc();
78     public static Vector JavaDoc vecXSLUtilDrop_02 = new Vector JavaDoc();
79     public static Vector JavaDoc vecXSLUtilDrop_12 = new Vector JavaDoc();
80     public static Vector JavaDoc vecFKcreate_02 = new Vector JavaDoc();
81     public static Vector JavaDoc vecFKdrop_02 = new Vector JavaDoc();
82     public static Vector JavaDoc vecXSLUtil_11 = new Vector JavaDoc();
83     public static Vector JavaDoc vecXSLUtil_12 = new Vector JavaDoc();
84     public static Vector JavaDoc vecXSLUtil_2 = new Vector JavaDoc();
85     public static Vector JavaDoc vecXSLUtil_3 = new Vector JavaDoc();
86     public static Vector JavaDoc vecXSLUtil_41 = new Vector JavaDoc();
87     public static Vector JavaDoc vecXSLUtil_42 = new Vector JavaDoc();
88     public static Vector JavaDoc vecXSLUtil_5 = new Vector JavaDoc();
89     public static String JavaDoc strPathProjectRoot = new String JavaDoc();
90     public static String JavaDoc strPathDomlFile = new String JavaDoc();
91     public static String JavaDoc strPathDodsConf = new String JavaDoc();
92     public static String JavaDoc strPathTypesConf = new String JavaDoc();
93     
94     public static String JavaDoc strDatabase = new String JavaDoc();
95     
96
97     private static final int minKeyLength = 4;
98     private static final int maxCounterLength = 3;
99     private static HashMap JavaDoc counterMap = new HashMap JavaDoc();
100     private static HashMap JavaDoc nameMap = new HashMap JavaDoc();
101     public static String JavaDoc dbVendorName="Standard";
102     
103     protected XSLTUtil() {}
104
105     /**
106      * Conversion of string to java.util.Date.
107      *
108      * @param s String which will be converted into Date.
109      *
110      * @return Date in which the string is transformed to.
111      */

112     public static java.util.Date JavaDoc str2date(String JavaDoc s) {
113         String JavaDoc[] formats = {
114             "yyyy-MM-dd H:mm:ss a", "yyyy MM dd H:mm:ss a", "yyyy-MM-dd H:mm:ss",
115             "yyyy MM dd H:mm:ss", "yyyy-MM-dd H:mm a", "yyyy MM dd H:mm a",
116             "yyyy-MM-dd H:mm", "yyyy MM dd H:mm", "yyyy-MM-dd", "yyyy MM dd",
117             "MMM dd yyyy h:mm:ss a", "MMM dd, yyyy h:mm:ss a",
118             "MMM dd yyyy h:mm:ss", "MMM dd, yyyy h:mm:ss", "MMM dd yyyy h:mm a",
119             "MMM dd, yyyy h:mm a", "MMM dd yyyy h:mm", "MMM dd, yyyy h:mm" };
120         java.util.Date JavaDoc ret = null;
121
122         for (int i = 0; i < formats.length; i++) {
123             SimpleDateFormat JavaDoc df = new SimpleDateFormat JavaDoc(formats[ i ]);
124
125             try {
126                 ret = df.parse(s);
127                 break;
128             } catch (ParseException JavaDoc e) {}
129         }
130         return ret;
131     }
132
133     /**
134      * Fix default values for java types. If default value isn't correct,
135      * appropriate value for specified java type will be taken.
136      *
137      * @param type Java type.
138      * @param value Default value.
139      *
140      * @return Corrected default value for specified java type.
141      */

142     public static String JavaDoc fixDefault(String JavaDoc type, String JavaDoc value) {
143         // FIX handle arrays
144
if (null == value) {
145             value = "";
146         }
147         String JavaDoc fixedValue = value;
148         String JavaDoc defaultValue = null;
149
150         if (type.endsWith("DO")) {
151             fixedValue = "null";
152         } // default value not allowed for DO refs
153
else if (type.equals("String")) {
154             if (fixedValue.length() == 0) {
155                 fixedValue = "null";
156             } else {
157                 fixedValue = "\"" + value + "\"";
158             }
159         } else if (type.equals("java.math.BigDecimal")) {
160             if (value.length() == 0) {
161                 fixedValue = "null";
162             } else {
163                 try {
164                     java.math.BigDecimal JavaDoc test = new java.math.BigDecimal JavaDoc(fixedValue);
165
166                     fixedValue = "new " + type + "(" + fixedValue + ")";
167                 } catch (RuntimeException JavaDoc e) {
168                     defaultValue = "null";
169                 }
170             }
171         } else if (type.equals("java.sql.Date")) {
172             if (value.length() == 0) {
173                 fixedValue = "null";
174             } else {
175                 try {
176                     java.util.Date JavaDoc d = str2date(fixedValue);
177                     java.sql.Date JavaDoc test = new java.sql.Date JavaDoc(d.getTime());
178
179                     fixedValue = "new " + type + "(" + fixedValue + ")";
180                 } catch (RuntimeException JavaDoc e) {
181                     defaultValue = "null";
182                 }
183             }
184         } else if (type.equals("java.sql.Time")) {
185             if (value.length() == 0) {
186                 fixedValue = "null";
187             } else {
188                 try {
189                     java.util.Date JavaDoc d = str2date(fixedValue);
190                     java.sql.Time JavaDoc test = new java.sql.Time JavaDoc(d.getTime());
191
192                     fixedValue = "new " + type + "(" + fixedValue + ")";
193                 } catch (RuntimeException JavaDoc e) {
194                     defaultValue = "null";
195                 }
196             }
197         } else if (type.equals("java.sql.Timestamp")) {
198             if (value.length() == 0) {
199                 fixedValue = "null";
200             } else {
201                 try {
202                     java.util.Date JavaDoc d = str2date(fixedValue);
203                     java.sql.Timestamp JavaDoc test = new java.sql.Timestamp JavaDoc(d.getTime());
204
205                     fixedValue = "new " + type + "(" + fixedValue + ")";
206                 } catch (RuntimeException JavaDoc e) {
207                     defaultValue = "null";
208                 }
209             }
210         } else if (type.equals("int")) {
211             if (value.length() == 0) {
212                 fixedValue = "0";
213             } else {
214                 try {
215                     int i = Integer.parseInt(value);
216                 } catch (Exception JavaDoc e) {
217                     defaultValue = "0";
218                 }
219             }
220         } else if (type.equals("boolean")) {
221             if (value.length() == 0) {
222                 fixedValue = "false";
223             } else {
224                 try {
225                     if (Boolean.valueOf(value).booleanValue()) {
226                         fixedValue = "true";
227                     } else {
228                         fixedValue = "false";
229                     }
230                 } catch (Exception JavaDoc e) {
231                     defaultValue = "false";
232                 }
233             }
234         } else if (type.equals("float")) {
235             if (value.length() == 0) {
236                 fixedValue = "0f";
237             } else {
238                 try {
239                     Float.valueOf(value);
240                     if (!value.endsWith("f")) {
241                         fixedValue = value + "f";
242                     }
243                 } catch (Exception JavaDoc e) {
244                     defaultValue = "0f";
245                 }
246             }
247         } else if (type.equals("byte")) {
248             if (value.length() == 0) {
249                 fixedValue = "0";
250             } else {
251                 try {
252                     Byte.parseByte(value);
253                 } catch (Exception JavaDoc e) {
254                     defaultValue = "0";
255                 }
256             }
257         } else if (type.equals("short")) {
258             if (value.length() == 0) {
259                 fixedValue = "0";
260             } else {
261                 try {
262                     Short.parseShort(value);
263                 } catch (Exception JavaDoc e) {
264                     defaultValue = "0";
265                 }
266             }
267         } else if (type.equals("long")) {
268             if (value.length() == 0) {
269                 fixedValue = "0L";
270             } else {
271                 try {
272                     Long.parseLong(value);
273                     if (!value.endsWith("L")) {
274                         fixedValue = value + "L";
275                     }
276                 } catch (Exception JavaDoc e) {
277                     defaultValue = "0L";
278                 }
279             }
280         } else if (type.equals("double")) {
281             if (value.length() == 0) {
282                 fixedValue = "0d";
283             } else {
284                 try {
285                     Double.valueOf(value);
286                     if (!value.endsWith("d")) {
287                         fixedValue = value + "d";
288                     }
289                 } catch (Exception JavaDoc e) {
290                     defaultValue = "0d";
291                 }
292             }
293         } else if (type.equals("byte[]")) {
294             try {
295                 // FIX
296
defaultValue = "{0}";
297             } catch (RuntimeException JavaDoc e) {}
298         } else {
299             defaultValue = "null";
300         }
301         if (null != defaultValue) {
302             fixedValue = defaultValue;
303         }
304         return fixedValue;
305     }
306
307     /**
308      * Adjust java type, cut "root." if String type begins with it.
309      *
310      * @param type Java type.
311      *
312      * @return Adjusted java type.
313      */

314     static public String JavaDoc adjustJavaType(String JavaDoc type) {
315         if (type.startsWith("root.")) {
316             return type.substring(5);
317         }
318         return type;
319     }
320
321     /**
322      * Get package name with leading "root." stripped off.
323      *
324      * @param pckg Package name.
325      *
326      * @return The packageName with leading "root." stripped off.
327      */

328     static public String JavaDoc getAdjustedPackageName(String JavaDoc pckg) {
329         if (pckg.startsWith("root.")) {
330             return pckg.substring(5);
331         }
332         return pckg;
333     }
334
335     /**
336      * Determine approperate clone method for specified member and java type.
337      *
338      * @param name Class member name (column table name).
339      * @param javaType Class member java type (column table java type).
340      * @param isObjectRef True if member is ObjectReference, otherwise false.
341      *
342      * @return Approperate clone method for specified member and java type.
343      */

344     static public String JavaDoc cloneValue(String JavaDoc name, String JavaDoc javaType, String JavaDoc isObjectRef) throws Exception JavaDoc {
345         // set the CLONE_VALUE tag
346
// boolean, byte, short, int, long, float, double
347
// String
348
// java.sql.Date, java.sql.Time, java.sql.Timestamp
349
// byte[]
350
// java.math.BigDecimal
351
//
352
String JavaDoc type = adjustJavaType(javaType);
353         String JavaDoc retClone = null;
354         String JavaDoc primitiveTypes = ":boolean:char:byte:short:int:long:float:double:";
355         String JavaDoc timeTypes = ":java.sql.Date:java.sql.Time:java.sql.Timestamp:";
356
357         if (-1 != primitiveTypes.indexOf(":" + type + ":")) {
358             retClone = name;
359         } else if (-1 != timeTypes.indexOf(":" + type + ":")) {
360             String JavaDoc shortType = type.substring(type.lastIndexOf('.') + 1);
361
362             retClone = "GenericDO.copy" + shortType + "(" + name + ")";
363         } else if (type.equals("String")) {
364             retClone = "GenericDO.copyString(" + name + ")";
365         } else if (type.equals("byte[]")) {
366             retClone = "GenericDO.copyByteArray(" + name + ")";
367         } else if (type.equals("java.math.BigDecimal")) {
368             retClone = "GenericDO.copyBigDecimal(" + name + ")";
369         } else {
370             if (isObjectRef.equals("true")) {
371                 retClone = type + ".createCopy( " + name + " )";
372             } else { // assume data type is of a cloneable class
373
retClone = "(" + type + ") " + name + ".clone()";
374             }
375         }
376         return retClone;
377     }
378
379     /**
380      * Transform java basic Objects in capital letters.
381      *
382      * @param type Class member java type (column table java_type).
383      *
384      * @return Capitalized java type.
385      */

386     static public String JavaDoc capitalizeJavaBasicObject(String JavaDoc type) throws Exception JavaDoc {
387         String JavaDoc javaType = type;
388         String JavaDoc primitiveTypes = ":boolean:char:byte:short:int:long:float:double:";
389
390         if (-1 != primitiveTypes.indexOf(":" + type + ":")) {
391             javaType = Common.capitalizeName(type);
392         }
393         return javaType;
394     }
395
396     /**
397      * Make java type from java type replacing '.' with '_'.
398      *
399      * @param type Class member java type (column table java_type).
400      *
401      * @return Java type.
402      */

403     static public String JavaDoc javaType(String JavaDoc type) {
404         String JavaDoc jt = type.replace('.', '_');
405
406         return convertArrayType(jt);
407     }
408
409     /**
410      * Make Jdbc type from java type.
411      *
412      * @param javaType Class member java type (column table java_type).
413      *
414      * @return jdbc java type.
415      */

416     static public String JavaDoc jdbcType(String JavaDoc javaType) {
417         String JavaDoc type = javaType;
418         int dot = type.lastIndexOf('.');
419
420         if (-1 != dot) {
421             type = type.substring(dot + 1);
422         }
423         String JavaDoc firstChar = type.substring(0, 1).toUpperCase();
424
425         return convertArrayType(firstChar + type.substring(1));
426     }
427
428     /**
429      * Convert java type into array type.
430      *
431      * @param type Class member java type (column table java_type).
432      *
433      * @return Converted array type.
434      */

435     static public String JavaDoc convertArrayType(String JavaDoc type) {
436         String JavaDoc at = type;
437         int i = type.indexOf("[]");
438
439         if (-1 != i) {
440             at = type.substring(0, i) + "s";
441         }
442         return at;
443     }
444
445     /**
446      * Construct an empty vector.
447      *
448      * @param xslprocessorcontext
449      * @param elemextensioncall
450      *
451      * @throws Exception
452      */

453     static public void createVector(XSLProcessorContext xslprocessorcontext, ElemExtensionCall elemextensioncall) throws Exception JavaDoc {
454         vecDropPrimaryKey.clear(); // vector with strings for droping Primary Keys
455
vecDropUnique.clear(); // vector with strings for droping Unique Constraints
456
vecDropIndex.clear(); // vector with strings for droping Indexes
457
vecDropTable.clear(); // vector with strings for droping Tables
458
vecFKcreate_01.clear();// Foreign key constraint names in SQLcreate.sql when
459
// REFERENCE_OBJECT/FOREIGN_KEY_GROUP does not exist.
460
vecFKcreate_02.clear();// Foreign key constraint names in SQLcreate.sql when
461
// REFERENCE_OBJECT/FOREIGN_KEY_GROUP exist.
462
vecFKdrop_01.clear(); // Foreign key constraint names in SQLdrop.sql when
463
// REFERENCE_OBJECT/FOREIGN_KEY_GROUP does not exist.
464
vecFKdrop_02.clear(); // Foreign key constraint in SQLdrop.sql names when
465
// REFERENCE_OBJECT/FOREIGN_KEY_GROUP exist.
466
vecXSLUtil_01.clear(); // TABLE_NAME in XML file when
467
// REFERENCE_OBJECT/FOREIGN_KEY_GROUP does not exist.
468
vecXSLUtil_02.clear(); // TABLE_NAME in XML file when
469
// REFERENCE_OBJECT/FOREIGN_KEY_GROUP exist.
470
vecXSLUtilDrop_01.clear(); // TABLE_NAME in XML file (for SQLdrop.sql) when
471
vecXSLUtilDrop_11.clear(); // COLUMN_NAME in XML file (for SQLdrop.sql) when
472
// REFERENCE_OBJECT/FOREIGN_KEY_GROUP does not exist.
473
vecXSLUtilDrop_02.clear(); // TABLE_NAME in XML file (for SQLdrop.sql) when
474
// REFERENCE_OBJECT/FOREIGN_KEY_GROUP exist.
475
vecXSLUtilDrop_12.clear(); // COLUMN_NAME in XML file (for SQLdrop.sql) when
476
// REFERENCE_OBJECT/FOREIGN_KEY_GROUP exist.
477
vecXSLUtil_11.clear(); // COLUMN/@name for each column (in XML file where
478
// REFERENCE_OBJECT/FOREIGN_KEY_GROUP does not exist) which refernces
479
// on the appropriate table in the vector vecXSLUtil_2.
480
// Values for COLUMN/@name are separated by ", ".
481
vecXSLUtil_12.clear(); // COLUMN/@name for each column (in XML file where
482
// REFERENCE_OBJECT/FOREIGN_KEY_GROUP exist) which refernces
483
// on the appropriate table in the vector vecXSLUtil_3.
484
// Values for COLUMN/@name are separated by ", ".
485
vecXSLUtil_2.clear(); // REFERENCE_OBJECT/TABLE_NAME in XML file when
486
// REFERENCE_OBJECT/FOREIGN_KEY_GROUP does not exist.
487
vecXSLUtil_3.clear(); // REFERENCE_OBJECT/TABLE_NAME in XML file when
488
// REFERENCE_OBJECT/FOREIGN_KEY_GROUP exist.
489
vecXSLUtil_41.clear(); // REFERENCE_OBJECT/FOREIGN_KEY_COLUMN_NAME for each column
490
// (in XML file where REFERENCE_OBJECT/FOREIGN_KEY_GROUP does not exist)
491
// which is referenced in to, and contains in table REFERENCE_OBJECT/TABLE_NAME
492
// in the vector vecXSLUtil_2. Values for REFERENCE_OBJECT/FOREIGN_KEY_COLUMN_NAME
493
// are separated by ", ".
494
vecXSLUtil_42.clear(); // REFERENCE_OBJECT/FOREIGN_KEY_COLUMN_NAME for each column
495
// (in XML file where REFERENCE_OBJECT/FOREIGN_KEY_GROUP exist)
496
// which is referenced in to, and contains in table REFERENCE_OBJECT/TABLE_NAME
497
// in the vector vecXSLUtil_3. Values for REFERENCE_OBJECT/FOREIGN_KEY_COLUMN_NAME
498
// are separated by ", ".
499
vecXSLUtil_5.clear(); // REFERENCE_OBJECT/FOREIGN_KEY_GROUP: every Object (String) in the vector
500
// is diferent REFERENCE_OBJECT/FOREIGN_KEY_GROUP name.
501
}
502
503     /**
504      * Construct an empty vector.
505      *
506      * @param xslprocessorcontext
507      * @param elemextensioncall
508      *
509      * @throws Exception
510      */

511     static public void resetCreateVectors(XSLProcessorContext xslprocessorcontext, ElemExtensionCall elemextensioncall) throws Exception JavaDoc {
512         vecFKcreate_01.clear();// Foreign key constraint names in SQLcreate.sql when
513
// REFERENCE_OBJECT/FOREIGN_KEY_GROUP does not exist.
514
vecFKcreate_02.clear();// Foreign key constraint names in SQLcreate.sql when
515
// REFERENCE_OBJECT/FOREIGN_KEY_GROUP exist.
516
vecXSLUtil_01.clear(); // TABLE_NAME in XML file when
517
// REFERENCE_OBJECT/FOREIGN_KEY_GROUP does not exist.
518
vecXSLUtil_02.clear(); // TABLE_NAME in XML file when
519
// REFERENCE_OBJECT/FOREIGN_KEY_GROUP exist.
520
vecXSLUtil_11.clear(); // COLUMN/@name for each column (in XML file where
521
// REFERENCE_OBJECT/FOREIGN_KEY_GROUP does not exist) which refernces
522
// on the appropriate table in the vector vecXSLUtil_2.
523
// Values for COLUMN/@name are separated by ", ".
524
vecXSLUtil_12.clear(); // COLUMN/@name for each column (in XML file where
525
// REFERENCE_OBJECT/FOREIGN_KEY_GROUP exist) which refernces
526
// on the appropriate table in the vector vecXSLUtil_3.
527
// Values for COLUMN/@name are separated by ", ".
528
vecXSLUtil_2.clear(); // REFERENCE_OBJECT/TABLE_NAME in XML file when
529
// REFERENCE_OBJECT/FOREIGN_KEY_GROUP does not exist.
530
vecXSLUtil_3.clear(); // REFERENCE_OBJECT/TABLE_NAME in XML file when
531
// REFERENCE_OBJECT/FOREIGN_KEY_GROUP exist.
532
vecXSLUtil_41.clear(); // REFERENCE_OBJECT/FOREIGN_KEY_COLUMN_NAME for each column
533
// (in XML file where REFERENCE_OBJECT/FOREIGN_KEY_GROUP does not exist)
534
// which is referenced in to, and contains in table REFERENCE_OBJECT/TABLE_NAME
535
// in the vector vecXSLUtil_2. Values for REFERENCE_OBJECT/FOREIGN_KEY_COLUMN_NAME
536
// are separated by ", ".
537
vecXSLUtil_42.clear(); // REFERENCE_OBJECT/FOREIGN_KEY_COLUMN_NAME for each column
538
// (in XML file where REFERENCE_OBJECT/FOREIGN_KEY_GROUP exist)
539
// which is referenced in to, and contains in table REFERENCE_OBJECT/TABLE_NAME
540
// in the vector vecXSLUtil_3. Values for REFERENCE_OBJECT/FOREIGN_KEY_COLUMN_NAME
541
// are separated by ", ".
542
vecXSLUtil_5.clear(); // REFERENCE_OBJECT/FOREIGN_KEY_GROUP: every Object (String) in the vector
543
// is diferent REFERENCE_OBJECT/FOREIGN_KEY_GROUP name.
544
}
545
546     /**
547      * Fill vector with the given attribute only if the given attribute
548      * isn't already in the vector.
549      *
550      * @param xslprocessorcontext
551      * @param elemextensioncall
552      *
553      * @throws Exception
554      */

555     static public void fillVector(XSLProcessorContext xslprocessorcontext, ElemExtensionCall elemextensioncall) throws Exception JavaDoc {
556         Object JavaDoc obj0 = null;
557         Object JavaDoc obj1 = null;
558         Object JavaDoc obj2 = null;
559         Object JavaDoc obj3 = null;
560         Object JavaDoc obj4 = null;
561         Object JavaDoc obj5 = null;
562         String JavaDoc s0 = XSLUtil.getAttribute(xslprocessorcontext, elemextensioncall,
563                 "attribut0", false);
564         String JavaDoc s1 = XSLUtil.getAttribute(xslprocessorcontext, elemextensioncall,
565                 "attribut1", false);
566         String JavaDoc s2 = XSLUtil.getAttribute(xslprocessorcontext, elemextensioncall,
567                 "attribut2", false);
568         String JavaDoc s3 = XSLUtil.getAttribute(xslprocessorcontext, elemextensioncall,
569                 "attribut3", false);
570         String JavaDoc s4 = XSLUtil.getAttribute(xslprocessorcontext, elemextensioncall,
571                 "attribut4", false);
572         String JavaDoc s5 = XSLUtil.getAttribute(xslprocessorcontext, elemextensioncall,
573                 "attribut5", false);
574         int i = 0;
575         String JavaDoc strTemp = new String JavaDoc();
576
577         obj5 = new XString("");
578         if (s5 != null) {
579             obj5 = XSLUtil.evaluate(xslprocessorcontext, elemextensioncall, s5);
580             if (obj5 != null) {
581                 String JavaDoc s51 = XSLUtil.getAttribute(xslprocessorcontext,
582                         elemextensioncall, "attribute5", false);
583
584                 if (s51 != null) {
585                     obj5 = new XString(s51);
586                 }
587             }
588         }
589         
590         if (s0 != null) {
591             obj0 = XSLUtil.evaluate(xslprocessorcontext, elemextensioncall, s0);
592             if (obj0 == null) {
593                 throw new WrappedRuntimeException(new IllegalArgumentException JavaDoc("bad \"select\" attribute ?!"));
594             }
595         } else {
596             String JavaDoc s01 = XSLUtil.getAttribute(xslprocessorcontext,
597                     elemextensioncall, "attribute0", false);
598
599             if (s01 != null) {
600                 obj0 = new XString(s01);
601             }
602         }
603         if (obj0 == null) {
604             obj0 = new XString("(no value)");
605         }
606             
607         if (s1 != null) {
608             obj1 = XSLUtil.evaluate(xslprocessorcontext, elemextensioncall, s1);
609             if (obj1 == null) {
610                 throw new WrappedRuntimeException(new IllegalArgumentException JavaDoc("bad \"select\" attribute ?!"));
611             }
612         } else {
613             String JavaDoc s11 = XSLUtil.getAttribute(xslprocessorcontext,
614                     elemextensioncall, "attribute1", false);
615
616             if (s11 != null) {
617                 obj1 = new XString(s11);
618             }
619         }
620         if (obj1 == null) {
621             obj1 = new XString("(no value)");
622         }
623         if (s2 != null) {
624             obj2 = XSLUtil.evaluate(xslprocessorcontext, elemextensioncall, s2);
625             if (obj2 == null) {
626                 throw new WrappedRuntimeException(new IllegalArgumentException JavaDoc("bad \"select\" attribute ?!"));
627             }
628         } else {
629             String JavaDoc s21 = XSLUtil.getAttribute(xslprocessorcontext,
630                     elemextensioncall, "attribute2", false);
631
632             if (s21 != null) {
633                 obj2 = new XString(s21);
634             }
635         }
636         if (obj2 == null) {
637             obj2 = new XString("(no value)");
638         }
639         if (s3 != null) {
640             obj3 = XSLUtil.evaluate(xslprocessorcontext, elemextensioncall, s3);
641             if (obj3 == null) {
642                 throw new WrappedRuntimeException(new IllegalArgumentException JavaDoc("bad \"select\" attribute ?!"));
643             }
644         } else {
645             String JavaDoc s31 = XSLUtil.getAttribute(xslprocessorcontext,
646                     elemextensioncall, "attribute3", false);
647
648             if (s31 != null) {
649                 obj3 = new XString(s31);
650             }
651         }
652         if (obj3 == null) {
653             obj3 = new XString("(no value)");
654         }
655         if (s4 != null) {
656             obj4 = XSLUtil.evaluate(xslprocessorcontext, elemextensioncall, s4);
657             if (obj4 == null) {
658                 throw new WrappedRuntimeException(new IllegalArgumentException JavaDoc("bad \"select\" attribute ?!"));
659             }
660         } else {
661             String JavaDoc s41 = XSLUtil.getAttribute(xslprocessorcontext,
662                     elemextensioncall, "attribute4", false);
663
664             if (s41 != null) {
665                 obj4 = new XString(s41);
666             }
667         }
668         if (obj4 == null) {
669             obj4 = new XString("(no value)");
670         } else {
671             strAttribut_0 = obj0.toString(); //tabela
672
strAttribut_1 = obj1.toString(); //kolona
673
strAttribut_2 = obj2.toString(); //referisana tabela
674
strAttribut_3 = obj3.toString(); //referisana kolona
675
strAttribut_4 = obj4.toString(); //referisana grupa
676
strAttribut_5 = obj5.toString(); //vendor
677

678             if (strAttribut_3.length() == 0) {
679                 if (strAttribut_5.equalsIgnoreCase("")) {
680                     strAttribut_3 = getDodsProperty("OidDbColumnName");
681                 } else {
682                     strAttribut_3 = getDodsProperty("OidDbColumnName",
683                             strAttribut_5);
684                 }
685             }
686             if (strAttribut_2.length() != 0 && strAttribut_4.length() == 0) {
687                 vecXSLUtil_01.addElement(strAttribut_0);
688                 vecXSLUtil_11.addElement(strAttribut_1);
689                 vecXSLUtilDrop_01.addElement(strAttribut_0);
690                 vecXSLUtilDrop_11.addElement(strAttribut_1);
691                 vecXSLUtil_2.addElement(strAttribut_2);
692                 vecXSLUtil_41.addElement(strAttribut_3);
693             }
694             if (strAttribut_2.length() != 0 && strAttribut_4.length() != 0) {
695                 if (!vecXSLUtil_5.contains(strAttribut_4)) {
696                     vecXSLUtil_02.addElement(strAttribut_0);
697                     vecXSLUtilDrop_02.addElement(strAttribut_0);
698                     vecXSLUtilDrop_12.addElement(strAttribut_1);
699                     vecXSLUtil_12.addElement(strAttribut_1);
700                     vecXSLUtil_3.addElement(strAttribut_2);
701                     vecXSLUtil_42.addElement(strAttribut_3);
702                     vecXSLUtil_5.addElement(strAttribut_4);
703                 } else {
704                     i = vecXSLUtil_5.indexOf(strAttribut_4);
705                     strTemp = vecXSLUtil_12.elementAt(i).toString();
706                     strTemp = strTemp + ", " + strAttribut_1;
707                     vecXSLUtil_12.setElementAt(strTemp, i);
708                     strTemp = vecXSLUtil_42.elementAt(i).toString();
709                     strTemp = strTemp + ", " + strAttribut_3;
710                     vecXSLUtil_42.setElementAt(strTemp, i);
711                 }
712             }
713         }
714     }
715
716     /**
717      * Fill vector with the string made from the given attribute.
718      *
719      * @param xslprocessorcontext
720      * @param elemextensioncall
721      *
722      * @throws Exception
723      */

724     static public void fillVecDropPrimaryKey(XSLProcessorContext xslprocessorcontext, ElemExtensionCall elemextensioncall) throws Exception JavaDoc {
725         
726         Object JavaDoc obj0 = null;
727         Object JavaDoc obj1 = null;
728         Object JavaDoc obj2 = null;
729         
730         String JavaDoc s0 = XSLUtil.getAttribute(xslprocessorcontext, elemextensioncall,
731                 "tableName", false);
732         String JavaDoc s1 = XSLUtil.getAttribute(xslprocessorcontext, elemextensioncall,
733                 "vendorName", false);
734                 
735         String JavaDoc s2 = XSLUtil.getAttribute(xslprocessorcontext, elemextensioncall,
736                 "columnName", false);
737
738         if (s2 != null) {
739             obj2 = XSLUtil.evaluate(xslprocessorcontext, elemextensioncall, s2);
740             if (obj2 == null) {
741                 throw new WrappedRuntimeException(new IllegalArgumentException JavaDoc("bad database vendor attribute ?!"));
742             }
743         }
744         if (obj2 == null) {
745             obj2 = new XString("(no value)");
746         }
747
748
749
750         if (s1 != null) {
751             obj1 = XSLUtil.evaluate(xslprocessorcontext, elemextensioncall, s1);
752             if (obj1 == null) {
753                 throw new WrappedRuntimeException(new IllegalArgumentException JavaDoc("bad database vendor attribute ?!"));
754             }
755         }
756         if (obj1 == null) {
757             obj1 = new XString("Standard");
758         }
759
760
761
762         if (s0 != null) {
763             obj0 = XSLUtil.evaluate(xslprocessorcontext, elemextensioncall, s0);
764             if (obj0 == null) {
765                 throw new WrappedRuntimeException(new IllegalArgumentException JavaDoc("bad \"select\" attribute ?!"));
766             }
767         }
768         if (obj0 == null) {
769             obj0 = new XString("(no value)");
770         } else {
771             String JavaDoc strTableName = obj0.toString();
772             String JavaDoc strVendorName= obj1.toString();
773             String JavaDoc strColumnName= obj2.toString();
774             String JavaDoc strTmp = "ALTER TABLE " + strTableName
775                     + " DROP CONSTRAINT " + returnFixedConstraintName(strTableName, strColumnName , "DROP", "PK", strTableName,strColumnName ,strVendorName)+ " ;";
776             vecDropPrimaryKey.addElement(strTmp);
777         }
778     }
779
780     /**
781      * Fill vector with the string made from the given attribute.
782      *
783      * @param xslprocessorcontext
784      * @param elemextensioncall
785      *
786      * @throws Exception
787      */

788     static public void fillVecDropUnique(XSLProcessorContext xslprocessorcontext, ElemExtensionCall elemextensioncall) throws Exception JavaDoc {
789         Object JavaDoc obj0 = null;
790         Object JavaDoc obj1 = null;
791         Object JavaDoc obj2 = null;
792
793         String JavaDoc s2 = XSLUtil.getAttribute(xslprocessorcontext, elemextensioncall,
794                 "columnName", false);
795
796
797         String JavaDoc s0 = XSLUtil.getAttribute(xslprocessorcontext, elemextensioncall,
798                 "tableName", false);
799
800         String JavaDoc s1 = XSLUtil.getAttribute(xslprocessorcontext, elemextensioncall,
801                 "vendorName", false);
802
803         if (s2 != null) {
804             obj2 = XSLUtil.evaluate(xslprocessorcontext, elemextensioncall, s2);
805             if (obj2 == null) {
806                 throw new WrappedRuntimeException(new IllegalArgumentException JavaDoc("bad database vendor attribute ?!"));
807             }
808         }
809         if (obj2 == null) {
810             obj2 = new XString("(no value)");
811         }
812
813         if (s1 != null) {
814             obj1 = XSLUtil.evaluate(xslprocessorcontext, elemextensioncall, s1);
815             if (obj1 == null) {
816                 throw new WrappedRuntimeException(new IllegalArgumentException JavaDoc("bad database vendor attribute ?!"));
817             }
818         }
819         if (obj1 == null) {
820             obj1 = new XString("Standard");
821         }
822
823         if (s0 != null) {
824             obj0 = XSLUtil.evaluate(xslprocessorcontext, elemextensioncall, s0);
825             if (obj0 == null) {
826                 throw new WrappedRuntimeException(new IllegalArgumentException JavaDoc("bad \"select\" attribute ?!"));
827             }
828         }
829         if (obj0 == null) {
830             obj0 = new XString("(no value)");
831         } else {
832             String JavaDoc strTableName = obj0.toString();
833             String JavaDoc strVendorName = obj1.toString();
834             String JavaDoc strColumnName = obj2.toString();
835             String JavaDoc strTmp = "ALTER TABLE " + strTableName
836                     + " DROP CONSTRAINT " + returnFixedConstraintName(strTableName , strColumnName, "DROP", "U", strTableName , strColumnName, strVendorName)+ " ;";
837             vecDropUnique.addElement(strTmp);
838         }
839     }
840
841     /**
842      * Fill vector with the string made from the given attribute.
843      *
844      * @param xslprocessorcontext
845      * @param elemextensioncall
846      *
847      * @throws Exception
848      */

849     static public void fillVecDropIndex(XSLProcessorContext xslprocessorcontext, ElemExtensionCall elemextensioncall) throws Exception JavaDoc {
850         Object JavaDoc obj0 = null;
851         Object JavaDoc obj1 = null;
852         Object JavaDoc obj2 = null;
853         
854         String JavaDoc s0 = XSLUtil.getAttribute(xslprocessorcontext, elemextensioncall,
855                 "tableName", false);
856         String JavaDoc s1 = XSLUtil.getAttribute(xslprocessorcontext, elemextensioncall,
857                 "indexName", false);
858         String JavaDoc s2 = XSLUtil.getAttribute(xslprocessorcontext, elemextensioncall,
859                 "vendorName", false);
860
861         if (s2 != null) {
862             obj2 = XSLUtil.evaluate(xslprocessorcontext, elemextensioncall, s2);
863             if (obj2 == null) {
864                 throw new WrappedRuntimeException(new IllegalArgumentException JavaDoc("bad database vendor attribute ?!"));
865             }
866         }
867         if (obj2 == null) {
868             obj2 = new XString("Standard");
869         }
870         
871         if (s0 != null) {
872             obj0 = XSLUtil.evaluate(xslprocessorcontext, elemextensioncall, s0);
873             if (obj0 == null) {
874                 throw new WrappedRuntimeException(new IllegalArgumentException JavaDoc("bad \"select\" attribute ?!"));
875             }
876         }
877         if (obj0 == null) {
878             obj0 = new XString("(no value)");
879         }
880         
881         if (s1 != null) {
882             obj1 = XSLUtil.evaluate(xslprocessorcontext, elemextensioncall, s1);
883             if (obj1 == null) {
884                 throw new WrappedRuntimeException(new IllegalArgumentException JavaDoc("bad \"select\" attribute ?!"));
885             }
886         }
887         if (obj1 == null) {
888             obj1 = new XString("(no value)");
889         } else {
890             String JavaDoc strTableName = obj0.toString();
891             String JavaDoc strIndexName = obj1.toString();
892             String JavaDoc strVendorName = obj2.toString();
893             String JavaDoc strTmp = "DROP INDEX " + returnFixedConstraintName(strTableName, strIndexName ,"DROP", "I", strTableName, strIndexName , strVendorName)+ " ;";
894
895             vecDropIndex.addElement(strTmp);
896         }
897     }
898
899     /**
900      * Fill vector with the string made from the given attribute.
901      *
902      * @param xslprocessorcontext
903      * @param elemextensioncall
904      *
905      * @throws Exception
906      */

907     static public void fillVecDropTable(XSLProcessorContext xslprocessorcontext, ElemExtensionCall elemextensioncall) throws Exception JavaDoc {
908         Object JavaDoc obj0 = null;
909         String JavaDoc s0 = XSLUtil.getAttribute(xslprocessorcontext, elemextensioncall,
910                 "tableName", false);
911
912         if (s0 != null) {
913             obj0 = XSLUtil.evaluate(xslprocessorcontext, elemextensioncall, s0);
914             if (obj0 == null) {
915                 throw new WrappedRuntimeException(new IllegalArgumentException JavaDoc("bad \"select\" attribute ?!"));
916             }
917         }
918         if (obj0 == null) {
919             obj0 = new XString("(no value)");
920         } else {
921             String JavaDoc strTmp = "DROP TABLE " + obj0.toString() + " ;";
922
923             vecDropTable.addElement(strTmp);
924         }
925     }
926
927     /**
928      * Get all constraints defined in this table.
929      *
930      * @return All constraints defined in this table.
931      *
932      * @throws Exception
933      */

934     static public String JavaDoc returnForeignKeyConstraints(String JavaDoc dbVendor) throws Exception JavaDoc {
935         String JavaDoc strTemp11 = new String JavaDoc();
936         String JavaDoc strTemp41 = new String JavaDoc();
937         String JavaDoc strTemp = "";
938         boolean delCascade = Common.getDodsConfProperty("DeleteCascade", dbVendor).equalsIgnoreCase("true");
939         String JavaDoc keyLengthStr = Common.getDodsConfProperty("ConstraintNameLength", dbVendor);
940         String JavaDoc tempName = null;
941         int keyLength = -1;
942         if (keyLengthStr!=null){
943              keyLength = new Integer JavaDoc(keyLengthStr).intValue();
944         }
945         int i = 0;
946         int j = 0;
947
948         // make unique name for Foreign Key constraint when FOREIGN_KEY_GROUP does not exist:
949
// "FK_" + TABLE_NAME + "_" + n ; where is int n > 0.
950
if (vecXSLUtil_01.size() > 0) {
951             i = 0;
952 // tempName = vecXSLUtil_01.elementAt(i).toString() + "_"
953
// + vecXSLUtil_11.elementAt(i).toString();
954
tempName = returnFixedConstraintName(vecXSLUtil_01.elementAt(i).toString(),vecXSLUtil_11.elementAt(i).toString(),"CREATE","FK",vecXSLUtil_01.elementAt(i).toString(),vecXSLUtil_11.elementAt(i).toString(),dbVendor);
955 // if ((tempName.length()>keyLength)&&(keyLength>=minKeyLength)){
956
// tempName=tempName.substring(0,keyLength-maxCounterLength)+"_1";
957
// }
958
strTemp = " CONSTRAINT " + tempName
959                     + " FOREIGN KEY (" + vecXSLUtil_11.elementAt(i).toString()
960                     + ") REFERENCES " + vecXSLUtil_2.get(i).toString() + " ("
961                     + vecXSLUtil_41.get(i).toString() + ")";
962             if (delCascade) {
963                 strTemp = strTemp + " ON DELETE CASCADE ,\n";
964             } else {
965                 strTemp = strTemp + " ,\n";
966             }
967             vecFKcreate_01.addElement(strTemp);
968             i = 1;
969             j = 2;
970             while (i < vecXSLUtil_01.size()) {
971                 strTemp = vecXSLUtil_01.elementAt(i - 1).toString();
972                 if (strTemp.equals(vecXSLUtil_01.elementAt(i).toString())) {
973 // tempName = vecXSLUtil_01.elementAt(i).toString() + "_"
974
// + vecXSLUtil_11.elementAt(i).toString();
975
tempName = returnFixedConstraintName(vecXSLUtil_01.elementAt(i).toString(),vecXSLUtil_11.elementAt(i).toString(),"CREATE","FK",vecXSLUtil_01.elementAt(i).toString(),vecXSLUtil_11.elementAt(i).toString(),dbVendor);
976                               
977 // if ((tempName.length()>keyLength)&&(keyLength>=minKeyLength)){
978
// tempName=tempName.substring(0,keyLength-maxCounterLength)+"_"+j;
979
// }
980
strTemp = " CONSTRAINT " + tempName
981                             + " FOREIGN KEY ("
982                             + vecXSLUtil_11.elementAt(i).toString()
983                             + ") REFERENCES " + vecXSLUtil_2.get(i).toString()
984                             + " (" + vecXSLUtil_41.get(i).toString() + ")";
985                     if (delCascade) {
986                         strTemp = strTemp + " ON DELETE CASCADE ,\n";
987                     } else {
988                         strTemp = strTemp + " ,\n";
989                     }
990                     vecFKcreate_01.addElement(strTemp);
991                 } else {
992                     j = 1;
993                     tempName = returnFixedConstraintName(vecXSLUtil_01.elementAt(i).toString(),vecXSLUtil_11.elementAt(i).toString(),"CREATE","FK",vecXSLUtil_01.elementAt(i).toString(),vecXSLUtil_11.elementAt(i).toString(),dbVendor);
994
995                     strTemp = " CONSTRAINT " + tempName
996                               + " FOREIGN KEY ("
997                               + vecXSLUtil_11.elementAt(i).toString()
998                               + ") REFERENCES " + vecXSLUtil_2.get(i).toString()
999                               + " (" + vecXSLUtil_41.get(i).toString() + ")";
1000                    if (delCascade) {
1001                        strTemp = strTemp + " ON DELETE CASCADE ,\n";
1002                    } else {
1003                        strTemp = strTemp + " ,\n";
1004                    }
1005                    vecFKcreate_01.addElement(strTemp);
1006                }
1007                j++;
1008                i++;
1009            } // end while
1010
} // end if
1011
// make unique name for Foreign Key constraint when FOREIGN_KEY_GROUP exist:
1012
// "FKG_" + TABLE_NAME + "_" + n ; where is int n > 0.
1013
// //"FKG_" + TABLE_NAME + "_" + REFERENCE_OBJECT/FOREIGN_KEY_GROUP
1014
if (vecXSLUtil_02.size() > 0) {
1015            i = 0;
1016// tempName = vecXSLUtil_02.elementAt(i).toString();
1017
// if ((tempName.length()>keyLength)&&(keyLength>=minKeyLength)){
1018
// tempName=tempName.substring(0,keyLength-maxCounterLength);
1019
// }
1020
tempName = returnFixedConstraintName("FKG", vecXSLUtil_02.elementAt(i).toString(),"CREATE","FKG","FKG", vecXSLUtil_02.elementAt(i).toString(),dbVendor);
1021
1022            strTemp = " CONSTRAINT "
1023                    + tempName
1024                    + " FOREIGN KEY (" + vecXSLUtil_12.elementAt(i).toString()
1025                    + ") REFERENCES " + vecXSLUtil_3.get(i).toString() + " ("
1026                    + vecXSLUtil_42.get(i).toString() + ")";
1027            if (delCascade) {
1028                strTemp = strTemp + " ON DELETE CASCADE ,\n";
1029            } else {
1030                strTemp = strTemp + " ,\n";
1031            }
1032            vecFKcreate_02.addElement(strTemp);
1033            i = 1;
1034            j = 2;
1035            while (i < vecXSLUtil_02.size()) {
1036                strTemp = vecXSLUtil_02.elementAt(i - 1).toString();
1037                if (strTemp.equals(vecXSLUtil_02.elementAt(i).toString())) {
1038// tempName = vecXSLUtil_02.elementAt(i).toString();
1039
// if ((tempName.length()>keyLength)&&(keyLength>=minKeyLength)){
1040
// tempName=tempName.substring(0,keyLength-maxCounterLength);
1041
// }
1042
tempName = returnFixedConstraintName("FKG", vecXSLUtil_02.elementAt(i).toString(),"CREATE","FKG","FKG", vecXSLUtil_02.elementAt(i).toString(),dbVendor);
1043
1044                    strTemp = " CONSTRAINT "
1045                            + tempName
1046                            + " FOREIGN KEY ("
1047                            + vecXSLUtil_12.elementAt(i).toString()
1048                            + ") REFERENCES " + vecXSLUtil_3.get(i).toString()
1049                            + " (" + vecXSLUtil_42.get(i).toString() + ")";
1050                    if (delCascade) {
1051                        strTemp = strTemp + " ON DELETE CASCADE ,\n";
1052                    } else {
1053                        strTemp = strTemp + " ,\n";
1054                    }
1055                    vecFKcreate_02.addElement(strTemp);
1056                } else {
1057                    j = 1;
1058// tempName = vecXSLUtil_02.elementAt(i).toString();
1059
// if ((tempName.length()>keyLength)&&(keyLength>=minKeyLength)){
1060
// tempName=tempName.substring(0,keyLength-maxCounterLength);
1061
// }
1062
tempName = returnFixedConstraintName("FKG", vecXSLUtil_02.elementAt(i).toString(),"CREATE","FKG","FKG", vecXSLUtil_02.elementAt(i).toString(),dbVendor);
1063
1064                    strTemp = " CONSTRAINT "
1065                            + tempName + "_" + j
1066                            + " FOREIGN KEY ("
1067                            + vecXSLUtil_12.elementAt(i).toString()
1068                            + ") REFERENCES " + vecXSLUtil_3.get(i).toString()
1069                            + " (" + vecXSLUtil_42.get(i).toString() + ")";
1070                    if (delCascade) {
1071                        strTemp = strTemp + " ON DELETE CASCADE ,\n";
1072                    } else {
1073                        strTemp = strTemp + " ,\n";
1074                    }
1075                    vecFKcreate_02.addElement(strTemp);
1076                }
1077                j++;
1078                i++;
1079            } // end while
1080
} // end if
1081
int i_fk = vecFKcreate_01.size();
1082        int i_fkg = vecFKcreate_02.size();
1083
1084        strTemp = "";
1085        if (i_fk != 0) {
1086            i = 0;
1087            while (i < i_fk) {
1088                strTemp = strTemp + vecFKcreate_01.elementAt(i).toString();
1089                i++;
1090            }
1091        }
1092        
1093        if (i_fkg != 0) {
1094            i = 0;
1095            while (i < i_fkg) {
1096                strTemp = strTemp + vecFKcreate_02.elementAt(i).toString();
1097                i++;
1098            }
1099        }
1100        
1101        if (strTemp.length() != 0) {
1102            strTemp = strTemp.substring(0, strTemp.length() - 3);
1103        }
1104        return strTemp;
1105    }
1106    
1107// /**
1108
// * Get all constraints defined in this table.
1109
// *
1110
// * @return All constraints defined in this table.
1111
// *
1112
// * @throws Exception
1113
// */
1114
// static public String returnForeignKeyConstraints() throws Exception {
1115
// String strTemp11 = new String();
1116
// String strTemp41 = new String();
1117
// String strTemp = "";
1118
//
1119
// int i = 0;
1120
// int j = 0;
1121
//
1122
// // make unique name for Foreign Key constraint when FOREIGN_KEY_GROUP does not exist:
1123
// // "FK_" + TABLE_NAME + "_" + n ; where is int n > 0.
1124
// if (vecXSLUtil_01.size() > 0) {
1125
// i = 0;
1126
// strTemp = " CONSTRAINT "
1127
// + vecXSLUtil_01.elementAt(i).toString() + "_"
1128
// + vecXSLUtil_11.elementAt(i).toString()
1129
// + " FOREIGN KEY (" + vecXSLUtil_11.elementAt(i).toString()
1130
// + ") REFERENCES " + vecXSLUtil_2.get(i).toString() + " ("
1131
// + vecXSLUtil_41.get(i).toString() + ")";
1132
// strTemp = strTemp + " ,\n";
1133
// vecFKcreate_01.addElement(strTemp);
1134
// i = 1;
1135
// j = 2;
1136
// while (i < vecXSLUtil_01.size()) {
1137
// strTemp = vecXSLUtil_01.elementAt(i - 1).toString();
1138
// if (strTemp.equals(vecXSLUtil_01.elementAt(i).toString())) {
1139
// strTemp = " CONSTRAINT "
1140
// + vecXSLUtil_01.elementAt(i).toString() + "_"
1141
// + vecXSLUtil_11.elementAt(i).toString()
1142
// + " FOREIGN KEY ("
1143
// + vecXSLUtil_11.elementAt(i).toString()
1144
// + ") REFERENCES " + vecXSLUtil_2.get(i).toString()
1145
// + " (" + vecXSLUtil_41.get(i).toString() + ")";
1146
// strTemp = strTemp + " ,\n";
1147
// vecFKcreate_01.addElement(strTemp);
1148
// } else {
1149
// j = 1;
1150
// strTemp = " CONSTRAINT "
1151
// + vecXSLUtil_01.elementAt(i).toString() + "_"
1152
// + vecXSLUtil_11.elementAt(i).toString()
1153
// + " FOREIGN KEY ("
1154
// + vecXSLUtil_11.elementAt(i).toString()
1155
// + ") REFERENCES " + vecXSLUtil_2.get(i).toString()
1156
// + " (" + vecXSLUtil_41.get(i).toString() + ")";
1157
// strTemp = strTemp + " ,\n";
1158
// vecFKcreate_01.addElement(strTemp);
1159
// }
1160
// j++;
1161
// i++;
1162
// } // end while
1163
// } // end if
1164
// // make unique name for Foreign Key constraint when FOREIGN_KEY_GROUP exist:
1165
// // "FKG_" + TABLE_NAME + "_" + n ; where is int n > 0.
1166
// // //"FKG_" + TABLE_NAME + "_" + REFERENCE_OBJECT/FOREIGN_KEY_GROUP
1167
// if (vecXSLUtil_02.size() > 0) {
1168
// i = 0;
1169
// strTemp = " CONSTRAINT FKG_"
1170
// + vecXSLUtil_02.elementAt(i).toString() + "_1"
1171
// + " FOREIGN KEY (" + vecXSLUtil_12.elementAt(i).toString()
1172
// + ") REFERENCES " + vecXSLUtil_3.get(i).toString() + " ("
1173
// + vecXSLUtil_42.get(i).toString() + ")";
1174
// strTemp = strTemp + " ,\n";
1175
// vecFKcreate_02.addElement(strTemp);
1176
// i = 1;
1177
// j = 2;
1178
// while (i < vecXSLUtil_02.size()) {
1179
// strTemp = vecXSLUtil_02.elementAt(i - 1).toString();
1180
// if (strTemp.equals(vecXSLUtil_02.elementAt(i).toString())) {
1181
// strTemp = " CONSTRAINT FKG_"
1182
// + vecXSLUtil_02.elementAt(i).toString() + "_" + j
1183
// + " FOREIGN KEY ("
1184
// + vecXSLUtil_12.elementAt(i).toString()
1185
// + ") REFERENCES " + vecXSLUtil_3.get(i).toString()
1186
// + " (" + vecXSLUtil_42.get(i).toString() + ")";
1187
// strTemp = strTemp + " ,\n";
1188
// vecFKcreate_02.addElement(strTemp);
1189
// } else {
1190
// j = 1;
1191
// strTemp = " CONSTRAINT FKG_"
1192
// + vecXSLUtil_02.elementAt(i).toString() + "_" + j
1193
// + " FOREIGN KEY ("
1194
// + vecXSLUtil_12.elementAt(i).toString()
1195
// + ") REFERENCES " + vecXSLUtil_3.get(i).toString()
1196
// + " (" + vecXSLUtil_42.get(i).toString() + ")";
1197
// strTemp = strTemp + " ,\n";
1198
// vecFKcreate_02.addElement(strTemp);
1199
// }
1200
// j++;
1201
// i++;
1202
// } // end while
1203
// } // end if
1204
// int i_fk = vecFKcreate_01.size();
1205
// int i_fkg = vecFKcreate_02.size();
1206
//
1207
// strTemp = "";
1208
// if (i_fk != 0) {
1209
// i = 0;
1210
// while (i < i_fk) {
1211
// strTemp = strTemp + vecFKcreate_01.elementAt(i).toString();
1212
// i++;
1213
// }
1214
// }
1215
//
1216
// if (i_fkg != 0) {
1217
// i = 0;
1218
// while (i < i_fkg) {
1219
// strTemp = strTemp + vecFKcreate_02.elementAt(i).toString();
1220
// i++;
1221
// }
1222
// }
1223
//
1224
// if (strTemp.length() != 0) {
1225
// strTemp = strTemp.substring(0, strTemp.length() - 3);
1226
// }
1227
// return strTemp;
1228
// }
1229

1230    /**
1231     * Create SQLdrop.sql file in which are all SQL DROP statements.
1232     * There is one SQLdrop.sql file for entire database.
1233     *
1234     * @param xslprocessorcontext
1235     * @param elemextensioncall
1236     *
1237     * @throws Exception
1238     */

1239    static public void createSQLdrop(XSLProcessorContext xslprocessorcontext, ElemExtensionCall elemextensioncall) throws Exception JavaDoc {
1240        String JavaDoc strTmp = new String JavaDoc();
1241        String JavaDoc strTemp = new String JavaDoc();
1242        String JavaDoc strProjectRoot = Common.getProjectRoot();
1243        String JavaDoc strFileSep = System.getProperty("file.separator");
1244        String JavaDoc strSqlDrop = new String JavaDoc();
1245
1246        strSqlDrop = strProjectRoot + strFileSep + "SQLdrop.sql";
1247        File JavaDoc fileSqlDrop = new File JavaDoc(strSqlDrop);
1248
1249        if (fileSqlDrop.exists()) {
1250            fileSqlDrop.delete();
1251        }
1252        fileSqlDrop.createNewFile();
1253        FileReader JavaDoc fileRead;
1254        FileWriter JavaDoc fileWrite = new FileWriter JavaDoc(fileSqlDrop);
1255        int i = 0;
1256        int j = 0;
1257
1258        // make unique name for Foreign Key constraint when FOREIGN_KEY_GROUP does not exist:
1259
// "FK_" + TABLE_NAME + "_" + n ; where is int n > 0.
1260
if (vecXSLUtilDrop_01.size() > 0) {
1261            i = 0;
1262            strTemp = vecXSLUtilDrop_01.elementAt(i).toString();
1263            strTemp = returnFixedConstraintName(vecXSLUtilDrop_01.elementAt(i).toString(),vecXSLUtilDrop_11.elementAt(i).toString(),"DROP","FK",vecXSLUtilDrop_01.elementAt(i).toString(),vecXSLUtilDrop_11.elementAt(i).toString(),dbVendorName);
1264
1265            vecFKdrop_01.addElement(strTemp);
1266            i = 1;
1267            j = 2;
1268            while (i < vecXSLUtilDrop_01.size()) {
1269                strTemp = vecXSLUtilDrop_01.elementAt(i - 1).toString();
1270                if (strTemp.equals(vecXSLUtilDrop_01.elementAt(i).toString())) {
1271                    strTemp = vecXSLUtilDrop_01.elementAt(i).toString();
1272                    strTemp = returnFixedConstraintName(strTemp,vecXSLUtilDrop_11.elementAt(i).toString(),"DROP","FK",strTemp,vecXSLUtilDrop_11.elementAt(i).toString(),dbVendorName);
1273                    vecFKdrop_01.addElement(strTemp);
1274                } else {
1275                    j = 1;
1276                    strTemp = vecXSLUtilDrop_01.elementAt(i).toString();
1277                    strTemp = returnFixedConstraintName(strTemp,vecXSLUtilDrop_11.elementAt(i).toString(),"DROP","FK",strTemp,vecXSLUtilDrop_11.elementAt(i).toString(),dbVendorName);
1278                    vecFKdrop_01.addElement(strTemp);
1279                }
1280                j++;
1281                i++;
1282            } // end while
1283
} // end if
1284
// make unique name for Foreign Key constraint when FOREIGN_KEY_GROUP exist:
1285
// "FK_" + TABLE_NAME + "_" + n ; where is int n > 0.
1286
// //"FK_" + TABLE_NAME + "_" + REFERENCE_OBJECT/FOREIGN_KEY_GROUP
1287
if (vecXSLUtilDrop_02.size() > 0) {
1288            i = 0;
1289            strTemp = vecXSLUtilDrop_02.elementAt(i).toString() + "_1";
1290            vecFKdrop_02.addElement(strTemp);
1291            i = 1;
1292            j = 2;
1293            while (i < vecXSLUtilDrop_02.size()) {
1294                strTemp = vecXSLUtilDrop_02.elementAt(i - 1).toString();
1295                if (strTemp.equals(vecXSLUtilDrop_02.elementAt(i).toString())) {
1296                    strTemp = vecXSLUtilDrop_02.elementAt(i).toString();
1297                    strTemp = returnFixedConstraintName(strTemp,vecXSLUtilDrop_12.elementAt(i).toString(),"DROP","FKG",strTemp,vecXSLUtilDrop_12.elementAt(i).toString(),dbVendorName);
1298                    vecFKdrop_02.addElement(strTemp);
1299                } else {
1300                    j = 1;
1301                    strTemp = vecXSLUtilDrop_02.elementAt(i).toString();
1302                    strTemp = returnFixedConstraintName(strTemp,vecXSLUtilDrop_12.elementAt(i).toString(),"DROP","FKG",strTemp,vecXSLUtilDrop_12.elementAt(i).toString(),dbVendorName);
1303                    vecFKdrop_02.addElement(strTemp);
1304                }
1305                j++;
1306                i++;
1307            } // end while
1308
} // end if
1309
// DROP CONSTRAINT Foreign Key when FOREIGN_KEY_GROUP does not exist
1310
i = 0;
1311        if (vecXSLUtilDrop_01.size() != 0) {
1312            while (i < vecXSLUtilDrop_01.size()) {
1313                StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
1314
1315                buf.append("ALTER TABLE ");
1316                buf.append(vecXSLUtilDrop_01.elementAt(i).toString());
1317                buf.append(" DROP CONSTRAINT ");
1318                buf.append(vecFKdrop_01.get(i).toString());
1319                buf.append(" ;");
1320                fileWrite.write(buf.toString());
1321                fileWrite.write(13);
1322                fileWrite.write(10); // new line
1323
i++;
1324            }
1325            fileWrite.write(13);
1326            fileWrite.write(10); // new line
1327
}
1328        // DROP CONSTRAINT Foreign Key when FOREIGN_KEY_GROUP exist
1329
i = 0;
1330        if (vecXSLUtilDrop_02.size() != 0) {
1331            while (i < vecXSLUtilDrop_02.size()) {
1332                StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
1333
1334                buf.append("ALTER TABLE ");
1335                buf.append(vecXSLUtilDrop_02.elementAt(i).toString());
1336                buf.append(" DROP CONSTRAINT ");
1337                buf.append(vecFKdrop_02.get(i).toString());
1338                buf.append(" ;");
1339                fileWrite.write(buf.toString());
1340                fileWrite.write(13);
1341                fileWrite.write(10); // new line
1342
i++;
1343            }
1344            fileWrite.write(13);
1345            fileWrite.write(10); // new line
1346
}
1347        // DROP Unique Constraints
1348
i = 0;
1349        if (vecDropUnique.size() != 0) {
1350            while (i < vecDropUnique.size()) {
1351                StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
1352
1353                buf.append(vecDropUnique.elementAt(i).toString());
1354                fileWrite.write(buf.toString());
1355                fileWrite.write(13);
1356                fileWrite.write(10); // new line
1357
i++;
1358            }
1359            fileWrite.write(13);
1360            fileWrite.write(10); // new line
1361
}
1362        // DROP INDEX
1363
i = 0;
1364        if (vecDropIndex.size() != 0) {
1365            while (i < vecDropIndex.size()) {
1366                StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
1367
1368                buf.append(vecDropIndex.elementAt(i).toString());
1369                fileWrite.write(buf.toString());
1370                fileWrite.write(13);
1371                fileWrite.write(10); // new line
1372
i++;
1373            }
1374            fileWrite.write(13);
1375            fileWrite.write(10); // new line
1376
}
1377        // DROP TABLE
1378
i = 0;
1379        if (vecDropTable.size() != 0) {
1380            while (i < vecDropTable.size()) {
1381                StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
1382
1383                buf.append(vecDropTable.elementAt(i).toString());
1384                fileWrite.write(buf.toString());
1385                fileWrite.write(13);
1386                fileWrite.write(10); // new line
1387
i++;
1388            }
1389            fileWrite.write(13);
1390            fileWrite.write(10); // new line
1391
fileWrite.write("DROP TABLE objectid ;");
1392            fileWrite.write(13);
1393            fileWrite.write(10); // new line
1394
}
1395        fileWrite.close();
1396    }
1397
1398    /**
1399     * Load doml file in memory structure.
1400     *
1401     * @param xslprocessorcontext
1402     * @param elemextensioncall
1403     *
1404     * @throws Exception
1405     */

1406    public static void fillHashtables(XSLProcessorContext xslprocessorcontext, ElemExtensionCall elemextensioncall) throws Exception JavaDoc {
1407        Object JavaDoc obj1 = null;
1408        String JavaDoc s1 = XSLUtil.getAttribute(xslprocessorcontext, elemextensioncall,
1409                "database", false);
1410
1411        if (s1 != null) {
1412            obj1 = XSLUtil.evaluate(xslprocessorcontext, elemextensioncall, s1);
1413            if (obj1 == null) {
1414                throw new WrappedRuntimeException(new IllegalArgumentException JavaDoc("bad \"select\" attribute ?!"));
1415            }
1416        }
1417        strDatabase = obj1.toString();
1418    }
1419
1420    /**
1421     *
1422     *
1423     * @param strUsedDatabase
1424     * @param s2
1425     *
1426     * @throws Exception
1427     */

1428    public static void fillHashtables(String JavaDoc strUsedDatabase, String JavaDoc s2) throws Exception JavaDoc {
1429        strDatabase = strUsedDatabase;
1430        
1431    }
1432
1433    /**
1434     *
1435     *
1436     * @param strKey
1437     *
1438     * @param dbVendor
1439     *
1440     * @throws Exception
1441     */

1442    public static String JavaDoc getDodsProperty(String JavaDoc strKey, String JavaDoc dbVendor) throws Exception JavaDoc {
1443        String JavaDoc strTemp;
1444
1445        if (dbVendor != null) {
1446            strTemp = Common.getDodsConfProperty(strKey, dbVendor);
1447        } else {
1448            strTemp = Common.getDodsConfProperty(strKey, strDatabase);
1449        }
1450        return strTemp;
1451    }
1452    
1453    /**
1454     *
1455     *
1456     * @param strKey
1457     *
1458     * @throws Exception
1459     */

1460    public static String JavaDoc getDodsProperty(String JavaDoc strKey) throws Exception JavaDoc {
1461        String JavaDoc strTemp = Common.getDodsConfProperty(strKey, strDatabase);
1462
1463        return strTemp;
1464    }
1465
1466    /**
1467     *
1468     *
1469     * @param strKey
1470     *
1471     * @throws Exception
1472     */

1473    public static String JavaDoc getDataType(String JavaDoc strKey) throws Exception JavaDoc {
1474        String JavaDoc strDataType = "JDBCtype/" + strKey;
1475
1476        strDataType = getDodsProperty(strDataType);
1477        return strDataType;
1478    }
1479    
1480    /**
1481     *
1482     *
1483     * @param strKey
1484     * @param dbVendor
1485     * @throws Exception
1486     */

1487    public static String JavaDoc getDataType(String JavaDoc strKey, String JavaDoc dbVendor) throws Exception JavaDoc {
1488        String JavaDoc strDataType = "JDBCtype/" + strKey;
1489
1490        strDataType = getDodsProperty(strDataType, dbVendor);
1491        return strDataType;
1492    }
1493    
1494    /**
1495     * Create SQLcreate.sql file where are all SQL CREATE statements.
1496     * This one SQLcreate.sql file is for entire database.
1497     *
1498     * @param xslprocessorcontext
1499     * @param elemextensioncall
1500     *
1501     * @throws Exception
1502     */

1503    public static void createSQLcomplete(XSLProcessorContext xslprocessorcontext, ElemExtensionCall elemextensioncall) throws Exception JavaDoc {
1504        String JavaDoc strProjectRoot = Common.getProjectRoot();
1505        Vector JavaDoc vecUrlOfSqlFiles = new Vector JavaDoc();
1506
1507        vecUrlOfSqlFiles = findSQLFiles(new File JavaDoc(strProjectRoot));
1508        String JavaDoc strUrlOfSqlFile;
1509        String JavaDoc strFileSep = System.getProperty("file.separator");
1510        String JavaDoc strSqlDrop = new String JavaDoc();
1511
1512        strSqlDrop = strProjectRoot + strFileSep + "SQLdrop.sql";
1513        strSqlDrop = strSqlDrop.replace('/', '\\');
1514        strSqlDrop = strSqlDrop.replace('\\', '/');
1515        if (System.getProperty("os.name").toLowerCase().startsWith("win")) {
1516            if (strFileSep != "/") {
1517                strSqlDrop = strSqlDrop.replace('/', '\\');
1518            }
1519        }
1520        String JavaDoc strSqlComplete = new String JavaDoc();
1521
1522        strSqlComplete = strProjectRoot + strFileSep + "SQLcreate.sql";
1523        strSqlComplete = strSqlComplete.replace('/', '\\');
1524        strSqlComplete = strSqlComplete.replace('\\', '/');
1525        if (System.getProperty("os.name").toLowerCase().startsWith("win")) {
1526            if (strFileSep != "/") {
1527                strSqlComplete = strSqlComplete.replace('/', '\\');
1528            }
1529        }
1530        File JavaDoc fileSqlComplete = new File JavaDoc(strSqlComplete);
1531
1532        if (fileSqlComplete.exists()) {
1533            fileSqlComplete.delete();
1534        }
1535        fileSqlComplete.createNewFile();
1536        FileReader JavaDoc fileRead;
1537        FileWriter JavaDoc fileWrite = new FileWriter JavaDoc(fileSqlComplete);
1538        int i = 0;
1539        int ii;
1540
1541        while (i < vecUrlOfSqlFiles.size()) {
1542            strUrlOfSqlFile = vecUrlOfSqlFiles.get(i).toString();
1543            if (!strUrlOfSqlFile.equalsIgnoreCase(strSqlDrop)
1544                    && !strUrlOfSqlFile.equalsIgnoreCase(strSqlComplete)) {
1545                fileRead = new FileReader JavaDoc(strUrlOfSqlFile);
1546                ii = fileRead.read();
1547                while (ii != -1) {
1548                    fileWrite.write(ii);
1549                    ii = fileRead.read();
1550                }
1551                fileRead.close();
1552            }
1553            i++;
1554        }
1555        fileWrite.write(13);
1556        fileWrite.write(10); // new line
1557
fileWrite.write(13);
1558        fileWrite.write(10); // new line
1559
fileWrite.write(13);
1560        fileWrite.write(10); // new line
1561
fileWrite.write("create table objectid");
1562        fileWrite.write(13);
1563        fileWrite.write(10); // new line
1564
fileWrite.write("(");
1565        fileWrite.write(13);
1566        fileWrite.write(10); // new line
1567
fileWrite.write(" next " + getDodsProperty("OidDbType")
1568                + " NOT NULL PRIMARY KEY");
1569        fileWrite.write(13);
1570        fileWrite.write(10); // new line
1571
fileWrite.write(");");
1572        fileWrite.write(13);
1573        fileWrite.write(10); // new line
1574
fileWrite.close();
1575    }
1576
1577    /**
1578     * Method findSQLFiles finds all SQL files (all files which contain ".sql" in their name) in a working directory and
1579     * all its subdirecories and puts their URL's into Vector.
1580     * If there is an error Exception "Ecxeption" is thrown.
1581     *
1582     * @param fDirectory The URL of the working directory.
1583     *
1584     * @return Vector The URLs of all output SQL files in working directory and in all its subdirectories.
1585     *
1586     * @throws Exception.
1587     */

1588    public static Vector JavaDoc findSQLFiles(File JavaDoc fDirectory) {
1589        Vector JavaDoc vPathDirectory = new Vector JavaDoc();
1590        File JavaDoc[] arrFileSql;
1591
1592        try {
1593            if ((arrFileSql = fDirectory.listFiles()) != null) {
1594                int i = 0;
1595
1596                while (i < arrFileSql.length) {
1597                    if (arrFileSql[i].isDirectory()) {
1598                        Vector JavaDoc vTemp = findSQLFiles(arrFileSql[i]);
1599
1600                        for (int j = 0; j < vTemp.size(); j++) {
1601                            vPathDirectory.addElement(vTemp.get(j));
1602                        }
1603                    } else if (arrFileSql[i].toString().toUpperCase().indexOf(".SQL")
1604                            != -1) {
1605                        vPathDirectory.addElement(arrFileSql[i]);
1606                    }
1607                    i++;
1608                }
1609            } else {
1610                System.out.println("Directory " + fDirectory.toString()
1611                        + " doesn't exist");
1612            }
1613        } catch (Exception JavaDoc se) {
1614            System.out.println("error " + se.getMessage());
1615        }
1616        return vPathDirectory;
1617    }
1618    
1619    /**
1620     * Fix default values for SQL data types. If default value isn't correct,
1621     * appropriate value for specified SQL type will be taken.
1622     *
1623     * @param type Java type.
1624     * @param value Default value.
1625     *
1626     * @return Corrected default value for specified SQL type.
1627     */

1628    public static String JavaDoc fixDefaultSQL(String JavaDoc type, String JavaDoc value) {
1629        if (null == value) {
1630            value = "";
1631        }
1632        String JavaDoc fixedValue = value;
1633        String JavaDoc defaultValue = "";
1634
1635        if (type.equals("DECIMAL") || type.equals("NUMERIC")) {
1636            if (value.length() == 0) {
1637                fixedValue = "0.0";
1638            } else {
1639                try {
1640                    java.math.BigDecimal JavaDoc test = new java.math.BigDecimal JavaDoc(fixedValue);
1641                } catch (RuntimeException JavaDoc e) {
1642                    defaultValue = "0.0";
1643                }
1644            }
1645        } else if (type.equals("INTEGER") || type.equals("tinyint")
1646                || type.equals("TINYINT") || type.equals("smallint")
1647                || type.equals("SMALLINT") || type.equals("INT4")
1648                || type.equals("INT8") || type.equals("MEDIUMINT")) {
1649            if (value.length() == 0) {
1650                fixedValue = "0";
1651            } else {
1652                try {
1653                    Integer.parseInt(value);
1654                } catch (Exception JavaDoc e) {
1655                    defaultValue = "0";
1656                }
1657            }
1658        } else if (type.equals("REAL") || type.equals("FLOAT")) {
1659            if (value.length() == 0) {
1660                fixedValue = "0.0";
1661            } else {
1662                try {
1663                    Float.valueOf(value);
1664                } catch (Exception JavaDoc e) {
1665                    defaultValue = "0.0";
1666                }
1667            }
1668        } else if (type.equals("BIGINT")) {
1669            if (value.length() == 0) {
1670                fixedValue = "0";
1671            } else {
1672                try {
1673                    Long.parseLong(value);
1674                } catch (Exception JavaDoc e) {
1675                    defaultValue = "0";
1676                }
1677            }
1678        } else if (type.equals("DOUBLE")) {
1679            if (value.length() == 0) {
1680                fixedValue = "0.0";
1681            } else {
1682                try {
1683                    Double.valueOf(value);
1684                } catch (Exception JavaDoc e) {
1685                    defaultValue = "0.0";
1686                }
1687            }
1688        } else {
1689            defaultValue = "0";
1690        }
1691        
1692        if ("" != defaultValue) {
1693            fixedValue = defaultValue;
1694        }
1695        
1696        return fixedValue;
1697    }
1698    
1699    static public String JavaDoc returnFixedConstraintName(String JavaDoc namePrefix, String JavaDoc nameSufix ,String JavaDoc operation ,String JavaDoc counterType, String JavaDoc counterKeyPrefix , String JavaDoc counterKey, String JavaDoc dbVendor ){
1700// private static HashMap counterMap = new HashMap();
1701
// private static HashMap nameMap = new HashMap();
1702

1703        if(dbVendor!="" && (!dbVendorName.equalsIgnoreCase(dbVendor))){
1704            dbVendorName=dbVendor;
1705        }
1706        Integer JavaDoc keyLength=null;
1707        String JavaDoc result="";
1708        if(namePrefix.equalsIgnoreCase("")||nameSufix.equalsIgnoreCase("")){
1709            result=namePrefix+nameSufix;
1710        }else{
1711            result=namePrefix+"_"+nameSufix;
1712        }
1713        
1714        String JavaDoc keyLengthStr = Common.getDodsConfProperty("ConstraintNameLength", dbVendorName);
1715        if (keyLengthStr!=null){
1716            try {
1717                keyLength = new Integer JavaDoc(keyLengthStr);
1718            } catch (NumberFormatException JavaDoc e) {}
1719        }
1720        String JavaDoc counterMapKey;
1721        if (counterType.equalsIgnoreCase("PK") || counterType.equalsIgnoreCase("PKG")){
1722            counterMapKey=counterType+":://"; // +counterKeyPrefix+counterKey;
1723
}else if(counterType.equalsIgnoreCase("I")){
1724            counterMapKey=counterType+":://";
1725        }else{
1726            counterMapKey=counterType+":://";//+counterKeyPrefix;
1727
}
1728        String JavaDoc nameMapKey=counterType+counterKeyPrefix+counterKey;
1729        int counter = 0;
1730        if (operation.equalsIgnoreCase("CREATE")){
1731            boolean cuted=false;
1732            if (keyLength!=null && keyLength.intValue()>=minKeyLength && result.length()>keyLength.intValue()){
1733                result=result.substring(0,keyLength.intValue()-maxCounterLength-1);
1734                counterMapKey=counterMapKey+":///"+result;
1735                if (!counterMap.containsKey(counterMapKey)){
1736                    counter = 1;
1737                }else{
1738                    counter = ((Integer JavaDoc)counterMap.get(counterMapKey)).intValue()+1;
1739                }
1740                counterMap.put(counterMapKey,new Integer JavaDoc(counter));
1741
1742                cuted=true;
1743            }
1744            if( cuted || counterType.equalsIgnoreCase("FKG")){
1745                result=result+"_"+counter;
1746            }
1747            nameMap.put(nameMapKey,result);
1748        }else if (operation.equalsIgnoreCase("DROP")){
1749            result=(String JavaDoc)nameMap.get(nameMapKey);
1750            if (result==null){
1751            }
1752        }
1753        return result;
1754    }
1755}
1756
Popular Tags