fintp_base
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AbstractFilter.h
Go to the documentation of this file.
1 /*
2 * FinTP - Financial Transactions Processing Application
3 * Copyright (C) 2013 Business Information Systems (Allevo) S.R.L.
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>
17 * or contact Allevo at : 031281 Bucuresti, 23C Calea Vitan, Romania,
18 * phone +40212554577, office@allevo.ro <mailto:office@allevo.ro>, www.allevo.ro.
19 */
20 
25 #ifndef ABSTRACTFILTER_H
26 #define ABSTRACTFILTER_H
27 
28 #include <string>
29 #include <stdexcept>
30 #include <sstream>
31 
32 #include "DllMain.h"
33 #include "Collections.h"
34 #include "WorkItemPool.h"
35 
36 #ifdef WIN32
37  #define __MSXML_LIBRARY_DEFINED__
38 #endif
39 
40 #include <xercesc/dom/DOM.hpp>
41 
42 using namespace std;
43 
44 namespace FinTP
45 {
52  {
53  public :
56  {
57  MQ,
59  XSD,
62  SSL,
64  P7M,
65  ZIP,
66  SWIFTFORMAT
67  };
68 
71  {
72  Xml,
73  Buffer
74  };
75 
77  static string ToString( FilterType::FilterTypeEnum type );
79  static string ToString( FilterType::FilterInputDataType type );
80 
82  static FilterType::FilterTypeEnum Parse( const string& type );
83  };
84 
85 
94  {
95  public :
96 
97  typedef WorkItem< ManagedBuffer > buffer_type;
98 
101  {
102  Completed = 1,
103  Fail = 2
104  // other values reserved for future use
105  };
106 
109  {
110  XmlToXml = 0,
111  XmlToBuffer = 1,
112  BufferToXml = 2,
113  BufferToBuffer = 3
114  };
115 
117  virtual ~AbstractFilter() {};
118 
119  protected:
120 
125  explicit AbstractFilter( FilterType::FilterTypeEnum type ) : m_FilterType( type ) {};
126 
127  // protected members
130  NameValueCollection m_Properties;
132 
133  // name of the file where the payload will be logged
135 
136 
137  public :
138 
139  // return true if the filter supports logging payload to a file
140  // note for overrides : return true/false if the payload can be read without rewinding ( not a stream )
141  virtual bool canLogPayload();
142 
143  virtual FilterResult ProcessMessage( XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument* inputOutputData, NameValueCollection& transportHeaders, bool asClient ) = 0;
144  virtual FilterResult ProcessMessage( const XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument* inputData, AbstractFilter::buffer_type outputData, NameValueCollection& transportHeaders, bool asClient ) = 0;
145  virtual FilterResult ProcessMessage( AbstractFilter::buffer_type inputData, XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument* outputData, NameValueCollection& transportHeaders, bool asClient ) = 0;
146  virtual FilterResult ProcessMessage( AbstractFilter::buffer_type inputData, AbstractFilter::buffer_type outputData, NameValueCollection& transportHeaders, bool asClient ) = 0;
147 
148  // take ownership of the buffer
149  virtual FilterResult ProcessMessage( const XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument* inputData, unsigned char** outputData, NameValueCollection& transportHeaders, bool asClient ) = 0;
150  virtual FilterResult ProcessMessage( AbstractFilter::buffer_type inputData, unsigned char** outputData, NameValueCollection& transportHeaders, bool asClient ) = 0;
151 
152  // return true if the filter can execute the requested operation in client/server context
153  virtual bool isMethodSupported( FilterMethod method, bool asClient );
154 
155  // accessors
156  // return the collection of properties for this filter
157  const NameValueCollection& getProperties() const;
158 
159  // sets the name of the file where the payload will be logged
160  void setLogFile( const string& filename);
161 
162  // sets the name of the file where the payload will be logged
163  string getLogFile() const;
164 
165  // is this a type of filter that receives or sends a message ?
166  virtual bool isTransportType() { return false; }
167 
168  // adds/sets a property
169  void addProperty( const string& name, const string& value );
170  //void setProperty( string name, string value );
171 
172  // returns the friendly name for a FilterMethod value
173  static string ToString( const FilterMethod type );
174  FilterType::FilterTypeEnum getFilterType() const { return m_FilterType; }
175 
176  virtual void Init() {}
177 
178  // transaction support
179  virtual void Rollback(){};
180  virtual void Commit(){};
181  virtual void Abort(){};
182 
183  virtual bool isBatch() const
184  {
185  stringstream errorMessage;
186  errorMessage << "[isBatch] is not implemented by this filter type [" << FilterType::ToString( m_FilterType ) << "]";
187  throw logic_error( errorMessage.str() );
188  }
189 
190  virtual string getQueueManagerName() const
191  {
192  stringstream errorMessage;
193  errorMessage << "[getQueueManagerName] is not implemented by this filter type [" << FilterType::ToString( m_FilterType ) << "]";
194  throw logic_error( errorMessage.str() );
195  }
196 
197  virtual string getTransportURI() const
198  {
199  stringstream errorMessage;
200  errorMessage << "[getTransportURI] is not implemented by this filter type [" << FilterType::ToString( m_FilterType ) << "]";
201  throw logic_error( errorMessage.str() );
202  }
203 #ifdef AMQ
204  virtual string getBrokerURI() const
205  {
206  stringstream errorMessage;
207  errorMessage << "[getBrokerURI] is not implemented by this filter type [" << FilterType::ToString( m_FilterType ) << "]";
208  throw logic_error( errorMessage.str() );
209  }
210 #endif
211  virtual string getQueueName() const
212  {
213  stringstream errorMessage;
214  errorMessage << "[getQueueName] is not implemented by this filter type [" << FilterType::ToString( m_FilterType ) << "]";
215  throw logic_error( errorMessage.str() );
216  }
217  };
218 
224  class ExportedObject FilterInvalidMethod : public logic_error
225  {
226  public :
227 
228  // .ctors and destructors
230  ~FilterInvalidMethod() throw() {};
231 
232  virtual const char *what() const throw()
233  { // return pointer to message string
234  try
235  {
236  return ( m_String.c_str() );
237  }
238  catch( ... )
239  {
240  return "unknown error";
241  }
242  }
243 
244  private :
245 
246  string m_String;
247  };
248 }
249 
250 #endif