More progress, just working on final touches.
I have this working now:
public interface GenericDAO<T, I>
{
List<T> findAll();
T findById(I id);
}
public interface PetDAO<T extends Pet> extends GenericDAO<T, String>,
TypedObjectDAO<T, PetType>
{
}
public class PetDAOImpl implements PetDAO<Pet> {...}
public class PersonDAOImpl implements GenericDAO<Person, String> {...}
public static void bind(ServiceBinder binder)
{
// PetDAO matches @Inject GenericDAO<Pet, String>, @Inject
TypedObjectDAO<Pet, PetType>
binder.bind(PetDAO.class, PetDAOImpl.class);
// PersonDAOImpl matches GenericDAO<Person, String>
binder.bind(PersonDAOImpl.class);
}
public class GenericLister<T, I>
{
@Inject
private GenericDAO<T, I> _beanDAO;
@Property
private List<T> _beans;
@Property
@Component(parameters = "source=beans")
private Loop<T> _beanLoop;
void beginRender()
{
_beans = _beanDAO.findAll();
}
}
public class PetLister extends GenericLister<Pet, String>
{
@Inject
private PetDAO<Pet> _petDao;
@Inject
private TypedObjectDAO<Pet, PetType> _typedDao;
public void beginRender() {
if ( _petDao.equals(_typedDao) ) throw new
RuntimeException("Should have gotten the same instance!");
Pet scruffy = _petDao.findById("Scruffy");
final List<Pet> list = _typedDao.findByType(PetType.DOG);
}
}
I modified a couple of interfaces which I'd like to get some feedback on:
Module
Added Collection<String> findServiceIdsForInterface(Class
serviceInterface, Type actualType);
ObjectLocator
Added <T> T getService(Class<T> serviceInterface, Type actualType);
I was only playing with getting @Inject to work so I modified
ServiceInjectionProvider to use injectRedirect when it detects a
generic field in order to have full access to the component class that
is doing the injection; This moves the locator.getService(fieldType,
actualType) into the constructor instead of during class
transformation.
I added a public static GenericsUtils.isAssignableFrom(Type
sourceType, Type targetType) that does rawType comparison, then finds
the class/interface that matches and compares their type parameters.
I'm going to looking at what to do with services built with a
ServiceBuilder. Hopefully I'll have a patch ready tonight or tomorrow.
Josh
On Thu, Aug 26, 2010 at 7:50 AM, Josh Canfield <[email protected]> wrote:
>> I get constant pushback on the need to define a
>> value property to store the current object.
>
>
> Yeah, that's exactly why I started down this path.
>
> I'm working through some ideas about getting generics support into @Inject'd
> services.
>
> How does the community feel about binding a generic type by providing the
> parameters something like this:
>
> //MyGenericInterface<Long,String>
>
> serviceBinder.bind(MyGenericInterface.class).withTypeParameters(Long.class,String.class);
>
> I'd append the type parameters to the serviceId. Each differently typed
> service would obviously need a different instance, although if you provide an
> implementation you would probably be able to do the wrong thing since there
> is no type checking.
>
> I'll try to prototype something today or tomorrow.
>
> -- Josh
>
> On Aug 26, 2010, at 7:17 AM, Howard Lewis Ship <[email protected]> wrote:
>
>> That looks awesome ... I get constant pushback on the need to define a
>> value property to store the current object.
>>
>> I would say we could start to deprecate the "var:" binding prefix once
>> this is in place.
>>
>> On Wed, Aug 25, 2010 at 11:50 PM, Josh Canfield <[email protected]>
>> wrote:
>>> I went back over the generics code and added better support for
>>> wildcard and parameterized types.
>>>
>>> One of my favorite parts of this change is the new improved Loop:
>>>
>>> �...@property
>>> �...@component(parameters = {"source=personSource"})
>>> private Loop<Person> personLoop;
>>>
>>> �...@property
>>> private List<Person> personSource;
>>>
>>>
>>> <h2>Person Loop</h2>
>>> <t:loop t:id="personLoop">
>>> <div id="person_${personLoop.index}">${personLoop.value.name}</div>
>>> </t:loop>
>>>
>>> I was able to make the value and index properties of loop public and
>>> access them from the template.
>>>
>>> Jira is down right now or I'd file a defect and attach it... I guess
>>> I'll do that later if needed.
>>>
>>>
>>> Josh
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [email protected]
>>> For additional commands, e-mail: [email protected]
>>>
>>
>>
>>
>> --
>> Howard M. Lewis Ship
>>
>> Creator of Apache Tapestry
>>
>> The source for Tapestry training, mentoring and support. Contact me to
>> learn how I can get you up and productive in Tapestry fast!
>>
>> (971) 678-5210
>> http://howardlewisship.com
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [email protected]
>> For additional commands, e-mail: [email protected]
>>
>
--
--
http://www.bodylabgym.com - a private, by appointment only, one-on-one
health and fitness facility.
--
http://www.ectransition.com - Quality Electronic Cigarettes at a
reasonable price!
--
TheDailyTube.com. Sign up and get the best new videos on the internet
delivered fresh to your inbox.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]