[jboss-cvs] JBossAS SVN: r94884 - in projects/jboss-deployers/branches/vfs3: deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/helpers and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Oct 14 13:31:21 EDT 2009


Author: david.lloyd at jboss.com
Date: 2009-10-14 13:31:20 -0400 (Wed, 14 Oct 2009)
New Revision: 94884

Added:
   projects/jboss-deployers/branches/vfs3/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/AbstractAttachmentLocatorType.java
   projects/jboss-deployers/branches/vfs3/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/AttachmentLocatorEnum.java
   projects/jboss-deployers/branches/vfs3/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/AttachmentLocatorType.java
   projects/jboss-deployers/branches/vfs3/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/helpers/ListDeploymentUnitFilter.java
Modified:
   projects/jboss-deployers/branches/vfs3/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/helpers/DeploymentProvidedDeploymentUnitFilter.java
Log:
Merge from trunk -r94634:94882

Copied: projects/jboss-deployers/branches/vfs3/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/AbstractAttachmentLocatorType.java (from rev 94882, projects/jboss-deployers/trunk/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/AbstractAttachmentLocatorType.java)
===================================================================
--- projects/jboss-deployers/branches/vfs3/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/AbstractAttachmentLocatorType.java	                        (rev 0)
+++ projects/jboss-deployers/branches/vfs3/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/AbstractAttachmentLocatorType.java	2009-10-14 17:31:20 UTC (rev 94884)
@@ -0,0 +1,51 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.deployers.spi.deployer.helpers;
+
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+
+/**
+ * Search a DeploymentUnit structure based on type rules.
+ *
+ * @author ales.justin at jboss.org
+ */
+public abstract class AbstractAttachmentLocatorType implements AttachmentLocatorType
+{
+   /**
+    * Check expected class is nto null.
+    *
+    * @param expectedClass the expected class
+    * @return expected class as a string
+    */
+   static String checkExpectedType(Class<?> expectedClass)
+   {
+      if (expectedClass == null)
+         throw new IllegalArgumentException("Null expected type.");
+
+      return expectedClass.getName();
+   }
+
+   public <T> T search(DeploymentUnit unit, Class<T> expectedType)
+   {
+      return search(unit, checkExpectedType(expectedType), expectedType);
+   }
+}
\ No newline at end of file

Copied: projects/jboss-deployers/branches/vfs3/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/AttachmentLocatorEnum.java (from rev 94882, projects/jboss-deployers/trunk/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/AttachmentLocatorEnum.java)
===================================================================
--- projects/jboss-deployers/branches/vfs3/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/AttachmentLocatorEnum.java	                        (rev 0)
+++ projects/jboss-deployers/branches/vfs3/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/AttachmentLocatorEnum.java	2009-10-14 17:31:20 UTC (rev 94884)
@@ -0,0 +1,87 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.deployers.spi.deployer.helpers;
+
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+
+/**
+ * Search a DeploymentUnit structure based on type rules.
+ *
+ * @author ales.justin at jboss.org
+ */
+public enum AttachmentLocatorEnum implements AttachmentLocatorType
+{
+   LOCAL(new LocalAttachmentLocatorType()),
+   PARENT(new ParentAttachmentLocatorType()),
+   TOP(new TopAttachmentLocatorType()),
+   HIERARCHY(new HierarchyAttachmentLocatorType());
+
+   private AttachmentLocatorType type;
+
+   AttachmentLocatorEnum(AttachmentLocatorType type)
+   {
+      this.type = type;
+   }
+
+   public <T> T search(DeploymentUnit unit, Class<T> expectedType)
+   {
+      return search(unit, AbstractAttachmentLocatorType.checkExpectedType(expectedType), expectedType);
+   }
+
+   public <T> T search(DeploymentUnit unit, String name, Class<T> expectedType)
+   {
+      return type.search(unit, name, expectedType);
+   }
+
+   public static class LocalAttachmentLocatorType extends AbstractAttachmentLocatorType
+   {
+      public <T> T search(DeploymentUnit unit, String name, Class<T> expectedType)
+      {
+         return unit.getAttachment(name, expectedType);
+      }
+   }
+
+   public static class ParentAttachmentLocatorType extends AbstractAttachmentLocatorType
+   {
+      public <T> T search(DeploymentUnit unit, String name, Class<T> expectedType)
+      {
+         DeploymentUnit parent = unit.getParent();
+         return (parent != null) ? parent.getAttachment(name, expectedType) : null;
+      }
+   }
+
+   public static class TopAttachmentLocatorType extends AbstractAttachmentLocatorType
+   {
+      public <T> T search(DeploymentUnit unit, String name, Class<T> expectedType)
+      {
+         return unit.getTopLevel().getAttachment(name, expectedType);
+      }
+   }
+
+   public static class HierarchyAttachmentLocatorType extends AbstractAttachmentLocatorType
+   {
+      public <T> T search(DeploymentUnit unit, String name, Class<T> expectedType)
+      {
+         return AttachmentLocator.searchAncestors(unit, name, expectedType);
+      }
+   }
+}
\ No newline at end of file

Copied: projects/jboss-deployers/branches/vfs3/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/AttachmentLocatorType.java (from rev 94882, projects/jboss-deployers/trunk/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/AttachmentLocatorType.java)
===================================================================
--- projects/jboss-deployers/branches/vfs3/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/AttachmentLocatorType.java	                        (rev 0)
+++ projects/jboss-deployers/branches/vfs3/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/AttachmentLocatorType.java	2009-10-14 17:31:20 UTC (rev 94884)
@@ -0,0 +1,53 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.deployers.spi.deployer.helpers;
+
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+
+/**
+ * Search a DeploymentUnit structure for attachment.
+ *
+ * @author ales.justin at jboss.org
+ */
+public interface AttachmentLocatorType
+{
+   /**
+    * Search deployment unit.
+    *
+    * @param unit the deployment unit
+    * @param expectedType the expected type
+    * @param <T> the exact type
+    * @return search result
+    */
+   <T> T search(DeploymentUnit unit, Class<T> expectedType);
+
+   /**
+    * Search deployment unit.
+    *
+    * @param unit the deployment unit
+    * @param name the attchment name
+    * @param expectedType the expected type
+    * @param <T> the exact type
+    * @return search result
+    */
+   <T> T search(DeploymentUnit unit, String name, Class<T> expectedType);
+}
\ No newline at end of file

Modified: projects/jboss-deployers/branches/vfs3/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/helpers/DeploymentProvidedDeploymentUnitFilter.java
===================================================================
--- projects/jboss-deployers/branches/vfs3/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/helpers/DeploymentProvidedDeploymentUnitFilter.java	2009-10-14 17:30:43 UTC (rev 94883)
+++ projects/jboss-deployers/branches/vfs3/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/helpers/DeploymentProvidedDeploymentUnitFilter.java	2009-10-14 17:31:20 UTC (rev 94884)
@@ -21,6 +21,8 @@
 */
 package org.jboss.deployers.vfs.spi.structure.helpers;
 
+import org.jboss.deployers.spi.deployer.helpers.AttachmentLocatorEnum;
+import org.jboss.deployers.spi.deployer.helpers.AttachmentLocatorType;
 import org.jboss.deployers.structure.spi.DeploymentUnit;
 import org.jboss.deployers.structure.spi.DeploymentUnitFilter;
 
@@ -33,9 +35,25 @@
  */
 public class DeploymentProvidedDeploymentUnitFilter extends VFS2BaseBridgeDeploymentUnitFilter
 {
+   /** By default we do local search */
+   private AttachmentLocatorType searchType = AttachmentLocatorEnum.LOCAL;
+
    protected boolean doAccepts(DeploymentUnit unit)
    {
-      DeploymentUnitFilter filter = unit.getAttachment(DeploymentUnitFilter.class);
+      DeploymentUnitFilter filter = searchType.search(unit, DeploymentUnitFilter.class);
       return filter == null || filter.accepts(unit);
    }
+
+   /**
+    * Set search type.
+    *
+    * @param searchType the search type
+    */
+   public void setSearchType(AttachmentLocatorType searchType)
+   {
+      if (searchType == null)
+         throw new IllegalArgumentException("Null search type");
+
+      this.searchType = searchType;
+   }
 }
\ No newline at end of file

Copied: projects/jboss-deployers/branches/vfs3/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/helpers/ListDeploymentUnitFilter.java (from rev 94882, projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/helpers/ListDeploymentUnitFilter.java)
===================================================================
--- projects/jboss-deployers/branches/vfs3/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/helpers/ListDeploymentUnitFilter.java	                        (rev 0)
+++ projects/jboss-deployers/branches/vfs3/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/helpers/ListDeploymentUnitFilter.java	2009-10-14 17:31:20 UTC (rev 94884)
@@ -0,0 +1,56 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.deployers.vfs.spi.structure.helpers;
+
+import java.util.List;
+
+import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnitFilter;
+import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
+
+/**
+ * Check the list of filters.
+ * This filter returns false if one filter in the list returns false.
+ *
+ * @author ales.justin at jboss.org
+ */
+public class ListDeploymentUnitFilter implements VFSDeploymentUnitFilter
+{
+   private List<VFSDeploymentUnitFilter> filters;
+
+   public ListDeploymentUnitFilter(List<VFSDeploymentUnitFilter> filters)
+   {
+      if (filters == null || filters.isEmpty())
+         throw new IllegalArgumentException("Null or empty filters list.");
+
+      this.filters = filters;
+   }
+
+   public boolean accepts(VFSDeploymentUnit unit)
+   {
+      for (VFSDeploymentUnitFilter filter : filters)
+      {
+         if (filter.accepts(unit) == false)
+            return false;
+      }
+      return true;
+   }
+}
\ No newline at end of file




More information about the jboss-cvs-commits mailing list