001package org.apache.archiva.redback.rbac.memory;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 * http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import org.apache.archiva.redback.rbac.Operation;
023import org.apache.archiva.redback.rbac.Resource;
024import org.apache.archiva.redback.rbac.Permission;
025
026/**
027 * MemoryPermission 
028 *
029 * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
030 *
031 */
032public class MemoryPermission
033    implements Permission, java.io.Serializable
034{
035
036    /**
037     * Field name
038     */
039    private String name;
040
041    /**
042     * Field description
043     */
044    private String description;
045
046    /**
047     * Field operation
048     */
049    private MemoryOperation operation;
050
051    /**
052     * Field resource
053     */
054    private MemoryResource resource;
055    
056    /**
057     * Field permanent
058     */
059    private boolean permanent = false;
060
061    /**
062     * Method equals
063     * 
064     * @param other
065     */
066    public boolean equals( Object other )
067    {
068        if ( this == other )
069        {
070            return true;
071        }
072
073        if ( !( other instanceof MemoryPermission ) )
074        {
075            return false;
076        }
077
078        MemoryPermission that = (MemoryPermission) other;
079        boolean result = true;
080        result = result && ( getName() == null ? that.getName() == null : getName().equals( that.getName() ) );
081        return result;
082    }
083
084    /**
085     * Get null
086     */
087    public String getDescription()
088    {
089        return this.description;
090    }
091
092    /**
093     * Get null
094     */
095    public String getName()
096    {
097        return this.name;
098    }
099
100    /**
101     * Get null
102     */
103    public Operation getOperation()
104    {
105        return (Operation) this.operation;
106    }
107
108    /**
109     * Get null
110     */
111    public Resource getResource()
112    {
113        return (Resource) this.resource;
114    }
115
116    /**
117     * Method hashCode
118     */
119    public int hashCode()
120    {
121        int result = 17;
122        result = 37 * result + ( name != null ? name.hashCode() : 0 );
123        return result;
124    }
125
126    /**
127     * Set null
128     * 
129     * @param description
130     */
131    public void setDescription( String description )
132    {
133        this.description = description;
134    }
135
136    /**
137     * Set null
138     * 
139     * @param name
140     */
141    public void setName( String name )
142    {
143        this.name = name;
144    }
145
146    /**
147     * Set null
148     * 
149     * @param operation
150     */
151    public void setOperation( Operation operation )
152    {
153        if ( !( operation instanceof Operation ) )
154        {
155            throw new ClassCastException( "MemoryPermission.setOperation(operation) parameter must be instanceof "
156                + Operation.class.getName() );
157        }
158        this.operation = (MemoryOperation) operation;
159    }
160
161    /**
162     * Set null
163     * 
164     * @param resource
165     */
166    public void setResource( Resource resource )
167    {
168        if ( !( resource instanceof Resource ) )
169        {
170            throw new ClassCastException( "MemoryPermission.setResource(resource) parameter must be instanceof "
171                + Resource.class.getName() );
172        }
173        this.resource = (MemoryResource) resource;
174    }
175
176    /**
177     * Method toString
178     */
179    public String toString()
180    {
181        StringBuilder buf = new StringBuilder();
182        buf.append( "name = '" );
183        buf.append( getName() + "'" );
184        return buf.toString();
185    }
186
187    public boolean isPermanent()
188    {
189        return permanent;
190    }
191
192    public void setPermanent( boolean permanent )
193    {
194        this.permanent = permanent;
195    }
196}