KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.update.core;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.Arrays JavaDoc;
15 import java.util.List JavaDoc;
16
17 /**
18  * Site Feature reference model object.
19  * <p>
20  * This class may be instantiated or subclassed by clients. However, in most
21  * cases clients should instead instantiate or subclass the provided
22  * concrete implementation of this model.
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.FeatureReference
31  * @since 2.1
32  */

33 public class SiteFeatureReferenceModel extends FeatureReference {
34
35     private List JavaDoc /* of String*/
36     categoryNames;
37
38
39     /**
40      * Creates an uninitialized feature reference model object.
41      *
42      * @since 2.0
43      */

44     public SiteFeatureReferenceModel() {
45         super();
46     }
47
48     /**
49      * Constructor FeatureReferenceModel.
50      * @param ref
51      */

52     public SiteFeatureReferenceModel(ISiteFeatureReference ref) {
53         super(ref);
54         if (ref instanceof SiteFeatureReferenceModel) {
55             SiteFeatureReferenceModel refModel = (SiteFeatureReferenceModel) ref;
56             setCategoryNames(refModel.getCategoryNames());
57         }
58     }
59
60
61     /**
62      * Returns the names of categories the referenced feature belongs to.
63      *
64      * @return an array of names, or an empty array.
65      * @since 2.0
66      */

67     public String JavaDoc[] getCategoryNames() {
68         if (categoryNames == null)
69             return new String JavaDoc[0];
70
71         return (String JavaDoc[]) categoryNames.toArray(new String JavaDoc[0]);
72     }
73
74     /**
75      * Sets the names of categories this feature belongs to.
76      * Throws a runtime exception if this object is marked read-only.
77      *
78      * @param categoryNames an array of category names
79      * @since 2.0
80      */

81     public void setCategoryNames(String JavaDoc[] categoryNames) {
82         assertIsWriteable();
83         if (categoryNames == null)
84             this.categoryNames = null;
85         else
86             this.categoryNames = new ArrayList JavaDoc(Arrays.asList(categoryNames));
87     }
88
89     /**
90      * Adds the name of a category this feature belongs to.
91      * Throws a runtime exception if this object is marked read-only.
92      *
93      * @param categoryName category name
94      * @since 2.0
95      */

96     public void addCategoryName(String JavaDoc categoryName) {
97         assertIsWriteable();
98         if (this.categoryNames == null)
99             this.categoryNames = new ArrayList JavaDoc();
100         if (!this.categoryNames.contains(categoryName))
101             this.categoryNames.add(categoryName);
102     }
103     
104     /**
105      * Removes the name of a categorys this feature belongs to.
106      * Throws a runtime exception if this object is marked read-only.
107      *
108      * @param categoryName category name
109      * @since 2.0
110      */

111     public void removeCategoryName(String JavaDoc categoryName) {
112         assertIsWriteable();
113         if (this.categoryNames != null)
114             this.categoryNames.remove(categoryName);
115     }
116 }
117
Popular Tags