Update of /cvsroot/metamorphosis/ruper2/src/java/core/org/krysalis/ruper/util/xml
In directory sc8-pr-cvs1:/tmp/cvs-serv14844/src/java/core/org/krysalis/ruper/util/xml
Modified Files:
XMLHandler.java
Log Message:
attribute object handling added - needs testing
Index: XMLHandler.java
===================================================================
RCS file: /cvsroot/metamorphosis/ruper2/src/java/core/org/krysalis/ruper/util/xml/XMLHandler.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** XMLHandler.java 10 Sep 2003 21:19:36 -0000 1.8
--- XMLHandler.java 11 Sep 2003 19:56:18 -0000 1.9
***************
*** 19,24 ****
* @author anou_mana
*/
! public class XMLHandler extends DefaultHandler
! {
private Stack m_tagObjectStack = new Stack();
--- 19,23 ----
* @author anou_mana
*/
! public class XMLHandler extends DefaultHandler {
private Stack m_tagObjectStack = new Stack();
***************
*** 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;
}
--- 27,41 ----
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;
}
***************
*** 50,69 ****
String qname,
Attributes attributes)
! throws SAXParseException
! {
! try
! {
! if (tag.equals(XMLTagConstants.PROPERTY_XML_TAG))
! {
// add the property to the xmlEntryTable
setAttributesToEntryTable(attributes);
}
! else
! {
// handle the case where the class is different from the one in xmltable
! String classAttributeName = attributes.getValue(XMLTagConstants.XML_CLASS_ATTRIBUTE);
! if(classAttributeName != null && !classAttributeName.equals(""))
! m_xmlEntryTable.put(tag, classAttributeName);
!
// find out if the tag - class is defined in the XMLEntryTable
String clazzName = (String) m_xmlEntryTable.get(tag);
--- 46,63 ----
String qname,
Attributes attributes)
! throws SAXParseException {
! try {
! if (tag.equals(XMLTagConstants.PROPERTY_XML_TAG)) {
// add the property to the xmlEntryTable
setAttributesToEntryTable(attributes);
}
! else {
// handle the case where the class is different from the one in xmltable
! String classAttributeName =
! attributes.getValue(XMLTagConstants.XML_CLASS_ATTRIBUTE);
! if (classAttributeName != null
! && !classAttributeName.equals(""))
! m_xmlEntryTable.put(tag, classAttributeName);
!
// find out if the tag - class is defined in the XMLEntryTable
String clazzName = (String) m_xmlEntryTable.get(tag);
***************
*** 72,77 ****
if (null != clazzName)
// if it is the XMLGrouperElement
! if (!clazzName.equals(XMLTagConstants.XML_GROUPER_ELEMENT))
! {
Object currentTagObject = null;
Class clazz =
--- 66,71 ----
if (null != clazzName)
// if it is the XMLGrouperElement
! if (!clazzName
! .equals(XMLTagConstants.XML_GROUPER_ELEMENT)) {
Object currentTagObject = null;
Class clazz =
***************
*** 83,88 ****
attributes.getValue(XMLTagConstants.XML_TAG_REF_ID);
! if (tagId == null)
! {
throw new Exception(
"No Id for the xml entry " + tag);
--- 77,81 ----
attributes.getValue(XMLTagConstants.XML_TAG_REF_ID);
! if (tagId == null) {
throw new Exception(
"No Id for the xml entry " + tag);
***************
*** 90,102 ****
//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 \""
--- 83,92 ----
//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 \""
***************
*** 108,125 ****
}
}
! else
! {
// parent is null so call the ref Mgr and create a ref
! currentTagObject = ReferenceManager.createReferenceObject( clazz, tagId, refId);
}
}
! else
! {
// create the object
! currentTagObject = ReferenceManager.createReferenceObject( clazz, tagId, refId);
!
}
! if (currentTagObject == null)
! {
//TODO
String message = "No tagObject " + tag;
--- 98,120 ----
}
}
! else {
// parent is null so call the ref Mgr and create a ref
! currentTagObject =
! ReferenceManager.createReferenceObject(
! clazz,
! tagId,
! refId);
}
}
! else {
// create the object
! currentTagObject =
! ReferenceManager.createReferenceObject(
! clazz,
! tagId,
! refId);
!
}
! if (currentTagObject == null) {
//TODO
String message = "No tagObject " + tag;
***************
*** 128,132 ****
//set the attributes
! setObjectAttributes(currentTagObject, attributes);
// add this to stack and the created objects
--- 123,127 ----
//set the attributes
! setObjectAttributes(tagId, currentTagObject, attributes);
// add this to stack and the created objects
***************
*** 138,143 ****
}
}
! catch (Exception exception)
! {
Logger.getLog().error("XML_BEAN_ERROR", exception);
throw new SAXParseException(
--- 133,137 ----
}
}
! catch (Exception exception) {
Logger.getLog().error("XML_BEAN_ERROR", exception);
throw new SAXParseException(
***************
*** 150,160 ****
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);
!
// add it to the entrytable
this.m_xmlEntryTable.put(attributeName, attributeValue);
--- 144,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);
!
// add it to the entrytable
this.m_xmlEntryTable.put(attributeName, attributeValue);
***************
*** 167,177 ****
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());
}
--- 159,167 ----
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());
}
***************
*** 181,186 ****
Method[] methods = clazz.getMethods();
! for (int i = 0; i < methods.length; i++)
! {
final Method method = methods[i];
final String methodName = method.getName();
--- 171,175 ----
Method[] methods = clazz.getMethods();
! for (int i = 0; i < methods.length; i++) {
final Method method = methods[i];
final String methodName = method.getName();
***************
*** 190,215 ****
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(
! parent,
! new Object[] { childClass, tagId, refId });
! // log it
! Logger.getLog().debug(
! "Child :"
! + childName
! + " is set, for the Parent "
! + clazz.getName());
! // jump out of the loop
! i = methods.length;
! //}
}
}
--- 179,197 ----
if (parameters.length == 3
&& childClass.equals(returnType)
! && methodName.startsWith("createChild")) {
! childObject =
! method.invoke(
! parent,
! new Object[] { childClass, tagId, refId });
! // log it
! Logger.getLog().debug(
! "Child :"
! + childName
! + " is set, for the Parent "
! + clazz.getName());
! // jump out of the loop
! i = methods.length;
}
}
***************
*** 221,226 ****
String attributeName,
Object attributeValue)
! throws Exception
! {
// introspect to see if there is a method with this attribute Name
Class clazz = tagObject.getClass();
--- 203,207 ----
String attributeName,
Object attributeValue)
! throws Exception {
// introspect to see if there is a method with this attribute Name
Class clazz = tagObject.getClass();
***************
*** 228,233 ****
boolean attributeSet = false;
! for (int i = 0; i < methods.length; i++)
! {
final Method method = methods[i];
final String methodName = method.getName();
--- 209,213 ----
boolean attributeSet = false;
! for (int i = 0; i < methods.length; i++) {
final Method method = methods[i];
final String methodName = method.getName();
***************
*** 238,248 ****
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 });
--- 218,226 ----
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 });
***************
*** 260,287 ****
}
! 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);
// tag, ref id and class attributes are already handled
! if(attributeName != XMLTagConstants.XML_TAG_ID ||
! attributeName != XMLTagConstants.XML_TAG_REF_ID ||
! attributeName != XMLTagConstants.XML_CLASS_ATTRIBUTE)
! {
!
// invoke the setMethod if Found
boolean attributeSet =
setMethods(tagObject, attributeName, attributeValue);
!
! if (!attributeSet)
! {
Logger.getLog().error(
"Attribute :"
--- 238,293 ----
}
! private void setObjectAttributes(String tagId, 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);
! Object attributeValue = attributes.getValue(j);
// tag, ref id and class attributes are already handled
! if (attributeName != XMLTagConstants.XML_TAG_ID
! || attributeName != XMLTagConstants.XML_TAG_REF_ID
! || attributeName != XMLTagConstants.XML_CLASS_ATTRIBUTE) {
! //check the xmlEntryTable to see if there are any class names
! // for the attributes
! String attributeClassName =
! (String) this.m_xmlEntryTable.get(tagId+"."+attributeName);
!
! Object objectAttributeValue = null;
! if (attributeClassName != null
! && !attributeClassName.equals("")) {
!
! // if there is a class name, load a class
! Class attributeClass = ClassLoaderHelper.getClassForName(attributeClassName);
!
! objectAttributeValue =
! ReferenceManager.createObject(attributeClass, (String) attributeValue, null);
!
! if(objectAttributeValue != null)
! {
! attributeValue = objectAttributeValue;
! }
!
! // find the classname without the pkg and make it the attributename
! int index = attributeClassName.lastIndexOf(".");
! if(index != -1)
! {
! attributeName = attributeClassName.substring(index, attributeClassName.length());
! }
! else
! attributeName = attributeClassName;
! }
!
! // get the classname without the pkg and pass it as attributename
! // for the setmethod
!
// invoke the setMethod if Found
boolean attributeSet =
setMethods(tagObject, attributeName, attributeValue);
!
! if (!attributeSet) {
Logger.getLog().error(
"Attribute :"
***************
*** 293,296 ****
--- 299,303 ----
}
}
+
/**
* Sets the locator in the project helper for future reference.
***************
*** 299,304 ****
* Will not be <code>null</code>.
*/
! public void setDocumentLocator(Locator locator)
! {
m_context.setLocator(locator);
}
--- 306,310 ----
* Will not be <code>null</code>.
*/
! public void setDocumentLocator(Locator locator) {
m_context.setLocator(locator);
}
***************
*** 315,325 ****
*/
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();
--- 321,329 ----
*/
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();
***************
*** 334,339 ****
*/
public void characters(char[] buf, int start, int count)
! throws SAXParseException
! {
}
--- 338,342 ----
*/
public void characters(char[] buf, int start, int count)
! throws SAXParseException {
}
***************
*** 345,350 ****
* @param uri the namespace uri
*/
! public void startPrefixMapping(String prefix, String uri)
! {
m_context.startPrefixMapping(prefix, uri);
}
--- 348,352 ----
* @param uri the namespace uri
*/
! public void startPrefixMapping(String prefix, String uri) {
m_context.startPrefixMapping(prefix, uri);
}
***************
*** 355,360 ****
* @param prefix the prefix that is not mapped anymore
*/
! public void endPrefixMapping(String prefix)
! {
m_context.endPrefixMapping(prefix);
}
--- 357,361 ----
* @param prefix the prefix that is not mapped anymore
*/
! public void endPrefixMapping(String prefix) {
m_context.endPrefixMapping(prefix);
}
***************
*** 362,367 ****
* @return
*/
! public XMLContext getContext()
! {
return m_context;
}
--- 363,367 ----
* @return
*/
! public XMLContext getContext() {
return m_context;
}
***************
*** 370,375 ****
* @return
*/
! public Stack getTagObjectStack()
! {
return m_tagObjectStack;
}
--- 370,374 ----
* @return
*/
! public Stack getTagObjectStack() {
return m_tagObjectStack;
}
***************
*** 378,383 ****
* @return
*/
! public XMLEntryTable getXmlEntryTable()
! {
return m_xmlEntryTable;
}
--- 377,381 ----
* @return
*/
! public XMLEntryTable getXmlEntryTable() {
return m_xmlEntryTable;
}
***************
*** 386,391 ****
* @param context
*/
! public void setContext(XMLContext context)
! {
m_context = context;
}
--- 384,388 ----
* @param context
*/
! public void setContext(XMLContext context) {
m_context = context;
}
***************
*** 394,399 ****
* @param object
*/
! public void setCurrentTagObject(Object object)
! {
m_currentTagObject = object;
}
--- 391,395 ----
* @param object
*/
! public void setCurrentTagObject(Object object) {
m_currentTagObject = object;
}
***************
*** 402,407 ****
* @param stack
*/
! public void setTagObjectStack(Stack stack)
! {
m_tagObjectStack = stack;
}
--- 398,402 ----
* @param stack
*/
! public void setTagObjectStack(Stack stack) {
m_tagObjectStack = stack;
}
***************
*** 410,415 ****
* @param table
*/
! public void setXmlEntryTable(XMLEntryTable table)
! {
m_xmlEntryTable = table;
}
--- 405,409 ----
* @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.