ruper2/src/java/core/org/krysalis/ruper2/util ClassLoaderHelper.java,NONE,1.1 FlagSet.java,NONE,1.1 Flag.java,NONE,1.1 FlagMap.java,NONE,1.1 RuperConstants.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/util
In directory sc8-pr-cvs1:/tmp/cvs-serv30481/src/java/core/org/krysalis/ruper2/util

Added Files:
	ClassLoaderHelper.java FlagSet.java Flag.java FlagMap.java 
	RuperConstants.java 
Log Message:
Avoid clash with existing Ruper...

--- NEW FILE: ClassLoaderHelper.java ---
/*
 * Created on Aug 29, 2003
 *
 */
package org.krysalis.ruper2.util;


/**
 * @author anou_mana
 */
public class ClassLoaderHelper {
	public static ClassLoader getClassLoader() {
		return getClassLoader(null);
	}

	public static ClassLoader getClassLoader(Object caller) {
		ClassLoader cl = null;

		try {
			cl = Thread.currentThread().getContextClassLoader();
		}
		catch (Exception e) {
			cl = null;
		}

		if (null != caller)
			//		Try Object's Loader
			if (null == cl) {
				try {
					cl = caller.getClass().getClassLoader();
				}
				catch (Exception e) {
					cl = null;
				}
			}

		// Try System Loader
		if (null == cl) {
			try {
				cl = ClassLoader.getSystemClassLoader();
			}
			catch (Exception e) {
				cl = null;
			}
		}

		return cl;
	}

	public static Class getClassForName(String name)
		throws ClassNotFoundException, NoClassDefFoundError {
		return Class.forName(name, true, getClassLoader());
	}

}

--- NEW FILE: FlagSet.java ---
/*
 * Created on Aug 26, 2003
 *
 * To change the template for this generated file go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
package org.krysalis.ruper2.util;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

/**
 * @author arb_jack
 */
public class FlagSet extends ArrayList {

	/**
	 * 
	 */
	public FlagSet() {
		super();
	}

	/**
	 * @param arg0
	 */
	public FlagSet(int initialSize) {
		super(initialSize);
	}

	/**
	 * @param otherCollection -- set to copy from
	 */
	public FlagSet(Collection otherCollection) {
		super(otherCollection);
	}

	/**
	* Determines if this set has a particular capability.
	*
	* @param capability The capability to check for.
	*/
	public boolean hasFlag(Flag flag) {
		boolean hasIt = false;
		for (Iterator i = iterator(); i.hasNext() && !hasIt;) {
			hasIt = ((Flag) i.next()).equals(flag);
		}
		return hasIt;
	}

	/**
	* Determines if this set has a particular set of flag.
	*
	* @param flag The capabilities to check for.
	*/
	public boolean hasCapabilities(FlagSet capabilities) {
		boolean hasEm = true;

		for (Iterator i = capabilities.iterator(); i.hasNext() && hasEm;) {
			hasEm &= hasFlag((Flag) i.next());
		}

		return hasEm;
	}
}

--- NEW FILE: Flag.java ---
/*
 * Created on Aug 26, 2003
 *
 * To change the template for this generated file go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
package org.krysalis.ruper2.util;

/**
 * @author arb_jack
 */
public class Flag {
	private final String m_name;

	public final static Flag TRUE = new Flag("TRUE");
	public final static Flag FALSE = new Flag("FALSE");

	protected Flag(final String name) {
		m_name = name;
	}

	public String toString() {
		return m_name;
	}

	public boolean equals(Object other) {
		boolean equal = false;

		if (other instanceof Flag) {
			equal = m_name.equals(((Flag) other).m_name);
		}
		else
			throw new IllegalArgumentException("Not a Flag: " + other);

		return equal;
	}

	public int hashCode() {
		return m_name.hashCode();
	}
}

--- NEW FILE: FlagMap.java ---
/*
 * Created on Aug 26, 2003
 *
 * To change the template for this generated file go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
package org.krysalis.ruper2.util;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

/**
 * @author arb_jack
 */
public class FlagMap extends HashMap {

	/**
	 * 
	 */
	public FlagMap() {
		super();
	}

	/**
	 * @param arg0
	 */
	public FlagMap(int initialSize) {
		super(initialSize);
	}

	/**
	* Determines if this set has a particular capability.
	*
	* @param capability The capability to check for.
	*/
	public boolean hasFlag(Flag flag) {
		return containsKey(flag);
	}

	/**
	* Determines if this set has a particular set of flag.
	*
	* @param flag The capabilities to check for.
	*/
	public boolean hasFlags(List flags) {
		boolean hasEm = true;

		for (Iterator i = flags.iterator(); i.hasNext() && hasEm;) {
			hasEm &= hasFlag((Flag) i.next());
		}

		return hasEm;
	}
}

--- NEW FILE: RuperConstants.java ---
/*
 * Created on Aug 28, 2003
 */
package org.krysalis.ruper2.util;

import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import org.krysalis.ruper2.protocols.VirtualResourceLocator;

/**
 * @author arb_jack
 */
public class RuperConstants {
	public final static List EMPTY_LIST = new ArrayList();

	public final static String DEFAULT_CONFIG_XML = "ruper.xml";

	public final static String STANDARD = "standard";
	public final static String DEFAULT = "default";
	public final static String UNNAMED = "unnamed";
	
	public final static String RUPER_HOME = "http://www.krysalis.org/ruper/";
	
	// Repository locations
	public final static String KRYSALIS_LOCATION = "http://www.krysalis.org/library/projects/";
	public final static String MAVEN_LOCATION = "http://www.ibiblio.org/maven/";

	// selector/comparator
	public final static String SELECTOR = "SELECTOR";
	public final static String COMPARATOR = "COMPARATOR";

	// :TODO: How can I make these final?  -- probably don't need this, it should be in xml
	public static URL MAVEN_URL;
	static {
		try {
			MAVEN_URL = new URL(MAVEN_LOCATION);
		}
		catch (Exception e) {
			e.printStackTrace(System.err);
		}
	}
	
	// :TODO: How can I make these final?
	public static VirtualResourceLocator MAVEN_VRL;
	static {
		try {
			MAVEN_VRL = new VirtualResourceLocator(MAVEN_LOCATION);
		}
		catch (Exception e) {
			e.printStackTrace(System.err);
		}
	}
	
	// :TODO: How can I make these final?
	public static VirtualResourceLocator KRYSALIS_VRL;
	static {
		try {
			KRYSALIS_VRL = new VirtualResourceLocator(KRYSALIS_LOCATION);
		}
		catch (Exception e) {
			e.printStackTrace(System.err);
		}
	}
}




-------------------------------------------------------
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.