/*
 * 
 * Copyright 2004 Sun Microsystems, Inc. All Rights Reserved.
 * 
 * The contents of this file are subject to the Sun Community Source
 * License v3.0/Jini Technology Specific Attachment v 1.0 (the
 * "License"). You may not use this file except in compliance with the
 * License. You may obtain a copy of the License at
 * http://wwws.sun.com/software/jini/licensing/SCSL3_JiniTSA1.html.
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
 * the License for the specific language governing rights and limitations
 * under the License.
 * 
 * The Reference Code is Jini Technology Core Platform code, v2.0. The
 * Developer of the Reference Code is Sun Microsystems, Inc.
 * 
 * Contributor(s): Sun Microsystems, Inc.
 * 
 */

package net.jini.core.constraint;

import java.io.Serializable;

/**
 * Represents a constraint on the confidentiality of message contents.
 * <p>
 * Serialization for this class is guaranteed to produce instances that are
 * comparable with <code>==</code>.
 *
 * @author Sun Microsystems, Inc.
 * @since 2.0
 */
public final class Confidentiality
				implements InvocationConstraint, Serializable
{
    private static final long serialVersionUID = 6173438948668674131L;

    /**
     * Transmit message contents so that they cannot easily be interpreted by
     * third parties (typically by using encryption). The mechanisms used
     * to maintain confidentiality are not specified by this constraint.
     */
    public static final Confidentiality YES = new Confidentiality(true);
    /**
     * Transmit message contents in the clear (no use of encryption).
     * <p>
     * Normally this constraint should not be used unless there is an
     * organizational policy that data must be transmitted in the clear.
     */
    public static final Confidentiality NO = new Confidentiality(false);

    /**
     * <code>true</code> for <code>YES</code>, <code>false</code> for
     * <code>NO</code>
     *
     * @serial
     */
    private final boolean val;

    /**
     * Simple constructor.
     *
     * @param val <code>true</code> for <code>YES</code>, <code>false</code>
     * for <code>NO</code>
     */
    private Confidentiality(boolean val) {
	this.val = val;
    }

    /**
     * Returns a string representation of this object.
     */
    public String toString() {
	return val ? "Confidentiality.YES" : "Confidentiality.NO";
    }

    /**
     * Canonicalize so that <code>==</code> can be used.
     */
    private Object readResolve() {
	return val ? YES : NO;
    }
}
