KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Derby - Class org.apache.derby.catalog.types.ReferencedColumnsDescriptorImpl
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
25 import org.apache.derby.iapi.services.io.Formatable;
26 import org.apache.derby.iapi.services.io.StoredFormatIds;
27 import org.apache.derby.catalog.ReferencedColumns;
28
29 import java.io.ObjectInput JavaDoc;
30 import java.io.ObjectOutput JavaDoc;
31 import java.io.IOException JavaDoc;
32
33 public class ReferencedColumnsDescriptorImpl
34     implements ReferencedColumns, Formatable
35 {
36     /********************************************************
37     **
38     ** This class implements Formatable. That means that it
39     ** can write itself to and from a formatted stream. If
40     ** you add more fields to this class, make sure that you
41     ** also write/read them with the writeExternal()/readExternal()
42     ** methods.
43     **
44     ** If, inbetween releases, you add more fields to this class,
45     ** then you should bump the version number emitted by the getTypeFormatId()
46     ** method.
47     **
48     ********************************************************/

49
50     private int[] referencedColumns;
51
52     /**
53      * Constructor for an ReferencedColumnsDescriptorImpl
54      *
55      * @param referencedColumns The array of referenced columns.
56      */

57
58     public ReferencedColumnsDescriptorImpl( int[] referencedColumns)
59     {
60         this.referencedColumns = referencedColumns;
61     }
62
63     /** Zero-argument constructor for Formatable interface */
64     public ReferencedColumnsDescriptorImpl()
65     {
66     }
67     /**
68     * @see ReferencedColumns#getReferencedColumnPositions
69     */

70     public int[] getReferencedColumnPositions()
71     {
72         return referencedColumns;
73     }
74
75     /* Externalizable interface */
76
77     /**
78      * @see java.io.Externalizable#readExternal
79      *
80      * @exception IOException Thrown on read error
81      */

82     public void readExternal(ObjectInput JavaDoc in) throws IOException JavaDoc
83     {
84         int rcLength = in.readInt();
85         referencedColumns = new int[rcLength];
86         for (int i = 0; i < rcLength; i++)
87         {
88             referencedColumns[i] = in.readInt();
89         }
90     }
91
92     /**
93      * @see java.io.Externalizable#writeExternal
94      *
95      * @exception IOException Thrown on write error
96      */

97     public void writeExternal(ObjectOutput JavaDoc out) throws IOException JavaDoc
98     {
99         out.writeInt(referencedColumns.length);
100         for (int i = 0; i < referencedColumns.length; i++)
101         {
102             out.writeInt(referencedColumns[i]);
103         }
104     }
105
106     /* TypedFormat interface */
107     public int getTypeFormatId()
108     {
109         return StoredFormatIds.REFERENCED_COLUMNS_DESCRIPTOR_IMPL_V01_ID;
110     }
111
112     /**
113       @see java.lang.Object#toString
114       */

115     public String JavaDoc toString()
116     {
117         StringBuffer JavaDoc sb = new StringBuffer JavaDoc(60);
118
119         sb.append('(');
120         for (int index = 0; index < referencedColumns.length; index++)
121         {
122             if (index > 0)
123                 sb.append(',');
124             sb.append(String.valueOf(referencedColumns[index]));
125
126         }
127         sb.append(')');
128         return sb.toString();
129     }
130 }
131
Popular Tags