1
|
/**
|
2
|
* Copyright (C) 2007 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.cdm.persistence.hibernate.replace.impl;
|
10
|
|
11
|
import java.lang.reflect.Field;
|
12
|
|
13
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
14
|
import eu.etaxonomy.cdm.persistence.hibernate.replace.ReferringObjectMetadata;
|
15
|
|
16
|
public abstract class ReferringObjectMetadataImpl implements ReferringObjectMetadata {
|
17
|
protected Field field;
|
18
|
protected String fieldName;
|
19
|
protected Class<? extends CdmBase> type;
|
20
|
|
21
|
public ReferringObjectMetadataImpl(Class fromClass, String propertyName,
|
22
|
Class<? extends CdmBase> toClass) throws SecurityException, NoSuchFieldException {
|
23
|
this.type = fromClass;
|
24
|
this.fieldName = propertyName;
|
25
|
try {
|
26
|
this.field = type.getDeclaredField(fieldName);
|
27
|
} catch(NoSuchFieldException nsfe) {
|
28
|
Class superClass = type.getSuperclass();
|
29
|
while(!superClass.equals(CdmBase.class)) {
|
30
|
try{
|
31
|
this.field = superClass.getDeclaredField(fieldName);
|
32
|
break;
|
33
|
} catch(NoSuchFieldException nsfe1) { }
|
34
|
superClass = superClass.getSuperclass();
|
35
|
}
|
36
|
if(this.field == null) {
|
37
|
throw nsfe;
|
38
|
}
|
39
|
}
|
40
|
this.field.setAccessible(true);
|
41
|
}
|
42
|
|
43
|
@Override
|
44
|
public Class<? extends CdmBase> getType() {
|
45
|
return this.type;
|
46
|
}
|
47
|
|
48
|
@Override
|
49
|
public String getFieldName() {
|
50
|
return this.fieldName;
|
51
|
}
|
52
|
}
|