src/share/jaxws_classes/com/sun/xml/internal/bind/v2/runtime/property/AttributeProperty.java

Fri, 04 Oct 2013 16:21:34 +0100

author
mkos
date
Fri, 04 Oct 2013 16:21:34 +0100
changeset 408
b0610cd08440
parent 0
373ffda63c9a
permissions
-rw-r--r--

8025054: Update JAX-WS RI integration to 2.2.9-b130926.1035
Reviewed-by: chegar

     1 /*
     2  * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Oracle in the LICENSE file that accompanied this code.
    10  *
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    14  * version 2 for more details (a copy is included in the LICENSE file that
    15  * accompanied this code).
    16  *
    17  * You should have received a copy of the GNU General Public License version
    18  * 2 along with this work; if not, write to the Free Software Foundation,
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    20  *
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    24  */
    26 package com.sun.xml.internal.bind.v2.runtime.property;
    28 import java.io.IOException;
    30 import javax.xml.stream.XMLStreamException;
    32 import com.sun.xml.internal.bind.api.AccessorException;
    33 import com.sun.xml.internal.bind.v2.util.QNameMap;
    34 import com.sun.xml.internal.bind.v2.model.core.AttributePropertyInfo;
    35 import com.sun.xml.internal.bind.v2.model.core.PropertyKind;
    36 import com.sun.xml.internal.bind.v2.model.runtime.RuntimeAttributePropertyInfo;
    37 import com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl;
    38 import com.sun.xml.internal.bind.v2.runtime.Name;
    39 import com.sun.xml.internal.bind.v2.runtime.XMLSerializer;
    40 import com.sun.xml.internal.bind.v2.runtime.JaxBeanInfo;
    41 import com.sun.xml.internal.bind.v2.runtime.unmarshaller.ChildLoader;
    42 import com.sun.xml.internal.bind.v2.runtime.reflect.Accessor;
    43 import com.sun.xml.internal.bind.v2.runtime.reflect.TransducedAccessor;
    45 import org.xml.sax.SAXException;
    47 /**
    48  * {@link Property} implementation for {@link AttributePropertyInfo}.
    49  *
    50  * <p>
    51  * This one works for both leaves and nodes, scalars and arrays.
    52  *
    53  * <p>
    54  * Implements {@link Comparable} so that it can be sorted lexicographically.
    55  *
    56  * @author Kohsuke Kawaguchi (kk@kohsuke.org)
    57  */
    58 public final class AttributeProperty<BeanT> extends PropertyImpl<BeanT>
    59     implements Comparable<AttributeProperty> {
    61     /**
    62      * Attribute name.
    63      */
    64     public final Name attName;
    66     /**
    67      * Heart of the conversion logic.
    68      */
    69     public final TransducedAccessor<BeanT> xacc;
    71     private final Accessor acc;
    73     public AttributeProperty(JAXBContextImpl context, RuntimeAttributePropertyInfo prop) {
    74         super(context,prop);
    75         this.attName = context.nameBuilder.createAttributeName(prop.getXmlName());
    76         this.xacc = TransducedAccessor.get(context,prop);
    77         this.acc = prop.getAccessor();   // we only use this for binder, so don't waste memory by optimizing
    78     }
    80     /**
    81      * Marshals one attribute.
    82      *
    83      * @see JaxBeanInfo#serializeAttributes(Object, XMLSerializer)
    84      */
    85     public void serializeAttributes(BeanT o, XMLSerializer w) throws SAXException, AccessorException, IOException, XMLStreamException {
    86         CharSequence value = xacc.print(o);
    87         if(value!=null)
    88             w.attribute(attName,value.toString());
    89     }
    91     public void serializeURIs(BeanT o, XMLSerializer w) throws AccessorException, SAXException {
    92         xacc.declareNamespace(o,w);
    93     }
    95     public boolean hasSerializeURIAction() {
    96         return xacc.useNamespace();
    97     }
    99     public void buildChildElementUnmarshallers(UnmarshallerChain chainElem, QNameMap<ChildLoader> handlers) {
   100         throw new IllegalStateException();
   101     }
   104     public PropertyKind getKind() {
   105         return PropertyKind.ATTRIBUTE;
   106     }
   108     public void reset(BeanT o) throws AccessorException {
   109         acc.set(o,null);
   110     }
   112     public String getIdValue(BeanT bean) throws AccessorException, SAXException {
   113         return xacc.print(bean).toString();
   114     }
   116     public int compareTo(AttributeProperty that) {
   117         return this.attName.compareTo(that.attName);
   118     }
   119 }

mercurial