View Javadoc

1   /*--------------------------------------------------------------------------
2    *  Copyright 2007 utgenome.org
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License");
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License.
15   *--------------------------------------------------------------------------*/
16  //--------------------------------------
17  // UTGB Common Project
18  //
19  // DataTypeBase.java
20  // Since: 2007/04/13
21  //
22  // $Date$
23  // $URL$ 
24  // $Author$
25  //--------------------------------------
26  package org.utgenome.gwt.utgb.client.db.datatype;
27  
28  import com.google.gwt.json.client.JSONString;
29  import com.google.gwt.json.client.JSONValue;
30  
31  
32  public abstract class DataTypeBase implements DataType
33  {
34  	protected String name;
35  	protected boolean isPrimaryKey = false;
36  	protected boolean isNotNull = false;
37  	
38  	public DataTypeBase(String name)
39  	{
40  		this.name = name;
41  	}
42  	
43  	public DataTypeBase(String name, boolean isPrimaryKey)
44  	{
45  		this.name = name;
46  		this.isPrimaryKey = isPrimaryKey;
47  	}
48  
49  	// hide the default constructor
50  	private DataTypeBase() {}
51  	
52  	public DataTypeBase(String name, boolean isPrimaryKey, boolean isNotNull) {
53  		this.name = name;
54  		this.isPrimaryKey = isPrimaryKey;
55  		this.isNotNull = isNotNull;
56  	}
57  
58  	public String getName() {
59  		return name;
60  	}
61  	
62  	public String toString(JSONValue value)
63  	{
64  		JSONString s = value.isString();
65  		if(s != null)
66  			return s.stringValue();
67  		else
68  			return value.toString();
69  	}
70  	
71  
72  	public void setAsPrimaryKey()
73  	{
74  		this.isPrimaryKey = true;
75  	}
76  	
77  	public boolean isPrimaryKey()
78  	{
79  		return isPrimaryKey;
80  	}
81  	
82  	public void setNotNull()
83  	{
84  		this.isNotNull = true;
85  	}
86  	public boolean isNotNull()
87  	{
88  		return isNotNull;
89  	}
90  
91  }
92  
93  
94  
95