View Javadoc

1   /*
2    * Copyright 2006 Outsource Cafe, Inc.
3    *
4    * Licensed under the Apache License, Version 2.0 (the 'License')
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *    http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an 'AS IS' BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.javagen.agile.oo.visitor;
17  
18  import java.util.List;
19  import java.util.Set;
20  
21  import org.javagen.agile.core.model.BasicModel;
22  import org.javagen.agile.core.model.Model;
23  import org.javagen.agile.oo.model.Class;
24  import org.javagen.agile.oo.model.Property;
25  import org.javagen.agile.oo.model.Reference;
26  
27  public class OOWalker {
28  
29  	public static void walk(Model javaModel, OOVisitor visitor) {
30  		if (javaModel==null)
31  			return;
32  		walk(javaModel, visitor, visitor.itinerary());
33  	}
34  
35  	public static void walk(Model model, OOVisitor visitor, Set<String> itinerary) {
36  		if (itinerary==null || itinerary.contains(model.getModelType())) {
37  			if (model instanceof Reference) {
38                  visitor.visit( (Reference)model );
39              } else if (model instanceof Property) {
40                  visitor.visit( (Property)model );
41              } else if (model instanceof Class) {
42                  visitor.visit( (Class)model );
43              } else if (model instanceof BasicModel) {
44  				visitor.visit( model );
45              }
46  		}
47          List<Model> children = model.allOwnedModels();
48  		if ( children != null) {
49  			for(Model child : children) {
50  				walk(child, visitor, itinerary);
51  			}
52  		}
53  	}
54  
55  }