Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposed fix for Issue #81 (deprecated constructor always throws an exception) #101

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 39 additions & 12 deletions src/main/java/ognl/OgnlContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ public class OgnlContext extends Object implements Map

/**
* Constructs a new OgnlContext with the given class resolver, type converter and member access.
* If any of these parameters is null the default will be used.
* If any of these parameters is null the default will be used, except <span class="strong">memberAccess which must be non-null</span>.
*
* @param classResolver the ClassResolver for a new OgnlContext.
* @param typeConverter the TypeConverter for a new OgnlContext.
* @param memberAccess the MemberAccess for a new OgnlContext.
* @param memberAccess the MemberAccess for a new OgnlContext. <span class="strong">Must be non-null</span>.
*/
public OgnlContext(ClassResolver classResolver, TypeConverter typeConverter, MemberAccess memberAccess)
{
Expand All @@ -115,19 +115,22 @@ public OgnlContext(ClassResolver classResolver, TypeConverter typeConverter, Mem
}

/**
* @deprecated use on of the constructors which require {@link MemberAccess}, this one can be removed soon
* Constructs a new OgnlContext with the given member access, class resolver, type converter and values.
* If any of these parameters is null the default will be used, except <span class="strong">memberAccess which must be non-null</span>.
*
* @param memberAccess the MemberAccess for a new OgnlContext. <span class="strong">Must be non-null</span>.
* @param classResolver the ClassResolver for a new OgnlContext.
* @param typeConverter the TypeConverter for a new OgnlContext.
* @param values the Map of values to provide for a new OgnlContext.
*/
@Deprecated
public OgnlContext(Map values)
{
// nulls will prevent overriding the default class resolver, type converter and member access
this(null, null, null, values);
}

public OgnlContext(MemberAccess memberAccess, ClassResolver classResolver, TypeConverter typeConverter, Map values)
{
super();
this._values = values;
if (values != null) {
this._values = values;
} else {
this._values = new HashMap(23); // No 'values' map has been specified, so we create one of the default size: 23 entries
}
if (classResolver != null) {
this._classResolver = classResolver;
} else {
Expand All @@ -141,17 +144,27 @@ public OgnlContext(MemberAccess memberAccess, ClassResolver classResolver, TypeC
if (memberAccess != null) {
this._memberAccess = memberAccess;
} else {
throw new RuntimeException("MemberAccess implementation must be provided!");
throw new IllegalArgumentException("MemberAccess implementation must be provided - null not permitted!");
}
}

/**
* Set (put) the provided value map content into the existing values Map for this OgnlContext.
*
* @param value a Map of additional values to put into this OgnlContext.
*/
public void setValues(Map value)
{
for (Object k : value.keySet()) {
_values.put(k, value.get(k));
}
}

/**
* Get the values Map for this OgnlContext.
*
* @return Map of values for this OgnlContext.
*/
public Map getValues()
{
return _values;
Expand Down Expand Up @@ -477,26 +490,31 @@ public Map getLocalReferences()
}

/* ================= Map interface ================= */
@Override
public int size()
{
return _values.size();
}

@Override
public boolean isEmpty()
{
return _values.isEmpty();
}

@Override
public boolean containsKey(Object key)
{
return _values.containsKey(key);
}

@Override
public boolean containsValue(Object value)
{
return _values.containsValue(value);
}

@Override
public Object get(Object key)
{
Object result;
Expand Down Expand Up @@ -529,6 +547,7 @@ public Object get(Object key)
return result;
}

@Override
public Object put(Object key, Object value)
{
Object result;
Expand Down Expand Up @@ -567,6 +586,7 @@ public Object put(Object key, Object value)
return result;
}

@Override
public Object remove(Object key)
{
Object result;
Expand Down Expand Up @@ -604,13 +624,15 @@ public Object remove(Object key)
return result;
}

@Override
public void putAll(Map t)
{
for (Object k : t.keySet()) {
put(k, t.get(k));
}
}

@Override
public void clear()
{
_values.clear();
Expand All @@ -631,29 +653,34 @@ public void clear()
setCurrentNode(null);
}

@Override
public Set keySet()
{
/* Should root, currentObject, classResolver, typeConverter & memberAccess be included here? */
return _values.keySet();
}

@Override
public Collection values()
{
/* Should root, currentObject, classResolver, typeConverter & memberAccess be included here? */
return _values.values();
}

@Override
public Set entrySet()
{
/* Should root, currentObject, classResolver, typeConverter & memberAccess be included here? */
return _values.entrySet();
}

@Override
public boolean equals(Object o)
{
return _values.equals(o);
}

@Override
public int hashCode()
{
return _values.hashCode();
Expand Down