Skip to content

Instantly share code, notes, and snippets.

@secondsun
Created November 15, 2012 14:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save secondsun/4078979 to your computer and use it in GitHub Desktop.
Save secondsun/4078979 to your computer and use it in GitHub Desktop.

In Main.java

Pipeline pipeline = new Pipeline(baseEarl);
PipeConfig<Data> config = new PipeConfig<>(Data.class); //config.baseUrl is null
Pipe<Data> pipe = pipeline(config);

In Pipeline.java

public Pipe pipe(Class klass, PipeConfig config) {
        if (config.getURL() == null) {
           config.setUrl(baseUrl);//Changing the object the user provided
        }
        Pipe pipe = pipeFactory.createPipe(config.getEntityClass(), config);
        pipes.put(config.getName(), pipe);
        return pipe;
    }

//In PipeFactory.java

@Override
    public <T> Pipe<T> createPipe(Class<T> klass, PipeConfig config) {
        Pipe<T> createdPipe;
        if (config.getType().equals(PipeTypes.REST)) {
            URL url = appendEndpoint(config.getBaseURL(), config.getEndpoint());//throws NPE
            HttpRestProvider httpProvider = new HttpRestProvider(url);
            
            if (config.getGsonBuilder() != null) {
                createdPipe = new RestAdapter<T>(klass, httpProvider, config.getGsonBuilder());
            } else {
                createdPipe = new RestAdapter<T>(klass, httpProvider);
            }
            
        } else {
            throw new IllegalArgumentException("Type is not supported yet");
        }
        
        if (config.getAuthModule() != null) {
            createdPipe.setAuthenticationModule(config.getAuthModule());
        }
        
        return createdPipe;
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment