|
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-2000 Sun * Microsystems, Inc. All Rights Reserved. */ package org.openide.loaders; import java.lang.reflect.InvocationTargetException; import java.io.IOException; import java.util.Enumeration; import org.openide.ServiceType; import org.openide.actions.AbstractCompileAction; import org.openide.loaders.MultiDataObject.Entry; import org.openide.cookies.CompilerCookie; import org.openide.compiler.Compiler; import org.openide.compiler.CompilerType; import org.openide.compiler.Compiler.Depth; import org.openide.nodes.PropertySupport; import org.openide.util.enum.*; import org.openide.util.Lookup; import org.openide.util.NbBundle; /** Support for compilation of data objects. * * @author Jaroslav Tulach */ public class CompilerSupport extends Object implements org.openide.cookies.CompilerCookie { /** extended attribute for the type of compiler */ // [PENDING] this is a misleading name, since it actually points to a handle to a CompilerType private static final java.lang.String EA_COMPILER_MANAGER = "NetBeansAttrDataObjectCompilerManager"; // NOI18N /** Name of property providing a custom {@link CompilerType} for a file. */ public static final java.lang.String PROP_COMPILER_TYPE = "compiler"; // NOI18N /** entry to be associated with */ private Entry entry; /** cookie class for the compilation */ private Class cookie; /** readOnlyAttrs is name of virtual attribute. This name of virtual attribute * is shared between classes (and should be changed everywhere): * - org.openide.filesystems.DefaultAttributes * - org.openide.loaders.ExecutionSupport * - org.openide.loaders.CompilerSupport * - org.netbeans.core.ExJarFileSystem */ private final static String READONLY_ATTRIBUTES = "readOnlyAttrs";//NOI18N /** New support for given entry. The file is taken from the * entry and is updated if the entry moves or renames itself. * @param entry entry to create instance from * @param cookie cookie class for the compilation (e.g. {@link org.openide.cookies.CompilerCookie.Build}) */ protected CompilerSupport(Entry entry, Class cookie) { this.entry = entry; this.cookie = cookie; } /** Supports only {@link Compiler#DEPTH_ONE depth one}. */ public boolean isDepthSupported(Depth depth) { return Compiler.DEPTH_ONE == depth; } /* Adds the right compiler to the job. */ public void addToJob(org.openide.compiler.CompilerJob job, Depth depth) { CompilerType comp = getCompilerType (entry); if (comp == null) { comp = defaultCompilerType (); } if (comp == null) { // #15256 etc. throw new IllegalStateException(getClass().getName() + ".defaultCompilerType returned null"); // NOI18N } comp.prepareJob (job, cookie, entry.getDataObject ()); } /** Allows subclasses to override the default compiler that should * be used for this support. */ protected org.openide.compiler.CompilerType defaultCompilerType() { return CompilerType.getDefault (); } /** Set compiler manager for a given file. * @param entry entry to set the compiler for * @param man type to use * @exception IOException if compiler cannot be set */ public static void setCompilerType(Entry entry, org.openide.compiler.CompilerType man) throws java.io.IOException { entry.getFile ().setAttribute ( EA_COMPILER_MANAGER, man == null ? null : new ServiceType.Handle (man) ); } /** Get compiler manager associated with a given file. * @param entry entry to obtain the compiler for * @return associated manager or null */ public static org.openide.compiler.CompilerType getCompilerType(Entry entry) { Object man = entry.getFile ().getAttribute (EA_COMPILER_MANAGER); if (man == null || ! (man instanceof ServiceType.Handle)) return null; ServiceType type = ((ServiceType.Handle) man).getServiceType (); if (type instanceof CompilerType) { return (CompilerType)type; } Lookup l = Environment.find (entry.getDataObject ()); return (CompilerType)l.lookup (CompilerType.class); // compiler type or null } /** Helper method that creates default properties for compilation of * given file entry. * * @param set sheet set to add properties to */ public void addProperties(org.openide.nodes.Sheet.Set set) { set.put (createCompilerProperty ()); } /** Utility method to handle compilation on given set of DataObject. * Extracts compiler cookies from the provided enumeration of * DataObjects and adds all of them into the provided compiler job. * * @param job compiler job to add objects to * @param en enumeration of DataObject or Node objects * @param type class that should be requested as a cookie * ( |
... 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.