KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > triactive > jdo > model > ClassMetaDataFlagMismatchException


1 /*
2  * Copyright 2002 (C) TJDO.
3  * All rights reserved.
4  *
5  * This software is distributed under the terms of the TJDO License version 1.0.
6  * See the terms of the TJDO License in the documentation provided with this software.
7  *
8  * $Id: ClassMetaDataFlagMismatchException.java,v 1.4 2002/11/08 05:06:22 jackknifebarber Exp $
9  */

10
11 package com.triactive.jdo.model;
12
13 import javax.jdo.spi.JDOImplHelper;
14 import javax.jdo.spi.PersistenceCapable;
15
16
17 /**
18  * A <tt>ClassMetaDataFlagMismatchException</tt> is thrown if the flag of a
19  * persistent field of an enhanced class does not match what would be
20  * expected based on the corresponding JDO metadata.
21  *
22  * @author <a HREF="mailto:mmartin5@austin.rr.com">Mike Martin</a>
23  * @version $Revision: 1.4 $
24  *
25  * @see ClassMetaData
26  */

27
28 public class ClassMetaDataFlagMismatchException extends ClassMetaDataMismatchException
29 {
30     /**
31      * Constructs a class metadata flag mismatch exception.
32      *
33      * @param clazz The enhanced class whose metadata does not match.
34      * @param fieldNumber The field number whose flag mismatched.
35      * @param expectedFlag The expected flag value.
36      * @param actualFlag The actual flag value.
37      */

38
39     public ClassMetaDataFlagMismatchException(Class JavaDoc clazz, int fieldNumber, byte expectedFlag, byte actualFlag)
40     {
41         super(clazz, " field #" + fieldNumber + " (" + getFieldName(clazz, fieldNumber) + ") has flag " +
42               getFlagName(actualFlag) + " but the metadata indicates it should be " + getFlagName(expectedFlag));
43     }
44
45     private static String JavaDoc getFlagName(byte flag)
46     {
47         switch (flag)
48         {
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 | PersistenceCapable.CHECK_WRITE:
54                 return "CHECK_READ | CHECK_WRITE (default fetch group)";
55             case PersistenceCapable.MEDIATE_READ | PersistenceCapable.MEDIATE_WRITE:
56                 return "MEDIATE_READ | MEDIATE_WRITE (non-default fetch group)";
57             default:
58                 return "unknown (" + flag + ")";
59         }
60     }
61
62     private final static String JavaDoc getFieldName(Class JavaDoc clazz, int fieldNumber)
63     {
64         String JavaDoc[] names = JDOImplHelper.getInstance().getFieldNames(clazz);
65         return (null != names) ? names[fieldNumber] : null;
66     }
67 }
68
Popular Tags