1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/bind/v2/runtime/property/AttributeProperty.java Tue Mar 06 16:09:35 2012 -0800 1.3 @@ -0,0 +1,119 @@ 1.4 +/* 1.5 + * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. Oracle designates this 1.11 + * particular file as subject to the "Classpath" exception as provided 1.12 + * by Oracle in the LICENSE file that accompanied this code. 1.13 + * 1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 + * version 2 for more details (a copy is included in the LICENSE file that 1.18 + * accompanied this code). 1.19 + * 1.20 + * You should have received a copy of the GNU General Public License version 1.21 + * 2 along with this work; if not, write to the Free Software Foundation, 1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 + * 1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.25 + * or visit www.oracle.com if you need additional information or have any 1.26 + * questions. 1.27 + */ 1.28 + 1.29 +package com.sun.xml.internal.bind.v2.runtime.property; 1.30 + 1.31 +import java.io.IOException; 1.32 + 1.33 +import javax.xml.stream.XMLStreamException; 1.34 + 1.35 +import com.sun.xml.internal.bind.api.AccessorException; 1.36 +import com.sun.xml.internal.bind.v2.util.QNameMap; 1.37 +import com.sun.xml.internal.bind.v2.model.core.AttributePropertyInfo; 1.38 +import com.sun.xml.internal.bind.v2.model.core.PropertyKind; 1.39 +import com.sun.xml.internal.bind.v2.model.runtime.RuntimeAttributePropertyInfo; 1.40 +import com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl; 1.41 +import com.sun.xml.internal.bind.v2.runtime.Name; 1.42 +import com.sun.xml.internal.bind.v2.runtime.XMLSerializer; 1.43 +import com.sun.xml.internal.bind.v2.runtime.JaxBeanInfo; 1.44 +import com.sun.xml.internal.bind.v2.runtime.unmarshaller.ChildLoader; 1.45 +import com.sun.xml.internal.bind.v2.runtime.reflect.Accessor; 1.46 +import com.sun.xml.internal.bind.v2.runtime.reflect.TransducedAccessor; 1.47 + 1.48 +import org.xml.sax.SAXException; 1.49 + 1.50 +/** 1.51 + * {@link Property} implementation for {@link AttributePropertyInfo}. 1.52 + * 1.53 + * <p> 1.54 + * This one works for both leaves and nodes, scalars and arrays. 1.55 + * 1.56 + * <p> 1.57 + * Implements {@link Comparable} so that it can be sorted lexicographically. 1.58 + * 1.59 + * @author Kohsuke Kawaguchi (kk@kohsuke.org) 1.60 + */ 1.61 +public final class AttributeProperty<BeanT> extends PropertyImpl<BeanT> 1.62 + implements Comparable<AttributeProperty> { 1.63 + 1.64 + /** 1.65 + * Attribute name. 1.66 + */ 1.67 + public final Name attName; 1.68 + 1.69 + /** 1.70 + * Heart of the conversion logic. 1.71 + */ 1.72 + public final TransducedAccessor<BeanT> xacc; 1.73 + 1.74 + private final Accessor acc; 1.75 + 1.76 + public AttributeProperty(JAXBContextImpl context, RuntimeAttributePropertyInfo prop) { 1.77 + super(context,prop); 1.78 + this.attName = context.nameBuilder.createAttributeName(prop.getXmlName()); 1.79 + this.xacc = TransducedAccessor.get(context,prop); 1.80 + this.acc = prop.getAccessor(); // we only use this for binder, so don't waste memory by optimizing 1.81 + } 1.82 + 1.83 + /** 1.84 + * Marshals one attribute. 1.85 + * 1.86 + * @see JaxBeanInfo#serializeAttributes(Object, XMLSerializer) 1.87 + */ 1.88 + public void serializeAttributes(BeanT o, XMLSerializer w) throws SAXException, AccessorException, IOException, XMLStreamException { 1.89 + CharSequence value = xacc.print(o); 1.90 + if(value!=null) 1.91 + w.attribute(attName,value.toString()); 1.92 + } 1.93 + 1.94 + public void serializeURIs(BeanT o, XMLSerializer w) throws AccessorException, SAXException { 1.95 + xacc.declareNamespace(o,w); 1.96 + } 1.97 + 1.98 + public boolean hasSerializeURIAction() { 1.99 + return xacc.useNamespace(); 1.100 + } 1.101 + 1.102 + public void buildChildElementUnmarshallers(UnmarshallerChain chainElem, QNameMap<ChildLoader> handlers) { 1.103 + throw new IllegalStateException(); 1.104 + } 1.105 + 1.106 + 1.107 + public PropertyKind getKind() { 1.108 + return PropertyKind.ATTRIBUTE; 1.109 + } 1.110 + 1.111 + public void reset(BeanT o) throws AccessorException { 1.112 + acc.set(o,null); 1.113 + } 1.114 + 1.115 + public String getIdValue(BeanT bean) throws AccessorException, SAXException { 1.116 + return xacc.print(bean).toString(); 1.117 + } 1.118 + 1.119 + public int compareTo(AttributeProperty that) { 1.120 + return this.attName.compareTo(that.attName); 1.121 + } 1.122 +}