@Override public void setUserValue(String name, Object value) { synchronized (this) { super.setUserValue(name, value); } }
public <T> void setUserValue(T object) { Objects.requireNonNull(object); setUserValue(object.getClass().getName(), object); }
public static void registerCode(Environment env, String protocol, Class<? extends WrapProcessor> clazz, int flags) { env.setUserValue(ProcessorException.class.getName() + "#" + protocol, ReflectionUtils.getClassName(clazz)); env.setUserValue(ProcessorException.class.getName() + "#" + protocol + ".flags", flags); }
private void init(Environment env) { userEnv = env.getUserValue("env", Map.class); if (userEnv == null) { env.setUserValue("env", userEnv = new LinkedHashMap<>()); } userEnv.putAll(System.getenv()); }
public static void registerProtocol(Environment env, String protocol, Class<? extends Stream> clazz) { env.setUserValue(Stream.class.getName() + "#" + protocol, ReflectionUtils.getClassName(clazz)); }
synchronized public static void putenv(Environment env, String _value) { if (_value.isEmpty()) { return; } String[] strings = StringUtils.split(_value, "=", 2); String name = strings[0]; String value = strings.length > 1 ? strings[1] : null; Map<String, String> zendEnv = env.getUserValue("env", Map.class); if (zendEnv == null) { env.setUserValue("env", zendEnv = new HashMap<String, String>()); } if (value == null) { zendEnv.remove(name); } else { zendEnv.put(name, value); } }
@Signature({ @Arg(value = "locale", nativeType = WrapLocale.class), @Arg(value = "globally", optional = @Optional("false")) }) public static Memory setDefault(Environment env, Memory... args) { Locale locale = args[0].toObject(WrapLocale.class).locale; if (args[1].toBoolean()) Locale.setDefault(locale); else env.setUserValue(WrapLocale.class.getName() + "#default", locale); return Memory.NULL; }
public static Memory json_decode(Environment env, String json, boolean assoc, int depth) { MemoryDeserializer memoryDeserializer = new MemoryDeserializer(); memoryDeserializer.setEnv(env); GsonBuilder gsonBuilder = JsonExtension.createGsonBuilderForDecode(memoryDeserializer); memoryDeserializer.setAssoc(assoc); memoryDeserializer.setMaxDepth(depth); Gson gson = gsonBuilder.create(); try { env.setUserValue(JsonFunctions.class.getName() + "#error", null); Memory r = gson.fromJson(json, Memory.class); if (r == null) return Memory.NULL; else return assoc ? r.toImmutable() : r; } catch (MemoryDeserializer.MaxDepthException e) { env.setUserValue(JsonFunctions.class.getName() + "#error", JsonConstants.JSON_ERROR_DEPTH); } catch (JsonSyntaxException e) { env.setUserValue(JsonFunctions.class.getName() + "#error", JsonConstants.JSON_ERROR_SYNTAX); } catch (JsonParseException e) { env.setUserValue(JsonFunctions.class.getName() + "#error", JsonConstants.JSON_ERROR_STATE_MISMATCH); } return Memory.NULL; }
@Signature({ @Arg(value = "timeZone", nativeType = WrapTimeZone.class), @Arg(value = "globally", optional = @Optional("false")) }) public static Memory setDefault(Environment env, Memory... args) { if (args[1].toBoolean()) TimeZone.setDefault(args[0].toObject(WrapTimeZone.class).timeZone); else env.setUserValue(WrapTime.class.getName() + "#def_time_zone", args[0].toObject(WrapTimeZone.class).timeZone); return Memory.NULL; }
@Signature({@Arg("protocol"), @Arg("className")}) public static Memory register(Environment env, Memory... args) { String protocol = args[0].toString(); String className = args[1].toString(); if (protocol.isEmpty()) { throw new IllegalArgumentException("Argument 1 (protocol) must be not empty"); } if (!protocol.matches("^[A-Za-z0-9]+$")) { throw new IllegalArgumentException("Invalid Argument 1 (protocol)"); } ClassEntity classEntity = env.fetchClass(className, true); if (classEntity == null){ throw new IllegalArgumentException(Messages.ERR_CLASS_NOT_FOUND.fetch(className)); } env.setUserValue(Stream.class.getName() + "#" + protocol, classEntity.getName()); return Memory.TRUE; }
@FastMethod @Signature public static Memory UTC(final Environment env, Memory... args) { Memory r = env.getUserValue(WrapTimeZone.class.getName() + "#UTC", Memory.class); if (r == null) { r = new ObjectMemory(new WrapTimeZone(env, UTC)); env.setUserValue(WrapTimeZone.class.getName() + "#UTC", r); } return r; }
@Signature({ @Arg("code"), @Arg("processorClass") }) public static Memory register(Environment env, Memory... args) { String code = args[0].toString(); String className = args[1].toString(); if (code.isEmpty()) { throw new IllegalArgumentException("Argument 1 (code) must be not empty"); } if (!code.matches("^[A-Za-z0-9]+$")) { throw new IllegalArgumentException("Invalid Argument 1 (code)"); } ClassEntity classEntity = env.fetchClass(className, true); if (classEntity == null) { throw new IllegalArgumentException(Messages.ERR_CLASS_NOT_FOUND.fetch(className)); } if (!classEntity.isInstanceOf(WrapProcessor.class)) { throw new IllegalArgumentException("Class " + className + " is not processor class"); } env.setUserValue(WrapProcessor.class.getName() + "#" + args[1].toString(), classEntity.getName()); return Memory.NULL; }