Author: nbelaevski
Date: 2010-12-17 09:15:05 -0500 (Fri, 17 Dec 2010)
New Revision: 20646
Removed:
branches/RF-7654/ui/validator/ui/src/main/java/org/richfaces/validator/ClientScriptServiceImpl.java
branches/RF-7654/ui/validator/ui/src/main/java/org/richfaces/validator/ClientServiceConfigParser.java
branches/RF-7654/ui/validator/ui/src/main/java/org/richfaces/validator/LibraryFunctionImplementation.java
branches/RF-7654/ui/validator/ui/src/test/java/org/richfaces/validator/ClientScriptServiceTest.java
branches/RF-7654/ui/validator/ui/src/test/java/org/richfaces/validator/ServiceConfigParserTest.java
Log:
Removed duplicate files
Deleted:
branches/RF-7654/ui/validator/ui/src/main/java/org/richfaces/validator/ClientScriptServiceImpl.java
===================================================================
---
branches/RF-7654/ui/validator/ui/src/main/java/org/richfaces/validator/ClientScriptServiceImpl.java 2010-12-17
13:59:20 UTC (rev 20645)
+++
branches/RF-7654/ui/validator/ui/src/main/java/org/richfaces/validator/ClientScriptServiceImpl.java 2010-12-17
14:15:05 UTC (rev 20646)
@@ -1,74 +0,0 @@
-/**
- *
- */
-package org.richfaces.validator;
-
-import java.util.Map;
-
-import javax.faces.application.Resource;
-import javax.faces.application.ResourceHandler;
-import javax.faces.context.FacesContext;
-
-import org.richfaces.component.util.Strings;
-
-/**
- * @author asmirnov
- *
- */
-public class ClientScriptServiceImpl implements ClientScriptService {
-
- private static final String TEXT_JAVASCRIPT = "text/javascript";
-
- private static final String ORG_RICHFACES_CSV = "org.richfaces.csv";
-
- private final Map<Class<?>, LibraryFunction> defaultMapping;
-
- public ClientScriptServiceImpl(Map<Class<?>, LibraryFunction>
defaultMapping) {
- this.defaultMapping = defaultMapping;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.richfaces.validator.ClientScriptService#getScript(java.lang.Class)
- */
- public LibraryFunction getScript(FacesContext facesContext, Class<?> javaClass)
throws ScriptNotFoundException {
- if (null == facesContext || null == javaClass) {
- throw new NullPointerException();
- }
- LibraryFunction function;
- try {
- function = getScriptResource(facesContext, javaClass);
- } catch (ScriptNotFoundException e) {
- if (defaultMapping.containsKey(javaClass)) {
- function = defaultMapping.get(javaClass);
- } else {
- function = getScriptFromAnnotation(javaClass);
- }
- }
- return function;
- }
-
- private LibraryFunction getScriptFromAnnotation(Class<?> javaClass) throws
ScriptNotFoundException {
- if (javaClass.isAnnotationPresent(ClientSideScript.class)) {
- ClientSideScript clientSideScript =
javaClass.getAnnotation(ClientSideScript.class);
- return new LibraryFunctionImplementation(clientSideScript.library(),
clientSideScript.resource(), clientSideScript.function());
- } else {
- throw new ScriptNotFoundException();
- }
- }
-
- private LibraryFunction getScriptResource(FacesContext facesContext, Class<?>
javaClass)
- throws ScriptNotFoundException {
- ResourceHandler resourceHandler =
facesContext.getApplication().getResourceHandler();
- String resourceName = javaClass.getSimpleName() + ".js";
- Resource facesResource = resourceHandler.createResource(resourceName,
ORG_RICHFACES_CSV, TEXT_JAVASCRIPT);
- if (null != facesResource) {
- final String functionName =
Strings.firstToLowerCase(javaClass.getSimpleName());
- return new LibraryFunctionImplementation(ORG_RICHFACES_CSV,resourceName,
functionName);
- } else {
- throw new ScriptNotFoundException();
- }
- }
-
-}
Deleted:
branches/RF-7654/ui/validator/ui/src/main/java/org/richfaces/validator/ClientServiceConfigParser.java
===================================================================
---
branches/RF-7654/ui/validator/ui/src/main/java/org/richfaces/validator/ClientServiceConfigParser.java 2010-12-17
13:59:20 UTC (rev 20645)
+++
branches/RF-7654/ui/validator/ui/src/main/java/org/richfaces/validator/ClientServiceConfigParser.java 2010-12-17
14:15:05 UTC (rev 20646)
@@ -1,67 +0,0 @@
-/**
- *
- */
-package org.richfaces.validator;
-
-import java.io.IOException;
-import java.net.URL;
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.Map;
-
-import javax.faces.FacesException;
-import javax.xml.bind.JAXB;
-
-import org.richfaces.validator.model.ClientSideScripts;
-import org.richfaces.validator.model.Component;
-
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableMap.Builder;
-import com.google.common.collect.Maps;
-
-/**
- * @author asmirnov
- *
- */
-public final class ClientServiceConfigParser {
-
- private ClientServiceConfigParser() {
- }
-
- public static Map<Class<?>, LibraryFunction> parseConfig(String name) {
- ClassLoader loader = Thread.currentThread().getContextClassLoader();
- if (null == loader) {
- loader = ClientServiceConfigParser.class.getClassLoader();
- }
- Builder<Class<?>, LibraryFunction> resultBuilder =
ImmutableMap.builder();
- try {
- Enumeration<URL> resources = loader.getResources(name);
- while (resources.hasMoreElements()) {
- URL url = (URL) resources.nextElement();
- resultBuilder.putAll(parse(loader, url));
- }
- } catch (IOException e) {
- return Collections.emptyMap();
- }
- return resultBuilder.build();
- }
-
- static Map<Class<?>, LibraryFunction> parse(ClassLoader loader, URL url)
{
- Map<Class<?>, LibraryFunction> result = Maps.newHashMap();
- try {
- ClientSideScripts clientSideScripts = JAXB.unmarshal(url,
ClientSideScripts.class);
- for (Component component : clientSideScripts.getComponent()) {
- Class<?> componentClass = loader.loadClass(component.getType());
- LibraryFunctionImplementation function = new
LibraryFunctionImplementation(component.getLibrary(),
- component.getResource(), component.getFunction());
- result.put(componentClass, function);
- }
- } catch (ClassNotFoundException e) {
- throw new FacesException("Class for component not found",e);
- } catch (Exception e) {
- throw new FacesException("Error parsing config file "+url,e);
- }
- return result;
- }
-
-}
Deleted:
branches/RF-7654/ui/validator/ui/src/main/java/org/richfaces/validator/LibraryFunctionImplementation.java
===================================================================
---
branches/RF-7654/ui/validator/ui/src/main/java/org/richfaces/validator/LibraryFunctionImplementation.java 2010-12-17
13:59:20 UTC (rev 20645)
+++
branches/RF-7654/ui/validator/ui/src/main/java/org/richfaces/validator/LibraryFunctionImplementation.java 2010-12-17
14:15:05 UTC (rev 20646)
@@ -1,24 +0,0 @@
-package org.richfaces.validator;
-
-final class LibraryFunctionImplementation implements LibraryFunction {
- private final LibraryResource library;
- private final String functionName;
-
- LibraryFunctionImplementation(LibraryResource library, String functionName) {
- this.library = library;
- this.functionName = functionName;
- }
-
- LibraryFunctionImplementation(String library, String resource, String functionName)
{
- this.library = new LibraryResource(library, resource);
- this.functionName = functionName;
- }
-
- public LibraryResource getResource() {
- return library;
- }
-
- public String getName() {
- return functionName;
- }
-}
\ No newline at end of file
Deleted:
branches/RF-7654/ui/validator/ui/src/test/java/org/richfaces/validator/ClientScriptServiceTest.java
===================================================================
---
branches/RF-7654/ui/validator/ui/src/test/java/org/richfaces/validator/ClientScriptServiceTest.java 2010-12-17
13:59:20 UTC (rev 20645)
+++
branches/RF-7654/ui/validator/ui/src/test/java/org/richfaces/validator/ClientScriptServiceTest.java 2010-12-17
14:15:05 UTC (rev 20646)
@@ -1,121 +0,0 @@
-/**
- *
- */
-package org.richfaces.validator;
-
-import static org.easymock.EasyMock.expect;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertSame;
-
-import java.util.Map;
-
-import javax.faces.application.Resource;
-import javax.faces.application.ResourceHandler;
-import javax.validation.constraints.Max;
-
-import org.jboss.test.faces.mock.Environment;
-import org.jboss.test.faces.mock.Environment.Feature;
-import org.jboss.test.faces.mock.Mock;
-import org.jboss.test.faces.mock.MockController;
-import org.jboss.test.faces.mock.MockFacesEnvironment;
-import org.jboss.test.faces.mock.MockTestRunner;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-import com.google.common.collect.ImmutableMap;
-
-/**
- * @author asmirnov
- *
- */
-(a)RunWith(MockTestRunner.class)
-public class ClientScriptServiceTest {
-
- private static final String TEXT_JAVASCRIPT = "text/javascript";
-
- private static final String ORG_RICHFACES_CSV = "org.richfaces.csv";
-
- private static final String RESOURCE_NAME =
ValidatorWithFacesResource.class.getSimpleName() + ".js";
-
- @Mock
- @Environment({ Feature.APPLICATION })
- private MockFacesEnvironment environment;
-
- @Mock
- private ResourceHandler resourceHandler;
-
- private MockController controller;
-
- @Mock
- private Resource resource;
-
- @Mock
- private LibraryFunction function;
-
- private ClientScriptServiceImpl serviceImpl;
-
- /**
- * @throws java.lang.Exception
- */
- @Before
- public void setUp() throws Exception {
-
expect(environment.getApplication().getResourceHandler()).andStubReturn(resourceHandler);
- Map<Class<?>, LibraryFunction> defaultMapping = ImmutableMap
- .<Class<?>, LibraryFunction> of(Max.class, function);
- serviceImpl = new ClientScriptServiceImpl(defaultMapping);
- }
-
- /**
- * @throws java.lang.Exception
- */
- @After
- public void tearDown() throws Exception {
- controller.verify();
- }
-
- /**
- * Test method for {@link
org.richfaces.validator.ClientScriptServiceImpl#getScript(FacesContext,
java.lang.Class)}.
- *
- * @throws Exception
- */
- @Test
- public void testGetScriptAsJsfResource() throws Exception {
- LibraryFunction script = getScript(resource, ValidatorWithFacesResource.class);
- assertEquals(RESOURCE_NAME, script.getResource().getResourceName());
- assertEquals(ORG_RICHFACES_CSV, script.getResource().getLibrary());
- assertEquals("validatorWithFacesResource", script.getName());
- }
-
- @Test
- public void testGetScriptFromAnnotation() throws Exception {
- LibraryFunction script = getScript(null, ValidatorWithFacesResource.class);
- assertEquals("baz.js", script.getResource().getResourceName());
- assertEquals("bar", script.getResource().getLibrary());
- assertEquals("foo", script.getName());
- }
-
- @Test
- public void testGetScriptFromDefaultMapping() throws Exception {
- LibraryFunction script = getScript(null, Max.class);
- assertSame(function, script);
- }
-
- @Test
- public void testGetScriptOverrideAnnotation() throws Exception {
- Map<Class<?>, LibraryFunction> defaultMapping =
ImmutableMap.<Class<?>, LibraryFunction> of(
- ValidatorWithFacesResource.class, function);
- serviceImpl = new ClientScriptServiceImpl(defaultMapping);
- LibraryFunction script = getScript(null, ValidatorWithFacesResource.class);
- assertSame(function, script);
- }
-
- private LibraryFunction getScript(Resource resource, Class<?> serverSideType)
throws ScriptNotFoundException {
- expect(resourceHandler.createResource(serverSideType.getSimpleName() +
".js", ORG_RICHFACES_CSV, TEXT_JAVASCRIPT)).andReturn(resource);
- controller.replay();
- LibraryFunction script = serviceImpl.getScript(environment.getFacesContext(),
serverSideType);
- return script;
- }
-
-}
Deleted:
branches/RF-7654/ui/validator/ui/src/test/java/org/richfaces/validator/ServiceConfigParserTest.java
===================================================================
---
branches/RF-7654/ui/validator/ui/src/test/java/org/richfaces/validator/ServiceConfigParserTest.java 2010-12-17
13:59:20 UTC (rev 20645)
+++
branches/RF-7654/ui/validator/ui/src/test/java/org/richfaces/validator/ServiceConfigParserTest.java 2010-12-17
14:15:05 UTC (rev 20646)
@@ -1,43 +0,0 @@
-package org.richfaces.validator;
-
-import static org.junit.Assert.*;
-
-import java.util.Map;
-
-import javax.faces.FacesException;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-public class ServiceConfigParserTest {
-
- @Before
- public void setUp() throws Exception {
- }
-
- @After
- public void tearDown() throws Exception {
- }
-
- @Test
- public void testParseConfig() {
- Map<Class<?>, LibraryFunction> parseConfig =
ClientServiceConfigParser.parseConfig("csv.xml");
- assertEquals(2, parseConfig.size());
- assertTrue(parseConfig.containsKey(String.class));
- LibraryFunction libraryFunction = parseConfig.get(String.class);
- assertEquals("stringConverter", libraryFunction.getName());
- assertEquals("csv.js",
libraryFunction.getResource().getResourceName());
- assertEquals("org.richfaces",
libraryFunction.getResource().getLibrary());
- }
-
- @Test(expected=FacesException.class)
- public void testParseBadConfig() {
- Map<Class<?>, LibraryFunction> parseConfig =
ClientServiceConfigParser.parseConfig("badcsv.xml");
- }
- @Test()
- public void testParseNoConfig() {
- Map<Class<?>, LibraryFunction> parseConfig =
ClientServiceConfigParser.parseConfig("non-exists-csv.xml");
- assertEquals(0, parseConfig.size());
- }
-}