KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > osgi > framework > internal > core > PackageSource


1 /*******************************************************************************
2  * Copyright (c) 2003, 2006 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.osgi.framework.internal.core;
12
13 import java.io.IOException JavaDoc;
14 import java.net.URL JavaDoc;
15 import java.util.Enumeration JavaDoc;
16 import org.eclipse.osgi.framework.util.KeyedElement;
17
18 public abstract class PackageSource implements KeyedElement {
19     protected String JavaDoc id;
20
21     public PackageSource(String JavaDoc id) {
22         this.id = id.intern();
23     }
24
25     public String JavaDoc getId() {
26         return id;
27     }
28
29     public abstract SingleSourcePackage[] getSuppliers();
30
31     public boolean compare(KeyedElement other) {
32         return id.equals(((PackageSource) other).getId());
33     }
34
35     public int getKeyHashCode() {
36         return id.hashCode();
37     }
38
39     public Object JavaDoc getKey() {
40         return id;
41     }
42
43     public boolean isNullSource() {
44         return false;
45     }
46
47     public boolean isFriend(String JavaDoc symbolicName) {
48         return true;
49     }
50
51     public abstract Class JavaDoc loadClass(String JavaDoc name) throws ClassNotFoundException JavaDoc;
52     public abstract URL JavaDoc getResource(String JavaDoc name);
53     public abstract Enumeration JavaDoc getResources(String JavaDoc name) throws IOException JavaDoc;
54
55     //TODO See how this relates with FilteredSourcePackage. Overwriting or doing a double dispatch might be good.
56
// This is intentionally lenient; we don't force all suppliers to match (only one)
57
// it is better to get class cast exceptions in split package cases than miss an event
58
public boolean hasCommonSource(PackageSource other) {
59         if (other == null)
60             return false;
61         if (this == other)
62             return true;
63         SingleSourcePackage[] suppliers1 = getSuppliers();
64         SingleSourcePackage[] suppliers2 = other.getSuppliers();
65         if (suppliers1 == null || suppliers2 == null)
66             return false;
67         // This will return true if the specified source has at least one
68
// of the suppliers of this source.
69
for (int i = 0; i < suppliers1.length; i++)
70             for (int j = 0; j < suppliers2.length; j++)
71                 if (suppliers2[j].equals(suppliers1[i]))
72                     return true;
73         return false;
74     }
75 }
76
Popular Tags