org.eclipse.jetty.ee8.webapp.AbsoluteOrdering Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jetty-ee8-webapp Show documentation
Show all versions of jetty-ee8-webapp Show documentation
Jetty web application support
The newest version!
//
// ========================================================================
// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.ee8.webapp;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.eclipse.jetty.util.resource.Resource;
/**
* AbsoluteOrdering
*/
public class AbsoluteOrdering implements Ordering {
public static final String OTHER = "@@-OTHER-@@";
protected List _order = new ArrayList();
protected boolean _hasOther = false;
protected MetaData _metaData;
public AbsoluteOrdering(MetaData metaData) {
_metaData = metaData;
}
@Override
public List order(List jars) {
List orderedList = new ArrayList();
List tmp = new ArrayList(jars);
//1. put everything into the list of named others, and take the named ones out of there,
//assuming we will want to use the clause
Map others = new HashMap(_metaData.getNamedFragmentDescriptors());
//2. for each name, take out of the list of others, add to tail of list
int index = -1;
for (String item : _order) {
if (!item.equals(OTHER)) {
FragmentDescriptor f = others.remove(item);
if (f != null) {
Resource jar = _metaData.getJarForFragmentName(item);
//take from others and put into final list in order, ignoring duplicate names
orderedList.add(jar);
//remove resource from list for resource matching name of descriptor
tmp.remove(jar);
}
} else
//remember the index at which we want to add in all the others
index = orderedList.size();
}
//3. if was specified, insert rest of the fragments
if (_hasOther) {
orderedList.addAll((index < 0 ? 0 : index), tmp);
}
return orderedList;
}
public void add(String name) {
_order.add(name);
}
public void addOthers() {
if (_hasOther)
throw new IllegalStateException("Duplicate element in absolute ordering");
_hasOther = true;
_order.add(OTHER);
}
}