Android Open Source - Mamytas Rest Method Factory






From Project

Back to project page Mamytas.

License

The source code is released under:

GNU General Public License

If you think the Android project Mamytas listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package mn.aug.restfulandroid.rest;
//from w w  w. ja  v a2 s .  c  o  m
import android.content.Context;
import android.content.UriMatcher;
import android.net.Uri;

import java.util.List;
import java.util.Map;

import mn.aug.restfulandroid.rest.resource.Lists;
import mn.aug.restfulandroid.rest.resource.Listw;
import mn.aug.restfulandroid.rest.resource.Login;
import mn.aug.restfulandroid.rest.resource.Task;
import mn.aug.restfulandroid.rest.resource.Tasks;
import mn.aug.restfulandroid.rest.resource.Timers;
import mn.aug.restfulandroid.service.ShareProcessor;

public class RestMethodFactory {

    private static final int TASKS = 1;
    private static final int LOGIN = 2;
    private static final int TASK = 3;
    private static final int TIMERS = 4;
    private static final int LISTS = 5;
    private static final int LIST = 6;
    private static final int SHARE=7;
    private static RestMethodFactory instance;
    private static Object lock = new Object();
    private UriMatcher uriMatcher;
    private Context mContext;

    private RestMethodFactory(Context context) {
        mContext = context.getApplicationContext();
        uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
        uriMatcher.addURI(Tasks.AUTHORITY, Tasks.PATH, TASKS);
        uriMatcher.addURI(Login.AUTHORITY, Login.PATH, LOGIN);
        uriMatcher.addURI(Task.AUTHORITY, Task.PATH, TASK);
        uriMatcher.addURI(Timers.AUTHORITY, Timers.PATH, TIMERS);
        uriMatcher.addURI(Lists.AUTHORITY, Lists.PATH, LISTS);
        uriMatcher.addURI(Listw.AUTHORITY, Listw.PATH, LIST);
        uriMatcher.addURI(ShareProcessor.AUTHORITY, ShareProcessor.PATH, SHARE );

    }

    public static RestMethodFactory getInstance(Context context) {
        synchronized (lock) {
            if (instance == null) {
                instance = new RestMethodFactory(context);
            }
        }

        return instance;
    }

    public RestMethod getRestMethod(Uri resourceUri, Method method,
                                    Map<String, List<String>> headers, byte[] body, long id) {

        switch (uriMatcher.match(resourceUri)) {
            case TASKS:

                switch (method) {
                    case GET:
                        return new GetTasksRestMethod(mContext, headers, id);
                    case POST:
                        return new PostTaskRestMethod(mContext, headers,body);
                    default :
                        break;
                }

                break;

            case TASK:

                switch (method) {
                    case PUT:
                        return new PutTaskRestMethod(mContext, headers, body, id);
                    case DELETE:
                        return new DeleteTaskRestMethod(mContext, headers,body,id);
                    default :
                        break;
                }

                break;

            case LISTS:

                switch (method) {
                    case GET:
                        return new GetListsRestMethod(mContext, headers);
                    case POST:
                        return new PostListRestMethod(mContext, headers,body);
                    default :
                        break;
                }

                break;

            case SHARE:

                switch (method) {
                    case POST:
                        return new ShareListRestMethod(mContext, headers,body,id);
                    default :
                        break;
                }

                break;

            case LIST:

                switch (method) {
                    case PUT:
                        return new PutListRestMethod(mContext, headers, body, id);
                    case DELETE:
                        return new DeleteListRestMethod(mContext, headers,body,id);
                    default :
                        break;
                }

                break;


            case LOGIN:
                if (method == Method.POST) {
                    return new LoginRestMethod(mContext, headers, body);
                }
                break;

            case TIMERS:

                switch (method) {
                    case GET:
                        return new GetTimersRestMethod(mContext, headers,body,id);
                    case POST:
                        return new PostTimerRestMethod(mContext, headers,body,id);
                    case PUT:
                        return new PutTimerRestMethod(mContext, headers, body, id);
                    default :
                        break;
                }

                break;
        }

        return null;
    }

    public static enum Method {
        GET, POST, PUT, DELETE
    }

}




Java Source Code List

mn.aug.restfulandroid.activity.AboutActivity.java
mn.aug.restfulandroid.activity.LoginActivity.java
mn.aug.restfulandroid.activity.ProjectEditor.java
mn.aug.restfulandroid.activity.ProjectsActivity.java
mn.aug.restfulandroid.activity.ProjectsArrayAdapter.java
mn.aug.restfulandroid.activity.TaskActivity.java
mn.aug.restfulandroid.activity.TaskEditor.java
mn.aug.restfulandroid.activity.TasksActivity.java
mn.aug.restfulandroid.activity.TasksArrayAdapter.java
mn.aug.restfulandroid.activity.TimerServiceHelper.java
mn.aug.restfulandroid.activity.TimerService.java
mn.aug.restfulandroid.activity.TimersArrayAdapter.java
mn.aug.restfulandroid.activity.base.RESTfulActivity.java
mn.aug.restfulandroid.activity.base.RESTfulListActivity.java
mn.aug.restfulandroid.activity.base.UndoBarController.java
mn.aug.restfulandroid.provider.CommentsDBAccess.java
mn.aug.restfulandroid.provider.ListsDBAccess.java
mn.aug.restfulandroid.provider.OwnershipDBAccess.java
mn.aug.restfulandroid.provider.ProviderDbHelper.java
mn.aug.restfulandroid.provider.RemindersDBAccess.java
mn.aug.restfulandroid.provider.TasksDBAccess.java
mn.aug.restfulandroid.provider.UsersDBAccess.java
mn.aug.restfulandroid.rest.AbstractRestMethod.java
mn.aug.restfulandroid.rest.DeleteListRestMethod.java
mn.aug.restfulandroid.rest.DeleteTaskRestMethod.java
mn.aug.restfulandroid.rest.GetListsRestMethod.java
mn.aug.restfulandroid.rest.GetTasksRestMethod.java
mn.aug.restfulandroid.rest.GetTimersRestMethod.java
mn.aug.restfulandroid.rest.LoginRestMethod.java
mn.aug.restfulandroid.rest.PostListRestMethod.java
mn.aug.restfulandroid.rest.PostTaskRestMethod.java
mn.aug.restfulandroid.rest.PostTimerRestMethod.java
mn.aug.restfulandroid.rest.PutListRestMethod.java
mn.aug.restfulandroid.rest.PutTaskRestMethod.java
mn.aug.restfulandroid.rest.PutTimerRestMethod.java
mn.aug.restfulandroid.rest.Request.java
mn.aug.restfulandroid.rest.Response.java
mn.aug.restfulandroid.rest.RestClient.java
mn.aug.restfulandroid.rest.RestMethodFactory.java
mn.aug.restfulandroid.rest.RestMethodResult.java
mn.aug.restfulandroid.rest.RestMethod.java
mn.aug.restfulandroid.rest.ShareListRestMethod.java
mn.aug.restfulandroid.rest.resource.Comment.java
mn.aug.restfulandroid.rest.resource.Lists.java
mn.aug.restfulandroid.rest.resource.Listw.java
mn.aug.restfulandroid.rest.resource.Login.java
mn.aug.restfulandroid.rest.resource.Reminder.java
mn.aug.restfulandroid.rest.resource.Resource.java
mn.aug.restfulandroid.rest.resource.TaskList.java
mn.aug.restfulandroid.rest.resource.Task.java
mn.aug.restfulandroid.rest.resource.Tasks.java
mn.aug.restfulandroid.rest.resource.Timer.java
mn.aug.restfulandroid.rest.resource.Timers.java
mn.aug.restfulandroid.security.AuthorizationManager.java
mn.aug.restfulandroid.security.RequestSigner.java
mn.aug.restfulandroid.service.ListProcessor.java
mn.aug.restfulandroid.service.ListsProcessor.java
mn.aug.restfulandroid.service.LoginProcessor.java
mn.aug.restfulandroid.service.ProcessorCallback.java
mn.aug.restfulandroid.service.ShareProcessor.java
mn.aug.restfulandroid.service.TaskProcessor.java
mn.aug.restfulandroid.service.TasksProcessor.java
mn.aug.restfulandroid.service.TimersProcessor.java
mn.aug.restfulandroid.service.WunderlistServiceHelper.java
mn.aug.restfulandroid.service.WunderlistService.java
mn.aug.restfulandroid.util.DateHelper.java
mn.aug.restfulandroid.util.DatePickerFragment.java
mn.aug.restfulandroid.util.Logger.java
mn.aug.restfulandroid.util.TimePickerFragment.java