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            @Override
079            public String toString() {
080                    try {
081                            return "Registry Entry: ["+key+" "+toStringType(type)+" "+value+"]";
082                    } catch (RegistryException e) {
083                            return "Registry Entry: ["+key+" "+value+"]";
084                    }
085            }
086    
087            /**
088             * cast a String type to a short Type
089             * @param strType
090             * @return
091             * @throws RegistryException
092             */
093            public static short toType(String strType) throws RegistryException {
094                    if(strType.equals(REGDWORD_TOKEN)) return RegistryEntry.TYPE_DWORD;
095                    else if(strType.equals(REGSTR_TOKEN)) return RegistryEntry.TYPE_STRING;
096                    else if(strType.equals(REGKEY_TOKEN)) return RegistryEntry.TYPE_KEY;
097                    throw new RegistryException(strType+ " is not a valid Registry Type");
098            }
099            
100            /**
101             * cast a short type to a String Type
102             * @param type
103             * @return Registry String Type Definition
104             * @throws RegistryException
105             */
106            public static String toStringType(short type) throws RegistryException {
107                    if(type==TYPE_DWORD) return REGDWORD_TOKEN;
108                    else if(type==TYPE_STRING) return REGSTR_TOKEN;
109                    else if(type==TYPE_KEY) return REGKEY_TOKEN;
110                    throw new RegistryException("invalid Registry Type definition");
111            }
112            
113            /**
114             * cast a short type to a String Type
115             * @param type
116             * @return Registry String Type Definition
117             * @throws RegistryException
118             */
119            public static String toCFStringType(short type) throws RegistryException {
120                    if(type==TYPE_DWORD) return "DWORD";
121                    else if(type==TYPE_STRING) return "STRING";
122                    else if(type==TYPE_KEY) return "KEY";
123                    throw new RegistryException("invalid Registry Type definition");
124            }
125    }