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