StartDrag using Generic method in Actionscript 3

Hi,
AS3:
How to get general id (or) name from xml loaded images. bcoz, i want to drag and drop that images in generic method. Now, i currently used the event.target.name for each one.
So, code length was too large. See my code below.
/*********loading images through xml********/
var bg_container_mc:MovieClip
var bg_bg_myXMLLoader:URLLoader = new URLLoader();
bg_bg_myXMLLoader.load(new URLRequest("xml/backgroundimages.xml"));
bg_bg_myXMLLoader.addEventListener(Event.COMPLETE, processXML_bg);
function processXML_bg(e:Event):void {
          var bg_myXML:XML=new XML(e.target.data);
          columns_bg=bg_myXML.@COLUMNS;
          bg_my_x=bg_myXML.@XPOSITION;
          bg_my_y=bg_myXML.@YPOSITION;
          bg_my_thumb_width=bg_myXML.@WIDTH;
          bg_my_thumb_height=bg_myXML.@HEIGHT;
          bg_my_images=bg_myXML.IMAGE;
          bg_my_total=bg_my_images.length();
          bg_container_mc = new MovieClip();
          bg_container_mc.x=bg_my_x;
          bg_container_mc.y=bg_my_y;
          ContentHead.addChild(bg_container_mc);
          for (var i:Number = 0; i < bg_my_total; i++) {
                   var bg_thumb_url=bg_my_images[i].@THUMB;
                    var bg_thumb_loader = new Loader();
                   bg_thumb_loader.load(new URLRequest(bg_thumb_url));
                   bg_thumb_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, thumbLoaded_bg);
                   bg_thumb_loader.name="bg_load"+i;
                   bg_thumb_loader.addEventListener(MouseEvent.MOUSE_DOWN, bg_down)
                   bg_thumb_loader.x = (bg_my_thumb_width-18)*bg_x_counter;
                   bg_thumb_loader.y = (bg_my_thumb_height-45)*bg_y_counter;
                   if (bg_x_counter+1<columns_bg) {
                             bg_x_counter++;
                   } else {
                             bg_x_counter=0;
                             bg_y_counter++;
function thumbLoaded_bg(e:Event):void {
          var my_thumb_bg:Loader=Loader(e.target.loader);
         var sprite:Sprite = new Sprite();
          var shape:Shape = new Shape();
          shape.graphics.lineStyle(1, 0x0098FF);
          shape.graphics.drawRect(e.target.loader.x-2, e.target.loader.y-2, e.target.loader.width+4, e.target.loader.height+4);
          sprite.addChild(shape);
          sprite.addChild(my_thumb_bg);
          sprite.x=4;
          bg_container_mc.addChild(sprite);
          my_thumb_bg.contentLoaderInfo.removeEventListener(Event.COMPLETE, thumbLoaded_bg);
//  get name for each image. 
I want to change this code in generic method. do needful.
function bg_down(event:MouseEvent):void {
          var bg_name:String=new String(event.currentTarget.name);
          var bg_load:MovieClip=event.currentTarget as MovieClip;
          if (event.currentTarget.name=="bg_load0") {
                  var alaska_mc:alaska_png=new alaska_png();
                   addChild(alaska_mc);
                   alaska_mc.x=stage.mouseX;
                   alaska_mc.y=stage.mouseY;
                   alaska_mc.name="alaska_duplicate"+alaska_inc;
                   alaska_inc++;
                   alaska_mc.startDrag(false);
                  alaska_mc.addEventListener(MouseEvent.MOUSE_UP, stdrag);
                   alaska_mc.addEventListener(MouseEvent.MOUSE_UP, stdrag);
          if (event.currentTarget.name=="bg_load1") {
                   var lake_mc:lake_png=new lake_png();
                   addChild(lake_mc);
                   lake_mc.x=lake_mc.mouseX;
                   lake_mc.y=lake_mc.mouseY;
                   lake_mc.name="lake_duplicate"+lake_inc;
                   lake_inc++;
                   lake_mc.startDrag(false);
                   lake_mc.addEventListener(MouseEvent.MOUSE_UP, stdrag);
          if (event.currentTarget.name=="bg_load2") {
                   var mountn_mc:mountn_png=new mountn_png();
                   addChild(mountn_mc);
                   mountn_mc.x=mountn_mc.mouseX;
                   mountn_mc.y=mountn_mc.mouseY;
                   mountn_mc.name="mountn_duplicate"+mountn_inc;
                   mountn_inc++;
                   mountn_mc.startDrag(false);
                   mountn_mc.addEventListener(MouseEvent.MOUSE_UP, stdrag);
          if (event.currentTarget.name=="bg_load3") {
                   var town_mc:town_png=new town_png();
                   addChild(town_mc);
                   town_mc.x=town_mc.mouseX;
                   town_mc.y=town_mc.mouseY;
                   town_mc.name="town_duplicate"+town_inc;
                   town_inc++;
                   town_mc.startDrag(false);
                   town_mc.addEventListener(MouseEvent.MOUSE_UP, stdrag);
          if (event.currentTarget.name=="bg_load4") {
                   var water_mc:water_png=new water_png();
                   addChild(water_mc);
                   water_mc.x=water_mc.mouseX;
                   water_mc.y=water_mc.mouseY;
                   water_mc.name="water_duplicate"+water_inc;
                   water_inc++;
                   water_mc.startDrag(false);
                  water_mc.addEventListener(MouseEvent.MOUSE_UP, stdrag);
          if (event.currentTarget.name=="bg_load5") {
                   var city_mc:city_png=new city_png();
                   addChild(city_mc);
                   city_mc.x=city_mc.mouseX;
                   city_mc.y=city_mc.mouseY;
                   city_mc.name="city_duplicate"+city_inc;
                   city_inc++;
                   city_mc.startDrag(false);
                  city_mc.addEventListener(MouseEvent.MOUSE_UP, stdrag);
          if (event.currentTarget.name=="bg_load6") {
                    var citywide_mc:citywide_png=new citywide_png();
                   addChild(citywide_mc);
                   citywide_mc.x=citywide_mc.mouseX;
                   citywide_mc.y=citywide_mc.mouseY;
                   citywide_mc.name="citywide_duplicate"+citywide_inc;
                   citywide_inc++;
                   citywide_mc.startDrag(false);
                  citywide_mc.addEventListener(MouseEvent.MOUSE_UP, stdrag);
          if (event.currentTarget.name=="bg_load7") {
                   var downtown_mc:downtown_png=new downtown_png();
                   addChild(downtown_mc);
                   downtown_mc.x=downtown_mc.mouseX;
                   downtown_mc.y=downtown_mc.mouseY;
                   downtown_mc.name="downtown_duplicate"+downtown_inc;
                   downtown_inc++;
                   downtown_mc.startDrag(false);
                  downtown_mc.addEventListener(MouseEvent.MOUSE_UP, stdrag);
          if (event.currentTarget.name=="bg_load8") {
                   var powerlines_mc:powerlines_png=new powerlines_png();
                   addChild(powerlines_mc);
                   powerlines_mc.x=powerlines_mc.mouseX;
                   powerlines_mc.y=powerlines_mc.mouseY;
                   powerlines_mc.name="powerlines_duplicate"+powerlines_inc;
                   powerlines_inc++;
                   powerlines_mc.startDrag(false);
                  powerlines_mc.addEventListener(MouseEvent.MOUSE_UP, stdrag);
          if (event.currentTarget.name=="bg_load9") {
                   var tropical_mc:tropical_png=new tropical_png();
                   addChild(tropical_mc);
                   tropical_mc.x=tropical_mc.mouseX;
                   tropical_mc.y=tropical_mc.mouseY;
                   tropical_mc.name="tropical_duplicate"+tropical_inc;
                   tropical_inc++;
                   tropical_mc.startDrag(false);
                  tropical_mc.addEventListener(MouseEvent.MOUSE_UP, stdrag);
          if (event.currentTarget.name=="bg_load10") {
                   var waters_mc:waters_png=new waters_png();
                   addChild(waters_mc);
                   waters_mc.x=waters_mc.mouseX;
                   waters_mc.y=waters_mc.mouseY;
                   waters_mc.name="waters_duplicate"+waterthumb_inc;
                   waterthumb_inc++;
                   waters_mc.startDrag(false);
                  waters_mc.addEventListener(MouseEvent.MOUSE_UP, stdrag);
Please suggest me if any  one.
Regards,
Viji. S

Post AS3 questions in the AS3 forum, not the AS1/2 forum.

Similar Messages

  • Sample Javadoc comments for classes or methods using generics?

    Can anyone show me a sample Javadoc comment for a class or a method that uses generics. All my attempts so far ended up in warnings from the Javadoc tool..
    I also looked in the Sun forums, in the Javadoc documentation, but nowhere could I find anything that would help me write correct javadoc comments.
    Any luck for you guys?
    Thanks a lot,
    -Laurent

    Thanks man, sorry it must seem obvious to you, but
    for some reason I couldn't get it to work.No. The first time I also had to ask.
    Now an even more difficult (for me) question: how
    would you refer to that method in a @see or {@link
    ..} javadoc comment?Manually erase the method:
    * The see tag refers to this method
    * @param <T> a type variable
    * @see #foo(Object)
    <T> void foo(T t) {}

  • How Do I Use Generics with Framework Extension Classes?

    Hi Guys and Gals,
    I've been writing alot of duplicate code lately for ViewObjects that are all basically the same. So it occurred to me that perhaps I could put shared code in a Framework Extension Class. My problem lies in the fact that I do quite a bit of class casting as well. I thought perhaps Generics could come to the rescue. But uh ... I don't really know anything about them, which makes asking the right questions or even researching difficult.
    Here's an example of what I would like to accomplish.
    I have many different Master-Detail ViewObjects which are all pretty much the same. For example ...
    PurchaseOrder (1-*) PoRows
    SalesOrder (1-*) SoRows
    Invoice (1-*) InvoiceRows
    etc...
    Here is sample code for the PurchaseOrder / PoRows
      public void cancelDocument()
        RowIterator ri = this.getPoRowsVO();  // access the detail view object
        RowSetIterator rsi = ((RowSet)ri).createRowSetIterator(null);
        while(rsi.hasNext())
          PoRowsVORowImpl next = (PoRowsVORowImpl)rsi.next();
          next.cancelRow();  // call a detail view object method exposed to the client
        rsi.closeRowSetIterator();
      }However, these two lines are cause for ponderance
         1.  RowIterator ri = this.getPoRowsVO();
         2.  PoRowsVORowImpl next = (PoRowsVORowImpl)rsi.next();Which leads me to two questions:
    1) How do I access the Detail part of the relationship in a framwork extension class generically?
    2) If I have to cast, is there a way to read the class type through reflection and cast using a generic method with what I've found?
    I would think writing common methods in a Framework Extension class would really help make maintaining my code easier, and I could see how it would be a powerful tool. But how would one get around these ViewObject specific problems?
    Will

    Hi,
    you are correct, Generics has a different meaning in Java then what you ask for.
    Actually to access a detail row set from a parent row, you can use code like this:
        public void voRowCancel(){
            for (int i = 0; i < this.getAttributeCount(); i++)
                   if(this.getStructureDef().getAttributeDef(i).getAttributeKind() == AttributeDef.ATTR_ASSOCIATED_ROWITERATOR){
                     RowSet rs = (RowSet) this.getAttribute(i);
                    // ... to do ...
        }However, the code you invoke is on a custom implementation class, which makes it difficult to get to this from here.
    Frank

  • Right way to use generics for cellular automatons?

    Hi,
    i've got a question about using generic types in combination with subclassing (which should be used in a cellular automaton),
    In fact there are only 3 classes that are necessary to understand my problem:
    - Cell (abstract)
    - CellularAutomaton
    - SubclassedCell (extends Cell)
    These classeses work as follows:
    A cellular automaton holds some cell's with respect to the order they were added. The cell itself holds some properties and the most important function in this small "framework". This function is "performCellAction(CellularAutomaton ca)". It retrieves the "neighbor" cells from the given parameter and calculates a new state using these neighbors.
    The way i implemented this using generics is:
    public class CellularAutomaton<T extends Cell>{
      private List<T> cells;
      public T getLeftNeighbor(T cell) { ... } // gets the left neighbor of the given cell
      public T getRightNeighbor(T cell) { ... } // gets the left neighbor of the given cell
    public abstract class Cell [
      public void performCellAction(CellularAutomaton<? extends Cell> ca) {}
    public class SubclassedCell extends Cell {
      private String str;
      public void performCellAction(CellularAutomaton<? extends Cell> ca) {
        Cell left = ca.getLeftNeighbor();
        // PROBLEM:
        // How to call left.getStr() here???
        // How can i be sure that ca contains objects of class subclassedCell (or objects of subclasses of subclassedCell) ... and not objects of class cell or another subclasses cell
      public String getStr() {}
    }In fact i found "something like a solution", which looks like this:
    public class CellularAutomaton<T extends Cell>{
      private List<T> cells;
      public T getLeftNeighbor(T cell) { ... } // gets the left neighbor of the given cell
      public T getRightNeighbor(T cell) { ... } // gets the left neighbor of the given cell
      public void computer() {
        for (T cell: cells) {
          // compiler warning here!!
          cell.performCellAction(this);
    public abstract class Cell<T extends Cell<?>> [
      public void performCellAction(CellularAutomaton<T> ca) {}
    public class SubclassedCell extends Cell<SubclassedCell> {
      private String str;
      performCellAction(CellularAutomaton<SubclassedCell> ca) {
        SubclassedCell left = ca.getLeftNeighbor();
        left.getStr(); // works here
      public String getStr() {}
    }However, even in this "working" solution i get a compiler warning at the method CellularAutomaton->computer():
    The warning is Type safety: The method performCellAction(CellularAutomaton) belongs to the raw type Cell. References to generic type Cell<T> should be parametrized and Cell<T extends Cell<?>> also looks very uncommon to me.
    Is there a betted way to achieve the goal to access left.getStr() in the performCellAction of the subclassed cell??
    Regards,
    Niko

    I thought of that myself, but if i do this, i get the following error:
    The method performCellAction(CellularAutomaton<capture#1-of ?>) in the type Cell<capture#1-of ?> is not applicable for the arguments (CellularAutomaton<T>)

  • How to attach document using Generic Object Service

    Hi all,
    How can i create attachment to the parked invoice using Generic Object services? i want function modules which are used to do it.
    Actually I want to do this from the business object method. I am having word document as one of the workitem step. once i get this document I need to attach this document to the parked invoice so that users can see that document by view object list.
    Its urgent.
    thanks.

    Hello,
    Check your configuration of document type assignement to required business document - object type, Archivelink table, content repository in OAC3 transaction.
    Goto respective business document > Click on GOS > Create > Store business document - Here you can see defined document type with desctiption. Double click on this the assign your document to this business document. Save it.
    This will help in attaching the document to your required business document.
    To verify you can check the archivelink table or by transaction OAAD.
    Hope this will help you.
    -Thanks,
    Ajay

  • Attach Documents using Generic Object Services

    With reference to Manual Bassani's SDN Contribution of code examples on how to attach documents using Generic Object Services - we have found that since implementing ECC 6 the following code no longer works (at the end of page 9):
    CALL CREATE ATTACHMENT SERVICE FROM TOOLBAR
    WHEN 'ATTACH'.
    CALL METHOD MANAGER->START_SERVICE_DIRECT
    EXPORTING
    IP_SERVICE = 'CREATE_ATTA'
    IS_OBJECT = OBJ
    EXCEPTIONS
    NO_OBJECT = 1
    OBJECT_INVALID = 2
    EXECUTION_FAILED = 3
    OTHERS = 4.
    It is necessary to use IP_SERVICE = 'PCATTA_CREA' to get this to function correctly.
    The original document can be found at [https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/0e6b0d95-0a01-0010-4696-ca0a48de5fb3]

    Check the Naimesh Patel Blog he explain very well
    http://help-abap.blogspot.com/2009/02/generic-object-services-gos-toolbar.html

  • How to create a generic method?

    Hi,
      I am using a std task TS01200205 to create instance for a BOR object. There are 2 key fields. I want to pass these 2 to the ObjectKey field.
    As for as I know, we have to concatenate these two Keyfields and assign it to 'Object Key' parameter.
      How can I concatenate the 2 strings in my Workflow? Is there any std way of doing it?
    Also what is a generic method? How to create it? Can I make use of generic method to achieve this?
    Thanks,
    Sivagami

    If you want to use it in different workflows the best solution is probably to define an interface and define and implement the method there (a nice thing about BOR interfaces is that you can provide an implementation and not just the definition).
    All you then need to do is let your object type(s) implement that interface, which only requires adding the interface since the implementation has been done already.
    However, I am not saying this is a good way of approaching things, I'm just telling you how you can implement what you suggest.

  • How to call java method from actionscript

    I've just now started working on Flex. May be its basic question but I’m not aware of it – how can I call a java method from actionscript. I want to call some java method on double click of a event. Can you please let me know how to proceed on this?

    OK. So, I think we can all conclude that you don't need to call any Java method, can't we? And, that wfUpdateMetadata is the command that will update your metadata.
    Now, the question is what are its arguments. It has two - the first is the name of a custom metadata field to be updated (let's suppose that one field is called xMinorVersion, and the other xMajorVersion), the other is the new value, e.g. <$wfUpdateMetaData("xMinorVersion", "New value.")$>As for new value - do you insist on using strings? Since you want to increase the value, it would be more convenient to work with numbers. For instance, with integers you could go with <$wfUpdateMetaData("xMinorVersion", xMinorVersion + 1)$>With strings you will need to convert it to numbers and back to strings. Besides, what happens if you have more than 100 minor versions? (you mentioned you want to add 0.01, but that would finally increase the major version, wouldn't it?) So, I think these two numbers are independent (perhaps, with exception that increase on the major version set the minor version to .00).
    If you want to present it, you can use profiles that will construct for you the representation 2.304 out of MajorVersion = 2, MinorVersion = 304
    Solved?

  • Doubt about generic method

    i have a generic method has shown below
    public static <E extends Number> <E>process(E list){
    List<Interger> output = new ArrayList<Interger>(); or List<Number> output = new ArrayList<Number>();
    return output ;
    if delcare the output variable using Interger or Number . when i am returning the output . it is showing me compiler error and it suggests me to add cast List<E>. Why i not able understand. please clarify my doubt.
    Thanks
    Sura.Maruthi
    Edited by: sura.maruthi on Sep 21, 2008 9:48 PM

    Your method declaration is garbled; there can be only one <...> clause, eg
    public static <E extends Number> E process(E list);This declaration says that for any subclass E of Number, the method process takes a single E instance (called list!?) and returns a single E instance. A valid implementation would be
    return list;I'm guessing you want the parameter to have type List<E>?. Like this:
    public static <E extends Number> E process(List<E> list);This declaration says that for any subclass E of Number, the method process takes a list of E's and returns a single E instance. A valid implementation would be
    return list.get(0);Or perhaps you also want to return a list of numbers?
    public static <E extends Number> List<E> process(List<E> list);This declaration says that for any subclass E of Number, the method process takes a list of E's and returns another list of E's. A valid implementation would be
    return list;Note that you cannot just return a list of Integers or Floats, because your generic method must work for any subclass of Number, and you're promising to return back a list of the same type as the argument passed in.
    Edited by: nygaard on Sep 22, 2008 10:05 AM

  • Getting information about a class using generics...

    Hi there.
    I have declared a class: "public class SomeClass<SC extends SomeClass>{/*Do something*/}".
    Can anyone tell me why a statement like "System.out.println(SC.class.getSimpleName());" within a method defined in SomeClass will not compile? Is there some other way to achieve what I want?

    YoungWinston wrote:
    Owen Thomas wrote:
    Well then, it would be great to be able to key a switch that tells the compiler one isn't working with "legacy code", if this might allow generics to reach a hitherto untapped potential.I don't see how, since not everybody is going to need (or want) such a switch. It also sounds like a recipe for disaster. Should we add such a switch for every enhancement that might have backwards-compatibility problems?Isn't that what the "deprecated" feature is for? Sure, there'll be backwards compatibility issues for a while, but after a few years, with management, things should settle as code is moved from pre to post "super-generics".
    Much of the Java core, and many third-party libraries might have to be re-written in that circumstance... economic stimulus.How could the Java core have been re-written if it requires use of a "not backwards-compatible" flag?i have not reason to believe that code compiled under a super-generics switch need not be backwards-compatible. One may have to simply exercise care in its use.
    I didn't want to bore you with trivia, and I didn't want you to frustrate me with more quips (well-meant though I'm sure they are) about how to write code. ;-)In which case I can only assume that you're using generics for something that probably, more correctly, requires reflection. Have you looked at the relevant parts of Class, as I suggested?No, but as you are impressing on me to have a look, I could do no wrong to have a sniff around. However, with no specific motivation in the current context, I don't think anything will catch my eye. The current need isn't great enough.

  • Generic  method to execue procedure

    Hi I was wondering if there was a way to write a generic method to execute a stored procedure in my EJB. I was thinking of the input parameters as being the data source, procedure name, and an array of parameters. I'm new to java and therefore I didn't know if I should be using a callable statement for prepared statement for this. Also how to get around the problen of knowing my datatype when trying to set parameters for a statement since each parameters expects you to provide a specific set method for data type.
    V

    Whoops sorry about the half broken code.
    javax.naming.InitialContext ctx = new javax.naming.InitialContext();
    javax.sql.DataSource ds =                    (javax.sql.DataSource) ctx.lookup("jdbc/sybase");
    conn = ds.getConnection();
    cstmt =     conn.prepareCall(
              "{call dbo.ModifyExchange (?,?,?,?,?,?,?,?,?,?,?,?)}");
    cstmt.setObject(1, (Object) inputs[0]);
    cstmt.setObject(2, (Object) inputs[1]);               
    cstmt.setObject(3, (Object) inputs[2]);
    cstmt.setObject(4, (Object) inputs[3]);
    cstmt.setObject(5, (Object) inputs[4]);
    cstmt.setObject(6, (Object) inputs[5]);
    cstmt.setObject(7, (Object) inputs[6]);
    cstmt.setObject(8, (Object) inputs[7]);
    cstmt.setObject(9, (Object) inputs[8]);
    cstmt.setObject(10,(Object) inputs[9]);
    cstmt.setObject(11,(Object) inputs[10]);
    cstmt.setObject(12,(Object) inputs[11]);
    System.out.println("ExecuteUpdate Beginning");
    result = cstmt.executeUpdate();
    When I execute it I get "com.sybase.jdbc2.jdbc.SybSQLException: Implicit conversion from datatype 'VARCHAR' to 'TINYINT' is not allowed. Use the CONVERT function to run this query."
    Any ideas?

  • Generic method - UnmarshalException (ClassNotFoundException)

    The mechanism was working fine until I added a generic method to the interface. Now it fails on a call to the new method.
    Here's the relevant code: public interface MyServer extends Remote {
        <T extends pub.beans.Bean> T getBeanAs ( Class<T> clazz, int key )
        throws RemoteException;
    public final class MyServerImpl implements MyServer {
        public synchronized <T extends pub.beans.Bean> T
                     getBeanAs ( final Class<T> clazz, final int key )
        throws RemoteException {
            Object bean = null;
            if( clazz == AbcBean.class )  {
                Abc obj = getObj( key );
                if( obj != null )  {
                    AllBeanTranslator x = new AllBeanTranslator();
                        * Translates an entity bean at the core of obj to external form.
                        * Core Data Object is class AbcDO.
                        * Returned object is class AbcBean.
                    bean = x.translateDO( obj.getData() );
            }  else  {  // ...
            return clazz.cast( bean );
    class Client  {
       public static void main ( final String[] args )
        throws Exception {
            System.setProperty("java.security.policy", "./security.policy" );
            if( System.getSecurityManager() == null ) {
                System.setSecurityManager(new RMISecurityManager());
            MyServer server = (BseServer)Naming.lookup( "MyServer" );
            AbcBean aBean = server.getBeanAs( AbcBean.class, 48 );
    // exception ^^^
    }This throws an exception on a class that the Client should know nothing about: AbcDO. The AbcBean hierarchy never references it. Here's the exception stack: Exception in thread "main" java.rmi.UnmarshalException: error unmarshalling return; nested exception is:
         java.lang.ClassNotFoundException: beans.AbcDO
         at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:178)
         at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:178)
         at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:132)
         at $Proxy0.getBeanAs(Unknown Source)
         at Client.main(Client.java:61)
    Caused by: java.lang.ClassNotFoundException: beans.AbcDO
         at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
         at java.security.AccessController.doPrivileged(Native Method)
         at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
         at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
         at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
         at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
         at java.lang.Class.forName0(Native Method)
         at java.lang.Class.forName(Class.java:247)
         at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:434)
         at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:165)
         at java.rmi.server.RMIClassLoader$2.loadClass(RMIClassLoader.java:620)
         at java.rmi.server.RMIClassLoader.loadClass(RMIClassLoader.java:247)
         at sun.rmi.server.MarshalInputStream.resolveClass(MarshalInputStream.java:197)
         at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1575)
         at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1496)
         at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1732)
         at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
         at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351)
         at java.beans.PropertyChangeSupport.readObject(PropertyChangeSupport.java:478)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:597)
         at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:974)
         at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1849)
         at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1753)
         at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
         at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1947)
         at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1871)
         at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1753)
         at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
         at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1947)
         at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1871)
         at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1753)
         at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
         at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351)
         at sun.rmi.server.UnicastRef.unmarshalValue(UnicastRef.java:306)
         at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:155)
         ... 4 moreAnother thing that puzzles me: Why no stub? When I saw that I turned on Stub Generation (I'm using Genady's RMI Eclipse Plug-in) but that caused a world of problems so I turned it back off.

    Just making them transient isn't the end of the solution, btw,
         * ChangeSupport serializes any serializable listeners.
         * If the listener is serializable but unknown to the codebase
         * causes UnmarshalException so best make these transient.
        protected transient PropertyChangeSupport pcs;
        protected transient VetoableChangeSupport vcs;After de-serialization pcs and vcs are null and of course the listeners are gone. AbcDO class uses events internally so they need to be re-established. Here's what I did, though I can think of at least two other solutions.
      // Normal constructor - not run during de-serialization
      protected AbcDO ( )  { 
          this.pcs = new PropertyChangeSupport( this );
          addPropertyChangeListener( this );
          this.vcs = new VetoableChangeSupport( this );
          addVetoableChangeListener( new AbcValidator() );
          this.SubObj = new SubObj ();
          this.SubObj .addPropertyChangeListener( this );
       * Re-establish transients after de-serialization.
       * Note how much this looks like the ctor.
       * @return this ready to rock again
       * @throws ObjectStreamException
      private Object readResolve ( )  throws ObjectStreamException  {
          this.pcs = new PropertyChangeSupport( this );
          addPropertyChangeListener( this );
          this.vcs = new VetoableChangeSupport( this );
          addVetoableChangeListener( new AbcValidator() );
          if( this.SubObj != null ) // should be impossible - subObj is final
              this.SubObj .addPropertyChangeListener( this );
          return this;
      }     Note that readResolve() may not be appropriate for a non-final class (see Effective Java). Note also that subObj needs its PropertyChangeSupport re-established.

  • Generic method

    Hi all,
    i have a question related to generic method in a non-generic class.
    the following code cannot be compiled. but I don't know why.
    public class G
           void print(Integer i)
              System.out.println("Inte");
         void print(String s)
              System.out.println("String");     
            <T> void callprint(T t)
              print(t);
            public static void main(String args[])
                    G g = new G();
                    g.callprint(new Integer(5));
    }Edited by: 812302 on Nov 16, 2010 6:58 PM
    Edited by: 812302 on Nov 16, 2010 6:59 PM

    Did you bother to read the error message. I'm sure it says something about not finding the print method and nothing to do with Generics. BTW you use square brackets for code tags or before and after your code.                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Generic method signature help

    Hello All,
    I'm confused about the following generic method signature . Compilation fails
    public class Animal{}
    public class Dog extends Animal{}
    public <E super Dog> List<E> methodABC(List<E> list){
    The compiler gives the following error
    E cannot be resolved to a type
    E cannot be resolved to a type
    Syntax error on token "super", , expected
    if i change the declaration of E to <E extends Dog>, no compiler error.
    An early response will be highly appreciated. Thanks in advance.
    Kind Regards.
    Hasnain Javed Khan.

    you cannot use "super" on a type variable, only on wildcards

  • Generic method and wildcards

    Suppose I have this simplified code to do dynamic mapping between specific classes. My question is: the addItem and getItem functions
    are pretty similar however addItem compiles fine and getItem raises compilation error:
    Type mismatch: cannot convert from Class<capture#5-of ? extends List<? extends Object>> to Class<P>
         private Map<Class<? extends Object>,
         Class<? extends List<? extends Object>>> map =
              new HashMap<Class<? extends Object>,
              Class<? extends List<? extends Object>>>();
         public Test() {
              getItem(Object.class);
         public <T extends Object, P extends List<T>> void addItem(Class<T> clz, Class<P> list) {
              map.put(clz, list);
         public <T extends Object, P extends List<T>> Class<P> getItem(Class<T> clz) {
              return map.get(clz);
         }

    Sergey_M. wrote:
    OK, thank you for the response. Then the actual question is how to achieve this functionality:
    1)Store mapping between two referenced classes, for example, Class<? extends MyClass> and Class<? extends List<? extends MyClass>>.
    I mean if we have class MyClass then pair will be (MyClass.class, MyList.class) where MyList implements List<MyClass>.The way you were doing it is fine.
    2)Provide generic method to get second class by supplying the first one.You can do this fine, but the exact type of list will of course be unknown by the calling code (if it knew the type of list it needed, why bother calling getItem in the first place?).
    Just change your method to:
    public <T extends Object> Class<? extends List<?>> getItem(Class<T> clz) {
              return map.get(clz);
         }And by then even the T is not needed, just use:
    public Class<? extends List<?>> getItem(Class<?> clz) {
       return map.get(clz);
    }I am fairly, but not fully sure that you never need <? extends Object>, as that is always just a more verbose way of saying <?>.

Maybe you are looking for