/*
 * Created on 25 janv. 2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package org.esupportail.webdavserver.store.uPortal;

import java.util.Calendar;
import java.util.Date;

import org.apache.slide.structure.ObjectNode;

import fr.univrennes1.cri.util.cacheManagement.Cacheable;

/**
 * @author tbellemb
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class CachedObjectNode implements Cacheable, CachedObjectsConstants {

	private ObjectNode objectNode;
	private String uri;
	private Date endOfLife;
	
	public CachedObjectNode(ObjectNode objectNode, String uri, int minutesToLive){
		this.objectNode = objectNode;
		this.uri = uri;
		if (minutesToLive == -1) endOfLife = null;
		else {
			endOfLife = new java.util.Date();
		    java.util.Calendar cal = java.util.Calendar.getInstance();
		    cal.setTime(endOfLife);
		    cal.add(Calendar.MINUTE, minutesToLive);
		    endOfLife = cal.getTime();
		}// if (minutesToLive == -1)
	}// CachedObjectNode
	
	public boolean isExpired() {
		if (endOfLife != null)
		{
			// date of expiration is compared.
			if (endOfLife.before(new java.util.Date()))	return true;
			else return false;
			
		}
		else return false; // This means it lives forever!
	}// isExpired

	public String getIdentifier() {
		return CACHED_OBJECT_NODE+uri;
	}// getIdentifier

	public ObjectNode getObjectNode() {
		return objectNode;
	}

	public String getUri() {
		return uri;
	}
	
	public String toString() {
		return uri+"("+endOfLife+")";
	}
}// CachedObjectNode
