001 package railo.runtime.registry; 002 003 004 /** 005 * represent a single Registry Entry 006 */ 007 public final class RegistryEntry { 008 /** 009 * Field <code>TYPE_STRING</code> 010 */ 011 public static final short TYPE_STRING=0; 012 /** 013 * Field <code>TYPE_DWORD</code> 014 */ 015 public static final short TYPE_DWORD=1; 016 /** 017 * Field <code>TYPE_ANY</code> 018 */ 019 public static final short TYPE_ANY=2; 020 /** 021 * Field <code>TYPE_KEY</code> 022 */ 023 public static final short TYPE_KEY=3; 024 025 /** 026 * Field <code>REGSTR_TOKEN</code> 027 */ 028 public static final String REGSTR_TOKEN = "REG_SZ"; 029 /** 030 * Field <code>REGKEY_TOKEN</code> 031 */ 032 public static final String REGKEY_TOKEN = "REG_KEY"; 033 /** 034 * Field <code>REGDWORD_TOKEN</code> 035 */ 036 public static final String REGDWORD_TOKEN = "REG_DWORD"; 037 038 private short type; 039 private String key; 040 private Object value; 041 042 /** 043 * constructor of the class 044 * @param type (RegistryEntry.TYPE_DWORD, RegistryEntry.TYPE_STRING) 045 * @param key 046 * @param value 047 * @throws RegistryException 048 */ 049 public RegistryEntry(short type,String key,Object value) throws RegistryException { 050 if(type!=TYPE_DWORD && type!=TYPE_STRING && type!=TYPE_KEY) 051 throw new RegistryException("invalid Registry Type definition"); 052 053 054 this.type=type; 055 this.key=key; 056 this.value=value; 057 } 058 059 /** 060 * @return Returns the key. 061 */ 062 public String getKey() { 063 return key; 064 } 065 /** 066 * @return Returns the type. 067 */ 068 public short getType() { 069 return type; 070 } 071 /** 072 * @return Returns the value. 073 */ 074 public Object getValue() { 075 return value; 076 } 077 078 /** 079 * @see java.lang.Object#toString() 080 */ 081 public String toString() { 082 try { 083 return "Registry Entry: ["+key+" "+toStringType(type)+" "+value+"]"; 084 } catch (RegistryException e) { 085 return "Registry Entry: ["+key+" "+value+"]"; 086 } 087 } 088 089 /** 090 * cast a String type to a short Type 091 * @param strType 092 * @return 093 * @throws RegistryException 094 */ 095 public static short toType(String strType) throws RegistryException { 096 if(strType.equals(REGDWORD_TOKEN)) return RegistryEntry.TYPE_DWORD; 097 else if(strType.equals(REGSTR_TOKEN)) return RegistryEntry.TYPE_STRING; 098 else if(strType.equals(REGKEY_TOKEN)) return RegistryEntry.TYPE_KEY; 099 throw new RegistryException(strType+ " is not a valid Registry Type"); 100 } 101 102 /** 103 * cast a short type to a String Type 104 * @param type 105 * @return Registry String Type Definition 106 * @throws RegistryException 107 */ 108 public static String toStringType(short type) throws RegistryException { 109 if(type==TYPE_DWORD) return REGDWORD_TOKEN; 110 else if(type==TYPE_STRING) return REGSTR_TOKEN; 111 else if(type==TYPE_KEY) return REGKEY_TOKEN; 112 throw new RegistryException("invalid Registry Type definition"); 113 } 114 115 /** 116 * cast a short type to a String Type 117 * @param type 118 * @return Registry String Type Definition 119 * @throws RegistryException 120 */ 121 public static String toCFStringType(short type) throws RegistryException { 122 if(type==TYPE_DWORD) return "DWORD"; 123 else if(type==TYPE_STRING) return "STRING"; 124 else if(type==TYPE_KEY) return "KEY"; 125 throw new RegistryException("invalid Registry Type definition"); 126 } 127 }