KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > update > internal > configurator > PluginEntry


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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.internal.configurator;
12
13 import org.eclipse.osgi.util.NLS;
14
15
16 /**
17  */

18 public class PluginEntry {
19
20     private String JavaDoc pluginId;
21     private String JavaDoc pluginVersion;
22     private boolean isFragment = false;
23     private VersionedIdentifier versionId;
24     private String JavaDoc url;
25     
26     public PluginEntry() {
27         super();
28     }
29
30     /**
31      * @return url relative to the site location: plugins/org.eclipse.foo/plugin.xml
32      * Note: to do: we should probably only use plugins/org.eclipse.foo/ in the future
33      */

34     public String JavaDoc getURL() {
35         return url;
36     }
37     
38     /**
39      * url is relative to the site
40      */

41     public void setURL(String JavaDoc url) {
42         this.url = url;
43     }
44
45     /**
46      * Returns the plug-in identifier for this entry.
47      *
48      * @return the plug-in identifier, or <code>null</code>
49      */

50     public String JavaDoc getPluginIdentifier() {
51         return pluginId;
52     }
53
54     /**
55      * Returns the plug-in version for this entry.
56      *
57      * @return the plug-in version, or <code>null</code>
58      */

59     public String JavaDoc getPluginVersion() {
60         return pluginVersion;
61     }
62
63     /**
64      * Indicates whether the entry describes a full plug-in, or
65      * a plug-in fragment.
66      *
67      * @return <code>true</code> if the entry is a plug-in fragment,
68      * <code>false</code> if the entry is a plug-in
69      */

70     public boolean isFragment() {
71         return isFragment;
72     }
73
74     /**
75      * Sets the entry plug-in identifier.
76      * Throws a runtime exception if this object is marked read-only.
77      *
78      * @param pluginId the entry identifier.
79      */

80     void setPluginIdentifier(String JavaDoc pluginId) {
81         this.pluginId = pluginId;
82     }
83
84     /**
85      * Sets the entry plug-in version.
86      * Throws a runtime exception if this object is marked read-only.
87      *
88      * @param pluginVersion the entry version.
89      */

90     void setPluginVersion(String JavaDoc pluginVersion) {
91         this.pluginVersion = pluginVersion;
92     }
93
94     /**
95      * Indicates whether this entry represents a fragment or plug-in.
96      * Throws a runtime exception if this object is marked read-only.
97      *
98      * @param isFragment fragment setting
99      */

100     public void isFragment(boolean isFragment) {
101         this.isFragment = isFragment;
102     }
103
104     /**
105      * @see Object#toString()
106      */

107     public String JavaDoc toString() {
108         String JavaDoc msg = (getPluginIdentifier()!=null)?getPluginIdentifier().toString():""; //$NON-NLS-1$
109
msg += getPluginVersion()!=null?" "+getPluginVersion().toString():""; //$NON-NLS-1$ //$NON-NLS-2$
110
msg += isFragment()?" fragment":" plugin"; //$NON-NLS-1$ //$NON-NLS-2$
111
return msg;
112     }
113
114
115     /**
116      * Returns the identifier of this plugin entry
117      */

118     public VersionedIdentifier getVersionedIdentifier() {
119         if (versionId != null)
120             return versionId;
121
122         String JavaDoc id = getPluginIdentifier();
123         String JavaDoc ver = getPluginVersion();
124         if (id != null && ver != null) {
125             try {
126                 versionId = new VersionedIdentifier(id, ver);
127                 return versionId;
128             } catch (Exception JavaDoc e) {
129                 Utils.log(NLS.bind(Messages.PluginEntry_versionError, (new String JavaDoc[] { id, ver })));
130             }
131         }
132
133         versionId = new VersionedIdentifier("",null); //$NON-NLS-1$
134
return versionId;
135     }
136
137     /**
138      * Sets the identifier of this plugin entry.
139      *
140      */

141     void setVersionedIdentifier(VersionedIdentifier identifier) {
142         setPluginIdentifier(identifier.getIdentifier());
143         setPluginVersion(identifier.getVersion().toString());
144     }
145
146     /**
147      * Compares two plugin entries for equality
148      *
149      * @param object plugin entry object to compare with
150      * @return <code>true</code> if the two entries are equal,
151      * <code>false</code> otherwise
152      */

153     public boolean equals(Object JavaDoc object) {
154         if (!(object instanceof PluginEntry))
155             return false;
156         PluginEntry e = (PluginEntry) object;
157         return getVersionedIdentifier().equals(e.getVersionedIdentifier());
158     }
159     
160     /* (non-Javadoc)
161      * @see java.lang.Object#hashCode()
162      */

163     public int hashCode() {
164         return getVersionedIdentifier().hashCode();
165     }
166 }
167
Popular Tags