Código Java dentro de Oracle Forms 6i

Preciso escrever um código Java dentro de um Oracle form 6i.

Procedimento: tem uma procedure que irá gerar um arquivo, e a classe Java terá
que fazer download do arquivo (Já tenho um exemplo pronto de uma Servlet), eu preciso
embutir dentro do Forms.

Os forms estão rodando no IAS.

agradeço desde já.

Mario

Acho a maneira mais fácil fazer em isso em Forms mesmo, usando o pacote dmbs_output e similares.

A Oracle dá suporte pra 6i ainda?

O arquivo que estou gerando está sendo gravado no Servidor, e eu preciso gravar na máquina do cliente que está rodando a aplicação.

Como eu posso fazer isto em Forms ?

Muito Obrigado.

Mario

[quote=boaglio]
Acho a maneira mais fácil fazer em isso em Forms mesmo, usando o pacote dmbs_output e similares.

A Oracle dá suporte pra 6i ainda? [/quote]

Vá lá no help do forms e procure por Text_IO, package responsável por tratar de arquivos.

Pesquisando meus arquivos aqui achei o texto abaixo. Veja se ajuda.

PURPOSE

To Upload the data from a local client file to a TextItem or To
Save the contents of a TextItem to a local client file.

SCOPE & APPLICATION

The code mentioned would work only with Forms 6i patch 5 and above,
due to Bug:1543274

The TEXT_IO package available with Forms would not help in this case,
since the TEXT_IO would act on the server files.
The solution mentioned here involves creating and using a Pluggable
Java Component (PJC). This PJC class would be used as an
Implementation class for the Text Item in Forms, by doing this we are
customizing the implementation of the Text Item.

a. Create the following file under $ORACLE_HOME\forms60\java


import oracle.forms.ui.*;
import oracle.forms.properties.ID;
import oracle.ewt.lwAWT.lwText.*;
import java.awt.*;
import java.io.*;

public class TextPJC extends VTextArea {
private static final ID READFILE   = ID.registerProperty("readfile");
private static final ID WRITEFILE   = ID.registerProperty("writefile");
private String filename=null;

  public TextPJC() {
    super();
  }

  public boolean setProperty(ID pid, Object value)
  {
    if(pid ==READFILE) {
       try {
             File inputFile = new File((String)value);
             FileReader in = new FileReader(inputFile);
             char c[] = new char[(int)inputFile.length()];
             char c1[]= new char[(int)inputFile.length()];
             in.read(c);
             int j=0;
             for (int i=0;i<inputFile.length();i++)
             {
             if((int)c[i]==13);
             else
             c1[j++]=c[i];
             }
             String str = String.copyValueOf(c1,0,j);
             this.setContent(new LWTextArea(str));
             in.close();
           }
       catch(Exception e) {System.out.println("Error in PJC " );e.printStackTrace();}
       return true;
       }
     else if(pid==WRITEFILE) {
       try {
             File inputFile = new File((String)value);
             FileWriter in = new FileWriter(inputFile);
             LWTextArea lw = (LWTextArea)(this.getContent());
             String text1 = lw.getText();
             int length1 = text1.length();
              char c[] = new char[(int)length1];
              char c1[]= new char[(int)length1*2];
              text1.getChars(0,length1,c,0);
              int j=0;
              String s1= System.getProperty("line.separator");
              for(int i=0;i<length1;i++)
              {
              if ((int)c[i]==10)
              {
                 s1.getChars(0,s1.length(),c1,j);
                  j=j+s1.length();
              }
              else
              c1[j++]=c[i];
              }
             in.write(c1,0,j);
             in.flush();
             in.close();
                     }
             catch(Exception e) {System.out.println("Error " );e.printStackTrace();}
             return true;
                             }
      else
      return super.setProperty(pid,value);
  }

 }

b. Compile the above program

Ensure the environment variable CLASSPATH contains
$ORACLE_HOME\forms60\java.
c:>cd $ORACLE_HOME\forms60\java
e:\orant\forms60\java> javac TextPJC.java

c. Package the class file into a jar file

e:\orant\forms60\java> jar cvf TextPJC.jar TextPJC.class
The jar file needs to be signed, to provide the class file access to
the local filesystem.Check out the links mentioned below for more
information on signing a jar file
http://java.sun.com/security/signExample/
http://java.sun.com/security/usingJavakey.html
After signing the jar file you would have the certificate file
(Assume TextPJC.x509) which needs to be imported into the identity
database of the client system

d. Include the above signed jar file in the html file, by including
the jar file in the ARCHIVE tag of the applet

e. Setup the client to use the jar file
The certificate needs to be imported into the client’s system & needs
to be trusted. This needs to be done using the javakey executable. The
above mentioned links would provide more information about it.

f. In the Form, Set the implementation class of the TextItem whose
data needs to be uploaded/saved from/to a file as “TextPJC”. Make sure
the Jar file created is in the CLASSPATH, before invoking the forms
builder.
For reading a file content into the textitem use
set_custom_property(‘TEXT_ITEM’,1,‘readfile’,‘filename’);
Where TEXT_ITEM is the name of the Text Item and ‘filename’ is the
name of the file to be read.
For writing the contents of the textitem to a file use
set_custom_property(‘TEXT_ITEM’,1,‘writefile’, ‘filename’);

Note :

  • You could create a Bean to display a FileDialog to select the file.

  • If you receive Security Exception even after trusting the jar file.

    cd $JINITIATOR_HOME\lib\security ( JINITIATOR_HOME is home directory for
    Jinitiator used. eg the default directory for Jinitiator v1.1.7.18 would be
    c:\program files\oracle\Jinitiator1.1.7.18)
    Take a backup of the java.security file
    Edit the java.security file and have only one entry for the identity.database
    pointing to c:\identitydb.obj

Ou ainda vc tem a opção de criar uma JSP (Java Stored Procedure) dentro do banco Oracle e realizar a chamada a partir do forms !
Acho bem interessante esta saída e mais otimizada !

[quote=leandroeschiavi]Ou ainda vc tem a opção de criar uma JSP (Java Stored Procedure) dentro do banco Oracle e realizar a chamada a partir do forms !
Acho bem interessante esta saída e mais otimizada ![/quote]

Mais interessante sem dúvida, mas mais otimizada pouco provável.

Qualquer coisa em Java dentro do Oracle é muito mais lento do que
PL/SQL. As rotinas do text_io são chamadas do PL/SQL, mas chamam
rotinas nativas em C, o que sem dúvida é bem rápido.