KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > sql > depend > BasicProviderInfo


1 /*
2
3    Derby - Class org.apache.derby.impl.sql.depend.BasicProviderInfo
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.impl.sql.depend;
23
24 import org.apache.derby.iapi.services.io.StoredFormatIds;
25
26 import org.apache.derby.iapi.sql.depend.ProviderInfo;
27
28 import org.apache.derby.iapi.services.sanity.SanityManager;
29
30 import org.apache.derby.catalog.DependableFinder;
31 import org.apache.derby.catalog.UUID;
32 import org.apache.derby.iapi.services.io.FormatableHashtable;
33
34 import java.io.ObjectOutput JavaDoc;
35 import java.io.ObjectInput JavaDoc;
36 import java.io.IOException JavaDoc;
37
38 /**
39  * This is the implementation of ProviderInfo in the DependencyManager.
40  */

41
42 public class BasicProviderInfo implements ProviderInfo
43 {
44     /********************************************************
45     **
46     ** This class implements Formatable. That means that it
47     ** can write itself to and from a formatted stream. If
48     ** you add more fields to this class, make sure that you
49     ** also write/read them with the writeExternal()/readExternal()
50     ** methods.
51     **
52     ** If, inbetween releases, you add more fields to this class,
53     ** then you should bump the version number emitted by the getTypeFormatId()
54     ** method.
55     **
56     ********************************************************/

57
58     public UUID uuid;
59     public DependableFinder dFinder;
60     public String JavaDoc providerName;
61
62     // CONSTRUCTORS
63

64     /**
65      * Public niladic constructor. Needed for Formatable interface to work.
66      *
67      */

68     public BasicProviderInfo() {}
69
70     /**
71      * Make one of these puppies.
72      *
73      * @param uuid UUID of Provider.
74      * @param dFinder DependableFinder for Provider.
75      * @param providerName Name of the Provider.
76      */

77     public BasicProviderInfo(
78                        UUID uuid,
79                        DependableFinder dFinder,
80                        String JavaDoc providerName)
81     {
82         this.uuid = uuid;
83         this.dFinder = dFinder;
84         this.providerName = providerName;
85     }
86
87     // ProviderInfo methods
88

89     /** @see ProviderInfo#getDependableFinder */
90     public DependableFinder getDependableFinder()
91     {
92         return dFinder;
93     }
94
95     /** @see ProviderInfo#getObjectId */
96     public UUID getObjectId()
97     {
98         return uuid;
99     }
100
101     /** @see ProviderInfo#getProviderName */
102     public String JavaDoc getProviderName()
103     {
104         return providerName;
105     }
106
107     // Formatable methods
108

109     /**
110      * Read this object from a stream of stored objects.
111      *
112      * @param in read this.
113      *
114      * @exception IOException thrown on error
115      * @exception ClassNotFoundException thrown on error
116      */

117     public void readExternal( ObjectInput JavaDoc in )
118          throws IOException JavaDoc, ClassNotFoundException JavaDoc
119     {
120
121         FormatableHashtable fh = (FormatableHashtable)in.readObject();
122         uuid = (UUID)fh.get("uuid");
123         dFinder = (DependableFinder)fh.get("dFinder");
124         providerName = (String JavaDoc) fh.get("providerName");
125     }
126
127     /**
128      * Write this object to a stream of stored objects.
129      *
130      * @param out write bytes here.
131      *
132      * @exception IOException thrown on error
133      */

134     public void writeExternal( ObjectOutput JavaDoc out )
135          throws IOException JavaDoc
136     {
137         FormatableHashtable fh = new FormatableHashtable();
138         fh.put("uuid", uuid);
139         fh.put("dFinder", dFinder);
140         fh.put("providerName", providerName);
141         out.writeObject(fh);
142     }
143  
144     /**
145      * Get the formatID which corresponds to this class.
146      *
147      * @return the formatID of this class
148      */

149     public int getTypeFormatId() { return StoredFormatIds.PROVIDER_INFO_V02_ID; }
150
151     /*
152       Object methods.
153       */

154     public String JavaDoc toString()
155     {
156         if (SanityManager.DEBUG)
157         {
158             String JavaDoc traceUUID;
159             String JavaDoc traceDFinder;
160             String JavaDoc traceProviderName;
161
162             if (uuid == null)
163             {
164                 traceUUID = "uuid: null ";
165             }
166             else
167             {
168                 traceUUID = "uuid: "+uuid+" ";
169             }
170
171             if (dFinder == null)
172             {
173                 traceDFinder = "dFinder: null ";
174             }
175             else
176             {
177                 traceDFinder = "dFinder: "+dFinder+" ";
178             }
179
180             if (providerName == null)
181             {
182                 traceProviderName = "providerName: null ";
183             }
184             else
185             {
186                 traceProviderName = "providerName: "+providerName+" ";
187             }
188
189             return "ProviderInfo: ("+traceUUID+traceDFinder+traceProviderName+")";
190         }
191         else
192         {
193             return "";
194         }
195     }
196 }
197
Popular Tags