Skip to content

Commit

Permalink
Initial hierarchy/overloading support for XSD
Browse files Browse the repository at this point in the history
git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@1965 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
nickarls committed Mar 13, 2009
1 parent 929e36c commit 29c1273
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 32 deletions.
13 changes: 4 additions & 9 deletions impl/src/main/java/org/jboss/webbeans/xsd/DataSetter.java
Expand Up @@ -7,8 +7,9 @@
import javax.lang.model.element.VariableElement;

import org.jboss.webbeans.xsd.model.ClassModel;
import org.jboss.webbeans.xsd.model.FieldModel;
import org.jboss.webbeans.xsd.model.MethodModel;
import org.jboss.webbeans.xsd.model.ParameterFieldModel;
import org.jboss.webbeans.xsd.model.ParameterModel;

public class DataSetter
{
Expand All @@ -33,7 +34,7 @@ public static void populateFieldModel(ClassModel classModel, Element element)
}
String name = element.getSimpleName().toString();
String type = element.asType().toString();
classModel.addField(new ParameterFieldModel(name, type));
classModel.addField(new FieldModel(name, type));
}

public static void populateMethodModel(ClassModel classModel, Element element)
Expand All @@ -52,7 +53,7 @@ public static void populateMethodModel(ClassModel classModel, Element element)
{
String paramName = parameterElement.getSimpleName().toString();
String paramType = parameterElement.asType().toString();
ParameterFieldModel parameter = new ParameterFieldModel(paramName, paramType);
ParameterModel parameter = new ParameterModel(paramName, paramType);
method.addParameter(parameter);
}
if ("<init>".equals(name))
Expand All @@ -65,10 +66,4 @@ public static void populateMethodModel(ClassModel classModel, Element element)
}
}

public static String getSimpleNameFromQualifiedName(String qualifiedName)
{
int lastDot = qualifiedName.lastIndexOf(".");
return lastDot < 0 ? qualifiedName : qualifiedName.substring(lastDot);
}

}
46 changes: 44 additions & 2 deletions impl/src/main/java/org/jboss/webbeans/xsd/model/ClassModel.java
@@ -1,21 +1,23 @@
package org.jboss.webbeans.xsd.model;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class ClassModel extends NamedModel
{
private ClassModel parent;

private List<ParameterFieldModel> fields = new ArrayList<ParameterFieldModel>();
private List<FieldModel> fields = new ArrayList<FieldModel>();
private List<MethodModel> methods = new ArrayList<MethodModel>();
private List<MethodModel> constructors = new ArrayList<MethodModel>();

public ClassModel()
{
}

public void addField(ParameterFieldModel fieldModel)
public void addField(FieldModel fieldModel)
{
fields.add(fieldModel);
}
Expand Down Expand Up @@ -63,4 +65,44 @@ public String getSimpleName()
return lastDot < 0 ? name : name.substring(lastDot + 1);
}

public Set<MethodModel> getMergedConstructors()
{
return new HashSet<MethodModel>(constructors);
}

public List<FieldModel> getFields()
{
return fields;
}

public Set<FieldModel> getMergedFields()
{
Set<FieldModel> mergedFields = new HashSet<FieldModel>(fields);
ClassModel currentParent = parent;
while (currentParent != null)
{
mergedFields.addAll(currentParent.getFields());
currentParent = currentParent.getParent();
}
return mergedFields;
}

public List<MethodModel> getMethods()
{
return methods;
}

public Set<MethodModel> getMergedMethods()
{
Set<MethodModel> mergedMethods = new HashSet<MethodModel>(methods);
ClassModel currentParent = parent;
while (currentParent != null)
{
mergedMethods.addAll(currentParent.getMethods());
currentParent = currentParent.getParent();
}
return mergedMethods;

}

}
31 changes: 31 additions & 0 deletions impl/src/main/java/org/jboss/webbeans/xsd/model/FieldModel.java
@@ -0,0 +1,31 @@
package org.jboss.webbeans.xsd.model;

public class FieldModel extends NamedModel
{
protected String type;

public FieldModel(String name, String type)
{
super(name);
this.type = type;
}

public String getType()
{
return type;
}

@Override
public boolean equals(Object other)
{
FieldModel otherModel = (FieldModel) other;
return name.equals(otherModel.getName()) && type.equals(otherModel.getType());
}

@Override
public int hashCode()
{
return name.hashCode() + type.hashCode();
}

}
19 changes: 16 additions & 3 deletions impl/src/main/java/org/jboss/webbeans/xsd/model/MethodModel.java
Expand Up @@ -6,20 +6,20 @@
public class MethodModel extends NamedModel
{
private String returnType;
private List<ParameterFieldModel> parameters = new ArrayList<ParameterFieldModel>();
private List<ParameterModel> parameters = new ArrayList<ParameterModel>();

public MethodModel(String name, String returnType)
{
super(name);
this.returnType = returnType;
}

public void addParameter(ParameterFieldModel parameter)
public void addParameter(ParameterModel parameter)
{
parameters.add(parameter);
}

public List<ParameterFieldModel> getParameters()
public List<ParameterModel> getParameters()
{
return parameters;
}
Expand All @@ -29,4 +29,17 @@ public String getReturnType()
return returnType;
}

@Override
public boolean equals(Object other)
{
MethodModel otherModel = (MethodModel) other;
return name.equals(otherModel.getName()) && returnType.equals(otherModel.getReturnType()) && parameters.equals(otherModel.getParameters());
}

@Override
public int hashCode()
{
return name.hashCode() + returnType.hashCode() + parameters.hashCode();
}

}

This file was deleted.

@@ -0,0 +1,24 @@
package org.jboss.webbeans.xsd.model;

public class ParameterModel extends FieldModel
{

public ParameterModel(String name, String type)
{
super(name, type);
}

@Override
public boolean equals(Object other)
{
ParameterModel otherModel = (ParameterModel) other;
return type.equals(otherModel.getType());
}

@Override
public int hashCode()
{
return type.hashCode();
}

}

0 comments on commit 29c1273

Please sign in to comment.