KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > triactive > jdo > model > MetaData


1 /*
2  * Copyright 2004 (C) TJDO.
3  * All rights reserved.
4  *
5  * This software is distributed under the terms of the TJDO License version 1.0.
6  * See the terms of the TJDO License in the documentation provided with this software.
7  *
8  * $Id: MetaData.java,v 1.8 2004/01/18 03:01:06 jackknifebarber Exp $
9  */

10
11 package com.triactive.jdo.model;
12
13 import java.net.URL JavaDoc;
14 import java.util.HashMap JavaDoc;
15 import java.util.Properties JavaDoc;
16 import java.util.List JavaDoc;
17 import java.util.Set JavaDoc;
18 import org.w3c.dom.Element JavaDoc;
19 import org.w3c.dom.Node JavaDoc;
20
21 public abstract class MetaData
22 {
23     /**
24      * The vendor string used for TJDO-specific metadata extensions. This is
25      * the string "triactive".
26      */

27     public static final String JavaDoc MY_VENDOR = "triactive";
28
29     protected final HashMap JavaDoc vendorExtensions = new HashMap JavaDoc();
30
31     protected MetaData()
32     {
33     }
34
35     protected MetaData(URL JavaDoc url, Element JavaDoc elem)
36     {
37         addVendorExtensions(url, elem);
38     }
39
40     /**
41      * Add the vendor extensions found nested within the given Element.
42      * @param url The URL that this is the resource that this Element came from.
43      * @param elem The Element to obtain the vendor extensions from.
44      */

45     protected void addVendorExtensions(URL JavaDoc url, Element JavaDoc elem)
46     {
47         for (Node JavaDoc node = elem.getFirstChild(); node != null; node = node.getNextSibling())
48         {
49             if (node instanceof Element JavaDoc)
50             {
51                 Element JavaDoc child = (Element JavaDoc)node;
52                 String JavaDoc childTag = child.getTagName();
53
54                 if (childTag.equals("extension"))
55                 {
56                     String JavaDoc vendorName = child.getAttribute("vendor-name");
57                     String JavaDoc key = child.getAttribute("key");
58                     String JavaDoc value = child.getAttribute("value");
59
60                     Properties JavaDoc p = (Properties JavaDoc)vendorExtensions.get(vendorName);
61
62                     if (p == null)
63                     {
64                         p = new Properties JavaDoc();
65                         vendorExtensions.put(vendorName, p);
66                     }
67
68                     p.put(key, value);
69                 }
70             }
71         }
72     }
73
74     abstract void getReferencedClasses(final String JavaDoc vendorID, final List JavaDoc ordered, final Set JavaDoc referenced);
75
76     public abstract String JavaDoc getJavaName();
77
78     public String JavaDoc getVendorExtension(String JavaDoc vendorName, String JavaDoc key)
79     {
80         Properties JavaDoc p = (Properties JavaDoc)vendorExtensions.get(vendorName);
81
82         if (p == null)
83             return null;
84         else
85             return (String JavaDoc)p.get(key);
86     }
87
88     protected static Class JavaDoc getReferencedType(String JavaDoc typeAttr, ClassMetaData owner)
89     {
90         Class JavaDoc 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 JavaDoc 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