|
|
|
Initial patch to facilitate discussions .....
Any feedback ? Would the solution offered be sufficient for your needs ? If yes, I think this could me made available through an extra property - which by default is turned off.
Thanks for this early implementation. Here are my suggestions and initial feedback.
The content is indeed what I was trying to get. I would be even better with the "source" information. For instance, I'd like that getDocumentations("version") equals "1.0.0" and getDocumentations("description") equals "Root element of the user configuration file.". Also, I think the name getDocumentations is not a good idea. That would conflict with a generated class in case where the XSD contains a node named "documentations". I think accessing the attribute directly would be better, or we need to break the Java naming convention (eg get_Documentations). I suppose this could lead to a bug. The content needs to have backslashes added before the line breaks, otherwise the generated code won't compile.:
Finally, how could such a documentation be available for the base-type elements that are transformed into methods? My idea was to use Java annotations, but I've just realized castor wants to be Java-1.3 compatible. Thanks for all this. Thanks for the feedback. Here's some initial comments ....
a) Don't worry about the change to a java.util.Map. I will be looking into this right now. And finally, not sure what you are referring to with a sentence like .... > Finally, how could such a documentation be available for the base-type elements that are transformed Updatd patch, incl. additional code for a) and b).
aThanks! bYes indeed. A collision is far less probable. cYes, it was my initial idea, too. I eventually changed it to the backslashes idea, because the line breaks could have a meaning. d
Sorry for not being clear once again. <xs:complexType name="Settings"> <xs:annotation> <xs:documentation source="version">1.0.0</xs:documentation> <xs:documentation source="description">Root element of the user configuration file.</xs:documentation> </xs:annotation> <xs:all> <xs:element name="localRepository" minOccurs="0" type="xs:string"> <xs:annotation> <xs:documentation source="version">1.0.0</xs:documentation> <xs:documentation source="description">The local repository.</xs:documentation> </xs:annotation> </xs:element> </xs:all> </xs:complexType> Castor will generate code. This code allows to Settings settings=new Settings(); settings.setLocalRepository("toto"); Now we can even get documentation for "<settings>" settings.getXMLSchemaDocumentations("description");
But localRepository is a base-type (xsd:string) and is acceded through methods: getLocalrepository() which returns a String. How do you get documentation for <localRepository> ?
What do you think? Am I missing an easy way to retrieve the description for localRepository? I am actually not sure whether I like any of these ideas sufficiently. Yes, using an annotation for Java 5.0 and above could be an option. Let me think about this a bit.
How did you implement the backslash idea ? I actually wonder whether the following annotation
<xs:documentation source="version">1.0.0</xs:documentation> should be translated anyhow to the following fragment in the Javadoc for the localRepositrory member: /**
Class that provides the replaceAll method in JDK 1.3
Sometimes I just say stupid things (or confuse programming languages) My implementation is only based on going to the next line. The generated code looks like this: Unable to find source-code formatter for language: servers.java. Available languages are: xhtml, javascript, java, none, html, actionscript, xml, sql public Servers() { super(); this._serverList = new java.util.Vector(); _xmlSchemaDocumentations.put("version", "1.0.0"); _xmlSchemaDocumentations.put("description", "Configuration of server-specific settings, mainly authentication" + +" method. This allows configuration of authentication on a per-server" + +" basis." + +" "); }
I don't need it, indeed. I have no idea whether this could be useful to anyone else. Updated patch, incl. StringUtil functionality.
I am actually tempted to commit this as is, and to address the remainder of the functionality through a new (follow-up) issue.
Updated patch, where I made the new code configurable via a new property (default = false).
Completes your patch.c1966.20070511.txt (10 kb) (new configuration, lines breaks, managed with property) with a TestCase for StringUtil (and fixes a NPE exception when the source is null).
I'll so some more testing, but I think this can soon be committed to trunk, indeed. Updated patch, with small structural changes to the new JUnit test case.
Your little fix in StringUtil to add a check for null just made me wonder about the validity of the solution when somebody adds multiple documentation elements without specifying a source attribute ?
Just for your information, I moved all code/issues that can be committed as it stands to a new sub-task. Makes it easier for us (me) in terms of release management.
Regis, I will commit
Returning to your suggestion to add additional code (methods) to allow access to documentation information for first-class members of top-level element/type definitions, one could easily expand the concept applied to the top-level elements/type deds, and add the following artifacts:
private Map _xmlSchemaDocumentationOfFields = new HashMap(); and allow access to its content by a method as follows: private String getXmlSchemaDocumentation(String fieldName, String source); It just occurred to me that al these members/methods to access the XML schema documentation information could (and in my humble opinion) should be moved to a class' descriptor, where it could be stored with the corresponding XMLClassDescriptor/XMLFieldDescriptor. Let me know whether you'd find this still useful.
Hi Werner,
First of all, happy new year, and thanks for this nice piece of software called castor. To answer your question, yes, having the descritption in a separate class would answer my use case. And it will not increase the size of the main class, which is probably a good thing indeed. Cheers > And it will not increase the size of the main class, which is probably a good thing indeed.
Which is exactly my main train of thought .. Just out of curiosity, what tool is it you are using Castor for ? My use case a GUI to edit the settings.xml file used to configure Maven.
http://code.google.com/p/m2settings My current workaround is based on a 'DocumentationProvider' that parses the XSD (again) to extract the xs:documentation. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
private List annotations;
or
private List documentations;
given that it does not really make sense to expose the content of the <xsd:appInfo> elements ?