1 /*
2 * ====================
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4 *
5 * Copyright 2008-2009 Sun Microsystems, Inc. All rights reserved.
6 *
7 * The contents of this file are subject to the terms of the Common Development
8 * and Distribution License("CDDL") (the "License"). You may not use this file
9 * except in compliance with the License.
10 *
11 * You can obtain a copy of the License at
12 * http://IdentityConnectors.dev.java.net/legal/license.txt
13 * See the License for the specific language governing permissions and limitations
14 * under the License.
15 *
16 * When distributing the Covered Code, include this CDDL Header Notice in each file
17 * and include the License file at identityconnectors/legal/license.txt.
18 * If applicable, add the following below this CDDL Header, with the fields
19 * enclosed by brackets [] replaced by your own identifying information:
20 * "Portions Copyrighted [year] [name of copyright owner]"
21 * ====================
22 */
23 package org.identityconnectors.framework.common.objects.filter;
24
25 import org.identityconnectors.framework.common.objects.Attribute;
26 import org.identityconnectors.framework.common.objects.ConnectorObject;
27
28 /**
29 * Filter based on strings.
30 */
31 public abstract class StringFilter extends SingleValueAttributeFilter {
32
33 /**
34 * Attempts to get a string from the attribute.
35 */
36 StringFilter(Attribute attr) {
37 super(attr);
38 Object val = super.getValue();
39 if (!(val instanceof String)) {
40 final String MSG = "Value must be a string!";
41 throw new IllegalArgumentException(MSG);
42 }
43 }
44
45 /**
46 * Get the string value from the afore mentioned attribute.
47 *
48 * @see SingleValueAttributeFilter#getValue()
49 */
50 public String getValue() {
51 return (String) super.getValue();
52 }
53
54 /**
55 * @throws ClassCastException
56 * iff the value from the {@link ConnectorObject}'s attribute
57 * of the same name as provided is not a string.
58 * @see org.identityconnectors.framework.common.objects.filter.Filter#accept(ConnectorObject)
59 */
60 public boolean accept(ConnectorObject obj) {
61 boolean ret = false;
62 Attribute attr = obj.getAttributeByName(getName());
63 if (attr != null) {
64 ret = accept((String)attr.getValue().get(0));
65 }
66 return ret;
67 }
68
69 public abstract boolean accept(String value);
70 }