1 42 43 package com.caucho.j2ee; 44 45 import com.caucho.config.ConfigException; 46 import com.caucho.util.L10N; 47 48 import org.w3c.dom.DocumentType ; 49 import org.w3c.dom.Element ; 50 51 54 public enum J2EEVersion { 55 J2EE12 { 56 public boolean hasFeaturesOf(J2EEVersion version) 57 { 58 return version == J2EE12; 59 } 60 }, 61 62 J2EE13 { 63 public boolean hasFeaturesOf(J2EEVersion version) 64 { 65 return version == J2EE12 66 || version == J2EE13; 67 } 68 }, 69 70 J2EE14 { 71 public boolean hasFeaturesOf(J2EEVersion version) 72 { 73 return version == J2EE12 74 || version == J2EE13 75 || version == J2EE14; 76 } 77 }, 78 79 JAVAEE5 { 80 public boolean hasFeaturesOf(J2EEVersion version) 81 { 82 return version == J2EE12 83 || version == J2EE13 84 || version == J2EE14 85 || version == JAVAEE5; 86 } 87 }, 88 89 RESIN { 90 public boolean hasFeaturesOf(J2EEVersion version) 91 { 92 return true; 93 } 94 }; 95 96 private static final L10N L = new L10N(J2EEVersion.class); 97 98 public static final String J2EE_NAMESPACE = "http://java.sun.com/xml/ns/j2ee"; 99 public static final String JAVAEE_NAMESPACE = "http://java.sun.com/xml/ns/javaee"; 100 public static final String RESIN_NAMESPACE = "http://caucho.com/ns/resin"; 101 102 108 public static J2EEVersion getJ2EEVersion(Element top) 109 { 110 String version = top.getAttribute("version"); 111 String ns = top.getNamespaceURI(); 112 113 if (version.length() > 0) { 114 if (ns == null) 115 throw new ConfigException(L.l("namespace is required because version is specified, either xmlns='{0}', xmlns='{1}', or xmlns='{2}'", 116 RESIN_NAMESPACE, 117 JAVAEE_NAMESPACE, 118 J2EE_NAMESPACE)); 119 120 if (ns.equals(J2EE_NAMESPACE)) { 121 if (version.equals("1.4")) 122 return J2EE14; 123 else 124 throw new ConfigException(L.l("version must be '{0}' for namespace '{1}'", "1.4", ns)); 125 } 126 else if (ns.equals(JAVAEE_NAMESPACE)) { 127 if (version.equals("5")) 128 return JAVAEE5; 129 else 130 throw new ConfigException(L.l("version must be '{0}' for namespace '{1}'", "5", ns)); 131 } 132 else if (ns.equals(RESIN_NAMESPACE)) { 133 return RESIN; 134 } 135 } 136 else if (ns != null) { 137 if (ns.equals(RESIN_NAMESPACE)) 138 return RESIN; 139 140 throw new ConfigException(L.l("unknown namespace '{0}', namespace must be one of xmlns='{1}', xmlns='{2}', or xmlns='{3}'", 141 ns, 142 RESIN_NAMESPACE, 143 JAVAEE_NAMESPACE, 144 J2EE_NAMESPACE)); 145 } 146 147 DocumentType doctype = top.getOwnerDocument().getDoctype(); 148 149 if (doctype != null) { 150 String publicId = doctype.getPublicId(); 151 152 if (publicId != null) { 153 if (publicId.contains("1.3")) 154 return J2EE13; 155 } 156 } 157 158 return J2EE12; 159 } 160 161 165 abstract public boolean hasFeaturesOf(J2EEVersion version); 166 } 167 | Popular Tags |