Changeset 1752 for trunk/docx4j/src


Ignore:
Timestamp:
01/17/12 09:14:49 (4 months ago)
Author:
jharrop
Message:

Without generics, since this returned a spurious 11th result when tested on w:t

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/docx4j/src/main/java/org/docx4j/utils/XPathAwareCloner.java

    r1751 r1752  
    3030                         
    3131        /** Clone this JAXB object, using default JAXBContext. */  
    32         public <T> T deepCopy(T value) {                 
    33                 return deepCopy(value, Context.jc);              
     32        public Object deepCopy(Object o) {               
     33                return deepCopy(o, Context.jc);          
    3434        }        
    3535         
     
    4141         * @return 
    4242         */ 
    43         public <T> T deepCopy(T value, JAXBContext jc) { 
     43        public Object deepCopy(Object o, JAXBContext jc) { 
    4444                 
    45                 if (value==null) { 
     45                if (o==null) { 
    4646                        throw new IllegalArgumentException("Can't clone a null argument"); 
    4747                } 
    4848                 
    4949                try { 
    50                         JAXBElement<?> elem; 
    51                         Class<?> valueClass; 
    52                         if (value instanceof JAXBElement<?>) { 
    53                                 log.debug("deep copy of JAXBElement.."); 
    54                                 elem = (JAXBElement<?>) value; 
    55                                 valueClass = elem.getDeclaredType(); 
    56                         } else { 
    57                                 log.debug("deep copy of " + value.getClass().getName() ); 
    58                                 @SuppressWarnings("unchecked") 
    59                                 Class<T> classT = (Class<T>) value.getClass(); 
    60                                 elem = new JAXBElement<T>(new QName("temp"), classT, value); 
    61                                 valueClass = classT; 
    62                         } 
    63                          
    6450                        // To be XPath aware, we need a binder. 
    6551                        // But to unmarshall using a binder, we need to unmarshal a node. 
    6652                        // So, our marshall should be to a W3C document 
    67                         org.w3c.dom.Document doc = XmlUtils.marshaltoW3CDomDocument(elem, jc); 
     53                        org.w3c.dom.Document doc = XmlUtils.marshaltoW3CDomDocument(o, jc); 
    6854                         
    6955                        // OK, unmarshall to binder 
     
    7258                        eventHandler.setContinue(false); 
    7359                        binder.setEventHandler(eventHandler); 
    74                         elem =  binder.unmarshal( doc, valueClass); 
    75  
    76                         T res; 
    77                         if (value instanceof JAXBElement<?>) { 
    78                                 @SuppressWarnings("unchecked") 
    79                                 T resT = (T) elem; 
    80                                 res = resT; 
    81                         } else { 
    82                                 @SuppressWarnings("unchecked") 
    83                                 T resT = (T) elem.getValue(); 
    84                                 res = resT; 
    85                         } 
    86                         jaxbElement = res; 
    87                         return res; 
     60                        jaxbElement =  binder.unmarshal( doc); 
     61                         
     62                        //log.debug("Clone: " + XmlUtils.marshaltoString(jaxbElement, true, true)); 
     63                         
     64                        return jaxbElement; 
    8865                } catch (JAXBException ex) { 
    8966                        throw new IllegalArgumentException(ex); 
     
    196173             
    197174            XPathAwareCloner cloner = new XPathAwareCloner(); 
    198             P clonedP = cloner.deepCopy(pIn); 
     175            P clonedP = (P)cloner.deepCopy(pIn); 
    199176             
    200177            List<Object> results = cloner.getJAXBNodesViaXPath("//w:r[contains( w:t, 'seeking')]", false); 
     178            //List<Object> results = cloner.getJAXBNodesViaXPath("//w:r", false); 
    201179             
    202             System.out.println(XmlUtils.marshaltoString(results.get(0), true, true)); 
     180            int i=1; 
     181            for (Object result: results) { 
     182                System.out.println("\n\r" + i + ": " + XmlUtils.marshaltoString(result, true, true)); 
     183                i++; 
     184            } 
    203185                 
    204186 
Note: See TracChangeset for help on using the changeset viewer.