001: /*
002: * Copyright 2005 Sun Microsystems, Inc.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.apache.roller.pojos;
018:
019: /**
020: * Represents a user's permissions within a website.
021: *
022: * @ejb:bean name="PermissionsData"
023: * @struts.form include-all="true"
024: * @hibernate.class lazy="false" table="roller_user_permissions"
025: * @hibernate.cache usage="read-write"
026: *
027: * @author Dave Johnson
028: */
029: public class PermissionsData extends PersistentObject {
030: private String id = null;
031: private WebsiteData website = null;
032: private UserData user = null;
033: private boolean pending = true;
034: public static short LIMITED = 0x00; // 0000
035: public static short AUTHOR = 0x01; // 0001
036: public static short ADMIN = 0x03; // 0011
037: private short permissionMask = LIMITED;
038:
039: /** Creates a new instance of PermissionsData */
040: public PermissionsData() {
041: }
042:
043: /**
044: * Check for specific permission.
045: */
046: public boolean has(short priv) {
047: return (getPermissionMask() & priv) == priv;
048: }
049:
050: /**
051: * @ejb:persistent-field
052: * @hibernate.id column="id"
053: * generator-class="uuid.hex" unsaved-value="null"
054: */
055: public String getId() {
056: return id;
057: }
058:
059: /** @ejb:persistent-field */
060: public void setId(String id) {
061: this .id = id;
062: }
063:
064: /**
065: * @hibernate.many-to-one column="website_id" cascade="none" not-null="false"
066: */
067: public WebsiteData getWebsite() {
068: return website;
069: }
070:
071: public void setWebsite(WebsiteData website) {
072: this .website = website;
073: }
074:
075: /**
076: * @hibernate.many-to-one column="user_id" cascade="none" not-null="false"
077: */
078: public UserData getUser() {
079: return user;
080: }
081:
082: public void setUser(UserData user) {
083: this .user = user;
084: }
085:
086: /**
087: * Bit mask that encodes user's permissions in website.
088: * @ejb:persistent-field
089: * @hibernate.property column="permission_mask" non-null="true" unique="false"
090: */
091: public short getPermissionMask() {
092: return permissionMask;
093: }
094:
095: /** @ejb:persistent-field */
096: public void setPermissionMask(short permissionMask) {
097: this .permissionMask = permissionMask;
098: }
099:
100: /**
101: * True if user has been invited to join site but has not yet accepted.
102: * And false if user is member of website.
103: * @ejb:persistent-field
104: * @hibernate.property column="pending" non-null="true" unique="false"
105: */
106: public boolean isPending() {
107: return pending;
108: }
109:
110: /** @ejb:persistent-field */
111: public void setPending(boolean pending) {
112: this .pending = pending;
113: }
114:
115: /**
116: * Set data from other object (no-op).
117: */
118: public void setData(PersistentObject vo) {
119: // no-op
120: }
121: }
|