/** Build an EL path which locates the referred-to entity **/ public String getELPath() { return PathUtil.buildPath(entity.entityname, entity.ID); }
public static String matchPath(String spec, String path) { String togo = ""; while (true) { if (spec == null || spec.equals("")) break; if (path == null || path.equals("")) return null; String spechead = PathUtil.getHeadPath(spec); String pathhead = PathUtil.getHeadPath(path); // if we fail to match on a specific component, fail. if (!(spechead.equals("*") || spechead.equals(pathhead))) return null; togo = PathUtil.composePath(togo, pathhead); spec = PathUtil.getFromHeadPath(spec); path = PathUtil.getFromHeadPath(path); } return togo; }
/** * Returns the very last path component of a bean path * * @param path bean path * @return last path segment */ public static String getTailPath(String path) { int lastdot = lastDotIndex(path); return getPathSegment(path, lastdot + 1); }
public void saveAll() { if (sebl.saveEL != null) { String penultimate = PathUtil.getToTailPath(sebl.saveEL); String savemethod = PathUtil.getTailPath(sebl.saveEL); Object saver = sebl.bma.getBeanValue(penultimate, beanlocator, null); for (Iterator it = delivered.keySet().iterator(); it.hasNext();) { String key = (String) it.next(); Object value = delivered.get(key); sebl.reflectivecache.invokeMethod(saver, savemethod, new Object[] { value }); } } }
/** Disused method */ public List getInvalidatingEntries(String path) { ArrayList togo = new ArrayList(); String[] splitEL = PathUtil.splitPath(path); StringList goup = new StringList(); for (int i = 0; i < splitEL.length; ++ i) { goup.add(splitEL[i]); String upstring = PathUtil.buildPath(goup.toStringArray()); List deps = (List) writemap.get(upstring); if (deps != null) { togo.addAll(deps); } } return togo; } }
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; } }
String guardproperty = guarddef.getGuardProperty(); if (guardEL != null && guardmethod != null) { guardmethod = PathUtil.composePath(guardEL, guardmethod); if (guard == null && guardEL == null) { if (guardmethod != null) { guardEL = PathUtil.getToTailPath(guardmethod); guardmethod = PathUtil.getTailPath(guardmethod); guardEL = PathUtil.getToTailPath(guardproperty); guardproperty = PathUtil.getTailPath(guardproperty);
/** Sets the method binding for this UICommand to perform no action but to * return the supplied value, should the cycle complete without errors. * This will overwrite any existing method binding for the component. * @param returnvalue The required return value from the action cycle. * @return this component. */ public UICommand setReturn(String returnvalue) { methodbinding = new ELReference(PathUtil.composePath("constantReturn", returnvalue)); return this; }
public ConverterCandidate(DataConverter converter) { this.converter = converter; if (converter.getTargetPath() != null) { segments = PathUtil.splitPath(converter.getTargetPath()); } } }
/** * 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 static String getHeadPath(String path) { return getPathSegment(path, 0); } /**
public void recordWrite(String upstring, SubmittedValueEntry sve) { recordMap(writemap, upstring, sve); String up2 = PathUtil.getToTailPath(upstring); if (up2 != null) { recordMap(writemap, up2, sve); } mapwrite.put(sve, upstring); }
/** * Compose a prefix and suffix EL path, where the prefix has not been escaped, * and is not null. * @param prefix A single path segment (bean name) starting the path, may not * be null or empty. This will become escaped. * @param suffix A single path segment (property name) continuing the path, * may not be null or empty. This will become escaped. * @return A properly escaped full path, representing "prefix.suffix". */ public static String buildPath(String prefix, String suffix) { CharWrap toappend = new CharWrap(); composeSegment(toappend, prefix); toappend.append('.'); composeSegment(toappend, suffix); return toappend.toString(); }
String[] segments = PathUtil.splitPath(oldpath); for (int i = 0; i < segments.length - 1; ++i) { moveobj = BeanUtil.navigateOne(moveobj, segments[i], mappingcontext); if (moveobj == null) { throw new NullPointerException("Null value in EL path at path '" + PathUtil.buildPath(segments, 0, i + 1) + "'"); dar.path = PathUtil.buildPath(segments, i + 1, segments.length); boolean accepted = ((DARReceiver) moveobj).addDataAlterationRequest(dar); if (accepted)
public boolean remove(String beanname) { if (sebl.removeEL == null) { throw new UnsupportedOperationException("Cannot implement removal from EntityBeanLocator without removeEL being set"); } // TODO: support the case where the fetch method signature accepts an object // rather than its ID Object togo = sebl.bma.invokeBeanMethod(PathUtil.composePath(sebl.removeEL, '\'' + beanname + '\''), beanlocator); delivered.remove(beanname); if (togo == null) return false; if (togo instanceof Boolean) { return ((Boolean)togo).booleanValue(); } return true; }
public static Object navigate(Object rootobj, String path, SAXalizerMappingContext mappingcontext) { if (path == null || path.equals("")) { return rootobj; } String[] components = PathUtil.splitPath(path); Object moveobj = rootobj; for (int comp = 0; comp < components.length; ++comp) { if (moveobj == null) { throw UniversalRuntimeException.accumulate( new IllegalArgumentException(), "Null value encounted in bean path at component " + (comp == 0 ? "<root>" : components[comp - 1] + " while traversing for " + components[comp])); } else { moveobj = navigateOne(moveobj, components[comp], mappingcontext); if (moveobj == UNREADABLE_PROPERTY) { throw new IllegalArgumentException("Property " + components[comp] + " is not readable for object of " + moveobj.getClass()); } } } return moveobj; }
/** * Returns the first path segment, without performing unescaping * * @param path a path * @return segment */ public static String getHeadPathEncoded(String path) { int firstdot = getPathSegment(null, path, 0); return path.substring(0, firstdot); }
public SubmittedValueEntry getUpstreamComponent(String writepath) { List writers = elmap.getWriters(writepath); if (writers == null) return null; for (int i = 0; i < writers.size(); ++ i) { SubmittedValueEntry writer = (SubmittedValueEntry) writers.get(i); if (writer.componentid != null) return writer; String readpath = elmap.getReadPath(writer); while (readpath != null) { SubmittedValueEntry sve = getUpstreamComponent(readpath); if (sve != null) return sve; readpath = PathUtil.getToTailPath(readpath); } } return null; }
/** * Compose a prefix and suffix EL path, where the prefix is already escaped. * Prefix may be empty, but not null. The suffix will become escaped. * * @param prefix path prefix * @param suffix path sufix * @return el path */ public static String composePath(String prefix, String suffix) { CharWrap toappend = new CharWrap(prefix); if (toappend.size != 0) { toappend.append('.'); } composeSegment(toappend, suffix); return toappend.toString(); }
/** * Builds an EL path of from an array of path segments. Particulary good when using * Strings of BeanLocators, Maps, and friends. Assumes none of the segments * have been escaped yet. * * @param segments array of paths * @return el path */ public static String buildPath(String[] segments) { return buildPath(segments, 0, segments.length); }