You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2010/01/22 15:58:54 UTC
svn commit: r902108 - in
/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search:
./ ConditionType.java OrSearchCondition.java SearchCondition.java
SearchContext.java SimpleSearchCondition.java
Author: sergeyb
Date: Fri Jan 22 14:58:54 2010
New Revision: 902108
URL: http://svn.apache.org/viewvc?rev=902108&view=rev
Log:
JAXRS: adding a search extension to be used by regular JAXRS services and by Atom logging
Added:
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/ConditionType.java (with props)
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/OrSearchCondition.java (with props)
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchCondition.java (with props)
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchContext.java (with props)
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SimpleSearchCondition.java (with props)
Added: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/ConditionType.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/ConditionType.java?rev=902108&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/ConditionType.java (added)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/ConditionType.java Fri Jan 22 14:58:54 2010
@@ -0,0 +1,36 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.jaxrs.ext.search;
+
+
+/**
+ * Possisble condition types
+ *
+ */
+public enum ConditionType {
+ EQUALS,
+ LESS_THAN,
+ GREATER_THAN,
+ LESS_OR_EQUALS,
+ GREATER_OR_EQUALS,
+ OR,
+ AND,
+ NOT,
+ CUSTOM
+}
Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/ConditionType.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/ConditionType.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/OrSearchCondition.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/OrSearchCondition.java?rev=902108&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/OrSearchCondition.java (added)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/OrSearchCondition.java Fri Jan 22 14:58:54 2010
@@ -0,0 +1,69 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.jaxrs.ext.search;
+
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Composite 'or' search condition
+ */
+public class OrSearchCondition<T> implements SearchCondition<T> {
+
+ private List<SearchCondition<T>> conditions;
+
+ public OrSearchCondition() {
+
+ }
+
+ public OrSearchCondition(List<SearchCondition<T>> conditions) {
+ this.conditions = conditions;
+ }
+
+ public void setConditions(List<SearchCondition<T>> conditions) {
+ this.conditions = conditions;
+ }
+
+ public boolean isMet(T pojo) {
+ for (SearchCondition<T> sc : conditions) {
+ if (sc.isMet(pojo)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public T getCondition() {
+ return null;
+ }
+
+ public ConditionType getConditionType() {
+ return ConditionType.OR;
+ }
+
+ public List<SearchCondition<T>> getConditions() {
+ return Collections.unmodifiableList(conditions);
+ }
+
+ public List<T> findAll(List<T> pojos) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/OrSearchCondition.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/OrSearchCondition.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchCondition.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchCondition.java?rev=902108&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchCondition.java (added)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchCondition.java Fri Jan 22 14:58:54 2010
@@ -0,0 +1,75 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.jaxrs.ext.search;
+
+import java.util.List;
+
+//CHECKSTYLE:OFF
+/**
+ * Can be used to build plain or complex/composite search conditions.
+ * <p>
+ * Google Collections <a href="http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/base/Predicate.html">Predicate</a>
+ * might've been used instead, but it is a too generic and its apply method is not quite needed here
+ * </p>
+ *
+ * @param <T> Type of the object which will be checked by SearchCondition instance
+ *
+ */
+//CHECKSTYLE:ON
+public interface SearchCondition<T> {
+
+ /**
+ * Checks if the given pojo instance meets this search condition
+ *
+ * @param pojo the object which will be checked
+ * @return true if the pojo meets this search condition, false - otherwise
+ */
+ boolean isMet(T pojo);
+
+ /**
+ * Returns a list of pojos matching the condition
+ * @param pojos list of pojos
+ * @return list of the matching pojos or null if none have been found
+ */
+ List<T> findAll(List<T> pojos);
+
+ /**
+ * Some SearchConditions may use instance of T to capture the actual search criteria
+ * thus making it simpler to implement isMet(T). In some cases, the code which is given
+ * SearchCondition may find it more efficient to directly deal with the captured state
+ * for a more efficient lookup of matching data/records as opposed to calling
+ * SearchCondition.isMet for every instance of T it knows about.
+ *
+ * @return T the captured search criteria, can be null
+ */
+ T getCondition();
+
+ /**
+ * List of conditions this SearchCondition may represent
+ * @return list of conditions, can be null
+ */
+ List<SearchCondition<T>> getConditions();
+
+ /**
+ * Type of condition this SearchCondition represents
+ * @return condition type
+ */
+ ConditionType getConditionType();
+
+}
Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchCondition.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchCondition.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchContext.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchContext.java?rev=902108&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchContext.java (added)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchContext.java Fri Jan 22 14:58:54 2010
@@ -0,0 +1,23 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.jaxrs.ext.search;
+
+public interface SearchContext {
+ <T> SearchCondition<T> getCondition(Class<T> cls);
+}
Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchContext.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchContext.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SimpleSearchCondition.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SimpleSearchCondition.java?rev=902108&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SimpleSearchCondition.java (added)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SimpleSearchCondition.java Fri Jan 22 14:58:54 2010
@@ -0,0 +1,60 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.jaxrs.ext.search;
+
+import java.util.List;
+
+public class SimpleSearchCondition<T> implements SearchCondition<T> {
+
+ private ConditionType cType;
+ private T condition;
+
+ public SimpleSearchCondition(ConditionType cType, T condition) {
+ this.cType = cType;
+ this.condition = condition;
+ }
+
+ public T getCondition() {
+ return condition;
+ }
+
+ public ConditionType getConditionType() {
+ return cType;
+ }
+
+ public List<SearchCondition<T>> getConditions() {
+ return null;
+ }
+
+ public boolean isMet(T pojo) {
+ // not implemented yet
+
+ // we need to get all getters from the condition
+ // and then depending on ConditionType do equals, compare, etc against
+ // corresponding values returned from pojo getters
+
+ return false;
+ }
+
+ public List<T> findAll(List<T> pojos) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SimpleSearchCondition.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SimpleSearchCondition.java
------------------------------------------------------------------------------
svn:keywords = Rev Date