blob: 9a38d5379b01a0082ee8ac6a9a5d312a0d46b9f7 [file] [log] [blame]
nitind958d79a2004-11-23 19:23:00 +00001/*******************************************************************************
amywu923ee602007-04-10 18:32:07 +00002 * Copyright (c) 2004, 2005 IBM Corporation and others.
nitind958d79a2004-11-23 19:23:00 +00003 * 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
amywu923ee602007-04-10 18:32:07 +00007 *
nitind958d79a2004-11-23 19:23:00 +00008 * Contributors:
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
david_williams56777022005-04-11 06:21:55 +000011package org.eclipse.wst.html.core.internal.contentmodel;
nitind958d79a2004-11-23 19:23:00 +000012
13
14
15/**
16 * Factory of ComplexTypeDefinition.
17 */
18final class ComplexTypeDefinitionFactory {
19
20 private static ComplexTypeDefinitionFactory instance = null;
21 private java.util.Hashtable definitions = null;
22 // constants for complex type name
23 /** for ADDRESS. */
24 public final static String CTYPE_ADDRESS = "CTYPE_ADDRESS";//$NON-NLS-1$
25 /** CDATA content. No ComplexTypeDefinition instance shuld be created. */
26 public final static String CTYPE_CDATA = "CTYPE_CDATA";//$NON-NLS-1$
27 /** col group content. COL* */
28 public final static String CTYPE_COLUMN_GROUP = "CTYPE_COLUMN_GROUP";//$NON-NLS-1$
29 /** for DL. */
30 public final static String CTYPE_DEFINITION_LIST = "CTYPE_DEFINITION_LIST";//$NON-NLS-1$
31 /** for EMBED. */
32 public final static String CTYPE_EMBED = "CTYPE_EMBED";//$NON-NLS-1$
33 /** empty content. No ComplexTypeDefinition instance should be created. */
34 public final static String CTYPE_EMPTY = "CTYPE_EMPTY";//$NON-NLS-1$
35 /** for FIELDSET. */
36 public final static String CTYPE_FIELDSET = "CTYPE_FIELDSET";//$NON-NLS-1$
37 /** for FRAMESET. */
38 public final static String CTYPE_FRAMESET = "CTYPE_FRAMESET";//$NON-NLS-1$
39 /** flow content. (%flow;)* */
40 public final static String CTYPE_FLOW_CONTAINER = "CTYPE_FLOW_CONTAINER";//$NON-NLS-1$
41 /** html content. HEAD, (FRAMESET|BODY) */
42 public final static String CTYPE_HTML = "CTYPE_HTML";//$NON-NLS-1$
43 /** head content. TITLE & ISINDEX? & BASE? */
44 public final static String CTYPE_HEAD = "CTYPE_HEAD";//$NON-NLS-1$
45 /** inline content. (%inline;)* */
46 public final static String CTYPE_INLINE_CONTAINER = "CTYPE_INLINE_CONTAINER";//$NON-NLS-1$
47 /** list item container. (LI)+ */
48 public final static String CTYPE_LI_CONTAINER = "CTYPE_LI_CONTAINER";//$NON-NLS-1$
49 /** for MAP. */
50 public final static String CTYPE_MAP = "CTYPE_MAP";//$NON-NLS-1$
51 /** noframes content. */
52 public final static String CTYPE_NOFRAMES_CONTENT = "CTYPE_NOFRAMES_CONTENT";//$NON-NLS-1$
53 /** for OPTGROUP. */
54 public final static String CTYPE_OPTION_CONTAINER = "CTYPE_OPTION_CONTAINER";//$NON-NLS-1$
55 /** param container. For OBJECT/APPLET. */
56 public final static String CTYPE_PARAM_CONTAINER = "CTYPE_PARAM_CONTAINER";//$NON-NLS-1$
57 /** PCDATA content. No ComplexTypeDefinition instance shuld be created. */
58 public final static String CTYPE_PCDATA = "CTYPE_PCDATA";//$NON-NLS-1$
59 /** for SELECT. */
60 public final static String CTYPE_SELECT = "CTYPE_SELECT";//$NON-NLS-1$
61 /** table content. CAPTION?, (COL*|COLGROUP*), THEAD?, TFOOT?, TBODY+ */
62 public final static String CTYPE_TABLE = "CTYPE_TABLE";//$NON-NLS-1$
63 /** table cell contaier. (TH|TD)+ */
64 public final static String CTYPE_TCELL_CONTAINER = "CTYPE_TCELL_CONTAINER";//$NON-NLS-1$
65 /** table record container. (TR)+ */
66 public final static String CTYPE_TR_CONTAINER = "CTYPE_TR_CONTAINER";//$NON-NLS-1$
67
68 /**
69 * ComplexTypeDefinitionFactory constructor comment.
70 */
71 private ComplexTypeDefinitionFactory() {
72 super();
73 definitions = new java.util.Hashtable();
74 }
75
76 /**
77 * Factory method for ComplexTypeDefinition.
78 * Each instance created in this method must be registered into
79 * the map with its name.
nitind958d79a2004-11-23 19:23:00 +000080 * @param definitionName java.lang.String
81 * @param elementCollection ElementCollection
82 */
83 public ComplexTypeDefinition createTypeDefinition(String definitionName, ElementCollection elementCollection) {
84 if (definitions.containsKey(definitionName)) {
85 return (ComplexTypeDefinition) definitions.get(definitionName);
86 }
87
88 ComplexTypeDefinition def = null;
89 if (definitionName == CTYPE_ADDRESS) {
90 def = new CtdAddress(elementCollection);
91
92 }
93 else if (definitionName == CTYPE_COLUMN_GROUP) {
94 def = new CtdColumnGroup(elementCollection);
95
96 }
97 else if (definitionName == CTYPE_DEFINITION_LIST) {
98 def = new CtdDl(elementCollection);
99
100 }
101 else if (definitionName == CTYPE_EMBED) {
102 def = new CtdEmbed(elementCollection);
103
104 }
105 else if (definitionName == CTYPE_FIELDSET) {
106 def = new CtdFieldset(elementCollection);
107
108 }
109 else if (definitionName == CTYPE_FLOW_CONTAINER) {
110 def = new CtdFlowContainer(elementCollection);
111
112 }
113 else if (definitionName == CTYPE_FRAMESET) {
114 def = new CtdFrameset(elementCollection);
115
116 }
117 else if (definitionName == CTYPE_HEAD) {
118 def = new CtdHead(elementCollection);
119
120 }
121 else if (definitionName == CTYPE_HTML) {
122 def = new CtdHtml(elementCollection);
123
124 }
125 else if (definitionName == CTYPE_INLINE_CONTAINER) {
126 def = new CtdInlineContainer(elementCollection);
127
128 }
129 else if (definitionName == CTYPE_LI_CONTAINER) {
130 def = new CtdLiContainer(elementCollection);
131
132 }
133 else if (definitionName == CTYPE_MAP) {
134 def = new CtdMap(elementCollection);
135
136 }
137 else if (definitionName == CTYPE_NOFRAMES_CONTENT) {
138 def = new CtdNoframesContent(elementCollection);
139
140 }
141 else if (definitionName == CTYPE_OPTION_CONTAINER) {
142 def = new CtdOptionContainer(elementCollection);
143
144 }
145 else if (definitionName == CTYPE_PARAM_CONTAINER) {
146 def = new CtdParamContainer(elementCollection);
147
148 }
149 else if (definitionName == CTYPE_SELECT) {
150 def = new CtdSelect(elementCollection);
151
152 }
153 else if (definitionName == CTYPE_TABLE) {
154 def = new CtdTable(elementCollection);
155
156 }
157 else if (definitionName == CTYPE_TCELL_CONTAINER) {
158 def = new CtdTableCellContainer(elementCollection);
159
160 }
161 else if (definitionName == CTYPE_TR_CONTAINER) {
162 def = new CtdTrContainer(elementCollection);
163
164 }
165 else {
166 def = null;
167 }
168 if (def == null)
169 return null; // fail to create.
170 definitions.put(definitionName, def);
171 return def;
172 }
173
174 /**
david_williams47a33d22005-05-28 01:26:57 +0000175 * For singleton.
nitind958d79a2004-11-23 19:23:00 +0000176 */
177 public synchronized static ComplexTypeDefinitionFactory getInstance() {
178 if (instance != null)
179 return instance;
180 instance = new ComplexTypeDefinitionFactory();
181 return instance;
182 }
amywu923ee602007-04-10 18:32:07 +0000183}