Skip to content

Commit 2d30c71

Browse files
bstansberrykabir
authored andcommitted
If necessary, install default jsf subsystem at end of profile xml parsing
1 parent c51ccad commit 2d30c71

File tree

14 files changed

+317
-58
lines changed

14 files changed

+317
-58
lines changed

controller/src/main/java/org/jboss/as/controller/extension/ExtensionAddHandler.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,11 @@
2222
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP;
2323
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR;
2424

25-
import java.util.Map;
26-
2725
import org.jboss.as.controller.Extension;
2826
import org.jboss.as.controller.OperationContext;
2927
import org.jboss.as.controller.OperationFailedException;
3028
import org.jboss.as.controller.OperationStepHandler;
3129
import org.jboss.as.controller.PathAddress;
32-
import org.jboss.as.controller.ProcessType;
33-
import org.jboss.as.controller.services.path.PathManager;
3430
import org.jboss.dmr.ModelNode;
3531
import org.jboss.modules.Module;
3632
import org.jboss.modules.ModuleIdentifier;
@@ -73,6 +69,7 @@ public ExtensionAddHandler(final ExtensionRegistry extensionRegistry, final bool
7369
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
7470
final String moduleName = PathAddress.pathAddress(operation.require(OP_ADDR)).getLastElement().getValue();
7571
ExtensionResource resource = new ExtensionResource(moduleName, extensionRegistry);
72+
7673
context.addResource(PathAddress.EMPTY_ADDRESS, resource);
7774

7875
if (!parallelBoot || !context.isBooting()) {
@@ -86,6 +83,7 @@ public void execute(OperationContext context, ModelNode operation) throws Operat
8683

8784
context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER);
8885
}
86+
8987
void initializeExtension(String module) throws OperationFailedException {
9088
try {
9189
for (Extension extension : Module.loadServiceFromCallerModuleLoader(ModuleIdentifier.fromString(module), Extension.class)) {

controller/src/main/java/org/jboss/as/controller/extension/ExtensionRegistry.java

+30-4
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
4242
import org.jboss.as.controller.descriptions.OverrideDescriptionProvider;
4343
import org.jboss.as.controller.parsing.ExtensionParsingContext;
44+
import org.jboss.as.controller.parsing.ProfileParsingCompletionHandler;
4445
import org.jboss.as.controller.persistence.SubsystemMarshallingContext;
4546
import org.jboss.as.controller.persistence.SubsystemXmlWriterRegistry;
4647
import org.jboss.as.controller.registry.AttributeAccess;
@@ -212,8 +213,6 @@ public ExtensionParsingContext getExtensionParsingContext(final String moduleNam
212213
*
213214
* @return the {@link ExtensionContext}. Will not return {@code null}
214215
*
215-
* @param moduleName the name of the extension's module. Cannot be {@code null}
216-
* @return the {@link ExtensionContext}. Will not return {@code null}
217216
* @throws IllegalStateException if no {@link #setSubsystemParentResourceRegistrations(ManagementResourceRegistration, ManagementResourceRegistration)} profile resource registration has been set}
218217
*/
219218
public ExtensionContext getExtensionContext(final String moduleName) {
@@ -245,6 +244,19 @@ public Set<String> getUnnamedNamespaces(final String moduleName) {
245244
return result;
246245
}
247246

247+
public Set<ProfileParsingCompletionHandler> getProfileParsingCompletionHandlers() {
248+
Set<ProfileParsingCompletionHandler> result = new HashSet<ProfileParsingCompletionHandler>();
249+
250+
for (ExtensionInfo extensionInfo : extensions.values()) {
251+
synchronized (extensionInfo) {
252+
if (extensionInfo.parsingCompletionHandler != null) {
253+
result.add(extensionInfo.parsingCompletionHandler);
254+
}
255+
}
256+
}
257+
return Collections.unmodifiableSet(result);
258+
}
259+
248260
/**
249261
* Cleans up a module's subsystems from the resource registration model.
250262
*
@@ -419,13 +431,20 @@ public void setDeploymentXmlMapping(String namespaceUri, XMLElementReader<ModelN
419431
public void setDeploymentXmlMapping(String subsystemName, String namespaceUri, XMLElementReader<ModelNode> reader) {
420432
// ignored
421433
}
434+
435+
@Override
436+
public void setProfileParsingCompletionHandler(ProfileParsingCompletionHandler handler) {
437+
assert handler != null : "handler is null";
438+
synchronized (extension) {
439+
extension.parsingCompletionHandler = handler;
440+
}
441+
}
422442
}
423443

424444
public class ExtensionContextImpl implements ExtensionContext {
425445

426446
private final ExtensionInfo extension;
427447
private final PathManager pathManager;
428-
private String subsystemName;
429448

430449
private ExtensionContextImpl(String extensionName, PathManager pathManager) {
431450
assert pathManager != null || !processType.isServer() : "pathManager is null";
@@ -442,7 +461,6 @@ public SubsystemRegistration registerSubsystem(String name, int majorVersion, in
442461
@Override
443462
public SubsystemRegistration registerSubsystem(String name, int majorVersion, int minorVersion, int microVersion) {
444463
assert name != null : "name is null";
445-
this.subsystemName = name;
446464
checkNewSubystem(extension.extensionModuleName, name);
447465
SubsystemInformationImpl info = extension.getSubsystemInfo(name);
448466
info.setMajorVersion(majorVersion);
@@ -592,6 +610,7 @@ public class ExtensionInfo {
592610
private final Set<String> unnamedParsers = new HashSet<String>();
593611
private final String extensionModuleName;
594612
private XMLMapper xmlMapper;
613+
private ProfileParsingCompletionHandler parsingCompletionHandler;
595614

596615
public ExtensionInfo(String extensionModuleName) {
597616
this.extensionModuleName = extensionModuleName;
@@ -710,6 +729,7 @@ public ManagementResourceRegistration getSubModel(PathAddress address) {
710729
return deployments.getSubModel(address);
711730
}
712731

732+
@SuppressWarnings("deprecation")
713733
@Override
714734
public ManagementResourceRegistration registerSubModel(PathElement address, DescriptionProvider descriptionProvider) {
715735
ManagementResourceRegistration depl = deployments.registerSubModel(address, descriptionProvider);
@@ -801,12 +821,14 @@ public void unregisterOperationHandler(String operationName) {
801821
subdeployments.unregisterOperationHandler(operationName);
802822
}
803823

824+
@SuppressWarnings("deprecation")
804825
@Override
805826
public void registerReadWriteAttribute(String attributeName, OperationStepHandler readHandler, OperationStepHandler writeHandler, AttributeAccess.Storage storage) {
806827
deployments.registerReadWriteAttribute(attributeName, readHandler, writeHandler, storage);
807828
subdeployments.registerReadWriteAttribute(attributeName, readHandler, writeHandler, storage);
808829
}
809830

831+
@SuppressWarnings("deprecation")
810832
@Override
811833
public void registerReadWriteAttribute(String attributeName, OperationStepHandler readHandler, OperationStepHandler writeHandler, EnumSet<AttributeAccess.Flag> flags) {
812834
deployments.registerReadWriteAttribute(attributeName, readHandler, writeHandler, flags);
@@ -819,12 +841,14 @@ public void registerReadWriteAttribute(AttributeDefinition definition, Operation
819841
subdeployments.registerReadWriteAttribute(definition, readHandler, writeHandler);
820842
}
821843

844+
@SuppressWarnings("deprecation")
822845
@Override
823846
public void registerReadOnlyAttribute(String attributeName, OperationStepHandler readHandler, AttributeAccess.Storage storage) {
824847
deployments.registerReadOnlyAttribute(attributeName, readHandler, storage);
825848
subdeployments.registerReadOnlyAttribute(attributeName, readHandler, storage);
826849
}
827850

851+
@SuppressWarnings("deprecation")
828852
@Override
829853
public void registerReadOnlyAttribute(String attributeName, OperationStepHandler readHandler, EnumSet<AttributeAccess.Flag> flags) {
830854
deployments.registerReadOnlyAttribute(attributeName, readHandler, flags);
@@ -837,6 +861,7 @@ public void registerReadOnlyAttribute(AttributeDefinition definition, OperationS
837861
subdeployments.registerReadOnlyAttribute(definition, readHandler);
838862
}
839863

864+
@SuppressWarnings("deprecation")
840865
@Override
841866
public void registerMetric(String attributeName, OperationStepHandler metricHandler) {
842867
deployments.registerMetric(attributeName, metricHandler);
@@ -849,6 +874,7 @@ public void registerMetric(AttributeDefinition definition, OperationStepHandler
849874
subdeployments.registerMetric(definition, metricHandler);
850875
}
851876

877+
@SuppressWarnings("deprecation")
852878
@Override
853879
public void registerMetric(String attributeName, OperationStepHandler metricHandler, EnumSet<AttributeAccess.Flag> flags) {
854880
deployments.registerMetric(attributeName, metricHandler, flags);

controller/src/main/java/org/jboss/as/controller/parsing/ExtensionParsingContext.java

+8
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,12 @@ public interface ExtensionParsingContext {
100100
@Deprecated
101101
void setDeploymentXmlMapping(String subsystemName, String namespaceUri, XMLElementReader<ModelNode> reader);
102102

103+
/**
104+
* Registers a {@link ProfileParsingCompletionHandler} to receive a callback upon completion of parsing of a
105+
* profile.
106+
*
107+
* @param handler the handler. Cannot be {@code null}
108+
*/
109+
void setProfileParsingCompletionHandler(ProfileParsingCompletionHandler handler);
110+
103111
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* JBoss, Home of Professional Open Source.
3+
* Copyright 2012, Red Hat, Inc., and individual contributors
4+
* as indicated by the @author tags. See the copyright.txt file in the
5+
* distribution for a full listing of individual contributors.
6+
*
7+
* This is free software; you can redistribute it and/or modify it
8+
* under the terms of the GNU Lesser General Public License as
9+
* published by the Free Software Foundation; either version 2.1 of
10+
* the License, or (at your option) any later version.
11+
*
12+
* This software is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public
18+
* License along with this software; if not, write to the Free
19+
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20+
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21+
*/
22+
23+
package org.jboss.as.controller.parsing;
24+
25+
import java.util.List;
26+
import java.util.Map;
27+
28+
import org.jboss.as.controller.Extension;
29+
import org.jboss.dmr.ModelNode;
30+
31+
/**
32+
* Callback an {@link Extension} can register to, upon completion of normal parsing of a profile, manipulate the list
33+
* of parsed boot operations associated with a profile.
34+
*
35+
* @author Brian Stansberry (c) 2011 Red Hat Inc.
36+
*/
37+
public interface ProfileParsingCompletionHandler {
38+
39+
/**
40+
* Callback indicating normal parsing of a profile is completed.
41+
*
42+
* @param profileBootOperations the boot operations added by subsystems in the profile, keyed by the URI of the
43+
* xml namespace used for the subsystem
44+
* @param otherBootOperations other operations registered in the boot prior to parsing of the profile
45+
*/
46+
void handleProfileParsingCompletion(final Map<String, List<ModelNode>> profileBootOperations, List<ModelNode> otherBootOperations);
47+
}

host-controller/src/main/java/org/jboss/as/host/controller/parsing/DomainXml.java

+30-12
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@
6767
import java.util.Collections;
6868
import java.util.EnumSet;
6969
import java.util.HashSet;
70+
import java.util.LinkedHashMap;
7071
import java.util.List;
72+
import java.util.Map;
7173
import java.util.Set;
7274
import java.util.concurrent.ExecutorService;
7375

@@ -83,6 +85,7 @@
8385
import org.jboss.as.controller.parsing.ExtensionXml;
8486
import org.jboss.as.controller.parsing.Namespace;
8587
import org.jboss.as.controller.parsing.ParseUtils;
88+
import org.jboss.as.controller.parsing.ProfileParsingCompletionHandler;
8689
import org.jboss.as.controller.persistence.ModelMarshallingContext;
8790
import org.jboss.as.controller.persistence.SubsystemMarshallingContext;
8891
import org.jboss.as.controller.resource.SocketBindingGroupResourceDefinition;
@@ -105,10 +108,12 @@
105108
public class DomainXml extends CommonXml {
106109

107110
private final ExtensionXml extensionXml;
111+
private final ExtensionRegistry extensionRegistry;
108112

109113
public DomainXml(final ModuleLoader loader, ExecutorService executorService, ExtensionRegistry extensionRegistry) {
110114
super();
111115
extensionXml = new ExtensionXml(loader, executorService, extensionRegistry);
116+
this.extensionRegistry = extensionRegistry;
112117
}
113118

114119
@Override
@@ -714,26 +719,30 @@ void parseProfiles(final XMLExtendedStreamReader reader, final ModelNode address
714719
throw MESSAGES.duplicateDeclaration("profile", name, reader.getLocation());
715720
}
716721

717-
final List<ModelNode> subsystems = new ArrayList<ModelNode>();
722+
718723
//final Set<String> includes = new HashSet<String>(); // See commented out section below.
719724
//final ModelNode profileIncludes = new ModelNode();
720725

721726
// Content
722727
// Sequence
723-
final Set<String> configuredSubsystemTypes = new HashSet<String>();
728+
final Map<String, List<ModelNode>> profileOps = new LinkedHashMap<String, List<ModelNode>>();
724729
while (reader.nextTag() != END_ELEMENT) {
725730
Namespace ns = Namespace.forUri(reader.getNamespaceURI());
726731
switch (ns) {
727732
case UNKNOWN: {
728733
if (Element.forName(reader.getLocalName()) != Element.SUBSYSTEM) {
729734
throw unexpectedElement(reader);
730735
}
731-
if (!configuredSubsystemTypes.add(reader.getNamespaceURI())) {
736+
String namespace = reader.getNamespaceURI();
737+
if (profileOps.containsKey(namespace)) {
732738
throw MESSAGES.duplicateDeclaration("subsystem", name, reader.getLocation());
733739
}
734740
// parse content
741+
final List<ModelNode> subsystems = new ArrayList<ModelNode>();
735742
reader.handleAny(subsystems);
736743

744+
profileOps.put(namespace, subsystems);
745+
737746
break;
738747
}
739748
case DOMAIN_1_0:
@@ -742,7 +751,7 @@ void parseProfiles(final XMLExtendedStreamReader reader, final ModelNode address
742751
case DOMAIN_1_3:{
743752
requireNamespace(reader, expectedNs);
744753
// include should come first
745-
if (configuredSubsystemTypes.size() > 0) {
754+
if (profileOps.size() > 0) {
746755
throw unexpectedElement(reader);
747756
}
748757
if (Element.forName(reader.getLocalName()) != Element.INCLUDE) {
@@ -770,6 +779,13 @@ void parseProfiles(final XMLExtendedStreamReader reader, final ModelNode address
770779
}
771780
}
772781
}
782+
783+
// Let extensions modify the profile
784+
Set<ProfileParsingCompletionHandler> completionHandlers = extensionRegistry.getProfileParsingCompletionHandlers();
785+
for (ProfileParsingCompletionHandler completionHandler : completionHandlers) {
786+
completionHandler.handleProfileParsingCompletion(profileOps, list);
787+
}
788+
773789
final ModelNode profile = new ModelNode();
774790
profile.get(OP).set(ADD);
775791
profile.get(OP_ADDR).set(address).add(ModelDescriptionConstants.PROFILE, name);
@@ -779,17 +795,19 @@ void parseProfiles(final XMLExtendedStreamReader reader, final ModelNode address
779795
list.add(profile);
780796

781797
// Process subsystems
782-
for(final ModelNode update : subsystems) {
783-
// Process relative subsystem path address
784-
final ModelNode subsystemAddress = address.clone().set(address).add(ModelDescriptionConstants.PROFILE, name);
785-
for(final Property path : update.get(OP_ADDR).asPropertyList()) {
786-
subsystemAddress.add(path.getName(), path.getValue().asString());
798+
for (List<ModelNode> subsystems : profileOps.values()) {
799+
for(final ModelNode update : subsystems) {
800+
// Process relative subsystem path address
801+
final ModelNode subsystemAddress = address.clone().set(address).add(ModelDescriptionConstants.PROFILE, name);
802+
for(final Property path : update.get(OP_ADDR).asPropertyList()) {
803+
subsystemAddress.add(path.getName(), path.getValue().asString());
804+
}
805+
update.get(OP_ADDR).set(subsystemAddress);
806+
list.add(update);
787807
}
788-
update.get(OP_ADDR).set(subsystemAddress);
789-
list.add(update);
790808
}
791809

792-
if (configuredSubsystemTypes.size() == 0) {
810+
if (profileOps.size() == 0) {
793811
throw MESSAGES.profileHasNoSubsystems(reader.getLocation());
794812
}
795813
}

jsf/src/main/java/org/jboss/as/jsf/subsystem/JSFSubsystemAdd.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
package org.jboss.as.jsf.subsystem;
2424

25+
import java.util.List;
26+
2527
import org.jboss.as.controller.AbstractBoottimeAddStepHandler;
2628
import org.jboss.as.controller.OperationContext;
2729
import org.jboss.as.controller.ServiceVerificationHandler;
@@ -36,8 +38,6 @@
3638
import org.jboss.dmr.ModelNode;
3739
import org.jboss.msc.service.ServiceController;
3840

39-
import java.util.List;
40-
4141
/**
4242
* The JSF subsystem add update handler.
4343
*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<subsystem xmlns="urn:jboss:domain:web:1.0" default-virtual-server="default-host">
2+
<connector name="http" scheme="http" protocol="HTTP/1.1" socket-binding="http"/>
3+
<virtual-server name="default-host" enable-welcome-root="false">
4+
<alias name="localhost"/>
5+
<alias name="example.com"/>
6+
</virtual-server>
7+
</subsystem>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<subsystem xmlns="urn:jboss:domain:web:1.1" default-virtual-server="default-host">
2+
<connector name="http" scheme="http" protocol="HTTP/1.1" socket-binding="http"/>
3+
<virtual-server name="default-host" enable-welcome-root="false">
4+
<alias name="localhost"/>
5+
<alias name="example.com"/>
6+
</virtual-server>
7+
</subsystem>

0 commit comments

Comments
 (0)