use of org.whole.lang.properties.factories.PropertiesEntityFactory in project whole by wholeplatform.
the class PropertiesUtils method translate.
@SuppressWarnings("unchecked")
public static Properties translate(java.util.Properties jProps) throws IOException {
PropertiesEntityFactory lf = PropertiesEntityFactory.instance;
Properties props = lf.create(PropertiesEntityDescriptorEnum.Properties);
Entries entries = props.getEntries();
if (entries.wSize() == 1)
// workaround for removing the resolver
entries.wRemove(0);
Enumeration<String> names = (Enumeration<String>) jProps.propertyNames();
while (names.hasMoreElements()) {
String name = names.nextElement();
String value = jProps.getProperty(name);
entries.wAdd(lf.createProperty(lf.createPropertyName(name), // FIXME workaround for null valued property returned from System.getProperties()
value != null ? lf.createPropertyValue(value) : CommonsEntityAdapterFactory.createResolver(PropertiesEntityDescriptorEnum.PropertyValue)));
}
return props;
}
use of org.whole.lang.properties.factories.PropertiesEntityFactory in project whole by wholeplatform.
the class PropertiesUtils method getProperty.
public static String getProperty(Properties props, String name, String defaultValue) {
if (EntityUtils.isResolver(props))
return defaultValue;
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)
return getProperty(props.getDefaults(), name, defaultValue);
else
return property.getValue().wStringValue();
}
use of org.whole.lang.properties.factories.PropertiesEntityFactory in project whole by wholeplatform.
the class FactoriesTest method testCompositeFactoryMethods.
@Test
public void testCompositeFactoryMethods() {
IEntityRegistry efi = ReflectionFactory.getLanguageKit(PropertiesLanguageKit.URI).getEntityRegistry(RegistryConfigurations.DEFAULT);
PropertiesEntityFactory ef = PropertiesEntityFactory.instance;
Entries p = ef.createEntries(ef.createProperty(), ef.create(PropertiesEntityDescriptorEnum.Property, "p2", "v2"));
efi.put(p);
Entries e1 = ef.createEntries();
Assert.assertEquals(2, e1.wSize());
Entries e2 = ef.createEntries(new Property[0]);
Assert.assertEquals(0, e2.wSize());
Entries e3 = ef.createEntries(ef.create(PropertiesEntityDescriptorEnum.Property, "p1", "v1"));
Assert.assertEquals(1, e3.wSize());
}
Aggregations