author | mchung |
Mon, 21 Jun 2010 15:02:47 -0700 | |
changeset 5815 | 8c68030e27b1 |
parent 5506 | 202f599c92aa |
child 6679 | bd0c524be1b4 |
permissions | -rw-r--r-- |
1327
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
1 |
/* |
5506 | 2 |
* Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. |
1327
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
4 |
* |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
1327
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
1327
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
10 |
* |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
15 |
* accompanied this code). |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
16 |
* |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
20 |
* |
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
1327
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
24 |
*/ |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
25 |
|
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
26 |
/* |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
27 |
* @bug 6622366 |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
28 |
* @summary Utility class used by other jtreg tests |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
29 |
*/ |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
30 |
|
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
31 |
import com.sun.servicetag.RegistrationData; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
32 |
import com.sun.servicetag.ServiceTag; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
33 |
import com.sun.servicetag.Registry; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
34 |
|
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
35 |
import java.util.Set; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
36 |
import java.util.Date; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
37 |
import java.util.Map; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
38 |
import java.util.Properties; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
39 |
import java.util.TimeZone; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
40 |
import java.text.ParseException; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
41 |
import java.text.SimpleDateFormat; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
42 |
import java.io.*; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
43 |
|
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
44 |
public class Util { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
45 |
public static ServiceTag newServiceTag(File f) |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
46 |
throws FileNotFoundException, IOException, NumberFormatException { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
47 |
return newServiceTag(f, false /* with instance_urn */); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
48 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
49 |
|
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
50 |
public static ServiceTag newServiceTag(File f, boolean noInstanceURN) |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
51 |
throws FileNotFoundException, IOException, NumberFormatException { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
52 |
Properties props = new Properties(); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
53 |
FileReader reader = new FileReader(f); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
54 |
try { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
55 |
props.load(reader); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
56 |
} finally { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
57 |
reader.close(); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
58 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
59 |
if (noInstanceURN) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
60 |
return ServiceTag.newInstance( |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
61 |
props.getProperty("product_name"), |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
62 |
props.getProperty("product_version"), |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
63 |
props.getProperty("product_urn"), |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
64 |
props.getProperty("product_parent"), |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
65 |
props.getProperty("product_parent_urn"), |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
66 |
props.getProperty("product_defined_inst_id"), |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
67 |
props.getProperty("product_vendor"), |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
68 |
props.getProperty("platform_arch"), |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
69 |
props.getProperty("container"), |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
70 |
props.getProperty("source")); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
71 |
} else { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
72 |
return ServiceTag.newInstance( |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
73 |
props.getProperty("instance_urn"), |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
74 |
props.getProperty("product_name"), |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
75 |
props.getProperty("product_version"), |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
76 |
props.getProperty("product_urn"), |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
77 |
props.getProperty("product_parent"), |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
78 |
props.getProperty("product_parent_urn"), |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
79 |
props.getProperty("product_defined_inst_id"), |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
80 |
props.getProperty("product_vendor"), |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
81 |
props.getProperty("platform_arch"), |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
82 |
props.getProperty("container"), |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
83 |
props.getProperty("source")); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
84 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
85 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
86 |
|
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
87 |
public static boolean matches(ServiceTag st1, ServiceTag st2) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
88 |
if (!st1.getInstanceURN().equals(st2.getInstanceURN())) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
89 |
System.out.println("instance_urn: " + st1.getInstanceURN() + |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
90 |
" != " + st2.getInstanceURN()); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
91 |
return false; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
92 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
93 |
return matchesNoInstanceUrn(st1, st2); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
94 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
95 |
|
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
96 |
public static boolean matchesNoInstanceUrn(ServiceTag st1, ServiceTag st2) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
97 |
if (!st1.getProductName().equals(st2.getProductName())) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
98 |
System.out.println("product_name: " + st1.getProductName() + |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
99 |
" != " + st2.getProductName()); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
100 |
return false; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
101 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
102 |
|
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
103 |
if (!st1.getProductVersion().equals(st2.getProductVersion())) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
104 |
System.out.println("product_version: " + st1.getProductVersion() + |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
105 |
" != " + st2.getProductVersion()); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
106 |
return false; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
107 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
108 |
if (!st1.getProductURN().equals(st2.getProductURN())) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
109 |
System.out.println("product_urn: " + st1.getProductURN() + |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
110 |
" != " + st2.getProductURN()); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
111 |
return false; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
112 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
113 |
if (!st1.getProductParentURN().equals(st2.getProductParentURN())) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
114 |
System.out.println("product_parent_urn: " + st1.getProductParentURN() + |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
115 |
" != " + st2.getProductParentURN()); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
116 |
return false; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
117 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
118 |
if (!st1.getProductParent().equals(st2.getProductParent())) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
119 |
System.out.println("product_parent: " + st1.getProductParent() + |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
120 |
" != " + st2.getProductParent()); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
121 |
return false; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
122 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
123 |
if (!st1.getProductDefinedInstanceID().equals(st2.getProductDefinedInstanceID())) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
124 |
System.out.println("product_defined_inst_id: " + |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
125 |
st1.getProductDefinedInstanceID() + |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
126 |
" != " + st2.getProductDefinedInstanceID()); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
127 |
return false; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
128 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
129 |
if (!st1.getProductVendor().equals(st2.getProductVendor())) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
130 |
System.out.println("product_vendor: " + st1.getProductVendor() + |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
131 |
" != " + st2.getProductVendor()); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
132 |
return false; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
133 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
134 |
if (!st1.getPlatformArch().equals(st2.getPlatformArch())) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
135 |
System.out.println("platform_arch: " + st1.getPlatformArch() + |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
136 |
" != " + st2.getPlatformArch()); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
137 |
return false; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
138 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
139 |
if (!st1.getContainer().equals(st2.getContainer())) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
140 |
System.out.println("container: " + st1.getContainer() + |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
141 |
" != " + st2.getContainer()); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
142 |
return false; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
143 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
144 |
if (!st1.getSource().equals(st2.getSource())) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
145 |
System.out.println("source: " + st1.getSource() + |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
146 |
" != " + st2.getSource()); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
147 |
return false; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
148 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
149 |
return true; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
150 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
151 |
|
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
152 |
public static void checkRegistrationData(String regFile, |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
153 |
Map<String, ServiceTag> stMap) |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
154 |
throws IOException { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
155 |
BufferedInputStream in = new BufferedInputStream(new FileInputStream(regFile)); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
156 |
RegistrationData registration = RegistrationData.loadFromXML(in); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
157 |
Set<ServiceTag> svcTags = registration.getServiceTags(); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
158 |
if (svcTags.size() != stMap.size()) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
159 |
throw new RuntimeException("Invalid service tag count= " + |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
160 |
svcTags.size() + " expected=" + stMap.size()); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
161 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
162 |
for (ServiceTag st : svcTags) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
163 |
ServiceTag st1 = stMap.get(st.getInstanceURN()); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
164 |
if (!matches(st, st1)) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
165 |
throw new RuntimeException("ServiceTag in the registry " + |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
166 |
"does not match the one in the map"); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
167 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
168 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
169 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
170 |
|
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
171 |
|
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
172 |
/** |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
173 |
* Formats the Date into a timestamp string in YYYY-MM-dd HH:mm:ss GMT. |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
174 |
* @param timestamp Date |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
175 |
* @return a string representation of the timestamp in the YYYY-MM-dd HH:mm:ss GMT format. |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
176 |
*/ |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
177 |
static String formatTimestamp(Date timestamp) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
178 |
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z"); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
179 |
df.setTimeZone(TimeZone.getTimeZone("GMT")); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
180 |
return df.format(timestamp); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
181 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
182 |
|
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
183 |
/** |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
184 |
* Parses a timestamp string in YYYY-MM-dd HH:mm:ss GMT format. |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
185 |
* @param timestamp Timestamp in the YYYY-MM-dd HH:mm:ss GMT format. |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
186 |
* @return Date |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
187 |
*/ |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
188 |
static Date parseTimestamp(String timestamp) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
189 |
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z"); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
190 |
df.setTimeZone(TimeZone.getTimeZone("GMT")); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
191 |
try { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
192 |
return df.parse(timestamp); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
193 |
} catch (ParseException e) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
194 |
// should not reach here |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
195 |
e.printStackTrace(); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
196 |
return new Date(); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
197 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
198 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
199 |
|
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
200 |
/** |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
201 |
* Returns the command simulating stclient behavior. |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
202 |
*/ |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
203 |
static String getSvcClientCommand(String stclientRegistry) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
204 |
String regDir = System.getProperty("test.classes"); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
205 |
|
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
206 |
StringBuilder sb = new StringBuilder(); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
207 |
// wrap each argument to the command with double quotes |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
208 |
sb.append("\""); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
209 |
sb.append(System.getProperty("java.home")); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
210 |
sb.append(File.separator).append("bin"); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
211 |
sb.append(File.separator).append("java"); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
212 |
sb.append("\""); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
213 |
sb.append(" -cp "); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
214 |
sb.append("\"").append(regDir).append("\""); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
215 |
sb.append(" \"-Dstclient.registry.path="); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
216 |
sb.append(stclientRegistry).append("\""); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
217 |
sb.append(" SvcTagClient"); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
218 |
return sb.toString(); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
219 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
220 |
|
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
221 |
private static Registry registry = null; |
5815
8c68030e27b1
6962815: support enable and disable of the servicetag's system registry for testing purpose
mchung
parents:
5506
diff
changeset
|
222 |
private static File registryFile = null; |
1327
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
223 |
/** |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
224 |
* Returns the Registry processed by SvcTagClient that simulates |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
225 |
* stclient. |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
226 |
*/ |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
227 |
static synchronized Registry getSvcTagClientRegistry() throws IOException { |
5815
8c68030e27b1
6962815: support enable and disable of the servicetag's system registry for testing purpose
mchung
parents:
5506
diff
changeset
|
228 |
String regDir = System.getProperty("test.classes"); |
8c68030e27b1
6962815: support enable and disable of the servicetag's system registry for testing purpose
mchung
parents:
5506
diff
changeset
|
229 |
File f = new File(regDir, "registry.xml"); |
1327
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
230 |
if (registry != null) { |
5815
8c68030e27b1
6962815: support enable and disable of the servicetag's system registry for testing purpose
mchung
parents:
5506
diff
changeset
|
231 |
if (!f.equals(registryFile) && f.length() != 0) { |
8c68030e27b1
6962815: support enable and disable of the servicetag's system registry for testing purpose
mchung
parents:
5506
diff
changeset
|
232 |
throw new AssertionError("Has to be empty registry.xml to run in samevm"); |
8c68030e27b1
6962815: support enable and disable of the servicetag's system registry for testing purpose
mchung
parents:
5506
diff
changeset
|
233 |
} |
1327
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
234 |
return registry; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
235 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
236 |
|
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
237 |
// System.setProperty("servicetag.verbose", "true"); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
238 |
// enable the helper class |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
239 |
System.setProperty("servicetag.sthelper.supported", "true"); |
5815
8c68030e27b1
6962815: support enable and disable of the servicetag's system registry for testing purpose
mchung
parents:
5506
diff
changeset
|
240 |
registryFile = f; |
1327
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
241 |
|
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
242 |
String stclientCmd = Util.getSvcClientCommand(registryFile.getCanonicalPath()); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
243 |
System.out.println("stclient cmd: " + stclientCmd); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
244 |
System.setProperty("servicetag.stclient.cmd", stclientCmd); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
245 |
|
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
246 |
// get the Registry object after the system properties are set |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
247 |
registry = Registry.getSystemRegistry(); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
248 |
return registry; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
249 |
} |
5815
8c68030e27b1
6962815: support enable and disable of the servicetag's system registry for testing purpose
mchung
parents:
5506
diff
changeset
|
250 |
|
8c68030e27b1
6962815: support enable and disable of the servicetag's system registry for testing purpose
mchung
parents:
5506
diff
changeset
|
251 |
static void emptyRegistryFile() throws IOException { |
8c68030e27b1
6962815: support enable and disable of the servicetag's system registry for testing purpose
mchung
parents:
5506
diff
changeset
|
252 |
if (registryFile.exists()) { |
8c68030e27b1
6962815: support enable and disable of the servicetag's system registry for testing purpose
mchung
parents:
5506
diff
changeset
|
253 |
BufferedOutputStream out = new BufferedOutputStream( |
8c68030e27b1
6962815: support enable and disable of the servicetag's system registry for testing purpose
mchung
parents:
5506
diff
changeset
|
254 |
new FileOutputStream(registryFile)); |
8c68030e27b1
6962815: support enable and disable of the servicetag's system registry for testing purpose
mchung
parents:
5506
diff
changeset
|
255 |
try { |
8c68030e27b1
6962815: support enable and disable of the servicetag's system registry for testing purpose
mchung
parents:
5506
diff
changeset
|
256 |
RegistrationData data = new RegistrationData(); |
8c68030e27b1
6962815: support enable and disable of the servicetag's system registry for testing purpose
mchung
parents:
5506
diff
changeset
|
257 |
data.storeToXML(out); |
8c68030e27b1
6962815: support enable and disable of the servicetag's system registry for testing purpose
mchung
parents:
5506
diff
changeset
|
258 |
} finally { |
8c68030e27b1
6962815: support enable and disable of the servicetag's system registry for testing purpose
mchung
parents:
5506
diff
changeset
|
259 |
out.close(); |
8c68030e27b1
6962815: support enable and disable of the servicetag's system registry for testing purpose
mchung
parents:
5506
diff
changeset
|
260 |
} |
8c68030e27b1
6962815: support enable and disable of the servicetag's system registry for testing purpose
mchung
parents:
5506
diff
changeset
|
261 |
} |
8c68030e27b1
6962815: support enable and disable of the servicetag's system registry for testing purpose
mchung
parents:
5506
diff
changeset
|
262 |
} |
1327
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
263 |
} |