Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
OW2 Util Copyright (C) 2008 Contact: easybeans@objectweb.org This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -------------------------------------------------------------------------- $Id: XmlFileDeployableFactoryImpl.java --------------------------------------------------------------------------
 
 
 package org.ow2.util.plan.deploy.deployable.impl.factory;
 
 import java.util.Map;
 
 
Implementation for the XmlFileDeployableFactory interface.

Author(s):
Mickaƫl LEDUQUE
 
 public class XmlFileDeployableFactoryImpl implements XmlFileDeployableFactory {

    
The logger.
 
     private Log logger = LogFactory.getLog(XmlFileDeployableFactoryImpl.class);

    
The XmlHelper used to identify XML files.
 
     private XmlHelper xmlHelper = new XmlHelper();

    
Default constructor.

Throws:
javax.xml.parsers.ParserConfigurationException when the XmlHelper initilization fails.
org.xml.sax.SAXException when the XmlHelper initilization fails.
 
         /* Needed because xmlHelper initialization can throw exceptions */
     }

    
XML namespace to FileDeployable association.
 
     private Map<StringClass<? extends FileDeployable<?, ?>>> xmlNSToDeployableMap
         = new HashMap<StringClass<? extends FileDeployable<?, ?>>>();

    
Returns the file deployable constructed from the IFileArchive using the given namespace.

Parameters:
fileArchive the archive that must be converted.
nameSpace the namespace to be used.
Returns:
the FileDeployable.
Throws:
org.ow2.util.plan.deploy.deployable.api.factory.FileDeployableException when the Deployable could not be constructed.
 
     private FileDeployable<?, ?> getXmlFileDeployable(final IFileArchive fileArchivefinal String nameSpace)
             throws FileDeployableException {
         Class<? extends FileDeployable<?, ?>> clazz = .get(nameSpace);
         if (clazz == null) {
             .debug("The XML namespace {0} found in the archive ''{0}'' is not handled by a factory"nameSpace,
                     fileArchive);
             return null;
         }
         Constructor<? extends FileDeployable<?, ?>> constructor = null;
         try {
             constructor = clazz.getDeclaredConstructor(IFileArchive.class);
         } catch (NoSuchMethodException e) {
             .error("No {0}(IArchive archive) constructor; aborting deployable generation"clazz.getName());
             throw new FileDeployableException(e);
        }
        try {
            return constructor.newInstance(fileArchive);
        } catch (InvocationTargetException e) {
            /*
             * Catch the InvocationTargetException because the nested exception
             * is more meaningful.
             */
            Throwable nested = e.getCause();
            throw new FileDeployableException(nested);
        } catch (Exception e) {
            .error("Caught error on constructor invokation : {0}"e);
            throw new FileDeployableException();
        }
    }

    
    public FileDeployable<?, ?> getFileDeployable(final IFileArchive fileArchivethrows FileDeployableException {
        String namespace = null;
        try {
            namespace = .getRootElementNameSpace(fileArchive.getFile());
        } catch (IOException e) {
            .error("IO Exception while parsing file {0}"fileArchive.getFile(), e);
            throw new FileDeployableException(e);
        } catch (SAXException e) {
            .error("Exception while parsing file {0} : this is not a XML file"fileArchive.getFile(), e);
            throw new FileDeployableException(e);
        }
        return getXmlFileDeployable(fileArchivenamespace);
    }

    
    public void registerFileDeployable(final Class<? extends FileDeployable<?, ?>> clazzfinal String nameSpace) {
        .put(nameSpaceclazz);
    }

    
    public void unregisterFileDeployable(final String nameSpace) {
        .remove(nameSpace);
    }
New to GrepCode? Check out our FAQ X