KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > core > schema > SchemaObject


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.schema;
12
13 import java.io.Serializable JavaDoc;
14
15 import org.eclipse.core.runtime.PlatformObject;
16 import org.eclipse.pde.internal.core.ischema.ISchema;
17 import org.eclipse.pde.internal.core.ischema.ISchemaObject;
18 import org.eclipse.pde.internal.core.util.PDEXMLHelper;
19
20 public abstract class SchemaObject extends PlatformObject implements
21         ISchemaObject, Serializable JavaDoc {
22     protected String JavaDoc fName;
23
24     private String JavaDoc fDescription;
25
26     transient private ISchemaObject fParent;
27
28     public SchemaObject(ISchemaObject parent, String JavaDoc name) {
29         fParent = parent;
30         fName = name;
31     }
32
33     public String JavaDoc getDescription() {
34         return fDescription;
35     }
36
37     public java.lang.String JavaDoc getName() {
38         return fName;
39     }
40
41     public ISchemaObject getParent() {
42         return fParent;
43     }
44
45     public void setParent(ISchemaObject parent) {
46         fParent = parent;
47     }
48
49     public ISchema getSchema() {
50         ISchemaObject object = this;
51
52         while (object.getParent() != null) {
53             object = object.getParent();
54         }
55         return (ISchema) object;
56     }
57
58     public String JavaDoc getWritableDescription() {
59         String JavaDoc lineDelimiter = System.getProperty("line.separator"); //$NON-NLS-1$
60
String JavaDoc description = PDEXMLHelper.getWritableString(getDescription());
61         String JavaDoc platformDescription = description.replaceAll(
62                 "\\r\\n|\\r|\\n", lineDelimiter); //$NON-NLS-1$
63

64         return platformDescription;
65     }
66
67     public void setDescription(String JavaDoc newDescription) {
68         String JavaDoc oldValue = fDescription;
69         fDescription = newDescription;
70         getSchema().fireModelObjectChanged(this, P_DESCRIPTION, oldValue,
71                 fDescription);
72     }
73
74     public void setName(String JavaDoc newName) {
75         String JavaDoc oldValue = fName;
76         fName = newName;
77         getSchema().fireModelObjectChanged(this, P_NAME, oldValue, fName);
78     }
79
80     public String JavaDoc toString() {
81         if (fName != null)
82             return fName;
83         return super.toString();
84     }
85
86 }
87
Popular Tags