01: /*******************************************************************************
02: * Copyright (c) 2000, 2007 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.pde.internal.core.schema;
11:
12: import java.io.Serializable;
13:
14: import org.eclipse.core.runtime.PlatformObject;
15: import org.eclipse.pde.internal.core.ischema.ISchema;
16: import org.eclipse.pde.internal.core.ischema.ISchemaObject;
17: import org.eclipse.pde.internal.core.util.PDEXMLHelper;
18:
19: public abstract class SchemaObject extends PlatformObject implements
20: ISchemaObject, Serializable {
21: protected String fName;
22:
23: private String fDescription;
24:
25: transient private ISchemaObject fParent;
26:
27: public SchemaObject(ISchemaObject parent, String name) {
28: fParent = parent;
29: fName = name;
30: }
31:
32: public String getDescription() {
33: return fDescription;
34: }
35:
36: public java.lang.String getName() {
37: return fName;
38: }
39:
40: public ISchemaObject getParent() {
41: return fParent;
42: }
43:
44: public void setParent(ISchemaObject parent) {
45: fParent = parent;
46: }
47:
48: public ISchema getSchema() {
49: ISchemaObject object = this ;
50:
51: while (object.getParent() != null) {
52: object = object.getParent();
53: }
54: return (ISchema) object;
55: }
56:
57: public String getWritableDescription() {
58: String lineDelimiter = System.getProperty("line.separator"); //$NON-NLS-1$
59: String description = PDEXMLHelper
60: .getWritableString(getDescription());
61: String platformDescription = description.replaceAll(
62: "\\r\\n|\\r|\\n", lineDelimiter); //$NON-NLS-1$
63:
64: return platformDescription;
65: }
66:
67: public void setDescription(String newDescription) {
68: String oldValue = fDescription;
69: fDescription = newDescription;
70: getSchema().fireModelObjectChanged(this , P_DESCRIPTION,
71: oldValue, fDescription);
72: }
73:
74: public void setName(String newName) {
75: String oldValue = fName;
76: fName = newName;
77: getSchema().fireModelObjectChanged(this , P_NAME, oldValue,
78: fName);
79: }
80:
81: public String toString() {
82: if (fName != null)
83: return fName;
84: return super.toString();
85: }
86:
87: }
|