1 | /******************************************************************************* |
2 | * Copyright (c) 2007, 2009 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.api.tools.internal.descriptors; |
12 | |
13 | import java.util.ArrayList; |
14 | import java.util.List; |
15 | |
16 | import org.eclipse.pde.api.tools.internal.provisional.descriptors.IElementDescriptor; |
17 | import org.eclipse.pde.api.tools.internal.util.Util; |
18 | |
19 | /** |
20 | * Common base class for element descriptors. |
21 | * |
22 | * @since 1.0.0 |
23 | */ |
24 | public abstract class ElementDescriptorImpl implements IElementDescriptor, Comparable { |
25 | |
26 | /** |
27 | * Constant used for controlling tracing in the descriptor framework |
28 | */ |
29 | private static boolean Debug = Util.DEBUG; |
30 | |
31 | /** |
32 | * Method used for initializing tracing in the descriptor framework |
33 | */ |
34 | public static void setDebug(boolean debugValue) { |
35 | Debug = debugValue || Util.DEBUG; |
36 | } |
37 | |
38 | /* (non-Javadoc) |
39 | * @see org.eclipse.pde.api.tools.model.component.IElementDescriptor#getParent() |
40 | */ |
41 | public IElementDescriptor getParent() { |
42 | return null; |
43 | } |
44 | |
45 | /* (non-Javadoc) |
46 | * @see org.eclipse.pde.api.tools.model.component.IElementDescriptor#getPath() |
47 | */ |
48 | public IElementDescriptor[] getPath() { |
49 | List list = new ArrayList(); |
50 | IElementDescriptor element = this; |
51 | while (element != null) { |
52 | list.add(0, element); |
53 | element = element.getParent(); |
54 | } |
55 | return (IElementDescriptor[]) list.toArray(new IElementDescriptor[list.size()]); |
56 | } |
57 | |
58 | /* (non-Javadoc) |
59 | * @see java.lang.Comparable#compareTo(java.lang.Object) |
60 | */ |
61 | public int compareTo(Object o) { |
62 | if (o instanceof ElementDescriptorImpl) { |
63 | ElementDescriptorImpl element = (ElementDescriptorImpl) o; |
64 | return getComparable().compareTo(element.getComparable()); |
65 | } |
66 | if (Debug) { |
67 | System.err.println(o.getClass()); |
68 | } |
69 | return -1; |
70 | } |
71 | |
72 | /** |
73 | * Returns this element's comparable delegate. |
74 | * |
75 | * @return comparable |
76 | */ |
77 | protected abstract Comparable getComparable(); |
78 | } |