1 11 package org.eclipse.pde.internal.core.product; 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.iproduct.IProduct; 25 import org.eclipse.pde.internal.core.iproduct.IProductModel; 26 import org.eclipse.pde.internal.core.iproduct.IProductModelFactory; 27 import org.w3c.dom.Document ; 28 import org.w3c.dom.Node ; 29 30 31 public class ProductModel extends AbstractModel implements IProductModel { 32 33 private static final long serialVersionUID = 1L; 34 35 private IProductModelFactory fFactory; 36 private IProduct fProduct; 37 38 41 protected void updateTimeStamp() { 42 } 43 44 47 public IProduct getProduct() { 48 if (fProduct == null) 49 fProduct = getFactory().createProduct(); 50 return fProduct; 51 } 52 53 56 public IProductModelFactory getFactory() { 57 if (fFactory == null) 58 fFactory = new ProductModelFactory(this); 59 return fFactory; 60 } 61 62 65 public String getInstallLocation() { 66 return null; 67 } 68 69 72 public boolean isInSync() { 73 return true; 74 } 75 76 79 public void load() throws CoreException { 80 } 81 82 85 public void load(InputStream stream, boolean outOfSync) 86 throws CoreException { 87 try { 88 SAXParser parser = getSaxParser(); 89 XMLDefaultHandler handler = new XMLDefaultHandler(); 90 parser.parse(stream, handler); 91 if (handler.isPrepared()) { 92 processDocument(handler.getDocument()); 93 setLoaded(true); 94 } 95 } catch (Exception e) { 96 PDECore.logException(e); 97 } finally { 98 try { 99 if (stream != null) 100 stream.close(); 101 } catch (IOException e) { 102 } 103 } 104 } 105 106 109 public void reload(InputStream source, boolean outOfSync) 110 throws CoreException { 111 load(source, outOfSync); 112 fireModelChanged( 113 new ModelChangedEvent(this, 114 IModelChangedEvent.WORLD_CHANGED, 115 new Object [] { fProduct }, 116 null)); 117 } 118 119 122 public boolean isEditable() { 123 return false; 124 } 125 126 private void processDocument(Document doc) { 127 Node rootNode = doc.getDocumentElement(); 128 if (fProduct == null) { 129 fProduct = getFactory().createProduct(); 130 } else { 131 fProduct.reset(); 132 } 133 fProduct.parse(rootNode); 134 } 135 } 136 | Popular Tags |