KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > jboss4 > 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.jboss4.config;
21 import java.io.File JavaDoc;
22 import java.io.IOException JavaDoc;
23 import java.io.OutputStream JavaDoc;
24 import javax.enterprise.deploy.model.DeployableObject JavaDoc;
25 import javax.enterprise.deploy.spi.exceptions.ConfigurationException JavaDoc;
26 import org.netbeans.modules.j2ee.jboss4.config.gen.JbossApp;
27 import org.openide.ErrorManager;
28 import org.openide.filesystems.FileUtil;
29 import org.openide.loaders.DataObjectNotFoundException;
30
31
32 /**
33  * EAR application deployment configuration handles jboss-app.xml configuration
34  * file creation.
35  *
36  * @author sherold
37  */

38 public class EarDeploymentConfiguration extends JBDeploymentConfiguration {
39     
40     private File JavaDoc jbossAppFile;
41     private JbossApp jbossApp;
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 jboss-app.xml file.
55      */

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

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

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

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

117     private JbossApp genereatejbossApp() {
118         return new JbossApp();
119     }
120 }
121
Popular Tags