KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > core > jdom > DOMFactory


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.jdt.core.jdom;
12
13 import org.eclipse.jdt.internal.core.jdom.*;
14
15 /**
16  * Standard implementation of <code>IDOMFactory</code>, and the only means
17  * of creating JDOMs and document fragments.
18  * <p>
19  * This class may be instantiated; it is not intended to be subclassed.
20  * </p>
21  * @deprecated The JDOM was made obsolete by the addition in 2.0 of the more
22  * powerful, fine-grained DOM/AST API found in the
23  * org.eclipse.jdt.core.dom package.
24  */

25 public class DOMFactory implements IDOMFactory {
26     String JavaDoc lineSeparator;
27 /**
28  * Creates a new DOM factory.
29  */

30 public DOMFactory() {
31     // constructor is explicitly API
32
this.lineSeparator = org.eclipse.jdt.internal.core.util.Util.getLineSeparator(null, null/*take the workspace line separator as no project is available*/);
33 }
34 /* (non-Javadoc)
35  * Method declared on IDOMFactory.
36  */

37 public IDOMCompilationUnit createCompilationUnit() {
38     return (new DOMBuilder()).createCompilationUnit();
39 }
40 /* (non-Javadoc)
41  * Method declared on IDOMFactory.
42  */

43 public IDOMCompilationUnit createCompilationUnit(char[] sourceCode, String JavaDoc name) {
44     if(sourceCode == null) {
45         return null;
46     }
47     return (new SimpleDOMBuilder()).createCompilationUnit(sourceCode, name.toCharArray());
48 }
49 /* (non-Javadoc)
50  * Method declared on IDOMFactory.
51  */

52 public IDOMCompilationUnit createCompilationUnit(String JavaDoc sourceCode, String JavaDoc name) {
53     if(sourceCode == null) {
54         return null;
55     }
56     return (new SimpleDOMBuilder()).createCompilationUnit(sourceCode.toCharArray(), name.toCharArray());
57 }
58 /* (non-Javadoc)
59  * Method declared on IDOMFactory.
60  */

61 public IDOMField createField() {
62     return createField("Object aField;"+ this.lineSeparator); //$NON-NLS-1$
63
}
64 /* (non-Javadoc)
65  * Method declared on IDOMFactory.
66  */

67 public IDOMField createField(String JavaDoc sourceCode) {
68     if(sourceCode == null) {
69         return null;
70     }
71     return (new DOMBuilder()).createField(sourceCode.toCharArray());
72 }
73 /* (non-Javadoc)
74  * Method declared on IDOMFactory.
75  */

76 public IDOMImport createImport() {
77     return (new DOMBuilder()).createImport();
78 }
79 /* (non-Javadoc)
80  * Method declared on IDOMFactory.
81  */

82 public IDOMImport createImport(String JavaDoc sourceCode) {
83     if(sourceCode == null) {
84         return null;
85     }
86     return (new DOMBuilder()).createImport(sourceCode.toCharArray());
87 }
88 /* (non-Javadoc)
89  * Method declared on IDOMFactory.
90  */

91 public IDOMInitializer createInitializer() {
92     return createInitializer("static {}"+ this.lineSeparator); //$NON-NLS-1$
93
}
94 /* (non-Javadoc)
95  * Method declared on IDOMFactory.
96  */

97 public IDOMInitializer createInitializer(String JavaDoc sourceCode) {
98     if(sourceCode == null) {
99         return null;
100     }
101     return (new DOMBuilder()).createInitializer(sourceCode.toCharArray());
102 }
103 /* (non-Javadoc)
104  * Method declared on IDOMFactory.
105  */

106 public IDOMMethod createMethod() {
107     return createMethod("public void newMethod() {"+ this.lineSeparator+"}"+ this.lineSeparator); //$NON-NLS-2$ //$NON-NLS-1$
108
}
109 /* (non-Javadoc)
110  * Method declared on IDOMFactory.
111  */

112 public IDOMMethod createMethod(String JavaDoc sourceCode) {
113     if(sourceCode == null) {
114         return null;
115     }
116     return (new DOMBuilder()).createMethod(sourceCode.toCharArray());
117 }
118 /* (non-Javadoc)
119  * Method declared on IDOMFactory.
120  */

121 public IDOMPackage createPackage() {
122     return (new DOMBuilder()).createPackage();
123 }
124 /* (non-Javadoc)
125  * Method declared on IDOMFactory.
126  */

127 public IDOMPackage createPackage(String JavaDoc sourceCode) {
128     if(sourceCode == null) {
129         return null;
130     }
131     return (new DOMBuilder()).createPackage(sourceCode.toCharArray());
132 }
133 /* (non-Javadoc)
134  * Method declared on IDOMFactory.
135  */

136 public IDOMType createType() {
137     return createType("public class AClass {"+ this.lineSeparator +"}"+ this.lineSeparator); //$NON-NLS-2$ //$NON-NLS-1$
138
}
139 /* (non-Javadoc)
140  * Method declared on IDOMFactory.
141  */

142 public IDOMType createClass() {
143     return createType("public class AClass {"+ this.lineSeparator +"}"+ this.lineSeparator); //$NON-NLS-2$ //$NON-NLS-1$
144
}
145 /* (non-Javadoc)
146  * Method declared on IDOMFactory.
147  */

148 public IDOMType createInterface() {
149     return createType("public interface AnInterface {"+ this.lineSeparator +"}"+ this.lineSeparator); //$NON-NLS-2$ //$NON-NLS-1$
150
}
151 /* (non-Javadoc)
152  * Method declared on IDOMFactory.
153  */

154 public IDOMType createType(String JavaDoc sourceCode) {
155     if(sourceCode == null) {
156         return null;
157     }
158     return (new DOMBuilder()).createType(sourceCode.toCharArray());
159 }
160 }
161
Popular Tags