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