I would get from a codelet the `Element` that contains the data type of a parameter.

I know that `SchemaHandler` has an useful method, `getTypeMap()`. I tried to access to `SchemaHandler` from an `YParameter`, this way:

public static Map<String, Element> getTypes(YParameter parameter) {
// Inelegant, but it seems the only way to get the specification
final YDataValidator dataValidator = parameter
.getParentDecomposition()
.getSpecification()
.getDataValidator();
// Using reflection, since for an incomprensible reason YDataValidator
// does not expose its internal SchemaHandler
final SchemaHandler schemaHandler = (SchemaHandler) ReflectionHelper.getFieldValue(dataValidator, "handler");
return schemaHandler.getTypeMap();
}

Unluckily, `parameter.getParentDecomposition()` returns me null....

Is there not another way to get the data type or the `SchemaHandler`?

Marco Sulla

Mon, 07/29/2019 - 18:06

Found it:

```

final WorkItemRecord wir = this.getWorkItem();
YEngine engine;

try {
engine = YEngine.getInstance(false);
}
catch (final YPersistenceException e1) {
throw new YPersistenceUncatchedException(e1);
}

final YSpecificationID specId = new YSpecificationID(wir);
final YSpecification spec = engine.getSpecification(specId);
final YDataValidator dataValidator = spec.getDataValidator();
final SchemaHandler schemaHandler = (SchemaHandler) ReflectionHelper.getFieldValue(dataValidator, "handler");

final Map<String, Element> types = schemaHandler.getTypeMap();

Element paramType;
String paramName;
String paramtypeStr;

for (final YParameter yParameter: inParams) {
paramName = yParameter.getName();
paramtypeStr = yParameter.getDataTypeName();
paramType = types.get(paramtypeStr);

logger.info("Type of parameter " + paramName + ":" + paramtypeStr + " - type schema: " + paramType);
}
```