KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > core > text > plugin > PluginAttribute


1 /*******************************************************************************
2  * Copyright (c) 2000, 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 package org.eclipse.pde.internal.core.text.plugin;
12
13 import java.io.PrintWriter JavaDoc;
14
15 import org.eclipse.core.runtime.CoreException;
16 import org.eclipse.pde.core.plugin.IPluginAttribute;
17 import org.eclipse.pde.core.plugin.ISharedPluginModel;
18 import org.eclipse.pde.internal.core.ischema.ISchema;
19 import org.eclipse.pde.internal.core.text.IDocumentAttribute;
20 import org.eclipse.pde.internal.core.text.IDocumentNode;
21
22 public class PluginAttribute extends PluginObjectNode implements
23         IPluginAttribute, IDocumentAttribute {
24     
25     private static final long serialVersionUID = 1L;
26
27     private transient IDocumentNode fEnclosingElement;
28     private transient int fNameOffset = -1;
29     private transient int fNameLength = -1;
30     private transient int fValueOffset = -1;
31     private transient int fValueLength = -1;
32
33     private String JavaDoc fValue;
34     
35     /* (non-Javadoc)
36      * @see org.eclipse.pde.core.plugin.IPluginAttribute#getValue()
37      */

38     public String JavaDoc getValue() {
39         return fValue;
40     }
41     /* (non-Javadoc)
42      * @see org.eclipse.pde.core.plugin.IPluginAttribute#setValue(java.lang.String)
43      */

44     public void setValue(String JavaDoc value) throws CoreException {
45         fValue = value;
46     }
47     /* (non-Javadoc)
48      * @see org.eclipse.pde.internal.ui.model.IDocumentAttribute#setEnclosingElement(org.eclipse.pde.internal.ui.model.IDocumentNode)
49      */

50     public void setEnclosingElement(IDocumentNode node) {
51         fEnclosingElement = node;
52     }
53     /* (non-Javadoc)
54      * @see org.eclipse.pde.internal.ui.model.IDocumentAttribute#getEnclosingElement()
55      */

56     public IDocumentNode getEnclosingElement() {
57         return fEnclosingElement;
58     }
59     /* (non-Javadoc)
60      * @see org.eclipse.pde.internal.ui.model.IDocumentAttribute#setNameOffset(int)
61      */

62     public void setNameOffset(int offset) {
63         fNameOffset = offset;
64     }
65     /* (non-Javadoc)
66      * @see org.eclipse.pde.internal.ui.model.IDocumentAttribute#getNameOffset()
67      */

68     public int getNameOffset() {
69         return fNameOffset;
70     }
71     /* (non-Javadoc)
72      * @see org.eclipse.pde.internal.ui.model.IDocumentAttribute#setNameLength(int)
73      */

74     public void setNameLength(int length) {
75         fNameLength = length;
76     }
77     /* (non-Javadoc)
78      * @see org.eclipse.pde.internal.ui.model.IDocumentAttribute#getNameLength()
79      */

80     public int getNameLength() {
81         return fNameLength;
82     }
83     /* (non-Javadoc)
84      * @see org.eclipse.pde.internal.ui.model.IDocumentAttribute#setValueOffset(int)
85      */

86     public void setValueOffset(int offset) {
87         fValueOffset = offset;
88     }
89     /* (non-Javadoc)
90      * @see org.eclipse.pde.internal.ui.model.IDocumentAttribute#getValueOffset()
91      */

92     public int getValueOffset() {
93         return fValueOffset;
94     }
95     /* (non-Javadoc)
96      * @see org.eclipse.pde.internal.ui.model.IDocumentAttribute#setValueLength(int)
97      */

98     public void setValueLength(int length) {
99         fValueLength = length;
100     }
101     /* (non-Javadoc)
102      * @see org.eclipse.pde.internal.ui.model.IDocumentAttribute#getValueLength()
103      */

104     public int getValueLength() {
105         return fValueLength;
106     }
107     /* (non-Javadoc)
108      * @see org.eclipse.pde.internal.ui.model.IDocumentAttribute#getAttributeName()
109      */

110     public String JavaDoc getAttributeName() {
111         return getName();
112     }
113     /* (non-Javadoc)
114      * @see org.eclipse.pde.internal.ui.model.IDocumentAttribute#getAttributeValue()
115      */

116     public String JavaDoc getAttributeValue() {
117         return getValue();
118     }
119     
120     /* (non-Javadoc)
121      * @see org.eclipse.pde.internal.ui.model.IDocumentAttribute#write()
122      */

123     public String JavaDoc write() {
124         return getName() + "=\"" + getWritableString(getValue()) + "\""; //$NON-NLS-1$ //$NON-NLS-2$
125
}
126
127     public String JavaDoc getWritableString(String JavaDoc source) {
128         return super
129                 .getWritableString(source)
130                 .replaceAll("\\r", "
") //$NON-NLS-1$ //$NON-NLS-2$
131
.replaceAll("\\n", "
"); //$NON-NLS-1$ //$NON-NLS-2$
132
}
133     
134     public void setAttributeName(String JavaDoc name) throws CoreException {
135         setName(name);
136     }
137     
138     public void setAttributeValue(String JavaDoc value) throws CoreException {
139         setValue(value);
140     }
141     
142     /* (non-Javadoc)
143      * @see org.eclipse.pde.internal.core.text.IDocumentAttribute#reconnectAttribute()
144      */

145     public void reconnect(ISharedPluginModel model, ISchema schema, IDocumentNode parent) {
146         super.reconnect(model, schema, parent);
147         // Transient field: Enclosing element
148
// Essentially is the parent (an element)
149
// Note: Parent field from plugin document node parent seems to be
150
// null; but, we will set it any ways
151
fEnclosingElement = parent;
152         // Transient field: Name Length
153
fNameLength = -1;
154         // Transient field: Name Offset
155
fNameOffset = -1;
156         // Transient field: Value Length
157
fValueLength = -1;
158         // Transient field: Value Offset
159
fValueOffset = -1;
160     }
161     
162     /* (non-Javadoc)
163      * @see org.eclipse.pde.internal.core.text.plugin.PluginObjectNode#write(java.lang.String, java.io.PrintWriter)
164      */

165     public void write(String JavaDoc indent, PrintWriter JavaDoc writer) {
166         // Used for text transfers for copy, cut, paste operations
167
// Although attributes cannot be copied directly
168
writer.write(write());
169     }
170     
171 }
172
Popular Tags