[webbeans-commits] Webbeans SVN: r2006 - in ri/trunk: xsd and 1 other directory.
by webbeans-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2009-03-15 13:43:03 -0400 (Sun, 15 Mar 2009)
New Revision: 2006
Removed:
ri/trunk/impl/src/main/java/org/jboss/webbeans/xsd/PackageInfo.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/xsd/PackageSchemaGenerator.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/xsd/helpers/
ri/trunk/impl/src/main/java/org/jboss/webbeans/xsd/model/
ri/trunk/impl/src/main/java/org/jboss/webbeans/xsd/sample-schema.xsd
Modified:
ri/trunk/xsd/
ri/trunk/xsd/pom.xml
Log:
move xsd to it's own project
Deleted: ri/trunk/impl/src/main/java/org/jboss/webbeans/xsd/PackageInfo.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/xsd/PackageInfo.java 2009-03-15 17:38:52 UTC (rev 2005)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/xsd/PackageInfo.java 2009-03-15 17:43:03 UTC (rev 2006)
@@ -1,48 +0,0 @@
-package org.jboss.webbeans.xsd;
-
-import java.util.List;
-
-import org.dom4j.Document;
-
-public class PackageInfo
-{
- private List<String> namespaces;
- private Document schema;
- private String packageName;
-
- public PackageInfo(String packageName)
- {
- this.packageName = packageName;
- }
-
- public List<String> getNamespaces()
- {
- return namespaces;
- }
-
- public void setNamespaces(List<String> namespaces)
- {
- this.namespaces = namespaces;
- }
-
- public Document getSchema()
- {
- return schema;
- }
-
- public void setSchema(Document schema)
- {
- this.schema = schema;
- }
-
- public String getPackageName()
- {
- return packageName;
- }
-
- public void setPackageName(String packageName)
- {
- this.packageName = packageName;
- }
-
-}
Deleted: ri/trunk/impl/src/main/java/org/jboss/webbeans/xsd/PackageSchemaGenerator.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/xsd/PackageSchemaGenerator.java 2009-03-15 17:38:52 UTC (rev 2005)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/xsd/PackageSchemaGenerator.java 2009-03-15 17:43:03 UTC (rev 2006)
@@ -1,124 +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;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Set;
-
-import javax.annotation.processing.AbstractProcessor;
-import javax.annotation.processing.ProcessingEnvironment;
-import javax.annotation.processing.RoundEnvironment;
-import javax.annotation.processing.SupportedAnnotationTypes;
-import javax.annotation.processing.SupportedSourceVersion;
-import javax.lang.model.SourceVersion;
-import javax.lang.model.element.Element;
-import javax.lang.model.element.TypeElement;
-import javax.lang.model.type.DeclaredType;
-import javax.lang.model.type.TypeKind;
-import javax.lang.model.util.ElementFilter;
-
-import org.jboss.webbeans.xsd.helpers.DataSetter;
-import org.jboss.webbeans.xsd.helpers.XSDHelper;
-import org.jboss.webbeans.xsd.model.ClassModel;
-
-/**
- * An annotation processor that updates the package-level XSD for the packages
- * that have had their files compiled.
- *
- * @author Nicklas Karlsson
- *
- */
-(a)SupportedSourceVersion(SourceVersion.RELEASE_6)
-@SupportedAnnotationTypes("*")
-public class PackageSchemaGenerator extends AbstractProcessor
-{
- // A helper for the XSD operations
- XSDHelper helper;
-
- @Override
- public synchronized void init(ProcessingEnvironment processingEnv)
- {
- super.init(processingEnv);
- helper = new XSDHelper(processingEnv.getFiler());
- }
-
- @Override
- public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv)
- {
- 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 : roundEnv.getRootElements())
- {
- workingSet.add(inspectClass(element));
- }
- if (!roundEnv.processingOver())
- {
- // Update the package XSDs for the files changed
- helper.updateSchemas(workingSet);
- // And flush the changes to disk
- helper.writeSchemas();
- }
- return false;
- }
-
- /**
- * Creates a class model from a class element
- *
- * @param element The element to analyze
- * @return The class model
- */
- private ClassModel inspectClass(Element element)
- {
- TypeElement typeElement = (TypeElement) element;
- ClassModel classModel = new ClassModel();
-
- // If the class has superclass's, scan them recursively
- if (typeElement.getSuperclass().getKind() != TypeKind.NONE)
- {
- inspectClass(((DeclaredType) typeElement.getSuperclass()).asElement());
- }
-
- // Gets the parent from the cache. We know it's there since we has scanned
- // the
- // hierarchy already
- ClassModel parent = helper.getCachedClassModel(typeElement.getSuperclass().toString());
- // Populate the class level info (name, parent etc)
- DataSetter.populateClassModel(classModel, element, parent);
- // Filter out the fields and populate the model
- for (Element field : ElementFilter.fieldsIn(element.getEnclosedElements()))
- {
- DataSetter.populateFieldModel(classModel, field);
- }
- // Filter out the methods and populate the model
- for (Element method : ElementFilter.methodsIn(element.getEnclosedElements()))
- {
- DataSetter.populateMethodModel(classModel, method);
- }
- // Filter out the constructors and populate the model
- for (Element constructor : ElementFilter.constructorsIn(element.getEnclosedElements()))
- {
- DataSetter.populateMethodModel(classModel, constructor);
- }
- // Place the new class model in the cache
- helper.cacheClassModel(classModel);
- return classModel;
- }
-
-}
Deleted: ri/trunk/impl/src/main/java/org/jboss/webbeans/xsd/sample-schema.xsd
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/xsd/sample-schema.xsd 2009-03-15 17:38:52 UTC (rev 2005)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/xsd/sample-schema.xsd 2009-03-15 17:43:03 UTC (rev 2006)
@@ -1,28 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
- elementFormDefault="qualified"
- targetNamespace="urn:java:com.acme.foo"
- xmlns:foo="urn:java:com.acme.foo"
- xmlns:ee="urn:java:ee"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://www.w3.org/2001/XMLSchema http://www.w3.org/2001/XMLSchema.xsd"
- >
-
- <xs:element name="Foo">
- <xs:complexType>
- <xs:choice>
- <!-- Options to allow people to declare this class a binding type or stereotype - TODO only if an annotation -->
- <xs:element ref="ee:BindingType"/>
- <xs:element ref="ee:StereotypType"/>
- <!-- Somehow import all binding types known etc. to give people that option -->
- <xs:any /> <!-- Can't guess all types people want to put here -->
- </xs:choice>
- </xs:complexType>
- </xs:element>
-
- <xs:element name="Bar">
-
- </xs:element>
-
-
-</xs:schema>
\ No newline at end of file
Property changes on: ri/trunk/xsd
___________________________________________________________________
Name: svn:ignore
+ target
.settings
.project
.classpath
Modified: ri/trunk/xsd/pom.xml
===================================================================
--- ri/trunk/xsd/pom.xml 2009-03-15 17:38:52 UTC (rev 2005)
+++ ri/trunk/xsd/pom.xml 2009-03-15 17:43:03 UTC (rev 2006)
@@ -44,6 +44,14 @@
<build>
<defaultGoal>install</defaultGoal>
<plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
</plugins>
</build>
15 years, 10 months
[webbeans-commits] Webbeans SVN: r2005 - in ri/trunk/impl/src: main/java/org/jboss/webbeans/bootstrap and 9 other directories.
by webbeans-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2009-03-15 13:38:52 -0400 (Sun, 15 Mar 2009)
New Revision: 2005
Added:
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/field/
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/field/ParameterizedListInjection.java
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/field/ParameterizedProducer.java
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/field/ParameterizedProducerTest.java
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/field/method/
Removed:
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/method/
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/AbstractBean.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/AbstractFacadeBean.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/AbstractProducerBean.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/EnterpriseBean.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/EventBean.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/SimpleBean.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployer.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/event/ObserverImpl.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/injection/ConstructorInjectionPoint.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/injection/ResolvableAnnotatedClass.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/AnnotatedItem.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/ForwardingAnnotatedItem.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/jlr/AbstractAnnotatedItem.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/jlr/AbstractAnnotatedMember.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedClassImpl.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedMethodImpl.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedParameterImpl.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/metadata/AnnotationModel.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/metadata/BindingTypeModel.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/metadata/ScopeModel.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/metadata/StereotypeModel.java
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/annotatedItem/ClassAnnotatedItemTest.java
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/field/method/IntInjection.java
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/field/method/ManagerProducer.java
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/field/method/ManagerProducerTest.java
Log:
rename methods to reflect JDK
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/AbstractBean.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/AbstractBean.java 2009-03-15 17:25:15 UTC (rev 2004)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/AbstractBean.java 2009-03-15 17:38:52 UTC (rev 2005)
@@ -260,10 +260,10 @@
// TODO CACHE THIS and rebuild on addBean
// TODO: a bit crude, don't check *all* injectionpoints, only those listed
// in the spec for passivation checks
- for (AnnotatedItem<?, ?> injectionPoint : getInjectionPoints())
+ for (AnnotatedInjectionPoint<?, ?> injectionPoint : getInjectionPoints())
{
Annotation[] bindings = injectionPoint.getMetaAnnotationsAsArray(BindingType.class);
- Bean<?> resolvedBean = manager.resolveByType(injectionPoint.getType(), bindings).iterator().next();
+ Bean<?> resolvedBean = manager.resolveByType(injectionPoint.getRawType(), bindings).iterator().next();
if (MetaDataCache.instance().getScopeModel(this.getScopeType()).isPassivating())
{
if (Dependent.class.equals(resolvedBean.getScopeType()) && !resolvedBean.isSerializable() && (((injectionPoint instanceof AnnotatedField) && !((AnnotatedField<?>) injectionPoint).isTransient()) || (injectionPoint instanceof AnnotatedParameter)) )
@@ -314,7 +314,7 @@
{
throw new DefinitionException("type: " + getType() + " must specify a deployment type");
}
- else if (deploymentType.equals(Standard.class) && !STANDARD_WEB_BEAN_CLASSES.contains(getAnnotatedItem().getType()))
+ else if (deploymentType.equals(Standard.class) && !STANDARD_WEB_BEAN_CLASSES.contains(getAnnotatedItem().getRawType()))
{
throw new DefinitionException(getAnnotatedItem().getName() + " cannot have deployment type @Standard");
}
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java 2009-03-15 17:25:15 UTC (rev 2004)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java 2009-03-15 17:38:52 UTC (rev 2005)
@@ -121,7 +121,7 @@
protected void initType()
{
log.trace("Bean type specified in Java");
- this.type = getAnnotatedItem().getType();
+ this.type = getAnnotatedItem().getRawType();
}
/**
@@ -270,7 +270,7 @@
protected void preSpecialize()
{
super.preSpecialize();
- if (getAnnotatedItem().getSuperclass() == null || getAnnotatedItem().getSuperclass().getType().equals(Object.class))
+ if (getAnnotatedItem().getSuperclass() == null || getAnnotatedItem().getSuperclass().getRawType().equals(Object.class))
{
throw new DefinitionException("Specializing bean must extend another bean " + toString());
}
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/AbstractFacadeBean.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/AbstractFacadeBean.java 2009-03-15 17:25:15 UTC (rev 2004)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/AbstractFacadeBean.java 2009-03-15 17:38:52 UTC (rev 2005)
@@ -62,7 +62,7 @@
@SuppressWarnings("unchecked")
protected Class<P> getTypeParameter()
{
- return (Class<P>) annotatedItem.getType().getTypeParameters()[0].getClass();
+ return (Class<P>) annotatedItem.getActualTypeArguments()[0].getClass();
}
/**
@@ -121,7 +121,7 @@
{
if (getAnnotatedItem() != null)
{
- this.type = getAnnotatedItem().getType();
+ this.type = getAnnotatedItem().getRawType();
}
}
catch (ClassCastException e)
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/AbstractProducerBean.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/AbstractProducerBean.java 2009-03-15 17:25:15 UTC (rev 2004)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/AbstractProducerBean.java 2009-03-15 17:38:52 UTC (rev 2005)
@@ -120,11 +120,11 @@
{
try
{
- this.type = getAnnotatedItem().getType();
+ this.type = getAnnotatedItem().getRawType();
}
catch (ClassCastException e)
{
- throw new RuntimeException(" Cannot cast producer type " + getAnnotatedItem().getType() + " to bean type " + (getDeclaredBeanType() == null ? " unknown " : getDeclaredBeanType()), e);
+ throw new RuntimeException(" Cannot cast producer type " + getAnnotatedItem().getRawType() + " to bean type " + (getDeclaredBeanType() == null ? " unknown " : getDeclaredBeanType()), e);
}
}
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/EnterpriseBean.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/EnterpriseBean.java 2009-03-15 17:25:15 UTC (rev 2004)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/EnterpriseBean.java 2009-03-15 17:38:52 UTC (rev 2005)
@@ -189,7 +189,7 @@
protected void preSpecialize()
{
super.preSpecialize();
- if (!manager.getEjbDescriptorCache().containsKey(getAnnotatedItem().getSuperclass().getType()))
+ if (!manager.getEjbDescriptorCache().containsKey(getAnnotatedItem().getSuperclass().getRawType()))
{
throw new DefinitionException("Annotation defined specializing EJB must have EJB superclass");
}
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/EventBean.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/EventBean.java 2009-03-15 17:25:15 UTC (rev 2004)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/EventBean.java 2009-03-15 17:38:52 UTC (rev 2005)
@@ -88,7 +88,7 @@
*/
private void validateInjectionPoint()
{
- if (!this.getAnnotatedItem().getType().equals(Event.class))
+ if (!this.getAnnotatedItem().getRawType().equals(Event.class))
{
throw new DefinitionException("Event field/parameter is not of type Event<T>: " + this.getAnnotatedItem());
}
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/SimpleBean.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/SimpleBean.java 2009-03-15 17:25:15 UTC (rev 2004)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/SimpleBean.java 2009-03-15 17:38:52 UTC (rev 2005)
@@ -365,7 +365,7 @@
protected void preSpecialize()
{
super.preSpecialize();
- if (manager.getEjbDescriptorCache().containsKey(getAnnotatedItem().getSuperclass().getType()))
+ if (manager.getEjbDescriptorCache().containsKey(getAnnotatedItem().getSuperclass().getRawType()))
{
throw new DefinitionException("Simple bean must specialize a simple bean");
}
@@ -458,7 +458,7 @@
protected void initType()
{
log.trace("Bean type specified in Java");
- this.type = getAnnotatedItem().getType();
+ this.type = getAnnotatedItem().getRawType();
}
/**
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-15 17:25:15 UTC (rev 2004)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployer.java 2009-03-15 17:38:52 UTC (rev 2005)
@@ -84,7 +84,7 @@
{
for (AnnotatedClass<?> clazz : deferredClasses)
{
- if (manager.getEjbDescriptorCache().containsKey(clazz.getType()))
+ if (manager.getEjbDescriptorCache().containsKey(clazz.getRawType()))
{
createEnterpriseBean(clazz);
}
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/event/ObserverImpl.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/event/ObserverImpl.java 2009-03-15 17:25:15 UTC (rev 2004)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/event/ObserverImpl.java 2009-03-15 17:38:52 UTC (rev 2005)
@@ -40,7 +40,6 @@
import org.jboss.webbeans.injection.MethodInjectionPoint;
import org.jboss.webbeans.introspector.AnnotatedMethod;
import org.jboss.webbeans.introspector.AnnotatedParameter;
-import org.jboss.webbeans.util.Reflections;
/**
* <p>
@@ -79,7 +78,7 @@
checkObserverMethod();
@SuppressWarnings("unchecked")
- Class<T> c = (Class<T>) observerMethod.getAnnotatedParameters(Observes.class).get(0).getType();
+ Class<T> c = (Class<T>) observerMethod.getAnnotatedParameters(Observes.class).get(0).getRawType();
this.eventType = c;
this.bindings = observerMethod.getAnnotatedParameters(Observes.class).get(0).getBindingsAsArray();
@@ -114,7 +113,7 @@
if (eventObjects.size() > 0)
{
AnnotatedParameter<?> eventParam = eventObjects.iterator().next();
- if (Reflections.isParameterizedType(eventParam.getType()))
+ if (eventParam.isParameterizedType())
{
throw new DefinitionException(this + " cannot observe parameterized event types");
}
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/injection/ConstructorInjectionPoint.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/injection/ConstructorInjectionPoint.java 2009-03-15 17:25:15 UTC (rev 2004)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/injection/ConstructorInjectionPoint.java 2009-03-15 17:38:52 UTC (rev 2005)
@@ -21,6 +21,7 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Type;
import java.util.AbstractList;
import java.util.Iterator;
import java.util.List;
@@ -173,5 +174,10 @@
}
return parameterValues;
}
+
+ public Type getType()
+ {
+ return getRawType();
+ }
}
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/injection/ResolvableAnnotatedClass.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/injection/ResolvableAnnotatedClass.java 2009-03-15 17:25:15 UTC (rev 2004)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/injection/ResolvableAnnotatedClass.java 2009-03-15 17:38:52 UTC (rev 2005)
@@ -93,10 +93,16 @@
throw new UnsupportedOperationException();
}
- public Class<T> getType()
+ public Class<T> getRawType()
{
return rawType;
}
+
+ @Override
+ public Type getType()
+ {
+ return getRawType();
+ }
public boolean isFinal()
{
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/AnnotatedItem.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/AnnotatedItem.java 2009-03-15 17:25:15 UTC (rev 2004)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/AnnotatedItem.java 2009-03-15 17:38:52 UTC (rev 2005)
@@ -129,9 +129,9 @@
*
* @return The type of the element
*/
- public Class<T> getType();
+ public Class<T> getRawType();
- public Type getUnderlyingType();
+ public Type getType();
/**
* Extends Java Class assignability such that actual type parameters are also
@@ -199,5 +199,7 @@
public String getName();
public AnnotationStore getAnnotationStore();
+
+ public boolean isParameterizedType();
}
\ No newline at end of file
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/ForwardingAnnotatedItem.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/ForwardingAnnotatedItem.java 2009-03-15 17:25:15 UTC (rev 2004)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/ForwardingAnnotatedItem.java 2009-03-15 17:38:52 UTC (rev 2005)
@@ -114,14 +114,14 @@
/**
* @see org.jboss.webbeans.introspector.AnnotatedItem
*/
- public Class<T> getType()
+ public Class<T> getRawType()
{
- return delegate().getType();
+ return delegate().getRawType();
}
- public Type getUnderlyingType()
+ public Type getType()
{
- return delegate().getUnderlyingType();
+ return delegate().getType();
}
/**
@@ -223,5 +223,10 @@
{
return delegate().getFlattenedTypeHierarchy();
}
+
+ public boolean isParameterizedType()
+ {
+ return delegate().isParameterizedType();
+ }
}
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/jlr/AbstractAnnotatedItem.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/jlr/AbstractAnnotatedItem.java 2009-03-15 17:25:15 UTC (rev 2004)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/jlr/AbstractAnnotatedItem.java 2009-03-15 17:38:52 UTC (rev 2005)
@@ -53,17 +53,18 @@
}
- public Type getUnderlyingType()
+ public Type getType()
{
- return getType();
+ return getRawType();
}
// Cached string representation
private String toString;
private final AnnotationStore annotationStore;
- private final Class<T> type;
+ private final Class<T> rawType;
private final Set<? extends Type> flattenedTypes;
private final boolean proxyable;
+ private final boolean _parameterizedType;
/**
* Constructor
@@ -74,18 +75,20 @@
* @param annotationMap A map of annotation to register
*
*/
- public AbstractAnnotatedItem(AnnotationStore annotatedItemHelper, Class<T> type)
+ public AbstractAnnotatedItem(AnnotationStore annotatedItemHelper, Class<T> rawType)
{
this.annotationStore = annotatedItemHelper;
- this.type = type;
- this.flattenedTypes = new Reflections.HierarchyDiscovery<Type>(type).getFlattenedTypes();
+ this.rawType = rawType;
+ this._parameterizedType = Reflections.isParameterizedType(rawType);
+ this.flattenedTypes = new Reflections.HierarchyDiscovery<Type>(rawType).getFlattenedTypes();
this.proxyable = Proxies.isTypesProxyable(flattenedTypes);
}
public AbstractAnnotatedItem(AnnotationStore annotatedItemHelper)
{
this.annotationStore = annotatedItemHelper;
- this.type = null;
+ this.rawType = null;
+ this._parameterizedType = false;
this.flattenedTypes = null;
this.proxyable = false;
}
@@ -145,7 +148,7 @@
if (other instanceof AnnotatedItem)
{
AnnotatedItem<?, ?> that = (AnnotatedItem<?, ?>) other;
- return this.getAnnotationsAsSet().equals(that.getAnnotationsAsSet()) && this.getType().equals(that.getType());
+ return this.getAnnotationsAsSet().equals(that.getAnnotationsAsSet()) && this.getRawType().equals(that.getRawType());
}
return false;
}
@@ -161,7 +164,7 @@
*/
public boolean isAssignableFrom(AnnotatedItem<?, ?> that)
{
- return isAssignableFrom(that.getType(), that.getActualTypeArguments());
+ return isAssignableFrom(that.getRawType(), that.getActualTypeArguments());
}
/**
@@ -208,7 +211,7 @@
*/
private boolean isAssignableFrom(Class<?> type, Type[] actualTypeArguments)
{
- return Types.boxedType(getType()).isAssignableFrom(Types.boxedType(type)) && Arrays.equals(getActualTypeArguments(), actualTypeArguments);
+ return Types.boxedType(getRawType()).isAssignableFrom(Types.boxedType(type)) && Arrays.equals(getActualTypeArguments(), actualTypeArguments);
}
/**
@@ -219,7 +222,7 @@
@Override
public int hashCode()
{
- return getType().hashCode();
+ return getRawType().hashCode();
}
/**
@@ -272,9 +275,9 @@
return proxyable;
}
- public Class<T> getType()
+ public Class<T> getRawType()
{
- return type;
+ return rawType;
}
public Set<? extends Type> getFlattenedTypeHierarchy()
@@ -288,5 +291,10 @@
{
return getAnnotationStore().isDeclaredAnnotationPresent(annotationType);
}
+
+ public boolean isParameterizedType()
+ {
+ return _parameterizedType;
+ }
}
\ No newline at end of file
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/jlr/AbstractAnnotatedMember.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/jlr/AbstractAnnotatedMember.java 2009-03-15 17:25:15 UTC (rev 2004)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/jlr/AbstractAnnotatedMember.java 2009-03-15 17:38:52 UTC (rev 2005)
@@ -159,7 +159,7 @@
*/
public T getValue(Manager manager)
{
- return manager.getInstanceByType(getType(), getMetaAnnotationsAsArray(BindingType.class));
+ return manager.getInstanceByType(getRawType(), getMetaAnnotationsAsArray(BindingType.class));
}
/**
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedClassImpl.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedClassImpl.java 2009-03-15 17:25:15 UTC (rev 2004)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedClassImpl.java 2009-03-15 17:38:52 UTC (rev 2005)
@@ -255,7 +255,6 @@
private String toString;
private final boolean _nonStaticMemberClass;
- private final boolean _parameterizedType;
private final boolean _abstract;
@@ -284,7 +283,6 @@
this.declaredAnnotatedFields = new AnnotatedFieldMap();
this.declaredMetaAnnotatedFields = new AnnotatedFieldMap();
this._nonStaticMemberClass = Reflections.isNonMemberInnerClass(rawType);
- this._parameterizedType = Reflections.isParameterizedType(rawType);
this._abstract = Reflections.isAbstract(rawType);
for (Class<?> c = clazz; c != Object.class && c != null; c = c.getSuperclass())
{
@@ -481,11 +479,6 @@
return _nonStaticMemberClass;
}
- public boolean isParameterizedType()
- {
- return _parameterizedType;
- }
-
public boolean isAbstract()
{
return _abstract;
@@ -613,9 +606,4 @@
return toString;
}
- public AnnotatedClass<T> wrap(Set<Annotation> annotations)
- {
- throw new UnsupportedOperationException();
- }
-
}
\ No newline at end of file
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedMethodImpl.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedMethodImpl.java 2009-03-15 17:25:15 UTC (rev 2004)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedMethodImpl.java 2009-03-15 17:38:52 UTC (rev 2005)
@@ -113,7 +113,7 @@
if (method.getParameterAnnotations()[i].length > 0)
{
Class<? extends Object> clazz = method.getParameterTypes()[i];
- AnnotatedParameter<Object> parameter = new AnnotatedParameterImpl<Object>(method.getParameterAnnotations()[i], (Class<Object>) clazz, this);
+ AnnotatedParameter<?> parameter = AnnotatedParameterImpl.of(method.getParameterAnnotations()[i], (Class<Object>) clazz, this);
this.parameters.add(parameter);
for (Annotation annotation : parameter.getAnnotationsAsSet())
{
@@ -126,7 +126,7 @@
else
{
Class<? extends Object> clazz = method.getParameterTypes()[i];
- AnnotatedParameter<Object> parameter = new AnnotatedParameterImpl<Object>(new Annotation[0], (Class<Object>) clazz, this);
+ AnnotatedParameter<?> parameter = AnnotatedParameterImpl.of(new Annotation[0], (Class<Object>) clazz, this);
this.parameters.add(parameter);
}
}
@@ -153,7 +153,7 @@
}
@Override
- public Type getUnderlyingType()
+ public Type getType()
{
return underlyingType;
}
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedParameterImpl.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedParameterImpl.java 2009-03-15 17:25:15 UTC (rev 2004)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedParameterImpl.java 2009-03-15 17:38:52 UTC (rev 2005)
@@ -65,7 +65,7 @@
* @param annotations The annotations array
* @param type The type of the parameter
*/
- public AnnotatedParameterImpl(Annotation[] annotations, Class<T> type, AnnotatedMember<?, ?> declaringMember)
+ private AnnotatedParameterImpl(Annotation[] annotations, Class<T> type, AnnotatedMember<?, ?> declaringMember)
{
super(AnnotationStore.of(annotations, annotations), type);
this.type = type;
@@ -135,7 +135,7 @@
*/
public T getValue(Manager manager)
{
- return manager.getInstanceByType(getType(), getMetaAnnotationsAsArray(BindingType.class));
+ return manager.getInstanceByType(getRawType(), getMetaAnnotationsAsArray(BindingType.class));
}
/**
@@ -166,7 +166,7 @@
buffer.append("static ");
if (_final)
buffer.append("final ");
- buffer.append(getType().getName());
+ buffer.append(getRawType().getName());
buffer.append(" for operation ");
buffer.append(getDeclaringMember().toString());
toString = buffer.toString();
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/metadata/AnnotationModel.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/metadata/AnnotationModel.java 2009-03-15 17:25:15 UTC (rev 2004)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/metadata/AnnotationModel.java 2009-03-15 17:38:52 UTC (rev 2005)
@@ -61,9 +61,9 @@
*/
protected void initType()
{
- if (!Annotation.class.isAssignableFrom(getType()))
+ if (!Annotation.class.isAssignableFrom(getRawType()))
{
- throw new DefinitionException(getMetaAnnotation().toString() + " can only be applied to an annotation, it was applied to " + getType());
+ throw new DefinitionException(getMetaAnnotation().toString() + " can only be applied to an annotation, it was applied to " + getRawType());
}
}
@@ -80,9 +80,9 @@
*
* @return The type
*/
- public Class<T> getType()
+ public Class<T> getRawType()
{
- return annotatedAnnotation.getType();
+ return annotatedAnnotation.getRawType();
}
/**
@@ -120,7 +120,7 @@
@Override
public String toString()
{
- return (isValid() ? "Valid" : "Invalid") + " annotation model for " + getType();
+ return (isValid() ? "Valid" : "Invalid") + " annotation model for " + getRawType();
}
}
\ No newline at end of file
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/metadata/BindingTypeModel.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/metadata/BindingTypeModel.java 2009-03-15 17:25:15 UTC (rev 2004)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/metadata/BindingTypeModel.java 2009-03-15 17:38:52 UTC (rev 2005)
@@ -69,7 +69,7 @@
{
for (AnnotatedMethod<?> annotatedMethod : getAnnotatedAnnotation().getMembers())
{
- if ((Reflections.isArrayType(annotatedMethod.getType()) || Annotation.class.isAssignableFrom(annotatedMethod.getType())) && !nonBindingTypes.contains(annotatedMethod))
+ if ((Reflections.isArrayType(annotatedMethod.getRawType()) || Annotation.class.isAssignableFrom(annotatedMethod.getRawType())) && !nonBindingTypes.contains(annotatedMethod))
{
throw new DefinitionException("Member of array type or annotation type must be annotated @NonBinding " + annotatedMethod);
}
@@ -126,7 +126,7 @@
*/
public boolean isEqual(Annotation instance, Annotation other)
{
- if (instance.annotationType().equals(getType()) && other.annotationType().equals(getType()))
+ if (instance.annotationType().equals(getRawType()) && other.annotationType().equals(getRawType()))
{
for (AnnotatedMethod<?> annotatedMethod : getAnnotatedAnnotation().getMembers())
{
@@ -169,7 +169,7 @@
@Override
public String toString()
{
- return (isValid() ? "Valid" : "Invalid") + " binding type model for " + getType() + " with non-binding types " + getNonBindingTypes();
+ return (isValid() ? "Valid" : "Invalid") + " binding type model for " + getRawType() + " with non-binding types " + getNonBindingTypes();
}
}
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/metadata/ScopeModel.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/metadata/ScopeModel.java 2009-03-15 17:25:15 UTC (rev 2004)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/metadata/ScopeModel.java 2009-03-15 17:38:52 UTC (rev 2005)
@@ -82,7 +82,7 @@
String valid = isValid() ? "Valid " : "Invalid";
String normal = isNormal() ? "normal " : "non-normal ";
String passivating = isPassivating() ? "passivating " : "pon-passivating ";
- return valid + normal + passivating + " scope model for " + getType();
+ return valid + normal + passivating + " scope model for " + getRawType();
}
}
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/metadata/StereotypeModel.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/metadata/StereotypeModel.java 2009-03-15 17:25:15 UTC (rev 2004)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/metadata/StereotypeModel.java 2009-03-15 17:38:52 UTC (rev 2005)
@@ -230,7 +230,7 @@
@Deprecated
public Class<? extends Annotation> getStereotypeClass()
{
- return getType();
+ return getRawType();
}
/**
Modified: ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/annotatedItem/ClassAnnotatedItemTest.java
===================================================================
--- ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/annotatedItem/ClassAnnotatedItemTest.java 2009-03-15 17:25:15 UTC (rev 2004)
+++ ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/annotatedItem/ClassAnnotatedItemTest.java 2009-03-15 17:38:52 UTC (rev 2005)
@@ -24,7 +24,7 @@
AnnotatedClass<Order> annotatedElement = AnnotatedClassImpl.of(Order.class);
assert annotatedElement.getAnnotationsAsSet().size() == 1;
assert annotatedElement.getAnnotation(Production.class) != null;
- assert annotatedElement.getType().equals(Order.class);
+ assert annotatedElement.getRawType().equals(Order.class);
}
@Test
Added: ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/field/ParameterizedListInjection.java
===================================================================
--- ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/field/ParameterizedListInjection.java (rev 0)
+++ ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/field/ParameterizedListInjection.java 2009-03-15 17:38:52 UTC (rev 2005)
@@ -0,0 +1,42 @@
+package org.jboss.webbeans.test.unit.implementation.producer.field;
+
+import java.util.List;
+
+public class ParameterizedListInjection
+{
+
+ private List<String> value;
+
+ //@Current
+ private List<String> fieldInjection;
+
+ private List<String> setterInjection;
+
+ //@Initializer
+ public void init(List<String> setterInjection)
+ {
+ this.setterInjection = setterInjection;
+ }
+
+ /*@Initializer
+ public ParameterizedListInjection(List<String> com)
+ {
+ this.value = com;
+ }*/
+
+ public java.util.List<String> getValue()
+ {
+ return value;
+ }
+
+ public List<String> getFieldInjection()
+ {
+ return fieldInjection;
+ }
+
+ public List<String> getSetterInjection()
+ {
+ return setterInjection;
+ }
+
+}
Property changes on: ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/field/ParameterizedListInjection.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/field/ParameterizedProducer.java
===================================================================
--- ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/field/ParameterizedProducer.java (rev 0)
+++ ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/field/ParameterizedProducer.java 2009-03-15 17:38:52 UTC (rev 2005)
@@ -0,0 +1,17 @@
+package org.jboss.webbeans.test.unit.implementation.producer.field;
+
+import java.util.Arrays;
+import java.util.List;
+
+import javax.inject.Produces;
+
+public class ParameterizedProducer
+{
+
+ @Produces
+ public List<String> create()
+ {
+ return Arrays.asList("aaa", "bbb");
+ }
+
+}
Property changes on: ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/field/ParameterizedProducer.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/field/ParameterizedProducerTest.java
===================================================================
--- ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/field/ParameterizedProducerTest.java (rev 0)
+++ ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/field/ParameterizedProducerTest.java 2009-03-15 17:38:52 UTC (rev 2005)
@@ -0,0 +1,25 @@
+package org.jboss.webbeans.test.unit.implementation.producer.field;
+
+import java.util.List;
+
+import javax.inject.TypeLiteral;
+
+import org.jboss.testharness.impl.packaging.Artifact;
+import org.jboss.webbeans.test.unit.AbstractWebBeansTest;
+
+@Artifact
+public class ParameterizedProducerTest extends AbstractWebBeansTest
+{
+
+ //@Test
+ public void testInjectManagerProducer()
+ {
+ assert manager.getInstanceByType(new TypeLiteral<List<String>>(){}).size() == 2;
+
+ ParameterizedListInjection item = manager.getInstanceByType(ParameterizedListInjection.class);
+ assert item.getValue().size() == 2;
+ assert item.getFieldInjection().size() == 2;
+ assert item.getSetterInjection().size() == 2;
+
+ }
+}
Property changes on: ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/field/ParameterizedProducerTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Copied: ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/field/method (from rev 2003, ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/method)
Modified: ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/field/method/IntInjection.java
===================================================================
--- ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/method/IntInjection.java 2009-03-15 15:53:42 UTC (rev 2003)
+++ ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/field/method/IntInjection.java 2009-03-15 17:38:52 UTC (rev 2005)
@@ -1,4 +1,4 @@
-package org.jboss.webbeans.test.unit.implementation.producer.method;
+package org.jboss.webbeans.test.unit.implementation.producer.field.method;
import javax.inject.Initializer;
Modified: ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/field/method/ManagerProducer.java
===================================================================
--- ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/method/ManagerProducer.java 2009-03-15 15:53:42 UTC (rev 2003)
+++ ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/field/method/ManagerProducer.java 2009-03-15 17:38:52 UTC (rev 2005)
@@ -1,4 +1,4 @@
-package org.jboss.webbeans.test.unit.implementation.producer.method;
+package org.jboss.webbeans.test.unit.implementation.producer.field.method;
import javax.inject.Current;
import javax.inject.Produces;
Modified: ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/field/method/ManagerProducerTest.java
===================================================================
--- ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/method/ManagerProducerTest.java 2009-03-15 15:53:42 UTC (rev 2003)
+++ ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/field/method/ManagerProducerTest.java 2009-03-15 17:38:52 UTC (rev 2005)
@@ -1,4 +1,4 @@
-package org.jboss.webbeans.test.unit.implementation.producer.method;
+package org.jboss.webbeans.test.unit.implementation.producer.field.method;
import org.jboss.testharness.impl.packaging.Artifact;
import org.jboss.webbeans.test.unit.AbstractWebBeansTest;
15 years, 10 months
[webbeans-commits] Webbeans SVN: r2004 - in ri/trunk: xsd and 10 other directories.
by webbeans-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2009-03-15 13:25:15 -0400 (Sun, 15 Mar 2009)
New Revision: 2004
Added:
ri/trunk/xsd/
ri/trunk/xsd/pom.xml
ri/trunk/xsd/src/
ri/trunk/xsd/src/main/
ri/trunk/xsd/src/main/java/
ri/trunk/xsd/src/main/java/org/
ri/trunk/xsd/src/main/java/org/jboss/
ri/trunk/xsd/src/main/java/org/jboss/webbeans/
ri/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/
ri/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/PackageInfo.java
ri/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/PackageSchemaGenerator.java
ri/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/helpers/
ri/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/helpers/DataSetter.java
ri/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/helpers/XSDHelper.java
ri/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/
ri/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/ClassModel.java
ri/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/FieldModel.java
ri/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/MethodModel.java
ri/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/NamedModel.java
ri/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/ParameterModel.java
ri/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/sample-schema.xsd
ri/trunk/xsd/src/main/resources/
ri/trunk/xsd/src/test/
ri/trunk/xsd/src/test/java/
ri/trunk/xsd/src/test/resources/
Modified:
ri/trunk/pom.xml
Log:
split out xsd
Modified: ri/trunk/pom.xml
===================================================================
--- ri/trunk/pom.xml 2009-03-15 15:53:42 UTC (rev 2003)
+++ ri/trunk/pom.xml 2009-03-15 17:25:15 UTC (rev 2004)
@@ -67,6 +67,7 @@
<module>api</module>
<module>spi</module>
<module>impl</module>
+ <module>xsd</module>
<module>porting-package</module>
<module>jboss-tck-runner</module>
</modules>
Added: ri/trunk/xsd/pom.xml
===================================================================
--- ri/trunk/xsd/pom.xml (rev 0)
+++ ri/trunk/xsd/pom.xml 2009-03-15 17:25:15 UTC (rev 2004)
@@ -0,0 +1,50 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <artifactId>webbeans-parent</artifactId>
+ <groupId>org.jboss.webbeans</groupId>
+ <version>1.0.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.jboss.webbeans</groupId>
+ <artifactId>webbeans-xsd-generator</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <name>Web Beans XSD generator</name>
+ <dependencies>
+
+ <dependency>
+ <groupId>org.jboss.webbeans</groupId>
+ <artifactId>jsr299-api</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.testng</groupId>
+ <artifactId>testng</artifactId>
+ <scope>test</scope>
+ <classifier>jdk15</classifier>
+ <exclusions>
+ <exclusion>
+ <artifactId>junit</artifactId>
+ <groupId>junit</groupId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>dom4j</groupId>
+ <artifactId>dom4j</artifactId>
+ </dependency>
+
+ </dependencies>
+
+ <build>
+ <defaultGoal>install</defaultGoal>
+ <plugins>
+ </plugins>
+ </build>
+
+</project>
Added: ri/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/PackageInfo.java
===================================================================
--- ri/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/PackageInfo.java (rev 0)
+++ ri/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/PackageInfo.java 2009-03-15 17:25:15 UTC (rev 2004)
@@ -0,0 +1,48 @@
+package org.jboss.webbeans.xsd;
+
+import java.util.List;
+
+import org.dom4j.Document;
+
+public class PackageInfo
+{
+ private List<String> namespaces;
+ private Document schema;
+ private String packageName;
+
+ public PackageInfo(String packageName)
+ {
+ this.packageName = packageName;
+ }
+
+ public List<String> getNamespaces()
+ {
+ return namespaces;
+ }
+
+ public void setNamespaces(List<String> namespaces)
+ {
+ this.namespaces = namespaces;
+ }
+
+ public Document getSchema()
+ {
+ return schema;
+ }
+
+ public void setSchema(Document schema)
+ {
+ this.schema = schema;
+ }
+
+ public String getPackageName()
+ {
+ return packageName;
+ }
+
+ public void setPackageName(String packageName)
+ {
+ this.packageName = packageName;
+ }
+
+}
Added: ri/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/PackageSchemaGenerator.java
===================================================================
--- ri/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/PackageSchemaGenerator.java (rev 0)
+++ ri/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/PackageSchemaGenerator.java 2009-03-15 17:25:15 UTC (rev 2004)
@@ -0,0 +1,124 @@
+/*
+ * 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;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import javax.annotation.processing.AbstractProcessor;
+import javax.annotation.processing.ProcessingEnvironment;
+import javax.annotation.processing.RoundEnvironment;
+import javax.annotation.processing.SupportedAnnotationTypes;
+import javax.annotation.processing.SupportedSourceVersion;
+import javax.lang.model.SourceVersion;
+import javax.lang.model.element.Element;
+import javax.lang.model.element.TypeElement;
+import javax.lang.model.type.DeclaredType;
+import javax.lang.model.type.TypeKind;
+import javax.lang.model.util.ElementFilter;
+
+import org.jboss.webbeans.xsd.helpers.DataSetter;
+import org.jboss.webbeans.xsd.helpers.XSDHelper;
+import org.jboss.webbeans.xsd.model.ClassModel;
+
+/**
+ * An annotation processor that updates the package-level XSD for the packages
+ * that have had their files compiled.
+ *
+ * @author Nicklas Karlsson
+ *
+ */
+(a)SupportedSourceVersion(SourceVersion.RELEASE_6)
+@SupportedAnnotationTypes("*")
+public class PackageSchemaGenerator extends AbstractProcessor
+{
+ // A helper for the XSD operations
+ XSDHelper helper;
+
+ @Override
+ public synchronized void init(ProcessingEnvironment processingEnv)
+ {
+ super.init(processingEnv);
+ helper = new XSDHelper(processingEnv.getFiler());
+ }
+
+ @Override
+ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv)
+ {
+ 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 : roundEnv.getRootElements())
+ {
+ workingSet.add(inspectClass(element));
+ }
+ if (!roundEnv.processingOver())
+ {
+ // Update the package XSDs for the files changed
+ helper.updateSchemas(workingSet);
+ // And flush the changes to disk
+ helper.writeSchemas();
+ }
+ return false;
+ }
+
+ /**
+ * Creates a class model from a class element
+ *
+ * @param element The element to analyze
+ * @return The class model
+ */
+ private ClassModel inspectClass(Element element)
+ {
+ TypeElement typeElement = (TypeElement) element;
+ ClassModel classModel = new ClassModel();
+
+ // If the class has superclass's, scan them recursively
+ if (typeElement.getSuperclass().getKind() != TypeKind.NONE)
+ {
+ inspectClass(((DeclaredType) typeElement.getSuperclass()).asElement());
+ }
+
+ // Gets the parent from the cache. We know it's there since we has scanned
+ // the
+ // hierarchy already
+ ClassModel parent = helper.getCachedClassModel(typeElement.getSuperclass().toString());
+ // Populate the class level info (name, parent etc)
+ DataSetter.populateClassModel(classModel, element, parent);
+ // Filter out the fields and populate the model
+ for (Element field : ElementFilter.fieldsIn(element.getEnclosedElements()))
+ {
+ DataSetter.populateFieldModel(classModel, field);
+ }
+ // Filter out the methods and populate the model
+ for (Element method : ElementFilter.methodsIn(element.getEnclosedElements()))
+ {
+ DataSetter.populateMethodModel(classModel, method);
+ }
+ // Filter out the constructors and populate the model
+ for (Element constructor : ElementFilter.constructorsIn(element.getEnclosedElements()))
+ {
+ DataSetter.populateMethodModel(classModel, constructor);
+ }
+ // Place the new class model in the cache
+ helper.cacheClassModel(classModel);
+ return classModel;
+ }
+
+}
Added: ri/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/helpers/DataSetter.java
===================================================================
--- ri/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/helpers/DataSetter.java (rev 0)
+++ ri/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/helpers/DataSetter.java 2009-03-15 17:25:15 UTC (rev 2004)
@@ -0,0 +1,118 @@
+/*
+ * 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 javax.lang.model.element.Element;
+import javax.lang.model.element.ExecutableElement;
+import javax.lang.model.element.Modifier;
+import javax.lang.model.element.TypeElement;
+import javax.lang.model.element.VariableElement;
+
+import org.jboss.webbeans.xsd.model.ClassModel;
+import org.jboss.webbeans.xsd.model.FieldModel;
+import org.jboss.webbeans.xsd.model.MethodModel;
+import org.jboss.webbeans.xsd.model.ParameterModel;
+
+/**
+ * Helper for examining classes and members and populating the model
+ *
+ * @author Nicklas Karlsson
+ *
+ */
+public class DataSetter
+{
+
+ /**
+ * Checks if an element is public
+ *
+ * @param element The element to check
+ * @return True if public, false otherwise
+ */
+ private static boolean isPublic(Element element)
+ {
+ return element.getModifiers().contains(Modifier.PUBLIC);
+ }
+
+ /**
+ * Inspects a type element and populates a class model
+ *
+ * @param classModel The class model to populate
+ * @param element The element to inspect
+ * @param parent The parent of the class
+ */
+ public static void populateClassModel(ClassModel classModel, Element element, ClassModel parent)
+ {
+ TypeElement typeElement = (TypeElement) element;
+ classModel.setName(typeElement.getQualifiedName().toString());
+ classModel.setParent(parent);
+ }
+
+ /**
+ * Inspects a field element and populates a class model
+ *
+ * @param classModel The class model to populate
+ * @param element The element to inspect
+ */
+ public static void populateFieldModel(ClassModel classModel, Element element)
+ {
+ if (!isPublic(element))
+ {
+ return;
+ }
+ String name = element.getSimpleName().toString();
+ String type = element.asType().toString();
+ classModel.addField(new FieldModel(name, type));
+ }
+
+ /**
+ * Inspects a method or constructor 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;
+ }
+ ExecutableElement executableElement = (ExecutableElement) element;
+
+ String name = element.getSimpleName().toString();
+ String returnType = executableElement.getReturnType().toString();
+ MethodModel method = new MethodModel(name, returnType);
+
+ for (VariableElement parameterElement : executableElement.getParameters())
+ {
+ String paramName = parameterElement.getSimpleName().toString();
+ String paramType = parameterElement.asType().toString();
+ ParameterModel parameter = new ParameterModel(paramName, paramType);
+ method.addParameter(parameter);
+ }
+ // OK, checting a little with a common model for methods and constructors
+ if ("<init>".equals(name))
+ {
+ classModel.addConstructor(method);
+ }
+ else
+ {
+ classModel.addMethod(method);
+ }
+ }
+
+}
Added: ri/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/helpers/XSDHelper.java
===================================================================
--- ri/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/helpers/XSDHelper.java (rev 0)
+++ ri/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/helpers/XSDHelper.java 2009-03-15 17:25:15 UTC (rev 2004)
@@ -0,0 +1,289 @@
+/*
+ * 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.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.annotation.processing.Filer;
+import javax.tools.StandardLocation;
+
+import org.dom4j.Document;
+import org.dom4j.DocumentException;
+import org.dom4j.DocumentHelper;
+import org.dom4j.Node;
+import org.dom4j.io.OutputFormat;
+import org.dom4j.io.SAXReader;
+import org.dom4j.io.XMLWriter;
+import org.jboss.webbeans.xsd.PackageInfo;
+import org.jboss.webbeans.xsd.model.ClassModel;
+
+/**
+ * Helper for XSD related operations
+ *
+ * @author Nicklas Karlsson
+ *
+ */
+public class XSDHelper
+{
+ public 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 filed of the annotation processing environment
+ private Filer filer;
+ // 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, PackageInfo> packageInfoMap = new HashMap<String, PackageInfo>();
+
+ /**
+ * Creates a new helper
+ *
+ * @param filer The filer of the processing environment
+ */
+ public XSDHelper(Filer filer)
+ {
+ this.filer = filer;
+ }
+
+ /**
+ * 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 PackageInfo readPackageInfo(String packageName) throws DocumentException, IOException
+ {
+ PackageInfo packageInfo = new PackageInfo(packageName);
+ packageInfo.setNamespaces(readNamespaces(packageName));
+ Document schema = readSchema(packageName);
+ packageInfo.setSchema(schema != null ? schema : createSchema(packageName));
+ return packageInfo;
+ }
+
+ /**
+ * Reads the namespaces for a package
+ *
+ * @param packageName The name of the package
+ * @return The namespaces
+ */
+ private List<String> readNamespaces(String packageName)
+ {
+ // TODO dummy
+ return new ArrayList<String>();
+ }
+
+ /**
+ * Creates a new schema document
+ *
+ * @param packageName The package name of the schema
+ * @return The document
+ */
+ private Document createSchema(String packageName)
+ {
+ Document packageXSD = DocumentHelper.createDocument();
+ packageXSD.addElement("Package");
+ return packageXSD;
+ }
+
+ /**
+ * 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 = filer.getResource(StandardLocation.CLASS_OUTPUT, packageName, "schema.xsd").openInputStream();
+ return new SAXReader().read(in);
+ }
+ catch (IOException e)
+ {
+ return null;
+ }
+ finally
+ {
+ if (in != null)
+ {
+ in.close();
+ }
+ }
+ }
+
+ /**
+ * Writes package info to the disk
+ *
+ * @param packageInfo The package info to store
+ */
+ private void writePackageInfo(PackageInfo packageInfo)
+ {
+ try
+ {
+ writeSchema(packageInfo.getPackageName(), packageInfo.getSchema());
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException("Could not write schema for " + packageInfo.getPackageName());
+ }
+ writeNamespaces(packageInfo.getPackageName(), packageInfo.getNamespaces());
+ }
+
+ /**
+ * Writes the namespaces to disk
+ *
+ * @param packageName The package name
+ * @param namespaces The namespaces
+ */
+ private void writeNamespaces(String packageName, List<String> namespaces)
+ {
+ // TODO dummy
+ }
+
+ /**
+ * Writes a schema to disk
+ *
+ * @param packageName The package name
+ * @param schema The schema
+ * @throws IOException If the file could not be written
+ */
+ private void writeSchema(String packageName, Document schema) throws IOException
+ {
+ OutputStream out = null;
+ try
+ {
+ OutputFormat format = OutputFormat.createPrettyPrint();
+ out = filer.createResource(StandardLocation.CLASS_OUTPUT, packageName, "schema.xsd").openOutputStream();
+ XMLWriter writer = new XMLWriter(out, format);
+ writer.write(schema);
+ 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();
+ PackageInfo packageInfo = packageInfoMap.get(packageName);
+ if (packageInfo == null) {
+ try
+ {
+ packageInfo = readPackageInfo(packageName);
+ }
+ catch (DocumentException e)
+ {
+ throw new RuntimeException("Could not parse schema for package " + packageName);
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException("Could not read schema for package " + packageName);
+ }
+ packageInfoMap.put(packageName, packageInfo);
+ }
+ updateClassInSchema(classModel, packageInfo.getSchema());
+ }
+ }
+
+ /**
+ * Writes the schemas back to disk
+ */
+ public void writeSchemas()
+ {
+ for (PackageInfo packageInfo : packageInfoMap.values()) {
+ writePackageInfo(packageInfo);
+ }
+ }
+
+ /**
+ * Updates a schema with XSD from a file model
+ *
+ * @param schema The schema
+ * @param classModel The class model
+ */
+ private void updateClassInSchema(ClassModel classModel, Document schema)
+ {
+ Node oldClassModel = schema.selectSingleNode("//" + classModel.getSimpleName());
+ if (oldClassModel != null)
+ {
+ // Remove the old class definition
+ schema.getRootElement().remove(oldClassModel);
+ }
+ // Create a new one
+ schema.getRootElement().addElement(classModel.getSimpleName());
+ }
+
+ /**
+ * Gets the short name of a package (the last part)
+ *
+ * @param packageName The package name
+ * @return A short name
+ */
+ private String getShortName(String packageName)
+ {
+ int lastDot = packageName.lastIndexOf(".");
+ return lastDot < 0 ? packageName : packageName.substring(lastDot + 1);
+ }
+
+ /**
+ * 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);
+ }
+}
Added: ri/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/ClassModel.java
===================================================================
--- ri/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/ClassModel.java (rev 0)
+++ ri/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/ClassModel.java 2009-03-15 17:25:15 UTC (rev 2004)
@@ -0,0 +1,223 @@
+/*
+ * 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 java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * A model of a class
+ *
+ * @author Nicklas Karlsson
+ *
+ */
+public class ClassModel extends NamedModel
+{
+ // The parent (or null if top-level)
+ private ClassModel parent;
+
+ // The fields of the class
+ private List<FieldModel> fields = new ArrayList<FieldModel>();
+ // The methods of the class
+ private List<MethodModel> methods = new ArrayList<MethodModel>();
+ // The constructors of the class
+ private List<MethodModel> constructors = new ArrayList<MethodModel>();
+
+ /**
+ * Creates a new class model
+ */
+ public ClassModel()
+ {
+ }
+
+ /**
+ * Adds a field to the class model
+ *
+ * @param fieldModel The field to add
+ */
+ public void addField(FieldModel fieldModel)
+ {
+ fields.add(fieldModel);
+ }
+
+ /**
+ * Adds a constructor to the model
+ *
+ * @param constructorModel The constructor to add
+ */
+ public void addConstructor(MethodModel constructorModel)
+ {
+ constructors.add(constructorModel);
+ }
+
+ /**
+ * Adds a method to the model
+ *
+ * @param methodModel The method to add
+ */
+ public void addMethod(MethodModel methodModel)
+ {
+ methods.add(methodModel);
+ }
+
+ @Override
+ public String toString()
+ {
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("Name: " + name + "\n");
+ buffer.append("Constructors: " + getMergedConstructors() + "\n");
+ buffer.append("Methods: " + getMergedMethods() + "\n");
+ buffer.append("Fields: " + getMergedFields() + "\n");
+ return buffer.toString();
+ }
+
+ /**
+ * Gets the parent class model of the class
+ *
+ * @return The parent or null if none present
+ */
+ public ClassModel getParent()
+ {
+ return parent;
+ }
+
+ /**
+ * Sets the parent
+ *
+ * @param parent The new parent class model
+ */
+ public void setParent(ClassModel parent)
+ {
+ this.parent = parent;
+ }
+
+ /**
+ * Gets the package of the file
+ *
+ * @return The package
+ */
+ public String getPackage()
+ {
+ int lastDot = name.lastIndexOf(".");
+ return lastDot < 0 ? name : name.substring(0, lastDot);
+ }
+
+ /**
+ * Gets the simple name of the class
+ *
+ * @return The simple name
+ */
+ public String getSimpleName()
+ {
+ int lastDot = name.lastIndexOf(".");
+ return lastDot < 0 ? name : name.substring(lastDot + 1);
+ }
+
+ /**
+ * Gets the merged hierarchy of available constructors. Returns the
+ * constructors of this class since constructors aren't inherited
+ *
+ * @return The set of constructors available
+ */
+ public Set<MethodModel> getMergedConstructors()
+ {
+ return new HashSet<MethodModel>(constructors);
+ }
+
+ /**
+ * Gets the public field of the class
+ *
+ * @return The public fields
+ */
+ public List<FieldModel> getFields()
+ {
+ return fields;
+ }
+
+ /**
+ * Gets the merged hierarchy of available fields.
+ *
+ * @return The set of public fields available
+ */
+ public Set<FieldModel> getMergedFields()
+ {
+ Set<FieldModel> mergedFields = new HashSet<FieldModel>(fields);
+ ClassModel currentParent = parent;
+ while (currentParent != null)
+ {
+ mergedFields.addAll(currentParent.getFields());
+ currentParent = currentParent.getParent();
+ }
+ return mergedFields;
+ }
+
+ /**
+ * Gets the public methods of the class
+ *
+ * @return The public methods
+ */
+ public List<MethodModel> getMethods()
+ {
+ return methods;
+ }
+
+ /**
+ * Gets the merged hierarchy of available fields.
+ *
+ * @return The set of public fields available
+ */
+ public Set<MethodModel> getMergedMethods()
+ {
+ Set<MethodModel> mergedMethods = new HashSet<MethodModel>(methods);
+ ClassModel currentParent = parent;
+ while (currentParent != null)
+ {
+ mergedMethods.addAll(currentParent.getMethods());
+ currentParent = currentParent.getParent();
+ }
+ return mergedMethods;
+ }
+
+ public Set<String> getReferencedTypes()
+ {
+ Set<String> types = new HashSet<String>();
+ for (FieldModel field : getMergedFields())
+ {
+ types.add(field.getType());
+ }
+ for (MethodModel method : getMergedMethods())
+ {
+ types.add(method.getReturnType());
+ for (ParameterModel parameter : method.getParameters())
+ {
+ types.add(parameter.getType());
+ }
+ }
+ for (MethodModel constructor : getMergedConstructors())
+ {
+ for (ParameterModel parameter : constructor.getParameters())
+ {
+ types.add(parameter.getType());
+ }
+ }
+ return types;
+ }
+
+}
Added: ri/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/FieldModel.java
===================================================================
--- ri/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/FieldModel.java (rev 0)
+++ ri/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/FieldModel.java 2009-03-15 17:25:15 UTC (rev 2004)
@@ -0,0 +1,60 @@
+/*
+ * 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;
+
+/**
+ * A model of a field
+ *
+ * @author Nicklas Karlsosn
+ *
+ */
+public class FieldModel extends NamedModel
+{
+ protected String type;
+
+ public FieldModel(String name, String type)
+ {
+ super(name);
+ this.type = type;
+ }
+
+ public String getType()
+ {
+ return type;
+ }
+
+ @Override
+ public boolean equals(Object other)
+ {
+ FieldModel otherModel = (FieldModel) other;
+ return name.equals(otherModel.getName()) && type.equals(otherModel.getType());
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return name.hashCode() + type.hashCode();
+ }
+
+ @Override
+ public String toString()
+ {
+ return type + " " + name;
+ }
+
+}
Added: ri/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/MethodModel.java
===================================================================
--- ri/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/MethodModel.java (rev 0)
+++ ri/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/MethodModel.java 2009-03-15 17:25:15 UTC (rev 2004)
@@ -0,0 +1,74 @@
+/*
+ * 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 java.util.ArrayList;
+import java.util.List;
+
+/**
+ * The model of a method
+ *
+ * @author Nicklas Karlsson
+ *
+ */
+public class MethodModel extends NamedModel
+{
+ private String returnType;
+ private List<ParameterModel> parameters = new ArrayList<ParameterModel>();
+
+ public MethodModel(String name, String returnType)
+ {
+ super(name);
+ this.returnType = returnType;
+ }
+
+ public void addParameter(ParameterModel parameter)
+ {
+ parameters.add(parameter);
+ }
+
+ public List<ParameterModel> getParameters()
+ {
+ return parameters;
+ }
+
+ public String getReturnType()
+ {
+ return returnType;
+ }
+
+ @Override
+ public boolean equals(Object other)
+ {
+ MethodModel otherModel = (MethodModel) other;
+ return name.equals(otherModel.getName()) && returnType.equals(otherModel.getReturnType()) && parameters.equals(otherModel.getParameters());
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return name.hashCode() + returnType.hashCode() + parameters.hashCode();
+ }
+
+ @Override
+ public String toString()
+ {
+ return returnType + " " + name + "(" + (parameters.isEmpty() ? "" : parameters) + ")";
+ }
+
+}
Added: ri/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/NamedModel.java
===================================================================
--- ri/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/NamedModel.java (rev 0)
+++ ri/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/NamedModel.java 2009-03-15 17:25:15 UTC (rev 2004)
@@ -0,0 +1,48 @@
+/*
+ * 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;
+
+/**
+ * A superclass for named models
+ *
+ * @author Nicklas Karlsson
+ *
+ */
+public class NamedModel
+{
+ protected String name;
+
+ public NamedModel()
+ {
+ }
+
+ public NamedModel(String name)
+ {
+ this.name = name;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+}
Added: ri/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/ParameterModel.java
===================================================================
--- ri/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/ParameterModel.java (rev 0)
+++ ri/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/ParameterModel.java 2009-03-15 17:25:15 UTC (rev 2004)
@@ -0,0 +1,47 @@
+/*
+ * 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;
+
+/**
+ * The model of a method or constrcutor parameter
+ *
+ * @author Nicklas Karlsson
+ *
+ */
+public class ParameterModel extends FieldModel
+{
+
+ public ParameterModel(String name, String type)
+ {
+ super(name, type);
+ }
+
+ @Override
+ public boolean equals(Object other)
+ {
+ ParameterModel otherModel = (ParameterModel) other;
+ return type.equals(otherModel.getType());
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return type.hashCode();
+ }
+
+}
Added: ri/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/sample-schema.xsd
===================================================================
--- ri/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/sample-schema.xsd (rev 0)
+++ ri/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/sample-schema.xsd 2009-03-15 17:25:15 UTC (rev 2004)
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ elementFormDefault="qualified"
+ targetNamespace="urn:java:com.acme.foo"
+ xmlns:foo="urn:java:com.acme.foo"
+ xmlns:ee="urn:java:ee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.w3.org/2001/XMLSchema http://www.w3.org/2001/XMLSchema.xsd"
+ >
+
+ <xs:element name="Foo">
+ <xs:complexType>
+ <xs:choice>
+ <!-- Options to allow people to declare this class a binding type or stereotype - TODO only if an annotation -->
+ <xs:element ref="ee:BindingType"/>
+ <xs:element ref="ee:StereotypType"/>
+ <!-- Somehow import all binding types known etc. to give people that option -->
+ <xs:any /> <!-- Can't guess all types people want to put here -->
+ </xs:choice>
+ </xs:complexType>
+ </xs:element>
+
+ <xs:element name="Bar">
+
+ </xs:element>
+
+
+</xs:schema>
\ No newline at end of file
15 years, 10 months
[webbeans-commits] Webbeans SVN: r2003 - in ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/producer: method and 1 other directory.
by webbeans-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2009-03-15 11:53:42 -0400 (Sun, 15 Mar 2009)
New Revision: 2003
Added:
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/method/
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/method/IntInjection.java
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/method/ManagerProducer.java
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/method/ManagerProducerTest.java
Removed:
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/IntInjection.java
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/ManagerProducer.java
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/ManagerProducerTest.java
Log:
minor
Deleted: ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/IntInjection.java
===================================================================
--- ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/IntInjection.java 2009-03-15 15:45:52 UTC (rev 2002)
+++ ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/IntInjection.java 2009-03-15 15:53:42 UTC (rev 2003)
@@ -1,15 +0,0 @@
-package org.jboss.webbeans.test.unit.implementation.producer;
-
-import javax.inject.Initializer;
-
-public class IntInjection
-{
-
- int value;
-
- @Initializer public IntInjection(Integer integer)
- {
- this.value = integer;
- }
-
-}
Deleted: ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/ManagerProducer.java
===================================================================
--- ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/ManagerProducer.java 2009-03-15 15:45:52 UTC (rev 2002)
+++ ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/ManagerProducer.java 2009-03-15 15:53:42 UTC (rev 2003)
@@ -1,32 +0,0 @@
-package org.jboss.webbeans.test.unit.implementation.producer;
-
-import javax.inject.Current;
-import javax.inject.Produces;
-import javax.inject.manager.InjectionPoint;
-import javax.inject.manager.Manager;
-
-class ManagerProducer
-{
-
- @Current Manager manager;
-
- private static boolean injectionPointInjected;
-
- public static boolean isInjectionPointInjected()
- {
- return injectionPointInjected;
- }
-
- public static void setInjectionPointInjected(boolean injectionPointInjected)
- {
- ManagerProducer.injectionPointInjected = injectionPointInjected;
- }
-
- @Produces
- Integer create(InjectionPoint point)
- {
- injectionPointInjected = point != null;
- return 10;
- }
-
-}
Deleted: ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/ManagerProducerTest.java
===================================================================
--- ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/ManagerProducerTest.java 2009-03-15 15:45:52 UTC (rev 2002)
+++ ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/ManagerProducerTest.java 2009-03-15 15:53:42 UTC (rev 2003)
@@ -1,18 +0,0 @@
-package org.jboss.webbeans.test.unit.implementation.producer;
-
-import org.jboss.testharness.impl.packaging.Artifact;
-import org.jboss.webbeans.test.unit.AbstractWebBeansTest;
-import org.testng.annotations.Test;
-
-@Artifact
-public class ManagerProducerTest extends AbstractWebBeansTest
-{
- @Test(description="WBRI-183")
- public void testInjectManagerProducer()
- {
- ManagerProducer.setInjectionPointInjected(false);
- manager.getInstanceByType(IntInjection.class);
- assert ManagerProducer.isInjectionPointInjected();
- }
-
-}
Copied: ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/method/IntInjection.java (from rev 2000, ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/IntInjection.java)
===================================================================
--- ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/method/IntInjection.java (rev 0)
+++ ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/method/IntInjection.java 2009-03-15 15:53:42 UTC (rev 2003)
@@ -0,0 +1,15 @@
+package org.jboss.webbeans.test.unit.implementation.producer.method;
+
+import javax.inject.Initializer;
+
+public class IntInjection
+{
+
+ int value;
+
+ @Initializer public IntInjection(Integer integer)
+ {
+ this.value = integer;
+ }
+
+}
Property changes on: ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/method/IntInjection.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Copied: ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/method/ManagerProducer.java (from rev 2000, ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/ManagerProducer.java)
===================================================================
--- ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/method/ManagerProducer.java (rev 0)
+++ ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/method/ManagerProducer.java 2009-03-15 15:53:42 UTC (rev 2003)
@@ -0,0 +1,32 @@
+package org.jboss.webbeans.test.unit.implementation.producer.method;
+
+import javax.inject.Current;
+import javax.inject.Produces;
+import javax.inject.manager.InjectionPoint;
+import javax.inject.manager.Manager;
+
+class ManagerProducer
+{
+
+ @Current Manager manager;
+
+ private static boolean injectionPointInjected;
+
+ public static boolean isInjectionPointInjected()
+ {
+ return injectionPointInjected;
+ }
+
+ public static void setInjectionPointInjected(boolean injectionPointInjected)
+ {
+ ManagerProducer.injectionPointInjected = injectionPointInjected;
+ }
+
+ @Produces
+ Integer create(InjectionPoint point)
+ {
+ injectionPointInjected = point != null;
+ return 10;
+ }
+
+}
Property changes on: ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/method/ManagerProducer.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Copied: ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/method/ManagerProducerTest.java (from rev 2000, ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/ManagerProducerTest.java)
===================================================================
--- ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/method/ManagerProducerTest.java (rev 0)
+++ ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/method/ManagerProducerTest.java 2009-03-15 15:53:42 UTC (rev 2003)
@@ -0,0 +1,18 @@
+package org.jboss.webbeans.test.unit.implementation.producer.method;
+
+import org.jboss.testharness.impl.packaging.Artifact;
+import org.jboss.webbeans.test.unit.AbstractWebBeansTest;
+import org.testng.annotations.Test;
+
+@Artifact
+public class ManagerProducerTest extends AbstractWebBeansTest
+{
+ @Test(description="WBRI-183")
+ public void testInjectManagerProducer()
+ {
+ ManagerProducer.setInjectionPointInjected(false);
+ manager.getInstanceByType(IntInjection.class);
+ assert ManagerProducer.isInjectionPointInjected();
+ }
+
+}
Property changes on: ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/method/ManagerProducerTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
15 years, 10 months
[webbeans-commits] Webbeans SVN: r2002 - in ri/trunk/impl/src/main/java/org/jboss/webbeans: injection and 1 other directory.
by webbeans-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2009-03-15 11:45:52 -0400 (Sun, 15 Mar 2009)
New Revision: 2002
Added:
ri/trunk/impl/src/main/java/org/jboss/webbeans/injection/NonContextualInjector.java
Removed:
ri/trunk/impl/src/main/java/org/jboss/webbeans/injection/ServletInjector.java
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/ManagerImpl.java
Log:
minor
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/ManagerImpl.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/ManagerImpl.java 2009-03-15 15:43:00 UTC (rev 2001)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/ManagerImpl.java 2009-03-15 15:45:52 UTC (rev 2002)
@@ -70,7 +70,7 @@
import org.jboss.webbeans.event.ObserverImpl;
import org.jboss.webbeans.injection.ResolvableAnnotatedClass;
import org.jboss.webbeans.injection.Resolver;
-import org.jboss.webbeans.injection.ServletInjector;
+import org.jboss.webbeans.injection.NonContextualInjector;
import org.jboss.webbeans.introspector.AnnotatedClass;
import org.jboss.webbeans.introspector.AnnotatedItem;
import org.jboss.webbeans.introspector.AnnotatedMethod;
@@ -134,7 +134,7 @@
private final transient Map<Bean<?>, Bean<?>> specializedBeans;
- private final transient ServletInjector servletInjector;
+ private final transient NonContextualInjector nonContextualInjector;
/**
* Create a new manager
@@ -162,7 +162,7 @@
}
};
this.specializedBeans = new HashMap<Bean<?>, Bean<?>>();
- this.servletInjector = new ServletInjector(this);
+ this.nonContextualInjector = new NonContextualInjector(this);
List<Class<? extends Annotation>> defaultEnabledDeploymentTypes = new ArrayList<Class<? extends Annotation>>();
defaultEnabledDeploymentTypes.add(0, Standard.class);
defaultEnabledDeploymentTypes.add(1, Production.class);
@@ -617,7 +617,7 @@
public void injectNonContextualInstance(Object instance)
{
- servletInjector.inject(instance);
+ nonContextualInjector.inject(instance);
}
@SuppressWarnings("unchecked")
Copied: ri/trunk/impl/src/main/java/org/jboss/webbeans/injection/NonContextualInjector.java (from rev 2001, ri/trunk/impl/src/main/java/org/jboss/webbeans/injection/ServletInjector.java)
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/injection/NonContextualInjector.java (rev 0)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/injection/NonContextualInjector.java 2009-03-15 15:45:52 UTC (rev 2002)
@@ -0,0 +1,41 @@
+package org.jboss.webbeans.injection;
+
+import java.util.Set;
+import java.util.concurrent.Callable;
+
+import org.jboss.webbeans.ManagerImpl;
+import org.jboss.webbeans.introspector.jlr.AnnotatedClassImpl;
+import org.jboss.webbeans.util.Beans;
+import org.jboss.webbeans.util.collections.ConcurrentCache;
+
+public class NonContextualInjector
+{
+
+ private final ConcurrentCache<Class<?>, Set<FieldInjectionPoint<?>>> instances;
+ private final ManagerImpl manager;
+
+ public NonContextualInjector(ManagerImpl manager)
+ {
+ this.manager = manager;
+ this.instances = new ConcurrentCache<Class<?>, Set<FieldInjectionPoint<?>>>();
+ }
+
+ public void inject(final Object instance)
+ {
+ Set<FieldInjectionPoint<?>> injectionPoints = instances.putIfAbsent(instance.getClass(), new Callable<Set<FieldInjectionPoint<?>>>()
+ {
+
+ public Set<FieldInjectionPoint<?>> call() throws Exception
+ {
+ return Beans.getFieldInjectionPoints(AnnotatedClassImpl.of(instance.getClass()), null);
+ }
+
+ }
+ );
+ for (FieldInjectionPoint<?> injectionPoint : injectionPoints)
+ {
+ injectionPoint.inject(instance, manager, null);
+ }
+ }
+
+}
Property changes on: ri/trunk/impl/src/main/java/org/jboss/webbeans/injection/NonContextualInjector.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Deleted: ri/trunk/impl/src/main/java/org/jboss/webbeans/injection/ServletInjector.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/injection/ServletInjector.java 2009-03-15 15:43:00 UTC (rev 2001)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/injection/ServletInjector.java 2009-03-15 15:45:52 UTC (rev 2002)
@@ -1,41 +0,0 @@
-package org.jboss.webbeans.injection;
-
-import java.util.Set;
-import java.util.concurrent.Callable;
-
-import org.jboss.webbeans.ManagerImpl;
-import org.jboss.webbeans.introspector.jlr.AnnotatedClassImpl;
-import org.jboss.webbeans.util.Beans;
-import org.jboss.webbeans.util.collections.ConcurrentCache;
-
-public class ServletInjector
-{
-
- private final ConcurrentCache<Class<?>, Set<FieldInjectionPoint<?>>> instances;
- private final ManagerImpl manager;
-
- public ServletInjector(ManagerImpl manager)
- {
- this.manager = manager;
- this.instances = new ConcurrentCache<Class<?>, Set<FieldInjectionPoint<?>>>();
- }
-
- public void inject(final Object instance)
- {
- Set<FieldInjectionPoint<?>> injectionPoints = instances.putIfAbsent(instance.getClass(), new Callable<Set<FieldInjectionPoint<?>>>()
- {
-
- public Set<FieldInjectionPoint<?>> call() throws Exception
- {
- return Beans.getFieldInjectionPoints(AnnotatedClassImpl.of(instance.getClass()), null);
- }
-
- }
- );
- for (FieldInjectionPoint<?> injectionPoint : injectionPoints)
- {
- injectionPoint.inject(instance, manager, null);
- }
- }
-
-}
15 years, 10 months
[webbeans-commits] Webbeans SVN: r2001 - in ri/trunk: impl/src/main/java/org/jboss/webbeans/injection and 2 other directories.
by webbeans-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2009-03-15 11:43:00 -0400 (Sun, 15 Mar 2009)
New Revision: 2001
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/ManagerImpl.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/injection/ServletInjector.java
ri/trunk/spi/
ri/trunk/spi/pom.xml
ri/trunk/spi/src/main/java/org/jboss/webbeans/manager/api/WebBeansManager.java
Log:
WBRI-184
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/ManagerImpl.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/ManagerImpl.java 2009-03-15 01:47:28 UTC (rev 2000)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/ManagerImpl.java 2009-03-15 15:43:00 UTC (rev 2001)
@@ -57,7 +57,6 @@
import javax.inject.manager.InterceptionType;
import javax.inject.manager.Interceptor;
import javax.inject.manager.Manager;
-import javax.servlet.Servlet;
import org.jboss.webbeans.bean.EnterpriseBean;
import org.jboss.webbeans.bean.NewEnterpriseBean;
@@ -616,9 +615,9 @@
return this.<T>getInstanceToInject(injectionPoint, null);
}
- public void injectServlet(Servlet servlet)
+ public void injectNonContextualInstance(Object instance)
{
- servletInjector.inject(servlet);
+ servletInjector.inject(instance);
}
@SuppressWarnings("unchecked")
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/injection/ServletInjector.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/injection/ServletInjector.java 2009-03-15 01:47:28 UTC (rev 2000)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/injection/ServletInjector.java 2009-03-15 15:43:00 UTC (rev 2001)
@@ -3,8 +3,6 @@
import java.util.Set;
import java.util.concurrent.Callable;
-import javax.servlet.Servlet;
-
import org.jboss.webbeans.ManagerImpl;
import org.jboss.webbeans.introspector.jlr.AnnotatedClassImpl;
import org.jboss.webbeans.util.Beans;
@@ -13,18 +11,18 @@
public class ServletInjector
{
- private final ConcurrentCache<Class<?>, Set<FieldInjectionPoint<?>>> servlets;
+ private final ConcurrentCache<Class<?>, Set<FieldInjectionPoint<?>>> instances;
private final ManagerImpl manager;
public ServletInjector(ManagerImpl manager)
{
this.manager = manager;
- this.servlets = new ConcurrentCache<Class<?>, Set<FieldInjectionPoint<?>>>();
+ this.instances = new ConcurrentCache<Class<?>, Set<FieldInjectionPoint<?>>>();
}
- public void inject(final Servlet instance)
+ public void inject(final Object instance)
{
- Set<FieldInjectionPoint<?>> injectionPoints = servlets.putIfAbsent(instance.getClass(), new Callable<Set<FieldInjectionPoint<?>>>()
+ Set<FieldInjectionPoint<?>> injectionPoints = instances.putIfAbsent(instance.getClass(), new Callable<Set<FieldInjectionPoint<?>>>()
{
public Set<FieldInjectionPoint<?>> call() throws Exception
Property changes on: ri/trunk/spi
___________________________________________________________________
Name: svn:ignore
- .classpath
target
.project
.settings
+ .classpath
target
.project
.settings
test-output
temp-testng-customsuite.xml
Modified: ri/trunk/spi/pom.xml
===================================================================
--- ri/trunk/spi/pom.xml 2009-03-15 01:47:28 UTC (rev 2000)
+++ ri/trunk/spi/pom.xml 2009-03-15 15:43:00 UTC (rev 2001)
@@ -36,11 +36,6 @@
</dependency>
<dependency>
- <groupId>javax.servlet</groupId>
- <artifactId>servlet-api</artifactId>
- <optional>true</optional>
- </dependency>
- <dependency>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
</dependency>
Modified: ri/trunk/spi/src/main/java/org/jboss/webbeans/manager/api/WebBeansManager.java
===================================================================
--- ri/trunk/spi/src/main/java/org/jboss/webbeans/manager/api/WebBeansManager.java 2009-03-15 01:47:28 UTC (rev 2000)
+++ ri/trunk/spi/src/main/java/org/jboss/webbeans/manager/api/WebBeansManager.java 2009-03-15 15:43:00 UTC (rev 2001)
@@ -18,7 +18,6 @@
package org.jboss.webbeans.manager.api;
import javax.inject.manager.Manager;
-import javax.servlet.Servlet;
/**
* Functionality provided by the Web Beans Manager over and above the JSR-299
@@ -31,11 +30,11 @@
{
/**
- * Perform JSR-299 dependency injection on a servlet
+ * Perform JSR-299 dependency injection into a non-contextual instance
*
- * @param servlet
- * the servlet instance to inject
+ * @param instance
+ * the instance to inject
*/
- public void injectServlet(Servlet servlet);
+ public void injectNonContextualInstance(Object instance);
}
15 years, 10 months
[webbeans-commits] Webbeans SVN: r2000 - in ri/trunk: impl/src/main/java/org/jboss/webbeans/bootstrap and 18 other directories.
by webbeans-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2009-03-14 21:47:28 -0400 (Sat, 14 Mar 2009)
New Revision: 2000
Added:
ri/trunk/impl/src/main/java/org/jboss/webbeans/mock/MockEELifecycle.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/mock/MockServletLifecycle.java
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/Animal.java
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/DeadlyAnimal.java
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/DeadlySpider.java
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/DefangedTarantula.java
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/Hound.java
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/HoundLocal.java
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/Salmon.java
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/ScottishFish.java
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/SeaBass.java
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/ServletEnvironmentTest.java
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/Sole.java
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/Spider.java
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/Tame.java
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/Tarantula.java
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/TarantulaProducer.java
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/Tuna.java
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/Whitefish.java
ri/trunk/spi/src/test/java/org/
ri/trunk/spi/src/test/java/org/jboss/
ri/trunk/spi/src/test/java/org/jboss/webbeans/
ri/trunk/spi/src/test/java/org/jboss/webbeans/bootstrap/
ri/trunk/spi/src/test/java/org/jboss/webbeans/bootstrap/api/
ri/trunk/spi/src/test/java/org/jboss/webbeans/bootstrap/api/test/
ri/trunk/spi/src/test/java/org/jboss/webbeans/bootstrap/api/test/BootstrapTest.java
ri/trunk/spi/src/test/java/org/jboss/webbeans/bootstrap/api/test/MockBootstrap.java
ri/trunk/spi/src/test/java/org/jboss/webbeans/bootstrap/api/test/MockEjbServices.java
ri/trunk/spi/src/test/java/org/jboss/webbeans/bootstrap/api/test/MockNamingContext.java
ri/trunk/spi/src/test/java/org/jboss/webbeans/bootstrap/api/test/MockResourceLoader.java
ri/trunk/spi/src/test/java/org/jboss/webbeans/bootstrap/api/test/MockTransactionServices.java
ri/trunk/spi/src/test/java/org/jboss/webbeans/bootstrap/api/test/MockWebBeanDiscovery.java
Removed:
ri/trunk/impl/src/main/java/org/jboss/webbeans/mock/MockLifecycle.java
ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/spi/EjbDiscovery.java
ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/spi/helpers/ForwardingEjbDiscovery.java
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/SimpleBean.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/mock/MockEjBServices.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/mock/MockEjbDiscovery.java
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/StandaloneContainersImpl.java
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/DiscoverFailsBootstrapTest.java
ri/trunk/porting-package/src/main/java/org/jboss/webbeans/tck/StandaloneContainersImpl.java
ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/Bootstrap.java
ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/Environments.java
ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/ServiceRegistry.java
ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/AbstractBootstrap.java
ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/ForwardingBootstrap.java
ri/trunk/spi/src/main/java/org/jboss/webbeans/ejb/spi/EjbServices.java
ri/trunk/spi/src/main/java/org/jboss/webbeans/ejb/spi/helpers/ForwardingEjbServices.java
Log:
WBRI-175, WBRI-178
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/SimpleBean.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/SimpleBean.java 2009-03-15 00:12:08 UTC (rev 1999)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/SimpleBean.java 2009-03-15 01:47:28 UTC (rev 2000)
@@ -268,26 +268,28 @@
*/
protected void injectEjbAndCommonFields(T beanInstance)
{
- NamingContext namingContext = manager.getServices().get(NamingContext.class);
- EjbServices ejbServices = manager.getServices().get(EjbServices.class);
- for (AnnotatedInjectionPoint<?, ?> injectionPoint : ejbInjectionPoints)
+ if (getManager().getServices().contains(EjbServices.class))
{
- Object ejbInstance = ejbServices.resolveEjb(injectionPoint, namingContext);
- injectionPoint.inject(beanInstance, ejbInstance);
+ EjbServices ejbServices = manager.getServices().get(EjbServices.class);
+ NamingContext namingContext = manager.getServices().get(NamingContext.class);
+ for (AnnotatedInjectionPoint<?, ?> injectionPoint : ejbInjectionPoints)
+ {
+ Object ejbInstance = ejbServices.resolveEjb(injectionPoint, namingContext);
+ injectionPoint.inject(beanInstance, ejbInstance);
+ }
+
+ for (AnnotatedInjectionPoint<?, ?> injectionPoint : persistenceUnitInjectionPoints)
+ {
+ Object puInstance = ejbServices.resolvePersistenceContext(injectionPoint, namingContext);
+ injectionPoint.inject(beanInstance, puInstance);
+ }
+
+ for (AnnotatedInjectionPoint<?, ?> injectionPoint : resourceInjectionPoints)
+ {
+ Object resourceInstance = ejbServices.resolveResource(injectionPoint, namingContext);
+ injectionPoint.inject(beanInstance, resourceInstance);
+ }
}
-
- for (AnnotatedInjectionPoint<?, ?> injectionPoint : persistenceUnitInjectionPoints)
- {
- Object puInstance = ejbServices.resolvePersistenceContext(injectionPoint, namingContext);
- injectionPoint.inject(beanInstance, puInstance);
- }
-
- for (AnnotatedInjectionPoint<?, ?> injectionPoint : resourceInjectionPoints)
- {
- Object resourceInstance = ejbServices.resolveResource(injectionPoint, namingContext);
- injectionPoint.inject(beanInstance, resourceInstance);
- }
-
}
/**
@@ -302,9 +304,12 @@
initInjectionPoints();
initPostConstruct();
initPreDestroy();
- initEjbInjectionPoints();
- initPersistenceUnitInjectionPoints();
- initResourceInjectionPoints();
+ if (getManager().getServices().contains(EjbServices.class))
+ {
+ initEjbInjectionPoints();
+ initPersistenceUnitInjectionPoints();
+ initResourceInjectionPoints();
+ }
}
/**
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java 2009-03-15 00:12:08 UTC (rev 1999)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java 2009-03-15 01:47:28 UTC (rev 2000)
@@ -27,6 +27,7 @@
import org.jboss.webbeans.bean.standard.ManagerBean;
import org.jboss.webbeans.bootstrap.api.Bootstrap;
import org.jboss.webbeans.bootstrap.api.helpers.AbstractBootstrap;
+import org.jboss.webbeans.bootstrap.spi.WebBeanDiscovery;
import org.jboss.webbeans.context.ApplicationContext;
import org.jboss.webbeans.context.ConversationContext;
import org.jboss.webbeans.context.DependentContext;
@@ -80,7 +81,7 @@
}
if (!getServices().contains(EjbServices.class))
{
- log.info("EJB services not available. Session beans, injection into non-contextual EJBs, injection of @Resource, @PersistenceContext and @EJB in simple beans, injection of Java EE resources and JMS resources will not be available.");
+ log.info("EJB services not available. Session beans will be simple beans, injection into non-contextual EJBs, injection of @Resource, @PersistenceContext and @EJB in simple beans, injection of Java EE resources and JMS resources will not be available.");
}
this.manager = new ManagerImpl(getServices());
getServices().get(NamingContext.class).bind(ManagerImpl.JNDI_KEY, getManager());
@@ -122,18 +123,6 @@
{
throw new IllegalStateException("Manager has not been initialized");
}
- if (getWebBeanDiscovery() == null)
- {
- throw new IllegalStateException("WebBeanDiscovery not set");
- }
- if (getEjbDiscovery() == null)
- {
- throw new IllegalStateException("EjbDiscovery is not set");
- }
- if (getResourceLoader() == null)
- {
- throw new IllegalStateException("ResourceLoader not set");
- }
if (getApplicationContext() == null)
{
throw new IllegalStateException("No application context BeanStore set");
@@ -141,10 +130,13 @@
beginApplication(getApplicationContext());
BeanStore requestBeanStore = new ConcurrentHashMapBeanStore();
beginDeploy(requestBeanStore);
- // Must populate EJB cache first, as we need it to detect whether a
- // bean is an EJB!
- manager.getEjbDescriptorCache().addAll(getEjbDiscovery().discoverEjbs());
- BeansXmlParser parser = new BeansXmlParser(getResourceLoader(), getWebBeanDiscovery().discoverWebBeansXml());
+ if (getServices().contains(EjbServices.class))
+ {
+ // Must populate EJB cache first, as we need it to detect whether a
+ // bean is an EJB!
+ manager.getEjbDescriptorCache().addAll(getServices().get(EjbServices.class).discoverEjbs());
+ }
+ BeansXmlParser parser = new BeansXmlParser(getServices().get(ResourceLoader.class), getServices().get(WebBeanDiscovery.class).discoverWebBeansXml());
parser.parse();
List<Class<? extends Annotation>> enabledDeploymentTypes = parser.getEnabledDeploymentTypes();
if (enabledDeploymentTypes != null)
@@ -152,7 +144,7 @@
manager.setEnabledDeploymentTypes(enabledDeploymentTypes);
}
log.info("Deployment types: " + manager.getEnabledDeploymentTypes());
- registerBeans(getWebBeanDiscovery().discoverWebBeanClasses());
+ registerBeans(getServices().get(WebBeanDiscovery.class).discoverWebBeanClasses());
manager.fireEvent(manager, new InitializedLiteral());
log.info("Web Beans initialized. Validating beans.");
manager.getResolver().resolveInjectionPoints();
Copied: ri/trunk/impl/src/main/java/org/jboss/webbeans/mock/MockEELifecycle.java (from rev 1999, ri/trunk/impl/src/main/java/org/jboss/webbeans/mock/MockLifecycle.java)
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/mock/MockEELifecycle.java (rev 0)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/mock/MockEELifecycle.java 2009-03-15 01:47:28 UTC (rev 2000)
@@ -0,0 +1,38 @@
+/*
+ * 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.mock;
+
+import org.jboss.webbeans.bootstrap.api.Environments;
+import org.jboss.webbeans.ejb.spi.EjbServices;
+import org.jboss.webbeans.transaction.spi.TransactionServices;
+
+public class MockEELifecycle extends MockServletLifecycle
+{
+
+ private static final TransactionServices MOCK_TRANSACTION_SERVICES = new MockTransactionServices();
+
+ public MockEELifecycle()
+ {
+ super();
+ getBootstrap().getServices().add(TransactionServices.class, MOCK_TRANSACTION_SERVICES);
+ getBootstrap().getServices().add(EjbServices.class, new MockEjBServices(getWebBeanDiscovery()));
+ getBootstrap().setEnvironment(Environments.EE);
+ }
+
+
+
+}
Property changes on: ri/trunk/impl/src/main/java/org/jboss/webbeans/mock/MockEELifecycle.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/mock/MockEjBServices.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/mock/MockEjBServices.java 2009-03-15 00:12:08 UTC (rev 1999)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/mock/MockEjBServices.java 2009-03-15 01:47:28 UTC (rev 2000)
@@ -11,13 +11,22 @@
import javax.inject.manager.InjectionPoint;
import javax.persistence.PersistenceContext;
+import org.jboss.webbeans.bootstrap.spi.WebBeanDiscovery;
import org.jboss.webbeans.ejb.api.EjbReference;
import org.jboss.webbeans.ejb.spi.EjbDescriptor;
import org.jboss.webbeans.ejb.spi.EjbServices;
import org.jboss.webbeans.resources.spi.NamingContext;
-final class MockEjBServices implements EjbServices
+public class MockEjBServices implements EjbServices
{
+
+ private final MockEjbDiscovery ejbDiscovery;
+
+ public MockEjBServices(WebBeanDiscovery webBeanDiscovery)
+ {
+ this.ejbDiscovery = new MockEjbDiscovery(webBeanDiscovery);
+ }
+
public Class<? extends Annotation> getEJBAnnotation()
{
return EJB.class;
@@ -52,6 +61,11 @@
{
// No-op
}
+
+ public Iterable<EjbDescriptor<?>> discoverEjbs()
+ {
+ return ejbDiscovery.discoverEjbs();
+ }
public <T> EjbReference<T> resolveEJB(EjbDescriptor<T> ejbDescriptor, NamingContext naming)
{
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/mock/MockEjbDiscovery.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/mock/MockEjbDiscovery.java 2009-03-15 00:12:08 UTC (rev 1999)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/mock/MockEjbDiscovery.java 2009-03-15 01:47:28 UTC (rev 2000)
@@ -26,11 +26,10 @@
import javax.ejb.Stateful;
import javax.ejb.Stateless;
-import org.jboss.webbeans.bootstrap.spi.EjbDiscovery;
import org.jboss.webbeans.bootstrap.spi.WebBeanDiscovery;
import org.jboss.webbeans.ejb.spi.EjbDescriptor;
-public class MockEjbDiscovery implements EjbDiscovery
+public class MockEjbDiscovery
{
private final WebBeanDiscovery webBeanDiscovery;
Deleted: ri/trunk/impl/src/main/java/org/jboss/webbeans/mock/MockLifecycle.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/mock/MockLifecycle.java 2009-03-15 00:12:08 UTC (rev 1999)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/mock/MockLifecycle.java 2009-03-15 01:47:28 UTC (rev 2000)
@@ -1,114 +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.mock;
-
-
-
-import org.jboss.webbeans.bootstrap.WebBeansBootstrap;
-import org.jboss.webbeans.bootstrap.spi.EjbDiscovery;
-import org.jboss.webbeans.bootstrap.spi.WebBeanDiscovery;
-import org.jboss.webbeans.context.api.BeanStore;
-import org.jboss.webbeans.context.api.helpers.ConcurrentHashMapBeanStore;
-import org.jboss.webbeans.ejb.spi.EjbServices;
-import org.jboss.webbeans.resources.spi.NamingContext;
-import org.jboss.webbeans.resources.spi.ResourceLoader;
-import org.jboss.webbeans.servlet.AbstractLifecycle;
-import org.jboss.webbeans.transaction.spi.TransactionServices;
-
-public class MockLifecycle extends AbstractLifecycle
-{
-
- private static final EjbServices MOCK_EJB_RESOLVER = new MockEjBServices();
- private static final ResourceLoader MOCK_RESOURCE_LOADER = new MockResourceLoader();
- private static final TransactionServices MOCK_TRANSACTION_SERVICES = new MockTransactionServices();
-
- private final WebBeansBootstrap bootstrap;
- private final MockWebBeanDiscovery webBeanDiscovery;
- private final BeanStore applicationBeanStore = new ConcurrentHashMapBeanStore();
- private final BeanStore sessionBeanStore = new ConcurrentHashMapBeanStore();
- private final BeanStore requestBeanStore = new ConcurrentHashMapBeanStore();
-
- public MockLifecycle()
- {
- this(new MockWebBeanDiscovery());
- }
-
- public MockLifecycle(MockWebBeanDiscovery mockWebBeanDiscovery)
- {
- this.webBeanDiscovery = mockWebBeanDiscovery;
- if (webBeanDiscovery == null)
- {
- throw new IllegalStateException("No WebBeanDiscovery is available");
- }
- bootstrap = new WebBeansBootstrap();
- bootstrap.getServices().add(NamingContext.class, new MockNamingContext(null));
- bootstrap.getServices().add(EjbServices.class, MOCK_EJB_RESOLVER);
- bootstrap.getServices().add(ResourceLoader.class, MOCK_RESOURCE_LOADER);
- bootstrap.getServices().add(WebBeanDiscovery.class, webBeanDiscovery);
- bootstrap.setApplicationContext(applicationBeanStore);
- bootstrap.getServices().add(TransactionServices.class, MOCK_TRANSACTION_SERVICES);
- bootstrap.getServices().add(EjbDiscovery.class, new MockEjbDiscovery(webBeanDiscovery));
- bootstrap.initialize();
- }
-
- public MockWebBeanDiscovery getWebBeanDiscovery()
- {
- return webBeanDiscovery;
- }
-
- public WebBeansBootstrap getBootstrap()
- {
- return bootstrap;
- }
-
- public void beginApplication()
- {
- bootstrap.boot();
- }
-
- public void endApplication()
- {
-
- }
-
- public void resetContexts()
- {
-
- }
-
- public void beginRequest()
- {
- super.beginRequest("Mock", requestBeanStore);
- }
-
- public void endRequest()
- {
- super.endRequest("Mock", requestBeanStore);
- }
-
- public void beginSession()
- {
- super.restoreSession("Mock", sessionBeanStore);
- }
-
- public void endSession()
- {
- // TODO Conversation handling breaks this :-(
- //super.endSession("Mock", sessionBeanStore);
- }
-
-}
Copied: ri/trunk/impl/src/main/java/org/jboss/webbeans/mock/MockServletLifecycle.java (from rev 1999, ri/trunk/impl/src/main/java/org/jboss/webbeans/mock/MockLifecycle.java)
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/mock/MockServletLifecycle.java (rev 0)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/mock/MockServletLifecycle.java 2009-03-15 01:47:28 UTC (rev 2000)
@@ -0,0 +1,87 @@
+package org.jboss.webbeans.mock;
+
+import org.jboss.webbeans.bootstrap.WebBeansBootstrap;
+import org.jboss.webbeans.bootstrap.api.Environments;
+import org.jboss.webbeans.bootstrap.spi.WebBeanDiscovery;
+import org.jboss.webbeans.context.api.BeanStore;
+import org.jboss.webbeans.context.api.helpers.ConcurrentHashMapBeanStore;
+import org.jboss.webbeans.resources.spi.NamingContext;
+import org.jboss.webbeans.resources.spi.ResourceLoader;
+import org.jboss.webbeans.servlet.AbstractLifecycle;
+
+public class MockServletLifecycle extends AbstractLifecycle
+{
+ private static final ResourceLoader MOCK_RESOURCE_LOADER = new MockResourceLoader();
+
+ private final WebBeansBootstrap bootstrap;
+ private final MockWebBeanDiscovery webBeanDiscovery;
+ private final BeanStore applicationBeanStore = new ConcurrentHashMapBeanStore();
+ private final BeanStore sessionBeanStore = new ConcurrentHashMapBeanStore();
+ private final BeanStore requestBeanStore = new ConcurrentHashMapBeanStore();
+
+ public MockServletLifecycle()
+ {
+ this.webBeanDiscovery = new MockWebBeanDiscovery();
+ if (webBeanDiscovery == null)
+ {
+ throw new IllegalStateException("No WebBeanDiscovery is available");
+ }
+ bootstrap = new WebBeansBootstrap();
+ bootstrap.setEnvironment(Environments.SERVLET);
+ bootstrap.getServices().add(NamingContext.class, new MockNamingContext(null));
+ bootstrap.getServices().add(ResourceLoader.class, MOCK_RESOURCE_LOADER);
+ bootstrap.getServices().add(WebBeanDiscovery.class, webBeanDiscovery);
+ bootstrap.setApplicationContext(applicationBeanStore);
+ }
+
+ public void initialize()
+ {
+ bootstrap.initialize();
+ }
+
+ public MockWebBeanDiscovery getWebBeanDiscovery()
+ {
+ return webBeanDiscovery;
+ }
+
+ public WebBeansBootstrap getBootstrap()
+ {
+ return bootstrap;
+ }
+
+ public void beginApplication()
+ {
+ bootstrap.boot();
+ }
+
+ public void endApplication()
+ {
+
+ }
+
+ public void resetContexts()
+ {
+
+ }
+
+ public void beginRequest()
+ {
+ super.beginRequest("Mock", requestBeanStore);
+ }
+
+ public void endRequest()
+ {
+ super.endRequest("Mock", requestBeanStore);
+ }
+
+ public void beginSession()
+ {
+ super.restoreSession("Mock", sessionBeanStore);
+ }
+
+ public void endSession()
+ {
+ // TODO Conversation handling breaks this :-(
+ //super.endSession("Mock", sessionBeanStore);
+ }
+}
Property changes on: ri/trunk/impl/src/main/java/org/jboss/webbeans/mock/MockServletLifecycle.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/StandaloneContainersImpl.java
===================================================================
--- ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/StandaloneContainersImpl.java 2009-03-15 00:12:08 UTC (rev 1999)
+++ ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/StandaloneContainersImpl.java 2009-03-15 01:47:28 UTC (rev 2000)
@@ -5,19 +5,35 @@
import org.jboss.testharness.api.DeploymentException;
import org.jboss.testharness.spi.StandaloneContainers;
import org.jboss.webbeans.CurrentManager;
-import org.jboss.webbeans.mock.MockLifecycle;
+import org.jboss.webbeans.mock.MockEELifecycle;
+import org.jboss.webbeans.mock.MockServletLifecycle;
import org.jboss.webbeans.mock.MockWebBeanDiscovery;
public class StandaloneContainersImpl implements StandaloneContainers
{
- private MockLifecycle lifecycle;
+ // TODO this is a hack ;-)
+ public static Class<? extends MockServletLifecycle> lifecycleClass = MockEELifecycle.class;
+ private MockServletLifecycle lifecycle;
+
public void deploy(Iterable<Class<?>> classes, Iterable<URL> beansXml) throws DeploymentException
{
- this.lifecycle = new MockLifecycle();
try
{
+ this.lifecycle = lifecycleClass.newInstance();
+ }
+ catch (InstantiationException e1)
+ {
+ throw new DeploymentException("Error instantiating lifeycle", e1);
+ }
+ catch (IllegalAccessException e1)
+ {
+ throw new DeploymentException("Error instantiating lifeycle", e1);
+ }
+ lifecycle.initialize();
+ try
+ {
MockWebBeanDiscovery discovery = lifecycle.getWebBeanDiscovery();
discovery.setWebBeanClasses(classes);
if (beansXml != null)
Modified: ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/DiscoverFailsBootstrapTest.java
===================================================================
--- ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/DiscoverFailsBootstrapTest.java 2009-03-15 00:12:08 UTC (rev 1999)
+++ ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/DiscoverFailsBootstrapTest.java 2009-03-15 01:47:28 UTC (rev 2000)
@@ -1,6 +1,7 @@
package org.jboss.webbeans.test.unit.bootstrap;
-import org.jboss.webbeans.mock.MockLifecycle;
+import org.jboss.webbeans.bootstrap.spi.WebBeanDiscovery;
+import org.jboss.webbeans.mock.MockEELifecycle;
import org.testng.annotations.Test;
public class DiscoverFailsBootstrapTest
@@ -9,7 +10,9 @@
@Test(groups="bootstrap", expectedExceptions=IllegalStateException.class)
public void testDiscoverFails()
{
- MockLifecycle lifecycle = new MockLifecycle(null);
+ MockEELifecycle lifecycle = new MockEELifecycle();
+ lifecycle.getBootstrap().getServices().add(WebBeanDiscovery.class, null);
+ lifecycle.initialize();
lifecycle.beginApplication();
}
Added: ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/Animal.java
===================================================================
--- ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/Animal.java (rev 0)
+++ ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/Animal.java 2009-03-15 01:47:28 UTC (rev 2000)
@@ -0,0 +1,6 @@
+package org.jboss.webbeans.test.unit.bootstrap.environments;
+
+interface Animal
+{
+
+}
Property changes on: ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/Animal.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/DeadlyAnimal.java
===================================================================
--- ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/DeadlyAnimal.java (rev 0)
+++ ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/DeadlyAnimal.java 2009-03-15 01:47:28 UTC (rev 2000)
@@ -0,0 +1,6 @@
+package org.jboss.webbeans.test.unit.bootstrap.environments;
+
+interface DeadlyAnimal
+{
+
+}
Property changes on: ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/DeadlyAnimal.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/DeadlySpider.java
===================================================================
--- ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/DeadlySpider.java (rev 0)
+++ ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/DeadlySpider.java 2009-03-15 01:47:28 UTC (rev 2000)
@@ -0,0 +1,6 @@
+package org.jboss.webbeans.test.unit.bootstrap.environments;
+
+interface DeadlySpider extends DeadlyAnimal
+{
+
+}
Property changes on: ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/DeadlySpider.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/DefangedTarantula.java
===================================================================
--- ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/DefangedTarantula.java (rev 0)
+++ ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/DefangedTarantula.java 2009-03-15 01:47:28 UTC (rev 2000)
@@ -0,0 +1,6 @@
+package org.jboss.webbeans.test.unit.bootstrap.environments;
+
+class DefangedTarantula extends Tarantula
+{
+
+}
Property changes on: ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/DefangedTarantula.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/Hound.java
===================================================================
--- ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/Hound.java (rev 0)
+++ ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/Hound.java 2009-03-15 01:47:28 UTC (rev 2000)
@@ -0,0 +1,21 @@
+package org.jboss.webbeans.test.unit.bootstrap.environments;
+
+import javax.annotation.Named;
+import javax.ejb.Remove;
+import javax.ejb.Stateful;
+
+@Stateful
+@Tame
+@Named("Pongo")
+class Hound implements HoundLocal
+{
+ @Remove
+ public void bye() {
+ }
+
+ public void ping()
+ {
+
+ }
+
+}
Property changes on: ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/Hound.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/HoundLocal.java
===================================================================
--- ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/HoundLocal.java (rev 0)
+++ ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/HoundLocal.java 2009-03-15 01:47:28 UTC (rev 2000)
@@ -0,0 +1,11 @@
+package org.jboss.webbeans.test.unit.bootstrap.environments;
+
+import javax.ejb.Local;
+
+@Local
+public interface HoundLocal
+{
+
+ public void ping();
+
+}
Property changes on: ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/HoundLocal.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/Salmon.java
===================================================================
--- ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/Salmon.java (rev 0)
+++ ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/Salmon.java 2009-03-15 01:47:28 UTC (rev 2000)
@@ -0,0 +1,11 @@
+package org.jboss.webbeans.test.unit.bootstrap.environments;
+
+import javax.annotation.Named;
+import javax.inject.Production;
+
+@Production
+@Named
+class Salmon implements ScottishFish
+{
+
+}
Property changes on: ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/Salmon.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/ScottishFish.java
===================================================================
--- ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/ScottishFish.java (rev 0)
+++ ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/ScottishFish.java 2009-03-15 01:47:28 UTC (rev 2000)
@@ -0,0 +1,6 @@
+package org.jboss.webbeans.test.unit.bootstrap.environments;
+
+interface ScottishFish extends Animal
+{
+
+}
Property changes on: ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/ScottishFish.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/SeaBass.java
===================================================================
--- ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/SeaBass.java (rev 0)
+++ ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/SeaBass.java 2009-03-15 01:47:28 UTC (rev 2000)
@@ -0,0 +1,11 @@
+package org.jboss.webbeans.test.unit.bootstrap.environments;
+
+import javax.context.RequestScoped;
+import javax.inject.Production;
+
+@Production
+@RequestScoped
+class SeaBass implements Animal
+{
+
+}
Property changes on: ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/SeaBass.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/ServletEnvironmentTest.java
===================================================================
--- ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/ServletEnvironmentTest.java (rev 0)
+++ ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/ServletEnvironmentTest.java 2009-03-15 01:47:28 UTC (rev 2000)
@@ -0,0 +1,104 @@
+package org.jboss.webbeans.test.unit.bootstrap.environments;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.inject.AnnotationLiteral;
+import javax.inject.manager.Bean;
+
+import org.jboss.testharness.impl.packaging.Artifact;
+import org.jboss.webbeans.bean.ProducerMethodBean;
+import org.jboss.webbeans.bean.RIBean;
+import org.jboss.webbeans.bean.SimpleBean;
+import org.jboss.webbeans.mock.MockEELifecycle;
+import org.jboss.webbeans.mock.MockServletLifecycle;
+import org.jboss.webbeans.test.unit.AbstractWebBeansTest;
+import org.jboss.webbeans.test.unit.StandaloneContainersImpl;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+@Artifact
+public class ServletEnvironmentTest extends AbstractWebBeansTest
+{
+
+ @BeforeClass
+ @Override
+ public void beforeClass() throws Throwable
+ {
+ StandaloneContainersImpl.lifecycleClass = MockServletLifecycle.class;
+ super.beforeClass();
+ }
+
+ @Override
+ @AfterClass(alwaysRun=true)
+ public void afterClass() throws Exception
+ {
+ StandaloneContainersImpl.lifecycleClass = MockEELifecycle.class;
+ super.afterClass();
+ }
+
+ @Test(groups="incontainer-broken")
+ public void testSimpleBeans()
+ {
+ List<Bean<?>> beans = manager.getBeans();
+ Map<Class<?>, Bean<?>> classes = new HashMap<Class<?>, Bean<?>>();
+ for (Bean<?> bean : beans)
+ {
+ if (bean instanceof RIBean)
+ {
+ classes.put(((RIBean<?>) bean).getType(), bean);
+ }
+ }
+ assert classes.containsKey(Tuna.class);
+ assert classes.containsKey(Salmon.class);
+ assert classes.containsKey(SeaBass.class);
+ assert classes.containsKey(Sole.class);
+
+ assert classes.get(Tuna.class) instanceof SimpleBean;
+ assert classes.get(Salmon.class) instanceof SimpleBean;
+ assert classes.get(SeaBass.class) instanceof SimpleBean;
+ assert classes.get(Sole.class) instanceof SimpleBean;
+ manager.getInstanceByType(Sole.class, new AnnotationLiteral<Whitefish>() {}).ping();
+ }
+
+ @Test(groups="incontainer-broken")
+ public void testProducerMethodBean()
+ {
+ //deployBeans(TarantulaProducer.class);
+ List<Bean<?>> beans = manager.getBeans();
+ Map<Class<?>, Bean<?>> classes = new HashMap<Class<?>, Bean<?>>();
+ for (Bean<?> bean : beans)
+ {
+ if (bean instanceof RIBean)
+ {
+ classes.put(((RIBean<?>) bean).getType(), bean);
+ }
+ }
+ assert classes.containsKey(TarantulaProducer.class);
+ assert classes.containsKey(Tarantula.class);
+
+ assert classes.get(TarantulaProducer.class) instanceof SimpleBean;
+ assert classes.get(Tarantula.class) instanceof ProducerMethodBean;
+ manager.getInstanceByType(Tarantula.class, new AnnotationLiteral<Tame>() {}).ping();
+ }
+
+ @Test(groups="incontainer-broken")
+ public void testSingleEnterpriseBean()
+ {
+ List<Bean<?>> beans = manager.getBeans();
+ Map<Class<?>, Bean<?>> classes = new HashMap<Class<?>, Bean<?>>();
+ for (Bean<?> bean : beans)
+ {
+ if (bean instanceof RIBean)
+ {
+ classes.put(((RIBean<?>) bean).getType(), bean);
+ }
+ }
+ assert classes.containsKey(Hound.class);
+ assert classes.get(Hound.class) instanceof SimpleBean;
+ manager.getInstanceByType(HoundLocal.class, new AnnotationLiteral<Tame>() {}).ping();
+ }
+
+}
Property changes on: ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/ServletEnvironmentTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/Sole.java
===================================================================
--- ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/Sole.java (rev 0)
+++ ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/Sole.java 2009-03-15 01:47:28 UTC (rev 2000)
@@ -0,0 +1,20 @@
+package org.jboss.webbeans.test.unit.bootstrap.environments;
+
+import javax.annotation.Named;
+import javax.ejb.EJB;
+import javax.inject.Production;
+
+@Production
+@Whitefish
+@Named("whitefish")
+class Sole implements ScottishFish
+{
+
+ @EJB HoundLocal hound;
+
+ public void ping()
+ {
+
+ }
+
+}
Property changes on: ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/Sole.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/Spider.java
===================================================================
--- ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/Spider.java (rev 0)
+++ ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/Spider.java 2009-03-15 01:47:28 UTC (rev 2000)
@@ -0,0 +1,11 @@
+package org.jboss.webbeans.test.unit.bootstrap.environments;
+
+class Spider implements Animal
+{
+
+ public final void layEggs()
+ {
+
+ }
+
+}
Property changes on: ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/Spider.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/Tame.java
===================================================================
--- ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/Tame.java (rev 0)
+++ ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/Tame.java 2009-03-15 01:47:28 UTC (rev 2000)
@@ -0,0 +1,22 @@
+package org.jboss.webbeans.test.unit.bootstrap.environments;
+
+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 Tame
+{
+
+}
Property changes on: ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/Tame.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/Tarantula.java
===================================================================
--- ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/Tarantula.java (rev 0)
+++ ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/Tarantula.java 2009-03-15 01:47:28 UTC (rev 2000)
@@ -0,0 +1,11 @@
+package org.jboss.webbeans.test.unit.bootstrap.environments;
+
+class Tarantula extends Spider implements DeadlySpider
+{
+
+ public void ping()
+ {
+
+ }
+
+}
Property changes on: ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/Tarantula.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/TarantulaProducer.java
===================================================================
--- ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/TarantulaProducer.java (rev 0)
+++ ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/TarantulaProducer.java 2009-03-15 01:47:28 UTC (rev 2000)
@@ -0,0 +1,13 @@
+package org.jboss.webbeans.test.unit.bootstrap.environments;
+
+import javax.inject.Produces;
+
+public class TarantulaProducer
+{
+
+ @Produces @Tame public Tarantula produceTameTarantula()
+ {
+ return new DefangedTarantula();
+ }
+
+}
Property changes on: ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/TarantulaProducer.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/Tuna.java
===================================================================
--- ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/Tuna.java (rev 0)
+++ ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/Tuna.java 2009-03-15 01:47:28 UTC (rev 2000)
@@ -0,0 +1,14 @@
+package org.jboss.webbeans.test.unit.bootstrap.environments;
+
+import javax.context.RequestScoped;
+
+@RequestScoped
+class Tuna
+{
+
+ public String getName()
+ {
+ return "Ophir";
+ }
+
+}
Property changes on: ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/Tuna.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/Whitefish.java
===================================================================
--- ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/Whitefish.java (rev 0)
+++ ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/Whitefish.java 2009-03-15 01:47:28 UTC (rev 2000)
@@ -0,0 +1,22 @@
+package org.jboss.webbeans.test.unit.bootstrap.environments;
+
+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
+public @interface Whitefish
+{
+
+}
Property changes on: ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/bootstrap/environments/Whitefish.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: ri/trunk/porting-package/src/main/java/org/jboss/webbeans/tck/StandaloneContainersImpl.java
===================================================================
--- ri/trunk/porting-package/src/main/java/org/jboss/webbeans/tck/StandaloneContainersImpl.java 2009-03-15 00:12:08 UTC (rev 1999)
+++ ri/trunk/porting-package/src/main/java/org/jboss/webbeans/tck/StandaloneContainersImpl.java 2009-03-15 01:47:28 UTC (rev 2000)
@@ -8,13 +8,13 @@
import org.jboss.testharness.spi.StandaloneContainers;
import org.jboss.webbeans.CurrentManager;
import org.jboss.webbeans.ManagerImpl;
-import org.jboss.webbeans.mock.MockLifecycle;
+import org.jboss.webbeans.mock.MockEELifecycle;
import org.jboss.webbeans.mock.MockWebBeanDiscovery;
public class StandaloneContainersImpl implements StandaloneContainers
{
- private MockLifecycle lifecycle;
+ private MockEELifecycle lifecycle;
public void deploy(List<Class<? extends Annotation>> enabledDeploymentTypes, Iterable<Class<?>> classes) throws DeploymentException
{
@@ -23,7 +23,8 @@
public void deploy(List<Class<? extends Annotation>> enabledDeploymentTypes, Iterable<Class<?>> classes, Iterable<URL> beansXml) throws DeploymentException
{
- this.lifecycle = new MockLifecycle();
+ this.lifecycle = new MockEELifecycle();
+ lifecycle.initialize();
try
{
ManagerImpl manager = lifecycle.getBootstrap().getManager();
Modified: ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/Bootstrap.java
===================================================================
--- ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/Bootstrap.java 2009-03-15 00:12:08 UTC (rev 1999)
+++ ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/Bootstrap.java 2009-03-15 01:47:28 UTC (rev 2000)
@@ -16,7 +16,6 @@
*/
package org.jboss.webbeans.bootstrap.api;
-import org.jboss.webbeans.bootstrap.spi.EjbDiscovery;
import org.jboss.webbeans.bootstrap.spi.WebBeanDiscovery;
import org.jboss.webbeans.context.api.BeanStore;
import org.jboss.webbeans.ejb.spi.EjbServices;
@@ -43,14 +42,6 @@
public void setWebBeanDiscovery(WebBeanDiscovery webBeanDiscovery);
/**
- * Set the EjbDiscovery to use
- *
- * @param ejbDiscovery
- */
- @Deprecated
- public void setEjbDiscovery(EjbDiscovery ejbDiscovery);
-
- /**
* Set the EjbServices to use
*
* @param ejbServices
@@ -137,4 +128,11 @@
*/
public void shutdown();
+ /**
+ * Get the services available to this bootstrap
+ *
+ * @return the services availabel
+ */
+ public ServiceRegistry getServices();
+
}
Modified: ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/Environments.java
===================================================================
--- ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/Environments.java 2009-03-15 00:12:08 UTC (rev 1999)
+++ ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/Environments.java 2009-03-15 01:47:28 UTC (rev 2000)
@@ -20,7 +20,6 @@
import java.util.HashSet;
import java.util.Set;
-import org.jboss.webbeans.bootstrap.spi.EjbDiscovery;
import org.jboss.webbeans.bootstrap.spi.WebBeanDiscovery;
import org.jboss.webbeans.ejb.spi.EjbServices;
import org.jboss.webbeans.resources.spi.NamingContext;
@@ -39,12 +38,12 @@
/**
* Java EE5 or Java EE6
*/
- EE(WebBeanDiscovery.class, EjbDiscovery.class, EjbServices.class, TransactionServices.class, NamingContext.class, ResourceLoader.class),
+ EE(WebBeanDiscovery.class, EjbServices.class, TransactionServices.class, NamingContext.class, ResourceLoader.class),
/**
* Java EE6 Web Profile
*/
- EE_WEB_PROFILE(WebBeanDiscovery.class, EjbDiscovery.class, EjbServices.class, TransactionServices.class, NamingContext.class, ResourceLoader.class),
+ EE_WEB_PROFILE(WebBeanDiscovery.class, EjbServices.class, TransactionServices.class, NamingContext.class, ResourceLoader.class),
/**
* Servlet container such as Tomcat
Modified: ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/ServiceRegistry.java
===================================================================
--- ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/ServiceRegistry.java 2009-03-15 00:12:08 UTC (rev 1999)
+++ ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/ServiceRegistry.java 2009-03-15 01:47:28 UTC (rev 2000)
@@ -1,3 +1,19 @@
+/*
+ * 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.bootstrap.api;
import java.util.HashMap;
@@ -3,5 +19,10 @@
import java.util.Map;
-
+/**
+ * A registry for services
+ *
+ * @author Pete Muir
+ *
+ */
public class ServiceRegistry
{
@@ -25,7 +46,14 @@
*/
public <S extends Service> void add(java.lang.Class<S> type, S service)
{
- services.put(type, service);
+ if (service == null)
+ {
+ services.remove(type);
+ }
+ else
+ {
+ services.put(type, service);
+ }
}
/**
Modified: ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/AbstractBootstrap.java
===================================================================
--- ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/AbstractBootstrap.java 2009-03-15 00:12:08 UTC (rev 1999)
+++ ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/AbstractBootstrap.java 2009-03-15 01:47:28 UTC (rev 2000)
@@ -22,7 +22,6 @@
import org.jboss.webbeans.bootstrap.api.Environment;
import org.jboss.webbeans.bootstrap.api.Service;
import org.jboss.webbeans.bootstrap.api.ServiceRegistry;
-import org.jboss.webbeans.bootstrap.spi.EjbDiscovery;
import org.jboss.webbeans.bootstrap.spi.WebBeanDiscovery;
import org.jboss.webbeans.context.api.BeanStore;
import org.jboss.webbeans.ejb.spi.EjbServices;
@@ -51,12 +50,6 @@
}
@Deprecated
- public void setEjbDiscovery(EjbDiscovery ejbDiscovery)
- {
- getServices().add(EjbDiscovery.class, ejbDiscovery);
- }
-
- @Deprecated
public void setEjbServices(EjbServices ejbServices)
{
getServices().add(EjbServices.class, ejbServices);
@@ -86,6 +79,7 @@
getServices().add(TransactionServices.class, transactionServices);
}
+ @Deprecated
public WebBeanDiscovery getWebBeanDiscovery()
{
return getServices().get(WebBeanDiscovery.class);
@@ -108,12 +102,6 @@
{
return getServices().get(EjbServices.class);
}
-
- @Deprecated
- public EjbDiscovery getEjbDiscovery()
- {
- return getServices().get(EjbDiscovery.class);
- }
@Deprecated
public TransactionServices getTransactionServices()
Modified: ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/ForwardingBootstrap.java
===================================================================
--- ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/ForwardingBootstrap.java 2009-03-15 00:12:08 UTC (rev 1999)
+++ ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/ForwardingBootstrap.java 2009-03-15 01:47:28 UTC (rev 2000)
@@ -17,7 +17,6 @@
package org.jboss.webbeans.bootstrap.api.helpers;
import org.jboss.webbeans.bootstrap.api.Bootstrap;
-import org.jboss.webbeans.bootstrap.spi.EjbDiscovery;
import org.jboss.webbeans.bootstrap.spi.WebBeanDiscovery;
import org.jboss.webbeans.context.api.BeanStore;
import org.jboss.webbeans.ejb.spi.EjbServices;
@@ -56,12 +55,6 @@
}
@Deprecated
- public void setEjbDiscovery(EjbDiscovery ejbDiscovery)
- {
- delegate().setEjbDiscovery(ejbDiscovery);
- }
-
- @Deprecated
public void setEjbServices(EjbServices ejbServices)
{
delegate().setEjbServices(ejbServices);
Deleted: ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/spi/EjbDiscovery.java
===================================================================
--- ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/spi/EjbDiscovery.java 2009-03-15 00:12:08 UTC (rev 1999)
+++ ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/spi/EjbDiscovery.java 2009-03-15 01:47:28 UTC (rev 2000)
@@ -1,43 +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.bootstrap.spi;
-
-import org.jboss.webbeans.bootstrap.api.Service;
-import org.jboss.webbeans.ejb.spi.EjbDescriptor;
-
-
-
-/**
- * A container should implement this interface to allow the Web Beans RI to
- * discover the EJBs the application contains
- *
- * @author Pete Muir
- *
- */
-public interface EjbDiscovery extends Service
-{
- public static final String PROPERTY_NAME = EjbDiscovery.class.getName();
-
- /**
- * Gets a descriptor for each EJB in the application
- *
- * @return The bean class to descriptor map
- */
- public Iterable<EjbDescriptor<?>> discoverEjbs();
-
-}
Deleted: ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/spi/helpers/ForwardingEjbDiscovery.java
===================================================================
--- ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/spi/helpers/ForwardingEjbDiscovery.java 2009-03-15 00:12:08 UTC (rev 1999)
+++ ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/spi/helpers/ForwardingEjbDiscovery.java 2009-03-15 01:47:28 UTC (rev 2000)
@@ -1,44 +0,0 @@
-package org.jboss.webbeans.bootstrap.spi.helpers;
-
-import org.jboss.webbeans.bootstrap.spi.EjbDiscovery;
-import org.jboss.webbeans.ejb.spi.EjbDescriptor;
-
-/**
- * An implementation of {@link EjbDiscovery} which forwards all its method calls
- * to another {@link EjbDiscovery}}. Subclasses should override one or more
- * methods to modify the behavior of the backing {@link EjbDiscovery} as desired
- * per the <a
- * href="http://en.wikipedia.org/wiki/Decorator_pattern">decorator pattern</a>.
- *
- * @author Pete Muir
- *
- */
-public abstract class ForwardingEjbDiscovery implements EjbDiscovery
-{
-
- protected abstract EjbDiscovery delegate();
-
- public Iterable<EjbDescriptor<?>> discoverEjbs()
- {
- return delegate().discoverEjbs();
- }
-
- @Override
- public boolean equals(Object obj)
- {
- return delegate().equals(obj);
- }
-
- @Override
- public String toString()
- {
- return delegate().toString();
- }
-
- @Override
- public int hashCode()
- {
- return delegate().hashCode();
- }
-
-}
Modified: ri/trunk/spi/src/main/java/org/jboss/webbeans/ejb/spi/EjbServices.java
===================================================================
--- ri/trunk/spi/src/main/java/org/jboss/webbeans/ejb/spi/EjbServices.java 2009-03-15 00:12:08 UTC (rev 1999)
+++ ri/trunk/spi/src/main/java/org/jboss/webbeans/ejb/spi/EjbServices.java 2009-03-15 01:47:28 UTC (rev 2000)
@@ -97,6 +97,13 @@
public <T> EjbReference<T> resolveEJB(EjbDescriptor<T> ejbDescriptor, NamingContext namingContext);
/**
+ * Gets a descriptor for each EJB in the application
+ *
+ * @return The bean class to descriptor map
+ */
+ public Iterable<EjbDescriptor<?>> discoverEjbs();
+
+ /**
* Get the annotation which defines an @EJB injection point
*
* @return the annotation which defines an @EJB injection point
Modified: ri/trunk/spi/src/main/java/org/jboss/webbeans/ejb/spi/helpers/ForwardingEjbServices.java
===================================================================
--- ri/trunk/spi/src/main/java/org/jboss/webbeans/ejb/spi/helpers/ForwardingEjbServices.java 2009-03-15 00:12:08 UTC (rev 1999)
+++ ri/trunk/spi/src/main/java/org/jboss/webbeans/ejb/spi/helpers/ForwardingEjbServices.java 2009-03-15 01:47:28 UTC (rev 2000)
@@ -58,11 +58,11 @@
{
return delegate().resolveResource(injectionPoint, namingContext);
}
-//
-// public void removeEjb(Collection<Object> instance)
-// {
-// delegate().removeEjb(instance);
-// }
+
+ public Iterable<EjbDescriptor<?>> discoverEjbs()
+ {
+ return delegate().discoverEjbs();
+ }
@Override
public boolean equals(Object obj)
Added: ri/trunk/spi/src/test/java/org/jboss/webbeans/bootstrap/api/test/BootstrapTest.java
===================================================================
--- ri/trunk/spi/src/test/java/org/jboss/webbeans/bootstrap/api/test/BootstrapTest.java (rev 0)
+++ ri/trunk/spi/src/test/java/org/jboss/webbeans/bootstrap/api/test/BootstrapTest.java 2009-03-15 01:47:28 UTC (rev 2000)
@@ -0,0 +1,105 @@
+package org.jboss.webbeans.bootstrap.api.test;
+
+import org.jboss.webbeans.bootstrap.api.Environments;
+import org.jboss.webbeans.bootstrap.api.helpers.AbstractBootstrap;
+import org.jboss.webbeans.bootstrap.spi.WebBeanDiscovery;
+import org.jboss.webbeans.context.api.helpers.ConcurrentHashMapBeanStore;
+import org.jboss.webbeans.ejb.spi.EjbServices;
+import org.jboss.webbeans.resources.spi.NamingContext;
+import org.jboss.webbeans.resources.spi.ResourceLoader;
+import org.jboss.webbeans.transaction.spi.TransactionServices;
+import org.testng.annotations.Test;
+
+public class BootstrapTest
+{
+
+ @Test(expectedExceptions=IllegalStateException.class)
+ public void testMissingWBDiscovery()
+ {
+ AbstractBootstrap bootstrap = new MockBootstrap();
+ bootstrap.setEnvironment(Environments.SE);
+ bootstrap.getServices().add(NamingContext.class, new MockNamingContext());
+ bootstrap.getServices().add(ResourceLoader.class, new MockResourceLoader());
+ bootstrap.setApplicationContext(new ConcurrentHashMapBeanStore());
+ bootstrap.initialize();
+ }
+
+ @Test(expectedExceptions=IllegalStateException.class)
+ public void testMissingEjbServices()
+ {
+ AbstractBootstrap bootstrap = new MockBootstrap();
+ bootstrap.setEnvironment(Environments.EE);
+ bootstrap.setApplicationContext(new ConcurrentHashMapBeanStore());
+ bootstrap.getServices().add(NamingContext.class, new MockNamingContext());
+ bootstrap.getServices().add(ResourceLoader.class, new MockResourceLoader());
+ bootstrap.getServices().add(TransactionServices.class, new MockTransactionServices());
+ bootstrap.getServices().add(WebBeanDiscovery.class, new MockWebBeanDiscovery());
+ bootstrap.initialize();
+ }
+
+ @Test
+ public void testEEEnv()
+ {
+ AbstractBootstrap bootstrap = new MockBootstrap();
+ bootstrap.setEnvironment(Environments.EE);
+ bootstrap.setApplicationContext(new ConcurrentHashMapBeanStore());
+ bootstrap.getServices().add(NamingContext.class, new MockNamingContext());
+ bootstrap.getServices().add(ResourceLoader.class, new MockResourceLoader());
+ bootstrap.getServices().add(TransactionServices.class, new MockTransactionServices());
+ bootstrap.getServices().add(WebBeanDiscovery.class, new MockWebBeanDiscovery());
+ bootstrap.getServices().add(EjbServices.class, new MockEjbServices());
+ bootstrap.initialize();
+ }
+
+ @Test
+ public void testEEWebProfileEnv()
+ {
+ AbstractBootstrap bootstrap = new MockBootstrap();
+ bootstrap.setEnvironment(Environments.EE_WEB_PROFILE);
+ bootstrap.setApplicationContext(new ConcurrentHashMapBeanStore());
+ bootstrap.getServices().add(NamingContext.class, new MockNamingContext());
+ bootstrap.getServices().add(ResourceLoader.class, new MockResourceLoader());
+ bootstrap.getServices().add(TransactionServices.class, new MockTransactionServices());
+ bootstrap.getServices().add(WebBeanDiscovery.class, new MockWebBeanDiscovery());
+ bootstrap.getServices().add(EjbServices.class, new MockEjbServices());
+ bootstrap.initialize();
+ }
+
+ @Test(expectedExceptions=IllegalStateException.class)
+ public void testMissingTxServices()
+ {
+ AbstractBootstrap bootstrap = new MockBootstrap();
+ bootstrap.setEnvironment(Environments.EE);
+ bootstrap.getServices().add(NamingContext.class, new MockNamingContext());
+ bootstrap.getServices().add(ResourceLoader.class, new MockResourceLoader());
+ bootstrap.setApplicationContext(new ConcurrentHashMapBeanStore());
+ bootstrap.getServices().add(EjbServices.class, new MockEjbServices());
+ bootstrap.getServices().add(WebBeanDiscovery.class, new MockWebBeanDiscovery());
+ bootstrap.initialize();
+ }
+
+ @Test
+ public void testSEEnv()
+ {
+ AbstractBootstrap bootstrap = new MockBootstrap();
+ bootstrap.setEnvironment(Environments.SE);
+ bootstrap.setApplicationContext(new ConcurrentHashMapBeanStore());
+ bootstrap.getServices().add(NamingContext.class, new MockNamingContext());
+ bootstrap.getServices().add(ResourceLoader.class, new MockResourceLoader());
+ bootstrap.getServices().add(WebBeanDiscovery.class, new MockWebBeanDiscovery());
+ bootstrap.initialize();
+ }
+
+ @Test
+ public void testServletEnv()
+ {
+ AbstractBootstrap bootstrap = new MockBootstrap();
+ bootstrap.setEnvironment(Environments.SERVLET);
+ bootstrap.getServices().add(NamingContext.class, new MockNamingContext());
+ bootstrap.getServices().add(ResourceLoader.class, new MockResourceLoader());
+ bootstrap.setApplicationContext(new ConcurrentHashMapBeanStore());
+ bootstrap.getServices().add(WebBeanDiscovery.class, new MockWebBeanDiscovery());
+ bootstrap.initialize();
+ }
+
+}
Property changes on: ri/trunk/spi/src/test/java/org/jboss/webbeans/bootstrap/api/test/BootstrapTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/spi/src/test/java/org/jboss/webbeans/bootstrap/api/test/MockBootstrap.java
===================================================================
--- ri/trunk/spi/src/test/java/org/jboss/webbeans/bootstrap/api/test/MockBootstrap.java (rev 0)
+++ ri/trunk/spi/src/test/java/org/jboss/webbeans/bootstrap/api/test/MockBootstrap.java 2009-03-15 01:47:28 UTC (rev 2000)
@@ -0,0 +1,32 @@
+package org.jboss.webbeans.bootstrap.api.test;
+
+import org.jboss.webbeans.bootstrap.api.helpers.AbstractBootstrap;
+import org.jboss.webbeans.manager.api.WebBeansManager;
+
+public class MockBootstrap extends AbstractBootstrap
+{
+
+ public void boot()
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public WebBeansManager getManager()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public void initialize()
+ {
+ verify();
+ }
+
+ public void shutdown()
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+}
Property changes on: ri/trunk/spi/src/test/java/org/jboss/webbeans/bootstrap/api/test/MockBootstrap.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/spi/src/test/java/org/jboss/webbeans/bootstrap/api/test/MockEjbServices.java
===================================================================
--- ri/trunk/spi/src/test/java/org/jboss/webbeans/bootstrap/api/test/MockEjbServices.java (rev 0)
+++ ri/trunk/spi/src/test/java/org/jboss/webbeans/bootstrap/api/test/MockEjbServices.java 2009-03-15 01:47:28 UTC (rev 2000)
@@ -0,0 +1,63 @@
+package org.jboss.webbeans.bootstrap.api.test;
+
+import java.lang.annotation.Annotation;
+
+import javax.inject.manager.InjectionPoint;
+
+import org.jboss.webbeans.ejb.api.EjbReference;
+import org.jboss.webbeans.ejb.spi.EjbDescriptor;
+import org.jboss.webbeans.ejb.spi.EjbServices;
+import org.jboss.webbeans.resources.spi.NamingContext;
+
+public class MockEjbServices implements EjbServices
+{
+
+ public Iterable<EjbDescriptor<?>> discoverEjbs()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Class<? extends Annotation> getEJBAnnotation()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Class<? extends Annotation> getPersistenceContextAnnotation()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Class<? extends Annotation> getResourceAnnotation()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public <T> EjbReference<T> resolveEJB(EjbDescriptor<T> ejbDescriptor, NamingContext namingContext)
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Object resolveEjb(InjectionPoint injectionPoint, NamingContext namingContext)
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Object resolvePersistenceContext(InjectionPoint injectionPoint, NamingContext namingContext)
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Object resolveResource(InjectionPoint injectionPoint, NamingContext namingContext)
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
Property changes on: ri/trunk/spi/src/test/java/org/jboss/webbeans/bootstrap/api/test/MockEjbServices.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/spi/src/test/java/org/jboss/webbeans/bootstrap/api/test/MockNamingContext.java
===================================================================
--- ri/trunk/spi/src/test/java/org/jboss/webbeans/bootstrap/api/test/MockNamingContext.java (rev 0)
+++ ri/trunk/spi/src/test/java/org/jboss/webbeans/bootstrap/api/test/MockNamingContext.java 2009-03-15 01:47:28 UTC (rev 2000)
@@ -0,0 +1,20 @@
+package org.jboss.webbeans.bootstrap.api.test;
+
+import org.jboss.webbeans.resources.spi.NamingContext;
+
+public class MockNamingContext implements NamingContext
+{
+
+ public void bind(String name, Object value)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public <T> T lookup(String name, Class<? extends T> expectedType)
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
Property changes on: ri/trunk/spi/src/test/java/org/jboss/webbeans/bootstrap/api/test/MockNamingContext.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/spi/src/test/java/org/jboss/webbeans/bootstrap/api/test/MockResourceLoader.java
===================================================================
--- ri/trunk/spi/src/test/java/org/jboss/webbeans/bootstrap/api/test/MockResourceLoader.java (rev 0)
+++ ri/trunk/spi/src/test/java/org/jboss/webbeans/bootstrap/api/test/MockResourceLoader.java 2009-03-15 01:47:28 UTC (rev 2000)
@@ -0,0 +1,28 @@
+package org.jboss.webbeans.bootstrap.api.test;
+
+import java.net.URL;
+
+import org.jboss.webbeans.resources.spi.ResourceLoader;
+
+public class MockResourceLoader implements ResourceLoader
+{
+
+ public Class<?> classForName(String name)
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public URL getResource(String name)
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Iterable<URL> getResources(String name)
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
Property changes on: ri/trunk/spi/src/test/java/org/jboss/webbeans/bootstrap/api/test/MockResourceLoader.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/spi/src/test/java/org/jboss/webbeans/bootstrap/api/test/MockTransactionServices.java
===================================================================
--- ri/trunk/spi/src/test/java/org/jboss/webbeans/bootstrap/api/test/MockTransactionServices.java (rev 0)
+++ ri/trunk/spi/src/test/java/org/jboss/webbeans/bootstrap/api/test/MockTransactionServices.java 2009-03-15 01:47:28 UTC (rev 2000)
@@ -0,0 +1,22 @@
+package org.jboss.webbeans.bootstrap.api.test;
+
+import javax.transaction.Synchronization;
+
+import org.jboss.webbeans.transaction.spi.TransactionServices;
+
+public class MockTransactionServices implements TransactionServices
+{
+
+ public boolean isTransactionActive()
+ {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public void registerSynchronization(Synchronization synchronizedObserver)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+}
Property changes on: ri/trunk/spi/src/test/java/org/jboss/webbeans/bootstrap/api/test/MockTransactionServices.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/spi/src/test/java/org/jboss/webbeans/bootstrap/api/test/MockWebBeanDiscovery.java
===================================================================
--- ri/trunk/spi/src/test/java/org/jboss/webbeans/bootstrap/api/test/MockWebBeanDiscovery.java (rev 0)
+++ ri/trunk/spi/src/test/java/org/jboss/webbeans/bootstrap/api/test/MockWebBeanDiscovery.java 2009-03-15 01:47:28 UTC (rev 2000)
@@ -0,0 +1,22 @@
+package org.jboss.webbeans.bootstrap.api.test;
+
+import java.net.URL;
+
+import org.jboss.webbeans.bootstrap.spi.WebBeanDiscovery;
+
+public class MockWebBeanDiscovery implements WebBeanDiscovery
+{
+
+ public Iterable<Class<?>> discoverWebBeanClasses()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Iterable<URL> discoverWebBeansXml()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
Property changes on: ri/trunk/spi/src/test/java/org/jboss/webbeans/bootstrap/api/test/MockWebBeanDiscovery.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
15 years, 10 months
[webbeans-commits] Webbeans SVN: r1999 - in ri/trunk: impl/src/main/java/org/jboss/webbeans/bean and 10 other directories.
by webbeans-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2009-03-14 20:12:08 -0400 (Sat, 14 Mar 2009)
New Revision: 1999
Added:
ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/Environment.java
ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/Environments.java
ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/Service.java
ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/ServiceRegistry.java
Removed:
ri/trunk/impl/src/main/java/org/jboss/webbeans/transaction/
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/ManagerImpl.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/EnterpriseBean.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/SimpleBean.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployer.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/event/TransactionalObserverImpl.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/mock/MockEjbDiscovery.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/mock/MockLifecycle.java
ri/trunk/porting-package/src/main/java/org/jboss/webbeans/tck/BeansImpl.java
ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/Bootstrap.java
ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/AbstractBootstrap.java
ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/ForwardingBootstrap.java
ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/spi/EjbDiscovery.java
ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/spi/WebBeanDiscovery.java
ri/trunk/spi/src/main/java/org/jboss/webbeans/ejb/spi/EjbServices.java
ri/trunk/spi/src/main/java/org/jboss/webbeans/resources/spi/NamingContext.java
ri/trunk/spi/src/main/java/org/jboss/webbeans/resources/spi/ResourceLoader.java
ri/trunk/spi/src/main/java/org/jboss/webbeans/transaction/spi/TransactionServices.java
Log:
generic services and environments for bootstrap (WBRI-175)
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/ManagerImpl.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/ManagerImpl.java 2009-03-14 22:57:40 UTC (rev 1998)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/ManagerImpl.java 2009-03-15 00:12:08 UTC (rev 1999)
@@ -63,10 +63,10 @@
import org.jboss.webbeans.bean.NewEnterpriseBean;
import org.jboss.webbeans.bean.RIBean;
import org.jboss.webbeans.bean.proxy.ClientProxyProvider;
+import org.jboss.webbeans.bootstrap.api.ServiceRegistry;
import org.jboss.webbeans.context.ContextMap;
import org.jboss.webbeans.context.CreationalContextImpl;
import org.jboss.webbeans.ejb.EjbDescriptorCache;
-import org.jboss.webbeans.ejb.spi.EjbServices;
import org.jboss.webbeans.event.EventManager;
import org.jboss.webbeans.event.ObserverImpl;
import org.jboss.webbeans.injection.ResolvableAnnotatedClass;
@@ -79,9 +79,6 @@
import org.jboss.webbeans.literal.NewLiteral;
import org.jboss.webbeans.manager.api.WebBeansManager;
import org.jboss.webbeans.metadata.MetaDataCache;
-import org.jboss.webbeans.resources.spi.NamingContext;
-import org.jboss.webbeans.resources.spi.ResourceLoader;
-import org.jboss.webbeans.transaction.spi.TransactionServices;
import org.jboss.webbeans.util.Beans;
import org.jboss.webbeans.util.Reflections;
@@ -132,18 +129,10 @@
private transient final Set<Interceptor> interceptors;
// The EJB resolver provided by the container
- private transient final EjbServices ejbServices;
+ private transient final ServiceRegistry serviceRegistry;
private transient final EjbDescriptorCache ejbDescriptorCache;
-
- private transient final ResourceLoader resourceLoader;
- // The transaction management related services provided by the container
- private transient final TransactionServices transactionServices;
-
- // The Naming (JNDI) access
- private transient final NamingContext namingContext;
-
private final transient Map<Bean<?>, Bean<?>> specializedBeans;
private final transient ServletInjector servletInjector;
@@ -153,12 +142,9 @@
*
* @param ejbServices the ejbResolver to use
*/
- public ManagerImpl(NamingContext namingContext, EjbServices ejbServices, ResourceLoader resourceLoader, TransactionServices transactionServices)
+ public ManagerImpl(ServiceRegistry serviceRegistry)
{
- this.ejbServices = ejbServices;
- this.namingContext = namingContext;
- this.resourceLoader = resourceLoader;
- this.transactionServices = transactionServices;
+ this.serviceRegistry = serviceRegistry;
this.beans = new CopyOnWriteArrayList<Bean<?>>();
this.newEnterpriseBeanMap = new ConcurrentHashMap<Class<?>, EnterpriseBean<?>>();
this.resolver = new Resolver(this);
@@ -891,33 +877,12 @@
throw new UnsupportedOperationException();
}
- public NamingContext getNaming()
+ public ServiceRegistry getServices()
{
- return namingContext;
+ return serviceRegistry;
}
- public final EjbServices getEjbServices()
- {
- return ejbServices;
- }
-
- public final ResourceLoader getResourceLoader()
- {
- return resourceLoader;
- }
-
/**
- * Provides access to the transaction services provided by the container
- * or application server.
- *
- * @return a TransactionServices provider per the SPI
- */
- public final TransactionServices getTransactionServices()
- {
- return transactionServices;
- }
-
- /**
* Accesses the factory used to create each instance of InjectionPoint that
* is injected into web beans.
*
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/EnterpriseBean.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/EnterpriseBean.java 2009-03-14 22:57:40 UTC (rev 1998)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/EnterpriseBean.java 2009-03-15 00:12:08 UTC (rev 1999)
@@ -44,10 +44,12 @@
import org.jboss.webbeans.ejb.InternalEjbDescriptor;
import org.jboss.webbeans.ejb.api.EjbReference;
import org.jboss.webbeans.ejb.spi.BusinessInterfaceDescriptor;
+import org.jboss.webbeans.ejb.spi.EjbServices;
import org.jboss.webbeans.introspector.AnnotatedClass;
import org.jboss.webbeans.introspector.AnnotatedMethod;
import org.jboss.webbeans.log.LogProvider;
import org.jboss.webbeans.log.Logging;
+import org.jboss.webbeans.resources.spi.NamingContext;
import org.jboss.webbeans.util.Proxies;
/**
@@ -380,7 +382,7 @@
public EjbReference<T> createReference()
{
- return getManager().getEjbServices().resolveEJB(getEjbDescriptor(), CurrentManager.rootManager().getNaming());
+ return manager.getServices().get(EjbServices.class).resolveEJB(getEjbDescriptor(), CurrentManager.rootManager().getServices().get(NamingContext.class));
}
}
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/SimpleBean.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/SimpleBean.java 2009-03-14 22:57:40 UTC (rev 1998)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/SimpleBean.java 2009-03-15 00:12:08 UTC (rev 1999)
@@ -33,6 +33,7 @@
import org.jboss.webbeans.ManagerImpl;
import org.jboss.webbeans.context.DependentContext;
import org.jboss.webbeans.context.DependentStorageRequest;
+import org.jboss.webbeans.ejb.spi.EjbServices;
import org.jboss.webbeans.injection.AnnotatedInjectionPoint;
import org.jboss.webbeans.injection.ConstructorInjectionPoint;
import org.jboss.webbeans.injection.FieldInjectionPoint;
@@ -47,6 +48,7 @@
import org.jboss.webbeans.log.LogProvider;
import org.jboss.webbeans.log.Logging;
import org.jboss.webbeans.metadata.MetaDataCache;
+import org.jboss.webbeans.resources.spi.NamingContext;
import org.jboss.webbeans.util.Names;
import org.jboss.webbeans.util.Reflections;
@@ -219,12 +221,12 @@
protected void initEjbInjectionPoints()
{
this.ejbInjectionPoints = new HashSet<AnnotatedInjectionPoint<?, ?>>();
- for (AnnotatedField<?> field : annotatedItem.getAnnotatedFields(manager.getEjbServices().getEJBAnnotation()))
+ for (AnnotatedField<?> field : annotatedItem.getAnnotatedFields(manager.getServices().get(EjbServices.class).getEJBAnnotation()))
{
this.ejbInjectionPoints.add(FieldInjectionPoint.of(this, field));
}
- for (AnnotatedMethod<?> method : annotatedItem.getAnnotatedMethods(manager.getEjbServices().getEJBAnnotation()))
+ for (AnnotatedMethod<?> method : annotatedItem.getAnnotatedMethods(manager.getServices().get(EjbServices.class).getEJBAnnotation()))
{
this.ejbInjectionPoints.add(MethodInjectionPoint.of(this, method));
}
@@ -233,7 +235,7 @@
protected void initPersistenceUnitInjectionPoints()
{
this.persistenceUnitInjectionPoints = new HashSet<AnnotatedInjectionPoint<?, ?>>();
- for (AnnotatedField<?> field : annotatedItem.getAnnotatedFields(manager.getEjbServices().getPersistenceContextAnnotation()))
+ for (AnnotatedField<?> field : annotatedItem.getAnnotatedFields(manager.getServices().get(EjbServices.class).getPersistenceContextAnnotation()))
{
if (field.getAnnotation(PersistenceContext.class).type().equals(PersistenceContextType.EXTENDED))
{
@@ -242,7 +244,7 @@
this.persistenceUnitInjectionPoints.add(FieldInjectionPoint.of(this, field));
}
- for (AnnotatedMethod<?> method : annotatedItem.getAnnotatedMethods(manager.getEjbServices().getPersistenceContextAnnotation()))
+ for (AnnotatedMethod<?> method : annotatedItem.getAnnotatedMethods(manager.getServices().get(EjbServices.class).getPersistenceContextAnnotation()))
{
if (method.getAnnotation(PersistenceContext.class).type().equals(PersistenceContextType.EXTENDED))
{
@@ -255,7 +257,7 @@
protected void initResourceInjectionPoints()
{
this.resourceInjectionPoints = new HashSet<AnnotatedInjectionPoint<?, ?>>();
- for (AnnotatedField<?> field : annotatedItem.getAnnotatedFields(manager.getEjbServices().getResourceAnnotation()))
+ for (AnnotatedField<?> field : annotatedItem.getAnnotatedFields(manager.getServices().get(EjbServices.class).getResourceAnnotation()))
{
this.resourceInjectionPoints.add(FieldInjectionPoint.of(this, field));
}
@@ -266,22 +268,23 @@
*/
protected void injectEjbAndCommonFields(T beanInstance)
{
-
+ NamingContext namingContext = manager.getServices().get(NamingContext.class);
+ EjbServices ejbServices = manager.getServices().get(EjbServices.class);
for (AnnotatedInjectionPoint<?, ?> injectionPoint : ejbInjectionPoints)
{
- Object ejbInstance = manager.getEjbServices().resolveEjb(injectionPoint, manager.getNaming());
+ Object ejbInstance = ejbServices.resolveEjb(injectionPoint, namingContext);
injectionPoint.inject(beanInstance, ejbInstance);
}
for (AnnotatedInjectionPoint<?, ?> injectionPoint : persistenceUnitInjectionPoints)
{
- Object puInstance = manager.getEjbServices().resolvePersistenceContext(injectionPoint, manager.getNaming());
+ Object puInstance = ejbServices.resolvePersistenceContext(injectionPoint, namingContext);
injectionPoint.inject(beanInstance, puInstance);
}
for (AnnotatedInjectionPoint<?, ?> injectionPoint : resourceInjectionPoints)
{
- Object resourceInstance = manager.getEjbServices().resolveResource(injectionPoint, manager.getNaming());
+ Object resourceInstance = ejbServices.resolveResource(injectionPoint, namingContext);
injectionPoint.inject(beanInstance, resourceInstance);
}
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-14 22:57:40 UTC (rev 1998)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployer.java 2009-03-15 00:12:08 UTC (rev 1999)
@@ -38,6 +38,7 @@
import org.jboss.webbeans.jsf.JSFApiAbstraction;
import org.jboss.webbeans.log.LogProvider;
import org.jboss.webbeans.log.Logging;
+import org.jboss.webbeans.resources.spi.ResourceLoader;
import org.jboss.webbeans.servlet.ServletApiAbstraction;
public class BeanDeployer
@@ -259,9 +260,10 @@
*/
private boolean isTypeSimpleWebBean(AnnotatedClass<?> clazz)
{
- EJBApiAbstraction ejbApiAbstraction = new EJBApiAbstraction(manager.getResourceLoader());
- JSFApiAbstraction jsfApiAbstraction = new JSFApiAbstraction(manager.getResourceLoader());
- ServletApiAbstraction servletApiAbstraction = new ServletApiAbstraction(manager.getResourceLoader());
+ ResourceLoader resourceLoader = manager.getServices().get(ResourceLoader.class);
+ EJBApiAbstraction ejbApiAbstraction = new EJBApiAbstraction(resourceLoader);
+ JSFApiAbstraction jsfApiAbstraction = new JSFApiAbstraction(resourceLoader);
+ ServletApiAbstraction servletApiAbstraction = new ServletApiAbstraction(resourceLoader);
// TODO: check 3.2.1 for more rules!!!!!!
return !clazz.isAbstract() && !clazz.isParameterizedType() && !servletApiAbstraction.SERVLET_CLASS.isAssignableFrom(clazz) && !servletApiAbstraction.FILTER_CLASS.isAssignableFrom(clazz) && !servletApiAbstraction.SERVLET_CONTEXT_LISTENER_CLASS.isAssignableFrom(clazz) && !servletApiAbstraction.HTTP_SESSION_LISTENER_CLASS.isAssignableFrom(clazz) && !servletApiAbstraction.SERVLET_REQUEST_LISTENER_CLASS.isAssignableFrom(clazz) && !ejbApiAbstraction.ENTERPRISE_BEAN_CLASS.isAssignableFrom(clazz) && !jsfApiAbstraction.UICOMPONENT_CLASS.isAssignableFrom(clazz) && hasSimpleWebBeanConstructor(clazz);
}
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java 2009-03-14 22:57:40 UTC (rev 1998)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java 2009-03-15 00:12:08 UTC (rev 1999)
@@ -38,14 +38,17 @@
import org.jboss.webbeans.conversation.JavaSEConversationTerminator;
import org.jboss.webbeans.conversation.NumericConversationIdGenerator;
import org.jboss.webbeans.conversation.ServletConversationManager;
+import org.jboss.webbeans.ejb.spi.EjbServices;
import org.jboss.webbeans.literal.DeployedLiteral;
import org.jboss.webbeans.literal.InitializedLiteral;
import org.jboss.webbeans.log.LogProvider;
import org.jboss.webbeans.log.Logging;
import org.jboss.webbeans.resources.DefaultNamingContext;
import org.jboss.webbeans.resources.DefaultResourceLoader;
+import org.jboss.webbeans.resources.spi.NamingContext;
+import org.jboss.webbeans.resources.spi.ResourceLoader;
import org.jboss.webbeans.servlet.HttpSessionManager;
-import org.jboss.webbeans.transaction.Transaction;
+import org.jboss.webbeans.transaction.spi.TransactionServices;
/**
* Common bootstrapping functionality that is run at application startup and
@@ -63,30 +66,24 @@
private ManagerImpl manager;
public WebBeansBootstrap()
{
- setResourceLoader(new DefaultResourceLoader());
- setNamingContext(new DefaultNamingContext());
+ // initialize default services
+ getServices().add(ResourceLoader.class, new DefaultResourceLoader());
+ getServices().add(NamingContext.class, new DefaultNamingContext());
}
public void initialize()
{
- if (getResourceLoader() == null)
+ verify();
+ if (!getServices().contains(TransactionServices.class))
{
- throw new IllegalStateException("ResourceLoader not set");
+ log.info("Transactional services not available. Transactional observers will be invoked synchronously.");
}
- if (getNamingContext() == null)
+ if (!getServices().contains(EjbServices.class))
{
- throw new IllegalStateException("NamingContext is not set");
+ log.info("EJB services not available. Session beans, injection into non-contextual EJBs, injection of @Resource, @PersistenceContext and @EJB in simple beans, injection of Java EE resources and JMS resources will not be available.");
}
- if (getEjbServices() == null)
- {
- throw new IllegalStateException("EjbServices is not set");
- }
- if (getTransactionServices() == null)
- {
- log.info("Transactional services not available. Transactional observers will be invoked synchronously.");
- }
- this.manager = new ManagerImpl(getNamingContext(), getEjbServices(), getResourceLoader(), getTransactionServices());
- getManager().getNaming().bind(ManagerImpl.JNDI_KEY, getManager());
+ this.manager = new ManagerImpl(getServices());
+ getServices().get(NamingContext.class).bind(ManagerImpl.JNDI_KEY, getManager());
CurrentManager.setRootManager(manager);
initializeContexts();
}
@@ -108,7 +105,6 @@
beanDeployer.addClasses(classes);
beanDeployer.addBean(ManagerBean.of(manager));
beanDeployer.addBean(InjectionPointBean.of(manager));
- beanDeployer.addClass(Transaction.class);
beanDeployer.addClass(ConversationImpl.class);
beanDeployer.addClass(ServletConversationManager.class);
beanDeployer.addClass(JavaSEConversationTerminator.class);
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/event/TransactionalObserverImpl.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/event/TransactionalObserverImpl.java 2009-03-14 22:57:40 UTC (rev 1998)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/event/TransactionalObserverImpl.java 2009-03-15 00:12:08 UTC (rev 1999)
@@ -87,7 +87,7 @@
@Override
public void notify(T event)
{
- if ((manager.getTransactionServices() != null) && (manager.getTransactionServices().isTransactionActive()))
+ if ((manager.getServices().get(TransactionServices.class) != null) && (manager.getServices().get(TransactionServices.class).isTransactionActive()))
{
deferEvent(event);
}
@@ -164,7 +164,7 @@
{
synchronization = new TransactionSynchronizedRunnable(deferredEvent, TransactionServices.Status.FAILURE);
}
- manager.getTransactionServices().registerSynchronization(synchronization);
+ manager.getServices().get(TransactionServices.class).registerSynchronization(synchronization);
}
}
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/mock/MockEjbDiscovery.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/mock/MockEjbDiscovery.java 2009-03-14 22:57:40 UTC (rev 1998)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/mock/MockEjbDiscovery.java 2009-03-15 00:12:08 UTC (rev 1999)
@@ -27,25 +27,26 @@
import javax.ejb.Stateless;
import org.jboss.webbeans.bootstrap.spi.EjbDiscovery;
+import org.jboss.webbeans.bootstrap.spi.WebBeanDiscovery;
import org.jboss.webbeans.ejb.spi.EjbDescriptor;
public class MockEjbDiscovery implements EjbDiscovery
{
- private final List<EjbDescriptor<?>> ejbs;
+ private final WebBeanDiscovery webBeanDiscovery;
- public MockEjbDiscovery(Iterable<Class<?>> allClasses)
+ public MockEjbDiscovery(WebBeanDiscovery webBeanDiscovery)
{
-
- this.ejbs = new ArrayList<EjbDescriptor<?>>();
- for (Class<?> ejbClass : discoverEjbs(allClasses))
- {
- this.ejbs.add(MockEjbDescriptor.of(ejbClass));
- }
+ this.webBeanDiscovery = webBeanDiscovery;
}
public Iterable<EjbDescriptor<?>> discoverEjbs()
{
+ List<EjbDescriptor<?>> ejbs = new ArrayList<EjbDescriptor<?>>();
+ for (Class<?> ejbClass : discoverEjbs(webBeanDiscovery.discoverWebBeanClasses()))
+ {
+ ejbs.add(MockEjbDescriptor.of(ejbClass));
+ }
return ejbs;
}
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/mock/MockLifecycle.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/mock/MockLifecycle.java 2009-03-14 22:57:40 UTC (rev 1998)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/mock/MockLifecycle.java 2009-03-15 00:12:08 UTC (rev 1999)
@@ -19,9 +19,12 @@
import org.jboss.webbeans.bootstrap.WebBeansBootstrap;
+import org.jboss.webbeans.bootstrap.spi.EjbDiscovery;
+import org.jboss.webbeans.bootstrap.spi.WebBeanDiscovery;
import org.jboss.webbeans.context.api.BeanStore;
import org.jboss.webbeans.context.api.helpers.ConcurrentHashMapBeanStore;
import org.jboss.webbeans.ejb.spi.EjbServices;
+import org.jboss.webbeans.resources.spi.NamingContext;
import org.jboss.webbeans.resources.spi.ResourceLoader;
import org.jboss.webbeans.servlet.AbstractLifecycle;
import org.jboss.webbeans.transaction.spi.TransactionServices;
@@ -35,9 +38,9 @@
private final WebBeansBootstrap bootstrap;
private final MockWebBeanDiscovery webBeanDiscovery;
- private BeanStore applicationBeanStore = new ConcurrentHashMapBeanStore();
- private BeanStore sessionBeanStore = new ConcurrentHashMapBeanStore();
- private BeanStore requestBeanStore = new ConcurrentHashMapBeanStore();
+ private final BeanStore applicationBeanStore = new ConcurrentHashMapBeanStore();
+ private final BeanStore sessionBeanStore = new ConcurrentHashMapBeanStore();
+ private final BeanStore requestBeanStore = new ConcurrentHashMapBeanStore();
public MockLifecycle()
{
@@ -52,12 +55,13 @@
throw new IllegalStateException("No WebBeanDiscovery is available");
}
bootstrap = new WebBeansBootstrap();
- bootstrap.setNamingContext(new MockNamingContext(null));
- bootstrap.setEjbServices(MOCK_EJB_RESOLVER);
- bootstrap.setResourceLoader(MOCK_RESOURCE_LOADER);
- bootstrap.setWebBeanDiscovery(webBeanDiscovery);
+ bootstrap.getServices().add(NamingContext.class, new MockNamingContext(null));
+ bootstrap.getServices().add(EjbServices.class, MOCK_EJB_RESOLVER);
+ bootstrap.getServices().add(ResourceLoader.class, MOCK_RESOURCE_LOADER);
+ bootstrap.getServices().add(WebBeanDiscovery.class, webBeanDiscovery);
bootstrap.setApplicationContext(applicationBeanStore);
- bootstrap.setTransactionServices(MOCK_TRANSACTION_SERVICES);
+ bootstrap.getServices().add(TransactionServices.class, MOCK_TRANSACTION_SERVICES);
+ bootstrap.getServices().add(EjbDiscovery.class, new MockEjbDiscovery(webBeanDiscovery));
bootstrap.initialize();
}
@@ -73,7 +77,6 @@
public void beginApplication()
{
- bootstrap.setEjbDiscovery(new MockEjbDiscovery(webBeanDiscovery.discoverWebBeanClasses()));
bootstrap.boot();
}
Modified: ri/trunk/porting-package/src/main/java/org/jboss/webbeans/tck/BeansImpl.java
===================================================================
--- ri/trunk/porting-package/src/main/java/org/jboss/webbeans/tck/BeansImpl.java 2009-03-14 22:57:40 UTC (rev 1998)
+++ ri/trunk/porting-package/src/main/java/org/jboss/webbeans/tck/BeansImpl.java 2009-03-15 00:12:08 UTC (rev 1999)
@@ -4,6 +4,7 @@
import org.jboss.webbeans.CurrentManager;
import org.jboss.webbeans.ejb.spi.BusinessInterfaceDescriptor;
import org.jboss.webbeans.ejb.spi.EjbDescriptor;
+import org.jboss.webbeans.resources.spi.NamingContext;
import org.jboss.webbeans.util.Reflections;
/**
@@ -88,7 +89,7 @@
}
if (jndiName == null)
throw new NullPointerException("No JNDI name found for interface " + localInterface.getName() + " on bean " + beanType.getName());
- enterpriseBean = CurrentManager.rootManager().getNaming().lookup(jndiName, localInterface);
+ enterpriseBean = CurrentManager.rootManager().getServices().get(NamingContext.class).lookup(jndiName, localInterface);
}
return enterpriseBean;
}
Modified: ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/Bootstrap.java
===================================================================
--- ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/Bootstrap.java 2009-03-14 22:57:40 UTC (rev 1998)
+++ ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/Bootstrap.java 2009-03-15 00:12:08 UTC (rev 1999)
@@ -1,3 +1,19 @@
+/*
+ * 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.bootstrap.api;
import org.jboss.webbeans.bootstrap.spi.EjbDiscovery;
@@ -23,6 +39,7 @@
*
* @param webBeanDiscovery
*/
+ @Deprecated
public void setWebBeanDiscovery(WebBeanDiscovery webBeanDiscovery);
/**
@@ -30,6 +47,7 @@
*
* @param ejbDiscovery
*/
+ @Deprecated
public void setEjbDiscovery(EjbDiscovery ejbDiscovery);
/**
@@ -37,6 +55,7 @@
*
* @param ejbServices
*/
+ @Deprecated
public void setEjbServices(EjbServices ejbServices);
/**
@@ -47,6 +66,7 @@
*
* @param namingContext
*/
+ @Deprecated
public void setNamingContext(NamingContext namingContext);
/**
@@ -55,8 +75,14 @@
*
* @param resourceLoader
*/
+ @Deprecated
public void setResourceLoader(ResourceLoader resourceLoader);
+ /**
+ * Set the bean store to use as backing for the application context
+ *
+ * @param beanStore the bean store to use
+ */
public void setApplicationContext(BeanStore beanStore);
/**
@@ -64,13 +90,25 @@
*
* @param transactionServices An implementation of TransactionService
*/
+ @Deprecated
public void setTransactionServices(TransactionServices transactionServices);
/**
+ * Set the environment in use, by default {@link Environments.EE}
+ *
+ * @param environment the environment to use
+ */
+ public void setEnvironment(Environment environment);
+
+ /**
* Initialize the bootstrap:
* <ul>
- * <li>Create the manager and bind it to JNDI</li>
+ * <li>Create the manager and bind it to JNDI</li>
* </ul>
+ *
+ * @throws IllegalStateException
+ * if not all the services required for the given environment are
+ * available
*/
public void initialize();
@@ -86,8 +124,9 @@
* Starts the boot process.
*
* Discovers the beans and registers them with the getManager(). Also
- * resolves the injection points. Before running {@link #boot()} the contexts
- * should be available
+ * resolves the injection points. Before running {@link #boot()}
+ * {@link #initialize()} must have been called and the contexts should be
+ * available
*
*/
public void boot();
Added: ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/Environment.java
===================================================================
--- ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/Environment.java (rev 0)
+++ ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/Environment.java 2009-03-15 00:12:08 UTC (rev 1999)
@@ -0,0 +1,37 @@
+/*
+ * 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.bootstrap.api;
+
+import java.util.Set;
+
+/**
+ * Represents an environment. Used to control which services Web Beans will require
+ * in order to boot
+ * @author Pete Muir
+ *
+ */
+public interface Environment
+{
+
+ /**
+ * The services to require for this environment
+ *
+ * @return the services to require
+ */
+ public Set<Class<? extends Service>> getRequiredServices();
+
+}
Property changes on: ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/Environment.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/Environments.java
===================================================================
--- ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/Environments.java (rev 0)
+++ ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/Environments.java 2009-03-15 00:12:08 UTC (rev 1999)
@@ -0,0 +1,71 @@
+/*
+ * 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.bootstrap.api;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.jboss.webbeans.bootstrap.spi.EjbDiscovery;
+import org.jboss.webbeans.bootstrap.spi.WebBeanDiscovery;
+import org.jboss.webbeans.ejb.spi.EjbServices;
+import org.jboss.webbeans.resources.spi.NamingContext;
+import org.jboss.webbeans.resources.spi.ResourceLoader;
+import org.jboss.webbeans.transaction.spi.TransactionServices;
+
+/**
+ * Various well known environments.
+ *
+ * @author Pete Muir
+ *
+ */
+public enum Environments implements Environment
+{
+
+ /**
+ * Java EE5 or Java EE6
+ */
+ EE(WebBeanDiscovery.class, EjbDiscovery.class, EjbServices.class, TransactionServices.class, NamingContext.class, ResourceLoader.class),
+
+ /**
+ * Java EE6 Web Profile
+ */
+ EE_WEB_PROFILE(WebBeanDiscovery.class, EjbDiscovery.class, EjbServices.class, TransactionServices.class, NamingContext.class, ResourceLoader.class),
+
+ /**
+ * Servlet container such as Tomcat
+ */
+ SERVLET(WebBeanDiscovery.class, NamingContext.class, ResourceLoader.class),
+
+ /**
+ * Java SE
+ */
+ SE(WebBeanDiscovery.class, NamingContext.class, ResourceLoader.class);
+
+ private Set<Class<? extends Service>> requiredServices;
+
+ private Environments(Class<? extends Service>... requiredServices)
+ {
+ this.requiredServices = new HashSet<Class<? extends Service>>(Arrays.asList(requiredServices));
+ }
+
+ public Set<Class<? extends Service>> getRequiredServices()
+ {
+ return requiredServices;
+ }
+
+}
\ No newline at end of file
Property changes on: ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/Environments.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/Service.java
===================================================================
--- ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/Service.java (rev 0)
+++ ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/Service.java 2009-03-15 00:12:08 UTC (rev 1999)
@@ -0,0 +1,27 @@
+/*
+ * 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.bootstrap.api;
+
+/**
+ * Marks a Service which is used by Web Beans to interact with it's environment
+ * @author Pete Muir
+ *
+ */
+public interface Service
+{
+
+}
Property changes on: ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/Service.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/ServiceRegistry.java
===================================================================
--- ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/ServiceRegistry.java (rev 0)
+++ ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/ServiceRegistry.java 2009-03-15 00:12:08 UTC (rev 1999)
@@ -0,0 +1,56 @@
+package org.jboss.webbeans.bootstrap.api;
+
+import java.util.HashMap;
+import java.util.Map;
+
+
+public class ServiceRegistry
+{
+
+ private final Map<Class<? extends Service>, Service> services;
+
+ public ServiceRegistry()
+ {
+ this.services = new HashMap<Class<? extends Service>, Service>();
+ }
+
+ /**
+ * Add a service to bootstrap
+ *
+ * @see Service
+ *
+ * @param <S> the service type to add
+ * @param serviceType the service type to add
+ * @param service the service implementation
+ */
+ public <S extends Service> void add(java.lang.Class<S> type, S service)
+ {
+ services.put(type, service);
+ }
+
+ /**
+ * Retrieve a service implementation
+ *
+ * @param <S> the service type
+ * @param serviceType the service type
+ * @return the service implementation, or null if none is registered
+ */
+ @SuppressWarnings("unchecked")
+ public <S extends Service> S get(Class<S> type)
+ {
+ return (S) services.get(type);
+ }
+
+ /**
+ * Check if a service is registered
+ *
+ * @param <S> the service type
+ * @param serviceType the service type
+ * @return true if a service is registered, otherwise false
+ */
+ public <S extends Service> boolean contains(Class<S> type)
+ {
+ return services.containsKey(type);
+ }
+
+}
Property changes on: ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/ServiceRegistry.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/AbstractBootstrap.java
===================================================================
--- ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/AbstractBootstrap.java 2009-03-14 22:57:40 UTC (rev 1998)
+++ ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/AbstractBootstrap.java 2009-03-15 00:12:08 UTC (rev 1999)
@@ -1,6 +1,27 @@
+/*
+ * 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.bootstrap.api.helpers;
+import static org.jboss.webbeans.bootstrap.api.Environments.EE;
+
import org.jboss.webbeans.bootstrap.api.Bootstrap;
+import org.jboss.webbeans.bootstrap.api.Environment;
+import org.jboss.webbeans.bootstrap.api.Service;
+import org.jboss.webbeans.bootstrap.api.ServiceRegistry;
import org.jboss.webbeans.bootstrap.spi.EjbDiscovery;
import org.jboss.webbeans.bootstrap.spi.WebBeanDiscovery;
import org.jboss.webbeans.context.api.BeanStore;
@@ -9,75 +30,95 @@
import org.jboss.webbeans.resources.spi.ResourceLoader;
import org.jboss.webbeans.transaction.spi.TransactionServices;
+/**
+ * A common implementation of {@link Bootstrap}.
+ *
+ * Not threadsafe
+ *
+ * @author Pete Muir
+ *
+ */
public abstract class AbstractBootstrap implements Bootstrap
{
+ private final ServiceRegistry serviceRegistry;
+ private Environment environment = EE;
- private WebBeanDiscovery webBeanDiscovery;
- private ResourceLoader resourceLoader;
- private NamingContext namingContext;
- private EjbServices ejbServices;
- private EjbDiscovery ejbDiscovery;
private BeanStore applicationContext;
- private TransactionServices transactionServices;
+
+ public AbstractBootstrap()
+ {
+ this.serviceRegistry = new ServiceRegistry();
+ }
+ @Deprecated
public void setEjbDiscovery(EjbDiscovery ejbDiscovery)
{
- this.ejbDiscovery = ejbDiscovery;
+ getServices().add(EjbDiscovery.class, ejbDiscovery);
}
+ @Deprecated
public void setEjbServices(EjbServices ejbServices)
{
- this.ejbServices = ejbServices;
+ getServices().add(EjbServices.class, ejbServices);
}
+ @Deprecated
public void setNamingContext(NamingContext namingContext)
{
- this.namingContext = namingContext;
+ getServices().add(NamingContext.class, namingContext);
}
+ @Deprecated
public void setResourceLoader(ResourceLoader resourceLoader)
{
- this.resourceLoader = resourceLoader;
+ getServices().add(ResourceLoader.class, resourceLoader);
}
+ @Deprecated
public void setWebBeanDiscovery(WebBeanDiscovery webBeanDiscovery)
{
- this.webBeanDiscovery = webBeanDiscovery;
+ getServices().add(WebBeanDiscovery.class, webBeanDiscovery);
}
+ @Deprecated
public void setTransactionServices(TransactionServices transactionServices)
{
- this.transactionServices = transactionServices;
+ getServices().add(TransactionServices.class, transactionServices);
}
public WebBeanDiscovery getWebBeanDiscovery()
{
- return webBeanDiscovery;
+ return getServices().get(WebBeanDiscovery.class);
}
+ @Deprecated
public ResourceLoader getResourceLoader()
{
- return resourceLoader;
+ return getServices().get(ResourceLoader.class);
}
+ @Deprecated
public NamingContext getNamingContext()
{
- return namingContext;
+ return getServices().get(NamingContext.class);
}
+ @Deprecated
public EjbServices getEjbServices()
{
- return ejbServices;
+ return getServices().get(EjbServices.class);
}
+ @Deprecated
public EjbDiscovery getEjbDiscovery()
{
- return ejbDiscovery;
+ return getServices().get(EjbDiscovery.class);
}
+ @Deprecated
public TransactionServices getTransactionServices()
{
- return transactionServices;
+ return getServices().get(TransactionServices.class);
}
public BeanStore getApplicationContext()
@@ -90,4 +131,30 @@
this.applicationContext = applicationContext;
}
+ public Environment getEnvironment()
+ {
+ return environment;
+ }
+
+ public void setEnvironment(Environment environment)
+ {
+ this.environment = environment;
+ }
+
+ protected void verify()
+ {
+ for (Class<? extends Service> serviceType : environment.getRequiredServices())
+ {
+ if (!getServices().contains(serviceType))
+ {
+ throw new IllegalStateException("Required service " + serviceType.getName() + " has not been specified");
+ }
+ }
+ }
+
+ public ServiceRegistry getServices()
+ {
+ return serviceRegistry;
+ }
+
}
\ No newline at end of file
Modified: ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/ForwardingBootstrap.java
===================================================================
--- ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/ForwardingBootstrap.java 2009-03-14 22:57:40 UTC (rev 1998)
+++ ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/ForwardingBootstrap.java 2009-03-15 00:12:08 UTC (rev 1999)
@@ -1,3 +1,19 @@
+/*
+ * 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.bootstrap.api.helpers;
import org.jboss.webbeans.bootstrap.api.Bootstrap;
@@ -9,6 +25,11 @@
import org.jboss.webbeans.resources.spi.NamingContext;
import org.jboss.webbeans.resources.spi.ResourceLoader;
+/**
+ * Implementation of {@link Bootstrap} which supports the decorator pattern
+ * @author Pete Muir
+ *
+ */
public abstract class ForwardingBootstrap implements Bootstrap
{
@@ -34,26 +55,31 @@
delegate().setApplicationContext(beanStore);
}
+ @Deprecated
public void setEjbDiscovery(EjbDiscovery ejbDiscovery)
{
delegate().setEjbDiscovery(ejbDiscovery);
}
+ @Deprecated
public void setEjbServices(EjbServices ejbServices)
{
delegate().setEjbServices(ejbServices);
}
+ @Deprecated
public void setNamingContext(NamingContext namingContext)
{
delegate().setNamingContext(namingContext);
}
+ @Deprecated
public void setResourceLoader(ResourceLoader resourceLoader)
{
delegate().setResourceLoader(resourceLoader);
}
+ @Deprecated
public void setWebBeanDiscovery(WebBeanDiscovery webBeanDiscovery)
{
delegate().setWebBeanDiscovery(webBeanDiscovery);
Modified: ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/spi/EjbDiscovery.java
===================================================================
--- ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/spi/EjbDiscovery.java 2009-03-14 22:57:40 UTC (rev 1998)
+++ ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/spi/EjbDiscovery.java 2009-03-15 00:12:08 UTC (rev 1999)
@@ -17,6 +17,7 @@
package org.jboss.webbeans.bootstrap.spi;
+import org.jboss.webbeans.bootstrap.api.Service;
import org.jboss.webbeans.ejb.spi.EjbDescriptor;
@@ -28,7 +29,7 @@
* @author Pete Muir
*
*/
-public interface EjbDiscovery
+public interface EjbDiscovery extends Service
{
public static final String PROPERTY_NAME = EjbDiscovery.class.getName();
Modified: ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/spi/WebBeanDiscovery.java
===================================================================
--- ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/spi/WebBeanDiscovery.java 2009-03-14 22:57:40 UTC (rev 1998)
+++ ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/spi/WebBeanDiscovery.java 2009-03-15 00:12:08 UTC (rev 1999)
@@ -19,6 +19,8 @@
import java.net.URL;
+import org.jboss.webbeans.bootstrap.api.Service;
+
/**
* A container should implement this interface to allow the Web Beans RI to
* discover the Web Beans to deploy
@@ -26,7 +28,7 @@
* @author Pete Muir
*
*/
-public interface WebBeanDiscovery
+public interface WebBeanDiscovery extends Service
{
public static final String PROPERTY_NAME = WebBeanDiscovery.class.getName();
Modified: ri/trunk/spi/src/main/java/org/jboss/webbeans/ejb/spi/EjbServices.java
===================================================================
--- ri/trunk/spi/src/main/java/org/jboss/webbeans/ejb/spi/EjbServices.java 2009-03-14 22:57:40 UTC (rev 1998)
+++ ri/trunk/spi/src/main/java/org/jboss/webbeans/ejb/spi/EjbServices.java 2009-03-15 00:12:08 UTC (rev 1999)
@@ -21,6 +21,7 @@
import javax.inject.manager.InjectionPoint;
+import org.jboss.webbeans.bootstrap.api.Service;
import org.jboss.webbeans.ejb.api.EjbReference;
import org.jboss.webbeans.resources.spi.NamingContext;
@@ -31,7 +32,7 @@
* @author Pete Muir
*
*/
-public interface EjbServices
+public interface EjbServices extends Service
{
public static final String PROPERTY_NAME = EjbServices.class.getName();
Modified: ri/trunk/spi/src/main/java/org/jboss/webbeans/resources/spi/NamingContext.java
===================================================================
--- ri/trunk/spi/src/main/java/org/jboss/webbeans/resources/spi/NamingContext.java 2009-03-14 22:57:40 UTC (rev 1998)
+++ ri/trunk/spi/src/main/java/org/jboss/webbeans/resources/spi/NamingContext.java 2009-03-15 00:12:08 UTC (rev 1999)
@@ -17,7 +17,17 @@
package org.jboss.webbeans.resources.spi;
-public interface NamingContext
+import org.jboss.webbeans.bootstrap.api.Service;
+
+/**
+ * JNDI operations for Web Beans, by default a read-write spec compliant
+ * implementation will be used. If you wish to substitute, for example, a read-
+ * only implementation, you may
+ *
+ * @author Pete Muir
+ *
+ */
+public interface NamingContext extends Service
{
public static final String PROPERTY_NAME = NamingContext.class.getName();
Modified: ri/trunk/spi/src/main/java/org/jboss/webbeans/resources/spi/ResourceLoader.java
===================================================================
--- ri/trunk/spi/src/main/java/org/jboss/webbeans/resources/spi/ResourceLoader.java 2009-03-14 22:57:40 UTC (rev 1998)
+++ ri/trunk/spi/src/main/java/org/jboss/webbeans/resources/spi/ResourceLoader.java 2009-03-15 00:12:08 UTC (rev 1999)
@@ -19,13 +19,17 @@
import java.net.URL;
+import org.jboss.webbeans.bootstrap.api.Service;
+
/**
- * Resource loading/class creation abstraction
+ * Resource loading/class creation services for Web Beans. By default an
+ * implementation which uses the Thread Context ClassLoader if available,
+ * otherwise the classloading of the implementation is used
*
* @author Pete Muir
*
*/
-public interface ResourceLoader
+public interface ResourceLoader extends Service
{
// Name of the resource loader
public static final String PROPERTY_NAME = ResourceLoader.class.getName();
Modified: ri/trunk/spi/src/main/java/org/jboss/webbeans/transaction/spi/TransactionServices.java
===================================================================
--- ri/trunk/spi/src/main/java/org/jboss/webbeans/transaction/spi/TransactionServices.java 2009-03-14 22:57:40 UTC (rev 1998)
+++ ri/trunk/spi/src/main/java/org/jboss/webbeans/transaction/spi/TransactionServices.java 2009-03-15 00:12:08 UTC (rev 1999)
@@ -2,6 +2,8 @@
import javax.transaction.Synchronization;
+import org.jboss.webbeans.bootstrap.api.Service;
+
/**
* <p>
* The container must implement the services related to transactional behavior
@@ -19,7 +21,7 @@
* @author David Allen
*
*/
-public interface TransactionServices
+public interface TransactionServices extends Service
{
/**
* Possible status conditions for a transaction. This can be used by SPI
15 years, 10 months
[webbeans-commits] Webbeans SVN: r1998 - in ri/trunk/impl/src/main/java/org/jboss/webbeans/xsd: helpers and 1 other directories.
by webbeans-commits@lists.jboss.org
Author: nickarls
Date: 2009-03-14 18:57:40 -0400 (Sat, 14 Mar 2009)
New Revision: 1998
Added:
ri/trunk/impl/src/main/java/org/jboss/webbeans/xsd/PackageInfo.java
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/xsd/PackageSchemaGenerator.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/xsd/helpers/XSDHelper.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/xsd/model/ClassModel.java
Log:
minor refactoring
Added: ri/trunk/impl/src/main/java/org/jboss/webbeans/xsd/PackageInfo.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/xsd/PackageInfo.java (rev 0)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/xsd/PackageInfo.java 2009-03-14 22:57:40 UTC (rev 1998)
@@ -0,0 +1,48 @@
+package org.jboss.webbeans.xsd;
+
+import java.util.List;
+
+import org.dom4j.Document;
+
+public class PackageInfo
+{
+ private List<String> namespaces;
+ private Document schema;
+ private String packageName;
+
+ public PackageInfo(String packageName)
+ {
+ this.packageName = packageName;
+ }
+
+ public List<String> getNamespaces()
+ {
+ return namespaces;
+ }
+
+ public void setNamespaces(List<String> namespaces)
+ {
+ this.namespaces = namespaces;
+ }
+
+ public Document getSchema()
+ {
+ return schema;
+ }
+
+ public void setSchema(Document schema)
+ {
+ this.schema = schema;
+ }
+
+ public String getPackageName()
+ {
+ return packageName;
+ }
+
+ public void setPackageName(String packageName)
+ {
+ this.packageName = packageName;
+ }
+
+}
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/xsd/PackageSchemaGenerator.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/xsd/PackageSchemaGenerator.java 2009-03-14 21:54:58 UTC (rev 1997)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/xsd/PackageSchemaGenerator.java 2009-03-14 22:57:40 UTC (rev 1998)
@@ -42,7 +42,7 @@
* that have had their files compiled.
*
* @author Nicklas Karlsson
- *
+ *
*/
@SupportedSourceVersion(SourceVersion.RELEASE_6)
@SupportedAnnotationTypes("*")
@@ -55,25 +55,25 @@
public synchronized void init(ProcessingEnvironment processingEnv)
{
super.init(processingEnv);
- helper = new XSDHelper(processingEnv);
+ helper = new XSDHelper(processingEnv.getFiler());
}
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv)
{
List<ClassModel> workingSet = new ArrayList<ClassModel>();
- // Iterates over the classes compiled, creates a model of the classes and add them
- // to a working set
+ // Iterates over the classes compiled, creates a model of the classes and
+ // add them to a working set
for (Element element : roundEnv.getRootElements())
{
workingSet.add(inspectClass(element));
}
if (!roundEnv.processingOver())
{
- // Update the packge XSDs for the files changed
- helper.updatePackageXSDs(workingSet);
+ // Update the package XSDs for the files changed
+ helper.updateSchemas(workingSet);
// And flush the changes to disk
- helper.flushPackageXSDs();
+ helper.writeSchemas();
}
return false;
}
@@ -95,7 +95,8 @@
inspectClass(((DeclaredType) typeElement.getSuperclass()).asElement());
}
- // Gets the parent from the cache. We know it's there since we has scanned the
+ // Gets the parent from the cache. We know it's there since we has scanned
+ // the
// hierarchy already
ClassModel parent = helper.getCachedClassModel(typeElement.getSuperclass().toString());
// Populate the class level info (name, parent etc)
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/xsd/helpers/XSDHelper.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/xsd/helpers/XSDHelper.java 2009-03-14 21:54:58 UTC (rev 1997)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/xsd/helpers/XSDHelper.java 2009-03-14 22:57:40 UTC (rev 1998)
@@ -20,158 +20,110 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
-import java.util.Map.Entry;
+import java.util.Set;
-import javax.annotation.processing.ProcessingEnvironment;
+import javax.annotation.processing.Filer;
import javax.tools.StandardLocation;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
-import org.dom4j.Namespace;
import org.dom4j.Node;
-import org.dom4j.QName;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.SAXReader;
import org.dom4j.io.XMLWriter;
+import org.jboss.webbeans.xsd.PackageInfo;
import org.jboss.webbeans.xsd.model.ClassModel;
-import org.xml.sax.SAXException;
/**
* Helper for XSD related operations
*
* @author Nicklas Karlsson
- *
+ *
*/
public class XSDHelper
{
- // The annotation processing environment
- private ProcessingEnvironment processingEnvironment;
+ public 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 filed of the annotation processing environment
+ private Filer filer;
// 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, Document> packageXSDs = new HashMap<String, Document>();
+ private Map<String, PackageInfo> packageInfoMap = new HashMap<String, PackageInfo>();
/**
* Creates a new helper
*
- * @param processingEnvironment The processing environment
+ * @param filer The filer of the processing environment
*/
- public XSDHelper(ProcessingEnvironment processingEnvironment)
+ public XSDHelper(Filer filer)
{
- this.processingEnvironment = processingEnvironment;
+ this.filer = filer;
}
/**
- * Updates the XSD for the affected packages
+ * Reads package info
*
- * @param classModels The list of class models in the batch
+ * @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
*/
- public void updatePackageXSDs(List<ClassModel> classModels)
+ private PackageInfo readPackageInfo(String packageName) throws DocumentException, IOException
{
- for (ClassModel classModel : classModels)
- {
- Document packageXSD = getPackageXSD(classModel.getPackage());
- updateClass(packageXSD, classModel);
- }
+ PackageInfo packageInfo = new PackageInfo(packageName);
+ packageInfo.setNamespaces(readNamespaces(packageName));
+ Document schema = readSchema(packageName);
+ packageInfo.setSchema(schema != null ? schema : createSchema(packageName));
+ return packageInfo;
}
/**
- * Writes the XSD documents back to disk
+ * Reads the namespaces for a package
+ *
+ * @param packageName The name of the package
+ * @return The namespaces
*/
- public void flushPackageXSDs()
+ private List<String> readNamespaces(String packageName)
{
- for (Entry<String, Document> entry : packageXSDs.entrySet())
- {
- try
- {
- writePackageXSD(entry.getKey(), entry.getValue());
- }
- catch (IOException e)
- {
- throw new RuntimeException("Could not flush XSD for " + entry.getKey());
- }
- catch (SAXException e)
- {
- throw new RuntimeException("Could not parse XSD when flushing for " + entry.getKey());
- }
- }
+ // TODO dummy
+ return new ArrayList<String>();
}
/**
- * Gets the XSD document for a package
+ * Creates a new schema document
*
- * @param packageName The package name of the XSD
+ * @param packageName The package name of the schema
* @return The document
*/
- private Document getPackageXSD(String packageName)
+ private Document createSchema(String packageName)
{
- // Tries to get the document from the cache
- Document packageXSD = packageXSDs.get(packageName);
- if (packageXSD == null)
- {
- // If this is the first modification to a package
- try
- {
- // Read it from disk
- packageXSD = readPackageXSD(packageName);
- }
- catch (IOException e)
- {
- throw new RuntimeException("Could not read schema for package " + packageName);
- }
- catch (DocumentException e)
- {
- throw new RuntimeException("Could not parse schema for package " + packageName);
- }
- // If it was not on disk
- if (packageXSD == null)
- {
- // Create a new document
- packageXSD = createPackageXSD(packageName);
- }
- // And cache it
- packageXSDs.put(packageName, packageXSD);
- }
+ Document packageXSD = DocumentHelper.createDocument();
+ packageXSD.addElement("Package");
return packageXSD;
}
/**
- * Updates a package XSD with XSD from a file model
+ * Reads a schema for a package
*
- * @param packageXSD The package XSD
- * @param classModel The class model
- */
- private void updateClass(Document packageXSD, ClassModel classModel)
- {
- Node oldClassModel = packageXSD.selectSingleNode("//" + classModel.getSimpleName());
- if (oldClassModel != null)
- {
- // Remove the old class definition
- packageXSD.getRootElement().remove(oldClassModel);
- }
- // Create a new one
- packageXSD.getRootElement().addElement(classModel.getSimpleName());
- }
-
- /**
- * Read the package XSD for a package
- *
* @param packageName The package name
- *
- * @return The document
- * @throws IOException If a file could not be read
- * @throws DocumentException If a document could not be parsed
+ * @return The schema document
+ * @throws DocumentException If the document could not be parsed
+ * @throws IOException If the document could not be read
*/
- private Document readPackageXSD(String packageName) throws IOException, DocumentException
+ private Document readSchema(String packageName) throws DocumentException, IOException
{
InputStream in = null;
try
{
- in = processingEnvironment.getFiler().getResource(StandardLocation.CLASS_OUTPUT, packageName, "schema.xsd").openInputStream();
+ in = filer.getResource(StandardLocation.CLASS_OUTPUT, packageName, "schema.xsd").openInputStream();
return new SAXReader().read(in);
}
catch (IOException e)
@@ -188,48 +140,50 @@
}
/**
- * Creates a new XSD document for a package
+ * Writes package info to the disk
*
- * @param packageName The name of the package
- * @return The document
+ * @param packageInfo The package info to store
*/
- private Document createPackageXSD(String packageName)
+ private void writePackageInfo(PackageInfo packageInfo)
{
- Document packageXSD = DocumentHelper.createDocument();
-
- packageXSD.addElement(new QName("Package", new Namespace(getShortName(packageName), "urn:java:" + packageName)));
- return packageXSD;
+ try
+ {
+ writeSchema(packageInfo.getPackageName(), packageInfo.getSchema());
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException("Could not write schema for " + packageInfo.getPackageName());
+ }
+ writeNamespaces(packageInfo.getPackageName(), packageInfo.getNamespaces());
}
/**
- * Gets the short name of a package (the last part)
+ * Writes the namespaces to disk
*
* @param packageName The package name
- * @return A short name
+ * @param namespaces The namespaces
*/
- private String getShortName(String packageName)
+ private void writeNamespaces(String packageName, List<String> namespaces)
{
- int lastDot = packageName.lastIndexOf(".");
- return lastDot < 0 ? packageName : packageName.substring(lastDot + 1);
+ // TODO dummy
}
/**
- * Writes a package XSD back to disk
+ * Writes a schema to disk
*
- * @param packageName The name of the package
- * @param packageXSD The document
- * @throws IOException If the file could not be written
- * @throws SAXException If the document was badly formatted
+ * @param packageName The package name
+ * @param schema The schema
+ * @throws IOException If the file could not be written
*/
- private void writePackageXSD(String packageName, Document packageXSD) throws IOException, SAXException
+ private void writeSchema(String packageName, Document schema) throws IOException
{
OutputStream out = null;
try
{
OutputFormat format = OutputFormat.createPrettyPrint();
- out = processingEnvironment.getFiler().createResource(StandardLocation.CLASS_OUTPUT, packageName, "schema.xsd").openOutputStream();
+ out = filer.createResource(StandardLocation.CLASS_OUTPUT, packageName, "schema.xsd").openOutputStream();
XMLWriter writer = new XMLWriter(out, format);
- writer.write(packageXSD);
+ writer.write(schema);
writer.flush();
writer.close();
}
@@ -243,8 +197,78 @@
}
/**
- * Gets a cached class model
+ * 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();
+ PackageInfo packageInfo = packageInfoMap.get(packageName);
+ if (packageInfo == null) {
+ try
+ {
+ packageInfo = readPackageInfo(packageName);
+ }
+ catch (DocumentException e)
+ {
+ throw new RuntimeException("Could not parse schema for package " + packageName);
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException("Could not read schema for package " + packageName);
+ }
+ packageInfoMap.put(packageName, packageInfo);
+ }
+ updateClassInSchema(classModel, packageInfo.getSchema());
+ }
+ }
+
+ /**
+ * Writes the schemas back to disk
+ */
+ public void writeSchemas()
+ {
+ for (PackageInfo packageInfo : packageInfoMap.values()) {
+ writePackageInfo(packageInfo);
+ }
+ }
+
+ /**
+ * Updates a schema with XSD from a file model
+ *
+ * @param schema The schema
+ * @param classModel The class model
+ */
+ private void updateClassInSchema(ClassModel classModel, Document schema)
+ {
+ Node oldClassModel = schema.selectSingleNode("//" + classModel.getSimpleName());
+ if (oldClassModel != null)
+ {
+ // Remove the old class definition
+ schema.getRootElement().remove(oldClassModel);
+ }
+ // Create a new one
+ schema.getRootElement().addElement(classModel.getSimpleName());
+ }
+
+ /**
+ * Gets the short name of a package (the last part)
+ *
+ * @param packageName The package name
+ * @return A short name
+ */
+ private String getShortName(String packageName)
+ {
+ int lastDot = packageName.lastIndexOf(".");
+ return lastDot < 0 ? packageName : packageName.substring(lastDot + 1);
+ }
+
+ /**
+ * Gets a cached class model
+ *
* @param FQN The FQN of the class
* @return The class model (or null if not cached)
*/
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/xsd/model/ClassModel.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/xsd/model/ClassModel.java 2009-03-14 21:54:58 UTC (rev 1997)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/xsd/model/ClassModel.java 2009-03-14 22:57:40 UTC (rev 1998)
@@ -26,7 +26,7 @@
* A model of a class
*
* @author Nicklas Karlsson
- *
+ *
*/
public class ClassModel extends NamedModel
{
@@ -131,8 +131,8 @@
}
/**
- * Gets the merged hierarchy of available constructors. Returns the constructors
- * of this class since constructors aren't inherited
+ * Gets the merged hierarchy of available constructors. Returns the
+ * constructors of this class since constructors aren't inherited
*
* @return The set of constructors available
*/
@@ -193,7 +193,31 @@
currentParent = currentParent.getParent();
}
return mergedMethods;
+ }
+ public Set<String> getReferencedTypes()
+ {
+ Set<String> types = new HashSet<String>();
+ for (FieldModel field : getMergedFields())
+ {
+ types.add(field.getType());
+ }
+ for (MethodModel method : getMergedMethods())
+ {
+ types.add(method.getReturnType());
+ for (ParameterModel parameter : method.getParameters())
+ {
+ types.add(parameter.getType());
+ }
+ }
+ for (MethodModel constructor : getMergedConstructors())
+ {
+ for (ParameterModel parameter : constructor.getParameters())
+ {
+ types.add(parameter.getType());
+ }
+ }
+ return types;
}
}
15 years, 10 months