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.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;

/**
 *
 * @author  pb97924
 */
public class DConfigRootWrapper extends WebappConfiguration.DConfigBeanWrapper
    implements DConfigBeanRoot, PropertyChangeListener {
    
    /** name of ctx root property. should be the same as in deployment.xml */
    public static final String PROP_CTX_ROOT = "contextRoot";  // NOI18N
    
    /**
     * "listeners" lists all the generic listeners.
     */
    private java.util.Vector listeners;
    
    /** 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 DConfigRootWrapper (DDBean ddBean, Context configBean) {
        super (ddBean, configBean);
    }
    
    private Context getContextBean () {
        return (Context)getBaseBean ();
    }
    
    /** Return a DConfigBean for a deployment descriptor that is not the 
     * module's primary deployment descriptor.
     */
    public DConfigBean getDConfigBean (DDBeanRoot ddBeanRoot) {
        return null;
    }
  
    public void setContextRoot (String ctxRoot) {
        getContextBean ().setAttributeValue ("path", ctxRoot); // NOI18N
        // generate default logger
        getContextBean().setLogger(true);
        getContextBean().setLoggerClassName("org.apache.catalina.logger.FileLogger"); // NOI18N
        // cut off leading slash
        String prefix = ctxRoot.length() > 0 ? ctxRoot.substring(1) : ctxRoot;
        getContextBean().setLoggerPrefix(prefix + "."); // NOI18N
        getContextBean().setLoggerSuffix(".log"); // NOI18N
        getContextBean().setLoggerTimestamp("true"); // NOI18N
    }
    
    public String getContextRoot () {
        return getContextBean ().getAttributeValue ("path");
    }
    
    public synchronized void addPropertyChangeListener (PropertyChangeListener pcl) {
        if (listeners == null) {
            listeners = new java.util.Vector ();
            getBaseBean ().addPropertyChangeListener (this);
        }
        listeners.add (pcl);
    }
    
    public synchronized void removePropertyChangeListener (PropertyChangeListener pcl) {
        if (listeners == null)
            return;
        listeners.remove (pcl);
        if (listeners.isEmpty ()) {
            listeners = null;
            getBaseBean ().removePropertyChangeListener (this);
        }
    }
    
    public void propertyChange (java.beans.PropertyChangeEvent evt) {
        String propertyName = evt.getPropertyName ();
        
        java.util.Vector targets = null;
        synchronized (this) {
            if (listeners != null) {
                targets = (java.util.Vector) listeners.clone ();
            }
        }
        
        if (targets != null) {
            for (int i = 0; i < targets.size (); i++) {
                PropertyChangeListener target = (PropertyChangeListener)targets.elementAt (i);
                target.propertyChange (evt);
            }
        }
        if ("/Context:path".equals (propertyName)) { // NOI18N
            propertyChange (new PropertyChangeEvent (evt.getSource (), PROP_CTX_ROOT, evt.getOldValue (), evt.getNewValue ()));
        }
    }
}
... 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.