001: /*
002:
003: Derby - Class org.apache.derby.impl.sql.depend.BasicProviderInfo
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to you under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: package org.apache.derby.impl.sql.depend;
023:
024: import org.apache.derby.iapi.services.io.StoredFormatIds;
025:
026: import org.apache.derby.iapi.sql.depend.ProviderInfo;
027:
028: import org.apache.derby.iapi.services.sanity.SanityManager;
029:
030: import org.apache.derby.catalog.DependableFinder;
031: import org.apache.derby.catalog.UUID;
032: import org.apache.derby.iapi.services.io.FormatableHashtable;
033:
034: import java.io.ObjectOutput;
035: import java.io.ObjectInput;
036: import java.io.IOException;
037:
038: /**
039: * This is the implementation of ProviderInfo in the DependencyManager.
040: */
041:
042: public class BasicProviderInfo implements ProviderInfo {
043: /********************************************************
044: **
045: ** This class implements Formatable. That means that it
046: ** can write itself to and from a formatted stream. If
047: ** you add more fields to this class, make sure that you
048: ** also write/read them with the writeExternal()/readExternal()
049: ** methods.
050: **
051: ** If, inbetween releases, you add more fields to this class,
052: ** then you should bump the version number emitted by the getTypeFormatId()
053: ** method.
054: **
055: ********************************************************/
056:
057: public UUID uuid;
058: public DependableFinder dFinder;
059: public String providerName;
060:
061: // CONSTRUCTORS
062:
063: /**
064: * Public niladic constructor. Needed for Formatable interface to work.
065: *
066: */
067: public BasicProviderInfo() {
068: }
069:
070: /**
071: * Make one of these puppies.
072: *
073: * @param uuid UUID of Provider.
074: * @param dFinder DependableFinder for Provider.
075: * @param providerName Name of the Provider.
076: */
077: public BasicProviderInfo(UUID uuid, DependableFinder dFinder,
078: String providerName) {
079: this .uuid = uuid;
080: this .dFinder = dFinder;
081: this .providerName = providerName;
082: }
083:
084: // ProviderInfo methods
085:
086: /** @see ProviderInfo#getDependableFinder */
087: public DependableFinder getDependableFinder() {
088: return dFinder;
089: }
090:
091: /** @see ProviderInfo#getObjectId */
092: public UUID getObjectId() {
093: return uuid;
094: }
095:
096: /** @see ProviderInfo#getProviderName */
097: public String getProviderName() {
098: return providerName;
099: }
100:
101: // Formatable methods
102:
103: /**
104: * Read this object from a stream of stored objects.
105: *
106: * @param in read this.
107: *
108: * @exception IOException thrown on error
109: * @exception ClassNotFoundException thrown on error
110: */
111: public void readExternal(ObjectInput in) throws IOException,
112: ClassNotFoundException {
113:
114: FormatableHashtable fh = (FormatableHashtable) in.readObject();
115: uuid = (UUID) fh.get("uuid");
116: dFinder = (DependableFinder) fh.get("dFinder");
117: providerName = (String) fh.get("providerName");
118: }
119:
120: /**
121: * Write this object to a stream of stored objects.
122: *
123: * @param out write bytes here.
124: *
125: * @exception IOException thrown on error
126: */
127: public void writeExternal(ObjectOutput out) throws IOException {
128: FormatableHashtable fh = new FormatableHashtable();
129: fh.put("uuid", uuid);
130: fh.put("dFinder", dFinder);
131: fh.put("providerName", providerName);
132: out.writeObject(fh);
133: }
134:
135: /**
136: * Get the formatID which corresponds to this class.
137: *
138: * @return the formatID of this class
139: */
140: public int getTypeFormatId() {
141: return StoredFormatIds.PROVIDER_INFO_V02_ID;
142: }
143:
144: /*
145: Object methods.
146: */
147: public String toString() {
148: if (SanityManager.DEBUG) {
149: String traceUUID;
150: String traceDFinder;
151: String traceProviderName;
152:
153: if (uuid == null) {
154: traceUUID = "uuid: null ";
155: } else {
156: traceUUID = "uuid: " + uuid + " ";
157: }
158:
159: if (dFinder == null) {
160: traceDFinder = "dFinder: null ";
161: } else {
162: traceDFinder = "dFinder: " + dFinder + " ";
163: }
164:
165: if (providerName == null) {
166: traceProviderName = "providerName: null ";
167: } else {
168: traceProviderName = "providerName: " + providerName
169: + " ";
170: }
171:
172: return "ProviderInfo: (" + traceUUID + traceDFinder
173: + traceProviderName + ")";
174: } else {
175: return "";
176: }
177: }
178: }
|