Generic decorator factory

I'd like to create a generic interface for a factory that decorates objects with a given interface.
Basically my decorated objects are of the same type then the non-decorated objects and additionally they implement an interface. The interface in question is "CheckMarkable".
I was thinking about declaring the interface for my factory like this:
public interface CheckMarkableFactory<E, CheckMarkableE extends E & CheckMarkable>
    CheckMarkableE decorate(E objToDecorate);
}But I get the following error: "Cannot specify any additional bound CheckMarkable when first bound is a type parameter".
Changing E & CheckMarkable to CheckMarkable & E won't help because I get the following error instead: "The type E is not an interface; it cannot be specified as a bounded parameter".
As a workaround, I can always do this:
public interface CheckMarkableFactory<E>
    /** Assumes that the returned value implements CheckMarkable */
    E decorate(E objToDecorate);
}or this:
public interface CheckMarkableFactory<E>
    /** Assumes that the returned value extends E */
    CheckMarkable decorate(E objToDecorate);
}But in both cases I need to cast my objects either to CheckMarkable or to their initial type (E)...
I was wondering if there is a way to prevent these casts by enforcing the factory to create CheckMarkable objects of the same type than the passed objects...

I'd like to create a generic interface for a factory that decorates objects with a given interface.
Basically my decorated objects are of the same type then the non-decorated objects and additionally they implement an interface. The interface in question is "CheckMarkable".
I was thinking about declaring the interface for my factory like this:
public interface CheckMarkableFactory<E, CheckMarkableE extends E & CheckMarkable>
    CheckMarkableE decorate(E objToDecorate);
}But I get the following error: "Cannot specify any additional bound CheckMarkable when first bound is a type parameter".
Changing E & CheckMarkable to CheckMarkable & E won't help because I get the following error instead: "The type E is not an interface; it cannot be specified as a bounded parameter".
As a workaround, I can always do this:
public interface CheckMarkableFactory<E>
    /** Assumes that the returned value implements CheckMarkable */
    E decorate(E objToDecorate);
}or this:
public interface CheckMarkableFactory<E>
    /** Assumes that the returned value extends E */
    CheckMarkable decorate(E objToDecorate);
}But in both cases I need to cast my objects either to CheckMarkable or to their initial type (E)...
I was wondering if there is a way to prevent these casts by enforcing the factory to create CheckMarkable objects of the same type than the passed objects...

Similar Messages

  • Generic abstract factory method

    Hello generics experts,
    I need some generics advise. In a simpel persistence framework I have the following case:
    abstract class BaseHandler {
      public List produceSomeStuff( String condition ) {
        List result = new ArrayList();
        //   .. do stuff
        result.add( make( attribs ));
        //.. do more stuff
        return result;
      public abstract Object make( attribs );
    public class AHandler extends BaseHandler {
      public List<A> getSomeA( String condition ) {
        List<A> result;
        List resObj = produceSomeStuff( condition );
        // make List<A> from resObj;
        return result;
      public A make( attribs ) {
        return new A( attribs );
    public class BHandler extends BaseHandler {
      public List<B> getSomeB( String condition ) {
        List<B> result;
        List resObj = produceSomeStuff( condition );
        // make List<B> from resObj;
        return result;
      public B make( attribs ) {
        return new B( attribs );
    }I would like to use generics in the BaseHandler to get the right type of list back, instead of an object list.
    Problem is, that if I make the abstract make method generic, the concrete make methods have to be generic too
    and I cant call new A(), new B() any more. Plus it seems I have to pass the A.class, B.class token around alot.
    Any advise on this ??
    I tried to use List<?> as BaseHandler.produceSomeStuff() return type, but this cant be assigned to List<A>.
    Arne Stabenau

    Hello, thanks for looking into this.
    I agree I was a lazy typer and A and B I shouldnt have used.
    class Customer {
         String name;
         public Customer( String name ) {
           this.name = name;
    class Bill {
         int amount;
         public Bill( String amount ) {
              amount = Integer.parseInt();
    abstract class BaseHandler {
      public List produceSomeStuff( String condition ) {
              List result = new ArrayList();
        // .. do stuff in a loop
        result.add( make( condition ));
        // .. do more stuff
        return result;
      public abstract Object make( String attribs );
    public class CustomerHandler extends BaseHandler {
      public List<Customer> getSomeCustomer( String condition ) {
              List<Customer> result;
        List resObj = produceSomeStuff( condition );
        // make List<Customer> from resObj;
        result = resObj; // unchecked
        return result;
      public Customer make( String attribs ) {
        return new Customer( attribs );
    public class BillHandler extends BaseHandler {
      public List<Bill> getSomeBill( String condition ) {
           List<Bill> result;
        List resObj = produceSomeStuff( condition );
        // make List<Bill> from resObj;
        result = resObj;
        return result;
      public Bill make( String attribs ) {
        return new Bill( attribs );
    }I can do all this and it works. But I get the unchecked messages from the compiler. The generics tutorial says one should not use the raw types any more. But I dont know what raw type to return from the BaseHandler produceSomeStuff method?
    I tried List<?> but I couldnt convert into List<Customer>. I tried to pass Customer.class or Bill.class around to the BaseHandler and then back to
    the make method, but then the make method became very ugly.
    Do I have to copy the List<Object> one by one into a List<Customer> in order
    to use generics as they are meant to be used? Is there a way with type
    variables in the BaseClass to achieve what I want?
    Arne

  • How to declare class variable with generic parameters?

    I've got a class that declares a type parameter T. I know how to declare a static method, but this doesn't work for a static variable:
    public class Test< T >
        * Map of String to instances of T.
        * error: '(' expected (pointing to =)
        * <identifier> expected (pointing to () )
       private final static < T > Map< String, T > MAP = new HashMap< String, T >();
        * Get instance of type T associated with the given key.
       public final static < T > T getType( String key )
          return MAP.get( key );
    }Edited by: 845859 on Mar 20, 2011 11:46 AM

    jveritas wrote:
    I'm trying to create a generic polymorphic Factory class that contains boilerplate code.
    I don't want to have to rewrite the registration code every time I have a different return type and parameter.I haven't seen a case yet where that is reasonable.
    If you have hundreds of factories then something is wrong with your code, design and architecture.
    If you have a factory which requires large number of a varying input types (producing different types) then something is probably wrong with your code and design.
    A reasonable factory usage is one where you have say 20 classes to be created and you need to add a new class every 3 months. Along with additional functionality represented by the class itself and perhaps variances in usage. Thus adding about 3 lines of code to one class is trivial. Conversely if you have hundreds of classes to be created by the factory and you are adding them daily then it is likely that
    1. Something is wrong with the architecture which requires a new class every day.
    2. You should be using a dynamic mechanism for creation rather than static because you can't roll out a static update that often.
    More than that the idiom that leads to factory creation is different for each factory. A factory that creates a database connection is substantially different than the one used in dynamic rules logic processing. A generic version will not be suitable for both.
    Actualy the only case I know of where such a factory might be seem to be a 'good' idea is where someone has gotten it into their head that every class should be represented by an interface and every class created by a factory (its own factory.) And of course that is flawed.

  • Generics with multiple interfaces

    I'm trying to figure out why the following is not valid:
    public class MediaService<L extends Deque<MediaFile> & List<MediaFile>> {
            L x = new LinkedList<MediaFile>();
    }Gives:
    Type mismatch: cannot convert from LinkedList<MediaFile> to LSeeing as LinkedList implements both these interfaces, I would expect this to be legal. What else is the use of the & operator in Generics?

    lhunath wrote:
    Basically:
    public static <T extends Deque<MediaFile> & List<MediaFile>> T newMediaList() {
    return new LinkedList<MediaFile>();
    It is possible to do this using covariant return types and a generic abstract factory, like this:
    import java.util.Deque;
    import java.util.LinkedList;
    import java.util.List;
    public class GT20 {
       public static void main(String[] args) {
          DequeListFactory<String, ?> factory = new LinkedListFactory<String>();
          Deque<String> d = factory.create();
          List<String> l = factory.create();
       private interface DequeListFactory<T, L extends Deque<T> & List<T>> {
          L create();
       private static class LinkedListFactory<T> implements DequeListFactory<T, LinkedList<T>> {
          @Override
          public LinkedList<T> create() {
             return new LinkedList<T>();
    }However, I would seriously question the use of such a factory. If you really have a need for a union of interfaces (I would suggest a design that requires/allows users to use your objects as Lists and Deques, something is seriously wrong), I would create such a union and use that in your contract. Java doesn't allow anonymous unions as you're trying to do, and using generics is just a hack. Here's what I might consider:
    import java.util.Deque;
    import java.util.LinkedList;
    import java.util.List;
    public class GT21 {
       private interface ListDeque<T> extends List<T>, Deque<T> {}
       private interface MyInterface<T> {
          ListDeque<T> getListDeque();
       private static class MyClass<T> implements MyInterface<T>{
          @Override
          public ListDeque<T> getListDeque() {
             return new MyLinkedList<T>();
       private static class MyLinkedList<T> extends LinkedList<T>
          implements ListDeque<T> {
    }

  • EJB object factory

     

    Declare the factory class as a startup class. In the main() method, create a new initial context and bind a new instance of the factory class into the jndi tree under an agreed on name. Youi client code should look for the factory calss under the agreed on name.
    Hope that helps.
    Narendra Pasuparthy wrote:
    Hi Eduardo,
    Thanks for looking into my problem, I have been trying to do this thing for
    the last 2 weeks and you help comes as a new sign of life to me.
    Anyway i understand the problem better now, but i am still far away from
    having to solve it. you say something about adding the object factory to the
    JNDI tree
    What you can do is add your object factory to the jndi tree. Your >bean
    could look it up, etc.How can i do this, i presume that when you say jndi tree you ae referring to
    the JNDI tree provided by the weblogic server; right?
    If you can shed more light on how i can add my object factory to the JNDI
    tree and how i can look it up i would appreciate your help.
    Looking forward to hearing form you soon.
    Bye,
    Naren
    From: [email protected] (Eduardo Ceballos)
    To: narendra <[email protected]>
    Subject: Re: EJB object factory
    Date: Mon, 21 Aug 2000 08:42:34 -0700
    MIME-Version: 1.0
    Received: from [63.96.160.4] by hotmail.com (3.2) with ESMTP id
    MHotMailBB6A99B0002AD820F39D3F60A0049AF50; Mon Aug 21 08:45:56 2000
    Received: from san-francisco.beasys.com (san-francisco.beasys.com
    [192.168.9.10])by beamail.beasys.com (8.9.1b+Sun/8.9.1) with ESMTP id
    IAA08176for <[email protected]>; Mon, 21 Aug 2000 08:45:54 -0700 (PDT)
    Received: from ashbury.weblogic.com (ashbury.beasys.com [172.17.8.3])by
    san-francisco.beasys.com (8.9.1b+Sun/8.9.1) with ESMTP id IAA13707for
    <[email protected]>; Mon, 21 Aug 2000 08:46:05 -0700 (PDT)
    Received: from weblogic.com ([192.168.11.197]) by ashbury.weblogic.com
    (Post.Office MTA v3.5.3 release 223 ID# 0-53833U200L200S0V35)
    with ESMTP id com for <[email protected]>; Mon, 21 Aug 2000
    09:03:01 -0700
    From [email protected] Mon Aug 21 08:47:42 2000
    Message-ID: <[email protected]>
    X-Mailer: Mozilla 4.73 [en] (WinNT; I)
    X-Accept-Language: en
    Newsgroups: weblogic.developer.interest.rmi-iiop
    References: <[email protected]>
    There is no provision for a generic object factory in the public api, and
    none is supported.
    What you can do is add your object factory to the jndi tree. Your bean
    could look it up, etc. I would urge you to
    make sure that there are appropriate acls on the factory, for obvious
    security reasons.
    narendra wrote:
    My problem is that i want to invoke a service running on another APPserver form an EJB bean,
    the other app server provides some client APIwhich i can use and invokethe service. Due to the
    security restriction in EJB container i was not able to do this, theapproach i am thinking
    about is establishing an object factory to create an object of theother app server client
    class and use that from the bean.
    the weblogic server seems to handle,"javax.sql.DataSource,""javax.jms.QueueConnectionFactory,"
    "javax.jms.TopicConnectionFactory" or "java.net.URL" how can it supportgeneric object factories, since I
    have a obect factory that does not construct any of the objects usingthe weblogic supported object
    factory.
    Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com

  • Configuration file bc4j.xcfg not found in the classpath.

    When i try to run an application that uses ADF BC i get an error telling me the bc4j.xcfg was not found.
    When i open my AppModule and click the bc4j.xcfg link it opens. When i look at the path it stored in, it is different from the path the error says.
    It's something like this:
    Configuration file /be/something/model/common/bc4j.xcfg is not found in the classpath
    but my appModule opens the bc4j.xcfg in a different folder:
    /be/something/utility/common/bc4j.xcfg
    It's a fact i modified the project and managed the packages a bit but i always used the refactor menu of jdeveloper in order to move or rename files.
    It appears that something has failed while moving/changing name.
    I looked inside my project to look for references for bc4j.xcfg but i can't find any so i can't see were to change the directory he needs to look for the bc4j file.
    How do i fix my project?

    John,
    In the DataBindings.cpx i can't find any reference to a datacontrol...
    This is my bindings:
    <?xml version="1.0" encoding="UTF-8" ?>
    <Application xmlns="http://xmlns.oracle.com/adfm/application"
                 version="11.1.1.56.60" id="DataBindings" SeparateXMLFiles="false"
                 Package="be.usermanagementProv.portlets" ClientType="Generic">
      <definitionFactories>
        <factory nameSpace="http://xmlns.oracle.com/adf/controller/binding"
                 className="oracle.adf.controller.internal.binding.TaskFlowBindingDefFactoryImpl"/>
        <dtfactory className="oracle.adf.controller.internal.dtrt.binding.BindingDTObjectFactory"/>
      </definitionFactories>
      <pageMap>
        <page path="/UserManagement/view.jspx"
              usageId="be_usermanagementProv_portlets_viewPageDef"/>
      </pageMap>
      <pageDefinitionUsages>
        <page id="be_usermanagementProv_portlets_viewPageDef"
              path="UserManagement.viewPageDef"/>
      </pageDefinitionUsages>
    </Application>In the datacontrol section when i right click the DC the "edit definition" is grayed out. Probably because the DC comes from the library and is not created in the application.

  • PortableRemoteObject.narrow

    Why is it necessary to use and cast the result of this method call, which appears to return the same object as was passed as the first argument? In other words, why do this:
    Object myObj = ctx.lookup(MYHOME);
    MyHome myHome = (MyHome)
    PortableRemoteObject.narrow(myObj, MyHome.class);
    MyEjb myEjb = myHome.create();
    -in code that must know each EJB, when you can do this:
    //In a generic HomeFactory class
    Object myObj = ctx.lookup(MYHOME);
    Class beanHome = Class.forName(MYHOME);
    PortableRemoteObject.narrow(myObj, beanHome);
    return myObj
    //In some other class
    MyHome myHome = (MyHome) HomeFactory.getHome(MYHOME);
    MyEjb = myHome.create();
    I left out the try-catch blocks and all of that for compactness. The reason I ask is because a generic Home Factory can store EJBHome objects in a collection, testing them first and returning them without creating the actual remote reference, so it does not need to know the specific EJB, allowing the specific client code to cast the generic Object to the specific EJBHome object.
    A Sun-certified instructor once told me that it was absolutely necessary to use the Object returned from the narrow method because it performed some essential RMI activity on the object, but I have never had a problem using it the second way I describe above in the HomeFactory. Also, I have never been able to find any documentation to substantiate his claim. Any thoughts as to the necessity of using the object returned from the narrow method? It appears to be the exact same object that is passed in to the method, and likely un-changed at that.

    The narrow method is there to allow an implementation to do some extra work or return a different object if it needs to. It appears that your implementation does not need to do these things so it just returns the object that was passed. If you take your shortcut, you will limit yourself to running only on your current implementation. If you try to switch implementations or even upgrade to a later version it might break. If you follow the correct method the your code will be portable.

  • ApplicationModule get configuration used bc4j.xcfg

    Is there a way to find the bc4j.xcfg file (or its content) used from an applicationModule instance ?
    In bc4j.xcfg file, I put some additionnal attributes values used as application parameters that I use during runtime, but I have to load them !
    Today, I have add in the constructor of the AM the class path to find the bc4j.xcfg file, but I think there is a better way... I hope !
    Thanks
    Rafael.

    John,
    In the DataBindings.cpx i can't find any reference to a datacontrol...
    This is my bindings:
    <?xml version="1.0" encoding="UTF-8" ?>
    <Application xmlns="http://xmlns.oracle.com/adfm/application"
                 version="11.1.1.56.60" id="DataBindings" SeparateXMLFiles="false"
                 Package="be.usermanagementProv.portlets" ClientType="Generic">
      <definitionFactories>
        <factory nameSpace="http://xmlns.oracle.com/adf/controller/binding"
                 className="oracle.adf.controller.internal.binding.TaskFlowBindingDefFactoryImpl"/>
        <dtfactory className="oracle.adf.controller.internal.dtrt.binding.BindingDTObjectFactory"/>
      </definitionFactories>
      <pageMap>
        <page path="/UserManagement/view.jspx"
              usageId="be_usermanagementProv_portlets_viewPageDef"/>
      </pageMap>
      <pageDefinitionUsages>
        <page id="be_usermanagementProv_portlets_viewPageDef"
              path="UserManagement.viewPageDef"/>
      </pageDefinitionUsages>
    </Application>In the datacontrol section when i right click the DC the "edit definition" is grayed out. Probably because the DC comes from the library and is not created in the application.

  • Help on DAO pattern

    Hello!
    I'm having a problem implementing the DAO pattern.
    Suppose that I have two database tables:
    emp(id, name, sex, deptid)
    dept(id, name)
    If I follow the DAO pattern, I use two DAO interfaces, one for each
    table, and "entity". EmployeeDAO, and DepartmentDAO.
    (I'm using an abstract factory to create storage-specific DAOS)
    These DAOs return instances of Employee, and Department, or lists of them. (ValueObjects).
    This is all great and works very well, but suppose I want to produce the following
    presentation on the web:
    deptname | male | female
    Dept A   | 10   | 20
    Dept B   | 15   | 30In essense, this is a request for all the departments.
    I would iterate through this list, and want to display how many
    males, and how many females there are in each department.
    Should this be in the DepartmentDAO, or in a separate DAO?
    Or should this be put in some BusinessDelegate?
    That is, DepartmentDelegate.countMales(dept);
    Or should I put a method in the ValueObject Department that in turn uses the DAO to count males?
    Or should I load the number of females into the valueobject when fetching it from the
    database in the first place?
    Or should I construct a specialized view of the department such as:
    class StupidViewOfDepartment
       private Department dept;
       private int males;
       private int females;
       public StupidViewOfDepartment(Department dept, int males, int females){
       public int numFemales();
          return females;
       public int numMales(){
          return males;
    }...having some class return a collection of this specialized view?
    In that case, which class would that be?
    A new DAO or the DepartmentDAO?
    All classical examples of DAO patterns that I can find, fails to adress
    other issues than just retreiving a single Employee, or a list of them.
    Can someone advise me on this?

    You said:
    My problem might be, that the data I'm asking for, is not distinct objects, business objects,
    but a "new type of object" consisting of this particular information, that is
    deptname, numMales, numFemales.
    EXACTLY! You are querying for data that is either aggregate, a combination of various other business objects or a very large set of known business objects. In any of these cases, you probably don't want to use a vanilla DAO. Write a dedicated search DAO. Depending on your OO purity level and time horizon, you could make VO's for the search request or the results returned.
    You said:
    I'd like to think of this as report functionality, or aggregate reports.
    I'm good at database programming, and I'm particularly good at optimization,
    so if I cannot do this the good-looking way, I can always resort to brutal techniques...ehum
    PERFECT! If you are great at database operations, and you know exactly how you want to optimize a given search, then give it its own DAO. The main problem with the object->relational boundary is that most cookie-cutter solutions (ala entity beans with CMP) cannot even remotely appropach the optimization level of a good database programmer. If you want to optimize a search in SQL or a stored procuedure, do that. Then have a dedicated search DAO use that funcitonality. (If you want to do it "right", make a search Factory object that will return various implementations, some may be vendor-specific or optimized, others might be generic; the Factory simply returns a search DAO interface, while specific implementations can concentrate on the task at hand. Swapping implementations with the same interface should be trivial).
    - Saish
    "My karma ran over your dogma." - Anon

  • What is command design pattern? what is the problem that it solves?

    Hi i have been reading few articles on command design pattern but was unable to understand what it is and what problem does it solve. As far as my understanding goes if there is a pre specified method in an object that could execute and perform the necessary activities then it is called as command design pattern. Why is it named as command design pattern, it is because in a shell we use commands to retrieve output. For example when we type "dir" in dos command prompt it returns the list of files. so here we have to remember a preexisting exe file named "dir" which does something when used. So here like we call it command because when "dir" is passed to the computers it returns something that is expected. may be the computer obeys the command issued and return something back. So like wise if there is a method that is defined as as the command, for example in struts framework the action class must have a method "execute()" which is called by the framework to execute the necessary action mapped to it. So if there is a predefined method like "execute" in struts then the object is said to be followed command design pattern. So what actually does it solve?
    What ever i have written is my understanding from the articles i have read about the design pattern. So kindly correct me if i am wrong. Help me understanding what actual problem does this pattern solves. Thanking you in advance.

    This is really off-topic for these forums. You might do better on StackOverflow.com. I'll just say that although the first Design Patterns book came as a revelation to me, it was more for (a) the nomenclature (decorator, factory, facade, etc) which is still with us and (b) about five of the original patterns, which told me things I didn't already know. I've never used any of the others, including Command, and the whole design patterns thing quickly degenerated into farce with what seemed like a sustained attempt to reduce the whole of computer science to design patterns, which really isn't the point. As an example, there is one in another book called Type Object, which is nothing but 3rd normal form, which can be defined roughly in a couple of sentences. This pattern went on for dozens of pages with a very artificial example. I wrote to the mailing list about it: 'Type Object considered hilarious'. I got a rude reply from the original author, which I guess I expected, but also an incredible response from the list owner, saying I should recast my objections in the form of a design pattern. That lost it for me. True story. Moral: don't take this religion, or any IT religion, too seriously. They come around every 18 months or so with the regularity of the next bit of Moore's Law. I've seen dozens of them come and go since 1971, all with something to say, all 90% nonsense.
    See here for a longer version of this incident.

  • Impossible to open number, error -1712, and file iWork's not found in the preference menu.

    Please help, I am bloqued with this damned machine !

    John,
    In the DataBindings.cpx i can't find any reference to a datacontrol...
    This is my bindings:
    <?xml version="1.0" encoding="UTF-8" ?>
    <Application xmlns="http://xmlns.oracle.com/adfm/application"
                 version="11.1.1.56.60" id="DataBindings" SeparateXMLFiles="false"
                 Package="be.usermanagementProv.portlets" ClientType="Generic">
      <definitionFactories>
        <factory nameSpace="http://xmlns.oracle.com/adf/controller/binding"
                 className="oracle.adf.controller.internal.binding.TaskFlowBindingDefFactoryImpl"/>
        <dtfactory className="oracle.adf.controller.internal.dtrt.binding.BindingDTObjectFactory"/>
      </definitionFactories>
      <pageMap>
        <page path="/UserManagement/view.jspx"
              usageId="be_usermanagementProv_portlets_viewPageDef"/>
      </pageMap>
      <pageDefinitionUsages>
        <page id="be_usermanagementProv_portlets_viewPageDef"
              path="UserManagement.viewPageDef"/>
      </pageDefinitionUsages>
    </Application>In the datacontrol section when i right click the DC the "edit definition" is grayed out. Probably because the DC comes from the library and is not created in the application.

  • Classes and subclasses given as String input - question

    Hello, I am new in Java so please don't laugh at my question!!
    I have a method as the following and I am trying to store objects of the type Turtle in a vector. However the objects can also be of Turtle subclasses: ContinuousTurtle, WrappingTurtle and ReflectingTurtle. The exact class is determined by the String cls which is input by the user.
    My question is, how can I use cls in a form that I don't have to use if-else statements for all 4 cases? (Imagine if I had 30 subclasses).
    I have tried these two and similar methods so far but they return an error and Eclipse is not of much help in this case.
    Simplified methods:
    //pre:  cls matches exactly the name of a valid Turtle class/subclass
    //post: returns vector with a new turtle of type cls added to the end
    private Vector<Turtle> newturtle(Vector<Turtle> storage, String cls){
         Turtle t = new cls(...);
         storage.add(t);
         etc.
    private Vector<Turtle> newturtle(Vector<Turtle> storage, String cls){
         Turtle t = new Turtle<cls>(...);
         storage.add(t);
         etc.
    }Thanks for your help.
    p.s.: I didn't know whether to post this question here or under Generics.

    a Factory is atually very simple (100x simpler than reflection).
    example:
    class TurtleFactory
      public Turtle makeTurtle(String typeOfTurtle)
        if (typeOfTurtle.equals("lazy") { return new LazyTurtle(); }
        else if (typeOfTurtle.equals("fast") { return new FastTurtle(); }
        <etc>
    }While at first this doesn't look any better than your original problem, what we've done is made a class that is responsible for all the types of turtles. This will also benefit in case some turtles need initialization or need something passed to their constructor. You encapsulate all that knowledge in one place so you rcode doesn't become littered with it else ladders.

  • [ANNOUNCE] MyFaces 1.0.6 beta released

    New version 1.0.6 beta of free open source JSF implementation was just released.
    Have a look at http://www.myfaces.org
    This is an overdue maintenance release which also offers some often and long requested issues:
    * Library split - there are now 3 myfaces libs:
    - myfaces-jsf-api.jar = the javax.faces.* classes for compile time
    - myfaces-components.jar = the MyFaces extended and custom components for use with any JSR-127 implementation
    - myfaces.jar = the MyFaces implementation (including extended and custom components)
    * Better Tiles support with our JspTilesViewHandler
    * Switch from LGPL to Apache 2.0 license
    Changes in Release 1.0.6 beta:
    * switch to apache license
    * new JspTilesViewHandler for flawless Tiles support
    * RFE #975649 Enhance HtmlTabbedPaneRenderer (rendered attribute for TabbedPane component)
    * RFE #990814 dataList component ignores styleClass attribute
    * bug #1004867 h:message has duplicate attributes
    * bug #1004896 h:dataTable id attribute not rendered
    * bug #995085 graphicImage ignores value attribute
    * bug #992668 selectOneMenu doesn't restore the bean value if it's a primitive
    * bug #992628 StateManager.SerializedView is not static
    * bug #992629 FacesContext.getRenderKit() unimplemented
    * bug #992452 HtmlTree doesn't properly restore state
    * bug #991740 HtmlTreeRender icon URL conversion
    * bug #991234 command links not working with javascript disabled
    * bug #990395 myfaces.jar has bad taglib descriptor
    * bug #990302 Navigation-Rule redirect
    * bug #985274 f:view locale does not always work
    * bug #978654 Input hidden value of null being converted to zero
    * bug #979038 jsCookMenu component does not create dummyForm
    * bug #979039 default-values for ConvertNumberTag and ConvertDateTimeTag
    * changed build.xml - now myfaces-components are shipped via bin-distribution
    * bug #985217 decorator-factory not supported
    * splitting jar-files (myfaces.jar, myfaces-jsf-api.jar, myfaces-components.jar)
    * new EXPERIMENTAL feature to detect JavaScript support of a client browser
    Regards,
    Manfred

    great!!

  • Acrobat X Pro installation

    Just received my new Dell computer preloaded with Acrobat X Standard. I purchased an Acrobat X Professional upgrade and I'm when I try to load it, I get  the following error message, "...Error 1303: The installer has insufficient privledges to access this directory: C:\Program Files(x86)\common files/Adobe/ARM\1.0. The installation cannot continue. Log-on as an administrator..." Any advice???

    Umm, log on as admin? Or at least fix your user privileges/ file permissions? Sounds like the install is tied to a generic virtual "factory" user used by the OEM install that is now disabled. Chbeck your user management system control panel under My Computer --> Manage. And do the same for file permissions by using My Computer --> Properties --> Security.
    Mylenium

  • Factory Patterns with Generics

    I am trying to combine the good old factory pattern with generics and could use some advice.
    I have the following
    //Base class from which all my things extend
    public abstract class Thing {
    //one kind of thing
    public class ThingOne extends Thing {
    //another kind of thing
    public class ThingTwo extends Thing {
    //interface for my factory
    public interface ThingFactory<T> {
    public T create(long id);
    //a factory for thingones
    public class ThingOneFactory<T> implements ThingFactory<T> {
    public T create(long id) {
    return (T) new ThingOne();
    public class TestClass{
    public <T extends Thing> T getThing(ThingFactory<T> tf){
    //do a bunch of generic stuff to figure out id to call create
    ThingFactory<T> instance = tf;
    return (T) instance.create(Long id);
    }My calling code would know what kind of thing it needs but necessarily the things id. Which can be computed in a generic way.
    TestClass gt = new TestClass();
    gt.getThing(new ThingOneFactory<ThingOne>());This all seems to work properly but I am getting "Type safety: Unchecked cast from ThingOne to T" in my ThingOneFactory
    My T's will always extend Thing, what am I missing? Is there a better way to do this?
    Edited by: nedry on Dec 29, 2009 5:39 PM

    I thought of that after I posted. But that just moves my unsafe cast warning into TestClass.Why?
    return (T) instance.create(Long id);That can't have ever compiled. What is the exact code? And why did you have to cast (what was the warning/error)?

Maybe you are looking for

  • How to use an external drive with 2 Macs?

    Using an external drive for LR 5.4 files and can download and view without any issues on my MacBook.  However, when the same drive is attached to my iMac I cannot download or view any files on the external drive that were added after March of this ye

  • Is there a way of protecting PDF documents from printing and/or copying?

    Does anybody know a way of protecting PDF documents from printing and/or copying? All this within the OS possibilities? Is there a way? know one can buy expensive programmes like from Adobe, but I use it so little that I would like a cheaper solution

  • Assignment field is not picking from GL

    Dear All, We are posting one real estate document with reference of the contract number. But when we see the FI document assignment field is not updating from GL which we maintained in sort key. In that FI document we have 4 line items but one line h

  • Frustrated - Installer does not see all hard drives

    Ok. I'm a pretty basic user and here is my situation. I have a G5 with two internal drives. On one drive "A" I have OS X 10.3.9 installed (using that now) on the other internal drive (B) I have 10.4.7. All was working fine using drive "B" as my start

  • External monitor goes full screen

    i have a custom two screen layout for Premiere Pro. but one of the monitor starts to play full screen an hides the other windows. Any tips on how to customize the video Playout? Thanks T