KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > model > bundle > ExportPackageObject


1 /*******************************************************************************
2  * Copyright (c) 2005 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.model.bundle;
12
13 import java.util.Iterator JavaDoc;
14 import java.util.TreeMap JavaDoc;
15
16 import org.eclipse.jdt.core.*;
17 import org.eclipse.osgi.util.*;
18 import org.eclipse.pde.core.IModelChangedEvent;
19
20 public class ExportPackageObject extends PackageObject {
21     
22     private static final String JavaDoc INTERNAL = "x-internal"; //$NON-NLS-1$
23
private static final String JavaDoc FRIENDS = "x-friends"; //$NON-NLS-1$
24

25     private static final long serialVersionUID = 1L;
26     
27     private boolean fInternal;
28
29     private TreeMap JavaDoc fFriends = new TreeMap JavaDoc();
30      
31     public ExportPackageObject(ManifestHeader header, ManifestElement element, String JavaDoc versionAttribute) {
32         super(header, element, versionAttribute);
33         processFriends(element.getDirective(FRIENDS));
34         fInternal = "true".equals(element.getDirective(INTERNAL)) || fFriends.size() > 0; //$NON-NLS-1$
35
}
36     
37     public ExportPackageObject(ManifestHeader header, IPackageFragment fragment, String JavaDoc versionAttribute) {
38         super(header, fragment.getElementName(), null, versionAttribute);
39     }
40     
41     private void processFriends(String JavaDoc value) {
42         if (value != null) {
43             String JavaDoc[] friends = ManifestElement.getArrayFromList(value);
44             for (int i = 0; i < friends.length; i++) {
45                 PackageFriend friend = new PackageFriend(this, friends[i]);
46                 fFriends.put(friend.getName(), friend);
47             }
48         }
49     }
50
51     protected void appendSupportedAttributes(StringBuffer JavaDoc buffer) {
52        super.appendSupportedAttributes(buffer);
53        if (!fInternal)
54            return;
55        
56        if (fInternal && fFriends.size() == 0) {
57            buffer.append(";"); //$NON-NLS-1$
58
buffer.append(INTERNAL);
59            buffer.append(":=true"); //$NON-NLS-1$
60
}
61        if (fFriends.size() > 0) {
62            buffer.append(";"); //$NON-NLS-1$
63
buffer.append(FRIENDS);
64            buffer.append(":=\""); //$NON-NLS-1$
65
Iterator JavaDoc iter = fFriends.keySet().iterator();
66            while (iter.hasNext()) {
67                buffer.append(iter.next().toString());
68                if (iter.hasNext())
69                    buffer.append(","); //$NON-NLS-1$
70
}
71            buffer.append("\""); //$NON-NLS-1$
72
}
73     }
74
75     public boolean isInternal() {
76         return fInternal;
77     }
78
79     public void setInternal(boolean internal) {
80         boolean old = fInternal;
81         fInternal = internal;
82         firePropertyChanged(this, INTERNAL, Boolean.valueOf(old), Boolean.valueOf(internal));
83     }
84     
85     public PackageFriend[] getFriends() {
86         return (PackageFriend[])fFriends.values().toArray(new PackageFriend[fFriends.size()]);
87     }
88     
89     public void addFriend(PackageFriend friend) {
90         fFriends.put(friend.getName(), friend);
91         fireStructureChanged(friend, IModelChangedEvent.INSERT);
92     }
93     
94     public void removeFriend(PackageFriend friend) {
95         fFriends.remove(friend.getName());
96         fireStructureChanged(friend, IModelChangedEvent.REMOVE);
97     }
98     
99     public boolean hasFriend(String JavaDoc name) {
100         return fFriends.containsKey(name);
101     }
102     
103     protected boolean skipDirective(String JavaDoc directive) {
104         return INTERNAL.equals(directive) || FRIENDS.equals(directive);
105     }
106     
107     public boolean hasSameVisibility(ExportPackageObject object) {
108         if (object.fInternal != fInternal)
109             return false;
110         
111         if (fFriends.size() != object.fFriends.size())
112             return false;
113         
114         Iterator JavaDoc iter = fFriends.keySet().iterator();
115         while (iter.hasNext()) {
116             if (!object.fFriends.containsKey(iter.next()))
117                 return false;
118         }
119         return true;
120     }
121
122 }
123
Popular Tags