PageRenderTime 33ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/projects/jboss-5.1.0/connector/src/main/org/jboss/resource/deployers/RARParserDeployer.java

https://gitlab.com/essere.lab.public/qualitas.class-corpus
Java | 125 lines | 73 code | 16 blank | 36 comment | 9 complexity | 25d72c2707062eefc50998a661db0e7d MD5 | raw file
  1. /*
  2. * JBoss, Home of Professional Open Source.
  3. * Copyright 2006, Red Hat Middleware LLC, and individual contributors
  4. * as indicated by the @author tags. See the copyright.txt file in the
  5. * distribution for a full listing of individual contributors.
  6. *
  7. * This is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU Lesser General Public License as
  9. * published by the Free Software Foundation; either version 2.1 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This software is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this software; if not, write to the Free
  19. * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  21. */
  22. package org.jboss.resource.deployers;
  23. import java.util.HashMap;
  24. import java.util.List;
  25. import java.util.Map;
  26. import org.jboss.deployers.vfs.spi.deployer.MultipleObjectModelFactoryDeployer;
  27. import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
  28. import org.jboss.resource.deployment.JBossRAObjectModelFactory;
  29. import org.jboss.resource.deployment.ResourceAdapterObjectModelFactory;
  30. import org.jboss.resource.metadata.ConnectorMetaData;
  31. import org.jboss.resource.metadata.JBossRAMetaData;
  32. import org.jboss.resource.metadata.RARDeploymentMetaData;
  33. import org.jboss.resource.metadata.repository.JCAMetaDataRepository;
  34. import org.jboss.virtual.VirtualFile;
  35. import org.jboss.xb.binding.ObjectModelFactory;
  36. /**
  37. * RARParserDeployer.
  38. *
  39. * @author <a href="adrian@jboss.com">Adrian Brock</a>
  40. * @author <a href="vicky.kak@jboss.com">Vicky Kak</a>
  41. * @author <a href="ales.justin@jboss.com">Ales Justin</a>
  42. * @version $Revision: 88350 $
  43. */
  44. public class RARParserDeployer extends MultipleObjectModelFactoryDeployer<RARDeploymentMetaData>
  45. {
  46. /** The metadata repsoitory */
  47. private JCAMetaDataRepository metaDataRepository;
  48. /** JEE specific RAR DD name */
  49. private static String jeeSpecRarDD = "ra.xml";
  50. /** Jboss specific RAR DD name */
  51. private static String jbossRarDD = "jboss-ra.xml";
  52. private static Map<String, Class<?>> getCustomMappings()
  53. {
  54. Map<String, Class<?>> mappings = new HashMap<String, Class<?>>();
  55. mappings.put(jeeSpecRarDD, ConnectorMetaData.class);
  56. mappings.put(jbossRarDD, JBossRAMetaData.class);
  57. return mappings;
  58. }
  59. /**
  60. * Create a new RARParserDeployer.
  61. */
  62. public RARParserDeployer()
  63. {
  64. super(RARDeploymentMetaData.class, getCustomMappings());
  65. // Enable MO creation of RARDeploymentMetaData
  66. setBuildManagedObject(true);
  67. }
  68. protected <U> ObjectModelFactory getObjectModelFactory(Class<U> expectedType, String fileName, U root)
  69. {
  70. if (ConnectorMetaData.class.equals(expectedType))
  71. {
  72. return new ResourceAdapterObjectModelFactory();
  73. }
  74. else if (JBossRAMetaData.class.equals(expectedType))
  75. {
  76. return new JBossRAObjectModelFactory();
  77. }
  78. else
  79. {
  80. throw new IllegalArgumentException("Cannot match arguments: expectedClass=" + expectedType + ", fileName=" + fileName);
  81. }
  82. }
  83. protected RARDeploymentMetaData mergeMetaData(VFSDeploymentUnit unit, Map<Class<?>, List<Object>> metadata) throws Exception
  84. {
  85. RARDeploymentMetaData deployment = new RARDeploymentMetaData();
  86. ConnectorMetaData cmd = getInstance(metadata, ConnectorMetaData.class);
  87. if (cmd != null)
  88. deployment.setConnectorMetaData(cmd);
  89. JBossRAMetaData jrmd = getInstance(metadata, JBossRAMetaData.class);
  90. if (jrmd != null)
  91. deployment.setRaXmlMetaData(jrmd);
  92. VFSDeploymentUnit parent = unit.getParent();
  93. String name = unit.getSimpleName();
  94. if (parent != null)
  95. name = parent.getSimpleName() + "#" + name;
  96. VirtualFile file = unit.getMetaDataFile(jeeSpecRarDD);
  97. deployment.getConnectorMetaData().setURL(file.toURL());
  98. metaDataRepository.addConnectorMetaData(name, deployment.getConnectorMetaData());
  99. return deployment;
  100. }
  101. public JCAMetaDataRepository getMetaDataRepository()
  102. {
  103. return metaDataRepository;
  104. }
  105. public void setMetaDataRepository(JCAMetaDataRepository metaDataRepository)
  106. {
  107. this.metaDataRepository = metaDataRepository;
  108. }
  109. }