1 19 20 26 27 package org.netbeans.modules.j2ee.dd.impl.common; 28 29 import java.io.OutputStream ; 30 import org.netbeans.modules.schema2beans.Version; 31 import org.netbeans.modules.schema2beans.BaseBean; 32 import org.netbeans.modules.j2ee.dd.api.common.CommonDDBean; 33 import org.netbeans.modules.j2ee.dd.api.common.NameAlreadyUsedException; 34 import org.netbeans.modules.j2ee.dd.api.common.CreateCapability; 35 import org.netbeans.modules.j2ee.dd.api.common.FindCapability; 36 import org.netbeans.modules.j2ee.dd.api.common.RootInterface; 37 import org.openide.filesystems.FileLock; 38 39 public abstract class EnclosingBean extends BaseBean implements CommonDDBean, CreateCapability, FindCapability { 40 41 private Object original = this; 42 43 44 public EnclosingBean(java.util.Vector comps, Version version) { 45 super(comps, version); 46 } 47 48 56 public CommonDDBean findBeanByName(String beanName, String propertyName, String value) { 57 return (CommonDDBean)CommonDDAccess.findBeanByName(this, beanName, propertyName, value); 58 } 59 60 66 public CommonDDBean createBean(String beanName) throws ClassNotFoundException { 67 return (CommonDDBean)CommonDDAccess.newBean(this, beanName, getPackagePostfix()); 68 } 69 70 private String getPackagePostfix() { 71 String pack = getClass().getPackage().getName(); 72 return pack; 75 } 76 77 82 public void write(org.openide.filesystems.FileObject fo) throws java.io.IOException { 83 FileLock lock = fo.lock(); 85 try { 86 OutputStream os = fo.getOutputStream(lock); 87 try { 88 write(os); 89 } finally { 90 os.close(); 91 } 92 } finally { 93 lock.releaseLock(); 94 } 95 } 96 97 public CommonDDBean addBean(String beanName, String [] propertyNames, Object [] propertyValues, String keyProperty) throws ClassNotFoundException , NameAlreadyUsedException { 98 if (keyProperty!=null) { 99 Object keyValue = null; 100 if (propertyNames!=null) 101 for (int i=0;i<propertyNames.length;i++) { 102 if (keyProperty.equals(propertyNames[i])) { 103 keyValue=propertyValues[i]; 104 break; 105 } 106 } 107 if (keyValue!=null && keyValue instanceof String ) { 108 if (findBeanByName(beanName, keyProperty,(String )keyValue)!=null) { 109 throw new NameAlreadyUsedException(beanName, keyProperty, (String )keyValue); 110 } 111 } 112 } 113 CommonDDBean newBean = createBean(beanName); 114 if (propertyNames!=null) 115 for (int i=0;i<propertyNames.length;i++) { 116 try { 117 ((BaseBean)newBean).setValue(propertyNames[i],propertyValues[i]); 118 } catch (IndexOutOfBoundsException ex) { 119 ((BaseBean)newBean).setValue(propertyNames[i],new Object []{propertyValues[i]}); 120 } 121 } 122 CommonDDAccess.addBean(this, newBean, beanName, getPackagePostfix()); 123 return newBean; 124 } 125 126 public CommonDDBean addBean(String beanName) throws ClassNotFoundException { 127 try { 128 return addBean(beanName,null,null,null); 129 } catch (NameAlreadyUsedException ex){} 130 return null; 131 } 132 133 public Object getOriginal() { 134 return original; 135 } 136 137 public Object clone() { 138 EnclosingBean enclosingBean = (EnclosingBean) super.clone(); 139 enclosingBean.original = original; 140 return enclosingBean; 141 } 142 143 public void merge(RootInterface root, int mode) { 144 this.merge((BaseBean)root,mode); 145 } 146 147 public static final String ID = "Id"; 149 public void setId(String value) { 150 setAttributeValue(ID, value); 151 } 152 153 public String getId() { 154 return getAttributeValue(ID); 155 } 156 157 } 158 | Popular Tags |