001/* 002 * (C) Copyright 2015 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Anahide Tchertchian 018 */ 019package org.nuxeo.theme.styling.service.descriptors; 020 021import java.util.HashMap; 022import java.util.Map; 023 024import org.nuxeo.common.xmap.annotation.XNode; 025import org.nuxeo.common.xmap.annotation.XNodeMap; 026import org.nuxeo.common.xmap.annotation.XObject; 027import org.nuxeo.theme.styling.negotiation.Negotiator; 028 029/** 030 * Descriptor for contributed negotiators. 031 * 032 * @since 7.4 033 */ 034@XObject("negotiator") 035public class NegotiatorDescriptor implements Comparable<NegotiatorDescriptor> { 036 037 @XNode("@class") 038 protected Class<Negotiator> klass; 039 040 @XNode("@order") 041 protected int order = 0; 042 043 @XNodeMap(value = "property", key = "@name", type = HashMap.class, componentType = String.class) 044 Map<String, String> properties = new HashMap<String, String>(); 045 046 public Class<Negotiator> getNegotiatorClass() { 047 return klass; 048 } 049 050 public void setNegotiatorKlass(Class<Negotiator> klass) { 051 this.klass = klass; 052 } 053 054 public int getOrder() { 055 return order; 056 } 057 058 public void setOrder(int order) { 059 this.order = order; 060 } 061 062 public Map<String, String> getProperties() { 063 return properties; 064 } 065 066 public void setProperties(Map<String, String> properties) { 067 this.properties = properties; 068 } 069 070 @Override 071 public int compareTo(NegotiatorDescriptor o) { 072 int cmp = order - o.order; 073 if (cmp == 0) { 074 // make sure we have a deterministic sort 075 cmp = klass.getName().compareTo(o.klass.getName()); 076 } 077 return cmp; 078 } 079 080 @Override 081 public NegotiatorDescriptor clone() { 082 NegotiatorDescriptor clone = new NegotiatorDescriptor(); 083 clone.setNegotiatorKlass(getNegotiatorClass()); 084 clone.setOrder(getOrder()); 085 Map<String, String> props = getProperties(); 086 if (props != null) { 087 clone.setProperties(new HashMap<String, String>(props)); 088 } 089 return clone; 090 } 091 092}