Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright 2013 Red Hat, Inc. and/or its affiliates. Licensed under the Eclipse Public License version 1.0, available at http://www.eclipse.org/legal/epl-v10.html
  
  
  package org.jboss.forge.addon.javaee;
  
 
 import  org.jboss.forge.furnace.util.ClassLoaders;
Descriptors that sets the context ClassLoader to the target class

Author(s):
George Gastaldi
 
 public final class Descriptors
 {
 
    public static <T extends Descriptor> T create(final Class<T> typethrows IllegalArgumentException
    {
       try
       {
          return ClassLoaders.executeIn(type.getClassLoader(), new Callable<T>()
          {
             @Override
             public T call() throws Exception
             {
                return org.jboss.shrinkwrap.descriptor.api.Descriptors.create(type);
             }
          });
       }
       catch (Exception e)
       {
          throw new RuntimeException(e);
       }
    }
 
    public static <T extends Descriptor> T create(final Class<T> typefinal String descriptorName)
             throws IllegalArgumentException
    {
       try
       {
          return ClassLoaders.executeIn(type.getClassLoader(), new Callable<T>()
          {
             @Override
             public T call() throws Exception
             {
                return org.jboss.shrinkwrap.descriptor.api.Descriptors.create(typedescriptorName);
             }
          });
       }
       catch (Exception e)
       {
          throw new RuntimeException(e);
       }
    }
 
    public static <T extends DescriptorDescriptorImporter<T> importAs(final Class<T> type)
             throws IllegalArgumentException
    {
       try
       {
          return ClassLoaders.executeIn(type.getClassLoader(), new Callable<DescriptorImporter<T>>()
          {
             @Override
             public DescriptorImporter<T> call() throws Exception
             {
                return org.jboss.shrinkwrap.descriptor.api.Descriptors.importAs(type);
             }
          });
       }
       catch (Exception e)
       {
          throw new RuntimeException(e);
       }
    }
 
    public static <T extends DescriptorDescriptorImporter<T> importAs(final Class<T> typefinal String descriptorName)
             throws IllegalArgumentException
    {
       try
       {
          return ClassLoaders.executeIn(type.getClassLoader(), new Callable<DescriptorImporter<T>>()
          {
             @Override
             public DescriptorImporter<T> call() throws Exception
             {
                return org.jboss.shrinkwrap.descriptor.api.Descriptors.importAs(typedescriptorName);
             }
          });
       }
       catch (Exception e)
       {
          throw new RuntimeException(e);
      }
   }
New to GrepCode? Check out our FAQ X