01: /* Copyright 2005 The JA-SIG Collaborative. All rights reserved.
02: * See license distributed with this file and
03: * available online at http://www.uportal.org/license.html
04: */
05:
06: package org.jasig.portal.layout.dlm;
07:
08: import org.jasig.portal.layout.UserLayoutStoreFactory;
09:
10: /**
11: * @version $Revision: 35755 $ $Date: 2005-05-04 12:54:01 -0700 (Wed, 04 May 2005) $
12: * @since uPortal 2.5
13: */
14: public final class Precedence {
15: public static final String RCS_ID = "@(#) $Header$";
16:
17: private double precedence = 0.0;
18: private int index = -1;
19: private static Precedence userPrecedence = new Precedence();
20:
21: private Precedence() {
22: }
23:
24: static Precedence newInstance(String fragmentIdx) {
25: if (fragmentIdx == null || fragmentIdx.equals(""))
26: return userPrecedence;
27: return new Precedence(fragmentIdx);
28: }
29:
30: public String toString() {
31: return "p[" + precedence + ", " + index + "]";
32: }
33:
34: private Precedence(String fragmentIdx) {
35: int fragmentIndex = 0;
36: try {
37: fragmentIndex = Integer.parseInt(fragmentIdx);
38: } catch (Exception e) {
39: // if unparsable default to lowest priority.
40: return;
41: }
42:
43: RDBMDistributedLayoutStore dls = (RDBMDistributedLayoutStore) UserLayoutStoreFactory
44: .getUserLayoutStoreImpl();
45:
46: this .precedence = dls.getFragmentPrecedence(fragmentIndex);
47: this .index = fragmentIndex;
48: }
49:
50: /**
51: Returns true of this complete precedence is less than the complete
52: precedence of the passed in Precedence object. The complete
53: precedence takes into account the location in the configuration
54: file of the fragment definition. If the "precedence" value is
55: equal then the precedence object with the lowest index has the
56: higher complete precedence. And index of -1 indicates the highest
57: index in the file.
58: */
59: public boolean isLessThan(Precedence p) {
60: if (this .precedence < p.precedence
61: || (this .precedence == p.precedence && (this .index == -1
62: && p.index > -1 || this .index > p.index)))
63: return true;
64: return false;
65: }
66:
67: public boolean isEqualTo(Precedence p) {
68: return this .precedence == p.precedence;
69: }
70:
71: public static Precedence getUserPrecedence() {
72: return userPrecedence;
73: }
74: }
|