001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008: *
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019:
020: package org.netbeans.modules.xslt.model.impl;
021:
022: import org.netbeans.modules.xslt.model.ApplyTemplates;
023: import org.netbeans.modules.xslt.model.Attribute;
024: import org.netbeans.modules.xslt.model.AttributeSet;
025: import org.netbeans.modules.xslt.model.CallTemplate;
026: import org.netbeans.modules.xslt.model.Choose;
027: import org.netbeans.modules.xslt.model.Copy;
028: import org.netbeans.modules.xslt.model.CopyOf;
029: import org.netbeans.modules.xslt.model.Document;
030: import org.netbeans.modules.xslt.model.Element;
031: import org.netbeans.modules.xslt.model.ForEach;
032: import org.netbeans.modules.xslt.model.If;
033: import org.netbeans.modules.xslt.model.Import;
034: import org.netbeans.modules.xslt.model.Include;
035: import org.netbeans.modules.xslt.model.Key;
036: import org.netbeans.modules.xslt.model.LiteralResultElement;
037: import org.netbeans.modules.xslt.model.Namespace;
038: import org.netbeans.modules.xslt.model.Number;
039: import org.netbeans.modules.xslt.model.Otherwise;
040: import org.netbeans.modules.xslt.model.Output;
041: import org.netbeans.modules.xslt.model.Param;
042: import org.netbeans.modules.xslt.model.Sequence;
043: import org.netbeans.modules.xslt.model.Sort;
044: import org.netbeans.modules.xslt.model.Stylesheet;
045: import org.netbeans.modules.xslt.model.Template;
046: import org.netbeans.modules.xslt.model.Text;
047: import org.netbeans.modules.xslt.model.ValueOf;
048: import org.netbeans.modules.xslt.model.Variable;
049: import org.netbeans.modules.xslt.model.When;
050: import org.netbeans.modules.xslt.model.XslComponent;
051: import org.netbeans.modules.xslt.model.XslComponentFactory;
052:
053: /**
054: * @author ads
055: *
056: */
057: class XslComponentFactoryImpl implements XslComponentFactory {
058:
059: XslComponentFactoryImpl(XslModelImpl model) {
060: myModel = model;
061: myBuilder = new ThreadLocal<XslComponentsBuildVisitor>();
062: }
063:
064: /* (non-Javadoc)
065: * @see org.netbeans.modules.xslt.model.XslComponentFactory#createApplyTemplates()
066: */
067: public ApplyTemplates createApplyTemplates() {
068: return new ApplyTemplatesImpl(getModel());
069: }
070:
071: /* (non-Javadoc)
072: * @see org.netbeans.modules.xslt.model.XslComponentFactory#createAttribute()
073: */
074: public Attribute createAttribute() {
075: return new AttributeImpl(getModel());
076: }
077:
078: /* (non-Javadoc)
079: * @see org.netbeans.modules.xslt.model.XslComponentFactory#createAttributeSet()
080: */
081: public AttributeSet createAttributeSet() {
082: return new AttributeSetImpl(getModel());
083: }
084:
085: /* (non-Javadoc)
086: * @see org.netbeans.modules.xslt.model.XslComponentFactory#createCallTemplate()
087: */
088: public CallTemplate createCallTemplate() {
089: return new CallTemplateImpl(getModel());
090: }
091:
092: /* (non-Javadoc)
093: * @see org.netbeans.modules.xslt.model.XslComponentFactory#createChoose()
094: */
095: public Choose createChoose() {
096: return new ChooseImpl(getModel());
097: }
098:
099: /* (non-Javadoc)
100: * @see org.netbeans.modules.xslt.model.XslComponentFactory#createCopy()
101: */
102: public Copy createCopy() {
103: return new CopyImpl(getModel());
104: }
105:
106: /* (non-Javadoc)
107: * @see org.netbeans.modules.xslt.model.XslComponentFactory#createCopyOf()
108: */
109: public CopyOf createCopyOf() {
110: return new CopyOfImpl(getModel());
111: }
112:
113: /* (non-Javadoc)
114: * @see org.netbeans.modules.xslt.model.XslComponentFactory#createDocument()
115: */
116: public Document createDocument() {
117: return new DocumentImpl(getModel());
118: }
119:
120: /* (non-Javadoc)
121: * @see org.netbeans.modules.xslt.model.XslComponentFactory#createElement()
122: */
123: public Element createElement() {
124: return new ElementImpl(getModel());
125: }
126:
127: /* (non-Javadoc)
128: * @see org.netbeans.modules.xslt.model.XslComponentFactory#createForEach()
129: */
130: public ForEach createForEach() {
131: return new ForEachImpl(getModel());
132: }
133:
134: /* (non-Javadoc)
135: * @see org.netbeans.modules.xslt.model.XslComponentFactory#createIf()
136: */
137: public If createIf() {
138: return new IfImpl(getModel());
139: }
140:
141: /* (non-Javadoc)
142: * @see org.netbeans.modules.xslt.model.XslComponentFactory#createInclude()
143: */
144: public Include createInclude() {
145: return new IncludeImpl(getModel());
146: }
147:
148: /* (non-Javadoc)
149: * @see org.netbeans.modules.xslt.model.XslComponentFactory#createKey()
150: */
151: public Key createKey() {
152: return new KeyImpl(getModel());
153: }
154:
155: /* (non-Javadoc)
156: * @see org.netbeans.modules.xslt.model.XslComponentFactory#createLiteralResultElement()
157: */
158: public LiteralResultElement createLiteralResultElement(String name,
159: String namespaceUri) {
160: org.w3c.dom.Element element = getModel().getDocument()
161: .createElementNS(namespaceUri, name);
162: return new LiteralResultElementImpl(getModel(), element);
163: }
164:
165: /* (non-Javadoc)
166: * @see org.netbeans.modules.xslt.model.XslComponentFactory#createNamespace()
167: */
168: public Namespace createNamespace() {
169: return new NamespaceImpl(getModel());
170: }
171:
172: /* (non-Javadoc)
173: * @see org.netbeans.modules.xslt.model.XslComponentFactory#createNumber()
174: */
175: public Number createNumber() {
176: return new NumberImpl(getModel());
177: }
178:
179: /* (non-Javadoc)
180: * @see org.netbeans.modules.xslt.model.XslComponentFactory#createOtherwise()
181: */
182: public Otherwise createOtherwise() {
183: return new OtherwiseImpl(getModel());
184: }
185:
186: /* (non-Javadoc)
187: * @see org.netbeans.modules.xslt.model.XslComponentFactory#createOutput()
188: */
189: public Output createOutput() {
190: return new OutputImpl(getModel());
191: }
192:
193: /* (non-Javadoc)
194: * @see org.netbeans.modules.xslt.model.XslComponentFactory#createParam()
195: */
196: public Param createParam() {
197: return new ParamImpl(getModel());
198: }
199:
200: /* (non-Javadoc)
201: * @see org.netbeans.modules.xslt.model.XslComponentFactory#createSequence()
202: */
203: public Sequence createSequence() {
204: return new SequenceImpl(getModel());
205: }
206:
207: /* (non-Javadoc)
208: * @see org.netbeans.modules.xslt.model.XslComponentFactory#createSort()
209: */
210: public Sort createSort() {
211: return new SortImpl(getModel());
212: }
213:
214: /* (non-Javadoc)
215: * @see org.netbeans.modules.xslt.model.XslComponentFactory#createStylesheet()
216: */
217: public Stylesheet createStylesheet() {
218: return new StylesheetImpl(getModel());
219: }
220:
221: /* (non-Javadoc)
222: * @see org.netbeans.modules.xslt.model.XslComponentFactory#createTemplate()
223: */
224: public Template createTemplate() {
225: return new TemplateImpl(getModel());
226: }
227:
228: /* (non-Javadoc)
229: * @see org.netbeans.modules.xslt.model.XslComponentFactory#createText()
230: */
231: public Text createText() {
232: return new TextImpl(getModel());
233: }
234:
235: /* (non-Javadoc)
236: * @see org.netbeans.modules.xslt.model.XslComponentFactory#createValueOf()
237: */
238: public ValueOf createValueOf() {
239: return new ValueOfImpl(getModel());
240: }
241:
242: /* (non-Javadoc)
243: * @see org.netbeans.modules.xslt.model.XslComponentFactory#createVariable()
244: */
245: public Variable createVariable() {
246: return new VariableImpl(getModel());
247: }
248:
249: /* (non-Javadoc)
250: * @see org.netbeans.modules.xslt.model.XslComponentFactory#createWhen()
251: */
252: public When createWhen() {
253: return new WhenImpl(getModel());
254: }
255:
256: /* (non-Javadoc)
257: * @see org.netbeans.modules.xslt.model.XslComponentFactory#createImport()
258: */
259: public Import createImport() {
260: return new ImportImpl(getModel());
261: }
262:
263: /* (non-Javadoc)
264: * @see org.netbeans.modules.xml.xam.dom.ComponentFactory#create(org.w3c.dom.Element, org.netbeans.modules.xml.xam.dom.DocumentComponent)
265: */
266: public XslComponent create(org.w3c.dom.Element child,
267: XslComponent parent) {
268: XslComponentsBuildVisitor visitor = getBuilder();
269: return visitor.createSubComponent(parent, child);
270: }
271:
272: private XslComponentsBuildVisitor getBuilder() {
273: XslComponentsBuildVisitor visitor = myBuilder.get();
274: if (visitor == null) {
275: visitor = new XslComponentsBuildVisitor(getModel());
276: myBuilder.set(visitor);
277: }
278: visitor.init();
279: return visitor;
280: }
281:
282: private XslModelImpl getModel() {
283: return myModel;
284: }
285:
286: private XslModelImpl myModel;
287:
288: private ThreadLocal<XslComponentsBuildVisitor> myBuilder;
289:
290: }
|