Skip to content

Commit

Permalink
add a jms resource receiving
Browse files Browse the repository at this point in the history
git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@2074 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
Victor Yarmolovich committed Mar 17, 2009
1 parent 46ecc87 commit 903b9d4
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 24 deletions.
5 changes: 5 additions & 0 deletions impl/pom.xml
Expand Up @@ -90,6 +90,11 @@
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
</dependency>

<dependency>
<groupId>javax.jms</groupId>
<artifactId>jms</artifactId>
</dependency>

<dependency>
<groupId>javax.el</groupId>
Expand Down
Expand Up @@ -8,5 +8,5 @@ public interface AnnotatedItemReceiver
{
boolean accept(Element element);

AnnotatedItem<?, ?> reciveAnnotatedItem(Element element);
AnnotatedItem<?, ?> receiveAnnotatedItem(Element element);
}
96 changes: 76 additions & 20 deletions impl/src/main/java/org/jboss/webbeans/util/xml/ParseXmlHelper.java
Expand Up @@ -8,6 +8,9 @@
import java.util.Set;

import javax.inject.DefinitionException;
import javax.jms.JMSException;
import javax.jms.Queue;
import javax.jms.Topic;

import org.dom4j.Element;
import org.jboss.webbeans.CurrentManager;
Expand All @@ -34,18 +37,18 @@ public class ParseXmlHelper
Set<AnnotatedItem<?, ?>> result = new HashSet<AnnotatedItem<?, ?>>();

for (Element bean : beans)
result.add(reciveBeanItem(bean));
result.add(receiveBeanItem(bean));

return result;
}

private static AnnotatedItem<?, ?> reciveBeanItem(Element element)
private static AnnotatedItem<?, ?> receiveBeanItem(Element element)
{
for (AnnotatedItemReceiver receiver : receivers)
{
if (receiver.accept(element))
{
return receiver.reciveAnnotatedItem(element);
return receiver.receiveAnnotatedItem(element);
}
}

Expand All @@ -63,9 +66,9 @@ public boolean accept(Element element)
return isJMSResource(element);
}

public AnnotatedItem<?, ?> reciveAnnotatedItem(Element element)
public AnnotatedItem<?, ?> receiveAnnotatedItem(Element element)
{
return reciveJMSResourceItem(element);
return receiveJMSResourceItem(element);
}

};
Expand All @@ -76,9 +79,9 @@ public boolean accept(Element element)
return isResource(element);
}

public AnnotatedItem<?, ?> reciveAnnotatedItem(Element element)
public AnnotatedItem<?, ?> receiveAnnotatedItem(Element element)
{
return reciveResourceItem(element);
return receiveResourceItem(element);
}

};
Expand All @@ -89,9 +92,9 @@ public boolean accept(Element element)
return isSessionBean(element);
}

public AnnotatedItem<?, ?> reciveAnnotatedItem(Element element)
public AnnotatedItem<?, ?> receiveAnnotatedItem(Element element)
{
return reciveSessionBeanItem(element);
return receiveSessionBeanItem(element);
}

};
Expand All @@ -102,9 +105,9 @@ public boolean accept(Element element)
return isSimpleBean(element);
}

public AnnotatedItem<?, ?> reciveAnnotatedItem(Element element)
public AnnotatedItem<?, ?> receiveAnnotatedItem(Element element)
{
return reciveSimpleBeanItem(element);
return receiveSimpleBeanItem(element);
}

};
Expand All @@ -120,17 +123,39 @@ public boolean accept(Element element)

private static boolean isJMSResource(Element element)
{
if (element.getNamespace().getURI().equalsIgnoreCase(XmlConstants.JAVA_EE_NAMESPACE) &&
if (isJavaEeNamespace(element) &&
(element.getName().equalsIgnoreCase(XmlConstants.TOPIC) ||
element.getName().equalsIgnoreCase(XmlConstants.QUEUE)))
return true;
return false;
}

private static AnnotatedItem<?, ?> reciveJMSResourceItem(Element element)
private static AnnotatedItem<?, ?> receiveJMSResourceItem(Element element)
{
// TODO:
return null;
final Element jmsElement = element;

if(jmsElement.getName().equalsIgnoreCase(XmlConstants.QUEUE))
{
Queue queue = new Queue()
{
public String getQueueName() throws JMSException
{
return getJmsResourceName(jmsElement);
}
};

return AnnotatedClassImpl.of(queue.getClass());
}

Topic topic = new Topic()
{
public String getTopicName() throws JMSException
{
return getJmsResourceName(jmsElement);
}
};

return AnnotatedClassImpl.of(topic.getClass());
}

private static boolean isResource(Element element)
Expand All @@ -139,7 +164,7 @@ private static boolean isResource(Element element)
while (elIterator.hasNext())
{
Element child = (Element) elIterator.next();
if (child.getNamespace().getURI().equalsIgnoreCase(XmlConstants.JAVA_EE_NAMESPACE) &&
if (isJavaEeNamespace(child) &&
(child.getName().equalsIgnoreCase(XmlConstants.RESOURCE) ||
child.getName().equalsIgnoreCase(XmlConstants.PERSISTENCE_CONTEXT) ||
child.getName().equalsIgnoreCase(XmlConstants.PERSISTENCE_UNIT) ||
Expand All @@ -150,7 +175,7 @@ private static boolean isResource(Element element)
return false;
}

private static AnnotatedItem<?, ?> reciveResourceItem(Element element)
private static AnnotatedItem<?, ?> receiveResourceItem(Element element)
{
// TODO:
return null;
Expand All @@ -165,7 +190,7 @@ private static boolean isSessionBean(Element element)
return false;
}

private static AnnotatedItem<?, ?> reciveSessionBeanItem(Element element)
private static AnnotatedItem<?, ?> receiveSessionBeanItem(Element element)
{
// TODO:
return null;
Expand All @@ -182,11 +207,12 @@ private static boolean isSimpleBean(Element element)
return false;
}

private static AnnotatedItem<?, ?> reciveSimpleBeanItem(Element element)
private static AnnotatedItem<?, ?> receiveSimpleBeanItem(Element element)
{
Class<?> beanClass = loadClass(element);

if (!Modifier.isStatic(beanClass.getModifiers()) && beanClass.isMemberClass())
if (!Modifier.isStatic(beanClass.getModifiers()) &&
beanClass.isMemberClass())
throw new DefinitionException("class " + beanClass + " is a non-static inner class");

// if (beanClass.getTypeParameters().length > 0)
Expand All @@ -209,4 +235,34 @@ private static Class<?> loadClass(Element element)
String classPath = packageName + "." + element.getName();
return resourceLoader.classForName(classPath);
}

private static String getJmsResourceName(Element element)
{
Iterator<?> elIterator = element.elementIterator();
while (elIterator.hasNext())
{
Element child = (Element) elIterator.next();
if (isJavaEeNamespace(child) &&
child.getName().equalsIgnoreCase(XmlConstants.RESOURCE))
{
Iterator<?> chIterator = child.elementIterator();
while(chIterator.hasNext())
{
Element chChild = (Element) chIterator.next();
if (isJavaEeNamespace(chChild) &&
(chChild.getName().equalsIgnoreCase(XmlConstants.NAME) ||
chChild.getName().equalsIgnoreCase(XmlConstants.MAPPED_NAME)))
{
return chChild.getName();
}
}
}
}
throw new DefinitionException("Incorrect JMSResource declaration for " + element.getName());
}

public static boolean isJavaEeNamespace(Element element)
{
return element.getNamespace().getURI().equalsIgnoreCase(XmlConstants.JAVA_EE_NAMESPACE);
}
}
Expand Up @@ -33,4 +33,8 @@ public class XmlConstants
public static final String QUEUE = "Queue";

public static final String URN_PREFIX = "urn:java:";

public static final String NAME = "name";

public static final String MAPPED_NAME = "mappedName";
}
Expand Up @@ -2,7 +2,6 @@

import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.AnnotatedElement;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashSet;
Expand Down Expand Up @@ -69,7 +68,7 @@ private List<Element> findBeans(Document document)

private boolean checkElementName(Element element)
{
if (element.getNamespace().getURI().equalsIgnoreCase(XmlConstants.JAVA_EE_NAMESPACE) &&
if (ParseXmlHelper.isJavaEeNamespace(element) &&
(element.getName().equalsIgnoreCase(XmlConstants.DEPLOY) ||
element.getName().equalsIgnoreCase(XmlConstants.INTERCEPTORS) ||
element.getName().equalsIgnoreCase(XmlConstants.DECORATORS)))
Expand All @@ -83,7 +82,7 @@ private boolean checkElementChildrenNames(Element element)
while (elIterator.hasNext())
{
Element child = (Element) elIterator.next();
if (child.getNamespace().getURI().equalsIgnoreCase(XmlConstants.JAVA_EE_NAMESPACE) &&
if (ParseXmlHelper.isJavaEeNamespace(child) &&
(child.getName().equalsIgnoreCase(XmlConstants.BINDING_TYPE) ||
child.getName().equalsIgnoreCase(XmlConstants.INTERCEPTOR_BINDING_TYPE) ||
child.getName().equalsIgnoreCase(XmlConstants.STEREOTYPE)))
Expand Down
6 changes: 6 additions & 0 deletions version-matrix/pom.xml
Expand Up @@ -121,6 +121,12 @@
<version>1.6.1</version>
</dependency>

<dependency>
<groupId>javax.jms</groupId>
<artifactId>jms</artifactId>
<version>1.1</version>
</dependency>

<dependency>
<groupId>javax.el</groupId>
<artifactId>el-api</artifactId>
Expand Down

0 comments on commit 903b9d4

Please sign in to comment.