1 21 package org.jacorb.security.level2; 22 23 32 33 import java.util.*; 34 35 import org.omg.Security.*; 36 37 public class SecAttributeManager 38 { 39 private Hashtable attributes = null; 40 private int id = Integer.MIN_VALUE + 1; 41 42 private static SecAttributeManager instance = null; 43 44 public SecAttributeManager() 45 { 46 attributes = new Hashtable(); 47 } 48 49 public static SecAttributeManager getInstance() 50 { 51 if( instance == null ) 52 { 53 instance = new SecAttributeManager(); 54 } 55 56 return instance; 57 } 58 59 public KeyAndCert getAttributeCertValue( SecAttribute attribute ) 60 { 61 return (KeyAndCert) getAttributeValue( attribute ); 62 } 63 64 public synchronized SecAttribute createAttribute( 65 Object attrib_value, 66 AttributeType attribute_type ) 67 { 68 byte[] value = new byte[]{ (byte) (( id >> 24 ) & 0xff), 70 (byte) (( id >> 16 ) & 0xff), 71 (byte) (( id >> 8 ) & 0xff), 72 (byte) ( id & 0xff) }; 73 74 attributes.put( new Integer ( id++ ), attrib_value ); 75 76 return new SecAttribute( attribute_type, 77 new byte[0], value ); 79 } 80 81 public Object getAttributeValue( SecAttribute attribute ) 82 { 83 if( attribute.value.length != 4 ) 84 { 85 throw new RuntimeException ( "Value of SecAttribute unknown!" ); 86 } 87 88 int the_id = 89 ((attribute.value[0] & 0xff) << 24 ) + 90 ((attribute.value[1] & 0xff) << 16 ) + 91 ((attribute.value[2] & 0xff) << 8 ) + 92 (attribute.value[3] & 0xff); 93 94 return attributes.get( new Integer ( the_id )); 95 } 96 97 public void removeAttribute( SecAttribute attribute ) 98 { 99 if( attribute.value.length != 4 ) 100 { 101 throw new RuntimeException ( "Value of SecAttribute unknown!" ); 102 } 103 104 int the_id = 105 ((attribute.value[0] & 0xff) << 24 ) + 106 ((attribute.value[1] & 0xff) << 16 ) + 107 ((attribute.value[2] & 0xff) << 8 ) + 108 (attribute.value[3] & 0xff); 109 110 attributes.remove( new Integer ( the_id )); 111 } 112 } | Popular Tags |