KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mr > kernel > dmf > DataManipulationFramework


1 package org.mr.kernel.dmf;
2
3 import java.util.HashMap JavaDoc;
4
5 import org.apache.commons.logging.Log;
6 import org.apache.commons.logging.LogFactory;
7 import org.mr.MantaAgent;
8 import org.mr.MessageManipulator;
9 import org.mr.core.protocol.MantaBusMessage;
10 import org.mr.core.protocol.MantaBusMessageConsts;
11 import org.mr.core.util.exceptions.CreationException;
12 import org.mr.core.util.patterns.flow.FlowFramework;
13 import org.mr.kernel.Plugin;
14
15 /*
16  * Copyright 2002 by
17  * <a HREF="http://www.coridan.com">Coridan</a>
18  * <a HREF="mailto: support@coridan.com ">support@coridan.com</a>
19  *
20  * The contents of this file are subject to the Mozilla Public License Version
21  * 1.1 (the "License"); you may not use this file except in compliance with the
22  * License. You may obtain a copy of the License at
23  * http://www.mozilla.org/MPL/
24  *
25  * Software distributed under the License is distributed on an "AS IS" basis,
26  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
27  * for the specific language governing rights and limitations under the
28  * License.
29  *
30  * The Original Code is "MantaRay" (TM).
31  *
32  * The Initial Developer of the Original Code is Coridan.
33  * Portions created by the Initial Developer are Copyright (C) 2006
34  * Coridan Inc. All Rights Reserved.
35  *
36  * Contributor(s): all the names of the contributors are added in the source
37  * code where applicable.
38  *
39  * Alternatively, the contents of this file may be used under the terms of the
40  * LGPL license (the "GNU LESSER GENERAL PUBLIC LICENSE"), in which case the
41  * provisions of LGPL are applicable instead of those above. If you wish to
42  * allow use of your version of this file only under the terms of the LGPL
43  * License and not to allow others to use your version of this file under
44  * the MPL, indicate your decision by deleting the provisions above and
45  * replace them with the notice and other provisions required by the LGPL.
46  * If you do not delete the provisions above, a recipient may use your version
47  * of this file under either the MPL or the GNU LESSER GENERAL PUBLIC LICENSE.
48
49  *
50  * This library is free software; you can redistribute it and/or modify it
51  * under the terms of the MPL as stated above or under the terms of the GNU
52  * Lesser General Public License as published by the Free Software Foundation;
53  * either version 2.1 of the License, or any later version.
54  *
55  * This library is distributed in the hope that it will be useful, but WITHOUT
56  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
57  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
58  * License for more details.
59  */

60
61  /**
62  * User: Moti Tal
63  * Date: Mar 10, 2005
64  * Time: 4:38:54 PM
65  *
66  * After staring this plug-in at the MantaRay bootstrap, the plug-in uses as hook to the MantaRay.
67  * For any incoming\outgoing messages this hook called by the Manta registry\service layer to manipulate the message.
68  */

69 public class DataManipulationFramework implements MessageManipulator, Plugin{
70
71     //the DMF plugin in name
72
private final static String JavaDoc PLUGIN_NAME = "MANTA-DMF";
73
74 // public final static String MANTA_MESSAGE_KEY = "MANTA-MESSAGE";
75

76     //A patch. Header name set at the MantaBusMessage by the DMF, which identify the message direction.
77
public final static String JavaDoc MANTA_MESSAGE_INCOMING_PARAM = "incoming";
78
79     //Holds the DMF flow set of roles.
80
FlowFramework m_flowFramework = null;
81
82     //logger
83
private Log m_log = null;
84
85     ///////////////////////////////////////////////////////////////////////////
86
////////// Impls MessageManipulator
87
///////////////////////////////////////////////////////////////////////////
88

89     public MantaBusMessage manipulate(MantaBusMessage orig, HashMap JavaDoc params, byte direction) {
90         try {
91
92             if(orig.getMessageType() != MantaBusMessageConsts.MESSAGE_TYPE_CLIENT)
93                 return orig;
94             if(m_log.isDebugEnabled())
95                 m_log.debug("Enter DMF.");
96             //the DMFObject hold the params and the orig message.
97
DMFObject dmfObject = new DMFObject(orig);
98             dmfObject.putAll(params);
99
100             //START PATCH
101
//if its incoming message
102
dmfObject.put(MANTA_MESSAGE_INCOMING_PARAM, direction==0?"true":"false" );
103             //END PATCH
104

105             //exexcute the DMF flow
106
if(m_log.isDebugEnabled())
107                 m_log.debug("Start DMF flow.");
108             dmfObject = (DMFObject)m_flowFramework.execute(dmfObject);
109
110             orig = dmfObject.getMantaBusMessage();
111             dmfObject.clear();
112         } catch (Exception JavaDoc e) {
113             if(m_log.isErrorEnabled())
114                 m_log.error("Unknown error occur.",e);
115         }
116         return orig;
117     }
118
119     ///////////////////////////////////////////////////////////////////////////
120
////////// Impls Plugin
121
///////////////////////////////////////////////////////////////////////////
122

123     /**
124      * This method is used to get the name of the plugin.
125      *
126      * @return The name of the Plugin
127      */

128     public String JavaDoc getName() {
129         return PLUGIN_NAME;
130     }
131
132     /**
133      * This method is used retreive the version of the plugin.
134      *
135      * @return the version number of the plugin
136      */

137     public float getVersion() {
138         return 0.1f;
139     }
140
141     /**
142      * This method is used to start the plugin by loading the configuration.
143      * After this method called, no farther recourses take by this plug-in.
144      */

145     public void start() {
146         try {
147             m_log=LogFactory.getLog("DMF");
148             StartupDMF startupDMF = new StartupDMF();
149             m_flowFramework = startupDMF.getFlowFramework();
150             MantaAgent.getInstance().getSingletonRepository().setMessageManipulator(this);
151         } catch (CreationException e) {
152             if(m_log.isErrorEnabled())
153                 m_log.error("DMF error initiating", e);
154         }
155     }
156
157     /**
158      * This method is used to stop the plugin.
159      */

160     public void stop() {
161         m_flowFramework = null;
162     }
163 }
164
Popular Tags