All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ru.ydn.wicket.wicketconsole.StorageModel Maven / Gradle / Ivy

There is a newer version: 1.3
Show newest version
package ru.ydn.wicket.wicketconsole;

import java.io.Serializable;

import org.apache.wicket.model.IModel;

public class StorageModel implements IModel{
	
	private Serializable serializableValue;
	private transient Object nonSerializableValue;
	private boolean valueWasDefined;
	
	public StorageModel() {
	}
	
	public StorageModel(T value) {
		setObject(value);
	}

	@Override
	public T getObject() {
		if(serializableValue!=null) return (T)serializableValue;
		else if(nonSerializableValue!=null) return (T)nonSerializableValue;
		else {
			if(valueWasDefined) {
				T resurected = resurect();
				if(resurected!=null) setObject(resurected);
				return resurected;
			} else {
				return null;
			}
		}
	}
	
	@Override
	public void setObject(T object) {
		serializableValue = null;
		nonSerializableValue = null;
		if(object instanceof Serializable) {
			serializableValue = (Serializable) object;
		} else {
			nonSerializableValue = object;
		}
		valueWasDefined = object!=null;
	}
	
	private T resurect() {
		return null;
	}
	
	@Override
	public void detach() {
		
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy