KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > update > standalone > AddSiteCommand


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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.update.standalone;
12 import java.io.*;
13 import java.net.*;
14
15 import org.eclipse.core.runtime.*;
16 import org.eclipse.update.configuration.*;
17 import org.eclipse.update.core.*;
18 import org.eclipse.update.internal.core.*;
19 import org.eclipse.update.operations.*;
20
21 /**
22  * Command to add a new product extension site.
23  * <p>
24  * <b>Note:</b> This class/interface is part of an interim API that is still under development and expected to
25  * change significantly before reaching stability. It is being made available at this early stage to solicit feedback
26  * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken
27  * (repeatedly) as the API evolves.
28  * </p>
29  * @since 3.0
30  */

31 public class AddSiteCommand extends ScriptedCommand {
32     private ISite site;
33     private File sitePath;
34     
35     /**
36      * @param fromSite if specified, list only the features from the specified local install site
37      */

38     public AddSiteCommand(String JavaDoc fromSite) throws Exception JavaDoc {
39         try {
40             if (fromSite != null) {
41                 sitePath = new File(fromSite);
42                 if (!sitePath.exists())
43                     throw new Exception JavaDoc(Messages.Standalone_noSite + fromSite);
44                     
45                 URL fromSiteURL = sitePath.toURL();
46                 site = SiteManager.getSite(fromSiteURL, null);
47                 if (site == null) {
48                     throw new Exception JavaDoc(Messages.Standalone_noSite + fromSite);
49                 }
50                 IConfiguredSite csite = site.getCurrentConfiguredSite();
51                 if (csite != null)
52                     throw new Exception JavaDoc(Messages.Standalone_siteConfigured + fromSite);
53             } else {
54                 throw new Exception JavaDoc(Messages.Standalone_noSite3 );
55             }
56         } catch (Exception JavaDoc e) {
57             throw e;
58         }
59     }
60
61     /**
62      */

63     public boolean run(IProgressMonitor monitor) {
64         // check if the config file has been modifed while we were running
65
IStatus status = OperationsManager.getValidator().validatePlatformConfigValid();
66         if (status != null) {
67             UpdateCore.log(status);
68             return false;
69         }
70         
71         if (site == null)
72             return false;
73             
74         try {
75             IConfiguredSite csite = getConfiguration().createConfiguredSite(sitePath);
76             getConfiguration().addConfiguredSite(csite);
77             // update the sites array to pick up new site
78
getConfiguration().getConfiguredSites();
79             SiteManager.getLocalSite().save();
80             return true;
81         } catch (CoreException e) {
82             UpdateCore.log(e);
83             return false;
84         }
85     }
86 }
87
Popular Tags