script element.
+ *
+ * @author qinluo
+ * @date 2022-11-15 13:00:59
+ * @since 1.0.0
+ */
+public class ScriptElementParser extends AbstractElementParser {
+
+ @Override
+ public void doParse(Element element, ParserContext context) {
+ ScriptDefinition elementDefinition = new ScriptDefinition();
+ String name = element.getAttribute(ParseConstants.NAME);
+ AssertUtil.notBlank(name, "script name must not be blank");
+ String type = element.getAttribute("type");
+
+ elementDefinition.setName(name);
+ elementDefinition.setIdentifier(name);
+ elementDefinition.setType(type);
+ elementDefinition.setScript(element.getTextContent());
+ context.register(elementDefinition);
+ }
+
+ @Override
+ public String getElementName() {
+ return ParseConstants.SCRIPT;
+ }
+}
diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/component/AttributeHolder.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/attribute/AttributeHolder.java
similarity index 92%
rename from smart-flow-core/src/main/java/org/smartboot/flow/core/component/AttributeHolder.java
rename to smart-flow-core/src/main/java/org/smartboot/flow/core/attribute/AttributeHolder.java
index f40eada..1cac30f 100644
--- a/smart-flow-core/src/main/java/org/smartboot/flow/core/component/AttributeHolder.java
+++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/attribute/AttributeHolder.java
@@ -1,4 +1,4 @@
-package org.smartboot.flow.core.component;
+package org.smartboot.flow.core.attribute;
/**
* @author qinluo
diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/attribute/AttributeValueResolver.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/attribute/AttributeValueResolver.java
new file mode 100644
index 0000000..faa8313
--- /dev/null
+++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/attribute/AttributeValueResolver.java
@@ -0,0 +1,60 @@
+package org.smartboot.flow.core.attribute;
+
+import org.smartboot.flow.core.exception.FlowException;
+import org.smartboot.flow.core.parser.DefaultObjectCreator;
+import org.smartboot.flow.core.parser.ObjectCreator;
+
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * @author qinluo
+ * @date 2022-11-28 20:41:17
+ * @since 1.0.0
+ */
+public class AttributeValueResolver {
+
+ private ObjectCreator objectCreator = new DefaultObjectCreator();
+
+ public void setObjectCreator(ObjectCreator objectCreator) {
+ this.objectCreator = objectCreator;
+ }
+
+ public Object resolve(Attributes attribute, Object value) {
+ if (value == null) {
+ return null;
+ }
+
+ if (attribute.accept(value)) {
+ return value;
+ }
+
+ Class> accepted = attribute.accept;
+ // Must as string
+ String strValue = String.valueOf(value);
+
+ if (accepted == Boolean.class || accepted == boolean.class) {
+ return Boolean.parseBoolean(strValue);
+ }
+
+ if (accepted == Long.class || accepted == long.class) {
+ return Long.parseLong(strValue);
+ }
+
+ if (accepted == Integer.class || accepted == int.class) {
+ return Integer.parseInt(strValue);
+ }
+
+ if (accepted == List.class) {
+ return Arrays.asList(strValue.split(","));
+ }
+
+ try {
+ return objectCreator.create(strValue, true);
+ } catch (Exception ignored) {
+ // Maybe not a class.
+ }
+
+ throw new FlowException("Can't not resolve attribute [" + attribute.getName() + "] value with " + value);
+ }
+}
diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/component/Attributes.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/attribute/Attributes.java
similarity index 67%
rename from smart-flow-core/src/main/java/org/smartboot/flow/core/component/Attributes.java
rename to smart-flow-core/src/main/java/org/smartboot/flow/core/attribute/Attributes.java
index 5663440..2227a06 100644
--- a/smart-flow-core/src/main/java/org/smartboot/flow/core/component/Attributes.java
+++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/attribute/Attributes.java
@@ -1,9 +1,10 @@
-package org.smartboot.flow.core.component;
+package org.smartboot.flow.core.attribute;
+import org.smartboot.flow.core.DegradeCallback;
+import org.smartboot.flow.core.component.Component;
import org.smartboot.flow.core.util.AssertUtil;
-import java.util.Arrays;
import java.util.List;
@@ -12,6 +13,7 @@ import java.util.List;
* @date 2022-11-12 18:46:30
* @since 1.0.0
*/
+@SuppressWarnings("unchecked")
public enum Attributes {
NAME("name", String.class) {
@@ -26,9 +28,6 @@ public enum Attributes {
@Override
public + * 应用场景:将两个参数类型不同的业务组件适配成统一的类型 + * + *
+ * + * @author huqiang + * @since 2022/12/7 14:35 + */ +public interface Adapter before(EngineContext newContext);
}
diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/builder/AdapterBuilder.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/builder/AdapterBuilder.java
index 9b3c08b..816021d 100644
--- a/smart-flow-core/src/main/java/org/smartboot/flow/core/builder/AdapterBuilder.java
+++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/builder/AdapterBuilder.java
@@ -8,22 +8,22 @@ import org.smartboot.flow.core.component.Component;
* @author huqiang
* @since 2022/12/7 19:36
*/
-public class AdapterBuilder component;
- private AdapterComponent adapterComponent;
+ private AdapterComponent component) {
+ adapterComponent = new AdapterComponent<>();
adapterComponent.setAdapter(adapter);
adapterComponent.setComponent(component);
applyValues(adapterComponent);
}
- public AdapterComponent build() {
+ public AdapterComponent