View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2009 eviware.com 
3    *
4    *  soapUI is free software; you can redistribute it and/or modify it under the 
5    *  terms of version 2.1 of the GNU Lesser General Public License as published by 
6    *  the Free Software Foundation.
7    *
8    *  soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 
9    *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
10   *  See the GNU Lesser General Public License for more details at gnu.org.
11   */
12  
13  package com.eviware.soapui.impl.wsdl.support.wsrm;
14  
15  import org.apache.xmlbeans.XmlCursor;
16  import org.apache.xmlbeans.XmlObject;
17  
18  import net.java.dev.wadl.x2009.x02.ApplicationDocument;
19  
20  public class WsrmBuilder
21  {
22  	private static final String WSRM_CREATE_SEQUENCE = "CreateSequence";
23  	private static final String WSRM_EXPIRES = "Expires";
24  	private static final String WSRM_ACKNOWLEDGMENTS_TO = "AcksTo";
25  
26  	private static final String WSRM_CLOSE_SEQUENCE = "CloseSequence";
27  	private static final String WSRM_IDENTIFIER = "Identifier";
28  	private static final String WSRM_LAST_MESSAGE = "LastMsgNumber";
29  
30  	private WsrmConfig wsrmConfig;
31  
32  	public WsrmBuilder( WsrmConfig wsrmConfig )
33  	{
34  		this.wsrmConfig = wsrmConfig;
35  	}
36  
37  	public XmlObject constructSequenceRequest()
38  	{
39  		XmlObject object = XmlObject.Factory.newInstance();
40  		XmlCursor cursor = object.newCursor();
41  		// cursor.toNextToken();
42  
43  		cursor.insertNamespace( "wsrm", wsrmConfig.getVersionNameSpace() );
44  
45  		cursor.beginElement( WSRM_CREATE_SEQUENCE, wsrmConfig.getVersionNameSpace() );
46  		cursor.insertElementWithText( WSRM_ACKNOWLEDGMENTS_TO, wsrmConfig.getAckTo() );
47  		if( wsrmConfig.getSequenceExpires() != null )
48  			cursor.insertElementWithText( WSRM_EXPIRES, wsrmConfig.getSequenceExpires().toString() );
49  
50  		cursor.dispose();
51  
52  		return object;
53  	}
54  
55  	public XmlObject constructSequenceClose()
56  	{
57  		XmlObject object = XmlObject.Factory.newInstance();
58  		XmlCursor cursor = object.newCursor();
59  		cursor.toNextToken();
60  
61  		cursor.insertNamespace( "wsrm", wsrmConfig.getVersionNameSpace() );
62  
63  		cursor.beginElement( WSRM_CLOSE_SEQUENCE, wsrmConfig.getVersionNameSpace() );
64  		cursor.insertElementWithText( WSRM_IDENTIFIER, wsrmConfig.getSequenceIdentifier() );
65  		// For a request, there will always be one message
66  		cursor.insertElementWithText( WSRM_LAST_MESSAGE, "1" );
67  
68  		cursor.dispose();
69  
70  		return object;
71  	}
72  }