All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.beigesoft.android.ajetty.WapClsLdAndr Maven / Gradle / Ivy

Go to download

A-Jetty for Android. It is Jetty 9.2 adapted for Android configured as minimum server with WebAppDeployer that can deploy ordinal WAR (JSP/JSTL must be pre-compiled into servlets by A-Tomcat). It's only for tests purposes. It doesn't comply to the latest Android policy (loading executable binaries from outside)!

The newest version!
/*
BSD 2-Clause License

Copyright (c) 2019, Beigesoft™
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
  list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
  this list of conditions and the following disclaimer in the documentation
  and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package org.beigesoft.android.ajetty;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.Enumeration;

import dalvik.system.DexClassLoader;

import org.eclipse.jetty.webapp.WebAppClassLoader;
import org.eclipse.jetty.webapp.WebAppContext;

import org.beigesoft.lang.IUrlClassLoader;

/**
 * 

WebAppClassLoader for Android.

* * @author Yury Demidenko */ public class WapClsLdAndr implements IUrlClassLoader { /** *

DexClassLoader.

**/ private DexClassLoader delegate = null; /** *

WebApp Context.

**/ private WebAppContext context; /** *

dexPath for DexClassLoader.

**/ private String dexPath = ""; /** *

optimizedDirectory for DexClassLoader.

**/ private String optimizedDirectory; /** *

Only constructor.

* @param pContext WebAppClassLoader.Context * @throws Exception an Exception **/ public WapClsLdAndr( final WebAppClassLoader.Context pContext) throws Exception { context = (WebAppContext) pContext; } /** *

Initialize DexClassLoader.

* @throws Exception an Exception **/ public final void init() throws Exception { String libPath = context.getWar() + File.separator + "WEB-INF/lib/"; File dirLib = new File(libPath); addJars(dirLib); String classesPath = context.getWar() + File.separator + "WEB-INF/classes/"; File dirClasses = new File(classesPath); addJars(dirClasses); this.delegate = new DexClassLoader(this.dexPath, this.optimizedDirectory, null, WapClsLdAndr.class.getClassLoader()); } /** *

Add jars into dexPath for DexClassLoader.

* @param pLib directory * @throws Exception an Exception **/ public final void addJars(final File pLib) throws Exception { if (pLib.exists() && pLib.isDirectory()) { File[] files = pLib.listFiles(); for (int i = 0; files != null && i < files.length; i++) { String fname = files[i].getName().toLowerCase(); if (!files[i].isDirectory() && fname.endsWith(".jar")) { String jar = files[i].getAbsolutePath(); if ("".equals(this.dexPath)) { this.dexPath = jar; } else { this.dexPath += File.pathSeparator + jar; } } } } } /** *

Just stub for find class.

* @param pName name * @return Class class * @throws ClassNotFoundException always **/ @Override public final Class findClass( final String pName) throws ClassNotFoundException { throw new ClassNotFoundException(); } /** *

Just stub for add URL.

* @param pUrl URL **/ @Override public final void addUrl(final URL pUrl) { // nothing } /** *

Just stub for get resources.

* @param pName name * @return Enumeration URL set * @throws IOException always **/ @Override public final Enumeration getResources( final String pName) throws IOException { throw new IOException(); } /** *

Just stub for get resource.

* @param pName name * @return URL URL **/ @Override public final URL getResource(final String pName) { return null; } /** *

Load classr.

* @param pName name * @return Class class * @throws ClassNotFoundException if not found **/ @Override public final Class loadClass( final String pName) throws ClassNotFoundException { return this.delegate.loadClass(pName); } //Simple getters and setters: /** *

Getter for delegate.

* @return DexClassLoader **/ public final DexClassLoader getDelegate() { return this.delegate; } /** *

Setter for delegate.

* @param pDelegate reference **/ public final void setDelegate(final DexClassLoader pDelegate) { this.delegate = pDelegate; } /** *

Getter for dexPath.

* @return String **/ public final String getDexPath() { return this.dexPath; } /** *

Setter for dexPath.

* @param pDexPath reference **/ public final void setDexPath(final String pDexPath) { this.dexPath = pDexPath; } /** *

Getter for optimizedDirectory.

* @return String **/ public final String getOptimizedDirectory() { return this.optimizedDirectory; } /** *

Setter for optimizedDirectory.

* @param pOptimizedDirectory reference **/ public final void setOptimizedDirectory(final String pOptimizedDirectory) { this.optimizedDirectory = pOptimizedDirectory; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy