001/** 002 * 003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved. 004 * 005 * This library is free software; you can redistribute it and/or 006 * modify it under the terms of the GNU Lesser General Public 007 * License as published by the Free Software Foundation; either 008 * version 2.1 of the License, or (at your option) any later version. 009 * 010 * This library is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 * Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public 016 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 017 * 018 **/ 019package lucee.runtime.registry; 020 021 022/** 023 * represent a single Registry Entry 024 */ 025public final class RegistryEntry { 026 /** 027 * Field <code>TYPE_STRING</code> 028 */ 029 public static final short TYPE_STRING=0; 030 /** 031 * Field <code>TYPE_DWORD</code> 032 */ 033 public static final short TYPE_DWORD=1; 034 /** 035 * Field <code>TYPE_ANY</code> 036 */ 037 public static final short TYPE_ANY=2; 038 /** 039 * Field <code>TYPE_KEY</code> 040 */ 041 public static final short TYPE_KEY=3; 042 043 /** 044 * Field <code>REGSTR_TOKEN</code> 045 */ 046 public static final String REGSTR_TOKEN = "REG_SZ"; 047 /** 048 * Field <code>REGKEY_TOKEN</code> 049 */ 050 public static final String REGKEY_TOKEN = "REG_KEY"; 051 /** 052 * Field <code>REGDWORD_TOKEN</code> 053 */ 054 public static final String REGDWORD_TOKEN = "REG_DWORD"; 055 056 private short type; 057 private String key; 058 private Object value; 059 060 /** 061 * constructor of the class 062 * @param type (RegistryEntry.TYPE_DWORD, RegistryEntry.TYPE_STRING) 063 * @param key 064 * @param value 065 * @throws RegistryException 066 */ 067 public RegistryEntry(short type,String key,Object value) throws RegistryException { 068 if(type!=TYPE_DWORD && type!=TYPE_STRING && type!=TYPE_KEY) 069 throw new RegistryException("invalid Registry Type definition"); 070 071 072 this.type=type; 073 this.key=key; 074 this.value=value; 075 } 076 077 /** 078 * @return Returns the key. 079 */ 080 public String getKey() { 081 return key; 082 } 083 /** 084 * @return Returns the type. 085 */ 086 public short getType() { 087 return type; 088 } 089 /** 090 * @return Returns the value. 091 */ 092 public Object getValue() { 093 return value; 094 } 095 096 @Override 097 public String toString() { 098 try { 099 return "Registry Entry: ["+key+" "+toStringType(type)+" "+value+"]"; 100 } catch (RegistryException e) { 101 return "Registry Entry: ["+key+" "+value+"]"; 102 } 103 } 104 105 /** 106 * cast a String type to a short Type 107 * @param strType 108 * @return 109 * @throws RegistryException 110 */ 111 public static short toType(String strType) throws RegistryException { 112 if(strType.equals(REGDWORD_TOKEN)) return RegistryEntry.TYPE_DWORD; 113 else if(strType.equals(REGSTR_TOKEN)) return RegistryEntry.TYPE_STRING; 114 else if(strType.equals(REGKEY_TOKEN)) return RegistryEntry.TYPE_KEY; 115 throw new RegistryException(strType+ " is not a valid Registry Type"); 116 } 117 118 /** 119 * cast a short type to a String Type 120 * @param type 121 * @return Registry String Type Definition 122 * @throws RegistryException 123 */ 124 public static String toStringType(short type) throws RegistryException { 125 if(type==TYPE_DWORD) return REGDWORD_TOKEN; 126 else if(type==TYPE_STRING) return REGSTR_TOKEN; 127 else if(type==TYPE_KEY) return REGKEY_TOKEN; 128 throw new RegistryException("invalid Registry Type definition"); 129 } 130 131 /** 132 * cast a short type to a String Type 133 * @param type 134 * @return Registry String Type Definition 135 * @throws RegistryException 136 */ 137 public static String toCFStringType(short type) throws RegistryException { 138 if(type==TYPE_DWORD) return "DWORD"; 139 else if(type==TYPE_STRING) return "STRING"; 140 else if(type==TYPE_KEY) return "KEY"; 141 throw new RegistryException("invalid Registry Type definition"); 142 } 143}