1 11 12 package org.eclipse.pde.internal.core.cheatsheet.simple; 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.simple.ISimpleCS; 26 import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSModel; 27 import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSModelFactory; 28 import org.w3c.dom.Document ; 29 import org.w3c.dom.Element ; 30 31 35 public class SimpleCSModel extends AbstractModel implements ISimpleCSModel { 36 37 private ISimpleCSModelFactory fFactory; 38 39 private ISimpleCS fSimpleCS; 40 41 44 private static final long serialVersionUID = 1L; 45 46 49 public SimpleCSModel() { 50 } 52 53 56 protected void updateTimeStamp() { 57 } 59 60 63 public ISimpleCSModelFactory getFactory() { 64 if (fFactory == null) { 65 fFactory = new SimpleCSModelFactory(this); 66 } 67 return fFactory; 68 } 69 70 73 public ISimpleCS getSimpleCS() { 74 if (fSimpleCS == null) { 75 fSimpleCS = getFactory().createSimpleCS(); 76 } 77 return fSimpleCS; 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 try { 100 SAXParser parser = getSaxParser(); 101 XMLDefaultHandler handler = new XMLDefaultHandler(); 102 parser.parse(source, handler); 103 if (handler.isPrepared()) { 104 processDocument(handler.getDocument()); 105 setLoaded(true); 106 } 107 } catch (Exception e) { 108 setException(e); 109 PDECore.logException(e); 110 } finally { 111 try { 112 if (source != null) 113 source.close(); 114 } catch (IOException e) { 115 } 116 } 117 } 118 119 122 public void reload(InputStream source, boolean outOfSync) 123 throws CoreException { 124 load(source, outOfSync); 125 fireModelChanged( 126 new ModelChangedEvent(this, 127 IModelChangedEvent.WORLD_CHANGED, 128 new Object [] { fSimpleCS }, 129 null)); 130 } 131 132 135 public boolean isEditable() { 136 return false; 137 } 138 139 142 private void processDocument(Document doc) { 143 Element rootNode = doc.getDocumentElement(); 144 if (fSimpleCS == null) { 145 fSimpleCS = getFactory().createSimpleCS(); 146 } else { 147 fSimpleCS.reset(); 148 } 149 fSimpleCS.parse(rootNode); 150 } 151 152 } 153 | Popular Tags |