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.impl;
36
37 import java.util.HashMap;
38 import java.util.Map;
39
40 import javax.xml.namespace.QName;
41
42 import org.apache.log4j.Logger;
43 import org.apache.muse.core.Resource;
44 import org.apache.muse.ws.addressing.EndpointReference;
45 import org.apache.muse.ws.addressing.soap.SoapFault;
46 import org.apache.muse.ws.resource.faults.ResourceUnavailableFault;
47 import org.apache.xmlbeans.XmlObject;
48 import org.ogf.graap.wsag.api.Negotiation;
49 import org.ogf.graap.wsag.api.exceptions.NegotiationFactoryException;
50 import org.ogf.graap.wsag.server.persistence.PersistentAgreementFactory;
51 import org.ogf.graap.wsag.wsrf.WSAG4JCapability;
52 import org.ogf.graap.wsag.wsrf.XmlUtils;
53 import org.ogf.graap.wsag.wsrf.faults.AgreementFactoryFault;
54 import org.ogf.schemas.graap.wsAgreement.negotiation.NegotiationContextType;
55 import org.ogf.schemas.graap.wsAgreement.negotiation.protocol.InitiateNegotiationInputDocument;
56 import org.ogf.schemas.graap.wsAgreement.negotiation.protocol.InitiateNegotiationInputType;
57 import org.ogf.schemas.graap.wsAgreement.negotiation.protocol.InitiateNegotiationOutputDocument;
58 import org.ogf.schemas.graap.wsAgreement.negotiation.protocol.InitiateNegotiationOutputType;
59 import org.w3.x2005.x08.addressing.EndpointReferenceType;
60
61
62
63
64
65 public class NegotiationFactoryCapability extends WSAG4JCapability
66 {
67
68 private static final Logger LOG = Logger.getLogger( NegotiationFactoryCapability.class );
69
70 private PersistentAgreementFactory getFactoryPersistence()
71 {
72 return ( (AgreementFactoryWsResource) getResource() ).getAgreementFactory();
73 }
74
75
76
77
78 public QName[] getPropertyNames()
79 {
80 return new QName[0];
81 }
82
83
84
85
86
87
88
89
90
91
92
93
94 public InitiateNegotiationOutputType initiateNegotiation( InitiateNegotiationInputDocument initiateInput )
95 throws SoapFault
96 {
97
98 InitiateNegotiationInputType input = initiateInput.getInitiateNegotiationInput();
99
100 NegotiationContextType context = input.getNegotiationContext();
101 XmlObject[] ncExtensions = input.getNoncriticalExtensionArray();
102 XmlObject[] cExtensions = new XmlObject[0];
103 Map<String, Object> environment = new HashMap<String, Object>();
104
105 Negotiation createdNegotiation = null;
106
107 try
108 {
109
110
111
112 createdNegotiation =
113 getFactoryPersistence().initiateNegotiation( context, cExtensions, ncExtensions, environment );
114 }
115 catch ( NegotiationFactoryException e )
116 {
117 throw new AgreementFactoryFault( e );
118 }
119 catch ( Exception e )
120 {
121 String message = "Illegal state in initiateNegotiation method. Error: " + e.getMessage();
122 LOG.error( message );
123 if ( LOG.isDebugEnabled() )
124 {
125 LOG.debug( e );
126 }
127 throw new ResourceUnavailableFault( message, e );
128 }
129
130 EndpointReferenceType epr = addNewNegotiationWsResource( createdNegotiation );
131
132 InitiateNegotiationOutputDocument output = InitiateNegotiationOutputDocument.Factory.newInstance();
133
134 output.addNewInitiateNegotiationOutput().setCreatedNegotiationEPR( epr );
135
136 return output.getInitiateNegotiationOutput();
137 }
138
139
140
141
142
143
144
145
146
147
148
149
150 protected EndpointReferenceType addNewNegotiationWsResource( Negotiation negotiation )
151 throws AgreementFactoryFault
152 {
153
154 try
155 {
156
157
158
159 Resource negotiationInstance = getResource().getResourceManager().createResource( "Negotiation" );
160
161
162
163
164
165 EndpointReference museFactoryEPR = getResource().getEndpointReference();
166 EndpointReferenceType factoryEPR = XmlUtils.convertMuseEPRToEndpoint( museFactoryEPR );
167
168 ( (NegotiationWsResource) negotiationInstance ).setFactoryEPR( factoryEPR );
169 ( (NegotiationWsResource) negotiationInstance ).setNegotiation( negotiation );
170
171 negotiationInstance.initialize();
172 getResource().getResourceManager().addResource( negotiationInstance.getEndpointReference(),
173 negotiationInstance );
174
175
176
177
178 EndpointReferenceType epr =
179 XmlUtils.convertMuseEPRToEndpoint( negotiationInstance.getEndpointReference() );
180
181 return epr;
182 }
183 catch ( Exception ex )
184 {
185 throw new AgreementFactoryFault(
186 "An internal error occured while adding a new negotiation. Message: "
187 + ex.getMessage() );
188 }
189 }
190
191 }