KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > oc4j > config > EarDeploymentConfiguration


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.j2ee.oc4j.config;
21
22 import java.io.File JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.io.OutputStream JavaDoc;
25 import javax.enterprise.deploy.model.DeployableObject JavaDoc;
26 import javax.enterprise.deploy.spi.exceptions.ConfigurationException JavaDoc;
27 import org.netbeans.modules.j2ee.oc4j.config.gen.OrionApplication;
28 import org.openide.ErrorManager;
29 import org.openide.filesystems.FileUtil;
30 import org.openide.loaders.DataObjectNotFoundException;
31
32 /**
33  * EAR application deployment configuration handles orion-application.xml configuration
34  * file creation.
35  *
36  * @author sherold
37  */

38 public class EarDeploymentConfiguration extends OC4JDeploymentConfiguration {
39     
40     private File JavaDoc file;
41     private OrionApplication orionApplication;
42         
43     /**
44      * Creates a new instance of EarDeploymentConfiguration
45      */

46     public EarDeploymentConfiguration(DeployableObject JavaDoc deployableObject) {
47         super(deployableObject);
48     }
49     
50     /**
51      * EarDeploymentConfiguration initialization. This method should be called before
52      * this class is being used.
53      *
54      * @param file orion-application.xml file.
55      */

56     public void init(File JavaDoc file, File JavaDoc resourceDir) {
57         super.init(resourceDir);
58         this.file = file;
59         getOC4JApplication();
60         if (dataObject == null) {
61             try {
62                 dataObject = dataObject.find(FileUtil.toFileObject(file));
63             } catch(DataObjectNotFoundException donfe) {
64                 ErrorManager.getDefault().notify(donfe);
65             }
66         }
67     }
68        
69     /**
70      * Return oc4jApplication graph. If it was not created yet, load it from the file
71      * and cache it. If the file does not exist, generate it.
72      *
73      * @return weblogicApplication graph or null if the weblogic-application.xml file is not parseable.
74      */

75     public synchronized OrionApplication getOC4JApplication() {
76         if (orionApplication == null) {
77             try {
78                 if (file.exists()) {
79                     // load configuration if already exists
80
try {
81                         orionApplication = orionApplication.createGraph(file);
82                     } catch (IOException JavaDoc ioe) {
83                         ErrorManager.getDefault().notify(ioe);
84                     } catch (RuntimeException JavaDoc re) {
85                         // orion-application.xml is not parseable, do nothing
86
}
87                 } else {
88                     // create orion-application.xml if it does not exist yet
89
orionApplication = genereateOC4JApplication();
90                     writefile(file, orionApplication);
91                 }
92             } catch (ConfigurationException JavaDoc ce) {
93                 ErrorManager.getDefault().notify(ce);
94             }
95         }
96         return orionApplication;
97     }
98     
99     // JSR-88 methods ---------------------------------------------------------
100

101     public void save(OutputStream JavaDoc os) throws ConfigurationException JavaDoc {
102         OrionApplication orionApplication = getOC4JApplication();
103         if (orionApplication == null) {
104             throw new ConfigurationException JavaDoc("Cannot read configuration, it is probably in an inconsistent state."); // NOI18N
105
}
106         try {
107             orionApplication.write(os);
108         } catch (IOException JavaDoc ioe) {
109             throw new ConfigurationException JavaDoc(ioe.getLocalizedMessage());
110         }
111     }
112     
113     // private helper methods -------------------------------------------------
114

115     /**
116      * Genereate Context graph.
117      */

118     private OrionApplication genereateOC4JApplication() {
119         return new OrionApplication();
120     }
121 }
Popular Tags