KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > core > text > bundle > ImportPackageObject


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.core.text.bundle;
12
13 import java.io.PrintWriter JavaDoc;
14
15 import org.eclipse.osgi.service.resolver.ExportPackageDescription;
16 import org.eclipse.osgi.util.ManifestElement;
17 import org.eclipse.pde.internal.core.ICoreConstants;
18 import org.eclipse.pde.internal.core.bundle.BundlePluginBase;
19 import org.eclipse.pde.internal.core.ibundle.IBundleModel;
20 import org.osgi.framework.Constants;
21 import org.osgi.framework.Version;
22
23 public class ImportPackageObject extends PackageObject {
24     
25     private static final long serialVersionUID = 1L;
26        
27     private static String JavaDoc getVersion(ExportPackageDescription desc) {
28         String JavaDoc version = desc.getVersion().toString();
29         if (!version.equals(Version.emptyVersion.toString()))
30             return desc.getVersion().toString();
31         return null;
32     }
33     
34     public ImportPackageObject(ManifestHeader header, ManifestElement element, String JavaDoc versionAttribute) {
35         super(header, element, versionAttribute);
36     }
37     
38     public ImportPackageObject(ManifestHeader header, ExportPackageDescription desc, String JavaDoc versionAttribute) {
39         super(header, desc.getName(), getVersion(desc), versionAttribute);
40     }
41     
42     public ImportPackageObject(ManifestHeader header, String JavaDoc id, String JavaDoc version, String JavaDoc versionAttribute) {
43         super(header, id, version, versionAttribute);
44     }
45    
46     public boolean isOptional() {
47         int manifestVersion = BundlePluginBase.getBundleManifestVersion(getHeader().getBundle());
48         if (manifestVersion > 1)
49             return Constants.RESOLUTION_OPTIONAL.equals(getDirective(Constants.RESOLUTION_DIRECTIVE));
50         return "true".equals(getAttribute(ICoreConstants.OPTIONAL_ATTRIBUTE)); //$NON-NLS-1$
51
}
52
53     public void setOptional(boolean optional) {
54         boolean old = isOptional();
55         int manifestVersion = BundlePluginBase.getBundleManifestVersion(getHeader().getBundle());
56         if (optional) {
57             if (manifestVersion > 1)
58                 setDirective(Constants.RESOLUTION_DIRECTIVE, Constants.RESOLUTION_OPTIONAL);
59             else
60                 setAttribute(ICoreConstants.OPTIONAL_ATTRIBUTE, "true"); //$NON-NLS-1$
61
} else {
62             setDirective(Constants.RESOLUTION_DIRECTIVE, null);
63             setAttribute(ICoreConstants.OPTIONAL_ATTRIBUTE, null);
64         }
65         fHeader.update();
66         firePropertyChanged(this, Constants.RESOLUTION_DIRECTIVE, Boolean.toString(old), Boolean.toString(optional));
67     }
68
69     /**
70      * @param model
71      * @param header
72      * @param versionAttribute
73      */

74     public void reconnect(IBundleModel model, ImportPackageHeader header,
75             String JavaDoc versionAttribute) {
76         super.reconnect(model, header, versionAttribute);
77         // No transient fields
78
}
79     
80     /* (non-Javadoc)
81      * @see org.eclipse.pde.internal.core.bundle.BundleObject#write(java.lang.String, java.io.PrintWriter)
82      */

83     public void write(String JavaDoc indent, PrintWriter JavaDoc writer) {
84         // Used for text transfers for copy, cut, paste operations
85
writer.write(write());
86     }
87     
88 }
89
Popular Tags