map two data structure

From: f (ffunus_at_yahoo.com)
Date: 11/28/03

  • Next message: pepegan: "Re: Problem with RMI in Linux"
    Date: 27 Nov 2003 21:01:11 -0800
    
    

    Suppose I have

    class Data1{
        public String name;
        public String address;

        public String getName(){
                   return name;
        }
        
        public void setName(String name){
                this.name = name;
        }
                
        public String getAddress(){
                return address;
            }

            public void setAddress(String address){
                this.address = address;
            }
    }

    class Data2{
        public String alis;
        public String port;

        public String getAlis(){
                   return alis;
        }
        
        public void setAlis(String alis){
                this.alis = alis;
        }
                
        public String getPort(){
                return port;
            }

            public void setPort(String port){
                this.port = port;
            }
    }

    class Data3{
        public String str1;
        public String str1;

        public String getStr1(){
                   return str1;
        }
        
        public void setStr1(String str1){
                this.str1 = str1;
        }
                
        public String getStr2(){
                   return str2;
        }
        
        public void setStr2(String str2){
                this.str2 = str2;
        }
    }

    Data1 data1;
    Data2 data2;
    Data3 data3;

    I want to set the attributes in Data3 by the attributes from Data1
    or/and Data2. Thus, sometimes I want to do this:

    data3.str1 = data2.alis;
    data3.str2 = data1.name;

    Sometimes I want to do this:

    data3.str1 = data1.address;
    data3.str2 = data1.name;

    Sometimes I want to do this:

    data3.str1 = data2.alis;
    data3.str2 = data2.port;
    ...

    There is a lot of possible transformations, but at run time, there is
    only one used. If I specifiy the mapping in some way, for example, a
    xml

    <mapping>
       <str1 source="data1" attribue="name">
       <str2 source="data2" attribue="alis">
    </mapping>

    My program will read this xml at runtime and do the appropriate
    transformation.
    Thus, my code will be short. If there a way to do this?
    I know I can do it with reflection, how is the perfermance? Any other
    ways?

    Thanks,

    qq


  • Next message: pepegan: "Re: Problem with RMI in Linux"

    Relevant Pages

    • Re: Files in an ASP.Net page
      ... public class Variables //Internal class for XML Serializing of class members ... public void set_Binding ... public String get_DataBaseName ... public int get_DeletedA ...
      (microsoft.public.dotnet.vjsharp)
    • Re: XML serialization of an Hashtable 2
      ... the same code doing a google search - ... > public string familyname; ... > public void AddNew() ...
      (microsoft.public.dotnet.languages.csharp)
    • Prblems accessing a bean from JSP
      ... values into the database to start wtih. ... public void initthrows ServletException { ... public void doGet(HttpServletRequest request, HttpServletResponse ... public String getUsername() { ...
      (comp.lang.java.programmer)
    • Re: XML serialization of an Hashtable 2
      ... >> public string familyname; ... public void AddNew() ... >>> public class Event ... There was an error reflecting type ...
      (microsoft.public.dotnet.languages.csharp)
    • Public Variable Problem
      ... public class mjlDisplayPanel extends JPanel { ... public void paintComponent{ ... public String getLines(){ ... public class myJLogo implements ActionListener { ...
      (comp.lang.java.programmer)