001/* MBeanTrustPermission.java -- Represents a trusted bean source.
002   Copyright (C) 2006 Free Software Foundation, Inc.
003
004This file is part of GNU Classpath.
005
006GNU Classpath is free software; you can redistribute it and/or modify
007it under the terms of the GNU General Public License as published by
008the Free Software Foundation; either version 2, or (at your option)
009any later version.
010
011GNU Classpath is distributed in the hope that it will be useful, but
012WITHOUT ANY WARRANTY; without even the implied warranty of
013MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014General Public License for more details.
015
016You should have received a copy of the GNU General Public License
017along with GNU Classpath; see the file COPYING.  If not, write to the
018Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
01902110-1301 USA.
020
021Linking this library statically or dynamically with other modules is
022making a combined work based on this library.  Thus, the terms and
023conditions of the GNU General Public License cover the whole
024combination.
025
026As a special exception, the copyright holders of this library give you
027permission to link this library with independent modules to produce an
028executable, regardless of the license terms of these independent
029modules, and to copy and distribute the resulting executable under
030terms of your choice, provided that you also meet, for each linked
031independent module, the terms and conditions of the license of that
032module.  An independent module is a module which is not derived from
033or based on this library.  If you modify this library, you may extend
034this exception to your version of the library, but you are not
035obligated to do so.  If you do not wish to do so, delete this
036exception statement from your version. */
037
038package javax.management;
039
040import java.security.BasicPermission;
041
042/**
043 * Represents the permission held by a trusted source of
044 * management beans.  For a bean to be added to a management
045 * server, the source of that bean must hold this permission.
046 * It has a target, but no actions. Valid values for the target
047 * are <code>"register"</code> and <code>"*"</code>, the latter
048 * representing both the existing <code>"register"</code> target
049 * and any future targets.
050 *
051 * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
052 * @since 1.5
053 */
054public class MBeanTrustPermission
055  extends BasicPermission
056{
057
058  /**
059   * Compatible with JDK 1.5
060   */
061  private static final long serialVersionUID = -2952178077029018140L;
062
063  /**
064   * Constructs a {@link MBeanTrustPermission} with the given target.
065   * The target must be either <code>"register"</code> or <code>"*"</code>.
066   * The actions of the permission default to <code>null</code>,
067   * so this is equivalent to calling
068   * <code>MBeanTrustPermission(target, null)</code>.
069   *
070   * @param target the target of this permission.
071   * @throws NullPointerException if <code>target</code> is null.
072   * @throws IllegalArgumentException if the target is other than
073   *                                  <code>"register"</code> or <code>"*"</code>.
074   * @see #MBeanTrustPermission(String, String)
075   */
076  public MBeanTrustPermission(String target)
077  {
078    this(target, null);
079  }
080
081  /**
082   * Constructs a {@link MBeanTrustPermission} with the given target
083   * and actions.  The target must be either <code>"register"</code>
084   * or <code>"*"</code>.  The actions must be either <code>null</code>
085   * or the empty string, <code>""</code>.
086   *
087   * @param target the target of this permission.
088   * @param actions the actions for this permission.
089   * @throws NullPointerException if <code>target</code> is null.
090   * @throws IllegalArgumentException if the target is other than
091   *                                  <code>"register"</code> or <code>"*"</code>
092   *                                  or actions is other than
093   *                                  <code>null</code> or <code>""</code>.
094   */
095  public MBeanTrustPermission(String target, String actions)
096  {
097    super(target, actions);
098    if ((!(target.equals("register"))) &&
099        (!(target.equals("*"))))
100      throw new IllegalArgumentException("The target must be 'register' or '*'");
101    if (actions != null && !(actions.length() == 0))
102      throw new IllegalArgumentException("The actions must be null or ''");
103  }
104
105}