use of eu.esdihumboldt.hale.common.core.io.ValueProperties in project hale by halestudio.
the class SQLArrayFactory method restore.
@Override
public SQLArray restore(Value value, Definition<?> definition, TypeResolver typeIndex, ClassResolver resolver) throws Exception {
ValueProperties props = value.as(ValueProperties.class);
if (props != null) {
// read element class
Class<?> elementType = null;
String className = props.getSafe(NAME_ELEMENT_CLASS).as(String.class);
if (className != null) {
elementType = resolver.loadClass(className);
}
// read element database type name
String elementTypeName = props.getSafe(NAME_ELEMENT_TYPE_NAME).as(String.class);
// read dimension
int dimension = props.getSafe(NAME_DIMENSION).as(Integer.class, 0);
// read array dimension sizes
int[] sizes = null;
ValueList sizeList = props.getSafe(NAME_SIZES).as(ValueList.class);
if (sizeList != null) {
sizes = new int[sizeList.size()];
int index = 0;
for (Value size : sizeList) {
sizes[index] = size.as(Integer.class, 0);
index++;
}
}
return new SQLArray(elementType, elementTypeName, dimension, sizes);
}
return SQLArray.NO_ARRAY;
}
use of eu.esdihumboldt.hale.common.core.io.ValueProperties in project hale by halestudio.
the class XmlElementsFactory method valueToElement.
private XmlElement valueToElement(Value val, Definition<?> definition, @SuppressWarnings("unused") TypeResolver typeResolver) {
ValueProperties props = val.as(ValueProperties.class);
if (props != null) {
QName name = props.getSafe("name").as(QName.class);
if (name != null) {
QName substitutionGroup = props.getSafe("substitutionGroup").as(QName.class);
TypeDefinition type = null;
if (definition instanceof TypeDefinition) {
type = (TypeDefinition) definition;
} else {
log.error("Wrong definition for XmlElements constraint: " + definition);
}
return new XmlElement(name, type, substitutionGroup);
}
}
return null;
}
use of eu.esdihumboldt.hale.common.core.io.ValueProperties in project hale by halestudio.
the class XmlElementsFactory method elementToValue.
private Value elementToValue(XmlElement element, @SuppressWarnings("unused") TypeReferenceBuilder refBuilder) {
ValueProperties result = new ValueProperties();
result.put("name", Value.complex(element.getName()));
if (element.getSubstitutionGroup() != null) {
result.put("substitutionGroup", Value.complex(element.getSubstitutionGroup()));
}
return result.toValue();
}
use of eu.esdihumboldt.hale.common.core.io.ValueProperties in project hale by halestudio.
the class ProjectVariables method setVariable.
/**
* Helper method to store a project variable value.
*
* @param name the variable name
* @param value the variable value
* @param projectConfiguration the project configuration service
*/
public static void setVariable(String name, Value value, ComplexConfigurationService projectConfiguration) {
Value variables = projectConfiguration.getProperty(PROJECT_PROPERTY_VARIABLES);
ValueProperties properties = variables.as(ValueProperties.class);
if (properties == null) {
properties = new ValueProperties();
} else {
if (variables.getValue() != null) {
log.error("Unknown representation of project variables");
}
}
properties.put(name, value);
projectConfiguration.setProperty(PROJECT_PROPERTY_VARIABLES, Value.complex(properties));
}
use of eu.esdihumboldt.hale.common.core.io.ValueProperties in project hale by halestudio.
the class ProjectVariables method getValue.
/**
* Get the value for a given variable name.
*
* @param name the variable name
* @return the project variable value or {@link Value#NULL}
*/
public Value getValue(String name) {
// 1st priority: system property
String value = System.getProperty(PREFIX_SYSTEM_PROPERTY + name);
if (value != null) {
return Value.of(value);
}
// 2nd priority: environment variable
value = System.getenv(PREFIX_ENV + name);
if (value != null) {
return Value.of(value);
}
// 3rd priority: use value stored in project
if (projectInfo != null) {
Value variables = projectInfo.getProperty(PROJECT_PROPERTY_VARIABLES);
ValueProperties properties = variables.as(ValueProperties.class);
if (properties != null) {
return properties.getSafe(name);
} else {
if (variables.getValue() != null) {
log.error("Unknown representation of project variables");
}
}
}
return Value.NULL;
}
Aggregations