Package com.sun.xml.bind.v2.runtime.reflect

Examples of com.sun.xml.bind.v2.runtime.reflect.Accessor


    private final Accessor acc;

    public RuntimeReferencePropertyInfoImpl(RuntimeClassInfoImpl classInfo, PropertySeed<Type,Class,Field,Method> seed) {
        super(classInfo,seed);
        Accessor rawAcc = ((RuntimeClassInfoImpl.RuntimePropertySeed)seed).getAccessor();
        if(getAdapter()!=null && !isCollection())
            // adapter for a single-value property is handled by accessor.
            // adapter for a collection property is handled by lister.
            rawAcc = rawAcc.adapt(getAdapter());
        this.acc = rawAcc;
    }
View Full Code Here


    private NonElement<T,C> type;

    public SingleTypePropertyInfoImpl(ClassInfoImpl<T,C,F,M> classInfo, PropertySeed<T,C,F,M> seed) {
        super(classInfo, seed);
        if(this instanceof RuntimePropertyInfo) {
            Accessor rawAcc = ((RuntimeClassInfoImpl.RuntimePropertySeed)seed).getAccessor();
            if(getAdapter()!=null && !isCollection())
                // adapter for a single-value property is handled by accessor.
                // adapter for a collection property is handled by lister.
                rawAcc = rawAcc.adapt(((RuntimePropertyInfo)this).getAdapter());
            this.acc = rawAcc;
        } else
            this.acc = null;
    }
View Full Code Here

        if(!(bi instanceof ClassBeanInfoImpl))
            throw new JAXBException(wrapperBean+" is not a bean");

        for( ClassBeanInfoImpl cb = (ClassBeanInfoImpl) bi; cb!=null; cb=cb.superClazz) {
            for (Property p : cb.properties) {
                final Accessor acc = p.getElementPropertyAccessor(nsUri,localName);
                if(acc!=null)
                    return new RawAccessor() {
                        // Accessor.set/get are designed for unmarshaller/marshaller, and hence
                        // they go through an adapter behind the scene.
                        // this isn't desirable for JAX-WS, which essentially uses this method
                        // just as a reflection library. So use the "unadapted" version to
                        // achieve the desired semantics
                        public Object get(Object bean) throws AccessorException {
                            return acc.getUnadapted(bean);
                        }

                        public void set(Object bean, Object value) throws AccessorException {
                            acc.setUnadapted(bean,value);
                        }
                    };
            }
        }
        throw new JAXBException(new QName(nsUri,localName)+" is not a valid property on "+wrapperBean);
View Full Code Here

        if(!(bi instanceof ClassBeanInfoImpl))
            throw new JAXBException(wrapperBean+" is not a bean");

        for( ClassBeanInfoImpl cb = (ClassBeanInfoImpl) bi; cb!=null; cb=cb.superClazz) {
            for (Property p : cb.properties) {
                final Accessor acc = p.getElementPropertyAccessor(nsUri,localName);
                if(acc!=null)
                    return new RawAccessor() {
                        // Accessor.set/get are designed for unmarshaller/marshaller, and hence
                        // they go through an adapter behind the scene.
                        // this isn't desirable for JAX-WS, which essentially uses this method
                        // just as a reflection library. So use the "unadapted" version to
                        // achieve the desired semantics
                        public Object get(Object bean) throws AccessorException {
                            return acc.getUnadapted(bean);
                        }

                        public void set(Object bean, Object value) throws AccessorException {
                            acc.setUnadapted(bean,value);
                        }
                    };
            }
        }
        throw new JAXBException(new QName(nsUri,localName)+" is not a valid property on "+wrapperBean);
View Full Code Here

        if(!(bi instanceof ClassBeanInfoImpl))
            throw new JAXBException(wrapperBean+" is not a bean");

        for( ClassBeanInfoImpl cb = (ClassBeanInfoImpl) bi; cb!=null; cb=cb.superClazz) {
            for (Property p : cb.properties) {
                final Accessor acc = p.getElementPropertyAccessor(nsUri,localName);
                if(acc!=null)
                    return new RawAccessor() {
                        // Accessor.set/get are designed for unmarshaller/marshaller, and hence
                        // they go through an adapter behind the scene.
                        // this isn't desirable for JAX-WS, which essentially uses this method
                        // just as a reflection library. So use the "unadapted" version to
                        // achieve the desired semantics
                        public Object get(Object bean) throws AccessorException {
                            return acc.getUnadapted(bean);
                        }

                        public void set(Object bean, Object value) throws AccessorException {
                            acc.setUnadapted(bean,value);
                        }
                    };
            }
        }
        throw new JAXBException(new QName(nsUri,localName)+" is not a valid property on "+wrapperBean);
View Full Code Here

            Property property = createProperty(bean, runtimePropertyInfo);
            bean.addProperty(property);
        }

        if (runtimeClassInfo.declaresAttributeWildcard()) {
            Accessor anyAttributeAccessor = runtimeClassInfo.getAttributeWildcard();
            Property anyAttributeProperty;

            // if we have an AdaptedAccessor wrapper, strip off wrapper but preserve the name of the adapter class
            if ("com.sun.xml.bind.v2.runtime.reflect.AdaptedAccessor".equals(anyAttributeAccessor.getClass().getName())) {
                try {
                    Field coreField = anyAttributeAccessor.getClass().getDeclaredField("core");
                    coreField.setAccessible(true);
                    anyAttributeAccessor = (Accessor) coreField.get(anyAttributeAccessor);
                } catch (Throwable e) {
                    throw new BuildException("Unable to access private fields of AdaptedAccessor class", e);
                }
            }

            if (anyAttributeAccessor instanceof Accessor.FieldReflection) {
                Accessor.FieldReflection fieldReflection = (Accessor.FieldReflection) anyAttributeAccessor;
                anyAttributeProperty = new Property(bean, fieldReflection.f.getName());
                anyAttributeProperty.setField(fieldReflection.f);
                anyAttributeProperty.setType(fieldReflection.f.getGenericType());
            } else if (anyAttributeAccessor instanceof Accessor.GetterSetterReflection) {
                Accessor.GetterSetterReflection getterSetterReflection = (Accessor.GetterSetterReflection) anyAttributeAccessor;

                if (getterSetterReflection.getter != null) {
                    String propertyName = getterSetterReflection.getter.getName();
                    if (propertyName.startsWith("get")) {
                        propertyName = Introspector.decapitalize(propertyName.substring(3));
                    } else if (propertyName.startsWith("is")) {
                        propertyName = Introspector.decapitalize(propertyName.substring(2));
                    }
                    anyAttributeProperty = new Property(bean, propertyName);
                    anyAttributeProperty.setType(getterSetterReflection.getter.getGenericReturnType());
                } else if (getterSetterReflection.setter != null) {
                    String propertyName = getterSetterReflection.setter.getName();
                    if (propertyName.startsWith("set")) {
                        propertyName = Introspector.decapitalize(propertyName.substring(3));
                    }
                    anyAttributeProperty = new Property(bean, propertyName);
                    anyAttributeProperty.setType(getterSetterReflection.setter.getGenericParameterTypes()[0]);
                } else {
                    throw new BuildException("Any attribute property for class " + bean + " does not have a getter or setter method");
                }

                anyAttributeProperty.setGetter(getterSetterReflection.getter);
                anyAttributeProperty.setSetter(getterSetterReflection.setter);
            } else {
                throw new BuildException("Unknown property accessor type '" + anyAttributeAccessor.getClass().getName() + "' for class " + bean);
            }           

            anyAttributeProperty.setXmlStyle(Property.XmlStyle.ATTRIBUTE);
            anyAttributeProperty.setComponentType(String.class);
            anyAttributeProperty.setXmlAny(true);
View Full Code Here

        property.setId(runtimePropertyInfo.id() == ID.ID);
        property.setIdref(runtimePropertyInfo.id() == ID.IDREF);
        property.setCollection(runtimePropertyInfo.isCollection());

        Accessor accessor = runtimePropertyInfo.getAccessor();

        if (runtimePropertyInfo.getAdapter() != null) {
            property.setAdapterType(runtimePropertyInfo.getAdapter().adapterType);
            property.setComponentType(runtimePropertyInfo.getAdapter().customType);
            property.setComponentAdaptedType(JavaUtils.toClass(runtimePropertyInfo.getAdapter().defaultType));
        }

        // if we have an AdaptedAccessor wrapper, strip off wrapper but preserve the name of the adapter class
        if ("com.sun.xml.bind.v2.runtime.reflect.AdaptedAccessor".equals(accessor.getClass().getName())) {
            try {

                Field coreField = accessor.getClass().getDeclaredField("core");
                coreField.setAccessible(true);
                accessor = (Accessor) coreField.get(accessor);

            } catch (Throwable e) {
                throw new BuildException("Unable to access private fields of AdaptedAccessor class", e);
            }
        }

        if (accessor instanceof Accessor.FieldReflection) {
            Accessor.FieldReflection fieldReflection = (Accessor.FieldReflection) accessor;
            property.setField(fieldReflection.f);
        } else if (accessor instanceof Accessor.GetterSetterReflection) {
            Accessor.GetterSetterReflection getterSetterReflection = (Accessor.GetterSetterReflection) accessor;
            property.setGetter(getterSetterReflection.getter);
            property.setSetter(getterSetterReflection.setter);
        } else {
            throw new BuildException("Unknown property accessor type '" + accessor.getClass().getName() + "' for property " + property);
        }

        if (runtimePropertyInfo instanceof RuntimeAttributePropertyInfo) {
            RuntimeAttributePropertyInfo attributeProperty = (RuntimeAttributePropertyInfo) runtimePropertyInfo;
            property.setXmlStyle(Property.XmlStyle.ATTRIBUTE);
View Full Code Here

/*     */   private static final String methodTemplateName;
/*     */   private static final Map<Class, String> suffixMap;
/*     */
/*     */   public static final TransducedAccessor get(RuntimePropertyInfo prop)
/*     */   {
/*  87 */     Accessor acc = prop.getAccessor();
/*     */
/*  90 */     Class opt = null;
/*     */
/*  92 */     TypeInfo parent = prop.parent();
/*  93 */     if (!(parent instanceof RuntimeClassInfo)) {
/*  94 */       return null;
/*     */     }
/*  96 */     Class dc = (Class)((RuntimeClassInfo)parent).getClazz();
/*  97 */     String newClassName = ClassTailor.toVMClassName(dc) + "_JaxbXducedAccessor_" + prop.getName();
/*     */
/* 100 */     if ((acc instanceof Accessor.FieldReflection))
/*     */     {
/* 102 */       Accessor.FieldReflection racc = (Accessor.FieldReflection)acc;
/* 103 */       Field field = racc.f;
/*     */
/* 105 */       int mods = field.getModifiers();
/* 106 */       if ((Modifier.isPrivate(mods)) || (Modifier.isFinal(mods)))
/*     */       {
/* 109 */         return null;
/*     */       }
/* 111 */       Class t = field.getType();
/* 112 */       if (t.isPrimitive()) {
/* 113 */         opt = AccessorInjector.prepare(dc, fieldTemplateName + (String)suffixMap.get(t), newClassName, new String[] { ClassTailor.toVMClassName(Bean.class), ClassTailor.toVMClassName(dc), "f_" + t.getName(), field.getName() });
/*     */       }
/*     */
/*     */     }
/*     */
/* 122 */     if (acc.getClass() == Accessor.GetterSetterReflection.class) {
/* 123 */       Accessor.GetterSetterReflection gacc = (Accessor.GetterSetterReflection)acc;
/*     */
/* 125 */       if ((gacc.getter == null) || (gacc.setter == null)) {
/* 126 */         return null;
/*     */       }
View Full Code Here

/*     */     }
/*     */
/* 129 */     if (opt == null) {
/* 130 */       return null;
/*     */     }
/* 132 */     Accessor acc = instanciate(opt);
/* 133 */     if (acc != null)
/* 134 */       logger.log(Level.FINE, "Using optimized Accessor for " + getter + " and " + setter);
/* 135 */     return acc;
/*     */   }
View Full Code Here

/*     */     }
/*     */
/* 176 */     if (opt == null) {
/* 177 */       return null;
/*     */     }
/* 179 */     Accessor acc = instanciate(opt);
/* 180 */     if (acc != null)
/* 181 */       logger.log(Level.FINE, "Using optimized Accessor for " + field);
/* 182 */     return acc;
/*     */   }
View Full Code Here

TOP

Related Classes of com.sun.xml.bind.v2.runtime.reflect.Accessor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.