Package org.jboss.errai.marshalling.client.api.json

Examples of org.jboss.errai.marshalling.client.api.json.EJObject


    final QueueSession session;
    final EJValue val = JSONDecoder.decode(((TextFrame) frame).getText());
    // this is not an active channel.
    if (!activeChannels.containsKey(socket)) {
      final EJObject ejObject = val.isObject();
      if (ejObject == null) {
        return;
      }

      final String commandType = ejObject.get(MessageParts.CommandType.name()).isString().stringValue();

      // this client apparently wants to connect.
      if (BusCommand.Associate.name().equals(commandType)) {
        final String sessionKey = ejObject.get(MessageParts.ConnectionSessionKey.name()).isString().stringValue();

        // has this client already attempted a connection, and is in a wait verify state
        if (sessionKey != null && (session = service.getBus().getSessionBySessionId(sessionKey)) != null) {
          final LocalContext localCometSession = LocalContext.get(session);

          if (localCometSession.hasAttribute(WebSocketServerHandler.SESSION_ATTR_WS_STATUS) &&
                  WebSocketServerHandler.WEBSOCKET_ACTIVE.equals(localCometSession.getAttribute(String.class, WebSocketServerHandler.SESSION_ATTR_WS_STATUS))) {

            // set the session queue into direct channel mode.
            final MessageQueue queue = service.getBus().getQueueBySession(sessionKey);
            queue.setDeliveryHandler(DirectDeliveryHandler.createFor(new SimpleEventChannelWrapped(socket)));
            activeChannels.put(socket, session);
            return;
          }

          // check the activation key matches.
          final EJString activationKey = ejObject.get(MessageParts.WebSocketToken.name()).isString();
          if (activationKey == null || !WebSocketTokenManager.verifyOneTimeToken(session, activationKey.stringValue())) {

            // nope. go away!
            sendMessage(new SimpleEventChannelWrapped(socket), getFailedNegotiation("bad negotiation key"));
          }
View Full Code Here


    return delegate.getEmptyArray();
  }

  @Override
  public T doNotNullDemarshall(final EJValue o, final MarshallingSession ctx) {
    final EJObject obj = o.isObject();

    if (obj != null) {
      final String objId = obj.get(SerializationParts.OBJECT_ID).isString().stringValue();
      if (ctx.hasObject(objId)) {
        // noinspection unchecked
        return (T) ctx.getObject(Object.class, objId);
      }

      EJValue val = obj.get(SerializationParts.QUALIFIED_VALUE);
      if (val.isNull()) {
        val = o;
      }
      return ctx.recordObject(objId, delegate.demarshall(val, ctx));
    }
View Full Code Here

  @Override
  public final C doDemarshall(final EJValue o, final MarshallingSession ctx) {
    if (o.isNull()) return null;

    final EJObject obj = o.isObject();

    if (obj != null) {
      final EJValue val = obj.get(SerializationParts.QUALIFIED_VALUE);
      return doDemarshall(val.isArray(), ctx);
    }
    else {
      return doDemarshall(o.isArray(), ctx);
    }
View Full Code Here

    for (int i = 0; i < array.size(); i++) {
      final EJValue elem = array.get(i);
      if (!elem.isNull()) {
        String type = null;
        final EJObject jsonObject;
        if ((jsonObject = elem.isObject()) != null) {
          if (!jsonObject.containsKey(SerializationParts.ENCODED_TYPE)) {
            // for collections with a concrete type parameter, we treat the ^EncodedType value as optional
            type = assumedElementType;
          }
        }
View Full Code Here

    if (o.isNull()) {
      return null;
    }

    if (o.isObject() != null) {
      final EJObject jsObject = o.isObject();
      final EJValue ejEncType = jsObject.get(SerializationParts.ENCODED_TYPE);
      String encodedType = null;
      if (!ejEncType.isNull() && ejEncType.isString() != null) {
        encodedType = ejEncType.isString().stringValue();
      }

      if (encodedType == null) {
        if (targetType == null) {
          if (jsObject.containsKey(SerializationParts.QUALIFIED_VALUE)) {
            // the object we're decoding is a wrapper with ^ObjectID and ^Value, but no type information.
            // just bypass this layer and return the "meat"
            return demarshall(Object.class, jsObject.get(SerializationParts.QUALIFIED_VALUE), ctx);
          }
          // without a ^Value property, this must be a Map
          return MapMarshaller.INSTANCE.demarshall(o, ctx);
        }
        else if (ctx.getMarshallerInstance(targetType.getName()) != null) {
          return ctx.getMarshallerInstance(targetType.getName()).demarshall(o, ctx);
        }
      }

      if (jsObject.containsKey(SerializationParts.NUMERIC_VALUE)) {
        return NumbersUtils.getNumber(encodedType, jsObject.get(SerializationParts.NUMERIC_VALUE));
      }

      if (ctx.getMarshallerInstance(encodedType) == null) {
        throw new RuntimeException("marshalled type is unknown to the marshalling framework: " + encodedType);
      }
View Full Code Here

  public Map<String, Object> demarshall(final EJValue o, final MarshallingSession ctx) {
    return doDemarshall(new HashMap<String, Object>(), o, ctx);
  }

  protected Map<String, Object> doDemarshall(final Map<String, Object> impl, final EJValue o, final MarshallingSession ctx) {
    final EJObject jsonObject = o.isObject();
    if (jsonObject == null)
      return null;

    for (final String key : jsonObject.keySet()) {
      final EJValue v = jsonObject.get(key);
      if (!v.isNull()) {
        final String type = ctx.determineTypeFor(null, v);

        if (type == null) {
          impl.put(key, v.toString());
View Full Code Here

  }

  protected Map<String, Object> doDemarshall(final Map<String, Object> impl,
                                             final EJValue o,
                                             final MarshallingSession ctx) {
    final EJObject jsonObject = o.isObject();

    for (final String key : jsonObject.keySet()) {
      if (MessageParts.SessionID.name().equals(key))
        continue;
      final EJValue v = jsonObject.get(key);
      if (!v.isNull()) {
        final Marshaller<Object> marshallerInstance = ctx.getMarshallerInstance(ctx.determineTypeFor(null, v));
        if (marshallerInstance == null) {
          if (MessageParts.Throwable.name().equals(key)) {
            impl.put(key, new Throwable(v.isObject().get("message").isString().stringValue()));
View Full Code Here

  public C demarshall(final EJValue o, final MarshallingSession ctx) {
    if (o.isNull()) {
      return null;
    }

    final EJObject obj = o.isObject();

    final String objId = obj.get(SerializationParts.OBJECT_ID).isString().stringValue();
    if (ctx.hasObject(objId)) {
      return (C) ctx.getObject(Object.class, objId);
    }

    final C val = doDemarshall(o, ctx);
View Full Code Here

    }

    @Override
    public String determineTypeFor(final String formatType, final Object o) {
      if (((EJValue) o).isObject() != null) {
        final EJObject jsonObject = ((EJValue) o).isObject();
        if (jsonObject.containsKey(SerializationParts.ENCODED_TYPE)) {
          return jsonObject.get(SerializationParts.ENCODED_TYPE).isString().stringValue();
        }
        else {
          return Map.class.getName();
        }
      }
View Full Code Here

  @Override
  public String determineTypeFor(final String formatType, final Object o) {
    final EJValue jsonValue = (EJValue) o;

    if (jsonValue.isObject() != null) {
      final EJObject jsonObject = jsonValue.isObject();
      if (jsonObject.containsKey(SerializationParts.ENCODED_TYPE)) {
        return jsonObject.get(SerializationParts.ENCODED_TYPE).isString().stringValue();
      }
      else {
        return Map.class.getName();
      }
    }
View Full Code Here

TOP

Related Classes of org.jboss.errai.marshalling.client.api.json.EJObject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.