1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.neethi;
17
18 import javax.xml.stream.XMLStreamException;
19 import javax.xml.stream.XMLStreamWriter;
20
21
22
23
24 public class PolicyReference implements PolicyComponent {
25
26 private String uri;
27
28
29
30
31
32 public void setURI(String uri) {
33 this.uri = uri;
34 }
35
36
37
38
39
40 public String getURI() {
41 return uri;
42 }
43
44 public boolean equal(PolicyComponent policyComponent) {
45 if (Constants.TYPE_POLICY_REF != policyComponent.getType()) {
46 return false;
47 }
48
49 String URI = ((PolicyReference) policyComponent).getURI();
50 if (URI != null && URI.length() != 0) {
51 return URI.equals(this.uri);
52 }
53
54 return false;
55 }
56
57
58
59
60
61 public short getType() {
62 return Constants.TYPE_POLICY_REF;
63 }
64
65
66
67
68
69
70 public PolicyComponent normalize() {
71 throw new UnsupportedOperationException("PolicyReference.normalize() is meaningless");
72 }
73
74
75
76
77
78
79
80
81
82
83 public PolicyComponent normalize(PolicyRegistry reg, boolean deep) {
84 String key = getURI();
85 if (key.startsWith("#")) {
86 key = key.substring(1);
87 }
88
89 Policy policy = reg.lookup(key);
90
91 if (policy == null) {
92 throw new RuntimeException(key + " can't be resolved" );
93 }
94
95 return policy.normalize(reg, deep);
96 }
97
98 public void serialize(XMLStreamWriter writer) throws XMLStreamException {
99
100 String wspPrefix = writer.getPrefix(Constants.URI_POLICY_NS);
101
102 if (wspPrefix == null) {
103 wspPrefix = Constants.ATTR_WSP;
104 writer.setPrefix(wspPrefix, Constants.URI_POLICY_NS);
105 }
106
107 writer.writeStartElement(wspPrefix, Constants.ELEM_POLICY_REF, Constants.URI_POLICY_NS);
108
109 writer.writeAttribute(Constants.ATTR_URI, getURI());
110
111 writer.writeEndElement();
112 }
113 }