ruper2/src/java/core/org/krysalis/ruper/util/xml XMLAttribute.java,NONE,1.1 XMLGrouperElement.java,1.1,1.2 XMLTagConstants.java,1.2,1.3 XMLEntryTable.java,1.8,1.9 XMLHandler.java,1.9,1.10

[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-serv8991/src/java/core/org/krysalis/ruper/util/xml

Modified Files:
	XMLGrouperElement.java XMLTagConstants.java XMLEntryTable.java 
	XMLHandler.java 
Added Files:
	XMLAttribute.java 
Log Message:
split the configXML from the general XML

The child add from the XML and the attributes for the RepositoryAttribute
tested

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

/**
 * @author anou_mana
 */
public interface XMLAttribute {

}

Index: XMLGrouperElement.java
===================================================================
RCS file: /cvsroot/metamorphosis/ruper2/src/java/core/org/krysalis/ruper/util/xml/XMLGrouperElement.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** XMLGrouperElement.java	9 Sep 2003 20:54:40 -0000	1.1
--- XMLGrouperElement.java	12 Sep 2003 15:19:42 -0000	1.2
***************
*** 9,12 ****
--- 9,13 ----
  public class XMLGrouperElement
  {
+ 	public static final String XML_GROUPER_ELEMENT_CLASSNAME = XMLGrouperElement.class.getName();
  
  	/**

Index: XMLTagConstants.java
===================================================================
RCS file: /cvsroot/metamorphosis/ruper2/src/java/core/org/krysalis/ruper/util/xml/XMLTagConstants.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** XMLTagConstants.java	10 Sep 2003 21:19:37 -0000	1.2
--- XMLTagConstants.java	12 Sep 2003 15:19:42 -0000	1.3
***************
*** 16,23 ****
  	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";
  
  	// Attributes
--- 16,23 ----
  	public final static String PROPERTY_XML_TAG = "property";
  	public final static String REPOSITORY_TAG = "repository";
! 	public final static String REPOSITORY_URL_TAG = "repository.url";
! 	public final static String REPOSITORY_ACTIVE_TAG = "repository.active";
! 	public final static String REPOSITORY_REMOTE_TAG = "repository.remote";
! 	public final static String REPOSITORYSET_TAG = "repositoryset";
  
  	// Attributes

Index: XMLEntryTable.java
===================================================================
RCS file: /cvsroot/metamorphosis/ruper2/src/java/core/org/krysalis/ruper/util/xml/XMLEntryTable.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** XMLEntryTable.java	11 Sep 2003 16:29:58 -0000	1.8
--- XMLEntryTable.java	12 Sep 2003 15:19:42 -0000	1.9
***************
*** 10,16 ****
   * @author anou_mana
   */
! public class XMLEntryTable
  {
! 	private HashMap m_entryToClassMap = new HashMap();
  
  	/**
--- 10,16 ----
   * @author anou_mana
   */
! public class XMLEntryTable 
  {
! 	protected HashMap m_entryToClassMap = new HashMap();
  
  	/**
***************
*** 20,24 ****
  	{
  		super();
- 		this.m_entryToClassMap.put(XMLTagConstants.CONFIG_TAG, XMLTagConstants.XML_GROUPER_ELEMENT);
  	}
  
--- 20,23 ----
***************
*** 31,35 ****
  	public void put(String entry, String className) throws Exception
  	{
- 		//Class clazz = ClassLoaderHelper.getClassForName(className);
  		this.m_entryToClassMap.put(entry, className);
  	}
--- 30,33 ----

Index: XMLHandler.java
===================================================================
RCS file: /cvsroot/metamorphosis/ruper2/src/java/core/org/krysalis/ruper/util/xml/XMLHandler.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** XMLHandler.java	11 Sep 2003 19:56:18 -0000	1.9
--- XMLHandler.java	12 Sep 2003 15:19:42 -0000	1.10
***************
*** 67,71 ****
  					// if it is the XMLGrouperElement
  					if (!clazzName
! 						.equals(XMLTagConstants.XML_GROUPER_ELEMENT)) {
  						Object currentTagObject = null;
  						Class clazz =
--- 67,72 ----
  					// if it is the XMLGrouperElement
  					if (!clazzName
! 						.equals(
! 							XMLGrouperElement.XML_GROUPER_ELEMENT_CLASSNAME)) {
  						Object currentTagObject = null;
  						Class clazz =
***************
*** 123,127 ****
  
  						//set the attributes
! 						setObjectAttributes(tagId, currentTagObject, attributes);
  
  						// add this to stack and the created objects
--- 124,128 ----
  
  						//set the attributes
! 						setObjectAttributes(tag, currentTagObject, attributes);
  
  						// add this to stack and the created objects
***************
*** 161,169 ****
  		throws Exception {
  		Object childObject = null;
! 		String childName = childClass.getName();
  		int index = childName.lastIndexOf(".");
  		if (index != -1) {
  			childName = childName.substring(index + 1, childName.length());
! 		}
  
  		// introspect to see if there is a method with this childName
--- 162,170 ----
  		throws Exception {
  		Object childObject = null;
! 		/*String childName = childClass.getName();
  		int index = childName.lastIndexOf(".");
  		if (index != -1) {
  			childName = childName.substring(index + 1, childName.length());
! 		}*/
  
  		// introspect to see if there is a method with this childName
***************
*** 178,182 ****
  
  			if (parameters.length == 3
- 				&& childClass.equals(returnType)
  				&& methodName.startsWith("createChild")) {
  				childObject =
--- 179,182 ----
***************
*** 188,192 ****
  				Logger.getLog().debug(
  					"Child :"
! 						+ childName
  						+ " is set, for the Parent "
  						+ clazz.getName());
--- 188,192 ----
  				Logger.getLog().debug(
  					"Child :"
! 						+ childClass.getName()
  						+ " is set, for the Parent "
  						+ clazz.getName());
***************
*** 201,205 ****
  	private boolean setMethods(
  		Object tagObject,
! 		String attributeName,
  		Object attributeValue)
  		throws Exception {
--- 201,205 ----
  	private boolean setMethods(
  		Object tagObject,
! 		Object attribute,
  		Object attributeValue)
  		throws Exception {
***************
*** 208,211 ****
--- 208,219 ----
  		Method[] methods = clazz.getMethods();
  		boolean attributeSet = false;
+ 		String attributeName = null;
+ 
+ 		if (attribute instanceof String) {
+ 			attributeName = (String) attribute;
+ 		}
+ 		else {
+ 			attributeName = getClassNameWithoutPackage(attribute);
+ 		}
  
  		for (int i = 0; i < methods.length; i++) {
***************
*** 216,221 ****
  
  			// check of setXyz(Class) pattern
! 			if (parameters.length == 1
! 				&& java.lang.Void.TYPE.equals(returnType)
  				&& methodName.startsWith("set")) {
  				// remove the set from the method name 
--- 224,228 ----
  
  			// check of setXyz(Class) pattern
! 			if (java.lang.Void.TYPE.equals(returnType)
  				&& methodName.startsWith("set")) {
  				// remove the set from the method name 
***************
*** 223,228 ****
  				// compare it with attribute name
  				if (tmp.equalsIgnoreCase(attributeName)) {
- 					method.invoke(tagObject, new Object[] { attributeValue });
  
  					// log it 
  					Logger.getLog().debug(
--- 230,244 ----
  				// compare it with attribute name
  				if (tmp.equalsIgnoreCase(attributeName)) {
  
+ 					if (parameters.length == 1) {
+ 						method.invoke(
+ 							tagObject,
+ 							new Object[] { attributeValue });
+ 					}
+ 					else if (parameters.length == 2) {
+ 						method.invoke(
+ 							tagObject,
+ 							new Object[] { attribute, attributeValue });
+ 					}
  					// log it 
  					Logger.getLog().debug(
***************
*** 238,242 ****
  	}
  
! 	private void setObjectAttributes(String tagId, Object tagObject, Attributes attributes)
  		throws Exception {
  		// introspect to see if there is a method with this attribute Name
--- 254,261 ----
  	}
  
! 	private void setObjectAttributes(
! 		String tag,
! 		Object tagObject,
! 		Attributes attributes)
  		throws Exception {
  		// introspect to see if there is a method with this attribute Name
***************
*** 247,291 ****
  			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) {
--- 266,313 ----
  			String attributeName = attributes.getLocalName(j);
  			Object attributeValue = attributes.getValue(j);
! 			Object attribute = attributeName;
  			// 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(
! 						tag + "." + 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,
! 							attributeName,
! 							null);
  
! 					if (objectAttributeValue != null) {
! 						if (!(objectAttributeValue instanceof XMLAttribute)) {
! 							objectAttributeValue =
! 								ReferenceManager.createObject(
! 									attributeClass,
! 									(String) attributeValue,
! 									null);
! 
! 							attributeValue = objectAttributeValue;
  
+ 						}
+ 						else {
+ 							attribute = objectAttributeValue;
+ 						}
+ 					}
+ 				}
  				// invoke the setMethod if Found 
  				boolean attributeSet =
! 					setMethods(tagObject, attribute, attributeValue);
  
  				if (!attributeSet) {
***************
*** 300,303 ****
--- 322,338 ----
  	}
  
+ 	private String getClassNameWithoutPackage(Object object) {
+ 		return getClassNameWithoutPackage(object.getClass().getName());
+ 	}
+ 
+ 	private String getClassNameWithoutPackage(String pkgClassName) {
+ 		int index = pkgClassName.lastIndexOf(".");
+ 		if (index != -1) {
+ 			pkgClassName =
+ 				pkgClassName.substring(index + 1, pkgClassName.length());
+ 		}
+ 		return pkgClassName;
+ 
+ 	}
  	/**
  	 * Sets the locator in the project helper for future reference.
***************
*** 325,329 ****
  		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();
--- 360,365 ----
  		String clazzName = (String) m_xmlEntryTable.get(name);
  		// if it is the XMLGrouperElement
! 		if (!clazzName
! 			.equals(XMLGrouperElement.XML_GROUPER_ELEMENT_CLASSNAME)) {
  			// 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.