alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

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-2003 Sun
 * Microsystems, Inc. All Rights Reserved.
 */

package org.netbeans.modules.tomcat5;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.InputStream;
import java.io.OutputStream;
import javax.enterprise.deploy.model.DDBean;
import javax.enterprise.deploy.model.DDBeanRoot;
import javax.enterprise.deploy.model.DeployableObject;
import javax.enterprise.deploy.model.XpathEvent;
import javax.enterprise.deploy.spi.DConfigBean;
import javax.enterprise.deploy.spi.DConfigBeanRoot;
import javax.enterprise.deploy.spi.DeploymentConfiguration;
import javax.enterprise.deploy.spi.exceptions.BeanNotFoundException;
import javax.enterprise.deploy.spi.exceptions.ConfigurationException;
import org.netbeans.modules.schema2beans.BaseBean;
import org.netbeans.modules.tomcat5.config.Context;
import org.openide.util.NbBundle;

/** Server specific configuration data related to Tomcat 5 server
 *
 * @author  Radim Kubacki
 */
public class WebappConfiguration implements DeploymentConfiguration {
    
    private DeployableObject deplObj;
    
    private DConfigRootWrapper contextRootBean;
    
    /** Creates a new instance of WebappConfiguration */
    public WebappConfiguration (DeployableObject deplObj) {
        this.deplObj = deplObj;
    }
    
    public DConfigBeanRoot getDConfigBeanRoot (DDBeanRoot dDBeanRoot) 
    throws ConfigurationException {
        if (contextRootBean == null) {
            // init default values for SSD
            Context ctx = new Context ();
            contextRootBean = new DConfigRootWrapper (dDBeanRoot, ctx);
        }
        return contextRootBean;
    }
    
    public DeployableObject getDeployableObject () {
        return deplObj;
    }
    
    public void removeDConfigBean (DConfigBeanRoot dConfigBeanRoot) 
    throws BeanNotFoundException {
        throw new BeanNotFoundException ("bean not found in WebappConfiguration "+dConfigBeanRoot);
    }
    
    public void restore (InputStream is) 
    throws ConfigurationException {
        restoreDConfigBean (is, deplObj.getDDBeanRoot ());
    }
    
    public DConfigBeanRoot restoreDConfigBean (InputStream is, DDBeanRoot dDBeanRoot) 
    throws ConfigurationException {
        try {
            Context ctx = Context.createGraph (is);
            contextRootBean = new DConfigRootWrapper (dDBeanRoot, ctx);
        }
        catch (Exception e) {
            throw new ConfigurationException (NbBundle.getMessage (WebappConfiguration.class, "MSG_Loading_Config")); //NOI18N
        }
        return contextRootBean;
    }
    
    public void save (OutputStream os) throws ConfigurationException {
        try {
            DConfigRootWrapper cb = (DConfigRootWrapper)getDConfigBeanRoot (deplObj.getDDBeanRoot ());
            cb.getBaseBean ().write (os);
        }
        catch (java.io.IOException ioe) {
            throw new ConfigurationException (ioe.getMessage ());
        }
    }
    
    public void saveDConfigBean (OutputStream os, DConfigBeanRoot dConfigBeanRoot) 
    throws ConfigurationException {
        if (dConfigBeanRoot instanceof DConfigRootWrapper) {
            BaseBean bb = ((DConfigRootWrapper)dConfigBeanRoot).getBaseBean ();
            try {
                bb.write (os);
            }
            catch (java.io.IOException ioe) {
                throw new ConfigurationException (ioe.getMessage ());
            }
        }
        else {
            throw new ConfigurationException ("saveDConfigBean failed. Cannot save "+dConfigBeanRoot);
        }
    }
    
    public String getPath () {
        return contextRootBean.getContextRoot ();
    }
    
    public void setPath (String path) {
        contextRootBean.setContextRoot (path);
    }
    
    /** Wrapper for config objects generated from schema2beans
     */
    static class DConfigBeanWrapper implements DConfigBean {
        
        /** Associated bean from standard deployment descriptor. */
        private DDBean ddBean;
        
        /** Encapsulaed bean. */
        private BaseBean configBean;
        
        /** Creates DConfigBean for given DDBean that is 
         * represented by object maintained by schema2beans.
         *
         * @param ddBean Bean from standard deploymet descriptor.
         * @param configBean wrapped schema2beans object.
         */
        public DConfigBeanWrapper (DDBean ddBean, BaseBean configBean) {
            this.configBean = configBean;
            this.ddBean = ddBean;
        }
        
        public BaseBean getBaseBean () {
            return configBean;
        }
        
        public DConfigBean getDConfigBean (DDBean dDBean) 
        throws ConfigurationException {
            return this;
        }
        
        public DDBean getDDBean () {
            return ddBean;
        }
        
        public String[] getXpaths () {
            return null;
        }
        
        public void notifyDDChange (XpathEvent xpathEvent) {
        }
        
        public void removeDConfigBean (DConfigBean dConfigBean) 
        throws BeanNotFoundException {
        }
        
        public void addPropertyChangeListener (PropertyChangeListener pcl) {
            configBean.addPropertyChangeListener (pcl);
        }
        
        public void removePropertyChangeListener (PropertyChangeListener pcl) {
            configBean.removePropertyChangeListener (pcl);
        }
        
    }
}
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 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.