001/* 002 * (C) Copyright 2012 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 * Benjamin JALON 018 */ 019package org.nuxeo.ecm.mobile; 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.ecm.mobile.handler.RequestHandler; 028 029/** 030 * @author <a href="mailto:bjalon@nuxeo.com">Benjamin JALON</a> 031 * @since 5.5 032 */ 033@XObject("requestHandler") 034public class RequestHandlerDescriptor { 035 036 @XNode("implementation") 037 public Class<?> klass; 038 039 @XNode("@name") 040 public String requestHandlerName; 041 042 @XNode("@disabled") 043 public boolean disabled; 044 045 @XNodeMap(value = "properties/property", key = "@name", type = HashMap.class, componentType = String.class) 046 protected Map<String, String> properties = new HashMap<String, String>(); 047 048 /** 049 * Application definition service provide a way to expose easily a new dedicated UI for a specific type of 050 * environment (for instance for user agent browser selection). Implementation given here the logic to tell if 051 * request must be redirected to this application or not. 052 */ 053 public RequestHandler getRequestHandlerInstance() { 054 Object obj; 055 try { 056 obj = klass.newInstance(); 057 } catch (ReflectiveOperationException e) { 058 throw new RuntimeException("Problem during the Given class instanciation please check your contribution", e); 059 } 060 if (obj instanceof RequestHandler) { 061 RequestHandler rh = (RequestHandler) obj; 062 rh.init(properties); 063 return rh; 064 } 065 066 throw new RuntimeException("Given class is not a " + RequestHandler.class + " implementation"); 067 } 068 069 public String getRequestHandlerName() { 070 return requestHandlerName; 071 } 072}