KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > correction > AddSingletonToSymbolicName


1 /*******************************************************************************
2  * Copyright (c) 2005, 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.internal.ui.correction;
12
13 import org.eclipse.pde.internal.core.TargetPlatformHelper;
14 import org.eclipse.pde.internal.core.ibundle.IBundle;
15 import org.eclipse.pde.internal.core.ibundle.IManifestHeader;
16 import org.eclipse.pde.internal.core.text.bundle.Bundle;
17 import org.eclipse.pde.internal.core.text.bundle.BundleModel;
18 import org.eclipse.pde.internal.core.text.bundle.BundleSymbolicNameHeader;
19 import org.eclipse.pde.internal.ui.PDEUIMessages;
20 import org.osgi.framework.Constants;
21
22 public class AddSingletonToSymbolicName extends AbstractManifestMarkerResolution {
23
24     private boolean fisDirective;
25     
26     public AddSingletonToSymbolicName(int type, boolean directive) {
27         super(type);
28         fisDirective = directive;
29     }
30
31     public String JavaDoc getDescription() {
32         if (fisDirective)
33             return PDEUIMessages.AddSingleon_dir_desc;
34         return PDEUIMessages.AddSingleon_att_desc;
35     }
36
37     public String JavaDoc getLabel() {
38         if (fisDirective)
39             return PDEUIMessages.AddSingleon_dir_label;
40         return PDEUIMessages.AddSingleon_att_label;
41     }
42
43     protected void createChange(BundleModel model) {
44         IBundle bundle = model.getBundle();
45         if (bundle instanceof Bundle) {
46             Bundle bun = (Bundle)bundle;
47             IManifestHeader header = bun.getManifestHeader(Constants.BUNDLE_SYMBOLICNAME);
48             if (header instanceof BundleSymbolicNameHeader) {
49                 if (fisDirective && TargetPlatformHelper.getTargetVersion() >= 3.1)
50                     bundle.setHeader(Constants.BUNDLE_MANIFESTVERSION, "2"); //$NON-NLS-1$
51
else if (!fisDirective && TargetPlatformHelper.getTargetVersion() < 3.1)
52                     bundle.setHeader(Constants.BUNDLE_MANIFESTVERSION, null);
53                 ((BundleSymbolicNameHeader)header).setSingleton(true);
54             }
55         }
56     }
57 }
58
Popular Tags