01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
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) throws Exception {
47: // TODO
48: return null;
49: }
50:
51: /** Callback from the BaseMBean to notify that an attribute has changed.
52: * Can be used to implement persistence.
53: *
54: * @param oname
55: * @param name
56: * @param value
57: */
58: public void updateField(ObjectName oname, String name, Object value) {
59: // nothing by default
60: }
61:
62: public void store() {
63: // nothing
64: }
65:
66: protected InputStream getInputStream() throws IOException {
67: if (source instanceof URL) {
68: URL url = (URL) source;
69: location = url.toString();
70: return url.openStream();
71: } else if (source instanceof File) {
72: location = ((File) source).getAbsolutePath();
73: return new FileInputStream((File) source);
74: } else if (source instanceof String) {
75: location = (String) source;
76: return new FileInputStream((String) source);
77: } else if (source instanceof InputStream) {
78: return (InputStream) source;
79: }
80: return null;
81: }
82:
83: }
|