Skip to main content
summaryrefslogtreecommitdiffstats
blob: eec9fdb29a6d759ef4fae5d933b40bf44c8f6c83 (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
/*******************************************************************************
 * Copyright (c) 2000, 2005 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.codegen;
      
import java.util.Enumeration;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.wst.ws.internal.datamodel.BasicElement;
import org.eclipse.wst.ws.internal.datamodel.Rel;


/**
* Objects of this class represent a visitor.
* This vistor will visit elements in a model given a 
* particular rel
* */
public class RelVisitor implements Visitor
{

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

  
  private int fElementCounter;
  private int fTotalElements;
  private String frelName;

  /**
  * Constructor.
  * 
  */

  public RelVisitor (String relName)
  {
     frelName = relName;
  }
  
  public int getTotalElementsToVisit()
  {
     return fTotalElements;
  }

  public boolean isLastElement()
  {
     if(getTotalElementsToVisit() - presentElement() == 0) return true;
     return false;
  }

  public int presentElement()
  {
     return fElementCounter;
  }
  
  public void initialize(VisitorAction va)
  {
    //implemented by subclasses
  }  
  public IStatus run (Object sourceElement,VisitorAction vAction)
  {
  	    IStatus status = Status.OK_STATUS;
        initialize(vAction);
  
        vAction.setVisitor(this);
        Rel rel = ((BasicElement)sourceElement).getRel(frelName);
        //set some state data
        fTotalElements = rel.getNumberOfTargetElements();
        fElementCounter = 0;  
        
        Enumeration e = rel.getTargetElements();
        while (e.hasMoreElements()){
           BasicElement targetElement = (BasicElement)e.nextElement(); 
           fElementCounter++;
           initialize(vAction);
           status = vAction.visit(targetElement);
        }
        return status;
  } 

}

Back to the top