崇尺(8)
扮寂:2011-01-28 IBM Arron Ferguson
鰯協
恷朔匯倖俶勣冩梢議旗鷹何蛍頁侃尖塰佩扮鰯協。距喘 XUI 斤?議bind 圭隈扮?BindingFactory 議匯倖糞箭繍瓜距喘。
勣繍庁侏旗鷹鰯協欺厮更夛議GUI?BindingFactory 議doBinding 圭隈?需 賠汽 7?駅倬峇佩參和荷恬?
俺資 URL?涙胎壓云仇、Internet 貧賜?斤了崔。
宥狛 JarURLConnection 窃殊臥 JAR 旺聞喘匯倖汽鏡議徭協吶窃紗墮匂紗墮窃。
貫紗墮議XML 猟亀臥孀匯倖窃?万謄塘 Resource 圷殆議class 奉來議兆各。宸倖窃頁庁侏議秘笥泣。
聞喘 Java 郡符崇尺糞箭晒宸倖割輝秘笥泣議窃旺距喘万議init 圭隈。init 圭隈壓古廷貧窃貌噐匯倖灸侏 Java 窃議main 圭隈?咀葎万断脅頁秘笥泣。
泌惚 JAR 猟周**根夕??珊俶勣繍夕?墮秘坪贋。
賠汽 7. BindingFactory 議doBinding 圭隈
public void doBinding(XUINode resource, XUI xui) throws XUIBindingException,
MalformedURLException, IOException {
if(resource.getAttributeValue("type").equals("java")) {
String className = resource.getAttributeValue("class");
String aURLString = resource.getAttributeValue("uri");
URL url = null;
// get the url ... if it''s not a valid URL, then try and grab
// it as a relative URL (i.e. java.io.File). If that fails
// re-throw the exception, it''s toast
try {
url = new URL("jar:" + aURLString + "!/");
} catch (MalformedURLException mue) {
String s = "jar:file://" + new File(aURLString)
.getAbsolutePath().replace("\\", "/") + "!/";
url = new URL(s);
if(url == null) {
// it really was malformed after all
throw new
MalformedURLException("Couldn''t bind to: "
+ aURLString);
}
}
// get a jar connection
JarURLConnection jarConnection = (JarURLConnection)url.openConnection();
// get the jar file
JarFile jarFile = jarConnection.getJarFile();
// jar files have entries. Cycle through the entries until finding
// the class sought after.
Enumeration entries = jarFile.entries();
// the class that will be the entry point into the model
JarEntry modelClassEntry = null;
Class modelClass = null;
XUIClassLoader xuiLoader =
new XUIClassLoader(this.getClass().getClassLoader());
while(entries.hasMoreElements()) {
JarEntry remoteClass = (JarEntry)entries.nextElement();
// load the classes
if(remoteClass.getName().endsWith(".class")) {
// have to get the second last word between period marks. This
// is because the convention allows for:
// org.purnamaproject.xui.XU
|