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 public ServiceTemplate(GetArg arg) throws IOException {
81
82
83
84
85
86 this(arg == null ? null: arg.get("serviceID", null, ServiceID.class),
87 arg == null? null: arg.get("serviceTypes", null, Class[].class),
88 arg == null? null: arg.get("attributeSetTemplates", null, Entry[].class)
89 );
90 }
91
92
93
94
95
96
97
98
99
100 public ServiceTemplate(ServiceID serviceID,
101 Class[] serviceTypes,
102 Entry[] attrSetTemplates)
103 {
104 this.serviceID = serviceID;
105 this.serviceTypes = serviceTypes;
106 this.attributeSetTemplates = attrSetTemplates;
107 }
108
109
110
111
112
113
114
115
116 @Override
117 public ServiceTemplate clone()
118 {
119 try {
120 ServiceTemplate clone = (ServiceTemplate) super.clone();
121 if (clone.serviceTypes != null){
122 clone.serviceTypes = clone.serviceTypes.clone();
123 }
124 if (clone.attributeSetTemplates != null){
125 clone.attributeSetTemplates = clone.attributeSetTemplates.clone();
126 for (int i = 0, l = clone.attributeSetTemplates.length; i < l; i++){
127 Entry e = clone.attributeSetTemplates[i];
128 if (e instanceof CloneableEntry){
129 clone.attributeSetTemplates[i] = ((CloneableEntry) e).clone();
130 }
131 }
132 }
133 return clone;
134 } catch (CloneNotSupportedException ex) {
135 throw new AssertionError();
136 }
137 }
138
139
140
141
142
143
144
145 public String toString() {
146 StringBuilder sBuffer = new StringBuilder();
147 sBuffer.append(
148 getClass().getName()).append(
149 "[serviceID=").append(
150 serviceID).append(
151 ", serviceTypes=");
152 if (serviceTypes != null) {
153 sBuffer.append("[");
154 if (serviceTypes.length > 0) {
155 for (int i = 0; i < serviceTypes.length - 1; i++)
156 sBuffer.append(serviceTypes[i]).append(" ");
157 sBuffer.append(serviceTypes[serviceTypes.length - 1]);
158 }
159 sBuffer.append("]");
160 } else {
161 sBuffer.append((Object)null);
162 }
163 sBuffer.append(", attributeSetTemplates=");
164 if (attributeSetTemplates != null) {
165 sBuffer.append("[");
166 if (attributeSetTemplates.length > 0) {
167 for (int i = 0; i < attributeSetTemplates.length - 1; i++)
168 sBuffer.append(attributeSetTemplates[i]).append(" ");
169 sBuffer.append(
170 attributeSetTemplates[attributeSetTemplates.length - 1]);
171 }
172 sBuffer.append("]");
173 } else {
174 sBuffer.append((Object)null);
175 }
176 return sBuffer.append("]").toString();
177 }
178
179 private void writeObject(ObjectOutputStream out) throws IOException {
180 out.defaultWriteObject();
181 }
182 }