usr/src/java/smf-old/org/opensolaris/os/scf/common/FMRI.java
author Dan Labrecque <dan.labrecque@oracle.com>
Thu, 19 Jan 2012 16:01:30 -0500
changeset 793 0a5a7daf579b
parent 323 usr/src/java/scf/common/org/opensolaris/os/scf/common/FMRI.java@497a785649eb
permissions -rw-r--r--
7130765 - Move old SMF module to VP core package
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
     1
/*
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
     2
 * CDDL HEADER START
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
     3
 *
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
     4
 * The contents of this file are subject to the terms of the
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
     5
 * Common Development and Distribution License (the "License").
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
     6
 * You may not use this file except in compliance with the License.
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
     7
 *
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
     8
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
     9
 * or http://www.opensolaris.org/os/licensing.
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    10
 * See the License for the specific language governing permissions
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    11
 * and limitations under the License.
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    12
 *
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    13
 * When distributing Covered Code, include this CDDL HEADER in each
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    14
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    15
 * If applicable, add the following below this CDDL HEADER, with the
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    16
 * fields enclosed by brackets "[]" replaced with your own identifying
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    17
 * information: Portions Copyright [yyyy] [name of copyright owner]
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    18
 *
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    19
 * CDDL HEADER END
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    20
 */
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    21
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    22
/*
793
0a5a7daf579b 7130765 - Move old SMF module to VP core package
Dan Labrecque <dan.labrecque@oracle.com>
parents: 323
diff changeset
    23
 * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved.
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    24
 */
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    25
310
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
    26
package org.opensolaris.os.scf.common;
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    27
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    28
import java.net.URI;
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    29
import java.net.URISyntaxException;
310
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
    30
import java.beans.ConstructorProperties;
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
    31
import java.util.Map;
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
    32
import java.util.EnumMap;
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
    33
import javax.management.openmbean.*;
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    34
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    35
/**
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    36
 * A basic FMRI class.  Probably should be named "SmfFMRI", as
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    37
 * legacy-run services aren't an SCF concept.
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    38
 */
310
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
    39
public class FMRI implements Comparable<FMRI>, CompositeDataView
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    40
{
310
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
    41
	/*
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
    42
	 * Static data
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
    43
	 */
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
    44
	public static final String SCF_SCOPE_LOCAL = "localhost";
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
    45
	private static final String FORMAT =
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
    46
	    "([A-Za-z][_A-Za-z0-9.-]*,)?[_A-Za-z0-9-]*";
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
    47
	private static final Map<FMRIScheme, String> scheme_strings =
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
    48
	    new EnumMap<FMRIScheme, String>(FMRIScheme.class);
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    49
310
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
    50
	static {
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
    51
		scheme_strings.put(FMRIScheme.FILE, "file");
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
    52
		scheme_strings.put(FMRIScheme.LEGACY, "lrc");
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
    53
		scheme_strings.put(FMRIScheme.SERVICE, "svc");
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    54
	}
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    55
310
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
    56
	/*
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
    57
	 * FMRI components
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    58
	 */
310
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
    59
	private FMRIScheme scheme_;
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
    60
	private String scope_ = null;
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
    61
	private String service_ = null;
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
    62
	private String instance_ = null;
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
    63
	private String pg_ = null;
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
    64
	private String property_ = null;
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
    65
	private String name_ = null;
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    66
310
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
    67
	/*
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
    68
	 * Derivative information
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
    69
	 */
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
    70
	private FMRIType svctype_;
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
    71
	private String canonicalStr_;
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    72
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    73
	/**
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    74
	 * Creates an FMRI from a URI.
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    75
	 */
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    76
	public FMRI(URI uri) throws URISyntaxException
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    77
	{
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    78
		if (!uri.isAbsolute() || uri.isOpaque())
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    79
			throw (new URISyntaxException(uri.toString(),
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    80
			    "Bad FMRI"));
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    81
310
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
    82
		String scheme = uri.getScheme();
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    83
		scope_ = uri.getAuthority();
310
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
    84
		if (scope_ == null || scope_.isEmpty() ||
314
8decc90a3ec6 9416 more fully featured FMRI type (fix lint)
David Powell <David.Powell@sun.com>
parents: 310
diff changeset
    85
		    scope_.equals(SCF_SCOPE_LOCAL))
310
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
    86
			scope_ = null;
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
    87
		canonicalStr_ = new URI(uri.getScheme(), scope_, uri.getPath(),
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
    88
		    null, null).toString();
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    89
310
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
    90
		if (scheme.equals("svc")) {
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
    91
			scheme_ = FMRIScheme.SERVICE;
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
    92
			svctype_ = FMRIType.SCOPE;
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    93
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    94
			String[] top = uri.getPath().split("/:properties/", 2);
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    95
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    96
			String[] next = top[0].split(":", 2);
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    97
			/*
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    98
			 * We can assume the path starts with a slash
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    99
			 * because we reject relative URIs above.
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   100
			 */
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   101
			service_ = next[0].substring(1);
310
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   102
			svctype_ = FMRIType.SERVICE;
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   103
			if (next.length == 2) {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   104
				instance_ = next[1];
310
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   105
				if (!instance_.matches(FORMAT))
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   106
					throw (new URISyntaxException(
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   107
					    uri.toString(),
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   108
					    "Invalid instance: " + instance_));
310
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   109
				svctype_ = FMRIType.INSTANCE;
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   110
			}
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   111
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   112
			if (top.length == 2) {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   113
				next = top[1].split("/", 2);
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   114
				pg_ = next[0];
310
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   115
				if (!pg_.matches(FORMAT))
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   116
					throw (new URISyntaxException(
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   117
					    uri.toString(),
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   118
					    "Invalid property group: " + pg_));
310
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   119
				svctype_ = FMRIType.PGROUP;
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   120
				if (next.length == 2) {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   121
					property_ = next[1];
310
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   122
					if (!property_.matches(FORMAT))
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   123
						throw (new URISyntaxException(
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   124
						    uri.toString(),
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   125
						    "Invalid property: " +
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   126
						    property_));
310
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   127
					svctype_ = FMRIType.PROPERTY;
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   128
				}
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   129
			}
310
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   130
		} else if (scheme.equals("file")) {
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   131
			scheme_ = FMRIScheme.FILE;
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   132
			name_ = uri.getPath();
310
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   133
		} else if (scheme.equals("lrc")) {
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   134
			scheme_ = FMRIScheme.LEGACY;
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   135
			name_ = uri.getPath();
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   136
		} else {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   137
			throw (new URISyntaxException(uri.toString(),
310
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   138
			    "Invalid FMRI scheme: " + scheme));
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   139
		}
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   140
	}
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   141
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   142
	/**
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   143
	 * Creates an FMRI from a string.
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   144
	 */
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   145
	public FMRI(String fmri) throws URISyntaxException
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   146
	{
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   147
		/* Work around bug 6504439 in scf_scope_to_fmri */
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   148
		this(new URI(fmri.equals("svc:") ? "svc:///" : fmri));
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   149
	}
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   150
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   151
	/**
310
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   152
	 * Constucts an FMRI from its attributes.  Needed for the class to be
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   153
	 * reconstructable.
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   154
	 */
314
8decc90a3ec6 9416 more fully featured FMRI type (fix lint)
David Powell <David.Powell@sun.com>
parents: 310
diff changeset
   155
	@SuppressWarnings({"fallthrough"})
310
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   156
	@ConstructorProperties({"scheme", "svcType", "scope", "name", "service",
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   157
	    "instance", "propertyGroup", "property"})
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   158
	public FMRI(FMRIScheme scheme, FMRIType type, String scope, String name,
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   159
	    String service, String instance, String pg, String property)
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   160
	{
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   161
		scheme_ = scheme;
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   162
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   163
		scope_ = scope;
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   164
		if (scope_ == null || scope_.isEmpty() ||
314
8decc90a3ec6 9416 more fully featured FMRI type (fix lint)
David Powell <David.Powell@sun.com>
parents: 310
diff changeset
   165
		    scope_.equals(SCF_SCOPE_LOCAL))
310
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   166
			scope_ = null;
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   167
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   168
		String path;
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   169
		if (scheme != FMRIScheme.SERVICE) {
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   170
			svctype_ = FMRIType.NONE;
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   171
			path = name_ = name;
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   172
		} else {
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   173
			svctype_ = type;
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   174
			name_ = null;
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   175
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   176
			path = "";
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   177
			switch (svctype_) {
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   178
			case PROPERTY:
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   179
			    property_ = property;
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   180
			    path = "/" + property + path;
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   181
			case PGROUP:
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   182
			    pg_ = pg;
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   183
			    path = "/:properties/" + pg + path;
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   184
			case INSTANCE:
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   185
			    instance_ = instance;
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   186
			    path = ":" + instance + path;
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   187
			case SERVICE:
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   188
			    service_ = service;
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   189
			    path = "/" + service + path;
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   190
			}
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   191
		}
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   192
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   193
		try {
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   194
			URI uri = new URI(scheme_strings.get(scheme), scope_,
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   195
			    path, null, null);
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   196
			canonicalStr_ = uri.toString();
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   197
		} catch (URISyntaxException ex) {
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   198
			canonicalStr_ = null;
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   199
		}
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   200
	}
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   201
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   202
	/**
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   203
	 * Returns the FMRI's type (scheme).
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   204
	 */
310
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   205
	public FMRIScheme getScheme()
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   206
	{
310
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   207
		return (scheme_);
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   208
	}
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   209
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   210
	/**
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   211
	 * Returns a svc: FMRI's type.
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   212
	 */
310
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   213
	public FMRIType getSvcType()
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   214
	{
310
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   215
		if (scheme_ != FMRIScheme.SERVICE)
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   216
			throw (new FMRIException(this, "not a service FMRI"));
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   217
		return (svctype_);
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   218
	}
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   219
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   220
	/**
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   221
	 * Returns the FMRI's scope.
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   222
	 */
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   223
	public String getScope()
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   224
	{
310
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   225
		return (scope_ == null ? SCF_SCOPE_LOCAL : scope_);
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   226
	}
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   227
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   228
	/**
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   229
	 * Returns the name of a legacy-run or file FMRI.
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   230
	 */
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   231
	public String getName()
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   232
	{
310
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   233
		if (scheme_ == FMRIScheme.SERVICE)
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   234
			throw (new FMRIException(this,
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   235
			    "not a file or legacy FMRI"));
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   236
		return (name_);
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   237
	}
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   238
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   239
	/**
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   240
	 * Throws an FMRIException from a function which may only be
310
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   241
	 * called on a svc: FMRI.  Takes the FMRIType required by the
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   242
	 * caller.
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   243
	 */
310
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   244
	private void checktype(FMRIType svctype)
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   245
	{
310
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   246
		String prefix = "unable to read " + svctype;
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   247
		if (scheme_ != FMRIScheme.SERVICE)
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   248
			throw (new FMRIException(this, prefix +
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   249
			    " from non-service FMRI"));
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   250
		if (svctype_.compareTo(svctype) < 0)
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   251
			throw (new FMRIException(this, prefix +
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   252
			    " from " + svctype_ + "FMRI"));
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   253
	}
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   254
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   255
	/**
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   256
	 * Returns the service component of a service FMRI.
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   257
	 */
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   258
	public String getService()
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   259
	{
310
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   260
		checktype(FMRIType.SERVICE);
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   261
		return (service_);
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   262
	}
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   263
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   264
	/**
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   265
	 * Returns the instance component of a service FMRI, or {@code
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   266
	 * null} if there is none.
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   267
	 */
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   268
	public String getInstance()
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   269
	{
310
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   270
		checktype(FMRIType.INSTANCE);
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   271
		return (instance_);
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   272
	}
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   273
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   274
	/**
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   275
	 * Returns the property group component of a service FMRI.
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   276
	 */
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   277
	public String getPropertyGroup()
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   278
	{
310
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   279
		checktype(FMRIType.PGROUP);
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   280
		return (pg_);
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   281
	}
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   282
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   283
	/**
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   284
	 * Returns the property component of a service FMRI.
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   285
	 */
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   286
	public String getProperty()
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   287
	{
310
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   288
		checktype(FMRIType.PROPERTY);
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   289
		return (property_);
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   290
	}
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   291
310
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   292
	public FMRI toServiceFMRI()
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   293
	{
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   294
		checktype(FMRIType.SERVICE);
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   295
		if (svctype_ == FMRIType.SERVICE)
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   296
			return this;
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   297
		return (new FMRI(scheme_, FMRIType.SERVICE, scope_, null,
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   298
		    service_, null, null, null));
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   299
	}
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   300
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   301
	public FMRI toInstanceFMRI()
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   302
	{
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   303
		checktype(FMRIType.INSTANCE);
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   304
		if (svctype_ == FMRIType.INSTANCE)
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   305
			return this;
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   306
		return (new FMRI(scheme_, FMRIType.INSTANCE, scope_, null,
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   307
		    service_, instance_, null, null));
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   308
	}
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   309
323
497a785649eb 10071 apply new design to SMF panel
David Powell <David.Powell@sun.com>
parents: 314
diff changeset
   310
	public FMRI toInstanceFMRI(String instanceName)
497a785649eb 10071 apply new design to SMF panel
David Powell <David.Powell@sun.com>
parents: 314
diff changeset
   311
	{
497a785649eb 10071 apply new design to SMF panel
David Powell <David.Powell@sun.com>
parents: 314
diff changeset
   312
		checktype(FMRIType.SERVICE);
497a785649eb 10071 apply new design to SMF panel
David Powell <David.Powell@sun.com>
parents: 314
diff changeset
   313
		return (new FMRI(scheme_, FMRIType.INSTANCE, scope_, null,
497a785649eb 10071 apply new design to SMF panel
David Powell <David.Powell@sun.com>
parents: 314
diff changeset
   314
		    service_, instanceName, null, null));
497a785649eb 10071 apply new design to SMF panel
David Powell <David.Powell@sun.com>
parents: 314
diff changeset
   315
	}
497a785649eb 10071 apply new design to SMF panel
David Powell <David.Powell@sun.com>
parents: 314
diff changeset
   316
310
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   317
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   318
	/*
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   319
	 * CompositeDataView methods
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   320
	 */
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   321
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   322
	private static final String[] itemNames = new String[] { "scheme",
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   323
	    "svcType", "scope", "name", "service", "instance", "propertyGroup",
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   324
	    "property" };
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   325
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   326
	/*
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   327
	 * Manually convert the FMRI to its automatically-determined
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   328
	 * CompositeType.  This conversion is normally performed by the
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   329
	 * MXBean implementation, but the automatic conversion uses our
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   330
	 * accessors to inspect the object.  Performing the conversion
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   331
	 * manually permits us to circumvent the run-time checking
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   332
	 * performed by our accessors (or to put it differently, permits
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   333
	 * us to leave the run-time checking in place).
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   334
	 */
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   335
	public CompositeData toCompositeData(CompositeType ct)
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   336
	{
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   337
		Object[] itemValues = new Object[] { scheme_.name(),
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   338
		    svctype_.name(), scope_, name_, service_, instance_, pg_,
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   339
		    property_ };
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   340
		try {
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   341
			return (new CompositeDataSupport(ct, itemNames,
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   342
			    itemValues));
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   343
		} catch (OpenDataException ex) {
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   344
			throw (new RuntimeException(ex));
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   345
		}
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   346
	}
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   347
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   348
	// Comparable methods
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   349
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   350
	private static int strcmp(String a, String b)
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   351
	{
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   352
		if (a == null)
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   353
			return (b == null ? 0 : 1);
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   354
		if (b == null)
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   355
			return (-1);
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   356
		return (a.compareTo(b));
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   357
	}
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   358
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   359
	public int compareTo(FMRI f)
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   360
	{
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   361
		int result = scheme_.compareTo(f.scheme_);
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   362
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   363
		if (result == 0)
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   364
			result = strcmp(scope_, f.scope_);
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   365
		if (scheme_ != FMRIScheme.SERVICE)
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   366
			result = strcmp(name_, f.name_);
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   367
		else {
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   368
			if (result == 0)
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   369
				result = strcmp(service_, f.service_);
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   370
			if (result == 0)
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   371
				result = strcmp(instance_, f.instance_);
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   372
			if (result == 0)
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   373
				result = strcmp(pg_, f.pg_);
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   374
			if (result == 0)
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   375
				result = strcmp(property_, f.property_);
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   376
		}
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   377
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   378
		return (result);
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   379
	}
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   380
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   381
	/*
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   382
	 * Object methods
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   383
	 */
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   384
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   385
	/**
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   386
	 * Returns the FMRI as a string.
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   387
	 */
310
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   388
	@Override
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   389
	public String toString()
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   390
	{
310
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   391
		return (canonicalStr_);
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   392
	}
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   393
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   394
	@Override
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   395
	public boolean equals(Object o)
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   396
	{
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   397
		if (o == null)
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   398
			return (false);
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   399
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   400
		FMRI f;
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   401
		try {
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   402
			f = (FMRI)o;
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   403
		} catch (ClassCastException e) {
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   404
			return (false);
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   405
		}
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   406
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   407
		return (compareTo(f) == 0);
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   408
	}
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   409
310
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   410
	@Override
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   411
	public int hashCode()
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   412
	{
310
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   413
		int hash = 7;
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   414
		hash = 79 * hash +
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   415
		    (this.scope_ != null ? this.scope_.hashCode() : 0);
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   416
		hash = 79 * hash +
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   417
		    (this.service_ != null ? this.service_.hashCode() : 0);
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   418
		hash = 79 * hash +
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   419
		    (this.instance_ != null ? this.instance_.hashCode() : 0);
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   420
		hash = 79 * hash +
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   421
		    (this.pg_ != null ? this.pg_.hashCode() : 0);
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   422
		hash = 79 * hash +
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   423
		    (this.property_ != null ? this.property_.hashCode() : 0);
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   424
		hash = 79 * hash +
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   425
		    (this.name_ != null ? this.name_.hashCode() : 0);
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   426
		hash = 79 * hash +
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   427
		    (this.scheme_ != null ? this.scheme_.hashCode() : 0);
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   428
		hash = 79 * hash +
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   429
		    (this.svctype_ != null ? this.svctype_.hashCode() : 0);
643b4561e982 9415 should deliver a gnome schema for svc: URIs
David Powell <David.Powell@sun.com>
parents: 79
diff changeset
   430
		return hash;
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   431
	}
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   432
}