F Interfaces Implemented By Rules Dictionary Editor Task Flow

This appendix describes the Oracle Business Rules Dictionary Editor Task Flow, which implements the MetadataDetails and NLSPrefrences interfaces when creating an ADF-based Web application. The interfaces are defined in the soaComposerTemplates.jar file.

This appendix includes the following sections:

F.1 The MetadataDetails Interface

The MetadataDetails interface is a part of the oracle.integration.console.metadata.model.share package and is defined in the soaComposerTemplates.jar file.

The MetadataDetails interface defines three methods, as shown below:

public interface MetadataDetails {
    /**
     * Retrieve the details of the metadata document
     * @return document in string format.
     */
    String getDocument();

    /**
     * Get related document.
     */
    String getRelatedDocument(final RelatedMetadataPath relatedPath);

    /**
     * Update the metadata document.
     * @param doc represents the updated document.
     */
    void setDocument(String doc) throws Exception;
}

F.1.1 The getDocument Method

This method is used to retrieve the rules file in a string format. For doing this action, you must connect to the Oracle Metadata Repository (MDS) or a file system, and return the rules file in a string format.

The code sample below shows how to get the file from a local file system:

private static final String RULES_FILE1 =
"file:///C:/scratch/<username>/system/mywork/linkedD/AutoAppProj/oracle/rules/credit/CreditRatingRules.rules";

   public String getDocument() {
        URL url = null;
        try {
            url = new URL(RULES_FILE1);
            return readFile(url);
        } catch (IOException e) {
            System.err.println(e);
        }
        return "";
    }

    private String readFile(URL dictURL) {
        InputStream is;
        try {
            is = dictURL.openStream();
        } catch (IOException e) {
            System.err.println(e);
            return "";
        }
        BufferedReader reader;
        try {
            reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
        } catch (UnsupportedEncodingException e) {
            System.err.println(e);
            return "";
        }
        String line = null;
        StringBuilder stringBuilder = new StringBuilder();
        String ls = System.getProperty("line.separator");
        try {
            while ((line = reader.readLine()) != null) {
                stringBuilder.append(line);
                stringBuilder.append(ls);
            }
        } catch (IOException e) {
            System.err.println(e);
            return "";
        } finally {
            try {
                reader.close();
            } catch (IOException e) {
                System.err.println(e);
            }
        }
        return stringBuilder.toString();
    }

F.1.2 The getRelatedDocument Method

This method is required when you work with linked dictionaries. You must connect to MDS, find the related dictionary file, and then return it in a string format. The code sample below shows how to find the path of the linked dictionaries that are stored within the ../oracle/rules directory in a local file system:

public String getRelatedDocument(RelatedMetadataPath relatedMetadataPath) {
        String currPath = RULES_FILE1.substring(0, RULES_FILE1.indexOf("oracle/rules"));
        String relatedDoc = currPath + "oracle/rules/" + relatedMetadataPath.getValue();
       
        URL url = null;
        try {
            url = new URL(relatedDoc);
            return readFile(url);
        } catch (IOException e) {
            System.err.println(e);
        }
        return "";
    }

F.1.3 The setDocument Method

This method is used to store the rules file. It returns a String doc value, which is the name of the updated dictionary based on user edits performed by using Rules Dictionary Editor Task Flow. You must store the rules file in MDS or a file system. The code sample below shows how to save the document in the local file system:

public void setDocument(String string) {
        URL url = null;

        try {
            url = new URL(RULES_FILE1);
        } catch (MalformedURLException e) {
            System.err.println(e);
            return;
        }
        Writer writer = null;
        try {
            //os = new FileWriter(url.getPath());
            writer =
                    new OutputStreamWriter(new FileOutputStream(url.getPath()),
                    "UTF-8");
        } catch (FileNotFoundException e) {
            System.err.println(e);
            return;
        } catch (IOException e) {
            System.err.println(e);
            return;
        }
        try {
            writer.write(string);
        } catch (IOException e) {
            System.err.println(e);
        } finally {
            if (writer != null) {
                try {
                    writer.close();
                } catch (IOException ioe) {
                    System.err.println(ioe);
                }
            }
        }
    }

F.2 The NLSPreferences Interface

The NLSPrefrences interface defines four methods as shown below:

public interface NLSPreferences
{
   /**
    * Returns the locale to be used.
    **/
    Locale getLocale();
 
    /**
     * Return the timezone to be used.
     **/
    TimeZone getTimeZone();
 
    /**
     * Return the dateformat to be used.
     */
    String getDateFormat();
 
    /**
     * Return the time format to be used.
     */
    String getTimeFormat();
 
    /**
     * Returns the grouping seperator.
     */
    char getGroupingSeparator();
 
    /**
     * Returns the grouping seperator.
     */
   char getDecimalSeparator();
}

The code sample below shows a sample implementation of the NLSPreferences interface:

public class MyNLSPreferences implements NLSPreferences {
        private static final String DATE_STYLE = "yyyy-MM-dd";
        private static final String TIME_STYLE = "HH-mm-ss";
        private static final char G_SEP = ',';
        private static final char D_SEP = '.';
 
        public Locale getLocale() {
            return Locale.FRENCH;
        }
 
        public TimeZone getTimeZone() {
            return TimeZone.getTimeZone("America/Los_Angeles");
        }
 
        public String getDateFormat() {
            return DATE_STYLE;
        }
 
        public String getTimeFormat() {
            return TIME_STYLE;
        }
        
        public char getGroupingSeparator() {
            return G_SEP;
        }
 
        public char getDecimalSeparator() {
            return D_SEP;
        }
    }