blob: 4f067f49accadb630077769b511e3760fafe6493 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
/*******************************************************************************
* Copyright (c) 2004, 2007 Boeing.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Boeing - initial API and implementation
*******************************************************************************/
package org.eclipse.osee.framework.skynet.core.attribute;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import org.eclipse.osee.framework.skynet.core.artifact.Attribute;
import org.eclipse.osee.framework.skynet.core.attribute.providers.ICharacterAttributeDataProvider;
/**
* @author Roberto E. Escobar
*/
public abstract class CharacterBackedAttribute<T> extends Attribute<T> {
@Override
public ICharacterAttributeDataProvider getAttributeDataProvider() {
// this cast is always safe since the the data provider passed in the constructor to
// the super class is of type ICharacterAttributeDataProvider
return (ICharacterAttributeDataProvider) super.getAttributeDataProvider();
}
@Override
protected boolean subClassSetValue(T value) {
Class<?> clazz = getClass();
String superclassName = clazz.getSuperclass().getSimpleName();
while (!superclassName.equals("CharacterBackedAttribute") && !superclassName.equals("BinaryBackedAttribute")) {
clazz = clazz.getSuperclass();
superclassName = clazz.getSuperclass().getSimpleName();
}
Type persistentClass = ((ParameterizedType) clazz.getGenericSuperclass()).getActualTypeArguments()[0];
if (!persistentClass.getTypeName().equals(value.getClass().getName())) {
throw new ClassCastException(
persistentClass + " attribute subClassSetValue called with type " + value.getClass());
}
return getAttributeDataProvider().setValue(value);
}
}
|