KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > catalog > types > UserDefinedTypeIdImpl


1 /*
2
3    Derby - Class org.apache.derby.catalog.types.UserDefinedTypeIdImpl
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to You under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derby.catalog.types;
23
24 import org.apache.derby.iapi.services.io.StoredFormatIds;
25
26 import java.sql.Types JavaDoc;
27 import java.io.ObjectOutput JavaDoc;
28 import java.io.ObjectInput JavaDoc;
29 import java.io.IOException JavaDoc;
30
31 public class UserDefinedTypeIdImpl extends BaseTypeIdImpl
32 {
33     /********************************************************
34     **
35     ** This class implements Formatable. That means that it
36     ** can write itself to and from a formatted stream. If
37     ** you add more fields to this class, make sure that you
38     ** also write/read them with the writeExternal()/readExternal()
39     ** methods.
40     **
41     ** If, inbetween releases, you add more fields to this class,
42     ** then you should bump the version number emitted by the getTypeFormatId()
43     ** method.
44     **
45     ********************************************************/

46
47     protected String JavaDoc className;
48
49     /**
50      * Public niladic constructor. Needed for Formatable interface to work.
51      *
52      */

53     public UserDefinedTypeIdImpl() { super(); }
54
55     /**
56      * Constructor for a UserDefinedTypeIdImpl. The SQLTypeName of a UserDefinedType
57      * is assumed to be its className.
58      *
59      * @param className The SQL name of the type
60      */

61
62     public UserDefinedTypeIdImpl(String JavaDoc className)
63     {
64         super(className);
65         this.className = className;
66         JDBCTypeId = java.sql.Types.JAVA_OBJECT;
67     }
68
69
70     /** Return the java class name for this type */
71     public String JavaDoc getClassName()
72     {
73         return className;
74     }
75
76     /** Does this type id represent a user type? */
77     public boolean userType()
78     {
79         return true;
80     }
81     // Formatable interface.
82

83     /**
84      * Read this object from a stream of stored objects.
85      *
86      * @param in read this.
87      *
88      * @exception IOException thrown on error
89      * @exception ClassNotFoundException thrown on error
90      */

91     public void readExternal( ObjectInput JavaDoc in )
92          throws IOException JavaDoc, ClassNotFoundException JavaDoc
93     {
94         super.readExternal( in );
95         className = in.readUTF();
96         JDBCTypeId = java.sql.Types.JAVA_OBJECT;
97     }
98
99     /**
100      * Write this object to a stream of stored objects.
101      *
102      * @param out write bytes here.
103      *
104      * @exception IOException thrown on error
105      */

106     public void writeExternal( ObjectOutput JavaDoc out )
107          throws IOException JavaDoc
108     {
109         super.writeExternal( out );
110         out.writeUTF( className );
111     }
112     /**
113      * Get the formatID which corresponds to this class.
114      *
115      * @return the formatID of this class
116      */

117     public int getTypeFormatId() { return StoredFormatIds.USERDEFINED_TYPE_ID_IMPL_V3; }
118
119     /**
120      * Get the format id for the wrapper type id that corresponds to
121      * this type id.
122      */

123     public int wrapperTypeFormatId() { return StoredFormatIds.USERDEFINED_TYPE_ID_V3; }
124 }
125
Popular Tags