KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > weblogic9 > config > EjbDeploymentConfiguration


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.WeblogicEjbJar;
28 import org.openide.ErrorManager;
29 import org.openide.filesystems.FileUtil;
30 import org.openide.loaders.DataObjectNotFoundException;
31
32
33 /**
34  * EJB module deployment configuration handles weblogic-ejb-jar.xml configuration file creation.
35  *
36  * @author sherold
37  */

38 public class EjbDeploymentConfiguration extends WLDeploymentConfiguration {
39     
40     private File JavaDoc file;
41     private WeblogicEjbJar weblogicEjbJar;
42         
43     /**
44      * Creates a new instance of EjbDeploymentConfiguration
45      */

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

56     public void init(File JavaDoc file) {
57         this.file = file;
58         getWeblogicEjbJar();
59         if (dataObject == null) {
60             try {
61                 dataObject = dataObject.find(FileUtil.toFileObject(file));
62             } catch(DataObjectNotFoundException donfe) {
63                 ErrorManager.getDefault().notify(donfe);
64             }
65         }
66     }
67        
68     /**
69      * Return WeblogicEjbJar 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 WeblogicEjbJar graph or null if the weblogic-ejb-jar.xml file is not parseable.
73      */

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

100     public void save(OutputStream JavaDoc os) throws ConfigurationException JavaDoc {
101         WeblogicEjbJar weblogicEjbJar = getWeblogicEjbJar();
102         if (weblogicEjbJar == null) {
103             throw new ConfigurationException JavaDoc("Cannot read configuration, it is probably in an inconsistent state."); // NOI18N
104
}
105         try {
106             weblogicEjbJar.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 WeblogicEjbJar graph.
116      */

117     private WeblogicEjbJar genereateWeblogicEjbJar() {
118         return new WeblogicEjbJar();
119     }
120 }
121
Popular Tags