[jdom-interest] Architecture advice sought (long)

Sasha Bilton Sasha.Bilton at alisonassociates.com
Fri Jul 27 02:25:43 PDT 2001


Hi, I'm new to this list and I'll apologise straight away for not lurking
for a bit - no excuse, but I'm fired up this morning!

I'm at the early stages of designing an API/Engine that needs to be losely
coupled to data and yet allow easy access to that data. XML is a no brainer
as it also allows me to hand code and import parts of the data set. Also I
want to transform the resulting data set into HTML as well as first pass
validate it using DTD. JDOM is very attractive to me as my experience is
very OO based - i've been craving a XML API like JDOM for some time.

My ideas so far are to extend Element into a class class called MapElement
so that it implements the java.util.Map interface. This works by  making
keys of all sub elements, with their value as the value object. e.g

<creature>
	<name>Oliphant</name>
	<weight>3.2</weight>
	<speed>
		<walking>10</walking>
		<running>30<running>
	</speed>
</creature>

maps out like this

key		object
---		------
name		(String)Oliphant
weight	(String)3.2
speed		(Element)xxx

What this means is that I can do stuff like

	final static String NAME = "name";
	String name = (String)creature.get(NAME); 
	creature.put(NAME,"Sam's Oliphant");

The map interface means I can very easily access sub elements and their
contents. 

I can subclass the MapElement to more specific classes like CreatureElement
that might have getName() and getWeight() and can also contain engine logic
based on the data.

So does that seem reasonable so far? 
Should I use wrapper classes instead of extending them?

Next - should I write a JDOMFactory to produce these subclasses? 

An idea is to take the super element name e.g <creature> and use it with a
class factory to make my CreatureElement rather than plan MapElement - e.g
to take an existing Element and make specialised Element from it...

public Element createNamedElementSpecialisation(Element basicElement)
{
	String superElementName = basicElement.getName();
	String className = "com.eoi.engine."+superElementName+"Element"; 
	//e.g	com.eoi.engine.CreatureElement

	Class c = Class.forName(className); // Create the class object

	Element e = c.newInstance(c); // Create an instance of
CreatureElement

	(MapElement)e.initaliseFromElement(basicElement); //copy this
elements XML to the new class
	
	return e;	// 
} 

I can detach() the old basic Element and null it for eventual garbage
collection, so the extra object count shouldn't be too high. 

Does this sound feasible, does it make sense?

Once again apologise for being such a bore first time out...

Sasha Bilton

 






_________________________________________________________________________

Alison Associates

The information contained in this e-mail and any attached files is intended only for the use of the person(s) to whom it is addressed and may be privileged, confidential and exempt from disclosure under applicable law. The views of the author may not necessarily reflect the views of the Company. If you are not the intended recipient please do not copy or convey this message or any attached files to any other person but delete this message and any attached files and notify us of incorrect receipt via e-mail to mailadmin at alisonassociates.com. 

_____________________________________________________________________
This message has been checked for all known viruses by MessageLabs.



More information about the jdom-interest mailing list