1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
package org.mule.config.spring.parsers.processors; |
8 | |
|
9 | |
import org.mule.config.spring.parsers.PreProcessor; |
10 | |
import org.mule.config.spring.parsers.assembly.configuration.PropertyConfiguration; |
11 | |
import org.mule.config.spring.util.SpringXMLUtils; |
12 | |
|
13 | |
import java.util.Arrays; |
14 | |
import java.util.HashSet; |
15 | |
import java.util.Set; |
16 | |
|
17 | |
import org.w3c.dom.Attr; |
18 | |
import org.w3c.dom.Element; |
19 | |
import org.w3c.dom.NamedNodeMap; |
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
public class BlockAttribute implements PreProcessor |
27 | |
{ |
28 | |
private Set<String> disallowed; |
29 | |
|
30 | |
public BlockAttribute(String disallowed) |
31 | |
{ |
32 | 0 | this(new String[]{ disallowed }); |
33 | 0 | } |
34 | |
|
35 | |
public BlockAttribute(String[] disallowed) |
36 | 0 | { |
37 | 0 | this.disallowed = new HashSet<String>(Arrays.asList(disallowed)); |
38 | 0 | } |
39 | |
|
40 | |
public void preProcess(PropertyConfiguration config, Element element) |
41 | |
{ |
42 | 0 | NamedNodeMap attributes = element.getAttributes(); |
43 | 0 | for (int i = 0; i < attributes.getLength(); i++) |
44 | |
{ |
45 | 0 | String alias = SpringXMLUtils.attributeName((Attr) attributes.item(i)); |
46 | 0 | String name = config.translateName(alias); |
47 | 0 | if (disallowed.contains(name)) |
48 | |
{ |
49 | 0 | throw new BlockAttributeException("Attribute " + alias + " is not allowed here."); |
50 | |
} |
51 | |
} |
52 | 0 | } |
53 | |
|
54 | |
public static class BlockAttributeException extends IllegalStateException |
55 | |
{ |
56 | |
BlockAttributeException(String message) |
57 | |
{ |
58 | 0 | super(message); |
59 | 0 | } |
60 | |
} |
61 | |
} |