KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-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.*;
14
15 import org.eclipse.core.runtime.*;
16 import org.eclipse.pde.core.*;
17 import org.eclipse.pde.internal.core.*;
18 import org.eclipse.pde.internal.core.isite.*;
19 import org.w3c.dom.*;
20
21 public abstract class SiteBuildObject
22     extends PlatformObject
23     implements ISiteBuildObject {
24     transient ISiteBuildModel model;
25     transient ISiteBuildObject parent;
26     boolean inTheModel;
27
28     void setInTheModel(boolean value) {
29         inTheModel = value;
30     }
31
32     public boolean isInTheModel() {
33         return inTheModel;
34     }
35
36     protected void ensureModelEditable() throws CoreException {
37         if (!model.isEditable()) {
38             throwCoreException(PDECore.getResourceString("SiteBuildObject.readOnlyException")); //$NON-NLS-1$
39
}
40     }
41     protected void firePropertyChanged(
42         String JavaDoc property,
43         Object JavaDoc oldValue,
44         Object JavaDoc newValue) {
45         firePropertyChanged(this, property, oldValue, newValue);
46     }
47     protected void firePropertyChanged(
48         ISiteBuildObject object,
49         String JavaDoc property,
50         Object JavaDoc oldValue,
51         Object JavaDoc newValue) {
52         if (model.isEditable() && model instanceof IModelChangeProvider) {
53             IModelChangeProvider provider = (IModelChangeProvider) model;
54             provider.fireModelObjectChanged(object, property, oldValue, newValue);
55         }
56     }
57     protected void fireStructureChanged(ISiteBuildObject child, int changeType) {
58         fireStructureChanged(new ISiteBuildObject[] { child }, changeType);
59     }
60     protected void fireStructureChanged(
61         ISiteBuildObject[] children,
62         int changeType) {
63         ISiteBuildModel model = getModel();
64         if (model.isEditable() && model instanceof IModelChangeProvider) {
65             IModelChangeProvider provider = (IModelChangeProvider) model;
66             provider.fireModelChanged(new ModelChangedEvent(provider, changeType, children, null));
67         }
68     }
69     public ISiteBuild getSiteBuild() {
70         return model.getSiteBuild();
71     }
72
73     public ISiteBuildModel getModel() {
74         return model;
75     }
76     
77     String JavaDoc getNodeAttribute(Node node, String JavaDoc name) {
78         NamedNodeMap atts = node.getAttributes();
79         Node attribute = null;
80         if (atts != null)
81            attribute = atts.getNamedItem(name);
82         if (attribute != null)
83             return attribute.getNodeValue();
84         return null;
85     }
86
87     int getIntegerAttribute(Node node, String JavaDoc name) {
88         String JavaDoc value = getNodeAttribute(node, name);
89         if (value != null) {
90             try {
91                 return Integer.parseInt(value);
92             } catch (NumberFormatException JavaDoc e) {
93             }
94         }
95         return 0;
96     }
97     
98     boolean getBooleanAttribute(Node node, String JavaDoc name) {
99         String JavaDoc value = getNodeAttribute(node, name);
100         if (value != null) {
101             return value.equalsIgnoreCase("true"); //$NON-NLS-1$
102
}
103         return false;
104     }
105     
106     public ISiteBuildObject getParent() {
107         return parent;
108     }
109
110     protected void reset() {
111     }
112
113     protected void throwCoreException(String JavaDoc message) throws CoreException {
114         Status status =
115             new Status(IStatus.ERROR, PDECore.getPluginId(), IStatus.OK, message, null);
116         throw new CoreException(status);
117     }
118
119     public static String JavaDoc getWritableString(String JavaDoc source) {
120         if (source == null)
121             return ""; //$NON-NLS-1$
122
StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
123         for (int i = 0; i < source.length(); i++) {
124             char c = source.charAt(i);
125             switch (c) {
126                 case '&' :
127                     buf.append("&amp;"); //$NON-NLS-1$
128
break;
129                 case '<' :
130                     buf.append("&lt;"); //$NON-NLS-1$
131
break;
132                 case '>' :
133                     buf.append("&gt;"); //$NON-NLS-1$
134
break;
135                 case '\'' :
136                     buf.append("&apos;"); //$NON-NLS-1$
137
break;
138                 case '\"' :
139                     buf.append("&quot;"); //$NON-NLS-1$
140
break;
141                 default :
142                     buf.append(c);
143                     break;
144             }
145         }
146         return buf.toString();
147     }
148
149     public void restoreProperty(String JavaDoc name, Object JavaDoc oldValue, Object JavaDoc newValue)
150         throws CoreException {
151     }
152
153     public void write(String JavaDoc indent, PrintWriter writer) {
154     }
155
156     public void setModel(ISiteBuildModel model) {
157         this.model = model;
158     }
159     
160     public void setParent(ISiteBuildObject parent) {
161         this.parent = parent;
162     }
163 }
164
Popular Tags