- Oracle SOAスイートでのSOAアプリケーションの開発
- ビジネス・ルール・サービス・コンポーネントの使用
- 宣言コンポーネントおよびタスク・フローの使用
- Oracle Business Rulesエディタの宣言コンポーネントの概要
- ルール・エディタ・コンポーネントを使用したサンプル・アプリケーションの作成および実行方法
- RuleSetModelオブジェクトの作成方法
RuleSetModelオブジェクトの作成方法
ルール・エディタ・コンポーネントには、oracle.bpel.rulesdc.model.impl.RuleSetModel
オブジェクトが必要です。
RuleSetModelオブジェクトを作成するには:
- Javaクラス(SomeBean.javaなど)をプロジェクトに作成します。
- Oracle JDeveloperを開きます。
- 「ファイル」メニューから、「新規」を選択して「Javaクラス」を作成します。
- SomeBean.javaで、RuleSetModelオブジェクトを返すメソッドを指定します。ルール・ファイルの場所およびパスを指定する必要があります。
SomeBean.java
ファイルの例を次に示します。package view;import java.io.BufferedReader; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.Serializable; import java.net.MalformedURLException; import java.net.URL; import oracle.bpel.rulesdc.model.decisiontable.impl.DecisionTablePrefsImpl; import oracle.bpel.rulesdc.model.decisiontable.interfaces.DecisionTablePrefs; import oracle.bpel.rulesdc.model.impl.IfThenPreferencesImpl; import oracle.bpel.rulesdc.model.impl.RuleSetModel; import oracle.bpel.rulesdc.model.interfaces.IfThenPreferences; import oracle.bpel.rulessharedutils.impl.RulesSharedUtils; import oracle.rules.sdk2.decisionpoint.DecisionPointDictionaryFinder; import oracle.rules.sdk2.dictionary.DictionaryFinder; import oracle.rules.sdk2.dictionary.RuleDictionary; import oracle.rules.sdk2.exception.SDKException; import oracle.rules.sdk2.ruleset.RuleSet; import oracle.rules.sdk2.ruleset.RuleSetTable; public class SomeBean { //on windows private static final String RULES_FILE1 = "file:///D:/scratch/asuraj/system_MAIN/rules_files/ApprovalRules.rules"; /* * on linux private static final String RULES_FILE1 = "file:////scratch/asuraj/backup/rules_files/ApprovalRules.rules"; */ private RuleSetModel ruleSetModel = null; private boolean viewOnly = true; private DecisionTablePrefs dtPrefs; private IfThenPreferences ifThenPrefs; public SomeBean() { super(); } public RuleSetModel getRuleSetModel() { if (ruleSetModel != null) return ruleSetModel; ruleSetModel = new RuleSetModel(getRuleSet()); System.out.println("ruleSetModel = " + ruleSetModel); return ruleSetModel; } public RuleSet getRuleSet() { RuleDictionary dict = openRulesDict(RULES_FILE1, new DecisionPointDictionaryFinder()); if (dict == null) return null; RuleSetTable ruleSetTable = dict.getRuleSetTable(); if (ruleSetTable == null || ruleSetTable.isEmpty()) return null; return ruleSetTable.get(0); } public void saveDictionary() { RuleDictionary dict = null; String rulesFile = null; if (this.ruleSetModel == null) return; dict = this.ruleSetModel.getRuleSet().getDictionary(); if (dict == null) return; if (dict.isModified()) RulesSharedUtils.updateDictionary(dict); if (!dict.isTransactionInProgress()) saveDictionary(dict, RULES_FILE1); } public void validate() { if (this.ruleSetModel == null) return; this.ruleSetModel.validate(); } //utility methods public static RuleDictionary openRulesDict(String fileName, DictionaryFinder finder) { URL url = null; try { url = new URL(fileName); } catch (MalformedURLException e) { System.err.println(e); return null; } RuleDictionary dict = null; try { dict = readFromDisk(url, finder); } catch (Exception e) { System.err.println(e); return null; } return dict; } public static RuleDictionary readFromDisk(URL dictURL, DictionaryFinder finder) { BufferedReader buf = null; try { buf = new BufferedReader(new InputStreamReader(dictURL.openStream(), "UTF-8")); return RuleDictionary.readDictionary(buf, finder); } catch (SDKException e) { System.err.println(e); } catch (IOException e) { System.err.println(e); } finally { if (buf != null) try { buf.close(); } catch (IOException e) { System.err.println(e); } } return null; } public static boolean saveDictionary(RuleDictionary dict, String ruleFileName) { if (dict == null || ruleFileName == null) return false; if (dict.isTransactionInProgress()) System.out.println("Transaction in progress, cannot save dictionary"); try { writeToDisk(dict, new URL(ruleFileName)); } catch (MalformedURLException e) { System.err.println(e); return false; } catch (Exception e) { System.err.println(e); return false; } return true; } public static void writeToDisk(RuleDictionary dic, URL dictURL) { OutputStreamWriter writer = null; try { writer = new OutputStreamWriter(new FileOutputStream(dictURL.getPath()), "UTF-8"); dic.writeDictionary(writer); } catch (IOException e) { System.err.println(e); } catch (SDKException e) { System.err.println(e); } finally { if (writer != null) try { writer.close(); } catch (IOException e) { System.err.println(e); } } } public void toggleMode() { viewOnly = !viewOnly; } public boolean isViewOnly() { return viewOnly; } public DecisionTablePrefs getDtPreferences() { if (dtPrefs == null) dtPrefs = new DTPreferences(); return dtPrefs; } public IfThenPreferences getIfThenPreferences() { if (ifThenPrefs == null) ifThenPrefs = new MyIfThenPrefs(); return ifThenPrefs; } public class MyIfThenPrefs extends IfThenPreferencesImpl implements Serializable { @Override public boolean isGenericAction() { return true; } @Override public boolean isGenericCondition() { return true; } } public class DTPreferences extends DecisionTablePrefsImpl implements Serializable { @Override public boolean isShowDTButtons() { return true; } } }
- adfc-config.xmlのSomeBean.javaを指します(Bean名はsomeBeanで、スコープはsessionです)。adfc-config.xmlの例:
<?xml version="1.0" encoding="UTF-8" ?> <adfc-config xmlns="http://xmlns.oracle.com/adf/controller" version="1.2"> <managed-bean id="__1"> <managed-bean-name>someBean</managed-bean-name> <managed-bean-class>view.SomeBean</managed-bean-class> <managed-bean-scope>session</managed-bean-scope> </managed-bean> </adfc-config>
- ADF/JSFフレームワークによって、SomeBean.javaへのコールが複数回実行され、ユーザー・インタフェースがレンダリングされます。たとえば、someBean.ruleSetModelが複数回コールされます。そのため、毎回再作成するのではなく、ruleSetModelを一度作成したら、それをキャッシュして返すことは、より効率的です。