Skip to content
This repository was archived by the owner on Nov 17, 2021. It is now read-only.

Commit 7c9ac55

Browse files
[resolves #144] Add plugin support for multiple namespace versions
1 parent 7e97fde commit 7c9ac55

File tree

4 files changed

+114
-20
lines changed

4 files changed

+114
-20
lines changed

config/src/main/java/org/wildfly/extras/config/ConfigSupport.java

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ public static void applyConfigChange(Path jbossHome, List<String> configs, boole
9292
ConfigLogger.info("Processing config for: " + plugin.getConfigName());
9393

9494
applyLayerChanges(jbossHome, plugin, enable);
95-
9695
applyConfigurationChanges(jbossHome, plugin, enable);
9796
}
9897
}
@@ -255,7 +254,6 @@ private static void applyConfigurationChanges(Path jbossHome, ConfigPlugin plugi
255254
domainPaths.add(Paths.get("domain", "configuration", "domain.xml"));
256255

257256
String message = (enable ? "\tEnable " : "\tDisable ") + plugin.getConfigName() + " configuration in: ";
258-
259257
String lineSeparator = System.getProperty("line.separator");
260258

261259
SAXBuilder jdom = new SAXBuilder();
@@ -374,16 +372,33 @@ private static byte[] loadBytesFromURL(URL resource) throws IOException {
374372
return out.toByteArray();
375373
}
376374

377-
@SuppressWarnings("unchecked")
375+
@Deprecated
378376
public static Element findElementWithAttributeValue(Element element, String name, Namespace ns, String attrName, String attrValue) {
379-
if (element.getName().equals(name) && element.getNamespace().equals(ns)) {
380-
Attribute attribute = element.getAttribute(attrName);
381-
if (attribute != null && attrValue.equals(attribute.getValue())) {
382-
return element;
377+
return findElementWithAttributeValue(element, name, attrName, attrValue, ns);
378+
}
379+
380+
@SuppressWarnings("unchecked")
381+
public static Element findElementWithAttributeValue(Element element, String name, String attrName, String attrValue, Namespace... supportedNamespaces) {
382+
for (Namespace ns : supportedNamespaces) {
383+
if (element.getName().equals(name) && element.getNamespace().equals(ns)) {
384+
Attribute attribute = element.getAttribute(attrName);
385+
if (attribute != null && attrValue.equals(attribute.getValue())) {
386+
return element;
387+
}
388+
}
389+
for (Element ch : (List<Element>) element.getChildren()) {
390+
Element result = findElementWithAttributeValue(ch, name, attrName, attrValue, supportedNamespaces);
391+
if (result != null) {
392+
return result;
393+
}
383394
}
384395
}
385-
for (Element ch : (List<Element>) element.getChildren()) {
386-
Element result = findElementWithAttributeValue(ch, name, ns, attrName, attrValue);
396+
return null;
397+
}
398+
399+
public static Element findChildElement(Element parent, String name, Namespace... supportedNamespaces) {
400+
for (Namespace ns : supportedNamespaces) {
401+
Element result = parent.getChild(name, ns);
387402
if (result != null) {
388403
return result;
389404
}
@@ -408,18 +423,24 @@ public static Map<String, Element> mapByAttributeName(List<Element> elements, St
408423
return rc;
409424
}
410425

411-
@SuppressWarnings("unchecked")
426+
@Deprecated
412427
public static List<Element> findProfileElements(Document doc, Namespace ns) {
428+
return findProfileElements(doc, new Namespace[] {ns});
429+
}
430+
431+
@SuppressWarnings("unchecked")
432+
public static List<Element> findProfileElements(Document doc, Namespace... supportedNamespaces) {
413433
List<Element> result = new ArrayList<>();
414-
Element profile = doc.getRootElement().getChild("profile", ns);
415-
if (profile != null) {
416-
result.add(profile);
417-
}
418-
Element profiles = doc.getRootElement().getChild("profiles", ns);
419-
if (profiles != null) {
420-
result.addAll(profiles.getChildren("profile", ns));
434+
for (Namespace ns : supportedNamespaces) {
435+
Element profile = doc.getRootElement().getChild("profile", ns);
436+
if (profile != null) {
437+
result.add(profile);
438+
}
439+
Element profiles = doc.getRootElement().getChild("profiles", ns);
440+
if (profiles != null) {
441+
result.addAll(profiles.getChildren("profile", ns));
442+
}
421443
}
422444
return result;
423445
}
424-
425446
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* #%L
3+
* Fuse EAP :: Config
4+
* %%
5+
* Copyright (C) 2015 RedHat
6+
* %%
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* #L%
19+
*/
20+
package org.wildfly.extras.config;
21+
22+
public interface NamespaceConstants {
23+
String NS_DOMAIN = "urn:jboss:domain";
24+
String NS_INFINISPAN = "urn:jboss:domain:infinispan";
25+
String NS_LOGGING = "urn:jboss:domain:logging";
26+
String NS_SECURITY = "urn:jboss:domain:security";
27+
String NS_WELD = "urn:jboss:domain:weld";
28+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* #%L
3+
* Fuse EAP :: Config
4+
* %%
5+
* Copyright (C) 2015 RedHat
6+
* %%
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* #L%
19+
*/
20+
package org.wildfly.extras.config;
21+
22+
import java.util.ArrayList;
23+
import java.util.LinkedHashMap;
24+
import java.util.List;
25+
import java.util.Map;
26+
27+
import org.jdom.Namespace;
28+
import org.wildfly.extras.config.internal.IllegalArgumentAssertion;
29+
30+
public class NamespaceRegistry {
31+
private Map<String, List<Namespace>> namespaces = new LinkedHashMap<>();
32+
33+
public void registerNamespace(String namespace, String version) {
34+
if (!namespaces.containsKey(namespace)) {
35+
namespaces.put(namespace, new ArrayList<Namespace>());
36+
}
37+
namespaces.get(namespace).add(Namespace.getNamespace(namespace + ":" + version));
38+
}
39+
40+
public Namespace[] getNamespaces(String namespace) {
41+
IllegalArgumentAssertion.assertTrue(namespaces.containsKey(namespace), "Unsupported namespace: " + namespace);
42+
List<Namespace> namespaces = this.namespaces.get(namespace);
43+
return namespaces.toArray(new Namespace[namespaces.size()]);
44+
}
45+
}

config/src/test/java/org/wildfly/camel/test/config/ConfigSupportTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public List<LayerConfig> getLayerConfigs() {
5858
@Override
5959
public void applyStandaloneConfigChange(ConfigContext context, boolean enable) {
6060
}
61-
61+
6262
@Override
6363
public void applyDomainConfigChange(ConfigContext context, boolean enable) {
6464
}
@@ -109,7 +109,7 @@ public List<LayerConfig> getLayerConfigs() {
109109
@Override
110110
public void applyStandaloneConfigChange(ConfigContext context, boolean enable) {
111111
}
112-
112+
113113
@Override
114114
public void applyDomainConfigChange(ConfigContext context, boolean enable) {
115115
}

0 commit comments

Comments
 (0)