KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.eclipse.osgi.util.ManifestElement;
14 import org.eclipse.pde.internal.core.ibundle.IBundleModel;
15
16 public class PackageObject extends PDEManifestElement {
17
18     private static final long serialVersionUID = 1L;
19
20     private transient String JavaDoc fVersionAttribute;
21     
22     public PackageObject(ManifestHeader header, ManifestElement element, String JavaDoc versionAttribute) {
23         super(header, element);
24         fVersionAttribute = versionAttribute;
25     }
26     
27     public PackageObject(ManifestHeader header, String JavaDoc name, String JavaDoc version, String JavaDoc versionAttribute) {
28         super(header, name.length() > 0 ? name : "."); //$NON-NLS-1$
29
fVersionAttribute = versionAttribute;
30         if (version != null)
31             addAttribute(fVersionAttribute, version);
32     }
33     
34      public String JavaDoc toString() {
35         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc(getValue());
36         String JavaDoc version = getVersion();
37         if (version != null && version.length() > 0) {
38             buffer.append(" "); //$NON-NLS-1$
39
boolean wrap = Character.isDigit(version.charAt(0));
40             if (wrap)
41                 buffer.append("("); //$NON-NLS-1$
42
buffer.append(version);
43             if (wrap)
44                 buffer.append(")"); //$NON-NLS-1$
45
}
46         return buffer.toString();
47     }
48     
49     public String JavaDoc getVersion() {
50         String JavaDoc[] version = getAttributes(fVersionAttribute);
51         if (version == null || version.length == 0)
52             return null;
53         if (version.length == 1)
54             return version[0];
55         return version[0] + ',' + version[1];
56     }
57
58     public String JavaDoc getName() {
59         return getValue();
60     }
61     
62     public void setName(String JavaDoc name) {
63         setValueComponents(new String JavaDoc[] {name});
64     }
65
66     public void setVersion(String JavaDoc version) {
67         String JavaDoc old = getVersion();
68         setAttribute(fVersionAttribute, version);
69         fHeader.update();
70         firePropertyChanged(this, fVersionAttribute, old, version);
71     }
72
73     public void reconnect(IBundleModel model, ManifestHeader header,
74             String JavaDoc versionAttribute) {
75         super.reconnect(model, header);
76         // Transient Field: Version Attribute
77
fVersionAttribute = versionAttribute;
78     }
79     
80 }
81
Popular Tags