Commit 3fb959bc authored by R.W.Majeed's avatar R.W.Majeed

extension return instance types with appropriate generic type

parent df61035a
......@@ -58,6 +58,6 @@ public interface Extension<T>{
* TODO change return type to array, to register all compatible classes
* @return instance type
*/
Class<?>[] getInstanceTypes();
Iterable<Class<? super T>> getInstanceTypes();
}
package de.sekmi.histream.impl;
import de.sekmi.histream.Extension;
import de.sekmi.histream.Observation;
import de.sekmi.histream.ext.IdExtensionType;
/**
* Extension to allow grouping/classification of facts.
* This can be seen similar to the {@code class} attribute
* in HTML which can be given to any element.
* <p>
* XXX still need to figure how to serialize the class id
* to the {@code fact/@class} attribute.
* </p>
*
* @author R.W.Majeed
*
*/
public class ClassExtension implements Extension<ClassExtension.Clazz> {
public static class Clazz implements IdExtensionType{
private String id;
@Override
public String getId() {
return id;
}
@Override
public void setId(String id) {
this.id = id;
}
}
@Override
public Clazz createInstance(Observation observation) {
// TODO use modifier "class" to get the class value
// otherwise unable to create a class for the given observation
throw new UnsupportedOperationException();
//return null;
}
@Override
public Clazz createInstance(Object... args) throws UnsupportedOperationException, IllegalArgumentException {
if( args.length != 1 || !(args[0] instanceof String) ){
throw new IllegalArgumentException("Fact extension for class needs exactly one string argument for the class id");
}
Clazz c = new Clazz();
c.setId((String)args[0]);
return c;
}
@Override
public Class<?>[] getInstanceTypes() {
return new Class[]{Clazz.class};
}
}
package de.sekmi.histream.impl;
import java.util.Arrays;
/*
* #%L
* histream
......@@ -34,10 +36,10 @@ import de.sekmi.histream.ext.Patient;
*
*/
public class SimplePatientExtension implements Extension<PatientImpl>{
private final static Class<?>[] TYPES = new Class<?>[]{Patient.class, PatientImpl.class};
private final static Iterable<Class<? super PatientImpl>> TYPES = Arrays.asList(Patient.class, PatientImpl.class);
@Override
public Class<?>[] getInstanceTypes() {return TYPES;}
public Iterable<Class<? super PatientImpl>> getInstanceTypes() {return TYPES;}
@Override
public PatientImpl createInstance(Object... args) {
......
......@@ -22,16 +22,19 @@ package de.sekmi.histream.impl;
import de.sekmi.histream.Observation;
import java.util.Arrays;
import de.sekmi.histream.Extension;
import de.sekmi.histream.ext.ExternalSourceType;
import de.sekmi.histream.ext.Patient;
import de.sekmi.histream.ext.Visit;
public class SimpleVisitExtension implements Extension<VisitImpl>{
private final static Class<?>[] TYPES = new Class<?>[]{Visit.class, VisitImpl.class};
private final static Iterable<Class<? super VisitImpl>> TYPES = Arrays.asList(Visit.class, VisitImpl.class);
@Override
public Class<?>[] getInstanceTypes() {return TYPES;}
public Iterable<Class<? super VisitImpl>> getInstanceTypes() {return TYPES;}
@Override
public VisitImpl createInstance(Object... args) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment