[jboss-cvs] JBossAS SVN: r62079 - in projects/microcontainer/trunk/kernel/src: main/org/jboss/beans/metadata/spi and 4 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Apr 4 11:18:38 EDT 2007
Author: alesj
Date: 2007-04-04 11:18:38 -0400 (Wed, 04 Apr 2007)
New Revision: 62079
Added:
projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/AbstractAliasMetaData.java
projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/spi/AliasMetaData.java
projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/AliasCharactersHandler.java
projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/AliasHandler.java
projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/BeanAliasInterceptor.java
projects/microcontainer/trunk/kernel/src/resources/tests/org/jboss/test/kernel/deployment/xml/test/Alias.xml
projects/microcontainer/trunk/kernel/src/resources/tests/org/jboss/test/kernel/deployment/xml/test/AliasWithBeanFactory.xml
projects/microcontainer/trunk/kernel/src/resources/tests/org/jboss/test/kernel/deployment/xml/test/AliasWithClass.xml
projects/microcontainer/trunk/kernel/src/resources/tests/org/jboss/test/kernel/deployment/xml/test/AliasWithNoReplace.xml
projects/microcontainer/trunk/kernel/src/resources/tests/org/jboss/test/kernel/deployment/xml/test/AliasWithReplace.xml
projects/microcontainer/trunk/kernel/src/resources/tests/org/jboss/test/kernel/deployment/xml/test/MultipleAlias.xml
projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/xml/test/AliasTestCase.java
Modified:
projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/AbstractBeanMetaData.java
projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/spi/BeanMetaData.java
projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/BeanSchemaBinding20.java
projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/BeanSchemaBindingHelper.java
projects/microcontainer/trunk/kernel/src/resources/main/schema/bean-deployer_2_0.xsd
projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/xml/test/XMLTestSuite.java
Log:
Alias introduction to BeanMetaData.
Added: projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/AbstractAliasMetaData.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/AbstractAliasMetaData.java (rev 0)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/AbstractAliasMetaData.java 2007-04-04 15:18:38 UTC (rev 62079)
@@ -0,0 +1,180 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.beans.metadata.plugins;
+
+import java.beans.PropertyEditor;
+import java.io.Serializable;
+import java.util.Iterator;
+
+import org.jboss.beans.metadata.spi.AliasMetaData;
+import org.jboss.beans.metadata.spi.MetaDataVisitor;
+import org.jboss.beans.metadata.spi.MetaDataVisitorNode;
+import org.jboss.logging.Logger;
+import org.jboss.util.JBossObject;
+import org.jboss.util.JBossStringBuilder;
+import org.jboss.util.StringPropertyReplacer;
+import org.jboss.util.propertyeditor.PropertyEditors;
+
+/**
+ * Metadata for an alias.
+ *
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ */
+public class AbstractAliasMetaData extends JBossObject
+ implements AliasMetaData, Serializable
+{
+ /**
+ * The log
+ */
+ private static final Logger log = Logger.getLogger(AbstractAliasMetaData.class);
+
+ static
+ {
+ try
+ {
+ PropertyEditors.init();
+ }
+ catch (Throwable t)
+ {
+ log.debug("Unable to initialise property editors", t);
+ }
+ }
+
+ private static final long serialVersionUID = 1L;
+
+ public String alias;
+
+ protected boolean replace = true;
+ protected String clazz;
+
+ /**
+ * Create a new annotation meta data
+ */
+ public AbstractAliasMetaData()
+ {
+ super();
+ }
+
+ public String getAlias()
+ {
+ return alias;
+ }
+
+ public void setAlias(String alias)
+ {
+ this.alias = alias;
+ }
+
+ public boolean isReplace()
+ {
+ return replace;
+ }
+
+ public void setReplace(boolean replace)
+ {
+ this.replace = replace;
+ }
+
+ public String getClazz()
+ {
+ return clazz;
+ }
+
+ public void setClazz(String clazz)
+ {
+ this.clazz = clazz;
+ }
+
+ public Object getAliasValue()
+ {
+ try
+ {
+ String aliasString = alias;
+ if (replace)
+ {
+ aliasString = StringPropertyReplacer.replaceProperties(aliasString);
+ }
+ if (clazz != null)
+ {
+ PropertyEditor editor = PropertyEditors.findEditor(clazz);
+ if (editor != null)
+ {
+ editor.setAsText(aliasString);
+ return editor.getValue();
+ }
+ else
+ {
+ log.warn("No matching PropertyEditor found for class: " + clazz);
+ }
+ }
+ return aliasString;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Error creating alias for " + alias, e);
+ }
+ }
+
+ public void initialVisit(MetaDataVisitor visitor)
+ {
+ visitor.initialVisit(this);
+ }
+
+ public void describeVisit(MetaDataVisitor vistor)
+ {
+ vistor.describeVisit(this);
+ }
+
+ public Iterator<? extends MetaDataVisitorNode> getChildren()
+ {
+ return null;
+ }
+
+ public void toString(JBossStringBuilder buffer)
+ {
+ buffer.append("alias=").append(alias);
+ buffer.append(" replace=").append(replace);
+ if (clazz != null)
+ buffer.append(" class=").append(clazz);
+ }
+
+ public void toShortString(JBossStringBuilder buffer)
+ {
+ buffer.append(alias);
+ }
+
+ protected int getHashCode()
+ {
+ return alias.hashCode();
+ }
+
+ public boolean equals(Object object)
+ {
+ if (object == null || object instanceof AbstractAliasMetaData == false)
+ return false;
+
+ AbstractAliasMetaData amd = (AbstractAliasMetaData)object;
+ // this is what we probably want? - never saw duplicate annotation on a bean/prop/...
+ return alias.equals(amd.alias) && (replace == amd.replace) && (clazz != null && clazz.equals(amd.clazz));
+ }
+
+}
Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/AbstractBeanMetaData.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/AbstractBeanMetaData.java 2007-04-04 14:55:06 UTC (rev 62078)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/AbstractBeanMetaData.java 2007-04-04 15:18:38 UTC (rev 62079)
@@ -72,6 +72,9 @@
/** The name of this instance */
protected String name;
+ /** The aliases */
+ protected Set<Object> aliases;
+
/** The mode */
protected ControllerMode mode;
@@ -91,7 +94,9 @@
protected LifecycleMetaData start;
/** The stop lifecycle */
- protected LifecycleMetaData stop; /** The destroy lifecycle */
+ protected LifecycleMetaData stop;
+
+ /** The destroy lifecycle */
protected LifecycleMetaData destroy;
/** What the bean demands Set<DemandMetaData> */
@@ -321,6 +326,16 @@
flushJBossObjectCache();
}
+ public Set<Object> getAliases()
+ {
+ return aliases;
+ }
+
+ public void setAliases(Set<Object> aliases)
+ {
+ this.aliases = aliases;
+ }
+
public ControllerMode getMode()
{
return mode;
@@ -548,6 +563,8 @@
public void toString(JBossStringBuilder buffer)
{
buffer.append("name=").append(name);
+ if (aliases != null)
+ buffer.append(" aliases=").append(aliases);
buffer.append(" bean=").append(bean);
buffer.append(" properties=");
JBossObject.list(buffer, properties);
Added: projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/spi/AliasMetaData.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/spi/AliasMetaData.java (rev 0)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/spi/AliasMetaData.java 2007-04-04 15:18:38 UTC (rev 62079)
@@ -0,0 +1,34 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.beans.metadata.spi;
+
+import org.jboss.util.JBossInterface;
+
+/**
+ * Metadata about an alias attribute.
+ *
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ */
+public interface AliasMetaData extends JBossInterface, MetaDataVisitorNode
+{
+ Object getAliasValue();
+}
Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/spi/BeanMetaData.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/spi/BeanMetaData.java 2007-04-04 14:55:06 UTC (rev 62078)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/spi/BeanMetaData.java 2007-04-04 15:18:38 UTC (rev 62079)
@@ -57,6 +57,13 @@
void setName(String name);
/**
+ * The aliases
+ *
+ * @return the aliases or null if there are no aliases
+ */
+ Set<Object> getAliases();
+
+ /**
* Get the mode
*
* @return the mode
Added: projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/AliasCharactersHandler.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/AliasCharactersHandler.java (rev 0)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/AliasCharactersHandler.java 2007-04-04 15:18:38 UTC (rev 62079)
@@ -0,0 +1,53 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.kernel.plugins.deployment.xml;
+
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.namespace.QName;
+
+import org.jboss.beans.metadata.plugins.AbstractAliasMetaData;
+import org.jboss.xb.binding.sunday.unmarshalling.CharactersHandler;
+import org.jboss.xb.binding.sunday.unmarshalling.ElementBinding;
+import org.jboss.xb.binding.sunday.unmarshalling.TypeBinding;
+
+/**
+ * AliasCharactersHandler.
+ *
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ */
+public class AliasCharactersHandler extends CharactersHandler
+{
+ /** The interceptor */
+ public static final AliasCharactersHandler HANDLER = new AliasCharactersHandler();
+
+ public Object unmarshal(QName qName, TypeBinding typeBinding, NamespaceContext nsCtx, org.jboss.xb.binding.metadata.ValueMetaData valueMetaData, String value)
+ {
+ return value;
+ }
+
+ public void setValue(QName qname, ElementBinding element, Object owner, Object value)
+ {
+ AbstractAliasMetaData alias = (AbstractAliasMetaData) owner;
+ alias.setAlias((String)value);
+ }
+
+}
Added: projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/AliasHandler.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/AliasHandler.java (rev 0)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/AliasHandler.java 2007-04-04 15:18:38 UTC (rev 62079)
@@ -0,0 +1,70 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.kernel.plugins.deployment.xml;
+
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.namespace.QName;
+
+import org.jboss.beans.metadata.plugins.AbstractAliasMetaData;
+import org.jboss.xb.binding.sunday.unmarshalling.DefaultElementHandler;
+import org.jboss.xb.binding.sunday.unmarshalling.ElementBinding;
+import org.xml.sax.Attributes;
+
+/**
+ * AliasHandler.
+ *
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ */
+public class AliasHandler extends DefaultElementHandler
+{
+ /** The handler */
+ public static final AliasHandler HANDLER = new AliasHandler();
+
+ public Object startElement(Object parent, QName name, ElementBinding element)
+ {
+ return new AbstractAliasMetaData();
+ }
+
+ public void attributes(Object o, QName elementName, ElementBinding element, Attributes attrs, NamespaceContext nsCtx)
+ {
+ AbstractAliasMetaData aliasMetaData = (AbstractAliasMetaData) o;
+ for (int i = 0; i < attrs.getLength(); ++i)
+ {
+ String localName = attrs.getLocalName(i);
+ if ("replace".equals(localName))
+ aliasMetaData.setReplace(Boolean.parseBoolean(attrs.getValue(i)));
+ else if ("class".equals(localName))
+ aliasMetaData.setClazz(attrs.getValue(i));
+ }
+
+ }
+
+ public Object endElement(Object o, QName qName, ElementBinding element)
+ {
+ AbstractAliasMetaData alias = (AbstractAliasMetaData) o;
+ if (alias.getAlias() == null)
+ {
+ throw new IllegalArgumentException("Empty <alias/> content");
+ }
+ return alias;
+ }
+}
Added: projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/BeanAliasInterceptor.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/BeanAliasInterceptor.java (rev 0)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/BeanAliasInterceptor.java 2007-04-04 15:18:38 UTC (rev 62079)
@@ -0,0 +1,54 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.kernel.plugins.deployment.xml;
+
+import java.util.HashSet;
+import java.util.Set;
+import javax.xml.namespace.QName;
+
+import org.jboss.beans.metadata.plugins.AbstractBeanMetaData;
+import org.jboss.beans.metadata.spi.AliasMetaData;
+import org.jboss.xb.binding.sunday.unmarshalling.DefaultElementInterceptor;
+
+/**
+ * BeanAliasInterceptor.
+ *
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ */
+public class BeanAliasInterceptor extends DefaultElementInterceptor
+{
+ /** The interceptor */
+ public static final BeanAliasInterceptor INTERCEPTOR = new BeanAliasInterceptor();
+
+ public void add(Object parent, Object child, QName name)
+ {
+ AbstractBeanMetaData bean = (AbstractBeanMetaData) parent;
+ AliasMetaData alias = (AliasMetaData) child;
+ Set<Object> aliases = bean.getAliases();
+ if (aliases == null)
+ {
+ aliases = new HashSet<Object>();
+ bean.setAliases(aliases);
+ }
+ aliases.add(alias.getAliasValue());
+ }
+}
Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/BeanSchemaBinding20.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/BeanSchemaBinding20.java 2007-04-04 14:55:06 UTC (rev 62078)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/BeanSchemaBinding20.java 2007-04-04 15:18:38 UTC (rev 62079)
@@ -53,6 +53,12 @@
/** The beanfactory element name */
public static final QName beanFactoryQName = new QName(BEAN_DEPLOYER_NS, "beanfactory");
+ /** The alias binding */
+ public static final QName aliasTypeQName = new QName(BEAN_DEPLOYER_NS, "aliasType");
+
+ /** The alias element name */
+ public static final QName aliasQName = new QName(BEAN_DEPLOYER_NS, "alias");
+
/** The annotation binding */
public static final QName annotationTypeQName = new QName(BEAN_DEPLOYER_NS, "annotationType");
@@ -272,6 +278,10 @@
TypeBinding lifecycleType = schemaBinding.getType(lifecycleTypeQName);
BeanSchemaBindingHelper.initLifecycleHandlers(lifecycleType);
+ // alias binding
+ TypeBinding aliasType = schemaBinding.getType(aliasTypeQName);
+ BeanSchemaBindingHelper.initAliasHandlers(aliasType);
+
// annotation binding
TypeBinding annotationType = schemaBinding.getType(annotationTypeQName);
BeanSchemaBindingHelper.initAnnotationHandlers(annotationType);
Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/BeanSchemaBindingHelper.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/BeanSchemaBindingHelper.java 2007-04-04 14:55:06 UTC (rev 62078)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/BeanSchemaBindingHelper.java 2007-04-04 15:18:38 UTC (rev 62079)
@@ -90,6 +90,9 @@
// bean has a destroy
beanType.pushInterceptor(BeanSchemaBinding20.destroyQName, BeanDestroyInterceptor.INTERCEPTOR);
+ // bean has aliases
+ beanType.pushInterceptor(BeanSchemaBinding20.aliasQName, BeanAliasInterceptor.INTERCEPTOR);
+
// bean has annotations
beanType.pushInterceptor(BeanSchemaBinding20.annotationQName, BeanAnnotationInterceptor.INTERCEPTOR);
@@ -118,6 +121,9 @@
{
beanFactoryType.setHandler(BeanFactoryHandler.HANDLER);
+ // bean factory has aliases
+ beanFactoryType.pushInterceptor(BeanSchemaBinding20.aliasQName, BeanAliasInterceptor.INTERCEPTOR);
+
// bean factory has a classloader
beanFactoryType.pushInterceptor(BeanSchemaBinding20.classloaderQName, BeanClassLoaderInterceptor.INTERCEPTOR);
@@ -251,8 +257,21 @@
}
/**
+ * Initialize the handlers for the alias type
+ *
+ * @param aliasType the alias type
+ */
+ public static void initAliasHandlers(TypeBinding aliasType)
+ {
+ aliasType.setHandler(AliasHandler.HANDLER);
+
+ // annotation can take characters
+ aliasType.setSimpleType(AliasCharactersHandler.HANDLER);
+ }
+
+ /**
* Initialize the handlers for the annotation type
- *
+ *
* @param annotationType the annotation type
*/
public static void initAnnotationHandlers(TypeBinding annotationType)
Modified: projects/microcontainer/trunk/kernel/src/resources/main/schema/bean-deployer_2_0.xsd
===================================================================
--- projects/microcontainer/trunk/kernel/src/resources/main/schema/bean-deployer_2_0.xsd 2007-04-04 14:55:06 UTC (rev 62078)
+++ projects/microcontainer/trunk/kernel/src/resources/main/schema/bean-deployer_2_0.xsd 2007-04-04 15:18:38 UTC (rev 62079)
@@ -81,6 +81,7 @@
</xsd:annotation>
<xsd:sequence>
<xsd:element name="annotation" type="annotationType" minOccurs="0" maxOccurs="unbounded"/>
+ <xsd:element name="alias" type="aliasType" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element name="classloader" type="classloaderType" minOccurs="0"/>
<xsd:element name="constructor" type="constructorType" minOccurs="0"/>
<xsd:element name="property" type="propertyType" minOccurs="0" maxOccurs="unbounded"/>
@@ -150,6 +151,7 @@
</xsd:documentation>
</xsd:annotation>
<xsd:sequence>
+ <xsd:element name="alias" type="aliasType" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element name="classloader" type="classloaderType" minOccurs="0"/>
<xsd:element name="constructor" type="constructorType" minOccurs="0"/>
<xsd:element name="property" type="propertyType" minOccurs="0" maxOccurs="unbounded"/>
@@ -389,13 +391,36 @@
<xsd:attribute name="whenRequired" type="controllerStateType" use="optional"/>
</xsd:complexType>
+ <xsd:complexType name="aliasType" mixed="true">
+ <xsd:annotation>
+ <xsd:documentation>
+ <![CDATA[
+ Bean's aliases.
+
+ e.g.
+ <bean name="MyName" class="com.acme.POJO">
+ <alias>YourName</alias>
+ <alias><value class="java.lang.Class">com.acme.POJO</value></alias>
+ <alias><value class="java.lang.Integer">1234</value></alias>
+ </bean>
+ ]]>
+ </xsd:documentation>
+ </xsd:annotation>
+ <xsd:simpleContent>
+ <xsd:extension base="xsd:string">
+ <xsd:attribute name="class" type="classNameType" use="optional"/>
+ <xsd:attribute name="replace" type="xsd:boolean"/>
+ </xsd:extension>
+ </xsd:simpleContent>
+ </xsd:complexType>
+
<xsd:complexType name="parameterType" mixed="true">
<xsd:annotation>
<xsd:documentation>
<![CDATA[
A parameter is used to define the constructor, factory
and lifecycle method usage.
-
+
e.g. Using number of parameters when this is unique enough
<bean ...>
<constructor>
@@ -403,7 +428,7 @@
<parameter>2nd Parameter</parameter>
</constructor>
</bean>
-
+
e.g. Explicitly stating the parameter type to resolve overloading
<bean ...>
<constructor>
Added: projects/microcontainer/trunk/kernel/src/resources/tests/org/jboss/test/kernel/deployment/xml/test/Alias.xml
===================================================================
--- projects/microcontainer/trunk/kernel/src/resources/tests/org/jboss/test/kernel/deployment/xml/test/Alias.xml (rev 0)
+++ projects/microcontainer/trunk/kernel/src/resources/tests/org/jboss/test/kernel/deployment/xml/test/Alias.xml 2007-04-04 15:18:38 UTC (rev 62079)
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<bean xmlns="urn:jboss:bean-deployer:2.0" class="Dummy">
+ <alias>SimpleAlias</alias>
+</bean>
Added: projects/microcontainer/trunk/kernel/src/resources/tests/org/jboss/test/kernel/deployment/xml/test/AliasWithBeanFactory.xml
===================================================================
--- projects/microcontainer/trunk/kernel/src/resources/tests/org/jboss/test/kernel/deployment/xml/test/AliasWithBeanFactory.xml (rev 0)
+++ projects/microcontainer/trunk/kernel/src/resources/tests/org/jboss/test/kernel/deployment/xml/test/AliasWithBeanFactory.xml 2007-04-04 15:18:38 UTC (rev 62079)
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<beanfactory xmlns="urn:jboss:bean-deployer:2.0" class="Dummy">
+ <alias>SimpleAliasWithBF</alias>
+</beanfactory>
Added: projects/microcontainer/trunk/kernel/src/resources/tests/org/jboss/test/kernel/deployment/xml/test/AliasWithClass.xml
===================================================================
--- projects/microcontainer/trunk/kernel/src/resources/tests/org/jboss/test/kernel/deployment/xml/test/AliasWithClass.xml (rev 0)
+++ projects/microcontainer/trunk/kernel/src/resources/tests/org/jboss/test/kernel/deployment/xml/test/AliasWithClass.xml 2007-04-04 15:18:38 UTC (rev 62079)
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<bean xmlns="urn:jboss:bean-deployer:2.0" class="Dummy">
+ <alias class="java.lang.Integer">12345</alias>
+</bean>
Added: projects/microcontainer/trunk/kernel/src/resources/tests/org/jboss/test/kernel/deployment/xml/test/AliasWithNoReplace.xml
===================================================================
--- projects/microcontainer/trunk/kernel/src/resources/tests/org/jboss/test/kernel/deployment/xml/test/AliasWithNoReplace.xml (rev 0)
+++ projects/microcontainer/trunk/kernel/src/resources/tests/org/jboss/test/kernel/deployment/xml/test/AliasWithNoReplace.xml 2007-04-04 15:18:38 UTC (rev 62079)
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<bean xmlns="urn:jboss:bean-deployer:2.0" class="Dummy">
+ <alias replace="false">X${alias.test.name}X</alias>
+</bean>
Added: projects/microcontainer/trunk/kernel/src/resources/tests/org/jboss/test/kernel/deployment/xml/test/AliasWithReplace.xml
===================================================================
--- projects/microcontainer/trunk/kernel/src/resources/tests/org/jboss/test/kernel/deployment/xml/test/AliasWithReplace.xml (rev 0)
+++ projects/microcontainer/trunk/kernel/src/resources/tests/org/jboss/test/kernel/deployment/xml/test/AliasWithReplace.xml 2007-04-04 15:18:38 UTC (rev 62079)
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<bean xmlns="urn:jboss:bean-deployer:2.0" class="Dummy">
+ <alias replace="true">X${alias.test.name}X</alias>
+</bean>
Added: projects/microcontainer/trunk/kernel/src/resources/tests/org/jboss/test/kernel/deployment/xml/test/MultipleAlias.xml
===================================================================
--- projects/microcontainer/trunk/kernel/src/resources/tests/org/jboss/test/kernel/deployment/xml/test/MultipleAlias.xml (rev 0)
+++ projects/microcontainer/trunk/kernel/src/resources/tests/org/jboss/test/kernel/deployment/xml/test/MultipleAlias.xml 2007-04-04 15:18:38 UTC (rev 62079)
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<bean xmlns="urn:jboss:bean-deployer:2.0" class="Dummy">
+ <alias>alias1</alias>
+ <alias>alias2</alias>
+ <alias>alias3</alias>
+</bean>
Added: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/xml/test/AliasTestCase.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/xml/test/AliasTestCase.java (rev 0)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/xml/test/AliasTestCase.java 2007-04-04 15:18:38 UTC (rev 62079)
@@ -0,0 +1,118 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.test.kernel.deployment.xml.test;
+
+import java.util.Set;
+
+import junit.framework.Test;
+import org.jboss.beans.metadata.plugins.AbstractBeanMetaData;
+
+/**
+ * AliasTestCase.
+ *
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ */
+public class AliasTestCase extends AbstractXMLTest
+{
+ public AliasTestCase(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite()
+ {
+ return suite(AliasTestCase.class);
+ }
+
+ protected Object getAlias(String name) throws Exception
+ {
+ AbstractBeanMetaData bean = unmarshalBean(name);
+ Set aliases = bean.getAliases();
+ assertNotNull(aliases);
+ assertEquals(1, aliases.size());
+ Object alias = aliases.iterator().next();
+ assertNotNull(alias);
+ return alias;
+ }
+
+ public void testAlias() throws Exception
+ {
+ Object alias = getAlias("Alias.xml");
+ assertEquals("SimpleAlias", alias);
+ }
+
+ public void testAliasWithClass() throws Exception
+ {
+ Object alias = getAlias("AliasWithClass.xml");
+ assertEquals(12345, alias);
+ }
+
+ public void testAliasWithReplace() throws Exception
+ {
+ SecurityManager sm = suspendSecurity();
+ try
+ {
+ System.setProperty("alias.test.name", "SimpleAlias");
+ Object alias = getAlias("AliasWithReplace.xml");
+ assertEquals("XSimpleAliasX", alias);
+ }
+ finally
+ {
+ resumeSecurity(sm);
+ }
+ }
+
+ public void testAliasWithNoReplace() throws Exception
+ {
+ SecurityManager sm = suspendSecurity();
+ try
+ {
+ System.setProperty("alias.test.name", "SimpleAlias");
+ Object alias = getAlias("AliasWithNoReplace.xml");
+ assertEquals("X${alias.test.name}X", alias);
+ }
+ finally
+ {
+ resumeSecurity(sm);
+ }
+ }
+
+ public void testMultipleAliases() throws Exception
+ {
+ AbstractBeanMetaData bean = unmarshalBean("MultipleAlias.xml");
+ Set aliases = bean.getAliases();
+ assertNotNull(aliases);
+ int size = aliases.size();
+ assertTrue(size > 1);
+ for(Object alias : aliases)
+ assertNotNull(alias);
+ }
+
+ public void testAliasAndBeanFactory() throws Exception
+ {
+ AbstractBeanMetaData bean = unmarshalBean("AliasWithBeanFactory.xml");
+ Set aliases = bean.getAliases();
+ assertNotNull(aliases);
+ assertFalse(aliases.isEmpty());
+ }
+
+}
Modified: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/xml/test/XMLTestSuite.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/xml/test/XMLTestSuite.java 2007-04-04 14:55:06 UTC (rev 62078)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/xml/test/XMLTestSuite.java 2007-04-04 15:18:38 UTC (rev 62079)
@@ -66,6 +66,7 @@
suite.addTest(ScopeTestCase.suite());
suite.addTest(BindingTestCase.suite());
suite.addTest(PolicyTestCase.suite());
+ suite.addTest(AliasTestCase.suite());
return suite;
}
More information about the jboss-cvs-commits
mailing list