krysalis-viprom/src/java/core2/org/krysalis/viprom Properties.java,NONE,1.1 Aliases.java,NONE,1.1 VirtualProjectModel.java,NONE,1.1 Smoke.java,NONE,1.1

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

Added Files:
	Properties.java Aliases.java VirtualProjectModel.java 
	Smoke.java 
Log Message:
Faking it out w/ core2, will go back to core

--- NEW FILE: Properties.java ---
/*
The Krysalis Patchy Software License, Version 1.1_01

Copyright (c) 2002-2003 Nicola Ken Barozzi.  All rights reserved.

This Licence is compatible with the BSD licence as described and 
approved by http://www.opensource.org/, and is based on the
Apache Software Licence Version 1.1.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

1. Redistributions of source code must retain the above copyright
   notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright
   notice, this list of conditions and the following disclaimer in
   the documentation and/or other materials provided with the
   distribution.

3. The end-user documentation included with the redistribution,
   if any, must include the following acknowledgment:
	  "This product includes software developed for project 
	Krysalis(http : //www.krysalis.org/)."
   Alternately, this acknowledgment may appear in the software itself,
   if and wherever such third-party acknowledgments normally appear.

4. The names "Krysalis" and "Nicola Ken Barozzi" and
   "Krysalis Centipede" must not be used to endorse or promote products
   derived from this software without prior written permission. For
   written permission, please contact [email protected].

5. Products derived from this software may not be called "Krysalis",
   "Krysalis Centipede", nor may "Krysalis" appear in their name, without
	prior written permission of Nicola Ken Barozzi.

6. This software may contain voluntary contributions made by many 
   individuals, who decided to donate the code to this project in respect 
   of this licence.

THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
====================================================================
*/
package org.krysalis.viprom;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;


public class Properties {

	public static final String PROJECT_NAME = "project.name";
	public static final String PROJECT_URL = "project.url";
	public static final String PROJECT_DESCRIPTION = "project.description";
	public static final String PROJECT_PACKAGE = "project.package";

	public static List getPropertyNames() {
		List pnames = new ArrayList();

		Object me = new Properties();
		Class myself = Properties.class;

		Field[] fields = myself.getFields();

		for (int i = 0; i < fields.length; ++i) {
			Field field = fields[i];

			try {
				pnames.add((String) field.get(me));
			}
			catch (Exception e) {
				//Ignore...
			}
		}

		return pnames;
	}
}
--- NEW FILE: Aliases.java ---
/*
The Krysalis Patchy Software License, Version 1.1_01

Copyright (c) 2002-2003 Nicola Ken Barozzi.  All rights reserved.

This Licence is compatible with the BSD licence as described and 
approved by http://www.opensource.org/, and is based on the
Apache Software Licence Version 1.1.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

1. Redistributions of source code must retain the above copyright
   notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright
   notice, this list of conditions and the following disclaimer in
   the documentation and/or other materials provided with the
   distribution.

3. The end-user documentation included with the redistribution,
   if any, must include the following acknowledgment:
	  "This product includes software developed for project 
	Krysalis(http : //www.krysalis.org/)."
   Alternately, this acknowledgment may appear in the software itself,
   if and wherever such third-party acknowledgments normally appear.

4. The names "Krysalis" and "Nicola Ken Barozzi" and
   "Krysalis Centipede" must not be used to endorse or promote products
   derived from this software without prior written permission. For
   written permission, please contact [email protected].

5. Products derived from this software may not be called "Krysalis",
   "Krysalis Centipede", nor may "Krysalis" appear in their name, without
	prior written permission of Nicola Ken Barozzi.

6. This software may contain voluntary contributions made by many 
   individuals, who decided to donate the code to this project in respect 
   of this licence.

THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
====================================================================
*/
package org.krysalis.viprom;

import java.util.HashMap;
import java.util.Map;

public class Aliases {

	/** GUMP-Style Metadata (e.g. module.xml) */
	public static final String GUMP = "Gump";
	/** MAven-Style Metadata (e.g. project.xml) */
	public static final String MAVEN = "Maven";
	/** AntBits-Style... */
	public static final String ANTBITS = "AntBits";

	private static Map l_gump = null;
	private static Map l_maven = null;
	private static Map l_antbits = null;

	static {

		//
		// GUMP Aliasing...
		//
		l_gump = new HashMap();

		// l_gump.put("project.url", "/module/project[@name=$project.name]/url");
		l_gump.put(Properties.PROJECT_URL, "/module/url/@href");
		l_gump.put(
			Properties.PROJECT_PACKAGE,
			"/module/project[@name=$project.name]/package");

		l_gump.put(
			Properties.PROJECT_DESCRIPTION,
			"/module/description");
			
		//
		// Maven Aliasing...
		//
		l_maven = new HashMap();

		l_maven.put(Properties.PROJECT_URL, "/project/url");
		l_maven.put(
			Properties.PROJECT_PACKAGE,
			"/project/package");
			
		l_maven.put(
			Properties.PROJECT_DESCRIPTION,
			"/project/shortDescription");
	}

	public static Map getAliasesFor(String type) {
		Map aliases = null;

		if (GUMP.equalsIgnoreCase(type))
			aliases = l_gump;
		else if (MAVEN.equalsIgnoreCase(type))
			aliases = l_maven;
		else if (ANTBITS.equalsIgnoreCase(type))
			aliases = l_antbits;
		else // Default...
			aliases = l_gump;

		return aliases;
	}
}
--- NEW FILE: VirtualProjectModel.java ---
/*
The Krysalis Patchy Software License, Version 1.1_01

Copyright (c) 2002-2003 Nicola Ken Barozzi.  All rights reserved.

This Licence is compatible with the BSD licence as described and 
approved by http://www.opensource.org/, and is based on the
Apache Software Licence Version 1.1.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

1. Redistributions of source code must retain the above copyright
   notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright
   notice, this list of conditions and the following disclaimer in
   the documentation and/or other materials provided with the
   distribution.

3. The end-user documentation included with the redistribution,
   if any, must include the following acknowledgment:
	  "This product includes software developed for project 
	Krysalis(http : //www.krysalis.org/)."
   Alternately, this acknowledgment may appear in the software itself,
   if and wherever such third-party acknowledgments normally appear.

4. The names "Krysalis" and "Nicola Ken Barozzi" and
   "Krysalis Centipede" must not be used to endorse or promote products
   derived from this software without prior written permission. For
   written permission, please contact [email protected].

5. Products derived from this software may not be called "Krysalis",
   "Krysalis Centipede", nor may "Krysalis" appear in their name, without
	prior written permission of Nicola Ken Barozzi.

6. This software may contain voluntary contributions made by many 
   individuals, who decided to donate the code to this project in respect 
   of this licence.

THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
====================================================================
*/
package org.krysalis.viprom;

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;

import org.apache.commons.jxpath.JXPathContext;
import org.apache.commons.jxpath.PackageFunctions;
import org.apache.commons.jxpath.Variables;
import org.krysalis.version.log.Logger;
import org.krysalis.version.util.debug.DebugUtils;
import org.krysalis.version.util.debug.Dumpable;
import org.w3c.dom.Document;

public class VirtualProjectModel implements Dumpable {

	private JXPathContext m_context;
	private Map m_aliases = null;

	// Keeping track of things...
	private Variables m_variables = null;

	public VirtualProjectModel(Document documentRoot, Map aliases, Variables variables) {
		m_context = JXPathContext.newContext(documentRoot);

		m_aliases = aliases;

		// 
		m_context.setLenient(true);

		// Make user 'properties' available as variables in the viprom
		if (null == variables)
			variables = new EngineVariables();
		m_context.setVariables(variables);
		m_variables = variables;

		//add java.util and java.lang as default function libraries
		m_context.setFunctions(new PackageFunctions("java.util.", "java.util"));
		m_context.setFunctions(new PackageFunctions("java.lang.", "java.lang"));
	}

	// Save a variable...
	public void setValue(String name, Object value) {
		m_context.setValue(name, value);
	}

	// Perform a query
	public List query(String query) {
		List result = new ArrayList();

		Iterator iter = perform(query);

		if (null != iter) {
			for (; iter.hasNext();) {
				result.add(iter.next());
			}
		}

		return result;
	}

	//	Perform a query, returning an iterator
	public Iterator iterate(String query) {
		Iterator iter = perform(query);

		if ((iter == null) || (!iter.hasNext())) {
			Logger.getLogger().verbose(
				"VIPROM unable to resolve '" + query + "'");
			return null;
		}

		return iter;
	}

	//	Perform a query, returning an iterator
	private Iterator perform(String query) {

		String actual = query;

		if (m_aliases.containsKey(query)) {
			actual = (String) m_aliases.get(query);

			Logger.getLogger().verbose(
				"VIPROM '" + query + "' -> XPATH '" + actual + "'");
				
			// SystemUtils.getSystemOut().println(query + " :-> " + actual);

			Iterator iter = m_context.iterate(actual);

			if ((iter == null) || (!iter.hasNext())) {
				Logger.getLogger().verbose(
					"VIPROM unable to resolve ["
						+ query
						+ "] (aliased to '"
						+ actual
						+ "')");
				return null;
			}

			return iter;

		}

		return null;
	}

	public class EngineVariables implements Variables {
		private Properties m_properties = new Properties();

		protected EngineVariables() {
		}

		public void declareVariable(String varName, Object value) {
			Logger.getLogger().verbose(
				"AntVariables - VIPROM: declare '"
					+ varName
					+ "' -> '"
					+ value.toString()
					+ "'");
			m_properties.setProperty(varName, value.toString());
		}
		public Object getVariable(String varName) {
			Object value = m_properties.getProperty(varName);
			Logger.getLogger().verbose(
				"AntVariables - VIPROM: get '"
					+ varName
					+ "' as '"
					+ ((null != value) ? value.toString() : null)
					+ "'");
			return value;
		}
		public boolean isDeclaredVariable(String varName) {
			boolean declared =
				(m_properties.getProperty(varName) == null ? false : true);
			Logger.getLogger().debug(
				"AntVariables - VIPROM: get '" + varName + "' is " + declared);
			return declared;
		}

		public void undeclareVariable(String varName) {
			//:TODO
		}
	}

	public void dump(PrintWriter out, int depth, boolean verbose) {
		final String indent = DebugUtils.getIndent(depth);
	}
}
--- NEW FILE: Smoke.java ---
/*
The Krysalis Patchy Software License, Version 1.1_01

Copyright (c) 2003 Nicola Ken Barozzi.  All rights reserved.

This Licence is compatible with the BSD licence as described and 
approved by http://www.opensource.org/, and is based on the
Apache Software Licence Version 1.1.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

1. Redistributions of source code must retain the above copyright
   notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright
   notice, this list of conditions and the following disclaimer in
   the documentation and/or other materials provided with the
   distribution.

3. The end-user documentation included with the redistribution,
   if any, must include the following acknowledgment:
      "This product includes software developed for project 
       Krysalis (http://www.krysalis.org/)."
   Alternately, this acknowledgment may appear in the software itself,
   if and wherever such third-party acknowledgments normally appear.

4. The names "Krysalis" and "Nicola Ken Barozzi" and
   "Krysalis Centipede" must not be used to endorse or promote products
   derived from this software without prior written permission. For
   written permission, please contact [email protected].

5. Products derived from this software may not be called "Krysalis",
   "Krysalis Centipede", nor may "Krysalis" appear in their name, without
    prior written permission of Nicola Ken Barozzi.

6. This software may contain voluntary contributions made by many 
   individuals, who decided to donate the code to this project in respect 
   of this licence.

THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
====================================================================
*/
package org.krysalis.viprom;

/**
 * Response to can we smoke.
 * @author: $Author: arb_jack $
 * @version: $Revision: 1.1 $
 */
public class Smoke {

    private boolean lamp = false;

    public String smoke() {
        return lamp
            ? "Smoke em if you got em"
            : "Field strip and police your butts";
    }

    /**
     * Returns the lamp.
     * @return boolean
     */
    public boolean isLampLighted() {
        return lamp;
    }

    /**
     * Sets the lamp.
     * @param lamp The lamp to set
     */
    public void setLamp(boolean lamp) {
        this.lamp = lamp;
    }
}




-------------------------------------------------------
This SF.net email is sponsored by: The SF.net Donation Program.
Do you like what SourceForge.net is doing for the Open
Source Community?  Make a contribution, and help us add new
features and functionality. Click here: http://sourceforge.net/donate/
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.