Search in sources :

Example 1 with AtlasFieldAction

use of io.atlasmap.api.AtlasFieldAction in project atlasmap by atlasmap.

the class DefaultAtlasFieldActionService method loadFieldActions.

protected void loadFieldActions() {
    ClassLoader classLoader = this.getClass().getClassLoader();
    final ServiceLoader<AtlasFieldAction> fieldActionServiceLoader = ServiceLoader.load(AtlasFieldAction.class, classLoader);
    for (final AtlasFieldAction atlasFieldAction : fieldActionServiceLoader) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Loading FieldAction class: " + atlasFieldAction.getClass().getCanonicalName());
        }
        Class<?> clazz = atlasFieldAction.getClass();
        Method[] methods = clazz.getMethods();
        for (Method method : methods) {
            AtlasFieldActionInfo annotation = method.getAnnotation(AtlasFieldActionInfo.class);
            if (annotation != null) {
                ActionDetail det = new ActionDetail();
                det.setClassName(clazz.getName());
                det.setMethod(method.getName());
                det.setName(annotation.name());
                det.setSourceType(annotation.sourceType());
                det.setTargetType(annotation.targetType());
                det.setSourceCollectionType(annotation.sourceCollectionType());
                det.setTargetCollectionType(annotation.targetCollectionType());
                try {
                    det.setParameters(detectFieldActionParameters("io.atlasmap.v2." + annotation.name()));
                } catch (ClassNotFoundException e) {
                    LOG.error(String.format("Error detecting parameters for field action=%s msg=%s", annotation.name(), e.getMessage()), e);
                }
                if (LOG.isTraceEnabled()) {
                    LOG.trace("Loaded FieldAction: " + det.getName());
                }
                listActionDetails().add(det);
            }
        }
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug(String.format("Loaded %s Field Actions", listActionDetails().size()));
    }
}
Also used : ActionDetail(io.atlasmap.v2.ActionDetail) AtlasFieldAction(io.atlasmap.api.AtlasFieldAction) Method(java.lang.reflect.Method) AtlasFieldActionInfo(io.atlasmap.spi.AtlasFieldActionInfo)

Aggregations

AtlasFieldAction (io.atlasmap.api.AtlasFieldAction)1 AtlasFieldActionInfo (io.atlasmap.spi.AtlasFieldActionInfo)1 ActionDetail (io.atlasmap.v2.ActionDetail)1 Method (java.lang.reflect.Method)1