KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > core > product > ProductModel


1 /*******************************************************************************
2  * Copyright (c) 2005, 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.product;
12
13 import java.io.IOException JavaDoc;
14 import java.io.InputStream JavaDoc;
15
16 import javax.xml.parsers.SAXParser JavaDoc;
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 JavaDoc;
28 import org.w3c.dom.Node JavaDoc;
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     /* (non-Javadoc)
39      * @see org.eclipse.pde.internal.core.AbstractModel#updateTimeStamp()
40      */

41     protected void updateTimeStamp() {
42     }
43
44     /* (non-Javadoc)
45      * @see org.eclipse.pde.internal.core.iproduct.IProductModel#getProduct()
46      */

47     public IProduct getProduct() {
48         if (fProduct == null)
49             fProduct = getFactory().createProduct();
50         return fProduct;
51     }
52
53     /* (non-Javadoc)
54      * @see org.eclipse.pde.internal.core.iproduct.IProductModel#getFactory()
55      */

56     public IProductModelFactory getFactory() {
57         if (fFactory == null)
58             fFactory = new ProductModelFactory(this);
59         return fFactory;
60     }
61
62     /* (non-Javadoc)
63      * @see org.eclipse.pde.internal.core.iproduct.IProductModel#getInstallLocation()
64      */

65     public String JavaDoc getInstallLocation() {
66         return null;
67     }
68
69     /* (non-Javadoc)
70      * @see org.eclipse.pde.core.IModel#isInSync()
71      */

72     public boolean isInSync() {
73         return true;
74     }
75
76     /* (non-Javadoc)
77      * @see org.eclipse.pde.core.IModel#load()
78      */

79     public void load() throws CoreException {
80     }
81
82     /* (non-Javadoc)
83      * @see org.eclipse.pde.core.IModel#load(java.io.InputStream, boolean)
84      */

85     public void load(InputStream JavaDoc stream, boolean outOfSync)
86             throws CoreException {
87         try {
88             SAXParser JavaDoc 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 JavaDoc e) {
96             PDECore.logException(e);
97         } finally {
98             try {
99                 if (stream != null)
100                     stream.close();
101             } catch (IOException JavaDoc e) {
102             }
103         }
104     }
105
106     /* (non-Javadoc)
107      * @see org.eclipse.pde.core.IModel#reload(java.io.InputStream, boolean)
108      */

109     public void reload(InputStream JavaDoc source, boolean outOfSync)
110             throws CoreException {
111         load(source, outOfSync);
112         fireModelChanged(
113                 new ModelChangedEvent(this,
114                     IModelChangedEvent.WORLD_CHANGED,
115                     new Object JavaDoc[] { fProduct },
116                     null));
117     }
118
119     /* (non-Javadoc)
120      * @see org.eclipse.pde.core.IBaseModel#isEditable()
121      */

122     public boolean isEditable() {
123         return false;
124     }
125     
126     private void processDocument(Document JavaDoc doc) {
127         Node JavaDoc 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