Update of /cvsroot/metamorphosis/ruper2/src/java/core/org/krysalis/ruper/util/xml
In directory sc8-pr-cvs1:/tmp/cvs-serv30114/src/java/core/org/krysalis/ruper/util/xml
Modified Files:
XMLEntryTable.java XMLHandler.java
Added Files:
XMLTagConstants.java
Log Message:
simple ruper.xml working
--- NEW FILE: XMLTagConstants.java ---
/*
* Created on Sep 10, 2003
*/
package org.krysalis.ruper.util.xml;
/**
* @author anou_mana
*/
public class XMLTagConstants
{
public final static String XML_TAG_ID = "id";
public final static String XML_TAG_REF_ID = "refId";
// XML tags
public final static String CONFIG_TAG = "config";
public final static String PROPERTY_XML_TAG = "property";
public final static String REPOSITORY_TAG = "repository";
// Class names
public final static String XML_GROUPER_ELEMENT = "org.krysalis.ruper.util.xml.XmlGrouperElement";
public final static String DEFAULT_REPOSITORY = "org.krysalis.ruper.repository.DefaultRepository";
/**
*
*/
public XMLTagConstants()
{
super();
// TODO Auto-generated constructor stub
}
public static void main(String[] args)
{
}
}
Index: XMLEntryTable.java
===================================================================
RCS file: /cvsroot/metamorphosis/ruper2/src/java/core/org/krysalis/ruper/util/xml/XMLEntryTable.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** XMLEntryTable.java 9 Sep 2003 20:54:40 -0000 1.5
--- XMLEntryTable.java 10 Sep 2003 16:09:37 -0000 1.6
***************
*** 22,25 ****
--- 22,27 ----
{
super();
+ this.m_entryToClassMap.put(XMLTagConstants.CONFIG_TAG, XMLTagConstants.XML_GROUPER_ELEMENT);
+ this.m_entryToClassMap.put(XMLTagConstants.REPOSITORY_TAG, XMLTagConstants.DEFAULT_REPOSITORY);
}
Index: XMLHandler.java
===================================================================
RCS file: /cvsroot/metamorphosis/ruper2/src/java/core/org/krysalis/ruper/util/xml/XMLHandler.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** XMLHandler.java 9 Sep 2003 21:49:05 -0000 1.5
--- XMLHandler.java 10 Sep 2003 16:09:37 -0000 1.6
***************
*** 4,8 ****
package org.krysalis.ruper.util.xml;
- import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.Stack;
--- 4,7 ----
***************
*** 11,16 ****
import org.krysalis.ruper.log.Logger;
import org.krysalis.ruper.util.ClassLoaderHelper;
- import org.krysalis.ruper.util.RuperConstants;
- import org.krysalis.ruper.util.reference.Referenceable;
import org.xml.sax.Attributes;
import org.xml.sax.Locator;
--- 10,13 ----
***************
*** 22,26 ****
* @author anou_mana
*/
! public class XMLHandler extends DefaultHandler {
private Stack m_tagObjectStack = new Stack();
--- 19,24 ----
* @author anou_mana
*/
! public class XMLHandler extends DefaultHandler
! {
private Stack m_tagObjectStack = new Stack();
***************
*** 30,44 ****
private XMLEntryTable m_xmlEntryTable;
! public XMLHandler(XMLContext context) {
m_context = context;
m_xmlEntryTable = new XMLEntryTable();
}
! public XMLHandler(XMLContext context, XMLEntryTable xmlEntryTable) {
m_context = context;
m_xmlEntryTable = xmlEntryTable;
}
! public Object getCurrentTagObject() {
return m_currentTagObject;
}
--- 28,45 ----
private XMLEntryTable m_xmlEntryTable;
! public XMLHandler(XMLContext context)
! {
m_context = context;
m_xmlEntryTable = new XMLEntryTable();
}
! public XMLHandler(XMLContext context, XMLEntryTable xmlEntryTable)
! {
m_context = context;
m_xmlEntryTable = xmlEntryTable;
}
! public Object getCurrentTagObject()
! {
return m_currentTagObject;
}
***************
*** 49,59 ****
String qname,
Attributes attributes)
! throws SAXParseException {
! try {
! if (tag.equals(RuperConstants.PROPERTY_XML_TAG)) {
// add the property to the xmlEntryTable
setAttributesToEntryTable(attributes);
}
! else {
// find out if the tag - class is defined in the XMLEntryTable
String clazzName = (String) m_xmlEntryTable.get(tag);
--- 50,64 ----
String qname,
Attributes attributes)
! throws SAXParseException
! {
! try
! {
! if (tag.equals(XMLTagConstants.PROPERTY_XML_TAG))
! {
// add the property to the xmlEntryTable
setAttributesToEntryTable(attributes);
}
! else
! {
// find out if the tag - class is defined in the XMLEntryTable
String clazzName = (String) m_xmlEntryTable.get(tag);
***************
*** 62,67 ****
if (null != clazzName)
// if it is the XMLGrouperElement
! if (!clazzName
! .equals(RuperConstants.XML_GROUPER_ELEMENT)) {
Object currentTagObject = null;
Class clazz =
--- 67,72 ----
if (null != clazzName)
// if it is the XMLGrouperElement
! if (!clazzName.equals(XMLTagConstants.XML_GROUPER_ELEMENT))
! {
Object currentTagObject = null;
Class clazz =
***************
*** 69,77 ****
String tagId =
! attributes.getValue(RuperConstants.XML_TAG_ID);
String refId =
! attributes.getValue(RuperConstants.XML_TAG_REF_ID);
! if (tagId == null) {
throw new Exception(
"No Id for the xml entry " + tag);
--- 74,83 ----
String tagId =
! attributes.getValue(XMLTagConstants.XML_TAG_ID);
String refId =
! attributes.getValue(XMLTagConstants.XML_TAG_REF_ID);
! if (tagId == null)
! {
throw new Exception(
"No Id for the xml entry " + tag);
***************
*** 79,88 ****
//if there is an object already in the stack, add this as child to it
! if (!m_tagObjectStack.empty()) {
Object parent = this.m_tagObjectStack.peek();
! if (parent != null) {
currentTagObject =
setChild(parent, clazz, tagId, refId);
! if (currentTagObject == null) {
throw new Exception(
"Unexpected child \""
--- 85,97 ----
//if there is an object already in the stack, add this as child to it
! if (!m_tagObjectStack.empty())
! {
Object parent = this.m_tagObjectStack.peek();
! if (parent != null)
! {
currentTagObject =
setChild(parent, clazz, tagId, refId);
! if (currentTagObject == null)
! {
throw new Exception(
"Unexpected child \""
***************
*** 94,113 ****
}
}
! else {
// parent is null so call the ref Mgr and create a ref
! Class[] argumentTypes =
! { java.lang.String.class };
! Constructor idArgument =
! clazz.getConstructor(argumentTypes);
!
! currentTagObject =
! idArgument.newInstance(
! new Object[] { tagId });
!
! ReferenceManager.createReference(
! (Referenceable) currentTagObject);
}
}
! if (currentTagObject == null) {
//TODO
String message = "No tagObject " + tag;
--- 103,120 ----
}
}
! else
! {
// parent is null so call the ref Mgr and create a ref
! currentTagObject = ReferenceManager.createReference( clazz, tagId, refId);
}
}
! else
! {
! // create the object
! currentTagObject = ReferenceManager.createReference( clazz, tagId, refId);
!
! }
! if (currentTagObject == null)
! {
//TODO
String message = "No tagObject " + tag;
***************
*** 126,130 ****
}
}
! catch (Exception exception) {
Logger.getLog().error("XML_BEAN_ERROR", exception);
throw new SAXParseException(
--- 133,138 ----
}
}
! catch (Exception exception)
! {
Logger.getLog().error("XML_BEAN_ERROR", exception);
throw new SAXParseException(
***************
*** 137,142 ****
private void setAttributesToEntryTable(Attributes attributes)
! throws Exception {
! for (int j = 0; j < attributes.getLength(); j++) {
String attributeName = attributes.getLocalName(j);
String attributeValue = attributes.getValue(j);
--- 145,152 ----
private void setAttributesToEntryTable(Attributes attributes)
! throws Exception
! {
! for (int j = 0; j < attributes.getLength(); j++)
! {
String attributeName = attributes.getLocalName(j);
String attributeValue = attributes.getValue(j);
***************
*** 152,160 ****
String tagId,
String refId)
! throws Exception {
Object childObject = null;
String childName = childClass.getName();
int index = childName.lastIndexOf(".");
! if (index != -1) {
childName = childName.substring(index + 1, childName.length());
}
--- 162,172 ----
String tagId,
String refId)
! throws Exception
! {
Object childObject = null;
String childName = childClass.getName();
int index = childName.lastIndexOf(".");
! if (index != -1)
! {
childName = childName.substring(index + 1, childName.length());
}
***************
*** 164,168 ****
Method[] methods = clazz.getMethods();
! for (int i = 0; i < methods.length; i++) {
final Method method = methods[i];
final String methodName = method.getName();
--- 176,181 ----
Method[] methods = clazz.getMethods();
! for (int i = 0; i < methods.length; i++)
! {
final Method method = methods[i];
final String methodName = method.getName();
***************
*** 172,180 ****
if (parameters.length == 3
&& childClass.equals(returnType)
! && methodName.startsWith("create")) {
// remove the set from the method name
! String tmp = methodName.substring(6, methodName.length());
// compare it with attribute name
! if (tmp.equalsIgnoreCase(childName)) {
childObject =
method.invoke(
--- 185,195 ----
if (parameters.length == 3
&& childClass.equals(returnType)
! && methodName.startsWith("createChild"))
! {
// remove the set from the method name
! //String tmp = methodName.substring(6, methodName.length());
// compare it with attribute name
! //if (tmp.equalsIgnoreCase(childName))
! //{
childObject =
method.invoke(
***************
*** 191,195 ****
// jump out of the loop
i = methods.length;
! }
}
}
--- 206,210 ----
// jump out of the loop
i = methods.length;
! //}
}
}
***************
*** 201,205 ****
String attributeName,
Object attributeValue)
! throws Exception {
// introspect to see if there is a method with this attribute Name
Class clazz = tagObject.getClass();
--- 216,221 ----
String attributeName,
Object attributeValue)
! throws Exception
! {
// introspect to see if there is a method with this attribute Name
Class clazz = tagObject.getClass();
***************
*** 207,211 ****
boolean attributeSet = false;
! for (int i = 0; i < methods.length; i++) {
final Method method = methods[i];
final String methodName = method.getName();
--- 223,228 ----
boolean attributeSet = false;
! for (int i = 0; i < methods.length; i++)
! {
final Method method = methods[i];
final String methodName = method.getName();
***************
*** 216,224 ****
if (parameters.length == 1
&& java.lang.Void.TYPE.equals(returnType)
! && methodName.startsWith("set")) {
// remove the set from the method name
String tmp = methodName.substring(3, methodName.length());
// compare it with attribute name
! if (tmp.equalsIgnoreCase(attributeName)) {
method.invoke(tagObject, new Object[] { attributeValue });
--- 233,243 ----
if (parameters.length == 1
&& java.lang.Void.TYPE.equals(returnType)
! && methodName.startsWith("set"))
! {
// remove the set from the method name
String tmp = methodName.substring(3, methodName.length());
// compare it with attribute name
! if (tmp.equalsIgnoreCase(attributeName))
! {
method.invoke(tagObject, new Object[] { attributeValue });
***************
*** 237,246 ****
private void setObjectAttributes(Object tagObject, Attributes attributes)
! throws Exception {
// introspect to see if there is a method with this attribute Name
Class clazz = tagObject.getClass();
Method[] methods = clazz.getMethods();
! for (int j = 0; j < attributes.getLength(); j++) {
String attributeName = attributes.getLocalName(j);
String attributeValue = attributes.getValue(j);
--- 256,267 ----
private void setObjectAttributes(Object tagObject, Attributes attributes)
! throws Exception
! {
// introspect to see if there is a method with this attribute Name
Class clazz = tagObject.getClass();
Method[] methods = clazz.getMethods();
! for (int j = 0; j < attributes.getLength(); j++)
! {
String attributeName = attributes.getLocalName(j);
String attributeValue = attributes.getValue(j);
***************
*** 250,254 ****
setMethods(tagObject, attributeName, attributeValue);
! if (!attributeSet) {
Logger.getLog().error(
"Attribute :"
--- 271,276 ----
setMethods(tagObject, attributeName, attributeValue);
! if (!attributeSet)
! {
Logger.getLog().error(
"Attribute :"
***************
*** 265,269 ****
* Will not be <code>null</code>.
*/
! public void setDocumentLocator(Locator locator) {
m_context.setLocator(locator);
}
--- 287,292 ----
* Will not be <code>null</code>.
*/
! public void setDocumentLocator(Locator locator)
! {
m_context.setLocator(locator);
}
***************
*** 280,288 ****
*/
public void endElement(String uri, String name, String qName)
! throws SAXException {
// find out if the tag - class is defined in the XMLEntryTable
String clazzName = (String) m_xmlEntryTable.get(name);
// if it is the XMLGrouperElement
! if (!clazzName.equals(RuperConstants.XML_GROUPER_ELEMENT)) {
// pop the element out of the stack
this.m_tagObjectStack.pop();
--- 303,313 ----
*/
public void endElement(String uri, String name, String qName)
! throws SAXException
! {
// find out if the tag - class is defined in the XMLEntryTable
String clazzName = (String) m_xmlEntryTable.get(name);
// if it is the XMLGrouperElement
! if (!clazzName.equals(XMLTagConstants.XML_GROUPER_ELEMENT))
! {
// pop the element out of the stack
this.m_tagObjectStack.pop();
***************
*** 297,301 ****
*/
public void characters(char[] buf, int start, int count)
! throws SAXParseException {
}
--- 322,327 ----
*/
public void characters(char[] buf, int start, int count)
! throws SAXParseException
! {
}
***************
*** 307,311 ****
* @param uri the namespace uri
*/
! public void startPrefixMapping(String prefix, String uri) {
m_context.startPrefixMapping(prefix, uri);
}
--- 333,338 ----
* @param uri the namespace uri
*/
! public void startPrefixMapping(String prefix, String uri)
! {
m_context.startPrefixMapping(prefix, uri);
}
***************
*** 316,320 ****
* @param prefix the prefix that is not mapped anymore
*/
! public void endPrefixMapping(String prefix) {
m_context.endPrefixMapping(prefix);
}
--- 343,348 ----
* @param prefix the prefix that is not mapped anymore
*/
! public void endPrefixMapping(String prefix)
! {
m_context.endPrefixMapping(prefix);
}
***************
*** 322,326 ****
* @return
*/
! public XMLContext getContext() {
return m_context;
}
--- 350,355 ----
* @return
*/
! public XMLContext getContext()
! {
return m_context;
}
***************
*** 329,333 ****
* @return
*/
! public Stack getTagObjectStack() {
return m_tagObjectStack;
}
--- 358,363 ----
* @return
*/
! public Stack getTagObjectStack()
! {
return m_tagObjectStack;
}
***************
*** 336,340 ****
* @return
*/
! public XMLEntryTable getXmlEntryTable() {
return m_xmlEntryTable;
}
--- 366,371 ----
* @return
*/
! public XMLEntryTable getXmlEntryTable()
! {
return m_xmlEntryTable;
}
***************
*** 343,347 ****
* @param context
*/
! public void setContext(XMLContext context) {
m_context = context;
}
--- 374,379 ----
* @param context
*/
! public void setContext(XMLContext context)
! {
m_context = context;
}
***************
*** 350,354 ****
* @param object
*/
! public void setCurrentTagObject(Object object) {
m_currentTagObject = object;
}
--- 382,387 ----
* @param object
*/
! public void setCurrentTagObject(Object object)
! {
m_currentTagObject = object;
}
***************
*** 357,361 ****
* @param stack
*/
! public void setTagObjectStack(Stack stack) {
m_tagObjectStack = stack;
}
--- 390,395 ----
* @param stack
*/
! public void setTagObjectStack(Stack stack)
! {
m_tagObjectStack = stack;
}
***************
*** 364,368 ****
* @param table
*/
! public void setXmlEntryTable(XMLEntryTable table) {
m_xmlEntryTable = table;
}
--- 398,403 ----
* @param table
*/
! public void setXmlEntryTable(XMLEntryTable table)
! {
m_xmlEntryTable = table;
}
-------------------------------------------------------
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.