use of gate.creole.Parameter in project gate-core by GateNLP.
the class PRPersistence method extractDataFromSource.
/**
* Populates this Persistence with the data that needs to be stored from the
* original source object.
*/
@Override
public void extractDataFromSource(Object source) throws PersistenceException {
if (!(source instanceof ProcessingResource)) {
throw new UnsupportedOperationException(getClass().getName() + " can only be used for " + ProcessingResource.class.getName() + " objects!\n" + source.getClass().getName() + " is not a " + ProcessingResource.class.getName());
}
super.extractDataFromSource(source);
Resource res = (Resource) source;
ResourceData rData = Gate.getCreoleRegister().get(res.getClass().getName());
if (rData == null)
throw new PersistenceException("Could not find CREOLE data for " + res.getClass().getName());
// now get the runtime params
ParameterList params = rData.getParameterList();
try {
// get the values for the init time parameters
runtimeParams = Factory.newFeatureMap();
// this is a list of lists
Iterator<List<Parameter>> parDisjIter = params.getRuntimeParameters().iterator();
while (parDisjIter.hasNext()) {
Iterator<Parameter> parIter = parDisjIter.next().iterator();
while (parIter.hasNext()) {
Parameter parameter = parIter.next();
String parName = parameter.getName();
Object parValue = res.getParameterValue(parName);
if (storeParameterValue(parValue, parameter.getDefaultValue())) {
((FeatureMap) runtimeParams).put(parName, parValue);
}
}
}
runtimeParams = PersistenceManager.getPersistentRepresentation(runtimeParams);
} catch (ResourceInstantiationException | ParameterException rie) {
throw new PersistenceException(rie);
}
}
Aggregations