Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start work on bean ordering for deployer
git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@2132 1c488680-804c-0410-94cd-c6b725194a0e
- Loading branch information
Showing
17 changed files
with
397 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
impl/src/main/java/org/jboss/webbeans/bootstrap/BootstrapOrderingBeanComparator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
package org.jboss.webbeans.bootstrap; | ||
|
||
import java.util.Comparator; | ||
|
||
import org.jboss.webbeans.bean.AbstractClassBean; | ||
import org.jboss.webbeans.bean.AbstractProducerBean; | ||
import org.jboss.webbeans.bean.NewBean; | ||
import org.jboss.webbeans.bean.RIBean; | ||
import org.jboss.webbeans.bean.standard.AbstractStandardBean; | ||
|
||
public class BootstrapOrderingBeanComparator implements Comparator<RIBean<?>> | ||
{ | ||
|
||
public int compare(RIBean<?> o1, RIBean<?> o2) | ||
{ | ||
if (o1 instanceof AbstractStandardBean && !(o2 instanceof AbstractStandardBean)) | ||
{ | ||
return -1; | ||
} | ||
else if (!(o1 instanceof AbstractStandardBean) && o2 instanceof AbstractStandardBean) | ||
{ | ||
return 1; | ||
} | ||
else if (o1 instanceof AbstractStandardBean && o2 instanceof AbstractStandardBean) | ||
{ | ||
return o1.getId().compareTo(o2.getId()); | ||
} | ||
else if (o1.getType().getName().startsWith("org.jboss.webbeans") && !o2.getType().getName().startsWith("org.jboss.webbeans")) | ||
{ | ||
return -1; | ||
} | ||
else if (!o1.getType().getName().startsWith("org.jboss.webbeans") && o2.getType().getName().startsWith("org.jboss.webbeans")) | ||
{ | ||
return 1; | ||
} | ||
else if (o1 instanceof AbstractClassBean) | ||
{ | ||
AbstractClassBean<?> b1 = (AbstractClassBean<?>) o1; | ||
if (o2 instanceof NewBean && !(o1 instanceof NewBean)) | ||
{ | ||
// Always initialize new beans after class beans | ||
return -1; | ||
} | ||
else if (o1 instanceof NewBean && o2 instanceof AbstractClassBean && !(o2 instanceof NewBean)) | ||
{ | ||
// Always initialize new beans after class beans | ||
return 1; | ||
} | ||
else if (o1 instanceof NewBean && !(o2 instanceof NewBean)) | ||
{ | ||
// Always initialize new class beans after class beans but before other beans | ||
return -1; | ||
} | ||
else if (o1 instanceof NewBean && o2 instanceof NewBean) | ||
{ | ||
return o1.getId().compareTo(o2.getId()); | ||
} | ||
else if (o2 instanceof AbstractClassBean) | ||
{ | ||
AbstractClassBean<?> b2 = (AbstractClassBean<?>) o2; | ||
if (o1.getTypes().contains(b2.getType())) | ||
{ | ||
return 1; | ||
} | ||
else if (b2.getTypes().contains(b1.getType())) | ||
{ | ||
return -1; | ||
} | ||
else | ||
{ | ||
return o1.getId().compareTo(o2.getId()); | ||
} | ||
} | ||
else if (o2 instanceof AbstractProducerBean) | ||
{ | ||
// Producer beans are always initialized after class beans | ||
return -1; | ||
} | ||
else | ||
{ | ||
// Ordering doesn't matter | ||
return o1.getId().compareTo(o2.getId()); | ||
} | ||
} | ||
else if (o1 instanceof AbstractProducerBean) | ||
{ | ||
AbstractProducerBean<?, ?> b1 = (AbstractProducerBean<?, ?>) o1; | ||
if (o2 instanceof NewBean) | ||
{ | ||
// Always initialize producers beans after new beans | ||
return 1; | ||
} | ||
else if (o2 instanceof AbstractClassBean) | ||
{ | ||
if (b1.getDeclaringBean().equals(o2)) | ||
{ | ||
return 1; | ||
} | ||
else | ||
{ | ||
return o1.getId().compareTo(o2.getId()); | ||
} | ||
} | ||
else | ||
{ | ||
// Ordering doesn't matter | ||
return o1.getId().compareTo(o2.getId()); | ||
} | ||
} | ||
else | ||
{ | ||
if (o2 instanceof AbstractClassBean || o2 instanceof AbstractProducerBean) | ||
{ | ||
// Initialize undefined ordering after defined ordering | ||
return 1; | ||
} | ||
else | ||
{ | ||
return o1.getId().compareTo(o2.getId()); | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.acme; | ||
|
||
public class RoadRunner | ||
{ | ||
|
||
} |
6 changes: 6 additions & 0 deletions
6
tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/Animal.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package org.jboss.webbeans.test.unit.bootstrap.ordering; | ||
|
||
interface Animal | ||
{ | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/Cow.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.jboss.webbeans.test.unit.bootstrap.ordering; | ||
|
||
import javax.context.ApplicationScoped; | ||
|
||
@ApplicationScoped | ||
class Cow implements Animal | ||
{ | ||
|
||
public static boolean mooed = false; | ||
|
||
public void moo() | ||
{ | ||
mooed = true; | ||
} | ||
|
||
} |
Oops, something went wrong.