org/objectweb/proactive/core/config/xml/MasterFileHandler.java

00001 /* 
00002  * ################################################################
00003  * 
00004  * ProActive: The Java(TM) library for Parallel, Distributed, 
00005  *            Concurrent computing with Security and Mobility
00006  * 
00007  * Copyright (C) 1997-2007 INRIA/University of Nice-Sophia Antipolis
00008  * Contact: proactive@objectweb.org
00009  * 
00010  * This library is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU Lesser General Public
00012  * License as published by the Free Software Foundation; either
00013  * version 2.1 of the License, or any later version.
00014  *  
00015  * This library is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * Lesser General Public License for more details.
00019  * 
00020  * You should have received a copy of the GNU Lesser General Public
00021  * License along with this library; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00023  * USA
00024  *  
00025  *  Initial developer(s):               The ProActive Team
00026  *                        http://www.inria.fr/oasis/ProActive/contacts.html
00027  *  Contributor(s): 
00028  * 
00029  * ################################################################
00030  */ 
00031 package org.objectweb.proactive.core.config.xml;
00032 
00033 import java.io.IOException;
00034 
00035 import org.objectweb.proactive.core.config.ProActiveConfiguration;
00036 import org.objectweb.proactive.core.xml.handler.AbstractUnmarshallerDecorator;
00037 import org.objectweb.proactive.core.xml.handler.UnmarshallerHandler;
00038 import org.objectweb.proactive.core.xml.io.Attributes;
00039 import org.xml.sax.InputSource;
00040 import org.xml.sax.SAXException;
00041 
00042 
00043 public class MasterFileHandler extends AbstractUnmarshallerDecorator
00044     implements MasterFileConstants {
00045     //    static {
00046     //        BasicConfigurator.configure();
00047     //    }
00048     protected static ProActiveConfiguration config;
00049 
00050     public MasterFileHandler() {
00051         addHandler(PROPERTIES_TAG,
00052             new PropertiesHandler(MasterFileHandler.config));
00053 
00054         //addHandler(LOG4J_FILE_TAG, new Log4jConfigurationHandler());
00055     }
00056 
00061     public static void createMasterFileHandler(String filename,
00062         ProActiveConfiguration config) {
00063         MasterFileHandler.config = config;
00064 
00065         InitialHandler h = new InitialHandler();
00066         org.objectweb.proactive.core.xml.io.StreamReader sr;
00067 
00068         try {
00069             InputSource source = null;
00070 
00071             //System.out.println("FILENAME = " + filename);
00072             if (filename.startsWith("bundle://")) {
00073 
00074                 /* osgi mode, get the ProActiveConfiguration in the jar root */
00075                 filename = "/ProActiveConfiguration.xml";
00076                 //filename = "/org/objectweb/proactive/core/config/ProActiveConfiguration.xml";
00077                 source = new InputSource(MasterFileHandler.class.getResourceAsStream(
00078                             filename));
00079             } else {
00080                 source = new org.xml.sax.InputSource(filename);
00081             }
00082             sr = new org.objectweb.proactive.core.xml.io.StreamReader(source, h);
00083             sr.read();
00084         } catch (IOException e) {
00085             e.printStackTrace();
00086         } catch (SAXException e) {
00087             e.printStackTrace();
00088         }
00089     }
00090 
00091     protected void notifyEndActiveHandler(String name,
00092         UnmarshallerHandler activeHandler) throws SAXException {
00093         //   System.out.println("End active handler");
00094     }
00095 
00096     public Object getResultObject() throws SAXException {
00097         //  System.out.println("get result object");
00098         return null;
00099     }
00100 
00101     public void startContextElement(String name, Attributes attributes)
00102         throws SAXException {
00103     }
00104 
00105     //
00106     // -- INNER CLASSES ------------------------------------------------------
00107     //
00108     private static class InitialHandler extends AbstractUnmarshallerDecorator {
00109         private MasterFileHandler masterFileHandler;
00110 
00111         // private InitialHandler(AbstractManager manager) {
00112         private InitialHandler() {
00113             super();
00114             masterFileHandler = new MasterFileHandler();
00115 
00116             //                    managerDescriptorHandler = new ManagerDescriptorHandler(manager);
00117             this.addHandler(MASTER_TAG, masterFileHandler);
00118         }
00119 
00120         public Object getResultObject() throws org.xml.sax.SAXException {
00121             //    return managerDescriptorHandler;
00122             return null; //masterFileHandler;
00123         }
00124 
00125         public void startContextElement(String name, Attributes attributes)
00126             throws org.xml.sax.SAXException {
00127         }
00128 
00129         protected void notifyEndActiveHandler(String name,
00130             UnmarshallerHandler activeHandler) throws org.xml.sax.SAXException {
00131         }
00132     }
00133 
00134     //    private class SingleValueUnmarshaller extends AbstractUnmarshallerDecorator {
00135     //        public void readValue(String value) throws org.xml.sax.SAXException {
00136     //            //  setResultObject(value);
00137     //        }
00138     //
00139     //        public void startContextElement(String name, Attributes attributes)
00140     //            throws org.xml.sax.SAXException {
00141     //            //    String key = attributes.getValue("key");
00142     //            String value = attributes.getValue("value");
00143     //            System.out.println("name = " + name + " value = " + value);
00144     //            //                    if (checkNonEmpty(key) && checkNonEmpty(value)) {
00145     //            //                            properties.put(key, value);
00146     //            //                    }
00147     //        }
00148     //
00149     //        /* (non-Javadoc)
00150     //         * @see org.objectweb.proactive.core.xml.handler.AbstractUnmarshallerDecorator#notifyEndActiveHandler(java.lang.String, org.objectweb.proactive.core.xml.handler.UnmarshallerHandler)
00151     //         */
00152     //        protected void notifyEndActiveHandler(String name,
00153     //            UnmarshallerHandler activeHandler) throws SAXException {
00154     //            // TO DO : Auto-generated method stub
00155     //        }
00156     //
00157     //        /* (non-Javadoc)
00158     //         * @see org.objectweb.proactive.core.xml.handler.UnmarshallerHandler#getResultObject()
00159     //         */
00160     //        public Object getResultObject() throws SAXException {
00161     //            // TO DO : Auto-generated method stub
00162     //            return null;
00163     //        }
00164     //    }
00165 }

Generated on Mon Jan 22 15:16:07 2007 for ProActive by  doxygen 1.5.1