XML和设计模式


国际化(internationalization):i18n简称的由来,第一个字母“i”到最后一个字母“n”之间有18个字母,所以······






package com.lovo.frame;


import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;
import java.util.Properties;


import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.Node;
import org.dom4j.io.SAXReader;


import com.lovo.service.StudentServiceInter;
import com.lovo.service.imp.StudentServiceImp;


public class TestFrame {


/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String className = "";
//利用properties文件做配置
// Properties props = new Properties();
// try {
// props.load(new FileInputStream("test.properties"));
// } catch (FileNotFoundException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// } catch (IOException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// className = props.getProperty("classname");

//利用xml文件做配置
SAXReader reader = new SAXReader();
try {
Document doc = reader.read(new FileInputStream("test.xml"));
//读取文本
// List allNodes = doc.selectNodes("//web/frame/service");
// className = ((Element)(allNodes.get(0))).getText();
// System.out.println(className);

//读取属性
List allNodes = doc.selectNodes("//web/frame/service/@name");
className = ((Attribute)allNodes.get(0)).getValue();
System.out.println(className);
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (DocumentException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}





StudentServiceInter ss;
try {
ss = (StudentServiceInter)Class.forName(className).newInstance();
ss.test();
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}


}


}




package com.lovo.service;


public interface StudentServiceInter {

public void test();

}




package com.lovo.service.imp;


import com.lovo.service.StudentServiceInter;


public class StudentServiceImp implements StudentServiceInter {


public void test() {
// TODO Auto-generated method stub
System.out.println("学生老业务");
}


}




package com.lovo.service.imp;


import com.lovo.service.StudentServiceInter;


public class StudentServiceNewImp implements StudentServiceInter {


public void test() {
// TODO Auto-generated method stub
System.out.println("学生新业务");
}


}






以下是枚举的代码


package com.lovo.test;


public class Season {

public static final String SPRING = "spring";
public static final String SUMMER = "summer";
public static final String AUTUMN = "autumn";
public static final String WINTER = "winter";
}





package com.lovo.test;


public enum SeasonEnum {
spring, summer, autumn,winter
}





package com.lovo.test;


import java.util.Locale;


public class TestMain {


/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
// 国际化i18n
// Locale[] all = Locale.getAvailableLocales();
// for(Locale lo : all){
// System.out.println(lo.getDisplayCountry() + "    " + lo.getCountry() + "   " + lo.getLanguage());
// }

//枚举
SeasonEnum season1 = SeasonEnum.spring;
SeasonEnum season2 = SeasonEnum.autumn;
System.out.println(season1.compareTo(season2));

}


}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值