• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Castor : The Source Code Generator

 
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I am writting a client component that is responsible for bunding objects to an XML message and the sending the message over the network.
I have a XML schema that I have asked castor to use when genarating source code. This is great I have objects the map to the XML and have validation for free. However I do have one problem with this.
I don't want to expose the generated source to the client. First of all it has a load of mashaling method that will only confuse them. I was planning to put a layer between the generated source and the clent. I tried to reduce the access of the generated source file to default but now the mashelling will not work. I get an Exception:
com.xyz.BreedDescriptor; java.lang.IllegalAccessException: Class org.exolab.castor.xml.util.ClassDescriptorResolverImpl can not access a member of class com.xyz.BreedDescriptor with modifiers "public"
Can anyone suggest a way that I can get my code genarated for me but still not allowing the client to see the classes.
Thanks
Chris
 
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe I am missing something but din't you say you
reduced the visibility to default package access....
So the other packages can't access your classes....
Also, does this code get generated dynamically everytime ( please say no ).
- madhav
 
Chris Harris
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Madhav,
I think you may have misunderstood
The diagram should help:
client app -> my app -> castor's generated code -> xml
I don't want to client to be able to see the generated code directly:
client app -> castor's generated code -> xml
My app will provide the user with a fixed API, that will contain business methods. It will be the responsibility of "my app" to call the correct methods within castor's generated code.
The plan is that when the XML schema changes, which is not very often, I would get castor to generator new code. I would then make the appropriate changes within may app and the client would not need to know any things has changed.
The reason I changed the class access to default was to attempt to stop the client from seeing the generated code. I was then planning to add a few public classes from my app to the same package as the generated code. However due to the way Castor marshals the code, it is not possible to have default classes, well at least I have not got it to work.
I am now thinking of using functionality within Castor that allows you to map to pre-existing classes, instead of using the code generation.
Any thoughts on this?
After all the research is it likely that I will not be using Castor after all. There has been a new requirement. Don't laugh (like I first did):
Need ONE XML binding tool that uses EXACTLY the same source and needs to work on J2SE, J2ME and .net. (I am sure that this is not going to work).
Now I know that .net has J# but that support jdk 1.1.4. Now that is going back some time. I have never using J2ME so I am not sure that what restriction that is going to have.
Any suggestion? Apart from the fact that the person who wrote this requirement is living in a dream land.
Thanks for you help.
Chris.
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Chris Harris:
Need ONE XML binding tool that uses EXACTLY the same source and needs to work on J2SE, J2ME and .net. (I am sure that this is not going to work).
Any suggestion? Apart from the fact that the person who wrote this requirement is living in a dream land.

As there probably is no such tool readily available, you're best bet might be to say, "Sure we can implement this requirement. It'll cost you XXXX man-days because [explain the facts]." If he still wants you to do it, you should call either the brain doctor or Guinness World Records...
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I would then make the appropriate changes within may app and the client would not need to know any things has changed.
The reason I changed the class access to default was to attempt to stop the client from seeing the generated code. I was then planning to add a few public classes from my app to the same package as the generated code. However due to the way Castor marshals the code, it is not possible to have default classes, well at least I have not got it to work.

Isin't this the primary reason why we have Interfaces ?
Probably I am still missing something.....
But then your ending statements make me think......

Need ONE XML binding tool that uses EXACTLY the same source and needs to work on J2SE, J2ME and .net. (I am sure that this is not going to work).
Now I know that .net has J# but that support jdk 1.1.4. Now that is going back some time. I have never using J2ME so I am not sure that what restriction that is going to have.

Am I missing something else here or is this not a solution -
XSLT....
ClientCode -> YourApp -> CastorGeneratedCode -> XSLT -> XML
Just thinking out loud.......
- m
[ February 19, 2004: Message edited by: Madhav Lakkapragada ]
 
Chris Harris
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,


Isin't this the primary reason why we have Interfaces ?



It may be easier it if show what I mean with some code.

The client code would be:

The advantage of this is that the client an not create a Dog unless they use my Factory method.
I was planning to do the something simular for my actual app. Therefore I could control the creation of my genarated objects. The only way a client could create an object from the castor generated code would be by using my Factory. However as the generated code always creates public classes, it is possible of the client to create the object directy:
| _______________________ |
| _______________________ |
| _______________________\/
client app -> my app -> castor's generated code -> xml


Me:
Need ONE XML binding tool that uses EXACTLY the same source and needs to work on J2SE, J2ME and .net. (I am sure that this is not going to work).
Now I know that .net has J# but that support jdk 1.1.4. Now that is going back some time. I have never using J2ME so I am not sure that what restriction that is going to have.

Madhav Lakkapragada :
Am I missing something else here or is this not a solution -
XSLT....


I am have not real experiance using XSLT. I have done some research and from what I can see it is a way of defining a template that could be using to transalate one XML doc to another.
How could such a tool help develop one code base that code be used on .net, J2ME and J2SE ?
Please say if I have misunderstood.
My current ideas of doing this app are:
1. Using the xml, xslt and rdf in a such a way that most of the logic of the app is defined within these files. I am sure it is possible, it just a case of working out the best ways to use them to bind object to diffrent lanagues into an XML file. Also do it the other way around, i.e the objects of diffrent languages are populated from an XML file.
2. Use JavaCC to write a compiler. It would read syntax from other OO langauage and with a lot of logic produce a java class file.
3. Does any one know if RMI IIOP can handle any of the objects of created of a language within .net.
Thanks,
Chris
[ February 20, 2004: Message edited by: Chris Harris ]
[ February 20, 2004: Message edited by: Chris Harris ]
 
slicker
Posts: 1108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I used Castor to get my project up and running, but switched to SAX on input and StringBuffer and append() on output. The savings in time demanded that I drop Castor.
I preallocate a pool of StringBuffers and build the xml myself. I thought this would be really difficult but is actually not that big a deal, Plus there are less classes to deal with.
 
Normally trees don't drive trucks. Does this tiny ad have a license?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic