| Method from org.jboss.embedded.DeploymentGroup Detail: |
public void add(VirtualFile vf) throws DeploymentException {
VFSDeploymentFactory factory = VFSDeploymentFactory.getInstance();
VFSDeployment deployment = factory.createVFSDeployment(vf);
mainDeployer.addDeployment(deployment);
deployments.add(deployment);
}
Schedule a VirtualFile to be deployed |
public void add(URL url) throws DeploymentException {
VirtualFile file = getVirtualFile(url);
add(file);
}
schedules a URL to be deployed |
protected void addBaseResource(URL url,
String baseResource) throws DeploymentException {
String urlString = url.toString();
int idx = urlString.lastIndexOf(baseResource);
urlString = urlString.substring(0, idx);
URL deployUrl = null;
try
{
deployUrl = new URL(urlString);
}
catch (MalformedURLException e)
{
throw new RuntimeException(e);
}
add(deployUrl);
}
|
public void addClasspath() throws DeploymentException {
addUrls(getClassPaths());
}
Scan all paths/jars in Java CLasspath (found with java.class.path System Property)
schedule these jars to be deployed |
public void addClasspath(String paths) throws DeploymentException {
List< URL > urls = getClassPaths(paths);
addUrls(urls);
}
Scan Java Classpath (found with java.class.path)
for a specified list of files you want to deploy
The files listed should be only the filename. Do not put relative or absolute paths in filenames.
i.e. "myejbs.jar, my-beans.xml" |
public void addDirectory(URL directory,
boolean recurse) throws DeploymentException, IOException {
addVirtualFiles(getDeployerDirUrls(filter, directory, recurse));
}
|
public void addDirectoryByResource(String resource,
boolean recurse) throws DeploymentException, IOException {
ClassLoader loader = Thread.currentThread().getContextClassLoader();
if (classLoader != null) loader = classLoader;
List< VirtualFile > files = getDeployerDirUrlsFromResource(filter, loader, resource, recurse);
addVirtualFiles(files);
}
Searches for a directory as described in the getDirFromResource() method of this class.
schedules all possible files in directory to be deployed |
public void addFileByResource(String resource) throws DeploymentException, IOException {
ClassLoader loader = Thread.currentThread().getContextClassLoader();
if (classLoader != null) loader = classLoader;
URL url = getDirFromResource(loader, resource);
if (url == null)
{
throw new DeploymentException("Unable to find file from resource: " + resource);
}
String urlStr = url.toString();
if (urlStr.endsWith("/"))
{
urlStr = urlStr.substring(0, urlStr.length() -1);
}
url = new URL(urlStr);
add(url);
}
Searches for a file based on the location of an existing classloader resource
as described in the getDirFromResource() method of this class.
schedules this particular file for deployment |
public void addMultipleResources(String resource) throws DeploymentException, IOException {
ClassLoader loader = Thread.currentThread().getContextClassLoader();
if (classLoader != null) loader = classLoader;
Enumeration< URL > urls = loader.getResources(resource);
while (urls.hasMoreElements())
{
add(urls.nextElement());
}
}
Search for resources using the group's configured classloader
if no classloader, then Thread.currentThread().getContextClassLoader() is used.
classLoader.getResources(String resource)
Schedule the resource to be deployed. |
public void addResource(String resource) throws DeploymentException, NullPointerException {
ClassLoader loader = Thread.currentThread().getContextClassLoader();
if (classLoader != null)
loader = classLoader;
URL url = loader.getResource(resource);
if (url == null)
throw new NullPointerException("Resource was null: " + resource);
add(url);
}
Search for the resource using the group's configured classloader
if no classloader, then Thread.currentThread().getContextClassLoader() is used.
classLoader.getResource(String resource)
Schedule the resource to be deployed. |
public void addResourceBase(String baseResource) throws DeploymentException {
ClassLoader loader = Thread.currentThread().getContextClassLoader();
if (classLoader != null) loader = classLoader;
URL url = loader.getResource(baseResource);
if (url == null) throw new RuntimeException("Could not find baseResource: " + baseResource);
addBaseResource(url, baseResource);
}
Deploy the classpath directory or .jar file a classloader resource is located in.
i.e.
classpath is "/home/wburke/lib/tutorial.jar"
tutorial.jar has "META-INF/persistence.xml" resource within it.
addResourceBase("META-INF/persistence.xml") will try and deploy tutorial.jar |
public void addResourceBase(Class baseResource) throws DeploymentException {
String resource = baseResource.getName().replace('.", '/") + ".class";
addResourceBase(resource);
}
Find the .class file resource of provided class
Return a URL pointing to the classpath the resource is located in.
i.e.
classpath is "/home/wburke/lib/tutorial.jar"
tutorial.jar has "META-INF/persistence.xml" resource within it.
addResourceBase("META-INF/persistence.xml") will try and deploy tutorial.jar |
public void addResourceBases(String baseResource) throws DeploymentException {
ClassLoader loader = Thread.currentThread().getContextClassLoader();
if (classLoader != null) loader = classLoader;
try
{
Enumeration< URL > urls = loader.getResources(baseResource);
while (urls.hasMoreElements())
{
URL url = urls.nextElement();
addBaseResource(url, baseResource);
}
}
catch (IOException e)
{
throw new RuntimeException(e);
}
}
Deploy the classpath directories or .jar files a classloader resource is located in.
ClassLoader.getResources() is used to find the base resources.
i.e.
classpath is "/home/wburke/lib/tutorial.jar:/home/wburke/lib/pu.jar"
tutorial.jar and pu.jar has "META-INF/persistence.xml" resource within it.
addResourceBases("META-INF/persistence.xml") will try and deploy tutorial.jar and pu.jar because
the both have the META-INF/persistence.xml resource within them. |
public void addUrls(List urls) throws DeploymentException {
for (URL url : urls)
{
add(url);
}
}
schedules a list of urls to be deployed |
public void addVirtualFiles(List vfs) throws DeploymentException {
for (VirtualFile vf : vfs)
{
add(vf);
}
}
schedules a list of virtual files to be deployed |
public static List getClassPaths() throws DeploymentException {
List< URL > list = new ArrayList< URL >();
String classpath = System.getProperty("java.class.path");
StringTokenizer tokenizer = new StringTokenizer(classpath, File.pathSeparator);
while (tokenizer.hasMoreTokens())
{
String path = tokenizer.nextToken();
File fp = new File(path);
if (!fp.exists()) throw new DeploymentException("File in java.class.path does not exist: " + fp);
try
{
list.add(fp.toURL());
}
catch (MalformedURLException e)
{
throw new DeploymentException(e);
}
}
return list;
}
|
public static List getClassPaths(String paths) throws DeploymentException {
ArrayList< URL > list = new ArrayList< URL >();
String classpath = System.getProperty("java.class.path");
StringTokenizer tokenizer = new StringTokenizer(classpath, File.pathSeparator);
String[] split = paths.split(",");
for (int i = 0; i < split.length; i++)
{
split[i] = split[i].trim();
}
while (tokenizer.hasMoreTokens())
{
String path = tokenizer.nextToken().trim();
boolean found = false;
for (String wantedPath : split)
{
if (path.endsWith(File.separator + wantedPath))
{
found = true;
break;
}
}
if (!found)
continue;
File fp = new File(path);
if (!fp.exists())
throw new DeploymentException("File in java.class.path does not exists: " + fp);
try
{
list.add(fp.toURL());
}
catch (MalformedURLException e)
{
throw new DeploymentException(e);
}
}
return list;
}
|
public static List getDeployerDirUrls(VirtualFileFilter filter,
URL url,
boolean recurse) throws DeploymentException, IOException {
VirtualFile file = null;
try
{
file = VFS.getRoot(url);
}
catch (Exception e)
{
throw new DeploymentException("Unable to find deployDir from url: " + url, e);
}
List< VirtualFile > files = new ArrayList< VirtualFile >();
addDeployments(filter, files, file, recurse);
return files;
}
|
public static List getDeployerDirUrlsFromResource(VirtualFileFilter filter,
ClassLoader loader,
String resource,
boolean recurse) throws DeploymentException, IOException {
URL url = getDirFromResource(loader, resource);
if (url == null)
{
throw new DeploymentException("Unable to find deployDir from resource: " + resource);
}
List< VirtualFile > files = getDeployerDirUrls(filter, url, recurse);
return files;
}
|
public List getDeploymentUnits() {
ArrayList< DeploymentUnit > result = new ArrayList< DeploymentUnit >();
MainDeployerStructure structure = (MainDeployerStructure) mainDeployer;
for (VFSDeployment deployment : deployments)
{
DeploymentUnit unit = structure.getDeploymentUnit(deployment.getName());
if (unit == null)
throw new IllegalStateException("DeploymentUnit not found " + deployment.getName());
result.add(unit);
}
return result;
}
|
public List getDeployments() {
return deployments;
}
|
public static URL getDirFromResource(ClassLoader loader,
String resource) {
int idx = resource.indexOf("/.");
String base = resource;
String relative = null;
if (idx != -1)
{
base = resource.substring(0, idx);
relative = resource.substring(idx + 1);
}
URL url = loader.getResource(base);
if (url == null) return null;
String urlAsString = url.toString();
String[] paths = urlAsString.split("/");
int last = paths.length - 2;
if (relative != null)
{
String[] relativePaths = relative.split("/");
int relativeStart = 0;
for (String relativePath : relativePaths)
{
if (relativePath.equals(".."))
{
last--;
relativeStart++;
}
else if (relativePath.equals("."))
{
relativeStart++;
}
else
{
break;
}
}
urlAsString = "";
for (int i = 0; i < = last; i++)
{
urlAsString += paths[i] + "/";
}
for (int i = relativeStart; i < relativePaths.length; i++)
{
urlAsString += relativePaths[i] + "/";
}
}
else
{
urlAsString = "";
for (int i = 0; i < = last; i++)
{
urlAsString += paths[i] + "/";
}
}
try
{
url = new URL(urlAsString);
}
catch (MalformedURLException e)
{
throw new RuntimeException(e);
}
return url;
}
Find the directory that contains a given resource.
The '.' character can be used to specify the current directory.
The '..' string can be used to specify a higher relative path
i.e.
getDirFromResource(loader, "org/jboss/Test.class")
file://org/jboss/
getDirFromResource(loader, "org/jboss/Test.class/..")
file://org/
getDirFromResource(loader, "org/jboss/Test.class/../acme")
file://org/acme/
getDirFromResource(loader, "org/jboss/Test.class/./embedded")
file://org/jboss/embedded/ |
public static VirtualFile getVirtualFile(URL url) throws DeploymentException {
VirtualFile file = null;
try
{
file = VFS.getRoot(url);
}
catch (IOException e)
{
throw new DeploymentException("Unable to get VirtualFile for url: " + url, e);
}
return file;
}
|
public void process() throws DeploymentException {
mainDeployer.process();
mainDeployer.checkComplete();
}
Ask the mainDeployer to process the set of files you added to the group
this will also check the processing |
public void setClassLoader(ClassLoader classLoader) {
this.classLoader = classLoader;
}
|
public void setFilter(VirtualFileFilter filter) {
this.filter = filter;
}
File filter that will be used when scanning a directory |
public void setKernel(Kernel kernel) {
this.kernel = kernel;
}
|
public void setMainDeployer(MainDeployer mainDeployer) {
this.mainDeployer = mainDeployer;
}
|
public void undeploy() throws DeploymentException {
for (VFSDeployment ctx : deployments)
mainDeployer.removeDeployment(ctx);
process();
}
Ask the mainDeployer to undeploy the set of files in the group |