use of org.apache.aries.blueprint.di.CircularDependencyException in project aries by apache.
the class BlueprintRepository method push.
public void push(Recipe recipe) {
LinkedList<Recipe> list = stack.get();
if (list != null && list.contains(recipe)) {
ArrayList<Recipe> circularity = new ArrayList<Recipe>(list.subList(list.indexOf(recipe), list.size()));
// remove anonymous nodes from circularity list
for (Iterator<Recipe> iterator = circularity.iterator(); iterator.hasNext(); ) {
Recipe item = iterator.next();
if (item != recipe && item.getName() == null) {
iterator.remove();
}
}
// add ending node to list so a full circuit is shown
circularity.add(recipe);
throw new CircularDependencyException(circularity);
}
if (list == null) {
list = new LinkedList<Recipe>();
stack.set(list);
}
list.add(recipe);
}
use of org.apache.aries.blueprint.di.CircularDependencyException in project aries by apache.
the class WiringTest method testCircularPrototype.
public void testCircularPrototype() throws Exception {
BlueprintRepository repository = createBlueprintContainer().getRepository();
try {
repository.create("circularPrototypeDriver");
fail("Did not throw exception");
} catch (CircularDependencyException e) {
// that's what we expect
}
try {
repository.create("circularPrototype");
fail("Did not throw exception");
} catch (CircularDependencyException e) {
// that's what we expect
}
}
use of org.apache.aries.blueprint.di.CircularDependencyException in project aries by apache.
the class WiringTest method testRecursive.
public void testRecursive() throws Exception {
BlueprintRepository repository = createBlueprintContainer().getRepository();
try {
repository.create("recursiveConstructor");
fail("Did not throw exception");
} catch (ComponentDefinitionException e) {
if (e.getCause() instanceof CircularDependencyException) {
// that's what we expect
} else {
fail("Did not throw expected exception");
throw e;
}
}
PojoRecursive pojo;
pojo = (PojoRecursive) repository.create("recursiveSetter");
assertNotNull(pojo);
pojo = (PojoRecursive) repository.create("recursiveInitMethod");
assertNotNull(pojo);
}
use of org.apache.aries.blueprint.di.CircularDependencyException in project aries by apache.
the class ReflectionUtilsTest method before.
@BeforeClass
public static void before() throws ClassNotFoundException {
mockBlueprint = EasyMock.createNiceMock(ExtendedBlueprintContainer.class);
final Capture<String> nameCapture = new Capture<String>();
EasyMock.expect(mockBlueprint.loadClass(EasyMock.capture(nameCapture))).andAnswer(new IAnswer<Class<?>>() {
public Class<?> answer() throws Throwable {
return Thread.currentThread().getContextClassLoader().loadClass(nameCapture.getValue());
}
});
EasyMock.replay(mockBlueprint);
ExecutionContext.Holder.setContext(new ExecutionContext() {
public void addPartialObject(String name, Object object) {
}
public boolean containsObject(String name) {
return false;
}
public Object convert(Object value, ReifiedType type) throws Exception {
if (type.getRawClass().equals(Inconvertible.class))
throw new Exception();
else if (type.getRawClass().equals(String.class))
return String.valueOf(value);
else if (type.getRawClass().equals(List.class)) {
if (value == null)
return null;
else if (value instanceof Collection)
return new ArrayList((Collection) value);
else
throw new Exception();
} else if (value == null)
return null;
else if (type.getRawClass().isInstance(value))
return value;
else
throw new Exception();
}
public boolean canConvert(Object value, ReifiedType type) {
if (value instanceof Inconvertible)
return false;
else if (type.getRawClass().equals(String.class))
return true;
else if (type.getRawClass().equals(List.class) && (value == null || value instanceof Collection))
return true;
else
return false;
}
public Object getObject(String name) {
return null;
}
public Object getPartialObject(String name) {
return null;
}
public Recipe getRecipe(String name) {
return null;
}
public Class loadClass(String className) throws ClassNotFoundException {
return null;
}
public Recipe pop() {
return null;
}
public void push(Recipe recipe) throws CircularDependencyException {
}
public void removePartialObject(String name) {
}
public Future<Object> addFullObject(String name, Future<Object> object) {
return null;
}
});
}
use of org.apache.aries.blueprint.di.CircularDependencyException in project aries by apache.
the class DependencyGraph method findCircuit.
private void findCircuit(Node node, ArrayList<Recipe> stack) {
if (stack.contains(node.recipe)) {
ArrayList<Recipe> circularity = new ArrayList<Recipe>(stack.subList(stack.indexOf(node.recipe), stack.size()));
// remove anonymous nodes from circularity list
for (Iterator<Recipe> iterator = circularity.iterator(); iterator.hasNext(); ) {
Recipe recipe = iterator.next();
if (recipe != node.recipe && recipe.getName() == null) {
iterator.remove();
}
}
// add ending node to list so a full circuit is shown
circularity.add(node.recipe);
throw new CircularDependencyException(circularity);
}
stack.add(node.recipe);
for (Node reference : node.references) {
findCircuit(reference, stack);
}
}
Aggregations