001: /*
002: * Copyright 2004 (C) TJDO.
003: * All rights reserved.
004: *
005: * This software is distributed under the terms of the TJDO License version 1.0.
006: * See the terms of the TJDO License in the documentation provided with this software.
007: *
008: * $Id: MetaData.java,v 1.8 2004/01/18 03:01:06 jackknifebarber Exp $
009: */
010:
011: package com.triactive.jdo.model;
012:
013: import java.net.URL;
014: import java.util.HashMap;
015: import java.util.Properties;
016: import java.util.List;
017: import java.util.Set;
018: import org.w3c.dom.Element;
019: import org.w3c.dom.Node;
020:
021: public abstract class MetaData {
022: /**
023: * The vendor string used for TJDO-specific metadata extensions. This is
024: * the string "triactive".
025: */
026: public static final String MY_VENDOR = "triactive";
027:
028: protected final HashMap vendorExtensions = new HashMap();
029:
030: protected MetaData() {
031: }
032:
033: protected MetaData(URL url, Element elem) {
034: addVendorExtensions(url, elem);
035: }
036:
037: /**
038: * Add the vendor extensions found nested within the given Element.
039: * @param url The URL that this is the resource that this Element came from.
040: * @param elem The Element to obtain the vendor extensions from.
041: */
042: protected void addVendorExtensions(URL url, Element elem) {
043: for (Node node = elem.getFirstChild(); node != null; node = node
044: .getNextSibling()) {
045: if (node instanceof Element) {
046: Element child = (Element) node;
047: String childTag = child.getTagName();
048:
049: if (childTag.equals("extension")) {
050: String vendorName = child
051: .getAttribute("vendor-name");
052: String key = child.getAttribute("key");
053: String value = child.getAttribute("value");
054:
055: Properties p = (Properties) vendorExtensions
056: .get(vendorName);
057:
058: if (p == null) {
059: p = new Properties();
060: vendorExtensions.put(vendorName, p);
061: }
062:
063: p.put(key, value);
064: }
065: }
066: }
067: }
068:
069: abstract void getReferencedClasses(final String vendorID,
070: final List ordered, final Set referenced);
071:
072: public abstract String getJavaName();
073:
074: public String getVendorExtension(String vendorName, String key) {
075: Properties p = (Properties) vendorExtensions.get(vendorName);
076:
077: if (p == null)
078: return null;
079: else
080: return (String) p.get(key);
081: }
082:
083: protected static Class getReferencedType(String typeAttr,
084: ClassMetaData owner) {
085: Class type;
086:
087: if (typeAttr.indexOf('.') < 0)
088: typeAttr = owner.getPackageName() + '.' + typeAttr;
089:
090: try {
091: type = Class.forName(typeAttr, true, owner.getPCClass()
092: .getClassLoader());
093: } catch (ClassNotFoundException e) {
094: throw new XMLMetaDataException(owner.getSourceURL(),
095: "Linkage class not found, referenced by "
096: + owner.getPCClass().getName(), e);
097: }
098:
099: return type;
100: }
101: }
|