|
Glassfish example source code file (ExtensionValidator.java)
The Glassfish ExtensionValidator.java source code
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 1997-2010 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*
*
* This file incorporates work covered by the following copyright and
* permission notice:
*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.catalina.util;
import org.apache.catalina.core.StandardContext;
import org.apache.naming.resources.Resource;
import javax.naming.Binding;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.DirContext;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Locale;
import java.util.NoSuchElementException;
import java.util.ResourceBundle;
import java.util.StringTokenizer;
import java.util.jar.JarInputStream;
import java.util.jar.Manifest;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Ensures that all extension dependies are resolved for a WEB application
* are met. This class builds a master list of extensions available to an
* applicaiton and then validates those extensions.
*
* See http://java.sun.com/j2se/1.4/docs/guide/extensions/spec.html for
* a detailed explanation of the extension mechanism in Java.
*
* @author Greg Murray
* @author Justyna Horwat
* @version $Revision: 1.3 $ $Date: 2006/03/12 01:27:08 $
*
*/
public final class ExtensionValidator {
private static Logger log = Logger.getLogger(ExtensionValidator.class.getName());
/**
* The string resources for this package.
*/
private static StringManager sm =
StringManager.getManager("org.apache.catalina.util");
private static volatile HashMap containerAvailableExtensions = null;
private static ArrayList containerManifestResources = new ArrayList();
private static ResourceBundle messages = null;
// ----------------------------------------------------- Static Initializer
/**
* This static initializer loads the container level extensions that are
* available to all web applications. This method scans all extension
* directories available via the "java.ext.dirs" System property.
*
* The System Class-Path is also scanned for jar files that may contain
* available extensions.
*/
static {
// check for container level optional packages
String systemClasspath = System.getProperty("java.class.path");
StringTokenizer strTok = new StringTokenizer(systemClasspath,
File.pathSeparator);
// build a list of jar files in the classpath
while (strTok.hasMoreTokens()) {
String classpathItem = strTok.nextToken();
if (classpathItem.toLowerCase(Locale.ENGLISH).endsWith(".jar")) {
File item = new File(classpathItem);
if (item.exists()) {
try {
addSystemResource(item);
} catch (IOException e) {
log.log(Level.SEVERE,
sm.getString("extensionValidator.failload",
item),
e);
}
}
}
}
// get the files in the extensions directory
String extensionsDir = System.getProperty("java.ext.dirs");
if (extensionsDir != null) {
StringTokenizer extensionsTok
= new StringTokenizer(extensionsDir, File.pathSeparator);
while (extensionsTok.hasMoreTokens()) {
File targetDir = new File(extensionsTok.nextToken());
if (!targetDir.exists() || !targetDir.isDirectory()) {
continue;
}
File[] files = targetDir.listFiles();
for (int i = 0; i < files.length; i++) {
if (files[i].getName().toLowerCase(Locale.ENGLISH).endsWith(".jar")) {
try {
addSystemResource(files[i]);
} catch (IOException e) {
log.log(Level.SEVERE,
sm.getString("extensionValidator.failload",
files[i]),
e);
}
}
}
}
}
}
// --------------------------------------------------------- Public Methods
/**
* Runtime validation of a Web Applicaiton.
*
* This method uses JNDI to look up the resources located under a
* <code>DirContext. It locates Web Application MANIFEST.MF
* file in the /META-INF/ directory of the application and all
* MANIFEST.MF files in each JAR file located in the WEB-INF/lib
* directory and creates an <code>ArrayList of
* <code>ManifestResorce
Other Glassfish examples (source code examples)Here is a short list of links related to this Glassfish ExtensionValidator.java source code file: |
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.