Skip to content

Commit

Permalink
jacline: Improve Dumbo init
Browse files Browse the repository at this point in the history
  • Loading branch information
kohlschuetter committed May 5, 2024
1 parent b6a17e0 commit 8ef118a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
15 changes: 9 additions & 6 deletions dumbo-jacline/src/main/java/com/kohlschutter/dumbo/js/Dumbo.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.kohlschutter.jacline.lib.coding.Codable;
import com.kohlschutter.jacline.lib.coding.CodingException;
import com.kohlschutter.jacline.lib.coding.Decodables;
import com.kohlschutter.jacline.lib.coding.Decoder;
import com.kohlschutter.jacline.lib.coding.Dictionary;
import com.kohlschutter.jacline.lib.coding.KeyDecoder;
import com.kohlschutter.jacline.lib.coding.KeyEncoder;
Expand Down Expand Up @@ -74,6 +75,13 @@ public static String resolveServiceTypeFromAlias(Class<?> clazz) {
}
}

@JsOverlay
public static String registerCodable(Class<?> clazz, Decoder<?> dec) {
String codedType = resolveServiceTypeFromAlias(clazz);
Decodables.setDecoder(codedType, dec);
return codedType;
}

@JsOverlay
public static void setText(Node node, String selector, Object text) {
setText0(node, selector, text);
Expand Down Expand Up @@ -174,12 +182,7 @@ public interface PostUnmarshalFunction {
}

@JsOverlay
public static void jaclineInit() {
Dumbo.whenLive(Dumbo::registerMarshallFiltersForJacline);
}

@JsOverlay
private static void registerMarshallFiltersForJacline() {
static void registerMarshallFiltersForJacline() {
Dumbo.registerMarshallFilters((m) -> {
if (m instanceof Codable) {
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* dumbo-jacline
*
* Copyright 2023 Christian Kohlschütter
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.kohlschutter.dumbo.js;

import com.kohlschutter.jacline.annotations.JsEntryPoint;
import com.kohlschutter.jacline.lib.util.JaclineUtil;

@JsEntryPoint
final class JaclineInit {
static {
if (JaclineUtil.isJavaScriptEnvironment()) {
Dumbo.registerMarshallFiltersForJacline();
}
}
}

0 comments on commit 8ef118a

Please sign in to comment.