|
What this is
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-2003 Sun * Microsystems, Inc. All Rights Reserved. */ package org.openide.modules; import java.beans.Beans; import java.util.*; import java.util.jar.Attributes; import java.io.PrintWriter; import java.io.StringWriter; import org.openide.util.NbBundle; import org.openide.loaders.DataLoader; import org.openide.options.SystemOption; import org.openide.filesystems.FileSystem; import org.openide.debugger.Debugger; import org.openide.ServiceType; import org.openide.util.actions.SystemAction; import org.openide.nodes.Node; import org.openide.util.HelpCtx; import org.openide.util.datatransfer.ExClipboard; import org.openide.util.SharedClassObject; /** Class representing one specially-treated section in a module's manifest file. * For example, one section may describe a single action provided by the module. * * @author Jaroslav Tulach, Jesse Glick * @deprecated No longer used. */ public abstract class ManifestSection extends Object { /** name of the class file, e.g. foo/Bar.class */ String name; /** name of the class, e.g. foo.bar */ private String className; /** instance of the class or exeception if not possible to create it */ private Object result; /** associated module */ private ModuleDescription descr; /** Package private constructor to allow creation only from this package. * @param name name of section, should be a class file, e.g. foo/Bar.class * @param descr associated module description * @throws IllegalModuleException if the name is not valid for an OpenIDE section */ ManifestSection (String name, ModuleDescription descr) throws IllegalModuleException { this.name = name; this.descr = descr; className = ModuleDescription.createPackageName (name); } /** Get the class which the generated instances will have. * @return the class * @throws Exception for various reasons */ public Class getSectionClass () throws Exception { if (name.endsWith (".class")) { // NOI18N return descr.cl.loadClass (className); } else { return getInstance ().getClass (); } } /** Getter for instance of this class. * @return the insttance * @exception Exception if there is an error */ Object createInstance () throws Exception { /* System.err.println("ManifestSection.createInstance; cl=" + cl); if (cl != null && cl instanceof java.net.URLClassLoader) { java.net.URL[] urls = ((java.net.URLClassLoader) cl).getURLs (); for (int i = 0; i < urls.length; i++) System.err.println("\t" + urls[i]); } */ Object o = null; try { // First check for SharedClassObject. if (name.endsWith (".class")) { // NOI18N // May throw ClassNotFoundException: Class clazz = descr.cl.loadClass (className); if (SharedClassObject.class.isAssignableFrom (clazz)) { // May throw IllegalArgumentException: o = SharedClassObject.findObject (clazz, true); } } if (o == null) { // .ser or non-SharedClassObject: o = Beans.instantiate (descr.cl, className); } } catch (ClassNotFoundException cnfe) { descr.showLoader (); throw cnfe; } // Don't try to check .ser files: it is quite legitimate to // serialize in a module objects whose class is from elsewhere // (e.g. the core). if (name.endsWith (".class") && o.getClass ().getClassLoader () != descr.cl) // NOI18N descr.badClasses.add (o.getClass ()); return o; } /** Getter for the only installed instance. * * @return the insttance * @exception Exception if there is an error */ synchronized Object getInstance () throws Exception { if (result instanceof Exception) { ((Exception)result).fillInStackTrace (); throw (Exception)result; } if (result == null) { try { result = createInstance (); } catch (Exception ex) { // remember the exception result = ex; throw ex; } catch (Throwable ex) { result = new ClassNotFoundException (exceptionMessage (ex)); throw (Exception) result; } } return result; } // Releases any loaded object from this section. void release () { result = null; } /** Creates a description of an exception. * @param ex exception * @return the string representation of the exception */ static String exceptionMessage (Throwable ex) { StringWriter sw = new StringWriter (); PrintWriter w = new PrintWriter (sw); w.println (ex.getClass ().getName ()); ex.printStackTrace (w); w.close (); return sw.toString (); } /** Abstract method of sections that invokes right method of the given * iterator. * @exception Exception if the section should be removed from list of section */ abstract void invokeIterator (Iterator it) throws Exception; /** Parses attributes and creates its description. * @param name name of the section * @param attr attribues * @param descr the associated module description * @return the section or null if attributes does not represent section * @exception IllegalModuleException if the attributes are not valid */ static ManifestSection createSection (String name, Attributes attr, ModuleDescription descr) throws IllegalModuleException { // Analyze the section String sectionName = attr.getValue (ModuleDescription.TAG_SECTION_CLASS); if (sectionName == null) { // no section tag return null; } else if (sectionName.equalsIgnoreCase(ModuleDescription.SECTION_ACTION)) { return new ActionSection(name, attr, descr); } else if (sectionName.equalsIgnoreCase(ModuleDescription.SECTION_OPTION)) { return new OptionSection(name, attr, descr); } else if (sectionName.equalsIgnoreCase(ModuleDescription.SECTION_LOADER)) { return new LoaderSection(name, attr, descr); } else if (sectionName.equalsIgnoreCase(ModuleDescription.SECTION_FILESYSTEM)) { return new FileSystemSection(name, attr, descr); } else if (sectionName.equalsIgnoreCase(ModuleDescription.SECTION_NODE)) { return new NodeSection(name, attr, descr); } else if (sectionName.equalsIgnoreCase(ModuleDescription.SECTION_SERVICE)) { return new ServiceSection(name, attr, descr); } else if (sectionName.equalsIgnoreCase(ModuleDescription.SECTION_DEBUGGER)) { return new DebuggerSection(name, attr, descr); } else if (sectionName.equalsIgnoreCase(ModuleDescription.SECTION_CLIPBOARD_CONVERTOR)) { return new ClipboardConvertorSection (name, attr, descr); } else { throw new IllegalModuleException (NbBundle.getMessage ( ManifestSection.class, "EXC_IllegalModuleClass", name, sectionName)); } } /** Iterator over different types of sections. * @see ModuleDescription#forEachSection */ public static interface Iterator { /** Process action section. * @param as the section * @exception InstantiationException if there is an error and the section should be ignored */ public void processAction (ActionSection as) throws InstantiationException; /** Process option section. * @param os the section * @exception InstantiationException if there is an error and the section should be ignored */ public void processOption (OptionSection os) throws InstantiationException; /** Process loader section. * @param ls the section * @exception InstantiationException if there is an error and the section should be ignored */ public void processLoader (LoaderSection ls) throws InstantiationException; /** Process debugger section. * @param ds the section * @exception InstantiationException if there is an error and the section should be ignored */ public void processDebugger (DebuggerSection ds) throws InstantiationException; /** Process service section. * @param es the section * @exception Instantiationception if there is an error and the section should be ignored */ public void processService (ServiceSection es) throws InstantiationException; /** Process file system section. * @param fs the section * @exception InstantiationException if there is an error and the section should be ignored */ public void processFileSystem (FileSystemSection fs) throws InstantiationException; /** Process node section. * @param es the section * @exception InstantiationException if there is an error and the section should be ignored */ public void processNode (NodeSection es) throws InstantiationException; /** Process clipboard convertor section. * @param ccs the section * @exception InstantiationException if there is an error and the section should be ignored */ public void processClipboardConvertor (ClipboardConvertorSection ccs) throws InstantiationException; } /** Module section for an Action. * @see SystemAction */ public static final class ActionSection extends ManifestSection { ActionSection(String name, Attributes attrs, ModuleDescription descr) throws IllegalModuleException { super(name, descr); } /** Get the action object. * @return the action * @exception InstantiationException if the action cannot be created */ public SystemAction getAction () throws InstantiationException { try { return (SystemAction)super.getInstance (); } catch (Exception ex) { throw new InstantiationException (ManifestSection.exceptionMessage (ex)); } } /** Calls the right method in the iterator. */ void invokeIterator (Iterator it) throws Exception { it.processAction (this); } } /** Module section for an Option. * @see SystemOption */ public static final class OptionSection extends ManifestSection { OptionSection (String name, Attributes attrs, ModuleDescription descr) throws IllegalModuleException { super(name, descr); } /** Get the system option. * @return the option * @exception InstantiationException if the action cannot be created */ public SystemOption getOption () throws InstantiationException { try { return (SystemOption)super.getInstance (); } catch (Exception ex) { throw new InstantiationException (ManifestSection.exceptionMessage (ex)); } } /** Calls the right method in the iterator. */ void invokeIterator (Iterator it) throws Exception { it.processOption (this); } } /** Module section for a Data Loader. * @see DataLoader */ public static final class LoaderSection extends ManifestSection { /** class name(s) of data object to * be inserted after loader that recognizes its */ private String[] installAfter; /** class name(s) of data object to be inserted before its recognizing * data loader */ private String[] installBefore; LoaderSection (String name, Attributes attrs, ModuleDescription descr) throws IllegalModuleException { super (name, descr); String val = attrs.getValue (ModuleDescription.TAG_INSTALL_AFTER); StringTokenizer tok; List res; if (val != null) { tok = new StringTokenizer (val, ", "); // NOI18N res = new LinkedList (); while (tok.hasMoreTokens ()) { String clazz = tok.nextToken (); if (! clazz.equals ("")) // NOI18N res.add (clazz); } installAfter = (String[]) res.toArray (new String[res.size ()]); } else { installAfter = null; } val = attrs.getValue (ModuleDescription.TAG_INSTALL_BEFORE); if (val != null) { tok = new StringTokenizer (val, ", "); // NOI18N res = new LinkedList (); while (tok.hasMoreTokens ()) { String clazz = tok.nextToken (); if (! clazz.equals ("")) // NOI18N res.add (clazz); } installBefore = (String[]) res.toArray (new String[res.size ()]); } else { installBefore = null; } } /** Get the data loader. * @throws InstantiationException if the loader could not be created * @return the loader */ public DataLoader getLoader () throws InstantiationException { try { return (DataLoader)super.getInstance (); } catch (Exception ex) { throw new InstantiationException (ManifestSection.exceptionMessage (ex)); } } /** Get the representation class(es) of the loader(s) that this one should be installed after. * @return a list of class names, or |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
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.