From 3ebd9e25c3e77c91f123cad3dabfe3d42bdee58b Mon Sep 17 00:00:00 2001 From: Jens-Heiner Rechtien Date: Fri, 19 Mar 2010 17:41:38 +0100 Subject: changefileheader3: #i110248#: change source file copyright notice from Sun Microsystems to Oracle; remove CVS style keywords (RCSfile, Revision) --- .../com/sun/star/registration/Registration.java | 7 +- .../com/sun/star/registration/makefile.mk | 8 +- .../com/sun/star/servicetag/BrowserSupport.java | 5 +- .../com/sun/star/servicetag/Installer.java | 5 +- .../star/servicetag/LinuxSystemEnvironment.java | 5 +- .../com/sun/star/servicetag/RegistrationData.java | 1062 ++++++++++---------- .../sun/star/servicetag/RegistrationDocument.java | 880 ++++++++-------- .../com/sun/star/servicetag/Registry.java | 5 +- .../com/sun/star/servicetag/ServiceTag.java | 5 +- .../com/sun/star/servicetag/SolarisServiceTag.java | 5 +- .../star/servicetag/SolarisSystemEnvironment.java | 5 +- .../com/sun/star/servicetag/SunConnection.java | 5 +- .../sun/star/servicetag/SysnetRegistryHelper.java | 5 +- .../com/sun/star/servicetag/SystemEnvironment.java | 5 +- .../servicetag/UnauthorizedAccessException.java | 5 +- .../registration/com/sun/star/servicetag/Util.java | 5 +- .../star/servicetag/WindowsSystemEnvironment.java | 5 +- .../com/sun/star/servicetag/makefile.mk | 8 +- .../servicetag/resources/product_registration.xsd | 732 +++++++------- 19 files changed, 1356 insertions(+), 1406 deletions(-) (limited to 'desktop/source/registration/com/sun/star') diff --git a/desktop/source/registration/com/sun/star/registration/Registration.java b/desktop/source/registration/com/sun/star/registration/Registration.java index 3d396e3b8d..a30f12e623 100644 --- a/desktop/source/registration/com/sun/star/registration/Registration.java +++ b/desktop/source/registration/com/sun/star/registration/Registration.java @@ -1,13 +1,10 @@ /************************************************************************* * * 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 + * Copyright 2000, 2010 Oracle and/or its affiliates. * - * $RCSfile: Registration.java,v $ - * $Revision: 1.3 $ + * OpenOffice.org - a multi-platform office productivity suite * * This file is part of OpenOffice.org. * diff --git a/desktop/source/registration/com/sun/star/registration/makefile.mk b/desktop/source/registration/com/sun/star/registration/makefile.mk index f20eaf71ad..68bcfce3fc 100644 --- a/desktop/source/registration/com/sun/star/registration/makefile.mk +++ b/desktop/source/registration/com/sun/star/registration/makefile.mk @@ -1,14 +1,10 @@ #************************************************************************* # # 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: makefile.mk,v $ +# Copyright 2000, 2010 Oracle and/or its affiliates. # -# $Revision: 1.2 $ +# OpenOffice.org - a multi-platform office productivity suite # # This file is part of OpenOffice.org. # diff --git a/desktop/source/registration/com/sun/star/servicetag/BrowserSupport.java b/desktop/source/registration/com/sun/star/servicetag/BrowserSupport.java index b0e944a0f8..0f436cbd41 100644 --- a/desktop/source/registration/com/sun/star/servicetag/BrowserSupport.java +++ b/desktop/source/registration/com/sun/star/servicetag/BrowserSupport.java @@ -2,13 +2,10 @@ * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * - * Copyright 2008 by Sun Microsystems, Inc. + * Copyright 2000, 2010 Oracle and/or its affiliates. * * OpenOffice.org - a multi-platform office productivity suite * - * $RCSfile: Registration.java,v $ - * $Revision: 1.3 $ - * * This file is part of OpenOffice.org. * * OpenOffice.org is free software: you can redistribute it and/or modify diff --git a/desktop/source/registration/com/sun/star/servicetag/Installer.java b/desktop/source/registration/com/sun/star/servicetag/Installer.java index f3b0b9c3c3..07768a3cb3 100644 --- a/desktop/source/registration/com/sun/star/servicetag/Installer.java +++ b/desktop/source/registration/com/sun/star/servicetag/Installer.java @@ -2,13 +2,10 @@ * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * - * Copyright 2008 by Sun Microsystems, Inc. + * Copyright 2000, 2010 Oracle and/or its affiliates. * * OpenOffice.org - a multi-platform office productivity suite * - * $RCSfile: Registration.java,v $ - * $Revision: 1.3 $ - * * This file is part of OpenOffice.org. * * OpenOffice.org is free software: you can redistribute it and/or modify diff --git a/desktop/source/registration/com/sun/star/servicetag/LinuxSystemEnvironment.java b/desktop/source/registration/com/sun/star/servicetag/LinuxSystemEnvironment.java index a58072d363..9bcee251bc 100644 --- a/desktop/source/registration/com/sun/star/servicetag/LinuxSystemEnvironment.java +++ b/desktop/source/registration/com/sun/star/servicetag/LinuxSystemEnvironment.java @@ -2,13 +2,10 @@ * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * - * Copyright 2008 by Sun Microsystems, Inc. + * Copyright 2000, 2010 Oracle and/or its affiliates. * * OpenOffice.org - a multi-platform office productivity suite * - * $RCSfile: Registration.java,v $ - * $Revision: 1.3 $ - * * This file is part of OpenOffice.org. * * OpenOffice.org is free software: you can redistribute it and/or modify diff --git a/desktop/source/registration/com/sun/star/servicetag/RegistrationData.java b/desktop/source/registration/com/sun/star/servicetag/RegistrationData.java index c58d83a33d..9323e5de7e 100644 --- a/desktop/source/registration/com/sun/star/servicetag/RegistrationData.java +++ b/desktop/source/registration/com/sun/star/servicetag/RegistrationData.java @@ -1,531 +1,531 @@ - -/* - * 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. - * - * It also has an environment map with - * the following elements: - *
- * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - *
hostnameHostname of the systeme.g. woody
hostIdHost ID of the systeme.g. 83abc1ab
osNameOperating system name e.g. SunOS
osVersionOperating system version e.g. 5.10
osArchitectureOperating system architecture e.g. sparc
systemModelSystem model e.g. SUNW,Sun-Fire-V440
systemManufacturerSystem manufacturer e.g. Sun Microsystems
cpuManufacturerCPU manufacturer e.g. Sun Microsystems
serialNumberSystem serial number e.g. BEL078932
physmemPhysical memory for the system (in MB) e.g. 4096
- *
- * The hostname and osName element must have a non-empty value. - * If an element is not available on a system and their value will be - * empty. - *

- * - * Registration XML Schema - *

- * A {@code RegistrationData} object can be {@link #loadFromXML loaded} from - * and {@link #storeToXML stored} into an XML file in the format described - * by the - * - * registration data schema. The registration data schema is defined by the - * Service Tags Technology. - *

- * Typically the registration data is constructed at installation time - * and stored in an XML file for later service tag lookup or registration. - * - *

- * Example Usage - *

- * The examples below show how the {@code RegistrationData} can be - * used for product registration. - * Exception handling is not shown in these examples for clarity. - *

    - *
  1. 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. - *
    - *
    - *   // 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); 
    - * 
    - *
  2. - *
  3. 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 Registration Relay Service. - *

    - * There are several registration services for Sun Connection. For example, - * the - * Registration Relay Service 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. - *

    - *

    - *   // 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();
    - * 
    - *
  4. - *
  5. This example shows how to store the registration data in an XML file. - * for later service tag lookup or registration. - *
    - *
    - *   BufferedOutputStream out = new BufferedOutputStream(
    - *       new FileOutputStream(""<JAVA_HOME>/lib/servicetag/registration.xml"));
    - *   registration.storeToXML(out);
    - *   out.close();
    - * 
    - *
  6. - *
  7. 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. - *
    - *
    - *   if (Registry.isSupported()) {
    - *       Set<ServiceTag> svctags = registration.getServiceTags();
    - *       for (ServiceTag st : svctags) {
    - *           Registry.getSystemRegistry().addServiceTag(st);
    - *       }
    - *   }
    - * 
    - *
  8. - *
- * - * @see Sun Connection Inventory Channel - */ -public class RegistrationData { - private final Map environment; - private final Map cpuInfo; - private final Map 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: - *
- * hostname, osName, osVersion and - * osArchitecture - *
- * 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(); - } - - private Map initEnvironment(SystemEnvironment sysEnv) { - Map map = new LinkedHashMap(); - 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 initCpuInfo(SystemEnvironment sysEnv) { - Map map = new LinkedHashMap(); - 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: - * urn:st:<32-char {@link java.util.UUID uuid}> - * - * @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 keys - * 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 getEnvironmentMap() { - return new LinkedHashMap(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 getCpuInfoMap() { - return new LinkedHashMap(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 getServiceTags() { - return new HashSet(svcTagMap.values()); - } - - /** - * Adds a service tag to this registration data. - * If the given service tag has an empty instance_urn, - * 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 - * instance_urn} 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 instance_urn in this registration - * data. - * - * @param instanceURN the instance_urn of the service tag - * @return the {@code ServiceTag} object of the given instance_urn - * 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 instance_urn from this - * registration data. - * - * @param instanceURN the instance_urn 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 product_defined_instance_id in the service tag - * of the given instance_urn in this registration data. - * - * @param instanceURN the instance_urn of the service tag to be updated. - * @param productDefinedInstanceID the value of the - * product_defined_instance_id 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 - * registration data schema. - * 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 - * registration data schema 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. + * + * It also has an environment map with + * the following elements: + *
+ * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
hostnameHostname of the systeme.g. woody
hostIdHost ID of the systeme.g. 83abc1ab
osNameOperating system name e.g. SunOS
osVersionOperating system version e.g. 5.10
osArchitectureOperating system architecture e.g. sparc
systemModelSystem model e.g. SUNW,Sun-Fire-V440
systemManufacturerSystem manufacturer e.g. Sun Microsystems
cpuManufacturerCPU manufacturer e.g. Sun Microsystems
serialNumberSystem serial number e.g. BEL078932
physmemPhysical memory for the system (in MB) e.g. 4096
+ *
+ * The hostname and osName element must have a non-empty value. + * If an element is not available on a system and their value will be + * empty. + *

+ * + * Registration XML Schema + *

+ * A {@code RegistrationData} object can be {@link #loadFromXML loaded} from + * and {@link #storeToXML stored} into an XML file in the format described + * by the + * + * registration data schema. The registration data schema is defined by the + * Service Tags Technology. + *

+ * Typically the registration data is constructed at installation time + * and stored in an XML file for later service tag lookup or registration. + * + *

+ * Example Usage + *

+ * The examples below show how the {@code RegistrationData} can be + * used for product registration. + * Exception handling is not shown in these examples for clarity. + *

    + *
  1. 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. + *
    + *
    + *   // 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); 
    + * 
    + *
  2. + *
  3. 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 Registration Relay Service. + *

    + * There are several registration services for Sun Connection. For example, + * the + * Registration Relay Service 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. + *

    + *

    + *   // 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();
    + * 
    + *
  4. + *
  5. This example shows how to store the registration data in an XML file. + * for later service tag lookup or registration. + *
    + *
    + *   BufferedOutputStream out = new BufferedOutputStream(
    + *       new FileOutputStream(""<JAVA_HOME>/lib/servicetag/registration.xml"));
    + *   registration.storeToXML(out);
    + *   out.close();
    + * 
    + *
  6. + *
  7. 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. + *
    + *
    + *   if (Registry.isSupported()) {
    + *       Set<ServiceTag> svctags = registration.getServiceTags();
    + *       for (ServiceTag st : svctags) {
    + *           Registry.getSystemRegistry().addServiceTag(st);
    + *       }
    + *   }
    + * 
    + *
  8. + *
+ * + * @see Sun Connection Inventory Channel + */ +public class RegistrationData { + private final Map environment; + private final Map cpuInfo; + private final Map 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: + *
+ * hostname, osName, osVersion and + * osArchitecture + *
+ * 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(); + } + + private Map initEnvironment(SystemEnvironment sysEnv) { + Map map = new LinkedHashMap(); + 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 initCpuInfo(SystemEnvironment sysEnv) { + Map map = new LinkedHashMap(); + 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: + * urn:st:<32-char {@link java.util.UUID uuid}> + * + * @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 keys + * 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 getEnvironmentMap() { + return new LinkedHashMap(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 getCpuInfoMap() { + return new LinkedHashMap(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 getServiceTags() { + return new HashSet(svcTagMap.values()); + } + + /** + * Adds a service tag to this registration data. + * If the given service tag has an empty instance_urn, + * 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 + * instance_urn} 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 instance_urn in this registration + * data. + * + * @param instanceURN the instance_urn of the service tag + * @return the {@code ServiceTag} object of the given instance_urn + * 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 instance_urn from this + * registration data. + * + * @param instanceURN the instance_urn 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 product_defined_instance_id in the service tag + * of the given instance_urn in this registration data. + * + * @param instanceURN the instance_urn of the service tag to be updated. + * @param productDefinedInstanceID the value of the + * product_defined_instance_id 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 + * registration data schema. + * 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 + * registration data schema 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 93a1f25a6c..4bfa1aa16a 100644 --- a/desktop/source/registration/com/sun/star/servicetag/RegistrationDocument.java +++ b/desktop/source/registration/com/sun/star/servicetag/RegistrationDocument.java @@ -1,440 +1,440 @@ - -/* - * 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 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 envMap, - Map cpuInfoMap) { - Element root = getRegistrationDataRoot(document); - - Element env = document.createElement(ST_NODE_ENVIRONMENT); - root.appendChild(env); - Set> keys = envMap.entrySet(); - for (Map.Entry 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 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; - } -} + +/* + * 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 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 envMap, + Map cpuInfoMap) { + Element root = getRegistrationDataRoot(document); + + Element env = document.createElement(ST_NODE_ENVIRONMENT); + root.appendChild(env); + Set> keys = envMap.entrySet(); + for (Map.Entry 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 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 51c90b9e94..ca093af81d 100644 --- a/desktop/source/registration/com/sun/star/servicetag/Registry.java +++ b/desktop/source/registration/com/sun/star/servicetag/Registry.java @@ -2,13 +2,10 @@ * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * - * Copyright 2008 by Sun Microsystems, Inc. + * Copyright 2000, 2010 Oracle and/or its affiliates. * * OpenOffice.org - a multi-platform office productivity suite * - * $RCSfile: Registration.java,v $ - * $Revision: 1.3 $ - * * This file is part of OpenOffice.org. * * OpenOffice.org is free software: you can redistribute it and/or modify diff --git a/desktop/source/registration/com/sun/star/servicetag/ServiceTag.java b/desktop/source/registration/com/sun/star/servicetag/ServiceTag.java index cfaa04baca..734f903b65 100644 --- a/desktop/source/registration/com/sun/star/servicetag/ServiceTag.java +++ b/desktop/source/registration/com/sun/star/servicetag/ServiceTag.java @@ -2,13 +2,10 @@ * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * - * Copyright 2008 by Sun Microsystems, Inc. + * Copyright 2000, 2010 Oracle and/or its affiliates. * * OpenOffice.org - a multi-platform office productivity suite * - * $RCSfile: Registration.java,v $ - * $Revision: 1.3 $ - * * This file is part of OpenOffice.org. * * OpenOffice.org is free software: you can redistribute it and/or modify diff --git a/desktop/source/registration/com/sun/star/servicetag/SolarisServiceTag.java b/desktop/source/registration/com/sun/star/servicetag/SolarisServiceTag.java index 1ce6790094..48b037e3b5 100644 --- a/desktop/source/registration/com/sun/star/servicetag/SolarisServiceTag.java +++ b/desktop/source/registration/com/sun/star/servicetag/SolarisServiceTag.java @@ -2,13 +2,10 @@ * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * - * Copyright 2008 by Sun Microsystems, Inc. + * Copyright 2000, 2010 Oracle and/or its affiliates. * * OpenOffice.org - a multi-platform office productivity suite * - * $RCSfile: Registration.java,v $ - * $Revision: 1.3 $ - * * This file is part of OpenOffice.org. * * OpenOffice.org is free software: you can redistribute it and/or modify diff --git a/desktop/source/registration/com/sun/star/servicetag/SolarisSystemEnvironment.java b/desktop/source/registration/com/sun/star/servicetag/SolarisSystemEnvironment.java index 01420fba8a..a6948d9b13 100644 --- a/desktop/source/registration/com/sun/star/servicetag/SolarisSystemEnvironment.java +++ b/desktop/source/registration/com/sun/star/servicetag/SolarisSystemEnvironment.java @@ -2,13 +2,10 @@ * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * - * Copyright 2008 by Sun Microsystems, Inc. + * Copyright 2000, 2010 Oracle and/or its affiliates. * * OpenOffice.org - a multi-platform office productivity suite * - * $RCSfile: Registration.java,v $ - * $Revision: 1.3 $ - * * This file is part of OpenOffice.org. * * OpenOffice.org is free software: you can redistribute it and/or modify diff --git a/desktop/source/registration/com/sun/star/servicetag/SunConnection.java b/desktop/source/registration/com/sun/star/servicetag/SunConnection.java index 5bc3396e1b..558cf9b0b4 100644 --- a/desktop/source/registration/com/sun/star/servicetag/SunConnection.java +++ b/desktop/source/registration/com/sun/star/servicetag/SunConnection.java @@ -2,13 +2,10 @@ * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * - * Copyright 2008 by Sun Microsystems, Inc. + * Copyright 2000, 2010 Oracle and/or its affiliates. * * OpenOffice.org - a multi-platform office productivity suite * - * $RCSfile: Registration.java,v $ - * $Revision: 1.3 $ - * * This file is part of OpenOffice.org. * * OpenOffice.org is free software: you can redistribute it and/or modify diff --git a/desktop/source/registration/com/sun/star/servicetag/SysnetRegistryHelper.java b/desktop/source/registration/com/sun/star/servicetag/SysnetRegistryHelper.java index 2508565b51..ed86175085 100644 --- a/desktop/source/registration/com/sun/star/servicetag/SysnetRegistryHelper.java +++ b/desktop/source/registration/com/sun/star/servicetag/SysnetRegistryHelper.java @@ -2,13 +2,10 @@ * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * - * Copyright 2008 by Sun Microsystems, Inc. + * Copyright 2000, 2010 Oracle and/or its affiliates. * * OpenOffice.org - a multi-platform office productivity suite * - * $RCSfile: Registration.java,v $ - * $Revision: 1.3 $ - * * This file is part of OpenOffice.org. * * OpenOffice.org is free software: you can redistribute it and/or modify diff --git a/desktop/source/registration/com/sun/star/servicetag/SystemEnvironment.java b/desktop/source/registration/com/sun/star/servicetag/SystemEnvironment.java index d218650ee5..973350732a 100644 --- a/desktop/source/registration/com/sun/star/servicetag/SystemEnvironment.java +++ b/desktop/source/registration/com/sun/star/servicetag/SystemEnvironment.java @@ -2,13 +2,10 @@ * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * - * Copyright 2008 by Sun Microsystems, Inc. + * Copyright 2000, 2010 Oracle and/or its affiliates. * * OpenOffice.org - a multi-platform office productivity suite * - * $RCSfile: Registration.java,v $ - * $Revision: 1.3 $ - * * This file is part of OpenOffice.org. * * OpenOffice.org is free software: you can redistribute it and/or modify diff --git a/desktop/source/registration/com/sun/star/servicetag/UnauthorizedAccessException.java b/desktop/source/registration/com/sun/star/servicetag/UnauthorizedAccessException.java index fd1e26643a..e26304fc1b 100644 --- a/desktop/source/registration/com/sun/star/servicetag/UnauthorizedAccessException.java +++ b/desktop/source/registration/com/sun/star/servicetag/UnauthorizedAccessException.java @@ -2,13 +2,10 @@ * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * - * Copyright 2008 by Sun Microsystems, Inc. + * Copyright 2000, 2010 Oracle and/or its affiliates. * * OpenOffice.org - a multi-platform office productivity suite * - * $RCSfile: Registration.java,v $ - * $Revision: 1.3 $ - * * This file is part of OpenOffice.org. * * OpenOffice.org is free software: you can redistribute it and/or modify diff --git a/desktop/source/registration/com/sun/star/servicetag/Util.java b/desktop/source/registration/com/sun/star/servicetag/Util.java index 1981a2ff6f..4250182484 100644 --- a/desktop/source/registration/com/sun/star/servicetag/Util.java +++ b/desktop/source/registration/com/sun/star/servicetag/Util.java @@ -2,13 +2,10 @@ * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * - * Copyright 2008 by Sun Microsystems, Inc. + * Copyright 2000, 2010 Oracle and/or its affiliates. * * OpenOffice.org - a multi-platform office productivity suite * - * $RCSfile: Registration.java,v $ - * $Revision: 1.3 $ - * * This file is part of OpenOffice.org. * * OpenOffice.org is free software: you can redistribute it and/or modify diff --git a/desktop/source/registration/com/sun/star/servicetag/WindowsSystemEnvironment.java b/desktop/source/registration/com/sun/star/servicetag/WindowsSystemEnvironment.java index 8f6b79dafa..ed7e14607f 100644 --- a/desktop/source/registration/com/sun/star/servicetag/WindowsSystemEnvironment.java +++ b/desktop/source/registration/com/sun/star/servicetag/WindowsSystemEnvironment.java @@ -2,13 +2,10 @@ * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * - * Copyright 2008 by Sun Microsystems, Inc. + * Copyright 2000, 2010 Oracle and/or its affiliates. * * OpenOffice.org - a multi-platform office productivity suite * - * $RCSfile: Registration.java,v $ - * $Revision: 1.3 $ - * * This file is part of OpenOffice.org. * * OpenOffice.org is free software: you can redistribute it and/or modify diff --git a/desktop/source/registration/com/sun/star/servicetag/makefile.mk b/desktop/source/registration/com/sun/star/servicetag/makefile.mk index d4ebbed2f0..ba1c616674 100644 --- a/desktop/source/registration/com/sun/star/servicetag/makefile.mk +++ b/desktop/source/registration/com/sun/star/servicetag/makefile.mk @@ -1,14 +1,10 @@ #************************************************************************* # # 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: makefile.mk,v $ +# Copyright 2000, 2010 Oracle and/or its affiliates. # -# $Revision: 1.2 $ +# OpenOffice.org - a multi-platform office productivity suite # # This file is part of OpenOffice.org. # 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 bb48ba9084..6681a563a0 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,366 +1,366 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- cgit v1.2.3