001    /*
002     * Copyright 2005-2007 The Kuali Foundation
003     *
004     *
005     * Licensed under the Educational Community License, Version 2.0 (the "License");
006     * you may not use this file except in compliance with the License.
007     * You may obtain a copy of the License at
008     *
009     * http://www.opensource.org/licenses/ecl2.php
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    package org.kuali.rice.kew.rule;
018    
019    import java.util.ArrayList;
020    import java.util.Collections;
021    import java.util.List;
022    
023    import org.kuali.rice.kew.engine.RouteContext;
024    import org.kuali.rice.kew.identity.PrincipalId;
025    
026    
027    /**
028     * RoleAttribute that exposes an INITIATOR abstract role which resolves to the
029     * initiator of the document.
030     *
031     * @author Kuali Rice Team (rice.collab@kuali.org)
032     */
033    public class InitiatorRoleAttribute extends UnqualifiedRoleAttribute {
034        private static final String INITIATOR_ROLE_KEY = "INITIATOR";
035        private static final String INITIATOR_ROLE_LABEL = "Initiator";
036    
037        private static final Role ROLE = new Role(InitiatorRoleAttribute.class, INITIATOR_ROLE_KEY, INITIATOR_ROLE_LABEL);
038        private static final List<Role> ROLES;
039        static {
040            ArrayList<Role> roles = new ArrayList<Role>(1);
041            roles.add(ROLE);
042            ROLES = Collections.unmodifiableList(roles);
043        }
044    
045        public InitiatorRoleAttribute() {
046            super(ROLES);
047        }
048    
049        public ResolvedQualifiedRole resolveRole(RouteContext routeContext, String roleName) {
050            List members = new ArrayList(1);
051            members.add(new PrincipalId(routeContext.getDocument().getInitiatorWorkflowId()));
052            return new ResolvedQualifiedRole(INITIATOR_ROLE_LABEL, members);
053        }
054    }