public boolean canSet(String name) { AccessMethod accessmethod = getAccessMethod(name); return accessmethod == null ? false : accessmethod.canSet(); }
public void setProperty(Object parent, String name, Object value) { AccessMethod accessmethod = getAccessMethod(name); if (accessmethod == null) { throw UniversalRuntimeException .accumulate(new PropertyException(), "Property " + name + " of object " + parent.getClass() + " not found"); } else if (!accessmethod.canSet()) { throw UniversalRuntimeException.accumulate(new PropertyException(), "Property " + name + " of object " + parent.getClass() + " is not writeable"); } accessmethod.setChildObject(parent, value); }
public boolean areEqual(Object left, Object right) { if (left == null) return right == null; if (right == null) return false; if (left.getClass() != right.getClass()) return false; Class objclass = left.getClass(); if (mappingcontext.generalLeafParser.isLeafType(objclass) || Collection.class.isAssignableFrom(objclass)) { return left.equals(right); } else { MethodAnalyser ma = mappingcontext.getAnalyser(objclass); for (int i = 0; i < ma.allgetters.length; ++i) { AccessMethod sam = ma.allgetters[i]; if (!sam.canGet() || !sam.canSet()) continue; Object leftchild = sam.getChildObject(left); Object rightchild = sam.getChildObject(right); boolean equals = areEqual(leftchild, rightchild); if (!equals) return false; } } return true; }
MethodAnalyser ma = mappingContext.getAnalyser(bean.getClass()); AccessMethod sam = ma.getAccessMethod(propname); if (sam == null || !sam.canSet()) { throw new IllegalArgumentException("TLAB target bean " + beanName + " does not have any writeable property named " + propname);
public Object cloneWithRespect(Object bean, Class respectful) { Class beanclz = bean.getClass(); MethodAnalyser targetma = mappingcontext.getAnalyser(beanclz); MethodAnalyser respectma = mappingcontext.getAnalyser(respectful); Object togo = reflectivecache.construct(beanclz); for (int i = 0; i < targetma.allgetters.length; ++i) { AccessMethod pot = targetma.allgetters[i]; if (!pot.canGet() || !pot.canSet()) continue; String propname = pot.getPropertyName(); if (respectma.getAccessMethod(propname) != null) { Object getit = pot.getChildObject(bean); pot.setChildObject(togo, getit); } } return togo; } }
/** * Takes a path ending with a greedy expression (probably .*) and appends the * "leaves" (fields) based on passed in arguments */ private void appendLeaves(Class rootclass, String pathroot, String attrprefix, StringList attnames, StringList paths) { String[] components = PathUtil.splitPath(pathroot); Class moveclass = rootclass; for (int i = 0; i < components.length; ++i) { MethodAnalyser ma = mappingcontext.getAnalyser(moveclass); String component = components[i]; AccessMethod method = ma.getAccessMethod(component); if (method == null || !(method.canGet() && method.canSet())) { throw new IllegalArgumentException( "Unable to find writeable property for path component " + component + " at " + moveclass); } moveclass = method.getAccessedType(); } MethodAnalyser ma = mappingcontext.getAnalyser(moveclass); for (int i = 0; i < ma.allgetters.length; ++i) { SAXAccessMethod method = ma.allgetters[i]; if (method.canGet() && method.canSet() && mappingcontext.generalLeafParser.isLeafType(method.getAccessedType())) { paths.add(PathUtil.composePathEncoded(pathroot, method.tagname)); attnames.add(attrprefix + method.tagname); } } }