001: /**
002: * Copyright (C) 2007 NetMind Consulting Bt.
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 3 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */package hu.netmind.persistence;
018:
019: import java.lang.reflect.Modifier;
020:
021: /**
022: * This class describes a persistable class. This is a finer grained
023: * thing than static classes, because the library allows for dynamic
024: * classes (classnames) to be created. So an unambigous description of
025: * a persistable class is it's class, and the dynamic name.
026: * @author Brautigam Robert
027: * @version Revision: $Revision$
028: */
029: public class ClassEntry {
030: private Class clazz;
031: private String dynamicName;
032: private String fullName;
033:
034: public ClassEntry(Class clazz, String dynamicName) {
035: this .clazz = clazz;
036: this .dynamicName = dynamicName;
037: if ((!DynamicObject.class.isAssignableFrom(clazz))
038: || (dynamicName == null) || (dynamicName.length() == 0)
039: || (!Character.isLetter(dynamicName.charAt(0))))
040: this .dynamicName = null;
041: if (dynamicName == null)
042: fullName = clazz.getName();
043: else
044: fullName = clazz.getName() + "." + dynamicName;
045: }
046:
047: public ClassEntry getSuperEntry() {
048: ClassEntry super Entry = null;
049: if (getDynamicName() != null) {
050: // Dynamic class
051: super Entry = new ClassEntry(getSourceClass(), null);
052: } else {
053: if (getSourceClass().getSuperclass() != null)
054: super Entry = new ClassEntry(getSourceClass()
055: .getSuperclass(), null);
056: }
057: return super Entry;
058: }
059:
060: public boolean hasDynamicAttributes() {
061: return StrictDynamicHandler.getPersistenceAttributeTypes(clazz,
062: dynamicName) != null;
063: }
064:
065: public boolean hasStaticAttributes() {
066: return StrictStaticHandler.hasStaticAttributes(this );
067: }
068:
069: public Class getSourceClass() {
070: return clazz;
071: }
072:
073: public String getDynamicName() {
074: return dynamicName;
075: }
076:
077: public String getFullName() {
078: return fullName;
079: }
080:
081: public String toString() {
082: return "[ClassEntry: " + fullName + "]";
083: }
084:
085: public boolean isPrimitive() {
086: return ClassTracker.isPrimitive(clazz);
087: }
088:
089: public boolean isEmpty() {
090: if (isPrimitive())
091: return false; // Primitive classes are saved
092: if ((clazz.isInterface())
093: || (clazz.getName().startsWith("java")))
094: return true; // Intefaces or java.** classes are non-storable
095: return false;
096: }
097:
098: public boolean isStorable() {
099: if (isPrimitive())
100: return true; // Primitive classes are saved
101: if ((clazz.isInterface())
102: || (clazz.getName().startsWith("java")))
103: return false; // Intefaces or java.** classes are non-storable
104: if ((Modifier.isAbstract(clazz.getModifiers()))
105: && (!hasStaticAttributes()))
106: return false; // Abstract superclasses which have no attributes
107: return true;
108: }
109:
110: public int hashCode() {
111: return fullName.hashCode();
112: }
113:
114: public boolean equals(Object obj) {
115: if (!(obj instanceof ClassEntry))
116: return false;
117: return ((ClassEntry) obj).getFullName().equals(getFullName());
118: }
119: }
|