KickJava   Java API By Example, From Geeks To Geeks.

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


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.apache.log4j.Logger;
34
35 import org.objectweb.fractal.api.Component;
36 import org.objectweb.fractal.api.NoSuchInterfaceException;
37 import org.objectweb.fractal.api.factory.GenericFactory;
38 import org.objectweb.fractal.api.factory.InstantiationException;
39 import org.objectweb.fractal.api.type.ComponentType;
40 import org.objectweb.fractal.api.type.TypeFactory;
41 import org.objectweb.fractal.util.Fractal;
42
43 import org.objectweb.proactive.core.ProActiveRuntimeException;
44 import org.objectweb.proactive.core.component.ControllerDescription;
45 import org.objectweb.proactive.core.descriptor.data.ProActiveDescriptor;
46 import org.objectweb.proactive.core.xml.handler.AbstractUnmarshallerDecorator;
47 import org.objectweb.proactive.core.xml.handler.UnmarshallerHandler;
48 import org.objectweb.proactive.core.xml.io.Attributes;
49
50 import org.xml.sax.SAXException JavaDoc;
51
52 import java.util.HashMap JavaDoc;
53
54
55 /**
56  * @author Matthieu Morel
57  */

58 public abstract class ComponentHandler extends AbstractUnmarshallerDecorator {
59     public static Logger logger = Logger.getLogger(ComponentHandler.class.getName());
60
61     protected ControllerDescription controllerDescription;
62     protected String JavaDoc virtualNode;
63     protected ProActiveDescriptor deploymentDescriptor;
64     protected ComponentsCache componentsCache;
65     protected HashMap JavaDoc componentTypes;
66     protected TypeFactory typeFactory;
67     protected GenericFactory cf;
68     protected ComponentType componentType = null;
69
70     /**
71      *
72      */

73     public ComponentHandler(ProActiveDescriptor deploymentDescriptor,
74         ComponentsCache componentsCache, HashMap JavaDoc componentTypes) {
75         controllerDescription = new ControllerDescription();
76         this.deploymentDescriptor = deploymentDescriptor;
77         this.componentsCache = componentsCache;
78         this.componentTypes = componentTypes;
79         try {
80             Component boot = Fractal.getBootstrapComponent();
81             typeFactory = Fractal.getTypeFactory(boot);
82             cf = Fractal.getGenericFactory(boot);
83         } catch (InstantiationException JavaDoc e1) {
84             throw new ProActiveRuntimeException("Cannot find Fractal boot component",
85                 e1);
86         } catch (NoSuchInterfaceException e1) {
87             throw new ProActiveRuntimeException("Cannot find Fractal interface",
88                 e1);
89         }
90     }
91
92     /**
93      * @link {org.objectweb.proactive.core.xml.handler.AbstractUnmarshallerDecorator#notifyEndActiveHandler(java.lang.String, org.objectweb.proactive.core.xml.handler.UnmarshallerHandler)}
94      */

95     protected void notifyEndActiveHandler(String JavaDoc name,
96         UnmarshallerHandler activeHandler) throws SAXException JavaDoc {
97     }
98
99     /**
100      * @link {org.objectweb.proactive.core.xml.handler.UnmarshallerHandler#getResultObject()}
101      */

102     public Object JavaDoc getResultObject() throws SAXException JavaDoc {
103         return null;
104     }
105
106     /**
107      * @link {org.objectweb.proactive.core.xml.handler.UnmarshallerHandler#startContextElement(java.lang.String, org.objectweb.proactive.core.xml.io.Attributes)}
108      */

109     public void startContextElement(String JavaDoc name, Attributes attributes)
110         throws SAXException JavaDoc {
111         String JavaDoc component_name = attributes.getValue(ComponentsDescriptorConstants.COMPONENT_NAME_TAG);
112         if (!checkNonEmpty(component_name)) {
113             throw new SAXException JavaDoc("component's name unspecified");
114         }
115         String JavaDoc virtual_node = attributes.getValue(ComponentsDescriptorConstants.COMPONENT_VIRTUAL_NODE_TAG);
116         if (!checkNonEmpty(virtual_node)) {
117             virtual_node = ComponentsDescriptorConstants.NULL;
118         }
119         String JavaDoc type_name = attributes.getValue(ComponentsDescriptorConstants.COMPONENT_TYPE_ATTRIBUTE_TAG);
120         if (!checkNonEmpty(type_name)) {
121             throw new SAXException JavaDoc("name of component type unspecified");
122         }
123         controllerDescription.setName(component_name);
124         virtualNode = virtual_node;
125         componentType = ((ComponentType) componentTypes.get(type_name));
126     }
127 }
128
Popular Tags