KickJava   Java API By Example, From Geeks To Geeks.

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


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 import java.net.MalformedURLException JavaDoc;
15 import java.net.URL JavaDoc;
16
17 import org.eclipse.core.runtime.CoreException;
18 import org.eclipse.pde.internal.core.ifeature.IFeatureURLElement;
19 import org.w3c.dom.Node JavaDoc;
20
21 public class FeatureURLElement
22     extends FeatureObject
23     implements IFeatureURLElement {
24     private static final long serialVersionUID = 1L;
25     private int fElementType;
26     private int fSiteType = UPDATE_SITE;
27     private URL JavaDoc fUrl;
28
29     public FeatureURLElement(int elementType) {
30         this.fElementType = elementType;
31     }
32     public FeatureURLElement(int elementType, URL JavaDoc url) {
33         this.fElementType = elementType;
34         this.fUrl = url;
35     }
36     public int getElementType() {
37         return fElementType;
38     }
39     public URL JavaDoc getURL() {
40         return fUrl;
41     }
42     public int getSiteType() {
43         return fSiteType;
44     }
45     protected void parse(Node JavaDoc node) {
46         super.parse(node);
47         String JavaDoc urlName = getNodeAttribute(node, "url"); //$NON-NLS-1$
48
try {
49             if(urlName!=null)
50                 fUrl = new URL JavaDoc(urlName);
51         } catch (MalformedURLException JavaDoc e) {
52         }
53         String JavaDoc typeName = getNodeAttribute(node, "type"); //$NON-NLS-1$
54
if (typeName != null && typeName.equals("web")) //$NON-NLS-1$
55
fSiteType = WEB_SITE;
56     }
57
58     public void setURL(URL JavaDoc url) throws CoreException {
59         ensureModelEditable();
60         Object JavaDoc oldValue = this.fUrl;
61         this.fUrl = url;
62         firePropertyChanged(this, P_URL, oldValue, url);
63     }
64
65     public void setSiteType(int type) throws CoreException {
66         ensureModelEditable();
67         Integer JavaDoc oldValue = new Integer JavaDoc(this.fSiteType);
68         this.fSiteType = type;
69         firePropertyChanged(this, P_URL, oldValue, new Integer JavaDoc(type));
70     }
71
72     public void restoreProperty(String JavaDoc name, Object JavaDoc oldValue, Object JavaDoc newValue)
73         throws CoreException {
74         if (name.equals(P_URL)) {
75             setURL((URL JavaDoc) newValue);
76         } else if (name.equals(P_SITE_TYPE)) {
77             setSiteType(((Integer JavaDoc) newValue).intValue());
78         } else
79             super.restoreProperty(name, oldValue, newValue);
80     }
81
82     public String JavaDoc toString() {
83         if (label != null)
84             return label;
85         if (fUrl != null)
86             return fUrl.toString();
87         return super.toString();
88     }
89     public void write(String JavaDoc indent, PrintWriter JavaDoc writer) {
90         String JavaDoc tag = null;
91         switch (fElementType) {
92             case UPDATE :
93                 tag = "update"; //$NON-NLS-1$
94
break;
95             case DISCOVERY :
96                 tag = "discovery"; //$NON-NLS-1$
97
break;
98         }
99         if (tag == null)
100             return;
101         writer.print(indent + "<" + tag); //$NON-NLS-1$
102
if (label != null && label.length()>0) {
103             writer.print(" label=\"" + getWritableString(label) + "\""); //$NON-NLS-1$ //$NON-NLS-2$
104
}
105         if (fUrl != null) {
106             writer.print(" url=\"" + getWritableString(fUrl.toString()) + "\""); //$NON-NLS-1$ //$NON-NLS-2$
107
}
108         if (fSiteType == WEB_SITE) {
109             writer.print(" type=\"web\""); //$NON-NLS-1$
110
}
111         writer.println("/>"); //$NON-NLS-1$
112
}
113 }
114
Popular Tags