ruper2/src/java/core/org/krysalis/ruper2/impl ResourceUpdaterContextIdentifier.java,NONE,1.1 ResourceUpdaterContext.java,NONE,1.1 ResourceUpdaterIdentifier.java,NONE,1.1 ReferenceManager.java,NONE,1.1 package.html,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/impl
In directory sc8-pr-cvs1:/tmp/cvs-serv30481/src/java/core/org/krysalis/ruper2/impl

Added Files:
	ResourceUpdaterContextIdentifier.java 
	ResourceUpdaterContext.java ResourceUpdaterIdentifier.java 
	ReferenceManager.java package.html 
Log Message:
Avoid clash with existing Ruper...

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

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

/**
 * @author anou_mana
 */
public class ResourceUpdaterContextIdentifier extends GenericIdentifier {

	public final static String RUPER_CONTEXT_URI =
		"http://krysalis.org/ruper/context";
	public final static String RUPER_CONTEXT_PREFIX = "context";

	public ResourceUpdaterContextIdentifier(String id) {
		super(RUPER_CONTEXT_URI, RUPER_CONTEXT_PREFIX, id);
	}
}

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

import java.io.File;

import org.krysalis.ruper2.ResourceUpdaterOptions;
import org.krysalis.ruper2.RuperException;
import org.krysalis.ruper2.log.Logger;
import org.krysalis.ruper2.protocols.DefaultProtocolOperationsManager;
import org.krysalis.ruper2.protocols.ProtocolOperationsManager;
import org.krysalis.ruper2.util.RuperConstants;
import org.krysalis.ruper2.util.identity.GenericIdentifier;
import org.krysalis.ruper2.util.reference.Referenceable;
import org.krysalis.version.util.SystemUtils;

/**
 * @author arb_jack
 */
public class ResourceUpdaterContext implements Referenceable {

	private ResourceUpdaterContextIdentifier m_identifier = null;

	private ProtocolOperationsManager m_protocolManager = null;

	private File m_baseFile = null;

	private Logger m_logger = null;

	private ResourceUpdaterOptions m_options = null;

	public ResourceUpdaterContext(String identifier) {
		m_baseFile = SystemUtils.getCWD();
		initClass(new ResourceUpdaterContextIdentifier(identifier));
	}
	public ResourceUpdaterContext(ResourceUpdaterContextIdentifier identifier) {
		m_baseFile = SystemUtils.getCWD();
		initClass(identifier);
	}

	public ResourceUpdaterContext() {
		m_baseFile = SystemUtils.getCWD();
		initClass(new ResourceUpdaterContextIdentifier(RuperConstants.DEFAULT));
	}

	public ResourceUpdaterContext(File baseFile) {
		m_baseFile = baseFile;
		initClass(new ResourceUpdaterContextIdentifier(RuperConstants.DEFAULT));
	}

	private void initClass(ResourceUpdaterContextIdentifier identifier) {
		m_identifier = identifier;
		m_logger = new Logger(Logger.getLog());
	}

	public static ResourceUpdaterContext getTestContext() {
		ResourceUpdaterContext context = new ResourceUpdaterContext();
		context.setProtocolManager(
			new DefaultProtocolOperationsManager(context));
		return context;
	}

	/**
	 * @return
	 */
	public ProtocolOperationsManager getProtocolManager() {
		return m_protocolManager;
	}

	/**
	 * @param manager
	 */
	public void setProtocolManager(ProtocolOperationsManager manager) {
		m_protocolManager = manager;
	}

	/**
	 * @return
	 */
	public File getBaseFile() {
		return m_baseFile;
	}

	/**
	 * @param file
	 */
	public void setBaseFile(File file) {
		m_baseFile = file;
	}

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

	/**
	 * @return
	 */
	public Logger getLogger() {
		return m_logger;
	}

	public static ResourceUpdaterContext getResourceUpdaterContext(
		ResourceUpdaterContextIdentifier identifier,
		boolean createIfRequired)
		throws RuperException {

		ResourceUpdaterContext context = null;

		if (ReferenceManager.hasReference(identifier)) {
			context =
				(ResourceUpdaterContext) ReferenceManager.getReference(
					identifier);
		}
		else {

			if (!createIfRequired)
				throw new RuperException(
					"Failed to access ResourceUpdaterContext ["
						+ identifier
						+ "]");

			context = new ResourceUpdaterContext(identifier);

			ReferenceManager.createReference(context);

		}

		return context;
	}
}

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

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

/**
 * @author anou_mana
 */
public class ResourceUpdaterIdentifier extends GenericIdentifier {

	public static final String RUPER_URI =
		"http://krysalis.org/ruper";
	public static final String RUPER_PREFIX = "ruper";

	public ResourceUpdaterIdentifier(final String id) {
		super(RUPER_URI, RUPER_PREFIX, id);
	}
}

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

import java.lang.reflect.Constructor;
import java.util.HashMap;
import java.util.Map;

import org.krysalis.ruper2.log.Logger;
import org.krysalis.ruper2.util.identity.GenericIdentifier;
import org.krysalis.ruper2.util.identity.GenericNamespace;
import org.krysalis.ruper2.util.reference.NoSuchReferenceException;
import org.krysalis.ruper2.util.reference.ReferenceTable;
import org.krysalis.ruper2.util.reference.Referenceable;
import org.krysalis.ruper2.util.text.MessageConstants;
import org.krysalis.ruper2.util.text.Messages;
import org.krysalis.version.util.debug.DebugUtils;

/**
 * @author ajack
 */
public final class ReferenceManager
{

	private static Map l_tables = new HashMap();

	//:TODO: Make chainable to support scoping?
	//:TODO: If so, add one to ResourceUpdaterContext & keep a global 

	private ReferenceManager()
	{
	}

	public static boolean hasReference(GenericIdentifier identifier)
	{
		boolean hasReference = false;

		GenericNamespace ns = identifier.getNamespace();

		synchronized (l_tables)
		{
			ReferenceTable table = (ReferenceTable) l_tables.get(ns);
			if (null == table)
			{

				hasReference = false;
			}
			else
			{

				hasReference = table.hasReference(identifier);
			}
		}

		return hasReference;
	}

	public static Object getReference(GenericIdentifier identifier)
		throws NoSuchReferenceException
	{
		Object reference = null;

		GenericNamespace ns = identifier.getNamespace();

		synchronized (l_tables)
		{
			ReferenceTable table = (ReferenceTable) l_tables.get(ns);
			if (null == table)
				throw new NoSuchReferenceException(identifier);

			reference = table.getReference(identifier);

			if (null == reference)
				throw new NoSuchReferenceException(identifier);
		}

		return reference;
	}

	public static void createReference(Referenceable referenceable)
	{
		GenericIdentifier identifier = referenceable.getIdentifier();
		GenericNamespace ns = identifier.getNamespace();

		synchronized (l_tables)
		{
			ReferenceTable table = (ReferenceTable) l_tables.get(ns);
			if (null == table)
			{

				table = new ReferenceTable(ns);
				l_tables.put(ns, table);
			}

			table.createReference(referenceable);
		}

	}

	public static Object createObject(
		Class clazz,
		String tagId,
		String refId)
	{
		Object reference = null;
		try
		{
			if(refId == null)
			{
				Class[] argumentTypes = { java.lang.String.class };
				Constructor idArgumentConstructor = clazz.getDeclaredConstructor(argumentTypes);
				idArgumentConstructor.setAccessible(true);
				reference = idArgumentConstructor.newInstance(new Object[] { tagId });
			}
			else
			{
				//TODO clone the object
			}
		}
		catch (Exception exp)
		{
			Logger.getLog().error(
				Messages.getString(MessageConstants.CREATE_OBJECT_ERROR),
				exp);
		}

		return reference;
	}

	public static Object createReferenceObject(
		Class clazz,
		String tagId,
		String refId)
	{
		Object reference = createObject(clazz, tagId, refId);
		//add the object to the reference table
		createReference((Referenceable)reference);
		return reference;
	}

	public static void dump() {
		DebugUtils.dump("References...", l_tables);
	}
}

--- NEW FILE: package.html ---
<body>
<p>The standard Ruper implementation.</p>
</body>



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