net.smartlab.web.BusinessObject Maven / Gradle / Ivy
/*
* The SmartWeb Framework
* Copyright (C) 2004-2006
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* For further informations on the SmartWeb Framework please visit
*
* http://smartweb.sourceforge.net
*/
package net.smartlab.web;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.lang.reflect.Field;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* TODO documentation
*
* @author rlogiacco
* @uml.dependency supplier="net.smartlab.web.Enumeration"
* @uml.dependency supplier="net.smartlab.web.StringEnumeration"
*/
public abstract class BusinessObject implements DataTransferObject {
private final static long serialVersionUID = 8960870409825593855L;
/**
* Allows for business operations logging.
*/
protected final transient Log logger = LogFactory.getLog(this.getClass());
/**
* This number stores the object version and is used for optimistical
* locking.
*
* @uml.property name="version"
*/
private long version;
/**
* Returns the object version. This property ensures optimistical locking
* support to every subclass.
*
* @return returns the version.
* @hibernate.version
* @uml.property name="version"
*/
public long getVersion() {
return version;
}
/**
* Sets the object version. This property ensures optimistical locking
* support to every subclass.
*
* @param version the version to set.
* @uml.property name="version"
*/
public void setVersion(long version) {
this.version = version;
}
/**
* Custom deserialization. We need to re-initialize a logger instance as loggers
* can't be serialized.
*/
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
try {
Class type = BusinessObject.class;
Field logger = type.getDeclaredField("logger");
logger.setAccessible(true);
logger.set(this, LogFactory.getLog(type));
logger.setAccessible(false);
} catch (Exception e) {
LogFactory.getLog(this.getClass())
.warn("unable to recover the logger after deserialization: logging statements will cause null pointer exceptions", e);
}
in.defaultReadObject();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy