KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > ui > launcher > OSGiLaunchConfigurationInitializer


1 /*******************************************************************************
2  * Copyright (c) 2006, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.ui.launcher;
12
13 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
14 import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
15 import org.eclipse.pde.core.plugin.IPluginModelBase;
16 import org.eclipse.pde.core.plugin.PluginRegistry;
17
18 /**
19  * Initilizes launch configuration attributes for newly-created OSGi Framework
20  * launch configurations
21  *
22  * <p>
23  * Clients may instantiate or subclass this class
24  * </p>
25  *
26  * @since 3.3
27  */

28 public class OSGiLaunchConfigurationInitializer {
29     
30     protected static final String JavaDoc DEFAULT = "default"; //$NON-NLS-1$
31

32     /**
33      * Initializes some attributes on a newly-created launch configuration
34      *
35      * @param configuration
36      * the launch configuration
37      */

38     public void initialize(ILaunchConfigurationWorkingCopy configuration) {
39         initializeFrameworkDefaults(configuration);
40         initializeBundleState(configuration);
41         initializeSourcePathProvider(configuration);
42     }
43     
44     /**
45      * Sets the source provider ID
46      *
47      * @param configuration
48      * the launch configuration
49      */

50     protected void initializeSourcePathProvider(ILaunchConfigurationWorkingCopy configuration) {
51         configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_SOURCE_PATH_PROVIDER,
52                                     PDESourcePathProvider.ID);
53     }
54
55     /**
56      * Initializes the start level and auto-start attributes
57      *
58      * @param configuration
59      * the launch configuration
60      */

61     protected void initializeFrameworkDefaults(ILaunchConfigurationWorkingCopy configuration) {
62         configuration.setAttribute(IPDELauncherConstants.DEFAULT_AUTO_START, true);
63         configuration.setAttribute(IPDELauncherConstants.DEFAULT_START_LEVEL, 4);
64     }
65     
66     /**
67      * Initializes the checked/unchecked state of bundles
68      *
69      * @param configuration
70      * the launch configuration
71      */

72     protected void initializeBundleState(ILaunchConfigurationWorkingCopy configuration) {
73         StringBuffer JavaDoc explugins = new StringBuffer JavaDoc();
74         StringBuffer JavaDoc wsplugins = new StringBuffer JavaDoc();
75         IPluginModelBase[] models = PluginRegistry.getActiveModels();
76         for (int i = 0; i < models.length; i++) {
77             String JavaDoc id = models[i].getPluginBase().getId();
78             boolean inWorkspace = models[i].getUnderlyingResource() != null;
79             appendBundle(inWorkspace ? wsplugins : explugins, id);
80         }
81         configuration.setAttribute(IPDELauncherConstants.WORKSPACE_BUNDLES, wsplugins.toString());
82         configuration.setAttribute(IPDELauncherConstants.TARGET_BUNDLES, explugins.toString());
83         configuration.setAttribute(IPDELauncherConstants.AUTOMATIC_ADD, true);
84     }
85     
86     private void appendBundle(StringBuffer JavaDoc buffer, String JavaDoc bundleID) {
87         if (buffer.length() > 0)
88             buffer.append(","); //$NON-NLS-1$
89
buffer.append(bundleID);
90         buffer.append("@"); //$NON-NLS-1$
91
buffer.append(getStartLevel(bundleID));
92         buffer.append(":"); //$NON-NLS-1$
93
buffer.append(getAutoStart(bundleID));
94     }
95     
96     /**
97      * Returns the bundle's start level
98      *
99      * @param bundleID
100      * the bundle ID
101      * @return the start level for the given bundle or the string <code>default</code>
102      */

103     protected String JavaDoc getStartLevel(String JavaDoc bundleID) {
104         return DEFAULT;
105     }
106     
107     /**
108      * Returns whether the bundle should be started automatically
109      * @param bundleID
110      * the bundle ID
111      * @return <code>true</code>, <code>false</code>, or <code>default</code>
112      */

113     protected String JavaDoc getAutoStart(String JavaDoc bundleID) {
114         return DEFAULT;
115     }
116
117 }
118
Popular Tags