Skip to main content
summaryrefslogtreecommitdiffstats
blob: a8f4cb17eabeec4f0bea64137b31c99b0d6e9870 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*******************************************************************************
 * Copyright (c) 2000, 2004 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.jst.ws.internal.consumption.sampleapp.codegen;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jst.ws.internal.consumption.codegen.Visitor;
import org.eclipse.jst.ws.internal.consumption.codegen.VisitorAction;
import org.eclipse.jst.ws.internal.consumption.codegen.bean.AttributeVisitor;
import org.eclipse.jst.ws.internal.consumption.codegen.bean.FieldVisitor;
import org.eclipse.jst.ws.internal.consumption.codegen.bean.TypeVisitor;
import org.eclipse.jst.ws.internal.consumption.datamodel.beanmodel.AttributeElement;
import org.eclipse.jst.ws.internal.consumption.datamodel.beanmodel.BeanElement;
import org.eclipse.jst.ws.internal.consumption.datamodel.beanmodel.TypeElement;
import org.eclipse.jst.ws.internal.consumption.datamodel.beanmodel.TypeFactory;
import org.eclipse.wst.ws.internal.datamodel.Element;


/**
* Objects of this class represent a LevelsDeepVisitorAction.
* */
public class LevelsDeepVisitorAction implements VisitorAction 
{

  // Copyright
  public static final String copyright = "(c) Copyright IBM Corporation 2000, 2002.";


  private int fLevelsDeep;
  private int fDeepestLevel;
  
  /**
  * Constructor.
  * This is the starting point
  * 
  */
  public LevelsDeepVisitorAction ()
  {
    fLevelsDeep = 0;
  }

  /**
  * Constructor.
  * This is the starting point
  * 
  */
  public LevelsDeepVisitorAction (int current,boolean increment)
  {
    fLevelsDeep = current;
    if(increment) fLevelsDeep++;
    fDeepestLevel = fLevelsDeep; 
  }
  
  public void initialize(String resident)
  {
    //nothing to be done but must be implemented
  }



  /**
  * The visitor that called this VisitorAction
  * @param visitor the visitor that called this visitor action
  */
  public void setVisitor(Visitor visitor)
  {
  }


  /**
  * Returns the level of nesting within this bean
  * @return int returns the int number representing the number of nests of this bean
  */
  public int getLevelsDeep()
  {
     return fDeepestLevel;
  }
 

  /**
  * Takes in an object to be acted upon by this visitor action
  * @param Object The object to be acted upon
  */
  public IStatus visit (Object object)
  {
      Element element = (Element)object;
      if (element instanceof AttributeElement || element instanceof TypeElement){
         TypeVisitor typeVisitor = new TypeVisitor();
         LevelsDeepVisitorAction lvda = new LevelsDeepVisitorAction(fLevelsDeep,true);
         typeVisitor.run(element,lvda);

         if (lvda.getLevelsDeep() > fDeepestLevel) fDeepestLevel = lvda.getLevelsDeep(); 
         
      }
      else if (element instanceof BeanElement && !(TypeFactory.recognizedBean(element.getName()))){
         AttributeVisitor attributeVisitor = new AttributeVisitor();
         LevelsDeepVisitorAction lvda = new LevelsDeepVisitorAction(fLevelsDeep,false);
         attributeVisitor.run(element,lvda);
         if (lvda.getLevelsDeep() > fDeepestLevel) fDeepestLevel = lvda.getLevelsDeep(); 
   
         FieldVisitor fieldVisitor = new FieldVisitor();
         LevelsDeepVisitorAction lvda2 = new LevelsDeepVisitorAction(fLevelsDeep,false);
         fieldVisitor.run(element,lvda2);
         if (lvda2.getLevelsDeep() > fDeepestLevel) fDeepestLevel = lvda2.getLevelsDeep(); 
   
      }
         
     return Status.OK_STATUS;   
  }

}

Back to the top