001: /******************************************************************************
002: * JBoss, a division of Red Hat *
003: * Copyright 2006, Red Hat Middleware, LLC, and individual *
004: * contributors as indicated by the @authors tag. See the *
005: * copyright.txt in the distribution for a full listing of *
006: * individual contributors. *
007: * *
008: * This is free software; you can redistribute it and/or modify it *
009: * under the terms of the GNU Lesser General Public License as *
010: * published by the Free Software Foundation; either version 2.1 of *
011: * the License, or (at your option) any later version. *
012: * *
013: * This software is distributed in the hope that it will be useful, *
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
016: * Lesser General Public License for more details. *
017: * *
018: * You should have received a copy of the GNU Lesser General Public *
019: * License along with this software; if not, write to the Free *
020: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
021: * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
022: ******************************************************************************/package org.jboss.portal.server.request;
023:
024: /**
025: * URL information that does not belong to the url value itself but rather to the context it represents for this URL.
026: *
027: * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
028: * @version $Revision: 8784 $
029: */
030: public final class URLContext {
031:
032: /** Mask for secure bit. */
033: public static final int SEC_MASK = 0x01;
034:
035: /** Mask for authenticated bit. */
036: public static final int AUTH_MASK = 0x02;
037:
038: /** . */
039: private final int mask;
040:
041: /** . */
042: private final boolean secure;
043:
044: /** . */
045: private final boolean authenticated;
046:
047: /** . */
048: private static final URLContext[] contexts = new URLContext[] {
049: new URLContext(false, false), new URLContext(true, false),
050: new URLContext(false, true), new URLContext(true, true), };
051:
052: private URLContext(boolean secure, boolean authenticated) {
053: this .mask = (secure ? SEC_MASK : 0)
054: | (authenticated ? AUTH_MASK : 0);
055: this .secure = secure;
056: this .authenticated = authenticated;
057: }
058:
059: public boolean isSecure() {
060: return secure;
061: }
062:
063: public boolean isAuthenticated() {
064: return authenticated;
065: }
066:
067: public URLContext withSecured(Boolean wantSecure) {
068: if (wantSecure == null) {
069: return this ;
070: } else if (Boolean.TRUE == wantSecure) {
071: return asSecured();
072: } else {
073: return asNonSecured();
074: }
075: }
076:
077: public URLContext asSecured() {
078: int newMask = mask | SEC_MASK;
079: return contexts[newMask];
080: }
081:
082: public URLContext asNonSecured() {
083: int newMask = mask & ~SEC_MASK;
084: return contexts[newMask];
085: }
086:
087: public URLContext withAuthenticated(Boolean wantAuthenticated) {
088: if (wantAuthenticated == null) {
089: return this ;
090: } else if (Boolean.TRUE == wantAuthenticated) {
091: return asAuthenticated();
092: } else {
093: return asNonAuthenticated();
094: }
095: }
096:
097: public URLContext asAuthenticated() {
098: int newMask = mask | AUTH_MASK;
099: return contexts[newMask];
100: }
101:
102: public URLContext asNonAuthenticated() {
103: int newMask = mask & ~AUTH_MASK;
104: return contexts[newMask];
105: }
106:
107: public int getMask() {
108: return mask;
109: }
110:
111: public static URLContext newInstance(int mask) {
112: return contexts[mask];
113: }
114:
115: public static URLContext newInstance(boolean secure,
116: boolean authenticated) {
117: int mask = (secure ? SEC_MASK : 0)
118: | (authenticated ? AUTH_MASK : 0);
119: return contexts[mask];
120: }
121: }
|