001/** 002 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 003 * 004 * Copyright (c) 2006 Sun Microsystems Inc. All Rights Reserved 005 * 006 * The contents of this file are subject to the terms 007 * of the Common Development and Distribution License 008 * (the License). You may not use this file except in 009 * compliance with the License. 010 * 011 * You can obtain a copy of the License at 012 * https://opensso.dev.java.net/public/CDDLv1.0.html or 013 * opensso/legal/CDDLv1.0.txt 014 * See the License for the specific language governing 015 * permission and limitations under the License. 016 * 017 * When distributing Covered Code, include this CDDL 018 * Header Notice in each file and include the License file 019 * at opensso/legal/CDDLv1.0.txt. 020 * If applicable, add the following below the CDDL Header, 021 * with the fields enclosed by brackets [] replaced by 022 * your own identifying information: 023 * "Portions Copyrighted [year] [name of copyright owner]" 024 * 025 * $Id: QueryElement.java,v 1.3 2008/06/25 05:43:35 qcheng Exp $ 026 * 027 */ 028 029package com.sun.identity.log; 030 031/** 032 * This class defines each individual query format. 033 * It stores field name, value and relationship between them. 034 * Currently it supports Equal, Not Equal, Greater Than, Lesser Than, 035 * Greater Than Or Equal and Lesser Than Or Equal relationships. 036 * @supported.all.api 037 */ 038public class QueryElement { 039 /** 040 * Invalid Relationship. 041 */ 042 public static final int NV = 0; 043 044 /** 045 * minimum relationship. set to "smallest"; 046 * "GT" in this case. 047 */ 048 private static final int MIN_REL = 1; 049 050 /** 051 * Greater Than Relationship. 052 */ 053 public static final int GT = 1; 054 055 /** 056 * Lesser Than Relationship. 057 */ 058 public static final int LT = 2; 059 060 /** 061 * Equal Relationship. 062 */ 063 public static final int EQ = 3; 064 065 /** 066 * Not Equal Relationship. 067 */ 068 public static final int NE = 4; 069 070 /** 071 * Greater Than or Equal Relationship. 072 */ 073 public static final int GE = 5; 074 075 /** 076 * Lesser Than or Equal Relationship. 077 */ 078 public static final int LE = 6; 079 080 /** 081 * Contains Relationship. 082 */ 083 public static final int CN = 7; 084 085 /** 086 * Starts With Relationship. 087 */ 088 public static final int SW = 8; 089 090 /** 091 * Ends With Relationship. 092 */ 093 public static final int EW = 9; 094 095 /** 096 * maximum relationship. set to "largest", 097 * "EW" in this case 098 */ 099 private static final int MAX_REL = 9; 100 101 /* private fields of the class */ 102 private String fieldName; 103 private String fieldValue; 104 private int relation; 105 106 /**Constructor. 107 * @param fld name of the field to be set. 108 * @param val value of the field to be set. 109 * @param rel relation between field and value to be checked. 110 **/ 111 public QueryElement(String fld, String val, int rel) 112 throws IllegalArgumentException { 113 this.fieldName = fld; 114 this.fieldValue = val; 115 if ((rel >= QueryElement.MIN_REL) && (rel <= QueryElement.MAX_REL)) { 116 this.relation = rel; 117 } else { 118 throw new IllegalArgumentException( 119 "rel param should be >= QueryElement.GT and <= QueryElement.EW"); 120 } 121 } 122 123 /**Default constructor. 124 * Allocates memory for respective items. 125 * All the fields to be set before use. 126 */ 127 public QueryElement() { 128 this.fieldName = new String(); 129 this.fieldValue = new String(); 130 this.relation = QueryElement.EQ; 131 } 132 133 /** 134 * Returns the field name on which query to be applied 135 * 136 * @return field name present in this query element. 137 */ 138 public String getFieldName() { 139 return (fieldName); 140 } 141 142 /** 143 * Returns the value of the field to be compared as stored in the query 144 * element. 145 * 146 * @return value the field to be queried. 147 */ 148 public String getFieldValue() { 149 return (fieldValue); 150 } 151 152 /** 153 * Returns relation to be applied in between field and value 154 * as stored in the query element. 155 * 156 * @return relation the relation between the field and value 157 * to be checked. 158 */ 159 public int getRelation() { 160 return (relation); 161 } 162 163 /** 164 * Sets the field name for this query element. 165 * 166 * @param field field or column name of the log record 167 */ 168 public void setFieldName(String field) { 169 this.fieldName = field; 170 } 171 172 /** 173 * Sets the value for the field name in this query element. 174 * 175 * @param value field or column value of the log record 176 */ 177 public void setFieldValue(String value) { 178 this.fieldValue = value; 179 } 180 181 /** 182 * This method modifies/sets the relation between the field 183 * name and value in this query element. 184 * 185 * @param value relation between field and value to be matched. 186 * @throws IllegalArgumentException if relation is invalid. 187 */ 188 public void setRelation(int value) 189 throws IllegalArgumentException { 190 if ((value >= QueryElement.MIN_REL) && (value <= QueryElement.MAX_REL)) 191 { 192 this.relation = value; 193 } else { 194 throw new IllegalArgumentException( 195 "value should be >= QueryElement.GT and <= QueryElement.EW"); 196 } 197 this.relation = value; 198 } 199}
Copyright © 2010-2017, ForgeRock All Rights Reserved.