Index: RELEASE_NOTES.txt =================================================================== --- RELEASE_NOTES.txt (revision 611569) +++ RELEASE_NOTES.txt (working copy) @@ -1,5 +1,8 @@ Changes since 4.0 Alpha 6 +* [HTTPCORE-139] allow for a NULL object as parameter value + Contributed by Roland Weber + * [HTTPCORE-137] DefaultHttpRequestFactory extended to support all methods specified in RFC 2616 (except CONNECT). Contributed by Oleg Kalnichevski Index: module-main/src/main/java/org/apache/http/params/HttpParams.java =================================================================== --- module-main/src/main/java/org/apache/http/params/HttpParams.java (revision 611569) +++ module-main/src/main/java/org/apache/http/params/HttpParams.java (working copy) @@ -48,8 +48,9 @@ * @param name the parent name. * * @return an object that represents the value of the parameter, - * null if the parameter is not set or if it - * is explicitly set to null + * null or + * {@link NoParamValue#NULL NoParamValue.NULL} + * if the parameter is not set or if it is explicitly unset * * @see #setParameter(String, Object) */ Index: module-main/src/main/java/org/apache/http/params/HttpProtocolParams.java =================================================================== --- module-main/src/main/java/org/apache/http/params/HttpProtocolParams.java (revision 611569) +++ module-main/src/main/java/org/apache/http/params/HttpProtocolParams.java (working copy) @@ -69,7 +69,7 @@ } String charset = (String) params.getParameter (CoreProtocolPNames.HTTP_ELEMENT_CHARSET); - if (charset == null) { + if (NoParamValue.isNull(charset)) { charset = HTTP.DEFAULT_PROTOCOL_CHARSET; } return charset; @@ -97,7 +97,7 @@ } String charset = (String) params.getParameter (CoreProtocolPNames.HTTP_CONTENT_CHARSET); - if (charset == null) { + if (NoParamValue.isNull(charset)) { charset = HTTP.DEFAULT_CONTENT_CHARSET; } return charset; @@ -126,7 +126,7 @@ } Object param = params.getParameter (CoreProtocolPNames.PROTOCOL_VERSION); - if (param == null) { + if (NoParamValue.isNull(param)) { return HttpVersion.HTTP_1_1; } return (ProtocolVersion)param; Index: module-main/src/main/java/org/apache/http/params/AbstractHttpParams.java =================================================================== --- module-main/src/main/java/org/apache/http/params/AbstractHttpParams.java (revision 611569) +++ module-main/src/main/java/org/apache/http/params/AbstractHttpParams.java (working copy) @@ -55,7 +55,7 @@ public long getLongParameter(final String name, long defaultValue) { Object param = getParameter(name); - if (param == null) { + if (NoParamValue.isNull(param)) { return defaultValue; } return ((Long)param).longValue(); @@ -68,7 +68,7 @@ public int getIntParameter(final String name, int defaultValue) { Object param = getParameter(name); - if (param == null) { + if (NoParamValue.isNull(param)) { return defaultValue; } return ((Integer)param).intValue(); @@ -81,7 +81,7 @@ public double getDoubleParameter(final String name, double defaultValue) { Object param = getParameter(name); - if (param == null) { + if (NoParamValue.isNull(param)) { return defaultValue; } return ((Double)param).doubleValue(); @@ -94,7 +94,7 @@ public boolean getBooleanParameter(final String name, boolean defaultValue) { Object param = getParameter(name); - if (param == null) { + if (NoParamValue.isNull(param)) { return defaultValue; } return ((Boolean)param).booleanValue(); Index: module-main/src/main/java/org/apache/http/params/NoParamValue.java =================================================================== --- module-main/src/main/java/org/apache/http/params/NoParamValue.java (revision 0) +++ module-main/src/main/java/org/apache/http/params/NoParamValue.java (revision 0) @@ -0,0 +1,113 @@ +/* + * $HeadURL$ + * $Revision$ + * $Date$ + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + */ + +package org.apache.http.params; + +import java.io.Serializable; + + +/** + * Represents a non-existent parameter value. + * An instance of this class is used in cases where a parameter has to + * be set to null explicitly, for example to prevent lookup + * of the default in {@link DefaultedHttpParams}. + * + * @author Roland Weber + * + * + * + * @version $Revision$ + * + * @since 4.0 + */ +public final class NoParamValue implements Serializable { + + private static final long serialVersionUID = -7516119797774405949L; + + + /** The default instance of this class. */ + public final static NoParamValue NULL = new NoParamValue(); + + + /** Restricted default constructor. */ + private NoParamValue() { + // no body + } + + + /** + * Checks whether the argument is null or {@link #NULL}. + * + * @param value the value to check + * + * @return true if the argument is null + * or {@link #equals} {@link #NULL} + */ + public final static boolean isNull(Object value) { + return ((value == null) || NULL.equals(value)); + } + + + /** + * Obtains a string representation of this object. + * + * @return a string indicating {@link NoParamValue} + */ + public final String toString() { + return getClass().getName(); + } + + + /** + * Checks whether this object equals another one. + * All instances of this class are equal. This is for cases + * where deserialization creates additional instances. + * + * @param o the other object + * + * @return true if the argument is a {@link NoParamValue}, + * false otherwise + */ + public final boolean equals(Object o) { + return (o instanceof NoParamValue); + } + + + /** + * Obtains a hashcode for this object. + * + * @return the hash code + */ + public final int hashCode() { + return 0; + } + +} Property changes on: module-main/src/main/java/org/apache/http/params/NoParamValue.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Date Author Id Revision HeadURL Name: svn:eol-style + native