001/*
002 * IzPack - Copyright 2001-2005 Julien Ponge, All Rights Reserved.
003 * 
004 * http://www.izforge.com/izpack/
005 * http://developer.berlios.de/projects/izpack/
006 * 
007 * Copyright 2005 Klaus Bartz
008 *
009 * Licensed under the Apache License, Version 2.0 (the "License");
010 * you may not use this file except in compliance with the License.
011 * You may obtain a copy of the License at
012 * 
013 *     http://www.apache.org/licenses/LICENSE-2.0
014 *     
015 * Unless required by applicable law or agreed to in writing, software
016 * distributed under the License is distributed on an "AS IS" BASIS,
017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018 * See the License for the specific language governing permissions and
019 * limitations under the License.
020 */
021
022package com.coi.tools.os.win;
023
024import java.io.Serializable;
025
026/**
027 * Data container for Windows registry logging. This container is used to hold old and new created
028 * registry data used at rewinding the registry changes.
029 * 
030 * @author Klaus Bartz
031 * 
032 */
033public class RegistryLogItem implements Cloneable, Serializable
034{
035
036    /**
037     * 
038     */
039    private static final long serialVersionUID = 3618134559108444211L;
040
041    /** Types of log items */
042    public static final int REMOVED_KEY = 1;
043
044    public static final int CREATED_KEY = 2;
045
046    public static final int REMOVED_VALUE = 3;
047
048    public static final int CREATED_VALUE = 4;
049
050    public static final int CHANGED_VALUE = 5;
051
052    private int type;
053
054    private int root;
055
056    private String key;
057
058    private String valueName;
059
060    private RegDataContainer newValue = null;
061
062    private RegDataContainer oldValue = null;
063
064    /**
065     * Default constructor.
066     */
067    private RegistryLogItem()
068    {
069        super();
070    }
071
072    /**
073     * Constructor with settings.
074     * 
075     * @param type type of loging item. Possible are REMOVED_KEY, CREATED_KEY, REMOVED_VALUE,
076     * CREATED_VALUE and CHANGED_VALUE
077     * @param root id for the registry root
078     * @param key key name of the item which should be logged
079     * @param valueName name of the value of the item which should be logged if it is a value type,
080     * else null
081     * @param newValue new value of the registry entry if it is a value type, else null
082     * @param oldValue old value of the registry entry if it is a value type, else null
083     */
084    public RegistryLogItem(int type, int root, String key, String valueName,
085            RegDataContainer newValue, RegDataContainer oldValue)
086    {
087        this.type = type;
088        this.root = root;
089        this.key = key;
090        this.valueName = valueName;
091        this.newValue = newValue;
092        this.oldValue = oldValue;
093    }
094
095    /**
096     * Returns the key name of this logging item.
097     * 
098     * @return the key name of this logging item
099     */
100    public String getKey()
101    {
102        return key;
103    }
104
105    /**
106     * Returns the new value of this logging item.
107     * 
108     * @return the new value of this logging item
109     */
110    public RegDataContainer getNewValue()
111    {
112        return newValue;
113    }
114
115    /**
116     * Returns the old value of this logging item.
117     * 
118     * @return the old value of this logging item
119     */
120    public RegDataContainer getOldValue()
121    {
122        return oldValue;
123    }
124
125    /**
126     * Returns the root id of this logging item.
127     * 
128     * @return the root id of this logging item
129     */
130    public int getRoot()
131    {
132        return root;
133    }
134
135    /**
136     * Returns the type id of this logging item.
137     * 
138     * @return the type id of this logging item
139     */
140    public int getType()
141    {
142        return type;
143    }
144
145    /**
146     * Returns the value name of this logging item.
147     * 
148     * @return the value name of this logging item
149     */
150    public String getValueName()
151    {
152        return valueName;
153    }
154
155    /**
156     * Sets the key name to the given string
157     * 
158     * @param string to be used as key name
159     */
160    public void setKey(String string)
161    {
162        key = string;
163    }
164
165    /**
166     * Sets the new value to the given RegDataContainer.
167     * 
168     * @param container to be used as new value
169     */
170    public void setNewValue(RegDataContainer container)
171    {
172        newValue = container;
173    }
174
175    /**
176     * Sets the old value to the given RegDataContainer.
177     * 
178     * @param container to be used as old value
179     */
180    public void setOldValue(RegDataContainer container)
181    {
182        oldValue = container;
183    }
184
185    /**
186     * Sets the root id for this logging item.
187     * 
188     * @param i root id to be used for this logging item
189     */
190    public void setRoot(int i)
191    {
192        root = i;
193    }
194
195    /**
196     * Sets the type id for this logging item.
197     * 
198     * @param i type id to be used for this logging item
199     */
200    public void setType(int i)
201    {
202        type = i;
203    }
204
205    /**
206     * Sets the value name to the given string
207     * 
208     * @param string to be used as value name
209     */
210    public void setValueName(String string)
211    {
212        valueName = string;
213    }
214
215    public Object clone() throws CloneNotSupportedException
216    {
217        RegistryLogItem retval = (RegistryLogItem) super.clone();
218        if (newValue != null) retval.newValue = (RegDataContainer) newValue.clone();
219        if (oldValue != null) retval.oldValue = (RegDataContainer) oldValue.clone();
220        return (retval);
221
222    }
223}