author | ohair |
Tue, 28 Dec 2010 15:53:50 -0800 | |
changeset 7668 | d4a77089c587 |
parent 6679 | bd0c524be1b4 |
permissions | -rw-r--r-- |
1327
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
1 |
/* |
7668 | 2 |
* Copyright (c) 2008, 2010, 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 |
package com.sun.servicetag; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
27 |
|
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
28 |
import java.io.*; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
29 |
import java.util.ArrayList; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
30 |
import java.util.Date; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
31 |
import java.util.HashSet; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
32 |
import java.util.List; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
33 |
import java.util.Properties; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
34 |
import java.util.Set; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
35 |
|
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
36 |
import static com.sun.servicetag.Util.*; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
37 |
import static com.sun.servicetag.RegistrationDocument.*; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
38 |
|
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
39 |
/** |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
40 |
* A service tag registry is a XML-based registry containing |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
41 |
* the list of {@link ServiceTag service tags} installed in the system. |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
42 |
* The {@code Registry} class provides interfaces |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
43 |
* to add, remove, update, and get a service tag from a service tag |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
44 |
* registry. |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
45 |
* This {@code Registry} class may not be supported |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
46 |
* on all systems. The {@link #isSupported} method |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
47 |
* can be called to determine if it is supported. |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
48 |
* <p> |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
49 |
* A registry may implement restrictions to only allow certain users |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
50 |
* to {@link #updateServiceTag update} and |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
51 |
* to {@link #removeServiceTag remove} a service tag record. Typically, |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
52 |
* only the owner of the service tag, the owner of the registry |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
53 |
* and superuser are authorized to update or remove a service tag in |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
54 |
* the registry. |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
55 |
* |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
56 |
* @see <a href="https://sn-tools.central.sun.com/twiki/bin/view/ServiceTags/ServiceTagDevGuideHelper"> |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
57 |
* Service Tag User Guide</a> |
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 |
public class Registry { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
60 |
|
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
61 |
private static final String STCLIENT_SOLARIS = "/usr/bin/stclient"; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
62 |
private static final String STCLIENT_LINUX = "/opt/sun/servicetag/bin/stclient"; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
63 |
// stclient exit value (see sthelper.h) |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
64 |
private static final int ST_ERR_NOT_AUTH = 245; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
65 |
private static final int ST_ERR_REC_NOT_FOUND = 225; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
66 |
|
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
67 |
// The stclient output has to be an exported interface |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
68 |
private static final String INSTANCE_URN_DESC = "Product instance URN="; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
69 |
private static boolean initialized = false; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
70 |
private static File stclient = null; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
71 |
private static String stclientPath = null; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
72 |
private static Registry registry = new Registry(); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
73 |
|
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
74 |
// System properties for testing |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
75 |
private static String SVCTAG_STCLIENT_CMD = "servicetag.stclient.cmd"; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
76 |
private static String SVCTAG_STHELPER_SUPPORTED = "servicetag.sthelper.supported"; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
77 |
|
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
78 |
private Registry() { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
79 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
80 |
|
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
81 |
private synchronized static String getSTclient() { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
82 |
if (!initialized) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
83 |
// Initialization to determine the platform's stclient pathname |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
84 |
String os = System.getProperty("os.name"); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
85 |
if (os.equals("SunOS")) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
86 |
stclient = new File(STCLIENT_SOLARIS); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
87 |
} else if (os.equals("Linux")) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
88 |
stclient = new File(STCLIENT_LINUX); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
89 |
} else if (os.startsWith("Windows")) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
90 |
stclient = getWindowsStClientFile(); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
91 |
} else { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
92 |
if (isVerbose()) { |
6679 | 93 |
System.out.println("Running on unsupported platform"); |
1327
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 |
initialized = true; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
97 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
98 |
|
5815
8c68030e27b1
6962815: support enable and disable of the servicetag's system registry for testing purpose
mchung
parents:
5506
diff
changeset
|
99 |
boolean supportsHelperClass = true; // default |
8c68030e27b1
6962815: support enable and disable of the servicetag's system registry for testing purpose
mchung
parents:
5506
diff
changeset
|
100 |
if (System.getProperty(SVCTAG_STHELPER_SUPPORTED) != null) { |
8c68030e27b1
6962815: support enable and disable of the servicetag's system registry for testing purpose
mchung
parents:
5506
diff
changeset
|
101 |
// the system property always overrides the default setting |
8c68030e27b1
6962815: support enable and disable of the servicetag's system registry for testing purpose
mchung
parents:
5506
diff
changeset
|
102 |
supportsHelperClass = Boolean.getBoolean(SVCTAG_STHELPER_SUPPORTED); |
8c68030e27b1
6962815: support enable and disable of the servicetag's system registry for testing purpose
mchung
parents:
5506
diff
changeset
|
103 |
} |
8c68030e27b1
6962815: support enable and disable of the servicetag's system registry for testing purpose
mchung
parents:
5506
diff
changeset
|
104 |
|
8c68030e27b1
6962815: support enable and disable of the servicetag's system registry for testing purpose
mchung
parents:
5506
diff
changeset
|
105 |
if (!supportsHelperClass) { |
8c68030e27b1
6962815: support enable and disable of the servicetag's system registry for testing purpose
mchung
parents:
5506
diff
changeset
|
106 |
// disable system registry |
8c68030e27b1
6962815: support enable and disable of the servicetag's system registry for testing purpose
mchung
parents:
5506
diff
changeset
|
107 |
return null; |
8c68030e27b1
6962815: support enable and disable of the servicetag's system registry for testing purpose
mchung
parents:
5506
diff
changeset
|
108 |
} |
8c68030e27b1
6962815: support enable and disable of the servicetag's system registry for testing purpose
mchung
parents:
5506
diff
changeset
|
109 |
|
8c68030e27b1
6962815: support enable and disable of the servicetag's system registry for testing purpose
mchung
parents:
5506
diff
changeset
|
110 |
// This is only used for testing |
8c68030e27b1
6962815: support enable and disable of the servicetag's system registry for testing purpose
mchung
parents:
5506
diff
changeset
|
111 |
String path = System.getProperty(SVCTAG_STCLIENT_CMD); |
8c68030e27b1
6962815: support enable and disable of the servicetag's system registry for testing purpose
mchung
parents:
5506
diff
changeset
|
112 |
if (path != null) { |
8c68030e27b1
6962815: support enable and disable of the servicetag's system registry for testing purpose
mchung
parents:
5506
diff
changeset
|
113 |
return path; |
8c68030e27b1
6962815: support enable and disable of the servicetag's system registry for testing purpose
mchung
parents:
5506
diff
changeset
|
114 |
} |
8c68030e27b1
6962815: support enable and disable of the servicetag's system registry for testing purpose
mchung
parents:
5506
diff
changeset
|
115 |
|
1327
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
116 |
// com.sun.servicetag package has to be compiled with JDK 5 as well |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
117 |
// JDK 5 doesn't support the File.canExecute() method. |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
118 |
// Risk not checking isExecute() for the stclient command is very low. |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
119 |
if (stclientPath == null && stclient != null && stclient.exists()) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
120 |
stclientPath = stclient.getAbsolutePath(); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
121 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
122 |
return stclientPath; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
123 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
124 |
|
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
125 |
/** |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
126 |
* Returns the system service tag registry. The {@code Registry} class |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
127 |
* may not be supported on some platforms; use the {@link #isSupported} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
128 |
* method to determine if it is supported. |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
129 |
* |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
130 |
* @return the {@code Registry} object for the system service tag registry. |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
131 |
* |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
132 |
* @throws UnsupportedOperationException if the {@code Registry} class is |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
133 |
* not supported. |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
134 |
*/ |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
135 |
public static Registry getSystemRegistry() { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
136 |
if (isSupported()) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
137 |
return registry; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
138 |
} else { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
139 |
throw new UnsupportedOperationException("Registry class is not supported"); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
140 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
141 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
142 |
|
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 |
* Returns {@code true} if the {@code Registry} class is supported on this system. |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
145 |
* |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
146 |
* @return {@code true} if the {@code Registry} class is supported; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
147 |
* otherwise, return {@code false}. |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
148 |
*/ |
5815
8c68030e27b1
6962815: support enable and disable of the servicetag's system registry for testing purpose
mchung
parents:
5506
diff
changeset
|
149 |
public static synchronized boolean isSupported() { |
8c68030e27b1
6962815: support enable and disable of the servicetag's system registry for testing purpose
mchung
parents:
5506
diff
changeset
|
150 |
return getSTclient() != null; |
1327
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 |
|
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
153 |
private static List<String> getCommandList() { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
154 |
// Set up the arguments to call stclient |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
155 |
List<String> command = new ArrayList<String>(); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
156 |
if (System.getProperty(SVCTAG_STCLIENT_CMD) != null) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
157 |
// This is for jtreg testing use. This will be set to something |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
158 |
// like: |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
159 |
// $JAVA_HOME/bin/java -cp $TEST_DIR \ |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
160 |
// -Dstclient.registry.path=$TEST_DIR/registry.xml \ |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
161 |
// SvcTagClient |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
162 |
// |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
163 |
// On Windows, the JAVA_HOME and TEST_DIR path could contain |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
164 |
// space e.g. c:\Program Files\Java\jdk1.6.0_05\bin\java. |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
165 |
// The SVCTAG_STCLIENT_CMD must be set with a list of |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
166 |
// space-separated parameters. If a parameter contains spaces, |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
167 |
// it must be quoted with '"'. |
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 |
String cmd = getSTclient(); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
170 |
int len = cmd.length(); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
171 |
int i = 0; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
172 |
while (i < len) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
173 |
char separator = ' '; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
174 |
if (cmd.charAt(i) == '"') { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
175 |
separator = '"'; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
176 |
i++; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
177 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
178 |
// look for the separator or matched the closing '"' |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
179 |
int j; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
180 |
for (j = i+1; j < len; j++) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
181 |
if (cmd.charAt(j) == separator) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
182 |
break; |
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 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
185 |
|
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
186 |
if (i == j-1) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
187 |
// add an empty parameter |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
188 |
command.add("\"\""); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
189 |
} else { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
190 |
// double quotes and space are not included |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
191 |
command.add(cmd.substring(i,j)); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
192 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
193 |
|
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
194 |
// skip spaces |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
195 |
for (i = j+1; i < len; i++) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
196 |
if (!Character.isSpaceChar(cmd.charAt(i))) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
197 |
break; |
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 |
if (isVerbose()) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
202 |
System.out.println("Command list:"); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
203 |
for (String s : command) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
204 |
System.out.println(s); |
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 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
207 |
} else { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
208 |
command.add(getSTclient()); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
209 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
210 |
return command; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
211 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
212 |
|
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
213 |
// Returns null if the service tag record not found; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
214 |
// or throw UnauthorizedAccessException or IOException |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
215 |
// based on the exitValue. |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
216 |
private static ServiceTag checkReturnError(int exitValue, |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
217 |
String output, |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
218 |
ServiceTag st) throws IOException { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
219 |
switch (exitValue) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
220 |
case ST_ERR_REC_NOT_FOUND: |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
221 |
return null; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
222 |
case ST_ERR_NOT_AUTH: |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
223 |
if (st != null) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
224 |
throw new UnauthorizedAccessException( |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
225 |
"Not authorized to access " + st.getInstanceURN() + |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
226 |
" installer_uid=" + st.getInstallerUID()); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
227 |
} else { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
228 |
throw new UnauthorizedAccessException( |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
229 |
"Not authorized:" + output); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
230 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
231 |
default: |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
232 |
throw new IOException("stclient exits with error" + |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
233 |
" (" + exitValue + ")\n" + output); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
234 |
} |
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 |
/** |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
238 |
* Adds a service tag to this registry. |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
239 |
* If the given service tag has an empty <tt>instance_urn</tt>, |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
240 |
* this helper class will generate a URN and place it in the |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
241 |
* copy of the service tag in this registry. |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
242 |
* This method will return the {@code ServiceTag} representing |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
243 |
* the service tag entry to this registry. |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
244 |
* |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
245 |
* @param st {@code ServiceTag} object |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
246 |
* @return a {@code ServiceTag} object representing the service tag |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
247 |
* entry to this registry. |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
248 |
* |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
249 |
* @throws IllegalArgumentException if a service tag of the same |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
250 |
* <tt>instance_urn</tt> already exists in this registry. |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
251 |
* |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
252 |
* @throws java.io.IOException if an I/O error occurs in this operation. |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
253 |
*/ |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
254 |
public ServiceTag addServiceTag(ServiceTag st) throws IOException { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
255 |
List<String> command = getCommandList(); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
256 |
command.add("-a"); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
257 |
if (st.getInstanceURN().length() > 0) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
258 |
ServiceTag sysSvcTag = getServiceTag(st.getInstanceURN()); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
259 |
if (sysSvcTag != null) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
260 |
throw new IllegalArgumentException("Instance_urn = " + |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
261 |
st.getInstanceURN() + " already exists"); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
262 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
263 |
command.add("-i"); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
264 |
command.add(st.getInstanceURN()); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
265 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
266 |
command.add("-p"); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
267 |
command.add(st.getProductName()); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
268 |
command.add("-e"); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
269 |
command.add(st.getProductVersion()); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
270 |
command.add("-t"); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
271 |
command.add(st.getProductURN()); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
272 |
if (st.getProductParentURN().length() > 0) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
273 |
command.add("-F"); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
274 |
command.add(st.getProductParentURN()); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
275 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
276 |
command.add("-P"); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
277 |
command.add(st.getProductParent()); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
278 |
if (st.getProductDefinedInstanceID().length() > 0) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
279 |
command.add("-I"); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
280 |
command.add(st.getProductDefinedInstanceID()); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
281 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
282 |
command.add("-m"); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
283 |
command.add(st.getProductVendor()); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
284 |
command.add("-A"); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
285 |
command.add(st.getPlatformArch()); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
286 |
command.add("-z"); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
287 |
command.add(st.getContainer()); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
288 |
command.add("-S"); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
289 |
command.add(st.getSource()); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
290 |
|
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
291 |
BufferedReader in = null; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
292 |
try { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
293 |
ProcessBuilder pb = new ProcessBuilder(command); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
294 |
Process p = pb.start(); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
295 |
String output = commandOutput(p); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
296 |
if (isVerbose()) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
297 |
System.out.println("Output from stclient -a command:"); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
298 |
System.out.println(output); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
299 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
300 |
String urn = ""; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
301 |
if (p.exitValue() == 0) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
302 |
// Obtain the instance urn from the stclient output |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
303 |
in = new BufferedReader(new StringReader(output)); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
304 |
String line = null; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
305 |
while ((line = in.readLine()) != null) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
306 |
line = line.trim(); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
307 |
if (line.startsWith(INSTANCE_URN_DESC)) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
308 |
urn = line.substring(INSTANCE_URN_DESC.length()); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
309 |
break; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
310 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
311 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
312 |
if (urn.length() == 0) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
313 |
throw new IOException("Error in creating service tag:\n" + |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
314 |
output); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
315 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
316 |
return getServiceTag(urn); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
317 |
} else { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
318 |
return checkReturnError(p.exitValue(), output, st); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
319 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
320 |
} finally { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
321 |
if (in != null) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
322 |
in.close(); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
323 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
324 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
325 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
326 |
|
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
327 |
/** |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
328 |
* Removes a service tag of the given <tt>instance_urn</tt> from this |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
329 |
* registry. |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
330 |
* |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
331 |
* @param instanceURN the <tt>instance_urn</tt> of the service tag |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
332 |
* to be removed. |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
333 |
* |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
334 |
* @return the {@code ServiceTag} object removed from this registry; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
335 |
* or {@code null} if the service tag does not exist in this registry. |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
336 |
* |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
337 |
* @throws UnauthorizedAccessException if the user is not authorized to |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
338 |
* remove the service tag of the given <tt>instance_urn</tt> |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
339 |
* from this registry. |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
340 |
* |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
341 |
* @throws java.io.IOException if an I/O error occurs in this operation. |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
342 |
*/ |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
343 |
public ServiceTag removeServiceTag(String instanceURN) throws IOException { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
344 |
ServiceTag st = getServiceTag(instanceURN); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
345 |
if (st == null) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
346 |
return null; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
347 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
348 |
|
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
349 |
List<String> command = getCommandList(); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
350 |
command.add("-d"); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
351 |
command.add("-i"); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
352 |
command.add(instanceURN); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
353 |
|
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
354 |
ProcessBuilder pb = new ProcessBuilder(command); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
355 |
Process p = pb.start(); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
356 |
String output = commandOutput(p); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
357 |
if (isVerbose()) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
358 |
System.out.println("Output from stclient -d command:"); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
359 |
System.out.println(output); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
360 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
361 |
if (p.exitValue() == 0) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
362 |
return st; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
363 |
} else { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
364 |
return checkReturnError(p.exitValue(), output, st); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
365 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
366 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
367 |
|
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
368 |
/** |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
369 |
* Updates the <tt>product_defined_instance_id</tt> in the service tag |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
370 |
* of the specified <tt>instance_urn</tt> in this registry. |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
371 |
* |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
372 |
* @param instanceURN the <tt>instance_urn</tt> of the service tag to be updated. |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
373 |
* @param productDefinedInstanceID the value of the |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
374 |
* <tt>product_defined_instance_id</tt> to be set. |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
375 |
* |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
376 |
* @return the updated {@code ServiceTag} object; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
377 |
* or {@code null} if the service tag does not exist in this |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
378 |
* registry. |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
379 |
* |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
380 |
* @throws UnauthorizedAccessException if the user is not authorized to |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
381 |
* update the service tag from this registry. |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
382 |
* |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
383 |
* @throws IOException if an I/O error occurs in this operation. |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
384 |
*/ |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
385 |
public ServiceTag updateServiceTag(String instanceURN, |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
386 |
String productDefinedInstanceID) |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
387 |
throws IOException { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
388 |
ServiceTag svcTag = getServiceTag(instanceURN); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
389 |
if (svcTag == null) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
390 |
return null; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
391 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
392 |
|
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
393 |
List<String> command = getCommandList(); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
394 |
command.add("-u"); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
395 |
command.add("-i"); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
396 |
command.add(instanceURN); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
397 |
command.add("-I"); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
398 |
if (productDefinedInstanceID.length() > 0) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
399 |
command.add(productDefinedInstanceID); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
400 |
} else { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
401 |
command.add("\"\""); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
402 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
403 |
|
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
404 |
ProcessBuilder pb = new ProcessBuilder(command); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
405 |
Process p = pb.start(); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
406 |
String output = commandOutput(p); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
407 |
if (isVerbose()) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
408 |
System.out.println("Output from stclient -u command:"); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
409 |
System.out.println(output); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
410 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
411 |
|
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
412 |
if (p.exitValue() == 0) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
413 |
return getServiceTag(instanceURN); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
414 |
} else { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
415 |
return checkReturnError(p.exitValue(), output, svcTag); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
416 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
417 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
418 |
|
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
419 |
/** |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
420 |
* Returns a {@code ServiceTag} object of the given <tt>instance_urn</tt> |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
421 |
* in this registry. |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
422 |
* |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
423 |
* @param instanceURN the <tt>instance_urn</tt> of the service tag |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
424 |
* @return a {@code ServiceTag} object of the given <tt>instance_urn</tt> |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
425 |
* in this registry; or {@code null} if not found. |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
426 |
* |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
427 |
* @throws java.io.IOException if an I/O error occurs in this operation. |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
428 |
*/ |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
429 |
public ServiceTag getServiceTag(String instanceURN) throws IOException { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
430 |
if (instanceURN == null) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
431 |
throw new NullPointerException("instanceURN is null"); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
432 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
433 |
|
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
434 |
List<String> command = getCommandList(); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
435 |
command.add("-g"); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
436 |
command.add("-i"); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
437 |
command.add(instanceURN); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
438 |
|
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
439 |
ProcessBuilder pb = new ProcessBuilder(command); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
440 |
Process p = pb.start(); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
441 |
String output = commandOutput(p); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
442 |
if (isVerbose()) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
443 |
System.out.println("Output from stclient -g command:"); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
444 |
System.out.println(output); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
445 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
446 |
if (p.exitValue() == 0) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
447 |
return parseServiceTag(output); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
448 |
} else { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
449 |
return checkReturnError(p.exitValue(), output, null); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
450 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
451 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
452 |
|
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
453 |
private ServiceTag parseServiceTag(String output) throws IOException { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
454 |
BufferedReader in = null; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
455 |
try { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
456 |
Properties props = new Properties(); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
457 |
// parse the service tag output from stclient |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
458 |
in = new BufferedReader(new StringReader(output)); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
459 |
String line = null; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
460 |
while ((line = in.readLine()) != null) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
461 |
if ((line = line.trim()).length() > 0) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
462 |
String[] ss = line.trim().split("=", 2); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
463 |
if (ss.length == 2) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
464 |
props.setProperty(ss[0].trim(), ss[1].trim()); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
465 |
} else { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
466 |
props.setProperty(ss[0].trim(), ""); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
467 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
468 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
469 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
470 |
|
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
471 |
String urn = props.getProperty(ST_NODE_INSTANCE_URN); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
472 |
String productName = props.getProperty(ST_NODE_PRODUCT_NAME); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
473 |
String productVersion = props.getProperty(ST_NODE_PRODUCT_VERSION); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
474 |
String productURN = props.getProperty(ST_NODE_PRODUCT_URN); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
475 |
String productParent = props.getProperty(ST_NODE_PRODUCT_PARENT); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
476 |
String productParentURN = props.getProperty(ST_NODE_PRODUCT_PARENT_URN); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
477 |
String productDefinedInstanceID = |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
478 |
props.getProperty(ST_NODE_PRODUCT_DEFINED_INST_ID); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
479 |
String productVendor = props.getProperty(ST_NODE_PRODUCT_VENDOR); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
480 |
String platformArch = props.getProperty(ST_NODE_PLATFORM_ARCH); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
481 |
String container = props.getProperty(ST_NODE_CONTAINER); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
482 |
String source = props.getProperty(ST_NODE_SOURCE); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
483 |
int installerUID = |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
484 |
Util.getIntValue(props.getProperty(ST_NODE_INSTALLER_UID)); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
485 |
Date timestamp = |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
486 |
Util.parseTimestamp(props.getProperty(ST_NODE_TIMESTAMP)); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
487 |
|
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
488 |
return new ServiceTag(urn, |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
489 |
productName, |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
490 |
productVersion, |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
491 |
productURN, |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
492 |
productParent, |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
493 |
productParentURN, |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
494 |
productDefinedInstanceID, |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
495 |
productVendor, |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
496 |
platformArch, |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
497 |
container, |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
498 |
source, |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
499 |
installerUID, |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
500 |
timestamp); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
501 |
} finally { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
502 |
if (in != null) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
503 |
in.close(); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
504 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
505 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
506 |
|
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
507 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
508 |
|
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
509 |
/** |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
510 |
* Returns the service tags of the specified |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
511 |
* <tt>product_urn</tt> in this registry. |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
512 |
* |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
513 |
* @param productURN the <tt>product_urn</tt> to look up |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
514 |
* @return a {@code Set} of {@code ServiceTag} objects |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
515 |
* of the specified <tt>product_urn</tt> in this registry. |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
516 |
* |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
517 |
* @throws java.io.IOException if an I/O error occurs in this operation. |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
518 |
*/ |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
519 |
public Set<ServiceTag> findServiceTags(String productURN) throws IOException { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
520 |
if (productURN == null) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
521 |
throw new NullPointerException("productURN is null"); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
522 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
523 |
|
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
524 |
List<String> command = getCommandList(); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
525 |
command.add("-f"); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
526 |
command.add("-t"); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
527 |
command.add(productURN); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
528 |
|
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
529 |
BufferedReader in = null; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
530 |
try { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
531 |
ProcessBuilder pb = new ProcessBuilder(command); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
532 |
Process p = pb.start(); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
533 |
String output = commandOutput(p); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
534 |
|
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
535 |
Set<ServiceTag> instances = new HashSet<ServiceTag>(); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
536 |
if (p.exitValue() == 0) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
537 |
// parse the service tag output from stclient |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
538 |
in = new BufferedReader(new StringReader(output)); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
539 |
String line = null; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
540 |
while ((line = in.readLine()) != null) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
541 |
String s = line.trim(); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
542 |
if (s.startsWith("urn:st:")) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
543 |
instances.add(getServiceTag(s)); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
544 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
545 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
546 |
} else { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
547 |
checkReturnError(p.exitValue(), output, null); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
548 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
549 |
return instances; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
550 |
} finally { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
551 |
if (in != null) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
552 |
in.close(); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
553 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
554 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
555 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
556 |
} |