1 /* 2 * Copyright (c) 1997, 2015, 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 */ 25 26 package com.sun.xml.internal.bind; 27 28 import java.lang.reflect.Field; 29 import java.lang.reflect.Method; 30 31 import javax.xml.bind.JAXBException; 32 33 import com.sun.xml.internal.bind.v2.runtime.reflect.Accessor; 34 35 public class AccessorFactoryImpl implements InternalAccessorFactory { 36 37 private static AccessorFactoryImpl instance = new AccessorFactoryImpl(); 38 private AccessorFactoryImpl(){} 39 40 public static AccessorFactoryImpl getInstance(){ 41 return instance; 42 } 43 44 /** 45 * Access a field of the class. 46 * 47 * @param bean the class to be processed. 48 * @param field the field within the class to be accessed. 49 * @param readOnly the isStatic value of the field's modifier. 50 * @return Accessor the accessor for this field 51 */ 52 public Accessor createFieldAccessor(Class bean, Field field, boolean readOnly) { 53 return readOnly 54 ? new Accessor.ReadOnlyFieldReflection(field) 55 : new Accessor.FieldReflection(field); 56 } 57 58 /** 59 * Access a field of the class. 60 * 61 * @param bean the class to be processed. 62 * @param field the field within the class to be accessed. 63 * @param readOnly the isStatic value of the field's modifier. 64 * @param supressWarning supress security warning about accessing fields through reflection 65 * @return Accessor the accessor for this field 66 */ 67 public Accessor createFieldAccessor(Class bean, Field field, boolean readOnly, boolean supressWarning) { 68 return readOnly 69 ? new Accessor.ReadOnlyFieldReflection(field, supressWarning) 70 : new Accessor.FieldReflection(field, supressWarning); 71 } 72 73 /** 74 * Access a property of the class. 75 * 76 * @param bean the class to be processed 77 * @param getter the getter method to be accessed. The value can be null. 78 * @param setter the setter method to be accessed. The value can be null. 79 * @return Accessor the accessor for these methods 80 */ 81 public Accessor createPropertyAccessor(Class bean, Method getter, Method setter) { 82 if (getter == null) { 83 return new Accessor.SetterOnlyReflection(setter); 84 } 85 if (setter == null) { 86 return new Accessor.GetterOnlyReflection(getter); 87 } 88 return new Accessor.GetterSetterReflection(getter, setter); 89 } 90 }