Improve XML parsing to handle attributes as well.
[cfb.git] / prod / net / jaekl / cfb / db / Column.java
1 package net.jaekl.cfb.db;
2
3 // Copyright (C) 2015 Christian Jaekl
4
5 public class Column {
6         public enum Type {
7                 CHAR, INTEGER, TIMESTAMP, TIMESTAMPTZ, VARCHAR 
8         };
9         public enum Null {
10                 NOT_NULL, NULL
11         }
12         
13         String m_name;
14         Type m_type;
15         int m_width;
16         Null m_null;
17         
18         public Column(String name, Type type, int width, Null canBeNull) 
19         {
20                 m_name = name;
21                 m_type = type;
22                 m_width = width;
23                 m_null = canBeNull;
24         }
25         
26         public String getName() { return m_name; }
27         public Type getType() { return m_type; }
28         public int getWidth() { return m_width; }
29         public Null getNull() { return m_null; }
30         
31         // Create a column based on an array of Objects
32         // Input format:  { name, type, width, can_be_null } 
33         public static Column construct(Object[] spec) {
34                 assert(null != spec);
35                 assert(4 == spec.length);
36                 assert(spec[0] instanceof String);
37                 assert(spec[1] instanceof Type);
38                 assert(spec[2] instanceof Number);
39                 assert(spec[3] instanceof Null);
40                 
41                 String name = (String)(spec[0]);
42                 Type type = (Type)(spec[1]);
43                 Number width = (Number)(spec[2]);
44                 Null canBeNull = (Null)(spec[3]);
45                 
46                 return new Column(name, type, width.intValue(), canBeNull);
47         }
48 }