<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆-295  評(píng)論-26  文章-1  trackbacks-0
     

    ----------厚厚發(fā)表于 2006年06月27日

    網(wǎng)絡(luò)上很多關(guān)于JAVA對(duì)Oracle中BLOB、CLOB類型字段的操作說明,有的不夠全面,有的不夠準(zhǔn)確,甚至有的簡(jiǎn)直就是胡說八道。最近的項(xiàng)目正巧用到了這方面的知識(shí),在這里做個(gè)總結(jié)。
    環(huán)境:
    Database: Oracle 9i
    App Server: BEA Weblogic 8.14
    表結(jié)構(gòu):
    CREATE TABLE TESTBLOB (ID Int, NAME Varchar2(20), BLOBATTR Blob)
    CREATE TABLE TESTBLOB (ID Int, NAME Varchar2(20), CLOBATTR Clob)
    JAVA可以通過JDBC,也可以通過JNDI訪問并操作數(shù)據(jù)庫(kù),這兩種方式的具體操作存在著一些差異,由于通過App Server的數(shù)據(jù)庫(kù)連接池JNDI獲得的數(shù)據(jù)庫(kù)連接提供的java.sql.Blob和java.sql.Clob實(shí)現(xiàn)類與JDBC方式提供的不同,因此在入庫(kù)操作的時(shí)候需要分別對(duì)待;出庫(kù)操作沒有這種差異,因此不用單獨(dú)對(duì)待。

    一、BLOB操作
    1、入庫(kù)
    (1)JDBC方式
    //通過JDBC獲得數(shù)據(jù)庫(kù)連接
    Class.forName("oracle.jdbc.driver.OracleDriver");
    Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:testdb", "test", "test");
    con.setAutoCommit(false);
    Statement st = con.createStatement();
    //插入一個(gè)空對(duì)象empty_blob()
    st.executeUpdate("insert into TESTBLOB (ID, NAME, BLOBATTR) values (1, "thename", empty_blob())");
    //鎖定數(shù)據(jù)行進(jìn)行更新,注意“for update”語句
    ResultSet rs = st.executeQuery("select BLOBATTR from TESTBLOB where ID=1 for update");
    if (rs.next())
    {
    //得到j(luò)ava.sql.Blob對(duì)象后強(qiáng)制轉(zhuǎn)換為oracle.sql.BLOB
    oracle.sql.BLOB blob = (oracle.sql.BLOB) rs.getBlob("BLOBATTR");
    OutputStream outStream = blob.getBinaryOutputStream();
    //data是傳入的byte數(shù)組,定義:byte[] data
    outStream.write(data, 0, data.length);
    }
    outStream.flush();
    outStream.close();
    con.commit();
    con.close();
    (2)JNDI方式
    //通過JNDI獲得數(shù)據(jù)庫(kù)連接
    Context context = new InitialContext();
    ds = (DataSource) context.lookup("ORA_JNDI");
    Connection con = ds.getConnection();
    con.setAutoCommit(false);
    Statement st = con.createStatement();
    //插入一個(gè)空對(duì)象empty_blob()
    st.executeUpdate("insert into TESTBLOB (ID, NAME, BLOBATTR) values (1, "thename", empty_blob())");
    //鎖定數(shù)據(jù)行進(jìn)行更新,注意“for update”語句
    ResultSet rs = st.executeQuery("select BLOBATTR from TESTBLOB where ID=1 for update");
    if (rs.next())
    {
    //得到j(luò)ava.sql.Blob對(duì)象后強(qiáng)制轉(zhuǎn)換為weblogic.jdbc.vendor.oracle.OracleThinBlob(不同的App Server對(duì)應(yīng)的可能會(huì)不同)
    weblogic.jdbc.vendor.oracle.OracleThinBlob blob = (weblogic.jdbc.vendor.oracle.OracleThinBlob) rs.getBlob("BLOBATTR");
    OutputStream outStream = blob.getBinaryOutputStream();
    //data是傳入的byte數(shù)組,定義:byte[] data
    outStream.write(data, 0, data.length);
    }
    outStream.flush();
    outStream.close();
    con.commit();
    con.close();
    2、出庫(kù)
    //獲得數(shù)據(jù)庫(kù)連接
    Connection con = ConnectionFactory.getConnection();
    con.setAutoCommit(false);
    Statement st = con.createStatement();
    //不需要“for update”
    ResultSet rs = st.executeQuery("select BLOBATTR from TESTBLOB where ID=1");
    if (rs.next())
    {
    java.sql.Blob blob = rs.getBlob("BLOBATTR");
    InputStream inStream = blob.getBinaryStream();
    //data是讀出并需要返回的數(shù)據(jù),類型是byte[]
    data = new byte[input.available()];
    inStream.read(data);
    inStream.close();
    }
    inStream.close();
    con.commit();
    con.close();
    二、CLOB操作
    1、入庫(kù)
    (1)JDBC方式
    //通過JDBC獲得數(shù)據(jù)庫(kù)連接
    Class.forName("oracle.jdbc.driver.OracleDriver");
    Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:testdb", "test", "test");
    con.setAutoCommit(false);
    Statement st = con.createStatement();
    //插入一個(gè)空對(duì)象empty_clob()
    st.executeUpdate("insert into TESTCLOB (ID, NAME, CLOBATTR) values (1, "thename", empty_clob())");
    //鎖定數(shù)據(jù)行進(jìn)行更新,注意“for update”語句
    ResultSet rs = st.executeQuery("select CLOBATTR from TESTCLOB where ID=1 for update");
    if (rs.next())
    {
    //得到j(luò)ava.sql.Clob對(duì)象后強(qiáng)制轉(zhuǎn)換為oracle.sql.CLOB
    oracle.sql.CLOB clob = (oracle.sql.CLOB) rs.getClob("CLOBATTR");
    Writer outStream = clob.getCharacterOutputStream();
    //data是傳入的字符串,定義:String data
    char[] c = data.toCharArray();
    outStream.write(c, 0, c.length);
    }
    outStream.flush();
    outStream.close();
    con.commit();
    con.close();
    (2)JNDI方式
    //通過JNDI獲得數(shù)據(jù)庫(kù)連接
    Context context = new InitialContext();
    ds = (DataSource) context.lookup("ORA_JNDI");
    Connection con = ds.getConnection();
    con.setAutoCommit(false);
    Statement st = con.createStatement();
    //插入一個(gè)空對(duì)象empty_clob()
    st.executeUpdate("insert into TESTCLOB (ID, NAME, CLOBATTR) values (1, "thename", empty_clob())");
    //鎖定數(shù)據(jù)行進(jìn)行更新,注意“for update”語句
    ResultSet rs = st.executeQuery("select CLOBATTR from TESTCLOB where ID=1 for update");
    if (rs.next())
    {
    //得到j(luò)ava.sql.Clob對(duì)象后強(qiáng)制轉(zhuǎn)換為weblogic.jdbc.vendor.oracle.OracleThinClob(不同的App Server對(duì)應(yīng)的可能會(huì)不同)
    weblogic.jdbc.vendor.oracle.OracleThinClob clob = (weblogic.jdbc.vendor.oracle.OracleThinClob) rs.getClob("CLOBATTR");
    Writer outStream = clob.getCharacterOutputStream();
    //data是傳入的字符串,定義:String data
    char[] c = data.toCharArray();
    outStream.write(c, 0, c.length);
    }
    outStream.flush();
    outStream.close();
    con.commit();
    con.close();
    2、出庫(kù)
    //獲得數(shù)據(jù)庫(kù)連接
    Connection con = ConnectionFactory.getConnection();
    con.setAutoCommit(false);
    Statement st = con.createStatement();
    //不需要“for update”
    ResultSet rs = st.executeQuery("select CLOBATTR from TESTCLOB where ID=1");
    if (rs.next())
    {
    java.sql.Clob clob = rs.getClob("CLOBATTR");
    Reader inStream = clob.getCharacterStream();
    char[] c = new char[(int) clob.length()];
    inStream.read(c);
    //data是讀出并需要返回的數(shù)據(jù),類型是String
    data = new String(c);
    inStream.close();
    }
    inStream.close();
    con.commit();
    con.close();
    需要注意的地方:
    1、java.sql.Blob、oracle.sql.BLOB、weblogic.jdbc.vendor.oracle.OracleThinBlob幾種類型的區(qū)別
    2、java.sql.Clob、oracle.sql.CLOB、weblogic.jdbc.vendor.oracle.OracleThinClob幾種類型的區(qū)別

    Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=839235


    posted @ 2007-07-24 16:43 華夢(mèng)行 閱讀(666) | 評(píng)論 (0)編輯 收藏

    <%@page contentType="text/html"%>
    <%@page pageEncoding="UTF-8"%>
    <html>
    ??? <script language="javascript">


    //test function with post method
    function RequestByPost(value)
    {
    var data;
    data = '<?xml version="1.0" encoding="utf-8"?>';
    data = data + '<soapenv:Envelope xmlns:xsi=";
    data = data + '<soapenv:Body>';
    data = data + '<ns1:getUser xmlns:ns1="
    http://ss/">';
    data = data + '<Name>'+"ffff"+'</Name>';
    data = data + '</ns1:getUser>';
    data = data + '</soapenv:Body>';
    data = data + '</soapenv:Envelope>';

    var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    var URL="http://localhost:8080/myPj/SayHelloTo?wsdl";
    xmlhttp.Open("POST",URL, false);
    xmlhttp.SetRequestHeader ("Content-Type","text/xml; charset=UTF-8");
    xmlhttp.SetRequestHeader ("SOAPAction","http://ss/SayHelloTo");
    alert(data);
    xmlhttp.Send(data);
    alert( xmlhttp.responseText);
    document.getElementById('mm').value=xmlhttp.responseText;
    }

    ??? </script>
    ??? <title>
    ??????? Call webservice with javascript and xmlhttp.
    ??? </title>
    ??? <body>
    ???????
    ??????? <div id="mm">
    ??????? <input type="button" value="CallWebserviceByGet" onClick="RequestByGet(null)">
    ??????? <input type="button" value="CallWebserviceByPost" onClick="RequestByPost('Zach')">
    ??????? <input id="mm" type="text"/>
    ??? </body>
    </html>

    ?

    posted @ 2007-07-17 16:18 華夢(mèng)行 閱讀(158) | 評(píng)論 (0)編輯 收藏
    res://msxml.dll/defaultss.xsl
    posted @ 2007-07-13 08:24 華夢(mèng)行 閱讀(103) | 評(píng)論 (0)編輯 收藏
    Result:
    hello null
    <?xml version="1.0" ?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns1="http://ss/"><soapenv:Body><ns1:sayHelloResponse><return>hello null</return></ns1:sayHelloResponse></soapenv:Body></soapenv:Envelope>
    posted @ 2007-07-06 13:10 華夢(mèng)行 閱讀(100) | 評(píng)論 (0)編輯 收藏

    nodeType 屬性

    KingCMS官方網(wǎng)站 Microsoft 2006-1-31 21:18:32
    作 用
    辨識(shí)節(jié)點(diǎn)的DOM 型態(tài)。  
    基本語法
    numNodeType = xmlDocNode.nodeType ;
     
    說 明

    此屬性只讀且傳回一個(gè)數(shù)值。

    有效的數(shù)值符合以下的型別:
    1-ELEMENT
    2-ATTRIBUTE
    3-TEXT
    4-CDATA
    5-ENTITY REFERENCE
    6-ENTITY
    7-PI (processing instruction)
    8-COMMENT
    9-DOCUMENT
    10-DOCUMENT TYPE
    11-DOCUMENT FRAGMENT
    12-NOTATION
     
     
    范 例
    numNodeType = xmlDoc.documentElement.nodeType;
    alert(numNodeType);
    posted @ 2007-07-06 12:58 華夢(mèng)行 閱讀(128) | 評(píng)論 (0)編輯 收藏
    type:表示所有的數(shù)據(jù)類型
    Message: 指明被調(diào)用的函數(shù)的參數(shù)
    Port:??? 指明服務(wù)的具體內(nèi)容,包括輸入輸出
    Binding:? 服務(wù)所綁定的協(xié)議

    addTwo Method invocation



    Method parameter(s)

    TypeValue
    int55
    int676

    Method returned

    int : "731"

    SOAP Request


    <?xml version="1.0" encoding="UTF-8"?>
    <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
        <S:Header/>
        <S:Body>
            <ns2:addTwo xmlns:ns2="http://my/">
                <mm>55</mm>
                <gg>676</gg>
            </ns2:addTwo>
        </S:Body>
    </S:Envelope>
    

    SOAP Response


    <?xml version="1.0" encoding="UTF-8"?>
    <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
        <S:Body>
            <ns2:addTwoResponse xmlns:ns2="http://my/">
                <return>731</return>
            </ns2:addTwoResponse>
        </S:Body>
    </S:Envelope>
    


    <?xml version="1.0" encoding="UTF-8"?><!-- Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.2-hudson-112-M1. --><!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.2-hudson-112-M1. --><definitions xmlns:wsu="http://my/" xmlns:xsd="http://my/" name="firstService">
    <types>
    <xsd:schema>
    <xsd:import namespace="http://my/" schemaLocation="http://localhost:8080/ssServ/firstService?xsd=1"></xsd:import>
    </xsd:schema>
    </types>
    <message name="usrLogin">
    <part name="parameters" element="tns:usrLogin"></part>
    </message>
    <message name="usrLoginResponse">
    <part name="parameters" element="tns:usrLoginResponse"></part>
    </message>
    <message name="addTwo">
    <part name="parameters" element="tns:addTwo"></part>
    </message>
    <message name="addTwoResponse">
    <part name="parameters" element="tns:addTwoResponse"></part>
    </message>
    <message name="userLogin">
    <part name="parameters" element="tns:userLogin"></part>
    </message>
    <message name="userLoginResponse">
    <part name="parameters" element="tns:userLoginResponse"></part>
    </message>
    <portType name="first">
    <operation name="usrLogin">
    <input message="tns:usrLogin"></input>
    <output message="tns:usrLoginResponse"></output>
    </operation>
    <operation name="addTwo">
    <input message="tns:addTwo"></input>
    <output message="tns:addTwoResponse"></output>
    </operation>
    <operation name="userLogin">
    <input message="tns:userLogin"></input>
    <output message="tns:userLoginResponse"></output>
    </operation>
    </portType>
    <binding name="firstPortBinding" type="tns:first">
    <soap:binding transport="<operation name="usrLogin">
    <soap:operation soapAction=""></soap:operation>
    <input>
    <soap:body use="literal"></soap:body>
    </input>
    <output>
    <soap:body use="literal"></soap:body>
    </output>
    </operation>
    <operation name="addTwo">
    <soap:operation soapAction=""></soap:operation>
    <input>
    <soap:body use="literal"></soap:body>
    </input>
    <output>
    <soap:body use="literal"></soap:body>
    </output>
    </operation>
    <operation name="userLogin">
    <soap:operation soapAction=""></soap:operation>
    <input>
    <soap:body use="literal"></soap:body>
    </input>
    <output>
    <soap:body use="literal"></soap:body>
    </output>
    </operation>
    </binding>
    <service name="firstService">
    <port name="firstPort" binding="tns:firstPortBinding">
    <soap:address location="
    http://localhost:8080/ssServ/firstService"></soap:address>
    </port>
    </service>
    </definitions>

    從本質(zhì)上說:客戶端發(fā)一個(gè)請(qǐng)求即SOAP 請(qǐng)求頭,到指定的web service地址wsdl,然后經(jīng)過webservice的處理之后,返回一個(gè) SOAP 相應(yīng), 然后再在客戶端解析他們
    posted @ 2007-07-05 18:27 華夢(mèng)行 閱讀(168) | 評(píng)論 (0)編輯 收藏

    程序員每天該做的事
    1、總結(jié)自己一天任務(wù)的完成情況

    最好的方式是寫工作日志,把自己今天完成了什么事情,遇見了什么問題都記錄下來,日后翻看好處多多

    2、考慮自己明天應(yīng)該做的主要工作

    把明天要做的事情列出來,并按照優(yōu)先級(jí)排列,第二天應(yīng)該把自己效率最高的時(shí)間分配給最重要的工作

    3、考慮自己一天工作中失誤的地方,并想出避免下一次再犯的方法

    出錯(cuò)不要緊,最重要的是不要重復(fù)犯相同的錯(cuò)誤,那是愚蠢

    4、考慮自己一天工作完成的質(zhì)量和效率能否還能提高

    一天只提高1%,365天你的效率就能提高多少倍你知道嗎? (1+0.01)^365 = 37 倍

    posted @ 2007-07-05 11:33 華夢(mèng)行 閱讀(125) | 評(píng)論 (0)編輯 收藏

    function hel(){
    ?alert("good");
    }?

    Event.observe(document, 'mousedown', hel.bindAsEventListener());


    ? Browser: {
    ??? IE:???? !!(window.attachEvent && !window.opera),?//判斷是不是IE? 轉(zhuǎn)換為boolean
    ??? Opera:? !!window.opera,
    ??? WebKit: navigator.userAgent.indexOf('AppleWebKit/') > -1,
    ??? Gecko:? navigator.userAgent.indexOf('Gecko') > -1 && navigator.userAgent.indexOf('KHTML') == -1
    ? },

    posted @ 2007-07-03 11:13 華夢(mèng)行 閱讀(148) | 評(píng)論 (0)編輯 收藏

    AnnotationProcessor ???? Annotation 處理的接口,實(shí)現(xiàn)類是DefaltAnnotationProcessor?:

    protected static?void lookupFieldResource (javax.naming.Context?context, java.lang.Object?instance, java.lang.reflect.Field?field, java.lang.String?name)
    ??????????Inject resources in specified field.
    protected static?void lookupMethodResource (javax.naming.Context?context, java.lang.Object?instance, java.lang.reflect.Method?method, java.lang.String?name)
    ??????????Inject resources in specified method.
    ?void postConstruct (java.lang.Object?instance)
    ??????????Call postConstruct method on the specified instance.
    ?void preDestroy (java.lang.Object?instance)
    ??????????Call preDestroy method on the specified instance.
    ?void processAnnotations (java.lang.Object?instance)
    ??????????Inject resources in specified instance


    public class DefaultAnnotationProcessor implements AnnotationProcessor {
    ???
    ??? protected javax.naming.Context context = null;
    ???
    ??? public DefaultAnnotationProcessor(javax.naming.Context context) {
    ??????? this.context = context;
    ??? }


    ??? /**
    ???? * Call postConstruct method on the specified instance.
    ???? */
    ??? public void postConstruct(Object instance)
    ??????? throws IllegalAccessException, InvocationTargetException {
    ???????
    ??????? Method[] methods = instance.getClass().getDeclaredMethods();
    ??????? Method postConstruct = null;
    ??????? for (int i = 0; i < methods.length; i++) {
    ??????????? if (methods[i].isAnnotationPresent(PostConstruct.class)) {
    ??????????????? if ((postConstruct != null)
    ??????????????????????? || (methods[i].getParameterTypes().length != 0)
    ??????????????????????? || (Modifier.isStatic(methods[i].getModifiers()))
    ??????????????????????? || (methods[i].getExceptionTypes().length > 0)
    ??????????????????????? || (!methods[i].getReturnType().getName().equals("void"))) {
    ??????????????????? throw new IllegalArgumentException("Invalid PostConstruct annotation");
    ??????????????? }
    ??????????????? postConstruct = methods[i];
    ??????????? }
    ??????? }

    ??????? // At the end the postconstruct annotated
    ??????? // method is invoked
    ??????? if (postConstruct != null) {
    ??????????? boolean accessibility = postConstruct.isAccessible();
    ??????????? postConstruct.setAccessible(true);
    ??????????? postConstruct.invoke(instance);
    ??????????? postConstruct.setAccessible(accessibility);
    ??????? }
    ???????
    ??? }
    ???
    ???
    ??? /**
    ???? * Call preDestroy method on the specified instance.
    ???? */
    ??? public void preDestroy(Object instance)
    ??????? throws IllegalAccessException, InvocationTargetException {
    ???????
    ??????? Method[] methods = instance.getClass().getDeclaredMethods();
    ??????? Method preDestroy = null;
    ??????? for (int i = 0; i < methods.length; i++) {
    ??????????? if (methods[i].isAnnotationPresent(PreDestroy.class)) {
    ??????????????? if ((preDestroy != null)
    ??????????????????????? || (methods[i].getParameterTypes().length != 0)
    ??????????????????????? || (Modifier.isStatic(methods[i].getModifiers()))
    ??????????????????????? || (methods[i].getExceptionTypes().length > 0)
    ??????????????????????? || (!methods[i].getReturnType().getName().equals("void"))) {
    ??????????????????? throw new IllegalArgumentException("Invalid PreDestroy annotation");
    ??????????????? }
    ??????????????? preDestroy = methods[i];
    ??????????? }
    ??????? }

    ??????? // At the end the postconstruct annotated
    ??????? // method is invoked
    ??????? if (preDestroy != null) {
    ??????????? boolean accessibility = preDestroy.isAccessible();
    ??????????? preDestroy.setAccessible(true);
    ??????????? preDestroy.invoke(instance);
    ??????????? preDestroy.setAccessible(accessibility);
    ??????? }
    ???????
    ??? }
    ???
    ???
    ??? /**
    ???? * Inject resources in specified instance.
    ???? */
    ??? public void processAnnotations(Object instance)
    ??????? throws IllegalAccessException, InvocationTargetException, NamingException {
    ???????
    ??????? if (context == null) {
    ??????????? // No resource injection
    ??????????? return;
    ??????? }
    ???????
    ??????? // Initialize fields annotations
    ??????? Field[] fields = instance.getClass().getDeclaredFields();
    ??????? for (int i = 0; i < fields.length; i++) {
    ??????????? if (fields[i].isAnnotationPresent(Resource.class)) {
    ??????????????? Resource annotation = (Resource) fields[i].getAnnotation(Resource.class);
    ??????????????? lookupFieldResource(context, instance, fields[i], annotation.name());
    ??????????? }
    ??????????? if (fields[i].isAnnotationPresent(EJB.class)) {
    ??????????????? EJB annotation = (EJB) fields[i].getAnnotation(EJB.class);
    ??????????????? lookupFieldResource(context, instance, fields[i], annotation.name());
    ??????????? }
    ??????????? if (fields[i].isAnnotationPresent(WebServiceRef.class)) {
    ??????????????? WebServiceRef annotation =
    ??????????????????? (WebServiceRef) fields[i].getAnnotation(WebServiceRef.class);
    ??????????????? lookupFieldResource(context, instance, fields[i], annotation.name());
    ??????????? }
    ??????????? if (fields[i].isAnnotationPresent(PersistenceContext.class)) {
    ??????????????? PersistenceContext annotation =
    ??????????????????? (PersistenceContext) fields[i].getAnnotation(PersistenceContext.class);
    ??????????????? lookupFieldResource(context, instance, fields[i], annotation.name());
    ??????????? }
    ??????????? if (fields[i].isAnnotationPresent(PersistenceUnit.class)) {
    ??????????????? PersistenceUnit annotation =
    ??????????????????? (PersistenceUnit) fields[i].getAnnotation(PersistenceUnit.class);
    ??????????????? lookupFieldResource(context, instance, fields[i], annotation.name());
    ??????????? }
    ??????? }
    ???????
    ??????? // Initialize methods annotations
    ??????? Method[] methods = instance.getClass().getDeclaredMethods();
    ??????? for (int i = 0; i < methods.length; i++) {
    ??????????? if (methods[i].isAnnotationPresent(Resource.class)) {
    ??????????????? Resource annotation = (Resource) methods[i].getAnnotation(Resource.class);
    ??????????????? lookupMethodResource(context, instance, methods[i], annotation.name());
    ??????????? }
    ??????????? if (methods[i].isAnnotationPresent(EJB.class)) {
    ??????????????? EJB annotation = (EJB) methods[i].getAnnotation(EJB.class);
    ??????????????? lookupMethodResource(context, instance, methods[i], annotation.name());
    ??????????? }
    ??????????? if (methods[i].isAnnotationPresent(WebServiceRef.class)) {
    ??????????????? WebServiceRef annotation =
    ??????????????????? (WebServiceRef) methods[i].getAnnotation(WebServiceRef.class);
    ??????????????? lookupMethodResource(context, instance, methods[i], annotation.name());
    ??????????? }
    ??????????? if (methods[i].isAnnotationPresent(PersistenceContext.class)) {
    ??????????????? PersistenceContext annotation =
    ??????????????????? (PersistenceContext) methods[i].getAnnotation(PersistenceContext.class);
    ??????????????? lookupMethodResource(context, instance, methods[i], annotation.name());
    ??????????? }
    ??????????? if (methods[i].isAnnotationPresent(PersistenceUnit.class)) {
    ??????????????? PersistenceUnit annotation =
    ??????????????????? (PersistenceUnit) methods[i].getAnnotation(PersistenceUnit.class);
    ??????????????? lookupMethodResource(context, instance, methods[i], annotation.name());
    ??????????? }
    ??????? }

    ??? }
    ???
    ???
    ??? /**
    ???? * Inject resources in specified field.
    ???? */
    ??? protected static void lookupFieldResource(javax.naming.Context context,
    ??????????? Object instance, Field field, String name)
    ??????? throws NamingException, IllegalAccessException {
    ???
    ??????? Object lookedupResource = null;
    ??????? boolean accessibility = false;
    ???????
    ??????? if ((name != null) &&
    ??????????????? (name.length() > 0)) {
    ??????????? lookedupResource = context.lookup(name);
    ??????? } else {
    ??????????? lookedupResource = context.lookup(instance.getClass().getName() + "/" + field.getName());
    ??????? }
    ???????
    ??????? accessibility = field.isAccessible();
    ??????? field.setAccessible(true);
    ??????? field.set(instance, lookedupResource);
    ??????? field.setAccessible(accessibility);
    ??? }


    ??? /**
    ???? * Inject resources in specified method.
    ???? */
    ??? protected static void lookupMethodResource(javax.naming.Context context,
    ??????????? Object instance, Method method, String name)
    ??????? throws NamingException, IllegalAccessException, InvocationTargetException {
    ???????
    ??????? if (!method.getName().startsWith("set")
    ??????????????? || method.getParameterTypes().length != 1
    ??????????????? || !method.getReturnType().getName().equals("void")) {
    ??????????? throw new IllegalArgumentException("Invalid method resource injection annotation");
    ??????? }
    ???????
    ??????? Object lookedupResource = null;
    ??????? boolean accessibility = false;
    ???????
    ??????? if ((name != null) &&
    ??????????????? (name.length() > 0)) {
    ??????????? lookedupResource = context.lookup(name);
    ??????? } else {
    ??????????? lookedupResource =
    ??????????????? context.lookup(instance.getClass().getName() + "/" + method.getName().substring(3));
    ??????? }
    ???????
    ??????? accessibility = method.isAccessible();
    ??????? method.setAccessible(true);
    ??????? method.invoke(instance, lookedupResource);
    ??????? method.setAccessible(accessibility);
    ??? }
    ???

    }

    posted @ 2007-06-28 15:26 華夢(mèng)行 閱讀(662) | 評(píng)論 (0)編輯 收藏
    http://webfx.eae.net/
    posted @ 2007-06-28 12:54 華夢(mèng)行 閱讀(118) | 評(píng)論 (0)編輯 收藏

    ? import java.lang.reflect.*;
    public class RunTest {
    ??? public static void main(String[] args) throws Exception {
    ???????
    ??????? int passed = 0, failed = 0;
    ??????? for (Method m : Class.forName("Foo").getMethods()) {
    ??????????? if (m.isAnnotationPresent(Test.class)) {
    ??????????????? try {
    ??????????????????? m.invoke(null);
    ???????????????????
    ??????????????????? passed++;
    ??????????????? } catch (Throwable ex) {
    ??????????????????? System.out.printf("Test %s failed: %s %n", m, ex.getCause());
    ??????????????????? failed++;
    ??????????????? }
    ??????????? }
    ??????? }
    ??????? System.out.printf("Passed: %d, Failed %d%n", passed, failed);
    ??? }
    }

    public class Foo {
    ??? @Test public static void m1() {
    ??? System.out.println("m1 SUcsessful");
    ??? }
    ??? public static void m2() { }
    ??? @Test public static void m3() {
    ??????? System.out.println("m3 Fails");
    ??????? throw new RuntimeException("Boom");
    ??? }
    ??? public static void m4() { }
    ??? @Test public static void m5() { }
    ??? public static void m6() { }
    ??? @Test public static void m7() {
    ??????? throw new RuntimeException("Crash");??????? }
    ???
    ??? public static void m8() { }
    }


    import java.lang.annotation.*;
    /*
    ?* Test.java
    ?*
    ?* Created on 2007年6月28日, 上午8:52
    ?*
    ?* To change this template, choose Tools | Template Manager
    ?* and open the template in the editor.
    ?*/

    /**
    ?*
    ?* @author ljl
    ?*/
    @Documented
    @Retention(RetentionPolicy.RUNTIME)
    @Target(ElementType.METHOD)
    public @interface Test {
    ???
    ???
    ???
    }

    posted @ 2007-06-28 09:24 華夢(mèng)行 閱讀(297) | 評(píng)論 (0)編輯 收藏

    /** The original page id sent from the server */
    dwr.engine._origScriptSessionId = "${scriptSessionId}";

    /** The session cookie name */
    dwr.engine._sessionCookieName = "${sessionCookieName}"; // JSESSIONID

    以上這段代碼取自? dwr?源碼包中?engine.js
    這里的${scriptSessionId}?? 與? ${sessionCookieName} 是從哪里或得的,又是怎么獲得的呢。
    有怎么會(huì)用? ${}? ,${}?是什么意思呢?請(qǐng)各位大俠不吝賜教!

    posted @ 2007-06-21 21:28 華夢(mèng)行 閱讀(1839) | 評(píng)論 (2)編輯 收藏
    僅列出標(biāo)題
    共15頁: First 上一頁 7 8 9 10 11 12 13 14 15 
    主站蜘蛛池模板: 亚洲熟妇无码另类久久久| 免费激情视频网站| 国产精品亚洲精品日韩已满| 美女被爆羞羞网站在免费观看| 日韩一级免费视频| 偷自拍亚洲视频在线观看99| 免费国产在线观看| 免费人成网站永久| 国产自偷亚洲精品页65页| 两性色午夜免费视频| 亚洲成A人片在线观看WWW| 日本在线看片免费人成视频1000 | 99精品视频在线视频免费观看| 久久国产亚洲精品麻豆| 日韩免费高清大片在线| 亚洲中文字幕久久精品无码2021| 最近免费中文字幕大全视频 | 久久精品国产免费| 久久亚洲精品成人AV| 免费影院未满十八勿进网站| 亚洲狠狠色丁香婷婷综合| 亚洲精品无码专区2| 一个人看的www免费视频在线观看| 久久久久亚洲精品天堂| 日本免费无遮挡吸乳视频电影| 免费视频成人国产精品网站 | 亚洲一区二区三区无码国产| 日韩免费视频一区| 精品多毛少妇人妻AV免费久久| 亚洲激情视频在线观看| 黄色网址免费大全| 国产精品亚洲一区二区三区| 亚洲精品无码永久中文字幕| 日本妇人成熟免费中文字幕| 污污视频网站免费观看| 亚洲成a人片77777老司机| 日韩精品视频免费网址| 黄网站色视频免费在线观看的a站最新 | 95免费观看体验区视频| 亚洲精品国产综合久久久久紧| 亚洲码国产精品高潮在线|