1 11 12 package org.eclipse.pde.internal.core.cheatsheet.comp; 13 14 import java.io.IOException ; 15 import java.io.InputStream ; 16 17 import javax.xml.parsers.SAXParser ; 18 19 import org.eclipse.core.runtime.CoreException; 20 import org.eclipse.pde.core.IModelChangedEvent; 21 import org.eclipse.pde.core.ModelChangedEvent; 22 import org.eclipse.pde.internal.core.AbstractModel; 23 import org.eclipse.pde.internal.core.PDECore; 24 import org.eclipse.pde.internal.core.XMLDefaultHandler; 25 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCS; 26 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSModel; 27 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSModelFactory; 28 import org.w3c.dom.Document ; 29 import org.w3c.dom.Element ; 30 31 35 public class CompCSModel extends AbstractModel implements ICompCSModel { 36 37 private ICompCSModelFactory fFactory; 38 39 private ICompCS fCompCS; 40 41 44 private static final long serialVersionUID = 1L; 45 46 49 public CompCSModel() { 50 } 52 53 56 protected void updateTimeStamp() { 57 } 59 60 63 public ICompCS getCompCS() { 64 if (fCompCS == null) { 65 fCompCS = getFactory().createCompCS(); 66 } 67 return fCompCS; 68 } 69 70 73 public ICompCSModelFactory getFactory() { 74 if (fFactory == null) { 75 fFactory = new CompCSModelFactory(this); 76 } 77 return fFactory; 78 } 79 80 83 public boolean isInSync() { 84 return true; 85 } 86 87 90 public void load() throws CoreException { 91 } 93 94 97 public void load(InputStream source, boolean outOfSync) 98 throws CoreException { 99 100 try { 101 SAXParser parser = getSaxParser(); 102 XMLDefaultHandler handler = new XMLDefaultHandler(); 103 parser.parse(source, handler); 104 if (handler.isPrepared()) { 105 processDocument(handler.getDocument()); 106 setLoaded(true); 107 } 108 } catch (Exception e) { 109 setException(e); 110 PDECore.logException(e); 111 } finally { 112 try { 113 if (source != null) { 114 source.close(); 115 } 116 } catch (IOException e) { 117 } 119 } 120 121 } 122 123 126 public void reload(InputStream source, boolean outOfSync) 127 throws CoreException { 128 129 load(source, outOfSync); 130 fireModelChanged( 131 new ModelChangedEvent(this, 132 IModelChangedEvent.WORLD_CHANGED, 133 new Object [] { fCompCS }, 134 null)); 135 } 136 137 140 public boolean isEditable() { 141 return false; 142 } 143 144 147 private void processDocument(Document doc) { 148 Element rootNode = doc.getDocumentElement(); 149 if (fCompCS == null) { 150 fCompCS = getFactory().createCompCS(); 151 } else { 152 fCompCS.reset(); 153 } 154 fCompCS.parse(rootNode); 155 } 156 157 } 158 | Popular Tags |