Package br.com.caelum.restfulie.client

Source Code of br.com.caelum.restfulie.client.DefaultLinkConverter

/***
* Copyright (c) 2009 Caelum - www.caelum.com.br/opensource - guilherme.silveira@caelum.com.br
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*   http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package br.com.caelum.restfulie.client;

import br.com.caelum.restfulie.RestClient;
import br.com.caelum.restfulie.http.DefaultRelation;

import com.thoughtworks.xstream.converters.Converter;
import com.thoughtworks.xstream.converters.MarshallingContext;
import com.thoughtworks.xstream.converters.UnmarshallingContext;
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;

/**
* Default transition converter.<br>
* Injects the current deserializer to all transitions.
*
* @author guilherme silveira
*
*/
public class DefaultLinkConverter implements Converter {

  private final RestClient client;

  public DefaultLinkConverter(RestClient client) {
    this.client = client;
  }

  public void marshal(Object source, HierarchicalStreamWriter writer,
      MarshallingContext context) {
    // marshalling does not do anything
  }

  public Object unmarshal(HierarchicalStreamReader reader,
      UnmarshallingContext context) {
    String rel = reader.getAttribute("rel");
    String href = reader.getAttribute("href");
    return new DefaultRelation(rel, href, client);
  }

  public boolean canConvert(Class type) {
    return type.equals(DefaultRelation.class);
  }

}
TOP

Related Classes of br.com.caelum.restfulie.client.DefaultLinkConverter

TOP
Copyright © 2018 www.massapi.com. 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.