View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    * 
9    *      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)
47              throws Exception
48      {
49          // TODO
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          // nothing by default 
63      }
64  
65      public void store() {
66          // nothing
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  }