Returning an instance of a subclass

I like to think of myself as a purist when designing OO relationships. Specifically, I don't agree with having classes in one package (com.foo) reference classes in a 'sub' package (com.foo.bar). I also don't agree with a class instantiating subclasses of itself. The way I see it is that the 'super' packages and super classes exist prior to their dependent clients.
That being said, I look in java.lang.Object and see it returning Objects of type Class and String - both subclasses of Object. This relationships forces me to create a String class before creating an Object class, but at the same time I can't create a String class until an Object class is defined. It's Java's own version of the chicken and the egg.
Any thoughts on this from the community? Does anyone else dislike this? Alternatively, does anyone have any reasons or situations where this is particular handy, besides the Object/Class/String example given. (And please DON'T anyone start explaining how it is possible to compile such a circular dependency. I know that. This question is purely philosophical in nature. I'm looking for a discussion here, not an answer per se.)
dlgrasse

Hi,
I believe that the purpose of our object oriented concepts, i.e. our meta-model, is to enable us to build models of things and think about them in a practical way.
You mention the example with the chicken and the egg which is just one example of circularity among definitions of concepts in the real world.
I think it is a strength when a programming language is capable of expressing such definitions because it reflects how we think about things. When I think about the "chicken and egg"-problem I can come to terms with it quite easily. Instead of denying the existence of either of them because of the infinite regress that seems to arise when I think about the problem, I think about the two as having evolved in parallel. Likewise, I see no problem in Objects evolving in parallel with String or vice versa. The fact that the one is a generalisation of the other does not necessarily mean that it was created before and independently of the other. In fact, that pattern is a really useful one in many situations.
I will try to follow your mode of thought. I understand that according to you, no definition of a class should refer to a class that its own definition depends on. Let's make a small language in which only objects exist (so-called primitive types included). The language supports inheritance. At the base of our class hierarchy we must have some class resembling Object. According to you this class can only operate on Objects (is this an impure reference? can an object refer to its own definition?). So tell me: how can this class be extended in a way that adds functionality? Do we need a set of primitive types to make purism work? If so, is it pure?
I think that all formal systems need at least two interacting and cross-defining concepts to be interesting, such as the theory of natural numbers, that of grammars, that of automata, etc. And it just doesn't make much sense to ask which one came first. Perhaps the design of a programming language is also bound to include such circular definitions to be interesting.
Regards,
Søren Bak

Similar Messages

  • Returning multiple instances of the same object?

    I have a fairly straight forward swing test class that contains a combobox. The problem is that an object is not selected in the combobox because I get different objects when building the list and when setting the selected item.
    To test this, I've added the following set of 4 lines on three locations in the code:
    - immediately after Toplink is initialized
    - when setting the selected item
    - when the main exits (and the JFrame is open)
    Stand s = Stand.findByPK(4).getDerrivedfromstand();
    System.out.println( s + ", Using EM #" + Integer.toHexString( lEntityManager.hashCode() ) );
    s = Stand.findByPK(1);
    System.out.println( s + ", Using EM #" + Integer.toHexString( lEntityManager.hashCode() ) );
    I happen to know that Stand 4 is derrived from Stand 1. So I get Stand 1 once via Stand 4 and once directly. The result is:
    java.vm.version=1.6.0-b105
    [TopLink Info]: 2007.05.30 11:01:10.531--ServerSession(33414193)--TopLink, version: Oracle TopLink Essentials - 2.0 (Build b41-beta2 (03/30/2007))
    [TopLink Info]: 2007.05.30 11:01:11.343--ServerSession(33414193)--file:/C:/Documents%20and%20Settings/toeu/My%20Documents/kp/reinders/reinders/voorraad/container/bm/build/-reinders login successful
    // immediatly after Toplink init
    [1] setObject=4 / SELECT ... FROM stand WHERE (standnr = >>>HERE<<< )
    executeQuery: SELECT ... FROM stand WHERE (standnr = ?)
    [1] setObject=1 / SELECT ... FROM stand WHERE (standnr = >>>HERE<<< )
    executeQuery: SELECT ... FROM stand WHERE (standnr = ?)
    nl.reinders.bm.Stand@1866417, Standnr=1, Using EM #1a8e53c
    [1] setObject=1 / SELECT ... FROM stand WHERE (standnr = >>>HERE<<< )
    executeQuery: SELECT ... FROM stand WHERE (standnr = ?)
    nl.reinders.bm.Stand@1866417, Standnr=1, Using EM #1a8e53c
    // when filling a combobox in the GUI
    executeQuery: SELECT ... FROM stand ORDER BY standid ASC
    getElementAt 0 = nl.reinders.bm.Stand@1866417, Standnr=1
    // when setting the value of the combobox
    executeQuery: SELECT ... FROM stand ORDER BY standid ASC
    [1] setObject=4 / SELECT ... FROM stand WHERE (standnr = >>>HERE<<< )
    executeQuery: SELECT ... FROM stand WHERE (standnr = ?)
    [1] setObject=1 / SELECT ... FROM stand WHERE (standnr = >>>HERE<<< )
    executeQuery: SELECT ... FROM stand WHERE (standnr = ?)
    nl.reinders.bm.Stand@171ef98, Standnr=1, Using EM #1a8e53c
    [1] setObject=1 / SELECT ... FROM stand WHERE (standnr = >>>HERE<<< )
    executeQuery: SELECT ... FROM stand WHERE (standnr = ?)
    nl.reinders.bm.Stand@171ef98, Standnr=1, Using EM #1a8e53c
    // when exiting the main (JFrame is open)
    [1] setObject=1 / SELECT ... FROM stand WHERE (standnr = >>>HERE<<< )
    executeQuery: SELECT ... FROM stand WHERE (standnr = ?)
    nl.reinders.bm.Stand@171ef98, Standnr=1, Using EM #1a8e53c
    [1] setObject=4 / SELECT ... FROM stand WHERE (standnr = >>>HERE<<< )
    executeQuery: SELECT ... FROM stand WHERE (standnr = ?)
    nl.reinders.bm.Stand@171ef98, Standnr=1, Using EM #1a8e53c
    [1] setObject=1 / SELECT ... FROM stand WHERE (standnr = >>>HERE<<< )
    executeQuery: SELECT ... FROM stand WHERE (standnr = ?)
    nl.reinders.bm.Stand@171ef98, Standnr=1, Using EM #1a8e53c
    What is amazing is that somewhere after the combobox is filled, the query returns another instance of the same record and thus the select item will not find an "equal" object in the list. Any suggestions?

    Nevermind. A clear was done on the EM somewhere down the line.

  • GetInstancesByFilter returns no instance

    Hi,
    I've a random comportment with BusinessProcess.getInstancesByFilter. Some times, this methods returns no instance although there is instances corresponding to my filter.
    Here my code :
    Fuego.Papi.BusinessProcess bp;
    Fuego.Papi.InstanceFilter instF;
    Fuego.Instance[] instances;
    bp = BusinessProcess();
    try {
    for (int i=0;i<100;i++) {
         bp.connectTo(url : Fuego.Server.directoryURL, user : "admin", password : "password",process : "/Process1");
         // création du filtre
         instF = InstanceFilter();
         instF.create(processService : bp.processService);
         instF.addAttributeTo(variable : "prjDemande", comparator : Comparison.IS,
         value : (String)i);
         // récupération de l'instance
         instF.searchScope = SearchScope(participantScope : ParticipantScope.ALL, statusScope : StatusScope.ONLY_INPROCESS);
         instances = bp.getInstancesByFilter(filter : instF);
         if (instances.count() == 0) {
         logMessage("============> Pas d'instance trouvée pour "+i);
         // Récupération de l'instance
         foreach (instance in instances) {
         logMessage("=============> instance "+i+" trouvée : "+activite+" / "+demande);
         bp.disconnectFrom();
    finally {
    try{
    bp.disconnectFrom();
    The only solution, I've found is to loop on the getInstancesByFilter until it returns a result...
    Thanks you for you help
    Thierry

    Is it running on Enterprise. If it's Enterprise are you running on a J2EE container (WLS)? How do you have your Workspace configured (single, multiple)?

  • Return proxy instances from EJB

    Is weblogic able to return proxy instances from EJBs?
    <BR>
    I am using the session-facade pattern with DTO/Value-Object being passed between
    facade and client(s). To handle different "levels of loading", I want to have
    one DTO for an entity, but then restrict the available properties by wrapping
    in an interface using java.lang.reflect.Proxy.
    <BR>
    Should this work? It doesn't. For example (from my session bean):<P><PRE>
    return new MyDTO();
    </PRE>works fine; however, the stubs generated by weblogic.ejbc have trouble unmarshalling
    the return if I do:<P><PRE>
    return Proxy.newProxyInstance(
    MyInterface.class.getClassLoader(),
    new Class[] { MyClass.class },
    new MyPassThruHandler( new MyDTO() )
    </PRE> returning various errors.
    <BR>
    Is this valid to do from weblogic? If not, I am mystified as to how not.
    <BR>
    Thanks,<P>
    Steve
    <BR>
    P.S., I am using WL61sp3.

    Hi all,
    Finally, I solve the problem. That is my misstake, i had a interface declared as private variable in the my concreteClass (inhert from AbstractClass)... now i declare as transient, let the interface variable don't to be serialize.
    Now everything fine...:-) thanks for help anyway.
    But just wonder why it don't throw any exception ???
    Gordon

  • Wmic /namespace:\\root\microsoftdfs path dfsrVolumeConfig where volumeGuid="2D5C6F5C-97C4-11E2-93EC-902B34BC5BAB" call ResumeReplication returns No Instance(s) available....

    Hello All,
    I found a post with the exact error that I am seeing:  Backlog calculations cannot be performed because the reference
    member returned zero replicated folders. and followed the proposed solution:  WMIC.EXE /namespace:\\root\microsoftdfs
    path dfsrreplicatedfolderconfig get replicatedfolderguid,replicatedfoldername  was used to get the GUID of the volume.  Next I ran:  wmic
    /namespace:\\root\microsoftdfs path dfsrVolumeConfig where volumeGuid="2D5C6F5C-97C4-11E2-93EC-902B34BC5BAB" call ResumeReplication  inserting the GUID resulting from the previous query, not the one in the posted fix (obviously)...
    It returns:  No Instance(s) Available.
    What have a I done incorrectly or missed?  Why does it not see my folder?
    Any input and help would be greatly appreciated!

    Hi, 
    The response “No Instance(s) Available” expressed either the DFS Replication service is not running, or the DFSR Database is corrupt.
    Please check if there is any error message in event log. If it is due to the DFSR Database is corrupt, you could recreate the DFSR Database by replicating from other member server or restore the Database once restore is done.
    For more detailed information, please refer to the thread below:
    DFSR - Database Corrupt
    http://social.technet.microsoft.com/Forums/windowsserver/en-US/b69839aa-f050-419c-9344-6b7bf067c318/dfsr-database-corrupt?forum=winserverfiles
    Regards,
    Mandy
    If you have any feedback on our support, please click
    here .
    We
    are trying to better understand customer views on social support experience, so your participation in this
    interview project would be greatly appreciated if you have time.
    Thanks for helping make community forums a great place.

  • IPhone Development - returning an instance

    With code like,
    NSString *str;
    int x = 3
    str = [NSString stringWithFormat:@"%i", x];
    How would I go about coding something like that for my own class, where I return an instance? Right now I'm doing this:
    Fraction *f = [[Fraction alloc] initWithNumerator:3 andDenominator:5];
    [f autorelease];
    return f;
    and I'd like to do:
    return [Fraction fractionWithNumerator:3 andDenominator:5];
    Thanks

    If I'm understanding your question correctly, you want a class method that will return an autoreleased instance of a Fraction*.
    So, change your method from:
    - (Fraction *)initWithNumerator:(int)n andDenominator:(int)d;
    to something like:
    + (Fraction *)fractionWithNumerator:(int)n andDenominator:(int)d;
    and change your:
    - (Fraction *)initWithNumerator:(int)n andDenominator:(int)d {
    [super init];
    if (self) {
    [self setNumerator:n andDenominator:d];
    return self;
    to something like:
    + (Fraction *)fractionWithNumerator:(int)n andDenominator:(int)d {
    Fraction* f;
    f = [[self alloc] init]);
    [f setNumerator:n andDenominator:d];
    return [f autorelease];

  • Return all instances of a string value

    I know that similar questions have been asked before but I am having a tough time getting things to work.
    I would like to search for all instances of a string value (shown red) and return the corresponding values in the adjacent cells (shown green) so that each room number is represented.  For example, I want the search for "Adequately" to return rooms 236 and 237 (and 237 just once even though it is listed twice).  Is this possible?
    Any help is appreciated.
    Clay

    Here's an example, similar in some ways to Yvan's, but taken a bit further.
    Data table (left) contains only the original data. I've shortened the ratings to allow an easier fit on this page.
    Summary table does the work in two stages.
    Pulls the room numbers for rooms matching each rating. (yellow portion of table. If desired, these rows may be hidden.
    Builds a list of these for each condition. (Footer row)
    Formulas (all on Summary)
    Row 1 is a header row, and contains the Rating labels, which must match those used on the Data table.
    B2:   =IF(AND(Data :: $E2=B$1,COUNTIFS(Data :: $E$2:$E2,B$1,Data :: $C$2:$C2,Data :: $C2,Data::$B$2:$B2,Data :: $B2)=1)," "&Data :: $B2&" "&Data :: $C2&" ","")
    Fill right to column F. Fill down to row 16 (as many rows as there are data rows on Data)
    Note the " " at the beginning and end of the 'if true' part: " "&Data :: $B2&" "&Data :: $C2&" "
    There is a single space between each pair of quotation marks. These are necessary to the second formula below.
    Row 17 is a Footer row.
    B17:  
    =IF(COUNTA(B)-COUNTBLANK(B)=0,"",TRIM(SUBSTITUTE(CONCATENATE(B2,B3,B4,B5,B6,B7,B 8,B9,B10,B11,B12,B13,B14,B15,B16),"  ",",
    There is a return character in the formula immediately before the last quotation mark. Press option-return to enter a return into a formula.
    SUBSTITUTE finds the two spaces added between items in the list and replaces them with a comma followed by the return noted above.
    TRIM is used to remove the single space before the first item in the list and the single space after the last.
    Regards,
    Barry

  • Return an Image from a subclass to a graphics class

    Hello
    I'm wondering how to return an Image generated by one class to a class which works as a graphics class. The graphics class is run from a main class. Let me make up a schedule:
    Image-generator return Image -> graphics class paint
    I have tried just making an Image and using the getGraphics to connect a graphics object to it, but it doesn't seem to work.
    Thanks in advance

    Okay, here are the pieces of code we use. (Comments are in Swedish but they are barely relevant, and explain merely basically what is happening in the program)
    The applet is compilable, but there is a nullpointerexception in Elefanträknaren, at getGraphics(). Believe me, I have tried finding the solution to this already.
    Spelet (main method)
    import java.applet.*;
    import java.awt.*;
    public class Spelet extends Applet
         /*Elefanträknaren testerna;*/
         Ritaren ritarN;
         Graphics g;
         public void init()
              /*testerna = new Elefanträknaren();*/
              ritarN = new Ritaren(g, getSize().width, getSize().height);
              setLayout(new GridLayout(1, 1));
              add(ritarN);
         public void start()
              ritarN.startaTråd();
         public void stop()
              ritarN.stoppaTråd();
         public void update(Graphics g)
              paint(g);
    }Ritaren (graphics object)
    import java.awt.*;
    public class Ritaren extends Panel implements Runnable
         Elefanträknaren e;
         Graphics g;
         int bredd, höjd;
         //Trådobjekt
         Thread tråd;
         public Ritaren(Graphics g, int bredd, int höjd)
              this.bredd = bredd;
              this.höjd = höjd;
              e = new Elefanträknaren(bredd, höjd);
         public void startaTråd()
              if( tråd == null )
                   tråd = new Thread(this); //Skapa tråden
                   tråd.start(); //Kör igång
                   e.startaTråd();
         public void stoppaTråd()
              if( tråd != null )
                   tråd.interrupt();
                   tråd = null;
         public void paint(Graphics g)
              g.drawImage(e.getSpökbilden(), 0, 0, this);
         public void update(Graphics g)
              paint(g);
         public void run()
              while( tråd != null )
                   repaint();
                   try
                        Thread.sleep(33);
                   catch(Exception e){}
    }Elefanträknaren (class generating the Image)
    import java.awt.*;
    import java.util.*;
    import java.awt.image.BufferedImage;
    import javax.swing.ImageIcon;
    public class Elefanträknaren extends Panel implements Runnable
         //Vektorn som innehåller alla Elefant-klasser
         private Vector elefanterna;
         //Ritobjektet för den dubbelbuffrade bilden
         private Graphics gx;
         //Bildobjektet för dubbelbuffringen
         private Image spökbilden;
         private int bredd, höjd;
         //Trådvariabeln
         private Thread tråd;
         //Rörelsen uppdateras 30 ggr/s. RÄKNARE håller koll på när en elefant ska läggas till (efter 30 st 30-delar = 1 ggr/s)
         int RÄKNARE = 30;
         int ÄNDRING = RÄKNARE;
         //DELAY betecknar delayen mellan två bilder/frames. 33 ms delay = 30 FPS
         int DELAY = 33;
         //Konstruktor
         public Elefanträknaren(int bredd, int höjd)
              elefanterna = new Vector();
              this.bredd = bredd;
              this.höjd = höjd;
         //Kör igång tråden/ge elefanterna liv
         public void startaTråd()
              if( tråd == null )
                   tråd = new Thread(this); //Skapa tråden
                   tråd.start(); //Kör igång
                   //Dubbelbuffringen initieras - detta måste ligga i startaTråd()
                   //spökbilden = new BufferedImage(bredd, höjd, BufferedImage.TYPE_INT_ARGB);
                   spökbilden = createImage(bredd, höjd);
                   gx = spökbilden.getGraphics();
         //Stoppa tråden/döda elefanterna
         public void stoppaTråd()
              if( tråd != null )
                   tråd.interrupt();
                   tråd = null;
         //Lägg till en elefant i vektorn
         private void läggTillElefant(Elefant e)
              elefanterna.add(e); //Lägg till en Elefant som objekt i vektorn
              Elefant temp = (Elefant)     elefanterna.get(elefanterna.size()-1);
              temp.startaTråd(); //Starta Elefantens tråd - ge Elefanten liv
         //Sätter ihop bilden som ska sickas till Ritaren
         public void uppdaterarN()
              //Rensa skärmen från den förra bilden
              gx.fillRect(0, 0, bredd, höjd);
              for( int i = 0; i < elefanterna.size(); i++ )
                   Elefant temp = (Elefant) elefanterna.get(i);
                   gx.drawImage(temp.getBild(), temp.getX(), temp.getY(), null);
         public Image getSpökbilden()
              return spökbilden;
         //Tråd-loopen
         public void run()
              while( tråd != null )
                   RÄKNARE++;
                   if( RÄKNARE >= ÄNDRING )
                        läggTillElefant(new Elefant(11, 50, 900));
                        RÄKNARE = 0;
                   uppdaterarN();
                   //repaint();
                   try
                        Thread.sleep(DELAY);
                   catch(Exception e){}
    }Elefant (a class which Elefanträknaren turns into an Image:
    import java.awt.*;
    import java.util.*;
    import javax.swing.ImageIcon;
    public class Elefant extends Panel implements Runnable
         private int x, y; //Elefantens koordinater
         private int hälsa; //Elefantens hälsa
         private int RÖRELSESTEG = 10;//Antal pixlar elefanten ska röra sig i sidled
         private int DELAY;
         //Animation
         private Vector bilderna = new Vector();
         private Vector bilderna2 = new Vector();
         private int fas; //Delen av animationen som ska visas
         private boolean framåt;
         //Tråddelen
         private Thread tråd;
         public Elefant(int x, int y, int hastighet)
              this.x = x;
              this.y = y;
              DELAY = 1000 - hastighet;
              hälsa = 100;
              framåt = true;
              fas = 0; //Nollställ fasen
              //Få fram bildernas namn
              for( int i = 0; i <= 5; i++ )
                   Image temp = new ImageIcon("Z:\\Projektet\\gamal\\Projektet\\Mappen\\mediat\\png\\jumbo" + i + ".png").getImage();
                   bilderna.add(temp);
                   Image temp2 = new ImageIcon("Z:\\Projektet\\gamal\\Projektet\\Mappen\\mediat\\png\\jumbo" + i + "r.png").getImage();
                   bilderna2.add(temp2);
         //get-variabler
         public int getX() { return x; }
         public int getY() { return y; }
         //Kör igång tråden/ge elefanten liv
         public void startaTråd()
              if( tråd == null )
                   tråd = new Thread(this); //Skapa tråden
                   tråd.start(); //Kör igång
         //Rör elefanten i sidled
         private void rörelse()
              //Animering
              if( fas < 5 ) fas++;
              else     fas = 0;
              //Flytta ner elefanten när den når en av spelets kanter
              if( x >= 800 || x <= 10 ) y += 85;
              //Kontrollera riktning
              if( x >= 800 ) framåt = false;
              else if( x <= 10 ) framåt = true;
              //Positionering
              if( framåt ) x += RÖRELSESTEG;
              else x -= RÖRELSESTEG;
         //Hämtar den aktuella bilden, och returnerar den
         public Image getBild()
              Image temp;
              if( framåt ) temp = (Image) bilderna.get(fas);
              else temp = (Image) bilderna2.get(fas);
              return temp;
         /* Tråd-hantering */
         //Stoppa tråden/döda elefanten
         public void stoppaTråd()
              if( tråd != null )
                   tråd.interrupt();
                   tråd = null;
         //Körs när elefanten är vid liv
         public void run()
              while( tråd != null )
                   rörelse();
                   try
                        Thread.sleep(DELAY);
                   catch(Exception e){}
    }

  • Creating instances of Document subclass

    I have two new classed, one extends Document (call it CustomDoc) and the other extends Folder (call it CustomFolder).
    Is there any way to use the iFS webui to create these instead of the standard Document and Folder objects?

    Do you want all iFS Files to be stored as an instance of Custom-Doc, or only certain kinds of file. In order to redirect a particular kind of file (identified by it's file extension) to a custom content type you can use the ClassSelectionParser.
    See attached an example that maps BMP, JPG and TIF to the SimpleImage type.
    <?xml version="1.0" standalone="yes"?>
    <OBJECTLIST>
    <PROPERTYBUNDLE>
    <UPDATE RefType="valuedefault">ParserLookupByFileExtension</UPDATE>
    <PROPERTIES>
    <PROPERTY ACTION="add">
    <NAME>tif</NAME>
    <VALUE DataType="String">oracle.ifs.beans.parsers.ClassSelectionParser</VALUE>
    </PROPERTY>
    <PROPERTY ACTION="add">
    <NAME>bmp</NAME>
    <VALUE DataType="String">oracle.ifs.beans.parsers.ClassSelectionParser</VALUE>
    </PROPERTY>
    <PROPERTY ACTION="add">
    <NAME>jpg</NAME>
    <VALUE DataType="String">oracle.ifs.beans.parsers.ClassSelectionParser</VALUE>
    </PROPERTY>
    </PROPERTIES>
    </PROPERTYBUNDLE>
    <PROPERTYBUNDLE>
    <UPDATE RefType="valuedefault">IFS.PARSER.ObjectTypeLookupByFileExtension</UPDATE>
    <PROPERTIES>
    <PROPERTY ACTION="add">
    <NAME>tif</NAME>
    <VALUE DataType="String">SimpleImage</VALUE>
    </PROPERTY>
    <PROPERTY ACTION="add">
    <NAME>jpg</NAME>
    <VALUE DataType="String">SimpleImage</VALUE>
    </PROPERTY>
    <PROPERTY ACTION="add">
    <NAME>bmp</NAME>
    <VALUE DataType="String">SimpleImage</VALUE>
    </PROPERTY>
    </PROPERTIES>
    </PROPERTYBUNDLE>
    </OBJECTLIST>
    I do not know of any way to create instances of custom folders except via XML, or the API,
    Here is an example of how to create an an instance of a custom folder using an XML file
    <PressReleaseFolder>
    <NAME>Oracle8i Press Release</NAME>
    <FOLDERPATH>/PublishedPressReleases</FOLDERPATH>
    <ACL reftype="name" classname="SystemAccessControlList">LockedContent</ACL>
    </PressReleaseFolder>
    null

  • 'instance of' or subclass Expression

    Login is a subclass of Entity. I need to include things in my expression that are in Login but I only have a reference to Entity.
    builder.get("entity").get("username") does not work because only the login subclass has username.
    builder.get("login").get("username") odes not work because login is not a valid attribute name.
    Mapping from my object to entity.
    oneToOneMapping = new OneToOneMapping();
    oneToOneMapping.setAttributeName("entity");
    oneToOneMapping.setForeignKeyFieldName("TABLEA.ENTITYID");
    oneToOneMapping.setReferenceClass(Entity.class);
    oneToOneMapping.setGetMethodName("getEntityHolder");
    oneToOneMapping.setSetMethodName("setEntityHolder");
    oneToOneMapping.setUsesIndirection(true);
    descriptor.addMapping(oneToOneMapping);
    I really don't want to do a subquery across the whole login table...

    There is currently no casting support in TopLink Expressions, please enter this enhancement request on EclipseLink.
    A workaround is to define a OneToOneQueryKey to the subclass in your descriptor. This will let you do,
    builder.get("login").get("username")
    i.e.
    queryKey = new OneToOneQueryKey();
    queryKey.setName("login");
    ExpressionBuilder builder = new ExpressionBuilder();
    queryKey.setSelectionCriteria(builder.getField("ENTITY.ENTITYID").equal(builder.getParameter("TABLEA.ENTITYID")));
    queryKey.setReferenceClass(Login.class);
    descriptor.addQueryKey(queryKey);
    James : http://www.eclipselink.org

  • Abstract class - subclass

    a quik question: if I have a abstract class define a method, and a subclass implementing it, and a third class with an instance casted as the abstract class, would the following method in the subclass then return the instance casted as subclass? :
    public Subclass getInstance() {
    return this;
    Stig.

    oops.... cant return SubClass....

  • Way to display the output of tail command in a Java app

    Hi,
    I have a Java app running in the Linux environment. The Weblogic outputs get written to a log. I would like to design a screen in my app that will enable me to monitor my logs. I normally log into the Linux machine and do a tail -f on the log.
    tail -f Managed_1.logI would like to run this tail -f command from my Java app so that I am able to view the log proress from my app itself. I know we can use Runtime to run external programs but this is a case where a command will be executed continuously and the output will need to be displayed in my app, more specifically on a JSP.
    Any ideas would be most appreciated.
    Thanks and regards,
    Ganesh

    I had a look at the API for the Process class which
    lists an abstract method called getOutputStream().
    What I am not clear is that the documentation says
    that the exec method of Runtime will return an
    instance of a subclass of Process. Does this mean
    that the getOutputStream() method would have already
    been coded for the subclass instance returned?Yes.
    And even if we do get the OutputStream from the tail
    -f process, we will still have to read and display
    the info on a line by line basis. Will this happend
    to be fast enough to macth atleast to some extent the
    speed at which the log is written to?There are two ways to answer this:
    1. Ask somebody who knows how fast the log is written to.
    2. Try it and see.
    My approach would be the second option.

  • Ternimating a process that is started from insite a java program

    Hi,
    I have a question:
    I am using Java 1.1 running on a HP-UX platform(HP-UX 11.0).
    I start a "unix shell script" from inside a java process. Everything starts and runs perfectly fine. If for some reason I MANUALLY kill the java program with a "kill" command, the unix process that was started by the java process is not getting killed. (effectively the signal is not getting passed on to the child process). Is there a way to fix this?
    Thanks in Advance.
    Srikanth
    [email protected]

    Here is what the java API docs say about the Process class:
    The Runtime.exec methods create a native process and return an instance of a subclass of Process
    that can be used to control the process and obtain information about it. The class Process
    provides methods for performing input from the process, performing output to the process,
    waiting for the process to complete, checking the exit status of the process, and destroying
    (killing) the process.
    The Runtime.exec methods may not work well for special processes on certain native platforms,
    such as native windowing processes, daemon processes, Win16/DOS processes on Win32, or
    shell scripts. The created subprocess does not have its own terminal or console. All its
    standard io (i.e. stdin, stdout, stderr) operations will be redirected to the parent process
    through three streams (Process.getOutputStream(), Process.getInputStream(), Process.getErrorStream()). The
    parent process uses these streams to feed input to and get output from the subprocess.
    Because some native platforms only provide limited buffer size for standard input and output
    streams, failure to promptly write the input stream or read the output stream of the
    subprocess may cause the subprocess to block, and even deadlock.
    The subprocess is not killed when there are no more references to the Process object, but
    rather the subprocess continues executing asynchronously.
    There is no requirement that a process represented by a Process object execute
    asynchronously or concurrently with respect to the Java process that owns the Process object.
    [/b[
    So the docs state that this class may not work with shell scripts. Which means that it may be no way to deal with this.
    Good luck
    Calin

  • Using unix in java

    Im trying to use this within a java app however I get the following error
    String cmdCreate[] = {"cd", "test"};
    Runtime.getRuntime().exec(cmdCreate);
    java.io.IOException: cd not found
         at java.lang.UNIXProcess.create(UNIXProcess.java)
         at java.lang.Runtime.execInternal(Native Method)
         at java.lang.Runtime.exec(Unknown Source)
         at java.lang.Runtime.exec(Unknown Source)
         at java.lang.Runtime.exec(Unknown Source)
         at a5.Test3.main(Test3.java:19)
    How can I fix this

    The Runtime.exec methods create a native process and return an instance of a subclass of Process that can be used to control the process and obtain information about it. The class Process provides methods for performing input from the process, performing output to the process, waiting for the process to complete, checking the exit status of the process, and destroying (killing) the process.
    The Runtime.exec methods may not work well for special processes on certain native platforms, such as native windowing processes, daemon processes, Win16/DOS processes on Win32, or shell scripts. The created subprocess does not have its own terminal or console. All its standard io (i.e. stdin, stdout, stderr) operations will be redirected to the parent process through three streams (Process.getOutputStream(), Process.getInputStream(), Process.getErrorStream()). The parent process uses these streams to feed input to and get output from the subprocess. Because some native platforms only provide limited buffer size for standard input and output streams, failure to promptly write the input stream or read the output stream of the subprocess may cause the subprocess to block, and even deadlock. ..... etc....
    .....

  • Why the singleton pattern used rather than static things?

    class Single
        private Single() {}
        private void print() { System.out.println("Foo~"); }
        private static Single one = new Single();
        public static void print() { one.print(); }
    class Stat
        public static void print() { System.out.println("Foo~"); }
    }What's the different?? What is the benefit of the singleton one?

    There is no practical difference - because, in fact, that is not the singleton pattern!
    A singleton would look like:
    class Singleton {
        private Singleton() {}
        public void print() { System.out.println("Foo~"); }
        private static Singleton instance = new Singleton();
        public static Singleton getInstance() { return instance; }
    }The benefit of this pattern is, that your client code doesn't have to know that there is only one instance (getInstance could return another instance for every call) or of which actual type it is (getInstance could return an instance of any Subclass of Singleton).
    See http://c2.com/cgi/wiki?SingletonPattern for more information on the pattern.

Maybe you are looking for