| 1 19 package org.netbeans.modules.j2ee.sun.share.configbean; 20 21 import java.util.ArrayList ; 22 import java.util.Collection ; 23 import java.util.Collections ; 24 import java.util.HashMap ; 25 import java.util.Iterator ; 26 import java.util.LinkedHashSet ; 27 import java.util.List ; 28 import java.util.Map ; 29 import java.util.ResourceBundle ; 30 import java.util.Set ; 31 import java.util.logging.Level ; 32 33 import java.text.MessageFormat ; 34 35 import java.beans.PropertyChangeEvent ; 36 import java.beans.PropertyChangeListener ; 37 import java.beans.PropertyChangeSupport ; 38 import java.beans.VetoableChangeListener ; 39 import java.beans.VetoableChangeSupport ; 40 41 import javax.enterprise.deploy.spi.DConfigBean ; 42 import javax.enterprise.deploy.model.DDBean ; 43 import javax.enterprise.deploy.model.XpathEvent ; 44 import javax.enterprise.deploy.model.XpathListener ; 45 import javax.enterprise.deploy.spi.exceptions.BeanNotFoundException ; 46 import javax.enterprise.deploy.spi.exceptions.ConfigurationException ; 47 48 import org.netbeans.modules.j2ee.sun.dd.api.CommonDDBean; 49 import org.netbeans.modules.j2ee.sun.dd.api.common.WebserviceEndpoint; 50 import org.netbeans.modules.j2ee.sun.dd.api.web.SunWebApp; 51 52 import org.netbeans.modules.j2ee.sun.share.Constants; 53 import org.openide.ErrorManager; 54 55 61 public abstract class Base implements Constants, DConfigBean , XpathListener , DConfigBeanUIFactory { 62 63 65 protected static final ResourceBundle bundle = ResourceBundle.getBundle( 66 "org.netbeans.modules.j2ee.sun.share.configbean.Bundle"); 68 70 public static final String DISPLAY_NAME = "displayName"; public static final String DIRTY_PROPERTY = "dirty"; 73 78 public static final Object GenericOldValue = new Object (); 79 80 private DDBean dDBean; 81 private Base parent; 82 private String baseXpath; 83 84 85 protected String descriptorElement; 86 87 92 private Boolean isValid = null; 93 94 96 private ErrorMessageDB errorMessageDB = null; 97 98 99 private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport (this); 100 101 102 private VetoableChangeSupport vetoableChangeSupport = new VetoableChangeSupport (this); 103 104 private PropertyChangeListener validationListener = new PropertyChangeListener () { 105 public void propertyChange(PropertyChangeEvent evt) { 106 if(ErrorMessageDB.VALIDATION_STATE_CHANGED.equals(evt.getPropertyName())) { 107 validationStateChanged((Boolean ) evt.getNewValue()); 108 } 109 } 110 }; 111 112 115 private static int identitySource = 0; 116 private String identity; 117 118 public String getIdentity() { 119 return identity; 120 } 121 122 public void setIdentity(String id) { 123 } 124 125 128 private int dirtyFlag; 129 130 public void setDirty() { 131 int oldDirtyFlag = dirtyFlag; 132 dirtyFlag += 1; 133 getPCS().firePropertyChange(DIRTY_PROPERTY, oldDirtyFlag, dirtyFlag); 134 } 135 136 138 public void firePropertyChange(String propertyName, Object oldProperty, Object newProperty) { 139 getPCS().firePropertyChange(propertyName, oldProperty, newProperty); 140 } 141 142 143 protected Base() { 144 identity = Integer.toString(++identitySource); 145 } 146 147 157 protected void init(DDBean dDBean, Base parent) throws ConfigurationException { 158 this.dDBean = dDBean; 159 this.parent = parent; 160 this.baseXpath = dDBean.getXpath(); 161 162 updateValidationFieldList(); 166 167 dDBean.addXpathListener(dDBean.getXpath(), this); 168 getMessageDB().addPropertyChangeListener(validationListener); 169 } 170 171 174 protected void cleanup() { 175 getMessageDB().removePropertyChangeListener(validationListener); 177 dDBean.removeXpathListener(dDBean.getXpath(), this); 178 179 synchronized (this) { 181 errorMessageDB = null; 182 } 183 184 if(parent != null) { 186 parent.removeChild(this); 187 } 188 189 parent = null; 191 } 192 193 protected String getDescriptorElement() { 194 return descriptorElement; 195 } 196 197 protected void setDescriptorElement(String element) { 198 descriptorElement = element; 199 } 200 201 protected String getComponentName() { 202 return null; 203 } 204 205 protected String getAbsoluteXpath(String field) { 206 StringBuffer buf = new StringBuffer (baseXpath.length() + field.length() + 1); 207 buf.append(baseXpath); 208 buf.append("/"); buf.append(field); 210 return buf.toString(); 211 } 212 213 216 protected boolean requiresJndiName() { 217 return J2EEVersion.J2EE_1_4.compareSpecification(getJ2EEModuleVersion()) >= 0; 218 } 219 220 221 224 private Map namedBeanCache = new HashMap (11); 225 226 protected void saveNamedBeans(String type, String nameProperty, CommonDDBean [] data) { 227 if(data != null && data.length > 0) { 228 Map dataMap = new HashMap (data.length*3); 229 for(int i = 0; i < data.length; i++) { 230 String beanName = (String ) data[i].getValue(nameProperty); 231 if(Utils.notEmpty(beanName)) { 232 dataMap.put(beanName, data[i]); 233 } 234 } 235 236 namedBeanCache.put(type, dataMap); 237 } 238 } 239 240 protected CommonDDBean removeNamedBean(String type, String beanName) { 241 CommonDDBean result = null; 242 Map dataMap = getNamedBeanMap(type); 243 if(dataMap != null) { 244 result = (CommonDDBean) dataMap.remove(beanName); 245 } 246 247 return result; 248 } 249 250 protected CommonDDBean removeCachedEndpoint(String hostType, String hostNameType, 251 String hostName, String endpointType, String portComponentName) { 252 CommonDDBean removedEndpoint = null; 256 Map dataMap = getNamedBeanMap(hostType); 257 if(dataMap != null) { 258 try { 259 Iterator entryIter = dataMap.entrySet().iterator(); 260 while(entryIter.hasNext()) { 261 Map.Entry entry = (Map.Entry ) entryIter.next(); 262 CommonDDBean host = (CommonDDBean) entry.getValue(); 263 Object n = host.getValue(hostNameType); 264 if(n instanceof String && hostName.equals((String ) n)) { 265 Object [] objs = host.getValues(endpointType); 266 if(objs != null) { 267 for(int i = 0; i < objs.length; i++) { 268 if(objs[i] instanceof WebserviceEndpoint) { 269 WebserviceEndpoint endpoint = (WebserviceEndpoint) objs[i]; 270 if(portComponentName.equals(endpoint.getPortComponentName())) { 271 host.removeValue(endpointType, endpoint); 272 removedEndpoint = endpoint; 273 } 274 } 275 } 276 } 277 } 278 } 279 } catch(IllegalArgumentException ex) { 280 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 282 } 283 } 284 return removedEndpoint; 285 } 286 287 protected Map getNamedBeanMap(String type) { 288 return (Map ) namedBeanCache.get(type); 289 } 290 291 protected void saveAllNamedBeans(CommonDDBean parentBean) { 292 Iterator iter = getNamedBeanSpecs().iterator(); 293 while(iter.hasNext()) { 294 NamedBean beanSpec = (NamedBean) iter.next(); 295 try { 296 Object data = parentBean.getValues(beanSpec.getType()); 297 if(data instanceof CommonDDBean []) { 298 saveNamedBeans(beanSpec.getType(), beanSpec.getPropertyName(), (CommonDDBean []) data); 299 } else if(data != null) { 300 } 302 } catch(Exception ex) { 303 } 306 } 307 } 308 309 protected void restoreAllNamedBeans(CommonDDBean parentBean, String version) { 310 Iterator iter = getNamedBeanSpecs().iterator(); 311 while(iter.hasNext()) { 312 NamedBean beanSpec = (NamedBean) iter.next(); 313 Map beanMap = getNamedBeanMap(beanSpec.getType()); 314 restoreNamedBeans(beanMap, beanSpec.getType(), parentBean, version); 315 } 316 } 317 318 protected void restoreNamedBeans(Map beanMap, String parentPropertyName, CommonDDBean parentBean, String version) { 319 if(beanMap != null && beanMap.size() > 0) { 320 for (Iterator beanIter = beanMap.entrySet().iterator(); beanIter.hasNext();) { 321 try { 322 Map.Entry entry = (Map.Entry ) beanIter.next(); 323 CommonDDBean bean = (CommonDDBean) entry.getValue(); 324 parentBean.addValue(parentPropertyName, bean.cloneVersion(version)); 325 } catch(Exception ex) { 326 } 329 } 330 } 331 } 332 333 protected void updateNamedBeanCache(String type) { 334 if(parent != null) { 335 String name = getComponentName(); 336 if(Utils.notEmpty(name)) { 337 parent.removeNamedBean(type, name); 338 } 339 } 340 } 341 342 protected Collection getNamedBeanSpecs() { 343 return Collections.EMPTY_LIST; 344 } 345 346 private static Collection commonAppBeanSpecs = new ArrayList (); 347 348 static { 349 commonAppBeanSpecs.add(new NamedBean(SunWebApp.EJB_REF, 350 org.netbeans.modules.j2ee.sun.dd.api.common.EjbRef.EJB_REF_NAME)); 351 commonAppBeanSpecs.add(new NamedBean(SunWebApp.MESSAGE_DESTINATION_REF, 352 org.netbeans.modules.j2ee.sun.dd.api.common.MessageDestinationRef.MESSAGE_DESTINATION_REF_NAME)); 353 commonAppBeanSpecs.add(new NamedBean(SunWebApp.RESOURCE_ENV_REF, 354 org.netbeans.modules.j2ee.sun.dd.api.common.ResourceEnvRef.RESOURCE_ENV_REF_NAME)); 355 commonAppBeanSpecs.add(new NamedBean(SunWebApp.RESOURCE_REF, 356 org.netbeans.modules.j2ee.sun.dd.api.common.ResourceRef.RES_REF_NAME)); 357 commonAppBeanSpecs.add(new NamedBean(SunWebApp.SERVICE_REF, 358 org.netbeans.modules.j2ee.sun.dd.api.common.ServiceRef.SERVICE_REF_NAME)); 359 } 360 361 protected static Collection getCommonNamedBeanSpecs() { 362 return commonAppBeanSpecs; 363 } 364 365 protected static class NamedBean { 366 private final String type; 367 private final String propertyName; 368 369 public NamedBean(final String t, final String pn) { 370 type = t; 371 propertyName = pn; 372 } 373 374 public String getType() { 375 return type; 376 } 377 378 public String getPropertyName() { 379 return propertyName; 380 } 381 } 382 383 384 387 protected final synchronized ErrorMessageDB getMessageDB() { 388 if(errorMessageDB == null) { 389 errorMessageDB = ErrorMessageDB.createMessageDB(); 390 } 391 return errorMessageDB; 392 } 393 394 404 protected List validationFieldList = new ArrayList (); 405 406 409 protected void updateValidationFieldList() { 410 } 411 412 public void validationStateChanged(Boolean newState) { 413 isValid = newState; 414 getPCS().firePropertyChange(DISPLAY_NAME, "", getDisplayName()); 415 } 416 417 422 public boolean isValid() { 423 if(isValid == null) { 424 boolean tempValid = validateFields(true); 425 isValid = Boolean.valueOf(tempValid); 426 } 427 428 return isValid.booleanValue(); 429 } 430 431 436 public boolean validateFields(boolean shortCircuit) { 437 ErrorMessageDB messageDB = getMessageDB(); 438 boolean result = true; 439 440 messageDB.clearErrors(); 441 for(Iterator iter = validationFieldList.iterator(); iter.hasNext() && (result || !shortCircuit); ) { 442 boolean fieldResult = validateField((String ) iter.next()); 443 result = result && fieldResult; 444 } 445 446 isValid = Boolean.valueOf(result); 447 448 return result; 449 } 450 451 458 public boolean validateField(String fieldId) { 459 return true; 460 } 461 462 465 public void fireXpathEvent(XpathEvent xpe) { 466 } 468 469 472 public J2EEBaseVersion getJ2EEModuleVersion() { 473 Base parent = getParent(); 474 if(parent != null) { 475 return getParent().getJ2EEModuleVersion(); 476 } else { 477 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, new IllegalStateException ("getJ2EEModuleVersion() called on child DConfigBean with null parent: " + this)); 478 } 479 return null; 480 } 481 482 public ASDDVersion getAppServerVersion() { 483 Base parent = getParent(); 484 if(parent != null) { 485 return getParent().getAppServerVersion(); 486 } else { 487 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, new IllegalStateException ("getAppServerVersion() called on child DConfigBean with null parent: " + this)); 488 } 489 return null; 490 } 491 492 495 protected DDBean getNameDD(String nameXpath) throws ConfigurationException { 496 DDBean nameDD = null; 497 498 DDBean [] beans = getDDBean().getChildBean(nameXpath); 499 if(beans.length == 1) { 500 nameDD = beans[0]; 502 } else { 503 Object [] args = new Object [2]; 504 args[0] = getDDBean().getXpath(); 505 args[1] = nameXpath; 506 507 if(beans.length > 1) { 508 throw Utils.makeCE("ERR_DDBeanHasDuplicateRequiredXpaths", args, null); } else { 510 throw Utils.makeCE("ERR_DDBeanMissingRequiredXpath", args, null); } 512 } 513 514 return nameDD; 515 } 516 517 protected void validateDDBean(DDBean ddBean) throws ConfigurationException { 518 if(ddBean == null) { 520 throw Utils.makeCE("ERR_DDBeanIsNull", null, null); } 522 523 if(ddBean.getXpath() == null) { 525 throw Utils.makeCE("ERR_DDBeanHasNullXpath", null, null); } 527 528 } 530 531 532 533 536 542 public DConfigBean getDConfigBean(DDBean dDBean) 543 throws javax.enterprise.deploy.spi.exceptions.ConfigurationException { 544 try { 545 jsr88Logger.entering(Base.class.toString(),"getDConfigBean",dDBean); 546 547 validateDDBean(dDBean); 548 Base dcbResult = getDCBInstance(dDBean); 549 550 554 if(dcbResult == null) { 555 dcbResult = getDCBFactoryMgr().createDCB(dDBean, this); 556 557 if(dcbResult != null) { 558 putDCBInstance(dcbResult); 559 addChild(dcbResult); 560 561 Base groupHead = dcbResult.getDCBHead(); 565 if(groupHead != null) { 566 dcbResult = groupHead; 567 } 568 569 beanAdded(dcbResult.getDDBean().getXpath()); 571 } 572 } 573 574 return dcbResult; 575 } catch(java.lang.AssertionError ex) { 576 ConfigurationException ce = new ConfigurationException (); 577 ce.initCause(ex); 578 throw ce; 579 } catch(RuntimeException ex) { 580 throw Utils.makeCE("ERR_UnknownConfigException", null, ex); } 582 } 583 584 588 protected void beanAdded(String xpath) { 589 } 590 591 595 protected void beanRemoved(String xpath) { 596 } 597 598 601 public DDBean getDDBean() { 602 return this.dDBean; 603 } 604 605 610 public String [] getXpaths() { 611 return getDCBFactoryMgr().getFactoryKeys(); 612 } 613 614 619 public void notifyDDChange(XpathEvent xpathEvent) { 620 } 622 623 643 650 public void removeDConfigBean(DConfigBean dConfigBean) throws BeanNotFoundException { 651 if(dConfigBean != null) { 652 if(dConfigBean.getDDBean() != null) { 653 if(((Base) dConfigBean).getParent() == this) { 654 656 Base beanToRemove = (Base) dConfigBean; 659 Object children[] = beanToRemove.getChildren().toArray(); 660 for(int i = 0; i < children.length; i++) { 661 try { 662 beanToRemove.removeDConfigBean((Base) children[i]); 663 } catch(BeanNotFoundException ex) { 664 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 667 } 668 } 669 670 DDBean key = dConfigBean.getDDBean(); 671 beanToRemove = removeDCBInstance(key); 672 673 if(beanToRemove != null) { 674 if(beanToRemove instanceof BaseRoot) { 675 BaseRoot rootBean = (BaseRoot) getConfig().getDCBRootCache().remove(key); 677 678 if(rootBean != null) { 679 assert(rootBean == beanToRemove); } 681 } else if(beanToRemove instanceof BaseModuleRef) { 682 getConfig().getPatchList().remove(key); 684 } 685 } 686 687 if(beanToRemove != null) { 688 String beanXpath = beanToRemove.getDDBean().getXpath(); 690 691 beanToRemove.cleanup(); 693 beanToRemove = null; 694 695 beanRemoved(beanXpath); 697 } else { 698 Object [] args = new Object [2]; 699 args[0] = dConfigBean.getDDBean(); 700 args[1] = key.getXpath(); 701 throw new BeanNotFoundException (MessageFormat.format( 702 bundle.getString("ERR_DConfigBeanNotFoundOnRemove"), args)); 703 } 704 } else { 705 throw new BeanNotFoundException ( 707 bundle.getString("ERR_DConfigBeanWrongParentOnRemove")); 708 } 709 } else { 710 throw new BeanNotFoundException ( 713 bundle.getString("ERR_DConfigBeanNotFoundOnRemoveNullDDBean")); 714 } 715 } else { 716 throw new BeanNotFoundException ( 718 bundle.getString("ERR_DConfigBeanNotFoundOnRemoveNullDConfigBean")); 719 } 720 } 721 722 725 public void addPropertyChangeListener(PropertyChangeListener pCL) { 726 propertyChangeSupport.addPropertyChangeListener(pCL); 727 } 728 729 732 public void removePropertyChangeListener(PropertyChangeListener pCL) { 733 propertyChangeSupport.removePropertyChangeListener(pCL); 734 } 735 736 739 protected PropertyChangeSupport getPCS() { 740 return propertyChangeSupport; 741 } 742 743 746 protected VetoableChangeSupport getVCS() { 747 return vetoableChangeSupport; 748 } 749 750 754 public void addVetoableChangeListener(VetoableChangeListener l) { 755 vetoableChangeSupport.addVetoableChangeListener(l); 756 } 757 758 762 public void removeVetoableChangeListener(VetoableChangeListener l) { 763 vetoableChangeSupport.removeVetoableChangeListener(l); 764 } 765 766 769 public Base getParent() { 770 return parent; 771 } 772 773 776 protected ConfigParser getParser() { 777 Base parent = getParent(); 778 if(parent != null) { 779 return parent.getParser(); 780 } 781 782 SunONEDeploymentConfiguration config = getConfig(); 783 if(config != null) { 784 BaseRoot dcbRoot = config.getMasterDCBRoot(); 785 if(dcbRoot != null) { 786 return dcbRoot.getParser(); 787 } 788 } 789 790 return null; 791 } 792 793 801 abstract Collection getSnippets(); 802 803 811 abstract boolean loadFromPlanFile(SunONEDeploymentConfiguration config); 812 813 823 public void addToGraphs(Map map, CommonDDBean bbCurrent, String bbKey) { 824 jsr88Logger.entering(this.getClass().toString(), "addToGraphs"); 826 String uriText = getUriText(); 827 Collection snippets = getSnippets(); 828 829 boolean isFirst = true; 830 CommonDDBean newCurrentBean = null; 831 String newSnippetKey = ""; 832 833 Iterator iter = snippets.iterator(); 834 while(iter.hasNext()) { 835 try { 836 CommonDDBean bean = null; 837 Snippet s = (Snippet) iter.next(); 838 839 if(s.hasDDSnippet()) { 840 String snippetKey = Utils.getFQNKey(uriText, s.getFileName()); 841 if(snippetKey.compareTo(bbKey) == 0) { 842 bean = s.mergeIntoRovingDD(bbCurrent); 844 } else if(map.containsKey(snippetKey)) { 845 try { 854 bean = s.mergeIntoRootDD((CommonDDBean) map.get(snippetKey)); 855 } catch(UnsupportedOperationException ex) { 856 jsr88Logger.finest("Invalid Snippet: Snippet Class: " + s.getClass().getName()); 857 CommonDDBean parent = (CommonDDBean) map.get(snippetKey); 858 jsr88Logger.finest("Parent Bean: " + ((parent != null) ? parent.getClass().getName() : "(null -- ack!)")); 859 jsr88Logger.finest("Snippet Key: " + snippetKey); 860 jsr88Logger.finest("Snippet Property Name: " + s.getPropertyName()); 861 throw ex; 862 } 863 } else { 864 bean = s.getDDSnippet(); 866 867 if(bean != null) { 869 map.put(snippetKey, bean); 870 } 871 } 872 873 if(isFirst) { 874 newCurrentBean = bean; 876 newSnippetKey = snippetKey; 877 isFirst = false; 878 } 879 } 880 } catch(Exception ex) { 881 jsr88Logger.log(Level.SEVERE, "Base.newAddToGraph() -- exception processing bean", ex); ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 883 } 884 } 885 886 Collection childList = getChildren(); 889 iter = childList.iterator(); 890 while(iter.hasNext()) { 891 Base childDCB = (Base) iter.next(); 892 childDCB.addToGraphs(map, processParentBean(newCurrentBean, childDCB), newSnippetKey); 893 } 894 895 jsr88Logger.exiting(this.getClass().toString(), "addToGraphs"); } 897 898 903 protected CommonDDBean processParentBean(CommonDDBean bean, DConfigBean child) { 904 return bean; 909 } 910 911 914 Collection getChildren() { 915 return children; 916 } 917 918 public String getUriText() { 919 if(parent != null) { 920 return parent.getUriText(); 921 } 922 923 return ""; } 927 928 static private char XPATH_SEPCHAR = '/'; 929 930 931 933 936 static String cleanDDBeanText(DDBean dDBean) { 937 String candidate = null; 938 939 try { 940 if(dDBean == null) { 941 return candidate; 942 } 943 944 candidate = dDBean.getText(); 945 if (null == candidate || (candidate.length() == 0)) { 946 return candidate; 947 } 948 949 if (!candidate.startsWith("<?xml")) { return candidate; 951 } 952 953 String xpath = dDBean.getXpath(); 954 if (null == xpath || (xpath.length() == 0)) { 955 return candidate; 956 } 957 958 int lindex = xpath.lastIndexOf(XPATH_SEPCHAR); 959 if (lindex > -1) { 960 lindex += 1; 961 String finalEl = xpath.substring(lindex); 962 finalEl = "<" + finalEl + ">"; int elementPos = candidate.indexOf(finalEl); 964 if (elementPos < 0) { 965 return candidate; 966 } 967 String retVal = candidate.substring(elementPos + finalEl.length()); 968 if (retVal.length() < finalEl.length() + 1) { 969 return retVal; 970 } 971 retVal = retVal.substring(0,retVal.length() - (finalEl.length()+2)); 972 return retVal; 973 } 974 } catch(RuntimeException ex) { 975 jsr88Logger.throwing("Base", "cleanDDBeanText", ex); } 977 978 return candidate; 979 } 980 981 private DDBean secondary; 982 private Set children = new LinkedHashSet (); 983 984 987 protected void addChild(DConfigBean bean) { 988 children.add(bean); 989 } 990 991 protected boolean removeChild(DConfigBean bean) { 992 return children.remove(bean); 993 } 994 995 998 void setSecondary(DDBean secondary) { 999 this.secondary = secondary; 1000 } 1001 1002 1005 public SunONEDeploymentConfiguration getConfig() { 1006 if (null != parent) { 1007 return parent.getConfig(); 1008 } 1009 1010 return null; 1011 } 1012 1013 1020 1027 public DConfigBeanProperties getUICustomization(DConfigBean self) { 1028 return new DConfigBeanProperties() { 1029 public String getDisplayName() { 1030 return Base.this.getDisplayName(); 1031 } 1032 1033 public String getHelpId() { 1034 return Base.this.getHelpId(); 1035 } 1036 }; 1037 } 1038 1039 1042 public String getDisplayName() { 1043 String name = getComponentName(); 1047 Object [] args = new Object [1]; 1048 args[0] = Utils.notEmpty(name) ? name : getDescriptorElement(); 1049 String pattern = bundle.getString(isValid() ? "LBL_BeanDisplayName" : "LBL_BeanDisplayNameBroken"); 1050 return MessageFormat.format(pattern, args); 1051 } 1052 1053 1058 abstract public String getHelpId(); 1059 1066 1070 1071 1074 protected void putDCBInstance(Base base) { 1075 DDBean key = base.getDDBean(); 1076 if(key != null) { 1077 SunONEDeploymentConfiguration config = getConfig(); 1078 if(config != null) { 1079 Map cache = config.getDCBCache(); 1080 1081 Object existingDCB = cache.get(key); 1082 if(existingDCB != null) { 1083 } else { 1085 } 1087 1088 cache.put(key, base); 1089 } else { 1090 } 1092 } else { 1093 } 1095 } 1096 1097 1101 protected Base getDCBInstance(DDBean key) { 1102 1104 Base result = null; 1105 SunONEDeploymentConfiguration config = getConfig(); 1106 1107 if(config != null) { 1108 Map cache = config.getDCBCache(); 1109 Object o = cache.get(key); 1110 1111 if(o != null) { 1112 if(o instanceof Base) { 1113 result = (Base) o; 1114 } else { 1115 } 1117 } else { 1118 } 1120 } else { 1121 } 1123 1124 return result; 1125 } 1126 1127 1131 protected Base removeDCBInstance(Base base) { 1132 return removeDCBInstance(base.getDDBean()); 1133 } 1134 1135 1139 protected Base removeDCBInstance(DDBean key) { 1140 Base result = null; 1141 SunONEDeploymentConfiguration config = getConfig(); 1142 1143 if(config != null) { 1144 Map cache = config.getDCBCache(); 1145 Object o = cache.remove(key); 1146 1147 if(o != null) { 1148 if(o instanceof Base) { 1149 result = (Base) o; 1150 } else { 1151 } 1153 } 1154 } else { 1155 } 1157 1158 return result; 1159 } 1160 1161 1169 1171 1175 private Map dcbChildGroupMap = null; 1176 1177 1181 protected Base getDCBGroup(DDBean dDBean) { 1182 Base dcbResult = null; 1183 1184 if(dcbChildGroupMap != null) { 1185 dcbResult = (Base) dcbChildGroupMap.get(dDBean.getXpath()); 1186 } 1187 1188 return dcbResult; 1189 } 1190 1191 1194 protected void addDCBGroup(Base dcb) { 1195 if(dcbChildGroupMap == null) { 1196 dcbChildGroupMap = new HashMap (7); 1197 } 1198 1199 if(getDCBGroup(dcb.getDDBean()) == null) { 1200 dcbChildGroupMap.put(dcb.getDDBean().getXpath(), dcb); 1201 } 1202 } 1203 1204 1206 1207 private List groupDCBList = null; 1208 private Base dcbHead = null; 1209 1210 1217 protected void initGroup(DDBean dDBean, Base parent) { 1218 if(parent != null) { 1219 Base dcb = parent.getDCBGroup(dDBean); 1220 if(dcb != null) { 1221 1224 dcbHead = dcb; 1225 dcbHead.addDCBToGroup(this); 1226 } else { 1227 1230 dcbHead = this; 1231 addDCBToGroup(this); 1232 1233 parent.addDCBGroup(this); 1234 } 1235 } 1236 } 1237 1238 1248 private void addDCBToGroup(Base dcb) { 1249 if(groupDCBList == null) { 1250 groupDCBList = new ArrayList (10); 1251 } 1252 1253 groupDCBList.add(dcb); 1254 } 1255 1256 1259 protected Base getDCBHead() { 1260 return dcbHead; 1261 } 1262 1263 1266 private static final java.util.Map defaultXPathToFactory = new java.util.HashMap (); 1267 1268 1272 protected java.util.Map getXPathToFactoryMap() { 1273 return defaultXPathToFactory; 1274 } 1275 1276 private DCBFactoryMgr factoryMgrInstance = null; 1277 1278 1282 DCBFactoryMgr getDCBFactoryMgr() { 1283 if(factoryMgrInstance == null) { 1284 factoryMgrInstance = new DCBFactoryMgr(getXPathToFactoryMap(), getDDBean().getXpath()); 1285 } 1286 1287 return factoryMgrInstance; 1288 } 1289 1290 1293 1294 1297 protected String constructFileName() { 1298 String ddXpath = dDBean.getXpath(); 1299 StringBuffer fname = new StringBuffer (32); 1300 fname.append("sun-"); 1302 if(null != ddXpath) { 1303 if(ddXpath.startsWith("/ejb-jar")) { fname.append("ejb-jar"); } else if(ddXpath.startsWith("/web-app")) { fname.append("web"); } else if(ddXpath.startsWith("/application")) { if (ddXpath.indexOf("client") > -1 ) { fname.append("application-client"); } else { 1311 fname.append("application"); } 1313 } else if(ddXpath.startsWith("/connector")) { fname.append("connector"); } else { 1316 String mess = MessageFormat.format(bundle.getString("ERR_InvalidXPathValueUsage"), new Object [] { ddXpath }); 1318 throw new java.lang.IllegalStateException (mess); 1319 } 1320 } else { 1321 throw new java.lang.IllegalStateException ("null Xpath value"); } 1324 1325 fname.append(".xml"); return fname.toString(); 1327 } 1328 1329 1338 abstract class DefaultSnippet implements Snippet { 1339 1340 public abstract CommonDDBean getDDSnippet(); 1341 1342 public org.netbeans.modules.schema2beans.BaseBean getCmpDDSnippet() { 1343 return null; 1344 } 1345 1346 public boolean hasDDSnippet() { 1347 return true; 1348 } 1349 1350 public String getFileName() { 1351 return constructFileName(); 1352 } 1353 1354 public CommonDDBean mergeIntoRootDD(CommonDDBean ddRoot) { 1355 throw new java.lang.UnsupportedOperationException (); 1356 } 1357 1358 public CommonDDBean mergeIntoRovingDD(CommonDDBean ddParent) { 1359 CommonDDBean newBean = getDDSnippet(); 1360 if(newBean != null) { 1361 if(ddParent != null) { 1362 String propertyName = getPropertyName(); 1363 if(propertyName != null) { 1364 ddParent.addValue(propertyName, newBean); 1365 } else { 1366 jsr88Logger.severe("No property name for " + Base.this.getClass()); } 1368 } else { 1369 jsr88Logger.severe("mergeIntoRovingDD() called with null parent (called on root bean?)"); } 1371 } else { 1372 jsr88Logger.severe("No snippet to merge for " + Base.this.getClass()); } 1374 return newBean; 1375 } 1376 1377 public String getPropertyName() { 1378 return null; 1379 } 1380 } 1381 1382 protected static class NameBasedFinder implements ConfigFinder { 1383 private String propertyName; 1384 private String propertyValue; 1385 private Class beanType; 1386 1387 public NameBasedFinder(String propName, String propValue, Class type) { 1388 this.propertyName = propName; 1389 this.propertyValue = propValue; 1390 this.beanType = type; 1391 } 1392 1393 public Object find(Object obj) { 1394 Object result = null; 1395 CommonDDBean root = (CommonDDBean) obj; 1396 String [] props = root.findPropertyValue(propertyName, propertyValue); 1397 1398 for(int i = 0; i < props.length; i++) { 1399 CommonDDBean candidate = root.getPropertyParent(props[i]); 1400 if(beanType.isInstance(candidate)) { 1401 result = candidate; 1402 break; 1403 } 1404 } 1405 1406 return result; 1407 } 1408 } 1409} 1410 | Popular Tags |