Skip to content

Commit

Permalink
Merge pull request #194 from jsight/WINDUP-168
Browse files Browse the repository at this point in the history
WINDUP-168: Handlers applied to the superclass'es method even if subtype...
  • Loading branch information
lincolnthree committed Aug 13, 2014
2 parents ae3a753 + 8bdc4d7 commit 70ec93c
Showing 1 changed file with 36 additions and 12 deletions.
Expand Up @@ -5,12 +5,12 @@
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.Set;

import javax.inject.Singleton;

import org.apache.commons.lang.StringUtils;
import org.jboss.windup.graph.model.WindupVertexFrame;

import com.thinkaurelius.titan.core.TitanProperty;
Expand All @@ -30,7 +30,7 @@
@Singleton
public class GraphTypeManager implements TypeResolver, FrameInitializer
{
private Map<String,Class<? extends WindupVertexFrame>> registeredTypes= new HashMap<>();
private Map<String, Class<? extends WindupVertexFrame>> registeredTypes = new HashMap<>();
private TypeRegistry typeRegistry = new TypeRegistry();

public Set<Class<? extends WindupVertexFrame>> getRegisteredTypes()
Expand Down Expand Up @@ -63,8 +63,8 @@ public void addTypeToRegistry(Class<? extends WindupVertexFrame> wvf)
*/
public void addTypeToElement(Class<? extends VertexFrame> kind, Element element)
{
EventVertex ev = (EventVertex)element;
StandardVertex v = (StandardVertex)ev.getBaseVertex();
EventVertex ev = (EventVertex) element;
StandardVertex v = (StandardVertex) ev.getBaseVertex();
Class<?> typeHoldingTypeField = typeRegistry.getTypeHoldingTypeField(kind);
if (typeHoldingTypeField == null)
return;
Expand Down Expand Up @@ -113,7 +113,9 @@ public Class<?>[] resolveTypes(Vertex v, Class<?> defaultType)
}

/**
* Returns the classes which this vertex/edge represents, typically subclasses. Always appends
* Returns the classes which this vertex/edge represents, typically subclasses. This will only return the lowest
* level subclasses (no superclasses of types in the type list will be returned). This prevents Annotation
* resolution issues between superclasses and subclasses (see also: WINDUP-168).
*/
private Class<?>[] resolve(Element e, Class<?> defaultType)
{
Expand All @@ -123,20 +125,42 @@ private Class<?>[] resolve(Element e, Class<?> defaultType)
{
// Name of the graph element property holding the type list.
String propName = typeHoldingTypeField.getAnnotation(TypeField.class).value();
EventVertex ev = (EventVertex)e;
StandardVertex v = (StandardVertex)ev.getBaseVertex();
EventVertex ev = (EventVertex) e;
StandardVertex v = (StandardVertex) ev.getBaseVertex();

Iterable<TitanProperty> valuesAll = v.getProperties(propName);
if (valuesAll != null)
{

List<Class<?>> resultClasses = new ArrayList<>();
for (TitanProperty value : valuesAll)
{
Class<?> type = typeRegistry.getType(typeHoldingTypeField, value.getValue().toString());
if (type == null)
continue;
resultClasses.add(type);
if (type != null)
{
// first check that no subclasses have already been added
ListIterator<Class<?>> previouslyAddedIterator = resultClasses.listIterator();
boolean shouldAdd = true;
while (previouslyAddedIterator.hasNext())
{
Class<?> previouslyAdded = previouslyAddedIterator.next();
if (previouslyAdded.isAssignableFrom(type))
{
// Remove the previously added superclass
previouslyAddedIterator.remove();
}
else if (type.isAssignableFrom(previouslyAdded))
{
// The current type is a superclass of a previously added type, don't add it
shouldAdd = false;
}
}

if (shouldAdd)
{
resultClasses.add(type);
}
}
}
if (!resultClasses.isEmpty())
{
Expand Down

0 comments on commit 70ec93c

Please sign in to comment.