KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > core > feature > FeatureInfo


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.pde.internal.core.feature;
12
13 import java.io.PrintWriter JavaDoc;
14
15 import org.eclipse.core.runtime.CoreException;
16 import org.eclipse.pde.internal.core.PDECoreMessages;
17 import org.eclipse.pde.internal.core.ifeature.IFeature;
18 import org.eclipse.pde.internal.core.ifeature.IFeatureInfo;
19 import org.w3c.dom.Node JavaDoc;
20
21 public class FeatureInfo extends FeatureObject implements IFeatureInfo {
22     private static final long serialVersionUID = 1L;
23     private String JavaDoc url;
24     private String JavaDoc description;
25     private int index;
26
27     public FeatureInfo(int index) {
28         this.index = index;
29     }
30
31     public int getIndex() {
32         return index;
33     }
34
35     private String JavaDoc getTag() {
36         return IFeature.INFO_TAGS[index];
37     }
38
39     /*
40      * @see IFeatureInfo#getURL()
41      */

42     public String JavaDoc getURL() {
43         return url;
44     }
45
46     /*
47      * @see IFeatureInfo#getDescription()
48      */

49     public String JavaDoc getDescription() {
50         return description;
51     }
52
53     /*
54      * @see IFeatureInfo#setURL(URL)
55      */

56     public void setURL(String JavaDoc url) throws CoreException {
57         ensureModelEditable();
58         Object JavaDoc oldValue = this.url;
59         this.url = url;
60         firePropertyChanged(P_URL, oldValue, url);
61     }
62
63     public void restoreProperty(String JavaDoc name, Object JavaDoc oldValue, Object JavaDoc newValue)
64         throws CoreException {
65         if (name.equals(P_DESC)) {
66             setDescription(newValue != null ? newValue.toString() : null);
67         } else if (name.equals(P_URL)) {
68             setURL(newValue != null ? newValue.toString() : null);
69         } else
70             super.restoreProperty(name, oldValue, newValue);
71     }
72
73     /*
74      * @see IFeatureInfo#setDescription(String)
75      */

76     public void setDescription(String JavaDoc description) throws CoreException {
77         ensureModelEditable();
78         Object JavaDoc oldValue = this.description;
79         this.description = description;
80         firePropertyChanged(P_DESC, oldValue, description);
81     }
82     protected void parse(Node JavaDoc node) {
83         url = getNodeAttribute(node, "url"); //$NON-NLS-1$
84
Node JavaDoc firstChild = node.getFirstChild();
85         if (firstChild!=null)
86             description = getNormalizedText(firstChild.getNodeValue());
87     }
88
89     public void write(String JavaDoc indent, PrintWriter JavaDoc writer) {
90         String JavaDoc indent2 = indent + Feature.INDENT;
91         String JavaDoc desc = description!=null?getWritableString(description.trim()):null;
92         writer.println();
93         writer.print(indent + "<" + getTag()); //$NON-NLS-1$
94
if (url != null) {
95             writer.print(" url=\"" + getWritableString(url) + "\""); //$NON-NLS-1$ //$NON-NLS-2$
96
}
97         writer.println(">"); //$NON-NLS-1$
98
if (desc!=null) writer.println(indent2 + desc);
99         writer.println(indent + "</" + getTag() + ">"); //$NON-NLS-1$ //$NON-NLS-2$
100
}
101
102     public boolean isEmpty() {
103         if (url != null)
104             return false;
105         String JavaDoc desc = description != null ? description.trim() : null;
106         if (desc != null && desc.length() > 0)
107             return false;
108         return true;
109     }
110
111     public String JavaDoc toString() {
112         switch (index) {
113             case IFeature.INFO_DESCRIPTION :
114                 return PDECoreMessages.FeatureInfo_description;
115             case IFeature.INFO_LICENSE :
116                 return PDECoreMessages.FeatureInfo_license;
117             case IFeature.INFO_COPYRIGHT :
118                 return PDECoreMessages.FeatureInfo_copyright;
119         }
120         return super.toString();
121     }
122 }
123
Popular Tags