com.zaubersoftware.mule.module.github.GithubUnmarshalerImpl.java Source code

Java tutorial

Introduction

Here is the source code for com.zaubersoftware.mule.module.github.GithubUnmarshalerImpl.java

Source

/**
 * Copyright (c) 2011 Zauber S.A. <http://www.zaubersoftware.com>
 *
 * 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 com.zaubersoftware.mule.module.github;

import java.io.InputStream;
import java.util.List;

import org.apache.commons.lang.Validate;

import com.github.api.v2.schema.User;
import com.github.api.v2.services.impl.BaseGitHubService;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import com.zaubersoftware.mule.module.github.schema.Commit;
import com.zaubersoftware.mule.module.github.schema.Push;
import com.zaubersoftware.mule.module.github.schema.Repository;

/**
 * {@link GithubUnmarshaller} implementation.  
 * 
 * 
 * @author C. Andrs Moratti
 * @author Marcelo Turrn
 * @since Mar 24, 2011
 */
public class GithubUnmarshalerImpl extends BaseGitHubService implements GithubUnmarshaller {

    /** @see GithubUnmarshaller#unmarshallCommit(InputStream) */
    public final Push unmarshallCommit(final InputStream jsonStream) {
        final JsonObject json = unmarshall(jsonStream);
        Validate.notNull(json);
        List<Commit> commits = unmarshall(new TypeToken<List<Commit>>() {
        }, json.get("commits"));
        User pusher = unmarshall(new TypeToken<User>() {
        }, json.get("pusher"));
        Repository repository = unmarshall(new TypeToken<Repository>() {
        }, json.get("repository"));
        return new Push(pusher, repository, commits, json.getAsJsonPrimitive("ref").getAsString());
    }
}