KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > core > site > SiteCategoryDefinition


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.site;
12
13 import java.io.PrintWriter JavaDoc;
14
15 import org.eclipse.core.runtime.CoreException;
16 import org.eclipse.pde.internal.core.isite.ISiteCategoryDefinition;
17 import org.eclipse.pde.internal.core.isite.ISiteDescription;
18 import org.w3c.dom.Node JavaDoc;
19 import org.w3c.dom.NodeList JavaDoc;
20
21 public class SiteCategoryDefinition
22     extends SiteObject
23     implements ISiteCategoryDefinition {
24
25     private static final long serialVersionUID = 1L;
26     private String JavaDoc name;
27     private ISiteDescription description;
28
29     /**
30      * @see org.eclipse.pde.internal.core.isite.ISiteCategoryDefinition#getName()
31      */

32     public String JavaDoc getName() {
33         return name;
34     }
35     
36     public boolean isValid() {
37         return name!=null && getLabel()!=null;
38     }
39
40     /**
41      * @see org.eclipse.pde.internal.core.isite.ISiteCategoryDefinition#setName(java.lang.String)
42      */

43     public void setName(String JavaDoc name) throws CoreException {
44         ensureModelEditable();
45         Object JavaDoc oldValue = this.name;
46         this.name = name;
47         firePropertyChanged(P_NAME, oldValue, name);
48     }
49
50     /**
51      * @see org.eclipse.pde.internal.core.isite.ISiteCategoryDefinition#getDescription()
52      */

53     public ISiteDescription getDescription() {
54         return description;
55     }
56
57     /**
58      * @see org.eclipse.pde.internal.core.isite.ISiteCategoryDefinition#setDescription(org.eclipse.pde.internal.core.isite.ISiteDescription)
59      */

60     public void setDescription(ISiteDescription description)
61         throws CoreException {
62         ensureModelEditable();
63         Object JavaDoc oldValue = this.description;
64         this.description = description;
65         firePropertyChanged(P_DESCRIPTION, oldValue, description);
66     }
67
68     protected void reset() {
69         super.reset();
70         name = null;
71         description = null;
72     }
73
74     protected void parse(Node JavaDoc node) {
75         super.parse(node);
76         name = getNodeAttribute(node, "name"); //$NON-NLS-1$
77
NodeList JavaDoc children = node.getChildNodes();
78         for (int i = 0; i < children.getLength(); i++) {
79             Node JavaDoc child = children.item(i);
80             if (child.getNodeType() == Node.ELEMENT_NODE
81                 && child.getNodeName().equalsIgnoreCase("description")) { //$NON-NLS-1$
82
description = getModel().getFactory().createDescription(this);
83                 ((SiteDescription) description).parse(child);
84                 ((SiteDescription)description).setInTheModel(true);
85                 break;
86             }
87         }
88     }
89     public void restoreProperty(String JavaDoc name, Object JavaDoc oldValue, Object JavaDoc newValue)
90         throws CoreException {
91         if (name.equals(P_NAME)) {
92             setName(newValue != null ? newValue.toString() : null);
93         } else if (
94             name.equals(P_DESCRIPTION)
95                 && newValue instanceof ISiteDescription) {
96             setDescription((ISiteDescription) newValue);
97         } else
98             super.restoreProperty(name, oldValue, newValue);
99     }
100     public void write(String JavaDoc indent, PrintWriter JavaDoc writer) {
101         writer.print(indent);
102         writer.print("<category-def"); //$NON-NLS-1$
103
if (name != null)
104             writer.print(" name=\"" + SiteObject.getWritableString(name) + "\""); //$NON-NLS-1$ //$NON-NLS-2$
105
if (label != null)
106             writer.print(" label=\"" + SiteObject.getWritableString(label) + "\""); //$NON-NLS-1$ //$NON-NLS-2$
107
if (description != null) {
108             writer.println(">"); //$NON-NLS-1$
109
description.write(indent + Site.INDENT, writer);
110             writer.println(indent + "</category-def>"); //$NON-NLS-1$
111
} else
112             writer.println("/>"); //$NON-NLS-1$
113
}
114 }
115
Popular Tags