KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mr > core > util > patterns > flow > AbstractCondition


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

55
56  /**
57  * User: Moti Tal
58  * Date: Feb 21, 2005
59  * Time: 12:36:02 PM
60  *
61  * This class provides a skeletal implementation of the Condition interface
62  * to minimize the effort required to implement this interface
63  */

64 public abstract class AbstractCondition implements Condition{
65
66     String JavaDoc m_condition;
67     String JavaDoc m_param;
68     String JavaDoc m_requiresValue;
69     String JavaDoc m_operator;
70     Message m_message;
71
72     public void configure(Element JavaDoc i_object) throws CreationException {
73         m_condition = i_object.getAttribute("name");
74         m_operator = i_object.getAttribute("operator");
75         NodeList JavaDoc list = i_object.getElementsByTagName("param");
76         if(list.getLength() < 1)
77             throw new CreationException("Missing condition parameters");
78         Element JavaDoc param = (Element JavaDoc)list.item(0);
79         m_param = param.getAttribute("name");
80         m_requiresValue = param.getAttribute("value");
81
82         NodeList JavaDoc elements = i_object.getElementsByTagName("message");
83         if(elements != null && elements.getLength() > 0){
84             m_message = new Message();
85             m_message.configure((Element JavaDoc)elements.item(0));
86         }
87     }
88
89     public String JavaDoc getCondition() {
90         return m_condition;
91     }
92
93     public String JavaDoc getParam() {
94         return m_param;
95     }
96
97     public String JavaDoc getRequiresValue() {
98         return m_requiresValue;
99     }
100
101      public String JavaDoc getOperator() {
102          return m_operator;
103      }
104
105      public Message getMessage() {
106          return m_message;
107      }
108
109      protected class Message{
110
111          String JavaDoc m_type = null;
112          Map JavaDoc m_map = null;
113
114          public void configure(Element JavaDoc i_element){
115             m_map = new HashMap JavaDoc();
116             m_type = i_element.getAttribute("type");
117             NodeList JavaDoc list = i_element.getElementsByTagName("param");
118             for(int i = 0 ; i <list.getLength() ; i++){
119                 Element JavaDoc node = (Element JavaDoc)list.item(i);
120                 m_map.put(node.getAttribute("name"), node.getAttribute("value"));
121             }
122          }
123
124          public String JavaDoc getType() {
125              return m_type;
126          }
127
128          public Map JavaDoc getMap() {
129              return m_map;
130          }
131
132      }
133  }
134
Popular Tags