ruper2/src/java/core/org/krysalis/ruper/util/xml XMLGrouperElement.java,NONE,1.1 XMLEntryTable.java,1.4,1.5 XMLHandler.java,1.3,1.4

[email protected]
Newsgroups gmane.comp.krysalis.metamorphosis.cvs
Message-ID <[email protected]>
Update of /cvsroot/metamorphosis/ruper2/src/java/core/org/krysalis/ruper/util/xml
In directory sc8-pr-cvs1:/tmp/cvs-serv12556/src/java/core/org/krysalis/ruper/util/xml

Modified Files:
	XMLEntryTable.java XMLHandler.java 
Added Files:
	XMLGrouperElement.java 
Log Message:
making the xml config to read ruper.xml

--- NEW FILE: XMLGrouperElement.java ---
/*
 * Created on Sep 9, 2003
  */
package org.krysalis.ruper.util.xml;

/**
 * @author anou_mana
 */
public class XMLGrouperElement
{

	/**
	 * 
	 */
	public XMLGrouperElement()
	{
		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.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** XMLEntryTable.java	5 Sep 2003 13:32:42 -0000	1.4
--- XMLEntryTable.java	9 Sep 2003 20:54:40 -0000	1.5
***************
*** 25,42 ****
  
  
! 	public void add(String entry, Class clazz)
  	{
  		this.m_entryToClassMap.put(entry, clazz);
  	}
  	
! 	public void add(String entry, String className) throws Exception
  	{
! 		Class clazz = ClassLoaderHelper.getClassForName(className);
! 		this.m_entryToClassMap.put(entry, clazz);
  	}
  	
! 	public Class getClass(String entry)
  	{
! 		return (Class)this.m_entryToClassMap.get(entry);
  	}
  }
--- 25,47 ----
  
  
! 	public void put(String entry, Class clazz)
  	{
  		this.m_entryToClassMap.put(entry, clazz);
  	}
  	
! 	public void put(String entry, String className) throws Exception
  	{
! 		//Class clazz = ClassLoaderHelper.getClassForName(className);
! 		this.m_entryToClassMap.put(entry, className);
  	}
  	
! 	public Object get(String entry)
  	{
! 		return this.m_entryToClassMap.get(entry);
! 	}
! 	
! 	public Object getClass(String entry)
! 	{
! 		return this.m_entryToClassMap.get(entry);
  	}
  }

Index: XMLHandler.java
===================================================================
RCS file: /cvsroot/metamorphosis/ruper2/src/java/core/org/krysalis/ruper/util/xml/XMLHandler.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** XMLHandler.java	5 Sep 2003 13:32:42 -0000	1.3
--- XMLHandler.java	9 Sep 2003 20:54:40 -0000	1.4
***************
*** 4,11 ****
--- 4,16 ----
  package org.krysalis.ruper.util.xml;
  
+ import java.lang.reflect.Constructor;
  import java.lang.reflect.Method;
  import java.util.Stack;
  
+ import org.krysalis.ruper.impl.ReferenceManager;
  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;
***************
*** 50,111 ****
  		throws SAXParseException
  	{
! 		//TODO  uri
! 		Object currentTagObject = this.m_context.getCreatedTagObject(tag);
! 
! 		// check if the tag object was already created
! 		if (currentTagObject == null)
  		{
! 			// find out if the tag - class is defined in the XMLEntryTable
! 			Class clazz = m_xmlEntryTable.getClass(tag);
! 			if (clazz == null)
  			{
! 				throw new SAXParseException(
! 					"Unexpected element \"" + qname + "\" " + tag,
! 					m_context.getLocator());
  			}
! 			try
  			{
! 				//if there is an object already in the stack, add this as child to it
! 				if (!this.m_tagObjectStack.empty())
  				{
! 					Object parent = this.m_tagObjectStack.pop();
! 					if (parent != null)
  					{
! 						currentTagObject = setChild(parent, clazz);
! 						if (currentTagObject == null)
  						{
! 							throw new SAXParseException(
! 								"Unexpected child \""
! 									+ qname
! 									+ "\" "
! 									+ tag
! 									+ " for the parent element "
! 									+ parent.getClass().getName(),
! 								m_context.getLocator());
  						}
! 						// after setting the child, push it into the stack
! 						this.m_tagObjectStack.push(parent);
  					}
  				}
- 				if(currentTagObject == null)
- 					currentTagObject = clazz.newInstance();
- 
- 				//set the attributes
- 				setObjectAttributes(currentTagObject, attributes);
- 
- 				// add this to stack and the created objects
- 				this.m_tagObjectStack.push(currentTagObject);
- 				this.m_context.putCreatedTagObject(tag, currentTagObject);
- 			}
- 			catch (Exception exception)
- 			{
- 				throw new SAXParseException(
- 					exception.getMessage(),
- 					m_context.getLocator());
  			}
  		}
  	}
! 
! 	private Object setChild( Object parent,	Class childClass )
  		throws Exception
  	{
--- 55,150 ----
  		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);
! 				// if it is the XMLGrouperElement
! 				if( !clazzName.equals(RuperConstants.XML_GROUPER_ELEMENT) )
  				{
! 					Object currentTagObject = null;
! 					Class clazz = ClassLoaderHelper.getClassForName(clazzName);
! 					
! 					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);	
! 					}
! 
! 					//if there is an object already in the stack, add this as child to it
! 					if (!this.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 \""
! 										+ qname
! 										+ "\" "
! 										+ tag
! 										+ " for the parent element "
! 										+ parent.getClass().getName());
! 							}
  						}
! 						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;
! 						throw new Exception(message);
  					}
+ 						
+ 					//set the attributes
+ 					setObjectAttributes(currentTagObject, attributes);
+ 	
+ 					// add this to stack and the created objects
+ 					this.m_tagObjectStack.push(currentTagObject);
+ 					this.m_context.putCreatedTagObject(tag, currentTagObject);
  				}
  			}
  		}
+ 		catch (Exception exception)
+ 		{
+ 			String message = exception.getMessage();	
+ 			Logger.getLog().error(message);
+ 			throw new SAXParseException( message, m_context.getLocator());
+ 		}
+ 		
  	}
! 	
! 	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);
! 		}		
! 	}
! 	
! 	private Object setChild( Object parent,	Class childClass, String tagId, String refId )
  		throws Exception
  	{
***************
*** 130,135 ****
  			Class[] parameters = method.getParameterTypes();
  
! 			// check of setXyz(Class) pattern
! 			if (parameters.length == 0
  				&& childClass.equals(returnType)
  				&& methodName.startsWith("create"))
--- 169,173 ----
  			Class[] parameters = method.getParameterTypes();
  
! 			if (parameters.length == 3
  				&& childClass.equals(returnType)
  				&& methodName.startsWith("create"))
***************
*** 140,144 ****
  				if (tmp.equalsIgnoreCase(childName))
  				{
! 					childObject = method.invoke(parent, new Object[] {});
  
  					// log it 
--- 178,182 ----
  				if (tmp.equalsIgnoreCase(childName))
  				{
! 					childObject = method.invoke(parent, new Object[] {childClass, tagId, refId});
  
  					// log it 
***************
*** 248,253 ****
  		throws SAXException
  	{
! 		// pop the element out of the stack
! 		this.m_tagObjectStack.pop();
  	}
  
--- 286,297 ----
  		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();
! 		}
  	}
  




-------------------------------------------------------
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.