KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > weblogic9 > 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.weblogic9.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.weblogic9.config.gen.WeblogicApplication;
28 import org.openide.ErrorManager;
29 import org.openide.filesystems.FileUtil;
30 import org.openide.loaders.DataObjectNotFoundException;
31
32
33 /**
34  * EAR application deployment configuration handles weblogic-application.xml configuration
35  * file creation.
36  *
37  * @author sherold
38  */

39 public class EarDeploymentConfiguration extends WLDeploymentConfiguration {
40     
41     private File JavaDoc file;
42     private WeblogicApplication weblogicApplication;
43         
44     /**
45      * Creates a new instance of EarDeploymentConfiguration
46      */

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

57     public void init(File JavaDoc file) {
58         this.file = file;
59         getWeblogicApplication();
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 weblogicApplication 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 WeblogicApplication getWeblogicApplication() {
76         if (weblogicApplication == null) {
77             try {
78                 if (file.exists()) {
79                     // load configuration if already exists
80
try {
81                         weblogicApplication = weblogicApplication.createGraph(file);
82                     } catch (IOException JavaDoc ioe) {
83                         ErrorManager.getDefault().notify(ioe);
84                     } catch (RuntimeException JavaDoc re) {
85                         // weblogic-application.xml is not parseable, do nothing
86
}
87                 } else {
88                     // create weblogic-application.xml if it does not exist yet
89
weblogicApplication = genereateweblogicApplication();
90                     writefile(file, weblogicApplication);
91                 }
92             } catch (ConfigurationException JavaDoc ce) {
93                 ErrorManager.getDefault().notify(ce);
94             }
95         }
96         return weblogicApplication;
97     }
98     
99     // JSR-88 methods ---------------------------------------------------------
100

101     public void save(OutputStream JavaDoc os) throws ConfigurationException JavaDoc {
102         WeblogicApplication weblogicApplication = getWeblogicApplication();
103         if (weblogicApplication == null) {
104             throw new ConfigurationException JavaDoc("Cannot read configuration, it is probably in an inconsistent state."); // NOI18N
105
}
106         try {
107             weblogicApplication.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 WeblogicApplication genereateweblogicApplication() {
119         return new WeblogicApplication();
120     }
121 }
122
Popular Tags