public static Filter getFilter(Env env, Value filterIdV) { int filterId; int defaultFilterId = FILTER_UNSAFE_RAW; if (filterIdV.isDefault()) { // XXX: lookup in ini filterId = defaultFilterId; } else if (filterIdV.isArray()) { Value value = filterIdV.get(env.createString("filter")); if (value.isNull()) { filterId = defaultFilterId; } else { filterId = value.toInt(); } } else { filterId = filterIdV.toInt(); } Filter filter = _filterMap.get(filterId); if (filter == null) { throw new UnimplementedException( L.l("filter not implemented: {0} ({1})", filterIdV, filterId)); } return filter; }
@Override protected int getMarshalingCostImpl(Value argValue) { if (argValue.isArray()) { if (argValue instanceof JavaAdapter) return Marshal.ONE; else return Marshal.ZERO; } else return Marshal.FOUR; }
@Override protected int getMarshalingCostImpl(Value argValue) { if (argValue instanceof JavaListAdapter && getExpectedClass().isAssignableFrom(argValue.toJavaObject().getClass())) return Marshal.ZERO; else if (argValue.isArray()) return Marshal.THREE; else return Marshal.FOUR; }
@EntrySet public Set<Map.Entry<Value, Value>> entrySet() { LinkedHashMap<Value, Value> map = new LinkedHashMap<Value, Value>(); if (_attributes != null) { ArrayValue array = new ArrayValueImpl(); for (SimpleXMLElement attr : _attributes) { StringValue value = attr._text; array.put(_env.createString(attr._name), value); } map.put(_env.createString("@attributes"), array); } boolean hasElement = false; if (_children != null) { for (SimpleXMLElement child : _children) { if (!child.isElement()) continue; hasElement = true; StringValue name = _env.createString(child.getName()); Value oldChild = map.get(name); Value childValue; if (child._text != null) childValue = child._text; else childValue = wrapJava(_env, _cls, child); if (oldChild == null) { map.put(name, childValue); } else if (oldChild.isArray()) { ArrayValue array = (ArrayValue) oldChild; array.append(childValue); } else { ArrayValue array = new ArrayValueImpl(); array.append(oldChild); array.append(childValue); map.put(name, array); } } } if (!hasElement && _text != null) { map.put(LongValue.ZERO, _text); } return map.entrySet(); }
public boolean send(@NotNull Value value, @Optional JMSQueue replyTo) throws JMSException { Message message = null; if (value.isArray()) { message = _session.createMapMessage(); ArrayValue array = (ArrayValue) value; Set<Map.Entry<Value, Value>> entrySet = array.entrySet(); for (Map.Entry<Value, Value> entry : entrySet) { if (entry.getValue() instanceof BinaryValue) { byte[] bytes = ((BinaryValue) entry.getValue()).toBytes(); ((MapMessage) message).setBytes(entry.getKey().toString(), bytes); } else { // every primitive except for bytes can be translated from a string ((MapMessage) message).setString(entry.getKey().toString(), entry.getValue().toString()); } } } else if (value instanceof BinaryValue) { message = _session.createBytesMessage(); byte[] bytes = ((BinaryValue) value).toBytes(); ((BytesMessage) message).writeBytes(bytes); } else if (value.isLongConvertible()) { message = _session.createStreamMessage(); ((StreamMessage) message).writeLong(value.toLong()); } else if (value.isDoubleConvertible()) { message = _session.createStreamMessage(); ((StreamMessage) message).writeDouble(value.toDouble()); } else if (value.toJavaObject() instanceof String) { message = _session.createTextMessage(); ((TextMessage) message).setText(value.toString()); } else if (value.toJavaObject() instanceof Serializable) { message = _session.createObjectMessage(); ((ObjectMessage) message).setObject((Serializable) value.toJavaObject()); } else { return false; } if (replyTo != null) message.setJMSReplyTo(replyTo._destination); _producer.send(message); return true; }
public static Value filter_var( Env env, @ReadOnly Value value, @Optional Value filterIdV, @Optional Value flagV) { if (value.isArray()) { return BooleanValue.FALSE; } Filter filter = getFilter(env, filterIdV); if (filter == null) { return BooleanValue.FALSE; } return filter.filter(env, value, flagV); }
@Override protected int getMarshalingCostImpl(Value argValue) { if (argValue.isArray()) return Marshal.ZERO; else if (argValue.isString()) return Marshal.ONE; else return Marshal.MAX; }