KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > core > cheatsheet > comp > CompCSParam


1 /*******************************************************************************
2  * Copyright (c) 2006, 2007 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
12 package org.eclipse.pde.internal.core.cheatsheet.comp;
13
14 import java.io.PrintWriter JavaDoc;
15 import java.util.ArrayList JavaDoc;
16 import java.util.List JavaDoc;
17
18 import org.eclipse.pde.internal.core.XMLPrintHandler;
19 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSModel;
20 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSObject;
21 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSParam;
22 import org.eclipse.pde.internal.core.util.PDETextHelper;
23 import org.w3c.dom.Element JavaDoc;
24 import org.w3c.dom.Text JavaDoc;
25
26 /**
27  * CompCSParam
28  *
29  */

30 public class CompCSParam extends CompCSObject implements ICompCSParam {
31
32     private String JavaDoc fFieldName;
33     
34     private String JavaDoc fFieldValue;
35     
36     /**
37      *
38      */

39     private static final long serialVersionUID = 1L;
40
41     /**
42      * @param model
43      * @param parent
44      */

45     public CompCSParam(ICompCSModel model, ICompCSObject parent) {
46         super(model, parent);
47         reset();
48     }
49
50     /* (non-Javadoc)
51      * @see org.eclipse.pde.internal.core.cheatsheet.comp.CompCSObject#getChildren()
52      */

53     public List JavaDoc getChildren() {
54         return new ArrayList JavaDoc();
55     }
56
57     /* (non-Javadoc)
58      * @see org.eclipse.pde.internal.core.cheatsheet.comp.CompCSObject#getElement()
59      */

60     public String JavaDoc getElement() {
61         return ELEMENT_PARAM;
62     }
63
64     /* (non-Javadoc)
65      * @see org.eclipse.pde.internal.core.cheatsheet.comp.CompCSObject#getName()
66      */

67     public String JavaDoc getName() {
68         return fFieldName;
69     }
70
71     /* (non-Javadoc)
72      * @see org.eclipse.pde.internal.core.cheatsheet.comp.CompCSObject#getType()
73      */

74     public int getType() {
75         return TYPE_PARAM;
76     }
77
78     /* (non-Javadoc)
79      * @see org.eclipse.pde.internal.core.cheatsheet.comp.CompCSObject#parseAttributes(org.w3c.dom.Element)
80      */

81     protected void parseAttributes(Element JavaDoc element) {
82         // Process name attribute
83
// Trim leading and trailing whitespace
84
fFieldName = element.getAttribute(ATTRIBUTE_NAME).trim();
85         // Process value attribute
86
// Trim leading and trailing whitespace
87
fFieldValue = element.getAttribute(ATTRIBUTE_VALUE).trim();
88     }
89
90     /* (non-Javadoc)
91      * @see org.eclipse.pde.internal.core.cheatsheet.comp.CompCSObject#parseElement(org.w3c.dom.Element)
92      */

93     protected void parseElement(Element JavaDoc element) {
94         // NO-OP
95
}
96
97     /* (non-Javadoc)
98      * @see org.eclipse.pde.internal.core.cheatsheet.comp.CompCSObject#reset()
99      */

100     public void reset() {
101         fFieldName = null;
102         fFieldValue = null;
103     }
104
105     /* (non-Javadoc)
106      * @see org.eclipse.pde.internal.core.cheatsheet.comp.CompCSObject#writeAttributes(java.lang.StringBuffer)
107      */

108     protected void writeAttributes(StringBuffer JavaDoc buffer) {
109         // Print name attribute
110
if ((fFieldName != null) &&
111                 (fFieldName.length() > 0)) {
112             // No trim required
113
// No encode required
114
buffer.append(XMLPrintHandler.wrapAttribute(
115                     ATTRIBUTE_NAME, fFieldName));
116         }
117         // Print value attribute
118
if ((fFieldValue != null) &&
119                 (fFieldValue.length() > 0)) {
120             // Trim leading and trailing whitespace
121
// Encode characters
122
buffer.append(XMLPrintHandler.wrapAttribute(
123                     ATTRIBUTE_VALUE,
124                     PDETextHelper.translateWriteText(
125                             fFieldValue.trim(), DEFAULT_SUBSTITUTE_CHARS)));
126         }
127     }
128
129     /* (non-Javadoc)
130      * @see org.eclipse.pde.internal.core.cheatsheet.comp.CompCSObject#writeElements(java.lang.String, java.io.PrintWriter)
131      */

132     protected void writeElements(String JavaDoc indent, PrintWriter JavaDoc writer) {
133         // NO-OP
134
}
135
136     /* (non-Javadoc)
137      * @see org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSParam#getFieldName()
138      */

139     public String JavaDoc getFieldName() {
140         return fFieldName;
141     }
142
143     /* (non-Javadoc)
144      * @see org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSParam#getFieldValue()
145      */

146     public String JavaDoc getFieldValue() {
147         return fFieldValue;
148     }
149
150     /* (non-Javadoc)
151      * @see org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSParam#setFieldName(java.lang.String)
152      */

153     public void setFieldName(String JavaDoc name) {
154         String JavaDoc old = fFieldName;
155         fFieldName = name;
156         if (isEditable()) {
157             firePropertyChanged(ATTRIBUTE_NAME, old, fFieldName);
158         }
159     }
160
161     /* (non-Javadoc)
162      * @see org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSParam#setFieldValue(java.lang.String)
163      */

164     public void setFieldValue(String JavaDoc value) {
165         String JavaDoc old = fFieldValue;
166         fFieldValue = value;
167         if (isEditable()) {
168             firePropertyChanged(ATTRIBUTE_VALUE, old, fFieldValue);
169         }
170     }
171
172     /* (non-Javadoc)
173      * @see org.eclipse.pde.internal.core.cheatsheet.comp.CompCSObject#parseText(org.w3c.dom.Text)
174      */

175     protected void parseText(Text JavaDoc text) {
176         // NO-OP
177
}
178
179 }
180
Popular Tags