Search in sources :

Example 1 with NotAppliedException

use of org.osgl.exception.NotAppliedException in project actframework by actframework.

the class JsonUtilConfig method configure.

public static void configure(final App app) {
    SerializeConfig config = SerializeConfig.getGlobalInstance();
    // patch https://github.com/alibaba/fastjson/issues/478
    config.put(FastJsonIterable.class, FastJsonIterableSerializer.instance);
    FastJsonJodaDateCodec jodaDateCodec = new FastJsonJodaDateCodec(app);
    app.registerSingleton(FastJsonJodaDateCodec.class, jodaDateCodec);
    FastJsonValueObjectSerializer valueObjectSerializer = new FastJsonValueObjectSerializer();
    app.registerSingleton(FastJsonValueObjectSerializer.class, valueObjectSerializer);
    FastJsonKeywordCodec keywordCodec = new FastJsonKeywordCodec();
    FastJsonSObjectCodec sObjectCodec = new FastJsonSObjectCodec();
    config.put(DateTime.class, jodaDateCodec);
    config.put(LocalDate.class, jodaDateCodec);
    config.put(LocalTime.class, jodaDateCodec);
    config.put(LocalDateTime.class, jodaDateCodec);
    config.put(ValueObject.class, valueObjectSerializer);
    config.put(Keyword.class, keywordCodec);
    config.put(KV.class, FastJsonKvCodec.INSTANCE);
    config.put(KVStore.class, FastJsonKvCodec.INSTANCE);
    ParserConfig parserConfig = ParserConfig.getGlobalInstance();
    parserConfig.putDeserializer(DateTime.class, jodaDateCodec);
    parserConfig.putDeserializer(LocalDate.class, jodaDateCodec);
    parserConfig.putDeserializer(LocalTime.class, jodaDateCodec);
    parserConfig.putDeserializer(LocalDateTime.class, jodaDateCodec);
    parserConfig.putDeserializer(Keyword.class, keywordCodec);
    parserConfig.putDeserializer(KV.class, FastJsonKvCodec.INSTANCE);
    parserConfig.putDeserializer(KVStore.class, FastJsonKvCodec.INSTANCE);
    parserConfig.putDeserializer(ISObject.class, sObjectCodec);
    parserConfig.putDeserializer(SObject.class, sObjectCodec);
    MvcConfig.jsonSerializer(new $.Func2<Writer, Object, Void>() {

        @Override
        public Void apply(Writer writer, Object v) throws NotAppliedException, $.Break {
            new JsonWriter(v, null, false, ActContext.Base.currentContext()).apply(writer);
            return null;
        }
    });
}
Also used : org.osgl.$(org.osgl.$) NotAppliedException(org.osgl.exception.NotAppliedException) ISObject(org.osgl.storage.ISObject) SObject(org.osgl.storage.impl.SObject) ParserConfig(com.alibaba.fastjson.parser.ParserConfig) Writer(java.io.Writer)

Example 2 with NotAppliedException

use of org.osgl.exception.NotAppliedException in project actframework by actframework.

the class DevModeClassLoader method scanSources.

private void scanSources() {
    Timer timer = metric.startTimer("act:classload:scan:scanSources");
    try {
        logger.debug("start to scan sources...");
        List<AppSourceCodeScanner> scanners = app().scannerManager().sourceCodeScanners();
        Set<String> classesNeedByteCodeScan = C.newSet();
        if (scanners.isEmpty()) {
            // LOGGER.warn("No source code scanner found");
            for (String className : sources.keySet()) {
                classesNeedByteCodeScan.add(className);
            }
        } else {
            for (String className : sources.keySet()) {
                classesNeedByteCodeScan.add(className);
                logger.debug("scanning %s ...", className);
                List<AppSourceCodeScanner> l = new ArrayList<>();
                for (AppSourceCodeScanner scanner : scanners) {
                    if (scanner.start(className)) {
                        // LOGGER.trace("scanner %s added to the list", scanner.getClass().getName());
                        l.add(scanner);
                    }
                }
                Source source = source(className);
                String[] lines = source.code().split("[\\n\\r]+");
                for (int i = 0, j = lines.length; i < j; ++i) {
                    String line = lines[i];
                    for (AppSourceCodeScanner scanner : l) {
                        scanner.visit(i, line, className);
                    }
                }
            }
        }
        if (classesNeedByteCodeScan.isEmpty()) {
            return;
        }
        final Set<String> embeddedClassNames = C.newSet();
        scanByteCode(classesNeedByteCodeScan, new $.F1<String, byte[]>() {

            @Override
            public byte[] apply(String s) throws NotAppliedException, $.Break {
                return bytecodeFromSource(s, embeddedClassNames);
            }
        });
        while (!embeddedClassNames.isEmpty()) {
            Set<String> embeddedClassNameCopy = C.newSet(embeddedClassNames);
            scanByteCode(embeddedClassNameCopy, new $.F1<String, byte[]>() {

                @Override
                public byte[] apply(String s) throws NotAppliedException, $.Break {
                    return bytecodeFromSource(s, embeddedClassNames);
                }
            });
            embeddedClassNames.removeAll(embeddedClassNameCopy);
        }
    } finally {
        timer.stop();
    }
}
Also used : org.osgl.$(org.osgl.$) NotAppliedException(org.osgl.exception.NotAppliedException) Timer(act.metric.Timer)

Example 3 with NotAppliedException

use of org.osgl.exception.NotAppliedException in project actframework by actframework.

the class I18n method buildEnumPropertyGetters.

private static Map<String, $.Function<Object, Object>> buildEnumPropertyGetters(Class<? extends Enum> enumClass) {
    Map<String, $.Function<Object, Object>> map = new HashMap<>();
    for (final Method method : enumClass.getMethods()) {
        if (void.class == method.getReturnType() || Void.class == method.getReturnType() || Modifier.isStatic(method.getModifiers()) || method.getParameterTypes().length > 0) {
            continue;
        }
        String name = propertyName(method);
        if (standardsAnnotationMethods.contains(name)) {
            continue;
        }
        map.put(method.getName(), new Osgl.Function<Object, Object>() {

            @Override
            public Object apply(Object o) throws NotAppliedException, Osgl.Break {
                return $.invokeVirtual(o, method);
            }
        });
    }
    return map;
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) NotAppliedException(org.osgl.exception.NotAppliedException) Method(java.lang.reflect.Method) Osgl(org.osgl.Osgl)

Aggregations

NotAppliedException (org.osgl.exception.NotAppliedException)3 org.osgl.$ (org.osgl.$)2 Timer (act.metric.Timer)1 ParserConfig (com.alibaba.fastjson.parser.ParserConfig)1 Writer (java.io.Writer)1 Method (java.lang.reflect.Method)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Osgl (org.osgl.Osgl)1 ISObject (org.osgl.storage.ISObject)1 SObject (org.osgl.storage.impl.SObject)1