1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 package org.ogf.graap.wsag.wsrf.sg.impl;
36
37 import javax.xml.namespace.QName;
38
39 import org.apache.log4j.Logger;
40 import org.apache.muse.ws.addressing.EndpointReference;
41 import org.apache.muse.ws.metadata.remote.MetadataExchangeClient;
42 import org.apache.muse.ws.resource.sg.impl.SimpleMembershipContentRule;
43 import org.apache.xmlbeans.XmlException;
44 import org.apache.xmlbeans.XmlObject;
45 import org.ogf.graap.wsag.api.WsagConstants;
46 import org.ogf.graap.wsag4j.types.engine.WSAG4JMetadataDocument;
47 import org.w3c.dom.Element;
48
49
50
51
52
53
54
55 public class MembershipContentRule extends SimpleMembershipContentRule
56 {
57
58 private static final Logger LOG = Logger.getLogger( MembershipContentRule.class );
59
60
61
62
63 public MembershipContentRule()
64 {
65 super();
66 }
67
68
69
70
71
72
73
74
75
76 public MembershipContentRule( Element xml )
77 {
78 super( xml );
79 }
80
81
82
83
84
85
86
87
88
89 public boolean isMatch( EndpointReference memberEPR )
90 {
91 boolean result = super.isMatch( memberEPR );
92
93 if ( result )
94 {
95 QName memberInterface = getMemberInterface();
96
97 if ( memberInterface != null )
98 {
99
100
101
102
103
104
105 QName porttype = MembershipContentRuleContext.getPortTypeQName();
106
107 if ( porttype != null )
108 {
109 boolean isMember =
110 memberInterface.getNamespaceURI().equals( porttype.getNamespaceURI() )
111 && memberInterface.getLocalPart().equals( porttype.getLocalPart() );
112
113 if ( LOG.isDebugEnabled() )
114 {
115 if ( isMember )
116 {
117 LOG.debug( "MembershipContentRule: Resource of type " + porttype.toString()
118 + " is member of service group. (MembershipInterface: "
119 + memberInterface.toString() + "). Resource will be added." );
120 }
121 else
122 {
123 LOG.debug( "MembershipContentRule: Resource of type " + porttype.toString()
124 + " not is member of service group. (MembershipInterface: "
125 + memberInterface.toString() + "). Resource was not added." );
126 }
127
128 }
129
130 return isMember;
131 }
132 else
133 {
134 if ( LOG.isDebugEnabled() )
135 {
136 LOG.debug( "MembershipContentRule: "
137 + "Could not retrieve resource port type from MembershipContentRuleContext. "
138 + "Port type is null." );
139 }
140 }
141
142 if ( LOG.isDebugEnabled() )
143 {
144 LOG.debug( "MembershipContentRule: Try to retrieve resource port type WS-MEX." );
145 }
146
147
148
149
150
151 try
152 {
153 MetadataExchangeClient mex = new MetadataExchangeClient( memberEPR );
154
155 Element[] response = mex.getMetadata( WsagConstants.WSAG4J_MEX_DIALECT );
156 if ( response.length == 1 )
157 {
158 try
159 {
160 WSAG4JMetadataDocument metadata =
161 (WSAG4JMetadataDocument) XmlObject.Factory.parse( response[0] );
162 porttype = metadata.getWSAG4JMetadata().getWSAG4JPortType();
163
164 return memberInterface.getNamespaceURI().equals( porttype.getNamespaceURI() )
165 && memberInterface.getLocalPart().equals( porttype.getLocalPart() );
166
167 }
168 catch ( XmlException e )
169 {
170
171
172
173 return false;
174 }
175 catch ( ClassCastException e )
176 {
177
178
179
180 return false;
181 }
182 }
183
184
185
186
187 return false;
188 }
189 catch ( Exception e )
190 {
191
192
193
194 return false;
195 }
196 }
197 }
198
199 return result;
200 }
201
202 }