blob: b5bfe6630d277682226d408dad0da3375bd05f2e [file] [log] [blame]
package org.eclipse.update.core.model;
/*
* (c) Copyright IBM Corp. 2000, 2002.
* All Rights Reserved.
*/
import java.net.MalformedURLException;
import java.net.URL;
import java.util.*;
import org.eclipse.update.core.IFeatureReference;
import org.eclipse.update.core.ISite;
/**
* An object which represents a feature reference.
* <p>
* This class may be instantiated, or further subclassed.
* </p>
* @since 2.0
*/
public class FeatureReferenceModel extends ModelObject {
private boolean broken= false;
private String type;
private String urlString;
private URL url;
private URLEntryModel updateURL;
private SiteMapModel site;
private List /* of String*/ categoryNames;
/**
* Creates an uninitialized model object.
*
* @since 2.0
*/
public FeatureReferenceModel() {
super();
}
/**
*
* @since 2.0
*/
public boolean equals(Object object) {
if (!(object instanceof IFeatureReference))
return false;
if (getURL()==null) return false;
FeatureReferenceModel f = (FeatureReferenceModel) object;
return (getURL().equals(f.getURL()));
}
/**
* @since 2.0
*/
public String getType() {
return type;
}
/**
* @since 2.0
*/
public SiteMapModel getSiteModel() {
return site;
}
/**
* @since 2.0
*/
public String getURLString() {
return urlString;
}
/**
* Returns the resolved URL for the feature reference.
*
* @return url, or <code>null</code>
* @since 2.0
*/
public URL getURL() {
return url;
}
/**
* @since 2.0
*/
public String[] getCategoryNames() {
if (categoryNames == null)
return new String[0];
return (String[]) categoryNames.toArray(new String[0]);
}
/**
* @since 2.0
*/
public void setType(String type) {
assertIsWriteable();
this.type = type;
}
/**
* @since 2.0
*/
public void setSiteModel(SiteMapModel site) {
assertIsWriteable();
this.site = site;
}
/**
* @since 2.0
*/
public void setURLString(String urlString) {
assertIsWriteable();
this.urlString = urlString;
this.url = null;
}
/**
* @since 2.0
*/
public void setCategoryNames(String[] categoryNames) {
assertIsWriteable();
if (categoryNames == null)
this.categoryNames = null;
else
this.categoryNames = new ArrayList(Arrays.asList(categoryNames));
}
/**
* @since 2.0
*/
public void addCategoryName(String categoryName) {
assertIsWriteable();
if (this.categoryNames == null)
this.categoryNames = new ArrayList();
if (!this.categoryNames.contains(categoryName))
this.categoryNames.add(categoryName);
}
/**
* @since 2.0
*/
public void removeCategoryName(String categoryName) {
assertIsWriteable();
if (this.categoryNames != null)
this.categoryNames.remove(categoryName);
}
/**
* @since 2.0
*/
public void resolve(URL base, ResourceBundle bundle) throws MalformedURLException {
// resolve local elements
url = resolveURL(base, bundle,urlString);
}
/**
* returns true if the Feature is not accessible at this time.
* @return Returns a boolean
*/
public boolean isBroken() {
return broken;
}
/**
* Sets the broken.
* @param broken The broken to set
*/
public void setBroken(boolean broken) {
this.broken = broken;
}
/**
* Gets the updateURL. This is the update URL for the Feature.
* This is used when the feature cannot be accessed.
* @return Returns a URLEntryModel
*/
public URLEntryModel getUpdateURL() {
return updateURL;
}
/**
* Sets the updateURL.
* @param updateURL The updateURL to set
*/
public void setUpdateURL(URLEntryModel updateURL) {
this.updateURL = updateURL;
}
}