KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xslt > model > impl > XslModelImpl


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.xslt.model.impl;
21
22 import java.util.ArrayList JavaDoc;
23 import java.util.List JavaDoc;
24 import java.util.Set JavaDoc;
25
26 import javax.xml.namespace.QName JavaDoc;
27
28 import org.netbeans.modules.xml.xam.ComponentUpdater;
29 import org.netbeans.modules.xml.xam.ModelSource;
30 import org.netbeans.modules.xml.xam.dom.AbstractDocumentModel;
31 import org.netbeans.modules.xml.xam.dom.ChangeInfo;
32 import org.netbeans.modules.xml.xam.dom.DocumentComponent;
33 import org.netbeans.modules.xslt.model.LiteralResultElement;
34 import org.netbeans.modules.xslt.model.SequenceConstructor;
35 import org.netbeans.modules.xslt.model.XslComponent;
36 import org.netbeans.modules.xslt.model.XslModel;
37 import org.w3c.dom.Element JavaDoc;
38 import org.w3c.dom.Node JavaDoc;
39
40
41 /**
42  * @author ads
43  *
44  */

45 class XslModelImpl extends AbstractDocumentModel<XslComponent>
46     implements XslModel
47 {
48
49     XslModelImpl( ModelSource source ) {
50         super(source);
51         myFactory = new XslComponentFactoryImpl( this );
52     }
53
54     /* (non-Javadoc)
55      * @see org.netbeans.modules.xml.xam.dom.AbstractDocumentModel#createRootComponent(org.w3c.dom.Element)
56      */

57     @Override JavaDoc
58     public XslComponent createRootComponent( Element root )
59     {
60         StylesheetImpl stylesheet = (StylesheetImpl)myFactory.create(root, null);
61         if (stylesheet != null) {
62             myRoot = stylesheet;
63         } else {
64             return null;
65         }
66         return getStylesheet();
67     }
68
69     /* (non-Javadoc)
70      * @see org.netbeans.modules.xml.xam.dom.AbstractDocumentModel#getComponentUpdater()
71      */

72     @Override JavaDoc
73     protected ComponentUpdater<XslComponent> getComponentUpdater()
74     {
75         if ( mySyncUpdateVisitor == null ){
76             mySyncUpdateVisitor = new SyncUpdateVisitor();
77         }
78         return mySyncUpdateVisitor;
79     }
80
81     /* (non-Javadoc)
82      * @see org.netbeans.modules.xslt.model.XslModel#getFactory()
83      */

84     public XslComponentFactoryImpl getFactory() {
85         return myFactory;
86     }
87
88     /* (non-Javadoc)
89      * @see org.netbeans.modules.xslt.model.XslModel#getStylesheet()
90      */

91     public StylesheetImpl getStylesheet() {
92         return (StylesheetImpl) getRootComponent();
93     }
94
95     /* (non-Javadoc)
96      * @see org.netbeans.modules.xml.xam.dom.DocumentModel#createComponent(org.netbeans.modules.xml.xam.dom.DocumentComponent, org.w3c.dom.Element)
97      */

98     public XslComponent createComponent( XslComponent parent, Element element ) {
99         return getFactory().create( element , parent);
100     }
101
102     /* (non-Javadoc)
103      * @see org.netbeans.modules.xml.xam.dom.DocumentModel#getRootComponent()
104      */

105     public XslComponent getRootComponent() {
106         return myRoot ;
107     }
108     
109     @Override JavaDoc
110     public Set JavaDoc<QName JavaDoc> getQNames() {
111         return XslElements.allQNames();
112     }
113     
114     public ChangeInfo prepareChangeInfo(List JavaDoc<Node JavaDoc> pathToRoot) {
115         ChangeInfo change = super.prepareChangeInfo(pathToRoot);
116         DocumentComponent parentComponent = findComponent(change.getRootToParentPath());
117         if (parentComponent == null) {
118             return change;
119         }
120         
121         // this are conditions where subject element is Literal element
122
if ( parentComponent instanceof SequenceConstructor &&
123                 !change.isDomainElement() && change.getChangedElement() != null)
124         {
125             prepareLiterlElementChange(change, parentComponent);
126         }
127         else {
128             change.setParentComponent( parentComponent );
129         }
130         return change;
131     }
132
133     private void prepareLiterlElementChange( ChangeInfo change,
134             DocumentComponent parentComponent )
135     {
136         if (change.getOtherNonDomainElementNodes() == null
137                 || change.getOtherNonDomainElementNodes().isEmpty())
138         {
139             // case add or remove literal result element
140
change.setDomainElement(true);
141             change.setParentComponent(null);
142         }
143         else {
144             List JavaDoc<Element> rootToChanged = new ArrayList JavaDoc<Element>(change
145                     .getRootToParentPath());
146             rootToChanged.add(change.getChangedElement());
147             DocumentComponent changedComponent = findComponent(rootToChanged);
148             if (changedComponent != null
149                     && changedComponent.getClass().isAssignableFrom(
150                             LiteralResultElement.class))
151             {
152                 // case literal result element is changed
153
change.markNonDomainChildAsChanged();
154                 change.setParentComponent(null);
155             }
156         }
157     }
158     
159     private XslComponentFactoryImpl myFactory;
160     
161     private StylesheetImpl myRoot;
162     
163     private SyncUpdateVisitor mySyncUpdateVisitor;
164     
165 }
166
Popular Tags