ruper2/src/java/core/org/krysalis/ruper2/resource Resource.java,NONE,1.1 ResourceGroup.java,NONE,1.1 ResourceType.java,NONE,1.1 ResourceIdentifier.java,NONE,1.1 ResourceSpecifier.java,NONE,1.1

[email protected]
Newsgroups gmane.comp.krysalis.metamorphosis.cvs
Message-ID <[email protected]>
Update of /cvsroot/metamorphosis/ruper2/src/java/core/org/krysalis/ruper2/resource
In directory sc8-pr-cvs1:/tmp/cvs-serv30481/src/java/core/org/krysalis/ruper2/resource

Added Files:
	Resource.java ResourceGroup.java ResourceType.java 
	ResourceIdentifier.java ResourceSpecifier.java 
Log Message:
Avoid clash with existing Ruper...

--- NEW FILE: Resource.java ---
/*
 * Created on Aug 27, 2003
 */
package org.krysalis.ruper2.resource;

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import org.krysalis.ruper2.protocols.VirtualResourceLocator;
import org.krysalis.ruper2.util.identity.GenericIdentifier;
import org.krysalis.ruper2.util.reference.Referenceable;
import org.krysalis.ruper2.util.select.Selectable;
import org.krysalis.version.Version;
import org.krysalis.version.impl.KrysalisVersion;
import org.krysalis.version.util.debug.DebugUtils;
import org.krysalis.version.util.debug.Dumpable;

/**
 * @author arb_jack
 * 
 * This defines a 'real world' file, e.g. junit-3.8.1.jar and
 * has all the information about it, and where it is.
 * 
 */
public class Resource implements Selectable, Referenceable, Dumpable {

	// What group is this in ?
	private ResourceGroup m_group = null;

	// What is the id and type for this thing?
	private ResourceIdentifier m_identifier = null;
	private ResourceType m_type = null;

	//
	//	Where is this thing?
	//	
	private String m_filename = null;
	private VirtualResourceLocator m_location = null;

	//
	// Optional Information, that might be found on some of
	// these, and we might have extracted it
	//
	private Version m_version = null;

	//:TODO: We want this?
	private String m_extension = null;

	//
	// Construct a Resource
	//
	public Resource(
		String name,
		Version version,
		ResourceType type,
		String filename,
		VirtualResourceLocator location) {

		m_identifier = new ResourceIdentifier(name);
		m_group = new ResourceGroup(m_identifier.getId());
		m_type = type;

		m_filename = filename;
		m_location = location;

		m_version = version;
	}

	//
	// Construct a Resource
	//
	public Resource(Resource other) {

		m_identifier = other.m_identifier;
		m_group = other.m_group;
		m_type = other.m_type;

		m_filename = other.m_filename;
		m_location = other.m_location;

		m_version = other.m_version;
	}

	//
	// Construct a Resource
	//
	public Resource(
		ResourceIdentifier identifier,
		String filename,
		VirtualResourceLocator location) {
		m_identifier = identifier;
		m_group = new ResourceGroup(identifier.getId());

		m_filename = filename;
		m_location = location;
	}

	/**
	 * @return
	 */
	public GenericIdentifier getIdentifier() {
		return m_identifier;
	}

	/**
	 * @return
	 */
	public Version getVersion() {
		return m_version;
	}

	public Object getSelectionObject() {
		return m_identifier;
	}

	public ResourceSpecifier getSpecifier() {
		return new ResourceSpecifier(m_group, m_identifier, m_type, m_version);
	}

	/**
	 * @return
	 */
	public VirtualResourceLocator getLocation() {
		return m_location;
	}
	/**
	 * @return
	 */
	public String getExtension() {
		return m_extension;
	}

	/**
	 * @return
	 */
	public String getFilename() {
		return m_filename;
	}

	/**
	 * @return
	 */
	public ResourceGroup getGroup() {
		return m_group;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	public boolean equals(Object other) {
		boolean equal = true;

		if (other instanceof Resource) {
			Resource otherResource = (Resource) other;

			equal = otherResource.m_identifier.equals(m_identifier);
			equal &= otherResource.m_group.equals(m_group);
			equal &= otherResource.m_type.equals(m_type);

			//:TODO: Same for version and ... ???
		}
		else
			throw new IllegalArgumentException(
				"Not a Resource: " + other.getClass().getName());

		return equal;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	public int hashCode() {
		int hash = 0;

		hash += m_group.hashCode();
		hash += m_identifier.hashCode();
		hash += m_type.hashCode();

		//:TODO: Optional ones..

		return super.hashCode();
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	public String toString() {

		return m_group + "~" + m_identifier;
	}

	public void dump(PrintWriter out, int depth, boolean verbose) {
		String indent = DebugUtils.getIndent(depth);

		out.print(indent);
		out.println("Resource Identifier: " + m_identifier);

		out.print(indent);
		out.println("Resource Type: " + m_type);

		out.print(indent);
		out.println("Resource Group: " + m_group);

		out.print(indent);
		out.println("Resource Filename: " + m_filename);

		out.print(indent);
		out.println("Resource Location: " + m_location);

		if (null != m_version) {
			out.print(indent);
			out.println("Resource Version: " + m_version);
		}
	}
	/**
	 * @return
	 */
	public ResourceType getType() {
		return m_type;
	}

	/**
	 * @param locator
	 */
	public void setLocation(VirtualResourceLocator locator) {
		m_location = locator;
	}

	public static List getTestResourceList(String group, int count) {
		List resourceList = new ArrayList();

		// Populate with some test resources...
		for (int i = 0; i < count; ++i) {
			String name = group + Integer.toString(1 + i);
			resourceList.add(
				Resource.getTestResource(
					name,
					new KrysalisVersion(1, i),
					ResourceType.JAVA_BINARY));
			resourceList.add(
				Resource.getTestResource(
					name,
					new KrysalisVersion(1, i),
					ResourceType.SOURCE_CODE));

			// Add some randomness
		}

		return resourceList;
	}

	public static Resource getTestResource() {
		return getTestResource("test");
	}

	public static Resource getTestResource(String name) {
		return getTestResource(name, ResourceType.JAVA_BINARY);
	}

	public static Resource getTestResource(String name, ResourceType type) {
		return getTestResource(name, new KrysalisVersion(1, 1), type);
	}

	public static Resource getTestResource(
		String name,
		Version version,
		ResourceType type) {
		return new Resource(
			name,
			version,
			type,
			name,
			new VirtualResourceLocator("http://somewhere/" + name));
	}
}

--- NEW FILE: ResourceGroup.java ---
/*
 * Created on Aug 23, 2003
 *
 */
package org.krysalis.ruper2.resource;

/**
 * @author arb_jack
 */
public class ResourceGroup {
	public String m_group = null;

	public ResourceGroup(String group) {
		m_group = group;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	public boolean equals(Object otherGroup) {
		return m_group.equals(((ResourceGroup) otherGroup).m_group);
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	public int hashCode() {
		return m_group.hashCode();
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	public String toString() {
		return m_group;
	}
	/**
	 * @return
	 */
	public String getGroup() {
		return m_group;
	}

	public static ResourceGroup getTestGroup() {
		return getTestGroup("test");
	}

	public static ResourceGroup getTestGroup(String name) {
		return new ResourceGroup(name);
	}
}

--- NEW FILE: ResourceType.java ---
/*
 * Created on Aug 23, 2003
 *
 */
package org.krysalis.ruper2.resource;

import org.krysalis.ruper2.util.identity.GenericNamespace;

/**
 * @author arb_jack
 */
public class ResourceType extends GenericNamespace  {

	public final static ResourceType UNKNOWN =
		new ResourceType("http://krysalis.org/resource/unknown", "unknown");

	public final static ResourceType JAVA_BINARY =
		new ResourceType("http://krysalis.org/resource/java", "java");

	public final static ResourceType SOURCE_CODE =
		new ResourceType("http://krysalis.org/resource/javasrc", "javasrc");

	public final static ResourceType DOCUMENTATION =
		new ResourceType("http://krysalis.org/resource/docs", "docs");

	public ResourceType(String uri, String prefix) {
		super(uri, prefix);
	}

	public static ResourceType getFromString(String typeStr) {
		ResourceType type = ResourceType.UNKNOWN;

		if ((null == typeStr) || ("" == typeStr) || ("java" == typeStr)) {
			type = ResourceType.JAVA_BINARY;
		}
		//:TODO: Hack...
		else if ("src".equals(typeStr)) {
			type = ResourceType.SOURCE_CODE;
		}
		else if ("docs".equals(typeStr)) {
			type = ResourceType.DOCUMENTATION;
		}

		// :TODO: 

		return type;
	}
}

--- NEW FILE: ResourceIdentifier.java ---
/*
 * Created on Aug 23, 2003
 *
 */
package org.krysalis.ruper2.resource;

import org.krysalis.ruper2.util.identity.GenericIdentifier;

/**
 * @author arb_jack
 */
public class ResourceIdentifier extends GenericIdentifier {

	public final static String JAVA_URI = "http://krysalis.org/java";
	public final static String JAVA_PREFIX = "java";

	public ResourceIdentifier(String id) {
		super(JAVA_URI, JAVA_PREFIX, id);
	}
}

--- NEW FILE: ResourceSpecifier.java ---
/*
 * Created on Aug 23, 2003
 *
 */
package org.krysalis.ruper2.resource;

import java.io.PrintWriter;

import org.krysalis.version.Version;
import org.krysalis.version.util.debug.DebugUtils;
import org.krysalis.version.util.debug.Dumpable;

/**
 * @author arb_jack
 */
public class ResourceSpecifier implements Dumpable {
	private ResourceGroup m_group = null;
	private ResourceIdentifier m_identifier = null;
	private ResourceType m_type = null;
	private Version m_version = null;

	public ResourceSpecifier(String name) {
		m_group = new ResourceGroup(name);
		m_identifier = new ResourceIdentifier(name);
		m_type = ResourceType.JAVA_BINARY;
		m_version = null;
	}

	public ResourceSpecifier(
		ResourceGroup group,
		ResourceIdentifier identifier,
		ResourceType type,
		Version version) {
		m_group = group;
		m_identifier = identifier;
		m_type = type;
		m_version = version;
	}
	
	/**
	 * @return
	 */
	public ResourceIdentifier getIdentifier() {
		return m_identifier;
	}

	/**
	 * @return
	 */
	public ResourceType getType() {
		return m_type;
	}

	/**
	 * @param identifier
	 */
	public void setIdentifier(ResourceIdentifier identifier) {
		m_identifier = identifier;
	}

	/**
	 * @param type
	 */
	public void setType(ResourceType type) {
		m_type = type;
	}

	/**
	 * @return
	 */
	public Version getVersion() {
		return m_version;
	}
	
	/**
	 * @return
	 */
	public ResourceGroup getGroup() {
		return m_group;
	}
	
	public void dump(PrintWriter out, int depth, boolean verbose) {
		String indent = DebugUtils.getIndent(depth);

		out.print(indent);
		out.println("Resource Identifier: " + m_identifier);

		out.print(indent);
		out.println("Resource Type: " + m_type);

		out.print(indent);
		out.println("Resource Group: " + m_group);

		if (null != m_version) {
			out.print(indent);
			out.println("Resource Version: " + m_version);
		}
	}
}




-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.