View Javadoc

1   /*
2    * Copyright 2011-2012 The Kuali Foundation Licensed under the
3    * Educational Community License, Version 2.0 (the "License"); you may
4    * not use this file except in compliance with the License. You may
5    * obtain a copy of the License at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing,
10   * software distributed under the License is distributed on an "AS IS"
11   * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12   * or implied. See the License for the specific language governing
13   * permissions and limitations under the License.
14   */
15  
16  package org.kuali.mobility.bus.service.util;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  
21  import org.apache.commons.collections.CollectionUtils;
22  import org.apache.commons.collections.Transformer;
23  import org.kuali.mobility.bus.entity.BusRoute;
24  import org.kuali.mobility.bus.entity.BusRouteImpl;
25  import org.kuali.mobility.bus.entity.BusStop;
26  import org.kuali.mobility.bus.entity.BusStopImpl;
27  
28  /**
29   *
30   * @author Aniruddha Jani <ajani@vivantech.com>
31   */
32  public class BusRouteTransform implements Transformer {
33  
34      @Override
35      public BusRouteImpl transform( Object obj ) {
36      	BusRouteImpl proxy = null;
37  
38          if( obj instanceof BusRoute ) {
39              proxy = new BusRouteImpl();
40              proxy.setId(((BusRoute)obj).getId());
41              proxy.setColor(((BusRoute)obj).getColor());
42              proxy.setName(((BusRoute)obj).getName());
43              proxy.setPath(((BusRoute)obj).getPath());
44              
45              List<BusStopImpl> stops = new ArrayList<BusStopImpl>();
46              CollectionUtils.collect( ((BusRoute)obj).getStops(), new BusStopTransform(), stops );            
47              proxy.setStops(stops);
48          }
49  
50          return proxy;
51      }
52  
53  }