KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > runtime > model > PluginModelObject


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.core.runtime.model;
12
13 import org.eclipse.core.runtime.Assert;
14
15 /**
16  * An object which has the general characteristics of all elements
17  * in a plug-in manifest.
18  * <p>
19  * This class may be subclassed.
20  * </p>
21  * @deprecated In Eclipse 3.0 the runtime was refactored and all
22  * non-essential elements removed. This class provides facilities primarily intended
23  * for tooling. As such it has been removed and no directly substitutable API provided.
24  */

25
26 public abstract class PluginModelObject {
27
28     // DTD properties (included in plug-in manifest)
29
private String JavaDoc name = null;
30
31     // transient properties (not included in plug-in manifest)
32
private int flags = 0;
33     // the last bit is a read-only flag
34
// IMPORTANT: One bit in the "flags" integer is used to store the
35
// read-only flag and the other bits are used to store an integer value
36
// which can be from -1 to (2**31) - 1. To help with the bit masking, the integer
37
// value stored in "flags" is (value + 1). This means that a "flags" value
38
// of 0 will NOT be marked as read-only and will return -1 for the start line value.
39
static final int M_READ_ONLY = 0x80000000;
40
41     /**
42      * Checks that this model object is writeable. A runtime exception
43      * is thrown if it is not.
44      */

45     protected void assertIsWriteable() {
46         Assert.isTrue(!isReadOnly(), "Model is read-only"); //$NON-NLS-1$
47
}
48
49     /**
50      * Returns the name of this element.
51      *
52      * @return the name of this element or <code>null</code>
53      */

54     public String JavaDoc getName() {
55         return name;
56     }
57
58     /**
59      * Return the line number for the start tag for this plug-in object. This
60      * is the line number of the element declaration from the plug-in manifest file.
61      *
62      * @return the line number of the start tag for this object
63      */

64     public int getStartLine() {
65         return (flags & ~M_READ_ONLY) - 1;
66     }
67
68     /**
69      * Returns whether or not this model object is read-only.
70      *
71      * @return <code>true</code> if this model object is read-only,
72      * <code>false</code> otherwise
73      * @see #markReadOnly()
74      */

75     public boolean isReadOnly() {
76         return (flags & M_READ_ONLY) == M_READ_ONLY;
77     }
78
79     /**
80      * Sets this model object and all of its descendents to be read-only.
81      * Subclasses may extend this implementation.
82      *
83      * @see #isReadOnly()
84      */

85     public void markReadOnly() {
86         flags |= M_READ_ONLY;
87     }
88
89     /**
90      * Optimization to replace a non-localized key with its localized value. Avoids having
91      * to access resource bundles for further lookups.
92      *
93      * @param value the localized name of this model object
94      */

95     public void setLocalizedName(String JavaDoc value) {
96         name = value;
97     }
98
99     /**
100      * Sets the name of this element.
101      *
102      * @param value the new name of this element. May be <code>null</code>.
103      */

104     public void setName(String JavaDoc value) {
105         assertIsWriteable();
106         name = value;
107     }
108
109     /**
110      * Set the line number for the start tag for this plug-in object. This is the
111      * line number for the element declaration from the plug-in manifest file.
112      * This value can only be set once, subsequent calls to this method will be
113      * ignored.
114      *
115      * @param lineNumber the line number of this object's declaration in the file
116      */

117     public void setStartLine(int lineNumber) {
118         if (getStartLine() == -1)
119             flags = (lineNumber + 1) | (flags & M_READ_ONLY);
120     }
121
122     /**
123      * Return a string representation of this object. This value is not to be relied
124      * on and can change at any time. To be used for debugging purposes only.
125      *
126      * @see java.lang.Object#toString()
127      */

128     public String JavaDoc toString() {
129         return this.getClass() + "(" + getName() + ")"; //$NON-NLS-1$ //$NON-NLS-2$
130
}
131 }
132
Popular Tags