/src/main/java/com/google/ie/common/util/EntityMapperUtility.java

http://thoughtsite.googlecode.com/ · Java · 57 lines · 22 code · 8 blank · 27 comment · 0 complexity · 5a3788edd42035e0e7be0d4dba420a51 MD5 · raw file

  1. /* Copyright 2010 Google Inc.
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS.
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License
  14. */
  15. package com.google.ie.common.util;
  16. import com.google.ie.business.domain.BadWord;
  17. import com.google.ie.business.domain.Idea;
  18. import com.google.ie.business.domain.IdeaComment;
  19. import com.google.ie.business.domain.Project;
  20. import com.google.ie.business.domain.ProjectComment;
  21. import java.io.Serializable;
  22. import java.util.HashMap;
  23. import java.util.Map;
  24. /**
  25. * Utility class to map the entity name with the entity
  26. *
  27. * @author adahiya
  28. *
  29. */
  30. public class EntityMapperUtility {
  31. /** Map to store name to entity mapping */
  32. private static Map<String, Class<? extends Serializable>> indexableEntities = new HashMap<String, Class<? extends Serializable>>();
  33. static {
  34. indexableEntities.put(Idea.class.getSimpleName(), Idea.class);
  35. indexableEntities.put(BadWord.class.getSimpleName(), BadWord.class);
  36. indexableEntities.put(IdeaComment.class.getSimpleName(), IdeaComment.class);
  37. indexableEntities.put(Project.class.getSimpleName(), Project.class);
  38. indexableEntities.put(ProjectComment.class.getSimpleName(), ProjectComment.class);
  39. }
  40. /**
  41. * Return the mapped entity identified by entity name
  42. *
  43. * @param entityName name of the entity to be mapped
  44. * @return entity class
  45. */
  46. public static Class<? extends Serializable> getEntity(String entityName) {
  47. return indexableEntities.get(entityName);
  48. }
  49. }