geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ge...@apache.org
Subject cvs commit: incubator-geronimo/modules/core/src/java/org/apache/geronimo/deployment/scanner DeploymentScanner.java DeploymentScannerMBean.java FileSystemScanner.java Scanner.java WebDAVScanner.java
Date Sun, 10 Aug 2003 20:47:53 GMT
geirm       2003/08/10 13:47:53

  Added:       modules/core/src/java/org/apache/geronimo/deployment
                        DeployerMBean.java DeploymentController.java
                        DeploymentControllerMBean.java DeploymentInfo.java
               modules/core/src/java/org/apache/geronimo/deployment/scanner
                        DeploymentScanner.java DeploymentScannerMBean.java
                        FileSystemScanner.java Scanner.java
                        WebDAVScanner.java
  Log:
  initial import
  
  Revision  Changes    Path
  1.1                  incubator-geronimo/modules/core/src/java/org/apache/geronimo/deployment/DeployerMBean.java
  
  Index: DeployerMBean.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.deployment;
  
  import java.net.URL;
  
  /**
   * 
   * 
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/10 20:47:53 $
   */
  public interface DeployerMBean {
      /**
       * Return the information needed by a @{link scanner.Scanner} to determine
       * if a URL is deployable
       * @param url the URL to evaluate
       * @return the info on the deployment at this URL, or null if this Deployer can't handle it
       */
      public DeploymentInfo canDeploy(URL url);
  }
  
  
  
  1.1                  incubator-geronimo/modules/core/src/java/org/apache/geronimo/deployment/DeploymentController.java
  
  Index: DeploymentController.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.deployment;
  
  import java.util.List;
  import java.util.Iterator;
  import java.util.Set;
  import java.util.HashSet;
  import javax.management.MBeanRegistration;
  import javax.management.ObjectName;
  import javax.management.MBeanServer;
  import javax.management.NotificationListener;
  import javax.management.Notification;
  import javax.management.NotificationFilterSupport;
  
  import org.apache.geronimo.jmx.JMXUtil;
  import org.apache.log4j.Logger;
  
  /**
   *
   *
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/10 20:47:53 $
   */
  public class DeploymentController implements MBeanRegistration, NotificationListener, DeploymentControllerMBean {
      private static final ObjectName DEFAULT_NAME = JMXUtil.getObjectName("geronimo.deployment:type=DeploymentController");
      private static final String MBEAN_REGISTERED = "JMX.mbean.registered";
      private static final String MBEAN_UNREGISTERED = "JMX.mbean.unregistered";
  
      private static final ObjectName DEPLOYER_PATTERN = JMXUtil.getObjectName("*:type=Deployer");
      private static final Logger log = Logger.getLogger(DeploymentController.class);
  
      private MBeanServer server;
      private final Set deployers = new HashSet();
  
      public ObjectName preRegister(MBeanServer mBeanServer, ObjectName objectName) throws Exception {
          server = mBeanServer;
          NotificationFilterSupport filter = new NotificationFilterSupport();
          filter.enableType(MBEAN_REGISTERED);
          filter.enableType(MBEAN_UNREGISTERED);
          server.addNotificationListener(JMXUtil.DELEGATE_NAME, this, filter, null);
          return objectName == null ? DEFAULT_NAME : objectName;
      }
  
      public void postRegister(Boolean aBoolean) {
      }
  
      public void preDeregister() throws Exception {
          server.removeNotificationListener(JMXUtil.DELEGATE_NAME, this);
      }
  
      public void postDeregister() {
      }
  
      public void handleNotification(Notification notification, Object o) {
          List mbeans = (List) o;
          for (Iterator i = mbeans.iterator(); i.hasNext();) {
              ObjectName name = (ObjectName) i.next();
  /* comment out until we get mx4j from maven fixed
              if (DEPLOYER_PATTERN.apply(name)) {
                  if (MBEAN_REGISTERED.equals(notification.getType())) {
                      log.info("Adding Deployer "+name);
                      deployers.add(name);
                  } else if (MBEAN_UNREGISTERED.equals(notification.getType())) {
                      log.info("Removing Deployer "+name);
                      deployers.remove(name);
                  }
              }
  */
          }
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/core/src/java/org/apache/geronimo/deployment/DeploymentControllerMBean.java
  
  Index: DeploymentControllerMBean.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.deployment;
  
  /**
   * 
   * 
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/10 20:47:53 $
   */
  public interface DeploymentControllerMBean {
  }
  
  
  
  1.1                  incubator-geronimo/modules/core/src/java/org/apache/geronimo/deployment/DeploymentInfo.java
  
  Index: DeploymentInfo.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.deployment;
  
  import java.net.URL;
  
  /**
   *
   *
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/10 20:47:53 $
   */
  public class DeploymentInfo {
      private final URL url;
      private final URL watchURL;
      private long timestamp;
  
      public DeploymentInfo(URL url, URL watchURL) {
          this.url = url;
          this.watchURL = watchURL;
      }
  
      public URL getURL() {
          return url;
      }
  
      public URL getWatchURL() {
          return watchURL;
      }
  
      public long getTimestamp() {
          return timestamp;
      }
  
      public void setTimestamp(long timestamp) {
          this.timestamp = timestamp;
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/core/src/java/org/apache/geronimo/deployment/scanner/DeploymentScanner.java
  
  Index: DeploymentScanner.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.deployment.scanner;
  
  import java.io.File;
  import java.io.IOException;
  import java.net.MalformedURLException;
  import java.net.URL;
  import java.util.Collections;
  import java.util.HashMap;
  import java.util.HashSet;
  import java.util.Iterator;
  import java.util.Map;
  import java.util.Set;
  import javax.management.Notification;
  import javax.management.NotificationBroadcasterSupport;
  import javax.management.MBeanRegistration;
  import javax.management.ObjectName;
  import javax.management.MBeanServer;
  
  import org.apache.log4j.Logger;
  
  /**
   * An MBean that maintains a list of URLs and periodically invokes a Scanner
   * to search them for deployments. The set found is sent out as a JMX
   * Notifiction.
   *
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/10 20:47:53 $
   */
  public class DeploymentScanner extends NotificationBroadcasterSupport implements DeploymentScannerMBean,MBeanRegistration {
      private static final Logger log = Logger.getLogger(DeploymentScanner.class);
      private final Map scanners = new HashMap();
      private long scanInterval;
      private boolean run;
      private Thread scanThread;
      private int sequence = 0;
      private ObjectName objectName;
  
      public ObjectName preRegister(MBeanServer mBeanServer, ObjectName objectName) throws Exception {
          this.objectName = objectName;
          return objectName;
      }
  
      public void postRegister(Boolean aBoolean) {
      }
  
      public void preDeregister() throws Exception {
      }
  
      public void postDeregister() {
      }
  
      public synchronized long getScanInterval() {
          return scanInterval;
      }
  
      public synchronized void setScanInterval(long scanInterval) {
          this.scanInterval = scanInterval;
      }
  
      public void addURL(String url, boolean recurse) throws MalformedURLException {
          addURL(new URL(url), recurse);
      }
  
      public synchronized void addURL(URL url, boolean recurse) {
          if (!scanners.containsKey(url)) {
              Scanner scanner = getScannerForURL(url, recurse);
              scanners.put(url, scanner);
          }
      }
  
      private Scanner getScannerForURL(URL url, boolean recurse) {
          String protocol = url.getProtocol();
          if ("file".equals(protocol)) {
              return new FileSystemScanner(new File(url.getFile()), recurse);
          } else if ("http".equals(protocol) || "https".equals(protocol)) {
              return new WebDAVScanner(url, recurse);
          } else {
              throw new IllegalArgumentException("Unknown protocol "+protocol);
          }
      }
  
      public void removeURL(String url) throws MalformedURLException {
          removeURL(new URL(url));
      }
  
      public synchronized void removeURL(URL url) {
          scanners.remove(url);
      }
  
      public synchronized void start() {
          if (scanThread == null) {
              run = true;
              scanThread = new Thread() {
                  public void run() {
                      synchronized (DeploymentScanner.this) {
                          while (run) {
                              scanNow();
                              try {
                                  DeploymentScanner.this.wait(scanInterval);
                              } catch (InterruptedException e) {
                              }
                          }
                      }
                  }
              };
              scanThread.start();
          }
      }
  
      public synchronized void stop() {
          run = false;
          if (scanThread != null) {
              scanThread.interrupt();
              scanThread = null;
          }
      }
  
      public synchronized void scanNow() {
          Set results = new HashSet();
          for (Iterator i = scanners.entrySet().iterator(); i.hasNext();) {
              Map.Entry entry = (Map.Entry) i.next();
              URL url = (URL) entry.getKey();
              log.debug("Starting scan of "+url);
              Scanner scanner = (Scanner) entry.getValue();
              try {
                  Set result = scanner.scan();
                  log.debug("Finished scan of "+url+", "+result.size()+" deployment(s) found");
                  results.addAll(result);
              } catch (IOException e) {
                  log.error("Error scanning url "+url,  e);
              }
          }
  
          Notification notification = new Notification(SCAN_COMPLETE, objectName, ++sequence);
          notification.setUserData(Collections.unmodifiableSet(results));
          sendNotification(notification);
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/core/src/java/org/apache/geronimo/deployment/scanner/DeploymentScannerMBean.java
  
  Index: DeploymentScannerMBean.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.deployment.scanner;
  
  import java.net.URL;
  import java.net.MalformedURLException;
  
  /**
   * 
   * 
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/10 20:47:53 $
   */
  public interface DeploymentScannerMBean {
      public static final String SCAN_COMPLETE="geronimo.deployment.SCAN_COMPLETE";
  
      public long getScanInterval();
  
      public void setScanInterval(long interval);
  
      public void addURL(URL url, boolean recurse);
  
      public void addURL(String url, boolean recurse) throws MalformedURLException;
  
      public void removeURL(URL url);
  
      public void removeURL(String url) throws MalformedURLException;
  
      public void scanNow();
  
      public void start();
  
      public void stop();
  }
  
  
  
  1.1                  incubator-geronimo/modules/core/src/java/org/apache/geronimo/deployment/scanner/FileSystemScanner.java
  
  Index: FileSystemScanner.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.deployment.scanner;
  
  import java.io.File;
  import java.io.FileFilter;
  import java.io.IOException;
  import java.util.HashSet;
  import java.util.LinkedList;
  import java.util.Set;
  
  import org.apache.geronimo.deployment.DeploymentInfo;
  
  /**
   *
   *
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/10 20:47:53 $
   */
  public class FileSystemScanner implements Scanner {
      private final File root;
      private final boolean recurse;
      private final FileFilter filter;
  
      public FileSystemScanner(File root, boolean recurse, FileFilter filter) {
          this.root = root;
          this.recurse = recurse;
          this.filter = filter;
      }
  
      private static final FileFilter DEFAULT_FILTER = new FileFilter() {
          public boolean accept(File pathname) {
              return !pathname.isHidden();
          }
      };
  
      public FileSystemScanner(File root, boolean recurse) {
          this(root, recurse, DEFAULT_FILTER);
      }
  
      public synchronized Set scan() throws IOException {
          Set result = new HashSet();
          LinkedList toScan = new LinkedList();
          toScan.addFirst(root);
          while (!toScan.isEmpty()) {
              File dir = (File) toScan.removeFirst();
              File[] files = dir.listFiles(filter);
              if (files == null) {
                  // this is not a directory any more ...
                  continue;
              }
  
              for (int i = 0; i < files.length; i++) {
                  File file = files[i];
                  // we consider a File deployable if it is not a directory,
                  // or if it is and it contains a META-INF subdirectory
                  if (!file.isDirectory() || new File(file, "META-INF").isDirectory()) {
                      result.add(file.toURL());
                  } else if (recurse) {
                      // add this to the end of the list so we go breadth first
                      toScan.addLast(file);
                  }
              }
          }
          return result;
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/core/src/java/org/apache/geronimo/deployment/scanner/Scanner.java
  
  Index: Scanner.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.deployment.scanner;
  
  import java.io.IOException;
  import java.util.Set;
  import java.net.URL;
  
  /**
   * Interface for scanning a location for deployments
   *
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/10 20:47:53 $
   */
  public interface Scanner {
      /**
       * Scan for any deployments
       * @return a Set<DeploymentInfo> of deployables found by this scanner
       * @throws IOException
       */
      public Set scan() throws IOException;
  }
  
  
  
  1.1                  incubator-geronimo/modules/core/src/java/org/apache/geronimo/deployment/scanner/WebDAVScanner.java
  
  Index: WebDAVScanner.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.deployment.scanner;
  
  import java.io.IOException;
  import java.io.InputStream;
  import java.net.MalformedURLException;
  import java.net.URL;
  import java.util.HashSet;
  import java.util.Iterator;
  import java.util.LinkedList;
  import java.util.Set;
  import javax.xml.parsers.SAXParser;
  import javax.xml.parsers.SAXParserFactory;
  
  import org.apache.commons.httpclient.HostConfiguration;
  import org.apache.commons.httpclient.HttpClient;
  import org.apache.commons.httpclient.HttpConnection;
  import org.apache.commons.httpclient.HttpMethod;
  import org.apache.commons.httpclient.HttpMethodBase;
  import org.apache.commons.httpclient.URI;
  import org.apache.commons.httpclient.URIException;
  import org.xml.sax.Attributes;
  import org.xml.sax.SAXException;
  import org.xml.sax.helpers.DefaultHandler;
  
  /**
   * Scanner that searches a remote site using WebDAV looking for deployments.
   * Sub-collections that themselves contain a META-INF sub-collection are
   * assumed to be deployable; others may be recursed into
   *
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/10 20:47:53 $
   */
  public class WebDAVScanner implements Scanner {
      private final URL base;
      private final HostConfiguration hostConfig;
      private final boolean recurse;
      private final HttpClient httpClient;
      private final SAXParser parser;
      private final DavHandler handler = new DavHandler();
  
      /**
       * Constructor taking a base URL and whether to recurse into sub-collections.
       * @param base the base URL on the WebDAV Server
       * @param recurse if true, the scan will recurse into sub-collections
       */
      public WebDAVScanner(URL base, boolean recurse) {
          assert (base.toString().endsWith("/"));
          this.base = base;
          this.recurse = recurse;
  
          // all this so we can get a connection to close...
          try {
              hostConfig = new HostConfiguration();
              URI uri = new URI(base.toString());
              hostConfig.setHost(uri);
              httpClient = new HttpClient();
              httpClient.setHostConfiguration(hostConfig);
          } catch (URIException e) {
              throw new IllegalArgumentException("Invalid URL " + base);
          }
  
          // set up the parser for the response
          SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
          saxParserFactory.setNamespaceAware(true);
          try {
              parser = saxParserFactory.newSAXParser();
          } catch (Exception e) {
              throw new AssertionError("Unable to allocate SAXParser: "+e.getMessage());
          }
      }
  
      public synchronized Set scan() throws IOException {
          try {
              Set result = new HashSet();
              LinkedList toScan = new LinkedList();
              toScan.add(base);
              while (!toScan.isEmpty()) {
                  URL scanURL = (URL) toScan.removeFirst();
                  Set scanResult = scanCollection(scanURL);
                  for (Iterator i = scanResult.iterator(); i.hasNext();) {
                      URL url = (URL) i.next();
                      if (!url.toString().endsWith("/")) {
                          // plain file - add it
                          result.add(url);
                      } else if (scanURL.equals(url)) {
                          // ignore the collection we scanned
                          continue;
                      } else if (hasMetaInf(url)) {
                          // a sub-collection with META-INF - add it
                          result.add(url);
                      } else if (recurse) {
                          // a sub-collection without META-INF and we are recursing
                          toScan.addLast(url);
                      }
                  }
                  handler.result.clear();
              }
              return result;
          } finally {
              handler.result.clear();
              HttpConnection conn = httpClient.getHttpConnectionManager().getConnection(hostConfig);
              conn.close();
              httpClient.getHttpConnectionManager().releaseConnection(conn);
          }
      }
  
      /**
       * See if the specified URL has a META-INF sub-collection
       * @param url the URL to check
       * @return true if the URL has a META-INF sub-collection
       * @throws IOException if there was a problem talking to the server
       */
      private boolean hasMetaInf(URL url) throws IOException {
          assert (url.toString().endsWith("/"));
          URL metaInfURL = new URL(url, "META-INF/");
          HttpMethod method = new PropfindMethod(metaInfURL.toString());
          try {
              method.setFollowRedirects(false);
              method.setRequestHeader("DAV", "1");
              method.setRequestHeader("Depth", "0");
              int status = httpClient.executeMethod(method);
              method.getResponseBody();
              if (status == 404) {
                  return false;
              } else if (status == 207) {
                  return true;
              } else {
                  throw new IOException("Unexpected result " + status);
              }
          } finally {
              method.releaseConnection();
          }
      }
  
      /**
       * Scan the supplied URL for all first-level members. We do not do a deep
       * scan as we do not want to recurse into entries with META-INFs
       * @param collection the collection to scan
       * @return a Set<URL> of members found
       * @throws IOException if there was a problem talking to the server
       */
      private Set scanCollection(URL collection) throws IOException {
          assert (collection.toString().endsWith("/"));
          HttpMethod method = new PropfindMethod(collection.toString());
          try {
              method.setFollowRedirects(true);
              method.setRequestHeader("DAV", "1");
              method.setRequestHeader("Depth", "1");
              int status = httpClient.executeMethod(method);
              if (status != 207) {
                  throw new IOException("WebDAV request returned status " + status);
              }
  
              InputStream is = method.getResponseBodyAsStream();
              parser.parse(is, handler);
              return handler.result;
          } catch (SAXException e) {
              throw new IOException("Unable to parse response");
          } finally {
              method.releaseConnection();
          }
      }
  
      /**
       * The WebDAV PROPFIND method - see RFC2518
       */
      private static final class PropfindMethod extends HttpMethodBase {
          public PropfindMethod(String uri) {
              super(uri);
          }
  
          public String getName() {
              return "PROPFIND";
          }
      }
  
      /**
       * SAX event parser that extracts the contents of the DAV:href elements
       * it the response
       */
      private final class DavHandler extends DefaultHandler {
          private final Set result = new HashSet();
          private final StringBuffer filename = new StringBuffer();
          private boolean capture;
  
          public void startElement(String uri, String localName,
                                   String qName, Attributes attributes)
                  throws SAXException {
              super.startElement(uri, localName, qName, attributes);
              if ("DAV:".equals(uri) && "href".equals(localName)) {
                  capture = true;
              }
          }
  
          public void characters(char ch[], int start, int length)
                  throws SAXException {
              super.characters(ch, start, length);
              if (capture) {
                  filename.append(ch, start, length);
              }
          }
  
          public void endElement(String uri, String localName, String qName)
                  throws SAXException {
              super.endElement(uri, localName, qName);
              if ("DAV:".equals(uri) && "href".equals(localName)) {
                  capture = false;
                  try {
                      result.add(new URL(base, filename.toString()));
                  } catch (MalformedURLException e) {
                      throw new SAXException(e);
                  }
                  filename.setLength(0);
              }
          }
      }
  }
  
  
  

Mime
View raw message