Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
  * JBoss, Home of Professional Open Source
  * Copyright 2006, JBoss Inc., and individual contributors as indicated
  * by the @authors tag. See the copyright.txt in the distribution for a
  * full listing of individual contributors.
  *
  * This 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 (at your option) any later version.
 *
 * This software 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 software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
 package org.jboss.embedded;
 
 import java.io.File;
 import java.net.URI;
 import java.net.URL;
 
comment

Author(s):
Bill Burke
adrian@jboss.org
Version:
$Revision: 1.1 $
 
 public class BinaryBootstrap extends Bootstrap
 {
    private static Bootstrap instance;
 
    public BinaryBootstrap(Kernel kernel)
    {
       super(kernel);
    }

   
For those applications that need a singelton Bootstrap instance

Returns:
the bootstrap
 
    public static synchronized Bootstrap getInstance()
    {
       if ( == null)
           = new BinaryBootstrap(createKernel());
 
       return ;
    }
 
    public static KernelDeployment parse(URL urlthrows JBossXBExceptionMalformedURLException
    {
       SchemaBindingResolver resolver = SingletonSchemaResolverFactory.getInstance().getSchemaBindingResolver();
       UnmarshallerFactory factory = UnmarshallerFactory.newInstance();
       Unmarshaller unmarshaller = factory.newUnmarshaller();
       return (KernelDeploymentunmarshaller.unmarshal(url.toString(), resolver);
    }
 
    public static void store(KernelDeployment deploymentFile binFilethrows Exception
    {
       FileOutputStream fos = new FileOutputStream(binFile);
       ObjectOutputStream oos = new ObjectOutputStream(fos);
       try
       {
          oos.writeObject(deployment);
       }
       finally
       {
          oos.close();
          fos.close();
       }
    }
 
    public static KernelDeployment load(File binFilethrows Exception
    {
       FileInputStream fis = new FileInputStream(binFile);
       ObjectInputStream ois = new ObjectInputStream(fis);
       try
      {
         return (KernelDeployment)ois.readObject();
      }
      finally
      {
         ois.close();
         fis.close();
      }
   }
   protected void deployBaseBootstrapUrl(URL urlthrows DeploymentException
   {
      try
      {
         URI uri = url.toURI();
         URI binUri = new URI(uri.toString() + ".bin");
         File textFile = new File(uri);
         File binFile = new File(binUri);
         KernelDeployment deployment;
         if (!binFile.exists() && !textFile.exists())
         {
            throw new DeploymentException("Unable to locate bootstrap file: " + url);
         }
         else if (binFile.exists() && textFile.exists())
         {
            if (textFile.lastModified() > binFile.lastModified())
            {
               ..println("new bootstrap file...");
               deployment = parse(url);
               store(deploymentbinFile);
            }
            else
            {
               deployment = load(binFile);
            }
         }
         else if (textFile.exists())
         {
            deployment = parse(url);
            store(deploymentbinFile);
         }
         else
         {
            deployment = load(binFile);
         }
         AbstractKernelDeployer deployer = new AbstractKernelDeployer();
         deployer.deploy(deployment);
      }
      catch (Throwable throwable)
      {
         throw new RuntimeException("Unable to bootstrap: "throwable);
      }
   }
New to GrepCode? Check out our FAQ X