[jboss-cvs] JBossAS SVN: r104440 - in projects/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins: metadata and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue May 4 11:22:40 EDT 2010
Author: alesj
Date: 2010-05-04 11:22:39 -0400 (Tue, 04 May 2010)
New Revision: 104440
Added:
projects/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins/metadata/
projects/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins/metadata/AbstractFromDeploymentDelegate.java
projects/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins/metadata/FromDeployment.java
projects/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins/metadata/FromDeploymentDelegate.java
projects/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins/metadata/FromDeploymentValueMetaData.java
Log:
[JBDEPLOY-259]; support deployment info injection -- initial version; TODO tests.
Added: projects/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins/metadata/AbstractFromDeploymentDelegate.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins/metadata/AbstractFromDeploymentDelegate.java (rev 0)
+++ projects/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins/metadata/AbstractFromDeploymentDelegate.java 2010-05-04 15:22:39 UTC (rev 104440)
@@ -0,0 +1,54 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, 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.plugins.metadata;
+
+import org.jboss.dependency.spi.Controller;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.deployers.structure.spi.DeploymentRegistry;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+
+/**
+ * Get info from context's deployment.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public abstract class AbstractFromDeploymentDelegate implements FromDeploymentDelegate
+{
+ /**
+ * Get context's owning deployment.
+ *
+ * @param context the context to check
+ * @return matching deployment or null
+ */
+ protected DeploymentUnit getDeploymentUnit(ControllerContext context)
+ {
+ Controller controller = context.getController();
+ ControllerContext cc = controller.getInstalledContext(DeploymentRegistry.class);
+ if (cc != null)
+ {
+ Object target = cc.getTarget();
+ return DeploymentRegistry.class.cast(target).getDeployment(context);
+ }
+ return null;
+ }
+}
\ No newline at end of file
Added: projects/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins/metadata/FromDeployment.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins/metadata/FromDeployment.java (rev 0)
+++ projects/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins/metadata/FromDeployment.java 2010-05-04 15:22:39 UTC (rev 104440)
@@ -0,0 +1,112 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, 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.plugins.metadata;
+
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+
+/**
+ * Get info from context's deployment.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public enum FromDeployment
+{
+ DEPLOYMENT(new DefaultFromDeploymentDelegate()),
+ SIMPLE_NAME(new SimpleNameFromDeploymentDelegate()),
+ TOP_DEPLOYMENT(new TopDeploymentDelegate()),
+ TOP_DEPLOYMENT_SIMPLE_NAME(new TopSimpleNameDeploymentDelegate());
+
+ private FromDeploymentDelegate delegate;
+
+ FromDeployment(FromDeploymentDelegate delegate)
+ {
+ this.delegate = delegate;
+ }
+
+ /**
+ * Get deployment info.
+ *
+ * @param context the context
+ * @return deployment's info
+ */
+ public Object executeLookup(ControllerContext context)
+ {
+ return delegate.executeLookup(context);
+ }
+
+ /**
+ * Get matching FromDeployment enum.
+ *
+ * @param type the type string
+ * @return matching FromDeployment or exception
+ */
+ public static FromDeployment getInstance(String type)
+ {
+ if (type == null)
+ throw new IllegalArgumentException("Null type");
+
+ for (FromDeployment fd : values())
+ {
+ if (type.equalsIgnoreCase(fd.name()))
+ return fd;
+ }
+
+ throw new IllegalArgumentException("NO such FromDeployment: " + type);
+ }
+
+ private static class DefaultFromDeploymentDelegate extends AbstractFromDeploymentDelegate
+ {
+ public Object executeLookup(ControllerContext context)
+ {
+ return getDeploymentUnit(context);
+ }
+ }
+
+ private static class SimpleNameFromDeploymentDelegate extends AbstractFromDeploymentDelegate
+ {
+ public Object executeLookup(ControllerContext context)
+ {
+ DeploymentUnit unit = getDeploymentUnit(context);
+ return unit != null ? unit.getSimpleName() : null;
+ }
+ }
+
+ private static class TopDeploymentDelegate extends AbstractFromDeploymentDelegate
+ {
+ public Object executeLookup(ControllerContext context)
+ {
+ DeploymentUnit unit = getDeploymentUnit(context);
+ return unit != null ? unit.getTopLevel() : null;
+ }
+ }
+
+ private static class TopSimpleNameDeploymentDelegate extends AbstractFromDeploymentDelegate
+ {
+ public Object executeLookup(ControllerContext context)
+ {
+ DeploymentUnit unit = getDeploymentUnit(context);
+ return unit != null ? unit.getTopLevel().getSimpleName() : null;
+ }
+ }
+}
Added: projects/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins/metadata/FromDeploymentDelegate.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins/metadata/FromDeploymentDelegate.java (rev 0)
+++ projects/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins/metadata/FromDeploymentDelegate.java 2010-05-04 15:22:39 UTC (rev 104440)
@@ -0,0 +1,41 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, 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.plugins.metadata;
+
+import org.jboss.dependency.spi.ControllerContext;
+
+/**
+ * Get info from context's deployment.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public interface FromDeploymentDelegate
+{
+ /**
+ * Get deployment info.
+ *
+ * @param context the context
+ * @return deployment's info
+ */
+ Object executeLookup(ControllerContext context);
+}
\ No newline at end of file
Added: projects/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins/metadata/FromDeploymentValueMetaData.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins/metadata/FromDeploymentValueMetaData.java (rev 0)
+++ projects/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins/metadata/FromDeploymentValueMetaData.java 2010-05-04 15:22:39 UTC (rev 104440)
@@ -0,0 +1,94 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, 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.plugins.metadata;
+
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlNsForm;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+import org.jboss.beans.metadata.plugins.AbstractValueMetaData;
+import org.jboss.beans.metadata.spi.MetaDataVisitor;
+import org.jboss.dependency.spi.Controller;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.reflect.spi.TypeInfo;
+import org.jboss.xb.annotations.JBossXmlSchema;
+
+/**
+ * Deployment value meta data.
+ *
+ * It allows injection on deployment info into beans.
+ * e.g. <property name="appName"><from-deployment type="simple_name" bean="Tx"/></property>
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+ at JBossXmlSchema(namespace="urn:jboss:bean-deployer:deployment:2.0", elementFormDefault=XmlNsForm.QUALIFIED)
+ at XmlRootElement(name="from-deployment")
+ at XmlType(name="fromDeploymentType", propOrder={})
+public class FromDeploymentValueMetaData extends AbstractValueMetaData
+{
+ private static final long serialVersionUID = 1l;
+
+ private transient ControllerContext context;
+ private FromDeployment fromDeployment;
+ private String bean;
+ private ControllerState state;
+
+ public Object getValue(TypeInfo info, ClassLoader cl) throws Throwable
+ {
+ ControllerContext lookup = context;
+ if (bean != null)
+ {
+ Controller controller = context.getController();
+ lookup = controller.getContext(bean, state, false);
+ if (lookup == null)
+ throw new IllegalArgumentException("No such bean '" + bean + "' in state " + state);
+ }
+ return fromDeployment.executeLookup(lookup);
+ }
+
+ public void initialVisit(MetaDataVisitor vistor)
+ {
+ context = vistor.getControllerContext();
+ vistor.initialVisit(this);
+ }
+
+ @XmlAttribute(name = "type", required = true)
+ public void setFromDeployment(String type)
+ {
+ fromDeployment = FromDeployment.getInstance(type);
+ }
+
+ @XmlAttribute
+ public void setBean(String bean)
+ {
+ this.bean = bean;
+ }
+
+ @XmlAttribute
+ public void setState(ControllerState state)
+ {
+ this.state = state;
+ }
+}
More information about the jboss-cvs-commits
mailing list