Search in sources :

Example 1 with PropertyValue

use of org.whole.lang.properties.model.PropertyValue in project whole by wholeplatform.

the class PropertiesUtils method setProperty.

public static String setProperty(Properties props, String name, String value) {
    PropertiesEntityFactory lf = PropertiesEntityFactory.instance;
    Property pattern = lf.createProperty(lf.createPropertyName(name), createVariable(PropertiesEntityDescriptorEnum.PropertyValue, "value"));
    Property property = Matcher.findChild(pattern, props.getEntries());
    if (property != null) {
        PropertyValue pv = property.getValue();
        String oldValue = pv.wStringValue();
        pv.wSetValue(value);
        return oldValue;
    } else {
        pattern.setValue(lf.createPropertyValue(value));
        props.getEntries().wAdd(pattern);
        return null;
    }
}
Also used : PropertiesEntityFactory(org.whole.lang.properties.factories.PropertiesEntityFactory) PropertyValue(org.whole.lang.properties.model.PropertyValue) Property(org.whole.lang.properties.model.Property)

Example 2 with PropertyValue

use of org.whole.lang.properties.model.PropertyValue in project whole by wholeplatform.

the class PropertiesUtils method translate.

public static java.util.Properties translate(Properties props) {
    if (EntityUtils.isResolver(props))
        return null;
    java.util.Properties jProps = new java.util.Properties(translate(props.getDefaults()));
    props.getEntries();
    ScannerIterator<Property> i = IteratorFactory.<Property>childScannerIterator();
    i.reset(props.getEntries());
    for (Property p : i) try {
        PropertyValue value = p.getValue();
        if (// FIXME workaround for null valued property returned from System.getProperties()
        !EntityUtils.isResolver(value))
            jProps.setProperty(p.getName().wStringValue(), value.wStringValue());
    } catch (IllegalArgumentException e) {
    }
    return jProps;
}
Also used : PropertyValue(org.whole.lang.properties.model.PropertyValue) Properties(org.whole.lang.properties.model.Properties) Property(org.whole.lang.properties.model.Property)

Aggregations

Property (org.whole.lang.properties.model.Property)2 PropertyValue (org.whole.lang.properties.model.PropertyValue)2 PropertiesEntityFactory (org.whole.lang.properties.factories.PropertiesEntityFactory)1 Properties (org.whole.lang.properties.model.Properties)1