| //------------------------------------------------------------------------------ |
| // Copyright (c) 2005, 2006 IBM Corporation and others. |
| // All rights reserved. This program and the accompanying materials |
| // are made available under the terms of the Eclipse Public License v1.0 |
| // which accompanies this distribution, and is available at |
| // http://www.eclipse.org/legal/epl-v10.html |
| // |
| // Contributors: |
| // IBM Corporation - initial implementation |
| //------------------------------------------------------------------------------ |
| package org.eclipse.epf.publishing.services; |
| |
| import java.util.ArrayList; |
| import java.util.HashMap; |
| import java.util.Iterator; |
| import java.util.List; |
| import java.util.Map; |
| |
| import org.eclipse.epf.library.util.LibraryUtil; |
| import org.eclipse.epf.publishing.PublishingPlugin; |
| |
| import com.ibm.uma.ContentCategory; |
| import com.ibm.uma.Guidance; |
| import com.ibm.uma.MethodElement; |
| import com.ibm.uma.Practice; |
| import com.ibm.uma.Roadmap; |
| import com.ibm.uma.SupportingMaterial; |
| import com.ibm.uma.TermDefinition; |
| |
| public class ProcessPublishingContentValidator extends PublishingContentValidator { |
| |
| // closure elements for process publishing, null for config publishing |
| List closureElements = null; |
| private boolean isFinalClosure = false; |
| |
| // maintain the object references generated from TaskDescriptors |
| // map of owner element to a list of referenced elements |
| Map objReferences = new HashMap(); |
| |
| private boolean debug = PublishingPlugin.getDefault().isDebugging(); |
| |
| public ProcessPublishingContentValidator(String pubDir, boolean validateExternalLinks) { |
| super(pubDir, validateExternalLinks); |
| } |
| |
| public void addClosureElements(List items) { |
| // do nothing |
| if ( closureElements == null ) { |
| closureElements = new ArrayList(); |
| } |
| |
| closureElements.addAll(items); |
| } |
| |
| /** |
| * make element closure |
| * all the published and referenced elements are the element closure. |
| * since they are all the elements referenced by the processes and their related process elements |
| * |
| * @param isFinalClosure boolean if true the closure is final, |
| * anything outside the closure is treated as not in closure. |
| * if false, the closure is final, any Guidances referenced by the elements in closure is treated as in closure. |
| * we need this to allow build the closure in steps but still not create broken links for published elements. |
| */ |
| public void makeElementClosure() { |
| this.isFinalClosure = true; |
| |
| // test |
| if ( debug) { |
| System.out.println("====================== Closure elements ======================="); //$NON-NLS-1$ |
| for (Iterator it = closureElements.iterator(); it.hasNext(); ) { |
| System.out.println(LibraryUtil.getTypeName((MethodElement)it.next())); |
| } |
| System.out.println("====================== Closure elements end ======================="); //$NON-NLS-1$ |
| } |
| } |
| |
| public boolean hasClosure() { |
| return (closureElements != null) && (closureElements.size() > 0); |
| } |
| |
| /** |
| * define if the element is in the process element closure or not |
| * The process element closure contains all the process elements of the selected processes, |
| * plus all the content elements those elements referenced. |
| */ |
| public boolean inClosure(MethodElement e) { |
| |
| if ( e == null ) { |
| return false; |
| } |
| |
| if ( !hasClosure() ) { |
| return true; |
| } |
| |
| if ( closureElements.contains(e) ) { |
| return true; |
| } |
| |
| if ( e instanceof ContentCategory ) { |
| return true; |
| } |
| |
| if ( !(e instanceof Guidance) ) { |
| return false; |
| } |
| |
| if ( e instanceof Practice |
| || e instanceof Roadmap |
| || e instanceof SupportingMaterial |
| || e instanceof TermDefinition ) |
| { |
| return true; |
| } |
| |
| return false; |
| |
| } |
| |
| /** |
| * check if the element is discarded or not |
| * discarded elements will be treated as out side the configursation |
| * |
| * @param owner MethodElement the owner of the element |
| * @param Object feature EStructuralFeature or OppositeFeature |
| * @param e MethodElement the element to be checked |
| */ |
| /* (non-Javadoc) |
| * @see com.ibm.rmc.library.layout.IContentValidator#isDiscarded(com.ibm.uma.MethodElement, java.lang.Object, com.ibm.uma.MethodElement) |
| */ |
| public boolean isDiscarded(MethodElement owner, Object feature, MethodElement e) { |
| |
| if ( owner == null ) { |
| owner = defaultTarget; |
| } else if ( defaultTarget != null && owner != defaultTarget ) { |
| |
| super.logWarning("Target mismatch" + LibraryUtil.getTypeName(owner) + "<--->" + LibraryUtil.getTypeName(defaultTarget)); //$NON-NLS-1$ //$NON-NLS-2$ |
| } |
| |
| if ( super.isDiscarded(owner, feature, e) ) { |
| return true; |
| } |
| |
| boolean inCls = inClosure(e); |
| if (!inCls && !isFinalClosure ) { |
| // if the closure is not final, then if the owner is in closure and the element is a Guidance, |
| // this element is also in closure |
| inCls = inClosure(owner) && (e instanceof Guidance); |
| } |
| |
| if ( !inCls ) { |
| return true; |
| } |
| |
| // // special handling for Tasks |
| // if ( owner instanceof Task ) { |
| // if ( feature == UmaPackage.eINSTANCE.getTask_AdditionallyPerformedBy() || |
| // feature == UmaPackage.eINSTANCE.getTask_MandatoryInput() || |
| // feature == UmaPackage.eINSTANCE.getTask_OptionalInput() || |
| // feature == UmaPackage.eINSTANCE.getTask_Output() ) { |
| // List refs = (List)objReferences.get(owner); |
| // if ( refs != null && !refs.contains(e) ) { |
| // return true; |
| // } |
| // } |
| // } |
| |
| return false; |
| } |
| |
| |
| // public void setElementReferences(Task element, List refs) { |
| // |
| // List items = (List)objReferences.get(element); |
| // if ( items == null ) { |
| // items = new ArrayList(); |
| // objReferences.put(element, items); |
| // } |
| // |
| // items.addAll(refs); |
| // } |
| |
| public void dispose() { |
| |
| if ( closureElements != null ) { |
| closureElements.clear(); |
| } |
| |
| if ( objReferences != null ) { |
| objReferences.clear(); |
| } |
| |
| super.dispose(); |
| } |
| |
| } |