| 1 | /******************************************************************************* | 
| 2 |  * Copyright (c) 2007, 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.model; | 
| 12 |   | 
| 13 | import org.eclipse.core.runtime.CoreException; | 
| 14 | import org.eclipse.pde.api.tools.internal.provisional.model.IApiBaseline; | 
| 15 | import org.eclipse.pde.api.tools.internal.provisional.model.IApiComponent; | 
| 16 | import org.eclipse.pde.api.tools.internal.provisional.model.IApiElement; | 
| 17 | import org.eclipse.pde.api.tools.internal.provisional.model.IApiType; | 
| 18 | import org.eclipse.pde.api.tools.internal.provisional.model.IApiTypeRoot; | 
| 19 |   | 
| 20 | /** | 
| 21 |  * Common implementation for {@link IApiTypeRoot} | 
| 22 |  *  | 
| 23 |  * @since 1.0.0 | 
| 24 |  */ | 
| 25 | public abstract class AbstractApiTypeRoot extends ApiElement implements IApiTypeRoot { | 
| 26 |   | 
| 27 |         /** | 
| 28 |          * Constructor | 
| 29 |          * @param parent the parent {@link IApiElement} or <code>null</code> if none | 
| 30 |          * @param name the name of the type root | 
| 31 |          */ | 
| 32 |         protected AbstractApiTypeRoot(IApiElement parent, String name) { | 
| 33 |                 super(parent, IApiElement.API_TYPE_ROOT, name); | 
| 34 |         } | 
| 35 |          | 
| 36 |         /* (non-Javadoc) | 
| 37 |          * @see org.eclipse.pde.api.tools.internal.provisional.IApiTypeRoot#getContents() | 
| 38 |          */ | 
| 39 |         public abstract byte[] getContents() throws CoreException; | 
| 40 |          | 
| 41 |         /* (non-Javadoc) | 
| 42 |          * @see org.eclipse.pde.api.tools.internal.provisional.IApiTypeRoot#getStructure() | 
| 43 |          */ | 
| 44 |         public IApiType getStructure() throws CoreException { | 
| 45 |                 ApiModelCache cache = ApiModelCache.getCache(); | 
| 46 |                 IApiComponent comp = getApiComponent(); | 
| 47 |                 IApiType type = null; | 
| 48 |                 if(comp != null) { | 
| 49 |                         IApiBaseline baseline = comp.getBaseline(); | 
| 50 |                         type = (IApiType) cache.getElementInfo(baseline.getName(), comp.getId(), this.getTypeName(), IApiElement.TYPE); | 
| 51 |                 } | 
| 52 |                 if(type == null) { | 
| 53 |                         type = TypeStructureBuilder.buildTypeStructure(getContents(), getApiComponent(), this); | 
| 54 |                         if(type == null) { | 
| 55 |                                 return null; | 
| 56 |                         } | 
| 57 |                         cache.cacheElementInfo(type); | 
| 58 |                 } | 
| 59 |                 return type; | 
| 60 |         } | 
| 61 |          | 
| 62 |         /** | 
| 63 |          * @see org.eclipse.pde.api.tools.internal.provisional.IApiTypeRoot#getApiComponent() | 
| 64 |          */ | 
| 65 |         public IApiComponent getApiComponent() { | 
| 66 |                 return (IApiComponent) getAncestor(IApiElement.COMPONENT); | 
| 67 |         } | 
| 68 | } |