Search in sources :

Example 1 with TransformationFactory

use of org.apache.tomcat.websocket.TransformationFactory in project tomcat by apache.

the class UpgradeUtil method createTransformations.

private static List<Transformation> createTransformations(List<Extension> negotiatedExtensions) {
    TransformationFactory factory = TransformationFactory.getInstance();
    LinkedHashMap<String, List<List<Extension.Parameter>>> extensionPreferences = new LinkedHashMap<>();
    // Result will likely be smaller than this
    List<Transformation> result = new ArrayList<>(negotiatedExtensions.size());
    for (Extension extension : negotiatedExtensions) {
        List<List<Extension.Parameter>> preferences = extensionPreferences.get(extension.getName());
        if (preferences == null) {
            preferences = new ArrayList<>();
            extensionPreferences.put(extension.getName(), preferences);
        }
        preferences.add(extension.getParameters());
    }
    for (Map.Entry<String, List<List<Extension.Parameter>>> entry : extensionPreferences.entrySet()) {
        Transformation transformation = factory.create(entry.getKey(), entry.getValue(), true);
        if (transformation != null) {
            result.add(transformation);
        }
    }
    return result;
}
Also used : Transformation(org.apache.tomcat.websocket.Transformation) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Extension(javax.websocket.Extension) ArrayList(java.util.ArrayList) List(java.util.List) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) TransformationFactory(org.apache.tomcat.websocket.TransformationFactory)

Aggregations

ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Extension (javax.websocket.Extension)1 Transformation (org.apache.tomcat.websocket.Transformation)1 TransformationFactory (org.apache.tomcat.websocket.TransformationFactory)1