KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > proactive > core > component > xml > BindingsHandler


1 /*
2  * ################################################################
3  *
4  * ProActive: The Java(TM) library for Parallel, Distributed,
5  * Concurrent computing with Security and Mobility
6  *
7  * Copyright (C) 1997-2004 INRIA/University of Nice-Sophia Antipolis
8  * Contact: proactive-support@inria.fr
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 2.1 of the License, or any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with this library; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23  * USA
24  *
25  * Initial developer(s): The ProActive Team
26  * http://www.inria.fr/oasis/ProActive/contacts.html
27  * Contributor(s):
28  *
29  * ################################################################
30  */

31 package org.objectweb.proactive.core.component.xml;
32
33 import org.objectweb.fractal.api.Component;
34 import org.objectweb.fractal.api.NoSuchInterfaceException;
35 import org.objectweb.fractal.api.control.BindingController;
36 import org.objectweb.fractal.api.control.IllegalBindingException;
37 import org.objectweb.fractal.api.control.IllegalLifeCycleException;
38 import org.objectweb.proactive.core.component.Constants;
39 import org.objectweb.proactive.core.xml.handler.AbstractUnmarshallerDecorator;
40 import org.objectweb.proactive.core.xml.handler.BasicUnmarshaller;
41 import org.objectweb.proactive.core.xml.handler.UnmarshallerHandler;
42 import org.objectweb.proactive.core.xml.io.Attributes;
43 import org.xml.sax.SAXException JavaDoc;
44
45 /**
46  * @author Matthieu Morel
47  */

48 // ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
49
//public class BindingsHandler extends CollectionUnmarshaller {
50
public class BindingsHandler extends AbstractUnmarshallerDecorator {
51     ComponentsCache componentsCache;
52     public BindingsHandler(ComponentsCache componentsCache) {
53         this.componentsCache = componentsCache;
54         addHandler(ComponentsDescriptorConstants.BINDING_TAG, new BindingHandler());
55
56     }
57
58     // ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
59
public class BindingHandler extends BasicUnmarshaller {
60
61         private String JavaDoc clientComponent = null;
62         private String JavaDoc clientInterface = null;
63         private String JavaDoc serverComponent = null;
64         private String JavaDoc serverInterface = null;
65
66         public BindingHandler() {
67         }
68
69         private void setClient(String JavaDoc client) {
70             clientComponent = client.substring(0, client.indexOf('.'));
71             clientInterface = client.substring(client.indexOf('.') + 1, client.length());
72         }
73
74         private void setServer(String JavaDoc server) {
75             serverComponent = server.substring(0, server.indexOf('.'));
76             serverInterface = server.substring(server.indexOf('.') + 1, server.length());
77         }
78
79         /**
80          * {@link org.objectweb.proactive.core.xml.handler.UnmarshallerHandler#startContextElement(java.lang.String, org.objectweb.proactive.core.xml.io.Attributes)}
81          */

82         public void startContextElement(String JavaDoc name, Attributes attributes) throws SAXException JavaDoc {
83             logger.debug("*****inside binding handler");
84
85             String JavaDoc client = attributes.getValue(ComponentsDescriptorConstants.BINDING_CLIENT_TAG);
86             if (!checkNonEmpty(client)) {
87                 throw new SAXException JavaDoc("binding client interface unspecified");
88             }
89             String JavaDoc server = attributes.getValue(ComponentsDescriptorConstants.BINDING_SERVER_TAG);
90             if (!checkNonEmpty(server)) {
91                 throw new SAXException JavaDoc("binding server interfaceunspecified");
92             }
93             setClient(client);
94             setServer(server);
95             // perform binding (binding is automatically stored within the component)
96
try {
97                 if(!componentsCache.containsComponentNamed(serverComponent)) {
98                     throw new SAXException JavaDoc("tried to perform a binding from " + serverComponent +'.' + serverInterface + " , but " + serverComponent + " does not exist");
99                 }
100                 (
101                     (BindingController) componentsCache.getComponent(clientComponent).getFcInterface(
102                         Constants.BINDING_CONTROLLER)).bindFc(
103                     clientInterface,
104                     ((Component) componentsCache.getComponent(serverComponent)).getFcInterface(serverInterface));
105                 logger.debug(
106                     "**** bound "
107                         + clientComponent
108                         + "."
109                         + clientInterface
110                         + " to "
111                         + serverComponent
112                         + "."
113                         + serverInterface);
114             } catch (NoSuchInterfaceException nsie) {
115                 nsie.printStackTrace();
116                 throw new SAXException JavaDoc("error while parsing", nsie);
117             } catch (IllegalLifeCycleException ilce) {
118                 ilce.printStackTrace();
119                 throw new SAXException JavaDoc("error while parsing", ilce);
120             } catch (IllegalBindingException ibe) {
121                 ibe.printStackTrace();
122                 throw new SAXException JavaDoc("error while parsing", ibe);
123             }
124
125         }
126
127         /**
128          * see {@link org.objectweb.proactive.core.xml.io.XMLHandler#endElement(java.lang.String)}
129          */

130         public void endElement(String JavaDoc name) throws SAXException JavaDoc {
131         }
132
133     }
134     /**
135      * see {@link org.objectweb.proactive.core.xml.handler.AbstractUnmarshallerDecorator#notifyEndActiveHandler(java.lang.String, org.objectweb.proactive.core.xml.handler.UnmarshallerHandler)}
136      */

137     protected void notifyEndActiveHandler(String JavaDoc name, UnmarshallerHandler activeHandler) throws SAXException JavaDoc {
138     }
139
140     /**
141      * see {@link org.objectweb.proactive.core.xml.handler.UnmarshallerHandler#getResultObject()}
142      */

143     public Object JavaDoc getResultObject() throws SAXException JavaDoc {
144         return null;
145     }
146
147     /**
148      * see {@link org.objectweb.proactive.core.xml.handler.UnmarshallerHandler#startContextElement(java.lang.String, org.objectweb.proactive.core.xml.io.Attributes)}
149      */

150     public void startContextElement(String JavaDoc name, Attributes attributes) throws SAXException JavaDoc {
151     }
152
153 }
Popular Tags