| 1 | /******************************************************************************* | 
| 2 |  * Copyright (c) 2008, 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.core.runtime.IProgressMonitor; | 
| 14 | import org.eclipse.core.runtime.IStatus; | 
| 15 | import org.eclipse.core.runtime.Status; | 
| 16 | import org.eclipse.pde.api.tools.internal.provisional.ApiDescriptionVisitor; | 
| 17 | import org.eclipse.pde.api.tools.internal.provisional.IApiAccess; | 
| 18 | import org.eclipse.pde.api.tools.internal.provisional.IApiAnnotations; | 
| 19 | import org.eclipse.pde.api.tools.internal.provisional.IApiDescription; | 
| 20 | import org.eclipse.pde.api.tools.internal.provisional.descriptors.IElementDescriptor; | 
| 21 | import org.eclipse.pde.api.tools.internal.provisional.descriptors.IPackageDescriptor; | 
| 22 |   | 
| 23 | /** | 
| 24 |  * A host API description combines descriptions of a host and all its | 
| 25 |  * fragments. | 
| 26 |  *  | 
| 27 |  * @since 1.0 | 
| 28 |  */ | 
| 29 | public class CompositeApiDescription implements IApiDescription { | 
| 30 |          | 
| 31 |         private IApiDescription[] fDescriptions; | 
| 32 |          | 
| 33 |         /** | 
| 34 |          * Constructs a composite API description out of the given descriptions. | 
| 35 |          *  | 
| 36 |          * @param descriptions | 
| 37 |          */ | 
| 38 |         public CompositeApiDescription(IApiDescription[] descriptions) { | 
| 39 |                 fDescriptions = descriptions; | 
| 40 |         } | 
| 41 |   | 
| 42 |         /* (non-Javadoc) | 
| 43 |          * @see org.eclipse.pde.api.tools.internal.provisional.IApiDescription#accept(org.eclipse.pde.api.tools.internal.provisional.ApiDescriptionVisitor) | 
| 44 |          */ | 
| 45 |         public void accept(ApiDescriptionVisitor visitor, IProgressMonitor monitor) { | 
| 46 |                 for (int i = 0; i < fDescriptions.length; i++) { | 
| 47 |                         fDescriptions[i].accept(visitor, monitor); | 
| 48 |                 } | 
| 49 |         } | 
| 50 |   | 
| 51 |         /* (non-Javadoc) | 
| 52 |          * @see org.eclipse.pde.api.tools.internal.provisional.IApiDescription#resolveAnnotations(java.lang.String, org.eclipse.pde.api.tools.internal.provisional.descriptors.IElementDescriptor) | 
| 53 |          */ | 
| 54 |         public IApiAnnotations resolveAnnotations(IElementDescriptor element) { | 
| 55 |                 for (int i = 0; i < fDescriptions.length; i++) { | 
| 56 |                         IApiAnnotations ann = fDescriptions[i].resolveAnnotations(element); | 
| 57 |                         if (ann != null) { | 
| 58 |                                 return ann; | 
| 59 |                         } | 
| 60 |                 } | 
| 61 |                 return null; | 
| 62 |         } | 
| 63 |   | 
| 64 |         /* (non-Javadoc) | 
| 65 |          * @see org.eclipse.pde.api.tools.internal.provisional.IApiDescription#setRestrictions(java.lang.String, org.eclipse.pde.api.tools.internal.provisional.descriptors.IElementDescriptor, int) | 
| 66 |          */ | 
| 67 |         public IStatus setRestrictions(IElementDescriptor element, int restrictions) { | 
| 68 |                 for (int i = 0; i < fDescriptions.length; i++) { | 
| 69 |                         IStatus status = fDescriptions[i].setRestrictions(element, restrictions); | 
| 70 |                         if (status.isOK() || i == (fDescriptions.length - 1)) { | 
| 71 |                                 return status; | 
| 72 |                         } | 
| 73 |                 } | 
| 74 |                 return Status.CANCEL_STATUS; | 
| 75 |         } | 
| 76 |         public IStatus setAddedProfile(IElementDescriptor element, int addedProfile) { | 
| 77 |                 return Status.OK_STATUS; | 
| 78 |         } | 
| 79 |         public IStatus setRemovedProfile(IElementDescriptor element, | 
| 80 |                         int removedProfile) { | 
| 81 |                 return Status.OK_STATUS; | 
| 82 |         } | 
| 83 |         public IStatus setSuperclass(IElementDescriptor element, String superclass) { | 
| 84 |                 return Status.OK_STATUS; | 
| 85 |         } | 
| 86 |         public IStatus setSuperinterfaces(IElementDescriptor element, | 
| 87 |                         String superinterfaces) { | 
| 88 |                 return Status.OK_STATUS; | 
| 89 |         } | 
| 90 |         public IStatus setInterface(IElementDescriptor element, | 
| 91 |                         boolean interfaceFlag) { | 
| 92 |                 return Status.OK_STATUS; | 
| 93 |         } | 
| 94 |         /* (non-Javadoc) | 
| 95 |          * @see org.eclipse.pde.api.tools.internal.provisional.IApiDescription#setVisibility(java.lang.String, org.eclipse.pde.api.tools.internal.provisional.descriptors.IElementDescriptor, int) | 
| 96 |          */ | 
| 97 |         public IStatus setVisibility(IElementDescriptor element, int visibility) { | 
| 98 |                 for (int i = 0; i < fDescriptions.length; i++) { | 
| 99 |                         IStatus status = fDescriptions[i].setVisibility(element, visibility); | 
| 100 |                         if (status.isOK() || i == (fDescriptions.length - 1)) { | 
| 101 |                                 return status; | 
| 102 |                         } | 
| 103 |                 } | 
| 104 |                 return Status.CANCEL_STATUS; | 
| 105 |         }         | 
| 106 |   | 
| 107 |         /* (non-Javadoc) | 
| 108 |          * @see org.eclipse.pde.api.tools.internal.provisional.IApiDescription#setAccessLevel(org.eclipse.pde.api.tools.internal.provisional.descriptors.IElementDescriptor, org.eclipse.pde.api.tools.internal.provisional.descriptors.IPackageDescriptor, int) | 
| 109 |          */ | 
| 110 |         public void setAccessLevel(IElementDescriptor element, IPackageDescriptor pelement, int access) { | 
| 111 |         } | 
| 112 |          | 
| 113 |         /* (non-Javadoc) | 
| 114 |          * @see org.eclipse.pde.api.tools.internal.provisional.IApiDescription#resolveAccessLevel(org.eclipse.pde.api.tools.internal.provisional.descriptors.IElementDescriptor, org.eclipse.pde.api.tools.internal.provisional.descriptors.IPackageDescriptor) | 
| 115 |          */ | 
| 116 |         public IApiAccess resolveAccessLevel(IElementDescriptor element, IPackageDescriptor pelement) { | 
| 117 |                 IApiAccess access = null; | 
| 118 |                 for(int i = 0; i < fDescriptions.length; i++) { | 
| 119 |                         access = fDescriptions[i].resolveAccessLevel(element, pelement); | 
| 120 |                         if(access != null) { | 
| 121 |                                 return access; | 
| 122 |                         } | 
| 123 |                 } | 
| 124 |                 return null; | 
| 125 |         } | 
| 126 | } |