001/* 002 * (C) Copyright 2012 Nuxeo SA (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * Benjamin JALON 016 */ 017package org.nuxeo.ecm.mobile; 018 019import java.util.HashMap; 020import java.util.Map; 021 022import org.nuxeo.common.xmap.annotation.XNode; 023import org.nuxeo.common.xmap.annotation.XNodeMap; 024import org.nuxeo.common.xmap.annotation.XObject; 025import org.nuxeo.ecm.mobile.handler.RequestHandler; 026 027/** 028 * @author <a href="mailto:bjalon@nuxeo.com">Benjamin JALON</a> 029 * @since 5.5 030 */ 031@XObject("requestHandler") 032public class RequestHandlerDescriptor { 033 034 @XNode("implementation") 035 public Class<?> klass; 036 037 @XNode("@name") 038 public String requestHandlerName; 039 040 @XNode("@disabled") 041 public boolean disabled; 042 043 @XNodeMap(value = "properties/property", key = "@name", type = HashMap.class, componentType = String.class) 044 protected Map<String, String> properties = new HashMap<String, String>(); 045 046 /** 047 * Application definition service provide a way to expose easily a new dedicated UI for a specific type of 048 * environment (for instance for user agent browser selection). Implementation given here the logic to tell if 049 * request must be redirected to this application or not. 050 */ 051 public RequestHandler getRequestHandlerInstance() { 052 Object obj; 053 try { 054 obj = klass.newInstance(); 055 } catch (ReflectiveOperationException e) { 056 throw new RuntimeException("Problem during the Given class instanciation please check your contribution", e); 057 } 058 if (obj instanceof RequestHandler) { 059 RequestHandler rh = (RequestHandler) obj; 060 rh.init(properties); 061 return rh; 062 } 063 064 throw new RuntimeException("Given class is not a " + RequestHandler.class + " implementation"); 065 } 066 067 public String getRequestHandlerName() { 068 return requestHandlerName; 069 } 070}