1 11 package org.eclipse.pde.internal.core.build; 12 13 import java.io.IOException ; 14 import java.io.InputStream ; 15 import java.util.Enumeration ; 16 import java.util.Properties ; 17 18 import org.eclipse.pde.core.IModelChangedEvent; 19 import org.eclipse.pde.core.ModelChangedEvent; 20 import org.eclipse.pde.core.build.IBuild; 21 import org.eclipse.pde.core.build.IBuildModel; 22 import org.eclipse.pde.core.build.IBuildModelFactory; 23 import org.eclipse.pde.internal.core.AbstractModel; 24 import org.eclipse.pde.internal.core.PDECore; 25 26 public abstract class BuildModel extends AbstractModel implements IBuildModel { 27 protected Build fBuild; 28 29 private BuildModelFactory fFactory; 30 31 public IBuild getBuild() { 32 if (isLoaded() == false) 33 load(); 34 return fBuild; 35 } 36 37 public IBuild getBuild(boolean createIfMissing) { 38 if (fBuild == null && createIfMissing) { 39 fBuild = new Build(); 40 fBuild.setModel(this); 41 setLoaded(true); 42 } 43 return getBuild(); 44 } 45 46 public IBuildModelFactory getFactory() { 47 if (fFactory == null) 48 fFactory = new BuildModelFactory(this); 49 return fFactory; 50 } 51 52 public abstract void load(); 53 54 public void load(InputStream source, boolean outOfSync) { 55 Properties properties = new Properties (); 56 try { 57 properties.load(source); 58 if (!outOfSync) 59 updateTimeStamp(); 60 } catch (IOException e) { 61 PDECore.logException(e); 62 return; 63 } 64 fBuild = new Build(); 65 fBuild.setModel(this); 66 for (Enumeration names = properties.propertyNames(); names.hasMoreElements();) { 67 String name = names.nextElement().toString(); 68 fBuild.processEntry(name, (String ) properties.get(name)); 69 } 70 setLoaded(true); 71 } 72 73 public void reload(InputStream source, boolean outOfSync) { 74 if (fBuild != null) 75 fBuild.reset(); 76 else { 77 fBuild = new Build(); 78 fBuild.setModel(this); 79 } 80 load(source, outOfSync); 81 fireModelChanged(new ModelChangedEvent(this, 82 IModelChangedEvent.WORLD_CHANGED, new Object [0], null)); 83 } 84 } 85 | Popular Tags |