All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.dragome.web.helpers.serverside.RequestUrlActivityMapperImpl Maven / Gradle / Ivy

There is a newer version: 0.96-beta4
Show newest version
/*******************************************************************************
 * Copyright (c) 2011-2014 Fernando Petrola
 * 
 *  This file is part of Dragome SDK.
 * 
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/gpl.html
 ******************************************************************************/
package com.dragome.web.helpers.serverside;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import com.dragome.services.ServiceLocator;
import com.dragome.services.interfaces.ReflectionService;
import com.dragome.view.VisualActivity;
import com.dragome.web.annotations.PageAlias;
import com.dragome.web.helpers.RequestUrlActivityMapper;

public class RequestUrlActivityMapperImpl implements RequestUrlActivityMapper
{
	public String getActivityClassNameFromUrl(String uri)
	{
		ReflectionService reflectionService= ServiceLocator.getInstance().getReflectionService();
		
		Set> modules= reflectionService.getSubTypesOf(VisualActivity.class);
		Set> aliases= reflectionService.getTypesAnnotatedWith(PageAlias.class);

		for (Class type : aliases)
		{
			PageAlias pageAlias= type.getAnnotation(PageAlias.class);
			if (pageAlias != null && uri.contains(pageAlias.alias()))
				return type.getName();
		}

		for (Class type : modules)
		{
			if (uri.contains(type.getSimpleName()))
				return type.getName();
		}

		return null;
	}

	public List> getExistingVisualActivities()
	{
		ReflectionService reflectionService= ServiceLocator.getInstance().getReflectionService();
		
		Set> classes= reflectionService.getSubTypesOf(VisualActivity.class);
		return new ArrayList>(classes);
	}

	public String getActivityAlias(Class visualActivity)
	{
		PageAlias pageAlias= visualActivity.getAnnotation(PageAlias.class);
		return pageAlias != null ? pageAlias.alias() : "";
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy