1 11 package org.eclipse.pde.internal.core.target; 12 13 import java.io.IOException ; 14 import java.io.InputStream ; 15 16 import javax.xml.parsers.SAXParser ; 17 18 import org.eclipse.core.runtime.CoreException; 19 import org.eclipse.pde.core.IModelChangedEvent; 20 import org.eclipse.pde.core.ModelChangedEvent; 21 import org.eclipse.pde.internal.core.AbstractModel; 22 import org.eclipse.pde.internal.core.PDECore; 23 import org.eclipse.pde.internal.core.XMLDefaultHandler; 24 import org.eclipse.pde.internal.core.itarget.ITarget; 25 import org.eclipse.pde.internal.core.itarget.ITargetModel; 26 import org.eclipse.pde.internal.core.itarget.ITargetModelFactory; 27 import org.w3c.dom.Document ; 28 import org.w3c.dom.Node ; 29 30 public class TargetModel extends AbstractModel implements ITargetModel { 31 32 private static final long serialVersionUID = 1L; 33 34 private ITargetModelFactory fFactory; 35 private ITarget fTarget; 36 37 protected void updateTimeStamp() { 38 } 39 40 public ITarget getTarget() { 41 if (fTarget == null) 42 fTarget = getFactory().createTarget(); 43 return fTarget; 44 } 45 46 public ITargetModelFactory getFactory() { 47 if (fFactory == null) 48 fFactory = new TargetModelFactory(this); 49 return fFactory; 50 } 51 52 public String getInstallLocation() { 53 return null; 54 } 55 56 public boolean isInSync() { 57 return true; 58 } 59 60 public void load() throws CoreException { 61 } 62 63 public void load(InputStream stream, boolean outOfSync) throws CoreException { 64 try { 65 SAXParser parser = getSaxParser(); 66 XMLDefaultHandler handler = new XMLDefaultHandler(); 67 parser.parse(stream, handler); 68 if (handler.isPrepared()) { 69 processDocument(handler.getDocument()); 70 setLoaded(true); 71 } 72 } catch (Exception e) { 73 PDECore.logException(e); 74 } finally { 75 try { 76 if (stream != null) 77 stream.close(); 78 } catch (IOException e) { 79 } 80 } 81 } 82 83 public void reload(InputStream source, boolean outOfSync) throws CoreException { 84 load(source, outOfSync); 85 fireModelChanged( 86 new ModelChangedEvent(this, 87 IModelChangedEvent.WORLD_CHANGED, 88 new Object [] { fTarget }, 89 null)); 90 } 91 92 public boolean isEditable() { 93 return false; 94 } 95 96 private void processDocument(Document doc) { 97 Node rootNode = doc.getDocumentElement(); 98 if (fTarget == null) { 99 fTarget = getFactory().createTarget(); 100 } else { 101 fTarget.reset(); 102 } 103 fTarget.parse(rootNode); 104 } 105 106 107 } 108 | Popular Tags |