1 28 29 package org.jibx.binding.model; 30 31 import org.jibx.runtime.ITrackSource; 32 import org.jibx.runtime.ValidationException; 33 34 41 42 public class ValidationProblem 43 { 44 public static final int WARNING_LEVEL = 0; 46 public static final int ERROR_LEVEL = 1; 47 public static final int FATAL_LEVEL = 2; 48 49 50 private final int m_severity; 51 52 53 private final String m_description; 54 55 56 private final Object m_component; 57 58 66 ValidationProblem(int level, String msg, Object obj) { 67 m_severity = level; 68 if (obj == null) { 69 m_description = msg; 70 } else { 71 m_description = msg + " for " + componentDescription(obj); 72 } 73 m_component = obj; 74 } 75 76 81 public static String componentDescription(Object obj) { 82 StringBuffer buff = new StringBuffer (); 83 if (obj instanceof ElementBase) { 84 buff.append(ElementBase.ELEMENT_NAMES[((ElementBase)obj).type()]); 85 buff.append(" element"); 86 } else { 87 String cname = obj.getClass().getName(); 88 int split = cname.lastIndexOf('.'); 89 if (split >= 0) { 90 cname = cname.substring(split+1); 91 } 92 buff.append(cname); 93 } 94 if (obj instanceof ITrackSource) { 95 buff.append(" at "); 96 buff.append(ValidationException.describe(obj)); 97 } else { 98 buff.append(" at unknown location"); 99 } 100 return buff.toString(); 101 } 102 103 109 ValidationProblem(String msg, Object obj) { 110 this(ERROR_LEVEL, msg, obj); 111 } 112 113 118 public Object getComponent() { 119 return m_component; 120 } 121 122 127 public String getDescription() { 128 return m_description; 129 } 130 131 136 public int getSeverity() { 137 return m_severity; 138 } 139 } | Popular Tags |