blob: 519de86d519507072d6a1e1b99efacb28d110529 [file] [log] [blame]
<HTML><HEAD><META CONTENT="text/html; charset=UTF-8" HTTP-EQUIV="Content-Type"/><TITLE>EMMA Coverage Report</TITLE><STYLE TYPE="text/css"> TABLE,TD,TH {border-style:solid; border-color:black;} TD,TH {background:white;margin:0;line-height:100%;padding-left:0.5em;padding-right:0.5em;} TD {border-width:0 1px 0 0;} TH {border-width:1px 1px 1px 0;} TR TD.h {color:red;} TABLE {border-spacing:0; border-collapse:collapse;border-width:0 0 1px 1px;} P,H1,H2,H3,TH {font-family:verdana,arial,sans-serif;font-size:10pt;} TD {font-family:courier,monospace;font-size:10pt;} TABLE.hdft {border-spacing:0;border-collapse:collapse;border-style:none;} TABLE.hdft TH,TABLE.hdft TD {border-style:none;line-height:normal;} TABLE.hdft TH.tl,TABLE.hdft TD.tl {background:#6699CC;color:white;} TABLE.hdft TD.nv {background:#6633DD;color:white;} .nv A:link {color:white;} .nv A:visited {color:white;} .nv A:active {color:yellow;} TABLE.hdft A:link {color:white;} TABLE.hdft A:visited {color:white;} TABLE.hdft A:active {color:yellow;} .in {color:#356085;} TABLE.s TD {padding-left:0.25em;padding-right:0.25em;} TABLE.s TD.l {padding-left:0.25em;padding-right:0.25em;text-align:right;background:#F0F0F0;} TABLE.s TR.z TD {background:#FF9999;} TABLE.s TR.p TD {background:#FFFF88;} TABLE.s TR.c TD {background:#CCFFCC;} A:link {color:#0000EE;text-decoration:none;} A:visited {color:#0000EE;text-decoration:none;} A:hover {color:#0000EE;text-decoration:underline;} TABLE.cn {border-width:0 0 1px 0;} TABLE.s {border-width:1px 0 1px 1px;} TD.h {color:red;border-width:0 1px 0 0;} TD.f {border-width:0 1px 0 1px;} TD.hf {color:red;border-width:0 1px 0 1px;} TH.f {border-width:1px 1px 1px 1px;} TR.cis TD {background:#F0F0F0;} TR.cis TD {border-width:1px 1px 1px 0;} TR.cis TD.h {color:red;border-width:1px 1px 1px 0;} TR.cis TD.f {border-width:1px 1px 1px 1px;} TR.cis TD.hf {color:red;border-width:1px 1px 1px 1px;} TD.b {border-style:none;background:transparent;line-height:50%;} TD.bt {border-width:1px 0 0 0;background:transparent;line-height:50%;} TR.o TD {background:#F0F0F0;}TABLE.it {border-style:none;}TABLE.it TD,TABLE.it TH {border-style:none;}</STYLE></HEAD><BODY><TABLE CLASS="hdft" CELLSPACING="0" WIDTH="100%"><TR><TH CLASS="tl"><A HREF="http://www.eclemma.org/">EMMA</A> Coverage Report (generated Fri Feb 20 18:44:54 GMT 2009)</TH></TR><TR><TD CLASS="nv">[<A HREF="../xslUnitTestCoverage.html">all classes</A>][<A HREF="96.html">org.eclipse.wst.sse.core.internal.model</A>]</TD></TR></TABLE><H2>COVERAGE SUMMARY FOR SOURCE FILE [<SPAN CLASS="in">AbstractModelLoader.java</SPAN>]</H2><TABLE CELLSPACING="0" WIDTH="100%"><TR><TH>name</TH><TH>class, %</TH><TH>method, %</TH><TH>block, %</TH><TH>line, %</TH></TR><TR><TD>AbstractModelLoader.java</TD><TD>100% (1/1)</TD><TD CLASS="h">35%  (7/20)</TD><TD CLASS="h">13%  (79/595)</TD><TD CLASS="h">17%  (27/161)</TD></TR></TABLE><H3>COVERAGE BREAKDOWN BY CLASS AND METHOD</H3><TABLE CLASS="cn" CELLSPACING="0" WIDTH="100%"><TR><TH CLASS="f">name</TH><TH>class, %</TH><TH>method, %</TH><TH>block, %</TH><TH>line, %</TH></TR><TR><TD CLASS="b"> </TD><TD CLASS="b"> </TD><TD CLASS="b"> </TD><TD CLASS="b"> </TD><TD CLASS="b"> </TD></TR><TR CLASS="cis"><TD CLASS="f">class <A HREF="#0">AbstractModelLoader</A></TD><TD>100% (1/1)</TD><TD CLASS="h">35%  (7/20)</TD><TD CLASS="h">13%  (79/595)</TD><TD CLASS="h">17%  (27/161)</TD></TR><TR><TD CLASS="f"><A HREF="#0">computeMem (): long</A></TD><TD> </TD><TD CLASS="h">0%   (0/1)</TD><TD CLASS="h">0%   (0/15)</TD><TD CLASS="h">0%   (0/4)</TD></TR><TR CLASS="o"><TD CLASS="f"><A HREF="#2">createModel (): IStructuredModel</A></TD><TD> </TD><TD CLASS="h">0%   (0/1)</TD><TD CLASS="h">0%   (0/35)</TD><TD CLASS="h">0%   (0/10)</TD></TR><TR><TD CLASS="f"><A HREF="#3">createModel (IStructuredModel): IStructuredModel</A></TD><TD> </TD><TD CLASS="h">0%   (0/1)</TD><TD CLASS="h">0%   (0/36)</TD><TD CLASS="h">0%   (0/11)</TD></TR><TR CLASS="o"><TD CLASS="f"><A HREF="#4">duplicateFactoryRegistry (IStructuredModel, IStructuredModel): void</A></TD><TD> </TD><TD CLASS="h">0%   (0/1)</TD><TD CLASS="h">0%   (0/29)</TD><TD CLASS="h">0%   (0/8)</TD></TR><TR><TD CLASS="f"><A HREF="#5">getAdapterFactories (): List</A></TD><TD> </TD><TD CLASS="h">0%   (0/1)</TD><TD CLASS="h">0%   (0/5)</TD><TD CLASS="h">0%   (0/1)</TD></TR><TR CLASS="o"><TD CLASS="f"><A HREF="#6">initEmbeddedType (IStructuredModel, IStructuredModel): void</A></TD><TD> </TD><TD CLASS="h">0%   (0/1)</TD><TD CLASS="h">0%   (0/1)</TD><TD CLASS="h">0%   (0/1)</TD></TR><TR><TD CLASS="f"><A HREF="#7">load (IFile, IStructuredModel): void</A></TD><TD> </TD><TD CLASS="h">0%   (0/1)</TD><TD CLASS="h">0%   (0/34)</TD><TD CLASS="h">0%   (0/9)</TD></TR><TR CLASS="o"><TD CLASS="f"><A HREF="#8">load (InputStream, IStructuredModel, EncodingRule): void</A></TD><TD> </TD><TD CLASS="h">0%   (0/1)</TD><TD CLASS="h">0%   (0/27)</TD><TD CLASS="h">0%   (0/7)</TD></TR><TR><TD CLASS="f"><A HREF="#9">load (InputStream, IStructuredModel, String, String): void</A></TD><TD> </TD><TD CLASS="h">0%   (0/1)</TD><TD CLASS="h">0%   (0/18)</TD><TD CLASS="h">0%   (0/4)</TD></TR><TR CLASS="o"><TD CLASS="f"><A HREF="#a">load (String, InputStream, IStructuredModel, String, String): void</A></TD><TD> </TD><TD CLASS="h">0%   (0/1)</TD><TD CLASS="h">0%   (0/84)</TD><TD CLASS="h">0%   (0/20)</TD></TR><TR><TD CLASS="f"><A HREF="#b">reinitialize (IStructuredModel): IStructuredModel</A></TD><TD> </TD><TD CLASS="h">0%   (0/1)</TD><TD CLASS="h">0%   (0/10)</TD><TD CLASS="h">0%   (0/2)</TD></TR><TR CLASS="o"><TD CLASS="f"><A HREF="#c">reload (InputStream, IStructuredModel): void</A></TD><TD> </TD><TD CLASS="h">0%   (0/1)</TD><TD CLASS="h">0%   (0/30)</TD><TD CLASS="h">0%   (0/9)</TD></TR><TR><TD CLASS="f"><A HREF="#d">transformInstance (IStructuredDocument, IStructuredDocument): void</A></TD><TD> </TD><TD CLASS="h">0%   (0/1)</TD><TD CLASS="h">0%   (0/192)</TD><TD CLASS="h">0%   (0/48)</TD></TR><TR CLASS="o"><TD CLASS="f"><A HREF="#e">AbstractModelLoader (): void</A></TD><TD> </TD><TD>100% (1/1)</TD><TD>100% (6/6)</TD><TD>100% (3/3)</TD></TR><TR><TD CLASS="f"><A HREF="#f">addFactories (IStructuredModel, List): void</A></TD><TD> </TD><TD>100% (1/1)</TD><TD>100% (34/34)</TD><TD>100% (9/9)</TD></TR><TR CLASS="o"><TD CLASS="f"><A HREF="#10">createModel (IStructuredDocument, String, IModelHandler): IStructuredModel</A></TD><TD> </TD><TD>100% (1/1)</TD><TD>100% (32/32)</TD><TD>100% (10/10)</TD></TR><TR><TD CLASS="f"><A HREF="#11">initEmbeddedTypePost (IStructuredModel): void</A></TD><TD> </TD><TD>100% (1/1)</TD><TD>100% (1/1)</TD><TD>100% (1/1)</TD></TR><TR CLASS="o"><TD CLASS="f"><A HREF="#12">initEmbeddedTypePre (IStructuredModel): void</A></TD><TD> </TD><TD>100% (1/1)</TD><TD>100% (1/1)</TD><TD>100% (1/1)</TD></TR><TR><TD CLASS="f"><A HREF="#13">initEmbeddedTypePre (IStructuredModel, IStructuredDocument): void</A></TD><TD> </TD><TD>100% (1/1)</TD><TD>100% (4/4)</TD><TD>100% (2/2)</TD></TR><TR CLASS="o"><TD CLASS="f"><A HREF="#14">preLoadAdapt (IStructuredModel): void</A></TD><TD> </TD><TD>100% (1/1)</TD><TD>100% (1/1)</TD><TD>100% (1/1)</TD></TR></TABLE><P></P><TABLE CLASS="s" CELLSPACING="0" WIDTH="100%"><TR><TD CLASS="l">1</TD><TD>/*******************************************************************************</TD></TR><TR><TD CLASS="l">2</TD><TD> * Copyright (c) 2001, 2008 IBM Corporation and others.</TD></TR><TR><TD CLASS="l">3</TD><TD> * All rights reserved. This program and the accompanying materials</TD></TR><TR><TD CLASS="l">4</TD><TD> * are made available under the terms of the Eclipse Public License v1.0</TD></TR><TR><TD CLASS="l">5</TD><TD> * which accompanies this distribution, and is available at</TD></TR><TR><TD CLASS="l">6</TD><TD> * http://www.eclipse.org/legal/epl-v10.html</TD></TR><TR><TD CLASS="l">7</TD><TD> *</TD></TR><TR><TD CLASS="l">8</TD><TD> * Contributors:</TD></TR><TR><TD CLASS="l">9</TD><TD> *     IBM Corporation - initial API and implementation</TD></TR><TR><TD CLASS="l">10</TD><TD> *     Jens Lukowski/Innoopract - initial renaming/restructuring</TD></TR><TR><TD CLASS="l">11</TD><TD> *     </TD></TR><TR><TD CLASS="l">12</TD><TD> *******************************************************************************/</TD></TR><TR><TD CLASS="l">13</TD><TD>package org.eclipse.wst.sse.core.internal.model;</TD></TR><TR><TD CLASS="l">14</TD><TD> </TD></TR><TR><TD CLASS="l">15</TD><TD>import java.io.IOException;</TD></TR><TR><TD CLASS="l">16</TD><TD>import java.io.InputStream;</TD></TR><TR><TD CLASS="l">17</TD><TD>import java.io.UnsupportedEncodingException;</TD></TR><TR><TD CLASS="l">18</TD><TD>import java.util.ArrayList;</TD></TR><TR><TD CLASS="l">19</TD><TD>import java.util.Iterator;</TD></TR><TR><TD CLASS="l">20</TD><TD>import java.util.List;</TD></TR><TR><TD CLASS="l">21</TD><TD> </TD></TR><TR><TD CLASS="l">22</TD><TD>import org.eclipse.core.resources.IFile;</TD></TR><TR><TD CLASS="l">23</TD><TD>import org.eclipse.core.runtime.CoreException;</TD></TR><TR><TD CLASS="l">24</TD><TD>import org.eclipse.jface.text.BadLocationException;</TD></TR><TR><TD CLASS="l">25</TD><TD>import org.eclipse.jface.text.IDocumentExtension3;</TD></TR><TR><TD CLASS="l">26</TD><TD>import org.eclipse.wst.sse.core.internal.Logger;</TD></TR><TR><TD CLASS="l">27</TD><TD>import org.eclipse.wst.sse.core.internal.document.IDocumentLoader;</TD></TR><TR><TD CLASS="l">28</TD><TD>import org.eclipse.wst.sse.core.internal.encoding.EncodingMemento;</TD></TR><TR><TD CLASS="l">29</TD><TD>import org.eclipse.wst.sse.core.internal.encoding.EncodingRule;</TD></TR><TR><TD CLASS="l">30</TD><TD>import org.eclipse.wst.sse.core.internal.ltk.modelhandler.IModelHandler;</TD></TR><TR><TD CLASS="l">31</TD><TD>import org.eclipse.wst.sse.core.internal.ltk.parser.BlockMarker;</TD></TR><TR><TD CLASS="l">32</TD><TD>import org.eclipse.wst.sse.core.internal.ltk.parser.BlockTagParser;</TD></TR><TR><TD CLASS="l">33</TD><TD>import org.eclipse.wst.sse.core.internal.ltk.parser.RegionParser;</TD></TR><TR><TD CLASS="l">34</TD><TD>import org.eclipse.wst.sse.core.internal.ltk.parser.StructuredDocumentRegionHandler;</TD></TR><TR><TD CLASS="l">35</TD><TD>import org.eclipse.wst.sse.core.internal.ltk.parser.StructuredDocumentRegionHandlerExtension;</TD></TR><TR><TD CLASS="l">36</TD><TD>import org.eclipse.wst.sse.core.internal.ltk.parser.StructuredDocumentRegionParser;</TD></TR><TR><TD CLASS="l">37</TD><TD>import org.eclipse.wst.sse.core.internal.ltk.parser.StructuredDocumentRegionParserExtension;</TD></TR><TR><TD CLASS="l">38</TD><TD>import org.eclipse.wst.sse.core.internal.provisional.IModelLoader;</TD></TR><TR><TD CLASS="l">39</TD><TD>import org.eclipse.wst.sse.core.internal.provisional.INodeAdapterFactory;</TD></TR><TR><TD CLASS="l">40</TD><TD>import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;</TD></TR><TR><TD CLASS="l">41</TD><TD>import org.eclipse.wst.sse.core.internal.provisional.document.IEncodedDocument;</TD></TR><TR><TD CLASS="l">42</TD><TD>import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;</TD></TR><TR><TD CLASS="l">43</TD><TD>import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredPartitioning;</TD></TR><TR><TD CLASS="l">44</TD><TD>import org.eclipse.wst.sse.core.internal.text.BasicStructuredDocument;</TD></TR><TR><TD CLASS="l">45</TD><TD>import org.eclipse.wst.sse.core.internal.text.rules.StructuredTextPartitioner;</TD></TR><TR><TD CLASS="l">46</TD><TD>import org.eclipse.wst.sse.core.internal.util.Assert;</TD></TR><TR><TD CLASS="l">47</TD><TD> </TD></TR><TR><TD CLASS="l">48</TD><TD> </TD></TR><TR><TD CLASS="l">49</TD><TD>/**</TD></TR><TR><TD CLASS="l">50</TD><TD> * This class reads a file and creates an Structured Model.</TD></TR><TR><TD CLASS="l">51</TD><TD> */</TD></TR><TR><TD CLASS="l"><A NAME="0">52</A></TD><TD>public abstract class AbstractModelLoader implements IModelLoader {</TD></TR><TR><TD CLASS="l">53</TD><TD>        protected static final int encodingNameSearchLimit = 1000;</TD></TR><TR><TD CLASS="l">54</TD><TD> </TD></TR><TR><TD CLASS="l">55</TD><TD>        private static long computeMem() {</TD></TR><TR CLASS="z"><TD CLASS="l">56</TD><TD>                for (int i = 0; i &lt; 5; i++) {</TD></TR><TR CLASS="z"><TD CLASS="l">57</TD><TD>                        System.gc();</TD></TR><TR CLASS="z"><TD CLASS="l">58</TD><TD>                        System.runFinalization();</TD></TR><TR><TD CLASS="l">59</TD><TD>                }</TD></TR><TR CLASS="z"><TD CLASS="l">60</TD><TD>                return Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();</TD></TR><TR><TD CLASS="l">61</TD><TD>        }</TD></TR><TR><TD CLASS="l">62</TD><TD> </TD></TR><TR CLASS="c"><TD CLASS="l">63</TD><TD>        private boolean DEBUG = false;</TD></TR><TR><TD CLASS="l">64</TD><TD>        protected IDocumentLoader documentLoaderInstance;</TD></TR><TR><TD CLASS="l">65</TD><TD> </TD></TR><TR><TD CLASS="l"><A NAME="e">66</A></TD><TD>        /**</TD></TR><TR><TD CLASS="l">67</TD><TD>         * AbstractLoader constructor also initializes encoding converter/mapper</TD></TR><TR><TD CLASS="l">68</TD><TD>         */</TD></TR><TR><TD CLASS="l">69</TD><TD>        public AbstractModelLoader() {</TD></TR><TR CLASS="c"><TD CLASS="l"><A NAME="f">70</A></TD><TD>                super();</TD></TR><TR CLASS="c"><TD CLASS="l">71</TD><TD>        }</TD></TR><TR><TD CLASS="l">72</TD><TD> </TD></TR><TR><TD CLASS="l">73</TD><TD>        protected void addFactories(IStructuredModel model, List factoryList) {</TD></TR><TR CLASS="c"><TD CLASS="l">74</TD><TD>                Assert.isNotNull(model);</TD></TR><TR CLASS="c"><TD CLASS="l">75</TD><TD>                FactoryRegistry registry = model.getFactoryRegistry();</TD></TR><TR CLASS="c"><TD CLASS="l">76</TD><TD>                Assert.isNotNull(registry, &#34;IStructuredModel &#34; + model.getId() + &#34; has a null FactoryRegistry&#34;); //$NON-NLS-1$ //$NON-NLS-2$</TD></TR><TR CLASS="c"><TD CLASS="l">77</TD><TD>                if (factoryList != null) {</TD></TR><TR CLASS="c"><TD CLASS="l">78</TD><TD>                        Iterator iterator = factoryList.iterator();</TD></TR><TR CLASS="c"><TD CLASS="l">79</TD><TD>                        while (iterator.hasNext()) {</TD></TR><TR CLASS="c"><TD CLASS="l">80</TD><TD>                                INodeAdapterFactory factory = (INodeAdapterFactory) iterator.next();</TD></TR><TR CLASS="c"><TD CLASS="l">81</TD><TD>                                registry.addFactory(factory);</TD></TR><TR><TD CLASS="l">82</TD><TD>                        }</TD></TR><TR><TD CLASS="l">83</TD><TD>                }</TD></TR><TR CLASS="c"><TD CLASS="l">84</TD><TD>        }</TD></TR><TR><TD CLASS="l">85</TD><TD> </TD></TR><TR><TD CLASS="l">86</TD><TD>        /**</TD></TR><TR><TD CLASS="l">87</TD><TD>         * This method should perform all the model initialization required before</TD></TR><TR><TD CLASS="l">88</TD><TD>         * it contains content, namely, it should call newModel, the</TD></TR><TR><TD CLASS="l">89</TD><TD>         * createNewStructuredDocument(), then add those adapter factories which</TD></TR><TR><TD CLASS="l"><A NAME="2">90</A></TD><TD>         * must be set before content is applied. This method should be called by</TD></TR><TR><TD CLASS="l">91</TD><TD>         * &#34;load&#34; method. (this is tentative API)</TD></TR><TR><TD CLASS="l">92</TD><TD>         */</TD></TR><TR><TD CLASS="l">93</TD><TD>        public IStructuredModel createModel() {</TD></TR><TR CLASS="z"><TD CLASS="l">94</TD><TD>                documentLoaderInstance = null;</TD></TR><TR CLASS="z"><TD CLASS="l">95</TD><TD>                IStructuredModel model = newModel();</TD></TR><TR CLASS="z"><TD CLASS="l">96</TD><TD>                IEncodedDocument structuredDocument = getDocumentLoader().createNewStructuredDocument();</TD></TR><TR CLASS="z"><TD CLASS="l">97</TD><TD>                if (structuredDocument instanceof IStructuredDocument) {</TD></TR><TR CLASS="z"><TD CLASS="l">98</TD><TD>                        model.setStructuredDocument((IStructuredDocument) structuredDocument);</TD></TR><TR CLASS="z"><TD CLASS="l">99</TD><TD>                        addFactories(model, getAdapterFactories());</TD></TR><TR><TD CLASS="l">100</TD><TD>                        //</TD></TR><TR CLASS="z"><TD CLASS="l">101</TD><TD>                        initEmbeddedTypePre(model, (IStructuredDocument) structuredDocument);</TD></TR><TR CLASS="z"><TD CLASS="l">102</TD><TD>                        initEmbeddedTypePost(model);</TD></TR><TR><TD CLASS="l">103</TD><TD>                        // For types with propagating adapters, its important</TD></TR><TR><TD CLASS="l">104</TD><TD>                        // that the propagating adapter be in place before the contents</TD></TR><TR><TD CLASS="l">105</TD><TD>                        // are set.</TD></TR><TR CLASS="z"><TD CLASS="l">106</TD><TD>                        preLoadAdapt(model);</TD></TR><TR><TD CLASS="l">107</TD><TD>                }</TD></TR><TR CLASS="z"><TD CLASS="l"><A NAME="10">108</A></TD><TD>                return model;</TD></TR><TR><TD CLASS="l">109</TD><TD>        }</TD></TR><TR><TD CLASS="l">110</TD><TD> </TD></TR><TR><TD CLASS="l">111</TD><TD>        public IStructuredModel createModel(IStructuredDocument structuredDocument, String baseLocation, IModelHandler handler) {</TD></TR><TR CLASS="c"><TD CLASS="l">112</TD><TD>                documentLoaderInstance = null;</TD></TR><TR CLASS="c"><TD CLASS="l">113</TD><TD>                IStructuredModel model = newModel();</TD></TR><TR CLASS="c"><TD CLASS="l">114</TD><TD>                model.setBaseLocation(baseLocation);</TD></TR><TR><TD CLASS="l">115</TD><TD>                </TD></TR><TR><TD CLASS="l">116</TD><TD>                // handler must be set early, incase a re-init is </TD></TR><TR><TD CLASS="l">117</TD><TD>                // required during creation.</TD></TR><TR CLASS="c"><TD CLASS="l">118</TD><TD>                model.setModelHandler(handler);</TD></TR><TR><TD CLASS="l">119</TD><TD>                </TD></TR><TR CLASS="c"><TD CLASS="l">120</TD><TD>                addFactories(model, getAdapterFactories());</TD></TR><TR><TD CLASS="l">121</TD><TD>                // For types with propagating adapters, it's important</TD></TR><TR><TD CLASS="l">122</TD><TD>                // that the propagating adapter be in place before the contents</TD></TR><TR><TD CLASS="l">123</TD><TD>                // are set.</TD></TR><TR CLASS="c"><TD CLASS="l">124</TD><TD>                preLoadAdapt(model);</TD></TR><TR CLASS="c"><TD CLASS="l">125</TD><TD>                initEmbeddedTypePre(model, structuredDocument);</TD></TR><TR><TD CLASS="l">126</TD><TD> </TD></TR><TR CLASS="c"><TD CLASS="l">127</TD><TD>                model.setStructuredDocument(structuredDocument);</TD></TR><TR><TD CLASS="l">128</TD><TD>                //</TD></TR><TR CLASS="c"><TD CLASS="l">129</TD><TD>                initEmbeddedTypePost(model);</TD></TR><TR><TD CLASS="l">130</TD><TD> </TD></TR><TR CLASS="c"><TD CLASS="l">131</TD><TD>                return model;</TD></TR><TR><TD CLASS="l">132</TD><TD>        }</TD></TR><TR><TD CLASS="l">133</TD><TD> </TD></TR><TR><TD CLASS="l"><A NAME="3">134</A></TD><TD>        /**</TD></TR><TR><TD CLASS="l">135</TD><TD>         * This method is used for cloning models.</TD></TR><TR><TD CLASS="l">136</TD><TD>         */</TD></TR><TR><TD CLASS="l">137</TD><TD>        public IStructuredModel createModel(IStructuredModel oldModel) {</TD></TR><TR CLASS="z"><TD CLASS="l">138</TD><TD>                documentLoaderInstance = null;</TD></TR><TR CLASS="z"><TD CLASS="l">139</TD><TD>                IStructuredModel newModel = newModel();</TD></TR><TR CLASS="z"><TD CLASS="l">140</TD><TD>                IStructuredDocument oldStructuredDocument = oldModel.getStructuredDocument();</TD></TR><TR CLASS="z"><TD CLASS="l">141</TD><TD>                IStructuredDocument newStructuredDocument = oldStructuredDocument.newInstance();</TD></TR><TR CLASS="z"><TD CLASS="l">142</TD><TD>                newModel.setStructuredDocument(newStructuredDocument);</TD></TR><TR><TD CLASS="l">143</TD><TD>                // NOTE: we DO NOT simply add the standard ones to the new model</TD></TR><TR><TD CLASS="l">144</TD><TD>                // addFactories(newModel, getAdapterFactories());</TD></TR><TR><TD CLASS="l">145</TD><TD>                // Now, we take the opportunity to add Factories from the oldModel's</TD></TR><TR><TD CLASS="l">146</TD><TD>                // registry to the new model's registry .. if they do not already</TD></TR><TR><TD CLASS="l">147</TD><TD>                // exist there.</TD></TR><TR CLASS="z"><TD CLASS="l">148</TD><TD>                duplicateFactoryRegistry(newModel, oldModel);</TD></TR><TR CLASS="z"><TD CLASS="l">149</TD><TD>                if (newModel instanceof AbstractStructuredModel) {</TD></TR><TR CLASS="z"><TD CLASS="l">150</TD><TD>                        ((AbstractStructuredModel) newModel).setContentTypeIdentifier(oldModel.getContentTypeIdentifier());</TD></TR><TR><TD CLASS="l">151</TD><TD>                }</TD></TR><TR><TD CLASS="l">152</TD><TD>                // addFactories(newModel, oldModel);</TD></TR><TR CLASS="z"><TD CLASS="l">153</TD><TD>                initEmbeddedType(oldModel, newModel);</TD></TR><TR><TD CLASS="l">154</TD><TD>                // For types with propagating adapters, its important</TD></TR><TR><TD CLASS="l">155</TD><TD>                // that the propagating adapter be in place before the contents</TD></TR><TR><TD CLASS="l">156</TD><TD>                // are set.</TD></TR><TR CLASS="z"><TD CLASS="l">157</TD><TD>                preLoadAdapt(newModel);</TD></TR><TR CLASS="z"><TD CLASS="l"><A NAME="4">158</A></TD><TD>                return newModel;</TD></TR><TR><TD CLASS="l">159</TD><TD>        }</TD></TR><TR><TD CLASS="l">160</TD><TD> </TD></TR><TR><TD CLASS="l">161</TD><TD>        private void duplicateFactoryRegistry(IStructuredModel newModel, IStructuredModel oldModel) {</TD></TR><TR CLASS="z"><TD CLASS="l">162</TD><TD>                List oldAdapterFactories = oldModel.getFactoryRegistry().getFactories();</TD></TR><TR CLASS="z"><TD CLASS="l">163</TD><TD>                List newAdapterFactories = new ArrayList();</TD></TR><TR CLASS="z"><TD CLASS="l">164</TD><TD>                Iterator oldListIterator = oldAdapterFactories.iterator();</TD></TR><TR CLASS="z"><TD CLASS="l">165</TD><TD>                while (oldListIterator.hasNext()) {</TD></TR><TR CLASS="z"><TD CLASS="l">166</TD><TD>                        INodeAdapterFactory oldAdapterFactory = (INodeAdapterFactory) oldListIterator.next();</TD></TR><TR><TD CLASS="l">167</TD><TD>                        // now &#34;clone&#34; the adapterfactory</TD></TR><TR CLASS="z"><TD CLASS="l">168</TD><TD>                        newAdapterFactories.add(oldAdapterFactory.copy());</TD></TR><TR><TD CLASS="l">169</TD><TD>                }</TD></TR><TR><TD CLASS="l">170</TD><TD>                // now that we have the &#34;cloned&#34; list, add to new model</TD></TR><TR CLASS="z"><TD CLASS="l">171</TD><TD>                addFactories(newModel, newAdapterFactories);</TD></TR><TR CLASS="z"><TD CLASS="l">172</TD><TD>        }</TD></TR><TR><TD CLASS="l">173</TD><TD> </TD></TR><TR><TD CLASS="l">174</TD><TD>        /**</TD></TR><TR><TD CLASS="l">175</TD><TD>         * This method must return those factories which must be attached to the</TD></TR><TR><TD CLASS="l"><A NAME="5">176</A></TD><TD>         * structuredModel before content is applied.</TD></TR><TR><TD CLASS="l">177</TD><TD>         */</TD></TR><TR><TD CLASS="l">178</TD><TD>        public List getAdapterFactories() {</TD></TR><TR><TD CLASS="l">179</TD><TD>                // abstract method returns none</TD></TR><TR CLASS="z"><TD CLASS="l">180</TD><TD>                return new ArrayList(0);</TD></TR><TR><TD CLASS="l">181</TD><TD>        }</TD></TR><TR><TD CLASS="l">182</TD><TD> </TD></TR><TR><TD CLASS="l">183</TD><TD>        abstract public IDocumentLoader getDocumentLoader();</TD></TR><TR><TD CLASS="l">184</TD><TD> </TD></TR><TR><TD CLASS="l">185</TD><TD>        /**</TD></TR><TR><TD CLASS="l">186</TD><TD>         * Method initEmbeddedType, &#34;pre&#34;-stage. Nothing to do here in super class.</TD></TR><TR><TD CLASS="l"><A NAME="12">187</A></TD><TD>         * </TD></TR><TR><TD CLASS="l">188</TD><TD>         * @param model</TD></TR><TR><TD CLASS="l">189</TD><TD>         */</TD></TR><TR><TD CLASS="l">190</TD><TD>        protected void initEmbeddedTypePre(IStructuredModel model) {</TD></TR><TR CLASS="c"><TD CLASS="l">191</TD><TD>        }</TD></TR><TR><TD CLASS="l">192</TD><TD> </TD></TR><TR><TD CLASS="l">193</TD><TD>        /**</TD></TR><TR><TD CLASS="l">194</TD><TD>         * Method initEmbeddedType, &#34;pre&#34;-stage. By default simply calls the</TD></TR><TR><TD CLASS="l">195</TD><TD>         * version of this method that uses only the structured model.</TD></TR><TR><TD CLASS="l">196</TD><TD>         * </TD></TR><TR><TD CLASS="l">197</TD><TD>         * @param model</TD></TR><TR><TD CLASS="l">198</TD><TD>         *            the model for which to initialize</TD></TR><TR><TD CLASS="l">199</TD><TD>         * @param structuredDocument</TD></TR><TR><TD CLASS="l">200</TD><TD>         *            The structured document containing the text content for the</TD></TR><TR><TD CLASS="l"><A NAME="13">201</A></TD><TD>         *            model, which may be a different instance than what is in the</TD></TR><TR><TD CLASS="l">202</TD><TD>         *            model at this stage.</TD></TR><TR><TD CLASS="l">203</TD><TD>         */</TD></TR><TR><TD CLASS="l">204</TD><TD>        protected void initEmbeddedTypePre(IStructuredModel model, IStructuredDocument structuredDocument) {</TD></TR><TR CLASS="c"><TD CLASS="l"><A NAME="11">205</A></TD><TD>                initEmbeddedTypePre(model);</TD></TR><TR CLASS="c"><TD CLASS="l">206</TD><TD>        }</TD></TR><TR><TD CLASS="l">207</TD><TD>                </TD></TR><TR><TD CLASS="l">208</TD><TD>        protected void initEmbeddedTypePost(IStructuredModel model) {</TD></TR><TR CLASS="c"><TD CLASS="l">209</TD><TD>        }</TD></TR><TR><TD CLASS="l">210</TD><TD> </TD></TR><TR><TD CLASS="l">211</TD><TD>        /**</TD></TR><TR><TD CLASS="l">212</TD><TD>         * Method initEmbeddedType. Nothing to do here in super class.</TD></TR><TR><TD CLASS="l">213</TD><TD>         * </TD></TR><TR><TD CLASS="l"><A NAME="6">214</A></TD><TD>         * @param oldModel</TD></TR><TR><TD CLASS="l">215</TD><TD>         * @param newModel</TD></TR><TR><TD CLASS="l">216</TD><TD>         */</TD></TR><TR><TD CLASS="l"><A NAME="7">217</A></TD><TD>        protected void initEmbeddedType(IStructuredModel oldModel, IStructuredModel newModel) {</TD></TR><TR CLASS="z"><TD CLASS="l">218</TD><TD>        }</TD></TR><TR><TD CLASS="l">219</TD><TD> </TD></TR><TR><TD CLASS="l">220</TD><TD>        public void load(IFile file, IStructuredModel model) throws IOException, CoreException {</TD></TR><TR CLASS="z"><TD CLASS="l">221</TD><TD>                IEncodedDocument structuredDocument = model.getStructuredDocument();</TD></TR><TR CLASS="z"><TD CLASS="l">222</TD><TD>                if (file == null)</TD></TR><TR CLASS="z"><TD CLASS="l">223</TD><TD>                        structuredDocument = getDocumentLoader().createNewStructuredDocument();</TD></TR><TR><TD CLASS="l">224</TD><TD>                else</TD></TR><TR CLASS="z"><TD CLASS="l">225</TD><TD>                        structuredDocument = getDocumentLoader().createNewStructuredDocument(file);</TD></TR><TR><TD CLASS="l">226</TD><TD> </TD></TR><TR><TD CLASS="l">227</TD><TD>                // TODO: need to straighten out IEncodedDocument mess</TD></TR><TR CLASS="z"><TD CLASS="l">228</TD><TD>                if (structuredDocument instanceof IStructuredDocument)</TD></TR><TR CLASS="z"><TD CLASS="l">229</TD><TD>                        transformInstance(model.getStructuredDocument(), (IStructuredDocument) structuredDocument);</TD></TR><TR><TD CLASS="l">230</TD><TD>                else</TD></TR><TR CLASS="z"><TD CLASS="l">231</TD><TD>                        model.getStructuredDocument().set(structuredDocument.get());</TD></TR><TR><TD CLASS="l">232</TD><TD> </TD></TR><TR><TD CLASS="l">233</TD><TD>                // original hack</TD></TR><TR><TD CLASS="l">234</TD><TD>                // model.setStructuredDocument((IStructuredDocument)</TD></TR><TR><TD CLASS="l">235</TD><TD>                // structuredDocument);</TD></TR><TR><TD CLASS="l">236</TD><TD>                // ((IStructuredDocument) structuredDocument).fireNewDocument(this);</TD></TR><TR CLASS="z"><TD CLASS="l">237</TD><TD>                documentLoaderInstance = null;</TD></TR><TR><TD CLASS="l">238</TD><TD>                // technicq of future</TD></TR><TR><TD CLASS="l">239</TD><TD>                // model.setStructuredDocument((IStructuredDocument)</TD></TR><TR><TD CLASS="l">240</TD><TD>                // structuredDocument);</TD></TR><TR><TD CLASS="l">241</TD><TD>                // documentLoaderInstance = null;</TD></TR><TR CLASS="z"><TD CLASS="l"><A NAME="8">242</A></TD><TD>        }</TD></TR><TR><TD CLASS="l">243</TD><TD> </TD></TR><TR><TD CLASS="l">244</TD><TD>        public void load(InputStream inputStream, IStructuredModel model, EncodingRule encodingRule) throws UnsupportedEncodingException, java.io.IOException {</TD></TR><TR><TD CLASS="l">245</TD><TD>                // note we don't open the stream, so we don't close it</TD></TR><TR CLASS="z"><TD CLASS="l">246</TD><TD>                IEncodedDocument structuredDocument = model.getStructuredDocument();</TD></TR><TR CLASS="z"><TD CLASS="l">247</TD><TD>                if (inputStream == null) {</TD></TR><TR CLASS="z"><TD CLASS="l">248</TD><TD>                        structuredDocument = getDocumentLoader().createNewStructuredDocument();</TD></TR><TR><TD CLASS="l">249</TD><TD>                }</TD></TR><TR><TD CLASS="l">250</TD><TD>                else {</TD></TR><TR><TD CLASS="l">251</TD><TD>                        // assume's model has been initialized already with base location</TD></TR><TR CLASS="z"><TD CLASS="l">252</TD><TD>                        structuredDocument = getDocumentLoader().createNewStructuredDocument(model.getBaseLocation(), inputStream, encodingRule);</TD></TR><TR><TD CLASS="l">253</TD><TD>                        // TODO: model's not designed for this!</TD></TR><TR><TD CLASS="l">254</TD><TD>                        // we want to move to this &#34;set&#34; method, but the 'fire' was needed</TD></TR><TR><TD CLASS="l">255</TD><TD>                        // as</TD></TR><TR><TD CLASS="l">256</TD><TD>                        // a work around for strucutredModel not handling 'set' right, but</TD></TR><TR><TD CLASS="l">257</TD><TD>                        // that 'fireNewDocument' method was causing unbalance</TD></TR><TR><TD CLASS="l">258</TD><TD>                        // &#34;aboutToChange&#34; and &#34;changed&#34;</TD></TR><TR><TD CLASS="l">259</TD><TD>                        // events.</TD></TR><TR><TD CLASS="l">260</TD><TD>                        // model.setStructuredDocument((IStructuredDocument)</TD></TR><TR><TD CLASS="l">261</TD><TD>                        // structuredDocument);</TD></TR><TR><TD CLASS="l">262</TD><TD>                        // ((IStructuredDocument)</TD></TR><TR><TD CLASS="l">263</TD><TD>                        // structuredDocument).fireNewDocument(this);</TD></TR><TR CLASS="z"><TD CLASS="l">264</TD><TD>                        model.getStructuredDocument().set(structuredDocument.get());</TD></TR><TR><TD CLASS="l">265</TD><TD> </TD></TR><TR><TD CLASS="l">266</TD><TD>                }</TD></TR><TR CLASS="z"><TD CLASS="l">267</TD><TD>                documentLoaderInstance = null;</TD></TR><TR><TD CLASS="l">268</TD><TD> </TD></TR><TR CLASS="z"><TD CLASS="l">269</TD><TD>        }</TD></TR><TR><TD CLASS="l">270</TD><TD> </TD></TR><TR><TD CLASS="l">271</TD><TD>        /**</TD></TR><TR><TD CLASS="l">272</TD><TD>         * deprecated -- use EncodingRule form</TD></TR><TR><TD CLASS="l">273</TD><TD>         */</TD></TR><TR><TD CLASS="l"><A NAME="9">274</A></TD><TD>        synchronized public void load(InputStream inputStream, IStructuredModel model, String encodingName, String lineDelimiter) throws UnsupportedEncodingException, java.io.IOException {</TD></TR><TR><TD CLASS="l">275</TD><TD>                // note we don't open the stream, so we don't close it</TD></TR><TR><TD CLASS="l">276</TD><TD>                // TEMP work around to maintain previous function,</TD></TR><TR><TD CLASS="l">277</TD><TD>                // until everyone can change to EncodingRule.FORCE_DEFAULT</TD></TR><TR CLASS="z"><TD CLASS="l">278</TD><TD>                if (encodingName != null &amp;&amp; encodingName.trim().length() == 0) {</TD></TR><TR><TD CLASS="l">279</TD><TD>                        // redirect to new method</TD></TR><TR CLASS="z"><TD CLASS="l">280</TD><TD>                        load(inputStream, model, EncodingRule.FORCE_DEFAULT);</TD></TR><TR><TD CLASS="l">281</TD><TD>                }</TD></TR><TR><TD CLASS="l">282</TD><TD>                else {</TD></TR><TR CLASS="z"><TD CLASS="l">283</TD><TD>                        load(inputStream, model, EncodingRule.CONTENT_BASED);</TD></TR><TR><TD CLASS="l">284</TD><TD>                }</TD></TR><TR CLASS="z"><TD CLASS="l"><A NAME="a">285</A></TD><TD>        }</TD></TR><TR><TD CLASS="l">286</TD><TD> </TD></TR><TR><TD CLASS="l">287</TD><TD>        public void load(String filename, InputStream inputStream, IStructuredModel model, String junk, String dummy) throws UnsupportedEncodingException, java.io.IOException {</TD></TR><TR><TD CLASS="l">288</TD><TD> </TD></TR><TR CLASS="z"><TD CLASS="l">289</TD><TD>                long memoryUsed = 0;</TD></TR><TR CLASS="z"><TD CLASS="l">290</TD><TD>                if (DEBUG) {</TD></TR><TR CLASS="z"><TD CLASS="l">291</TD><TD>                        memoryUsed = computeMem();</TD></TR><TR CLASS="z"><TD CLASS="l">292</TD><TD>                        System.out.println(&#34;measuring heap memory for &#34; + filename); //$NON-NLS-1$</TD></TR><TR><TD CLASS="l">293</TD><TD>                        // System.out.println(&#34;heap memory used before load: &#34; +</TD></TR><TR><TD CLASS="l">294</TD><TD>                        // memoryUsed);</TD></TR><TR><TD CLASS="l">295</TD><TD>                }</TD></TR><TR><TD CLASS="l">296</TD><TD> </TD></TR><TR><TD CLASS="l">297</TD><TD>                // during an initial load, we expect the olddocument to be empty</TD></TR><TR><TD CLASS="l">298</TD><TD>                // during re-load, however, it would be full.</TD></TR><TR CLASS="z"><TD CLASS="l">299</TD><TD>                IEncodedDocument newstructuredDocument = null;</TD></TR><TR CLASS="z"><TD CLASS="l">300</TD><TD>                IEncodedDocument oldStructuredDocument = model.getStructuredDocument();</TD></TR><TR><TD CLASS="l">301</TD><TD> </TD></TR><TR><TD CLASS="l">302</TD><TD>                // get new document</TD></TR><TR CLASS="z"><TD CLASS="l">303</TD><TD>                if (inputStream == null) {</TD></TR><TR CLASS="z"><TD CLASS="l">304</TD><TD>                        newstructuredDocument = getDocumentLoader().createNewStructuredDocument();</TD></TR><TR><TD CLASS="l">305</TD><TD>                }</TD></TR><TR><TD CLASS="l">306</TD><TD>                else {</TD></TR><TR CLASS="z"><TD CLASS="l">307</TD><TD>                        newstructuredDocument = getDocumentLoader().createNewStructuredDocument(filename, inputStream);</TD></TR><TR><TD CLASS="l">308</TD><TD>                }</TD></TR><TR CLASS="z"><TD CLASS="l">309</TD><TD>                if (DEBUG) {</TD></TR><TR CLASS="z"><TD CLASS="l">310</TD><TD>                        long memoryAtEnd = computeMem();</TD></TR><TR><TD CLASS="l">311</TD><TD>                        // System.out.println(&#34;heap memory used after loading new</TD></TR><TR><TD CLASS="l">312</TD><TD>                        // document: &#34; + memoryAtEnd);</TD></TR><TR CLASS="z"><TD CLASS="l">313</TD><TD>                        System.out.println(&#34;    heap memory implied used by document: &#34; + (memoryAtEnd - memoryUsed)); //$NON-NLS-1$</TD></TR><TR><TD CLASS="l">314</TD><TD>                }</TD></TR><TR><TD CLASS="l">315</TD><TD> </TD></TR><TR><TD CLASS="l">316</TD><TD> </TD></TR><TR><TD CLASS="l">317</TD><TD>                // TODO: need to straighten out IEncodedDocument mess</TD></TR><TR CLASS="z"><TD CLASS="l">318</TD><TD>                if (newstructuredDocument instanceof IStructuredDocument) {</TD></TR><TR CLASS="z"><TD CLASS="l">319</TD><TD>                        transformInstance((IStructuredDocument) oldStructuredDocument, (IStructuredDocument) newstructuredDocument);</TD></TR><TR><TD CLASS="l">320</TD><TD>                }</TD></TR><TR><TD CLASS="l">321</TD><TD>                else {</TD></TR><TR><TD CLASS="l">322</TD><TD>                        // we don't really expect this case, just included for safety</TD></TR><TR CLASS="z"><TD CLASS="l">323</TD><TD>                        oldStructuredDocument.set(newstructuredDocument.get());</TD></TR><TR><TD CLASS="l">324</TD><TD>                }</TD></TR><TR><TD CLASS="l">325</TD><TD>                // original hack</TD></TR><TR><TD CLASS="l">326</TD><TD>                // model.setStructuredDocument((IStructuredDocument)</TD></TR><TR><TD CLASS="l">327</TD><TD>                // structuredDocument);</TD></TR><TR><TD CLASS="l">328</TD><TD>                // ((IStructuredDocument) structuredDocument).fireNewDocument(this);</TD></TR><TR CLASS="z"><TD CLASS="l">329</TD><TD>                documentLoaderInstance = null;</TD></TR><TR><TD CLASS="l">330</TD><TD>                // technicq of future</TD></TR><TR><TD CLASS="l">331</TD><TD>                // model.setStructuredDocument((IStructuredDocument)</TD></TR><TR><TD CLASS="l">332</TD><TD>                // structuredDocument);</TD></TR><TR><TD CLASS="l">333</TD><TD>                // documentLoaderInstance = null;</TD></TR><TR CLASS="z"><TD CLASS="l">334</TD><TD>                if (DEBUG) {</TD></TR><TR CLASS="z"><TD CLASS="l">335</TD><TD>                        long memoryAtEnd = computeMem();</TD></TR><TR><TD CLASS="l">336</TD><TD>                        // System.out.println(&#34;heap memory used after setting to model: &#34;</TD></TR><TR><TD CLASS="l">337</TD><TD>                        // + memoryAtEnd);</TD></TR><TR CLASS="z"><TD CLASS="l">338</TD><TD>                        System.out.println(&#34;    heap memory implied used by document and model: &#34; + (memoryAtEnd - memoryUsed)); //$NON-NLS-1$</TD></TR><TR><TD CLASS="l">339</TD><TD>                }</TD></TR><TR><TD CLASS="l">340</TD><TD> </TD></TR><TR CLASS="z"><TD CLASS="l">341</TD><TD>        }</TD></TR><TR><TD CLASS="l">342</TD><TD> </TD></TR><TR><TD CLASS="l">343</TD><TD>        /**</TD></TR><TR><TD CLASS="l">344</TD><TD>         * required by interface, being declared here abstractly just as another</TD></TR><TR><TD CLASS="l">345</TD><TD>         * reminder.</TD></TR><TR><TD CLASS="l">346</TD><TD>         */</TD></TR><TR><TD CLASS="l">347</TD><TD>        abstract public IStructuredModel newModel();</TD></TR><TR><TD CLASS="l">348</TD><TD> </TD></TR><TR><TD CLASS="l">349</TD><TD>        /**</TD></TR><TR><TD CLASS="l">350</TD><TD>         * There's nothing to do here in abstract class for initializing adapters.</TD></TR><TR><TD CLASS="l">351</TD><TD>         * Subclasses can and should override this method and provide proper</TD></TR><TR><TD CLASS="l">352</TD><TD>         * intialization (For example, to get DOM document and 'getAdapter' on it,</TD></TR><TR><TD CLASS="l">353</TD><TD>         * so that the first node/notifier has the adapter on it.)</TD></TR><TR><TD CLASS="l"><A NAME="14">354</A></TD><TD>         */</TD></TR><TR><TD CLASS="l">355</TD><TD>        protected void preLoadAdapt(IStructuredModel structuredModel) {</TD></TR><TR><TD CLASS="l">356</TD><TD> </TD></TR><TR><TD CLASS="l">357</TD><TD> </TD></TR><TR CLASS="c"><TD CLASS="l">358</TD><TD>        }</TD></TR><TR><TD CLASS="l">359</TD><TD> </TD></TR><TR><TD CLASS="l">360</TD><TD>        /**</TD></TR><TR><TD CLASS="l">361</TD><TD>         * Normally, here in the abstact class, there's nothing to do, but we will</TD></TR><TR><TD CLASS="l">362</TD><TD>         * reset text, since this MIGHT end up being called to recover from error</TD></TR><TR><TD CLASS="l">363</TD><TD>         * conditions (e.g. IStructuredDocument exceptions) And, can be called by</TD></TR><TR><TD CLASS="l">364</TD><TD>         * subclasses.</TD></TR><TR><TD CLASS="l">365</TD><TD>         */</TD></TR><TR><TD CLASS="l">366</TD><TD>        public IStructuredModel reinitialize(IStructuredModel model) {</TD></TR><TR><TD CLASS="l">367</TD><TD>                // Note: the &#34;minimumization&#34; routines</TD></TR><TR><TD CLASS="l">368</TD><TD>                // of 'replaceText' allow many old nodes to pass through, when</TD></TR><TR><TD CLASS="l"><A NAME="b">369</A></TD><TD>                // really its assumed they are created anew.</TD></TR><TR><TD CLASS="l">370</TD><TD>                // so we need to use 'setText' (I think &#34;setText' ends up</TD></TR><TR><TD CLASS="l">371</TD><TD>                // throwing a 'newModel' event though, that may have some</TD></TR><TR><TD CLASS="l">372</TD><TD>                // implications.</TD></TR><TR CLASS="z"><TD CLASS="l">373</TD><TD>                model.getStructuredDocument().setText(this, model.getStructuredDocument().get());</TD></TR><TR CLASS="z"><TD CLASS="l">374</TD><TD>                return model;</TD></TR><TR><TD CLASS="l">375</TD><TD>        }</TD></TR><TR><TD CLASS="l">376</TD><TD> </TD></TR><TR><TD CLASS="l">377</TD><TD>        /**</TD></TR><TR><TD CLASS="l">378</TD><TD>         * This method gets a fresh copy of the data, and repopulates the models</TD></TR><TR><TD CLASS="l">379</TD><TD>         * ... by a call to setText on the structuredDocument. This method is</TD></TR><TR><TD CLASS="l">380</TD><TD>         * needed in some cases where clients are sharing a model and then changes</TD></TR><TR><TD CLASS="l">381</TD><TD>         * canceled. Say for example, one editor and several &#34;displays&#34; are</TD></TR><TR><TD CLASS="l">382</TD><TD>         * sharing a model, if the editor is closed without saving changes, then</TD></TR><TR><TD CLASS="l"><A NAME="c">383</A></TD><TD>         * the displays still need a model, but they should revert to the original</TD></TR><TR><TD CLASS="l">384</TD><TD>         * unsaved version.</TD></TR><TR><TD CLASS="l">385</TD><TD>         */</TD></TR><TR><TD CLASS="l">386</TD><TD>        synchronized public void reload(InputStream inputStream, IStructuredModel structuredModel) {</TD></TR><TR CLASS="z"><TD CLASS="l">387</TD><TD>                documentLoaderInstance = null;</TD></TR><TR><TD CLASS="l">388</TD><TD>                try {</TD></TR><TR><TD CLASS="l">389</TD><TD>                        // temp solution ... we should be able to do better (more</TD></TR><TR><TD CLASS="l">390</TD><TD>                        // efficient) in future.</TD></TR><TR><TD CLASS="l">391</TD><TD>                        // Adapters will (probably) need to be sensitive to the fact that</TD></TR><TR><TD CLASS="l">392</TD><TD>                        // the document instance changed</TD></TR><TR><TD CLASS="l">393</TD><TD>                        // (by being life cycle listeners)</TD></TR><TR CLASS="z"><TD CLASS="l">394</TD><TD>                        load(inputStream, structuredModel, EncodingRule.CONTENT_BASED);</TD></TR><TR><TD CLASS="l">395</TD><TD> </TD></TR><TR><TD CLASS="l">396</TD><TD>                        // // Note: we apparently read the data (and encoding) correctly</TD></TR><TR><TD CLASS="l">397</TD><TD>                        // // before, we just need to make sure we followed the same rule</TD></TR><TR><TD CLASS="l">398</TD><TD>                        // as</TD></TR><TR><TD CLASS="l">399</TD><TD>                        // // before.</TD></TR><TR><TD CLASS="l">400</TD><TD>                        // EncodingMemento previousMemento =</TD></TR><TR><TD CLASS="l">401</TD><TD>                        // structuredModel.getStructuredDocument().getEncodingMemento();</TD></TR><TR><TD CLASS="l">402</TD><TD>                        // EncodingRule previousRule = previousMemento.getEncodingRule();</TD></TR><TR><TD CLASS="l">403</TD><TD>                        // //IFile file = ResourceUtil.getFileFor(structuredModel);</TD></TR><TR><TD CLASS="l">404</TD><TD>                        // // Note: there's opportunity here for some odd behavior, if the</TD></TR><TR><TD CLASS="l">405</TD><TD>                        // // settings have changed from the first load to the reload.</TD></TR><TR><TD CLASS="l">406</TD><TD>                        // But,</TD></TR><TR><TD CLASS="l">407</TD><TD>                        // // hopefully,</TD></TR><TR><TD CLASS="l">408</TD><TD>                        // // will result in the intended behavior.</TD></TR><TR><TD CLASS="l">409</TD><TD>                        // Reader allTextReader =</TD></TR><TR><TD CLASS="l">410</TD><TD>                        // getDocumentLoader().readInputStream(inputStream, previousRule);</TD></TR><TR><TD CLASS="l">411</TD><TD>                        //</TD></TR><TR><TD CLASS="l">412</TD><TD>                        // // TODO: avoid use of String instance</TD></TR><TR><TD CLASS="l">413</TD><TD>                        // getDocumentLoader().reload(structuredModel.getStructuredDocument(),</TD></TR><TR><TD CLASS="l">414</TD><TD>                        // allTextReader);</TD></TR><TR><TD CLASS="l">415</TD><TD>                        // // and now &#34;reset&#34; encoding memento to keep it current with the</TD></TR><TR><TD CLASS="l">416</TD><TD>                        // // one</TD></TR><TR><TD CLASS="l">417</TD><TD>                        // // that was just determined.</TD></TR><TR><TD CLASS="l">418</TD><TD>                        // structuredModel.getStructuredDocument().setEncodingMemento(getDocumentLoader().getEncodingMemento());</TD></TR><TR><TD CLASS="l">419</TD><TD>                        // structuredModel.setDirtyState(false);</TD></TR><TR><TD CLASS="l">420</TD><TD>                        // StructuredTextUndoManager undoMgr =</TD></TR><TR><TD CLASS="l">421</TD><TD>                        // structuredModel.getUndoManager();</TD></TR><TR><TD CLASS="l">422</TD><TD>                        // if (undoMgr != null) {</TD></TR><TR><TD CLASS="l">423</TD><TD>                        // undoMgr.reset();</TD></TR><TR><TD CLASS="l">424</TD><TD>                        // }</TD></TR><TR><TD CLASS="l">425</TD><TD>                }</TD></TR><TR CLASS="z"><TD CLASS="l">426</TD><TD>                catch (UnsupportedEncodingException e) {</TD></TR><TR><TD CLASS="l">427</TD><TD>                        // couldn't happen. The program has apparently</TD></TR><TR><TD CLASS="l">428</TD><TD>                        // read the model once, and there'd be no reason the encoding</TD></TR><TR><TD CLASS="l">429</TD><TD>                        // could not be used again.</TD></TR><TR CLASS="z"><TD CLASS="l">430</TD><TD>                        Logger.logException(&#34;Warning:  XMLLoader::reload.  This exception really should not have happened!! But will attemp to continue after dumping stack trace&#34;, e); //$NON-NLS-1$</TD></TR><TR CLASS="z"><TD CLASS="l">431</TD><TD>                        throw new Error(&#34;Program Error&#34;, e); //$NON-NLS-1$</TD></TR><TR><TD CLASS="l">432</TD><TD>                }</TD></TR><TR CLASS="z"><TD CLASS="l">433</TD><TD>                catch (IOException e) {</TD></TR><TR><TD CLASS="l">434</TD><TD>                        // couldn't happen. The program has apparently</TD></TR><TR><TD CLASS="l">435</TD><TD>                        // read the model once, and there'd be no (common) reason it</TD></TR><TR><TD CLASS="l">436</TD><TD>                        // couldn't be loaded again.</TD></TR><TR CLASS="z"><TD CLASS="l">437</TD><TD>                        Logger.logException(&#34;Warning:  XMLLoader::reload.  This exception really should not have happened!! But will attemp to continue after dumping stack trace&#34;, e); //$NON-NLS-1$</TD></TR><TR CLASS="z"><TD CLASS="l">438</TD><TD>                        throw new Error(&#34;Program Error&#34;, e); //$NON-NLS-1$</TD></TR><TR><TD CLASS="l">439</TD><TD>                }</TD></TR><TR CLASS="z"><TD CLASS="l">440</TD><TD>        }</TD></TR><TR><TD CLASS="l">441</TD><TD> </TD></TR><TR><TD CLASS="l">442</TD><TD>        /**</TD></TR><TR><TD CLASS="l">443</TD><TD>         * this work is done better elsewhere, but done here for this version to</TD></TR><TR><TD CLASS="l">444</TD><TD>         * reduce changes. especially since the need for it should go away once we</TD></TR><TR><TD CLASS="l">445</TD><TD>         * no longer need to re-use old document instance.</TD></TR><TR><TD CLASS="l">446</TD><TD>         */</TD></TR><TR><TD CLASS="l">447</TD><TD>        private void transformInstance(IStructuredDocument oldInstance, IStructuredDocument newInstance) {</TD></TR><TR><TD CLASS="l">448</TD><TD>                /**</TD></TR><TR><TD CLASS="l">449</TD><TD>                 * https://w3.opensource.ibm.com/bugzilla/show_bug.cgi?id=4920</TD></TR><TR><TD CLASS="l">450</TD><TD>                 * </TD></TR><TR><TD CLASS="l"><A NAME="d">451</A></TD><TD>                 * JSP taglib support broken, correct by duplicating extended setup</TD></TR><TR><TD CLASS="l">452</TD><TD>                 * information (BlockTagParser extension,</TD></TR><TR><TD CLASS="l">453</TD><TD>                 * StructuredDocumentRegionParser extensions)</TD></TR><TR><TD CLASS="l">454</TD><TD>                 */</TD></TR><TR CLASS="z"><TD CLASS="l">455</TD><TD>                RegionParser oldParser = oldInstance.getParser();</TD></TR><TR CLASS="z"><TD CLASS="l">456</TD><TD>                RegionParser newParser = newInstance.getParser().newInstance();</TD></TR><TR><TD CLASS="l">457</TD><TD>                // Register all of the old StructuredDocumentRegionHandlers on the new</TD></TR><TR><TD CLASS="l">458</TD><TD>                // parser</TD></TR><TR CLASS="z"><TD CLASS="l">459</TD><TD>                if (oldParser instanceof StructuredDocumentRegionParserExtension &amp;&amp; newParser instanceof StructuredDocumentRegionParserExtension) {</TD></TR><TR CLASS="z"><TD CLASS="l">460</TD><TD>                        List oldHandlers = ((StructuredDocumentRegionParserExtension) oldParser).getStructuredDocumentRegionHandlers();</TD></TR><TR CLASS="z"><TD CLASS="l">461</TD><TD>                        for (int i = 0; i &lt; oldHandlers.size(); i++) {</TD></TR><TR CLASS="z"><TD CLASS="l">462</TD><TD>                                StructuredDocumentRegionHandler handler = ((StructuredDocumentRegionHandler) oldHandlers.get(i));</TD></TR><TR CLASS="z"><TD CLASS="l">463</TD><TD>                                if (handler instanceof StructuredDocumentRegionHandlerExtension) {</TD></TR><TR><TD CLASS="l">464</TD><TD>                                        /**</TD></TR><TR><TD CLASS="l">465</TD><TD>                                         * Skip the transferring here, the handler will do this</TD></TR><TR><TD CLASS="l">466</TD><TD>                                         * after everything else but the source is transferred.</TD></TR><TR><TD CLASS="l">467</TD><TD>                                         */</TD></TR><TR><TD CLASS="l">468</TD><TD>                                }</TD></TR><TR><TD CLASS="l">469</TD><TD>                                else {</TD></TR><TR CLASS="z"><TD CLASS="l">470</TD><TD>                                        ((StructuredDocumentRegionParser) oldParser).removeStructuredDocumentRegionHandler(handler);</TD></TR><TR CLASS="z"><TD CLASS="l">471</TD><TD>                                        ((StructuredDocumentRegionParser) newParser).addStructuredDocumentRegionHandler(handler);</TD></TR><TR CLASS="z"><TD CLASS="l">472</TD><TD>                                        handler.resetNodes();</TD></TR><TR><TD CLASS="l">473</TD><TD>                                }</TD></TR><TR><TD CLASS="l">474</TD><TD>                        }</TD></TR><TR><TD CLASS="l">475</TD><TD>                }</TD></TR><TR><TD CLASS="l">476</TD><TD>                // Add any global BlockMarkers to the new parser</TD></TR><TR CLASS="z"><TD CLASS="l">477</TD><TD>                if (oldParser instanceof BlockTagParser &amp;&amp; newParser instanceof BlockTagParser) {</TD></TR><TR CLASS="z"><TD CLASS="l">478</TD><TD>                        List oldBlockMarkers = ((BlockTagParser) oldParser).getBlockMarkers();</TD></TR><TR CLASS="z"><TD CLASS="l">479</TD><TD>                        for (int i = 0; i &lt; oldBlockMarkers.size(); i++) {</TD></TR><TR CLASS="z"><TD CLASS="l">480</TD><TD>                                BlockMarker blockMarker = ((BlockMarker) oldBlockMarkers.get(i));</TD></TR><TR CLASS="z"><TD CLASS="l">481</TD><TD>                                if (blockMarker.isGlobal()) {</TD></TR><TR CLASS="z"><TD CLASS="l">482</TD><TD>                                        ((BlockTagParser) newParser).addBlockMarker(blockMarker);</TD></TR><TR><TD CLASS="l">483</TD><TD>                                }</TD></TR><TR><TD CLASS="l">484</TD><TD>                        }</TD></TR><TR><TD CLASS="l">485</TD><TD>                }</TD></TR><TR><TD CLASS="l">486</TD><TD> </TD></TR><TR CLASS="z"><TD CLASS="l">487</TD><TD>                ((BasicStructuredDocument) oldInstance).setParser(newParser);</TD></TR><TR><TD CLASS="l">488</TD><TD> </TD></TR><TR CLASS="z"><TD CLASS="l">489</TD><TD>                ((BasicStructuredDocument) oldInstance).setReParser(newInstance.getReParser().newInstance());</TD></TR><TR><TD CLASS="l">490</TD><TD> </TD></TR><TR CLASS="z"><TD CLASS="l">491</TD><TD>                if (newInstance.getDocumentPartitioner() instanceof StructuredTextPartitioner) {</TD></TR><TR CLASS="z"><TD CLASS="l">492</TD><TD>                        StructuredTextPartitioner partitioner = null;</TD></TR><TR CLASS="z"><TD CLASS="l">493</TD><TD>                        if (oldInstance instanceof IDocumentExtension3 &amp;&amp; newInstance instanceof IDocumentExtension3) {</TD></TR><TR CLASS="z"><TD CLASS="l">494</TD><TD>                                partitioner = ((StructuredTextPartitioner) ((IDocumentExtension3) newInstance).getDocumentPartitioner(IStructuredPartitioning.DEFAULT_STRUCTURED_PARTITIONING));</TD></TR><TR CLASS="z"><TD CLASS="l">495</TD><TD>                                if (partitioner != null) {</TD></TR><TR CLASS="z"><TD CLASS="l">496</TD><TD>                                        partitioner = (StructuredTextPartitioner) partitioner.newInstance();</TD></TR><TR><TD CLASS="l">497</TD><TD>                                }</TD></TR><TR CLASS="z"><TD CLASS="l">498</TD><TD>                                ((IDocumentExtension3) oldInstance).setDocumentPartitioner(IStructuredPartitioning.DEFAULT_STRUCTURED_PARTITIONING, partitioner);</TD></TR><TR><TD CLASS="l">499</TD><TD>                        }</TD></TR><TR CLASS="z"><TD CLASS="l">500</TD><TD>                        if (partitioner == null) {</TD></TR><TR CLASS="z"><TD CLASS="l">501</TD><TD>                                partitioner = (StructuredTextPartitioner) ((StructuredTextPartitioner) newInstance.getDocumentPartitioner()).newInstance();</TD></TR><TR CLASS="z"><TD CLASS="l">502</TD><TD>                                oldInstance.setDocumentPartitioner(partitioner);</TD></TR><TR><TD CLASS="l">503</TD><TD>                        }</TD></TR><TR CLASS="z"><TD CLASS="l">504</TD><TD>                        if (partitioner != null) {</TD></TR><TR CLASS="z"><TD CLASS="l">505</TD><TD>                                partitioner.connect(oldInstance);</TD></TR><TR><TD CLASS="l">506</TD><TD>                        }</TD></TR><TR><TD CLASS="l">507</TD><TD>                }</TD></TR><TR><TD CLASS="l">508</TD><TD> </TD></TR><TR CLASS="z"><TD CLASS="l">509</TD><TD>                String existingLineDelimiter = null;</TD></TR><TR><TD CLASS="l">510</TD><TD>                try {</TD></TR><TR CLASS="z"><TD CLASS="l">511</TD><TD>                        existingLineDelimiter = newInstance.getLineDelimiter(0);</TD></TR><TR><TD CLASS="l">512</TD><TD>                }</TD></TR><TR CLASS="z"><TD CLASS="l">513</TD><TD>                catch (BadLocationException e) {</TD></TR><TR><TD CLASS="l">514</TD><TD>                        // if empty file, assume platform default</TD></TR><TR><TD CLASS="l">515</TD><TD>                        // TODO: should be using user set preference, per content type?</TD></TR><TR CLASS="z"><TD CLASS="l">516</TD><TD>                        existingLineDelimiter = System.getProperty(&#34;line.separator&#34;); //$NON-NLS-1$</TD></TR><TR><TD CLASS="l">517</TD><TD>                }</TD></TR><TR><TD CLASS="l">518</TD><TD> </TD></TR><TR CLASS="z"><TD CLASS="l">519</TD><TD>                oldInstance.setLineDelimiter(existingLineDelimiter); //$NON-NLS-1$);</TD></TR><TR CLASS="z"><TD CLASS="l">520</TD><TD>                if (newInstance.getEncodingMemento() != null) {</TD></TR><TR CLASS="z"><TD CLASS="l">521</TD><TD>                        oldInstance.setEncodingMemento((EncodingMemento) newInstance.getEncodingMemento().clone());</TD></TR><TR><TD CLASS="l">522</TD><TD>                }</TD></TR><TR><TD CLASS="l">523</TD><TD> </TD></TR><TR><TD CLASS="l">524</TD><TD>                /**</TD></TR><TR><TD CLASS="l">525</TD><TD>                 * https://w3.opensource.ibm.com/bugzilla/show_bug.cgi?id=4920</TD></TR><TR><TD CLASS="l">526</TD><TD>                 * </TD></TR><TR><TD CLASS="l">527</TD><TD>                 * JSP taglib support broken, correct by duplicating extended setup</TD></TR><TR><TD CLASS="l">528</TD><TD>                 * information (BlockTagParser extension,</TD></TR><TR><TD CLASS="l">529</TD><TD>                 * StructuredDocumentRegionParser extensions)</TD></TR><TR><TD CLASS="l">530</TD><TD>                 */</TD></TR><TR CLASS="z"><TD CLASS="l">531</TD><TD>                if (oldParser instanceof StructuredDocumentRegionParserExtension &amp;&amp; newParser instanceof StructuredDocumentRegionParserExtension) {</TD></TR><TR CLASS="z"><TD CLASS="l">532</TD><TD>                        List oldHandlers = ((StructuredDocumentRegionParserExtension) oldParser).getStructuredDocumentRegionHandlers();</TD></TR><TR CLASS="z"><TD CLASS="l">533</TD><TD>                        for (int i = 0; i &lt; oldHandlers.size(); i++) {</TD></TR><TR CLASS="z"><TD CLASS="l">534</TD><TD>                                StructuredDocumentRegionHandler handler = ((StructuredDocumentRegionHandler) oldHandlers.get(i));</TD></TR><TR CLASS="z"><TD CLASS="l">535</TD><TD>                                if (handler instanceof StructuredDocumentRegionHandlerExtension) {</TD></TR><TR CLASS="z"><TD CLASS="l">536</TD><TD>                                        StructuredDocumentRegionHandlerExtension handlerExtension = (StructuredDocumentRegionHandlerExtension) handler;</TD></TR><TR CLASS="z"><TD CLASS="l">537</TD><TD>                                        handlerExtension.setStructuredDocument(oldInstance);</TD></TR><TR><TD CLASS="l">538</TD><TD>                                }</TD></TR><TR><TD CLASS="l">539</TD><TD>                        }</TD></TR><TR><TD CLASS="l">540</TD><TD>                }</TD></TR><TR CLASS="z"><TD CLASS="l">541</TD><TD>                String holdString = newInstance.get();</TD></TR><TR CLASS="z"><TD CLASS="l">542</TD><TD>                newInstance = null;</TD></TR><TR CLASS="z"><TD CLASS="l">543</TD><TD>                oldInstance.set(holdString);</TD></TR><TR CLASS="z"><TD CLASS="l">544</TD><TD>        }</TD></TR><TR><TD CLASS="l">545</TD><TD>}</TD></TR></TABLE><P></P><TABLE CLASS="hdft" CELLSPACING="0" WIDTH="100%"><TR><TD CLASS="nv">[<A HREF="../xslUnitTestCoverage.html">all classes</A>][<A HREF="96.html">org.eclipse.wst.sse.core.internal.model</A>]</TD></TR><TR><TD CLASS="tl"><A HREF="http://www.eclemma.org/support.html">EMMA 2.0.5312 EclEmma Fix 1</A> (C) Vladimir Roubtsov</TD></TR></TABLE></BODY></HTML>