1 /*
2 *
3 * Copyright 2005 Sun Microsystems, Inc.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 * Note: Changes by the Jgroup team are marked ** GREG **.
18 *
19 */
20 package com.sun.jini.reggie;
21
22 import java.io.Serializable;
23 import java.lang.reflect.Field;
24 import java.lang.reflect.Modifier;
25 import java.rmi.RemoteException;
26
27 import net.jini.core.lookup.ServiceID;
28 import net.jini.core.lookup.ServiceTemplate;
29
30 /**
31 * A Template contains the fields of a ServiceTemplate packaged up for
32 * transmission between client-side proxies and the registrar server.
33 * Instances are never visible to clients, they are private to the
34 * communication between the proxies and the server.
35 * <p>
36 * This class only has a bare minimum of methods, to minimize
37 * the amount of code downloaded into clients.
38 *
39 * @author Sun Microsystems, Inc.
40 *
41 */
42 class Template implements Serializable
43 {
44
45 private static final long serialVersionUID = 2L;
46
47 /**
48 * ServiceTemplate.serviceID
49 *
50 * @serial
51 */
52 public ServiceID serviceID;
53
54 /**
55 * ServiceTemplate.serviceTypes converted to ServiceTypes
56 *
57 * @serial
58 */
59 public ServiceType[] serviceTypes;
60
61 /**
62 * ServiceTemplate.attributeSetTemplates converted to EntryReps
63 *
64 * @serial
65 */
66 public EntryRep[] attributeSetTemplates;
67
68 /**
69 * Group identifies (if any) ** GREG **
70 */
71 public String gid;
72
73 /**
74 * Converts a ServiceTemplate to a Template. Any exception that results
75 * is bundled up into a MarshalException.
76 */
77 public Template(ServiceTemplate tmpl) throws RemoteException
78 {
79 serviceID = tmpl.serviceID;
80 serviceTypes = ClassMapper.toServiceType(tmpl.serviceTypes);
81 attributeSetTemplates = EntryRep.toEntryRep(tmpl.attributeSetTemplates, false);
82
83 // Search for a group name ** GREG **
84 if (tmpl.attributeSetTemplates != null) {
85 for (int i=0; i < tmpl.attributeSetTemplates.length && gid == null; i++) {
86 Field[] fields = tmpl.attributeSetTemplates[i].getClass().getFields();
87 for (int j=0; j < fields.length && gid==null; j++) {
88 if ((fields[j].getModifiers() &
89 (Modifier.STATIC|Modifier.FINAL|Modifier.TRANSIENT)) == 0 &&
90 fields[j].getType().equals(String.class) &&
91 fields[j].getName().equals("groupName")
92 ) {
93 try {
94 gid = (String) fields[j].get(tmpl.attributeSetTemplates[i]);
95 } catch (Exception e) {
96 e.printStackTrace();
97 }
98 }
99 }
100 }
101 }
102 }
103 }