1 10 11 package com.triactive.jdo.model; 12 13 import java.net.URL ; 14 import java.util.HashMap ; 15 import java.util.Properties ; 16 import java.util.List ; 17 import java.util.Set ; 18 import org.w3c.dom.Element ; 19 import org.w3c.dom.Node ; 20 21 public abstract class MetaData 22 { 23 27 public static final String MY_VENDOR = "triactive"; 28 29 protected final HashMap vendorExtensions = new HashMap (); 30 31 protected MetaData() 32 { 33 } 34 35 protected MetaData(URL url, Element elem) 36 { 37 addVendorExtensions(url, elem); 38 } 39 40 45 protected void addVendorExtensions(URL url, Element elem) 46 { 47 for (Node node = elem.getFirstChild(); node != null; node = node.getNextSibling()) 48 { 49 if (node instanceof Element ) 50 { 51 Element child = (Element )node; 52 String childTag = child.getTagName(); 53 54 if (childTag.equals("extension")) 55 { 56 String vendorName = child.getAttribute("vendor-name"); 57 String key = child.getAttribute("key"); 58 String value = child.getAttribute("value"); 59 60 Properties p = (Properties )vendorExtensions.get(vendorName); 61 62 if (p == null) 63 { 64 p = new Properties (); 65 vendorExtensions.put(vendorName, p); 66 } 67 68 p.put(key, value); 69 } 70 } 71 } 72 } 73 74 abstract void getReferencedClasses(final String vendorID, final List ordered, final Set referenced); 75 76 public abstract String getJavaName(); 77 78 public String getVendorExtension(String vendorName, String key) 79 { 80 Properties p = (Properties )vendorExtensions.get(vendorName); 81 82 if (p == null) 83 return null; 84 else 85 return (String )p.get(key); 86 } 87 88 protected static Class getReferencedType(String typeAttr, ClassMetaData owner) 89 { 90 Class type; 91 92 if (typeAttr.indexOf('.') < 0) 93 typeAttr = owner.getPackageName() + '.' + typeAttr; 94 95 try 96 { 97 type = Class.forName(typeAttr, true, owner.getPCClass().getClassLoader()); 98 } 99 catch (ClassNotFoundException e) 100 { 101 throw new XMLMetaDataException(owner.getSourceURL(), "Linkage class not found, referenced by " + owner.getPCClass().getName(), e); 102 } 103 104 return type; 105 } 106 } 107 | Popular Tags |