Search in sources :

Example 6 with Properties

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

the class PropertiesTest method testLoadAsText.

@Test
public void testLoadAsText() throws IOException {
    Properties props1 = PropertiesUtils.loadFromText(PropertiesTest.class.getResourceAsStream("plugin.properties"));
    Properties props2 = PropertiesUtils.loadFromText(PropertiesTest.class.getResourceAsStream("build.properties"));
    PropertiesUtils.saveToText(props2, System.out, "comment");
    PropertiesUtils.saveToXml(props1, System.out, "comment");
}
Also used : Properties(org.whole.lang.properties.model.Properties) Test(org.junit.Test)

Example 7 with Properties

use of org.whole.lang.properties.model.Properties 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)

Example 8 with Properties

use of org.whole.lang.properties.model.Properties 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;
}
Also used : PropertiesEntityFactory(org.whole.lang.properties.factories.PropertiesEntityFactory) Enumeration(java.util.Enumeration) Entries(org.whole.lang.properties.model.Entries) Properties(org.whole.lang.properties.model.Properties)

Example 9 with Properties

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

the class PropertiesPart method getModelSpecificChildren.

@Override
protected List<IEntity> getModelSpecificChildren() {
    Properties entity = getModelEntity();
    List<IEntity> list = new ArrayList<IEntity>(3);
    list.add(entity.getComment());
    list.add(entity.getDefaults());
    list.add(entity.getEntries());
    return list;
}
Also used : IEntity(org.whole.lang.model.IEntity) ArrayList(java.util.ArrayList) Properties(org.whole.lang.properties.model.Properties)

Example 10 with Properties

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

the class PersistenceTest method testSingleBuilder2Java.

@Test
public void testSingleBuilder2Java() {
    ModelBuilderOperation op = new ModelBuilderOperation();
    JavaStoreProducerBuilderOperation javaOp = new JavaStoreProducerBuilderOperation(op);
    ((JavaStoreProducerBuilder) javaOp.wGetBuilder()).buildStartCompilationUnit("test", "Test");
    try {
        Properties props = PropertiesUtils.translate(System.getProperties());
        props.getEntries().wAdd(0, createResolver(PropertiesEntityDescriptorEnum.Property));
        new ModelTemplate(props).apply(javaOp);
    } catch (IOException e) {
        e.printStackTrace();
    }
    // new TopDownTraversal(new ModelsModel().create()).apply(javaOp);
    ((JavaStoreProducerBuilder) javaOp.wGetBuilder()).buildEndCompilationUnit();
    // new ModelsModel().apply(new JavaStoreProducerBuilderOperation(op));
    IEntity model = op.wGetResult();
    PrettyPrinterOperation.prettyPrint(model);
}
Also used : ModelBuilderOperation(org.whole.lang.builders.ModelBuilderOperation) ModelTemplate(org.whole.lang.templates.ModelTemplate) JavaStoreProducerBuilder(org.whole.lang.java.util.JavaStoreProducerBuilder) IEntity(org.whole.lang.model.IEntity) JavaStoreProducerBuilderOperation(org.whole.lang.java.util.JavaStoreProducerBuilderOperation) IOException(java.io.IOException) Properties(org.whole.lang.properties.model.Properties) Test(org.junit.Test)

Aggregations

Properties (org.whole.lang.properties.model.Properties)10 Test (org.junit.Test)5 IEntity (org.whole.lang.model.IEntity)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 PropertiesEntityFactory (org.whole.lang.properties.factories.PropertiesEntityFactory)2 Property (org.whole.lang.properties.model.Property)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 OutputStream (java.io.OutputStream)1 Charset (java.nio.charset.Charset)1 Enumeration (java.util.Enumeration)1 ModelBuilderOperation (org.whole.lang.builders.ModelBuilderOperation)1 JavaStoreProducerBuilder (org.whole.lang.java.util.JavaStoreProducerBuilder)1 JavaStoreProducerBuilderOperation (org.whole.lang.java.util.JavaStoreProducerBuilderOperation)1 Entries (org.whole.lang.properties.model.Entries)1 PropertyValue (org.whole.lang.properties.model.PropertyValue)1 ModelTemplate (org.whole.lang.templates.ModelTemplate)1