revised expression parser API design
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.beans.factory.config;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Context object for evaluating an expression within a bean definition.
|
||||
@@ -32,6 +33,7 @@ public class BeanExpressionContext {
|
||||
|
||||
|
||||
public BeanExpressionContext(BeanFactory beanFactory, Scope scope) {
|
||||
Assert.notNull(beanFactory, "BeanFactory must not be null");
|
||||
this.beanFactory = beanFactory;
|
||||
this.scope = scope;
|
||||
}
|
||||
@@ -47,16 +49,37 @@ public class BeanExpressionContext {
|
||||
|
||||
public boolean containsObject(String key) {
|
||||
return (this.beanFactory.containsBean(key) ||
|
||||
this.scope.resolveContextualObject(key) != null);
|
||||
(this.scope != null && this.scope.resolveContextualObject(key) != null));
|
||||
}
|
||||
|
||||
public Object getObject(String key) {
|
||||
if (this.beanFactory.containsBean(key)) {
|
||||
return this.beanFactory.getBean(key);
|
||||
}
|
||||
else {
|
||||
else if (this.scope != null){
|
||||
return this.scope.resolveContextualObject(key);
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (this == other) {
|
||||
return true;
|
||||
}
|
||||
if (!(other instanceof BeanExpressionContext)) {
|
||||
return false;
|
||||
}
|
||||
BeanExpressionContext otherContext = (BeanExpressionContext) other;
|
||||
return (this.beanFactory == otherContext.beanFactory && this.scope == otherContext.scope);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.beanFactory.hashCode();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user