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.ObjectOutputStream;
22 import net.jini.core.entry.CloneableEntry;
23 import net.jini.core.entry.Entry;
24 import org.apache.river.api.io.AtomicSerial;
25 import org.apache.river.api.io.AtomicSerial.GetArg;
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47 @AtomicSerial
48 public class ServiceTemplate implements java.io.Serializable, Cloneable {
49
50 private static final long serialVersionUID = 7854483807886483216L;
51
52
53
54
55
56
57 public ServiceID serviceID;
58
59
60
61
62
63 public Class[] serviceTypes;
64
65
66
67
68
69 public Entry[] attributeSetTemplates;
70
71
72
73
74
75
76
77
78
79
80
81 public ServiceTemplate(GetArg arg) throws IOException, ClassNotFoundException {
82
83
84
85
86
87 this(arg == null ? null: arg.get("serviceID", null, ServiceID.class),
88 arg == null? null: arg.get("serviceTypes", null, Class[].class),
89 arg == null? null: arg.get("attributeSetTemplates", null, Entry[].class)
90 );
91 }
92
93
94
95
96
97
98
99
100
101 public ServiceTemplate(ServiceID serviceID,
102 Class[] serviceTypes,
103 Entry[] attrSetTemplates)
104 {
105 this.serviceID = serviceID;
106 this.serviceTypes = serviceTypes;
107 this.attributeSetTemplates = attrSetTemplates;
108 }
109
110
111
112
113
114
115
116
117 @Override
118 public ServiceTemplate clone()
119 {
120 try {
121 ServiceTemplate clone = (ServiceTemplate) super.clone();
122 if (clone.serviceTypes != null){
123 clone.serviceTypes = clone.serviceTypes.clone();
124 }
125 if (clone.attributeSetTemplates != null){
126 clone.attributeSetTemplates = clone.attributeSetTemplates.clone();
127 for (int i = 0, l = clone.attributeSetTemplates.length; i < l; i++){
128 Entry e = clone.attributeSetTemplates[i];
129 if (e instanceof CloneableEntry){
130 clone.attributeSetTemplates[i] = ((CloneableEntry) e).clone();
131 }
132 }
133 }
134 return clone;
135 } catch (CloneNotSupportedException ex) {
136 throw new AssertionError();
137 }
138 }
139
140
141
142
143
144
145
146 public String toString() {
147 StringBuilder sBuffer = new StringBuilder();
148 sBuffer.append(
149 getClass().getName()).append(
150 "[serviceID=").append(
151 serviceID).append(
152 ", serviceTypes=");
153 if (serviceTypes != null) {
154 sBuffer.append("[");
155 if (serviceTypes.length > 0) {
156 for (int i = 0; i < serviceTypes.length - 1; i++)
157 sBuffer.append(serviceTypes[i]).append(" ");
158 sBuffer.append(serviceTypes[serviceTypes.length - 1]);
159 }
160 sBuffer.append("]");
161 } else {
162 sBuffer.append((Object)null);
163 }
164 sBuffer.append(", attributeSetTemplates=");
165 if (attributeSetTemplates != null) {
166 sBuffer.append("[");
167 if (attributeSetTemplates.length > 0) {
168 for (int i = 0; i < attributeSetTemplates.length - 1; i++)
169 sBuffer.append(attributeSetTemplates[i]).append(" ");
170 sBuffer.append(
171 attributeSetTemplates[attributeSetTemplates.length - 1]);
172 }
173 sBuffer.append("]");
174 } else {
175 sBuffer.append((Object)null);
176 }
177 return sBuffer.append("]").toString();
178 }
179
180 private void writeObject(ObjectOutputStream out) throws IOException {
181 out.defaultWriteObject();
182 }
183 }