summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOliver Bolte <obo@openoffice.org>2009-12-11 11:17:18 +0000
committerOliver Bolte <obo@openoffice.org>2009-12-11 11:17:18 +0000
commitb1f7f1382f58be2870df59c045dc288bec6139cc (patch)
tree72571f552f3ff2efd776635e6a2265be2c6c5cd1
parent0c2044e9bfc79f86ab11257bd472f8b8e130fa70 (diff)
CWS-TOOLING: integrate CWS fwk131
2009-12-09 14:31:58 +0100 cd r277766 : #161124# Fix problem with cpu frequency as float. Added context class loader code to fix problems with certain Java versions. 2009-12-04 12:06:17 +0100 mav r277732 : #i107440# in case of problems with extensions the office libraries still should be usable 2009-12-03 18:22:08 +0100 ab r277716 : #i107283# Pass config help path as argument to compileExtensionHelp() 2009-12-03 18:21:16 +0100 ab r277715 : #i107283# Pass config help path as argument to compileExtensionHelp() 2009-12-03 10:35:18 +0100 cd r277707 : #161124# Update service tag implementation for additional fields 2009-11-30 14:04:15 +0100 ab r277674 : #i107263 Fixed service ctor search algorithm 2009-11-27 10:59:04 +0100 cd r277666 : #161124# Update service tag sources 2009-11-26 15:14:53 +0100 cd r277659 : #i107087# Remove event listener from tab window on TabWindowService dtor 2009-11-25 15:05:01 +0100 cd r277637 : #i107087# TabWindowService must set member pointer to zero on VCLEVENT_OBJECT_DYING. The window life time is controlled by the docking window! Adding missing RemoveEventListener call.
-rw-r--r--basic/source/classes/sbunoobj.cxx3
-rw-r--r--basic/source/uno/namecont.cxx12
-rw-r--r--desktop/source/deployment/registry/help/dp_help.cxx7
-rw-r--r--desktop/source/registration/com/sun/star/servicetag/BrowserSupport.java7
-rw-r--r--desktop/source/registration/com/sun/star/servicetag/Installer.java9
-rw-r--r--desktop/source/registration/com/sun/star/servicetag/LinuxSystemEnvironment.java146
-rw-r--r--desktop/source/registration/com/sun/star/servicetag/RegistrationData.java1004
-rw-r--r--desktop/source/registration/com/sun/star/servicetag/RegistrationDocument.java814
-rw-r--r--desktop/source/registration/com/sun/star/servicetag/Registry.java7
-rw-r--r--desktop/source/registration/com/sun/star/servicetag/ServiceTag.java7
-rw-r--r--desktop/source/registration/com/sun/star/servicetag/SolarisServiceTag.java7
-rw-r--r--desktop/source/registration/com/sun/star/servicetag/SolarisSystemEnvironment.java281
-rw-r--r--desktop/source/registration/com/sun/star/servicetag/SunConnection.java7
-rw-r--r--desktop/source/registration/com/sun/star/servicetag/SysnetRegistryHelper.java7
-rw-r--r--desktop/source/registration/com/sun/star/servicetag/SystemEnvironment.java93
-rw-r--r--desktop/source/registration/com/sun/star/servicetag/UnauthorizedAccessException.java7
-rw-r--r--desktop/source/registration/com/sun/star/servicetag/Util.java9
-rw-r--r--desktop/source/registration/com/sun/star/servicetag/WindowsSystemEnvironment.java100
-rw-r--r--desktop/source/registration/com/sun/star/servicetag/resources/product_registration.xsd667
-rw-r--r--framework/inc/classes/fwktabwindow.hxx1
-rw-r--r--framework/inc/services/tabwindowservice.hxx87
-rw-r--r--framework/source/classes/fwktabwindow.cxx6
-rw-r--r--framework/source/services/tabwindowservice.cxx32
23 files changed, 2055 insertions, 1265 deletions
diff --git a/basic/source/classes/sbunoobj.cxx b/basic/source/classes/sbunoobj.cxx
index 8ee3df992e..70f2150a41 100644
--- a/basic/source/classes/sbunoobj.cxx
+++ b/basic/source/classes/sbunoobj.cxx
@@ -3377,9 +3377,10 @@ SbxVariable* SbUnoService::Find( const String& rName, SbxClassType )
// Create and insert SbUnoServiceCtor
SbxVariableRef xSbCtorRef = new SbUnoServiceCtor( aName, xCtor );
QuickInsert( (SbxVariable*)xSbCtorRef );
- pRes = xSbCtorRef;
}
}
+
+ pRes = SbxObject::Find( rName, SbxCLASS_METHOD );
}
}
diff --git a/basic/source/uno/namecont.cxx b/basic/source/uno/namecont.cxx
index c15d937f9b..3ad2332d9a 100644
--- a/basic/source/uno/namecont.cxx
+++ b/basic/source/uno/namecont.cxx
@@ -940,7 +940,17 @@ sal_Bool SfxLibraryContainer::init_Impl(
// #110009
if( !bStorage && meInitMode == DEFAULT )
- implScanExtensions();
+ {
+ try
+ {
+ implScanExtensions();
+ }
+ catch( uno::Exception& )
+ {
+ // TODO: error handling?
+ OSL_ASSERT( "Cannot access extensions!" );
+ }
+ }
// #110009 Preload?
{
diff --git a/desktop/source/deployment/registry/help/dp_help.cxx b/desktop/source/deployment/registry/help/dp_help.cxx
index 8ef0a7141a..9b532d68e4 100644
--- a/desktop/source/deployment/registry/help/dp_help.cxx
+++ b/desktop/source/deployment/registry/help/dp_help.cxx
@@ -39,6 +39,7 @@
#include "ucbhelper/content.hxx"
#include "comphelper/servicedecl.hxx"
#include "svtools/inettype.hxx"
+#include "svtools/pathoptions.hxx"
#include <transex3/compilehelp.hxx>
#include <com/sun/star/ucb/XSimpleFileAccess.hpp>
@@ -350,8 +351,12 @@ void BackendImpl::implProcessHelp
pXhpFiles[iXhp] = aXhpRelFile;
}
+ rtl::OUString aOfficeHelpPath( SvtPathOptions().GetHelpPath() );
+ rtl::OUString aOfficeHelpPathFileURL;
+ ::osl::File::getFileURLFromSystemPath( aOfficeHelpPath, aOfficeHelpPathFileURL );
+
HelpProcessingErrorInfo aErrorInfo;
- bool bSuccess = compileExtensionHelp( aHelpStr, aLangURL,
+ bool bSuccess = compileExtensionHelp( aOfficeHelpPathFileURL, aHelpStr, aLangURL,
nXhpFileCount, pXhpFiles, aErrorInfo );
if( bSuccess && xInvocation.is() )
diff --git a/desktop/source/registration/com/sun/star/servicetag/BrowserSupport.java b/desktop/source/registration/com/sun/star/servicetag/BrowserSupport.java
index 7623e7f2f6..b0e944a0f8 100644
--- a/desktop/source/registration/com/sun/star/servicetag/BrowserSupport.java
+++ b/desktop/source/registration/com/sun/star/servicetag/BrowserSupport.java
@@ -1,14 +1,13 @@
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
+ *
* Copyright 2008 by Sun Microsystems, Inc.
*
* OpenOffice.org - a multi-platform office productivity suite
*
- * $RCSfile: BrowserSupport.java,v $
- *
- * $Revision: 1.2 $
+ * $RCSfile: Registration.java,v $
+ * $Revision: 1.3 $
*
* This file is part of OpenOffice.org.
*
diff --git a/desktop/source/registration/com/sun/star/servicetag/Installer.java b/desktop/source/registration/com/sun/star/servicetag/Installer.java
index b8e6e34dfd..f3b0b9c3c3 100644
--- a/desktop/source/registration/com/sun/star/servicetag/Installer.java
+++ b/desktop/source/registration/com/sun/star/servicetag/Installer.java
@@ -1,14 +1,13 @@
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
+ *
* Copyright 2008 by Sun Microsystems, Inc.
*
* OpenOffice.org - a multi-platform office productivity suite
*
- * $RCSfile: Installer.java,v $
- *
- * $Revision: 1.2 $
+ * $RCSfile: Registration.java,v $
+ * $Revision: 1.3 $
*
* This file is part of OpenOffice.org.
*
@@ -794,7 +793,7 @@ public class Installer {
reader.close();
}
- String resourceFilename = "/com/sun/star/servicetag/resources/register";
+ String resourceFilename = "/com/sun/servicetag/resources/register";
for (Locale locale : supportedLocales) {
String name = REGISTRATION_HTML_NAME;
String resource = resourceFilename;
diff --git a/desktop/source/registration/com/sun/star/servicetag/LinuxSystemEnvironment.java b/desktop/source/registration/com/sun/star/servicetag/LinuxSystemEnvironment.java
index 88ccd453a1..a58072d363 100644
--- a/desktop/source/registration/com/sun/star/servicetag/LinuxSystemEnvironment.java
+++ b/desktop/source/registration/com/sun/star/servicetag/LinuxSystemEnvironment.java
@@ -1,14 +1,13 @@
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
+ *
* Copyright 2008 by Sun Microsystems, Inc.
*
* OpenOffice.org - a multi-platform office productivity suite
*
- * $RCSfile: LinuxSystemEnvironment.java,v $
- *
- * $Revision: 1.2 $
+ * $RCSfile: Registration.java,v $
+ * $Revision: 1.3 $
*
* This file is part of OpenOffice.org.
*
@@ -29,6 +28,7 @@
*
************************************************************************/
+
package com.sun.star.servicetag;
// The Service Tags team maintains the latest version of the implementation
@@ -40,6 +40,7 @@ package com.sun.star.servicetag;
// (e.g. NetBeans and SunStudio) will use the version in JDK.
import java.io.*;
+import java.util.*;
/**
* Linux implementation of the SystemEnvironment class.
@@ -47,16 +48,25 @@ import java.io.*;
class LinuxSystemEnvironment extends SystemEnvironment {
LinuxSystemEnvironment() {
setHostId(getLinuxHostId());
- setSystemModel(getCommandOutput("/bin/uname", "-i"));
+
+ setSystemModel(getLinuxModel());
setSystemManufacturer(getLinuxSystemManufacturer());
setCpuManufacturer(getLinuxCpuManufacturer());
setSerialNumber(getLinuxSN());
+ setPhysMem(getLinuxPhysMem());
+ setSockets(getLinuxSockets());
+ setCores(getLinuxCores());
+ setVirtCpus(getLinuxVirtCpus());
+ setCpuName(getLinuxCpuName());
+ setClockRate(getLinuxClockRate());
}
private String dmiInfo = null;
+ private String kstatCpuInfo = null;
- private static final int SN = 1;
+ private static final int SN = 1;
private static final int SYS = 2;
private static final int CPU = 3;
+ private static final int MODEL = 4;
private String getLinuxHostId() {
String output = getCommandOutput("/usr/bin/hostid");
@@ -91,6 +101,21 @@ class LinuxSystemEnvironment extends SystemEnvironment {
return getLinuxDMIInfo("dmi type 4", "manufacturer");
}
+ private String getLinuxModel() {
+ String tmp = getLinuxPSNInfo(MODEL);
+ if (tmp.length() > 0) {
+ return tmp + "::" + getCommandOutput("/bin/uname","-v");
+ }
+
+ tmp = getLinuxDMIInfo("dmi type 1", "product name");
+ if (tmp.length() > 0) {
+ return tmp + "::" + getCommandOutput("/bin/uname","-v");
+ }
+
+ return getCommandOutput("/bin/uname","-i")
+ + "::" + getCommandOutput("/bin/uname","-v");
+ }
+
/**
* Tries to obtain and return the system manufacturer.
@@ -158,7 +183,7 @@ class LinuxSystemEnvironment extends SystemEnvironment {
dmidecodeThread.start();
try {
- dmidecodeThread.join(2000);
+ dmidecodeThread.join(3000);
if (dmidecodeThread.isAlive()) {
dmidecodeThread.interrupt();
dmiInfo = "";
@@ -191,4 +216,111 @@ class LinuxSystemEnvironment extends SystemEnvironment {
return "";
}
+ private String getLinuxClockRate() {
+ String contents = getFileContent("/proc/cpuinfo");
+ String token = "cpu MHz";
+ for (String line : contents.split("\n")) {
+ if (line.contains(token)) {
+ String[] key = line.split(":", 2);
+ if (key.length > 1) {
+ return key[1].trim();
+ }
+ }
+ }
+ return "";
+ }
+
+ private String getLinuxCpuName() {
+ String contents = getFileContent("/proc/cpuinfo");
+ String token = "model name";
+ for (String line : contents.split("\n")) {
+ if (line.contains(token)) {
+ String[] key = line.split(":", 2);
+ if (key.length > 1) {
+ return key[1].trim();
+ }
+ }
+ }
+ return "";
+ }
+
+ private String getLinuxVirtCpus() {
+ Set<String> set = new HashSet<String>();
+ String contents = getFileContent("/proc/cpuinfo");
+ String token = "processor";
+ for (String line : contents.split("\n")) {
+ if (line.contains(token)) {
+ String[] key = line.split(":", 2);
+ if (key.length > 1) {
+ set.add(key[1].trim());
+ }
+ }
+ }
+ return "" + set.size();
+ }
+
+ private String getLinuxCores() {
+ Set<String> set = new HashSet<String>();
+ String contents = getFileContent("/proc/cpuinfo");
+ String token = "core id";
+ for (String line : contents.split("\n")) {
+ if (line.contains(token)) {
+ String[] key = line.split(":", 2);
+ if (key.length > 1) {
+ set.add(key[1].trim());
+ }
+ }
+ }
+ if (set.size() == 0) {
+ return "1";
+ }
+ return "" + set.size();
+ }
+
+ private String getLinuxPhysMem() {
+ String contents = getFileContent("/proc/meminfo");
+ for (String line : contents.split("\n")) {
+ if (line.contains("MemTotal")) {
+ String[] total = line.split(":", 2);
+ if (total.length > 1) {
+ String[] mem = total[1].trim().split(" ");
+ if (mem.length >= 1) {
+ return mem[0].trim();
+ } else {
+ return total[1].trim();
+ }
+ }
+ }
+ }
+
+ return "";
+ }
+
+ private String getLinuxSockets() {
+ Set<String> physIdSet = new HashSet<String>();
+ Set<String> procSet = new HashSet<String>();
+ String contents = getFileContent("/proc/cpuinfo");
+ String physIdToken = "physical id";
+ String procToken = "processor";
+
+ for (String line : contents.split("\n")) {
+ if (line.contains(physIdToken)) {
+ String[] key = line.split(":", 2);
+ if (key.length > 1) {
+ physIdSet.add(key[1].trim());
+ }
+ }
+
+ if (line.contains(procToken)) {
+ String[] key = line.split(":", 2);
+ if (key.length > 1) {
+ procSet.add(key[1].trim());
+ }
+ }
+ }
+ if (physIdSet.size() != 0) {
+ return "" + physIdSet.size();
+ }
+ return "" + procSet.size();
+ }
}
diff --git a/desktop/source/registration/com/sun/star/servicetag/RegistrationData.java b/desktop/source/registration/com/sun/star/servicetag/RegistrationData.java
index 44ce33dece..c58d83a33d 100644
--- a/desktop/source/registration/com/sun/star/servicetag/RegistrationData.java
+++ b/desktop/source/registration/com/sun/star/servicetag/RegistrationData.java
@@ -1,473 +1,531 @@
-/*************************************************************************
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * Copyright 2008 by Sun Microsystems, Inc.
- *
- * OpenOffice.org - a multi-platform office productivity suite
- *
- * $RCSfile: RegistrationData.java,v $
- *
- * $Revision: 1.2 $
- *
- * This file is part of OpenOffice.org.
- *
- * OpenOffice.org is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License version 3
- * only, as published by the Free Software Foundation.
- *
- * OpenOffice.org is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License version 3 for more details
- * (a copy is included in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU Lesser General Public License
- * version 3 along with OpenOffice.org. If not, see
- * <http://www.openoffice.org/license.html>
- * for a copy of the LGPLv3 License.
- *
- ************************************************************************/
-
-package com.sun.star.servicetag;
-
-import java.io.*;
-import java.net.UnknownHostException;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.Set;
-
-import static com.sun.star.servicetag.RegistrationDocument.*;
-
-/**
- * A {@code RegistrationData} object is a container of one or more
- * {@link #getServiceTags service tags} that identify the
- * components for product registration.
- * Each {@code RegistrationData} object has a {@link #getRegistrationURN
- * uniform resource name} (URN) as its identifier.
- * <a name="EnvMap"></a>
- * It also has an <i>environment map</i> with
- * the following elements:
- * <blockquote>
- * <table border=0>
- * <tr>
- * <td><tt>hostname</tt></td>
- * <td>Hostname of the system</td>
- * <td>e.g. woody</td>
- * </tr>
- * <tr>
- * <td><tt>hostId</tt></td>
- * <td>Host ID of the system</td>
- * <td>e.g. 83abc1ab</td>
- * </tr>
- * <tr>
- * <td><tt>osName</tt></td>
- * <td>Operating system name</td>
- * <td> e.g. SunOS</td>
- * </tr>
- * <tr>
- * <td><tt>osVersion</tt></td>
- * <td>Operating system version</td>
- * <td> e.g. 5.10</td>
- * </tr>
- * <tr>
- * <td><tt>osArchitecture</tt></td>
- * <td>Operating system architecture</td>
- * <td> e.g. sparc</td>
- * </tr>
- * <tr>
- * <td><tt>systemModel</tt></td>
- * <td>System model</td>
- * <td> e.g. SUNW,Sun-Fire-V440</td>
- * </tr>
- * <tr>
- * <td><tt>systemManufacturer</tt></td>
- * <td>System manufacturer</td>
- * <td> e.g. Sun Microsystems</td>
- * </tr>
- * <tr>
- * <td><tt>cpuManufacturer</tt></td>
- * <td>CPU manufacturer</td>
- * <td> e.g. Sun Microsystems</td>
- * </tr>
- * <tr>
- * <td><tt>serialNumber</tt></td>
- * <td>System serial number</td>
- * <td> e.g. BEL078932</td>
- * </tr>
- * </table>
- * </blockquote>
- * The <tt>hostname</tt> and <tt>osName</tt> element must have a non-empty value.
- * If an element is not available on a system and their value will be
- * empty.
- * <p>
- * <a name="XMLSchema">
- * <b>Registration XML Schema</b></a>
- * <p>
- * A {@code RegistrationData} object can be {@link #loadFromXML loaded} from
- * and {@link #storeToXML stored} into an XML file in the format described
- * by the
- * <a href="https://sn-tools.central.sun.com/twiki/pub/ServiceTags/RegistrationRelayService/product_registration.xsd">
- * registration data schema</a>. The registration data schema is defined by the
- * Service Tags Technology.
- * <p>
- * Typically the registration data is constructed at installation time
- * and stored in an XML file for later service tag lookup or registration.
- *
- * <p>
- * <b>Example Usage</b>
- * <p>
- * The examples below show how the {@code RegistrationData} can be
- * used for product registration.
- * Exception handling is not shown in these examples for clarity.
- * <ol>
- * <li>This example shows how the JDK creates a JDK service tag, installs it
- * in the system service tag registry and adds it to the registration data.
- * <br>
- * <blockquote><pre>
- * // create a service tag object with an instance_urn
- * ServiceTag st = ServiceTag.newInstance(ServiceTag.generateInstanceURN(),
- * ....);
- * // Adds to the system service tag registry if supported
- * if (Registry.isSupported()) {
- * Registry.getSystemRegistry().addServiceTag(st);
- * }
- *
- * // add to the registration data
- * RegistrationData registration = new RegistrationData();
- * registration.addServiceTag(st);
- * </pre></blockquote>
- * </li>
- * <li>At this point, the registration data is ready to
- * send to Sun Connection for registration. This example shows how to register
- * the JDK via the <i>Registration Relay Service</i>.
- * <p>
- * There are several registration services for Sun Connection. For example,
- * the <a href="https://sn-tools.central.sun.com/twiki/bin/view/ServiceTags/RegistrationRelayService">
- * Registration Relay Service</a> is a web application interface that
- * processes the registration data payload sent via HTTP post
- * and hosts the registration user interface for a specified
- * registration URL. Refer to the
- * Registration Relay Service Specification for details.
- * <p>
- * <blockquote><pre>
- * // Open the connection to the URL of the registration service
- * HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
- * con.setDoInput(true);
- * con.setDoOutput(true);
- * con.setUseCaches(false);
- * con.setAllowUserInteraction(false);
- * con.setRequestMethod("POST");
- * con.setRequestProperty("Content-Type", "text/xml;charset=\"utf-8\"");
- * con.connect();
- *
- * // send the registration data to the registration service
- * OutputStream out = con.getOutputStream();
- * registration.storeToXML(out);
- * out.close();
- * </pre></blockquote>
- * </li>
- * <li>This example shows how to store the registration data in an XML file.
- * for later service tag lookup or registration.
- * <br>
- * <blockquote><pre>
- * BufferedOutputStream out = new BufferedOutputStream(
- * new FileOutputStream(""&lt;JAVA_HOME&gt;/lib/servicetag/registration.xml"));
- * registration.storeToXML(out);
- * out.close();
- * </pre></blockquote>
- * </li>
- * <li>This example shows how to install service tags that are in the
- * registration data in the system service tag registry when determined
- * to be available. The system service tag registry might not have existed
- * when the registration data was constructed.
- * <br>
- * <blockquote><pre>
- * if (Registry.isSupported()) {
- * Set&lt;ServiceTag&gt; svctags = registration.getServiceTags();
- * for (ServiceTag st : svctags) {
- * Registry.getSystemRegistry().addServiceTag(st);
- * }
- * }
- * </pre></blockquote>
- * </li>
- * </ol>
- *
- * @see <a href="https://sunconnection.sun.com/inventory">Sun Connection Inventory Channel</a>
- */
-public class RegistrationData {
- private final Map<String, String> environment;
- private final Map<String, ServiceTag> svcTagMap;
- private final String urn;
-
- /**
- * Creates a {@code RegistrationData} object with a generated
- * {@link #getRegistrationURN registration URN}.
- * The following keys in the {@link #getEnvironmentMap environment map}
- * will be initialized for the configuration of the
- * running system:
- * <blockquote>
- * <tt>hostname</tt>, <tt>osName</tt>, <tt>osVersion</tt> and
- * <tt>osArchitecture</tt>
- * </blockquote>
- * and the value of other keys may be empty.
- */
- public RegistrationData() {
- this(Util.generateURN());
- }
-
- // package private
- RegistrationData(String urn) {
- this.urn = urn;
- this.environment = initEnvironment();
- this.svcTagMap = new LinkedHashMap<String, ServiceTag>();
- }
-
- private Map<String, String> initEnvironment() {
- Map<String, String> map = new LinkedHashMap<String, String>();
- SystemEnvironment sysEnv = SystemEnvironment.getSystemEnvironment();
- map.put(ST_NODE_HOSTNAME, sysEnv.getHostname());
- map.put(ST_NODE_HOST_ID, sysEnv.getHostId());
- map.put(ST_NODE_OS_NAME, sysEnv.getOsName());
- map.put(ST_NODE_OS_VERSION, sysEnv.getOsVersion());
- map.put(ST_NODE_OS_ARCH, sysEnv.getOsArchitecture());
- map.put(ST_NODE_SYSTEM_MODEL, sysEnv.getSystemModel());
- map.put(ST_NODE_SYSTEM_MANUFACTURER, sysEnv.getSystemManufacturer());
- map.put(ST_NODE_CPU_MANUFACTURER, sysEnv.getCpuManufacturer());
- map.put(ST_NODE_SERIAL_NUMBER, sysEnv.getSerialNumber());
- return map;
- }
-
- /**
- * Returns the uniform resource name of this registration data
- * in this format:
- * <tt>urn:st:&lt;32-char {@link java.util.UUID uuid}&gt;</tt>
- *
- * @return the URN of this registration data.
- */
- public String getRegistrationURN() {
- return urn;
- }
-
- /**
- * Returns a map containing the environment information for this
- * registration data. See the set of <a href="#EnvMap">keys</a>
- * in the environment map. Subsequent update to the environment
- * map via the {@link #setEnvironment setEnvironment} method will not be reflected
- * in the returned map.
- *
- * @return an environment map for this registration data.
- */
- public Map<String, String> getEnvironmentMap() {
- return new LinkedHashMap<String,String>(environment);
- }
-
- /**
- * Sets an element of the specified {@code name} in the environment map
- * with the given {@code value}.
- *
- * @throws IllegalArgumentException if {@code name} is not a valid key
- * in the environment map, or {@code value} is not valid.
- */
- public void setEnvironment(String name, String value) {
- if (name == null) {
- throw new NullPointerException("name is null");
- }
- if (value == null) {
- throw new NullPointerException("value is null");
- }
- if (environment.containsKey(name)) {
- if (name.equals(ST_NODE_HOSTNAME) || name.equals(ST_NODE_OS_NAME)) {
- if (value.length() == 0) {
- throw new IllegalArgumentException("\"" +
- name + "\" requires non-empty value.");
- }
- }
- environment.put(name, value);
- } else {
- throw new IllegalArgumentException("\"" +
- name + "\" is not an environment element.");
- }
- }
-
- /**
- * Returns all service tags in this registration data.
- *
- * @return a {@link Set Set} of the service tags
- * in this registration data.
- */
- public Set<ServiceTag> getServiceTags() {
- return new HashSet<ServiceTag>(svcTagMap.values());
- }
-
- /**
- * Adds a service tag to this registration data.
- * If the given service tag has an empty <tt>instance_urn</tt>,
- * this method will generate a URN and place it in the copy
- * of the service tag in this registration data.
- * This method will return the {@code ServiceTag} object
- * added to this registration data.
- *
- * @param st {@code ServiceTag} object to be added.
- * @return a {@code ServiceTag} object added to this registration data.
- *
- * @throws IllegalArgumentException if
- * a service tag of the same {@link ServiceTag#getInstanceURN
- * <tt>instance_urn</tt>} already exists in the registry.
- */
- public synchronized ServiceTag addServiceTag(ServiceTag st) {
- ServiceTag svcTag = ServiceTag.newInstanceWithUrnTimestamp(st);
-
- String instanceURN = svcTag.getInstanceURN();
- if (svcTagMap.containsKey(instanceURN)) {
- throw new IllegalArgumentException("Instance_urn = " + instanceURN +
- " already exists in the registration data.");
- } else {
- svcTagMap.put(instanceURN, svcTag);
- }
- return svcTag;
- }
-
- /**
- * Returns a service tag of the given <tt>instance_urn</tt> in this registration
- * data.
- *
- * @param instanceURN the <tt>instance_urn</tt> of the service tag
- * @return the {@code ServiceTag} object of the given <tt>instance_urn</tt>
- * if exists; otherwise return {@code null}.
- */
- public synchronized ServiceTag getServiceTag(String instanceURN) {
- if (instanceURN == null) {
- throw new NullPointerException("instanceURN is null");
- }
- return svcTagMap.get(instanceURN);
- }
-
- /**
- * Removes a service tag of the given <tt>instance_urn</tt> from this
- * registration data.
- *
- * @param instanceURN the <tt>instance_urn</tt> of
- * the service tag to be removed.
- *
- * @return the removed {@code ServiceTag} object;
- * or {@code null} if the service tag does not exist in this
- * registration data.
- */
- public synchronized ServiceTag removeServiceTag(String instanceURN) {
- if (instanceURN == null) {
- throw new NullPointerException("instanceURN is null");
- }
-
- ServiceTag svcTag = null;
- if (svcTagMap.containsKey(instanceURN)) {
- svcTag = svcTagMap.remove(instanceURN);
- }
- return svcTag;
- }
-
- /**
- * Updates the <tt>product_defined_instance_id</tt> in the service tag
- * of the given <tt>instance_urn</tt> in this registration data.
- *
- * @param instanceURN the <tt>instance_urn</tt> of the service tag to be updated.
- * @param productDefinedInstanceID the value of the
- * <tt>product_defined_instance_id</tt> to be set.
- *
- * @return the updated {@code ServiceTag} object;
- * or {@code null} if the service tag does not exist in this
- * registration data.
- */
- public synchronized ServiceTag updateServiceTag(String instanceURN,
- String productDefinedInstanceID) {
- ServiceTag svcTag = getServiceTag(instanceURN);
- if (svcTag == null) {
- return null;
- }
-
- svcTag = ServiceTag.newInstanceWithUrnTimestamp(svcTag);
- // update the product defined instance ID field
- svcTag.setProductDefinedInstanceID(productDefinedInstanceID);
- svcTagMap.put(instanceURN, svcTag);
- return svcTag;
- }
-
- /**
- * Reads the registration data from the XML document on the
- * specified input stream. The XML document must be
- * in the format described by the <a href="#XMLSchema">
- * registration data schema</a>.
- * The specified stream is closed after this method returns.
- *
- * @param in the input stream from which to read the XML document.
- * @return a {@code RegistrationData} object read from the input
- * stream.
- *
- * @throws IllegalArgumentException if the input stream
- * contains an invalid registration data.
- *
- * @throws IOException if an error occurred when reading from the input stream.
- */
- public static RegistrationData loadFromXML(InputStream in) throws IOException {
- try {
- return RegistrationDocument.load(in);
- } finally {
- in.close();
- }
- }
-
- /**
- * Writes the registration data to the specified output stream
- * in the format described by the <a href="#XMLSchema">
- * registration data schema</a> with "UTF-8" encoding.
- * The specified stream remains open after this method returns.
- *
- * @param os the output stream on which to write the XML document.
- *
- * @throws IOException if an error occurred when writing to the output stream.
- */
- public void storeToXML(OutputStream os) throws IOException {
- RegistrationDocument.store(os, this);
- os.flush();
- }
-
- /**
- * Returns a newly allocated byte array containing the registration
- * data in XML format.
- *
- * @return a newly allocated byte array containing the registration
- * data in XML format.
- */
- public byte[] toXML() {
- try {
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- storeToXML(out);
- return out.toByteArray();
- } catch (IOException e) {
- // should not reach here
- return new byte[0];
- }
- }
-
- /**
- * Returns a string representation of this registration data in XML
- * format.
- *
- * @return a string representation of this registration data in XML
- * format.
- */
- @Override
- public String toString() {
- try {
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- storeToXML(out);
- return out.toString("UTF-8");
- } catch (IOException e) {
- // should not reach here
- return "Error creating the return string.";
- }
- }
-}
+
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 1997-2008 Sun Microsystems, Inc. All rights reserved.
+ *
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common Development
+ * and Distribution License("CDDL") (collectively, the "License"). You
+ * may not use this file except in compliance with the License. You can obtain
+ * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
+ * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
+ * language governing permissions and limitations under the License.
+ *
+ * When distributing the software, include this License Header Notice in each
+ * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
+ * Sun designates this particular file as subject to the "Classpath" exception
+ * as provided by Sun in the GPL Version 2 section of the License file that
+ * accompanied this code. If applicable, add the following below the License
+ * Header, with the fields enclosed by brackets [] replaced by your own
+ * identifying information: "Portions Copyrighted [year]
+ * [name of copyright owner]"
+ *
+ * Contributor(s):
+ *
+ * If you wish your version of this file to be governed by only the CDDL or
+ * only the GPL Version 2, indicate your decision by adding "[Contributor]
+ * elects to include this software in this distribution under the [CDDL or GPL
+ * Version 2] license." If you don't indicate a single choice of license, a
+ * recipient has the option to distribute your version of this file under
+ * either the CDDL, the GPL Version 2 or to extend the choice of license to
+ * its licensees as provided above. However, if you add GPL Version 2 code
+ * and therefore, elected the GPL Version 2 license, then the option applies
+ * only if the new code is made subject to such option by the copyright
+ * holder.
+ */
+
+package com.sun.star.servicetag;
+
+import java.io.*;
+import java.net.UnknownHostException;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Set;
+
+import static com.sun.star.servicetag.RegistrationDocument.*;
+
+/**
+ * A {@code RegistrationData} object is a container of one or more
+ * {@link #getServiceTags service tags} that identify the
+ * components for product registration.
+ * Each {@code RegistrationData} object has a {@link #getRegistrationURN
+ * uniform resource name} (URN) as its identifier.
+ * <a name="EnvMap"></a>
+ * It also has an <i>environment map</i> with
+ * the following elements:
+ * <blockquote>
+ * <table border=0>
+ * <tr>
+ * <td><tt>hostname</tt></td>
+ * <td>Hostname of the system</td>
+ * <td>e.g. woody</td>
+ * </tr>
+ * <tr>
+ * <td><tt>hostId</tt></td>
+ * <td>Host ID of the system</td>
+ * <td>e.g. 83abc1ab</td>
+ * </tr>
+ * <tr>
+ * <td><tt>osName</tt></td>
+ * <td>Operating system name</td>
+ * <td> e.g. SunOS</td>
+ * </tr>
+ * <tr>
+ * <td><tt>osVersion</tt></td>
+ * <td>Operating system version</td>
+ * <td> e.g. 5.10</td>
+ * </tr>
+ * <tr>
+ * <td><tt>osArchitecture</tt></td>
+ * <td>Operating system architecture</td>
+ * <td> e.g. sparc</td>
+ * </tr>
+ * <tr>
+ * <td><tt>systemModel</tt></td>
+ * <td>System model</td>
+ * <td> e.g. SUNW,Sun-Fire-V440</td>
+ * </tr>
+ * <tr>
+ * <td><tt>systemManufacturer</tt></td>
+ * <td>System manufacturer</td>
+ * <td> e.g. Sun Microsystems</td>
+ * </tr>
+ * <tr>
+ * <td><tt>cpuManufacturer</tt></td>
+ * <td>CPU manufacturer</td>
+ * <td> e.g. Sun Microsystems</td>
+ * </tr>
+ * <tr>
+ * <td><tt>serialNumber</tt></td>
+ * <td>System serial number</td>
+ * <td> e.g. BEL078932</td>
+ * </tr>
+ * <tr>
+ * <td><tt>physmem</tt></td>
+ * <td>Physical memory for the system (in MB)</td>
+ * <td> e.g. 4096</td>
+ * </tr>
+ * </table>
+ * </blockquote>
+ * The <tt>hostname</tt> and <tt>osName</tt> element must have a non-empty value.
+ * If an element is not available on a system and their value will be
+ * empty.
+ * <p>
+ * <a name="XMLSchema">
+ * <b>Registration XML Schema</b></a>
+ * <p>
+ * A {@code RegistrationData} object can be {@link #loadFromXML loaded} from
+ * and {@link #storeToXML stored} into an XML file in the format described
+ * by the
+ * <a href="https://sn-tools.central.sun.com/twiki/pub/ServiceTags/RegistrationRelayService/product_registration.xsd">
+ * registration data schema</a>. The registration data schema is defined by the
+ * Service Tags Technology.
+ * <p>
+ * Typically the registration data is constructed at installation time
+ * and stored in an XML file for later service tag lookup or registration.
+ *
+ * <p>
+ * <b>Example Usage</b>
+ * <p>
+ * The examples below show how the {@code RegistrationData} can be
+ * used for product registration.
+ * Exception handling is not shown in these examples for clarity.
+ * <ol>
+ * <li>This example shows how the JDK creates a JDK service tag, installs it
+ * in the system service tag registry and adds it to the registration data.
+ * <br>
+ * <blockquote><pre>
+ * // create a service tag object with an instance_urn
+ * ServiceTag st = ServiceTag.newInstance(ServiceTag.generateInstanceURN(),
+ * ....);
+ * // Adds to the system service tag registry if supported
+ * if (Registry.isSupported()) {
+ * Registry.getSystemRegistry().addServiceTag(st);
+ * }
+ *
+ * // add to the registration data
+ * RegistrationData registration = new RegistrationData();
+ * registration.addServiceTag(st);
+ * </pre></blockquote>
+ * </li>
+ * <li>At this point, the registration data is ready to
+ * send to Sun Connection for registration. This example shows how to register
+ * the JDK via the <i>Registration Relay Service</i>.
+ * <p>
+ * There are several registration services for Sun Connection. For example,
+ * the <a href="https://sn-tools.central.sun.com/twiki/bin/view/ServiceTags/RegistrationRelayService">
+ * Registration Relay Service</a> is a web application interface that
+ * processes the registration data payload sent via HTTP post
+ * and hosts the registration user interface for a specified
+ * registration URL. Refer to the
+ * Registration Relay Service Specification for details.
+ * <p>
+ * <blockquote><pre>
+ * // Open the connection to the URL of the registration service
+ * HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
+ * con.setDoInput(true);
+ * con.setDoOutput(true);
+ * con.setUseCaches(false);
+ * con.setAllowUserInteraction(false);
+ * con.setRequestMethod("POST");
+ * con.setRequestProperty("Content-Type", "text/xml;charset=\"utf-8\"");
+ * con.connect();
+ *
+ * // send the registration data to the registration service
+ * OutputStream out = con.getOutputStream();
+ * registration.storeToXML(out);
+ * out.close();
+ * </pre></blockquote>
+ * </li>
+ * <li>This example shows how to store the registration data in an XML file.
+ * for later service tag lookup or registration.
+ * <br>
+ * <blockquote><pre>
+ * BufferedOutputStream out = new BufferedOutputStream(
+ * new FileOutputStream(""&lt;JAVA_HOME&gt;/lib/servicetag/registration.xml"));
+ * registration.storeToXML(out);
+ * out.close();
+ * </pre></blockquote>
+ * </li>
+ * <li>This example shows how to install service tags that are in the
+ * registration data in the system service tag registry when determined
+ * to be available. The system service tag registry might not have existed
+ * when the registration data was constructed.
+ * <br>
+ * <blockquote><pre>
+ * if (Registry.isSupported()) {
+ * Set&lt;ServiceTag&gt; svctags = registration.getServiceTags();
+ * for (ServiceTag st : svctags) {
+ * Registry.getSystemRegistry().addServiceTag(st);
+ * }
+ * }
+ * </pre></blockquote>
+ * </li>
+ * </ol>
+ *
+ * @see <a href="https://sunconnection.sun.com/inventory">Sun Connection Inventory Channel</a>
+ */
+public class RegistrationData {
+ private final Map<String, String> environment;
+ private final Map<String, String> cpuInfo;
+ private final Map<String, ServiceTag> svcTagMap;
+ private final String urn;
+
+ /**
+ * Creates a {@code RegistrationData} object with a generated
+ * {@link #getRegistrationURN registration URN}.
+ * The following keys in the {@link #getEnvironmentMap environment map}
+ * will be initialized for the configuration of the
+ * running system:
+ * <blockquote>
+ * <tt>hostname</tt>, <tt>osName</tt>, <tt>osVersion</tt> and
+ * <tt>osArchitecture</tt>
+ * </blockquote>
+ * and the value of other keys may be empty.
+ */
+ public RegistrationData() {
+ this(Util.generateURN());
+ }
+
+ // package private
+ RegistrationData(String urn) {
+ this.urn = urn;
+ SystemEnvironment sysEnv = SystemEnvironment.getSystemEnvironment();
+ this.environment = initEnvironment(sysEnv);
+ this.cpuInfo = initCpuInfo(sysEnv);
+ this.svcTagMap = new LinkedHashMap<String, ServiceTag>();
+ }
+
+ private Map<String, String> initEnvironment(SystemEnvironment sysEnv) {
+ Map<String, String> map = new LinkedHashMap<String, String>();
+ map.put(ST_NODE_HOSTNAME, sysEnv.getHostname());
+ map.put(ST_NODE_HOST_ID, sysEnv.getHostId());
+ map.put(ST_NODE_OS_NAME, sysEnv.getOsName());
+ map.put(ST_NODE_OS_VERSION, sysEnv.getOsVersion());
+ map.put(ST_NODE_OS_ARCH, sysEnv.getOsArchitecture());
+ map.put(ST_NODE_SYSTEM_MODEL, sysEnv.getSystemModel());
+ map.put(ST_NODE_SYSTEM_MANUFACTURER, sysEnv.getSystemManufacturer());
+ map.put(ST_NODE_CPU_MANUFACTURER, sysEnv.getCpuManufacturer());
+ map.put(ST_NODE_SERIAL_NUMBER, sysEnv.getSerialNumber());
+ map.put(ST_NODE_PHYS_MEM, sysEnv.getPhysMem());
+ return map;
+ }
+
+ private Map<String, String> initCpuInfo(SystemEnvironment sysEnv) {
+ Map<String, String> map = new LinkedHashMap<String, String>();
+ map.put(ST_NODE_SOCKETS, sysEnv.getSockets());
+ map.put(ST_NODE_CORES, sysEnv.getCores());
+ map.put(ST_NODE_VIRT_CPUS, sysEnv.getVirtCpus());
+ map.put(ST_NODE_CPU_NAME, sysEnv.getCpuName());
+ map.put(ST_NODE_CLOCK_RATE, sysEnv.getClockRate());
+ return map;
+ }
+
+ /**
+ * Returns the uniform resource name of this registration data
+ * in this format:
+ * <tt>urn:st:&lt;32-char {@link java.util.UUID uuid}&gt;</tt>
+ *
+ * @return the URN of this registration data.
+ */
+ public String getRegistrationURN() {
+ return urn;
+ }
+
+ /**
+ * Returns a map containing the environment information for this
+ * registration data. See the set of <a href="#EnvMap">keys</a>
+ * in the environment map. Subsequent update to the environment
+ * map via the {@link #setEnvironment setEnvironment} method will not be reflected
+ * in the returned map.
+ *
+ * @return an environment map for this registration data.
+ */
+ public Map<String, String> getEnvironmentMap() {
+ return new LinkedHashMap<String,String>(environment);
+ }
+
+ /**
+ * Returns a map containing the cpu information for this
+ * registration data. Subsequent update to the cpu info
+ * map via the {@link #setCpuInfo setCpuInfo} method will not be reflected
+ * in the returned map.
+ *
+ * @return a cpu info map for this registration data.
+ */
+ public Map<String, String> getCpuInfoMap() {
+ return new LinkedHashMap<String,String>(cpuInfo);
+ }
+
+ /**
+ * Sets an element of the specified {@code name} in the environment map
+ * with the given {@code value}.
+ *
+ * @throws IllegalArgumentException if {@code name} is not a valid key
+ * in the environment map, or {@code value} is not valid.
+ */
+ public void setEnvironment(String name, String value) {
+ if (name == null) {
+ throw new NullPointerException("name is null");
+ }
+ if (value == null) {
+ throw new NullPointerException("value is null");
+ }
+ if (environment.containsKey(name)) {
+ if (name.equals(ST_NODE_HOSTNAME) || name.equals(ST_NODE_OS_NAME)) {
+ if (value.length() == 0) {
+ throw new IllegalArgumentException("\"" +
+ name + "\" requires non-empty value.");
+ }
+ }
+ environment.put(name, value);
+ } else {
+ throw new IllegalArgumentException("\"" +
+ name + "\" is not an environment element.");
+ }
+ }
+
+ /**
+ * Sets an element of the specified {@code name} in the cpu info map
+ * with the given {@code value}.
+ *
+ * @throws IllegalArgumentException if {@code name} is not a valid key
+ * in the cpu info map, or {@code value} is not valid.
+ */
+ public void setCpuInfo(String name, String value) {
+ if (name == null) {
+ throw new NullPointerException("name is null");
+ }
+ if (value == null) {
+ throw new NullPointerException("value is null");
+ }
+ if (cpuInfo.containsKey(name)) {
+ cpuInfo.put(name, value);
+ } else {
+ throw new IllegalArgumentException("\"" +
+ name + "\" is not an cpuinfo element.");
+ }
+ }
+
+ /**
+ * Returns all service tags in this registration data.
+ *
+ * @return a {@link Set Set} of the service tags
+ * in this registration data.
+ */
+ public Set<ServiceTag> getServiceTags() {
+ return new HashSet<ServiceTag>(svcTagMap.values());
+ }
+
+ /**
+ * Adds a service tag to this registration data.
+ * If the given service tag has an empty <tt>instance_urn</tt>,
+ * this method will generate a URN and place it in the copy
+ * of the service tag in this registration data.
+ * This method will return the {@code ServiceTag} object
+ * added to this registration data.
+ *
+ * @param st {@code ServiceTag} object to be added.
+ * @return a {@code ServiceTag} object added to this registration data.
+ *
+ * @throws IllegalArgumentException if
+ * a service tag of the same {@link ServiceTag#getInstanceURN
+ * <tt>instance_urn</tt>} already exists in the registry.
+ */
+ public synchronized ServiceTag addServiceTag(ServiceTag st) {
+ ServiceTag svcTag = ServiceTag.newInstanceWithUrnTimestamp(st);
+
+ String instanceURN = svcTag.getInstanceURN();
+ if (svcTagMap.containsKey(instanceURN)) {
+ throw new IllegalArgumentException("Instance_urn = " + instanceURN +
+ " already exists in the registration data.");
+ } else {
+ svcTagMap.put(instanceURN, svcTag);
+ }
+ return svcTag;
+ }
+
+ /**
+ * Returns a service tag of the given <tt>instance_urn</tt> in this registration
+ * data.
+ *
+ * @param instanceURN the <tt>instance_urn</tt> of the service tag
+ * @return the {@code ServiceTag} object of the given <tt>instance_urn</tt>
+ * if exists; otherwise return {@code null}.
+ */
+ public synchronized ServiceTag getServiceTag(String instanceURN) {
+ if (instanceURN == null) {
+ throw new NullPointerException("instanceURN is null");
+ }
+ return svcTagMap.get(instanceURN);
+ }
+
+ /**
+ * Removes a service tag of the given <tt>instance_urn</tt> from this
+ * registration data.
+ *
+ * @param instanceURN the <tt>instance_urn</tt> of
+ * the service tag to be removed.
+ *
+ * @return the removed {@code ServiceTag} object;
+ * or {@code null} if the service tag does not exist in this
+ * registration data.
+ */
+ public synchronized ServiceTag removeServiceTag(String instanceURN) {
+ if (instanceURN == null) {
+ throw new NullPointerException("instanceURN is null");
+ }
+
+ ServiceTag svcTag = null;
+ if (svcTagMap.containsKey(instanceURN)) {
+ svcTag = svcTagMap.remove(instanceURN);
+ }
+ return svcTag;
+ }
+
+ /**
+ * Updates the <tt>product_defined_instance_id</tt> in the service tag
+ * of the given <tt>instance_urn</tt> in this registration data.
+ *
+ * @param instanceURN the <tt>instance_urn</tt> of the service tag to be updated.
+ * @param productDefinedInstanceID the value of the
+ * <tt>product_defined_instance_id</tt> to be set.
+ *
+ * @return the updated {@code ServiceTag} object;
+ * or {@code null} if the service tag does not exist in this
+ * registration data.
+ */
+ public synchronized ServiceTag updateServiceTag(String instanceURN,
+ String productDefinedInstanceID) {
+ ServiceTag svcTag = getServiceTag(instanceURN);
+ if (svcTag == null) {
+ return null;
+ }
+
+ svcTag = ServiceTag.newInstanceWithUrnTimestamp(svcTag);
+ // update the product defined instance ID field
+ svcTag.setProductDefinedInstanceID(productDefinedInstanceID);
+ svcTagMap.put(instanceURN, svcTag);
+ return svcTag;
+ }
+
+ /**
+ * Reads the registration data from the XML document on the
+ * specified input stream. The XML document must be
+ * in the format described by the <a href="#XMLSchema">
+ * registration data schema</a>.
+ * The specified stream is closed after this method returns.
+ *
+ * @param in the input stream from which to read the XML document.
+ * @return a {@code RegistrationData} object read from the input
+ * stream.
+ *
+ * @throws IllegalArgumentException if the input stream
+ * contains an invalid registration data.
+ *
+ * @throws IOException if an error occurred when reading from the input stream.
+ */
+ public static RegistrationData loadFromXML(InputStream in) throws IOException {
+ try {
+ return RegistrationDocument.load(in);
+ } finally {
+ in.close();
+ }
+ }
+
+ /**
+ * Writes the registration data to the specified output stream
+ * in the format described by the <a href="#XMLSchema">
+ * registration data schema</a> with "UTF-8" encoding.
+ * The specified stream remains open after this method returns.
+ *
+ * @param os the output stream on which to write the XML document.
+ *
+ * @throws IOException if an error occurred when writing to the output stream.
+ */
+ public void storeToXML(OutputStream os) throws IOException {
+ RegistrationDocument.store(os, this);
+ os.flush();
+ }
+
+ /**
+ * Returns a newly allocated byte array containing the registration
+ * data in XML format.
+ *
+ * @return a newly allocated byte array containing the registration
+ * data in XML format.
+ */
+ public byte[] toXML() {
+ try {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ storeToXML(out);
+ return out.toByteArray();
+ } catch (IOException e) {
+ // should not reach here
+ return new byte[0];
+ }
+ }
+
+ /**
+ * Returns a string representation of this registration data in XML
+ * format.
+ *
+ * @return a string representation of this registration data in XML
+ * format.
+ */
+ @Override
+ public String toString() {
+ try {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ storeToXML(out);
+ return out.toString("UTF-8");
+ } catch (IOException e) {
+ // should not reach here
+ return "Error creating the return string.";
+ }
+ }
+}
diff --git a/desktop/source/registration/com/sun/star/servicetag/RegistrationDocument.java b/desktop/source/registration/com/sun/star/servicetag/RegistrationDocument.java
index ae810d205f..93a1f25a6c 100644
--- a/desktop/source/registration/com/sun/star/servicetag/RegistrationDocument.java
+++ b/desktop/source/registration/com/sun/star/servicetag/RegistrationDocument.java
@@ -1,374 +1,440 @@
-/*************************************************************************
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * Copyright 2008 by Sun Microsystems, Inc.
- *
- * OpenOffice.org - a multi-platform office productivity suite
- *
- * $RCSfile: RegistrationDocument.java,v $
- *
- * $Revision: 1.2 $
- *
- * This file is part of OpenOffice.org.
- *
- * OpenOffice.org is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License version 3
- * only, as published by the Free Software Foundation.
- *
- * OpenOffice.org is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License version 3 for more details
- * (a copy is included in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU Lesser General Public License
- * version 3 along with OpenOffice.org. If not, see
- * <http://www.openoffice.org/license.html>
- * for a copy of the LGPLv3 License.
- *
- ************************************************************************/
-
-package com.sun.star.servicetag;
-
-import java.io.*;
-import java.net.URL;
-import java.util.Collection;
-import java.util.Map;
-import java.util.Set;
-
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.xml.sax.SAXException;
-import org.xml.sax.InputSource;
-
-import javax.xml.XMLConstants;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.validation.Schema;
-import javax.xml.validation.SchemaFactory;
-import javax.xml.validation.Validator;
-
-// For write operation
-import javax.xml.transform.OutputKeys;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.TransformerConfigurationException;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
-
-/**
- * XML Support Class for Product Registration.
- */
-class RegistrationDocument {
-
- private static final String REGISTRATION_DATA_SCHEMA =
- "/com/sun/star/servicetag/resources/product_registration.xsd";
- private static final String REGISTRATION_DATA_VERSION = "1.0";
- private static final String SERVICE_TAG_VERSION = "1.0";
- final static String ST_NODE_REGISTRATION_DATA = "registration_data";
- final static String ST_ATTR_REGISTRATION_VERSION = "version";
- final static String ST_NODE_ENVIRONMENT = "environment";
- final static String ST_NODE_HOSTNAME = "hostname";
- final static String ST_NODE_HOST_ID = "hostId";
- final static String ST_NODE_OS_NAME = "osName";
- final static String ST_NODE_OS_VERSION = "osVersion";
- final static String ST_NODE_OS_ARCH = "osArchitecture";
- final static String ST_NODE_SYSTEM_MODEL = "systemModel";
- final static String ST_NODE_SYSTEM_MANUFACTURER = "systemManufacturer";
- final static String ST_NODE_CPU_MANUFACTURER = "cpuManufacturer";
- final static String ST_NODE_SERIAL_NUMBER = "serialNumber";
- final static String ST_NODE_REGISTRY = "registry";
- final static String ST_ATTR_REGISTRY_URN = "urn";
- final static String ST_ATTR_REGISTRY_VERSION = "version";
- final static String ST_NODE_SERVICE_TAG = "service_tag";
- final static String ST_NODE_INSTANCE_URN = "instance_urn";
- final static String ST_NODE_PRODUCT_NAME = "product_name";
- final static String ST_NODE_PRODUCT_VERSION = "product_version";
- final static String ST_NODE_PRODUCT_URN = "product_urn";
- final static String ST_NODE_PRODUCT_PARENT_URN = "product_parent_urn";
- final static String ST_NODE_PRODUCT_PARENT = "product_parent";
- final static String ST_NODE_PRODUCT_DEFINED_INST_ID = "product_defined_inst_id";
- final static String ST_NODE_PRODUCT_VENDOR = "product_vendor";
- final static String ST_NODE_PLATFORM_ARCH = "platform_arch";
- final static String ST_NODE_TIMESTAMP = "timestamp";
- final static String ST_NODE_CONTAINER = "container";
- final static String ST_NODE_SOURCE = "source";
- final static String ST_NODE_INSTALLER_UID = "installer_uid";
-
- static RegistrationData load(InputStream in) throws IOException {
- Document document = initializeDocument(in);
-
- // Gets the registration URN
- Element root = getRegistrationDataRoot(document);
- Element registryRoot =
- getSingletonElementFromRoot(root, ST_NODE_REGISTRY);
- String urn = registryRoot.getAttribute(ST_ATTR_REGISTRY_URN);
-
- // Construct a new RegistrationData object from the DOM tree
- // Initialize the environment map and service tags
- RegistrationData regData = new RegistrationData(urn);
- addServiceTags(registryRoot, regData);
-
- Element envRoot = getSingletonElementFromRoot(root, ST_NODE_ENVIRONMENT);
- buildEnvironmentMap(envRoot, regData);
- return regData;
- }
-
- static void store(OutputStream os, RegistrationData registration)
- throws IOException {
- // create a new document with the root node
- Document document = initializeDocument();
-
- // create the nodes for the environment map and the service tags
- // in the registration data
- addEnvironmentNodes(document,
- registration.getEnvironmentMap());
- addServiceTagRegistry(document,
- registration.getRegistrationURN(),
- registration.getServiceTags());
- transform(document, os);
- }
-
- // initialize a document from an input stream
- private static Document initializeDocument(InputStream in) throws IOException {
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- try {
- // XML schema for validation
- SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
- URL xsdUrl = RegistrationDocument.class.getResource(REGISTRATION_DATA_SCHEMA);
- Schema schema = sf.newSchema(xsdUrl);
- Validator validator = schema.newValidator();
-
- DocumentBuilder builder = factory.newDocumentBuilder();
- Document doc = builder.parse(new InputSource(in));
- validator.validate(new DOMSource(doc));
- return doc;
- } catch (SAXException sxe) {
- IllegalArgumentException e = new IllegalArgumentException("Error generated in parsing");
- e.initCause(sxe);
- throw e;
- } catch (ParserConfigurationException pce) {
- // Parser with specific options can't be built
- // should not reach here
- InternalError x = new InternalError("Error in creating the new document");
- x.initCause(pce);
- throw x;
- }
- }
-
- // initialize a new document for the registration data
- private static Document initializeDocument() throws IOException {
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- try {
- DocumentBuilder builder = factory.newDocumentBuilder();
- Document doc = builder.newDocument();
-
- // initialize the document with the registration_data root
- Element root = doc.createElement(ST_NODE_REGISTRATION_DATA);
- doc.appendChild(root);
- root.setAttribute(ST_ATTR_REGISTRATION_VERSION, REGISTRATION_DATA_VERSION);
-
- return doc;
- } catch (ParserConfigurationException pce) {
- // Parser with specified options can't be built
- // should not reach here
- InternalError x = new InternalError("Error in creating the new document");
- x.initCause(pce);
- throw x;
- }
- }
-
- // Transform the current DOM tree with the given output stream.
- private static void transform(Document document, OutputStream os) {
- try {
- // Use a Transformer for output
- TransformerFactory tFactory = TransformerFactory.newInstance();
- tFactory.setAttribute("indent-number", new Integer(3));
-
- Transformer transformer = tFactory.newTransformer();
-
- transformer.setOutputProperty(OutputKeys.INDENT, "yes");
- transformer.setOutputProperty(OutputKeys.METHOD, "xml");
- transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
- transformer.setOutputProperty(OutputKeys.STANDALONE, "yes");
- transformer.transform(new DOMSource(document),
- new StreamResult(new BufferedWriter(new OutputStreamWriter(os, "UTF-8"))));
- } catch (UnsupportedEncodingException ue) {
- // Should not reach here
- InternalError x = new InternalError("Error generated during transformation");
- x.initCause(ue);
- throw x;
- } catch (TransformerConfigurationException tce) {
- // Error generated by the parser
- // Should not reach here
- InternalError x = new InternalError("Error in creating the new document");
- x.initCause(tce);
- throw x;
- } catch (TransformerException te) {
- // Error generated by the transformer
- InternalError x = new InternalError("Error generated during transformation");
- x.initCause(te);
- throw x;
- }
- }
-
- private static void addServiceTagRegistry(Document document,
- String registryURN,
- Set<ServiceTag> svcTags) {
- // add service tag registry node and its attributes
- Element reg = document.createElement(ST_NODE_REGISTRY);
- reg.setAttribute(ST_ATTR_REGISTRY_URN, registryURN);
- reg.setAttribute(ST_ATTR_REGISTRY_VERSION, SERVICE_TAG_VERSION);
-
- Element root = getRegistrationDataRoot(document);
- root.appendChild(reg);
-
- // adds the elements for the service tags
- for (ServiceTag st : svcTags) {
- addServiceTagElement(document, reg, st);
- }
- }
-
- private static void addServiceTagElement(Document document,
- Element registryRoot,
- ServiceTag st) {
- Element svcTag = document.createElement(ST_NODE_SERVICE_TAG);
- registryRoot.appendChild(svcTag);
- addChildElement(document, svcTag,
- ST_NODE_INSTANCE_URN, st.getInstanceURN());
- addChildElement(document, svcTag,
- ST_NODE_PRODUCT_NAME, st.getProductName());
- addChildElement(document, svcTag,
- ST_NODE_PRODUCT_VERSION, st.getProductVersion());
- addChildElement(document, svcTag,
- ST_NODE_PRODUCT_URN, st.getProductURN());
- addChildElement(document, svcTag,
- ST_NODE_PRODUCT_PARENT_URN, st.getProductParentURN());
- addChildElement(document, svcTag,
- ST_NODE_PRODUCT_PARENT, st.getProductParent());
- addChildElement(document, svcTag,
- ST_NODE_PRODUCT_DEFINED_INST_ID,
- st.getProductDefinedInstanceID());
- addChildElement(document, svcTag,
- ST_NODE_PRODUCT_VENDOR, st.getProductVendor());
- addChildElement(document, svcTag,
- ST_NODE_PLATFORM_ARCH, st.getPlatformArch());
- addChildElement(document, svcTag,
- ST_NODE_TIMESTAMP, Util.formatTimestamp(st.getTimestamp()));
- addChildElement(document, svcTag,
- ST_NODE_CONTAINER, st.getContainer());
- addChildElement(document, svcTag,
- ST_NODE_SOURCE, st.getSource());
- addChildElement(document, svcTag,
- ST_NODE_INSTALLER_UID,
- String.valueOf(st.getInstallerUID()));
- }
-
- private static void addChildElement(Document document, Element root,
- String element, String text) {
- Element node = document.createElement(element);
- node.appendChild(document.createTextNode(text));
- root.appendChild(node);
- }
-
- // Constructs service tags from the document
- private static void addServiceTags(Element registryRoot,
- RegistrationData registration) {
- NodeList children = registryRoot.getElementsByTagName(ST_NODE_SERVICE_TAG);
- int length = (children == null ? 0 : children.getLength());
- for (int i = 0; i < length; i++) {
- Element svcTagElement = (Element) children.item(i);
- ServiceTag st = getServiceTag(svcTagElement);
- registration.addServiceTag(st);
- }
- }
-
- // build environment map from the document
- private static void buildEnvironmentMap(Element envRoot,
- RegistrationData registration) {
- registration.setEnvironment(ST_NODE_HOSTNAME, getTextValue(envRoot, ST_NODE_HOSTNAME));
- registration.setEnvironment(ST_NODE_HOST_ID, getTextValue(envRoot, ST_NODE_HOST_ID));
- registration.setEnvironment(ST_NODE_OS_NAME, getTextValue(envRoot, ST_NODE_OS_NAME));
- registration.setEnvironment(ST_NODE_OS_VERSION, getTextValue(envRoot, ST_NODE_OS_VERSION));
- registration.setEnvironment(ST_NODE_OS_ARCH, getTextValue(envRoot, ST_NODE_OS_ARCH));
- registration.setEnvironment(ST_NODE_SYSTEM_MODEL, getTextValue(envRoot, ST_NODE_SYSTEM_MODEL));
- registration.setEnvironment(ST_NODE_SYSTEM_MANUFACTURER, getTextValue(envRoot, ST_NODE_SYSTEM_MANUFACTURER));
- registration.setEnvironment(ST_NODE_CPU_MANUFACTURER, getTextValue(envRoot, ST_NODE_CPU_MANUFACTURER));
- registration.setEnvironment(ST_NODE_SERIAL_NUMBER, getTextValue(envRoot, ST_NODE_SERIAL_NUMBER));
- }
-
- // add the nodes representing the environment map in the document
- private static void addEnvironmentNodes(Document document,
- Map<String, String> envMap) {
- Element root = getRegistrationDataRoot(document);
- Element env = document.createElement(ST_NODE_ENVIRONMENT);
- root.appendChild(env);
- Set<Map.Entry<String, String>> keys = envMap.entrySet();
- for (Map.Entry<String, String> entry : keys) {
- addChildElement(document, env, entry.getKey(), entry.getValue());
- }
- }
-
- private static Element getRegistrationDataRoot(Document doc) {
- Element root = doc.getDocumentElement();
- if (!root.getNodeName().equals(ST_NODE_REGISTRATION_DATA)) {
- throw new IllegalArgumentException("Not a " +
- ST_NODE_REGISTRATION_DATA +
- " node \"" + root.getNodeName() + "\"");
- }
- return root;
- }
-
- private static Element getSingletonElementFromRoot(Element root, String name) {
- NodeList children = root.getElementsByTagName(name);
- int length = (children == null ? 0 : children.getLength());
- if (length != 1) {
- throw new IllegalArgumentException("Invalid number of " + name +
- " nodes = " + length);
- }
- Element e = (Element) children.item(0);
- if (!e.getNodeName().equals(name)) {
- throw new IllegalArgumentException("Not a " + name +
- " node \"" + e.getNodeName() + "\"");
- }
- return e;
- }
-
- // Constructs one ServiceTag instance from a service tag element root
- private static ServiceTag getServiceTag(Element svcTagElement) {
- return new ServiceTag(
- getTextValue(svcTagElement, ST_NODE_INSTANCE_URN),
- getTextValue(svcTagElement, ST_NODE_PRODUCT_NAME),
- getTextValue(svcTagElement, ST_NODE_PRODUCT_VERSION),
- getTextValue(svcTagElement, ST_NODE_PRODUCT_URN),
- getTextValue(svcTagElement, ST_NODE_PRODUCT_PARENT),
- getTextValue(svcTagElement, ST_NODE_PRODUCT_PARENT_URN),
- getTextValue(svcTagElement, ST_NODE_PRODUCT_DEFINED_INST_ID),
- getTextValue(svcTagElement, ST_NODE_PRODUCT_VENDOR),
- getTextValue(svcTagElement, ST_NODE_PLATFORM_ARCH),
- getTextValue(svcTagElement, ST_NODE_CONTAINER),
- getTextValue(svcTagElement, ST_NODE_SOURCE),
- Util.getIntValue(getTextValue(svcTagElement, ST_NODE_INSTALLER_UID)),
- Util.parseTimestamp(getTextValue(svcTagElement, ST_NODE_TIMESTAMP))
- );
- }
-
- private static String getTextValue(Element e, String tagName) {
- String value = "";
- NodeList nl = e.getElementsByTagName(tagName);
- if (nl != null && nl.getLength() > 0) {
- Element el = (Element) nl.item(0);
- Node node = el.getFirstChild();
- if (node != null) {
- value = node.getNodeValue();
- }
- }
- return value;
- }
-}
+
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 1997-2008 Sun Microsystems, Inc. All rights reserved.
+ *
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common Development
+ * and Distribution License("CDDL") (collectively, the "License"). You
+ * may not use this file except in compliance with the License. You can obtain
+ * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
+ * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
+ * language governing permissions and limitations under the License.
+ *
+ * When distributing the software, include this License Header Notice in each
+ * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
+ * Sun designates this particular file as subject to the "Classpath" exception
+ * as provided by Sun in the GPL Version 2 section of the License file that
+ * accompanied this code. If applicable, add the following below the License
+ * Header, with the fields enclosed by brackets [] replaced by your own
+ * identifying information: "Portions Copyrighted [year]
+ * [name of copyright owner]"
+ *
+ * Contributor(s):
+ *
+ * If you wish your version of this file to be governed by only the CDDL or
+ * only the GPL Version 2, indicate your decision by adding "[Contributor]
+ * elects to include this software in this distribution under the [CDDL or GPL
+ * Version 2] license." If you don't indicate a single choice of license, a
+ * recipient has the option to distribute your version of this file under
+ * either the CDDL, the GPL Version 2 or to extend the choice of license to
+ * its licensees as provided above. However, if you add GPL Version 2 code
+ * and therefore, elected the GPL Version 2 license, then the option applies
+ * only if the new code is made subject to such option by the copyright
+ * holder.
+ */
+
+package com.sun.star.servicetag;
+
+import java.io.*;
+import java.net.URL;
+import java.util.Collection;
+import java.util.Map;
+import java.util.Set;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+import org.xml.sax.InputSource;
+
+import javax.xml.XMLConstants;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.validation.Schema;
+import javax.xml.validation.SchemaFactory;
+import javax.xml.validation.Validator;
+
+// For write operation
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+/**
+ * XML Support Class for Product Registration.
+ */
+class RegistrationDocument {
+
+ private static final String REGISTRATION_DATA_SCHEMA =
+ "/com/sun/star/servicetag/resources/product_registration.xsd";
+ private static final String REGISTRATION_DATA_VERSION = "1.0";
+ private static final String SERVICE_TAG_VERSION = "1.0";
+ final static String ST_NODE_REGISTRATION_DATA = "registration_data";
+ final static String ST_ATTR_REGISTRATION_VERSION = "version";
+ final static String ST_NODE_ENVIRONMENT = "environment";
+ final static String ST_NODE_HOSTNAME = "hostname";
+ final static String ST_NODE_HOST_ID = "hostId";
+ final static String ST_NODE_OS_NAME = "osName";
+ final static String ST_NODE_OS_VERSION = "osVersion";
+ final static String ST_NODE_OS_ARCH = "osArchitecture";
+ final static String ST_NODE_SYSTEM_MODEL = "systemModel";
+ final static String ST_NODE_SYSTEM_MANUFACTURER = "systemManufacturer";
+ final static String ST_NODE_CPU_MANUFACTURER = "cpuManufacturer";
+ final static String ST_NODE_SERIAL_NUMBER = "serialNumber";
+ final static String ST_NODE_PHYS_MEM = "physmem";
+ final static String ST_NODE_CPU_INFO = "cpuinfo";
+ final static String ST_NODE_SOCKETS = "sockets";
+ final static String ST_NODE_CORES = "cores";
+ final static String ST_NODE_VIRT_CPUS = "virtcpus";
+ final static String ST_NODE_CPU_NAME = "name";
+ final static String ST_NODE_CLOCK_RATE = "clockrate";
+ final static String ST_NODE_REGISTRY = "registry";
+ final static String ST_ATTR_REGISTRY_URN = "urn";
+ final static String ST_ATTR_REGISTRY_VERSION = "version";
+ final static String ST_NODE_SERVICE_TAG = "service_tag";
+ final static String ST_NODE_INSTANCE_URN = "instance_urn";
+ final static String ST_NODE_PRODUCT_NAME = "product_name";
+ final static String ST_NODE_PRODUCT_VERSION = "product_version";
+ final static String ST_NODE_PRODUCT_URN = "product_urn";
+ final static String ST_NODE_PRODUCT_PARENT_URN = "product_parent_urn";
+ final static String ST_NODE_PRODUCT_PARENT = "product_parent";
+ final static String ST_NODE_PRODUCT_DEFINED_INST_ID = "product_defined_inst_id";
+ final static String ST_NODE_PRODUCT_VENDOR = "product_vendor";
+ final static String ST_NODE_PLATFORM_ARCH = "platform_arch";
+ final static String ST_NODE_TIMESTAMP = "timestamp";
+ final static String ST_NODE_CONTAINER = "container";
+ final static String ST_NODE_SOURCE = "source";
+ final static String ST_NODE_INSTALLER_UID = "installer_uid";
+
+ static RegistrationData load(InputStream in) throws IOException {
+ Document document = initializeDocument(in);
+
+ // Gets the registration URN
+ Element root = getRegistrationDataRoot(document);
+ Element registryRoot =
+ getSingletonElementFromRoot(root, ST_NODE_REGISTRY);
+ String urn = registryRoot.getAttribute(ST_ATTR_REGISTRY_URN);
+
+ // Construct a new RegistrationData object from the DOM tree
+ // Initialize the environment map and service tags
+ RegistrationData regData = new RegistrationData(urn);
+ addServiceTags(registryRoot, regData);
+
+ Element envRoot = getSingletonElementFromRoot(root, ST_NODE_ENVIRONMENT);
+ buildEnvironmentMap(envRoot, regData);
+
+ Element cpuInfo = getSingletonElementFromRoot(envRoot, ST_NODE_CPU_INFO);
+ buildCpuInfoMap(cpuInfo, regData);
+ return regData;
+ }
+
+ static void store(OutputStream os, RegistrationData registration)
+ throws IOException {
+ // create a new document with the root node
+ Document document = initializeDocument();
+
+ // create the nodes for the environment map and the service tags
+ // in the registration data
+ addEnvironmentNodes(document,
+ registration.getEnvironmentMap(),
+ registration.getCpuInfoMap());
+ addServiceTagRegistry(document,
+ registration.getRegistrationURN(),
+ registration.getServiceTags());
+ transform(document, os);
+ }
+
+ // initialize a document from an input stream
+ private static Document initializeDocument(InputStream in) throws IOException {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ SchemaFactory sf = null;
+ try {
+ // Some Java versions (e.g., 1.5.0_06-b05) fail with a
+ // NullPointerException if SchemaFactory.newInstance is called with
+ // a null context class loader, so work around that here (and the
+ // class loader of this class hopefully is not the null bootstrap
+ // class loader):
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ if (cl == null) {
+ Thread.currentThread().setContextClassLoader(
+ RegistrationDocument.class.getClassLoader());
+ }
+ try {
+ sf = SchemaFactory.newInstance(
+ XMLConstants.W3C_XML_SCHEMA_NS_URI);
+ } finally {
+ Thread.currentThread().setContextClassLoader(cl);
+ }
+
+ Schema schema = null;
+ try {
+ // Even using the workaround above is not enough on some
+ // Java versions. Therefore try to workaround the validation
+ // completely!
+ URL xsdUrl = RegistrationDocument.class.getResource(REGISTRATION_DATA_SCHEMA);
+ schema = sf.newSchema(xsdUrl);
+ }
+ catch (NullPointerException nex) {
+ }
+
+ Validator validator = null;
+ if (schema != null)
+ validator = schema.newValidator();
+
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ Document doc = builder.parse(new InputSource(in));
+
+ if (validator != null)
+ validator.validate(new DOMSource(doc));
+
+ return doc;
+ } catch (SAXException sxe) {
+ IllegalArgumentException e = new IllegalArgumentException("Error generated in parsing");
+ e.initCause(sxe);
+ throw e;
+ } catch (ParserConfigurationException pce) {
+ // Parser with specific options can't be built
+ // should not reach here
+ InternalError x = new InternalError("Error in creating the new document");
+ x.initCause(pce);
+ throw x;
+ }
+ }
+
+ // initialize a new document for the registration data
+ private static Document initializeDocument() throws IOException {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ try {
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ Document doc = builder.newDocument();
+
+ // initialize the document with the registration_data root
+ Element root = doc.createElement(ST_NODE_REGISTRATION_DATA);
+ doc.appendChild(root);
+ root.setAttribute(ST_ATTR_REGISTRATION_VERSION, REGISTRATION_DATA_VERSION);
+
+ return doc;
+ } catch (ParserConfigurationException pce) {
+ // Parser with specified options can't be built
+ // should not reach here
+ InternalError x = new InternalError("Error in creating the new document");
+ x.initCause(pce);
+ throw x;
+ }
+ }
+
+ // Transform the current DOM tree with the given output stream.
+ private static void transform(Document document, OutputStream os) {
+ try {
+ // Use a Transformer for output
+ TransformerFactory tFactory = TransformerFactory.newInstance();
+ tFactory.setAttribute("indent-number", new Integer(3));
+
+ Transformer transformer = tFactory.newTransformer();
+
+ transformer.setOutputProperty(OutputKeys.INDENT, "yes");
+ transformer.setOutputProperty(OutputKeys.METHOD, "xml");
+ transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
+ transformer.setOutputProperty(OutputKeys.STANDALONE, "yes");
+ transformer.transform(new DOMSource(document),
+ new StreamResult(new BufferedWriter(new OutputStreamWriter(os, "UTF-8"))));
+ } catch (UnsupportedEncodingException ue) {
+ // Should not reach here
+ InternalError x = new InternalError("Error generated during transformation");
+ x.initCause(ue);
+ throw x;
+ } catch (TransformerConfigurationException tce) {
+ // Error generated by the parser
+ // Should not reach here
+ InternalError x = new InternalError("Error in creating the new document");
+ x.initCause(tce);
+ throw x;
+ } catch (TransformerException te) {
+ // Error generated by the transformer
+ InternalError x = new InternalError("Error generated during transformation");
+ x.initCause(te);
+ throw x;
+ }
+ }
+
+ private static void addServiceTagRegistry(Document document,
+ String registryURN,
+ Set<ServiceTag> svcTags) {
+ // add service tag registry node and its attributes
+ Element reg = document.createElement(ST_NODE_REGISTRY);
+ reg.setAttribute(ST_ATTR_REGISTRY_URN, registryURN);
+ reg.setAttribute(ST_ATTR_REGISTRY_VERSION, SERVICE_TAG_VERSION);
+
+ Element root = getRegistrationDataRoot(document);
+ root.appendChild(reg);
+
+ // adds the elements for the service tags
+ for (ServiceTag st : svcTags) {
+ addServiceTagElement(document, reg, st);
+ }
+ }
+
+ private static void addServiceTagElement(Document document,
+ Element registryRoot,
+ ServiceTag st) {
+ Element svcTag = document.createElement(ST_NODE_SERVICE_TAG);
+ registryRoot.appendChild(svcTag);
+ addChildElement(document, svcTag,
+ ST_NODE_INSTANCE_URN, st.getInstanceURN());
+ addChildElement(document, svcTag,
+ ST_NODE_PRODUCT_NAME, st.getProductName());
+ addChildElement(document, svcTag,
+ ST_NODE_PRODUCT_VERSION, st.getProductVersion());
+ addChildElement(document, svcTag,
+ ST_NODE_PRODUCT_URN, st.getProductURN());
+ addChildElement(document, svcTag,
+ ST_NODE_PRODUCT_PARENT_URN, st.getProductParentURN());
+ addChildElement(document, svcTag,
+ ST_NODE_PRODUCT_PARENT, st.getProductParent());
+ addChildElement(document, svcTag,
+ ST_NODE_PRODUCT_DEFINED_INST_ID,
+ st.getProductDefinedInstanceID());
+ addChildElement(document, svcTag,
+ ST_NODE_PRODUCT_VENDOR, st.getProductVendor());
+ addChildElement(document, svcTag,
+ ST_NODE_PLATFORM_ARCH, st.getPlatformArch());
+ addChildElement(document, svcTag,
+ ST_NODE_TIMESTAMP, Util.formatTimestamp(st.getTimestamp()));
+ addChildElement(document, svcTag,
+ ST_NODE_CONTAINER, st.getContainer());
+ addChildElement(document, svcTag,
+ ST_NODE_SOURCE, st.getSource());
+ addChildElement(document, svcTag,
+ ST_NODE_INSTALLER_UID,
+ String.valueOf(st.getInstallerUID()));
+ }
+
+ private static void addChildElement(Document document, Element root,
+ String element, String text) {
+ Element node = document.createElement(element);
+ node.appendChild(document.createTextNode(text));
+ root.appendChild(node);
+ }
+
+ // Constructs service tags from the document
+ private static void addServiceTags(Element registryRoot,
+ RegistrationData registration) {
+ NodeList children = registryRoot.getElementsByTagName(ST_NODE_SERVICE_TAG);
+ int length = (children == null ? 0 : children.getLength());
+ for (int i = 0; i < length; i++) {
+ Element svcTagElement = (Element) children.item(i);
+ ServiceTag st = getServiceTag(svcTagElement);
+ registration.addServiceTag(st);
+ }
+ }
+
+ // build environment map from the document
+ private static void buildEnvironmentMap(Element envRoot,
+ RegistrationData registration) {
+ registration.setEnvironment(ST_NODE_HOSTNAME, getTextValue(envRoot, ST_NODE_HOSTNAME));
+ registration.setEnvironment(ST_NODE_HOST_ID, getTextValue(envRoot, ST_NODE_HOST_ID));
+ registration.setEnvironment(ST_NODE_OS_NAME, getTextValue(envRoot, ST_NODE_OS_NAME));
+ registration.setEnvironment(ST_NODE_OS_VERSION, getTextValue(envRoot, ST_NODE_OS_VERSION));
+ registration.setEnvironment(ST_NODE_OS_ARCH, getTextValue(envRoot, ST_NODE_OS_ARCH));
+ registration.setEnvironment(ST_NODE_SYSTEM_MODEL, getTextValue(envRoot, ST_NODE_SYSTEM_MODEL));
+ registration.setEnvironment(ST_NODE_SYSTEM_MANUFACTURER, getTextValue(envRoot, ST_NODE_SYSTEM_MANUFACTURER));
+ registration.setEnvironment(ST_NODE_CPU_MANUFACTURER, getTextValue(envRoot, ST_NODE_CPU_MANUFACTURER));
+ registration.setEnvironment(ST_NODE_SERIAL_NUMBER, getTextValue(envRoot, ST_NODE_SERIAL_NUMBER));
+ registration.setEnvironment(ST_NODE_PHYS_MEM, getTextValue(envRoot, ST_NODE_PHYS_MEM));
+ }
+
+ private static void buildCpuInfoMap(Element cpuInfoRoot,
+ RegistrationData registration) {
+ registration.setCpuInfo(ST_NODE_SOCKETS, getTextValue(cpuInfoRoot, ST_NODE_SOCKETS));
+ registration.setCpuInfo(ST_NODE_CORES, getTextValue(cpuInfoRoot, ST_NODE_CORES));
+ registration.setCpuInfo(ST_NODE_VIRT_CPUS, getTextValue(cpuInfoRoot, ST_NODE_VIRT_CPUS));
+ registration.setCpuInfo(ST_NODE_CPU_NAME, getTextValue(cpuInfoRoot, ST_NODE_CPU_NAME));
+ registration.setCpuInfo(ST_NODE_CLOCK_RATE, getTextValue(cpuInfoRoot, ST_NODE_CLOCK_RATE));
+ }
+
+ // add the nodes representing the environment map in the document
+ private static void addEnvironmentNodes(Document document,
+ Map<String, String> envMap,
+ Map<String, String> cpuInfoMap) {
+ Element root = getRegistrationDataRoot(document);
+
+ Element env = document.createElement(ST_NODE_ENVIRONMENT);
+ root.appendChild(env);
+ Set<Map.Entry<String, String>> keys = envMap.entrySet();
+ for (Map.Entry<String, String> entry : keys) {
+ addChildElement(document, env, entry.getKey(), entry.getValue());
+ }
+
+ Element cpuInfo = document.createElement(ST_NODE_CPU_INFO);
+ env.appendChild(cpuInfo);
+ keys = cpuInfoMap.entrySet();
+ for (Map.Entry<String, String> entry : keys) {
+ addChildElement(document, cpuInfo, entry.getKey(), entry.getValue());
+ }
+ }
+
+ private static Element getRegistrationDataRoot(Document doc) {
+ Element root = doc.getDocumentElement();
+ if (!root.getNodeName().equals(ST_NODE_REGISTRATION_DATA)) {
+ throw new IllegalArgumentException("Not a " +
+ ST_NODE_REGISTRATION_DATA +
+ " node \"" + root.getNodeName() + "\"");
+ }
+ return root;
+ }
+
+ private static Element getSingletonElementFromRoot(Element root, String name) {
+ NodeList children = root.getElementsByTagName(name);
+ int length = (children == null ? 0 : children.getLength());
+ if (length != 1) {
+ throw new IllegalArgumentException("Invalid number of " + name +
+ " nodes = " + length);
+ }
+ Element e = (Element) children.item(0);
+ if (!e.getNodeName().equals(name)) {
+ throw new IllegalArgumentException("Not a " + name +
+ " node \"" + e.getNodeName() + "\"");
+ }
+ return e;
+ }
+
+ // Constructs one ServiceTag instance from a service tag element root
+ private static ServiceTag getServiceTag(Element svcTagElement) {
+ return new ServiceTag(
+ getTextValue(svcTagElement, ST_NODE_INSTANCE_URN),
+ getTextValue(svcTagElement, ST_NODE_PRODUCT_NAME),
+ getTextValue(svcTagElement, ST_NODE_PRODUCT_VERSION),
+ getTextValue(svcTagElement, ST_NODE_PRODUCT_URN),
+ getTextValue(svcTagElement, ST_NODE_PRODUCT_PARENT),
+ getTextValue(svcTagElement, ST_NODE_PRODUCT_PARENT_URN),
+ getTextValue(svcTagElement, ST_NODE_PRODUCT_DEFINED_INST_ID),
+ getTextValue(svcTagElement, ST_NODE_PRODUCT_VENDOR),
+ getTextValue(svcTagElement, ST_NODE_PLATFORM_ARCH),
+ getTextValue(svcTagElement, ST_NODE_CONTAINER),
+ getTextValue(svcTagElement, ST_NODE_SOURCE),
+ Util.getIntValue(getTextValue(svcTagElement, ST_NODE_INSTALLER_UID)),
+ Util.parseTimestamp(getTextValue(svcTagElement, ST_NODE_TIMESTAMP))
+ );
+ }
+
+ private static String getTextValue(Element e, String tagName) {
+ String value = "";
+ NodeList nl = e.getElementsByTagName(tagName);
+ if (nl != null && nl.getLength() > 0) {
+ Element el = (Element) nl.item(0);
+ Node node = el.getFirstChild();
+ if (node != null) {
+ value = node.getNodeValue();
+ }
+ }
+ return value;
+ }
+}
diff --git a/desktop/source/registration/com/sun/star/servicetag/Registry.java b/desktop/source/registration/com/sun/star/servicetag/Registry.java
index 879db1fdec..51c90b9e94 100644
--- a/desktop/source/registration/com/sun/star/servicetag/Registry.java
+++ b/desktop/source/registration/com/sun/star/servicetag/Registry.java
@@ -1,14 +1,13 @@
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
+ *
* Copyright 2008 by Sun Microsystems, Inc.
*
* OpenOffice.org - a multi-platform office productivity suite
*
- * $RCSfile: Registry.java,v $
- *
- * $Revision: 1.2 $
+ * $RCSfile: Registration.java,v $
+ * $Revision: 1.3 $
*
* This file is part of OpenOffice.org.
*
diff --git a/desktop/source/registration/com/sun/star/servicetag/ServiceTag.java b/desktop/source/registration/com/sun/star/servicetag/ServiceTag.java
index 26a2bbdd60..cfaa04baca 100644
--- a/desktop/source/registration/com/sun/star/servicetag/ServiceTag.java
+++ b/desktop/source/registration/com/sun/star/servicetag/ServiceTag.java
@@ -1,14 +1,13 @@
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
+ *
* Copyright 2008 by Sun Microsystems, Inc.
*
* OpenOffice.org - a multi-platform office productivity suite
*
- * $RCSfile: ServiceTag.java,v $
- *
- * $Revision: 1.2 $
+ * $RCSfile: Registration.java,v $
+ * $Revision: 1.3 $
*
* This file is part of OpenOffice.org.
*
diff --git a/desktop/source/registration/com/sun/star/servicetag/SolarisServiceTag.java b/desktop/source/registration/com/sun/star/servicetag/SolarisServiceTag.java
index 45ff7b8f7d..1ce6790094 100644
--- a/desktop/source/registration/com/sun/star/servicetag/SolarisServiceTag.java
+++ b/desktop/source/registration/com/sun/star/servicetag/SolarisServiceTag.java
@@ -1,14 +1,13 @@
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
+ *
* Copyright 2008 by Sun Microsystems, Inc.
*
* OpenOffice.org - a multi-platform office productivity suite
*
- * $RCSfile: SolarisServiceTag.java,v $
- *
- * $Revision: 1.2 $
+ * $RCSfile: Registration.java,v $
+ * $Revision: 1.3 $
*
* This file is part of OpenOffice.org.
*
diff --git a/desktop/source/registration/com/sun/star/servicetag/SolarisSystemEnvironment.java b/desktop/source/registration/com/sun/star/servicetag/SolarisSystemEnvironment.java
index 35dcdba239..01420fba8a 100644
--- a/desktop/source/registration/com/sun/star/servicetag/SolarisSystemEnvironment.java
+++ b/desktop/source/registration/com/sun/star/servicetag/SolarisSystemEnvironment.java
@@ -1,14 +1,13 @@
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
+ *
* Copyright 2008 by Sun Microsystems, Inc.
*
* OpenOffice.org - a multi-platform office productivity suite
*
- * $RCSfile: SolarisSystemEnvironment.java,v $
- *
- * $Revision: 1.2 $
+ * $RCSfile: Registration.java,v $
+ * $Revision: 1.3 $
*
* This file is part of OpenOffice.org.
*
@@ -40,17 +39,180 @@ package com.sun.star.servicetag;
// (e.g. NetBeans and SunStudio) will use the version in JDK.
import java.io.*;
+import java.util.Set;
+import java.util.HashSet;
/**
* Solaris implementation of the SystemEnvironment class.
*/
class SolarisSystemEnvironment extends SystemEnvironment {
+ private static final int SN = 1;
+ private static final int SYS = 2;
+ private static final int CPU = 3;
+ private static final int MODEL = 4;
+ private String kstatCpuInfo = null;
+
SolarisSystemEnvironment() {
setHostId(getCommandOutput("/usr/bin/hostid"));
- setSystemModel(getCommandOutput("/usr/bin/uname", "-i"));
+ setSystemModel(getSolarisModel());
setSystemManufacturer(getSolarisSystemManufacturer());
setCpuManufacturer(getSolarisCpuManufacturer());
setSerialNumber(getSolarisSN());
+ setPhysMem(getSolarisPhysMem());
+ setSockets(getSolarisSockets());
+ setCores(getSolarisCores());
+ setVirtCpus(getSolarisVirtCpus());
+ setCpuName(getSolarisCpuName());
+ setClockRate(getSolarisClockRate());
+ }
+
+ private String getSolarisClockRate() {
+ String data = getSolarisKstatCpuInfo();
+
+ String lines[] = data.split("\n");
+ String token = "clock_MHz";
+ for (int i=0; i<lines.length; i++) {
+ String line = lines[i].trim();
+ if (line.startsWith(token)) {
+ return line.substring(line.indexOf(token) + token.length()).trim();
+ }
+ }
+ return "";
+ }
+
+ private String getSolarisCpuName() {
+ String data = getSolarisKstatCpuInfo();
+
+ String lines[] = data.split("\n");
+ String token = "brand";
+ for (int i=0; i<lines.length; i++) {
+ String line = lines[i].trim();
+ if (line.startsWith(token)) {
+ return line.substring(line.indexOf(token) + token.length()).trim();
+ }
+ }
+ return "";
+ }
+
+ private String getSolarisVirtCpus() {
+ String data = getSolarisKstatCpuInfo();
+
+ int cnt = 0;
+ String lines[] = data.split("\n");
+ String token = " cpu_info ";
+ for (int i=0; i<lines.length; i++) {
+ String line = lines[i].trim();
+ if (line.indexOf(token) != -1) {
+ cnt++;
+ }
+ }
+ return "" + cnt;
+ }
+
+ private String getSolarisCores() {
+ String data = getSolarisKstatCpuInfo();
+
+ Set<String> set = new HashSet<String>();
+ String lines[] = data.split("\n");
+ String coreIdToken = "core_id";
+ String coreId = "";
+ String chipIdToken = "chip_id";
+ String chipId = "";
+ for (int i=0; i<lines.length; i++) {
+ String line = lines[i].trim();
+ if (line.startsWith(chipIdToken)) {
+ chipId = line.substring(line.indexOf(chipIdToken) + chipIdToken.length()).trim();
+ }
+ if (line.startsWith(coreIdToken)) {
+ coreId = line.substring(line.indexOf(coreIdToken) + coreIdToken.length()).trim();
+ set.add(chipId + "," + coreId);
+ }
+ }
+ return "" + set.size();
+ }
+
+ private String getSolarisPhysMem() {
+ String data = getCommandOutput("/usr/sbin/prtconf");
+
+ int cnt = 0;
+ String lines[] = data.split("\n");
+ String token = "Memory size:";
+ for (int i=0; i<lines.length; i++) {
+ String line = lines[i].trim();
+ if (line.startsWith(token)) {
+ line = line.substring(line.indexOf(token) + token.length()).trim();
+ if (line.indexOf(" ") != -1) {
+ return line.substring(0, line.indexOf(" ")).trim();
+ }
+ }
+ }
+ return "";
+ }
+
+ private String getSolarisSockets() {
+ String data = getSolarisKstatCpuInfo();
+
+ Set<String> set = new HashSet<String>();
+ String lines[] = data.split("\n");
+ String token = "chip_id";
+ for (int i=0; i<lines.length; i++) {
+ String line = lines[i].trim();
+ if (line.startsWith(token)) {
+ String id = line.substring(line.indexOf(token) + token.length()).trim();
+ set.add(id);
+ }
+ }
+ return "" + set.size();
+ }
+
+ private synchronized String getSolarisKstatCpuInfo() {
+ // only try to get kstat cpu_info information once, after that, we can
+ // reuse the output
+ if (kstatCpuInfo == null) {
+ Thread thread = new Thread() {
+ public void run() {
+ kstatCpuInfo = getCommandOutput("/usr/bin/kstat", "cpu_info");
+ }
+ };
+ thread.start();
+
+ try {
+ thread.join(2000);
+ if (thread.isAlive()) {
+ thread.interrupt();
+ kstatCpuInfo = "";
+ }
+ } catch (InterruptedException ie) {
+ thread.interrupt();
+ }
+ }
+ return kstatCpuInfo;
+ }
+
+ private String getSolarisModel() {
+ String tmp = getFileContent("/var/run/psn");
+ if (tmp.length() > 0) {
+ String[] lines = tmp.split("\n");
+ if (MODEL <= lines.length) {
+ return lines[MODEL-1] + "::"
+ + getCommandOutput("/usr/bin/uname", "-v");
+ }
+ }
+
+ if ("sparc".equalsIgnoreCase(System.getProperty("os.arch"))) {
+ return getCommandOutput("/usr/bin/uname", "-i") + "::"
+ + getCommandOutput("/usr/bin/uname", "-v");
+ } else {
+ String model = getSmbiosData("1", "Product: ");
+ if (model == null || model.trim().equals("")) {
+ model = getCommandOutput("/usr/bin/uname", "-i");
+ }
+ if (model == null) {
+ model = "";
+ }
+ return model.trim() + "::"
+ + getCommandOutput("/usr/bin/uname", "-v");
+ }
}
/**
@@ -58,13 +220,21 @@ class SolarisSystemEnvironment extends SystemEnvironment {
* @return The cpu manufacturer (an empty string if not found or an error occurred)
*/
private String getSolarisCpuManufacturer() {
+ String tmp = getFileContent("/var/run/psn");
+ if (tmp.length() > 0) {
+ String[] lines = tmp.split("\n");
+ if (CPU <= lines.length) {
+ return lines[CPU-1];
+ }
+ }
+
// not fully accurate, this could be another manufacturer (fujitsu for example)
if ("sparc".equalsIgnoreCase(System.getProperty("os.arch"))) {
return "Sun Microsystems, Inc";
}
- // if we're here, then we'll try smbios (type 3)
- return getSmbiosData("3", "Manufacturer: ");
+ // if we're here, then we'll try smbios (type 4)
+ return getSmbiosData("4", "Manufacturer: ");
}
/**
@@ -72,8 +242,19 @@ class SolarisSystemEnvironment extends SystemEnvironment {
* @return The system manufacturer (an empty string if not found or an error occurred)
*/
private String getSolarisSystemManufacturer() {
+ String tmp = getFileContent("/var/run/psn");
+ if (tmp.length() > 0) {
+ String[] lines = tmp.split("\n");
+ if (SYS <= lines.length) {
+ return lines[SYS-1];
+ }
+ }
+
// not fully accurate, this could be another manufacturer (fujitsu for example)
if ("sparc".equalsIgnoreCase(System.getProperty("os.arch"))) {
+ if (getCommandOutput("/usr/bin/uname", "-m").equals("sun4us")) {
+ return "Fujitsu";
+ }
return "Sun Microsystems, Inc";
}
@@ -89,7 +270,10 @@ class SolarisSystemEnvironment extends SystemEnvironment {
// try to read from the psn file if it exists
String tmp = getFileContent("/var/run/psn");
if (tmp.length() > 0) {
- return tmp.trim();
+ String[] lines = tmp.split("\n");
+ if (SN <= lines.length) {
+ return lines[SN-1];
+ }
}
// if we're here, then we'll try sneep
@@ -110,6 +294,17 @@ class SolarisSystemEnvironment extends SystemEnvironment {
return tmpSN;
}
+ if ("sparc".equalsIgnoreCase(System.getProperty("os.arch"))) {
+ tmpSN = getSNViaPrtfruX();
+ if (tmpSN.length() > 0) {
+ return tmpSN;
+ }
+ tmpSN = getSNViaPrtfru();
+ if (tmpSN.length() > 0) {
+ return tmpSN;
+ }
+ }
+
// give up and return
return "";
}
@@ -156,4 +351,74 @@ class SolarisSystemEnvironment extends SystemEnvironment {
}
}
+ private String getSNViaPrtfruX() {
+ String data = getCommandOutput("/usr/sbin/prtfru", "-x");
+
+ boolean FRUTREE_FLAG = false;
+ boolean FRUNAME_FLAG = false;
+ boolean MB_LABEL_FLAG = false;
+ boolean SYSTEM_BOARD_FLAG = false;
+
+ String lines[] = data.split("\n");
+ for (int i=0; i<lines.length; i++) {
+ String line = lines[i];
+ if (SYSTEM_BOARD_FLAG) {
+ String tok = "<Sun_Serial_No value=\"";
+ int index = line.indexOf(tok);
+ if (index != -1) {
+ String val = line.substring(index+tok.length());
+ String vals[] = val.split("\"");
+ if (vals.length > 0) {
+ return vals[0].trim();
+ }
+ break;
+ }
+ }
+
+ if (line.indexOf("</ContainerData>") != -1) {
+ FRUTREE_FLAG = false;
+ FRUNAME_FLAG = false;
+ SYSTEM_BOARD_FLAG = false;
+ }
+
+ if (FRUNAME_FLAG && line.indexOf("<Container name=\"system-board\">") != -1 ) {
+ SYSTEM_BOARD_FLAG = true;
+ }
+
+ if (FRUTREE_FLAG && line.indexOf("<Fru name=\"chassis\">") != -1 ) {
+ FRUNAME_FLAG = true;
+ }
+
+ if (line.indexOf("<Location name=\"frutree\">") != -1) {
+ FRUTREE_FLAG = true;
+ }
+ }
+
+ return "";
+ }
+
+ private String getSNViaPrtfru() {
+ String data = getCommandOutput("/usr/sbin/prtfru");
+ boolean CHASSIS_FLAG = false;
+
+ String lines[] = data.split("\n");
+ for (int i=0; i<lines.length; i++) {
+ String line = lines[i];
+ if (CHASSIS_FLAG) {
+ String tok = "/ManR/Sun_Serial_No:";
+ int index = line.indexOf(tok);
+ if (index != -1) {
+ String val = line.substring(index+tok.length());
+ return val.trim();
+ }
+ }
+
+ if (line.indexOf("/frutree/chassis/system-board (container)") != -1) {
+ CHASSIS_FLAG = true;
+ } else if (line.indexOf("/frutree/chassis/MB?Label=MB/system-board (container)") != -1) {
+ CHASSIS_FLAG = true;
+ }
+ }
+ return "";
+ }
}
diff --git a/desktop/source/registration/com/sun/star/servicetag/SunConnection.java b/desktop/source/registration/com/sun/star/servicetag/SunConnection.java
index 36c527e018..5bc3396e1b 100644
--- a/desktop/source/registration/com/sun/star/servicetag/SunConnection.java
+++ b/desktop/source/registration/com/sun/star/servicetag/SunConnection.java
@@ -1,14 +1,13 @@
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
+ *
* Copyright 2008 by Sun Microsystems, Inc.
*
* OpenOffice.org - a multi-platform office productivity suite
*
- * $RCSfile: SunConnection.java,v $
- *
- * $Revision: 1.2 $
+ * $RCSfile: Registration.java,v $
+ * $Revision: 1.3 $
*
* This file is part of OpenOffice.org.
*
diff --git a/desktop/source/registration/com/sun/star/servicetag/SysnetRegistryHelper.java b/desktop/source/registration/com/sun/star/servicetag/SysnetRegistryHelper.java
index 3295a2d45d..2508565b51 100644
--- a/desktop/source/registration/com/sun/star/servicetag/SysnetRegistryHelper.java
+++ b/desktop/source/registration/com/sun/star/servicetag/SysnetRegistryHelper.java
@@ -1,14 +1,13 @@
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
+ *
* Copyright 2008 by Sun Microsystems, Inc.
*
* OpenOffice.org - a multi-platform office productivity suite
*
- * $RCSfile: SysnetRegistryHelper.java,v $
- *
- * $Revision: 1.2 $
+ * $RCSfile: Registration.java,v $
+ * $Revision: 1.3 $
*
* This file is part of OpenOffice.org.
*
diff --git a/desktop/source/registration/com/sun/star/servicetag/SystemEnvironment.java b/desktop/source/registration/com/sun/star/servicetag/SystemEnvironment.java
index 40151dfa4c..badf5bbbfd 100644
--- a/desktop/source/registration/com/sun/star/servicetag/SystemEnvironment.java
+++ b/desktop/source/registration/com/sun/star/servicetag/SystemEnvironment.java
@@ -1,14 +1,13 @@
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
+ *
* Copyright 2008 by Sun Microsystems, Inc.
*
* OpenOffice.org - a multi-platform office productivity suite
*
- * $RCSfile: SystemEnvironment.java,v $
- *
- * $Revision: 1.2 $
+ * $RCSfile: Registration.java,v $
+ * $Revision: 1.3 $
*
* This file is part of OpenOffice.org.
*
@@ -57,6 +56,12 @@ public class SystemEnvironment {
private String systemManufacturer;
private String cpuManufacturer;
private String serialNumber;
+ private String physmem;
+ private String sockets;
+ private String cores;
+ private String virtcpus;
+ private String cpuname;
+ private String clockrate;
private static SystemEnvironment sysEnv = null;
public static synchronized SystemEnvironment getSystemEnvironment() {
@@ -90,6 +95,12 @@ public class SystemEnvironment {
this.systemManufacturer = "";
this.cpuManufacturer = "";
this.serialNumber = "";
+ this.physmem = "";
+ this.sockets = "";
+ this.cores = "";
+ this.virtcpus = "";
+ this.cpuname = "";
+ this.clockrate = "";
}
@@ -158,6 +169,56 @@ public class SystemEnvironment {
}
/**
+ * Sets the physmem
+ * @param physmem The physmem to set.
+ */
+ public void setPhysMem(String physmem) {
+ this.physmem = physmem;
+ }
+
+ /**
+ * Sets the sockets
+ * @param sockets The sockets to set.
+ */
+ public void setSockets(String sockets) {
+ this.sockets = sockets;
+ }
+
+ /**
+ * Sets the cores
+ * @param cores The cores to set.
+ */
+ public void setCores(String cores) {
+ this.cores = cores;
+ }
+
+ /**
+ * Sets the virtcpus
+ * @param virtcpus The virtcpus to set.
+ */
+ public void setVirtCpus(String virtcpus) {
+ this.virtcpus = virtcpus;
+ }
+
+ /**
+ * Sets the cpuname
+ * @param cpuname The cpuname to set.
+ */
+ public void setCpuName(String cpuname) {
+ this.cpuname = cpuname;
+ }
+
+ /**
+ * Sets the clockrate
+ * @param clockrate The clockrate to set.
+ */
+ public void setClockRate(String clockrate) {
+ Float f = Float.parseFloat(clockrate);
+ Integer nClockrate = f.intValue();
+ this.clockrate = nClockrate.toString();
+ }
+
+ /**
* Sets the hostid. Truncates to a max length of 16 chars.
* @param hostId The hostid to set.
*/
@@ -227,6 +288,30 @@ public class SystemEnvironment {
return serialNumber;
}
+ public String getPhysMem() {
+ return physmem;
+ }
+
+ public String getSockets() {
+ return sockets;
+ }
+
+ public String getCores() {
+ return cores;
+ }
+
+ public String getVirtCpus() {
+ return virtcpus;
+ }
+
+ public String getCpuName() {
+ return cpuname;
+ }
+
+ public String getClockRate() {
+ return clockrate;
+ }
+
/**
* Returns the hostId.
* @return The hostId.
diff --git a/desktop/source/registration/com/sun/star/servicetag/UnauthorizedAccessException.java b/desktop/source/registration/com/sun/star/servicetag/UnauthorizedAccessException.java
index 196e987955..fd1e26643a 100644
--- a/desktop/source/registration/com/sun/star/servicetag/UnauthorizedAccessException.java
+++ b/desktop/source/registration/com/sun/star/servicetag/UnauthorizedAccessException.java
@@ -1,14 +1,13 @@
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
+ *
* Copyright 2008 by Sun Microsystems, Inc.
*
* OpenOffice.org - a multi-platform office productivity suite
*
- * $RCSfile: UnauthorizedAccessException.java,v $
- *
- * $Revision: 1.2 $
+ * $RCSfile: Registration.java,v $
+ * $Revision: 1.3 $
*
* This file is part of OpenOffice.org.
*
diff --git a/desktop/source/registration/com/sun/star/servicetag/Util.java b/desktop/source/registration/com/sun/star/servicetag/Util.java
index e8ae3fc6ed..7de1e832a5 100644
--- a/desktop/source/registration/com/sun/star/servicetag/Util.java
+++ b/desktop/source/registration/com/sun/star/servicetag/Util.java
@@ -1,14 +1,13 @@
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
+ *
* Copyright 2008 by Sun Microsystems, Inc.
*
* OpenOffice.org - a multi-platform office productivity suite
*
- * $RCSfile: Util.java,v $
- *
- * $Revision: 1.2 $
+ * $RCSfile: Registration.java,v $
+ * $Revision: 1.3 $
*
* This file is part of OpenOffice.org.
*
@@ -40,7 +39,7 @@ import java.util.UUID;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
-// Utility class for com.sun.star.servicetag package
+// Utility class for com.sun.servicetag package
class Util {
private static boolean verbose = (System.getProperty("servicetag.verbose") != null);
private static String jrepath = null;
diff --git a/desktop/source/registration/com/sun/star/servicetag/WindowsSystemEnvironment.java b/desktop/source/registration/com/sun/star/servicetag/WindowsSystemEnvironment.java
index 97ceeb5e7d..ec391d8270 100644
--- a/desktop/source/registration/com/sun/star/servicetag/WindowsSystemEnvironment.java
+++ b/desktop/source/registration/com/sun/star/servicetag/WindowsSystemEnvironment.java
@@ -1,14 +1,13 @@
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
+ *
* Copyright 2008 by Sun Microsystems, Inc.
*
* OpenOffice.org - a multi-platform office productivity suite
*
- * $RCSfile: WindowsSystemEnvironment.java,v $
- *
- * $Revision: 1.2 $
+ * $RCSfile: Registration.java,v $
+ * $Revision: 1.3 $
*
* This file is part of OpenOffice.org.
*
@@ -33,7 +32,7 @@ package com.sun.star.servicetag;
// The Service Tags team maintains the latest version of the implementation
// for system environment data collection. JDK will include a copy of
-// the most recent released version for a JDK release. We rename
+// the most recent released version for a JDK release. We rename
// the package to com.sun.servicetag so that the Sun Connection
// product always uses the latest version from the com.sun.scn.servicetags
// package. JDK and users of the com.sun.servicetag API
@@ -42,6 +41,8 @@ package com.sun.star.servicetag;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
+import java.util.HashSet;
+import java.util.Set;
/**
* Windows implementation of the SystemEnvironment class.
@@ -71,6 +72,13 @@ class WindowsSystemEnvironment extends SystemEnvironment {
}
setCpuManufacturer(cpuMfr);
+ setSockets(getWindowsSockets());
+ setCores(getWindowsCores());
+ setVirtCpus(getWindowsVirtCpus());
+ setPhysMem(getWindowsPhysMem());
+ setCpuName(getWmicResult("cpu", "get", "Name"));
+ setClockRate(getWmicResult("cpu", "get", "MaxClockSpeed"));
+
// try to remove the temp file that gets created from running wmic cmds
try {
// look in the current working directory
@@ -83,6 +91,44 @@ class WindowsSystemEnvironment extends SystemEnvironment {
}
}
+ private String getWindowsVirtCpus() {
+ String res = getWmicResult("cpu", "get", "NumberOfLogicalProcessors");
+ if (res == null || res.equals("")) {
+ res = "1";
+ }
+ return res;
+ }
+
+ private String getWindowsCores() {
+ String res = getWmicResult("cpu", "get", "NumberOfCores");
+ if (res == null || res.equals("")) {
+ res = "1";
+ }
+ return res;
+ }
+
+ private String getWindowsSockets() {
+ String res = getFullWmicResult("cpu", "get", "DeviceID");
+ Set<String> set = new HashSet<String>();
+ for (String line : res.split("\n")) {
+ line = line.trim();
+ if (line.equals("")) {
+ continue;
+ }
+ set.add(line);
+ }
+ if (set.size() == 0) {
+ return "1";
+ }
+ return "" + set.size();
+ }
+
+ private String getWindowsPhysMem() {
+ String mem = getWmicResult("computersystem", "get", "TotalPhysicalMemory");
+ long l = Long.parseLong(mem);
+ return "" + ((long) (l / (1024*1024)));
+ }
+
/**
* This method invokes wmic outside of the normal environment
@@ -142,4 +188,48 @@ class WindowsSystemEnvironment extends SystemEnvironment {
}
return res.trim();
}
+
+ private String getFullWmicResult(String alias, String verb, String property) {
+ String res = "";
+ BufferedReader in = null;
+ try {
+ ProcessBuilder pb = new ProcessBuilder("cmd", "/C", "WMIC", alias, verb, property);
+ Process p = pb.start();
+ // need this for executing windows commands (at least
+ // needed for executing wmic command)
+ BufferedWriter bw = new BufferedWriter(
+ new OutputStreamWriter(p.getOutputStream()));
+ bw.write(13);
+ bw.flush();
+ bw.close();
+
+ p.waitFor();
+ if (p.exitValue() == 0) {
+ in = new BufferedReader(new InputStreamReader(p.getInputStream()));
+ String line = null;
+ while ((line = in.readLine()) != null) {
+ line = line.trim();
+ if (line.length() == 0) {
+ continue;
+ }
+ if (line.toLowerCase().indexOf(property.toLowerCase()) != -1) {
+ continue;
+ }
+ res += line + "\n";
+ }
+ }
+
+ } catch (Exception e) {
+ // ignore the exception
+ } finally {
+ if (in != null) {
+ try {
+ in.close();
+ } catch (IOException e) {
+ // ignore
+ }
+ }
+ }
+ return res;
+ }
}
diff --git a/desktop/source/registration/com/sun/star/servicetag/resources/product_registration.xsd b/desktop/source/registration/com/sun/star/servicetag/resources/product_registration.xsd
index e9b34417d9..bb48ba9084 100644
--- a/desktop/source/registration/com/sun/star/servicetag/resources/product_registration.xsd
+++ b/desktop/source/registration/com/sun/star/servicetag/resources/product_registration.xsd
@@ -1,301 +1,366 @@
-<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
-
-<xs:element name="registration_data">
- <xs:complexType>
- <xs:sequence>
- <xs:element name="environment"
- minOccurs="1"
- maxOccurs="1">
- <xs:complexType>
- <xs:sequence>
- <xs:element ref="hostname"
- minOccurs='1'
- maxOccurs='1'/>
- <xs:element ref="hostId"
- minOccurs='1'
- maxOccurs='1'/>
- <xs:element ref="osName"
- minOccurs='1'
- maxOccurs='1'/>
- <xs:element ref="osVersion"
- minOccurs='1'
- maxOccurs='1'/>
- <xs:element ref="osArchitecture"
- minOccurs='1'
- maxOccurs='1'/>
- <xs:element ref="systemModel"
- minOccurs='1'
- maxOccurs='1'/>
- <xs:element ref="systemManufacturer"
- minOccurs='1'
- maxOccurs='1'/>
- <xs:element ref="cpuManufacturer"
- minOccurs='1'
- maxOccurs='1'/>
- <xs:element ref="serialNumber"
- minOccurs='1'
- maxOccurs='1'/>
- </xs:sequence>
- </xs:complexType>
- </xs:element>
- <xs:element name="registry"
- minOccurs="1"
- maxOccurs="1">
- <xs:complexType>
- <xs:sequence>
- <xs:element name="service_tag"
- minOccurs="0"
- maxOccurs="1024">
- <xs:complexType>
- <xs:sequence>
- <xs:element ref="instance_urn"
- minOccurs='1'
- maxOccurs='1'/>
- <xs:element ref="product_name"
- minOccurs='1'
- maxOccurs='1'/>
- <xs:element ref="product_version"
- minOccurs='1'
- maxOccurs='1'/>
- <xs:element ref="product_urn"
- minOccurs='1'
- maxOccurs='1'/>
- <xs:element ref="product_parent_urn"
- minOccurs='1'
- maxOccurs='1'/>
- <xs:element ref="product_parent"
- minOccurs='1'
- maxOccurs='1'/>
- <xs:element ref="product_defined_inst_id"
- minOccurs='1'
- maxOccurs='1'/>
- <xs:element ref="product_vendor"
- minOccurs='1'
- maxOccurs='1'/>
- <xs:element ref="platform_arch"
- minOccurs='1'
- maxOccurs='1'/>
- <xs:element ref="timestamp"
- minOccurs='1'
- maxOccurs='1'/>
- <xs:element ref="container"
- minOccurs='1'
- maxOccurs='1'/>
- <xs:element ref="source"
- minOccurs='1'
- maxOccurs='1'/>
- <xs:element ref="installer_uid"
- minOccurs='1'
- maxOccurs='1'/>
- </xs:sequence>
- </xs:complexType>
- </xs:element>
- </xs:sequence>
- <xs:attribute name="urn"
- type="xs:string"
- use="required"/>
- <xs:attribute name="version"
- type="xs:string"
- use="required"/>
- </xs:complexType>
- </xs:element>
- </xs:sequence>
- <xs:attribute name="version"
- type="xs:string"
- use="required"/>
- </xs:complexType>
-</xs:element>
-
- <!-- definition of simple elements -->
- <xs:element name="hostname">
- <xs:simpleType>
- <xs:restriction base="xs:string">
- <xs:minLength value="1"/>
- <xs:maxLength value="255"/>
- </xs:restriction>
- </xs:simpleType>
- </xs:element>
-
- <xs:element name="hostId">
- <xs:simpleType>
- <xs:restriction base="xs:string">
- <xs:minLength value="0"/>
- <xs:maxLength value="16"/>
- </xs:restriction>
- </xs:simpleType>
- </xs:element>
-
- <xs:element name="osName">
- <xs:simpleType>
- <xs:restriction base="xs:string">
- <xs:minLength value="1"/>
- <xs:maxLength value="256"/>
- </xs:restriction>
- </xs:simpleType>
- </xs:element>
-
- <xs:element name="osVersion">
- <xs:simpleType>
- <xs:restriction base="xs:string">
- <xs:minLength value="0"/>
- <xs:maxLength value="50"/>
- </xs:restriction>
- </xs:simpleType>
- </xs:element>
-
- <xs:element name="osArchitecture">
- <xs:simpleType>
- <xs:restriction base="xs:string">
- <xs:minLength value="0"/>
- <xs:maxLength value="256"/>
- </xs:restriction>
- </xs:simpleType>
- </xs:element>
-
- <xs:element name="systemModel">
- <xs:simpleType>
- <xs:restriction base="xs:string">
- <xs:minLength value="0"/>
- <xs:maxLength value="50"/>
- </xs:restriction>
- </xs:simpleType>
- </xs:element>
-
- <xs:element name="systemManufacturer">
- <xs:simpleType>
- <xs:restriction base="xs:string">
- <xs:minLength value="0"/>
- <xs:maxLength value="50"/>
- </xs:restriction>
- </xs:simpleType>
- </xs:element>
-
- <xs:element name="cpuManufacturer">
- <xs:simpleType>
- <xs:restriction base="xs:string">
- <xs:minLength value="0"/>
- <xs:maxLength value="50"/>
- </xs:restriction>
- </xs:simpleType>
- </xs:element>
-
- <xs:element name="serialNumber">
- <xs:simpleType>
- <xs:restriction base="xs:string">
- <xs:minLength value="0"/>
- <xs:maxLength value="256"/>
- </xs:restriction>
- </xs:simpleType>
- </xs:element>
-
- <xs:element name="instance_urn">
- <xs:simpleType>
- <xs:restriction base="xs:string">
- <xs:minLength value="1"/>
- <xs:maxLength value="255"/>
- </xs:restriction>
- </xs:simpleType>
- </xs:element>
-
- <xs:element name="product_name">
- <xs:simpleType>
- <xs:restriction base="xs:string">
- <xs:maxLength value="255"/>
- </xs:restriction>
- </xs:simpleType>
- </xs:element>
-
- <xs:element name="product_version">
- <xs:simpleType>
- <xs:restriction base="xs:string">
- <xs:maxLength value="63"/>
- </xs:restriction>
- </xs:simpleType>
- </xs:element>
-
- <xs:element name="product_urn">
- <xs:simpleType>
- <xs:restriction base="xs:string">
- <xs:minLength value="1"/>
- <xs:maxLength value="255"/>
- </xs:restriction>
- </xs:simpleType>
- </xs:element>
-
- <xs:element name="product_parent_urn">
- <xs:simpleType>
- <xs:restriction base="xs:string">
- <xs:minLength value="0"/>
- <xs:maxLength value="255"/>
- </xs:restriction>
- </xs:simpleType>
- </xs:element>
-
- <xs:element name="product_parent">
- <xs:simpleType>
- <xs:restriction base="xs:string">
- <xs:minLength value="1"/>
- <xs:maxLength value="255"/>
- </xs:restriction>
- </xs:simpleType>
- </xs:element>
-
- <xs:element name="product_defined_inst_id">
- <xs:simpleType>
- <xs:restriction base="xs:string">
- <xs:minLength value="0"/>
- <xs:maxLength value="255"/>
- </xs:restriction>
- </xs:simpleType>
- </xs:element>
-
- <xs:element name="product_vendor">
- <xs:simpleType>
- <xs:restriction base="xs:string">
- <xs:minLength value="1"/>
- <xs:maxLength value="63"/>
- </xs:restriction>
- </xs:simpleType>
- </xs:element>
-
- <xs:element name="platform_arch">
- <xs:simpleType>
- <xs:restriction base="xs:string">
- <xs:minLength value="1"/>
- <xs:maxLength value="63"/>
- </xs:restriction>
- </xs:simpleType>
- </xs:element>
-
- <xs:element name="timestamp">
- <xs:simpleType>
- <xs:restriction base="xs:string">
- <xs:maxLength value="24"/>
- </xs:restriction>
- </xs:simpleType>
- </xs:element>
-
- <xs:element name="container">
- <xs:simpleType>
- <xs:restriction base="xs:string">
- <xs:maxLength value="63"/>
- </xs:restriction>
- </xs:simpleType>
- </xs:element>
-
- <xs:element name="source">
- <xs:simpleType>
- <xs:restriction base="xs:string">
- <xs:maxLength value="63"/>
- </xs:restriction>
- </xs:simpleType>
- </xs:element>
-
- <xs:element name="installer_uid">
- <xs:simpleType>
- <xs:restriction base="xs:integer">
- </xs:restriction>
- </xs:simpleType>
- </xs:element>
-
-</xs:schema>
+<?xml version="1.0" encoding="UTF-8"?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
+
+<xs:element name="registration_data">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element name="environment"
+ minOccurs="1"
+ maxOccurs="1">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element ref="hostname"
+ minOccurs='1'
+ maxOccurs='1'/>
+ <xs:element ref="hostId"
+ minOccurs='1'
+ maxOccurs='1'/>
+ <xs:element ref="osName"
+ minOccurs='1'
+ maxOccurs='1'/>
+ <xs:element ref="osVersion"
+ minOccurs='1'
+ maxOccurs='1'/>
+ <xs:element ref="osArchitecture"
+ minOccurs='1'
+ maxOccurs='1'/>
+ <xs:element ref="systemModel"
+ minOccurs='1'
+ maxOccurs='1'/>
+ <xs:element ref="systemManufacturer"
+ minOccurs='1'
+ maxOccurs='1'/>
+ <xs:element ref="cpuManufacturer"
+ minOccurs='1'
+ maxOccurs='1'/>
+ <xs:element ref="serialNumber"
+ minOccurs='1'
+ maxOccurs='1'/>
+ <xs:element ref="physmem"
+ minOccurs='0'
+ maxOccurs='1'/>
+ <xs:element name="cpuinfo"
+ minOccurs='0'
+ maxOccurs='1'>
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element ref="sockets"
+ minOccurs='0'
+ maxOccurs='1'/>
+ <xs:element ref="cores"
+ minOccurs='0'
+ maxOccurs='1'/>
+ <xs:element ref="virtcpus"
+ minOccurs='0'
+ maxOccurs='1'/>
+ <xs:element ref="name"
+ minOccurs='0'
+ maxOccurs='1'/>
+ <xs:element ref="clockrate"
+ minOccurs='0'
+ maxOccurs='1'/>
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+ <xs:element name="registry"
+ minOccurs="1"
+ maxOccurs="1">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element name="service_tag"
+ minOccurs="0"
+ maxOccurs="1024">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element ref="instance_urn"
+ minOccurs='1'
+ maxOccurs='1'/>
+ <xs:element ref="product_name"
+ minOccurs='1'
+ maxOccurs='1'/>
+ <xs:element ref="product_version"
+ minOccurs='1'
+ maxOccurs='1'/>
+ <xs:element ref="product_urn"
+ minOccurs='1'
+ maxOccurs='1'/>
+ <xs:element ref="product_parent_urn"
+ minOccurs='1'
+ maxOccurs='1'/>
+ <xs:element ref="product_parent"
+ minOccurs='1'
+ maxOccurs='1'/>
+ <xs:element ref="product_defined_inst_id"
+ minOccurs='1'
+ maxOccurs='1'/>
+ <xs:element ref="product_vendor"
+ minOccurs='1'
+ maxOccurs='1'/>
+ <xs:element ref="platform_arch"
+ minOccurs='1'
+ maxOccurs='1'/>
+ <xs:element ref="timestamp"
+ minOccurs='1'
+ maxOccurs='1'/>
+ <xs:element ref="container"
+ minOccurs='1'
+ maxOccurs='1'/>
+ <xs:element ref="source"
+ minOccurs='1'
+ maxOccurs='1'/>
+ <xs:element ref="installer_uid"
+ minOccurs='1'
+ maxOccurs='1'/>
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+ </xs:sequence>
+ <xs:attribute name="urn"
+ type="xs:string"
+ use="required"/>
+ <xs:attribute name="version"
+ type="xs:string"
+ use="required"/>
+ </xs:complexType>
+ </xs:element>
+ </xs:sequence>
+ <xs:attribute name="version"
+ type="xs:string"
+ use="required"/>
+ </xs:complexType>
+</xs:element>
+
+ <!-- definition of simple elements -->
+ <xs:element name="hostname">
+ <xs:simpleType>
+ <xs:restriction base="xs:string">
+ <xs:minLength value="1"/>
+ <xs:maxLength value="255"/>
+ </xs:restriction>
+ </xs:simpleType>
+ </xs:element>
+
+ <xs:element name="hostId">
+ <xs:simpleType>
+ <xs:restriction base="xs:string">
+ <xs:minLength value="0"/>
+ <xs:maxLength value="16"/>
+ </xs:restriction>
+ </xs:simpleType>
+ </xs:element>
+
+ <xs:element name="osName">
+ <xs:simpleType>
+ <xs:restriction base="xs:string">
+ <xs:minLength value="1"/>
+ <xs:maxLength value="256"/>
+ </xs:restriction>
+ </xs:simpleType>
+ </xs:element>
+
+ <xs:element name="osVersion">
+ <xs:simpleType>
+ <xs:restriction base="xs:string">
+ <xs:minLength value="0"/>
+ <xs:maxLength value="50"/>
+ </xs:restriction>
+ </xs:simpleType>
+ </xs:element>
+
+ <xs:element name="osArchitecture">
+ <xs:simpleType>
+ <xs:restriction base="xs:string">
+ <xs:minLength value="0"/>
+ <xs:maxLength value="256"/>
+ </xs:restriction>
+ </xs:simpleType>
+ </xs:element>
+
+ <xs:element name="systemModel">
+ <xs:simpleType>
+ <xs:restriction base="xs:string">
+ <xs:minLength value="0"/>
+ <xs:maxLength value="50"/>
+ </xs:restriction>
+ </xs:simpleType>
+ </xs:element>
+
+ <xs:element name="systemManufacturer">
+ <xs:simpleType>
+ <xs:restriction base="xs:string">
+ <xs:minLength value="0"/>
+ <xs:maxLength value="50"/>
+ </xs:restriction>
+ </xs:simpleType>
+ </xs:element>
+
+ <xs:element name="cpuManufacturer">
+ <xs:simpleType>
+ <xs:restriction base="xs:string">
+ <xs:minLength value="0"/>
+ <xs:maxLength value="50"/>
+ </xs:restriction>
+ </xs:simpleType>
+ </xs:element>
+
+ <xs:element name="serialNumber">
+ <xs:simpleType>
+ <xs:restriction base="xs:string">
+ <xs:minLength value="0"/>
+ <xs:maxLength value="256"/>
+ </xs:restriction>
+ </xs:simpleType>
+ </xs:element>
+
+ <xs:element name="instance_urn">
+ <xs:simpleType>
+ <xs:restriction base="xs:string">
+ <xs:minLength value="1"/>
+ <xs:maxLength value="255"/>
+ </xs:restriction>
+ </xs:simpleType>
+ </xs:element>
+
+ <xs:element name="product_name">
+ <xs:simpleType>
+ <xs:restriction base="xs:string">
+ <xs:maxLength value="255"/>
+ </xs:restriction>
+ </xs:simpleType>
+ </xs:element>
+
+ <xs:element name="product_version">
+ <xs:simpleType>
+ <xs:restriction base="xs:string">
+ <xs:maxLength value="63"/>
+ </xs:restriction>
+ </xs:simpleType>
+ </xs:element>
+
+ <xs:element name="product_urn">
+ <xs:simpleType>
+ <xs:restriction base="xs:string">
+ <xs:minLength value="1"/>
+ <xs:maxLength value="255"/>
+ </xs:restriction>
+ </xs:simpleType>
+ </xs:element>
+
+ <xs:element name="product_parent_urn">
+ <xs:simpleType>
+ <xs:restriction base="xs:string">
+ <xs:minLength value="0"/>
+ <xs:maxLength value="255"/>
+ </xs:restriction>
+ </xs:simpleType>
+ </xs:element>
+
+ <xs:element name="product_parent">
+ <xs:simpleType>
+ <xs:restriction base="xs:string">
+ <xs:minLength value="0"/>
+ <xs:maxLength value="255"/>
+ </xs:restriction>
+ </xs:simpleType>
+ </xs:element>
+
+ <xs:element name="product_defined_inst_id">
+ <xs:simpleType>
+ <xs:restriction base="xs:string">
+ <xs:minLength value="0"/>
+ <xs:maxLength value="255"/>
+ </xs:restriction>
+ </xs:simpleType>
+ </xs:element>
+
+ <xs:element name="product_vendor">
+ <xs:simpleType>
+ <xs:restriction base="xs:string">
+ <xs:minLength value="0"/>
+ <xs:maxLength value="63"/>
+ </xs:restriction>
+ </xs:simpleType>
+ </xs:element>
+
+ <xs:element name="platform_arch">
+ <xs:simpleType>
+ <xs:restriction base="xs:string">
+ <xs:minLength value="0"/>
+ <xs:maxLength value="63"/>
+ </xs:restriction>
+ </xs:simpleType>
+ </xs:element>
+
+ <xs:element name="timestamp">
+ <xs:simpleType>
+ <xs:restriction base="xs:string">
+ <xs:maxLength value="24"/>
+ </xs:restriction>
+ </xs:simpleType>
+ </xs:element>
+
+ <xs:element name="container">
+ <xs:simpleType>
+ <xs:restriction base="xs:string">
+ <xs:maxLength value="63"/>
+ </xs:restriction>
+ </xs:simpleType>
+ </xs:element>
+
+ <xs:element name="source">
+ <xs:simpleType>
+ <xs:restriction base="xs:string">
+ <xs:maxLength value="63"/>
+ </xs:restriction>
+ </xs:simpleType>
+ </xs:element>
+
+ <xs:element name="installer_uid">
+ <xs:simpleType>
+ <xs:restriction base="xs:integer">
+ </xs:restriction>
+ </xs:simpleType>
+ </xs:element>
+
+ <xs:element name="physmem">
+ <xs:simpleType>
+ <xs:restriction base="xs:integer"/>
+ </xs:simpleType>
+ </xs:element>
+
+ <xs:element name="sockets">
+ <xs:simpleType>
+ <xs:restriction base="xs:integer"/>
+ </xs:simpleType>
+ </xs:element>
+
+ <xs:element name="cores">
+ <xs:simpleType>
+ <xs:restriction base="xs:integer"/>
+ </xs:simpleType>
+ </xs:element>
+
+ <xs:element name="virtcpus">
+ <xs:simpleType>
+ <xs:restriction base="xs:integer"/>
+ </xs:simpleType>
+ </xs:element>
+
+ <xs:element name="name">
+ <xs:simpleType>
+ <xs:restriction base="xs:string">
+ <xs:maxLength value="128"/>
+ </xs:restriction>
+ </xs:simpleType>
+ </xs:element>
+
+ <xs:element name="clockrate">
+ <xs:simpleType>
+ <xs:restriction base="xs:integer"/>
+ </xs:simpleType>
+ </xs:element>
+
+</xs:schema>
diff --git a/framework/inc/classes/fwktabwindow.hxx b/framework/inc/classes/fwktabwindow.hxx
index e9d7f0bd4b..84574282e8 100644
--- a/framework/inc/classes/fwktabwindow.hxx
+++ b/framework/inc/classes/fwktabwindow.hxx
@@ -125,6 +125,7 @@ public:
~FwkTabWindow();
void AddEventListener( const Link& rEventListener );
+ void RemoveEventListener( const Link& rEventListener );
FwkTabPage* AddTabPage( sal_Int32 nIndex, const css::uno::Sequence< css::beans::NamedValue >& rProperties );
void ActivatePage( sal_Int32 nIndex );
void RemovePage( sal_Int32 nIndex );
diff --git a/framework/inc/services/tabwindowservice.hxx b/framework/inc/services/tabwindowservice.hxx
index 198d84be0b..0614397e21 100644
--- a/framework/inc/services/tabwindowservice.hxx
+++ b/framework/inc/services/tabwindowservice.hxx
@@ -48,13 +48,13 @@
#include <macros/xinterface.hxx>
#include <macros/xtypeprovider.hxx>
#include <macros/xserviceinfo.hxx>
-#include <general.h>
+#include <general.h>
#include <stdtypes.h>
-
+
//_________________________________________________________________________________________________________________
// interface includes
//_________________________________________________________________________________________________________________
-
+
#include <com/sun/star/awt/XSimpleTabController.hpp>
#include <com/sun/star/awt/XWindow.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
@@ -62,7 +62,7 @@
//_________________________________________________________________________________________________________________
// other includes
//_________________________________________________________________________________________________________________
-
+
#include <cppuhelper/weak.hxx>
#include <vcl/window.hxx>
@@ -81,31 +81,31 @@ namespace framework{
//_________________________________________________________________________________________________________________
struct TTabPageInfo
-{
- public:
+{
+ public:
- TTabPageInfo()
- : m_nIndex ( -1 )
- , m_bCreated (sal_False)
- , m_pPage ( NULL )
- , m_lProperties ( )
- {}
-
- TTabPageInfo(::sal_Int32 nID)
- : m_nIndex ( nID )
- , m_bCreated (sal_False)
- , m_pPage ( NULL )
- , m_lProperties ( )
- {}
-
- public:
+ TTabPageInfo()
+ : m_nIndex ( -1 )
+ , m_bCreated (sal_False)
+ , m_pPage ( NULL )
+ , m_lProperties ( )
+ {}
+
+ TTabPageInfo(::sal_Int32 nID)
+ : m_nIndex ( nID )
+ , m_bCreated (sal_False)
+ , m_pPage ( NULL )
+ , m_lProperties ( )
+ {}
+
+ public:
- ::sal_Int32 m_nIndex;
+ ::sal_Int32 m_nIndex;
::sal_Bool m_bCreated;
FwkTabPage* m_pPage;
css::uno::Sequence< css::beans::NamedValue > m_lProperties;
-};
-
+};
+
typedef ::std::hash_map< ::sal_Int32 ,
TTabPageInfo ,
Int32HashCode ,
@@ -118,10 +118,11 @@ typedef ::std::hash_map< ::sal_Int32 ,
class TabWindowService : public css::lang::XTypeProvider
, public css::lang::XServiceInfo
, public css::awt::XSimpleTabController
+ , public css::lang::XComponent
, public ThreadHelpBase
, public TransactionBase
- , public PropertySetHelper
- , public ::cppu::OWeakObject
+ , public PropertySetHelper
+ , public ::cppu::OWeakObject
{
//-------------------------------------------------------------------------------------------------------------
// public methods
@@ -132,7 +133,7 @@ class TabWindowService : public css::lang::XTypeProvider
//---------------------------------------------------------------------------------------------------------
// constructor / destructor
//---------------------------------------------------------------------------------------------------------
-
+
TabWindowService( const css::uno::Reference< css::lang::XMultiServiceFactory >& xFactory );
virtual ~TabWindowService();
@@ -186,8 +187,8 @@ class TabWindowService : public css::lang::XTypeProvider
DECL_DLLPRIVATE_LINK( EventListener, VclSimpleEvent * );
- void impl_checkTabIndex (::sal_Int32 nID) throw (css::lang::IndexOutOfBoundsException);
- TTabPageInfoHash::iterator impl_getTabPageInfo(::sal_Int32 nID) throw (css::lang::IndexOutOfBoundsException);
+ void impl_checkTabIndex (::sal_Int32 nID) throw (css::lang::IndexOutOfBoundsException);
+ TTabPageInfoHash::iterator impl_getTabPageInfo(::sal_Int32 nID) throw (css::lang::IndexOutOfBoundsException);
FwkTabWindow* mem_TabWin ();
/*
::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper();
@@ -203,26 +204,26 @@ class TabWindowService : public css::lang::XTypeProvider
private:
/// reference to factory, which has created this instance
- css::uno::Reference< css::lang::XMultiServiceFactory > m_xFactory;
-
+ css::uno::Reference< css::lang::XMultiServiceFactory > m_xFactory;
+
/// the tab window as XWindow ( to hold window* alive !)
- css::uno::Reference< css::awt::XWindow > m_xTabWin;
-
- /// the VCL tab window
- FwkTabWindow* m_pTabWin;
-
- /// container of inserted tab pages
- TTabPageInfoHash m_lTabPageInfos;
-
+ css::uno::Reference< css::awt::XWindow > m_xTabWin;
+
+ /// the VCL tab window
+ FwkTabWindow* m_pTabWin;
+
+ /// container of inserted tab pages
+ TTabPageInfoHash m_lTabPageInfos;
+
/// container of the added TabListener
::cppu::OMultiTypeInterfaceContainerHelper m_lListener;
-
+
/// counter of the tabpage indexes
- ::sal_Int32 m_nPageIndexCounter;
-
+ ::sal_Int32 m_nPageIndexCounter;
+
/// index of the current active page
::sal_Int32 m_nCurrentPageIndex;
-
+
/// title of the tabcontrolled window
::rtl::OUString m_sTitle;
diff --git a/framework/source/classes/fwktabwindow.cxx b/framework/source/classes/fwktabwindow.cxx
index 8ffa00a492..af8319c193 100644
--- a/framework/source/classes/fwktabwindow.cxx
+++ b/framework/source/classes/fwktabwindow.cxx
@@ -65,7 +65,6 @@ namespace framework
{
// class FwkTabControl ---------------------------------------------------
-
FwkTabControl::FwkTabControl( Window* pParent, const ResId& rResId ) :
TabControl( pParent, rResId )
@@ -336,6 +335,11 @@ void FwkTabWindow::AddEventListener( const Link& rEventListener )
m_aTabCtrl.AddEventListener( rEventListener );
}
+void FwkTabWindow::RemoveEventListener( const Link& rEventListener )
+{
+ m_aTabCtrl.RemoveEventListener( rEventListener );
+}
+
// -----------------------------------------------------------------------
FwkTabPage* FwkTabWindow::AddTabPage( sal_Int32 nIndex, const uno::Sequence< beans::NamedValue >& rProperties )
diff --git a/framework/source/services/tabwindowservice.cxx b/framework/source/services/tabwindowservice.cxx
index 6c78600aa9..71136a9ac4 100644
--- a/framework/source/services/tabwindowservice.cxx
+++ b/framework/source/services/tabwindowservice.cxx
@@ -75,18 +75,20 @@ namespace framework{
// css::uno::XInterface, XTypeProvider, XServiceInfo
//*****************************************************************************************************************
-DEFINE_XINTERFACE_5 ( TabWindowService ,
+DEFINE_XINTERFACE_6 ( TabWindowService ,
OWeakObject ,
DIRECT_INTERFACE(css::lang::XTypeProvider ),
DIRECT_INTERFACE(css::lang::XServiceInfo ),
+ DIRECT_INTERFACE(css::lang::XComponent),
DIRECT_INTERFACE(css::awt::XSimpleTabController),
DIRECT_INTERFACE(css::beans::XPropertySet ),
DIRECT_INTERFACE(css::beans::XPropertySetInfo )
)
-DEFINE_XTYPEPROVIDER_5 ( TabWindowService ,
+DEFINE_XTYPEPROVIDER_6 ( TabWindowService ,
css::lang::XTypeProvider ,
css::lang::XServiceInfo ,
+ css::lang::XComponent ,
css::awt::XSimpleTabController ,
css::beans::XPropertySet ,
css::beans::XPropertySetInfo
@@ -100,7 +102,7 @@ DEFINE_XSERVICEINFO_MULTISERVICE ( TabWindowService ,
DEFINE_INIT_SERVICE ( TabWindowService,
{
- impl_initializePropInfo();
+ impl_initializePropInfo();
m_aTransactionManager.setWorkingMode( E_WORK );
}
)
@@ -141,7 +143,12 @@ TabWindowService::TabWindowService( const css::uno::Reference< css::lang::XMulti
// destructor
//*****************************************************************************************************************
TabWindowService::~TabWindowService()
-{
+{
+ // SAFE->
+ ResetableGuard aGuard(m_aLock);
+
+ if (m_pTabWin)
+ m_pTabWin->RemoveEventListener( LINK( this, TabWindowService, EventListener ) );
}
//*****************************************************************************************************************
@@ -286,8 +293,11 @@ void SAL_CALL TabWindowService::dispose()
m_lListener.disposeAndClear (aEvent);
+ if (m_pTabWin)
+ m_pTabWin->RemoveEventListener( LINK( this, TabWindowService, EventListener ) );
+
m_pTabWin = NULL;
- m_xTabWin.clear ();
+ m_xTabWin.clear();
}
//*****************************************************************************************************************
@@ -357,6 +367,7 @@ css::uno::Any SAL_CALL TabWindowService::impl_getPropertyValue(const ::rtl::OUSt
//*****************************************************************************************************************
IMPL_LINK( TabWindowService, EventListener, VclSimpleEvent*, pEvent )
{
+
if ( !pEvent && !pEvent->ISA(VclWindowEvent))
return 0;
@@ -369,6 +380,11 @@ IMPL_LINK( TabWindowService, EventListener, VclSimpleEvent*, pEvent )
if (nEventId == VCLEVENT_OBJECT_DYING)
{
m_lListener.disposeAndClear (aEvent);
+
+ m_pTabWin->RemoveEventListener( LINK( this, TabWindowService, EventListener ) );
+ m_pTabWin = NULL;
+ m_xTabWin.clear();
+
return 0;
}
@@ -454,9 +470,9 @@ FwkTabWindow* TabWindowService::mem_TabWin ()
FwkTabWindow* pWin = NULL;
if ( ! m_xTabWin.is ())
- {
- Window* pFakeParent = dynamic_cast< Window* >(Application::GetDefaultDevice ());
-
+ {
+ Window* pFakeParent = dynamic_cast< Window* >(Application::GetDefaultDevice ());
+
m_pTabWin = new FwkTabWindow (pFakeParent);
m_xTabWin = VCLUnoHelper::GetInterface (m_pTabWin);