1 19 20 package org.netbeans.modules.j2ee.ddloaders.app; 21 22 import java.io.IOException ; 23 import java.io.InputStream ; 24 import org.netbeans.modules.schema2beans.BaseBean; 25 import org.netbeans.modules.j2ee.dd.api.common.CommonDDBean; 26 import org.netbeans.modules.j2ee.dd.api.application.DDProvider; 27 import org.netbeans.modules.j2ee.dd.impl.application.ApplicationProxy; 28 import org.netbeans.modules.j2ee.dd.api.application.Application; 29 import org.xml.sax.InputSource ; 30 import org.xml.sax.SAXException ; 31 32 33 37 public class EarDDUtils { 38 private EarDDUtils() {} 39 40 48 public static String findFreeName (CommonDDBean[] elements, String identifier, String name) { 49 if (checkFreeName (elements, identifier, name)) { 50 return name; 51 } 52 for (int i = 1;;i++) { 53 String destName = name + "_"+i; if (checkFreeName (elements, identifier, destName)) { 55 return destName; 56 } 57 } 58 } 59 60 66 private static boolean checkFreeName (CommonDDBean [] elements, String identifier, Object o) { 67 for (int i=0; i<elements.length; i++) { 68 Object val = elements[i].getValue (identifier); 69 if (val != null && val.equals (o)) { 70 return false; 71 } 72 } 73 return true; 74 } 75 76 78 public static BaseBean getBaseBean(CommonDDBean bean) { 79 if (bean instanceof BaseBean) return (BaseBean)bean; 80 else if (bean instanceof ApplicationProxy) return (BaseBean) ((ApplicationProxy)bean).getOriginal(); 81 return null; 82 } 83 84 public static Application createApplication(InputSource is) throws IOException , SAXException { 85 return DDProvider.getDefault().getDDRoot(is); 86 } 87 } 88 | Popular Tags |