alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 *                 Sun Public License Notice
 *
 * The contents of this file are subject to the Sun Public License
 * Version 1.0 (the "License"). You may not use this file except in
 * compliance with the License. A copy of the License is available at
 * http://www.sun.com/
 *
 * The Original Code is NetBeans. The Initial Developer of the Original
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun
 * Microsystems, Inc. All Rights Reserved.
 */

package org.netbeans.modules.web.api.webmodule;

import java.util.Iterator;
import org.netbeans.modules.web.webmodule.WebModuleAccessor;
import org.netbeans.modules.web.spi.webmodule.*;
import org.openide.filesystems.FileObject;
import org.openide.util.Lookup;

/** WebModule should be used to access contens and properties of web module.
 * 

* A client may obtain a WebModule instance using * WebModule.getWebModule(fileObject) static method, for any * FileObject in the web module directory structure. *

*
*

* Use classpath API to obtain classpath for the document base (this classpath * is used for code completion of JSPs). An example: *

 *   WebModule wm = ...;
 *   FileObject docRoot = wm.getDocumentBase ();
 *   ClassPath cp = ClassPath.getClassPath(docRoot, ClassPath.EXECUTE);
 * 
 * 
*

* Note that the particular directory structure for web module is not guaranteed * by this API. *

* * @author Pavel Buzek */ public final class WebModule { public static final String J2EE_13_LEVEL = "1.3"; //NOI18N public static final String J2EE_14_LEVEL = "1.4"; //NOI18N private WebModuleImplementation impl; private static final Lookup.Result implementations = Lookup.getDefault().lookup(new Lookup.Template(WebModuleProvider.class)); static { WebModuleAccessor.DEFAULT = new WebModuleAccessor() { public WebModule createWebModule(WebModuleImplementation spiWebmodule) { return new WebModule(spiWebmodule); } public WebModuleImplementation getWebModuleImplementation(WebModule wm) { return wm == null ? null : wm.impl; } }; } private WebModule (WebModuleImplementation impl) { if (impl == null) throw new IllegalArgumentException (); this.impl = impl; } /** Find the WebModule for given file or null if the file does not belong * to any web module. */ public static WebModule getWebModule (FileObject f) { if (f == null) { throw new NullPointerException("Passed null to WebModule.getWebModule(FileObject)"); // NOI18N } Iterator it = implementations.allInstances().iterator(); while (it.hasNext()) { WebModuleProvider impl = (WebModuleProvider)it.next(); WebModule wm = impl.findWebModule (f); if (wm != null) { return wm; } } return null; } /** Folder that contains sources of the static documents for * the web module (html, JSPs, etc.). */ public FileObject getDocumentBase () { return impl.getDocumentBase (); } /** WEB-INF folder for the web module. * It may return null for web module that does not have any WEB-INF folder. *
* The WEB-INF folder would typically be a child of the folder returned * by {@link #getDocumentBase} but does not need to be. *
*/ public FileObject getWebInf () { return impl.getWebInf (); } /** Deployment descriptor (web.xml file) of the web module. *
* The web.xml file would typically be a child of the folder returned * by {@link #getWebInf} but does not need to be. *
*/ public FileObject getDeploymentDescriptor () { return impl.getDeploymentDescriptor (); } /** Context path of the web module. */ public String getContextPath () { return impl.getContextPath (); } /** J2EE platform version - one of the constants {@link #J2EE_13_LEVEL}, * {@link #J2EE_14_LEVEL}. * @return J2EE platform version */ public String getJ2eePlatformVersion () { return impl.getJ2eePlatformVersion (); } /** Returns true if the object represents the same web module. */ public boolean equals (Object obj) { if (!WebModule.class.isAssignableFrom(obj.getClass())) return false; WebModule wm = (WebModule) obj; return getDocumentBase().equals(wm.getDocumentBase()) && getJ2eePlatformVersion().equals (wm.getJ2eePlatformVersion()) && getContextPath().equals(wm.getContextPath()); } public int hashCode () { return getDocumentBase ().getPath ().length () + getContextPath ().length (); } }
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 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.