1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package net.jini.core.lookup;
19
20 import java.io.IOException;
21 import java.io.ObjectInputStream;
22 import java.io.ObjectOutputStream;
23 import java.io.ObjectStreamField;
24 import net.jini.core.entry.CloneableEntry;
25 import net.jini.core.entry.Entry;
26 import org.apache.river.api.io.AtomicSerial;
27 import org.apache.river.api.io.AtomicSerial.GetArg;
28
29
30
31
32
33
34
35
36
37 @AtomicSerial
38 public class ServiceItem implements java.io.Serializable, Cloneable {
39
40 private static final long serialVersionUID = 717395451032330758L;
41 private static final ObjectStreamField[] serialPersistentFields =
42 {
43
44 new ObjectStreamField("serviceID", ServiceID.class),
45
46 new ObjectStreamField("service", Object.class),
47
48 new ObjectStreamField("attributeSets", Entry[].class)
49 };
50
51
52 public ServiceID serviceID;
53
54 public Object service;
55
56 public Entry[] attributeSets;
57
58
59
60
61
62
63
64
65
66 public ServiceItem(GetArg arg) throws IOException {
67 this( arg == null ? null: arg.get("serviceID", null, ServiceID.class),
68 arg == null ? null: arg.get("service", null),
69 arg == null ? null: arg.get("attributeSets", null, Entry[].class));
70 }
71
72
73
74
75
76
77
78
79 public ServiceItem(ServiceID serviceID, Object service, Entry[] attrSets)
80 {
81 this.serviceID = serviceID;
82 this.service = service;
83 this.attributeSets = attrSets;
84 }
85
86
87
88
89
90
91
92 public String toString()
93 {
94 StringBuilder sBuffer = new StringBuilder(256);
95 sBuffer.append(
96 getClass().getName()).append(
97 "[serviceID=").append(serviceID).append(
98 ", service=").append(service).append(
99 ", attributeSets=");
100 if (attributeSets != null) {
101 sBuffer.append("[");
102 if (attributeSets.length > 0) {
103 for (int i = 0; i < attributeSets.length - 1; i++)
104 sBuffer.append(attributeSets[i]).append(" ");
105 sBuffer.append(attributeSets[attributeSets.length - 1]);
106 }
107 sBuffer.append("]");
108 } else {
109 sBuffer.append((Object)null);
110 }
111 return sBuffer.append("]").toString();
112 }
113
114
115
116
117
118
119
120
121
122
123 @Override
124 public ServiceItem clone()
125 {
126 try {
127 ServiceItem clone = (ServiceItem) super.clone();
128 if (clone.attributeSets != null){
129 clone.attributeSets = clone.attributeSets.clone();
130 for (int i = 0, l = clone.attributeSets.length; i < l; i++){
131 Entry e = clone.attributeSets[i];
132 if (e instanceof CloneableEntry){
133 clone.attributeSets[i] = ((CloneableEntry) e).clone();
134 }
135
136 }
137 }
138 return clone;
139 } catch (CloneNotSupportedException ex) {
140 throw new AssertionError();
141 }
142 }
143
144
145
146
147
148
149 private void writeObject(ObjectOutputStream out) throws IOException {
150 out.defaultWriteObject();
151 }
152
153
154
155
156
157
158
159 private void readObject(ObjectInputStream in)
160 throws IOException, ClassNotFoundException
161 {
162 in.defaultReadObject();
163 }
164 }