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 java.util.HashMap;
38 import java.util.Iterator;
39 import java.util.List;
40 import java.util.Map;
41 import java.util.Vector;
42
43 import javax.xml.namespace.QName;
44
45 import org.apache.log4j.Logger;
46 import org.apache.muse.core.Resource;
47 import org.apache.muse.core.serializer.SerializerRegistry;
48 import org.apache.muse.ws.addressing.EndpointReference;
49 import org.apache.muse.ws.addressing.soap.SoapFault;
50 import org.apache.muse.ws.resource.WsResource;
51 import org.apache.muse.ws.resource.sg.MembershipContentRule;
52 import org.apache.muse.ws.resource.sg.ServiceGroupPersistence;
53 import org.apache.muse.ws.resource.sg.impl.SimpleServiceGroup;
54
55
56
57
58
59
60
61 public class ServiceGroup extends SimpleServiceGroup
62 {
63
64 private static final Logger LOG = Logger.getLogger( ServiceGroup.class );
65
66 private Map<EndpointReference, WsResource> entriesByMemberEPR =
67 new HashMap<EndpointReference, WsResource>();
68
69 private List<WsResource> entryResources = new Vector<WsResource>();
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87 public void resourceAdded( EndpointReference memberEPR, Resource resource ) throws SoapFault
88 {
89 try
90 {
91 QName porttype = resource.getWsdlPortType();
92 if ( porttype != null )
93 {
94 if ( LOG.isDebugEnabled() )
95 {
96 LOG.debug( "Created resource with port type " + porttype
97 + ". Setting port type for MembershipContentRuleContext." );
98 }
99
100 MembershipContentRuleContext.setPortTypeQName( porttype );
101 }
102 else
103 {
104 if ( LOG.isDebugEnabled() )
105 {
106 LOG.debug( "Could not set port type for MembershipContentRuleContext. WSDL port type is null." );
107 }
108 }
109
110 super.resourceAdded( memberEPR, resource );
111 }
112 finally
113 {
114 MembershipContentRuleContext.setPortTypeQName( null );
115 }
116 }
117
118
119
120
121
122
123
124
125
126 public void initialize() throws SoapFault
127 {
128 super.initialize();
129 SerializerRegistry registry = SerializerRegistry.getInstance();
130 registry.registerSerializer( MembershipContentRule.class, new MembershipContentRuleSerializer() );
131 }
132
133
134
135
136
137
138
139
140 @Override
141 public void resourceRemoved( EndpointReference epr ) throws SoapFault
142 {
143
144
145
146
147 if ( hasBeenShutdown() )
148 {
149 getWsResource().getResourceManager().removeListener( this );
150 }
151 else
152 {
153 WsResource entry = getEntry( epr );
154
155
156
157
158
159
160
161
162 if ( entry != null )
163 {
164 entry.shutdown();
165 }
166 }
167 }
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184 public synchronized WsResource addEntry( EndpointReference memberEPR, WsResource entry )
185 {
186 entriesByMemberEPR.put( memberEPR, entry );
187 entryResources.add( entry );
188 return entry;
189 }
190
191
192
193
194
195
196 public synchronized WsResource[] getEntry()
197 {
198 WsResource[] asArray = new WsResource[entryResources.size()];
199 return (WsResource[]) entryResources.toArray( asArray );
200 }
201
202
203
204
205
206
207
208
209
210 public synchronized WsResource getEntry( EndpointReference memberEPR )
211 {
212 return entriesByMemberEPR.get( memberEPR );
213 }
214
215
216
217
218
219
220
221 public synchronized void removeEntry( WsResource entry )
222 {
223 if ( entry == null )
224 {
225 throw new NullPointerException( "The entry resource is null." );
226 }
227
228
229
230
231
232
233
234 Iterator<EndpointReference> i = entriesByMemberEPR.keySet().iterator();
235 EndpointReference memberEPR = null;
236
237 while ( i.hasNext() && memberEPR == null )
238 {
239 EndpointReference nextEPR = (EndpointReference) i.next();
240 WsResource nextEntry = (WsResource) entriesByMemberEPR.get( nextEPR );
241
242 if ( entry == nextEntry )
243 {
244 memberEPR = nextEPR;
245 }
246 }
247
248 String message = "The Entry reference was not found in the ServiceGroup, so it could not be removed.";
249 if ( entriesByMemberEPR.remove( memberEPR ) == null )
250 {
251
252 throw new RuntimeException( message );
253 }
254
255 if ( !entryResources.remove( entry ) )
256 {
257 throw new RuntimeException( message );
258 }
259
260
261
262
263 ServiceGroupPersistence persistence = (ServiceGroupPersistence) getPersistence();
264
265 try
266 {
267 if ( persistence != null )
268 {
269 persistence.resourceRemoved( entry.getEndpointReference() );
270 }
271 }
272 catch ( SoapFault fault )
273 {
274 LOG.error( fault );
275 }
276 }
277
278 }