01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 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.PrintWriter;
13:
14: import org.eclipse.pde.internal.core.ischema.IDocumentSection;
15: import org.eclipse.pde.internal.core.ischema.ISchemaObject;
16:
17: public class DocumentSection extends SchemaObject implements
18: IDocumentSection, Comparable {
19:
20: private static final long serialVersionUID = 1L;
21:
22: public static final String[] DOC_SECTIONS = {
23: IDocumentSection.SINCE, IDocumentSection.EXAMPLES,
24: IDocumentSection.API_INFO, IDocumentSection.IMPLEMENTATION,
25: IDocumentSection.COPYRIGHT };
26:
27: private String sectionId;
28:
29: public DocumentSection(ISchemaObject parent, String sectionId,
30: String name) {
31: super (parent, name);
32: this .sectionId = sectionId;
33: }
34:
35: public String getSectionId() {
36: return sectionId;
37: }
38:
39: public void write(String indent, PrintWriter writer) {
40: String description = getWritableDescription();
41: if (description == null || description.equals("")) //$NON-NLS-1$
42: return;
43: String indent2 = indent + Schema.INDENT;
44: String indent3 = indent2 + Schema.INDENT;
45: writer.println(indent + "<annotation>"); //$NON-NLS-1$
46: writer.println(indent2 + "<appInfo>"); //$NON-NLS-1$
47: writer.println(indent3
48: + "<meta.section type=\"" + sectionId + "\"/>"); //$NON-NLS-1$ //$NON-NLS-2$
49: writer.println(indent2 + "</appInfo>"); //$NON-NLS-1$
50: writer.println(indent2 + "<documentation>"); //$NON-NLS-1$
51: writer.println(indent3 + description);
52: writer.println(indent2 + "</documentation>"); //$NON-NLS-1$
53: writer.println(indent + "</annotation>"); //$NON-NLS-1$
54: }
55:
56: public boolean equals(Object obj) {
57: if (obj instanceof DocumentSection
58: && ((DocumentSection) obj).getSectionId().equals(
59: sectionId))
60: return true;
61: return false;
62: }
63:
64: public int compareTo(Object arg0) {
65: if (arg0 instanceof DocumentSection) {
66: int otherIndex = getIndex(((DocumentSection) arg0)
67: .getSectionId());
68: int this Index = getIndex(sectionId);
69: if (otherIndex == this Index)
70: return 0;
71: else if (otherIndex == -1)
72: return -1;
73: else
74: return this Index - otherIndex;
75: }
76: return -1;
77: }
78:
79: private int getIndex(String sectionId) {
80: if (sectionId == null)
81: return -1;
82: for (int i = 0; i < DOC_SECTIONS.length; i++) {
83: if (DOC_SECTIONS[i].equals(sectionId))
84: return i;
85: }
86: return -1;
87: }
88: }
|