javacommons/security/javasrc/com/nokia/mj/impl/security/midp/common/MandatoryPermissionAttribute.java
branchRCL_3
changeset 14 04becd199f91
equal deleted inserted replaced
13:f5050f1da672 14:04becd199f91
       
     1 /*
       
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 package com.nokia.mj.impl.security.midp.common;
       
    19 
       
    20 /**
       
    21  * Encapsulation of a mandatory permission attribute
       
    22  */
       
    23 public class MandatoryPermissionAttribute
       
    24         extends PermissionAttribute
       
    25 {
       
    26     /**
       
    27      * Constructor for legacy attributes
       
    28      */
       
    29     MandatoryPermissionAttribute()
       
    30     {
       
    31         super(MANDATORY_LEGACY_ATTRIBUTE_NAME);
       
    32     }
       
    33 
       
    34     MandatoryPermissionAttribute(String attrName, String attrValue)
       
    35     {
       
    36         super(attrName, attrValue);
       
    37     }
       
    38 
       
    39     MandatoryPermissionAttribute(String attrValue)
       
    40     {
       
    41         super(MANDATORY_LEGACY_ATTRIBUTE_NAME, attrValue);
       
    42     }
       
    43 
       
    44     public static PermissionAttribute[] HandleLegacyAttribute(String attrValue)
       
    45     {
       
    46         if (attrValue == null)
       
    47         {
       
    48             return null;
       
    49         }
       
    50         MandatoryPermissionAttribute[] mandatoryPerms = null;
       
    51         MIDPPermission[] perms = InitFromLegacyAttribute(
       
    52                                      MANDATORY_LEGACY_ATTRIBUTE_NAME, attrValue, false /* ignore unknown values */);
       
    53         if (perms != null)
       
    54         {
       
    55             mandatoryPerms = new MandatoryPermissionAttribute[perms.length];
       
    56             for (int i=0; i<mandatoryPerms.length; i++)
       
    57             {
       
    58                 mandatoryPerms[i] = new MandatoryPermissionAttribute(perms[i]);
       
    59             }
       
    60         }
       
    61         return mandatoryPerms;
       
    62     }
       
    63 
       
    64     public int getImportance()
       
    65     {
       
    66         return MANDATORY_PERMISSION;
       
    67     }
       
    68 
       
    69     public String toString()
       
    70     {
       
    71         StringBuffer sb = new StringBuffer();
       
    72         sb.append("MANDATORY\n");
       
    73         sb.append("Name: "+getName()+ "\n");
       
    74         sb.append("Target: "+getTarget()+ "\n");
       
    75         sb.append("ActionList: "+getActionList()+ "\n");
       
    76         return sb.toString();
       
    77     }
       
    78 
       
    79     private MandatoryPermissionAttribute(MIDPPermission permission)
       
    80     {
       
    81         super(permission.getName(),
       
    82               permission.getTarget(),
       
    83               permission.getActionList(),
       
    84               MANDATORY_LEGACY_ATTRIBUTE_NAME);
       
    85     }
       
    86 }