Search in sources :

Example 1 with NullArgument

use of net.morimekta.providence.jdbi.v2.util.NullArgument in project providence by morimekta.

the class MessageNamedArgumentFinder method find.

@Override
@SuppressWarnings("unchecked")
public Argument find(String name) {
    if (!prefix.isEmpty()) {
        if (name.startsWith(prefix)) {
            name = name.substring(prefix.length());
        } else {
            return null;
        }
    }
    String[] parts = name.split("[.]");
    PMessage leaf = message;
    PMessageDescriptor leafDescriptor = message.descriptor();
    for (int i = 0; i < parts.length - 1; ++i) {
        String part = parts[i];
        PField field = leafDescriptor.findFieldByName(part);
        if (field == null)
            return null;
        if (field.getType() != PType.MESSAGE) {
            throw new IllegalArgumentException("");
        }
        leafDescriptor = (PMessageDescriptor) field.getDescriptor();
        if (leaf != null) {
            leaf = (PMessage) leaf.get(field.getId());
        }
    }
    String leafName = parts[parts.length - 1];
    PField field = leafDescriptor.findFieldByName(leafName);
    if (field != null) {
        if (leaf != null) {
            return new MessageFieldArgument(leaf, field, getColumnType(field));
        }
        return new NullArgument(getColumnType(field));
    }
    return null;
}
Also used : PField(net.morimekta.providence.descriptor.PField) PMessage(net.morimekta.providence.PMessage) PMessageDescriptor(net.morimekta.providence.descriptor.PMessageDescriptor) NullArgument(net.morimekta.providence.jdbi.v2.util.NullArgument)

Aggregations

PMessage (net.morimekta.providence.PMessage)1 PField (net.morimekta.providence.descriptor.PField)1 PMessageDescriptor (net.morimekta.providence.descriptor.PMessageDescriptor)1 NullArgument (net.morimekta.providence.jdbi.v2.util.NullArgument)1