| 1 | /******************************************************************************* | 
| 2 |  * Copyright (c) 2009 IBM Corporation and others. | 
| 3 |  * All rights reserved. This program and the accompanying materials | 
| 4 |  * are made available under the terms of the Eclipse Public License v1.0 | 
| 5 |  * which accompanies this distribution, and is available at | 
| 6 |  * http://www.eclipse.org/legal/epl-v10.html | 
| 7 |  * | 
| 8 |  * Contributors: | 
| 9 |  *     IBM Corporation - initial API and implementation | 
| 10 |  *******************************************************************************/ | 
| 11 | package org.eclipse.pde.api.tools.internal; | 
| 12 |   | 
| 13 | import org.eclipse.pde.api.tools.internal.provisional.IApiAccess; | 
| 14 |   | 
| 15 | /** | 
| 16 |  * Default implementation of {@link IApiAccess} | 
| 17 |  *  | 
| 18 |  * @since 1.0.1 | 
| 19 |  * @noextend This class is not intended to be subclassed by clients. | 
| 20 |  * @noinstantiate This class is not intended to be instantiated by clients. | 
| 21 |  */ | 
| 22 | public class ApiAccess implements IApiAccess { | 
| 23 |   | 
| 24 |         public static final IApiAccess NORMAL_ACCESS = new NormalAccess(); | 
| 25 |          | 
| 26 |         static class NormalAccess implements IApiAccess { | 
| 27 |                 /* (non-Javadoc) | 
| 28 |                  * @see org.eclipse.pde.api.tools.internal.provisional.IApiAccess#getAccessLevel() | 
| 29 |                  */ | 
| 30 |                 public int getAccessLevel() { | 
| 31 |                         return IApiAccess.NORMAL; | 
| 32 |                 } | 
| 33 |         } | 
| 34 |          | 
| 35 |         private int access = IApiAccess.NORMAL; | 
| 36 |          | 
| 37 |         /** | 
| 38 |          * Constructor | 
| 39 |          * @param access | 
| 40 |          */ | 
| 41 |         public ApiAccess(int access) { | 
| 42 |                 this.access = access; | 
| 43 |         } | 
| 44 |          | 
| 45 |         /* (non-Javadoc) | 
| 46 |          * @see org.eclipse.pde.api.tools.internal.provisional.IApiAccess#getAccessLevel() | 
| 47 |          */ | 
| 48 |         public int getAccessLevel() { | 
| 49 |                 return this.access; | 
| 50 |         } | 
| 51 |   | 
| 52 |         /* (non-Javadoc) | 
| 53 |          * @see java.lang.Object#hashCode() | 
| 54 |          */ | 
| 55 |         public int hashCode() { | 
| 56 |                 return this.access; | 
| 57 |         } | 
| 58 |          | 
| 59 |         /* (non-Javadoc) | 
| 60 |          * @see java.lang.Object#equals(java.lang.Object) | 
| 61 |          */ | 
| 62 |         public boolean equals(Object obj) { | 
| 63 |                 if(obj instanceof IApiAccess) { | 
| 64 |                         return this.access == ((IApiAccess)obj).getAccessLevel(); | 
| 65 |                 } | 
| 66 |                 return false; | 
| 67 |         } | 
| 68 |          | 
| 69 |         /* (non-Javadoc) | 
| 70 |          * @see java.lang.Object#toString() | 
| 71 |          */ | 
| 72 |         public String toString() { | 
| 73 |                 StringBuffer buffer = new StringBuffer(); | 
| 74 |                 buffer.append("Access Level: "); //$NON-NLS-1$ | 
| 75 |                 buffer.append(getAccessText(getAccessLevel())); | 
| 76 |                 return buffer.toString(); | 
| 77 |         } | 
| 78 |          | 
| 79 |         /** | 
| 80 |          * Returns a textual representation of an {@link IApiAccess} | 
| 81 |          *  | 
| 82 |          * @param access | 
| 83 |          * @return the textual representation of an {@link IApiAccess} | 
| 84 |          */ | 
| 85 |         public static String getAccessText(int access) { | 
| 86 |                 switch(access) { | 
| 87 |                         case IApiAccess.NORMAL: return "NORMAL"; //$NON-NLS-1$ | 
| 88 |                         case IApiAccess.FRIEND: return "FRIEND"; //$NON-NLS-1$ | 
| 89 |                 } | 
| 90 |                 return "<UNKNOWN ACCESS LEVEL>"; //$NON-NLS-1$ | 
| 91 |         } | 
| 92 | } |