2011年8月21日 星期日

Tuscany 2.0 beta3 建立多個 Node 在同一個 SCA Domain 的呼叫方式

The code snippet :

import org.apache.tuscany.sca.node.NodeFactory;
import org.apache.tuscany.sca.node.configuration.NodeConfiguration;
import org.apache.tuscany.sca.node.configuration.impl.NodeConfigurationImpl;

String ContributionPath;
org.apache.tuscany.sca.node.Node nodeInstance = null;
NodeConfiguration nodeCof = new NodeConfigurationImpl();
nodeCof.addContribution( ContributionName , ContributionPath );

NodeFactory.getInstance().setAutoDestroy(false);
nodeInstance = NodeFactory.getInstance().createNode( nodeCof );

nodeInstance.start();

Reference site :

http://mail-archives.apache.org/mod_mbox/tuscany-commits/201104.mbox/%3C20110427102304.31D60238890A@eris.apache.org%3E

How to handle SCA the error Business Interface in not compatible on OSGi

當我打包整個 Tuscany Runtime 成 OSGi bundle 並且安裝到 glassfish 上面時

其他 OSGi bundle 使用 Tuscany Runtime bundle 時偶而會發出

Business interface is XXX not compatible

這是 bundle 在 MANIFEST.MF 中 Import-Package 不完全所至

所以最快的解決辦法 就是把 Tuscany Runtime Bundle 所 Export-Package 全部變成
該 SCA-OSGi bundle 的 Import-Package 就可以解決這個問題

啟動 Glassfish OSGI Telnet 服務

啟動 Glassfish 的 OSGI telent 服務

修改

$GLASSFISH/osgi/felix/conf/config.properties

optionals.bundles = ....
$(com.sun.aas.installRootURI}modules/org.apache.felix.shell.jar \
$(com.sun.aas.installRootURI}modules/org.apache.felix.shell.remote.jar \

telnet localhost 6666

就可以進入 remote console 管理 bundles

2011年5月3日 星期二

確認 android Resource layout 內的 view 是否存在

Android 的 project 編譯的時候會產生對應的 R.java ,
layout.xml 中的 view 物件會產生對應的 id ,
所以可以裡用 Activity.getViewById 取得對應的 View 物件

但是如何確認 R.id 內 有沒有要的 view 呢??

利用 Java Reflection 機制可以達到這個功能
首先讓我們先回憶一下 id 如何產生
下面 宣告一個 Button 在 layout.xml 當中,


放到 eclipse 編譯後會產生對應的 R.java
幸運的是 變數名稱等於 上述 分配的 id 名稱
只要 id 名稱不變 就可以確認該 View 是否存在於 layout.xml 當中
因此搭配下列的程式碼

Class cls = R.id.class;
Field field = null;
int value = 0;

try {
field = cls.getField("button_testSSL");
if ( field == null ) {
return ;
}
} catch ( Exception e ) {
e.printStackTrace();
}
try {
value = field.getInt(null);
} catch ( Exception e ) {
e.printStackTrace();
}

field 等於 null 表示該物件不存在, 如果存在就利用 field.getInt 取得該 View id

之後利用 getViewById(value) 就可以取得該物件了

這樣一來就不用每次換UI都要註解掉一些不用的函數, 可以省去很多功夫