All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sfm.reflect.meta.DirectClassMeta Maven / Gradle / Ivy

Go to download

Java library to map flat record - ResultSet, csv - to java object with minimum configuration and low footprint.

There is a newer version: 1.10.3
Show newest version
package org.sfm.reflect.meta;

import org.sfm.map.MapperBuildingException;
import org.sfm.reflect.InstantiatorDefinition;
import org.sfm.reflect.Getter;
import org.sfm.reflect.ReflectionService;
import org.sfm.reflect.Setter;
import org.sfm.reflect.impl.NullSetter;

import java.lang.reflect.Type;
import java.util.Collections;
import java.util.List;

public final class DirectClassMeta implements ClassMeta {


    public static final String[] HEADERS = new String[]{""};
    private final ReflectionService reflectService;
	private final Type target;

	public DirectClassMeta(Type target, ReflectionService reflectService) throws MapperBuildingException {
		this.target = target;
		this.reflectService = reflectService;
	}


    @Override
    public ReflectionService getReflectionService() {
        return reflectService;
    }

    @Override
    public PropertyFinder newPropertyFinder() {
        return new DirectPropertyFinder();
    }

    @Override
    public Type getType() {
        return target;
    }

    @Override
    public String[] generateHeaders() {
        return HEADERS;
    }

    @Override
    public boolean isLeaf() {
        return true;
    }

    @Override
    public List getInstantiatorDefinitions() {
        return Collections.emptyList();
    }

    public class DirectPropertyFinder implements PropertyFinder {

        @Override
        public  PropertyMeta findProperty(PropertyNameMatcher propertyNameMatcher) {
            return new DirectPropertyMeta("direct", reflectService, target);
        }

        @Override
        public List getEligibleInstantiatorDefinitions() {
            return null;
        }

        @Override
        public  ConstructorPropertyMeta findConstructor(InstantiatorDefinition instantiatorDefinition) {
            return null;
        }
    }

    public class DirectPropertyMeta extends PropertyMeta {
        private final Type type;

        public DirectPropertyMeta(String name, ReflectionService reflectService, Type type) {
            super(name, reflectService);
            this.type = type;
        }


        @Override
        protected Setter newSetter() {
            return NullSetter.setter();
        }

        @Override
        protected Getter newGetter() {
            throw new UnsupportedOperationException();

        }

        @Override
        public Type getType() {
            return type;
        }

        @Override
        public String getPath() {
            return ".";
        }

        @Override
        public String toString() {
            return "DirectPropertyMeta{" +
                    "type=" + type +
                    '}';
        }
    }

    @Override
    public String toString() {
        return "DirectClassMeta{" +
                "target=" + target +
                '}';
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy