[Idrs-commit] CVS: Idrs/dev/src/net/sourceforge/idrs/deploy/compile RmlCompiler.java,NONE,1.1 Compil
Brought to you by:
bigman921
|
From: Marc B. <big...@us...> - 2002-03-04 23:05:38
|
Update of /cvsroot/idrs/Idrs/dev/src/net/sourceforge/idrs/deploy/compile
In directory usw-pr-cvs1:/tmp/cvs-serv28790/src/net/sourceforge/idrs/deploy/compile
Modified Files:
Compiler.java CompilerState.java RMLHandler.java
Added Files:
RmlCompiler.java
Log Message:
Completed initial xml compilation system
--- NEW FILE: RmlCompiler.java ---
/*
RmlCompiler.java
Copyright (C) 2002 Marc Boorshtein
The contents of this file are subject to the Mozilla Public License Version 1.0 (the License);
you may not use this file except in compliance with the License. You may obtain a copy of the
License at http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific
language governing rights and limitations under the License.
*/
/**
*This class is used to transform and compile an rml page
*/
package net.sourceforge.idrs.deploy.compile;
import net.sourceforge.idrs.core.report.*;
import java.util.*;
import java.io.*;
import org.xml.sax.*;
import org.xml.sax.helpers.*;
import javax.xml.parsers.*;
import net.sourceforge.idrs.deploy.macro.*;
import net.sourceforge.idrs.deploy.compile.*;
/**
*
* @author mlb
* @version
*/
public class RmlCompiler {
IDRSRep rep;
/** Creates new RmlCompiler */
public RmlCompiler(PrintWriter log, String rml, String xmlParser,String schemaSrc, boolean isFile, String rmlNS) throws Exception {
boolean fail;
StringWriter transformOut = new StringWriter();
InputSource in;
CompilerState comp = new CompilerState();
MacroToXML trans = new MacroToXML(xmlParser,schemaSrc,isFile,rmlNS);
log.println("Transformation : ");
try {
trans.setRML(rml);
trans.setWriter(transformOut);
trans.transformToXML();
System.out.println("Transformation Complete!");
fail = false;
}
catch (Exception e) {
fail = true;
e.printStackTrace(log);
}
log.println(transformOut.getBuffer());
log.flush();
if (fail) {
log.println("Translation Failed");
log.flush();
return;
}
try {
StringReader xmlIn = new StringReader(transformOut.getBuffer().toString());
in = new InputSource(xmlIn);
XMLReader parser = XMLReaderFactory.createXMLReader(xmlParser);
parser.setContentHandler(new RMLHandler(comp));
parser.parse(in);
}
catch (Exception ee) {
ee.printStackTrace(log);
}
if (fail) {
log.println("Compilation Failed");
return;
}
log.flush();
rep = comp.getReport();
}
public IDRSRep getReport() {
return rep;
}
}
Index: Compiler.java
===================================================================
RCS file: /cvsroot/idrs/Idrs/dev/src/net/sourceforge/idrs/deploy/compile/Compiler.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** Compiler.java 27 Feb 2002 23:56:31 -0000 1.3
--- Compiler.java 4 Mar 2002 23:05:34 -0000 1.4
***************
*** 41,44 ****
--- 41,45 ----
public void setState(CompilerState state) throws Exception {
this.state = state;
+
}
Index: CompilerState.java
===================================================================
RCS file: /cvsroot/idrs/Idrs/dev/src/net/sourceforge/idrs/deploy/compile/CompilerState.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** CompilerState.java 27 Feb 2002 23:56:31 -0000 1.2
--- CompilerState.java 4 Mar 2002 23:05:34 -0000 1.3
***************
*** 12,15 ****
--- 12,16 ----
import net.sourceforge.idrs.script.*;
import net.sourceforge.idrs.script.embedable.*;
+ import net.sourceforge.idrs.deploy.compile.units.Repeat;
/**
***************
*** 25,29 ****
IDRSRep rep;
HashMap comp_atts;
!
/** Creates new CompilerState */
public CompilerState() {
--- 26,31 ----
IDRSRep rep;
HashMap comp_atts;
! Stack lines;
!
/** Creates new CompilerState */
public CompilerState() {
***************
*** 31,38 ****
nodes = new Stack();
comp_atts = new HashMap();
!
}
/**
*Pushes a new <code>Compiler</code> instance onto the stack
*@param node New <code>Compiler</code> instace
--- 33,69 ----
nodes = new Stack();
comp_atts = new HashMap();
! lines = new Stack();
!
! }
!
! /**
! Pushes a new set of lines onto the stack
! */
! public void pushLines() throws Exception {
! lines.push(new Vector());
! System.out.println("Stack size : " + lines.size());
! }
!
! /**
! *Pops the lines off the stack
! */
! public Vector popLines() {
! Vector vec = (Vector) lines.pop();
! Enumeration e = vec.elements();
! while (e.hasMoreElements()) {
! System.out.println(e.nextElement());
! }
! System.out.println("Stack size : " + lines.size());
! return vec;
}
/**
+ *Peeks at the top of the lines stack
+ */
+ public Vector peekLines() {
+ return (Vector) lines.peek();
+ }
+
+ /**
*Pushes a new <code>Compiler</code> instance onto the stack
*@param node New <code>Compiler</code> instace
***************
*** 41,45 ****
nodes.push(node);
}
!
/**
*Pops current <code>Compiler</code> instance from the stack
--- 72,76 ----
nodes.push(node);
}
!
/**
*Pops current <code>Compiler</code> instance from the stack
***************
*** 48,52 ****
return (Compiler) nodes.pop();
}
!
/**
*Peeks at current <code>Compiler</code> instance from the stack
--- 79,83 ----
return (Compiler) nodes.pop();
}
!
/**
*Peeks at current <code>Compiler</code> instance from the stack
***************
*** 55,59 ****
return (Compiler) nodes.peek();
}
!
/**
*Retrieves the <code>Line</code> currently being worked on
--- 86,90 ----
return (Compiler) nodes.peek();
}
!
/**
*Retrieves the <code>Line</code> currently being worked on
***************
*** 61,74 ****
public Line getCurrentLine() {
if (currentLine == null) {
! this.currentLine = new Line();
}
return this.currentLine;
}
!
/**
*Retrieves the <code>RepeatLine</code> currently being worked on
*/
public RepeatLine getCurrentRepeatLine() {
! return this.currRepLine;
}
--- 92,111 ----
public Line getCurrentLine() {
if (currentLine == null) {
! this.currentLine = new Line();
}
return this.currentLine;
}
!
/**
*Retrieves the <code>RepeatLine</code> currently being worked on
*/
public RepeatLine getCurrentRepeatLine() {
! Repeat rep = (Repeat) this.getFirstInstace(Repeat.class) ;
! if (rep != null) {
! return rep.getRepeatLine();
! }
! else {
! return null;
! }
}
***************
*** 129,156 ****
public void sealLine() {
!
this.currentLine.seal();
!
! if (this.currRepLine != null) {
! this.currRepLine.addLine(this.currentLine);
! }
! else {
! this.rep.getBody().addLine(this.currentLine);
! }
this.currentLine = null;
}
!
public void addRepeatLine(String id, String color1, String color2) throws Exception {
this.currentLine = new RepeatLine(id,color1,color2);
}
!
public void setRepeatLine() {
this.currRepLine.seal();
this.rep.getBody().addLine(this.currRepLine);
this.currRepLine = null;
! }
!
!
/**
*This allows for the setting of the current line
--- 166,189 ----
public void sealLine() {
!
this.currentLine.seal();
! ((Vector) lines.peek()).add(currentLine);
this.currentLine = null;
}
!
! /*
public void addRepeatLine(String id, String color1, String color2) throws Exception {
this.currentLine = new RepeatLine(id,color1,color2);
}
!
public void setRepeatLine() {
+
this.currRepLine.seal();
this.rep.getBody().addLine(this.currRepLine);
this.currRepLine = null;
! }*/
!
!
/**
*This allows for the setting of the current line
***************
*** 160,162 ****
--- 193,215 ----
}
+ /**
+ *Retrieves the first instance of a given class
+ */
+
+ private Object getFirstInstace(Class c) {
+ Object[] objs = nodes.toArray();
+
+ for (int i=0;i<objs.length;i++) {
+ if (c.equals(objs[i].getClass()) ) {
+ return objs[i];
+ }
+ }
+
+ return null;
+ }
+
+ public boolean isLineNull() {
+ return this.currentLine == null;
+ }
+
}
Index: RMLHandler.java
===================================================================
RCS file: /cvsroot/idrs/Idrs/dev/src/net/sourceforge/idrs/deploy/compile/RMLHandler.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** RMLHandler.java 30 Jan 2002 01:43:13 -0000 1.1
--- RMLHandler.java 4 Mar 2002 23:05:35 -0000 1.2
***************
*** 37,45 ****
/** Creates new RMLHandler */
! public RMLHandler() {
classes = new HashMap();
methods = new HashMap();
!
! state = new CompilerState();
isMethodState = new Stack();
}
--- 37,44 ----
/** Creates new RMLHandler */
! public RMLHandler(CompilerState state) {
classes = new HashMap();
methods = new HashMap();
! this.state = state;
isMethodState = new Stack();
}
***************
*** 54,65 ****
*/
public void startElement(String namespaceURI, String localName, String rawName, Attributes atts) throws SAXException {
currBuff = new StringBuffer();
Class compileClass;
Compiler compiler;
!
! String className = RMLHandler.BASE_PACKAGE + getClassName(localName);
!
compileClass = (Class) classes.get(className);
!
if (compileClass == null) {
try {
--- 53,75 ----
*/
public void startElement(String namespaceURI, String localName, String rawName, Attributes atts) throws SAXException {
+ try {
+ System.out.println("Start Element");
+ System.out.println(localName);
+ System.out.println(rawName);
+ }
+ catch (Exception e){}
+
currBuff = new StringBuffer();
Class compileClass;
Compiler compiler;
!
! String className = getClassName(localName);
!
! try {
! System.out.println("Class Name : " + className);
! }catch (Exception e1){}
!
compileClass = (Class) classes.get(className);
!
if (compileClass == null) {
try {
***************
*** 72,95 ****
this.atts = atts;
}
!
if (compileClass != null) {
try {
compiler = (Compiler) compileClass.newInstance();
! state.pushNode(compiler);
! compiler.setAttributes(atts);
compiler.setState(state);
}
catch (Exception e) {
e.printStackTrace(System.out);
}
!
!
}
!
this.isMethodState.push(new Boolean(isMethod));
}
!
}
!
/**
*Executed at the end of a tag, performs the following tasks:<br>
--- 82,112 ----
this.atts = atts;
}
!
if (compileClass != null) {
try {
compiler = (Compiler) compileClass.newInstance();
!
compiler.setState(state);
+ compiler.setAttributes(atts);
+ state.pushNode(compiler);
+ System.out.println("Push Class : " + compiler.getClass());
+
}
catch (Exception e) {
e.printStackTrace(System.out);
}
!
!
}
!
this.isMethodState.push(new Boolean(isMethod));
+ try {
+ System.out.println("Push " + isMethod);
+ }
+ catch (Exception ee){}
}
!
}
!
/**
*Executed at the end of a tag, performs the following tasks:<br>
***************
*** 100,146 ****
*/
public void endElement(String namespaceURI, String localName, String rawName) throws SAXException {
String methodName = getMethodName(localName);
Compiler curr;
!
Class[] paramTypes = {String.class, Attributes.class};
Object[] params = {currBuff.toString(),this.atts};
Method meth;
!
this.isMethod = ((Boolean) this.isMethodState.pop()).booleanValue();
!
if (this.isMethod) {
curr = state.peekNode();
! meth = (Method) this.methods.get(methodName);
!
! if (meth == null) {
try {
meth = curr.getClass().getMethod(methodName,paramTypes);
}
catch (Exception e1) {
! e1.printStackTrace(System.out);
}
!
this.methods.put(methodName,meth);
! }
!
try {
meth.invoke(curr,params);
}
catch (Exception e2) {
! e2.printStackTrace(System.out);
}
}
else {
curr = state.popNode();
! curr.seal();
}
}
!
public void characters(char[] ch, int start, int end) {
for (int i=start;i<start + end;i++) {
! currBuff.append(ch[i]);
}
}
!
/**
*Retrieves the compiled report
--- 117,184 ----
*/
public void endElement(String namespaceURI, String localName, String rawName) throws SAXException {
+ try {
+ System.out.println("End Element");
+ System.out.println(localName);
+ System.out.println(rawName);
+ }
+ catch (Exception e){}
+
String methodName = getMethodName(localName);
Compiler curr;
!
Class[] paramTypes = {String.class, Attributes.class};
Object[] params = {currBuff.toString(),this.atts};
Method meth;
!
this.isMethod = ((Boolean) this.isMethodState.pop()).booleanValue();
! System.out.println("Pop " + this.isMethod);
!
if (this.isMethod) {
curr = state.peekNode();
! System.out.println("Current Class : " + curr.getClass());
! //meth = (Method) this.methods.get(methodName);
!
! //if (meth == null) {
try {
meth = curr.getClass().getMethod(methodName,paramTypes);
}
catch (Exception e1) {
! throw new SAXException(e1);
}
!
this.methods.put(methodName,meth);
! //}
!
try {
+ System.out.println("Curr :" + curr + "!");
+ System.out.println("Params :" + params[0] + "-" + params[1]);
+ System.out.println("Method : " + meth.getName());
+
meth.invoke(curr,params);
}
catch (Exception e2) {
! //e2.printStackTrace(System.out);
! throw new SAXException(e2);
}
}
else {
curr = state.popNode();
! System.out.println("Pop Class : " + curr.getClass());
! try {
! curr.seal();
! }
! catch (Exception e) {
! e.printStackTrace(System.out);
! throw new SAXException(e);
! }
}
}
!
public void characters(char[] ch, int start, int end) {
for (int i=start;i<start + end;i++) {
! currBuff.append(ch[i]);
}
}
!
/**
*Retrieves the compiled report
***************
*** 149,153 ****
return state.getReport();
}
!
/**
*Generates a full class name by capitalizing the first character of the tag and tacking
--- 187,191 ----
return state.getReport();
}
!
/**
*Generates a full class name by capitalizing the first character of the tag and tacking
|