|
What this is
Other links
The source code
/*
* Sun Public License Notice
*
* The contents of this file are subject to the Sun Public License
* Version 1.0 (the "License"). You may not use this file except in
* compliance with the License. A copy of the License is available at
* http://www.sun.com/
*
* The Original Code is NetBeans. The Initial Developer of the Original
* Code is Sun Microsystems, Inc. Portions Copyright 1997-2001 Sun
* Microsystems, Inc. All Rights Reserved.
*/
package org.netbeans.modules.j2ee.deployment.config;
import javax.enterprise.deploy.model.*;
import javax.enterprise.deploy.spi.*;
import javax.enterprise.deploy.spi.exceptions.ConfigurationException;
import org.netbeans.modules.j2ee.deployment.plugins.api.*;
import org.netbeans.modules.j2ee.deployment.impl.Server;
import org.openide.*;
import java.util.*;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeEvent;
import org.openide.nodes.*;
import org.netbeans.modules.j2ee.deployment.config.ui.ConfigBeanNode;
public class ConfigBeanStorage implements PropertyChangeListener {
static final String PROP_DISPLAY_NAME = DConfigBeanProperties.PROP_DISPLAY_NAME;
ConfigurationStorage config;
DConfigBean bean;
Sheet.Set sheet;
ConfigBeanStorage parent;
public Map childMap = new HashMap();
ConfigBeanNode node = null;
public ConfigBeanStorage(DConfigBean bean, ConfigBeanStorage parent, ConfigurationStorage config) throws ConfigurationException{
this.bean = bean;
this.parent = parent;
this.config = config;
if (parent == null) {
this.parent = this;
}
// need to ensure that the basebean events are caught?
// synchronize new CBS and event handling
initChildren();
// store itself in its BaseBean.
StandardDDImpl dd = (StandardDDImpl) bean.getDDBean();
dd.proxy.addConfigBean(this);
// PENDING set up listener on dd to implement notify()
bean.addPropertyChangeListener(this);
}
public ConfigurationStorage getStorage() {
return config;
}
public synchronized Node getNode() {
if (node == null)
node = new ConfigBeanNode(this);
return node;
}
public void propertyChange(PropertyChangeEvent pce) {
if (config != null) {
config.setChanged();
}
if (PROP_DISPLAY_NAME.equalsIgnoreCase(pce.getPropertyName())) {
getNode().setDisplayName((String) pce.getNewValue());
}
}
public void remove() {
DDCommon dd = (DDCommon) ((StandardDDImpl)bean.getDDBean()).proxy;
dd.removeConfigBean(this);
if(parent != null) {
try {
parent.bean.removeDConfigBean(bean);
} catch (Exception e) {
ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
}
}
}
private void initChildren() throws ConfigurationException {
String[] xpaths = bean.getXpaths();
if(xpaths == null) return;
for(int i = 0; i < xpaths.length; i++) {
DDBean[] beans = bean.getDDBean().getChildBean(xpaths[i]);
for(int j = 0; j < beans.length; j++) {
addChild((StandardDDImpl) beans[j]);
}
}
}
void fireEvent(String relPath, XpathEvent xe) throws ConfigurationException {
String[] xpaths = bean.getXpaths();
if(xpaths == null) return;
for(int i = 0 ; i < xpaths.length; i++) {
if(xpaths[i].equals(relPath) || xpaths[i].equals(xe.getBean().getXpath())) {
if (xe.isAddEvent()) addChild((StandardDDImpl) xe.getBean());
else removeChild(xe.getBean());
break;
}
}
}
private void addChild(StandardDDImpl dd) throws ConfigurationException {
DConfigBean cb = bean.getDConfigBean(dd);
if(cb == null) {
return;
}
ConfigBeanStorage cbs = new ConfigBeanStorage(cb, parent, config);
Collection c = (Collection) childMap.get(dd.getXpath());
if(c == null) {
c = new HashSet();
childMap.put(dd.getXpath(), c);
}
c.add(cbs);
fireChildBeanAddedEvent(cbs);
}
private void removeChild(DDBean remBean) {
Collection c = (Collection) childMap.get(remBean.getXpath());
if(c == null) return;
for(Iterator i = c.iterator(); i.hasNext(); ) {
ConfigBeanStorage cbs = (ConfigBeanStorage) i.next();
if (cbs.bean.getDDBean().equals(remBean)) {
cbs.remove();
i.remove();
fireChildBeanRemovedEvent(cbs);
}
}
}
public DConfigBean getConfigBean() {
return bean;
}
public static interface ChildrenChangeListener {
public void childBeanAdded(ConfigBeanStorage childBeanStorage);
public void childBeanRemoved(ConfigBeanStorage childBeanStorage);
}
List childrenChangeListeners = new Vector();
public void addChildrenChangeListener(ChildrenChangeListener l) {
childrenChangeListeners.add(l);
}
public void removeChildrenChangeListener(ChildrenChangeListener l) {
childrenChangeListeners.remove(l);
}
private void fireChildBeanAddedEvent(ConfigBeanStorage childBeanStorage) {
for (Iterator i=childrenChangeListeners.iterator(); i.hasNext();) {
ChildrenChangeListener l = (ChildrenChangeListener) i.next();
l.childBeanAdded(childBeanStorage);
}
}
private void fireChildBeanRemovedEvent(ConfigBeanStorage childBeanStorage) {
for (Iterator i=childrenChangeListeners.iterator(); i.hasNext();) {
ChildrenChangeListener l = (ChildrenChangeListener) i.next();
l.childBeanRemoved(childBeanStorage);
}
}
}
|
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.