private AttributeDefinitionSpecification parseAD(DepthAwareXMLStreamReader parser) throws XMLStreamException {
        AttributeDefinitionSpecification ad = new AttributeDefinitionSpecification();

        //extension attributes <URI, <attr, val>>
        Map<String, Map<String, String>> extAttributes = new HashMap<String, Map<String, String>>();

        int attrCount = parser.getAttributeCount();
        for (int i = 0; i < attrCount; i++) {
            QName qname = parser.getAttributeName(i);
            String attrVal = parser.getAttributeValue(i);

            if (qname.equals(ID)) {
                ad.setId(attrVal);
            } else if (qname.equals(NAME)) {
                ad.setName(getLocalizedName(attrVal));
                String defaultName = ad.getName();
                String attributeName = getLocalizedName(attrVal + "$Ref");
                ad.setAttributeName(attributeName.equals(attrVal + "$Ref") ? defaultName : attributeName);
            } else if (qname.equals(DESCRIPTION)) {
                ad.setDescription(getLocalizedName(attrVal));
            } else if (qname.equals(TYPE)) {
                ad.setType(parseType(attrVal));
            } else if (qname.equals(CARDINALITY)) {
                ad.setCardinality(Integer.parseInt(attrVal));
            } else if (qname.equals(DEFAULT)) {
                List<String> values = MetaTypeHelper.parseValue(attrVal);
                ad.setDefaultValue(values.toArray(new String[values.size()]));
            } else if (qname.equals(REQUIRED)) { // default true
                ad.setRequired(Boolean.parseBoolean(attrVal));
            } else if (qname.equals(MIN)) {
                ad.setMinValue(attrVal);
            } else if (qname.equals(MAX)) {
                ad.setMaxValue(attrVal);
            }

            String namespace = qname.getNamespaceURI();
            //support extension attributes
            if (namespace.length() != 0 && !!!namespace.startsWith(METATYPE_URI)) {
                if (extAttributes.containsKey(namespace)) {
                    Map<String, String> attrMap = extAttributes.get(namespace);
                    attrMap.put(qname.getLocalPart(), attrVal);
                } else {
                    HashMap<String, String> attrMap = new HashMap<String, String>();
                    attrMap.put(qname.getLocalPart(), attrVal);
                    extAttributes.put(namespace, attrMap);
                }
            }
        }

        ad.setExtendedAttributes(new ExtendableHelper(extAttributes));

        int depth = parser.getDepth();
        while (parser.hasNext(depth)) {
            int event = parser.next();
            if (event == XMLStreamConstants.START_ELEMENT) {
                String name = parser.getName().getLocalPart();
                if (name.equalsIgnoreCase(OPTION)) {
                    ad.addValueOption(parseOption(parser));
                }
            }
        }
        return ad;
    }
private AttributeDefinitionSpecification parseAD ( DepthAwareXMLStreamReader parser ) throws XMLStreamException { AttributeDefinitionSpecification ad = new AttributeDefinitionSpecification ( ) ; Map < String , Map < String , String > > extAttributes = new HashMap < String , Map < String , String > > ( ) ; int attrCount = parser . getAttributeCount ( ) ; for ( int i = 0 ; i < attrCount ; i ++ ) { QName qname = parser . getAttributeName ( i ) ; String attrVal = parser . getAttributeValue ( i ) ; if ( qname . equals ( ID ) ) { ad . setId ( attrVal ) ; } else if ( qname . equals ( NAME ) ) { ad . setName ( getLocalizedName ( attrVal ) ) ; String defaultName = ad . getName ( ) ; String attributeName = getLocalizedName ( attrVal + "$Ref" ) ; ad . setAttributeName ( attributeName . equals ( attrVal + "$Ref" ) ? defaultName : attributeName ) ; } else if ( qname . equals ( DESCRIPTION ) ) { ad . setDescription ( getLocalizedName ( attrVal ) ) ; } else if ( qname . equals ( TYPE ) ) { ad . setType ( parseType ( attrVal ) ) ; } else if ( qname . equals ( CARDINALITY ) ) { ad . setCardinality ( Integer . parseInt ( attrVal ) ) ; } else if ( qname . equals ( DEFAULT ) ) { List < String > values = MetaTypeHelper . parseValue ( attrVal ) ; ad . setDefaultValue ( values . toArray ( new String [ values . size ( ) ] ) ) ; } else if ( qname . equals ( REQUIRED ) ) { ad . setRequired ( Boolean . parseBoolean ( attrVal ) ) ; } else if ( qname . equals ( MIN ) ) { ad . setMinValue ( attrVal ) ; } else if ( qname . equals ( MAX ) ) { ad . setMaxValue ( attrVal ) ; } String namespace = qname . getNamespaceURI ( ) ; if ( namespace . length ( ) != 0 && ! ! ! namespace . startsWith ( METATYPE_URI ) ) { if ( extAttributes . containsKey ( namespace ) ) { Map < String , String > attrMap = extAttributes . get ( namespace ) ; attrMap . put ( qname . getLocalPart ( ) , attrVal ) ; } else { HashMap < String , String > attrMap = new HashMap < String , String > ( ) ; attrMap . put ( qname . getLocalPart ( ) , attrVal ) ; extAttributes . put ( namespace , attrMap ) ; } } } ad . setExtendedAttributes ( new ExtendableHelper ( extAttributes ) ) ; int depth = parser . getDepth ( ) ; while ( parser . hasNext ( depth ) ) { int event = parser . next ( ) ; if ( event == XMLStreamConstants . START_ELEMENT ) { String name = parser . getName ( ) . getLocalPart ( ) ; if ( name . equalsIgnoreCase ( OPTION ) ) { ad . addValueOption ( parseOption ( parser ) ) ; } } } return ad ; }
@param xmlStreamReader
@return