/** * Get the device belonging to some communication status resource. Only devices with standard OGEMA device types * are reported, custom types are ignored. * @param status * @param filterCustomTypes * if true, only devices with standard OGEMA device types are reported, custom types are ignored. * @return * the list of deviecs found that belong to the status resource. */ public static List<PhysicalElement> getDevices(final CommunicationStatus status, final boolean filterCustomTypes) { return ResourceUtils.getContextResources(status, PhysicalElement.class, false, filterCustomTypes ? Pattern.compile("^org\\.ogema\\.") : null, null); }
/** * Get all context resource of the specified type. The following conditions define 'context resources': * <ul> * <li>subresources of this resource of the specified type * <li>subresources of some parent resource of the specified type * <li>subresources of some resource that references this resource (respectively, subresource of a parent of the referencing node), of the specified type * </ul> * If the inclusive parameter is false, then the first matches to one of the three conditions above are returned. If inclusive is true, * then the matches for all conditions are returned.<br> * * Note that this method may be quite expensive, depending on the complexity of the resource tree of the passed resource and its * referencing nodes. * * @param target * @param targetType * @param inclusive * if true, the search will continue even when the first matches have been found, otherwise it breaks * @return * never null * @throws NullPointerException if targetType is null */ public static <R extends Resource> List<R> getContextResources(final Resource target, final Class<R> targetType, final boolean inclusive) { return getContextResources(target, targetType, inclusive, null, null); }
/** * Get the first matching context resource of the specified type. See {@link #getContextResources(Resource, Class, boolean)}. * @param target * @param targetType * @param typePattern * restrict to resources whose type matches the pattern; may be null * @param namePattern * restrict to resources whose name matches the pattern; may be null * @return * A matching context resource, or null if none was found. * @throws NullPointerException if targetType is null */ public static <R extends Resource> R getFirstContextResource(final Resource target, final Class<R> targetType, final Pattern typePattern, final Pattern namePattern) { final List<R> resources = getContextResources(target, targetType, false, typePattern, namePattern); return !resources.isEmpty() ? resources.get(0) : null; }
if (target == null) return Collections.emptyList(); return getContextResources(target, targetType, inclusive, true, typePattern, namePattern);
result.addAll(getContextResources(ref, targetType, inclusive, false, typePattern, namePattern));