01: /*
02: * Copyright 2002 (C) TJDO.
03: * All rights reserved.
04: *
05: * This software is distributed under the terms of the TJDO License version 1.0.
06: * See the terms of the TJDO License in the documentation provided with this software.
07: *
08: * $Id: ClassMetaDataFlagMismatchException.java,v 1.4 2002/11/08 05:06:22 jackknifebarber Exp $
09: */
10:
11: package com.triactive.jdo.model;
12:
13: import javax.jdo.spi.JDOImplHelper;
14: import javax.jdo.spi.PersistenceCapable;
15:
16: /**
17: * A <tt>ClassMetaDataFlagMismatchException</tt> is thrown if the flag of a
18: * persistent field of an enhanced class does not match what would be
19: * expected based on the corresponding JDO metadata.
20: *
21: * @author <a href="mailto:mmartin5@austin.rr.com">Mike Martin</a>
22: * @version $Revision: 1.4 $
23: *
24: * @see ClassMetaData
25: */
26:
27: public class ClassMetaDataFlagMismatchException extends
28: ClassMetaDataMismatchException {
29: /**
30: * Constructs a class metadata flag mismatch exception.
31: *
32: * @param clazz The enhanced class whose metadata does not match.
33: * @param fieldNumber The field number whose flag mismatched.
34: * @param expectedFlag The expected flag value.
35: * @param actualFlag The actual flag value.
36: */
37:
38: public ClassMetaDataFlagMismatchException(Class clazz,
39: int fieldNumber, byte expectedFlag, byte actualFlag) {
40: super (clazz, " field #" + fieldNumber + " ("
41: + getFieldName(clazz, fieldNumber) + ") has flag "
42: + getFlagName(actualFlag)
43: + " but the metadata indicates it should be "
44: + getFlagName(expectedFlag));
45: }
46:
47: private static String getFlagName(byte flag) {
48: switch (flag) {
49: case PersistenceCapable.CHECK_WRITE:
50: return "CHECK_WRITE (transient transactional)";
51: case PersistenceCapable.MEDIATE_WRITE:
52: return "MEDIATE_WRITE (primary key part)";
53: case PersistenceCapable.CHECK_READ
54: | PersistenceCapable.CHECK_WRITE:
55: return "CHECK_READ | CHECK_WRITE (default fetch group)";
56: case PersistenceCapable.MEDIATE_READ
57: | PersistenceCapable.MEDIATE_WRITE:
58: return "MEDIATE_READ | MEDIATE_WRITE (non-default fetch group)";
59: default:
60: return "unknown (" + flag + ")";
61: }
62: }
63:
64: private final static String getFieldName(Class clazz,
65: int fieldNumber) {
66: String[] names = JDOImplHelper.getInstance().getFieldNames(
67: clazz);
68: return (null != names) ? names[fieldNumber] : null;
69: }
70: }
|