KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > core > site > AbstractSiteBuildModel


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

11 package org.eclipse.pde.internal.core.site;
12
13 import java.io.*;
14
15 import javax.xml.parsers.*;
16
17 import org.eclipse.core.runtime.*;
18 import org.eclipse.pde.core.*;
19 import org.eclipse.pde.internal.core.*;
20 import org.eclipse.pde.internal.core.isite.*;
21 import org.w3c.dom.*;
22
23 public abstract class AbstractSiteBuildModel
24     extends AbstractModel
25     implements ISiteBuildModel {
26     protected transient SiteBuild siteBuild;
27
28     public AbstractSiteBuildModel() {
29     }
30
31     public ISiteBuild getSiteBuild() {
32         if (siteBuild == null) {
33             SiteBuild s = new SiteBuild();
34             s.model = this;
35             this.siteBuild= s;
36         }
37         return siteBuild;
38     }
39     
40     public ISiteBuild createSiteBuild() {
41         SiteBuild s = new SiteBuild();
42         s.model = this;
43         s.parent = null;
44         return s;
45     }
46     
47     public ISiteBuildFeature createFeature() {
48         SiteBuildFeature f = new SiteBuildFeature();
49         f.model = this;
50         f.parent = getSiteBuild();
51         return f;
52     }
53
54     public String JavaDoc getInstallLocation() {
55         return null;
56     }
57     public boolean isEditable() {
58         return true;
59     }
60     public boolean isEnabled() {
61         return true;
62     }
63     public void load(InputStream stream, boolean outOfSync) throws CoreException {
64         try {
65             SAXParser parser = getSaxParser();
66             XMLDefaultHandler handler = new XMLDefaultHandler();
67             parser.setProperty("http://xml.org/sax/properties/lexical-handler", handler); //$NON-NLS-1$
68
parser.parse(stream, handler);
69             processDocument(handler.getDocument());
70             loaded = true;
71             if (!outOfSync)
72                 updateTimeStamp();
73         } catch (Exception JavaDoc e) {
74             throwParseErrorsException(e);
75         }
76     }
77
78     private void processDocument(Document doc) {
79         Node rootNode = doc.getDocumentElement();
80         if (siteBuild == null) {
81             siteBuild = new SiteBuild();
82             siteBuild.model = this;
83         } else {
84             siteBuild.reset();
85         }
86         siteBuild.parse(rootNode);
87     }
88     public void reload(InputStream stream, boolean outOfSync)
89         throws CoreException {
90         if (siteBuild != null)
91             siteBuild.reset();
92         load(stream, outOfSync);
93         fireModelChanged(
94             new ModelChangedEvent(this,
95                 IModelChangedEvent.WORLD_CHANGED,
96                 new Object JavaDoc[] { siteBuild },
97                 null));
98     }
99     public boolean isReconcilingModel() {
100         return false;
101     }
102 }
103
Popular Tags