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