[jboss-cvs] jbosside/core/plugins/org.jboss.ide.eclipse.packages.core/src/main/org/jboss/ide/eclipse/archives/core ...

Robert Stryker rob.stryker at jboss.com
Wed Apr 18 12:52:05 EDT 2007


  User: rawb    
  Date: 07/04/18 12:52:05

  Added:       core/plugins/org.jboss.ide.eclipse.packages.core/src/main/org/jboss/ide/eclipse/archives/core   
                        Trace.java ArchivesCorePlugin.java
                        ExtensionManager.java
  Log:
  refactored to archive rather than package, a la max
  
  Revision  Changes    Path
  1.1      date: 2007/04/18 16:52:05;  author: rawb;  state: Exp;jbosside/core/plugins/org.jboss.ide.eclipse.packages.core/src/main/org/jboss/ide/eclipse/archives/core/Trace.java
  
  Index: Trace.java
  ===================================================================
  package org.jboss.ide.eclipse.archives.core;
  
  import org.eclipse.core.runtime.Platform;
  
  public class Trace {
  
  	public static final String DEBUG_OPTION_ROOT = "org.jboss.ide.eclipse.packages.core/debug/";
  	public static final String DEBUG_OPTION_STREAM_CLOSE = DEBUG_OPTION_ROOT + "streamClose";
  	
  	public static boolean isDebugging(String option)
  	{
  		return ArchivesCorePlugin.getDefault().isDebugging()
  			&& "true".equalsIgnoreCase(Platform.getDebugOption(option));
  	}
  	
  	public static void trace (Class caller, String message)
  	{
  		trace(caller, message, null);
  	}
  	
  	public static void trace (Class caller, String message, String option)
  	{
  		trace(caller, message, null, option);
  	}
  	
  	public static void trace (Class caller, Throwable t)
  	{
  		trace(caller, t, null);
  	}
  	
  	public static void trace (Class caller, Throwable t, String option)
  	{
  		trace(caller, t.getMessage(), t, option);
  	}
  	
  	public static void trace (Class caller, String message, Throwable t, String option)
  	{
  		if (!ArchivesCorePlugin.getDefault().isDebugging())
  			return;
  
  		if (option != null) {
  			if (!isDebugging(option))
  				return;
  		}
  		
  		System.out.println("[" + caller.getName() + "] " + message);
  		
  		if (t != null)
  		{
  			t.printStackTrace();
  		}
  	}
  	
  }
  
  
  
  1.1      date: 2007/04/18 16:52:05;  author: rawb;  state: Exp;jbosside/core/plugins/org.jboss.ide.eclipse.packages.core/src/main/org/jboss/ide/eclipse/archives/core/ArchivesCorePlugin.java
  
  Index: ArchivesCorePlugin.java
  ===================================================================
  /*
   * JBoss, a division of Red Hat
   * Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
   * by the @authors tag. See the copyright.txt in the distribution for a
   * full listing of individual contributors.
   *
   * This is free software; you can redistribute it and/or modify it
   * under the terms of the GNU Lesser General Public License as
   * published by the Free Software Foundation; either version 2.1 of
   * the License, or (at your option) any later version.
   *
   * This software is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
   * Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public
   * License along with this software; if not, write to the Free
   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
   */
  package org.jboss.ide.eclipse.archives.core;
  
  import org.eclipse.core.runtime.Plugin;
  import org.jboss.ide.eclipse.archives.core.model.internal.xb.XMLBinding;
  import org.osgi.framework.BundleContext;
  
  /**
   * The activator class controls the plug-in life cycle
   */
  public class ArchivesCorePlugin extends Plugin {
  
  	// The plug-in ID
  	public static final String PLUGIN_ID = "org.jboss.ide.eclipse.archives.core";
  
  	// The shared instance
  	private static ArchivesCorePlugin plugin;
  	
  	/**
  	 * The constructor
  	 */
  	public ArchivesCorePlugin() {
  		plugin = this;
  	}
  
  	/*
  	 * (non-Javadoc)
  	 * @see org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext)
  	 */
  	public void start(BundleContext context) throws Exception {
  		super.start(context);
  		
  		// force JBossXB initialization
  		XMLBinding.init();
  	}
  
  	/*
  	 * (non-Javadoc)
  	 * @see org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext)
  	 */
  	public void stop(BundleContext context) throws Exception {
  		plugin = null;
  		super.stop(context);
  	}
  
  	/**
  	 * Returns the shared instance
  	 *
  	 * @return the shared instance
  	 */
  	public static ArchivesCorePlugin getDefault() {
  		return plugin;
  	}
  
  }
  
  
  
  1.1      date: 2007/04/18 16:52:05;  author: rawb;  state: Exp;jbosside/core/plugins/org.jboss.ide.eclipse.packages.core/src/main/org/jboss/ide/eclipse/archives/core/ExtensionManager.java
  
  Index: ExtensionManager.java
  ===================================================================
  package org.jboss.ide.eclipse.archives.core;
  
  import java.util.ArrayList;
  import java.util.Hashtable;
  
  import org.eclipse.core.runtime.CoreException;
  import org.eclipse.core.runtime.IConfigurationElement;
  import org.eclipse.core.runtime.IExtension;
  import org.eclipse.core.runtime.IExtensionPoint;
  import org.eclipse.core.runtime.IExtensionRegistry;
  import org.eclipse.core.runtime.InvalidRegistryObjectException;
  import org.eclipse.core.runtime.Platform;
  import org.jboss.ide.eclipse.archives.core.model.types.IArchiveType;
  
  public class ExtensionManager {
  	public static final String ARCHIVE_TYPES_EXTENSION_ID = "org.jboss.ide.eclipse.archives.core.packageTypes";
  	
  	public static IExtension[] findExtension (String extensionId)
  	{
  		IExtensionRegistry registry = Platform.getExtensionRegistry();
  		IExtensionPoint extensionPoint = registry.getExtensionPoint(extensionId);
  		return extensionPoint.getExtensions();
  	}
  	
  	public static IArchiveType[] findPackageTypes ()
  	{
  		ArrayList archiveTypes = new ArrayList();
  		IExtension[] extensions = findExtension(ARCHIVE_TYPES_EXTENSION_ID);
  		
  		for (int i = 0; i < extensions.length; i++)
  		{
  			IConfigurationElement elements[] = extensions[i].getConfigurationElements();
  			for (int j = 0; j < elements.length; j++)
  			{
  				try {
  					Object executable = elements[j].createExecutableExtension("class");
  					archiveTypes.add((IArchiveType)executable);
  				} catch (InvalidRegistryObjectException e) {
  					Trace.trace(ExtensionManager.class, e);
  				} catch( CoreException e ) {
  					Trace.trace(ExtensionManager.class, e);
  				}
  			}
  		}
  		
  		return (IArchiveType[]) archiveTypes.toArray(new IArchiveType[archiveTypes.size()]);
  	}
  	
  	private static Hashtable archiveTypes;
  	public static IArchiveType getArchiveType (String packageType) {
  		if (archiveTypes == null)
  		{
  			archiveTypes = new Hashtable();
  			IArchiveType[] registeredTypes = ExtensionManager.findPackageTypes();
  			for (int i = 0; i < registeredTypes.length; i++)	
  			{
  				archiveTypes.put(registeredTypes[i].getId(), registeredTypes[i]);
  			}
  		}
  		return (IArchiveType) archiveTypes.get(packageType);
  	}
  
  	
  }
  
  
  



More information about the jboss-cvs-commits mailing list