Writing /home/infogasy/domains/wiki.infogasy.net/public_html/data/cache/3/317a8580fe4c2a089dbf5ff7f9479aa4.xhtml failed

Andao Hiresaka Objet indray faha XVII

Fanorenana lafiny Mpamatsy sy lafiny Mpanjifa (tohiny)

Mbola lafiny Mpamatsy aloha no hofakafakaina mialoha

Averintsika eto indray ary aloha ilay rafitra novaintsika tao amin’ny resaka faha-16 iny, ka hapetraka ao ireo kilasy fototra misahana ilay andraikitra tsirairay avy :

Adi-hevitra :

Raha jerena fotsiny aloha ny sary dia hita fa kilasy roa ihany no tokony hisy fanovana na fanampiana hetsika na toetra ao anatin?ireo kilasy efa vitantsika talohan’ny resaka faha-16. Nohon’ny fisian?ilay kilasy Mpamatsy antsoina hoe ResakaObjetServer.java, vao noforonintsika tamin’ny resaka talohan?ity mantsy dia zavatra tsy maintsy ahitsy ireo fanovana na fanampiana marimarina kokoa.

Tsy iza ireo fa :

Kilasy ZavatraAzoKajiana.java sy SehoLahasoratra.java

Kilasy ZavatraAzoKajiana vaovao:

package resakaObjet;
 
import java.util.*;
import resakaObjet.TahirySoratraASCII;
 
public class ZavatraAzoKajiana
{
   private Object sanda;
   private TahirySoratraASCII tahiry;
 
   public ZavatraAzoKajiana()
   {
     sanda = new Object();
     tahiry = new TahirySoratraASCII(".","tahiry.dat","");
   }
 
   public ZavatraAzoKajiana(Object sandaHafa)
   {
     sanda = sandaHafa;
   }
 
   public Object getSanda()
   {
     return sanda;
   }
 
   public void setSanda(Object sandaHafa)
   {
     sanda = sandaHafa;
   }
 
   public TahirySoratraASCII getTahiry()
   {
     return tahiry;
   }
 
   public void setTahiryZavatra(Object zavatra)
   {
     setSanda(zavatra);
     tahiry.manoratraTahiry(zavatra);
   }
 
   public Object getTahiryZavatra()
   {
     setSanda(tahiry.mamakyTahiry());
     return getSanda();
   }
 
/** Hetsika ilaina ho solon'ny taloha mampita amin'ny andalan-tohatra
  * fitehirizana maharitra raha antso lavitra amin'ny XML-RPC misy eto
  * no hampiasaina
  *@param soratra - ampidirina anaty Vector ireo lahasoratra any amin'ny lafiny Mpanjifa
  * (mbola ho hazavaina aoriana ny amin'izany !)
  * @return isa manamarika fa nahomby ilay hetsika
  */
    public int setRPCTahiryZavatra(String soratra)
    {
        try
        {
           setTahiryZavatra(soratra);
           return 1;
        }
        catch(Exception e)
        {
           return 0;
        }
    }
 
  /** Hetsika ilaina ho solon'ny taloha mampita amin'ny andalan-tohatra
  * fitehirizana maharitra raha antso lavitra amin'ny XML-RPC misy eto
  * no hampiasaina
  * @return karazana Vector mitahiry ireo lahasoratra nalaina tanaty fitehirizana
  */
    public String getRPCTahiryZavatra()
    {
        try
        {
            return ((StringBuffer)getTahiryZavatra()).toString();
        }
        catch(Exception e)
        {
            return new String();
        }
    }
  
   public Object kajyAdisanina(double sandaHafa) throws ResakaObjetException
   {
     if(getSanda().getClass() != Double.class) throw new ResakaObjetException(getSanda());
     Double d = (Double)getSanda();
     return new Double(d.doubleValue()+sandaHafa) ;
   }
  
   public Object kajyAdisanina(String sandaHafa) throws ResakaObjetException
   {
     if(getSanda().getClass() != String.class) throw new ResakaObjetException(getSanda());
     String s = (String)getSanda();
     return s.concat(sandaHafa);
   }
  
   public String toString()
   {
     return sanda.toString();
   }
  
   static public void main(String arg[]) {
     ZavatraAzoKajiana test = new ZavatraAzoKajiana();
  
     test.setRPCTahiryZavatra(new Integer(9999*12).toString());
     test.getRPCTahiryZavatra();
     System.out.println(test.getSanda());
   }
 
}

Fanazavana:

Ataontsika soratra matavy ny zavatra nampiana tao amin’io kilasy io.

public int setRPCTahiryZavatra(String soratra)
    {
        try
        {
           setTahiryZavatra(soratra);
           return 1;
        }
        catch(Exception e)
        {
           return 0;
        }
    }

Zavatra roa no tsy maintsy ovaina @ fanoratana io hetsika vaovao fandefasana zavatra any amin’ny Tahiry maharitra io, mba hifanaraka amin’ny vavonin’ny parser XML miasa ao anaty fonosana org.apache.xmlrpc :

  • Ny argument faritana mazava fa String
  • Ny vokatra miverina ovaina ho karazana tranainy (type primitif); isa tsy mivaky izy eto na entier.
/** Hetsika ilaina ho solon'ny taloha mampita amin'ny andalan-tohatra
  * fitehirizana maharitra raha antso lavitra amin'ny XML-RPC misy eto
  * no hampiasaina
  * @return karazana Vector mitahiry ireo lahasoratra nalaina tanaty fitehirizana
  */
        public String getRPCTahiryZavatra()
        {
            try
            {
                return ((StringBuffer)getTahiryZavatra()).toString();
            }
            catch(Exception e)
            {
               return new String();
            }
        }

Ity hetsika vaovao ity indray izay tsy mila argument dia natao kosa hamerina vokatra karazana soratra na String, mamaky avy any @ andalan-tohatara Tahiry maharitra ireo lahasoratra voatahiry.

amin’ireo hetsika roa ireo dia marihina tsara fa hita ao anatin?ireo ihany izany ny hetsika roa nahazatra taloha dia tsy iza fa: setTahiryZavatra(Object) sy Object getTahiryZavatra(). Saingy ilay karazana Object moa mbola tsy fantatry ny parser XML ?ntsika mivantana, ka noho izany tsy maintsy isika mamadika azy ho String mba tsy hisy ny olana fandefasana na fandraisana argument sy vokatra.

N.B: Efa misy tarikevitra fototra azo hikarohana ny vaha-olana amin’io, omen’ny API JSE nanomboka ny version 1.4, ao anatin?ireo fonosana mikasika ny XML. Tsy dia mbola ilaintsika eto aloha ny misava izay lalana izay !!!?

Hitodika amin’ny lafiny Mpanjifa amin’izay ary isika, amin’ny alalan’ny fijerena izay tokony hampiana ao amin’ny andalan-tohatra Fanehoana izany.

Kilasy SehoLahasoratra.java :

package resakaObjet;
 
import java.util.*;
import java.awt.*;
import java.awt.event.* ;
import javax.swing.*;
import resakaObjet.ZavatraAzoKajiana;
import java.net.*;
import org.apache.xmlrpc.*; // fonosana fitrandrahana  XML-RPC
 
public class SehoLahasoratra extends Frame
{
   static private String anaranaMpamatsy = "localhost";
   static private int hirikaRPC = 4440;
   private InetAddress adiresyMpamatsy;
   private XmlRpcClient xmlrpc;
   Vector params, result;
   String str;
   Integer entier;
 
   Label lohateny1, lohateny2;
   Button bokotra1, bokotra2, bokotra3;
   TextArea tahirySoratra;
   TextArea lahasoratra;
 
   private ZavatraAzoKajiana zavatra;
 
 
   public SehoLahasoratra() throws Exception
   {
       super("Fanoratana lahasoratra");
 
       adiresyMpamatsy = InetAddress.getByName(anaranaMpamatsy);
       xmlrpc = new XmlRpcClient(anaranaMpamatsy,hirikaRPC);
       System.out.println("Hote : "+adiresyMpamatsy+" : "+ hirikaRPC);
       params = new Vector(); result = new Vector();
       str = ""; entier = new Integer(0);
 
       lohateny1 = new Label("Lahasoratra taloha :");
       tahirySoratra = new TextArea(20,100);
       lohateny2 = new Label("Lahasoratra vaovao :");
       lahasoratra = new TextArea(20,100);
       bokotra1 = new Button("Alefaso");
       bokotra2 = new Button("Fafao");
       bokotra3 = new Button("Vakio");
 
       zavatra = new ZavatraAzoKajiana();
 
       setLayout(new lahasoratraLayout());
 
       add(lohateny1);       add(bokotra3); add(tahirySoratra);
       add(lohateny2); add(lahasoratra);
       add(bokotra1); add(bokotra2);
 
       pack();
       addWindowListener(this.new RindraToerana());
   }
 
   public TextArea getTahirySoratra()
   {
       return tahirySoratra;
   }
 
   public TextArea getLahasoratra()
   {
       return lahasoratra;
   }
 
   public ZavatraAzoKajiana getZavatra()
   {
       return zavatra;
   }
 
   public void setHainoTranga()
   {
       bokotra1.addActionListener(this.new RindraTranga());
       bokotra1.setActionCommand("1");
       bokotra2.addActionListener(this.new RindraTranga());
       bokotra2.setActionCommand("2");
       bokotra3.addActionListener(this.new RindraTranga());
       bokotra3.setActionCommand("3");
   }
 
   public void actionAlefaso()
   {
       try
       {
           params.clear();
           str = (String)xmlrpc.execute("lahasoratra.getRPCTahiryZavatra",params);
 
           zavatra.setSanda(str);
           zavatra.setSanda(zavatra.kajyAdisanina("\n================\n"));
           zavatra.setSanda(zavatra.kajyAdisanina(lahasoratra.getText()));
 
           params.clear();
           params.add((String)zavatra.getSanda());
           entier = (Integer)xmlrpc.execute("lahasoratra.setRPCTahiryZavatra",params);
       }
       catch (Exception ex)
       {
       }
       String s = (String)zavatra.getSanda();
       tahirySoratra.setText(s);
       int pos = s.length();
       tahirySoratra.setCaretPosition(pos);
       lahasoratra.setText("");
   }
 
   public void actionVakio()
   {
       try
       {
           params.clear();
           str = (String)xmlrpc.execute("lahasoratra.getRPCTahiryZavatra",params);
       }
       catch (Exception e)
       {
       }
       tahirySoratra.setText(str);
       int pos = str.length();
       tahirySoratra.setCaretPosition(pos);
   }
 
   private class RindraTranga implements ActionListener
   {
       public void actionPerformed(ActionEvent e)
       {
          String action = e.getActionCommand();
          int choix = Integer.parseInt(action);
          switch(choix)
          {
              case 1:
                 actionAlefaso();
                 break;
              case 2:
                 getLahasoratra().setText("");
                 break;
              case 3:
                 actionVakio();
                 break;
          }
       }
   }
 
   private class lahasoratraLayout implements LayoutManager
   {
       ??????????
   }
 
   private class RindraToerana extends WindowAdapter {
       public void windowClosing(WindowEvent ev)
       {
          System.exit(0);
       }
   }
 
   static public void main(String arg[]) throws Exception
   {
       SehoLahasoratra test = new SehoLahasoratra();
       test.setHainoTranga();
       test.getTahirySoratra().setEditable(false);
       test.setVisible(true);
   }
}

Fanazavana:

Mbola ataontsika soratra matavy ihany ireo novaina rehetra tanaty kilasy SehoLahasoratra.

Nefa alohan’ny hirosoana @ ny fanazavana dia tsara tadidiana fa ity kilasy ity izany dia miparitaka @ ny milina rehetra te-hifandray @ ny milina misy ny kilasy ZavatraAzoKajiana sy TahirySoratraASCII izay ao an-damosin’ny kilasy Mpamatsy ResakObjetServer.

Ilay fifandraisana moa dia mazava ho azy fa ny tambazotra tranonkala no tsotra indrindra.

Noho izany ary ny zavatra tsy maintsy takiana amin’ny milina rehetra te-hampiasa azy ity dia izao:

  • Misy ny JRE (Java Runtime Environnement) tafapetraka amin’ilay milina, mba ahafahana manana ny JVM mampihodina ireo kilasy rehetra ilain’ny rafitra fanehoana ao anatin’ny kilasy SehoLahasoratra.
  • Manana fifandraisana lavitra amin’ilay milina itoeran?ireo vainga ResakaObjetServer-ZavatraAzoKajiana-TahirySOratraASCII. Mety ho anaty tambazotra voafaritra akaiky (reseau local) na midadasika (reseau etendu) no zotra ifandraisana amin’izany.

Raha jerena amin’izay ary izay nampiana tanatin?ity kilasy SehoLahasoratra efa hitantsika taloha ity dia izao no azo ambara:

        static private String anaranaMpamatsy = "localhost";
        static private int hirikaRPC = 4440;
        private InetAddress adiresyMpamatsy;
        private XmlRpcClient xmlrpc;
        Vector params, result;
        String str;
        Integer entier;

Famaritana ireo toetra rehetra ilaina mba ahafahana mifandray @ ny milina itoeran’ny Mpamatsy.

  • Ny anaran’ny tondro ny milina anaranaMpamatsy anaty tambazotra moa eto dia ?localhost? : izany hoe ny milina iasako ity ihany izany no misy ireo vainga Mpamatsy ireo;
  • Ny hirikaRPC sy adiresyMpamatsy moa dia ireo antsoina hoe Adresse TCP/IP sy nomerao port (ilaina foana rehefa miasa anaty tambazotra)
  • Ny xmlrpc dia ilay Objet karazana XmlRpcClient ahafahana mifandray @ ny Objet karazana WebServer (mpamatsyXmlRpc no nataontsika anarany tary @ ny resaka faha-16 tary).
  • Ireo toetra karazana Vector, String, sy Integer moa dia tahiry mandalo ilaina @ ny kirakira rehetra hataontsika anatin?ity kilasy SehoLahasoratra ity

Ny zavatra hafa niova ankoatra izay moa dia ireo soratra ao anaty hetsika actionAlefaso() sy actionVakio(), izay misy endrika itoviazany ny fampiasana azy:
1. Fandefasana ireo argument(raha misy)
2. Fiantsoana ny hetsika mila ireo argument ireo
3. Fandraisana ny vokatra miverina (raha misy).

Anaty actionAlefaso() :

      params.clear(); // Diovina ny fitoerana mandalo n?ireo arguments
      // miantso ny hetsika getRPCTahiryZavatra (tsy mila argument io) ary mandray
      // anaty fitoerana antsoina hoe str karazana  String ny vokatra (ny lahasoratra)
      str = (String)xmlrpc.execute("lahasoratra.getRPCTahiryZavatra",params);
      // ampidirina anaty toetra zavatra karazana ZavatraAzoKajiana
      zavatra.setSanda(str);
      
      
      params.clear();// Diovina ny fitoerana mandalo n?ireo arguments
      // ampidirina anaty Vector ny argument (lahasoratra vaovao)
      params.add((String)zavatra.getSanda());
      // miantso ny hetsika setRPCTahiryZavatra (mila argument karazana String); ny
      // vokatra miverina karazana Integer dia hamantarana ny fahombiazan'ny fiantsoana
      // ilay hetsika. Ny ataon?ilay hetsika moa dia mandefa anaty Tahiry maharitra ilay
      // lahasoratra vaovao.
      entier = (Integer)xmlrpc.execute("lahasoratra.setRPCTahiryZavatra",params);

Anaty actionVakio() :

      params.clear();
      str = (String)xmlrpc.execute("lahasoratra.getRPCTahiryZavatra",params);

Ity moa dia mitovy tsy misy valaka @ ny andinina voalohany tao @ ny hetsika actionAlefaso() ihany; izany hoe mamaky tanaty Tahiry maharitra ireo lahasoratra efa voatahiry

N.B:
Ny zava-dehibe tsara fantatra ary rehefa manoratra vainga hifandray amin’ny mpamatsy isika ao anaty praograma mpanjifa dia tsy maintsy alefa anaty Vector izany ireo argument ireo. Ny Vector mantsy no antsoina hoe: conteneur d?objets, ary ny tena mahatsara azy dia afaka mitahiry zavatra karazana Object izy (izany hoe ; ny zava-drehetra e !). Ka mila mitandrina ihany izany ny amin’ireo argument satria raha ohatra tsy blem @ ny Vector ny mandray argument karazana maro dia blem be ho an’ny vavonin’ny parser XML ny argument izay tsy voafaritra ao anaty specification XML-RPC Data eken’ny maro.


(De @ manaraka indray kalongany ary e ! ?)

 

andaohiresakaobjetfahaxvii.txt · Novaina farany:: 2008/09/11 12:43