Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[EMB-32] Start to move out Virtual Archives into a new repo/project l…
…ocation, temporarily called "declarchive"
  • Loading branch information
Andrew Lee Rubinger committed Aug 5, 2009
0 parents commit 2d38098
Show file tree
Hide file tree
Showing 22 changed files with 2,569 additions and 0 deletions.
39 changes: 39 additions & 0 deletions api/pom.xml
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
vi:ts=2:sw=2:expandtab:
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<!-- Parent -->
<parent>
<groupId>org.jboss.declarchive</groupId>
<artifactId>declarchive-build</artifactId>
<version>0.1.0-SNAPSHOT</version>
<relativePath>../build/pom.xml</relativePath>
</parent>

<!-- Model Version -->
<modelVersion>4.0.0</modelVersion>

<!-- Artifact Configuration -->
<artifactId>declarchive-api</artifactId>
<version>0.1.0-SNAPSHOT</version>
<name>Declarchive API</name>
<description>Client View of the Declarchive Project</description>


<!-- Properties -->
<properties>

<!-- Versioning -->

</properties>

<!-- Dependencies -->
<dependencies>

</dependencies>

</project>

113 changes: 113 additions & 0 deletions api/src/main/java/org/jboss/declarchive/api/Archive.java
@@ -0,0 +1,113 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2009, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file 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.declarchive.api;

import java.net.URL;

/**
* Archive
*
* Represents a collection of resources which may
* be constructed declaratively / programmatically.
*
* @author <a href="mailto:andrew.rubinger@jboss.org">ALR</a>
* @version $Revision: $
*/
public interface Archive
{
//-------------------------------------------------------------------------------------||
// Contracts --------------------------------------------------------------------------||
//-------------------------------------------------------------------------------------||

/**
* Adds the specified Class to the archive
*
* @param The class to add
* @return This virtual deployment
* @throws IllegalArgumentException If no class was specified
*/
Archive addClass(Class<?> clazz) throws IllegalArgumentException;

/**
* Adds the specified Classes to the archive.
*
* @param classes
* @return This virtual deployment
* @throws IllegalArgumentException If no classes were specified
*/
Archive addClasses(Class<?>... classes) throws IllegalArgumentException;

/**
* Adds the resource with the specified name to the
* deployment. The resource name must be visible to the ClassLoader
* of the archive
*
* @param name
* @return
* @throws IllegalArgumentException If the name was not specified
*/
Archive addResource(String name) throws IllegalArgumentException;

/**
* Adds the specified resource to the archive, using the specified ClassLoader
* to load the resource
*
* @param name
* @param cl
* @return
* @throws IllegalArgumentException If either the name or ClassLoader is not specified
*/
Archive addResource(String name, ClassLoader cl) throws IllegalArgumentException;

/**
* Adds the resource located at the specified URL to the archive. The
* location within the archive will be equal to the path portion of the
* specified URL.
*
* @param location
* @return
* @throws IllegalArgumentException If the location is not specified
*/
Archive addResource(URL location) throws IllegalArgumentException;

/**
* Adds the resource located at the specified URL to
* the archive at the specified path.
*
* @param location
* @param newPath The new path to assign, or null if
* the path portion of the location should be used
* @return
* @throws IllegalArgumentException If the location is not specified
*/
Archive addResource(URL location, String newPath) throws IllegalArgumentException;

/**
* Returns a multiline "ls -l"-equse output of the contents of
* this deployment and (recursively) its children if the verbosity
* flag is set to "true". Otherwise the no-arg version is invoked
*
* @return
*/
String toString(boolean verbose);

}
108 changes: 108 additions & 0 deletions api/src/main/java/org/jboss/declarchive/api/SecurityActions.java
@@ -0,0 +1,108 @@
package org.jboss.declarchive.api;

import java.lang.reflect.Constructor;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;

/**
* SecurityActions
*
* A set of privileged actions that are not to leak out
* of this package
*
* @author <a href="mailto:andrew.rubinger@jboss.org">ALR</a>
* @version $Revision: $
*/
class SecurityActions
{

//-------------------------------------------------------------------------------||
// Constructor ------------------------------------------------------------------||
//-------------------------------------------------------------------------------||

/**
* No external instantiation
*/
private SecurityActions()
{

}

//-------------------------------------------------------------------------------||
// Utility Methods --------------------------------------------------------------||
//-------------------------------------------------------------------------------||

/**
* Obtains the Thread Context ClassLoader
*/
static ClassLoader getThreadContextClassLoader()
{
return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
{
public ClassLoader run()
{
return Thread.currentThread().getContextClassLoader();
}
});
}

/**
* Obtains the constructor for the specified class with the specified param types
* according to the contract of {@link Class#getConstructor(Class...)}
*
* @param clazz
* @param paramTypes
* @return
* @throws NoSuchMethodException
* @throws SecurityException
* @throws IllegalArgumentException If the class or param types were not specified
*/
static Constructor<?> getConstructor(final Class<?> clazz, final Class<?>... paramTypes)
throws NoSuchMethodException, SecurityException, IllegalArgumentException
{
// Precondition checks
if (clazz == null)
{
throw new IllegalArgumentException("class must be specified");
}
if (paramTypes == null)
{
throw new IllegalArgumentException("param types must be specified");
}

try
{
return AccessController.doPrivileged(new PrivilegedExceptionAction<Constructor<?>>()
{

@Override
public Constructor<?> run() throws Exception
{
return clazz.getConstructor(paramTypes);
}
});
}
catch (final PrivilegedActionException pae)
{
// Throw nsme and se
final Throwable unwrapped = pae.getCause();
if (unwrapped instanceof NoSuchMethodException)
{
final NoSuchMethodException nsme = (NoSuchMethodException) unwrapped;
throw nsme;
}
if (unwrapped instanceof SecurityException)
{
final SecurityException se = (SecurityException) unwrapped;
throw se;
}

// Throw the cause as encountered
throw new RuntimeException("Error in obtaining constructor", unwrapped);

}
}

}

0 comments on commit 2d38098

Please sign in to comment.