Repository /TunedIT/core.jar:org.tunedit.core.ResourceName


Back

No file description

Source code

/*
 *  Copyright (C) 2009 by TunedIT. All rights reserved.
 *
 */
package org.tunedit.core;


/**
 * <p>Represents TunedIT resource name.
 * Can perform some basic <i>syntactical</i> operations on this name,
 * like splitting into "file" and "class" parts.
 * In the future will also perform syntactical validation of the resource name.  
 * </p>
 * <p>Currently, resource name has the following form:</p>
 * <pre>    DIR{/DIR}/FILE[:CLASS] </pre>
 * <p>
 * where <code>DIR{/DIR}/FILE</code> is a "file" part containing full name 
 * of a file (file path) in TunedIT Repository and
 * <code>CLASS</code> is an optional "class" part
 * which contains a fully qualified name of a Java class contained in the file
 * (the file is expected to be a JAR file in such case).
 * If present, the class part is separated from the file part by a colon ":".    
 * </p>
 * 
 * @author Marcin Wojnarski
 *
 */
public class ResourceName {
	
	private String name;

	/**
	 * TODO: check whether the name is a correct TunedIT name.
	 * @param name
	 */
	public ResourceName(String name) throws Exception {
		if(name == null) throw new Exception("Resource name is null");
		this.name = name;
	}

	@Override
	public String toString() {
		return name;
	}

	/** Returns the file part of this resource name, as String. */
	public String getFilePart() {
		if(isFile()) return name; 
		try {
			return name.split(":")[0];
		}
		catch(Exception e) { return null; }		// should not happen
	}

	/** Returns the class part of this resource name or null if there is no class part. */
	public String getClassPart() {
		try {
			return name.split(":")[1];
		}
		catch(Exception e) {
			return null;
		}
	}

	/** Returns true if this ResourceName contains only a file part. */
	public boolean isFile() {
		return !isClass();
	}
	
	/** Returns true if this ResourceName represents a class resource,
	 * i.e., it contains a class part (colon ":" followed by a full class name). */
	public boolean isClass() {
		return name.contains(":");
	}

}

Copyright © 2008-2011 by TunedIT
Design by luksite