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; } }
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; }
public static AccessMethod findSingleGetter(Class objclass, SAXalizerMappingContext context, String tagname) { MethodAnalyser ma = context.getAnalyser(objclass); AccessMethod method = ma.getAccessMethod(tagname); if (!method.canGet() || method.isDenumerable()) { throw new UniversalRuntimeException( "Located access method of unsuitable type for name " + tagname + " in " + objclass); } return method; }
Class targetclazz = setter.getAccessedType(); Object depbean = resolveDependent(beanref, pri, targetclazz, setter.getDeclaredType()); setter.setChildObject(newbean, depbean);
public DataAlterationRequest reshapeDAR(DataAlterationRequest toshape) { if (toshape.type.equals(DataAlterationRequest.ADD)) { String cutback = PathUtil.getToTailPath(toshape.path); // cutback may be null! so examine methods of cutback2. This MUST // be a concrete object!! String cutback2 = PathUtil.getToTailPath(cutback); String membername = PathUtil.getTailPath(cutback); Object lastentity = bma.getBeanValue(cutback2, rbl, addressibleBeanModel); MethodAnalyser ma = mappingcontext.getAnalyser(lastentity.getClass()); AccessMethod sam = ma.getAccessMethod(membername); String entityname = eni.getEntityName(sam.getDeclaredType()); if (entityname == null) { String message = "ID Defunnelling reshaper could not infer entity name for entity of type " + sam.getDeclaredType() + " - make sure to supply an EntityNameInferrer for this type"; Logger.log.warn(message); throw new IllegalArgumentException(message); } Object newentity = null; if (toshape.data != null) { // data has already been conformed in type to "oldvalue" and so is at least scalar String newentitypath = PathUtil.buildPath(entityname, (String)toshape.data); newentity = bma.getBeanValue(newentitypath, rbl, addressibleBeanModel); } DataAlterationRequest togo = new DataAlterationRequest(cutback, newentity); return togo; } else { return toshape; } }
/** * 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); } } }
public int compare(Object o1, Object o2) { Comparable field1 = (Comparable) accessor.getChildObject(o1); Comparable field2 = (Comparable) accessor.getChildObject(o2); return field1.compareTo(field2); }
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 canSet(String name) { AccessMethod accessmethod = getAccessMethod(name); return accessmethod == null ? false : accessmethod.canSet(); }
public Class getPropertyType(Object parent, String name) { AccessMethod accessmethod = getAccessMethod(name); if (accessmethod == null) { throw UniversalRuntimeException.accumulate(new PropertyException(), "Property " + name + " of " + targetclass + " not found "); } return accessmethod.getAccessedType(); }
public void unlink(Object parent, String name) { AccessMethod accessmethod = getAccessMethod(name); if (accessmethod == null) { throw UniversalRuntimeException .accumulate(new PropertyException(), "Property " + name + " of object " + parent.getClass() + " not found"); } accessmethod.setChildObject(parent, null); }
public boolean canGet(String name) { AccessMethod accessmethod = getAccessMethod(name); return accessmethod == null ? false : accessmethod.canGet(); }
Class declared = sam.getDeclaredType(); Class container = declared == Object.class && lastobj != null ? lastobj.getClass() : declared;
public static boolean match(Object query, Object totest, AccessMethod[] fields) { for (int i = 0; i < fields.length; ++ i) { Object querychild = fields[i].getChildObject(query); if (querychild != null) { Object testchild = fields[i].getChildObject(totest); if (!querychild.equals(testchild)) 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); sam.setChildObject(bean, value);
Object completed = ((CompletableDenumeration)denval).complete(); AccessMethod deliver = beingparsed.ma.getAccessMethod(denkey); deliver.setChildObject(beingparsed.object, completed); parentsetter.setChildObject(parentobject, beingparsed.object);
public void init() { List classes = genericDAO.getPersistentClasses(); for (int i = 0; i < classes.size(); ++i) { Class clazz = (Class) classes.get(i); String idprop = genericDAO.getIdProperty(clazz); MethodAnalyser ma = mappingcontext.getAnalyser(clazz); AccessMethod am = ma.getAccessMethod(idprop); Class idclazz = am.getDeclaredType(); DefaultEntityMapper dem = new DefaultEntityMapper(); dem.setEntityClass(clazz); dem.setIDClass(idclazz); dem.setMappingContext(mappingcontext); if (genericDAO instanceof InitializingCoreGenericDAO) { dem.setObjectFactory(new ObjectFactory() { public Object getObject() { return ((InitializingCoreGenericDAO) genericDAO).instantiate(); } }); } GenericDAOEntityHandler gdeh = new GenericDAOEntityHandler(); gdeh.setGenericDAO(genericDAO); gdeh.setPersistentClass(clazz); BasicObstinateEBL boebl = new BasicObstinateEBL(); boebl.setEntityHandler(gdeh); boebl.setEntityMapper(dem); String entityname = getEntityName(clazz); locators.put(entityname, boebl); } }
private String computeLocalID(Object bean, Object idstrategy, int index) { String localid = null; if (idstrategy instanceof DirectIndexStrategy) { localid = Integer.toString(index); } else { IDRemapStrategy remapstrategy = (IDRemapStrategy) idstrategy; MethodAnalyser ma = darapplier.getMappingContext().getAnalyser( bean.getClass()); AccessMethod sam = ma.getAccessMethod(remapstrategy.idfield); localid = sam.getChildObject(bean).toString(); } return localid; }
public void init() { List classes = genericDAO.getPersistentClasses(); for (int i = 0; i < classes.size(); ++i) { Class clazz = (Class) classes.get(i); String idprop = genericDAO.getIdProperty(clazz); MethodAnalyser ma = mappingcontext.getAnalyser(clazz); AccessMethod am = ma.getAccessMethod(idprop); Class idclazz = am.getDeclaredType(); DefaultEntityMapper dem = new DefaultEntityMapper(); dem.setEntityClass(clazz); dem.setIDClass(idclazz); dem.setMappingContext(mappingcontext); if (genericDAO instanceof InitializingCoreGenericDAO) { dem.setObjectFactory(new ObjectFactory() { public Object getObject() { return ((InitializingCoreGenericDAO)genericDAO).instantiate(); }}); } GenericDAOEntityHandler gdeh = new GenericDAOEntityHandler(); gdeh.setGenericDAO(genericDAO); gdeh.setPersistentClass(clazz); BasicObstinateEBL boebl = new BasicObstinateEBL(); boebl.setEntityHandler(gdeh); boebl.setEntityMapper(dem); String entityname = getEntityName(clazz); locators.put(entityname, boebl); } }
public Object getProperty(Object parent, String name) { AccessMethod accessmethod = getAccessMethod(name); if (accessmethod == null) { throw UniversalRuntimeException .accumulate(new PropertyException(), "Property " + name + " of object " + parent.getClass() + " not found"); } return accessmethod.getChildObject(parent); }