001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.kernel.servlet;
016    
017    import javax.servlet.http.HttpServletRequest;
018    
019    /**
020     * @author Igor Spasic
021     */
022    public class NonSerializableObjectRequestWrapper extends
023            PersistentHttpServletRequestWrapper {
024    
025            public static boolean isWrapped(HttpServletRequest request) {
026                    Boolean wrapped = (Boolean)request.getAttribute(
027                            NonSerializableObjectRequestWrapper.class.getName());
028    
029                    if (wrapped == null) {
030                            return false;
031                    }
032    
033                    return wrapped.booleanValue();
034            }
035    
036            public NonSerializableObjectRequestWrapper(HttpServletRequest request) {
037                    super(request);
038    
039                    request.setAttribute(
040                            NonSerializableObjectRequestWrapper.class.getName(), Boolean.TRUE);
041            }
042    
043            @Override
044            public Object getAttribute(String name) {
045                    Object object = super.getAttribute(name);
046    
047                    object = NonSerializableObjectHandler.getValue(object);
048    
049                    return object;
050            }
051    
052            @Override
053            public void setAttribute(String name, Object object) {
054                    object = new NonSerializableObjectHandler(object);
055    
056                    super.setAttribute(name, object);
057            }
058    
059    }