001    /**
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     *
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    package org.apache.camel.component.gae.login;
018    
019    import org.apache.camel.Component;
020    import org.apache.camel.Consumer;
021    import org.apache.camel.Processor;
022    import org.apache.camel.Producer;
023    import org.apache.camel.component.gae.bind.OutboundBinding;
024    import org.apache.camel.impl.DefaultEndpoint;
025    
026    /**
027     * Represents a <a href="http://camel.apache.org/glogin.html">GLogin
028     * Endpoint</a>.
029     */
030    public class GLoginEndpoint extends DefaultEndpoint {
031    
032        private OutboundBinding<GLoginEndpoint, GLoginData, GLoginData> outboundBinding;
033    
034        private String hostName;
035    
036        private String clientName;
037    
038        private String userName;
039    
040        private String password;
041    
042        private int devPort;
043        
044        private boolean devAdmin;
045    
046        private boolean devMode;
047        
048        private GLoginService service;
049    
050        /**
051         * Creates a new GLoginEndpoint.
052         * 
053         * @param endpointUri
054         * @param component
055         *            component that created this endpoint.
056         * @param hostName
057         *            internet hostname of a GAE application, for example
058         *            <code>example.appspot.com</code>, or <code>localhost</code> if
059         *            the application is running on a local development server.
060         * @param devPort
061         *            port for connecting to the local development server.
062         */
063        public GLoginEndpoint(String endpointUri, Component component, String hostName, int devPort) {
064            super(endpointUri, component);
065            this.hostName = hostName;
066            this.clientName = "apache-camel-2.x";
067            this.devPort = devPort;
068            this.devAdmin = false;
069        }
070    
071        /**
072         * Returns the component instance that created this endpoint.
073         */
074        @Override
075        public GLoginComponent getComponent() {
076            return (GLoginComponent)super.getComponent();
077        }
078    
079        /**
080         * Returns the internet hostname of the GAE application where to login.
081         */
082        public String getHostName() {
083            return hostName;
084        }
085    
086        public OutboundBinding<GLoginEndpoint, GLoginData, GLoginData> getOutboundBinding() {
087            return outboundBinding;
088        }
089    
090        /**
091         * Sets the outbound binding for <code>glogin</code> endpoints. Default binding
092         * is {@link GLoginBinding}.
093         */
094        public void setOutboundBinding(OutboundBinding<GLoginEndpoint, GLoginData, GLoginData> outboundBinding) {
095            this.outboundBinding = outboundBinding;
096        }
097    
098        public String getClientName() {
099            return clientName;
100        }
101    
102        /**
103         * Sets the client name used for authentication. The default name is
104         * <code>apache-camel-2.x</code>.
105         * 
106         * @param clientName
107         */
108        public void setClientName(String clientName) {
109            this.clientName = clientName;
110        }
111    
112        public String getUserName() {
113            return userName;
114        }
115    
116        /**
117         * Sets the login username (a Google mail address).
118         * 
119         * @param userName
120         */
121        public void setUserName(String userName) {
122            this.userName = userName;
123        }
124    
125        public String getPassword() {
126            return password;
127        }
128    
129        /**
130         * Sets the login password.
131         * 
132         * @param password
133         */
134        public void setPassword(String password) {
135            this.password = password;
136        }
137    
138        /**
139         * Returns the port for connecting to a development server. Only used
140         * if {@link #devMode} is <code>true</code>. Default is 8080.
141         */
142        public int getDevPort() {
143            return devPort;
144        }
145    
146        public boolean isDevAdmin() {
147            return devAdmin;
148        }
149    
150        /**
151         * Set to <code>true</code> for logging in as admin to a development server.
152         * Only used if {@link #devMode} is <code>true</code>. Default is
153         * <code>false</code>.
154         * 
155         * @param devAdmin
156         */
157        public void setDevAdmin(boolean devAdmin) {
158            this.devAdmin = devAdmin;
159        }
160    
161        public boolean isDevMode() {
162            return devMode;
163        }
164    
165        /**
166         * Set to <code>true</code> for connecting to a development server.
167         * 
168         * @param devMode
169         */
170        public void setDevMode(boolean devMode) {
171            this.devMode = devMode;
172        }
173    
174        public GLoginService getService() {
175            return service;
176        }
177    
178        /**
179         * Sets the service that makes the remote calls to Google services or the
180         * local development server. Testing code should inject a mock service here
181         * (using serviceRef in endpoint URI).
182         * 
183         * @param service
184         */
185        public void setService(GLoginService service) {
186            this.service = service;
187        }
188    
189        /**
190         * Creates a {@link GLoginProducer}.
191         */
192        public Producer createProducer() throws Exception {
193            return new GLoginProducer(this);
194        }
195    
196        /**
197         * throws {@link UnsupportedOperationException}
198         */
199        public Consumer createConsumer(Processor processor) throws Exception {
200            throw new UnsupportedOperationException("consumption from glogin endpoint not supported");
201        }
202    
203        /**
204         * Returns <code>true</code>.
205         */
206        public boolean isSingleton() {
207            return true;
208        }
209    
210    }