Search in sources :

Example 1 with Property

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

the class PropertyRowPart method getModelSpecificChildren.

@Override
protected List<IEntity> getModelSpecificChildren() {
    Property entity = getModelEntity();
    List<IEntity> list = new ArrayList<IEntity>(2);
    list.add(entity.getName());
    list.add(entity.getValue());
    return list;
}
Also used : IEntity(org.whole.lang.model.IEntity) ArrayList(java.util.ArrayList) Property(org.whole.lang.properties.model.Property)

Example 2 with Property

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

the class PropertyPart method getModelSpecificChildren.

@Override
protected List<IEntity> getModelSpecificChildren() {
    Property entity = getModelEntity();
    List<IEntity> list = new ArrayList<IEntity>(2);
    list.add(entity.getName());
    list.add(entity.getValue());
    return list;
}
Also used : IEntity(org.whole.lang.model.IEntity) ArrayList(java.util.ArrayList) Property(org.whole.lang.properties.model.Property)

Example 3 with Property

use of org.whole.lang.properties.model.Property 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 4 with Property

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

the class PropertiesTest method testGetSetProperty.

@Test
public void testGetSetProperty() {
    PropertiesEntityFactory lf = PropertiesEntityFactory.instance;
    Properties props = lf.createProperties(lf.createComment("Test properties"), createResolver(PropertiesEntityDescriptorEnum.Properties), lf.createEntries(new Property[] { lf.createProperty(lf.createPropertyName("prop1"), lf.createPropertyValue("value 1")), lf.createProperty(lf.createPropertyName("prop2"), lf.createPropertyValue("value 2")) }));
    String prop1Value = PropertiesUtils.getProperty(props, "prop1");
    Assert.assertEquals("value 1", prop1Value);
}
Also used : PropertiesEntityFactory(org.whole.lang.properties.factories.PropertiesEntityFactory) Properties(org.whole.lang.properties.model.Properties) Property(org.whole.lang.properties.model.Property) Test(org.junit.Test)

Example 5 with Property

use of org.whole.lang.properties.model.Property 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)6 PropertiesEntityFactory (org.whole.lang.properties.factories.PropertiesEntityFactory)3 ArrayList (java.util.ArrayList)2 IEntity (org.whole.lang.model.IEntity)2 Properties (org.whole.lang.properties.model.Properties)2 PropertyValue (org.whole.lang.properties.model.PropertyValue)2 Test (org.junit.Test)1