~ubuntu-branches/ubuntu/quantal/netbeans/quantal

« back to all changes in this revision

Viewing changes to xml/xsl/api/src/org/netbeans/modules/xslt/model/impl/XslComponentFactoryImpl.java

  • Committer: Bazaar Package Importer
  • Author(s): Marek Slama
  • Date: 2008-01-29 14:11:22 UTC
  • Revision ID: james.westby@ubuntu.com-20080129141122-fnzjbo11ntghxfu7
Tags: upstream-6.0.1
ImportĀ upstreamĀ versionĀ 6.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 
3
 *
 
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
 
5
 *
 
6
 * The contents of this file are subject to the terms of either the GNU
 
7
 * General Public License Version 2 only ("GPL") or the Common
 
8
 * Development and Distribution License("CDDL") (collectively, the
 
9
 * "License"). You may not use this file except in compliance with the
 
10
 * License. You can obtain a copy of the License at
 
11
 * http://www.netbeans.org/cddl-gplv2.html
 
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
 
13
 * specific language governing permissions and limitations under the
 
14
 * License.  When distributing the software, include this License Header
 
15
 * Notice in each file and include the License file at
 
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
 
17
 * particular file as subject to the "Classpath" exception as provided
 
18
 * by Sun in the GPL Version 2 section of the License file that
 
19
 * accompanied this code. If applicable, add the following below the
 
20
 * License Header, with the fields enclosed by brackets [] replaced by
 
21
 * your own identifying information:
 
22
 * "Portions Copyrighted [year] [name of copyright owner]"
 
23
 *
 
24
 * Contributor(s):
 
25
 *
 
26
 * The Original Software is NetBeans. The Initial Developer of the Original
 
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
 
28
 * Microsystems, Inc. All Rights Reserved.
 
29
 *
 
30
 * If you wish your version of this file to be governed by only the CDDL
 
31
 * or only the GPL Version 2, indicate your decision by adding
 
32
 * "[Contributor] elects to include this software in this distribution
 
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
 
34
 * single choice of license, a recipient has the option to distribute
 
35
 * your version of this file under either the CDDL, the GPL Version 2 or
 
36
 * to extend the choice of license to its licensees as provided above.
 
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
 
38
 * Version 2 license, then the option applies only if the new code is
 
39
 * made subject to such option by the copyright holder.
 
40
 */
 
41
 
 
42
package org.netbeans.modules.xslt.model.impl;
 
43
 
 
44
import org.netbeans.modules.xslt.model.ApplyTemplates;
 
45
import org.netbeans.modules.xslt.model.Attribute;
 
46
import org.netbeans.modules.xslt.model.AttributeSet;
 
47
import org.netbeans.modules.xslt.model.CallTemplate;
 
48
import org.netbeans.modules.xslt.model.Choose;
 
49
import org.netbeans.modules.xslt.model.Copy;
 
50
import org.netbeans.modules.xslt.model.CopyOf;
 
51
import org.netbeans.modules.xslt.model.Document;
 
52
import org.netbeans.modules.xslt.model.Element;
 
53
import org.netbeans.modules.xslt.model.ForEach;
 
54
import org.netbeans.modules.xslt.model.If;
 
55
import org.netbeans.modules.xslt.model.Import;
 
56
import org.netbeans.modules.xslt.model.Include;
 
57
import org.netbeans.modules.xslt.model.Key;
 
58
import org.netbeans.modules.xslt.model.LiteralResultElement;
 
59
import org.netbeans.modules.xslt.model.Namespace;
 
60
import org.netbeans.modules.xslt.model.Number;
 
61
import org.netbeans.modules.xslt.model.Otherwise;
 
62
import org.netbeans.modules.xslt.model.Output;
 
63
import org.netbeans.modules.xslt.model.Param;
 
64
import org.netbeans.modules.xslt.model.Sequence;
 
65
import org.netbeans.modules.xslt.model.Sort;
 
66
import org.netbeans.modules.xslt.model.Stylesheet;
 
67
import org.netbeans.modules.xslt.model.Template;
 
68
import org.netbeans.modules.xslt.model.Text;
 
69
import org.netbeans.modules.xslt.model.ValueOf;
 
70
import org.netbeans.modules.xslt.model.Variable;
 
71
import org.netbeans.modules.xslt.model.When;
 
72
import org.netbeans.modules.xslt.model.XslComponent;
 
73
import org.netbeans.modules.xslt.model.XslComponentFactory;
 
74
 
 
75
 
 
76
/**
 
77
 * @author ads
 
78
 *
 
79
 */
 
80
class XslComponentFactoryImpl implements XslComponentFactory {
 
81
 
 
82
    XslComponentFactoryImpl( XslModelImpl model ) {
 
83
        myModel = model;
 
84
        myBuilder = new ThreadLocal<XslComponentsBuildVisitor>();
 
85
    }
 
86
 
 
87
    /* (non-Javadoc)
 
88
     * @see org.netbeans.modules.xslt.model.XslComponentFactory#createApplyTemplates()
 
89
     */
 
90
    public ApplyTemplates createApplyTemplates() {
 
91
        return new ApplyTemplatesImpl( getModel() );
 
92
    }
 
93
 
 
94
    /* (non-Javadoc)
 
95
     * @see org.netbeans.modules.xslt.model.XslComponentFactory#createAttribute()
 
96
     */
 
97
    public Attribute createAttribute() {
 
98
        return new AttributeImpl( getModel() );
 
99
    }
 
100
 
 
101
    /* (non-Javadoc)
 
102
     * @see org.netbeans.modules.xslt.model.XslComponentFactory#createAttributeSet()
 
103
     */
 
104
    public AttributeSet createAttributeSet() {
 
105
        return new AttributeSetImpl( getModel() );
 
106
    }
 
107
 
 
108
    /* (non-Javadoc)
 
109
     * @see org.netbeans.modules.xslt.model.XslComponentFactory#createCallTemplate()
 
110
     */
 
111
    public CallTemplate createCallTemplate() {
 
112
        return new CallTemplateImpl( getModel() );
 
113
    }
 
114
 
 
115
    /* (non-Javadoc)
 
116
     * @see org.netbeans.modules.xslt.model.XslComponentFactory#createChoose()
 
117
     */
 
118
    public Choose createChoose() {
 
119
        return new ChooseImpl( getModel() );
 
120
    }
 
121
 
 
122
    /* (non-Javadoc)
 
123
     * @see org.netbeans.modules.xslt.model.XslComponentFactory#createCopy()
 
124
     */
 
125
    public Copy createCopy() {
 
126
        return new CopyImpl( getModel() );
 
127
    }
 
128
 
 
129
    /* (non-Javadoc)
 
130
     * @see org.netbeans.modules.xslt.model.XslComponentFactory#createCopyOf()
 
131
     */
 
132
    public CopyOf createCopyOf() {
 
133
        return new CopyOfImpl( getModel() );
 
134
    }
 
135
 
 
136
    /* (non-Javadoc)
 
137
     * @see org.netbeans.modules.xslt.model.XslComponentFactory#createDocument()
 
138
     */
 
139
    public Document createDocument() {
 
140
        return new DocumentImpl( getModel() );
 
141
    }
 
142
 
 
143
    /* (non-Javadoc)
 
144
     * @see org.netbeans.modules.xslt.model.XslComponentFactory#createElement()
 
145
     */
 
146
    public Element createElement() {
 
147
        return new ElementImpl( getModel() );
 
148
    }
 
149
 
 
150
    /* (non-Javadoc)
 
151
     * @see org.netbeans.modules.xslt.model.XslComponentFactory#createForEach()
 
152
     */
 
153
    public ForEach createForEach() {
 
154
        return new ForEachImpl( getModel() );
 
155
    }
 
156
 
 
157
    /* (non-Javadoc)
 
158
     * @see org.netbeans.modules.xslt.model.XslComponentFactory#createIf()
 
159
     */
 
160
    public If createIf() {
 
161
        return new IfImpl( getModel() );
 
162
    }
 
163
 
 
164
    /* (non-Javadoc)
 
165
     * @see org.netbeans.modules.xslt.model.XslComponentFactory#createInclude()
 
166
     */
 
167
    public Include createInclude() {
 
168
        return new IncludeImpl( getModel() );
 
169
    }
 
170
 
 
171
    /* (non-Javadoc)
 
172
     * @see org.netbeans.modules.xslt.model.XslComponentFactory#createKey()
 
173
     */
 
174
    public Key createKey() {
 
175
        return new KeyImpl( getModel() );
 
176
    }
 
177
 
 
178
    /* (non-Javadoc)
 
179
     * @see org.netbeans.modules.xslt.model.XslComponentFactory#createLiteralResultElement()
 
180
     */
 
181
    public LiteralResultElement createLiteralResultElement( String name ,
 
182
            String namespaceUri ) 
 
183
    {
 
184
        org.w3c.dom.Element element = getModel().getDocument().
 
185
            createElementNS( namespaceUri, name );
 
186
        return new LiteralResultElementImpl( getModel() , element );
 
187
    }
 
188
 
 
189
    /* (non-Javadoc)
 
190
     * @see org.netbeans.modules.xslt.model.XslComponentFactory#createNamespace()
 
191
     */
 
192
    public Namespace createNamespace() {
 
193
        return new NamespaceImpl( getModel() );
 
194
    }
 
195
 
 
196
    /* (non-Javadoc)
 
197
     * @see org.netbeans.modules.xslt.model.XslComponentFactory#createNumber()
 
198
     */
 
199
    public Number createNumber() {
 
200
        return new NumberImpl( getModel() );
 
201
    }
 
202
 
 
203
    /* (non-Javadoc)
 
204
     * @see org.netbeans.modules.xslt.model.XslComponentFactory#createOtherwise()
 
205
     */
 
206
    public Otherwise createOtherwise() {
 
207
        return new OtherwiseImpl( getModel() );
 
208
    }
 
209
 
 
210
    /* (non-Javadoc)
 
211
     * @see org.netbeans.modules.xslt.model.XslComponentFactory#createOutput()
 
212
     */
 
213
    public Output createOutput() {
 
214
        return new OutputImpl( getModel() );
 
215
    }
 
216
 
 
217
    /* (non-Javadoc)
 
218
     * @see org.netbeans.modules.xslt.model.XslComponentFactory#createParam()
 
219
     */
 
220
    public Param createParam() {
 
221
        return new ParamImpl( getModel() );
 
222
    }
 
223
 
 
224
    /* (non-Javadoc)
 
225
     * @see org.netbeans.modules.xslt.model.XslComponentFactory#createSequence()
 
226
     */
 
227
    public Sequence createSequence() {
 
228
        return new SequenceImpl( getModel() );
 
229
    }
 
230
 
 
231
    /* (non-Javadoc)
 
232
     * @see org.netbeans.modules.xslt.model.XslComponentFactory#createSort()
 
233
     */
 
234
    public Sort createSort() {
 
235
        return new SortImpl( getModel() );
 
236
    }
 
237
 
 
238
    /* (non-Javadoc)
 
239
     * @see org.netbeans.modules.xslt.model.XslComponentFactory#createStylesheet()
 
240
     */
 
241
    public Stylesheet createStylesheet() {
 
242
        return new StylesheetImpl( getModel() );
 
243
    }
 
244
 
 
245
    /* (non-Javadoc)
 
246
     * @see org.netbeans.modules.xslt.model.XslComponentFactory#createTemplate()
 
247
     */
 
248
    public Template createTemplate() {
 
249
        return new TemplateImpl( getModel() );
 
250
    }
 
251
 
 
252
    /* (non-Javadoc)
 
253
     * @see org.netbeans.modules.xslt.model.XslComponentFactory#createText()
 
254
     */
 
255
    public Text createText() {
 
256
        return new TextImpl( getModel() );
 
257
    }
 
258
 
 
259
    /* (non-Javadoc)
 
260
     * @see org.netbeans.modules.xslt.model.XslComponentFactory#createValueOf()
 
261
     */
 
262
    public ValueOf createValueOf() {
 
263
        return new ValueOfImpl( getModel() );
 
264
    }
 
265
 
 
266
    /* (non-Javadoc)
 
267
     * @see org.netbeans.modules.xslt.model.XslComponentFactory#createVariable()
 
268
     */
 
269
    public Variable createVariable() {
 
270
        return new VariableImpl( getModel() );
 
271
    }
 
272
 
 
273
    /* (non-Javadoc)
 
274
     * @see org.netbeans.modules.xslt.model.XslComponentFactory#createWhen()
 
275
     */
 
276
    public When createWhen() {
 
277
        return new WhenImpl( getModel() );
 
278
    }
 
279
 
 
280
    /* (non-Javadoc)
 
281
     * @see org.netbeans.modules.xslt.model.XslComponentFactory#createImport()
 
282
     */
 
283
    public Import createImport() {
 
284
        return new ImportImpl( getModel() );
 
285
    }
 
286
    
 
287
    /* (non-Javadoc)
 
288
     * @see org.netbeans.modules.xml.xam.dom.ComponentFactory#create(org.w3c.dom.Element, org.netbeans.modules.xml.xam.dom.DocumentComponent)
 
289
     */
 
290
    public XslComponent create( org.w3c.dom.Element child, XslComponent parent )
 
291
    {
 
292
        XslComponentsBuildVisitor visitor = getBuilder( );
 
293
        return visitor.createSubComponent( parent , child  );
 
294
    }
 
295
    
 
296
    private XslComponentsBuildVisitor getBuilder() {
 
297
        XslComponentsBuildVisitor visitor = myBuilder.get();
 
298
        if ( visitor == null ) {
 
299
            visitor = new XslComponentsBuildVisitor( getModel());
 
300
            myBuilder.set( visitor );
 
301
        }
 
302
        visitor.init();
 
303
        return visitor;
 
304
    }
 
305
    
 
306
    private XslModelImpl getModel() {
 
307
        return myModel;
 
308
    }
 
309
    
 
310
    private XslModelImpl myModel;
 
311
    
 
312
    private ThreadLocal<XslComponentsBuildVisitor> myBuilder;
 
313
 
 
314
}