KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > util > explorer > parser > lib > NodeDispatcher


1 /*====================================================================
2
3 Objectweb Explorer Framework
4 Copyright (C) 2000-2005 INRIA - USTL - LIFL - GOAL
5 Contact: openccm@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Jerome Moroy, Philippe Merle.
23 Contributor(s): ______________________________________.
24
25 ====================================================================
26 $Id: NodeDispatcher.java,v 1.2 2005/07/06 15:36:00 moroy Exp $
27 ====================================================================*/

28
29 package org.objectweb.util.explorer.parser.lib;
30
31 import java.util.Iterator JavaDoc;
32 import java.util.List JavaDoc;
33
34 import org.objectweb.fractal.api.NoSuchInterfaceException;
35 import org.objectweb.util.explorer.core.common.api.BadParamException;
36 import org.objectweb.util.explorer.core.common.api.KeyProvider;
37 import org.objectweb.util.explorer.core.common.lib.BindingFeature;
38 import org.objectweb.util.explorer.core.role.api.RoleProvider;
39 import org.objectweb.util.explorer.explorerConfig.Node;
40 import org.objectweb.util.explorer.explorerConfig.Role;
41 import org.objectweb.util.explorer.explorerConfig.beans.ExplorerBean;
42 import org.objectweb.util.explorer.parser.api.ExplorerParser;
43 import org.objectweb.util.explorer.parser.api.NodeParser;
44 import org.objectweb.util.explorer.parser.api.RoleParser;
45
46 /**
47  * This component manages the "node" XML element.
48  *
49  * @author <a HREF="mailto:Jerome.Moroy@lifl.fr">Jérôme Moroy</a>,
50  * <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>.
51  *
52  * @version 0.1
53  */

54 public class NodeDispatcher
55      extends BindingFeature
56   implements ExplorerParser, RoleParser
57 {
58
59     //==================================================================
60
//
61
// Internal States.
62
//
63
// ==================================================================
64

65     // ==================================================================
66
//
67
// Constructors.
68
//
69
// ==================================================================
70

71     // ==================================================================
72
//
73
// No internal method.
74
//
75
// ==================================================================
76

77     protected void dispatchNode(String JavaDoc roleId, Node theNode){
78         try {
79             String JavaDoc[] keyElements = new String JavaDoc[]{theNode.getTypeSystem(),theNode.getTypeName(),roleId};
80             Object JavaDoc key = ((KeyProvider)lookupFc(KeyProvider.KEY_PROVIDER)).computeKey(keyElements);
81
82             String JavaDoc[] clientIftNames = listFc();
83             for (int i = 0; i < clientIftNames.length; i++) {
84                 if(clientIftNames[i].startsWith(NodeParser.NODE_PARSER)){
85                     ((NodeParser)lookupFc(clientIftNames[i])).parseNode(key,theNode);
86                 }
87             }
88         } catch (BadParamException e) {
89             e.printStackTrace();
90         } catch (NoSuchInterfaceException e) {
91             e.printStackTrace();
92         }
93     }
94     
95     protected void parseNodeList(String JavaDoc roleId, List JavaDoc nodeList){
96         Iterator JavaDoc it = nodeList.iterator();
97         while (it.hasNext()) {
98             Node node = (Node)it.next();
99             if(node!=null) {
100                 dispatchNode(roleId, node);
101             }
102         }
103     }
104     
105     // ==================================================================
106
//
107
// Public methods for BindingFeature class.
108
//
109
// ==================================================================
110

111     /* (non-Javadoc)
112      * @see org.objectweb.util.explorer.core.common.lib.BindingFeature#clientFc()
113      */

114     public String JavaDoc[] clientFc() {
115         return new String JavaDoc[]{NodeParser.NODE_PARSER,
116                             KeyProvider.KEY_PROVIDER};
117     }
118
119     // ==================================================================
120
//
121
// Public methods for ExplorerParser interface.
122
//
123
// ==================================================================
124

125     /* (non-Javadoc)
126      * @see org.objectweb.util.explorer.parser.api.ExplorerParser#parseExplorer(org.objectweb.util.explorer.explorerConfig.beans.ExplorerBean)
127      */

128     public void parseExplorer(ExplorerBean explorer) {
129         parseNodeList(RoleProvider.DEFAULT_ROLE,explorer.getNodeList());
130     }
131
132     // ==================================================================
133
//
134
// Public methods for RoleParser interface.
135
//
136
// ==================================================================
137

138     /* (non-Javadoc)
139      * @see org.objectweb.util.explorer.parser.api.RoleParser#parseRole(org.objectweb.util.explorer.explorerConfig.Role)
140      */

141     public void parseRole(Role role) {
142         parseNodeList(role.getId(),role.getNodeList());
143     }
144 }
145
Popular Tags