KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > update > core > SiteFeatureReference


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.update.core;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.List JavaDoc;
15
16 import org.eclipse.update.internal.core.Messages;
17 import org.eclipse.update.internal.core.UpdateCore;
18
19 /**
20  * Convenience implementation of a feature reference.
21  * <p>
22  * This class may be instantiated or subclassed by clients.
23  * </p>
24  * <p>
25  * <b>Note:</b> This class/interface is part of an interim API that is still under development and expected to
26  * change significantly before reaching stability. It is being made available at this early stage to solicit feedback
27  * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken
28  * (repeatedly) as the API evolves.
29  * </p>
30  * @see org.eclipse.update.core.IFeatureReference
31  * @see org.eclipse.update.core.model.FeatureReferenceModel
32  * @see org.eclipse.update.core.ISiteFeatureReference
33  * @see org.eclipse.update.core.SiteFeatureReferenceModel
34  * @since 2.1
35  */

36 public class SiteFeatureReference extends SiteFeatureReferenceModel implements ISiteFeatureReference {
37
38     private List JavaDoc categories;
39
40     /**
41      * Feature reference default constructor
42      */

43     public SiteFeatureReference() {
44         super();
45     }
46
47     /**
48      * Constructor FeatureReference.
49      * @param ref the reference to copy
50      */

51     public SiteFeatureReference(ISiteFeatureReference ref) {
52         super(ref);
53     }
54
55     /**
56      * Returns an array of categories the referenced feature belong to.
57      *
58      * @see ISiteFeatureReference#getCategories()
59      * @since 2.1
60      */

61     public ICategory[] getCategories() {
62
63         if (categories == null) {
64             categories = new ArrayList JavaDoc();
65             String JavaDoc[] categoriesAsString = getCategoryNames();
66             for (int i = 0; i < categoriesAsString.length; i++) {
67                 ICategory siteCat = getSite().getCategory(categoriesAsString[i]);
68                 if (siteCat != null)
69                     categories.add(siteCat);
70                 else {
71                     String JavaDoc siteURL = getSite().getURL() != null ? getSite().getURL().toExternalForm() : null;
72                     UpdateCore.warn("Category " + categoriesAsString[i] + " not found in Site:" + siteURL); //$NON-NLS-1$ //$NON-NLS-2$
73
}
74             }
75         }
76
77         if (categories.size() == 0) {
78             //there was no category defined
79
//so we add the default "Other" category
80
ICategory category = new Category(Messages.SiteCategory_other_label, Messages.SiteCategory_other_description);
81             categories.add(category);
82         }
83         
84         ICategory[] result = new ICategory[0];
85
86         if (!(categories == null || categories.isEmpty())) {
87             result = new ICategory[categories.size()];
88             categories.toArray(result);
89         }
90         return result;
91     }
92
93     /**
94      * Adds a category to the referenced feature.
95      *
96      * @see ISiteFeatureReference#addCategory(ICategory)
97      * @since 2.1
98      */

99     public void addCategory(ICategory category) {
100         this.addCategoryName(category.getName());
101     }
102
103 }
104
Popular Tags