1
/*___INFO__MARK_BEGIN__*/
2
/*************************************************************************
4
* The Contents of this file are made available subject to the terms of
5
* the Sun Industry Standards Source License Version 1.2
7
* Sun Microsystems Inc., March, 2001
10
* Sun Industry Standards Source License Version 1.2
11
* =================================================
12
* The contents of this file are subject to the Sun Industry Standards
13
* Source License Version 1.2 (the "License"); You may not use this file
14
* except in compliance with the License. You may obtain a copy of the
15
* License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
17
* Software provided under this License is provided on an "AS IS" basis,
18
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
19
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
20
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
21
* See the License for the specific provisions governing your rights and
22
* obligations concerning the Software.
24
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
26
* Copyright: 2001 by Sun Microsystems, Inc.
28
* All Rights Reserved.
30
************************************************************************/
31
/*___INFO__MARK_END__*/
32
package com.sun.grid.cull;
34
import java.util.HashSet;
35
import java.util.List;
37
import java.util.logging.Level;
38
import java.util.logging.Logger;
43
public class CullDefinitionFilter {
45
private static Logger logger = Logger.getLogger("cullconv");
47
private String [] includes;
48
private String [] excludes;
49
private String objectFilter;
50
private boolean printDependencies;
53
/** Creates a new instance of CullDefinitionFilter */
54
public CullDefinitionFilter(String [] includes, String [] excludes) {
55
this.includes = includes;
56
this.excludes = excludes;
59
public java.util.Set getObjectNames(CullDefinition cullDef) {
61
Set orgSet = cullDef.getObjectNames();
62
HashSet filteredCullObjectNameSet = new HashSet();
64
if( this.includes == null || this.includes.length == 0 ) {
65
filteredCullObjectNameSet.addAll(orgSet);
68
for(int i = 0; i < includes.length; i++) {
69
if( orgSet.contains(includes[i]) ) {
70
filteredCullObjectNameSet.add(includes[i]);
75
if( this.excludes != null && this.excludes.length > 0 ) {
76
for(int i = 0; i < excludes.length; i++ ) {
77
filteredCullObjectNameSet.remove(excludes[i]);
81
if(isPrintDependencies()) {
82
logger.info("dependencies --------------------------------------");
83
logger.info("object filter = '" + getObjectFilter() + "'" );
85
CullDependencies depend = new CullDependencies(cullDef, filteredCullObjectNameSet, getObjectFilter());
87
String [] names = new String[filteredCullObjectNameSet.size()];
88
filteredCullObjectNameSet.toArray(names);
89
for(int i = 0; i < names.length; i++ ) {
91
CullDependencies.Node node = depend.getNode(names[i]);
93
logger.warning("node for obj " + names[i] + " not found");
96
boolean isNeeded = node.isNeeded();
98
if(isPrintDependencies()) {
99
logger.info(node.toString());
100
} else if( logger.isLoggable(Level.FINE ) ) {
101
logger.fine(node.toString());
105
filteredCullObjectNameSet.remove(names[i]);
109
if(filteredCullObjectNameSet.isEmpty()) {
110
logger.warning("No cull object matches the objectFilter '" + getObjectFilter() + "'");
112
return filteredCullObjectNameSet;
115
public String getObjectFilter() {
119
public void setObjectFilter(String objectFilter) {
120
this.objectFilter = objectFilter;
123
public boolean isPrintDependencies() {
124
return printDependencies;
127
public void setPrintDependencies(boolean printDependencies) {
128
this.printDependencies = printDependencies;