4740 |
05 Feb 09 |
nicklas |
1 |
/** |
4740 |
05 Feb 09 |
nicklas |
$Id$ |
4740 |
05 Feb 09 |
nicklas |
3 |
|
4740 |
05 Feb 09 |
nicklas |
Copyright (C) 2008 Nicklas Nordborg |
4740 |
05 Feb 09 |
nicklas |
5 |
|
4740 |
05 Feb 09 |
nicklas |
This file is part of BASE - BioArray Software Environment. |
4740 |
05 Feb 09 |
nicklas |
Available at http://base.thep.lu.se/ |
4740 |
05 Feb 09 |
nicklas |
8 |
|
4740 |
05 Feb 09 |
nicklas |
BASE is free software; you can redistribute it and/or |
4740 |
05 Feb 09 |
nicklas |
modify it under the terms of the GNU General Public License |
4740 |
05 Feb 09 |
nicklas |
as published by the Free Software Foundation; either version 3 |
4740 |
05 Feb 09 |
nicklas |
of the License, or (at your option) any later version. |
4740 |
05 Feb 09 |
nicklas |
13 |
|
4740 |
05 Feb 09 |
nicklas |
BASE is distributed in the hope that it will be useful, |
4740 |
05 Feb 09 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
4740 |
05 Feb 09 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4740 |
05 Feb 09 |
nicklas |
GNU General Public License for more details. |
4740 |
05 Feb 09 |
nicklas |
18 |
|
4740 |
05 Feb 09 |
nicklas |
You should have received a copy of the GNU General Public License |
4740 |
05 Feb 09 |
nicklas |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
4740 |
05 Feb 09 |
nicklas |
21 |
*/ |
4740 |
05 Feb 09 |
nicklas |
22 |
package net.sf.basedb.util.overview.validator; |
4740 |
05 Feb 09 |
nicklas |
23 |
|
4740 |
05 Feb 09 |
nicklas |
24 |
import net.sf.basedb.core.DbControl; |
4740 |
05 Feb 09 |
nicklas |
25 |
import net.sf.basedb.util.overview.Fix; |
4740 |
05 Feb 09 |
nicklas |
26 |
import net.sf.basedb.util.overview.OverviewContext; |
4740 |
05 Feb 09 |
nicklas |
27 |
import net.sf.basedb.util.overview.Validator; |
4740 |
05 Feb 09 |
nicklas |
28 |
import net.sf.basedb.util.overview.Node; |
4740 |
05 Feb 09 |
nicklas |
29 |
|
4740 |
05 Feb 09 |
nicklas |
30 |
/** |
4740 |
05 Feb 09 |
nicklas |
A simple node validation implementation that takes care of missing |
4740 |
05 Feb 09 |
nicklas |
and denied access to items. This implementation will create |
4740 |
05 Feb 09 |
nicklas |
child nodes for items that we are denied access to but not to |
4740 |
05 Feb 09 |
nicklas |
missing items. Missing items are reported as failures to the |
4740 |
05 Feb 09 |
nicklas |
parent node. Denied access are reported as failures to the node |
4740 |
05 Feb 09 |
nicklas |
representing the item. |
4740 |
05 Feb 09 |
nicklas |
37 |
|
4740 |
05 Feb 09 |
nicklas |
@author Nicklas |
4740 |
05 Feb 09 |
nicklas |
@version 2.10 |
4740 |
05 Feb 09 |
nicklas |
@base.modified $Date$ |
4740 |
05 Feb 09 |
nicklas |
41 |
*/ |
4740 |
05 Feb 09 |
nicklas |
42 |
public abstract class BasicNodeValidator<I> |
4740 |
05 Feb 09 |
nicklas |
43 |
implements NodeValidator<I> |
4740 |
05 Feb 09 |
nicklas |
44 |
{ |
4740 |
05 Feb 09 |
nicklas |
45 |
|
4740 |
05 Feb 09 |
nicklas |
46 |
private Validator ruleMissing; |
4740 |
05 Feb 09 |
nicklas |
47 |
private Validator ruleDenied; |
4740 |
05 Feb 09 |
nicklas |
48 |
|
4740 |
05 Feb 09 |
nicklas |
49 |
/** |
4740 |
05 Feb 09 |
nicklas |
Creates a new validator. |
4740 |
05 Feb 09 |
nicklas |
@param ruleMissing The validation rule that is broken if an item is missing, |
4740 |
05 Feb 09 |
nicklas |
or null to not report missing items as a failure |
4740 |
05 Feb 09 |
nicklas |
@param ruleDenied The validation rule that is broken if we are denied access |
4740 |
05 Feb 09 |
nicklas |
to an item, or null to not report this as a failure |
4740 |
05 Feb 09 |
nicklas |
55 |
*/ |
4740 |
05 Feb 09 |
nicklas |
56 |
public BasicNodeValidator(Validator ruleMissing, Validator ruleDenied) |
4740 |
05 Feb 09 |
nicklas |
57 |
{ |
4740 |
05 Feb 09 |
nicklas |
58 |
this.ruleDenied = ruleDenied; |
4740 |
05 Feb 09 |
nicklas |
59 |
this.ruleMissing = ruleMissing; |
4740 |
05 Feb 09 |
nicklas |
60 |
} |
4740 |
05 Feb 09 |
nicklas |
61 |
|
4740 |
05 Feb 09 |
nicklas |
62 |
/* |
4740 |
05 Feb 09 |
nicklas |
From the NodeValidator interface |
4740 |
05 Feb 09 |
nicklas |
64 |
-------------------------------- |
4740 |
05 Feb 09 |
nicklas |
65 |
*/ |
4740 |
05 Feb 09 |
nicklas |
66 |
/** |
4740 |
05 Feb 09 |
nicklas |
Submits the {@link #ruleMissing} validator to the context as a failure |
4740 |
05 Feb 09 |
nicklas |
unless it is null. |
4740 |
05 Feb 09 |
nicklas |
@return Always false |
4740 |
05 Feb 09 |
nicklas |
70 |
*/ |
4740 |
05 Feb 09 |
nicklas |
71 |
@Override |
4740 |
05 Feb 09 |
nicklas |
72 |
public boolean preMissingItem(DbControl dc, OverviewContext context, Node parentNode) |
4740 |
05 Feb 09 |
nicklas |
73 |
{ |
4740 |
05 Feb 09 |
nicklas |
74 |
if (ruleMissing != null) |
4740 |
05 Feb 09 |
nicklas |
75 |
{ |
5651 |
08 Jun 11 |
nicklas |
76 |
context.createFailure(ruleMissing, parentNode, null, getMissingItemFix(dc, parentNode)); |
4740 |
05 Feb 09 |
nicklas |
77 |
} |
4740 |
05 Feb 09 |
nicklas |
78 |
return false; |
4740 |
05 Feb 09 |
nicklas |
79 |
} |
4740 |
05 Feb 09 |
nicklas |
80 |
|
4740 |
05 Feb 09 |
nicklas |
81 |
/** |
4740 |
05 Feb 09 |
nicklas |
@return Always true |
4740 |
05 Feb 09 |
nicklas |
83 |
*/ |
4740 |
05 Feb 09 |
nicklas |
84 |
@Override |
4740 |
05 Feb 09 |
nicklas |
85 |
public boolean preDeniedItem(DbControl dc, OverviewContext context, Node parentNode) |
4740 |
05 Feb 09 |
nicklas |
86 |
{ |
4740 |
05 Feb 09 |
nicklas |
87 |
return true; |
4740 |
05 Feb 09 |
nicklas |
88 |
} |
4740 |
05 Feb 09 |
nicklas |
89 |
|
4740 |
05 Feb 09 |
nicklas |
90 |
/** |
4740 |
05 Feb 09 |
nicklas |
Subclasses should override this method if the need more validation for an |
4740 |
05 Feb 09 |
nicklas |
existing and accessible item. |
4740 |
05 Feb 09 |
nicklas |
@return Always true |
4740 |
05 Feb 09 |
nicklas |
94 |
*/ |
4740 |
05 Feb 09 |
nicklas |
95 |
@Override |
4740 |
05 Feb 09 |
nicklas |
96 |
public boolean preValidate(DbControl dc, OverviewContext context, I item, Node parentNode) |
4740 |
05 Feb 09 |
nicklas |
97 |
{ |
4740 |
05 Feb 09 |
nicklas |
98 |
return true; |
4740 |
05 Feb 09 |
nicklas |
99 |
} |
4740 |
05 Feb 09 |
nicklas |
100 |
|
4740 |
05 Feb 09 |
nicklas |
101 |
/** |
4740 |
05 Feb 09 |
nicklas |
Do nothing. |
4740 |
05 Feb 09 |
nicklas |
103 |
*/ |
4740 |
05 Feb 09 |
nicklas |
104 |
@Override |
4740 |
05 Feb 09 |
nicklas |
105 |
public void postMissingItem(DbControl dc, OverviewContext context, Node node, Node parentNode) |
4740 |
05 Feb 09 |
nicklas |
106 |
{} |
4740 |
05 Feb 09 |
nicklas |
107 |
|
4740 |
05 Feb 09 |
nicklas |
108 |
/** |
4740 |
05 Feb 09 |
nicklas |
Submits the {@link #ruleDenied} validator to the context as a failure |
4740 |
05 Feb 09 |
nicklas |
unless it is null. |
4740 |
05 Feb 09 |
nicklas |
111 |
*/ |
4740 |
05 Feb 09 |
nicklas |
112 |
@Override |
4740 |
05 Feb 09 |
nicklas |
113 |
public void postDeniedItem(DbControl dc, OverviewContext context, Node node, Node parentNode) |
4740 |
05 Feb 09 |
nicklas |
114 |
{ |
4740 |
05 Feb 09 |
nicklas |
115 |
if (ruleDenied != null) |
4740 |
05 Feb 09 |
nicklas |
116 |
{ |
5651 |
08 Jun 11 |
nicklas |
117 |
context.createFailure(ruleDenied, node, null, getDeniedItemFix(dc, node, parentNode)); |
4740 |
05 Feb 09 |
nicklas |
118 |
} |
4740 |
05 Feb 09 |
nicklas |
119 |
} |
4740 |
05 Feb 09 |
nicklas |
120 |
|
4740 |
05 Feb 09 |
nicklas |
121 |
/** |
4740 |
05 Feb 09 |
nicklas |
Do nothing. Subclasses should override this method if they need more validation for an |
4740 |
05 Feb 09 |
nicklas |
existing and accessible item. |
4740 |
05 Feb 09 |
nicklas |
124 |
*/ |
4740 |
05 Feb 09 |
nicklas |
125 |
@Override |
4740 |
05 Feb 09 |
nicklas |
126 |
public void postValidate(DbControl dc, OverviewContext context, Node node, Node parentNode) |
4740 |
05 Feb 09 |
nicklas |
127 |
{} |
4740 |
05 Feb 09 |
nicklas |
128 |
|
4740 |
05 Feb 09 |
nicklas |
129 |
/** |
4740 |
05 Feb 09 |
nicklas |
Do nothing. Subclasses should override this method if they need to validate all items |
4740 |
05 Feb 09 |
nicklas |
inside a folder-type node. |
4740 |
05 Feb 09 |
nicklas |
132 |
*/ |
4740 |
05 Feb 09 |
nicklas |
133 |
@Override |
4740 |
05 Feb 09 |
nicklas |
134 |
public void postValidateFolder(DbControl dc, OverviewContext context, Node folderNode, Node parentNode) |
4740 |
05 Feb 09 |
nicklas |
135 |
{} |
4740 |
05 Feb 09 |
nicklas |
136 |
// ----------------------------------- |
4740 |
05 Feb 09 |
nicklas |
137 |
|
4740 |
05 Feb 09 |
nicklas |
138 |
/** |
4740 |
05 Feb 09 |
nicklas |
Subclasses should override this method if they have a suggessted fix |
4740 |
05 Feb 09 |
nicklas |
for a missing item problem. The default implementation does nothing, |
4740 |
05 Feb 09 |
nicklas |
but the following template may be usable by most subclasses: |
4740 |
05 Feb 09 |
nicklas |
<pre class="code"> |
4740 |
05 Feb 09 |
nicklas |
new Fix("Add item to parent", parentNode.getItem()) |
4740 |
05 Feb 09 |
nicklas |
</pre> |
4740 |
05 Feb 09 |
nicklas |
145 |
*/ |
5651 |
08 Jun 11 |
nicklas |
146 |
protected abstract Fix getMissingItemFix(DbControl dc, Node parentNode); |
4740 |
05 Feb 09 |
nicklas |
147 |
|
4740 |
05 Feb 09 |
nicklas |
148 |
/** |
4740 |
05 Feb 09 |
nicklas |
Subclasses should override this method if they have a suggessted fix |
4740 |
05 Feb 09 |
nicklas |
for an access denied problem. The default implementation does nothing. |
4740 |
05 Feb 09 |
nicklas |
151 |
*/ |
5651 |
08 Jun 11 |
nicklas |
152 |
protected Fix getDeniedItemFix(DbControl dc, Node node, Node parentNode) |
4740 |
05 Feb 09 |
nicklas |
153 |
{ |
4740 |
05 Feb 09 |
nicklas |
154 |
return null; |
4740 |
05 Feb 09 |
nicklas |
155 |
} |
4740 |
05 Feb 09 |
nicklas |
156 |
} |