Package org.jboss.ejb3.deployers

Source Code of org.jboss.ejb3.deployers.JBoss5DeploymentUnit

/*
* JBoss, Home of Professional Open Source
* Copyright 2005, Red Hat Middleware LLC., 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.ejb3.deployers;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;

import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
import org.jboss.ejb3.interceptor.InterceptorInfoRepository;
import org.jboss.virtual.VirtualFile;
import org.jboss.virtual.VirtualFileFilter;
import org.jboss.virtual.VisitorAttributes;
import org.jboss.virtual.plugins.context.jar.JarUtils;
import org.jboss.virtual.plugins.vfs.helpers.FilterVirtualFileVisitor;
import org.jboss.virtual.plugins.vfs.helpers.SuffixesExcludeFilter;

/**
* Comment
*
* @author <a href="mailto:bill@jboss.org">Bill Burke</a>
* @version $Revision: 43304 $
*/
public class JBoss5DeploymentUnit implements org.jboss.ejb3.DeploymentUnit
{
   private VFSDeploymentUnit unit;
   private ClassLoader classLoader;
   private InterceptorInfoRepository interceptorInfoRepository;
   private Map defaultPersistenceProperties;

   public JBoss5DeploymentUnit(VFSDeploymentUnit unit)
   {
      this(unit, unit.getClassLoader());
   }
  
   public JBoss5DeploymentUnit(VFSDeploymentUnit unit, ClassLoader classLoader)
   {
      assert unit != null : "unit is null";
      assert classLoader != null : "classLoader is null";
     
      this.unit = unit;
      this.classLoader = classLoader;
      this.interceptorInfoRepository = new InterceptorInfoRepository(classLoader);
   }

   public VirtualFile getRootFile()
   {
      return unit.getFile("");
   }
  
   public URL getRelativeURL(String jar)
   {
      try
      {
         return new URL(jar);
      }
      catch (MalformedURLException e)
      {
         try
         {
            if (getUrl() == null)
               throw new RuntimeException("relative <jar-file> not allowed when standalone deployment unit is used");
            return new URL(getUrl(), jar);
         }
         catch (Exception e1)
         {
            throw new RuntimeException("could not find relative path: " + jar, e1);
         }
      }
   }

   URL extractDescriptorUrl(String resource)
   {
      try
      {
         VirtualFile vf = unit.getMetaDataFile(resource);
         if (vf == null) return null;
         return vf.toURL();
      }
      catch (Exception e)
      {
         throw new RuntimeException(e);
      }
   }

   public URL getPersistenceXml()
   {
      return extractDescriptorUrl("persistence.xml");
   }

   public URL getEjbJarXml()
   {
      return extractDescriptorUrl("ejb-jar.xml");
   }

   public URL getJbossXml()
   {
      return extractDescriptorUrl("jboss.xml");
   }

   public VirtualFile getMetaDataFile(String name)
   {
      return unit.getMetaDataFile(name);
   }
  
   public List<Class> getClasses()
   {
      return null;
   }

   public ClassLoader getClassLoader()
   {
      return classLoader;
   }

   public ClassLoader getResourceLoader()
   {
      return getClassLoader();
   }

   public String getShortName()
   {
      return unit.getFile("").getName();
   }

   public URL getUrl()
   {
      try
      {
         return unit.getFile("").toURL();
      }
      catch (Exception e)
      {
         throw new RuntimeException(e);
      }
   }

   public String getDefaultEntityManagerName()
   {
      String url = getUrl().toString();
      String name = url.substring(url.lastIndexOf('/') + 1, url.lastIndexOf('.'));
      return name;
   }

   public Map getDefaultPersistenceProperties()
   {
      return defaultPersistenceProperties;
   }

   public void setDefaultPersistenceProperties(Map defaultPersistenceProperties)
   {
      this.defaultPersistenceProperties = defaultPersistenceProperties;
   }

   public Hashtable getJndiProperties()
   {
      return null;
   }

   public InterceptorInfoRepository getInterceptorInfoRepository()
   {
      return interceptorInfoRepository;
   }

   public List<VirtualFile> getResources(VirtualFileFilter filter)
   {
      VisitorAttributes va = new VisitorAttributes();
      va.setLeavesOnly(true);
      SuffixesExcludeFilter noJars = new SuffixesExcludeFilter(JarUtils.getSuffixes());
      va.setRecurseFilter(noJars);
      FilterVirtualFileVisitor visitor = new FilterVirtualFileVisitor(filter, va);

      try
      {
         VirtualFile root = getRootFile();
         if( root.isLeaf() == false )
            root.visit(visitor);
      }
      catch (IOException e)
      {
         throw new RuntimeException(e);
      }
     
      List<VirtualFile> resources = visitor.getMatched();
     
      return resources;
   }
}
TOP

Related Classes of org.jboss.ejb3.deployers.JBoss5DeploymentUnit

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.