use of io.atlasmap.spi.AtlasFieldActionInfo in project atlasmap by atlasmap.
the class StringComplexFieldActions method padStringLeft.
@AtlasFieldActionInfo(name = "PadStringLeft", sourceType = FieldType.STRING, targetType = FieldType.STRING, sourceCollectionType = CollectionType.NONE, targetCollectionType = CollectionType.NONE)
public static String padStringLeft(Action action, String input) {
if (action == null || !(action instanceof PadStringLeft) || ((PadStringLeft) action).getPadCharacter() == null || ((PadStringLeft) action).getPadCount() == null) {
throw new IllegalArgumentException("PadStringLeft must be specfied with padCharacter and padCount");
}
PadStringLeft padStringLeft = (PadStringLeft) action;
StringBuilder builder = new StringBuilder();
for (int i = 0; i < padStringLeft.getPadCount(); i++) {
builder.append(padStringLeft.getPadCharacter());
}
if (input != null) {
builder.append(input);
}
return builder.toString();
}
use of io.atlasmap.spi.AtlasFieldActionInfo in project atlasmap by atlasmap.
the class StringComplexFieldActions method replaceFirst.
@AtlasFieldActionInfo(name = "ReplaceFirst", sourceType = FieldType.STRING, targetType = FieldType.STRING, sourceCollectionType = CollectionType.NONE, targetCollectionType = CollectionType.NONE)
public static String replaceFirst(Action action, String input) {
if (action == null || !(action instanceof ReplaceFirst)) {
throw new IllegalArgumentException("Action must be a ReplaceFirst action");
}
ReplaceFirst replaceFirst = (ReplaceFirst) action;
String match = replaceFirst.getMatch();
if (match == null || match.length() == 0) {
throw new IllegalArgumentException("ReplaceFirst action must be specified with a non-empty old string");
}
String newString = replaceFirst.getNewString();
return input == null ? null : input.replaceFirst(match, newString == null ? "" : newString);
}
use of io.atlasmap.spi.AtlasFieldActionInfo 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()));
}
}
Aggregations