gt: 		if (obj instanceof BaseModel<?>) {
context: /**
   * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
   *
   * The contents of this file are subject to the terms of the Liferay Enterprise
   * Subscription License ("License"). You may not use this file except in
   * compliance with the License. You can obtain a copy of the License by
   * contacting Liferay, Inc. See the License for the specific language governing
   * permissions and limitations under the License, including but not limited to
   * distribution rights of the Software.
   *
   *
   *
   */
  
  package com.rivetlogic.suggestionbox.service;
  
  import com.liferay.portal.kernel.exception.PortalException;
  import com.liferay.portal.kernel.exception.SystemException;
  import com.liferay.portal.kernel.io.unsync.UnsyncByteArrayInputStream;
  import com.liferay.portal.kernel.io.unsync.UnsyncByteArrayOutputStream;
  import com.liferay.portal.kernel.log.Log;
  import com.liferay.portal.kernel.log.LogFactoryUtil;
  import com.liferay.portal.kernel.util.ClassLoaderObjectInputStream;
  import com.liferay.portal.kernel.util.PropsUtil;
  import com.liferay.portal.kernel.util.Validator;
  import com.liferay.portal.model.BaseModel;
  
  import com.rivetlogic.suggestionbox.model.SuggestionClp;
  
  import java.io.ObjectInputStream;
  import java.io.ObjectOutputStream;
  
  import java.lang.reflect.Method;
  
  import java.util.ArrayList;
  import java.util.List;
  
  /**
   * @author Manrique Varela
   */
  public class ClpSerializer {
  	public static String getServletContextName() {
  		if (Validator.isNotNull(_servletContextName)) {
  			return _servletContextName;
  		}
  
  		synchronized (ClpSerializer.class) {
  			if (Validator.isNotNull(_servletContextName)) {
  				return _servletContextName;
  			}
  
  			try {
  				ClassLoader classLoader = ClpSerializer.class.getClassLoader();
  
  				Class<?> portletPropsClass = classLoader.loadClass(
  						"com.liferay.util.portlet.PortletProps");
  
  				Method getMethod = portletPropsClass.getMethod("get",
  						new Class<?>[] { String.class });
  
  				String portletPropsServletContextName = (String)getMethod.invoke(null,
  						"suggestion-box-portlet-deployment-context");
  
  				if (Validator.isNotNull(portletPropsServletContextName)) {
  					_servletContextName = portletPropsServletContextName;
  				}
  			}
  			catch (Throwable t) {
  				if (_log.isInfoEnabled()) {
  					_log.info(
  						"Unable to locate deployment context from portlet properties");
  				}
  			}
  
  			if (Validator.isNull(_servletContextName)) {
  				try {
  					String propsUtilServletContextName = PropsUtil.get(
  							"suggestion-box-portlet-deployment-context");
  
  					if (Validator.isNotNull(propsUtilServletContextName)) {
  						_servletContextName = propsUtilServletContextName;
  					}
  				}
  				catch (Throwable t) {
  					if (_log.isInfoEnabled()) {
  						_log.info(
  							"Unable to locate deployment context from portal properties");
  					}
  				}
  			}
  
  			if (Validator.isNull(_servletContextName)) {
  				_servletContextName = "suggestion-box-portlet";
  			}
  
  			return _servletContextName;
  		}
  	}
  
  	public static Object translateInput(BaseModel<?> oldModel) {
  		Class<?> oldModelClass = oldModel.getClass();
  
  		String oldModelClassName = oldModelClass.getName();
  
  		if (oldModelClassName.equals(SuggestionClp.class.getName())) {
  			return translateInputSuggestion(oldModel);
  		}
  
  		return oldModel;
  	}
  
  	public static Object translateInput(List<Object> oldList) {
  		List<Object> newList = new ArrayList<Object>(oldList.size());
  
  		for (int i = 0; i < oldList.size(); i++) {
  			Object curObj = oldList.get(i);
  
  			newList.add(translateInput(curObj));
  		}
  
  		return newList;
  	}
  
  	public static Object translateInputSuggestion(BaseModel<?> oldModel) {
  		SuggestionClp oldClpModel = (SuggestionClp)oldModel;
  
  		BaseModel<?> newModel = oldClpModel.getSuggestionRemoteModel();
  
  		newModel.setModelAttributes(oldClpModel.getModelAttributes());
  
  		return newModel;
  	}
  
  	public static Object translateInput(Object obj) {
  		if (obj instanceof BaseModel<?>) {
  			return translateInput((BaseModel<?>)obj);
  		}
  		else if (obj instanceof List<?>) {
  			return translateInput((List<Object>)obj);
  		}
  		else {
  			return obj;
  		}
  	}
  
  	public static Object translateOutput(BaseModel<?> oldModel) {
  		Class<?> oldModelClass = oldModel.getClass();
  
  		String oldModelClassName = oldModelClass.getName();
  
  		if (oldModelClassName.equals(
  					"com.rivetlogic.suggestionbox.model.impl.SuggestionImpl")) {
  			return translateOutputSuggestion(oldModel);
  		}
  		else if (oldModelClassName.endsWith("Clp")) {
  			try {
  				ClassLoader classLoader = ClpSerializer.class.getClassLoader();
  
  				Method getClpSerializerClassMethod = oldModelClass.getMethod(
  						"getClpSerializerClass");
  
  				Class<?> oldClpSerializerClass = (Class<?>)getClpSerializerClassMethod.invoke(oldModel);
  
  				Class<?> newClpSerializerClass = classLoader.loadClass(oldClpSerializerClass.getName());
  
  				Method translateOutputMethod = newClpSerializerClass.getMethod("translateOutput",
  						BaseModel.class);
  
  				Class<?> oldModelModelClass = oldModel.getModelClass();
  
  				Method getRemoteModelMethod = oldModelClass.getMethod("get" +
  						oldModelModelClass.getSimpleName() + "RemoteModel");
  
  				Object oldRemoteModel = getRemoteModelMethod.invoke(oldModel);
  
  				BaseModel<?> newModel = (BaseModel<?>)translateOutputMethod.invoke(null,
  						oldRemoteModel);
  
  				return newModel;
  			}
  			catch (Throwable t) {
  				if (_log.isInfoEnabled()) {
  					_log.info("Unable to translate " + oldModelClassName, t);
  				}
  			}
  		}
  
  		return oldModel;
  	}
  
  	public static Object translateOutput(List<Object> oldList) {
  		List<Object> newList = new ArrayList<Object>(oldList.size());
  
  		for (int i = 0; i < oldList.size(); i++) {
  			Object curObj = oldList.get(i);
  
  			newList.add(translateOutput(curObj));
  		}
  
  		return newList;
  	}
  
  	public static Object translateOutput(Object obj) {
  