|
What this is
Other links
The source code/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.modules.registry; import org.netbeans.api.registry.Context; import org.netbeans.api.registry.ContextException; import org.netbeans.spi.registry.BasicContext; import org.openide.ErrorManager; import org.openide.util.TopologicalSortException; import org.openide.util.Utilities; import java.util.*; /** * This class orders context items according to positional attributes * and for backward compatibility it also accepts relative ordering * attributes. After the relative ordering attrs are removed the * ordering functionality in this class can be simplified. * * There are also several checks for "ordered" attribute * which are commented out till this mechanism gets common. * * @author copy & pasted from old Datasystems */ public class OrderingSupport { private static final char SEP = '/'; public static final OrderingSupport DEFAULT = new OrderingSupport(); private OrderingSupport() { } /** * @return ordered list of binding names and subcontext names. * */ public List getOrderedNames(Context ctx) { // check that context is ordered String ordered = ctx.getAttribute(null, "ordered", null); if (ordered == null || (!ordered.equals("true"))) { // TODO: add this diagnostic later // ErrorManager.getDefault().log(ErrorManager.WARNING, "Context "+ctx+" is not marked as ordered."); } List l = getItems(ctx); Map constraints = getOrderingConstraints(ctx); if (constraints.keySet().size() != 0) { try { l = Utilities.topologicalSort(l, constraints); } catch (TopologicalSortException ex) { List corrected = ex.partialSort(); ErrorManager.getDefault().log(ErrorManager.WARNING, "Note: context [" + ctx + "] cannot be consistently sorted due to ordering conflicts."); // NOI18N ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); ErrorManager.getDefault().log(ErrorManager.WARNING, "Using partial sort: " + corrected); // NOI18N l = corrected; } } // check for fullorder attribute String fullorder = ctx.getAttribute(null, "fullorder", null); if (fullorder != null) { List list = new ArrayList(); // ensure that items are returned in specified full order // and additional items are left as they are at the end StringTokenizer tok = new StringTokenizer(fullorder, ","); while (tok.hasMoreTokens()) { String token = tok.nextToken(); if (l.remove(token)) { list.add(token); } } list.addAll(l); l = list; } return l; } // list all items of the context private List getItems(Context ctx) { List l = new ArrayList(); Iterator i = ctx.getBindingNames().iterator(); while (i.hasNext()) { l.add((String)i.next()); } i = ctx.getSubcontextNames().iterator(); while (i.hasNext()) { l.add(((String)i.next())+"/"); } return l; } private Map getOrderingConstraints(Context ctx) { Map map = new HashMap(); try { addPositions(map, ctx); } catch (ContextException ex) { ErrorManager.getDefault().log(ErrorManager.EXCEPTION, ex.toString()); } addPartials(map, ctx); return map; } /** * Read old partial ordering attributes. Method updates the passed map. * * @param m map |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.