KickJava   Java API By Example, From Geeks To Geeks.

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


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.pde.internal.core.schema;
12
13 import java.io.PrintWriter JavaDoc;
14
15 import org.eclipse.pde.core.IWritable;
16 import org.eclipse.pde.internal.core.ischema.ISchema;
17 import org.eclipse.pde.internal.core.ischema.ISchemaRestriction;
18 import org.eclipse.pde.internal.core.ischema.ISchemaSimpleType;
19
20 public class SchemaSimpleType
21     extends SchemaType
22     implements ISchemaSimpleType, IWritable {
23
24     private static final long serialVersionUID = 1L;
25     private ISchemaRestriction restriction;
26     public static final String JavaDoc P_RESTRICTION = "restriction"; //$NON-NLS-1$
27

28     public SchemaSimpleType(ISchema schema, String JavaDoc typeName) {
29         super(schema, typeName);
30     }
31     public SchemaSimpleType(ISchemaSimpleType type) {
32         super(type.getSchema(), type.getName());
33         ISchemaRestriction rest = type.getRestriction();
34         if (rest != null) {
35             if (rest instanceof ChoiceRestriction) {
36                 restriction = new ChoiceRestriction((ChoiceRestriction) rest);
37                 restriction.setBaseType(this);
38             }
39         }
40     }
41     public ISchemaRestriction getRestriction() {
42         return restriction;
43     }
44
45     public void setSchema(ISchema schema) {
46         super.setSchema(schema);
47         if (restriction != null)
48             restriction.setParent(schema);
49     }
50
51     public void setRestriction(ISchemaRestriction restriction) {
52         Object JavaDoc oldValue = this.restriction;
53         this.restriction = restriction;
54         if (restriction != null)
55             restriction.setBaseType(this);
56         getSchema().fireModelObjectChanged(
57             this,
58             P_RESTRICTION,
59             oldValue,
60             restriction);
61     }
62     public void write(String JavaDoc indent, PrintWriter JavaDoc writer) {
63         writer.println(indent + "<simpleType>"); //$NON-NLS-1$
64
if (restriction != null) {
65             restriction.write(indent + Schema.INDENT, writer);
66         }
67         writer.println(indent + "</simpleType>"); //$NON-NLS-1$
68
}
69 }
70
Popular Tags