1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.modeler.modules;
18
19 import java.io.File;
20 import java.io.FileInputStream;
21 import java.io.IOException;
22 import java.io.InputStream;
23 import java.net.URL;
24 import java.util.List;
25
26 import javax.management.ObjectName;
27
28 import org.apache.commons.modeler.Registry;
29
30 /*** Source for descriptor data. More sources can be added.
31 *
32 */
33 public class ModelerSource {
34 protected Object source;
35 protected String location;
36
37 /*** Load data, returns a list of items.
38 *
39 * @param registry
40 * @param location
41 * @param type
42 * @param source Introspected object or some other source
43 * @throws Exception
44 */
45 public List loadDescriptors( Registry registry, String location,
46 String type, Object source)
47 throws Exception
48 {
49
50 return null;
51 }
52
53 /*** Callback from the BaseMBean to notify that an attribute has changed.
54 * Can be used to implement persistence.
55 *
56 * @param oname
57 * @param name
58 * @param value
59 */
60 public void updateField( ObjectName oname, String name,
61 Object value ) {
62
63 }
64
65 public void store() {
66
67 }
68
69 protected InputStream getInputStream() throws IOException {
70 if( source instanceof URL ) {
71 URL url=(URL)source;
72 location=url.toString();
73 return url.openStream();
74 } else if( source instanceof File ) {
75 location=((File)source).getAbsolutePath();
76 return new FileInputStream((File)source);
77 } else if( source instanceof String) {
78 location=(String)source;
79 return new FileInputStream((String)source);
80 } else if( source instanceof InputStream ) {
81 return (InputStream)source;
82 }
83 return null;
84 }
85
86 }