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