001: /*
002: * Copyright 2002 Sun Microsystems, Inc. All
003: * rights reserved. Use of this product is subject
004: * to license terms. Federal Acquisitions:
005: * Commercial Software -- Government Users
006: * Subject to Standard License Terms and
007: * Conditions.
008: *
009: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
010: * are trademarks or registered trademarks of Sun Microsystems,
011: * Inc. in the United States and other countries.
012: */
013:
014: package com.sun.portal.providers.context;
015:
016: import java.util.List;
017: import java.util.Iterator;
018: import java.util.ArrayList;
019: import java.util.Set;
020: import java.util.Collections;
021:
022: /**
023: * This class implements the "client" filter.
024: */
025: public class ClientPropertiesFilter extends PropertiesFilter {
026:
027: private static final String PARENTCLIENTS = "parentId";
028:
029: /**
030: * Constructor. Do not call this directly. Instead use
031: * <code>PropertiesFilterFactory.get(CLIENT_PROPERTIESFILTER_CLASSNAME, ...)</code>.
032: *
033: * @see PropertiesFilterFactory#get(String, String, boolean)
034: */
035: public ClientPropertiesFilter() {
036: super ();
037: }
038:
039: /**
040: * CACHING IS DISABLED FOR NOW.
041: *
042: * Return <code>true</code>.
043: *
044: * @return <code>true</code>
045: *
046: public boolean isCachable() {
047: return true;
048: }
049: */
050:
051: /**
052: * Return "<code>client</code>"
053: *
054: * @return "<code>client</code>"
055: */
056: public String getCondition() {
057: return "client";
058: }
059:
060: /**
061: * Does the given condition and value match this client filter?
062: * This match method is based on a case-sensitive string comparison.
063: *
064: * In other words, the condition should be "client" and value should
065: * exactly match the value that was used to instantiate this filter.
066: *
067: * @param condition filter condition. i.e. "client"
068: * @param value client type
069: * @return boolean value indicating whether match has succeeded or not.
070: */
071: public boolean match(String condition, String value) {
072: return condition.toLowerCase().equals("client")
073: && getValue().equals(value);
074: }
075:
076: /**
077: * A convenience method for getting a list of
078: * <code>ClientPropertiesFilters</code> for the given client.
079: *
080: * @param context provider context
081: * @param clientType client type string
082: * @param required boolean value that determines whether the filters are
083: * required or optional
084: * @return List of <code>ClientPropertiesFilter</code>s
085: */
086: public static List getClientFilters(ProviderContext context,
087: String clientType, boolean required)
088: throws PropertiesFilterException {
089: List filters = new ArrayList();
090: filters
091: .add(PropertiesFilterFactory
092: .get(
093: PropertiesFilterFactory.CLIENT_PROPERTIESFILTER_CLASSNAME,
094: clientType, required));
095: Set parents = getClientParents(context, clientType);
096: if (parents != null) {
097: for (Iterator pi = parents.iterator(); pi.hasNext();) {
098: filters
099: .add(PropertiesFilterFactory
100: .get(
101: PropertiesFilterFactory.CLIENT_PROPERTIESFILTER_CLASSNAME,
102: (String) pi.next(), required));
103: }
104: }
105:
106: //
107: // order it from the least-specific to the most-specific
108: //
109: Collections.reverse(filters);
110:
111: return filters;
112:
113: }
114:
115: /**
116: * A convenience method for getting a list of
117: * <code>ClientPropertiesFilters</code> for the client based on the given
118: * context.
119: *
120: * @param context provider context
121: * @param required boolean value that determines whether the filters are
122: * required or optional
123: * @return List of <code>ClientPropertiesFilter</code>s
124: */
125: public static List getClientFilters(ProviderContext context,
126: boolean required) throws PropertiesFilterException {
127:
128: return getClientFilters(context, context.getClientType(),
129: required);
130:
131: }
132:
133: /**
134: * Gets the set of parents for the specified client.
135: * @param context provider context
136: * @param clientType client type string
137: * @return Set of parent strings for the client
138: */
139: public static Set getClientParents(ProviderContext context,
140: String clientType) {
141: return context.getClientTypeProperties(clientType,
142: PARENTCLIENTS);
143: }
144:
145: /**
146: * Gets the set of parents for the client based on the context.
147: * @param context provider context
148: * @return Set of parent strings for the client
149: */
150: public static Set getClientParents(ProviderContext context) {
151: return getClientParents(context, context.getClientType());
152: }
153:
154: }
|