001/**
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hdfs.web.resources;
019
020import org.apache.hadoop.fs.permission.FsPermission;
021
022/** Permission parameter, use a Short to represent a FsPermission. */
023public class PermissionParam extends ShortParam {
024  /** Parameter name. */
025  public static final String NAME = "permission";
026  /** Default parameter value. */
027  public static final String DEFAULT = NULL;
028
029  private static final Domain DOMAIN = new Domain(NAME, 8);
030
031  private static final short DEFAULT_PERMISSION = 0755;
032
033  /** @return the default FsPermission. */
034  public static FsPermission getDefaultFsPermission() {
035    return new FsPermission(DEFAULT_PERMISSION);
036  }
037
038  /**
039   * Constructor.
040   * @param value the parameter value.
041   */
042  public PermissionParam(final FsPermission value) {
043    super(DOMAIN, value == null? null: value.toShort(), null, null);
044  }
045
046  /**
047   * Constructor.
048   * @param str a string representation of the parameter value.
049   */
050  public PermissionParam(final String str) {
051    super(DOMAIN, DOMAIN.parse(str), (short)0, (short)01777);
052  }
053
054  @Override
055  public String getName() {
056    return NAME;
057  }
058
059  /** @return the represented FsPermission. */
060  public FsPermission getFsPermission() {
061    final Short v = getValue();
062    return new FsPermission(v != null? v: DEFAULT_PERMISSION);
063  }
064}