001/** 002 * GRANITE DATA SERVICES 003 * Copyright (C) 2006-2013 GRANITE DATA SERVICES S.A.S. 004 * 005 * This file is part of the Granite Data Services Platform. 006 * 007 * Granite Data Services is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * Granite Data Services is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 015 * General Public License for more details. 016 * 017 * You should have received a copy of the GNU Lesser General Public 018 * License along with this library; if not, write to the Free Software 019 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 020 * USA, or see <http://www.gnu.org/licenses/>. 021 */ 022package org.granite.tide.validators; 023 024import java.io.Externalizable; 025import java.io.IOException; 026import java.io.ObjectInput; 027import java.io.ObjectOutput; 028 029/** 030 * @author William DRAI 031 */ 032public class InvalidValue implements Externalizable { 033 034 private static final long serialVersionUID = 1L; 035 036 private final Object rootBean; 037 private final Object bean; 038 private final Class<?> beanClass; 039 private final String path; 040 private final Object value; 041 private final String message; 042 043 044 public InvalidValue(Object bean, String path, Object value, String message) { 045 if (bean == null || path == null) 046 throw new NullPointerException("bean and path parameters cannot be null"); 047 this.rootBean = bean; 048 this.bean = bean; 049 this.beanClass = bean.getClass(); 050 this.path = path; 051 this.value = value; 052 this.message = message; 053 } 054 055 public InvalidValue(Object rootBean, Object bean, String path, Object value, String message) { 056 if (bean == null || path == null) 057 throw new NullPointerException("bean and path parameters cannot be null"); 058 this.rootBean = rootBean; 059 this.bean = bean; 060 this.beanClass = bean.getClass(); 061 this.path = path; 062 this.value = value; 063 this.message = message; 064 } 065 066 public InvalidValue(Class<?> beanClass, String path, Object value, String message) { 067 if (beanClass == null || path == null) 068 throw new NullPointerException("beanClass and path parameters cannot be null"); 069 this.rootBean = null; 070 this.bean = null; 071 this.beanClass = beanClass; 072 this.path = path; 073 this.value = value; 074 this.message = message; 075 } 076 077 public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { 078 // write only bean... 079 } 080 081 public void writeExternal(ObjectOutput out) throws IOException { 082 out.writeObject(rootBean); 083 out.writeObject(bean); 084 out.writeObject(beanClass.getName()); 085 out.writeObject(path); 086 out.writeObject(value); 087 out.writeObject(message); 088 } 089}