KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > core > build > BuildModel


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.core.build;
12
13 import java.io.IOException JavaDoc;
14 import java.io.InputStream JavaDoc;
15 import java.util.Enumeration JavaDoc;
16 import java.util.Properties JavaDoc;
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 JavaDoc source, boolean outOfSync) {
55         Properties JavaDoc properties = new Properties JavaDoc();
56         try {
57             properties.load(source);
58             if (!outOfSync)
59                 updateTimeStamp();
60         } catch (IOException JavaDoc e) {
61             PDECore.logException(e);
62             return;
63         }
64         fBuild = new Build();
65         fBuild.setModel(this);
66         for (Enumeration JavaDoc names = properties.propertyNames(); names.hasMoreElements();) {
67             String JavaDoc name = names.nextElement().toString();
68             fBuild.processEntry(name, (String JavaDoc) properties.get(name));
69         }
70         setLoaded(true);
71     }
72
73     public void reload(InputStream JavaDoc 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 JavaDoc[0], null));
83     }
84 }
85
Popular Tags