Tuesday 20 March 2012

Tools to convert .Class files to .Java files

Converting .Class files to .Java file is very important step in OAFramework Extensions. Below are the most used tools to perform this.


Tool : JAD  
             
    Download Link for JAD
  
Command to Convert all class files to java files under all subdirectories with Original Folder Structure
jad -o -r -sjava -dsrc c:/jadnt158/Samp/**/*.class

Command to delete all class files in subdirectories
Del /s *.class –


Tool: FrontEnd                


    Download Link for FrontEnd


Tool: Cavaj

                    

    Download Link for CAVAJ

Important Profile Options realted to OA Framework

Personalize Self-Service Defn / FND_CUSTOM_OA_DEFINTION

This is intended for system administrators who wish to personalize regions at the localization, site, verticalization, org and responsibility levels. On enabling this profile option for the administrator, every OA Framework page will contain a global Personalize button. By clicking on this global button, the administrator can personalize the regions available on that page.

Disable Self-service Personal / FND_DISABLE_OA_CUSTOMIZATIONS

This is a system profile option specifically created for use by Oracle Support. You can set this profile option to "Yes" or "No" at the site or application level. If this system profile option is set to Yes, any personalizations made by the customer, regardless of the level at which the personalizations were made, will not be applied. All pages using OA Framework will now display the regions based on their original definitions.
Note: When this profile is set to "Yes", a warning message that all personalizations are disabled is displayed on every page to which a user navigates.

FND: Personalization Region Link Enabled / FND_PERSONALIZATION_REGION_LINK_ENABLED

Enables the "Personalize Region" links on a page if the Personalize Self-Service Defn / FND_CUSTOM_OA_DEFINTION profile is set to Yes.

Fnd Xliff Export Root Path / FND_XLIFF_EXPORT_ROOT_PATH

Use this profile option to set the root path used to generate the full path where the Xliff files are exported to when users extract their translated personalizations using the Extract Translation Files page in OA Personalization Framework. The permissions for the root path directory that you specify must be set to read, write, create for all users, using chmod 777 [dir_path].

Xliff Import Root Path / FND_XLIFF_IMPORT_ROOT_PATH

Use this profile option to set the root path used to derive the full path from where the Xliff files are uploaded when users use the Upload Translations page in OA Personalization Framework to upload translated personalizations.

FND: Personalization Document Root Path / FND_PERZ_DOC_ROOT_PATH

Use this profile option to define the root path where personalizations documents are exported to or imported from when users use the Database page or the File System page of the Functional Administrator responsibility's Document Manager, respectively.

Recommended this profile set to the $APPL_TOP staging area:
              $APP_TOP/<CompanyIdentifier>/
             <CustomProductShortName>/
            <product-version>/mds/webui
of the current deployed environment, where personalization documents are to be imported from or exported to. This profile option should be set at the Site level.

FND: Diagnostics / FND_DIAGNOSTICS

Setting this to “Yes” causes a Diagnostics global button to render on every page. Select this button to view the log messages for the page. Enabling this profile also automatically renders the "About this page" link at the bottom of every OA Framework page.

Useful Scripts in OA Framework

Upload a Single PG.xml file

From Command Prompt

·         <JDEV_DIR>\jdevbin\jdev\bin\import <JDEV_DIR>\jdevbin\jdev\myclasses\xxt\oracle\apps\pon\registration\webui\XXTSupplierRegistrationPG.xml -username apps -password apps -dbconnection "(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=<DB_HOST_NAME>)(PORT=<DB_PORT>))(CONNECT_DATA=(SID=<DB_SID>)))" -rootDir <JDEV_DIR>\jdevbin\jdev\myclasses\ -rootPackage /

From Unix Box

·         java oracle.jrad.tools.xml.importer.XMLImporter CarLoanViewOnlyPG.xml  -username <user name> -password <password> -dbconnection "(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=<hostname>)(PORT=<port number>))(CONNECT_DATA=(SID=<SID>)))" -rootdir ./ -rootPackage /xxmhp/oracle/apps/per/carloan/webui


Upload multiple PG.xml files

·         <JDEV_DIR>/jdevbin/jdev/bin/import <JDEV_DIR>/jdevbin/jdev/myclasses /oracle/apps/xxpo/pdt/ordering/webui -rootDir <JDEV_DIR>/jdevbin/jdev/myclasses / -username apps -password <APPS_PASSWORD> -dbconnection "(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=<DB_HOSTNAME>)(PORT=<DB_PORT>))(CONNECT_DATA=(SID=<DB_SID>)))" -includeSubpackages -jdk13 -mmddir <JDEV_DIR>/jdevbin/jdev/lib/ext/jrad/config/mmd -rootPackage /

When you have the Substitutions upload the JPX using the following script from the UNIX prompt

From Unix Box

·         java oracle.jrad.tools.xml.importer.JPXImporter XXMHPIprocChargeAccountDesc.jpx -username <Database User Id> -password <Password> -dbconnection "(description=(address_list=(address=(protocol=tcp)(host=<Host Name>)(port=<Port Number>)))(connect_data =(sid=<SID>)))"


Download Components From Server (Important For Standard Pages Downloading)
From Command Prompt

·         export /custom/oracle/apps/apc/webui/dseInvoiceReviewRn -rootdir U:\viji\Jdeveloepr9i\jdevhome\jdev\myprojects -username apps -password applsys97 -dbconnection "(description = (address_list = (address = (community = tcp.world)(protocol = tcp)(host =d00725)(port = 1525)))(connect_data = (sid = DEVF)))"
From Unix Box

·         java oracle.jrad.tools.xml.exporter.XMLExporter /oracle/apps/rrs/site/user/webui/CreateMethodforSiteTempPG -rootdir $JAVA_TOP/chola -username apps -password apps -dbconnection "(description = (address_list = (address = (community = tcp.world)(protocol = tcp)(host = ) (port = )))(connect_data = (sid = )))"

View  Documents
Begin
Jdr_utils.printDocument(‘/oracle/apps/pon/award/completion/webui/ponCompleteAward2PG’);
End;

To find the personalized file path for a particular PG.xml
begin
jdr_utils.listCustomizations('/oracle/apps/fnd/framework/navigate/webui/AppsNavigateMobilePG');
end;

To download the personalized file, first run the above script in SQL, that will display the full path for the personalized file, then run the below command
Begin
Jdr_utils.printDocument (‘/oracle/apps/fnd/framework/navigate/webui/customizations/site/0/AppsNavigateMobilePG’);
End;
DELETE A DOCUMENT OR DELETE A PERSONALIZATION OR     DELETE AN EXTENSION OR A SUBSTITUTION
The title says it all. Once you have found the exact name of the document with its full path [using jdr_utils.listdocuments], you can then delete the same by using command below.

For example to delete the Application Module substitution, use command
DECLARE
BEGIN
jdr_utils.deletedocument(p_document => '/oracle/apps/per/irc/candidateSelfService/server/customizations/site/0/VisitorAM');
END;

To create translations for the personalized page or for a custom page, download the corresponding xlf file for the personalized page or the custom page. Then change the prompts in the destination language and import the page again.

Extract XLF file for a particular directory (For arabic language, for a different language, change accordingly).

·         <JDEV_DIR>\jdevbin\jdev\bin\xliffextract /xxt/oracle/apps/pon/registration/webui -includeSubpackages -mmd_dir D:\Jdev1150CU2\jdevbin\jdev\lib\ext\jrad\config\mmd -root D:\Temp\XLIF\registration -xliff_dir D:\Temp\XLIF\registration -source db -username apps -password <APPS_PASSWORD> -dbconnection "(DESCRIPTION= (ADDRESS=(PROTOCOL=tcp)(HOST=<DB_HOSTNAME>)(PORT=<DB_PORT>))(CONNECT_DATA=(SID=<DB_SID>)))" -languages ar-AE

Extract XLF file for a particular file(For arabic language, for a different language, change accordingly).

·         <JDEV_DIR>\jdevbin\jdev\bin\xliffextract /oracle/apps/pon/outcome/creation/webui/customizations/site/0/ponCreatePOPG -root D:\temp -xliff_dir D:\temp -mmd_dir <JDEV_HOME>\jdevbin\jdev\lib\ext\jrad\config\mmd\ -source db -username apps -password <APPS_PASSWORD> -dbconnection " (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL= TCP)(HOST = <DB_HOSTNAME>)(PORT = <DB_PORT>)) ) (CONNECT_DATA = (SERVICE_NAME = <DB_SID>) ) )" -languages ar-AE

To find the personalization for a particular object or for the whole system or for a particular package.

Login with the user who has Functional Administrator responsibility, you search the Object you have substituted (Functional Administrator=>Personalization=>Import/Export).
Search with a particular path, Eg. /oracle/apps/icx will give all the personalization under the path.
If the the profile option “FND: Personalization Document Root Path” set properly, the personalization can be exported to the system directly.

Monday 19 March 2012

Java Stored Procedures and Load Java Utility

Step 1: DEVELOP JAVA CLASS, WITH MEMBER METHOD(S)

public class Hello
{
   public static String world ()
   {
      return "Hello world";
    }
}     
  
Then compile the source using:
javac Hello.java
NOTE:
1.      It is not necessary to compile the java source file in this step since the utility loadjava (refer STEP 2) does this for us.
2.      Methods with VOID return type get mapped to Procedures, where as methods with NON – VOID return type get mapped to functions when these are published using the call specifications (STEP 3)

Step 2: LOAD THE JAVA SOURCE/CLASS INTO THE ORACLE DATABASE

loadjava –u user_name/password@oracleSID -r –v hello_word.java

C:\oracle9i\bin> loadjava -u scott/tiger@dbsmgi Hello.java

Step 3: WRITE THE CALL SPECS TO PUBLISH THE JAVA CLASSES

SQL> CREATE OR REPLACE FUNCTION proc_get_msg RETURN VARCHAR2
 AS LANGUAGE JAVA
 NAME 'Hello.world() return java.lang.String';
  /
Function created.

Step 4:  CALLING THE JAVA STORED PROCEDURES

SQL> set serveroutput on;
SQL> call dbms_java.set_output(50);

Define the variable to get the message returned by function
SQL> VARIABLE var_MSG VARCHAR2(20);

Call the Function (get the return value into the variable)
SQL> CALL proc_get_msg() INTO :var_MSG;

Print the result
SQL> print var_MSG;

VAR_MSG
---------------------
Hello world

Where are the class files stored ?

SQL> desc all_objects;

Name                       Type                   Nullable                         Default Comments                                                                     
-------------- ------------ -------- ------- ----------------------------------------------------------------------------
OWNER                    VARCHAR2(30)            Username of the owner of the object                                          
OBJECT_NAME          VARCHAR2(30)                Name of the object                                                          
SUBOBJECT_NAME    VARCHAR2(30)       Y       Name of the sub-object (for example, partition
OBJECT_ID              NUMBER                        Object number of the object                                                 
DATA_OBJECT_ID      NUMBER                         Y       Object number of the segment which contains the object                      
OBJECT_TYPE            VARCHAR2(19)      Y       Type of the object                                                          
CREATED                 DATE                             Timestamp for the creation of the object                                    
LAST_DDL_TIME       DATE                             Timestamp for the last DDL change (including GRANT and 
                                                                                                                         REVOKE) to the object
TIMESTAMP           VARCHAR2(19)       Y       Timestamp for the specification of the object                               
STATUS                  VARCHAR2(7)         Y       Status of the object                                                        
TEMPORARY      VARCHAR2(1)                Y       Can the current session only see data that it placed in this                   
                                                                     object itself? 
GENERATED      VARCHAR2(1)                Y       Was the name of this object system generated?                               
SECONDARY      VARCHAR2(1)                Y       Is this a secondary object created as part of icreate for domain
                                                                     indexes?   

SQL>select * from all_objects where object_name like 'Hello%';

OWNER  OBJECT_NAME    SUBOBJECT_NAME   OBJECT_ID  DATA_OBJECT_ID OBJECT_TYPE  CREATED   LAST_DDL_TIME TIMESTAMP  STATUS  TEMPORARY GENERATED SECONDARY
------------------------------ ------------------------------ ------------------------------ --------- -------------- ------------------- ----------- ------------- ------------------- ------- --------- --------- ---------
APPS    Hello                                                  736206                JAVA CLASS          6/6/2007 5: 6/14/2007 12: 2007-06-06:05:40:45 VALID   N         N         N


SQL> desc user_java_classes

Name          Type           Nullable Default Comments                                                                   
------------- -------------- -------- ------- --------------------------------------------------------------------------
NAME          VARCHAR2(4000) Y                name of the java class                                                     
MAJOR         NUMBER         Y                the major version number of the java class as defined in JVM specification
MINOR         NUMBER         Y                the minor version number of the java class as defined in JVM specification
KIND          VARCHAR2(9)    Y                is the stored object a java class or java interface?                      
ACCESSIBILITY VARCHAR2(6)    Y                the accessiblity of the java class                                        
IS_INNER      VARCHAR2(3)    Y                is this java class an inner class                                         
IS_ABSTRACT   VARCHAR2(3)    Y                is this an abstract class?                                                
IS_FINAL      VARCHAR2(3)    Y                is this an final class?                                                   
IS_DEBUG      VARCHAR2(3)    Y                does this class contain debug information?                                
SOURCE        VARCHAR2(4000) Y                source designation of the java class                                      
SUPER         VARCHAR2(4000) Y                super class of this java class                                            
OUTER         VARCHAR2(4000) Y                outer class of this java class if this java class is an inner class       


SQL> Select * From user_java_classes where NAME like 'Hello%';

Hello     45  3 INTERFACE PUBLIC NO  NO  NO  NO Hello.java java/lang/Object
-

1 row selected.

Using the main Method

The main method can take a variable number of arguments which are typically passed on the command line to the Java VM.

Example:

public class  DemoMain {
  public static void main(String args[])  {
   for(int i=0; i< args.length; i++)
        System.out.println("args[" + i + "]:" + args[i]);
     }
}

Now we have to load it in the database using :

loadjava -user scott/tiger@dbsmgi -verbose -resolve DemoMain.java

Create a wrapper for the method. Assming that it takes either one or two arguments

CREATE OR REPLACE PACKAGE DemoMain AS
          Procedure  Main(p1 IN VARCHAR2) IS
          Language Java
          Name 'DemoMain.main(java.lang.String[])';
         
          Procedure  Main(p1 IN VARCHAR2, p2 IN VARCHAR2) IS
          Language Java
          Name 'DemoMain.main(java.lang.String[])';
END DemoMain;
SQL>  CALL DemoMain.Main(‘One’, ‘Two’);

Using the IN OUT or OUT parameters

If a parameter is IN OUT or OUT, then it needs to be passed by reference rather than by value. To achieve this, the Java parameter should be passed as an array.

Example:
import oracle.sql.*;
import java.sql.*;
class JavaModes
{
          public static void numP(int p1, int[] p2, int[] p3) {
          p3[0] = p2[0] * 2; -- Assign p3= p2 * 2
          p2[0] = p2[0] + p1; -- Assign p2=p2 + p1
          }
         
          public static void charP(String p1, String[] p2, String[] p3) {
          p2[0] += p1; -- Concatenate p1 on end of p2
          p3[0] = "Hello, I am a Java String";
          }
         
          public static void dateP(DATE p1, DATE[] p2, DATE[] p3) throws SQLException{
          p2[0] = p2[0].addMonths(6); -- Add 6 months to p2
          p3[0] = p1.addMonths(-6); -- Set p3 to p1 -6 months
          }
}

The corresponding PL/SQL wrapper is

CREATE OR REPLACE Package JavaModes AS
      Procedure NumP(p1 IN Number, p2 IN OUT Number, p3 OUT Number) IS
      Language Java
      Name 'JavaModes.numP(int, int[], int[])';
         
      Procedure CharP(p1 IN VARCHAR2, p2 IN OUT VARCHAR2, p3 OUT VARCHAR2) IS
      Language Java
      Name 'JavaModes.charP(java.lang.String, java.lang.String[], java.lang.String[])';
         
      Procedure DateP(p1 IN DATE, p2 IN OUT DATE, p3 OUT DATE) IS
      Language Java
      Name 'JavaModes.dateP(oracle.sql.DATE, oracle.sql.DATE[], oracle.sql.DATE[])';
END JavaModes;

Generate XML Data for generic SQL Query

Using below query I've develope a package, which gives XML data if you input you query and tags.

SELECT xmlelement("BusinessGroup1",xmlagg(XMLELEMENT("BusinessGroup2", XMLELEMENT("name", e.full_name),XMLELEMENT ( "Number", e.employee_number)))).getclobval()
FROM per_all_people_f e where trunc(sysdate) between effective_start_date and effective_end_date and rownum <10

Package:

Specification:
create or replace PACKAGE CPAY_GENERATE_XML_FILE
AS

FUNCTION GENERATE_XML_QUERY(
    p_tag       IN VARCHAR2,
    p_query     IN VARCHAR2,
    p_condition IN VARCHAR2)
  RETURN CLOB;

FUNCTION tokens(
    chr_string IN VARCHAR2,
    token      IN VARCHAR2)
  RETURN NUMBER;

FUNCTION tokenize(
    chr_string IN VARCHAR2,
    token      IN VARCHAR2,
    pos        IN NUMBER)
  RETURN VARCHAR2;

END CPAY_GENERATE_XML_FILE;

Package Body:

create or replace
PACKAGE BODY CPAY_GENERATE_XML_FILE
AS
FUNCTION GENERATE_XML_QUERY(
    p_tag       IN VARCHAR2,
    p_query     IN VARCHAR2,
    p_condition IN VARCHAR2)
  RETURN CLOB
AS
  no_tokens        INT;
  no_inside_tokens NUMBER;
  i                INT;
  v_string         VARCHAR2(150);
  v_column         VARCHAR2(150);
  v_tag            VARCHAR2(150);
  v_xml_query      VARCHAR2(4000) := 'SELECT xmlagg(XMLELEMENT("'||p_tag||'"';
  no_tags          NUMBER         :=0;
  v_braces         VARCHAR2(55)   := NULL;
  j                INT;
type r_cursor
IS
  REF
  CURSOR;
    v_xml_cursor r_cursor;
    v_count NUMBER :=0;
    v_xml CLOB;
  BEGIN
    no_tags       := TOKENS( CHR_STRING => p_tag, TOKEN => ' ' );
    IF (no_tags   <> 0) THEN
      v_xml_query := 'select';
      FOR j       IN 1..no_tags
      LOOP
        v_xml_query := v_xml_query||' xmlelement ("'||trim(tokenize(p_tag,' ',j))||'",';
        v_braces    := v_braces || ')';
      END LOOP;
      v_xml_query := v_xml_query||' xmlagg(XMLELEMENT("'||trim(SUBSTR(p_tag,instr(p_tag,' ',-1,1)+1,LENGTH(p_tag)))||'"';
      dbms_output.put_line ('v_xml_query: '||v_xml_query);
    END IF;
    no_tokens := TOKENS( CHR_STRING => p_query, TOKEN => ',' );
    dbms_output.put_line('no_of_tokens:'||no_tokens);
    FOR i IN 1..no_tokens
    LOOP
      v_string :=trim(tokenize(p_query,',',i));
      DBMS_OUTPUT.PUT_LINE('v_string = ' ||v_string);
      v_column := SUBSTR(v_string,0,(instr(v_string,' ',1,1)));
      v_tag    := SUBSTR(v_string,(instr(v_string,' ',1,1)));
      DBMS_OUTPUT.PUT_LINE('v_column = ' ||v_column);
      DBMS_OUTPUT.PUT_LINE('v_tag = ' ||v_tag);
      IF (v_string  IS NOT NULL) THEN
        v_xml_query := v_xml_query|| ', XMLELEMENT('||v_tag||', '||v_column||')';
      END IF;
      v_string := NULL;
      v_column :=NULL;
      v_tag    := NULL;
    END LOOP;
    v_string := trim(SUBSTR(p_query,instr(p_query,',',-1,1)+1,LENGTH(p_query)));
    DBMS_OUTPUT.PUT_LINE('v_string = ' ||v_string);
    v_column := SUBSTR(v_string,0,(instr(v_string,' ',1,1)));
    v_tag    := SUBSTR(v_string,(instr(v_string,' ',1,1)));
    DBMS_OUTPUT.PUT_LINE('v_column = ' ||v_column);
    DBMS_OUTPUT.PUT_LINE('v_tag = ' ||v_tag);
    IF (no_tags   <> 0) THEN
      v_xml_query := v_xml_query|| ', XMLELEMENT('||v_tag||', '||v_column||')))'||v_braces||'.getclobval() '||p_condition;
    ELSE
      v_xml_query := v_xml_query|| ', XMLELEMENT('||v_tag||', '||v_column||'))).getclobval() '||p_condition;
    END IF;
    IF (p_query   IS NULL) THEN
      v_xml_query := 'SELECT xmlagg(XMLELEMENT("'||p_tag||'")) from dual';
    END IF;
    IF (v_xml_query IS NOT NULL) THEN
      EXECUTE immediate (v_xml_query) INTO v_xml;
      RETURN v_xml;
    END IF;
  EXCEPTION
  WHEN OTHERS THEN
    RETURN NULL;
    dbms_output.put_line(sqlerrm);
  END GENERATE_XML_QUERY;
FUNCTION tokenize(
    chr_string IN VARCHAR2,
    token      IN VARCHAR2,
    pos        IN NUMBER)
  RETURN VARCHAR2
AS
  v_out   VARCHAR2(100);
  chk_pos NUMBER:=1;
BEGIN
  WHILE instr(chr_string,token,1,chk_pos) > 0
  LOOP
    chk_pos := chk_pos + 1;
  END LOOP;
  IF pos <= chk_pos-1 AND pos > 0 THEN
    --chk_pos := chk_pos - 1;
    IF pos   = 1 THEN
      v_out := SUBSTR(chr_string,instr(chr_string,token,0,1)+1,(instr(chr_string,token,1,1) - instr(chr_string,token,0,1))-1);
    ELSE
      v_out := SUBSTR(chr_string,instr(chr_string,token,1,pos-1)+1,(instr(chr_string,token,1,pos) - instr(chr_string,token,1,pos-1))-1);
    END IF;
  ELSE
    v_out := SUBSTR(chr_string,instr(chr_string,token,-1,1)+1,LENGTH(chr_string));
    --v_out := to_char(length(chr_string));
  END IF;
  IF pos   > chk_pos+1 OR pos <= 0 THEN
    v_out := NULL;
  END IF;
  RETURN v_out;
END tokenize;
FUNCTION tokens(
    chr_string IN VARCHAR2,
    token      IN VARCHAR2)
  RETURN NUMBER
AS
  v_out   VARCHAR2(100);
  chk_pos NUMBER :=1;
  tkn     NUMBER := 0;
BEGIN
  WHILE instr(chr_string,token,1,chk_pos) > 0
  LOOP
    chk_pos := chk_pos + 1;
    tkn     := tkn     + 1 ;
  END LOOP;
  RETURN tkn;
END TOKENS;
END CPAY_GENERATE_XML_FILE;

Example of Procedure call to generate XML:

DECLARE
  P_TAG VARCHAR2(2000);
  P_QUERY VARCHAR2(4000);
  P_CONDITION VARCHAR2(200);
  v_Return clob;
BEGIN
v_Return := '<ORGUSER>';
   P_TAG := 'ORGID';
  P_QUERY := 'ORGANIZATION_ID "organizationid", name "orgname"';
  P_CONDITION := 'from hr_all_organization_units where rownum=1';

  v_Return := v_Return||CPAY_GENERATE_XML_FILE.GENERATE_XML_QUERY(
    P_TAG => P_TAG,
    P_QUERY => P_QUERY,
    P_CONDITION => P_CONDITION
  );
  P_TAG := 'USER1 USER2';
  P_QUERY := 'user_name "uname", user_id "uid"';
  P_CONDITION := 'from fnd_user where rownum<=10';

  v_Return := v_Return||CPAY_GENERATE_XML_FILE.GENERATE_XML_QUERY(
    P_TAG => P_TAG,
    P_QUERY => P_QUERY,
    P_CONDITION => P_CONDITION
  );
 

  v_Return := v_Return||'</ORGUSER>';
  DBMS_OUTPUT.PUT_LINE('v_Return = ' || v_Return);
END;