Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/flexstor/common/util/AssetRoleList.java


1   /*
2    * AssetRoleList.java
3    *
4    * Copyright $Date: 2003/08/11 02:22:31 $ FLEXSTOR.net Inc.
5    *
6    * This work is licensed for use and distribution under license terms found at
7    * http://www.flexstor.org/license.html
8    *
9    */
10  
11  package com.flexstor.common.util;
12  
13  import java.util.Enumeration;
14  import java.util.Hashtable;
15  
16  import com.flexstor.common.constants.AssetRolesI;
17  import com.flexstor.common.data.ejb.assetrolelist.AssetRoleListData;
18  import com.flexstor.common.gateway.AssetRoleListGateway;
19  import com.flexstor.common.gateway.exceptions.TransactionFailedException;
20  import com.flexstor.common.resources.Resources;
21  
22  public class AssetRoleList
23     implements AssetRolesI
24  {
25     private static AssetRoleList instance;
26     private static Hashtable       assetRoles;
27     
28     private AssetRoleList ( )
29     {
30     }
31     
32     public static AssetRoleList getInstance ( )
33     {
34        if ( instance == null )
35           instance = new AssetRoleList();
36           
37        return instance;
38     }
39     
40     /**
41      * Loads a list of all available servers.
42      */
43     public static boolean initialize ( )
44     {
45        AssetRoleListGateway gateway = null;
46  
47        try
48        {
49           gateway = new AssetRoleListGateway();
50           gateway.connect();
51           assetRoles = gateway.getAssetRoleList();
52           return true;
53        }
54        catch ( TransactionFailedException e )
55        {
56           assetRoles = new Hashtable();
57           return false;
58        }
59        finally
60        {
61           if ( gateway != null )
62              gateway.dispose();
63        }
64     }
65     
66     public static int getNumberOfRoles ( )
67     {
68        return assetRoles.size();
69     }
70     
71     public static int[] getAssetRoleIdList ( )
72     {
73        int i        = 0;
74        int naList[] = new int[assetRoles.size()];
75        
76        for ( Enumeration e = assetRoles.elements(); e.hasMoreElements(); i++ )
77           naList[i] = ((AssetRoleListData)e.nextElement()).getId();
78        
79        return naList;
80     }
81     
82     public static String getAssetRoleLabel ( int nAssetRoleId )
83     {
84        AssetRoleListData role = (AssetRoleListData)assetRoles.get ( new Integer(nAssetRoleId) );
85        return Resources.get ( role.getLabelLink() );
86     }
87  }