KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > hivemind > internal > ser > ServiceToken


1 // Copyright 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package org.apache.hivemind.internal.ser;
16
17 import java.io.Externalizable JavaDoc;
18 import java.io.IOException JavaDoc;
19 import java.io.ObjectInput JavaDoc;
20 import java.io.ObjectOutput JavaDoc;
21
22 import org.apache.hivemind.util.Defense;
23
24 /**
25  * Instance used to replace actual service (proxies) during serialization. Note that this represents
26  * a back-door into HiveMind's {@link org.apache.hivemind.internal.RegistryInfrastructure}, which
27  * is less than ideal, and should not be used by end-user code!
28  *
29  * @author Howard M. Lewis Ship
30  * @since 1.1
31  */

32 public class ServiceToken implements Externalizable JavaDoc
33 {
34     private static final long serialVersionUID = 1L;
35     private String JavaDoc _serviceId;
36
37     // Needed for Externalizable.
38

39     public ServiceToken()
40     {
41     }
42
43     public ServiceToken(String JavaDoc serviceId)
44     {
45         Defense.notNull(serviceId, "serviceId");
46
47         _serviceId = serviceId;
48     }
49
50     public String JavaDoc getServiceId()
51     {
52         return _serviceId;
53     }
54
55     public void writeExternal(ObjectOutput JavaDoc out) throws IOException JavaDoc
56     {
57         out.writeUTF(_serviceId);
58     }
59
60     public void readExternal(ObjectInput JavaDoc in) throws IOException JavaDoc, ClassNotFoundException JavaDoc
61     {
62         _serviceId = in.readUTF();
63     }
64
65     Object JavaDoc readResolve()
66     {
67         return ServiceSerializationHelper.getServiceSerializationSupport()
68                 .getServiceFromToken(this);
69     }
70 }
Popular Tags