9 Replies Latest reply: Feb 8, 2010 8:52 AM by Alexey Loubyansky RSS

    Xml attribute list

    Kabir Khan Master

      I'm trying to do the following to allow for several values in an xml attribute

      public enum QualifierPoint
      {
       @XmlEnumValue("Constructor") CONSTRUCTOR,
       @XmlEnumValue("Method") METHOD,
       @XmlEnumValue("Property") PROPERTY
      }
      
      @XmlType(name="qualifierType")
      public class AbstractInjectQualifierMetaData extends AbstractQualifierMetaData
      {
       private static final long serialVersionUID = 1L;
      
       protected List<QualifierPoint> points;
      
       @XmlAttribute(name="points")
       public void setPoints(List<QualifierPoint> points)
       {
       this.points = points;
       }
      
       public List<QualifierPoint> getPoints()
       {
       return points;
       }
      }
      


      However
       <qualifier points="Method">123</qualifier>
      

      fails with
      Caused by: java.lang.RuntimeException: QName points error setting property points with value org.jboss.beans.metadata.plugins.QualifierPoint
      @3e5dc994 to org.jboss.beans.metadata.plugins.AbstractInjectQualifierMetaData@2136814472
       at org.jboss.xb.builder.runtime.PropertyHandler.handle(PropertyHandler.java:60)
       at org.jboss.xb.builder.runtime.AbstractPropertyHandler.doHandle(AbstractPropertyHandler.java:98)
       at org.jboss.xb.builder.runtime.AbstractPropertyHandler.attribute(AbstractPropertyHandler.java:118)
       at org.jboss.xb.binding.sunday.unmarshalling.AttributesHandler.attributes(AttributesHandler.java:51)
       at org.jboss.xb.binding.sunday.unmarshalling.DefaultElementHandler.attributes(DefaultElementHandler.java:65)
       at org.jboss.xb.builder.runtime.BeanHandler.startParticle(BeanHandler.java:109)
       at org.jboss.xb.binding.sunday.unmarshalling.SundayContentHandler.startElement(SundayContentHandler.java:616)
       at org.jboss.xb.binding.parser.sax.SaxJBossXBParser$DelegatingContentHandler.startElement(SaxJBossXBParser.java:401)
       at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
       at org.apache.xerces.xinclude.XIncludeHandler.startElement(Unknown Source)
       at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
       at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.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.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
       at org.jboss.xb.binding.parser.sax.SaxJBossXBParser.parse(SaxJBossXBParser.java:173)
       ... 29 more
      Caused by: java.lang.IllegalArgumentException: Wrong arguments. setPoints for target org.jboss.beans.metadata.plugins.AbstractInjectQualifie
      rMetaData@57922f46 expected=[java.util.List] actual=[org.jboss.beans.metadata.plugins.QualifierPoint]
       at org.jboss.reflect.plugins.introspection.ReflectionUtils.handleErrors(ReflectionUtils.java:395)
       at org.jboss.reflect.plugins.introspection.ReflectionUtils.invoke(ReflectionUtils.java:69)
       at org.jboss.reflect.plugins.introspection.ReflectMethodInfoImpl.invoke(ReflectMethodInfoImpl.java:151)
       at org.jboss.beans.info.plugins.DefaultPropertyInfo.set(DefaultPropertyInfo.java:143)
       at org.jboss.xb.spi.AbstractBeanAdapter.set(AbstractBeanAdapter.java:95)
       at org.jboss.xb.builder.runtime.PropertyHandler.handle(PropertyHandler.java:56)
       ... 47 more
      


      and
       <qualifier points="Constructor, Property">123</qualifier>
      

      fails with
      Caused by: java.lang.RuntimeException: Invalid value Constructor, Property valid are [Method, Property, Constructor]
       at org.jboss.xb.builder.runtime.EnumValueAdapter.cast(EnumValueAdapter.java:136)
       at org.jboss.xb.builder.runtime.AbstractPropertyHandler.attribute(AbstractPropertyHandler.java:115)
       at org.jboss.xb.binding.sunday.unmarshalling.AttributesHandler.attributes(AttributesHandler.java:51)
       at org.jboss.xb.binding.sunday.unmarshalling.DefaultElementHandler.attributes(DefaultElementHandler.java:65)
       at org.jboss.xb.builder.runtime.BeanHandler.startParticle(BeanHandler.java:109)
       at org.jboss.xb.binding.sunday.unmarshalling.SundayContentHandler.startElement(SundayContentHandler.java:616)
       at org.jboss.xb.binding.parser.sax.SaxJBossXBParser$DelegatingContentHandler.startElement(SaxJBossXBParser.java:401)
       at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
       at org.apache.xerces.xinclude.XIncludeHandler.startElement(Unknown Source)
       at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
       at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.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.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
       at org.jboss.xb.binding.parser.sax.SaxJBossXBParser.parse(SaxJBossXBParser.java:173)
       ... 29 more
      



        • 1. Re: Xml attribute list
          Alexey Loubyansky Master

          Ok, I'll have look.

          • 2. Re: Xml attribute list
            Alexey Loubyansky Master

            Should be fixed in the current snapshot. https://jira.jboss.org/jira/browse/JBXB-235
            Are you ok for now with the snapshot?

            • 3. Re: Xml attribute list
              Kabir Khan Master

              Thanks, I'll try the snapshot. Ales will let you know when we need a proper release

              • 4. Re: Xml attribute list
                Kabir Khan Master

                I see it forces me to write

                points="Property Constructor"
                


                if I try to use a comma or something it fails
                points="Property, Constructor"
                

                thinking the first one is called 'Property,'. Is is possible to support commas as separator?

                • 6. Re: Xml attribute list
                  Kabir Khan Master

                  ok :-)

                  • 7. Re: Xml attribute list
                    Alexey Loubyansky Master

                    Actually, we can do it by providing a value adapter. But in the schema the type of the attribute will have to be just string. So, if you care about pure XML validation this attribute will be valid as long as the value is a string.

                    • 8. Re: Xml attribute list
                      Kabir Khan Master

                      Alexey,

                       

                      Can you please take a look to see if my xsd attempts are ok?

                       

                         <xsd:complexType name="qualifierBeanType" mixed="true">
                            <xsd:annotation>
                               <xsd:documentation>
                                 <![CDATA[
                                 Qualifiers.
                                 ]]>
                               </xsd:documentation>
                            </xsd:annotation>
                            <xsd:choice minOccurs="0" maxOccurs="unbounded">
                               <xsd:any namespace="##other" processContents="strict"/>
                            </xsd:choice>
                            <xsd:attribute name="content" type="xsd:string" use="optional"/>
                            <xsd:attribute name="type" use="optional" default="Supplied">
                               <xsd:simpleType>
                                  <xsd:restriction base="xsd:string">
                                     <xsd:enumeration value="Supplied"></xsd:enumeration>
                                     <xsd:enumeration value="Optional"></xsd:enumeration>
                                     <xsd:enumeration value="Required"></xsd:enumeration>
                                  </xsd:restriction>
                               </xsd:simpleType>
                            </xsd:attribute>
                            <xsd:attribute name="points" use="optional">
                               <xsd:simpleType>
                                  <xsd:list>
                                     <xsd:simpleType>
                                            <xsd:restriction base="xsd:string">
                                               <xsd:enumeration value="Constructor"></xsd:enumeration>
                                               <xsd:enumeration value="Method"></xsd:enumeration>
                                               <xsd:enumeration value="Property"></xsd:enumeration>
                                            </xsd:restriction>
                                     </xsd:simpleType>
                                  </xsd:list>
                               </xsd:simpleType>
                            </xsd:attribute>
                         </xsd:complexType>
                      
                      I think I have got the choice ok (copied from the thing I am mimicking), but am unsure about the attributes. What I want is
                      - An attribute called 'content' that just takes a string.
                      - An attribute called 'type' that can be either 'Supplied', 'Optional' or 'Required' with 'Supplied' as the default.
                      - An attribute called 'points' that can take one or more of 'Constructor', 'Method' or 'Property'. If I am on the right path, can I make it ignore the case of these so that 'propeRTY' etc. would be valid as well?
                      • 9. Re: Xml attribute list
                        Alexey Loubyansky Master

                        Sorry for the very late response. I guess, you've figured it out by now yourself (which wasn't my intention!).

                         

                        Looks good. As to the case-insensitivity, you can't do it with enumeration since there you define the specific allowed values. You could consider using patterns, e.g. http://www.ibm.com/developerworks/xml/library/x-case/index.html