1 /*
2 * Copyright 2001-2008 The Apache Software Foundation.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17
18 package org.apache.juddi.query;
19
20 import java.util.List;
21 import javax.persistence.EntityManager;
22
23 import org.apache.juddi.query.util.DynamicQuery;
24 import org.apache.juddi.query.util.FindQualifiers;
25 import org.uddi.api_v3.Name;
26
27 /**
28 * Returns the list of service keys possessing the Names in the passed Name list.
29 * Output is restricted by list of service keys passed in. If null, all services are searched.
30 * Output is produced by building the appropriate JPA query based on input and find qualifiers.
31 *
32 * From specification:
33 * "This optional collection of string values represents one or more names potentially qualified with xml:lang attributes.
34 * Since "exactMatch" is the default behavior, the value supplied for the name argument must be an exact match. If the "approximateMatch"
35 * findQualifier is used together with an appropriate wildcard character in the name, then any businessService data contained in the specified
36 * businessEntity (or across all businesses if the businessKey is omitted or specified as empty) with matching name value will be returned.
37 * Matching occurs using wildcard matching rules. See Section 5.1.6 About Wildcards. If multiple name values are passed, the match occurs
38 * on a logical OR basis within any names supplied. Each name MAY be marked with an xml:lang adornment. If a language markup is specified,
39 * the search results report a match only on those entries that match both the name value and language criteria. The match on language is a
40 * leftmost case-insensitive comparison of the characters supplied. This allows one to find all services whose name begins with an "A" and are
41 * expressed in any dialect of French, for example. Values which can be passed in the language criteria adornment MUST obey the rules governing
42 * the xml:lang data type as defined in Section 3.3.2.3 name."
43 *
44 * @author <a href="mailto:jfaath@apache.org">Jeff Faath</a>
45 */
46 public class FindServiceByNameQuery {
47
48 public static final String ENTITY_NAME_CHILD = "ServiceName";
49
50 private static final FindEntityByNamesQuery findQuery;
51
52 static {
53 findQuery = new FindEntityByNamesQuery(BusinessServiceQuery.ENTITY_NAME,
54 BusinessServiceQuery.ENTITY_ALIAS,
55 BusinessServiceQuery.KEY_NAME,
56 BusinessServiceQuery.ENTITY_FIELD,
57 ENTITY_NAME_CHILD,
58 BusinessServiceQuery.SIGNATURE_PRESENT);
59 }
60
61 public static List<Object> select(EntityManager em, FindQualifiers fq, List<Name> names, String parentKey, List<Object> keysIn) {
62 if (parentKey != null && parentKey.length() > 0) {
63 DynamicQuery.Parameter param = new DynamicQuery.Parameter(BusinessServiceQuery.ENTITY_ALIAS + "." + BusinessServiceQuery.KEY_NAME_PARENT, parentKey, DynamicQuery.PREDICATE_EQUALS);
64 return findQuery.select(em, fq, names, keysIn, param);
65 }
66 else
67 return findQuery.select(em, fq, names, keysIn);
68
69 }
70
71 }