KickJava   Java API By Example, From Geeks To Geeks.

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


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.BufferedOutputStream JavaDoc;
23 import java.io.File JavaDoc;
24 import java.io.IOException JavaDoc;
25 import java.io.InputStream JavaDoc;
26 import java.io.OutputStream JavaDoc;
27 import javax.enterprise.deploy.model.DDBeanRoot JavaDoc;
28 import javax.enterprise.deploy.model.DeployableObject JavaDoc;
29 import javax.enterprise.deploy.spi.DConfigBeanRoot JavaDoc;
30 import javax.enterprise.deploy.spi.DeploymentConfiguration JavaDoc;
31 import javax.enterprise.deploy.spi.exceptions.BeanNotFoundException JavaDoc;
32 import javax.enterprise.deploy.spi.exceptions.ConfigurationException JavaDoc;
33 import org.netbeans.modules.schema2beans.BaseBean;
34 import org.openide.filesystems.FileLock;
35 import org.openide.filesystems.FileObject;
36 import org.openide.filesystems.FileSystem;
37 import org.openide.filesystems.FileUtil;
38 import org.openide.loaders.DataObject;
39 import org.openide.util.NbBundle;
40
41 /**
42  * Base for WebLogic DeploymentConfiguration implementations.
43  *
44  * @author sherold
45  */

46 public abstract class WLDeploymentConfiguration implements DeploymentConfiguration JavaDoc {
47     
48     protected DeployableObject JavaDoc deplObj;
49     protected DataObject dataObject;
50     
51     /**
52      * Creates a new instance of WLDeploymentConfiguration
53      */

54     public WLDeploymentConfiguration (DeployableObject JavaDoc deplObj) {
55         this.deplObj = deplObj;
56     }
57     
58     public DataObject getDataObject() {
59         return dataObject;
60     }
61     
62     // JSR-88 methods ---------------------------------------------------------
63

64     public DeployableObject JavaDoc getDeployableObject () {
65         return deplObj;
66     }
67     
68     // JSR-88 methods empty implementation ------------------------------------
69

70     public DConfigBeanRoot JavaDoc getDConfigBeanRoot (DDBeanRoot JavaDoc dDBeanRoot)
71     throws ConfigurationException JavaDoc {
72         return null;
73     }
74     
75     public void removeDConfigBean (DConfigBeanRoot JavaDoc dConfigBeanRoot)
76     throws BeanNotFoundException JavaDoc {
77         throw new BeanNotFoundException JavaDoc ("bean not found " + dConfigBeanRoot); // NOI18N
78
}
79     
80     public void restore (InputStream JavaDoc is)
81     throws ConfigurationException JavaDoc {
82     }
83     
84     public DConfigBeanRoot JavaDoc restoreDConfigBean (InputStream JavaDoc is, DDBeanRoot JavaDoc dDBeanRoot)
85     throws ConfigurationException JavaDoc {
86         return null;
87     }
88     
89     public void saveDConfigBean (OutputStream JavaDoc os, DConfigBeanRoot JavaDoc dConfigBeanRoot)
90     throws ConfigurationException JavaDoc {
91     }
92     
93     // helper methods -------------------------------------------------
94

95     protected void writefile(final File JavaDoc file, final BaseBean bean) throws ConfigurationException JavaDoc {
96         try {
97             FileObject cfolder = FileUtil.toFileObject(file.getParentFile());
98             if (cfolder == null) {
99                 File JavaDoc parentFile = file.getParentFile();
100                 try {
101                     cfolder = FileUtil.toFileObject(parentFile.getParentFile()).createFolder(parentFile.getName());
102                 } catch (IOException JavaDoc ioe) {
103                     throw new ConfigurationException JavaDoc(NbBundle.getMessage(WLDeploymentConfiguration.class, "MSG_FailedToCreateConfigFolder", parentFile.getAbsolutePath()));
104                 }
105             }
106             final FileObject folder = cfolder;
107             FileSystem fs = folder.getFileSystem();
108             fs.runAtomicAction(new FileSystem.AtomicAction() {
109                 public void run() throws IOException JavaDoc {
110                     OutputStream JavaDoc os = null;
111                     FileLock lock = null;
112                     try {
113                         String JavaDoc name = file.getName();
114                         FileObject configFO = folder.getFileObject(name);
115                         if (configFO == null) {
116                             configFO = folder.createData(name);
117                         }
118                         lock = configFO.lock();
119                         os = new BufferedOutputStream JavaDoc (configFO.getOutputStream(lock), 4086);
120                         // TODO notification needed
121
if (bean != null) {
122                             bean.write(os);
123                         }
124                     } finally {
125                         if (os != null) {
126                             try { os.close(); } catch(IOException JavaDoc ioe) {}
127                         }
128                         if (lock != null)
129                             lock.releaseLock();
130                     }
131                 }
132             });
133         } catch (IOException JavaDoc e) {
134             throw new ConfigurationException JavaDoc (e.getLocalizedMessage ());
135         }
136     }
137 }
138
Popular Tags