1 19 24 25 package org.netbeans.modules.j2ee.sun.share.configbean; 26 27 import java.util.Map ; 28 import java.util.ResourceBundle ; 29 import java.text.MessageFormat ; 30 31 import javax.enterprise.deploy.spi.DConfigBean ; 32 import javax.enterprise.deploy.spi.DeploymentConfiguration ; 33 import javax.enterprise.deploy.spi.exceptions.ConfigurationException ; 34 import javax.enterprise.deploy.model.DDBean ; 35 import javax.enterprise.deploy.model.DDBeanRoot ; 36 import javax.enterprise.deploy.model.DeployableObject ; 37 38 42 public class DCBFactoryMgr { 43 44 protected static final ResourceBundle bundle = ResourceBundle.getBundle( 45 "org.netbeans.modules.j2ee.sun.share.configbean.Bundle"); 47 private Map factoryMap; 48 private String beanBaseXpath; 49 50 52 public DCBFactoryMgr(Map xPathFactoryMap, String baseXpath) { 53 factoryMap = xPathFactoryMap; 54 beanBaseXpath = baseXpath; 55 56 if(!Utils.hasTrailingSlash(beanBaseXpath)) { 57 beanBaseXpath += "/"; } 59 } 60 61 public Base createDCB(DDBean ddBean, Base dcbParent) throws ConfigurationException { 62 Base dcbResult = null; 63 64 67 if(dcbResult == null) { 69 String ddBeanRelativeXPath = makeRelative(ddBean.getXpath()); 70 DCBFactory factory = (DCBFactory) factoryMap.get(ddBeanRelativeXPath); 71 if(factory != null) { 72 dcbResult = factory.createDCB(ddBean, dcbParent); 73 if (null == dcbResult) { 74 dcbResult = new Error (); 75 dcbResult.init(ddBean, dcbParent); 76 } 77 } else { 78 Object [] args = new Object [1]; 79 args[0] = ddBean.getXpath(); 80 throw Utils.makeCE("ERR_BadFactoryMapping", args, null); } 82 } 83 84 return dcbResult; 85 } 86 87 public String [] getFactoryKeys() { 88 return (String []) factoryMap.keySet().toArray(new String [factoryMap.size()]); 89 } 90 91 102 private String makeRelative(String xpath) { 103 String result; 104 105 if(xpath.startsWith(beanBaseXpath)) { 106 result = xpath.substring(beanBaseXpath.length()); 107 } else if(!xpath.startsWith("/")) { result = xpath; 109 } else { 110 result = xpath; 111 } 112 113 return result; 114 } 115 } 116 | Popular Tags |