Update of /cvsroot/metamorphosis/krysalis-viprom/src/java/core/org/krysalis/viprom
In directory sc8-pr-cvs1:/tmp/cvs-serv26154/src/java/core/org/krysalis/viprom
Modified Files:
VirtualProjectModel.java
Added Files:
NamedProperties.java StandardQueries.java
Removed Files:
Aliases.java Smoke.java Properties.java
Log Message:
1) Load XSLT from resource (using ClassLoaderContext)
2) Added XSLT for gump (later for gump to viprom cooking)
3) 'Cook' raw metadata via XSLT (into ViPrOM form)
4) Query into cooked prior to raw
5) Allow metedata 'type' to define queries for raw
6) Standard queries into cooked.
--- NEW FILE: NamedProperties.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 NamedProperties {
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 NamedProperties();
Class myself = NamedProperties.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: StandardQueries.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 StandardQueries {
private static Map l_queries = null;
static {
//
// GUMP Aliasing...
//
l_queries = new HashMap();
// l_gump.put("project.url", "/module/project[@name=$project.name]/url");
l_queries.put(NamedProperties.PROJECT_URL, "/module/url/@href");
l_queries.put(
NamedProperties.PROJECT_PACKAGE,
"/module/project[@name=$project.name]/package");
l_queries.put(
NamedProperties.PROJECT_DESCRIPTION,
"/module/description");
// //
// // Maven Aliasing...
// //
// l_maven = new HashMap();
//
// l_maven.put(NamedProperties.PROJECT_URL, "/project/url");
// l_maven.put(
// NamedProperties.PROJECT_PACKAGE,
// "/project/package");
//
// l_maven.put(
// NamedProperties.PROJECT_DESCRIPTION,
// "/project/shortDescription");
}
public static String getStandardQuery(String name)
{
return (String)l_queries.get(name);
}
}
Index: VirtualProjectModel.java
===================================================================
RCS file: /cvsroot/metamorphosis/krysalis-viprom/src/java/core/org/krysalis/viprom/VirtualProjectModel.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** VirtualProjectModel.java 28 Oct 2003 14:19:03 -0000 1.1
--- VirtualProjectModel.java 28 Oct 2003 20:16:02 -0000 1.2
***************
*** 60,64 ****
import java.util.Iterator;
import java.util.List;
- import java.util.Map;
import java.util.Properties;
--- 60,63 ----
***************
*** 69,107 ****
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();
--- 68,137 ----
import org.krysalis.version.util.debug.DebugUtils;
import org.krysalis.version.util.debug.Dumpable;
+ import org.krysalis.version.util.envsafe.ClassLoaderContext;
+ import org.krysalis.viprom.metadata.MetadataModel;
import org.w3c.dom.Document;
public class VirtualProjectModel implements Dumpable {
! private JXPathContext m_raw;
! private JXPathContext m_cooked;
! private MetadataModel m_model = null;
// Keeping track of things...
private Variables m_variables = null;
! public VirtualProjectModel(
! Document documentRoot,
! MetadataModel model,
! Variables variables)
! throws Exception {
! // The 'raw' context
! m_raw = JXPathContext.newContext(documentRoot);
!
! // The metadata model
! m_model = model;
!
! m_cooked =
! JXPathContext.newContext(
! m_model.cook(new ClassLoaderContext(this), documentRoot));
//
! m_raw.setLenient(true);
// Make user 'properties' available as variables in the viprom
if (null == variables)
variables = new EngineVariables();
! m_raw.setVariables(variables);
m_variables = variables;
//add java.util and java.lang as default function libraries
! m_raw.setFunctions(new PackageFunctions("java.util.", "java.util"));
! m_raw.setFunctions(new PackageFunctions("java.lang.", "java.lang"));
}
// Save a variable...
public void setValue(String name, Object value) {
! m_raw.setValue(name, value);
}
// Perform a query
+ public String getProperty(String query) {
+ StringBuffer buffer = new StringBuffer();
+
+ Iterator iter = perform(query);
+
+ if (null != iter) {
+ for (; iter.hasNext();) {
+ if (buffer.length() > 0 )
+ buffer.append(", ");
+ buffer.append(iter.next().toString());
+ }
+ }
+
+ return buffer.toString();
+ }
+
+ // Perform a query
public List query(String query) {
List result = new ArrayList();
***************
*** 134,161 ****
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;
}
--- 164,215 ----
private Iterator perform(String query) {
! String actual = null;
! //
! // Try a standard query against cooked, if available
! //
!
! actual = (String) StandardQueries.getStandardQuery(query);
! if (null != actual) {
!
! Logger.getLogger().verbose("VIPROM '" + query + "' as cooked");
!
! // SystemUtils.getSystemOut().println(query + " :-> " + actual);
!
! Iterator iter = m_cooked.iterate(query);
!
! if ((iter != null) && (iter.hasNext()))
! return iter;
!
! Logger.getLogger().verbose(
! "VIPROM unable to resolve COOKED ["
! + query
! + "] (query '"
! + actual
! + "')");
! }
!
! //
! // Try a non-standard query against raw
! //
! actual = (String) m_model.getQueryForName(query);
! if (null != actual) {
Logger.getLogger().verbose(
"VIPROM '" + query + "' -> XPATH '" + actual + "'");
! // SystemUtils.getSystemOut().println(query + " :-> " + actual);
! Iterator iter = m_raw.iterate(actual);
! if ((iter != null) && (iter.hasNext()))
! return iter;
+ Logger.getLogger().verbose(
+ "VIPROM unable to resolve RAW ["
+ + query
+ + "] (query '"
+ + actual
+ + "')");
}
--- Aliases.java DELETED ---
--- Smoke.java DELETED ---
--- Properties.java DELETED ---
-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive? Does it
help you create better code? SHARE THE LOVE, and help us help
YOU! 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.