All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.ocap.application.AppFilter Maven / Gradle / Ivy

There is a newer version: 1.3.1
Show newest version
package org.ocap.application;

import org.dvb.application.AppID;
import org.dvb.application.AppsDatabaseFilter;
import java.util.Enumeration;

/**
 * AppFilter provides a means of filtering AppIDs.  As a
 * subclass of {@link AppsDatabaseFilter}, the method {@link #accept}
 * makes a true/false decision based on an AppID.
 *
 * 

An AppFilter contains a list of zero or more {@link AppPattern}s. Each * AppPattern has the attributes: pattern, action, and * priority. pattern specifies a group of AppIDs with * a pair of ranges for organization ID and application ID. * action specifies an action assigned to the AppID group; * either {@link AppPattern#ALLOW}, {@link AppPattern#DENY}, or {@link * AppPattern#ASK}. priority specifies this AppPattern's * position in the search order: the biggest number comes first. * Applications can insert an AppPattern anywhere in the search * order by using the priority attribute effectively * (AppFilter.add). When two or more AppPatterns in an * AppFilter have the same priority, the search order among them is * undefined. It is not recommendable to use AppPatterns that have the * same priority but different actions. * *

When accept is called, the given AppID is compared to * the AppID group of each AppPattern in the search order until a match * is found. Then, it returns true or false * if the action of matching AppPattern is ALLOW or * DENY respectively. If no match is found, * accept returns true. * *

If the action of matching AppPattern is ASK, then * AppFilter calls AppFilterHandler.accept for the final * decision; the matching AppPattern is handed over to this method. * Applications can specify the AppFilterHandler with * AppFilter.setAskHandler. If no AppFilterHandler is set, * AppFilter returns true. * * *

AppPatterns can have an expiration time and MSO-private * information (expirationTime and info). * accept and getAppPatterns methods ignore * AppPatterns that have expired. The implementation may delete expired * AppPatterns from AppFilter. * *

Example: * *

 * import org.ocap.application.*;
 * import org.dvb.application.AppID;
 *
 * AppManagerProxy am = ...;
 * AppPattern[] patterns = {
 *     /* note that search order is dictated by "priority" */
 *     new AppPattern("10-5f:1-ff", AppPattern.ALLOW, 40),     // #3
 *     new AppPattern("30:2c-34", AppPattern.ALLOW, 100),      // #1
 *     new AppPattern("20-40", AppPattern.DENY, 80),           // #2
 * };
 * AppFilter af = new AppFilter(patterns);
 * 
 * /* false - matches "20-40" */
 * boolean badOne = af.accept(new AppID(0x30, 0x10));
 *
 * /* true - matches "30:2c-34" */
 * boolean goodOne = af.accept(new AppID(0x30, 0x30));
 *
 * /* will be the second entry: priority between 100 and 80 */
 * af.add(new AppPattern("40-4f:1000-1fff", DENY, 90));
 *
 * /* register af with the system */
 * am.setAppFilter(af);
 * 
* * @see AppPattern * @see AppFilterHandler * @see AppManagerProxy * @see org.dvb.application.AppID * @see org.dvb.application.AppsDatabaseFilter */ public class AppFilter extends AppsDatabaseFilter { /** * Constructs an empty AppFilter. */ public AppFilter() { } /** * Constructs an AppFilter with initial AppPatterns. * * @param patterns AppPatterns to constitute an AppFilter. */ public AppFilter(AppPattern[] patterns) { } /** * Returns the AppPatterns in this AppFilter. * * @return the enumeration of AppPatterns. When this AppFilter * has no AppPattern, this method returns an empty Enumeration, * not null. */ public Enumeration getAppPatterns() { return null; } /** * Returns whether this AppFilter accepts the given AppID. * * @param appID an AppID to test. * * @return true if appID passes this * filter. */ public boolean accept(AppID appID) { return true; } /** * Adds an AppPattern to this AppFilter. * * @param pattern the AppPattern to add */ public void add(AppPattern pattern) { } /** * Removes an AppPattern that equals to pattern in this * AppFilter. If this AppFilter does not contain * pattern, it is unchanged. * * @param pattern the AppPattern to remove. * * @return true if the AppFilter contained the * specified AppPattern. * * @see AppPattern#equals */ public boolean remove(AppPattern pattern) { return false; } /** * Sets the handler to call when accept hits an * AppPatterns with action {@link AppPattern#ASK}. * *

If a handler is already registered with this AppFilter, the * new handler replaces it. * * @param handler the handler to set. */ public void setAskHandler(AppFilterHandler handler) { } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy