KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > share > config > SecondaryConfigDataObject


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.sun.share.config;
21
22 import java.util.Collections JavaDoc;
23 import java.util.Set JavaDoc;
24 import javax.enterprise.deploy.spi.exceptions.ConfigurationException JavaDoc;
25 import org.netbeans.modules.j2ee.deployment.plugins.api.ConfigurationSupport;
26
27 import org.openide.cookies.EditCookie;
28 import org.openide.cookies.OpenCookie;
29 import org.openide.cookies.SaveCookie;
30 import org.openide.filesystems.FileObject;
31 import org.openide.loaders.DataObject;
32 import org.openide.loaders.DataObjectExistsException;
33 import org.openide.loaders.DataObjectNotFoundException;
34 import org.openide.loaders.MultiFileLoader;
35
36 import org.netbeans.modules.j2ee.sun.share.config.ui.ConfigBeanTopComponent;
37 import org.netbeans.modules.j2ee.sun.share.configbean.SunONEDeploymentConfiguration;
38 import org.openide.filesystems.FileUtil;
39
40
41 /**
42  * @author nn136682
43  */

44 public class SecondaryConfigDataObject extends ConfigDataObject {
45     
46     private ConfigDataObject primary;
47     
48     /** Creates a new instance of SecondaryConfigDataObject */
49     public SecondaryConfigDataObject(FileObject pf, MultiFileLoader loader) throws DataObjectExistsException {
50         super(pf, loader);
51     }
52     
53     public boolean isSecondaryOf(ConfigDataObject primary) {
54         return getPrimaryDataObject() == primary;
55     }
56     
57     public SunONEDeploymentConfiguration getDeploymentConfiguration() throws ConfigurationException JavaDoc {
58         // Request deployment configuration for SJSAS from j2eeserver module
59
ConfigDataObject p = getPrimaryDataObject();
60         FileObject fo = p.getPrimaryFile();
61         String JavaDoc serverId = getProvider().getServerID();
62         ConfigurationSupport.requestCreateConfiguration(fo, serverId);
63         return SunONEDeploymentConfiguration.getConfiguration(FileUtil.toFile(fo));
64     }
65     
66     private ConfigDataObject getPrimaryDataObject() {
67         if (primary == null || !primary.isValid()) {
68             // The only JSR-88 secondary configuration file supported by SJSAS 8.x
69
// or 9.x is sun-cmp-mappings.xml which is secondary for sun-ejb-jar.xml
70
// AND that they will always reside in the same directory. So we can find
71
// the primary data object by doing a find("sun-ejb-jar.xml") here.
72
FileObject folder = getPrimaryFile().getParent();
73             FileObject sejFO = folder.getFileObject("sun-ejb-jar", "xml");
74             if(sejFO != null) {
75                 try {
76                     DataObject dObj = DataObject.find(sejFO);
77                     primary = (ConfigDataObject) dObj.getCookie(ConfigDataObject.class);
78                     if(primary != null) {
79                         primary.addSecondary(this);
80                     }
81                 } catch(DataObjectNotFoundException ex) {
82                 }
83             }
84         }
85         
86         return primary;
87     }
88     
89     private EditCookie _getEditCookie() {
90         ConfigDataObject cdo = getPrimaryDataObject();
91         EditCookie primaryEdit = cdo == null ? null : cdo.getEditCookie();
92         EditCookie myEdit = super.getEditCookie();
93         if (primaryEdit != null) {
94             return myEdit;
95         } else {
96             return null;
97         }
98     }
99
100     private OpenCookie _getOpenCookie() {
101         ConfigDataObject cdo = getPrimaryDataObject();
102         return cdo == null ? null : (OpenCookie) cdo.getCookie(OpenCookie.class);
103     }
104
105     public org.openide.nodes.Node.Cookie getCookie(Class JavaDoc c) {
106         if (OpenCookie.class.isAssignableFrom(c)) {
107             return _getOpenCookie();
108         } else if (EditCookie.class.isAssignableFrom(c)) {
109             return _getEditCookie();
110         }
111         return super.getCookie(c);
112     }
113     
114     protected Set JavaDoc getSecondaries() {
115         return Collections.EMPTY_SET;
116     }
117     
118     protected ConfigurationStorage getStorage() {
119         ConfigDataObject cdo = getPrimaryDataObject();
120         return cdo == null ? null : cdo.getStorage();
121     }
122     
123     protected void openConfigEditor() {
124         ConfigDataObject cdo = getPrimaryDataObject();
125         if (cdo != null) {
126             getPrimaryDataObject().openConfigEditor();
127             firePropertyChange(PROP_COOKIE, null, null);
128         }
129     }
130     
131     protected ConfigBeanTopComponent findOpenedConfigEditor() {
132         ConfigDataObject cdo = getPrimaryDataObject();
133         return cdo == null ? null : cdo.findOpenedConfigEditor();
134     }
135     
136     public boolean closeConfigEditors() {
137         ConfigDataObject cdo = getPrimaryDataObject();
138         return cdo == null ? false : cdo.closeConfigEditors();
139     }
140     
141     public void fileDeleted(org.openide.filesystems.FileEvent fe) {
142         if (fe.getFile().equals(this.getPrimaryFile()) && getPrimaryDataObject() != null) {
143             primary.removeSecondary(this);
144         }
145     }
146
147     protected void fireCookieChange() {
148         fireLimitedCookieChange();
149         ConfigDataObject cdo = getPrimaryDataObject();
150         if (cdo != null) {
151             cdo.fireLimitedCookieChange();
152         }
153     }
154
155     //warn: is called from primary ConfigDataObject, don't delegate back
156
public void setChanged() {
157         addSaveCookie(new S0());
158     }
159
160    //No actual save until we have SPI to notify individual config descriptor change.
161
private class S0 implements SaveCookie {
162         public void save() throws java.io.IOException JavaDoc {
163             ConfigDataObject cdo = getPrimaryDataObject();
164             if (cdo != null) {
165                 cdo.resetAllChanged();
166             }
167         }
168     }
169 }
170
Popular Tags