package com.uas.report.axis;

import java.util.Date;
import java.util.List;

public abstract class Resource {

	/**
	 * 更新一次，版本号加1
	 */
	public static final int DEFAULT_VERSION = 1;

	private int version = DEFAULT_VERSION;
	private Date creationDate;
	private Date updateDate;
	private String name;
	private String label;
	private String description;
	private List<Attribute> attributes;
	private String parentUri;
	private String uri;

	public int getVersion() {
		return version;
	}

	public void setVersion(int version) {
		this.version = version;
	}

	public Date getCreationDate() {
		return creationDate;
	}

	public void setCreationDate(Date creationDate) {
		this.creationDate = creationDate;
	}

	public Date getUpdateDate() {
		return updateDate;
	}

	public void setUpdateDate(Date updateDate) {
		this.updateDate = updateDate;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getLabel() {
		return label;
	}

	public void setLabel(String label) {
		this.label = label;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public List<Attribute> getAttributes() {
		return attributes;
	}

	public void setAttributes(List<Attribute> attributes) {
		this.attributes = attributes;
	}

	public String getUri() {
		return uri;
	}

	public void setUri(String uri) {
		this.uri = uri;
	}

	public String getParentUri() {
		return parentUri;
	}

	public void setParentUri(String parentUri) {
		this.parentUri = parentUri;
	}

	public String getURIString() {
		if (uri == null) {
			StringBuffer sb = new StringBuffer();
			if (getParentUri() != null && !getParentUri().equals(Folder.SEPARATOR))
				sb.append(getParentUri());
			sb.append(Folder.SEPARATOR);
			if (getName() != null && !getName().equals(Folder.SEPARATOR))
				sb.append(getName());
			uri = sb.toString();
		}
		return uri;
	}

	public String getResourceType() {
		return getImplementingItf().getName();
	}

	protected abstract Class<?> getImplementingItf();

	@Override
	public String toString() {
		return "Resource [version=" + version + ", creationDate=" + creationDate + ", updateDate=" + updateDate
				+ ", name=" + name + ", label=" + label + ", description=" + description + ", attributes=" + attributes
				+ ", folderUri=" + parentUri + ", uri=" + uri + "]";
	}

}
