[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: building an object model of a XML schema

  • From: Paul Cody Johnston <pcj@i...>
  • To: Jeff Lowery <jlowery@s...>
  • Date: Mon, 16 Jul 2001 01:51:51 -0700

xml adt
* Jeff Lowery (jlowery@s...) wrote:
> > I'm going to go out on a limb here (except I'm in good 
> > company) and claim
> > that if there is no interface, there IS NO type so far as O-O 
> > is concerned.
> 
> What about primitive datatypes? Are they not types? I'm not sure how you
> would classify C struct-like classes in C++ (struct is a class in C++,
> remember). But I get your drift.
> 

Primitive datatypes are definitely types, and they have an interface.
The interface in Java for an int is that you can access one, do
arithmetic on them, and cast them to other primitive datatype.  But
the interface is built into the compiler (and runtime).

> 
> I think a class has three parts, data, interface, and implementation. It's
> the implentation I seek  to address. Performance, for example, is not
> expressed in data or in the interface, although if I was calling push() and
> pop() I might think I was using a stack, but it could be deque.
> 

<snip>

> 
> The sword that this whole concept is likely to fall on is whether or not a
> fairly simple set of behavioral archetypes is sufficient for tweaking
> generated classes so that data is dealt with efficiently. 

This statement needs an example.  How does a behavioral archetype get
used to by some processor / generator?

Another issue
> occurs to me too, and that is the adjustment of data "graininess" from the
> application standpoint. For example, if I have:
> 
> 	<point unit="mm">
> 		<x>23.3</x>
> 		<y>42.0</y>
> 	</point>
> 
> I probably don't want to generate a class such as:
> 
> class Point
> {
> 	String m_unit;
> 	double m_x;
> 	double m_y;
> 
> 	double getX();
> 	double getY();
> 	String getUnit();
> 	
> 	void setX( double x );
> 	void setY( double y );
> 	void setUnit( String unit );
> };
> 
> I would like to see generated a setPoint(double x, double y, String unit)
> method, also, for convenience. Two ways of doing this: one is to use the
> generated classes as bases for higher-level classes that have convenience
> methods such as the one just mentioned. The other is to somehow tweak the
> data model with additional information to indicate that x, y, and unit
> should have a common set() method in addition to those automatically
> generated.
> 

Just thinking out loud, but this is how I could imagine this being
implemented.

(1) Create a new namespace to be used for prefixing special
    attributes.  These special attributes are used to pass hints to
    the generator tool.

(2) Write a generator tool that looks for those "special" attributes
    in a XML schema (or elsewhere perhaps) to generate interfaces /
    classes based on the schema and hints.

Example namespace: adt (abstract data type)

Potential things you might want to say to the generator:

adt:isType = "true"|"false"

 Should this element be represented as a class (or equivalent)?

adt:typenamePrefix = "My"

 Override prefix class naming

adt:typename = "MyClassName"

 Override class naming altogether

adt:isMember = "true"|"false"

 Should this `thing' be a data member of the generated class(es)?

adt:hasAccessor = "true"|"false"

 Should the `thing' have a get method?

adt:hasMutator = "true"|"false"

 Should the `thing' have a set method?

adt:getMethodPrefix = "xxx"
adt:setMethodPrefix = "yyy"

 To override the default generator set and set prefixes.

atd:getMethodName = "xxx"
adt:setMethodName = "yyy"

 To override the default generator set and set names completely.

Those are obvious ones.  Other things that would take more thought:

adt:mutator "x y"

 Assuming two properties 'x' and 'y', create a method like:

 public void setXY(int x, int y) {
     setX(x); setY(y);
 }

Content models are obviously regular expressions that define what
kinds of things can be seen in a particular sequence.  Often times a
content model is "simple"; it is easy to disassemble the regular
expression at concatentation points.  For example:

 <!ELEMENT customer (name, address, transaction*)>

So this is easy to map to a class having methods like:

 Name setName
 Address setAddress
 List getTransactions
 void addTransaction
 void removeTransaction
 ...

Therefore, you could hint on a XML Schema particle element that the
List type of transactions should be of a particular type:

adt:collection = "list, linked-list, array-list, array"

Anyhow, you get the picture.  At any rate, I would think this
resembles both Castor and JAXB, and any other mapping technology.
This issues that are going to creep in to any effort are:

(1) Generality comes at the price of specificity.  If your tool is
    general, people may not want to use it if a better tool exists in
    the language they're interested in (like Castor and JAXB).  Not
    too many people are sophisticated enough or have the need to
    generate implementations in Java, Perl, Python, C++, Ruby, etc all
    at the same time. Be kinda cool though.

(2) Avoiding specificity is hard.  I tried to minimize exposure to
    Java-only stuff in the above example, with poor effect.

(3) Mapping anything, in general, isn't easy, because you're
    essentially trying to patch together things that have different
    ideas and different requirements.

Ok, enough rambling...

Paul

+---------------+---------------+------------------+
| Paul Johnston | pcj@i... | http://inxar.org |
+---------------+---------------+------------------+ 
  

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.