1 19 20 package org.netbeans.modules.xslt.model.impl; 21 22 import java.util.ArrayList ; 23 import java.util.List ; 24 import java.util.Set ; 25 26 import javax.xml.namespace.QName ; 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 ; 38 import org.w3c.dom.Node ; 39 40 41 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 57 @Override 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 72 @Override 73 protected ComponentUpdater<XslComponent> getComponentUpdater() 74 { 75 if ( mySyncUpdateVisitor == null ){ 76 mySyncUpdateVisitor = new SyncUpdateVisitor(); 77 } 78 return mySyncUpdateVisitor; 79 } 80 81 84 public XslComponentFactoryImpl getFactory() { 85 return myFactory; 86 } 87 88 91 public StylesheetImpl getStylesheet() { 92 return (StylesheetImpl) getRootComponent(); 93 } 94 95 98 public XslComponent createComponent( XslComponent parent, Element element ) { 99 return getFactory().create( element , parent); 100 } 101 102 105 public XslComponent getRootComponent() { 106 return myRoot ; 107 } 108 109 @Override 110 public Set <QName > getQNames() { 111 return XslElements.allQNames(); 112 } 113 114 public ChangeInfo prepareChangeInfo(List <Node > pathToRoot) { 115 ChangeInfo change = super.prepareChangeInfo(pathToRoot); 116 DocumentComponent parentComponent = findComponent(change.getRootToParentPath()); 117 if (parentComponent == null) { 118 return change; 119 } 120 121 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 change.setDomainElement(true); 141 change.setParentComponent(null); 142 } 143 else { 144 List <Element> rootToChanged = new ArrayList <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 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 |