[webbeans-commits] Webbeans SVN: r2147 - ri/trunk/impl/src/main/java/org/jboss/webbeans/xml.
by webbeans-commits@lists.jboss.org
Author: vitold
Date: 2009-03-23 11:09:12 -0400 (Mon, 23 Mar 2009)
New Revision: 2147
Removed:
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/AnnotatedItemReceiver.java
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/ParseXmlHelper.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlParser.java
Log:
changes with getting bean class
Deleted: ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/AnnotatedItemReceiver.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/AnnotatedItemReceiver.java 2009-03-23 14:25:23 UTC (rev 2146)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/AnnotatedItemReceiver.java 2009-03-23 15:09:12 UTC (rev 2147)
@@ -1,12 +0,0 @@
-package org.jboss.webbeans.xml;
-
-
-import org.dom4j.Element;
-import org.jboss.webbeans.introspector.AnnotatedItem;
-
-public interface AnnotatedItemReceiver
-{
- boolean accept(Element element);
-
- AnnotatedItem<?, ?> receiveAnnotatedItem(Element element);
-}
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/ParseXmlHelper.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/ParseXmlHelper.java 2009-03-23 14:25:23 UTC (rev 2146)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/ParseXmlHelper.java 2009-03-23 15:09:12 UTC (rev 2147)
@@ -1,7 +1,6 @@
package org.jboss.webbeans.xml;
import java.io.IOException;
-import java.lang.reflect.Modifier;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashSet;
@@ -12,261 +11,23 @@
import java.util.Set;
import javax.inject.DefinitionException;
-import javax.jms.JMSException;
-import javax.jms.Queue;
-import javax.jms.Topic;
import org.dom4j.Attribute;
import org.dom4j.Element;
import org.dom4j.Namespace;
-import org.jboss.webbeans.CurrentManager;
-import org.jboss.webbeans.ManagerImpl;
-import org.jboss.webbeans.introspector.AnnotatedItem;
-import org.jboss.webbeans.introspector.jlr.AnnotatedClassImpl;
+import org.jboss.webbeans.introspector.AnnotatedClass;
import org.jboss.webbeans.resources.spi.ResourceLoadingException;
public class ParseXmlHelper
-{
- private static List<AnnotatedItemReceiver> receivers;
-
- static
- {
- receivers = initializeReceivers();
- }
-
- public static Set<AnnotatedItem<?, ?>> getBeanItems(List<Element> beans)
- {
- Set<AnnotatedItem<?, ?>> result = new HashSet<AnnotatedItem<?, ?>>();
-
- for (Element bean : beans)
- result.add(receiveBeanItem(bean));
-
- return result;
- }
-
- private static AnnotatedItem<?, ?> receiveBeanItem(Element element)
- {
- for (AnnotatedItemReceiver receiver : receivers)
- {
- if (receiver.accept(element))
- {
- return receiver.receiveAnnotatedItem(element);
- }
- }
-
- throw new DefinitionException("definition of a bean " + element.getName() + " is incorrect");
- }
-
- private static List<AnnotatedItemReceiver> initializeReceivers()
- {
- List<AnnotatedItemReceiver> receivers = new ArrayList<AnnotatedItemReceiver>();
-
- AnnotatedItemReceiver jmsResourceReceiver = new AnnotatedItemReceiver()
- {
- public boolean accept(Element element)
- {
- return isJMSResource(element);
- }
-
- public AnnotatedItem<?, ?> receiveAnnotatedItem(Element element)
- {
- return receiveJMSResourceItem(element);
- }
-
- };
- AnnotatedItemReceiver resourceReceiver = new AnnotatedItemReceiver()
- {
- public boolean accept(Element element)
- {
- return isResource(element);
- }
-
- public AnnotatedItem<?, ?> receiveAnnotatedItem(Element element)
- {
- return receiveResourceItem(element);
- }
-
- };
- AnnotatedItemReceiver sessionBeanReceiver = new AnnotatedItemReceiver()
- {
- public boolean accept(Element element)
- {
- return isSessionBean(element);
- }
-
- public AnnotatedItem<?, ?> receiveAnnotatedItem(Element element)
- {
- return receiveSessionBeanItem(element);
- }
-
- };
- AnnotatedItemReceiver simpleBeanReceiver = new AnnotatedItemReceiver()
- {
- public boolean accept(Element element)
- {
- return isSimpleBean(element);
- }
-
- public AnnotatedItem<?, ?> receiveAnnotatedItem(Element element)
- {
- return receiveSimpleBeanItem(element);
- }
-
- };
-
- //order of elements is important
- receivers.add(jmsResourceReceiver);
- receivers.add(resourceReceiver);
- receivers.add(sessionBeanReceiver);
- receivers.add(simpleBeanReceiver);
-
- return receivers;
- }
-
- private static boolean isJMSResource(Element element)
- {
- if (isJavaEeNamespace(element) &&
- (element.getName().equalsIgnoreCase(XmlConstants.TOPIC) ||
- element.getName().equalsIgnoreCase(XmlConstants.QUEUE)))
- return true;
- return false;
- }
-
- private static AnnotatedItem<?, ?> receiveJMSResourceItem(Element element)
- {
- 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)
- {
- Iterator<?> elIterator = element.elementIterator();
- while (elIterator.hasNext())
- {
- Element child = (Element) elIterator.next();
- if (isJavaEeNamespace(child) &&
- (child.getName().equalsIgnoreCase(XmlConstants.RESOURCE) ||
- child.getName().equalsIgnoreCase(XmlConstants.PERSISTENCE_CONTEXT) ||
- child.getName().equalsIgnoreCase(XmlConstants.PERSISTENCE_UNIT) ||
- child.getName().equalsIgnoreCase(XmlConstants.EJB) ||
- child.getName().equalsIgnoreCase(XmlConstants.WEB_SERVICE_REF)))
- return true;
- }
- return false;
- }
-
- private static AnnotatedItem<?, ?> receiveResourceItem(Element element)
- {
- // TODO:
- return null;
- }
-
- private static boolean isSessionBean(Element element)
- {
- ManagerImpl manager = CurrentManager.rootManager();
- if (manager.getEjbDescriptorCache().containsKey(element.getName()) ||
- element.attribute(XmlConstants.EJB_NAME) != null)
- return true;
- return false;
- }
-
- private static AnnotatedItem<?, ?> receiveSessionBeanItem(Element element)
- {
- // TODO:
- return null;
- }
-
- private static boolean isSimpleBean(Element element)
- {
- //TODO
- String urn = element.getNamespace().getURI();
- Class<?> beanClass = null;//loadElementClass(urn, element.getName());
-
- if (!Modifier.isAbstract(beanClass.getModifiers()) &&
- beanClass.getTypeParameters().length == 0)
- return true;
-
- return false;
- }
-
- private static AnnotatedItem<?, ?> receiveSimpleBeanItem(Element element)
- {
- //TODO
- String urn = element.getNamespace().getURI();
- Class<?> beanClass = null;//loadElementClass(urn, element.getName());
-
- if (!Modifier.isStatic(beanClass.getModifiers()) &&
- beanClass.isMemberClass())
- throw new DefinitionException("class " + beanClass + " is a non-static inner class");
-
- // if (beanClass.getTypeParameters().length > 0)
- // throw new DefinitionException("class " + beanClass +
- // " is a parameterized type");
-
- // TODO:
- // boolean isDecorator = false;
- // if (Modifier.isAbstract(beanClass.getModifiers()) && !isDecorator)
- // throw new DefinitionException("class " + beanClass +
- // " is an abstract and not Decorator");
-
- return AnnotatedClassImpl.of(beanClass);
- }
-
- 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);
}
- public static <T> Class<? extends T> loadElementClass(Element element, Class<T> expectedType, XmlEnvironment environment, Map<String, Set<String>> packagesMap)
+ public static <T> AnnotatedClass<? extends T> loadElementClass(Element element, Class<T> expectedType, XmlEnvironment environment, Map<String, Set<String>> packagesMap)
{
- List<Class<? extends T>> classesList = new ArrayList<Class<? extends T>>();
+ List<AnnotatedClass<? extends T>> classesList = new ArrayList<AnnotatedClass<? extends T>>();
String className = element.getName();
String prefix = element.getNamespacePrefix();
@@ -280,7 +41,7 @@
String classPath = packageName + "." + element.getName();
try
{
- Class<? extends T> classType = environment.loadClass(classPath, expectedType).getRawType();
+ AnnotatedClass<? extends T> classType = environment.loadClass(classPath, expectedType);
classesList.add(classType);
}
catch(ResourceLoadingException e){}
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlParser.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlParser.java 2009-03-23 14:25:23 UTC (rev 2146)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlParser.java 2009-03-23 15:09:12 UTC (rev 2147)
@@ -21,6 +21,7 @@
import org.dom4j.Namespace;
import org.dom4j.QName;
import org.dom4j.io.SAXReader;
+import org.jboss.webbeans.introspector.AnnotatedClass;
import org.jboss.webbeans.log.Log;
import org.jboss.webbeans.log.Logging;
@@ -54,9 +55,16 @@
private void parseForBeans(Document document)
{
- List<Element> beanElements = findBeans(document);
- // TODO Only pass in classes here
- //environment.getClasses().addAll(ParseXmlHelper.getBeanItems(beanElements));
+ List<AnnotatedClass<?>> beanClasses = new ArrayList<AnnotatedClass<?>>();
+
+ List<Element> beanElements = findBeans(document);
+ for (Element beanElement : beanElements)
+ {
+ AnnotatedClass<?> beanClass = ParseXmlHelper.loadElementClass(beanElement, Object.class, environment, packagesMap);
+ beanClasses.add(beanClass);
+ }
+
+ environment.getClasses().addAll(beanClasses);
}
private void parseForDeploy(Document document)
@@ -173,12 +181,12 @@
List<Element> children = element.elements();
for (Element child : children)
{
- Class<? extends Annotation> deploymentClass = ParseXmlHelper.loadElementClass(child, Annotation.class, environment, packagesMap);
+ AnnotatedClass<? extends Annotation> deploymentClass = ParseXmlHelper.loadElementClass(child, Annotation.class, environment, packagesMap);
// if(deploymentClass.getAnnotation(DeploymentType.class) == null)
// throw new DefinitionException("<Deploy> child <" + element.getName() + "> must be a deployment type");
- deploymentClasses.add(deploymentClass);
+ deploymentClasses.add(deploymentClass.getRawType());
}
haveAnyDeployElement = true;
return deploymentClasses;
15 years, 10 months
[webbeans-commits] Webbeans SVN: r2146 - ri/trunk/impl/src/main/java/org/jboss/webbeans/xml.
by webbeans-commits@lists.jboss.org
Author: vitold
Date: 2009-03-23 10:25:23 -0400 (Mon, 23 Mar 2009)
New Revision: 2146
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/ParseXmlHelper.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlConstants.java
Log:
add validation if 'schema.xsd' file present
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/ParseXmlHelper.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/ParseXmlHelper.java 2009-03-23 12:59:18 UTC (rev 2145)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/ParseXmlHelper.java 2009-03-23 14:25:23 UTC (rev 2146)
@@ -307,15 +307,24 @@
String attrPrefix = attribute.getNamespacePrefix();
String attrData = attribute.getStringValue();
+ String urn = "";
for(String attrVal : attrData.split(" "))
{
if(attrVal.startsWith(XmlConstants.URN_PREFIX))
{
- URL namespaceFile = loadNamespaceFile(attrVal);
+ urn = attrVal;
+ URL namespaceFile = loadFile(urn, XmlConstants.NAMESPACE_FILE_NAME);
if(namespaceFile == null)
- throw new DefinitionException("Could not find 'namespace' file according to specified URN '" + attrVal + "'");
+ throw new DefinitionException("Could not find '" + XmlConstants.NAMESPACE_FILE_NAME + "' file according to specified URN '" + urn + "'");
packagesSet.addAll(parseNamespaceFile(namespaceFile));
}
+ if(attribute.getName().equalsIgnoreCase(XmlConstants.SCHEMA_LOCATION) &&
+ attrVal.startsWith(XmlConstants.HTTP_PREFIX) && urn.trim().length() > 0)
+ {
+ URL schemaFile = loadFile(urn, XmlConstants.SCHEMA_FILE_NAME);
+ if(schemaFile == null)
+ throw new DefinitionException("Could not find '" + XmlConstants.SCHEMA_FILE_NAME + "' file according to specified URN '" + urn + "'");
+ }
}
addElementToPackagesMap(packagesMap, attrPrefix, packagesSet);
@@ -334,7 +343,7 @@
{
Set<String> packagesSet = new HashSet<String>();
- URL namespaceFile = loadNamespaceFile(uri);
+ URL namespaceFile = loadFile(uri, XmlConstants.NAMESPACE_FILE_NAME);
if(namespaceFile != null)
{
packagesSet.addAll(parseNamespaceFile(namespaceFile));
@@ -350,12 +359,12 @@
}
}
- private static URL loadNamespaceFile(String urn)
+ private static URL loadFile(String urn, String fileName)
{
char separator = '/';
String packageName = urn.replaceFirst(XmlConstants.URN_PREFIX, "");
String path = packageName.replace('.', separator);
- String filePath = separator + path + separator + XmlConstants.NAMESPACE_FILE_NAME;
+ String filePath = separator + path + separator + fileName;
URL namespaceFile = ParseXmlHelper.class.getResource(filePath);
return namespaceFile;
}
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlConstants.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlConstants.java 2009-03-23 12:59:18 UTC (rev 2145)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlConstants.java 2009-03-23 14:25:23 UTC (rev 2146)
@@ -33,6 +33,10 @@
public static final String QUEUE = "Queue";
public static final String URN_PREFIX = "urn:java:";
+
+ public static final String HTTP_PREFIX = "http://";
+
+ public static final String SCHEMA_LOCATION = "schemaLocation";
public static final String NAME = "name";
@@ -42,5 +46,7 @@
public static final String NAMESPACE_FILE_NAME = "namespace";
+ public static final String SCHEMA_FILE_NAME = "schema.xsd";
+
public static final String NAMESPACE_FILE_DELIMETER = " ";
}
15 years, 10 months
[webbeans-commits] Webbeans SVN: r2145 - in ri/trunk: tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering and 1 other directory.
by webbeans-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2009-03-23 08:59:18 -0400 (Mon, 23 Mar 2009)
New Revision: 2145
Added:
ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployerEnvironment.java
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployer.java
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/DeployerOrderingTest.java
Log:
Split out a bean deployer environment
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployer.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployer.java 2009-03-23 12:34:19 UTC (rev 2144)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployer.java 2009-03-23 12:59:18 UTC (rev 2145)
@@ -26,6 +26,7 @@
import org.jboss.webbeans.event.ObserverImpl;
import org.jboss.webbeans.introspector.AnnotatedClass;
import org.jboss.webbeans.introspector.AnnotatedField;
+import org.jboss.webbeans.introspector.AnnotatedItem;
import org.jboss.webbeans.introspector.AnnotatedMethod;
import org.jboss.webbeans.introspector.WrappedAnnotatedField;
import org.jboss.webbeans.introspector.WrappedAnnotatedMethod;
@@ -41,25 +42,29 @@
private static final LogProvider log = Logging.getLogProvider(BeanDeployer.class);
- private final Set<RIBean<?>> beans;
- private final Set<ObserverImpl<?>> observers;
+ private final BeanDeployerEnvironment beanDeployerEnvironment;
private final Set<AnnotatedClass<?>> classes;
private final ManagerImpl manager;
public BeanDeployer(ManagerImpl manager)
{
this.manager = manager;
- this.beans = new TreeSet<RIBean<?>>(new BootstrapOrderingBeanComparator());
+ this.beanDeployerEnvironment = new BeanDeployerEnvironment();
this.classes = new HashSet<AnnotatedClass<?>>();
- this.observers = new HashSet<ObserverImpl<?>>();
}
- public BeanDeployer addBean(RIBean<?> bean)
+ public <T> BeanDeployer addBean(AnnotatedItem<T, ?> item, RIBean<T> bean)
{
- this.beans.add(bean);
+ this.beanDeployerEnvironment.addBean(item, bean);
return this;
}
+ public <T> BeanDeployer addBean(RIBean<T> bean)
+ {
+ this.beanDeployerEnvironment.addBean(null, bean);
+ return this;
+ }
+
public BeanDeployer addClass(Class<?> clazz)
{
if (!clazz.isAnnotation() && !clazz.isEnum())
@@ -96,13 +101,15 @@
public BeanDeployer deploy()
{
+ Set<RIBean<?>> beans = new TreeSet<RIBean<?>>(new BootstrapOrderingBeanComparator());
+ beans.addAll(beanDeployerEnvironment.getBeans());
for (RIBean<?> bean : beans)
{
bean.initialize();
log.info("Bean: " + bean);
}
manager.setBeans(beans);
- for (ObserverImpl<?> observer : observers)
+ for (ObserverImpl<?> observer : beanDeployerEnvironment.getObservers())
{
observer.initialize();
log.info("Observer : " + observer);
@@ -110,17 +117,12 @@
}
return this;
}
-
- public Set<RIBean<?>> getBeans()
+
+ public BeanDeployerEnvironment getBeanDeployerEnvironment()
{
- return beans;
+ return beanDeployerEnvironment;
}
- protected void printBeans()
- {
-
- }
-
/**
* Creates a Web Bean from a bean abstraction and adds it to the set of
* created beans
@@ -130,10 +132,10 @@
* @param bean
* The bean representation
*/
- protected void createBean(AbstractClassBean<?> bean, final AnnotatedClass<?> annotatedClass)
+ protected <T> void createBean(AbstractClassBean<T> bean, final AnnotatedClass<T> annotatedClass)
{
- beans.add(bean);
+ addBean(annotatedClass, bean);
manager.getResolver().addInjectionPoints(bean.getInjectionPoints());
@@ -158,10 +160,10 @@
}
}
- private void createProducerMethod(AbstractClassBean<?> declaringBean, AnnotatedMethod<?> annotatedMethod)
+ private <T> void createProducerMethod(AbstractClassBean<?> declaringBean, AnnotatedMethod<T> annotatedMethod)
{
- ProducerMethodBean<?> bean = ProducerMethodBean.of(annotatedMethod, declaringBean, manager);
- beans.add(bean);
+ ProducerMethodBean<T> bean = ProducerMethodBean.of(annotatedMethod, declaringBean, manager);
+ addBean(annotatedMethod, bean);
manager.getResolver().addInjectionPoints(bean.getInjectionPoints());
}
@@ -183,10 +185,10 @@
}
}
- private void createProducerField(AbstractClassBean<?> declaringBean, AnnotatedField<?> field)
+ private <T> void createProducerField(AbstractClassBean<?> declaringBean, AnnotatedField<T> field)
{
- ProducerFieldBean<?> bean = ProducerFieldBean.of(field, declaringBean, manager);
- beans.add(bean);
+ ProducerFieldBean<T> bean = ProducerFieldBean.of(field, declaringBean, manager);
+ addBean(field, bean);
}
private void createProducerFields(AbstractClassBean<?> declaringBean, AnnotatedClass<?> annotatedClass)
@@ -213,22 +215,22 @@
private void createObserverMethod(AbstractClassBean<?> declaringBean, AnnotatedMethod<?> method)
{
ObserverImpl<?> observer = ObserverFactory.create(method, declaringBean, manager);
- observers.add(observer);
+ beanDeployerEnvironment.getObservers().add(observer);
}
- private void createSimpleBean(AnnotatedClass<?> annotatedClass)
+ private <T> void createSimpleBean(AnnotatedClass<T> annotatedClass)
{
- SimpleBean<?> bean = SimpleBean.of(annotatedClass, manager);
+ SimpleBean<T> bean = SimpleBean.of(annotatedClass, manager);
createBean(bean, annotatedClass);
- beans.add(NewSimpleBean.of(annotatedClass, manager));
+ addBean(NewSimpleBean.of(annotatedClass, manager));
}
- private void createEnterpriseBean(AnnotatedClass<?> annotatedClass)
+ private <T> void createEnterpriseBean(AnnotatedClass<T> annotatedClass)
{
// TODO Don't create enterprise bean if it has no local interfaces!
- EnterpriseBean<?> bean = EnterpriseBean.of(annotatedClass, manager);
+ EnterpriseBean<T> bean = EnterpriseBean.of(annotatedClass, manager);
createBean(bean, annotatedClass);
- beans.add(NewEnterpriseBean.of(annotatedClass, manager));
+ addBean(NewEnterpriseBean.of(annotatedClass, manager));
}
/**
Added: ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployerEnvironment.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployerEnvironment.java (rev 0)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployerEnvironment.java 2009-03-23 12:59:18 UTC (rev 2145)
@@ -0,0 +1,62 @@
+package org.jboss.webbeans.bootstrap;
+
+import java.lang.annotation.Annotation;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
+
+import org.jboss.webbeans.bean.RIBean;
+import org.jboss.webbeans.event.ObserverImpl;
+import org.jboss.webbeans.injection.resolution.ResolvableAnnotatedClass;
+import org.jboss.webbeans.introspector.AnnotatedItem;
+
+public class BeanDeployerEnvironment
+{
+
+ private static final AnnotatedItem<?, ?> OTHER_BEANS_ANNOTATED_ITEM = ResolvableAnnotatedClass.of(BeanDeployerEnvironment.class, new Annotation[0]);
+
+ private final Map<AnnotatedItem<?, ?>, Set<RIBean<?>>> beanMap;
+ private final Set<ObserverImpl<?>> observers;
+
+ public BeanDeployerEnvironment()
+ {
+ this.beanMap = new HashMap<AnnotatedItem<?,?>, Set<RIBean<?>>>();
+ this.observers = new HashSet<ObserverImpl<?>>();
+ }
+
+ public Map<AnnotatedItem<?, ?>, Set<RIBean<?>>> getBeanMap()
+ {
+ return beanMap;
+ }
+
+ public void addBean(AnnotatedItem<?, ?> key, RIBean<?> value)
+ {
+ if (key == null)
+ {
+ key = OTHER_BEANS_ANNOTATED_ITEM;
+ }
+ if (!beanMap.containsKey(key))
+ {
+ beanMap.put(key, new HashSet<RIBean<?>>());
+ }
+ beanMap.get(key).add(value);
+ }
+
+ public Set<RIBean<?>> getBeans()
+ {
+ Set<RIBean<?>> beans = new HashSet<RIBean<?>>();
+ for (Entry<AnnotatedItem<?, ?>, Set<RIBean<?>>> entry : beanMap.entrySet())
+ {
+ beans.addAll(entry.getValue());
+ }
+ return beans;
+ }
+
+ public Set<ObserverImpl<?>> getObservers()
+ {
+ return observers;
+ }
+
+}
Property changes on: ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployerEnvironment.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/DeployerOrderingTest.java
===================================================================
--- ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/DeployerOrderingTest.java 2009-03-23 12:34:19 UTC (rev 2144)
+++ ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/DeployerOrderingTest.java 2009-03-23 12:59:18 UTC (rev 2145)
@@ -2,6 +2,8 @@
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Set;
+import java.util.TreeSet;
import javax.inject.AnnotationLiteral;
@@ -17,6 +19,7 @@
import org.jboss.webbeans.bean.standard.InstanceBean;
import org.jboss.webbeans.bean.standard.ManagerBean;
import org.jboss.webbeans.bootstrap.BeanDeployer;
+import org.jboss.webbeans.bootstrap.BootstrapOrderingBeanComparator;
import org.jboss.webbeans.literal.NewLiteral;
import org.jboss.webbeans.mock.MockEjbDescriptor;
import org.jboss.webbeans.mock.MockServletLifecycle;
@@ -61,13 +64,15 @@
BeanDeployer beanDeployer = new BeanDeployer(manager);
beanDeployer.addClasses(Arrays.asList(Cow.class, Tuna.class));
beanDeployer.createBeans();
- assert beanDeployer.getBeans().size() == 4;
- for (RIBean<?> bean : new ArrayList<RIBean<?>>(beanDeployer.getBeans()).subList(0, 2))
+ Set<RIBean<?>> beans = new TreeSet<RIBean<?>>(new BootstrapOrderingBeanComparator());
+ beans.addAll(beanDeployer.getBeanDeployerEnvironment().getBeans());
+ assert beans.size() == 4;
+ for (RIBean<?> bean : new ArrayList<RIBean<?>>(beans).subList(0, 2))
{
assert !(bean instanceof NewBean);
assert bean instanceof SimpleBean;
}
- for (RIBean<?> bean : new ArrayList<RIBean<?>>(beanDeployer.getBeans()).subList(2, 4))
+ for (RIBean<?> bean : new ArrayList<RIBean<?>>(beans).subList(2, 4))
{
assert (bean instanceof NewBean);
assert bean instanceof SimpleBean;
@@ -82,13 +87,15 @@
manager.getEjbDescriptorCache().add(MockEjbDescriptor.of(Lion.class));
manager.getEjbDescriptorCache().add(MockEjbDescriptor.of(Gazelle.class));
beanDeployer.createBeans();
- assert beanDeployer.getBeans().size() == 4;
- for (RIBean<?> bean : new ArrayList<RIBean<?>>(beanDeployer.getBeans()).subList(0, 2))
+ Set<RIBean<?>> beans = new TreeSet<RIBean<?>>(new BootstrapOrderingBeanComparator());
+ beans.addAll(beanDeployer.getBeanDeployerEnvironment().getBeans());
+ assert beans.size() == 4;
+ for (RIBean<?> bean : new ArrayList<RIBean<?>>(beans).subList(0, 2))
{
assert !(bean instanceof NewBean);
assert bean instanceof EnterpriseBean;
}
- for (RIBean<?> bean : new ArrayList<RIBean<?>>(beanDeployer.getBeans()).subList(2, 4))
+ for (RIBean<?> bean : new ArrayList<RIBean<?>>(beans).subList(2, 4))
{
assert (bean instanceof NewBean);
assert bean instanceof EnterpriseBean;
@@ -102,17 +109,19 @@
beanDeployer.addBean(EventBean.of(manager)).addBean(InjectionPointBean.of(manager)).addBean(InstanceBean.of(manager)).addBean(ManagerBean.of(manager));
beanDeployer.addClasses(Arrays.asList(Cow.class, Tuna.class));
beanDeployer.createBeans();
- assert beanDeployer.getBeans().size() == 8;
- for (RIBean<?> bean : new ArrayList<RIBean<?>>(beanDeployer.getBeans()).subList(0, 4))
+ Set<RIBean<?>> beans = new TreeSet<RIBean<?>>(new BootstrapOrderingBeanComparator());
+ beans.addAll(beanDeployer.getBeanDeployerEnvironment().getBeans());
+ assert beans.size() == 8;
+ for (RIBean<?> bean : new ArrayList<RIBean<?>>(beans).subList(0, 4))
{
assert bean instanceof AbstractStandardBean;
}
- for (RIBean<?> bean : new ArrayList<RIBean<?>>(beanDeployer.getBeans()).subList(4, 6))
+ for (RIBean<?> bean : new ArrayList<RIBean<?>>(beans).subList(4, 6))
{
assert !(bean instanceof NewBean);
assert bean instanceof SimpleBean;
}
- for (RIBean<?> bean : new ArrayList<RIBean<?>>(beanDeployer.getBeans()).subList(6, 8))
+ for (RIBean<?> bean : new ArrayList<RIBean<?>>(beans).subList(6, 8))
{
assert (bean instanceof NewBean);
assert bean instanceof SimpleBean;
@@ -125,12 +134,14 @@
BeanDeployer beanDeployer = new BeanDeployer(manager);
beanDeployer.addClasses(Arrays.asList(Cow.class, Tuna.class, RoadRunner.class));
beanDeployer.createBeans();
- assert beanDeployer.getBeans().size() == 6;
- for (RIBean<?> bean : new ArrayList<RIBean<?>>(beanDeployer.getBeans()).subList(0, 4))
+ Set<RIBean<?>> beans = new TreeSet<RIBean<?>>(new BootstrapOrderingBeanComparator());
+ beans.addAll(beanDeployer.getBeanDeployerEnvironment().getBeans());
+ assert beans.size() == 6;
+ for (RIBean<?> bean : new ArrayList<RIBean<?>>(beans).subList(0, 4))
{
assert bean.getType().getName().startsWith("org.jboss.webbeans");
}
- for (RIBean<?> bean : new ArrayList<RIBean<?>>(beanDeployer.getBeans()).subList(4, 6))
+ for (RIBean<?> bean : new ArrayList<RIBean<?>>(beans).subList(4, 6))
{
assert bean.getType().getName().startsWith("com.acme");
}
@@ -145,8 +156,10 @@
int indexOfProducerDeclaringBean = 0;
int indexOfProducer = 0;
int i = 0;
- assert beanDeployer.getBeans().size() == 5;
- for (RIBean<?> bean : beanDeployer.getBeans())
+ Set<RIBean<?>> beans = new TreeSet<RIBean<?>>(new BootstrapOrderingBeanComparator());
+ beans.addAll(beanDeployer.getBeanDeployerEnvironment().getBeans());
+ assert beans.size() == 5;
+ for (RIBean<?> bean : beans)
{
if (bean.getType().equals(TarantulaProducer.class) && !bean.getBindings().contains(new NewLiteral()))
{
@@ -167,12 +180,14 @@
BeanDeployer beanDeployer = new BeanDeployer(manager);
beanDeployer.addClasses(Arrays.asList(Spider.class, Tarantula.class, DefangedTarantula.class, Tuna.class));
beanDeployer.createBeans();
- assert beanDeployer.getBeans().size() == 8;
+ Set<RIBean<?>> beans = new TreeSet<RIBean<?>>(new BootstrapOrderingBeanComparator());
+ beans.addAll(beanDeployer.getBeanDeployerEnvironment().getBeans());
+ assert beans.size() == 8;
int indexOfSpider = 0;
int indexOfTarantula = 0;
int indexOfDefangedTarantula = 0;
int i = 0;
- for (RIBean<?> bean : beanDeployer.getBeans())
+ for (RIBean<?> bean : beans)
{
if (bean.getType().equals(Spider.class))
{
@@ -198,13 +213,15 @@
BeanDeployer beanDeployer = new BeanDeployer(manager);
beanDeployer.addClasses(Arrays.asList(Shop.class, JewelryShop.class, Tuna.class));
beanDeployer.createBeans();
- assert beanDeployer.getBeans().size() == 8;
+ Set<RIBean<?>> beans = new TreeSet<RIBean<?>>(new BootstrapOrderingBeanComparator());
+ beans.addAll(beanDeployer.getBeanDeployerEnvironment().getBeans());
+ assert beans.size() == 8;
int indexOfShop = 0;
int indexOfJewelryShop = 0;
int indexOfExpensiveGift = 0;
int indexOfNecklace = 0;
int i = 0;
- for (RIBean<?> bean : beanDeployer.getBeans())
+ for (RIBean<?> bean : beans)
{
if (bean.getType().equals(Shop.class) && !bean.getBindings().contains(new NewLiteral()))
{
15 years, 10 months
[webbeans-commits] Webbeans SVN: r2144 - ri/trunk/impl/src/main/java/org/jboss/webbeans/xml.
by webbeans-commits@lists.jboss.org
Author: vitold
Date: 2009-03-23 08:34:19 -0400 (Mon, 23 Mar 2009)
New Revision: 2144
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlParser.java
Log:
minor changes
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlParser.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlParser.java 2009-03-23 11:45:41 UTC (rev 2143)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlParser.java 2009-03-23 12:34:19 UTC (rev 2144)
@@ -72,18 +72,8 @@
element.getName().equalsIgnoreCase(XmlConstants.DEPLOY))
environment.getEnabledDeploymentTypes().addAll(obtainDeploymentTypes(element));
}
- }
-
- @SuppressWarnings("unchecked")
- public boolean checkNamespaces(Document document)
- {
- //TODO: not finished
- Element root = document.getRootElement();
- List<Namespace> declaredNamespaces = root.declaredNamespaces();
-
- return true;
- }
-
+ }
+
private Document createDocument(URL url)
{
try
@@ -97,7 +87,6 @@
}
SAXReader reader = new SAXReader();
Document document = reader.read(xmlStream);
- checkNamespaces(document);
fullFillPackagesMap(document);
return document;
}
15 years, 10 months
[webbeans-commits] Webbeans SVN: r2143 - in ri/trunk: jboss-as and 2 other directories.
by webbeans-commits@lists.jboss.org
Author: vitold
Date: 2009-03-23 07:45:41 -0400 (Mon, 23 Mar 2009)
New Revision: 2143
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/ParseXmlHelper.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlParser.java
ri/trunk/jboss-as/build.properties
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/xml/parser/XmlParserImplTest.java
ri/trunk/tests/src/test/resources/org/jboss/webbeans/test/unit/xml/parser/user-defined-beans.xml
Log:
some changes with parsing namespaces
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/ParseXmlHelper.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/ParseXmlHelper.java 2009-03-23 11:40:01 UTC (rev 2142)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/ParseXmlHelper.java 2009-03-23 11:45:41 UTC (rev 2143)
@@ -7,6 +7,7 @@
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.Scanner;
import java.util.Set;
@@ -15,11 +16,14 @@
import javax.jms.Queue;
import javax.jms.Topic;
+import org.dom4j.Attribute;
import org.dom4j.Element;
+import org.dom4j.Namespace;
import org.jboss.webbeans.CurrentManager;
import org.jboss.webbeans.ManagerImpl;
import org.jboss.webbeans.introspector.AnnotatedItem;
import org.jboss.webbeans.introspector.jlr.AnnotatedClassImpl;
+import org.jboss.webbeans.resources.spi.ResourceLoadingException;
public class ParseXmlHelper
{
@@ -196,8 +200,9 @@
private static boolean isSimpleBean(Element element)
{
+ //TODO
String urn = element.getNamespace().getURI();
- Class<?> beanClass = loadClassByURN(urn, element.getName());
+ Class<?> beanClass = null;//loadElementClass(urn, element.getName());
if (!Modifier.isAbstract(beanClass.getModifiers()) &&
beanClass.getTypeParameters().length == 0)
@@ -208,8 +213,9 @@
private static AnnotatedItem<?, ?> receiveSimpleBeanItem(Element element)
{
+ //TODO
String urn = element.getNamespace().getURI();
- Class<?> beanClass = loadClassByURN(urn, element.getName());
+ Class<?> beanClass = null;//loadElementClass(urn, element.getName());
if (!Modifier.isStatic(beanClass.getModifiers()) &&
beanClass.isMemberClass())
@@ -258,73 +264,140 @@
return element.getNamespace().getURI().equalsIgnoreCase(XmlConstants.JAVA_EE_NAMESPACE);
}
- // TODO you can't reparse all files every time you want to load a class. Switch to an OO design and cache
- // TODO Don't do your own classloading, use xml env
- // TODO Don't load Class, use AnnotatedClass
- public static Class<?> loadClassByURN(String urn, String className)
+ public static <T> Class<? extends T> loadElementClass(Element element, Class<T> expectedType, XmlEnvironment environment, Map<String, Set<String>> packagesMap)
{
- List<Class<?>> classes = new ArrayList<Class<?>>();
- List<String> packages = new ArrayList<String>();
- URL namespaceFile = loadNamespaceFile(urn);
+ List<Class<? extends T>> classesList = new ArrayList<Class<? extends T>>();
+ String className = element.getName();
+ String prefix = element.getNamespacePrefix();
- if(namespaceFile == null)
- packages.add(urn.replaceFirst(XmlConstants.URN_PREFIX, ""));
-
- else
- packages.addAll(parseNamespaceFile(namespaceFile));
-
- for(String possiblePackage : packages)
+ for(Map.Entry<String, Set<String>> packagesEntry : packagesMap.entrySet())
{
- String classPath = possiblePackage + "." + className;
- try
+ if(prefix.equalsIgnoreCase(packagesEntry.getKey()))
{
- classes.add(Class.forName(classPath));
+ Set<String> packages = packagesEntry.getValue();
+ for(String packageName : packages)
+ {
+ String classPath = packageName + "." + element.getName();
+ try
+ {
+ Class<? extends T> classType = environment.loadClass(classPath, expectedType).getRawType();
+ classesList.add(classType);
+ }
+ catch(ResourceLoadingException e){}
+ }
}
- catch (ClassNotFoundException e)
- {}
}
- if(classes.size() == 0)
- throw new DefinitionException("Could not find '" + className + "'according to specified URN '" + urn + "'");
+ if(classesList.size() == 0)
+ throw new DefinitionException("Could not find '" + className + "'");
- if(classes.size() == 1)
- return classes.get(0);
+ if(classesList.size() == 1)
+ return classesList.get(0);
throw new DefinitionException("There are multiple packages containing a Java type with the same name '" + className + "'");
}
- public static URL loadNamespaceFile(String urn)
+ public static void checkRootAttributes(Element root, Map<String, Set<String>> packagesMap)
{
+ Iterator<?> rootAttrIterator = root.attributeIterator();
+ while(rootAttrIterator.hasNext())
+ {
+ Set<String> packagesSet = new HashSet<String>();
+ Attribute attribute = (Attribute)rootAttrIterator.next();
+ String attrPrefix = attribute.getNamespacePrefix();
+ String attrData = attribute.getStringValue();
+
+ for(String attrVal : attrData.split(" "))
+ {
+ if(attrVal.startsWith(XmlConstants.URN_PREFIX))
+ {
+ URL namespaceFile = loadNamespaceFile(attrVal);
+ if(namespaceFile == null)
+ throw new DefinitionException("Could not find 'namespace' file according to specified URN '" + attrVal + "'");
+ packagesSet.addAll(parseNamespaceFile(namespaceFile));
+ }
+ }
+
+ addElementToPackagesMap(packagesMap, attrPrefix, packagesSet);
+ }
+ }
+
+ public static void checkRootDeclaredNamespaces(Element root, Map<String, Set<String>> packagesMap)
+ {
+ Iterator<?> namespacesIterator = root.declaredNamespaces().iterator();
+ while(namespacesIterator.hasNext())
+ {
+ Namespace namespace = (Namespace)namespacesIterator.next();
+ String prefix = namespace.getPrefix();
+ String uri = namespace.getURI();
+ if(uri.startsWith(XmlConstants.URN_PREFIX))
+ {
+ Set<String> packagesSet = new HashSet<String>();
+
+ URL namespaceFile = loadNamespaceFile(uri);
+ if(namespaceFile != null)
+ {
+ packagesSet.addAll(parseNamespaceFile(namespaceFile));
+ }
+ else
+ {
+ String packageName = uri.replaceFirst(XmlConstants.URN_PREFIX, "");
+ packagesSet.add(packageName);
+ }
+
+ addElementToPackagesMap(packagesMap, prefix, packagesSet);
+ }
+ }
+ }
+
+ private static URL loadNamespaceFile(String urn)
+ {
char separator = '/';
String packageName = urn.replaceFirst(XmlConstants.URN_PREFIX, "");
String path = packageName.replace('.', separator);
String filePath = separator + path + separator + XmlConstants.NAMESPACE_FILE_NAME;
- return ParseXmlHelper.class.getResource(filePath);
+ URL namespaceFile = ParseXmlHelper.class.getResource(filePath);
+ return namespaceFile;
}
- public static List<String> parseNamespaceFile(URL namespaceFile)
+ private static Set<String> parseNamespaceFile(URL namespaceFile)
{
- List<String> packages = new ArrayList<String>();
- Scanner fileScanner;
- try
+ Set<String> packages = new HashSet<String>();
+ Scanner fileScanner;
+ try
+ {
+ fileScanner = new Scanner(namespaceFile.openStream());
+ while (fileScanner.hasNextLine() )
{
- fileScanner = new Scanner(namespaceFile.openStream());
- while (fileScanner.hasNextLine() )
+ String line = fileScanner.nextLine();
+ Scanner lineScanner = new Scanner(line);
+ lineScanner.useDelimiter(XmlConstants.NAMESPACE_FILE_DELIMETER);
+ while(lineScanner.hasNext())
{
- String line = fileScanner.nextLine();
- Scanner lineScanner = new Scanner(line);
- lineScanner.useDelimiter(XmlConstants.NAMESPACE_FILE_DELIMETER);
- while(lineScanner.hasNext())
- {
- packages.add(lineScanner.next());
- }
+ packages.add(lineScanner.next());
}
- return packages;
+ lineScanner.close();
}
- catch (IOException e)
- {
- throw new RuntimeException("Error opening " + namespaceFile.toString());
- }
-
+ fileScanner.close();
+ return packages;
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException("Error opening " + namespaceFile.toString());
+ }
}
+
+ private static void addElementToPackagesMap(Map<String, Set<String>> packagesMap, String prefix, Set<String> packagesSet)
+ {
+ if(packagesMap.containsKey(prefix))
+ {
+ Set<String> packages = packagesMap.get(prefix);
+ packages.addAll(packagesSet);
+ packagesMap.put(prefix, packages);
+ }
+ else
+ {
+ packagesMap.put(prefix, packagesSet);
+ }
+ }
}
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlParser.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlParser.java 2009-03-23 11:40:01 UTC (rev 2142)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlParser.java 2009-03-23 11:45:41 UTC (rev 2143)
@@ -5,19 +5,21 @@
import java.lang.annotation.Annotation;
import java.net.URL;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import javax.inject.DefinitionException;
import javax.inject.DeploymentException;
-import javax.inject.DeploymentType;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.Namespace;
+import org.dom4j.QName;
import org.dom4j.io.SAXReader;
import org.jboss.webbeans.log.Log;
import org.jboss.webbeans.log.Logging;
@@ -30,6 +32,8 @@
private boolean haveAnyDeployElement = false;
+ private Map<String, Set<String>> packagesMap = new HashMap<String, Set<String>>();
+
public XmlParser(XmlEnvironment environment)
{
this.environment = environment;
@@ -94,6 +98,7 @@
SAXReader reader = new SAXReader();
Document document = reader.read(xmlStream);
checkNamespaces(document);
+ fullFillPackagesMap(document);
return document;
}
catch (IOException e)
@@ -166,31 +171,34 @@
if(deployElements.size() - deployElementsSet.size() != 0)
throw new DefinitionException("The same deployment type is declared more than once");
-// String standardName = XmlConstants.STANDARD;
-// String standardPrefix = "";
-// String standardUri = XmlConstants.JAVA_EE_NAMESPACE;
-// Namespace standardNamespace = new Namespace(standardPrefix, standardUri);
-// QName qName = new QName(standardName, standardNamespace);
-// Element standardElement = element.element(qName);
-// if (standardElement == null)
-// throw new DeploymentException("The @Standard deployment type must be declared");
+ String standardName = XmlConstants.STANDARD;
+ String standardPrefix = "";
+ String standardUri = XmlConstants.JAVA_EE_NAMESPACE;
+ Namespace standardNamespace = new Namespace(standardPrefix, standardUri);
+ QName qName = new QName(standardName, standardNamespace);
+ Element standardElement = element.element(qName);
+ if (standardElement == null)
+ throw new DeploymentException("The @Standard deployment type must be declared");
List<Class<? extends Annotation>> deploymentClasses = new ArrayList<Class<? extends Annotation>>();
List<Element> children = element.elements();
for (Element child : children)
- {
- String urn = child.getNamespace().getURI();
- Class<?> deploymentClass = ParseXmlHelper.loadClassByURN(urn, child.getName());
+ {
+ Class<? extends Annotation> deploymentClass = ParseXmlHelper.loadElementClass(child, Annotation.class, environment, packagesMap);
- if(!deploymentClass.isAnnotation())
- throw new DeploymentException("<Deploy> child " + element.getName() + " must be a Java annotation type");
-
- if(deploymentClass.getAnnotation(DeploymentType.class) == null)
- throw new DefinitionException("<Deploy> child " + element.getName() + " must be a deployment type");
+// if(deploymentClass.getAnnotation(DeploymentType.class) == null)
+// throw new DefinitionException("<Deploy> child <" + element.getName() + "> must be a deployment type");
- deploymentClasses.add(deploymentClass.asSubclass(Annotation.class));
+ deploymentClasses.add(deploymentClass);
}
haveAnyDeployElement = true;
return deploymentClasses;
}
+
+ private void fullFillPackagesMap(Document document)
+ {
+ Element root = document.getRootElement();
+ ParseXmlHelper.checkRootAttributes(root, packagesMap);
+ ParseXmlHelper.checkRootDeclaredNamespaces(root, packagesMap);
+ }
}
Modified: ri/trunk/jboss-as/build.properties
===================================================================
--- ri/trunk/jboss-as/build.properties 2009-03-23 11:40:01 UTC (rev 2142)
+++ ri/trunk/jboss-as/build.properties 2009-03-23 11:45:41 UTC (rev 2143)
@@ -1,5 +1,5 @@
# Container a number of properties associated with installing Web Beans into JBoss AS and running the TCK in JBoss AS
-#jboss.home=/Applications/jboss-5.0.1.GA
+jboss.home=C:\JBoss\jboss-5.0.0\
# recommended minimum JAVA_OPTS for running JBoss with the TCK
java.opts=-Xms128m -Xmx384m -XX:MaxPermSize=128m -Dorg.jboss.resolver.warning=true -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000
Modified: ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/xml/parser/XmlParserImplTest.java
===================================================================
--- ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/xml/parser/XmlParserImplTest.java 2009-03-23 11:40:01 UTC (rev 2142)
+++ ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/xml/parser/XmlParserImplTest.java 2009-03-23 11:45:41 UTC (rev 2143)
@@ -1,10 +1,22 @@
package org.jboss.webbeans.test.unit.xml.parser;
+import java.io.IOException;
+import java.io.InputStream;
import java.net.URL;
+import java.util.ArrayList;
import java.util.HashSet;
+import java.util.Iterator;
import java.util.List;
import java.util.Set;
+import javax.inject.DeploymentException;
+
+import org.dom4j.Attribute;
+import org.dom4j.Document;
+import org.dom4j.DocumentException;
+import org.dom4j.Element;
+import org.dom4j.Namespace;
+import org.dom4j.io.SAXReader;
import org.jboss.testharness.impl.packaging.Artifact;
import org.jboss.testharness.impl.packaging.Classes;
import org.jboss.testharness.impl.packaging.Resource;
@@ -17,8 +29,10 @@
import org.jboss.webbeans.test.unit.xml.beans.TestBean;
import org.jboss.webbeans.test.unit.xml.beans.TestDeploymentType;
import org.jboss.webbeans.xml.ParseXmlHelper;
+import org.jboss.webbeans.xml.XmlConstants;
import org.jboss.webbeans.xml.XmlEnvironment;
import org.jboss.webbeans.xml.XmlParser;
+import org.testng.annotations.Test;
@Artifact
@Resources({
@@ -49,36 +63,15 @@
assert parserEnv.getClasses().size() == 1;
}
-
- //@Test
- public void testParceNamespaceFile()
- {
- String urn = "urn:java:org.jboss.webbeans.test.unit.xml.parser";
-
- URL url = ParseXmlHelper.loadNamespaceFile(urn);
- List<String> packages = ParseXmlHelper.parseNamespaceFile(url);
- assert packages.size() == 2;
- }
-
- //@Test
- public void testLoadClassByURN()
- {
- String urn = "urn:java:org.jboss.webbeans.test.unit.xml.parser";
- String beanName = "TestBean";
- String deploymentTypeName = "TestDeploymentType";
-
- Class<?> beanClass = ParseXmlHelper.loadClassByURN(urn, beanName);
- Class<?> deploymentTypeClass = ParseXmlHelper.loadClassByURN(urn, deploymentTypeName);
-
- assert beanClass.equals(TestBean.class);
- assert deploymentTypeClass.equals(TestDeploymentType.class);
- }
}
/*
- <Beans xmlns="urn:java:ee" xmlns:myapp="urn:java:org.jboss.webbeans.test.unit.xml.parser"
- xmlns:test="urn:java:org.jboss.webbeans.test.unit.xml">
- <Deploy>
+<Beans xmlns="urn:java:ee" xmlns:myapp="urn:java:org.jboss.webbeans.test.unit.xml.beans"
+ xmlns:test="urn:java:org.jboss.webbeans.test.unit.xml.parser"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:java:ee http://java.sun.com/jee/ee/schema-1.0.xsd
+ urn:java:com.mydomain.myapp http://mydomain.com/myapp/schema-1.2.xsd">
+ <Deploy>
<Standard />
<Production />
<test:AnotherDeploymentType />
@@ -94,5 +87,5 @@
<ConversationScoped />
<BindingType />
</myapp:Login>
- </Beans>
+</Beans>
*/
Modified: ri/trunk/tests/src/test/resources/org/jboss/webbeans/test/unit/xml/parser/user-defined-beans.xml
===================================================================
--- ri/trunk/tests/src/test/resources/org/jboss/webbeans/test/unit/xml/parser/user-defined-beans.xml 2009-03-23 11:40:01 UTC (rev 2142)
+++ ri/trunk/tests/src/test/resources/org/jboss/webbeans/test/unit/xml/parser/user-defined-beans.xml 2009-03-23 11:45:41 UTC (rev 2143)
@@ -1,17 +1,20 @@
<Beans xmlns="urn:java:ee" xmlns:myapp="urn:java:org.jboss.webbeans.test.unit.xml.beans"
- xmlns:test="urn:java:org.jboss.webbeans.test.unit.xml.parser">
+ xmlns:test="urn:java:org.jboss.webbeans.test.unit.xml.parser"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:java:ee http://java.sun.com/jee/ee/schema-1.0.xsd
+ urn:java:org.jboss.webbeans.test.unit.xml.parser http://mydomain.com/myapp/schema-1.2.xsd">
<Deploy>
<Standard />
<Production />
- <test:AnotherDeploymentType />
+ <myapp:AnotherDeploymentType />
</Deploy>
- <myapp:Order>
+ <xsi:Order>
<ConversationScoped />
<myapp:PaymentProcessor>
- <myapp:Asynchronous />
+ <test:Asynchronous />
</myapp:PaymentProcessor>
<myapp:User />
- </myapp:Order>
+ </xsi:Order>
<myapp:Login>
<ConversationScoped />
<BindingType />
15 years, 10 months
[webbeans-commits] Webbeans SVN: r2142 - in ri/trunk: tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering and 1 other directory.
by webbeans-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2009-03-23 07:40:01 -0400 (Mon, 23 Mar 2009)
New Revision: 2142
Added:
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/AnotherDeploymentType.java
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/Expensive.java
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/JewelryShop.java
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/Necklace.java
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/Product.java
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/Shop.java
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/Sparkly.java
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BootstrapOrderingBeanComparator.java
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/DeployerOrderingTest.java
Log:
ordering for specializing producer methods
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BootstrapOrderingBeanComparator.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BootstrapOrderingBeanComparator.java 2009-03-23 11:20:10 UTC (rev 2141)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BootstrapOrderingBeanComparator.java 2009-03-23 11:40:01 UTC (rev 2142)
@@ -15,24 +15,10 @@
{
if (o1 instanceof AbstractClassBean && o2 instanceof AbstractProducerBean)
{
-// AbstractProducerBean<?, ?> b2 = (AbstractProducerBean<?, ?>) o2;
-// System.out.println(" declaring bean " + b2.getDeclaringBean().getType());
-// if (b2.getDeclaringBean().equals(o1))
-// {
-// System.out.println(" class " + o1.getType() + " < producer " + o2.getType());
-// return -1;
-// }
return -1;
}
else if (o1 instanceof AbstractProducerBean && o2 instanceof AbstractClassBean)
{
-// AbstractProducerBean<?, ?> b1 = (AbstractProducerBean<?, ?>) o1;
-// System.out.println(" declaring bean " + b1.getDeclaringBean().getType());
-// if (b1.getDeclaringBean().equals(o2))
-// {
-// System.out.println(" class " + o2.getType() + " < producer " + o1.getType());
-// return 1;
-// }
return 1;
}
@@ -52,6 +38,20 @@
}
}
+ if (o1 instanceof AbstractProducerBean && o2 instanceof AbstractProducerBean)
+ {
+ AbstractProducerBean<?, ?> b1 = (AbstractProducerBean<?, ?>) o1;
+ AbstractProducerBean<?, ?> b2 = (AbstractProducerBean<?, ?>) o2;
+ if (b1.getDeclaringBean().getSuperclasses().contains(b2.getDeclaringBean().getType().getName()))
+ {
+ return 1;
+ }
+ else if (b2.getDeclaringBean().getSuperclasses().contains(b1.getDeclaringBean().getType().getName()))
+ {
+ return -1;
+ }
+ }
+
if (o1 instanceof AbstractStandardBean && !(o2 instanceof AbstractStandardBean))
{
return -1;
Added: ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/AnotherDeploymentType.java
===================================================================
--- ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/AnotherDeploymentType.java (rev 0)
+++ ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/AnotherDeploymentType.java 2009-03-23 11:40:01 UTC (rev 2142)
@@ -0,0 +1,20 @@
+package org.jboss.webbeans.test.unit.bootstrap.ordering;
+
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.inject.DeploymentType;
+
+@Target( { TYPE, METHOD })
+@Retention(RUNTIME)
+@Documented
+@DeploymentType
+@interface AnotherDeploymentType
+{
+
+}
Property changes on: ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/AnotherDeploymentType.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/DeployerOrderingTest.java
===================================================================
--- ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/DeployerOrderingTest.java 2009-03-23 11:20:10 UTC (rev 2141)
+++ ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/DeployerOrderingTest.java 2009-03-23 11:40:01 UTC (rev 2142)
@@ -3,6 +3,8 @@
import java.util.ArrayList;
import java.util.Arrays;
+import javax.inject.AnnotationLiteral;
+
import org.jboss.webbeans.CurrentManager;
import org.jboss.webbeans.ManagerImpl;
import org.jboss.webbeans.bean.EnterpriseBean;
@@ -189,5 +191,43 @@
assert indexOfDefangedTarantula > indexOfTarantula;
assert indexOfTarantula > indexOfSpider;
}
+
+ @Test(groups="bootstrap")
+ public void testClassHierarchiesForMethods()
+ {
+ BeanDeployer beanDeployer = new BeanDeployer(manager);
+ beanDeployer.addClasses(Arrays.asList(Shop.class, JewelryShop.class, Tuna.class));
+ beanDeployer.createBeans();
+ assert beanDeployer.getBeans().size() == 8;
+ int indexOfShop = 0;
+ int indexOfJewelryShop = 0;
+ int indexOfExpensiveGift = 0;
+ int indexOfNecklace = 0;
+ int i = 0;
+ for (RIBean<?> bean : beanDeployer.getBeans())
+ {
+ if (bean.getType().equals(Shop.class) && !bean.getBindings().contains(new NewLiteral()))
+ {
+ indexOfShop = i;
+ }
+ if (bean.getType().equals(JewelryShop.class) && !bean.getBindings().contains(new NewLiteral()))
+ {
+ indexOfJewelryShop = i;
+ }
+ if (bean.getType().equals(Product.class) && bean.getBindings().contains(new AnnotationLiteral<Sparkly>() {}))
+ {
+ indexOfNecklace = i;
+ }
+ if (bean.getType().equals(Product.class) && !bean.getBindings().contains(new AnnotationLiteral<Sparkly>() {}))
+ {
+ indexOfExpensiveGift = i;
+ }
+ i++;
+ }
+ assert indexOfJewelryShop > indexOfShop;
+ assert indexOfExpensiveGift > indexOfShop;
+ assert indexOfNecklace > indexOfJewelryShop;
+ assert indexOfNecklace > indexOfExpensiveGift;
+ }
}
Added: ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/Expensive.java
===================================================================
--- ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/Expensive.java (rev 0)
+++ ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/Expensive.java 2009-03-23 11:40:01 UTC (rev 2142)
@@ -0,0 +1,22 @@
+package org.jboss.webbeans.test.unit.bootstrap.ordering;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.inject.BindingType;
+
+@Target( { TYPE, METHOD, PARAMETER, FIELD })
+@Retention(RUNTIME)
+@Documented
+@BindingType
+@interface Expensive
+{
+
+}
Property changes on: ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/Expensive.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/JewelryShop.java
===================================================================
--- ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/JewelryShop.java (rev 0)
+++ ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/JewelryShop.java 2009-03-23 11:40:01 UTC (rev 2142)
@@ -0,0 +1,15 @@
+package org.jboss.webbeans.test.unit.bootstrap.ordering;
+
+import javax.inject.Produces;
+import javax.inject.Specializes;
+
+class JewelryShop extends Shop
+{
+
+ @Override @Produces @Specializes @Sparkly @AnotherDeploymentType
+ public Product getExpensiveGift()
+ {
+ return new Necklace();
+ }
+
+}
Property changes on: ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/JewelryShop.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/Necklace.java
===================================================================
--- ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/Necklace.java (rev 0)
+++ ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/Necklace.java 2009-03-23 11:40:01 UTC (rev 2142)
@@ -0,0 +1,6 @@
+package org.jboss.webbeans.test.unit.bootstrap.ordering;
+
+class Necklace extends Product
+{
+
+}
Property changes on: ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/Necklace.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/Product.java
===================================================================
--- ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/Product.java (rev 0)
+++ ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/Product.java 2009-03-23 11:40:01 UTC (rev 2142)
@@ -0,0 +1,6 @@
+package org.jboss.webbeans.test.unit.bootstrap.ordering;
+
+class Product
+{
+
+}
Property changes on: ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/Product.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/Shop.java
===================================================================
--- ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/Shop.java (rev 0)
+++ ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/Shop.java 2009-03-23 11:40:01 UTC (rev 2142)
@@ -0,0 +1,16 @@
+package org.jboss.webbeans.test.unit.bootstrap.ordering;
+
+import javax.annotation.Named;
+import javax.inject.Produces;
+
+
+class Shop
+{
+
+ @Produces @Expensive @Named
+ public Product getExpensiveGift()
+ {
+ return new Product();
+ }
+
+}
Property changes on: ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/Shop.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/Sparkly.java
===================================================================
--- ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/Sparkly.java (rev 0)
+++ ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/Sparkly.java 2009-03-23 11:40:01 UTC (rev 2142)
@@ -0,0 +1,22 @@
+package org.jboss.webbeans.test.unit.bootstrap.ordering;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.inject.BindingType;
+
+@Target( { TYPE, METHOD, PARAMETER, FIELD })
+@Retention(RUNTIME)
+@Documented
+@BindingType
+@interface Sparkly
+{
+
+}
Property changes on: ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/Sparkly.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
15 years, 10 months
[webbeans-commits] Webbeans SVN: r2141 - ri/trunk/tests.
by webbeans-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2009-03-23 07:20:10 -0400 (Mon, 23 Mar 2009)
New Revision: 2141
Modified:
ri/trunk/tests/
Log:
ignores
Property changes on: ri/trunk/tests
___________________________________________________________________
Name: svn:ignore
- .project
.classpath
.settings
target
temp-testng-customsuite.xml
+ .project
.classpath
.settings
target
temp-testng-customsuite.xml
test-output
15 years, 10 months
[webbeans-commits] Webbeans SVN: r2140 - in extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd: helpers and 1 other directories.
by webbeans-commits@lists.jboss.org
Author: nickarls
Date: 2009-03-23 04:24:05 -0400 (Mon, 23 Mar 2009)
New Revision: 2140
Modified:
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/PackageSchemaGenerator.java
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/Schema.java
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/helpers/DataSetter.java
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/ConstructorModel.java
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/FieldModel.java
Log:
minor
Modified: extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/PackageSchemaGenerator.java
===================================================================
--- extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/PackageSchemaGenerator.java 2009-03-23 07:56:32 UTC (rev 2139)
+++ extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/PackageSchemaGenerator.java 2009-03-23 08:24:05 UTC (rev 2140)
@@ -36,6 +36,8 @@
import javax.lang.model.util.ElementFilter;
import org.dom4j.DocumentException;
+import org.jboss.webbeans.log.LogProvider;
+import org.jboss.webbeans.log.Logging;
import org.jboss.webbeans.xsd.helpers.DataSetter;
import org.jboss.webbeans.xsd.model.ClassModel;
@@ -50,6 +52,8 @@
@SupportedAnnotationTypes("*")
public class PackageSchemaGenerator extends AbstractProcessor
{
+ private static LogProvider log = Logging.getLogProvider(PackageSchemaGenerator.class);
+
private Map<String, ClassModel> classModelCache;
private Map<String, Schema> schemas;
@@ -75,8 +79,7 @@
}
catch (DocumentException e)
{
- // TODO: real logging
- System.out.println("Could not read or create schema for " + classModel.getPackage());
+ log.error("Could not read or create schema for package " + classModel.getPackage());
}
}
}
@@ -90,8 +93,7 @@
}
catch (IOException e)
{
- // TODO: real logging
- System.out.println("Could not write schema.xsd for " + schema);
+ log.error("Could not write schema.xsd for " + schema, e);
}
}
}
Modified: extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/Schema.java
===================================================================
--- extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/Schema.java 2009-03-23 07:56:32 UTC (rev 2139)
+++ extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/Schema.java 2009-03-23 08:24:05 UTC (rev 2140)
@@ -52,6 +52,7 @@
*/
public class Schema
{
+ // The default namespace of the schema
public static final List<Namespace> defaultNamespaces = new ArrayList<Namespace>();
static
@@ -95,6 +96,11 @@
init();
}
+ /**
+ * Creates a new schema document
+ *
+ * @return The document
+ */
private Document createDocument()
{
Document document = DocumentHelper.createDocument();
@@ -112,17 +118,45 @@
return document;
}
+ /**
+ * Static factory method
+ *
+ * @param packageName The package name
+ * @param packageElement The package content representation
+ * @param filer The filer for resources
+ *
+ * @return A new schema instance
+ *
+ * @throws DocumentException If an existing schema could not be parsed
+ */
public static Schema of(String packageName, PackageElement packageElement, Filer filer) throws DocumentException
{
return new Schema(packageName, packageElement, filer);
}
+ /**
+ * Reads a schema document
+ *
+ * @param filer The filer to be used for resource reading
+ *
+ * @return The schema documetn
+ *
+ * @throws IOException If the file could not be find or there was an error reading it
+ * @throws DocumentException If the read document could not be parsed
+ */
private Document readDocument(Filer filer) throws IOException, DocumentException
{
InputStream in = filer.getResource(StandardLocation.CLASS_OUTPUT, packageName, "schema.xsd").openInputStream();
return new SAXReader().read(in);
}
+ /**
+ * Writes a schema back to disk
+ *
+ * @param filer The filer to be used for resource writing
+ *
+ * @throws IOException If the file could not be written
+ */
public void write(Filer filer) throws IOException
{
OutputFormat format = OutputFormat.createPrettyPrint();
@@ -164,6 +198,7 @@
}
}
+ // Collect namespaces that are references in the document
Set<Namespace> referencedNamespaces = new HashSet<Namespace>(defaultNamespaces);
for (Object attribute : document.getRootElement().selectNodes("//@type"))
{
@@ -173,6 +208,8 @@
referencedNamespaces.add(document.getRootElement().getNamespaceForPrefix(prefix));
}
+ // Register the namespaces with the namespace handler if they are present, otherwise
+ // remove them from the document
for (Object item : document.getRootElement().additionalNamespaces())
{
Namespace namespace = (Namespace) item;
@@ -211,6 +248,7 @@
* Rebuilds the schema document
*
* @param packageElement The package abstraction
+ * @return the schema for fluent interface
*/
public Schema rebuild()
{
@@ -223,9 +261,9 @@
}
}
+ // Remove old version of class xsd (if present) and add the fresh version
for (ClassModel classModel : classModels)
{
- // Remove old version of class xsd (if present)
for (Object previousClass : document.selectNodes("/xs:schema/xs:element[@name=\"" + classModel.getSimpleName() + "\"]"))
{
((Element) previousClass).detach();
Modified: extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/helpers/DataSetter.java
===================================================================
--- extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/helpers/DataSetter.java 2009-03-23 07:56:32 UTC (rev 2139)
+++ extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/helpers/DataSetter.java 2009-03-23 08:24:05 UTC (rev 2140)
@@ -58,8 +58,7 @@
{
return;
}
- FieldModel field = FieldModel.of(element.getSimpleName().toString());
- classModel.addField(field);
+ classModel.addField(FieldModel.of(element.getSimpleName().toString()));
}
/**
@@ -74,18 +73,22 @@
{
return;
}
- ConstructorModel constructor = ConstructorModel.of((ExecutableElement) element);
- classModel.addConstructor(constructor);
+ classModel.addConstructor(ConstructorModel.of((ExecutableElement) element));
}
+ /**
+ * Inspects a method and populates a class model
+ *
+ * @param classModel The class model to populate
+ * @param element The element to inspect
+ */
public static void populateMethodModel(ClassModel classModel, Element element)
{
if (!isPublic(element))
{
return;
}
- MethodModel method = MethodModel.of((ExecutableElement) element);
- classModel.addMethod(method);
+ classModel.addMethod(MethodModel.of((ExecutableElement) element));
}
}
Modified: extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/ConstructorModel.java
===================================================================
--- extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/ConstructorModel.java 2009-03-23 07:56:32 UTC (rev 2139)
+++ extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/ConstructorModel.java 2009-03-23 08:24:05 UTC (rev 2140)
@@ -1,3 +1,20 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, 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.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package org.jboss.webbeans.xsd.model;
import javax.lang.model.element.ExecutableElement;
@@ -6,6 +23,12 @@
import org.dom4j.Element;
import org.jboss.webbeans.xsd.NamespaceHandler;
+/**
+ * The model of a method
+ *
+ * @author Nicklas Karlsson
+ *
+ */
public class ConstructorModel extends MethodModel
{
Modified: extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/FieldModel.java
===================================================================
--- extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/FieldModel.java 2009-03-23 07:56:32 UTC (rev 2139)
+++ extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/FieldModel.java 2009-03-23 08:24:05 UTC (rev 2140)
@@ -1,3 +1,20 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, 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.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package org.jboss.webbeans.xsd.model;
import org.dom4j.Element;
@@ -3,4 +20,10 @@
import org.jboss.webbeans.xsd.NamespaceHandler;
+/**
+ * The model of a field
+ *
+ * @author Nicklas Karlsson
+ *
+ */
public class FieldModel extends NamedModel
{
15 years, 10 months
[webbeans-commits] Webbeans SVN: r2139 - in extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd: helpers and 1 other directory.
by webbeans-commits@lists.jboss.org
Author: nickarls
Date: 2009-03-23 03:56:32 -0400 (Mon, 23 Mar 2009)
New Revision: 2139
Removed:
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/helpers/XSDHelper.java
Modified:
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/PackageSchemaGenerator.java
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/Schema.java
Log:
refactor, ditch XSDHelper
Modified: extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/PackageSchemaGenerator.java
===================================================================
--- extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/PackageSchemaGenerator.java 2009-03-23 07:09:01 UTC (rev 2138)
+++ extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/PackageSchemaGenerator.java 2009-03-23 07:56:32 UTC (rev 2139)
@@ -17,8 +17,9 @@
package org.jboss.webbeans.xsd;
-import java.util.ArrayList;
-import java.util.List;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
import java.util.Set;
import javax.annotation.processing.AbstractProcessor;
@@ -34,8 +35,8 @@
import javax.lang.model.type.TypeKind;
import javax.lang.model.util.ElementFilter;
+import org.dom4j.DocumentException;
import org.jboss.webbeans.xsd.helpers.DataSetter;
-import org.jboss.webbeans.xsd.helpers.XSDHelper;
import org.jboss.webbeans.xsd.model.ClassModel;
/**
@@ -49,41 +50,66 @@
@SupportedAnnotationTypes("*")
public class PackageSchemaGenerator extends AbstractProcessor
{
- // A helper for the XSD operations
- XSDHelper helper;
+ private Map<String, ClassModel> classModelCache;
+ private Map<String, Schema> schemas;
@Override
public synchronized void init(ProcessingEnvironment processingEnvironment)
{
super.init(processingEnvironment);
- helper = new XSDHelper(processingEnvironment);
+ classModelCache = new HashMap<String, ClassModel>();
+ schemas = new HashMap<String, Schema>();
}
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnvironment)
{
- List<ClassModel> workingSet = new ArrayList<ClassModel>();
-
- // Iterates over the classes compiled, creates a model of the classes and
- // add them to a working set
for (Element element : roundEnvironment.getRootElements())
{
if (ElementKind.CLASS.equals(element.getKind()) || ElementKind.ANNOTATION_TYPE.equals(element.getKind()))
{
ClassModel classModel = inspectClass(element);
- workingSet.add(classModel);
+ try
+ {
+ addClassToSchema(classModel);
+ }
+ catch (DocumentException e)
+ {
+ // TODO: real logging
+ System.out.println("Could not read or create schema for " + classModel.getPackage());
+ }
}
}
if (!roundEnvironment.processingOver())
{
- // Update the package XSDs for the files changed
- helper.updateSchemas(workingSet);
- // And flush the changes to disk
- helper.writeSchemas();
+ for (Schema schema : schemas.values())
+ {
+ try
+ {
+ schema.rebuild().write(processingEnv.getFiler());
+ }
+ catch (IOException e)
+ {
+ // TODO: real logging
+ System.out.println("Could not write schema.xsd for " + schema);
+ }
+ }
}
return false;
}
+ private void addClassToSchema(ClassModel classModel) throws DocumentException
+ {
+ String packageName = classModel.getPackage();
+ Schema schema = schemas.get(packageName);
+ if (schema == null)
+ {
+ schema = Schema.of(packageName, classModel.getPackageElement(), processingEnv.getFiler());
+ schemas.put(packageName, schema);
+ }
+ schema.addClass(classModel);
+ }
+
/**
* Creates a class model from a class element
*
@@ -103,7 +129,7 @@
// Gets the parent from the cache. We know it's there since we has scanned
// the hierarchy already
- classModel.setParent(helper.getCachedClassModel(typeElement.getSuperclass().toString()));
+ classModel.setParent(classModelCache.get(typeElement.getSuperclass().toString()));
// Filter out the fields and populate the model
for (Element field : ElementFilter.fieldsIn(element.getEnclosedElements()))
{
@@ -120,7 +146,7 @@
DataSetter.populateConstructorModel(classModel, constructor);
}
// Place the new class model in the cache
- helper.cacheClassModel(classModel);
+ classModelCache.put(classModel.getName(), classModel);
return classModel;
}
Modified: extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/Schema.java
===================================================================
--- extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/Schema.java 2009-03-23 07:09:01 UTC (rev 2138)
+++ extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/Schema.java 2009-03-23 07:56:32 UTC (rev 2139)
@@ -17,18 +17,30 @@
package org.jboss.webbeans.xsd;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
+import javax.annotation.processing.Filer;
import javax.lang.model.element.PackageElement;
import javax.lang.model.element.TypeElement;
+import javax.tools.StandardLocation;
import org.dom4j.Attribute;
import org.dom4j.Document;
+import org.dom4j.DocumentException;
+import org.dom4j.DocumentFactory;
+import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.Namespace;
+import org.dom4j.QName;
+import org.dom4j.io.OutputFormat;
+import org.dom4j.io.SAXReader;
+import org.dom4j.io.XMLWriter;
import org.jboss.webbeans.xsd.model.ClassModel;
import org.jboss.webbeans.xsd.model.TypedModel;
@@ -62,25 +74,65 @@
* Creates a new package
*
* @param packageName The name of the package
+ * @throws DocumentException
*/
- public Schema(String packageName, PackageElement packageElement)
+ public Schema(String packageName, PackageElement packageElement, Filer filer) throws DocumentException
{
- classModels = new HashSet<ClassModel>();
this.packageName = packageName;
this.packageElement = packageElement;
+ classModels = new HashSet<ClassModel>();
namespaceHandler = new NamespaceHandler(packageName);
+ try
+ {
+ document = readDocument(filer);
+ } catch (IOException e) {
+ // schema not found, safe to proceed
+ }
+ if (document == null)
+ {
+ document = createDocument();
+ }
+ init();
}
- /**
- * Gets the name of the package
- *
- * @return The package name
- */
- public String getPackageName()
+ private Document createDocument()
{
- return packageName;
+ Document document = DocumentHelper.createDocument();
+ QName rootQName = DocumentFactory.getInstance().createQName("schema", "xs", "http://www.w3.org/2001/XMLSchema");
+ Element rootElement = DocumentFactory.getInstance().createElement(rootQName);
+ rootElement.addAttribute("elementFormDefault", "qualified");
+ rootElement.addAttribute("targetNamespace", "urn:java:" + packageName);
+ rootElement.addAttribute("elementFormDefault", "qualified");
+ rootElement.addAttribute("xsi:schemaLocation", "http://www.w3.org/2001/XMLSchema http://www.w3.org/2001/XMLSchema.xsd");
+ document.setRootElement(rootElement);
+ for (Namespace namespace : defaultNamespaces)
+ {
+ rootElement.add(namespace);
+ }
+ return document;
}
+ public static Schema of(String packageName, PackageElement packageElement, Filer filer) throws DocumentException
+ {
+ return new Schema(packageName, packageElement, filer);
+ }
+
+ private Document readDocument(Filer filer) throws IOException, DocumentException
+ {
+ InputStream in = filer.getResource(StandardLocation.CLASS_OUTPUT, packageName, "schema.xsd").openInputStream();
+ return new SAXReader().read(in);
+ }
+
+ public void write(Filer filer) throws IOException
+ {
+ OutputFormat format = OutputFormat.createPrettyPrint();
+ OutputStream out = filer.createResource(StandardLocation.CLASS_OUTPUT, packageName, "schema.xsd").openOutputStream();
+ XMLWriter writer = new XMLWriter(out, format);
+ writer.write(document);
+ writer.flush();
+ writer.close();
+ }
+
/**
* Adds a class model to the working set and adds the referenced types to the
* namespace handler
@@ -97,27 +149,6 @@
}
/**
- * Gets the XSD document
- *
- * @return The XSD document
- */
- public Document getDocument()
- {
- return document;
- }
-
- /**
- * Sets the XSD document
- *
- * @param document The XSD document
- */
- public void setDocument(Document document)
- {
- this.document = document;
- init();
- }
-
- /**
* Cleans out namespaces and XSD for files that are no longer present in the
* package
*/
Deleted: extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/helpers/XSDHelper.java
===================================================================
--- extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/helpers/XSDHelper.java 2009-03-23 07:09:01 UTC (rev 2138)
+++ extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/helpers/XSDHelper.java 2009-03-23 07:56:32 UTC (rev 2139)
@@ -1,221 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, 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.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.jboss.webbeans.xsd.helpers;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.annotation.processing.ProcessingEnvironment;
-import javax.lang.model.element.PackageElement;
-import javax.tools.StandardLocation;
-
-import org.dom4j.Document;
-import org.dom4j.DocumentException;
-import org.dom4j.DocumentFactory;
-import org.dom4j.DocumentHelper;
-import org.dom4j.Element;
-import org.dom4j.Namespace;
-import org.dom4j.QName;
-import org.dom4j.io.OutputFormat;
-import org.dom4j.io.SAXReader;
-import org.dom4j.io.XMLWriter;
-import org.jboss.webbeans.xsd.Schema;
-import org.jboss.webbeans.xsd.model.ClassModel;
-
-/**
- * Helper for XSD related operations
- *
- * @author Nicklas Karlsson
- *
- */
-public class XSDHelper
-{
- // The annotation processing environment
- private ProcessingEnvironment processingEnvironment;
- // The cache of already processed classes
- private Map<String, ClassModel> classModelCache = new HashMap<String, ClassModel>();
- // The XSD documents of the affected packages
- private Map<String, Schema> schemaMap = new HashMap<String, Schema>();
-
- /**
- * Creates a new helper
- *
- * @param filer The filer of the processing environment
- */
- public XSDHelper(ProcessingEnvironment processingEnvironment)
- {
- this.processingEnvironment = processingEnvironment;
- }
-
- /**
- * Reads package info
- *
- * @param packageName The package name
- * @return The package info of the package
- * @throws DocumentException If the schema could not be parsed
- * @throws IOException If the schema could not be read
- */
- private Schema createSchema(String packageName, PackageElement packageElement) throws DocumentException, IOException
- {
- Schema schema = new Schema(packageName, packageElement);
- Document document = readSchema(packageName);
- if (document == null)
- {
- document = DocumentHelper.createDocument();
- QName rootQName = DocumentFactory.getInstance().createQName("schema", "xs", "http://www.w3.org/2001/XMLSchema");
- Element rootElement = DocumentFactory.getInstance().createElement(rootQName);
- rootElement.addAttribute("elementFormDefault", "qualified");
- rootElement.addAttribute("targetNamespace", "urn:java:" + packageName);
- rootElement.addAttribute("elementFormDefault", "qualified");
- for (Namespace namespace : Schema.defaultNamespaces)
- {
- rootElement.add(namespace);
- }
- document.setRootElement(rootElement);
- }
- schema.setDocument(document);
- return schema;
- }
-
- /**
- * Reads a schema for a package
- *
- * @param packageName The package name
- * @return The schema document
- * @throws DocumentException If the document could not be parsed
- * @throws IOException If the document could not be read
- */
- private Document readSchema(String packageName) throws DocumentException, IOException
- {
- InputStream in = null;
- try
- {
- in = processingEnvironment.getFiler().getResource(StandardLocation.CLASS_OUTPUT, packageName, "schema.xsd").openInputStream();
- return new SAXReader().read(in);
- }
- catch (IOException e)
- {
- return null;
- }
- finally
- {
- if (in != null)
- {
- in.close();
- }
- }
- }
-
- private void writeSchema(Schema schema) throws IOException
- {
- OutputStream out = null;
- try
- {
- OutputFormat format = OutputFormat.createPrettyPrint();
- out = processingEnvironment.getFiler().createResource(StandardLocation.CLASS_OUTPUT, schema.getPackageName(), "schema.xsd").openOutputStream();
- XMLWriter writer = new XMLWriter(out, format);
- writer.write(schema.getDocument());
- writer.flush();
- writer.close();
- }
- finally
- {
- if (out != null)
- {
- out.close();
- }
- }
- }
-
- /**
- * Updates the schemas for the affected packages
- *
- * @param classModels The list of class models in the batch
- */
- public void updateSchemas(List<ClassModel> classModels)
- {
- for (ClassModel classModel : classModels)
- {
- String packageName = classModel.getPackage();
- Schema schema = schemaMap.get(packageName);
- if (schema == null)
- {
- try
- {
- schema = createSchema(packageName, classModel.getPackageElement());
- }
- catch (DocumentException e)
- {
- throw new RuntimeException("Could not parse schema for package " + packageName, e);
- }
- catch (IOException e)
- {
- throw new RuntimeException("Could not read schema for package " + packageName, e);
- }
- schemaMap.put(packageName, schema);
- }
- schema.addClass(classModel);
- }
- }
-
- /**
- * Writes the schemas back to disk
- *
- * @param packageModels
- */
- public void writeSchemas()
- {
- for (Schema schema : schemaMap.values())
- {
- schema.rebuild();
- try
- {
- writeSchema(schema);
- }
- catch (IOException e)
- {
- throw new RuntimeException("Could not write schema for " + schema.getPackageName(), e);
- }
- }
- }
-
- /**
- * Gets a cached class model
- *
- * @param FQN The FQN of the class
- * @return The class model (or null if not cached)
- */
- public ClassModel getCachedClassModel(String FQN)
- {
- return classModelCache.get(FQN);
- }
-
- /**
- * Puts a class model in the cache
- *
- * @param classModel The class model
- */
- public void cacheClassModel(ClassModel classModel)
- {
- classModelCache.put(classModel.getName(), classModel);
- }
-}
15 years, 10 months
[webbeans-commits] Webbeans SVN: r2138 - in extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd: helpers and 1 other directories.
by webbeans-commits@lists.jboss.org
Author: nickarls
Date: 2009-03-23 03:09:01 -0400 (Mon, 23 Mar 2009)
New Revision: 2138
Added:
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/FieldModel.java
Modified:
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/NamespaceHandler.java
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/Schema.java
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/helpers/DataSetter.java
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/helpers/XSDHelper.java
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/ClassModel.java
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/MethodModel.java
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/TypedModel.java
Log:
Some refactorings
Modified: extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/NamespaceHandler.java
===================================================================
--- extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/NamespaceHandler.java 2009-03-23 05:25:18 UTC (rev 2137)
+++ extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/NamespaceHandler.java 2009-03-23 07:09:01 UTC (rev 2138)
@@ -18,11 +18,14 @@
package org.jboss.webbeans.xsd;
import java.util.Arrays;
+import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
+import org.dom4j.Namespace;
+
/**
* Helper for generating and keeping track of namespaces in a schema
*
@@ -31,91 +34,28 @@
*/
public class NamespaceHandler
{
- // The set of reserved EE packages
private static final Set<String> URN_JAVA_EE = new HashSet<String>(Arrays.asList("java.lang", "java.util", "javax.annotation", "javax.inject", "javax.context", "javax.interceptor", "javax.decorator", "javax.event", "javax.ejb", "javax.persistence", "javax.xml.ws", "javax.jms", "javax.sql"));
- // The local package of the scema
private String localPackage;
+ private Map<String, Namespace> namespaces = new HashMap<String, Namespace>();
- // Duplicate shortname counters
- private Map<String, Integer> counters = new HashMap<String, Integer>();
- // Namespace infos
- private Map<String, SchemaNamespace> schemaNamespaces = new HashMap<String, SchemaNamespace>();
-
- public Map<String, SchemaNamespace> getSchemaNamespaces()
+ public Collection<Namespace> getNamespaces()
{
- return schemaNamespaces;
+ return namespaces.values();
}
- /**
- * Creats a new namespace generator
- *
- * @param localPackage The local package
- */
public NamespaceHandler(String localPackage)
{
this.localPackage = localPackage;
- addPackage(localPackage);
+ addNamespace(new Namespace("", localPackage));
}
- /**
- * Data for a package namespace
- *
- * @author Nicklas Karlsson
- *
- */
- public class SchemaNamespace
+ public String getPrefix(String packageName)
{
- // The package name
- String packageName;
- // The full namespace
- String shortNamespace;
- // The urn
- String urn;
- // Is this a EE reserved package?
- boolean ee;
-
- public SchemaNamespace(String packageName, String shortNamespace, boolean ee)
- {
- this.packageName = packageName;
- this.shortNamespace = shortNamespace;
- this.ee = ee;
- this.urn = "urn:java:" + (ee ? "ee" : packageName);
- }
-
- @Override
- public String toString()
- {
- return shortNamespace + "=" + urn;
- }
- }
-
- /**
- * Gets all used namespaces for the schema
- *
- * @return The used namespaces
- */
- // public Set<String> getUsedNamespaces()
- // {
- // Set<String> usedNamespaces = new HashSet<String>();
- // for (SchemaNamespace schemaNamespace : schemaNamespaces.values())
- // {
- // usedNamespaces.add(schemaNamespace.getFullNamespace());
- // }
- // return usedNamespaces;
- // }
- /**
- * Gets a namespace abbreviation for a package
- *
- * @param packageName The name of the package
- * @return The namespace abbreviation
- */
- public String getShortNamespace(String packageName)
- {
String shortName = getPackageName(packageName);
- if (schemaNamespaces.containsKey(shortName))
+ if (namespaces.containsKey(shortName))
{
- return schemaNamespaces.get(shortName).shortNamespace;
+ return namespaces.get(shortName).getPrefix();
}
else
{
@@ -123,59 +63,91 @@
}
}
- /**
- * Gets the short name (last part) of a package
- *
- * @param packageName The package name to parse
- * @return The short name
- */
- private String getShortName(String packageName)
+ private String getPackageLastPart(String packageName)
{
int lastDot = packageName.lastIndexOf(".");
return lastDot < 0 ? packageName : packageName.substring(lastDot + 1);
}
- private String getPackageName(String FQN)
+ private String getPackageName(String FQCN)
{
- int lastDot = FQN.lastIndexOf(".");
- return lastDot < 0 ? "nopak" : FQN.substring(0, lastDot);
+ int lastDot = FQCN.lastIndexOf(".");
+ return lastDot < 0 ? "nopak" : FQCN.substring(0, lastDot);
}
public void addPackage(String packageName)
{
- if (schemaNamespaces.containsKey(packageName))
+ if (namespaces.containsKey(packageName))
{
return;
}
- String shortNamespace = "";
- boolean ee = false;
+ String prefix = null;
+ String URI = "java:urn:" + packageName;
if (localPackage.equals(packageName))
{
- // Nothing to do but want to hit this case first for performance
+ prefix = "";
}
else if (URN_JAVA_EE.contains(packageName))
{
- shortNamespace = "ee";
- ee = true;
+ prefix = "ee";
+ URI = "java:urn:ee";
}
else
{
- String shortName = getShortName(packageName);
- Integer count = counters.get(shortName);
- String countString = "";
- if (count == null)
+ prefix = getAvailablePrefix(packageName);
+ }
+ namespaces.put(packageName, new Namespace(prefix, URI));
+ }
+
+ private String getAvailablePrefix(String packageName)
+ {
+ int suffix = 1;
+ boolean found = false;
+ while (true)
+ {
+ String prefix = getPackageLastPart(packageName) + (suffix == 1 ? "" : String.valueOf(suffix));
+ for (Namespace namespace : namespaces.values())
{
- count = new Integer(1);
- counters.put(shortName, count);
+ if (namespace.getPrefix().equals(prefix))
+ {
+ found = true;
+ break;
+ }
}
+ if (!found)
+ {
+ return prefix;
+ }
else
{
- count++;
- countString = String.valueOf(count);
+ suffix++;
+ found = false;
}
- shortNamespace = getShortName(packageName) + countString;
}
- schemaNamespaces.put(packageName, new SchemaNamespace(packageName, shortNamespace, ee));
}
+ public void addNamespace(Namespace namespace)
+ {
+ namespaces.put(getNamespacePackage(namespace), namespace);
+ }
+
+ private String getNamespacePackage(Namespace namespace)
+ {
+ int urnJava = namespace.getURI().indexOf("urn:java:");
+ if (urnJava >= 0)
+ {
+ return namespace.getURI().substring(urnJava);
+ }
+ else
+ {
+ return namespace.getURI();
+ }
+ }
+
+ @Override
+ public String toString()
+ {
+ return namespaces.toString();
+ }
+
}
Modified: extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/Schema.java
===================================================================
--- extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/Schema.java 2009-03-23 05:25:18 UTC (rev 2137)
+++ extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/Schema.java 2009-03-23 07:09:01 UTC (rev 2138)
@@ -29,7 +29,6 @@
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.Namespace;
-import org.jboss.webbeans.xsd.NamespaceHandler.SchemaNamespace;
import org.jboss.webbeans.xsd.model.ClassModel;
import org.jboss.webbeans.xsd.model.TypedModel;
@@ -41,6 +40,14 @@
*/
public class Schema
{
+ public static final List<Namespace> defaultNamespaces = new ArrayList<Namespace>();
+
+ static
+ {
+ defaultNamespaces.add(new Namespace("wb", "http://seamframework.org/WebBeans"));
+ defaultNamespaces.add(new Namespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"));
+ };
+
// The name of the package
private String packageName;
// The XSD document
@@ -50,7 +57,7 @@
// The set of classes to update
private Set<ClassModel> classModels;
private PackageElement packageElement;
-
+
/**
* Creates a new package
*
@@ -58,10 +65,10 @@
*/
public Schema(String packageName, PackageElement packageElement)
{
- this.packageName = packageName;
- namespaceHandler = new NamespaceHandler(packageName);
classModels = new HashSet<ClassModel>();
+ this.packageName = packageName;
this.packageElement = packageElement;
+ namespaceHandler = new NamespaceHandler(packageName);
}
/**
@@ -75,7 +82,8 @@
}
/**
- * Adds a class model to the working set and adds the referenced types to the namespace handler
+ * Adds a class model to the working set and adds the referenced types to the
+ * namespace handler
*
* @param classModel The class model
*/
@@ -106,34 +114,16 @@
public void setDocument(Document document)
{
this.document = document;
+ init();
}
/**
- * Checks if a class is still in the package
- *
- * @param packageElement The package abstraction
- * @param FQN The full name of the class
- * @return True if present, false otherwise
+ * Cleans out namespaces and XSD for files that are no longer present in the
+ * package
*/
- private boolean isClassInPackage(String FQN)
+ private void init()
{
- for (javax.lang.model.element.Element classElement : packageElement.getEnclosedElements())
- {
- TypeElement typeElement = (TypeElement) classElement;
- if (typeElement.getQualifiedName().toString().equals(FQN))
- {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Cleans out XSD for files that are no longer present in the package
- * @param packageElement
- */
- private void cleanRemovedClasses()
- {
+ // Removes elements that are no longer in the package
for (Object xsdClass : document.selectNodes("/xs:schema/xs:element"))
{
String FQN = packageName + "." + ((Element) xsdClass).attributeValue("name");
@@ -142,51 +132,48 @@
((Element) xsdClass).detach();
}
}
- }
- /**
- * Updates the namespaces of the XSD document
- */
- private void updateNamespaces()
- {
- // Collects the prefixes of the namspaces referenced in the classes
- List<String> referencedNamespaces = new ArrayList<String>();
- for (Object attribute : document.getRootElement().selectNodes("//@ref"))
+ Set<Namespace> referencedNamespaces = new HashSet<Namespace>(defaultNamespaces);
+ for (Object attribute : document.getRootElement().selectNodes("//@type"))
{
String ref = ((Attribute) attribute).getValue();
int colon = ref.indexOf(":");
- String namespace = colon < 0 ? "" : ref.substring(0, colon);
- referencedNamespaces.add(namespace);
+ String prefix = colon < 0 ? "" : ref.substring(0, colon);
+ referencedNamespaces.add(document.getRootElement().getNamespaceForPrefix(prefix));
}
-
- // Collects the prefixes of the namespaces in the schema document
- List<String> currentNamespaces = new ArrayList<String>();
+
for (Object item : document.getRootElement().additionalNamespaces())
{
Namespace namespace = (Namespace) item;
- String prefix = namespace.getPrefix();
- if (!("".equals(prefix) || "xsi".equals(prefix)))
+ if (referencedNamespaces.contains(namespace))
{
- currentNamespaces.add(namespace.getPrefix());
+ namespaceHandler.addNamespace(namespace);
}
+ else
+ {
+ document.getRootElement().remove(namespace);
+ }
}
-
- // Removes the namespaces that are no longer referenced
- currentNamespaces.removeAll(referencedNamespaces);
- for (String obsolete : currentNamespaces)
+ }
+
+ /**
+ * Checks if a class is still in the package
+ *
+ * @param packageElement The package abstraction
+ * @param FQN The full name of the class
+ * @return True if present, false otherwise
+ */
+ private boolean isClassInPackage(String FQN)
+ {
+ for (javax.lang.model.element.Element classElement : packageElement.getEnclosedElements())
{
- document.getRootElement().remove(document.getRootElement().getNamespaceForPrefix(obsolete));
- }
-
- // Adds new namespaces if they are not already present
- for (SchemaNamespace schemaNamespace : namespaceHandler.getSchemaNamespaces().values())
- {
- if (document.getRootElement().getNamespaceForPrefix(schemaNamespace.shortNamespace) == null)
+ TypeElement typeElement = (TypeElement) classElement;
+ if (typeElement.getQualifiedName().toString().equals(FQN))
{
- document.getRootElement().addNamespace(schemaNamespace.shortNamespace, schemaNamespace.urn);
+ return true;
}
}
-
+ return false;
}
/**
@@ -194,10 +181,16 @@
*
* @param packageElement The package abstraction
*/
- public void rebuild()
+ public Schema rebuild()
{
- cleanRemovedClasses();
- updateNamespaces();
+ // Adds new namespaces if they are not already present
+ for (Namespace namespace : namespaceHandler.getNamespaces())
+ {
+ if (document.getRootElement().getNamespaceForPrefix(namespace.getPrefix()) == null)
+ {
+ document.getRootElement().add(namespace);
+ }
+ }
for (ClassModel classModel : classModels)
{
@@ -208,6 +201,7 @@
}
document.getRootElement().add(classModel.toXSD(namespaceHandler));
}
+ return this;
}
@Override
@@ -216,9 +210,9 @@
StringBuilder buffer = new StringBuilder();
buffer.append("Package: " + packageName + "\n");
buffer.append("Used namespaces\n");
- for (SchemaNamespace schemaNamespace : namespaceHandler.getSchemaNamespaces().values())
+ for (Namespace namespace : namespaceHandler.getNamespaces())
{
- buffer.append(" " + schemaNamespace + "\n");
+ buffer.append(" " + namespace + "\n");
}
buffer.append("Contained classes:\n");
for (ClassModel classModel : classModels)
Modified: extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/helpers/DataSetter.java
===================================================================
--- extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/helpers/DataSetter.java 2009-03-23 05:25:18 UTC (rev 2137)
+++ extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/helpers/DataSetter.java 2009-03-23 07:09:01 UTC (rev 2138)
@@ -23,8 +23,8 @@
import org.jboss.webbeans.xsd.model.ClassModel;
import org.jboss.webbeans.xsd.model.ConstructorModel;
+import org.jboss.webbeans.xsd.model.FieldModel;
import org.jboss.webbeans.xsd.model.MethodModel;
-import org.jboss.webbeans.xsd.model.NamedModel;
/**
* Helper for examining classes and members and populating the model
@@ -58,7 +58,7 @@
{
return;
}
- NamedModel field = NamedModel.of(element.getSimpleName().toString());
+ FieldModel field = FieldModel.of(element.getSimpleName().toString());
classModel.addField(field);
}
Modified: extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/helpers/XSDHelper.java
===================================================================
--- extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/helpers/XSDHelper.java 2009-03-23 05:25:18 UTC (rev 2137)
+++ extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/helpers/XSDHelper.java 2009-03-23 07:09:01 UTC (rev 2138)
@@ -33,6 +33,7 @@
import org.dom4j.DocumentFactory;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
+import org.dom4j.Namespace;
import org.dom4j.QName;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.SAXReader;
@@ -85,8 +86,10 @@
rootElement.addAttribute("elementFormDefault", "qualified");
rootElement.addAttribute("targetNamespace", "urn:java:" + packageName);
rootElement.addAttribute("elementFormDefault", "qualified");
- rootElement.addNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
- rootElement.addAttribute("xsi:schemaLocation", "http://www.w3.org/2001/XMLSchema http://www.w3.org/2001/XMLSchema.xsd");
+ for (Namespace namespace : Schema.defaultNamespaces)
+ {
+ rootElement.add(namespace);
+ }
document.setRootElement(rootElement);
}
schema.setDocument(document);
@@ -184,7 +187,6 @@
for (Schema schema : schemaMap.values())
{
schema.rebuild();
- System.out.println(schema.getDocument().asXML());
try
{
writeSchema(schema);
Modified: extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/ClassModel.java
===================================================================
--- extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/ClassModel.java 2009-03-23 05:25:18 UTC (rev 2137)
+++ extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/ClassModel.java 2009-03-23 07:09:01 UTC (rev 2138)
@@ -43,7 +43,7 @@
// The parent (or null if top-level)
private ClassModel parent;
// The fields of the class
- private List<NamedModel> fields = new ArrayList<NamedModel>();
+ private List<FieldModel> fields = new ArrayList<FieldModel>();
// The methods of the class
private List<MethodModel> methods = new ArrayList<MethodModel>();
// The constructors of the class
@@ -68,7 +68,7 @@
*
* @param field The field to add
*/
- public void addField(NamedModel field)
+ public void addField(FieldModel field)
{
fields.add(field);
}
@@ -129,7 +129,7 @@
*
* @return The public fields
*/
- public List<NamedModel> getFields()
+ public List<FieldModel> getFields()
{
return fields;
}
@@ -252,10 +252,7 @@
{
Element classElement = DocumentFactory.getInstance().createElement("xs:element");
classElement.addAttribute("name", getSimpleName());
- Element complexElement = DocumentFactory.getInstance().createElement("xs:complexType");
- Element anyElement = DocumentFactory.getInstance().createElement("xs:any");
- complexElement.add(anyElement);
- classElement.add(complexElement);
+ classElement.addAttribute("type", "wb:bean");
Element choice = DocumentFactory.getInstance().createElement("xs:choice");
for (ConstructorModel constructor : getMergedConstructors())
@@ -265,16 +262,16 @@
choice.add(constructor.toXSD(namespaceHandler));
}
}
- anyElement.add(choice);
+ classElement.add(choice);
for (MethodModel method : getMergedMethods())
{
- anyElement.add(method.toXSD(namespaceHandler));
+ classElement.add(method.toXSD(namespaceHandler));
}
for (NamedModel field : getMergedFields())
{
- anyElement.add(field.toXSD(namespaceHandler));
+ classElement.add(field.toXSD(namespaceHandler));
}
return classElement;
Added: extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/FieldModel.java
===================================================================
--- extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/FieldModel.java (rev 0)
+++ extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/FieldModel.java 2009-03-23 07:09:01 UTC (rev 2138)
@@ -0,0 +1,27 @@
+package org.jboss.webbeans.xsd.model;
+
+import org.dom4j.Element;
+import org.jboss.webbeans.xsd.NamespaceHandler;
+
+public class FieldModel extends NamedModel
+{
+
+ protected FieldModel(String name)
+ {
+ super(name);
+ }
+
+ public static FieldModel of(String name)
+ {
+ return new FieldModel(name);
+ }
+
+ @Override
+ public Element toXSD(NamespaceHandler namespaceHandler)
+ {
+ Element field = super.toXSD(namespaceHandler);
+ field.addAttribute("type", "wb:field");
+ return field;
+ }
+
+}
Modified: extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/MethodModel.java
===================================================================
--- extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/MethodModel.java 2009-03-23 05:25:18 UTC (rev 2137)
+++ extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/MethodModel.java 2009-03-23 07:09:01 UTC (rev 2138)
@@ -96,6 +96,7 @@
public Element toXSD(NamespaceHandler namespaceHandler)
{
Element method = super.toXSD(namespaceHandler);
+ method.addAttribute("type", "wb:method");
for (TypedModel parameter : parameters)
{
method.add(parameter.toXSD(namespaceHandler));
Modified: extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/TypedModel.java
===================================================================
--- extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/TypedModel.java 2009-03-23 05:25:18 UTC (rev 2137)
+++ extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/TypedModel.java 2009-03-23 07:09:01 UTC (rev 2138)
@@ -100,10 +100,9 @@
} else {
}
- String typeOrRef = isPrimitive() ? ("xs:" + type) : (namespaceHandler.getShortNamespace(type) + ":" + getTypeSimpleName());
- String attrName = isPrimitive() ? "type" : "ref";
+ String typeValue = isPrimitive() ? ("xs:" + type) : (namespaceHandler.getPrefix(type) + ":" + getTypeSimpleName());
Element item = DocumentFactory.getInstance().createElement("xs:element");
- item.addAttribute(attrName, typeOrRef);
+ item.addAttribute("type", typeValue);
return item;
}
15 years, 10 months