|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
你说是sun公司对她研究的透还是微软?针对自己工具开发的.net性能上肯定会站上风的。//文件:PropertyManager.java
//这个类实在没甚么用了,能够往失落,但必要往失落后面几个类中对这个类的援用。
packagecom.qingtuo.db.pool;
importjava.util.*;
importjava.io.*;
/**
*ManagespropertiesfortheentireJivesystem.Propertiesaremerely
*piecesofinformationthatneedtobesavedinbetweenserverrestarts.
*<p>
*Atthemoment,propertiesarestoredinaJavaPropertiesfile.Inaversion
*ofJivecomingsoon,thepropertiesfileformatwillmovetoXML.XML
*propertieswillallowhierarchicalpropertystructureswhichmaymeanthe
*APIofthisclasswillhavetochange.
*<p>
*JivepropertiesareonlymeanttobesetandretreviedbycoreJiveclasses.
*Therefore,skinwritersshouldprobablyignorethisclass.
*<p>
*Thisclassisimplementedasasingletonsincemanyclassloadersseemto
*takeissuewithdoingclasspathresourceloadingfromastaticcontext.
*/
publicclassPropertyManager{
privatestaticPropertyManagermanager=null;
privatestaticObjectmanagerLock=newObject();
privatestaticStringpropsName="/pcc_2000.properties";
/**
*ReturnsaJiveproperty
*
*@paramnamethenameofthepropertytoreturn.
*@returnsthepropertyvaluespecifiedbyname.
*/
publicstaticStringgetProperty(Stringname){
if(manager==null){
synchronized(managerLock){
if(manager==null){
Stringsysname=System.getProperty("os.name").toUpperCase();
if(sysname.indexOf("WIN")!=-1){
propsName=propsName2000;
}
else{
propsName=propsNameLinux;
}
manager=newPropertyManager(propsName);
}
}
}
returnmanager.getProp(name);
}
/**
*SetsaJiveproperty.
*
*@paramnamethenameofthepropertybeingset.
*@paramvaluethevalueofthepropertybeingset.
*/
publicstaticvoidsetProperty(Stringname,Stringvalue){
if(manager==null){
synchronized(managerLock){
if(manager==null){
manager=newPropertyManager(propsName);
}
}
}
manager.setProp(name,value);
}
/**
*Returnstrueifthepropertiesarereadable.Thismethodismainly
*valuableatsetuptimetoensurethatthepropertiesfileissetup
*correctly.
*/
publicstaticbooleanpropertyFileIsReadable(){
if(manager==null){
synchronized(managerLock){
if(manager==null){
manager=newPropertyManager(propsName);
}
}
}
returnmanager.propFileIsReadable();
}
/**
*Returnstrueifthepropertiesarewritable.Thismethodismainly
*valuableatsetuptimetoensurethatthepropertiesfileissetup
*correctly.
*/
publicstaticbooleanpropertyFileIsWritable(){
if(manager==null){
synchronized(managerLock){
if(manager==null){
manager=newPropertyManager(propsName);
}
}
}
returnmanager.propFileIsWritable();
}
/**
*Returnstrueifthejive.propertiesfileexistswherethepathproperty
*purportsthatitdoes.
*/
publicstaticbooleanpropertyFileExists(){
if(manager==null){
synchronized(managerLock){
if(manager==null){
manager=newPropertyManager(propsName);
}
}
}
returnmanager.propFileExists();
}
privatePropertiesproperties=null;
privateObjectpropertiesLock=newObject();
privateStringresourceURI;
/**
*Singletonaccessonly.
*/
privatePropertyManager(StringresourceURI){
this.resourceURI=resourceURI;
}
/**
*GetsaJiveproperty.Jivepropertiesarestoredinjive.properties.
*Thepropertiesfileshouldbeaccesiblefromtheclasspath.Additionally,
*itshouldhaveapathfieldthatgivesthefullpathtowherethe
*fileislocated.Gettingpropertiesisafastoperation.
*/
publicStringgetProp(Stringname){
//Ifpropertiesarentloadedyet.Wealsoneedtomakethisthread
//safe,sosynchronize...
if(properties==null){
synchronized(propertiesLock){
//Needanadditionalcheck
if(properties==null){
loadProps();
}
}
}
returnproperties.getProperty(name);
}
/**
*SetsaJiveproperty.Becausethepropertiesmustbesavedtodisk
*everytimeapropertyisset,propertysettingisrelativelyslow.
*/
publicvoidsetProp(Stringname,Stringvalue){
//Onlyonethreadshouldbewritingtothefilesystematonce.
synchronized(propertiesLock){
//Createthepropertiesobjectifnecessary.
if(properties==null){
loadProps();
}
properties.setProperty(name,value);
//Now,savethepropertiestodisk.Inorderforthistowork,theuser
//needstohavesetthepathfieldinthepropertiesfile.Trim
//theStringtomakesuretherearenoextraspaces.
Stringpath=properties.getProperty("path").trim();
OutputStreamout=null;
try{
out=newFileOutputStream(path);
properties.store(out,"jive.properties--"+(newjava.util.Date()));
}
catch(Exceptionioe){
System.err.println("Therewasanerrorwritingjive.propertiesto"+path+"."+
"EnsurethatthepathexistsandthattheJiveprocesshaspermission"+
"towritetoit--"+ioe);
ioe.printStackTrace();
}
finally{
try{
out.close();
}catch(Exceptione){}
}
}
}
/**
*LoadsJivepropertiesfromthedisk.
*/
privatevoidloadProps(){
properties=newProperties();
InputStreamin=null;
try{
in=getClass().getResourceAsStream(resourceURI);
properties.load(in);
}
catch(IOExceptionioe){
System.err.println("ErrorreadingPccproperties"+ioe);
ioe.printStackTrace();
}
finally{
try{
in.close();
}catch(Exceptione){}
}
}
/**
*Returnstrueifthepropertiesarereadable.Thismethodismainly
*valuableatsetuptimetoensurethatthepropertiesfileissetup
*correctly.
*/
publicbooleanpropFileIsReadable(){
try{
InputStreamin=getClass().getResourceAsStream(resourceURI);
returntrue;
}
catch(Exceptione){
returnfalse;
}
}
/**
*Returnstrueifthejive.propertiesfileexistswherethepathproperty
*purportsthatitdoes.
*/
publicbooleanpropFileExists(){
Stringpath=getProp("path");
Filefile=newFile(path);
if(file.isFile()){
returntrue;
}
else{
returnfalse;
}
}
/**
*Returnstrueifthepropertiesarewritable.Thismethodismainly
*valuableatsetuptimetoensurethatthepropertiesfileissetup
*correctly.
*/
publicbooleanpropFileIsWritable(){
Stringpath=getProp("path");
Filefile=newFile(path);
if(file.isFile()){
//Seeifwecanwritetothefile
if(file.canWrite()){
returntrue;
}
else{
returnfalse;
}
}
else{
returnfalse;
}
}
privatestaticStringpropsName2000="/pcc_2000.properties";
privatestaticStringpropsNameLinux="/pcc_linux.properties";
}
大型的应用一般不会用这些框架(因为性能考虑);开发人员根据需要选择用一些框架,也可以不选用框架;不用框架并不代表要自己写框架;修改框架的可能性更小。 |
|