Skip to content

Commit

Permalink
WFLY-4559 Introduce a new version of jboss-all.xml schema for Weld
Browse files Browse the repository at this point in the history
  • Loading branch information
jharting committed Jun 9, 2015
1 parent 712ffd8 commit 5ef4158
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 36 deletions.
@@ -0,0 +1,33 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2015, Red Hat, Inc., and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* 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.jboss.as.weld;

import org.jboss.staxmapper.XMLExtendedStreamReader;

abstract class AbstractWeldJBossAllParser {

protected Boolean getAttributeAsBoolean(XMLExtendedStreamReader reader, String attributeName) {
for (int i = 0; i < reader.getAttributeCount(); i++) {
final String name = reader.getAttributeLocalName(i);
final String value = reader.getAttributeValue(i);
if (attributeName.equals(name)) {
return Boolean.valueOf(value);
}
}
return null;
}
}
56 changes: 56 additions & 0 deletions weld/src/main/java/org/jboss/as/weld/WeldJBossAll10Parser.java
@@ -0,0 +1,56 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2013, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt 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.
*/
package org.jboss.as.weld;

import static org.jboss.as.weld.WeldResourceDefinition.NON_PORTABLE_MODE_ATTRIBUTE_NAME;
import static org.jboss.as.weld.WeldResourceDefinition.REQUIRE_BEAN_DESCRIPTOR_ATTRIBUTE_NAME;

import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamException;

import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.jbossallxml.JBossAllXMLParser;
import org.jboss.staxmapper.XMLExtendedStreamReader;

/**
* Parses <code>jboss-all.xml</code> and creates {@link WeldJBossAllConfiguration} holding the parsed configuration.
*
* @author Jozef Hartinger
*
*/
class WeldJBossAll10Parser extends AbstractWeldJBossAllParser implements JBossAllXMLParser<WeldJBossAllConfiguration> {

public static final String NAMESPACE = "urn:jboss:weld:1.0";
public static final QName ROOT_ELEMENT = new QName(NAMESPACE, "weld");
public static final WeldJBossAll10Parser INSTANCE = new WeldJBossAll10Parser();

private WeldJBossAll10Parser() {
}

@Override
public WeldJBossAllConfiguration parse(XMLExtendedStreamReader reader, DeploymentUnit deploymentUnit) throws XMLStreamException {
Boolean requireBeanDescriptor = getAttributeAsBoolean(reader, REQUIRE_BEAN_DESCRIPTOR_ATTRIBUTE_NAME);
Boolean nonPortableMode = getAttributeAsBoolean(reader, NON_PORTABLE_MODE_ATTRIBUTE_NAME);
return new WeldJBossAllConfiguration(requireBeanDescriptor, nonPortableMode, false);
}

}
Expand Up @@ -28,7 +28,6 @@
import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamException;

import org.jboss.as.controller.parsing.ParseUtils;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.jbossallxml.JBossAllXMLParser;
import org.jboss.staxmapper.XMLExtendedStreamReader;
Expand All @@ -39,42 +38,20 @@
* @author Jozef Hartinger
*
*/
class WeldJBossAllParser implements JBossAllXMLParser<WeldJBossAllConfiguration> {
class WeldJBossAll11Parser extends AbstractWeldJBossAllParser implements JBossAllXMLParser<WeldJBossAllConfiguration> {

public static final String NAMESPACE = "urn:jboss:weld:1.0";
public static final String NAMESPACE = "urn:jboss:weld:1.1";
public static final QName ROOT_ELEMENT = new QName(NAMESPACE, "weld");
public static final WeldJBossAllParser INSTANCE = new WeldJBossAllParser();
public static final WeldJBossAll11Parser INSTANCE = new WeldJBossAll11Parser();

private WeldJBossAllParser() {
private WeldJBossAll11Parser() {
}

@Override
public WeldJBossAllConfiguration parse(XMLExtendedStreamReader reader, DeploymentUnit deploymentUnit) throws XMLStreamException {
Boolean requireBeanDescriptor = null;
Boolean nonPortableMode = null;
Boolean developmentMode = null;

for (int i = 0; i < reader.getAttributeCount(); i++) {
final String name = reader.getAttributeLocalName(i);
final String value = reader.getAttributeValue(i);
switch (name) {
case REQUIRE_BEAN_DESCRIPTOR_ATTRIBUTE_NAME: {
requireBeanDescriptor = Boolean.valueOf(value);
break;
}
case NON_PORTABLE_MODE_ATTRIBUTE_NAME: {
nonPortableMode = Boolean.valueOf(value);
break;
}
case DEVELOPMENT_MODE_ATTRIBUTE_NAME: {
developmentMode = Boolean.valueOf(value);
break;
}
default: {
throw ParseUtils.unexpectedAttribute(reader, i);
}
}
}
Boolean requireBeanDescriptor = getAttributeAsBoolean(reader, REQUIRE_BEAN_DESCRIPTOR_ATTRIBUTE_NAME);
Boolean nonPortableMode = getAttributeAsBoolean(reader, NON_PORTABLE_MODE_ATTRIBUTE_NAME);
Boolean developmentMode = getAttributeAsBoolean(reader, DEVELOPMENT_MODE_ATTRIBUTE_NAME);
return new WeldJBossAllConfiguration(requireBeanDescriptor, nonPortableMode, developmentMode);
}

Expand Down
6 changes: 5 additions & 1 deletion weld/src/main/java/org/jboss/as/weld/WeldSubsystemAdd.java
Expand Up @@ -81,7 +81,11 @@ protected void performBoottime(final OperationContext context, ModelNode operati
context.addStep(new AbstractDeploymentChainStep() {
@Override
protected void execute(DeploymentProcessorTarget processorTarget) {
processorTarget.addDeploymentProcessor(WeldExtension.SUBSYSTEM_NAME, Phase.STRUCTURE, Phase.STRUCTURE_REGISTER_JBOSS_ALL_WELD, new JBossAllXmlParserRegisteringProcessor<>(WeldJBossAllParser.ROOT_ELEMENT, WeldJBossAllConfiguration.ATTACHMENT_KEY, WeldJBossAllParser.INSTANCE));
final JBossAllXmlParserRegisteringProcessor<?> jbossAllParsers = JBossAllXmlParserRegisteringProcessor.builder()
.addParser(WeldJBossAll10Parser.ROOT_ELEMENT, WeldJBossAllConfiguration.ATTACHMENT_KEY, WeldJBossAll10Parser.INSTANCE)
.addParser(WeldJBossAll11Parser.ROOT_ELEMENT, WeldJBossAllConfiguration.ATTACHMENT_KEY, WeldJBossAll11Parser.INSTANCE)
.build();
processorTarget.addDeploymentProcessor(WeldExtension.SUBSYSTEM_NAME, Phase.STRUCTURE, Phase.STRUCTURE_REGISTER_JBOSS_ALL_WELD, jbossAllParsers);
processorTarget.addDeploymentProcessor(WeldExtension.SUBSYSTEM_NAME, Phase.PARSE, Phase.PARSE_WELD_CONFIGURATION, new WeldConfigurationProcessor(requireBeanDescriptor, nonPortableMode, developmentMode));
processorTarget.addDeploymentProcessor(WeldExtension.SUBSYSTEM_NAME, Phase.PARSE, Phase.PARSE_CDI_ANNOTATIONS, new CdiAnnotationProcessor());
processorTarget.addDeploymentProcessor(WeldExtension.SUBSYSTEM_NAME, Phase.PARSE, Phase.PARSE_CDI_BEAN_DEFINING_ANNOTATIONS, new BeanDefiningAnnotationProcessor());
Expand Down
5 changes: 0 additions & 5 deletions weld/src/main/resources/schema/jboss-weld-1_0.xsd
Expand Up @@ -42,11 +42,6 @@
<xs:documentation>If true then the non-portable mode is enabled. The non-portable mode is suggested by the specification to overcome problems with legacy applications that do not use CDI SPI properly and may be rejected by more strict validation in CDI 1.1.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="development-mode" type="xs:boolean" default="false">
<xs:annotation>
<xs:documentation>Weld comes with a special mode for application development. When the development mode is enabled, certain built-in tools, which facilitate the development of CDI applications, are available. Setting this attribute to true activates the development mode.</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>

</xs:schema>
52 changes: 52 additions & 0 deletions weld/src/main/resources/schema/jboss-weld-1_1.xsd
@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
~ JBoss, Home of Professional Open Source.
~ Copyright 2013, 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.
-->

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="urn:jboss:weld:1.1"
xmlns="urn:jboss:weld:1.1"
elementFormDefault="qualified"
attributeFormDefault="unqualified"
version="1.1">

<xs:element name="weld" type="configuration"/>

<xs:complexType name="configuration">
<xs:attribute name="require-bean-descriptor" type="xs:boolean" default="false">
<xs:annotation>
<xs:documentation>If true then implicit bean archives without bean descriptor file (beans.xml) are ignored by Weld</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="non-portable-mode" type="xs:boolean" default="false">
<xs:annotation>
<xs:documentation>If true then the non-portable mode is enabled. The non-portable mode is suggested by the specification to overcome problems with legacy applications that do not use CDI SPI properly and may be rejected by more strict validation in CDI 1.1.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="development-mode" type="xs:boolean" default="false">
<xs:annotation>
<xs:documentation>Weld comes with a special mode for application development. When the development mode is enabled, certain built-in tools, which facilitate the development of CDI applications, are available. Setting this attribute to true activates the development mode.</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>

</xs:schema>

0 comments on commit 5ef4158

Please sign in to comment.