Search in sources :

Example 26 with IDataTypeParser

use of org.whole.lang.parsers.IDataTypeParser in project whole by wholeplatform.

the class GenericBuilderContext method wEntity.

public void wEntity(EntityDescriptor<?> entityDesc, String value) {
    DataKinds dataKind = entityDesc.getDataKind();
    // FIXME workaround move responsibility into generated spec builder adapters
    if (dataKind.isString())
        builderStrategy.wEntity(entityDesc, value);
    else {
        IDataTypeParser dataTypeParser = DataTypeUtils.getDataTypeParser(entityDesc, DataTypeParsers.PERSISTENCE);
        switch(dataKind) {
            case DATE:
                builderStrategy.wEntity(entityDesc, dataTypeParser.parseDate(entityDesc, value));
                break;
            case ENUM_VALUE:
                builderStrategy.wEntity(entityDesc, dataTypeParser.parseEnumValue(entityDesc, value));
                break;
            case OBJECT:
                builderStrategy.wEntity(entityDesc, dataTypeParser.parseObject(entityDesc, value));
                break;
        }
    }
    wNext();
}
Also used : IDataTypeParser(org.whole.lang.parsers.IDataTypeParser) DataKinds(org.whole.lang.reflect.DataKinds)

Example 27 with IDataTypeParser

use of org.whole.lang.parsers.IDataTypeParser in project whole by wholeplatform.

the class DataTypeUtils method buildFromPersistenceString.

public static void buildFromPersistenceString(IBuilder builder, EntityDescriptor<?> ed, String value) {
    IDataTypeParser parser = getDataTypeParser(ed, DataTypeParsers.PERSISTENCE);
    buildFromString(builder, ed, value, parser);
}
Also used : IDataTypeParser(org.whole.lang.parsers.IDataTypeParser)

Example 28 with IDataTypeParser

use of org.whole.lang.parsers.IDataTypeParser in project whole by wholeplatform.

the class DataTypeUtils method setFromPresentationString.

public static void setFromPresentationString(IEntity entity, String value) {
    IDataTypeParser parser = getDataTypeParser(entity, DataTypeParsers.PRESENTATION);
    setFromString(entity, value, parser);
}
Also used : IDataTypeParser(org.whole.lang.parsers.IDataTypeParser)

Example 29 with IDataTypeParser

use of org.whole.lang.parsers.IDataTypeParser in project whole by wholeplatform.

the class DataTypeUtils method setFromPersistenceString.

public static void setFromPersistenceString(IEntity entity, String value) {
    IDataTypeParser parser = getDataTypeParser(entity, DataTypeParsers.PERSISTENCE);
    setFromString(entity, value, parser);
}
Also used : IDataTypeParser(org.whole.lang.parsers.IDataTypeParser)

Example 30 with IDataTypeParser

use of org.whole.lang.parsers.IDataTypeParser in project whole by wholeplatform.

the class SchemaHelpers method deploySchemaOperations.

public static void deploySchemaOperations(final String languageUri) {
    ILanguageKit lk = ReflectionFactory.getLanguageKit(languageUri, false, null);
    if (!lk.isDynamic())
        return;
    // configure data-type parsers
    IMappingStrategy mappingStrategy = MappingStrategyRegistry.instance().getMappingStrategy(languageUri);
    IDataTypeParser parser = new XsiDataTypeParser(mappingStrategy.getDataTypeParsers());
    DynamicLanguageKit languageKit = (DynamicLanguageKit) lk;
    languageKit.setDataTypeParser(DataTypeParsers.PERSISTENCE, parser);
    languageKit.setDataTypeParser(DataTypeParsers.PRESENTATION, parser);
    // deploy a generic pretty print
    ReflectionFactory.deploy(new AbstractLanguageExtensionDeployer() {

        public void deploy(ReflectionFactory platform) {
            platform.addOperationFactory(languageUri, PrettyPrinterOperation.ID, new IVisitorFactory() {

                public IVisitor create(IOperation operation, int stage) {
                    return new XsiPrettyPrinterVisitor();
                }
            });
        }
    });
}
Also used : IOperation(org.whole.lang.operations.IOperation) IMappingStrategy(org.whole.lang.xsd.codebase.IMappingStrategy) DynamicLanguageKit(org.whole.lang.reflect.DynamicLanguageKit) ReflectionFactory(org.whole.lang.reflect.ReflectionFactory) XsiDataTypeParser(org.whole.lang.xsd.parsers.XsiDataTypeParser) AbstractLanguageExtensionDeployer(org.whole.lang.reflect.AbstractLanguageExtensionDeployer) XsiPrettyPrinterVisitor(org.whole.lang.xsd.visitors.XsiPrettyPrinterVisitor) IDataTypeParser(org.whole.lang.parsers.IDataTypeParser) IVisitorFactory(org.whole.lang.visitors.IVisitorFactory) ILanguageKit(org.whole.lang.reflect.ILanguageKit)

Aggregations

IDataTypeParser (org.whole.lang.parsers.IDataTypeParser)32 Test (org.junit.Test)18 IEntity (org.whole.lang.model.IEntity)12 TestEntitiesEntityFactory (org.whole.lang.testentities.factories.TestEntitiesEntityFactory)10 DataKinds (org.whole.lang.reflect.DataKinds)3 ILanguageKit (org.whole.lang.reflect.ILanguageKit)3 SchemaDataTypeParsers.normalizedString (org.whole.lang.xsd.parsers.SchemaDataTypeParsers.normalizedString)3 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 DateTime (org.joda.time.DateTime)1 Grammar (org.whole.lang.grammars.model.Grammar)1 EnumValue (org.whole.lang.model.EnumValue)1 IOperation (org.whole.lang.operations.IOperation)1 ForwardEntityDescriptorStrategyDataTypeParser (org.whole.lang.parsers.ForwardEntityDescriptorStrategyDataTypeParser)1 AbstractLanguageExtensionDeployer (org.whole.lang.reflect.AbstractLanguageExtensionDeployer)1 DynamicLanguageKit (org.whole.lang.reflect.DynamicLanguageKit)1 EntityDescriptor (org.whole.lang.reflect.EntityDescriptor)1 EntityDescriptorEnum (org.whole.lang.reflect.EntityDescriptorEnum)1