Skip to content

Commit

Permalink
Refactored HintsFacet into HintsFacetImpl and fixed ClassLoaderAdapte…
Browse files Browse the repository at this point in the history
…rCallback for Class parameters
  • Loading branch information
gastaldi committed Jan 25, 2013
1 parent f47b32b commit dcd46f9
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 51 deletions.
Expand Up @@ -157,7 +157,32 @@ private List<Object> convertParameterValues(final Object[] args, Method delegate
final Class<?> delegateParameterType = delegateMethod.getParameterTypes()[i];
final Object parameterValue = args[i];

if (delegateParameterType.isPrimitive() || parameterValue == null)
// If it is a class, use the toLoader loaded version
if (parameterValue instanceof Class<?>)
{
Class<?> paramClassValue = (Class<?>) parameterValue;
Class<?> loadedClass;
try
{
loadedClass = toLoader.loadClass(paramClassValue.getName());
}
catch (ClassNotFoundException e)
{
// Oh oh, there is no class with this type in the target.
// Trying with delegate ClassLoader;
try
{
loadedClass = delegate.getClass().getClassLoader().loadClass(paramClassValue.getName());
}
catch (ClassNotFoundException cnfe)
{
// No way, here is the original class and god bless you :)
loadedClass = paramClassValue;
}
}
parameterValues.add(loadedClass);
}
else if (delegateParameterType.isPrimitive() || parameterValue == null)
{
parameterValues.add(parameterValue);
}
Expand Down
55 changes: 10 additions & 45 deletions ui/api/src/main/java/org/jboss/forge/ui/facets/HintsFacet.java
Expand Up @@ -4,58 +4,23 @@
* Licensed under the Eclipse Public License version 1.0, available at
* http://www.eclipse.org/legal/epl-v10.html
*/

package org.jboss.forge.ui.facets;

import org.jboss.forge.container.util.Assert;
import org.jboss.forge.environment.Environment;
import org.jboss.forge.facets.BaseFacet;
import org.jboss.forge.facets.Facet;
import org.jboss.forge.ui.UIInput;
import org.jboss.forge.ui.hints.HintsLookup;
import org.jboss.forge.ui.hints.InputType;

/**
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
*
* Hints facet
*
* @author <a href="mailto:ggastald@redhat.com">George Gastaldi</a>
*
*/
public class HintsFacet extends BaseFacet<UIInput<?>>
public interface HintsFacet extends Facet<UIInput<?>>
{
private HintsLookup hintsLookup;
private InputType inputType;

public HintsFacet(UIInput<?> origin, Environment environment)
{
super(origin);
Assert.notNull(environment, "Environment must not be null.");

this.hintsLookup = new HintsLookup(environment);
}

@Override
public boolean install()
{
return true;
}

@Override
public boolean isInstalled()
{
return getOrigin().hasFacet(this.getClass());
}

public InputType getInputType()
{
if (inputType == null)
{
inputType = hintsLookup.getInputType(getOrigin().getValueType());
}
// TODO should we calculate and return a default input type here, or elsewhere?
return inputType;
}
public abstract InputType getInputType();

public HintsFacet setInputType(InputType type)
{
inputType = type;
return this;
}
public abstract HintsFacet setInputType(InputType type);

}
}
Expand Up @@ -20,9 +20,9 @@

/**
* Implementation of a {@link UIInput} object
*
*
* @author <a href="mailto:ggastald@redhat.com">George Gastaldi</a>
*
*
* @param <T>
*/
@Vetoed
Expand Down Expand Up @@ -153,7 +153,7 @@ public UIInput<T> setValue(T value)
@Override
public boolean supports(Class<? extends Facet<?>> type)
{
return type.isAssignableFrom(HintsFacet.class);
return HintsFacet.class.isAssignableFrom(type);
}

}
Expand Up @@ -16,7 +16,7 @@

import org.jboss.forge.environment.Environment;
import org.jboss.forge.ui.UIInput;
import org.jboss.forge.ui.facets.HintsFacet;
import org.jboss.forge.ui.impl.facets.HintsFacetImpl;

/**
* Produces UIInput objects
Expand All @@ -41,7 +41,7 @@ public <T> UIInput<T> produceInput(InjectionPoint injectionPoint)
Class<T> valueType = (Class<T>) typeArguments[0];
UIInputImpl<T> input = new UIInputImpl<T>(name, valueType);

HintsFacet hintsFacet = new HintsFacet(input, environment);
HintsFacetImpl hintsFacet = new HintsFacetImpl(input, environment);
input.install(hintsFacet);
return input;
}
Expand Down
@@ -0,0 +1,76 @@
/*
* Copyright 2013 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Eclipse Public License version 1.0, available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.jboss.forge.ui.impl.facets;

import org.jboss.forge.environment.Environment;
import org.jboss.forge.facets.BaseFacet;
import org.jboss.forge.ui.UIInput;
import org.jboss.forge.ui.facets.HintsFacet;
import org.jboss.forge.ui.hints.HintsLookup;
import org.jboss.forge.ui.hints.InputType;

/**
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
*
*/
public class HintsFacetImpl extends BaseFacet<UIInput<?>> implements HintsFacet
{
private HintsLookup hintsLookup;
private InputType inputType;

public HintsFacetImpl(UIInput<?> origin, Environment environment)
{
super(origin);
if (environment == null)
{
throw new IllegalStateException("Environment must not be null.");
}

this.hintsLookup = new HintsLookup(environment);
}

@Override
public boolean install()
{
return true;
}

@Override
public boolean isInstalled()
{
return getOrigin().hasFacet(this.getClass());
}

/*
* (non-Javadoc)
*
* @see org.jboss.forge.ui.facets.HintsFacet#getInputType()
*/
@Override
public InputType getInputType()
{
if (inputType == null)
{
inputType = hintsLookup.getInputType(getOrigin().getValueType());
}
// TODO should we calculate and return a default input type here, or elsewhere?
return inputType;
}

/*
* (non-Javadoc)
*
* @see org.jboss.forge.ui.facets.HintsFacet#setInputType(org.jboss.forge.ui.hints.InputType)
*/
@Override
public HintsFacet setInputType(InputType type)
{
inputType = type;
return this;
}

}

0 comments on commit dcd46f9

Please sign in to comment.