IRelatedMetadataDetailsの実装を渡すサンプル・コード
コンシューマは、oracle.integration.console.metadata.model.share.IRelatedMetadataDetailsの実装を渡す必要があります。
IRelatedMetadataDetailsの実装には、リポジトリからリソース・バンドルをロードするためのコードおよびユーザーがルール・アプリケーションに対する変更をコミットするときにバンドル・ファイルを保存するためのコードが含まれます。
コンシューマは、dictionaryName + "Translations_" + locale.toString() + ".xml"規則を使用して、リソース・バンドル・ファイルの名前を構築する必要があります。
public class MyRelatedMetadataDetails implements IRelatedMetadataDetails {
private static final Locale[] LOCALES = { Locale.US, Locale.FRENCH };
private static final String RESOURCE_PATH =
"file:///C:/scratch/sumit/system/rules/";
private static final String RESOURCE_BASE = "SimpleRule";
public MyRelatedMetadataDetails() {
super();
}
public String getDocument(IRelatedMetadataPath relatedPath) {
String resourceSuffix = relatedPath.getValue();
try {
return loadResource(resourceSuffix);
} catch (IOException e) {
return "";
}
}
private static String loadResource(String resourceSuffix) throws IOException {
FileInputStream fis = null;
FileChannel fc = null;
try {
URL url = new URL(RESOURCE_PATH + RESOURCE_BASE + resourceSuffix);
fis = new FileInputStream(url.getFile());
fc = fis.getChannel();
ByteBuffer bb = ByteBuffer.allocate((int)fc.size());
fc.read(bb);
bb.rewind();
return Charset.defaultCharset().decode(bb).toString();
} finally {
if (fis != null) {
fis.close();
}
if (fc != null) {
fc.close();
}
}
}
public void createDocument(IRelatedMetadataPath relatedPath,
String document) {
try {
storeResource(relatedPath.getValue(), document);
} catch (IOException e) {
e.printStackTrace();
}
}
public void saveDocument(IRelatedMetadataPath path, String document) {
try {
storeResource(path.getValue(), document);
} catch (IOException e) {
e.printStackTrace();
}
}
private static void storeResource(String resourceSuffix,
String document) throws IOException {
FileOutputStream fos = null;
FileChannel fc = null;
try {
URL url = new URL(RESOURCE_PATH + RESOURCE_BASE + resourceSuffix);
fos = new FileOutputStream(url.getFile());
fc = fos.getChannel();
ByteBuffer bb = ByteBuffer.allocateDirect(1024);
bb.clear();
bb.put(Charset.defaultCharset().encode(document));
bb.flip();
while (bb.hasRemaining()) {
fc.write(bb);
}
} finally {
if (fos != null) {
fos.close();
}
if (fc != null) {
fc.close();
}
}
}
public IRelatedMetadataPathFinderFactory getFinderFactory() {
return new RelatedMetadataPathFinderFactory();
}
public List<IRelatedMetadataPath> getExisting(IRelatedMetadataPathFinder finder) {
List<IRelatedMetadataPath> paths = new ArrayList<IRelatedMetadataPath>();
for (Locale locale : LOCALES) {
paths.add(RelatedResourceMetadataPath.buildFromLocale(locale));
}
return paths;
}
public class RelatedMetadataPathFinderFactory implements IRelated`MetadataPathFinderFactory {
public IRelatedMetadataPathFinder getResourceFinder() {
return new RelatedMetadataPathFinder();
}
}
public class RelatedMetadataPathFinder implements IRelatedMetadataPathFinder {
public String getType() {
return null;
}
public IRelatedMetadataPath matches(oracle.integration.console.metadata.model.share.MetadataPath srcPath,
oracle.integration.console.metadata.model.share.MetadataPath matchPath) {
return null;
}
}
}