Search in sources :

Example 11 with WholeIllegalArgumentException

use of org.whole.lang.exceptions.WholeIllegalArgumentException in project whole by wholeplatform.

the class ReusablesInterpreterVisitor method visit.

@Override
public void visit(Registry entity) {
    entity.getRegistryUri().accept(this);
    String registryId = getResult().wStringValue();
    if (!ResourceRegistry.hasRegistry(registryId))
        throw new WholeIllegalArgumentException("Undefined registry " + registryId).withSourceEntity(entity).withBindings(getBindings());
    IResourceRegistry<IResource> registry = ResourceRegistry.getRegistry(registryId);
    entity.getUri().accept(this);
    String uri = getResult().wStringValue();
    if (ResourceUtils.hasFragmentPart(uri) && registry instanceof CompoundResourceRegistry) {
        CompoundResourceRegistry<IResource> compoundRegistry = (CompoundResourceRegistry<IResource>) registry;
        setResult(compoundRegistry.getFunctionModel(uri, true, getBindings()));
    } else
        setResult(registry.getResourceModel(uri, true, getBindings()));
}
Also used : WholeIllegalArgumentException(org.whole.lang.exceptions.WholeIllegalArgumentException) CompoundResourceRegistry(org.whole.lang.resources.CompoundResourceRegistry) IResource(org.whole.lang.resources.IResource)

Example 12 with WholeIllegalArgumentException

use of org.whole.lang.exceptions.WholeIllegalArgumentException in project whole by wholeplatform.

the class WorkflowsInterpreterVisitor method visit.

@Override
public void visit(CreateEntity entity) {
    try {
        entity.getEntityName().accept(this);
        String typeName = getResultString();
        EntityDescriptor<?> ed = CommonsDataTypePersistenceParser.parseEntityDescriptor(typeName);
        if (ed == null)
            throw new WholeIllegalArgumentException("The requested entity does not exist: " + typeName).withSourceEntity(entity).withBindings(getBindings());
        IEntityRegistryProvider provider = null;
        switch(entity.getRegistry().getValue().getOrdinal()) {
            case RegistryEnum.DEFAULT_ord:
                provider = RegistryConfigurations.DEFAULT;
                break;
            case RegistryEnum.RESOLVER_ord:
                provider = RegistryConfigurations.RESOLVER;
                break;
            case RegistryEnum.ADAPTER_ord:
                provider = RegistryConfigurations.ADAPTER;
                break;
            case RegistryEnum.STRICT_ord:
                provider = RegistryConfigurations.STRICT;
                break;
            case RegistryEnum.CUSTOM_ord:
                provider = RegistryConfigurations.CUSTOM;
                break;
        }
        IEntityFactory ef = GenericEntityFactory.instance(provider);
        IEntity model;
        Arguments arguments = entity.getArguments();
        if (Matcher.matchImpl(WorkflowsEntityDescriptorEnum.Assignments, arguments)) {
            ITransactionScope resettableScope = BindingManagerFactory.instance.createTransactionScope();
            getBindings().wEnterScope(resettableScope);
            arguments.accept(this);
            for (int i = 0; i < arguments.wSize(); i++) {
                String name = ((Assignments) arguments).get(i).getName().getValue();
                FeatureDescriptor fd = ed.getFeatureDescriptorEnum().valueOf(name);
                if (fd != null)
                    getBindings().wDef(name, EntityUtils.convertCloneIfReparenting(getBindings().wGet(name), ed.getEntityFeatureDescriptor(fd)));
            }
            model = ef.create(ed, getBindings());
            resettableScope.rollback();
            getBindings().wExitScope();
        } else if (Matcher.matchImpl(WorkflowsEntityDescriptorEnum.Expressions, arguments)) {
            IEntity selfEntity = getBindings().wGet("self");
            if (ed.getEntityKind().isData()) {
                ((Expressions) arguments).get(0).accept(this);
                model = DataTypeUtils.convertCloneIfParented(getResult(), ed);
                resetSelfEntity(selfEntity);
            } else {
                IEntity[] values = new IEntity[arguments.wSize()];
                for (int i = 0; i < values.length; i++) {
                    ((Expressions) arguments).get(i).accept(this);
                    values[i] = EntityUtils.convertCloneIfReparenting(getResult(), ed.getEntityFeatureDescriptor(i));
                    resetSelfEntity(selfEntity);
                }
                model = ef.create(ed, values);
            }
        } else
            model = ef.create(ed);
        setResult(entity.getModel(), model);
    } catch (Exception e) {
        throw IWholeRuntimeException.asWholeException(e, entity, getBindings());
    }
}
Also used : ITransactionScope(org.whole.lang.bindings.ITransactionScope) IEntity(org.whole.lang.model.IEntity) IEntityFactory(org.whole.lang.factories.IEntityFactory) Arguments(org.whole.lang.workflows.model.Arguments) Assignments(org.whole.lang.workflows.model.Assignments) WholeIllegalArgumentException(org.whole.lang.exceptions.WholeIllegalArgumentException) MissingVariableException(org.whole.lang.visitors.MissingVariableException) IOException(java.io.IOException) IWholeRuntimeException(org.whole.lang.exceptions.IWholeRuntimeException) VisitException(org.whole.lang.visitors.VisitException) ParseException(org.whole.lang.parsers.ParseException) WholeIllegalArgumentException(org.whole.lang.exceptions.WholeIllegalArgumentException) FeatureDescriptor(org.whole.lang.reflect.FeatureDescriptor) IEntityRegistryProvider(org.whole.lang.factories.IEntityRegistryProvider) Expressions(org.whole.lang.workflows.model.Expressions)

Example 13 with WholeIllegalArgumentException

use of org.whole.lang.exceptions.WholeIllegalArgumentException in project whole by wholeplatform.

the class GrammarsDefaultDataTypeParser method matches.

protected String matches(EntityDescriptor<?> ed, String value) {
    Pattern pattern = grammarBasedDataTypeParser.getDataTerminal(ed).getPattern();
    java.util.regex.Pattern compiledPattern = Matcher.matchImpl(GrammarsEntityDescriptorEnum.CompiledPattern, pattern) ? ((CompiledPattern) pattern).getValue() : java.util.regex.Pattern.compile(((RegExp) pattern).getValue());
    if (!compiledPattern.matcher(value).matches())
        throw new WholeIllegalArgumentException(WholeMessages.no_data_type);
    return value;
}
Also used : CompiledPattern(org.whole.lang.grammars.model.CompiledPattern) Pattern(org.whole.lang.grammars.model.Pattern) RegExp(org.whole.lang.grammars.model.RegExp) WholeIllegalArgumentException(org.whole.lang.exceptions.WholeIllegalArgumentException)

Example 14 with WholeIllegalArgumentException

use of org.whole.lang.exceptions.WholeIllegalArgumentException in project whole by wholeplatform.

the class QueriesDynamicCompilerVisitor method stringValue.

protected final String stringValue(Name entity) {
    setResult(null);
    entity.accept(this);
    IEntity result = getResult();
    if (result == null)
        throw new WholeIllegalArgumentException(WholeMessages.null_value_argument).withSourceEntity(entity).withBindings(getBindings());
    return result.wStringValue();
}
Also used : IEntity(org.whole.lang.model.IEntity) WholeIllegalArgumentException(org.whole.lang.exceptions.WholeIllegalArgumentException)

Example 15 with WholeIllegalArgumentException

use of org.whole.lang.exceptions.WholeIllegalArgumentException in project whole by wholeplatform.

the class MathUtils method remainder.

public static IEntity remainder(IEntity result1, IEntity result2) {
    DataKinds dataKind1 = DataTypeUtils.getUnboxedDataKind(result1);
    DataKinds dataKind2 = DataTypeUtils.getUnboxedDataKind(result2);
    IEntity result;
    if (dataKind1.isNotAData() || dataKind2.isNotAData())
        throw new WholeIllegalArgumentException(WholeMessages.no_data);
    else if (dataKind1.isDouble() || dataKind2.isDouble())
        result = BindingManagerFactory.instance.createValue(DataTypeUtils.toDouble(result1) % DataTypeUtils.toDouble(result2));
    else if (dataKind1.isFloat() || dataKind2.isFloat())
        result = BindingManagerFactory.instance.createValue(DataTypeUtils.toFloat(result1) % DataTypeUtils.toFloat(result2));
    else if (dataKind1.isLong() || dataKind2.isLong())
        result = BindingManagerFactory.instance.createValue(DataTypeUtils.toLong(result1) % DataTypeUtils.toLong(result2));
    else
        result = BindingManagerFactory.instance.createValue(DataTypeUtils.toInt(result1) % DataTypeUtils.toInt(result2));
    return result;
}
Also used : IEntity(org.whole.lang.model.IEntity) WholeIllegalArgumentException(org.whole.lang.exceptions.WholeIllegalArgumentException) DataKinds(org.whole.lang.reflect.DataKinds)

Aggregations

WholeIllegalArgumentException (org.whole.lang.exceptions.WholeIllegalArgumentException)32 DataKinds (org.whole.lang.reflect.DataKinds)16 IEntity (org.whole.lang.model.IEntity)15 EnumValue (org.whole.lang.model.EnumValue)3 IBindingManager (org.whole.lang.bindings.IBindingManager)2 IWholeRuntimeException (org.whole.lang.exceptions.IWholeRuntimeException)2 FeatureDescriptor (org.whole.lang.reflect.FeatureDescriptor)2 ILanguageKit (org.whole.lang.reflect.ILanguageKit)2 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 DateTimeZone (org.joda.time.DateTimeZone)1 DateTimeParser (org.joda.time.format.DateTimeParser)1 DateTimeParserBucket (org.joda.time.format.DateTimeParserBucket)1 FixedDateTimeZone (org.joda.time.tz.FixedDateTimeZone)1 ITransactionScope (org.whole.lang.bindings.ITransactionScope)1 URLPersistenceProvider (org.whole.lang.codebase.URLPersistenceProvider)1 IEntityFactory (org.whole.lang.factories.IEntityFactory)1 IEntityRegistryProvider (org.whole.lang.factories.IEntityRegistryProvider)1 CompiledPattern (org.whole.lang.grammars.model.CompiledPattern)1 Pattern (org.whole.lang.grammars.model.Pattern)1