[jboss-cvs] JBossAS SVN: r94847 - in projects/jboss-deployers/trunk: 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 06:10:27 EDT 2009
Author: alesj
Date: 2009-10-14 06:10:27 -0400 (Wed, 14 Oct 2009)
New Revision: 94847
Added:
projects/jboss-deployers/trunk/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/AbstractAttachmentLocatorType.java
projects/jboss-deployers/trunk/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/AttachmentLocatorEnum.java
projects/jboss-deployers/trunk/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/AttachmentLocatorType.java
Modified:
projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/helpers/DeploymentProvidedDeploymentUnitFilter.java
Log:
Add simple search extensions.
Added: projects/jboss-deployers/trunk/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/AbstractAttachmentLocatorType.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/AbstractAttachmentLocatorType.java (rev 0)
+++ projects/jboss-deployers/trunk/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/AbstractAttachmentLocatorType.java 2009-10-14 10:10:27 UTC (rev 94847)
@@ -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
Added: projects/jboss-deployers/trunk/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/AttachmentLocatorEnum.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/AttachmentLocatorEnum.java (rev 0)
+++ projects/jboss-deployers/trunk/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/AttachmentLocatorEnum.java 2009-10-14 10:10:27 UTC (rev 94847)
@@ -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/trunk/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/AttachmentLocatorType.java (from rev 94053, projects/jboss-deployers/trunk/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/AttachmentLocator.java)
===================================================================
--- projects/jboss-deployers/trunk/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/AttachmentLocatorType.java (rev 0)
+++ projects/jboss-deployers/trunk/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/AttachmentLocatorType.java 2009-10-14 10:10:27 UTC (rev 94847)
@@ -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/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/helpers/DeploymentProvidedDeploymentUnitFilter.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/helpers/DeploymentProvidedDeploymentUnitFilter.java 2009-10-14 09:58:58 UTC (rev 94846)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/helpers/DeploymentProvidedDeploymentUnitFilter.java 2009-10-14 10:10:27 UTC (rev 94847)
@@ -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
More information about the jboss-cvs-commits
mailing list