org.osgl.OsglConfig Java Examples

The following examples show how to use org.osgl.OsglConfig. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SampleData.java    From actframework with Apache License 2.0 6 votes vote down vote up
private static boolean shouldWaive(Method getter, Class<?> implementClass) {
    int modifiers = getter.getModifiers();
    if (Modifier.isTransient(modifiers) || Modifier.isStatic(modifiers)) {
        return true;
    }
    String fieldName = getter.getName().substring(3);
    Class<?> entityType = Generics.getReturnType(getter, implementClass);
    return ParamValueLoaderService.noBind(entityType)
            || getter.isAnnotationPresent(NoBind.class)
            || getter.isAnnotationPresent(Stateless.class)
            || getter.isAnnotationPresent(Global.class)
            || ParamValueLoaderService.isInBlackList(fieldName)
            || Object.class.equals(entityType)
            || Class.class.equals(entityType)
            || OsglConfig.globalMappingFilter_shouldIgnore(fieldName);
}
 
Example #2
Source File: Endpoint.java    From actframework with Apache License 2.0 6 votes vote down vote up
private static boolean shouldWaive(Method getter, Class<?> implementClass) {
    int modifiers = getter.getModifiers();
    if (Modifier.isTransient(modifiers) || Modifier.isStatic(modifiers)) {
        return true;
    }
    String fieldName = getter.getName().substring(3);
    Class<?> entityType = Generics.getReturnType(getter, implementClass);
    return ParamValueLoaderService.noBind(entityType)
            || getter.isAnnotationPresent(NoBind.class)
            || getter.isAnnotationPresent(Stateless.class)
            || getter.isAnnotationPresent(Global.class)
            || ParamValueLoaderService.isInBlackList(fieldName)
            || Object.class.equals(entityType)
            || Class.class.equals(entityType)
            || OsglConfig.globalMappingFilter_shouldIgnore(fieldName);
}
 
Example #3
Source File: SObject.java    From java-tool with Apache License 2.0 6 votes vote down vote up
protected boolean probeBinary() {
    String contentType = getContentType();
    if (null != contentType) {
        MimeType mimeType = MimeType.findByContentType(contentType);
        if (null != mimeType) {
            return !mimeType.test(MimeType.Trait.text);
        }
    }
    final $.Var<Boolean> var = new $.Var<>(false);
    consumeOnce(new $.F1<InputStream, Object>() {
        @Override
        public Object apply(InputStream is) throws NotAppliedException, Lang.Break {
            boolean isBinary = OsglConfig.binaryDataProbe().apply($.convert(is).to(Reader.class));
            var.set(isBinary);
            return null;
        }
    });
    return var.get();
}
 
Example #4
Source File: ResultSetRecordConverter.java    From java-tool with Apache License 2.0 5 votes vote down vote up
public T doConvert() {
    try {
        T entity = (T) OsglConfig.globalInstanceFactory().apply(targetType);
        if (Map.class.isAssignableFrom(targetType)) {
            return (T) convertToMap((Map) entity);
        } else if (AdaptiveMap.class.isAssignableFrom(targetType)) {
            return (T) convertToAdaptiveMap((AdaptiveMap) entity);
        } else {
            return (T) convertToEntity(entity);
        }
    } catch (SQLException e) {
        throw E.sqlException(e);
    }
}
 
Example #5
Source File: BufferedOutput.java    From java-tool with Apache License 2.0 5 votes vote down vote up
public static Output wrap(Output output) {
    int limit = OsglConfig.getThreadLocalCharBufferLimit();
    if (limit <= 2048) {
        // buffer too small (less than FastJSON SerializeWriter's internal buffer), no need to wrap it
        return output;
    }
    return new BufferedOutput(output);
}
 
Example #6
Source File: Genie.java    From java-di with Apache License 2.0 4 votes vote down vote up
private void registerModule(Object module) {
    boolean isClass = module instanceof Class;
    Class moduleClass = isClass ? (Class) module : module.getClass();
    if (Module.class.isAssignableFrom(moduleClass)) {
        if (isClass) {
            module = $.newInstance(moduleClass);
            isClass = false;
        }
        ((Module) module).applyTo(this);
    }

    if (Provider.class.isAssignableFrom(moduleClass)) {
        if (isClass) {
            module = OsglConfig.globalInstanceFactory().apply(moduleClass);
            isClass = false;
        }
        List<Type> typeParams = Generics.typeParamImplementations(moduleClass, Provider.class);
        if (typeParams.isEmpty()) {
            logger.warn("Unknown Provider: " + moduleClass);
        } else {
            Type type = typeParams.get(0);
            if (type instanceof Class) {
                registerProvider((Class) type, (Provider) module);
            } else {
                logger.warn("Unknown Provider: " + moduleClass);
            }
        }
    }

    for (Method method : moduleClass.getDeclaredMethods()) {
        if (method.isAnnotationPresent(Provides.class)) {
            method.setAccessible(true);
            boolean isStatic = Modifier.isStatic(method.getModifiers());
            if (isClass && !isStatic) {
                module = $.newInstance(moduleClass);
                isClass = false;
            }
            registerFactoryMethod(isStatic ? null : module, method);
        }
    }
}
 
Example #7
Source File: JsonUtilConfig.java    From actframework with Apache License 2.0 4 votes vote down vote up
public JsonWriter(Object v, PropertySpec.MetaInfo spec, boolean format, ActContext context) {
    if (null == v) {
        this.v = "{}";
        this.isLargeResponse = false;
        this.sv = (String)v;
    } else if (v instanceof String) {
        String s = S.string(v).trim();
        int len = s.length();
        if (0 == len) {
            this.v = "{}";
        } else {
            char a = s.charAt(0);
            char z = s.charAt(len - 1);
            if (('{' == a && '}' == z) || ('[' == a && ']' == z)) {
                this.v = s;
            } else {
                this.v = "{\"result\":" + s + "}";
            }
        }
        this.isLargeResponse = ((String) v).length() > OsglConfig.getThreadLocalCharBufferLimit();
        this.sv = (String) v;
    } else {
        this.v = v;
        AppConfig config = Act.appConfig();
        Locale locale = null == context ? config.locale() : context.locale(true);
        String dateFormatPattern = null == context ? null : context.dateFormatPattern();
        if (S.blank(dateFormatPattern)) {
            if (context instanceof ActionContext && ((ActionContext) context).shouldSuppressJsonDateFormat()) {
                this.dateFormat = null;
            } else {
                if (!config.i18nEnabled() || locale.equals(config.locale())) {
                    this.dateFormat = config.dateTimeFormat();
                } else {
                    dateFormatPattern = config.localizedDateTimePattern(locale);
                    this.dateFormat = new SimpleDateFormat(dateFormatPattern, locale);
                }
            }
        } else {
            this.dateFormat = new SimpleDateFormat(dateFormatPattern, locale);
        }
        this.disableCircularReferenceDetect = null == spec && context.isDisableCircularReferenceDetect();
        this.filters = initFilters(v, spec, context);
        this.features = initFeatures(format, context);
        this.config = initConfig(context);
        this.isLargeResponse = context instanceof ActionContext && ((ActionContext) context).isLargeResponse();
    }
}
 
Example #8
Source File: BufferedOutput.java    From java-tool with Apache License 2.0 4 votes vote down vote up
private BufferedOutput(Output output) {
    sink = $.requireNotNull(output);
    charBufLimit = OsglConfig.getThreadLocalCharBufferLimit();
    byteBufLimit = OsglConfig.getThreadLocalByteArrayBufferLimit();
}
 
Example #9
Source File: StringReplace.java    From java-tool with Apache License 2.0 4 votes vote down vote up
public SimpleStringReplace() {
    this(OsglConfig.DEF_STRING_SEARCH);
}