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

/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */

/*
 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
 */

package org.opensolaris.os.rad;

import javax.management.openmbean.OpenDataException;
import javax.management.openmbean.OpenType;
import org.opensolaris.os.adr.Type;
import org.opensolaris.os.adr.Type.EnumType;

/**
 * Interface for factoring enumeration mapping out of ADRXDR.  The RAD data
 * model supports compatibly extending enumerations by optionally mapping
 * unknown values to a designated fallback value.  Because only the client
 * knows which version of the interface it is bound to, it is up to the
 * client infrastructure to perform this adaptation.  Moreover, this
 * knowledge isn't available to Client, only the layer above it.
 * <br>
 * Unfortunately, some consumers (e.g. JMX MXBeans), while flexible in other
 * areas, lack flexibility in their consumption of enumerated values.  There
 * are three options available to us: remap all OpenData returned from Client
 * (expensive), selectively modify the OpenData returned from Client (requires
 * reimplementing much of CompositeType and CompositeDataSupport), or
 * instruct Client to map Enums into a form more suited to the consumer.
 * <br>
 * This implements the third option.
 */
public abstract class EnumMapper {
    protected Client client_ = null;

    void setClient(Client client) {
	client_ = client;
    }

    public abstract OpenType<?> toOpenType(EnumType type);
    public abstract Object fromWire(Type.EnumType type, Type.EnumValue value)
	throws OpenDataException;
    public abstract String toWire(Type.EnumType type, Object data);
}