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

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


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

    final EJObject obj = o.isObject();
   
    String objId = obj.get(SerializationParts.OBJECT_ID).isString().stringValue();
    if (ctx.hasObjectHash(objId)) {
      return (C) ctx.getObject(Object.class, objId);
    }
   
    C val = doDemarshall(o, ctx);
View Full Code Here


  }

  @Override
  public Object doNotNullDemarshall(EJValue o, MarshallingSession ctx) {
    if (o.isObject() != null) {
      EJObject jsObject = o.isObject();
      EJString string = jsObject.get(SerializationParts.ENCODED_TYPE).isString();
      if (string == null) {
        return MapMarshaller.INSTANCE.demarshall(o, ctx);
      }

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

      Marshaller<Object> marshaller = ctx.getMarshallerInstance(string.stringValue());

      if (marshaller == null) {
View Full Code Here

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

  protected Map doDermashall(Map impl, EJValue o, MarshallingSession ctx) {
    EJObject jsonObject = o.isObject();
    if (jsonObject == null)
      return null;

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

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

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

  protected Map doDermashall(Map impl, EJValue o, MarshallingSession ctx) {
    EJObject jsonObject = o.isObject();

    for (String key : jsonObject.keySet()) {
      if (MessageParts.SessionID.name().equals(key)) continue;
      EJValue v = jsonObject.get(key);
      if (!v.isNull()) {
        impl.put(key, ctx.getMarshallerInstance(ctx.determineTypeFor(null, v)).demarshall(v, ctx));
      }
      else {
        impl.put(key, null);
View Full Code Here

    return delegate.getTypeHandled();
  }

  @Override
  public T doNotNullDemarshall(EJValue o, MarshallingSession ctx) {
    EJObject obj = o.isObject();
    String objId = obj.get(SerializationParts.OBJECT_ID).isString().stringValue();
    if (ctx.hasObjectHash(objId)) {
      //noinspection unchecked
      return (T) ctx.getObject(Object.class, objId);
    }
View Full Code Here

  public T demarshall(EJValue o, MarshallingSession ctx) {
    return doDermashall((T) new HashMap(), o, ctx);
  }

  protected T doDermashall(T impl, EJValue o, MarshallingSession ctx) {
    EJObject jsonObject = o.isObject();

    Object demarshalledKey, demarshalledValue;
    for (String key : jsonObject.keySet()) {
      if (key.startsWith(SerializationParts.EMBEDDED_JSON)) {
        EJValue val = ParserFactory.get().parse(key.substring(SerializationParts.EMBEDDED_JSON.length()));
        demarshalledKey = ctx.getMarshallerInstance(ctx.determineTypeFor(null, val)).demarshall(val, ctx);
      }
      else {
        demarshalledKey = key;
      }

      EJValue v = jsonObject.get(key);
      if (!v.isNull()) {
       demarshalledValue = ctx.getMarshallerInstance(ctx.determineTypeFor(null, v)).demarshall(v, ctx);
      }
      else {
        demarshalledValue = null;
View Full Code Here

    else if (!(frame instanceof TextWebSocketFrame)) {
      throw new UnsupportedOperationException(String.format("%s frame types not supported", frame.getClass()
              .getName()));
    }

    @SuppressWarnings("unchecked") EJObject val = JSONDecoder.decode(((TextWebSocketFrame) frame).getText()).isObject();

    QueueSession session;

    // this is not an active channel.
    if (!activeChannels.containsKey(ctx.getChannel())) {
      String commandType =  val.get(MessageParts.CommandType.name()).isString().stringValue();

      // this client apparently wants to connect.
      if (BusCommands.ConnectToQueue.name().equals(commandType)) {
        String sessionKey = val.get(MessageParts.ConnectionSessionKey.name()).isString().stringValue();

        // has this client already attempted a connection, and is in a wait verify state
        if (sessionKey != null && (session = svc.getBus().getSessionBySessionId(sessionKey)) != null) {
          if (session.hasAttribute(SESSION_ATTR_WS_STATUS) &&
                  WEBSOCKET_ACTIVE.equals(session.getAttribute(String.class, SESSION_ATTR_WS_STATUS))) {

            // open the channel
            activeChannels.put(ctx.getChannel(), session);

            // set the session queue into direct channel mode.
            svc.getBus().getQueueBySession(sessionKey).setDirectSocketChannel(ctx.getChannel());

            // remove the web socket token so it cannot be re-used for authentication.
            session.removeAttribute(MessageParts.WebSocketToken.name());
            session.removeAttribute(SESSION_ATTR_WS_STATUS);

            return;
          }

          // check the activation key matches what we have in the ssession.
          String activationKey = session.getAttribute(String.class, MessageParts.WebSocketToken.name());
          if (activationKey == null || !activationKey.equals(val.get(MessageParts.WebSocketToken.name()).isString().stringValue())) {
            // nope. go away!
            sendMessage(ctx, getFailedNegotiation("bad negotiation key"));
          }
          else {
            // the key matches. now we send the reverse challenge to prove this client is actually
View Full Code Here

  public T demarshall(EJValue o, MarshallingSession ctx) {
    return doDermashall((T) new HashMap(), o, ctx);
  }

  protected T doDermashall(T impl, EJValue o, MarshallingSession ctx) {
    EJObject jsonObject = o.isObject();

    Object demarshalledKey, demarshalledValue;
    for (String key : jsonObject.keySet()) {
      if (key.startsWith(SerializationParts.EMBEDDED_JSON)) {
        EJValue val = ParserFactory.get().parse(key.substring(SerializationParts.EMBEDDED_JSON.length()));
        demarshalledKey = ctx.getMarshallerInstance(ctx.determineTypeFor(null, val)).demarshall(val, ctx);
      }
      else {
        demarshalledKey = key;
      }

      EJValue v = jsonObject.get(key);
      if (!v.isNull()) {
       demarshalledValue = ctx.getMarshallerInstance(ctx.determineTypeFor(null, v)).demarshall(v, ctx);
      }
      else {
        demarshalledValue = null;
View Full Code Here

  @SuppressWarnings({"ConstantConditions", "unchecked"})
  @Override
  public Object demarshall(final EJValue o, final MarshallingSession ctx) {
    try {
      if (o.isObject() != null) {
        final EJObject oMap = o.isObject();
        final Object newInstance;

        if (MarshallUtil.isEncodedObject(oMap)) {
          if (MarshallUtil.isEncodedNumeric(oMap)) {
            return NumbersUtils.getEncodedNumber(oMap);
          }

          final String objID = oMap.get(SerializationParts.OBJECT_ID).isString().stringValue();

          if (ctx.hasObject(objID)) {
            newInstance = ctx.getObject(Object.class, objID);

            /**
             * If this only contains 2 fields, it is only a graph reference.
             */
            if (oMap.size() == 2) {
              return newInstance;
            }
          }
          else {
            /**
             * Check to see if this object is instantiate only... meaning it has no fields to marshall.
             */
            if (oMap.containsKey(SerializationParts.INSTANTIATE_ONLY)) {
              newInstance = getTypeHandled().newInstance();
              ctx.recordObject(objID, newInstance);
              return newInstance;
            }

            final InstantiationMapping cMapping = definition.getInstantiationMapping();
            final Object[] parms = new Object[cMapping.getMappings().length];
            final Class[] targetTypes = cMapping.getSignature();

            int i = 0;
            for (final Mapping mapping : cMapping.getMappings()) {
              final Marshaller<Object> marshaller = ctx.getMarshallerInstance(mapping.getType().getFullyQualifiedName());
              //noinspection unchecked
              parms[i] = DataConversion.convert(
                      marshaller.demarshall(oMap.get(mapping.getKey()), ctx), targetTypes[i++]);
            }

            if (cMapping instanceof ConstructorMapping) {
              final Constructor constructor = ((ConstructorMapping) cMapping).getMember().asConstructor();
              constructor.setAccessible(true);
              newInstance = constructor.newInstance(parms);
            }
            else {
              newInstance = ((FactoryMapping) cMapping).getMember().asMethod().invoke(null, parms);
            }

            ctx.recordObject(objID, newInstance);
          }

          for (final MemberMapping mapping : definition.getWritableMemberMappings()) {
            final EJValue o1 = oMap.get(mapping.getKey());

            if (!o1.isNull()) {
              final Marshaller<Object> marshaller
                      = ctx.getMarshallerInstance(mapping.getType().getFullyQualifiedName());

              if (mapping.getBindingMember() instanceof MetaField) {
                final MetaField f = (MetaField) mapping.getBindingMember();

                setProperty(newInstance, f.asField(),
                        marshaller.demarshall(o1, ctx));
              }
              else {
                final Method m = ((MetaMethod) mapping.getBindingMember()).asMethod();

                m.invoke(newInstance, DataConversion.convert(
                        marshaller.demarshall(o1, ctx),
                        m.getParameterTypes()[0]));
              }
            }
          }

          return newInstance;
        }
        else if (oMap.containsKey(SerializationParts.ENUM_STRING_VALUE)) {
          return Enum.valueOf(getClassReference(oMap),
                  oMap.get(SerializationParts.ENUM_STRING_VALUE).isString().stringValue());
        }
        else {
          throw new RuntimeException("bad payload");
        }
      }
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

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.