Skip to main content
summaryrefslogtreecommitdiffstats
blob: f693dfab03b210e5be8a74fe03b4f8d554294fe7 (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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*******************************************************************************
 * 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.codegen.javamofvisitors;

import java.util.Iterator;
import java.util.ListIterator;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.emf.common.util.EList;
import org.eclipse.jem.java.Field;
import org.eclipse.jem.java.JavaClass;
import org.eclipse.jem.java.JavaHelpers;
import org.eclipse.jem.java.JavaParameter;
import org.eclipse.jem.java.JavaVisibilityKind;
import org.eclipse.jem.java.Method;
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.command.common.JavaMofReflectionCommand;
import org.eclipse.jst.ws.internal.consumption.datamodel.beanmodel.TypeFactory;


/**
* Objects of this class represent a visitor.
* */
public class JavaMofFieldVisitor implements Visitor 
{

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


  private String clientProject;

  /*
  * Constructor
  **/
  public JavaMofFieldVisitor()
  {
  }

  /*
  * Use this to reflect 
  */
  public void setProject(String clientProject)
  {
    this.clientProject = clientProject;
  }

   /*
  * Use this to reflect 
  */
  public String getProject()
  {
    return clientProject;
  }

  /*
  * Get the attribute belonging to this complex type 
  * @param JavaParameter javaParameter that owns the type
  * @param VisitorAction Action to be performed on each method
  **/
  public IStatus run ( Object javaclass, VisitorAction vAction)
  {
  	IStatus status = Status.OK_STATUS;
    JavaClass javaClass = (JavaClass)javaclass;     

    boolean holderClass = false;
    EList implemented = javaClass.getImplementsInterfaces();
	for (int i = 0; i < implemented.size(); i++) {
	  JavaClass anInterface = (JavaClass) implemented.get(i);
	  if (anInterface.getQualifiedName().equals("javax.xml.rpc.holders.Holder"))
	    holderClass = true;
	}      

     //beaninfo code
    if(holderClass){     
      EList e  = javaClass.getFields();
      ListIterator list = e.listIterator();
      while(list.hasNext()){
        Field field = (Field)list.next();     
        if(field.getJavaVisibility().getValue() == JavaVisibilityKind.PUBLIC && !field.isFinal() && !field.isStatic()){
          if(fieldCheck(field))
            status = vAction.visit(field);
        }
      }
    }
    
    return status;
  }       
  private boolean fieldCheck(Field field)
  {
    // so its a bean make sure it has a default constructor 
    JavaMofReflectionCommand javaMofRef = new JavaMofReflectionCommand();
    javaMofRef.setProxyBean(((JavaHelpers)field.getEType()).getQualifiedName());
    javaMofRef.setClientProject(getProject());
    javaMofRef.execute(null, null);
    if(javaMofRef.getJavaClass() instanceof JavaClass){
      if(TypeFactory.recognizedBean(javaMofRef.getJavaClass().getJavaName())) return true;
      return defaultCheck((JavaClass)javaMofRef.getJavaClass());
    }
    return true;
  }
        
 private boolean defaultCheck(JavaClass javaClass){
    
   Iterator m=javaClass.getMethods().iterator();
   //now check for a default constructor
   boolean defaultConst = true;
   while (m.hasNext()) {
    Method method=(Method)m.next();
    if (javaClass.getName().equals(method.getName())){
      //now the inputs
      JavaParameter javaParameter[] = method.listParametersWithoutReturn();
      if (javaParameter.length > 0){
        //then we have no default constructor
        defaultConst = false; 
      }
      else if(javaParameter.length == 0){
        if (method.getJavaVisibility().getValue() == 0)
          return true;
        else if(method.getJavaVisibility().getValue() == 1) 
          defaultConst = false;
      }
    }
  }
    
  return defaultConst;
  }
}

Back to the top