1 /*
   2  * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.servicetag;
  27 
  28 import java.io.IOException;
  29 import java.util.Set;
  30 
  31 /**
  32  * Utility class to obtain the service tag for the Solaris Operating System.
  33  */
  34 class SolarisServiceTag {
  35     private final static String[] SolarisProductURNs = new String[] {
  36         "urn:uuid:a7a38948-2bd5-11d6-98ce-9d3ac1c0cfd7", /* Solaris 8 */
  37         "urn:uuid:4f82caac-36f3-11d6-866b-85f428ef944e", /* Solaris 9 */
  38         "urn:uuid:a19de03b-48bc-11d9-9607-080020a9ed93", /* Solaris 9 sparc */
  39         "urn:uuid:4c35c45b-4955-11d9-9607-080020a9ed93", /* Solaris 9 x86 */
  40         "urn:uuid:5005588c-36f3-11d6-9cec-fc96f718e113", /* Solaris 10 */
  41         "urn:uuid:6df19e63-7ef5-11db-a4bd-080020a9ed93"  /* Solaris 11 */
  42     };
  43 
  44     /**
  45      * Returns null if not found.
  46      *
  47      * There is only one service tag for the operating system.
  48      */
  49     static ServiceTag getServiceTag() throws IOException {
  50         if (Registry.isSupported()) {
  51             Registry streg = Registry.getSystemRegistry();
  52             for (String parentURN : SolarisProductURNs) {
  53                 Set<ServiceTag> instances = streg.findServiceTags(parentURN);
  54                 for (ServiceTag st : instances) {
  55                     // there should have only one service tag for the OS
  56                     return st;
  57                 }
  58             }
  59         }
  60         return null;
  61     }
  62 }