usr/src/java/rad/org/opensolaris/os/rad/EnumMapper.java
author David Powell <david.e.powell@oracle.com>
Thu, 11 Aug 2011 15:41:42 -0700
changeset 764 ebb25c1dac73
parent 681 e3ebf98ba2fd
permissions -rw-r--r--
18812 Support building with alternate java implementations
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
681
e3ebf98ba2fd 18035 enumeration fallback values
David Powell <david.e.powell@oracle.com>
parents:
diff changeset
     1
/*
e3ebf98ba2fd 18035 enumeration fallback values
David Powell <david.e.powell@oracle.com>
parents:
diff changeset
     2
 * CDDL HEADER START
e3ebf98ba2fd 18035 enumeration fallback values
David Powell <david.e.powell@oracle.com>
parents:
diff changeset
     3
 *
e3ebf98ba2fd 18035 enumeration fallback values
David Powell <david.e.powell@oracle.com>
parents:
diff changeset
     4
 * The contents of this file are subject to the terms of the
e3ebf98ba2fd 18035 enumeration fallback values
David Powell <david.e.powell@oracle.com>
parents:
diff changeset
     5
 * Common Development and Distribution License (the "License").
e3ebf98ba2fd 18035 enumeration fallback values
David Powell <david.e.powell@oracle.com>
parents:
diff changeset
     6
 * You may not use this file except in compliance with the License.
e3ebf98ba2fd 18035 enumeration fallback values
David Powell <david.e.powell@oracle.com>
parents:
diff changeset
     7
 *
e3ebf98ba2fd 18035 enumeration fallback values
David Powell <david.e.powell@oracle.com>
parents:
diff changeset
     8
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
e3ebf98ba2fd 18035 enumeration fallback values
David Powell <david.e.powell@oracle.com>
parents:
diff changeset
     9
 * or http://www.opensolaris.org/os/licensing.
e3ebf98ba2fd 18035 enumeration fallback values
David Powell <david.e.powell@oracle.com>
parents:
diff changeset
    10
 * See the License for the specific language governing permissions
e3ebf98ba2fd 18035 enumeration fallback values
David Powell <david.e.powell@oracle.com>
parents:
diff changeset
    11
 * and limitations under the License.
e3ebf98ba2fd 18035 enumeration fallback values
David Powell <david.e.powell@oracle.com>
parents:
diff changeset
    12
 *
e3ebf98ba2fd 18035 enumeration fallback values
David Powell <david.e.powell@oracle.com>
parents:
diff changeset
    13
 * When distributing Covered Code, include this CDDL HEADER in each
e3ebf98ba2fd 18035 enumeration fallback values
David Powell <david.e.powell@oracle.com>
parents:
diff changeset
    14
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
e3ebf98ba2fd 18035 enumeration fallback values
David Powell <david.e.powell@oracle.com>
parents:
diff changeset
    15
 * If applicable, add the following below this CDDL HEADER, with the
e3ebf98ba2fd 18035 enumeration fallback values
David Powell <david.e.powell@oracle.com>
parents:
diff changeset
    16
 * fields enclosed by brackets "[]" replaced with your own identifying
e3ebf98ba2fd 18035 enumeration fallback values
David Powell <david.e.powell@oracle.com>
parents:
diff changeset
    17
 * information: Portions Copyright [yyyy] [name of copyright owner]
e3ebf98ba2fd 18035 enumeration fallback values
David Powell <david.e.powell@oracle.com>
parents:
diff changeset
    18
 *
e3ebf98ba2fd 18035 enumeration fallback values
David Powell <david.e.powell@oracle.com>
parents:
diff changeset
    19
 * CDDL HEADER END
e3ebf98ba2fd 18035 enumeration fallback values
David Powell <david.e.powell@oracle.com>
parents:
diff changeset
    20
 */
e3ebf98ba2fd 18035 enumeration fallback values
David Powell <david.e.powell@oracle.com>
parents:
diff changeset
    21
e3ebf98ba2fd 18035 enumeration fallback values
David Powell <david.e.powell@oracle.com>
parents:
diff changeset
    22
/*
e3ebf98ba2fd 18035 enumeration fallback values
David Powell <david.e.powell@oracle.com>
parents:
diff changeset
    23
 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
e3ebf98ba2fd 18035 enumeration fallback values
David Powell <david.e.powell@oracle.com>
parents:
diff changeset
    24
 */
e3ebf98ba2fd 18035 enumeration fallback values
David Powell <david.e.powell@oracle.com>
parents:
diff changeset
    25
e3ebf98ba2fd 18035 enumeration fallback values
David Powell <david.e.powell@oracle.com>
parents:
diff changeset
    26
package org.opensolaris.os.rad;
e3ebf98ba2fd 18035 enumeration fallback values
David Powell <david.e.powell@oracle.com>
parents:
diff changeset
    27
e3ebf98ba2fd 18035 enumeration fallback values
David Powell <david.e.powell@oracle.com>
parents:
diff changeset
    28
import javax.management.openmbean.OpenDataException;
e3ebf98ba2fd 18035 enumeration fallback values
David Powell <david.e.powell@oracle.com>
parents:
diff changeset
    29
import javax.management.openmbean.OpenType;
e3ebf98ba2fd 18035 enumeration fallback values
David Powell <david.e.powell@oracle.com>
parents:
diff changeset
    30
import org.opensolaris.os.adr.Type;
e3ebf98ba2fd 18035 enumeration fallback values
David Powell <david.e.powell@oracle.com>
parents:
diff changeset
    31
import org.opensolaris.os.adr.Type.EnumType;
e3ebf98ba2fd 18035 enumeration fallback values
David Powell <david.e.powell@oracle.com>
parents:
diff changeset
    32
e3ebf98ba2fd 18035 enumeration fallback values
David Powell <david.e.powell@oracle.com>
parents:
diff changeset
    33
/**
e3ebf98ba2fd 18035 enumeration fallback values
David Powell <david.e.powell@oracle.com>
parents:
diff changeset
    34
 * Interface for factoring enumeration mapping out of ADRXDR.  The RAD data
e3ebf98ba2fd 18035 enumeration fallback values
David Powell <david.e.powell@oracle.com>
parents:
diff changeset
    35
 * model supports compatibly extending enumerations by optionally mapping
e3ebf98ba2fd 18035 enumeration fallback values
David Powell <david.e.powell@oracle.com>
parents:
diff changeset
    36
 * unknown values to a designated fallback value.  Because only the client
e3ebf98ba2fd 18035 enumeration fallback values
David Powell <david.e.powell@oracle.com>
parents:
diff changeset
    37
 * knows which version of the interface it is bound to, it is up to the
e3ebf98ba2fd 18035 enumeration fallback values
David Powell <david.e.powell@oracle.com>
parents:
diff changeset
    38
 * client infrastructure to perform this adaptation.  Moreover, this
e3ebf98ba2fd 18035 enumeration fallback values
David Powell <david.e.powell@oracle.com>
parents:
diff changeset
    39
 * knowledge isn't available to Client, only the layer above it.
e3ebf98ba2fd 18035 enumeration fallback values
David Powell <david.e.powell@oracle.com>
parents:
diff changeset
    40
 * <br>
e3ebf98ba2fd 18035 enumeration fallback values
David Powell <david.e.powell@oracle.com>
parents:
diff changeset
    41
 * Unfortunately, some consumers (e.g. JMX MXBeans), while flexible in other
e3ebf98ba2fd 18035 enumeration fallback values
David Powell <david.e.powell@oracle.com>
parents:
diff changeset
    42
 * areas, lack flexibility in their consumption of enumerated values.  There
e3ebf98ba2fd 18035 enumeration fallback values
David Powell <david.e.powell@oracle.com>
parents:
diff changeset
    43
 * are three options available to us: remap all OpenData returned from Client
e3ebf98ba2fd 18035 enumeration fallback values
David Powell <david.e.powell@oracle.com>
parents:
diff changeset
    44
 * (expensive), selectively modify the OpenData returned from Client (requires
e3ebf98ba2fd 18035 enumeration fallback values
David Powell <david.e.powell@oracle.com>
parents:
diff changeset
    45
 * reimplementing much of CompositeType and CompositeDataSupport), or
e3ebf98ba2fd 18035 enumeration fallback values
David Powell <david.e.powell@oracle.com>
parents:
diff changeset
    46
 * instruct Client to map Enums into a form more suited to the consumer.
e3ebf98ba2fd 18035 enumeration fallback values
David Powell <david.e.powell@oracle.com>
parents:
diff changeset
    47
 * <br>
e3ebf98ba2fd 18035 enumeration fallback values
David Powell <david.e.powell@oracle.com>
parents:
diff changeset
    48
 * This implements the third option.
e3ebf98ba2fd 18035 enumeration fallback values
David Powell <david.e.powell@oracle.com>
parents:
diff changeset
    49
 */
e3ebf98ba2fd 18035 enumeration fallback values
David Powell <david.e.powell@oracle.com>
parents:
diff changeset
    50
public abstract class EnumMapper {
e3ebf98ba2fd 18035 enumeration fallback values
David Powell <david.e.powell@oracle.com>
parents:
diff changeset
    51
    protected Client client_ = null;
e3ebf98ba2fd 18035 enumeration fallback values
David Powell <david.e.powell@oracle.com>
parents:
diff changeset
    52
e3ebf98ba2fd 18035 enumeration fallback values
David Powell <david.e.powell@oracle.com>
parents:
diff changeset
    53
    void setClient(Client client) {
e3ebf98ba2fd 18035 enumeration fallback values
David Powell <david.e.powell@oracle.com>
parents:
diff changeset
    54
	client_ = client;
e3ebf98ba2fd 18035 enumeration fallback values
David Powell <david.e.powell@oracle.com>
parents:
diff changeset
    55
    }
e3ebf98ba2fd 18035 enumeration fallback values
David Powell <david.e.powell@oracle.com>
parents:
diff changeset
    56
764
ebb25c1dac73 18812 Support building with alternate java implementations
David Powell <david.e.powell@oracle.com>
parents: 681
diff changeset
    57
    public abstract OpenType<?> toOpenType(EnumType type);
681
e3ebf98ba2fd 18035 enumeration fallback values
David Powell <david.e.powell@oracle.com>
parents:
diff changeset
    58
    public abstract Object fromWire(Type.EnumType type, Type.EnumValue value)
e3ebf98ba2fd 18035 enumeration fallback values
David Powell <david.e.powell@oracle.com>
parents:
diff changeset
    59
	throws OpenDataException;
e3ebf98ba2fd 18035 enumeration fallback values
David Powell <david.e.powell@oracle.com>
parents:
diff changeset
    60
    public abstract String toWire(Type.EnumType type, Object data);
e3ebf98ba2fd 18035 enumeration fallback values
David Powell <david.e.powell@oracle.com>
parents:
diff changeset
    61
}