/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2014 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.wildfly.extension.elytron;

import static org.jboss.as.controller.PersistentResourceXMLDescription.decorator;
import static org.wildfly.extension.elytron.ElytronDescriptionConstants.CREDENTIAL_STORES;
import static org.wildfly.extension.elytron.ElytronDescriptionConstants.SECURITY_PROPERTY;

import org.jboss.as.controller.AttributeMarshallers;
import org.jboss.as.controller.AttributeParsers;
import org.jboss.as.controller.PersistentResourceXMLDescription;

/**
 * The subsystem parser, which uses stax to read and write to and from xml
 *
 * @author <a href="mailto:darran.lofthouse@jboss.com">Darran Lofthouse</a> *
 * @author Tomaz Cerar
 * @since 4.0
 */
class ElytronSubsystemParser2_0 extends ElytronSubsystemParser1_2 {

    @Override
    String getNameSpace() {
        return ElytronExtension.NAMESPACE_2_0;
    }
    //at this point definition below is not really needed as it is the same as for 1.1, but it is here as place holder when subsystem parser evolves.
    @Override
    public PersistentResourceXMLDescription getParserDescription() {
        return PersistentResourceXMLDescription.builder(ElytronExtension.SUBSYSTEM_PATH, getNameSpace())
                .addAttribute(ElytronDefinition.DEFAULT_AUTHENTICATION_CONTEXT)
                .addAttribute(ElytronDefinition.INITIAL_PROVIDERS)
                .addAttribute(ElytronDefinition.FINAL_PROVIDERS)
                .addAttribute(ElytronDefinition.DISALLOWED_PROVIDERS)
                .addAttribute(ElytronDefinition.SECURITY_PROPERTIES, new AttributeParsers.PropertiesParser(null, SECURITY_PROPERTY, true), new AttributeMarshallers.PropertiesAttributeMarshaller(null, SECURITY_PROPERTY, true))
                .addChild(getAuthenticationClientParser())
                .addChild(getAuditLoggingParser())
                .addChild(getProviderParser())
                .addChild(getDomainParser())
                .addChild(getRealmParser())
                .addChild(getMapperParser())
                .addChild(getTlsParser())
                .addChild(getDirContextParser())
                .addChild(decorator(CREDENTIAL_STORES).addChild(new CredentialStoreParser().parser))
                .addChild(getSaslParser())
                .addChild(getHttpParser())
                .addChild(getPolicyParser())
                .addChild(getCredentialSecurityFactoryParser())
                .build();
    }


}

@@ -2477,20 +2477,16 @@
 (get
-AuditLogging
+Provider
 Pars
@@ -2516,32 +2516,36 @@
 addChild(get
-Provider
+AuditLogging
 Parser())%0A  
@@ -2664,14 +2664,33 @@
 (get
-Mapper
+CredentialSecurityFactory
 Pars
@@ -2728,11 +2728,14 @@
 (get
-Tls
+Mapper
 Pars
@@ -2773,18 +2773,12 @@
 (get
-DirContext
+Http
 Pars
@@ -2813,80 +2813,22 @@
 ild(
-decorator(CREDENTIAL_STORES).addChild(new CredentialStoreParser().parser
+getSaslParser(
 ))%0A 
@@ -2847,36 +2847,35 @@
    .addChild(get
-Sasl
+Tls
 Parser())%0A      
@@ -2890,38 +2890,96 @@
   .addChild(
-getHttpParser(
+decorator(CREDENTIAL_STORES).addChild(new CredentialStoreParser().parser
 ))%0A         
@@ -3002,14 +3002,18 @@
 (get
-Policy
+DirContext
 Pars
@@ -3051,32 +3051,13 @@
 (get
-CredentialSecurityFactor
+Polic
 yPar

Put the elytron parser description children in the same order as xsd