You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Jason Wood <ja...@auto-trol.com> on 2005/01/19 16:41:20 UTC
[betwixt] couple of questions
1) is there a document describing the different attributes each element in a
configuration file an contain?
2) has to do with List.
When using a configuration if the <addDefaults/> element is not present then
all properties must be explicitly listed. For a List property to show up in
the XML output, it as all the rest must be explicitly listed ... <element
name="MyAttributes" property="attributes"/>. This is fine, but "MyAttribute"
will show up for every entry in the java.util.List...
example ...
public class OutterClass
{
private Vector attributes = new Vector();
public OutterClass()
{
attributes.add(new DerivedClassA());
attributes.add(new DerivedClassB());
}
public void addAttribute(BaseClass attr)
{
attributes.add(attr);
}
public Vector getAttributes()
{
return attributes;
}
}
public class DerivedClassA implements BaseClass
{
}
public class DerivedClassB implements BaseClass
{
}
<?xml version='1.0' encoding='UTF-8' ?>
<info>
<element name='MyOutterClass'>
<element name="MyAttributes" property="attributes"/>
</element>
</info>
<MyOutterClass>
<MyAttributes/>
<MyAttributes/>
</MyOutterClass>
-----------------------------------------------------------------
I tried to remove the name="MyAttribtue" because I want betwixt to use each
entries (DerivedClassA and DerivedClassA) .betwixt file. for instance
<info>
<element name="MyDerivedClassA">
<addDefaults/>
</element>
</info>
<info>
<element name="MyDerivedClassB">
<addDefaults/>
</element>
</info>
but the digester states the "name" attribtue is required...
[ERROR] Digester - Begin event threw exception <org.xml.sax.SAXException:
Name attribute is required.>org.xml.sax.SAXException: Name attribute is
required.
at
org.apache.commons.betwixt.digester.ElementRule.begin(ElementRule.java:75)
at
org.apache.commons.digester.Digester.startElement(Digester.java:1286)
at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown
Source)
at
org.apache.xerces.parsers.AbstractXMLDocumentParser.emptyElement(Unknown
Source)
at
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unkno
wn Source)
at
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatc
her.dispatch(Unknown Source)
at
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown
Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown
Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown
Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.apache.commons.digester.Digester.parse(Digester.java:1629)
at
org.apache.commons.betwixt.XMLIntrospector.findByXMLDescriptor(XMLIntrospect
or.java:949)
at
org.apache.commons.betwixt.XMLIntrospector.introspect(XMLIntrospector.java:4
65)
at
org.apache.commons.betwixt.XMLIntrospector.introspect(XMLIntrospector.java:4
12)
at
org.apache.commons.betwixt.io.AbstractBeanWriter.writeBean(AbstractBeanWrite
r.java:223)
at
org.apache.commons.betwixt.io.AbstractBeanWriter.write(AbstractBeanWriter.ja
va:155)
at
org.apache.commons.betwixt.io.BeanWriter.write(BeanWriter.java:190)
at com.betwixt.Main.main(Main.java:30)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39
)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl
.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at
com.intellij.rt.execution.application.AppMain.main(AppMain.java:78)
I thought I could use the PluralStemmer in this case, but there is not
enough information being passed to findPluralDescriptor( String
propertyName, Map map ) in order for the code to choose the right
ElementDescriptor. Is it possible that if the name attribute is not present
to tell betwixt to use the given name in the classes .betwixt file for
output? If it is possible and not already in the current CVS src ... can I
checkout the source and add it.
Thanks
J
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: [betwixt] couple of questions
Posted by robert burrell donkin <ro...@blueyonder.co.uk>.
hi jason
On 19 Jan 2005, at 15:41, Jason Wood wrote:
> 1) is there a document describing the different attributes each
> element in a
> configuration file an contain?
if you mean by configuration file: a dot betwixt file there's a DTD in
CVS but doesn't seem to be anywhere on the website.
> 2) has to do with List.
collective properties have a getter and an adder. collectives without
adders are read-only. the mapping of read-only collectives differs from
those that can also be read. you've discovered an example of the
difference.
> When using a configuration if the <addDefaults/> element is not
> present then
> all properties must be explicitly listed. For a List property to show
> up in
> the XML output, it as all the rest must be explicitly listed ...
> <element
> name="MyAttributes" property="attributes"/>. This is fine, but
> "MyAttribute"
> will show up for every entry in the java.util.List...
<snip>
> <MyOutterClass>
> <MyAttributes/>
> <MyAttributes/>
> </MyOutterClass>
this is the behaviour i would expect by default.
> I tried to remove the name="MyAttribtue" because I want betwixt to use
> each
> entries (DerivedClassA and DerivedClassA) .betwixt file.
i'd be surprised if the above approach can be made to work. one issue
is that betwixt needs to be told that you want to use the dynamic bind
type (the type of the instance) rather than the introspection time type
(the logical type derived from the type of the property).
> I thought I could use the PluralStemmer in this case, but there is not
> enough information being passed to findPluralDescriptor( String
> propertyName, Map map ) in order for the code to choose the right
> ElementDescriptor.
PluralStemmer is a little shackled by backwards compatibility but the
intention has always been to provide support elsewhere. take a look at
http://jakarta.apache.org/commons/betwixt/guide/derived.html but you'll
need the latest code from CVS HEAD to take advantage.
> Is it possible that if the name attribute is not present
> to tell betwixt to use the given name in the classes .betwixt file for
> output?
that sounds like a pretty reasonable change. not sure it's on my list
of itches just now so i'm sure when i'd get round to coding it...
> If it is possible and not already in the current CVS src ...
> can I checkout the source and add it.
i would very strongly suggest checking out the latest source from CVS
in any case: you'll need to roll your own betwixt version to take
advantage of the improved support for derived beans and mixed
collectives.
i would also strongly encourage you to play around with the source.
betwixt is open source: you're free to change the source and use it in
whatever way you'd like (providing that you abide by the small number
of conditions in the ASL2.0). if your changes work for you then that's
fine.
on the other hand, betwixt development is ongoing and it's likely that
a private betwixt fork will become difficult to maintain as the apache
version is pushed forward. it therefore makes sense to share your
changes by donating them to apache by contributing a patch. patches are
more likely to be committed if they come with documentation patches and
unit test and are compact. please attach patches to a bug report (the
list will strip them out) but you might want to follow up on list.
if you do want to contribute a patch to the ASF to add functionality
allowing the element name to be derived at runtime together with unit
tests and documentation, there's a very good chance that i'll review
it. if you run into problems with the implementation but contribute
unit tests and documentation then that would definitely increase the
changes of me coding a solution.
- robert
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: [betwixt] couple of questions
Posted by robert burrell donkin <ro...@blueyonder.co.uk>.
hi jason
i've had a check and i'm pretty sure that the functionality you
required was added to betwixt as part of the anonymous collections
work. please update to CVS HEAD and take a look at the latest
documentation.
- robert
On 19 Jan 2005, at 15:41, Jason Wood wrote:
> 1) is there a document describing the different attributes each
> element in a
> configuration file an contain?
> 2) has to do with List.
>
> When using a configuration if the <addDefaults/> element is not
> present then
> all properties must be explicitly listed. For a List property to show
> up in
> the XML output, it as all the rest must be explicitly listed ...
> <element
> name="MyAttributes" property="attributes"/>. This is fine, but
> "MyAttribute"
> will show up for every entry in the java.util.List...
>
> example ...
>
> public class OutterClass
> {
> private Vector attributes = new Vector();
>
> public OutterClass()
> {
> attributes.add(new DerivedClassA());
> attributes.add(new DerivedClassB());
> }
>
> public void addAttribute(BaseClass attr)
> {
> attributes.add(attr);
> }
>
> public Vector getAttributes()
> {
> return attributes;
> }
> }
>
> public class DerivedClassA implements BaseClass
> {
> }
>
> public class DerivedClassB implements BaseClass
> {
> }
>
> <?xml version='1.0' encoding='UTF-8' ?>
> <info>
> <element name='MyOutterClass'>
> <element name="MyAttributes" property="attributes"/>
> </element>
> </info>
>
> <MyOutterClass>
> <MyAttributes/>
> <MyAttributes/>
> </MyOutterClass>
> -----------------------------------------------------------------
>
> I tried to remove the name="MyAttribtue" because I want betwixt to use
> each
> entries (DerivedClassA and DerivedClassA) .betwixt file. for instance
>
> <info>
> <element name="MyDerivedClassA">
> <addDefaults/>
> </element>
> </info>
>
> <info>
> <element name="MyDerivedClassB">
> <addDefaults/>
> </element>
> </info>
>
> but the digester states the "name" attribtue is required...
>
> [ERROR] Digester - Begin event threw exception
> <org.xml.sax.SAXException:
> Name attribute is required.>org.xml.sax.SAXException: Name attribute is
> required.
> at
> org.apache.commons.betwixt.digester.ElementRule.begin(ElementRule.java:
> 75)
> at
> org.apache.commons.digester.Digester.startElement(Digester.java:1286)
> at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown
> Source)
> at
> org.apache.xerces.parsers.AbstractXMLDocumentParser.emptyElement(Unknow
> n
> Source)
> at
> org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanStartElement(
> Unkno
> wn Source)
> at
> org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDi
> spatc
> her.dispatch(Unknown Source)
> at
> org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unkn
> own
> Source)
> at org.apache.xerces.parsers.XML11Configuration.parse(Unknown
> Source)
> at org.apache.xerces.parsers.XML11Configuration.parse(Unknown
> Source)
> at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
> at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
> at org.apache.commons.digester.Digester.parse(Digester.java:1629)
> at
> org.apache.commons.betwixt.XMLIntrospector.findByXMLDescriptor(XMLIntro
> spect
> or.java:949)
> at
> org.apache.commons.betwixt.XMLIntrospector.introspect(XMLIntrospector.j
> ava:4
> 65)
> at
> org.apache.commons.betwixt.XMLIntrospector.introspect(XMLIntrospector.j
> ava:4
> 12)
> at
> org.apache.commons.betwixt.io.AbstractBeanWriter.writeBean(AbstractBean
> Write
> r.java:223)
> at
> org.apache.commons.betwixt.io.AbstractBeanWriter.write(AbstractBeanWrit
> er.ja
> va:155)
> at
> org.apache.commons.betwixt.io.BeanWriter.write(BeanWriter.java:190)
> at com.betwixt.Main.main(Main.java:30)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.ja
> va:39
> )
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccesso
> rImpl
> .java:25)
> at java.lang.reflect.Method.invoke(Method.java:324)
> at
> com.intellij.rt.execution.application.AppMain.main(AppMain.java:78)
>
> I thought I could use the PluralStemmer in this case, but there is not
> enough information being passed to findPluralDescriptor( String
> propertyName, Map map ) in order for the code to choose the right
> ElementDescriptor. Is it possible that if the name attribute is not
> present
> to tell betwixt to use the given name in the classes .betwixt file for
> output? If it is possible and not already in the current CVS src ...
> can I
> checkout the source and add it.
>
> Thanks
> J
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org