[jboss-user] [Snowdrop] - Re: Snowdrop and JBoss AS 7.2.0

Juraj Tomasov do-not-reply at jboss.com
Thu Jan 10 03:11:32 EST 2013


Juraj Tomasov [https://community.jboss.org/people/jtomasov] created the discussion

"Re: Snowdrop and JBoss AS 7.2.0"

To view the discussion, visit: https://community.jboss.org/message/790006#790006

--------------------------------------------------------------
The reason of incompatibility Snowdrop subsystem with JBoss AS 7.2.0.Alpha1-SNAPSHOT is the fact ExtensionContext registerSubsystem methods have changed.

Changes needed to make Snowdrop subsystem can be registered in JBoss AS 7.1.3 onwards are as follows:

1. In snowdrop-parent.pom change

<version.org.jboss.as7>7.1.3.Final</version.org.jboss.as7>

2. amend org.jboss.spring.deployers.as7.SpringExtension class

/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2010, Red Hat, Inc., and individual contributors
 * as indicated by the @author tags. See the copyright.txt file in the
 * distribution for a full listing of individual contributors.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site:  http://www.fsf.org http://www.fsf.org.
 */


package org.jboss.spring.deployers.as7;


import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ADD;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.DESCRIBE;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM;


import java.util.List;
import java.util.Locale;


import javax.xml.stream.XMLStreamException;


import org.jboss.as.controller.Extension;
import org.jboss.as.controller.ExtensionContext;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.OperationStepHandler;
import org.jboss.as.controller.SubsystemRegistration;
import org.jboss.as.controller.descriptions.DescriptionProvider;
import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
import org.jboss.as.controller.descriptions.common.CommonDescriptions;
import org.jboss.as.controller.parsing.ExtensionParsingContext;
import org.jboss.as.controller.parsing.ParseUtils;
import org.jboss.as.controller.persistence.SubsystemMarshallingContext;
import org.jboss.as.controller.registry.ManagementResourceRegistration;
import org.jboss.as.controller.registry.OperationEntry;
import org.jboss.dmr.ModelNode;
import org.jboss.logging.Logger;
import org.jboss.staxmapper.XMLElementReader;
import org.jboss.staxmapper.XMLElementWriter;
import org.jboss.staxmapper.XMLExtendedStreamReader;
import org.jboss.staxmapper.XMLExtendedStreamWriter;


/**
 * @author Marius Bogoevici
 */
public class SpringExtension implements Extension {


    private static final Logger log = Logger.getLogger("org.jboss.snowdrop");


    public static final String SUBSYSTEM_NAME = "spring";


    public static final String NAMESPACE = "urn:jboss:domain:snowdrop:1.0";


*private static final int MANAGEMENT_API_MAJOR_VERSION = 1;*
*    private static final int MANAGEMENT_API_MINOR_VERSION = 2;*
*    private static final int MANAGEMENT_API_MICRO_VERSION = 0;*

    private static SpringSubsystemElementParser parser = new SpringSubsystemElementParser();


    private static final DescriptionProvider SUBSYSTEM_ADD_DESCRIPTION = new DescriptionProvider() {
        @Override
        public ModelNode getModelDescription(Locale locale) {
            return SpringDescriptionProviders.getSubsystemAddDescription(locale);
        }
    };


    static final DescriptionProvider SUBSYSTEM_DESCRIPTION = new DescriptionProvider() {
        @Override
        public ModelNode getModelDescription(Locale locale) {
            return SpringDescriptionProviders.getSubsystemDescription(locale);
        }
    };


    private static ModelNode createAddSubSystemOperation() {
        final ModelNode subsystem = new ModelNode();
        subsystem.get(OP).set(ADD);
        subsystem.get(OP_ADDR).add(ModelDescriptionConstants.SUBSYSTEM, SUBSYSTEM_NAME);
        return subsystem;
    }


    public void initialize(ExtensionContext context) {
        log.debug("Activating Spring Extension");
 *final SubsystemRegistration subsystem = context.registerSubsystem(SUBSYSTEM_NAME,MANAGEMENT_API_MAJOR_VERSION,MANAGEMENT_API_MINOR_VERSION,MANAGEMENT_API_MICRO_VERSION);*
        final ManagementResourceRegistration registration = subsystem.registerSubsystemModel(SUBSYSTEM_DESCRIPTION);
        registration.registerOperationHandler(ADD, SpringSubsystemAdd.INSTANCE, SUBSYSTEM_ADD_DESCRIPTION, false);
        registration.registerOperationHandler(DESCRIBE, SpringSubsystemDescribeHandler.INSTANCE, SpringSubsystemDescribeHandler.INSTANCE, false, OperationEntry.EntryType.PRIVATE);
        subsystem.registerXMLElementWriter(parser);
    }


    public void initializeParsers(ExtensionParsingContext context) {
        log.debug("Setting up parsers");
        context.setSubsystemXmlMapping(NAMESPACE, parser);
    }


    static class SpringSubsystemElementParser implements XMLElementReader<List<ModelNode>>,
            XMLElementWriter<SubsystemMarshallingContext> {


        /**
         * {@inheritDoc}
         */
        @Override
        public void readElement(XMLExtendedStreamReader reader, List<ModelNode> list) throws XMLStreamException {
            ParseUtils.requireNoAttributes(reader);
            ParseUtils.requireNoContent(reader);
            final ModelNode update = new ModelNode();
            update.get(OP).set(ADD);
            update.get(OP_ADDR).add(SUBSYSTEM, SUBSYSTEM_NAME);
            list.add(createAddSubSystemOperation());
        }


        private static ModelNode createAddSubSystemOperation() {
            final ModelNode subsystem = new ModelNode();
            subsystem.get(OP).set(ADD);
            subsystem.get(OP_ADDR).add(ModelDescriptionConstants.SUBSYSTEM, SUBSYSTEM_NAME);
            return subsystem;
        }


        /**
         * {@inheritDoc}
         */
        @Override
        public void writeContent(final XMLExtendedStreamWriter writer, final SubsystemMarshallingContext context) throws
                XMLStreamException {
            //TODO seems to be a problem with empty elements cleaning up the queue in FormattingXMLStreamWriter.runAttrQueue
            context.startSubsystemElement(NAMESPACE, false);
            writer.writeEndElement();


        }
    }


    private static class SpringSubsystemDescribeHandler implements OperationStepHandler, DescriptionProvider {


        static final SpringSubsystemDescribeHandler INSTANCE = new SpringSubsystemDescribeHandler();


        @Override
        public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
            context.getResult().add(createAddSubSystemOperation());
            context.completeStep();
        }


        @Override
        public ModelNode getModelDescription(Locale locale) {
            return CommonDescriptions.getSubsystemDescribeOperation(locale);
        }
    }
}
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/790006#790006]

Start a new discussion in Snowdrop at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2082]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20130110/4708e0e7/attachment-0001.html 


More information about the jboss-user mailing list