Package java.lang.reflect

Examples of java.lang.reflect.Method


  @Test
  public void testGetMethod()
  {
    DispatchControllerHelper helper = new DispatchControllerHelper();
    SimpleDispatchAction action = new SimpleDispatchAction();
    Method method1 = helper.getMethod(action, "insert");
    Method method2 = helper.getMethod(action, "insert");
    assert method1 == method2;
  }
View Full Code Here


  @Test
  public void testConverterReader() throws Exception
  {
    Class c = FormWithDateConverter.class;
    Method method = c.getMethod("getStartDate");

    ConverterReader converterReader = new ConverterReader();
    Converter converter = converterReader.readConverter(method);

    assert converter instanceof DatePatternConverter;
View Full Code Here

  @Test
  public void testReorderedConverter() throws Exception
  {
    Class c = BeanWithReorderedConverters.class;
    Method method = c.getMethod("getDate");

    ConverterReader converterReader = new ConverterReader();
    Converter converter = converterReader.readConverter(method);

    assert converter instanceof DatePatternConverter;
View Full Code Here

    try
    {

      Class c = BeanWithTwoConverters.class;
      Method method = c.getMethod("getDate");

      ConverterReader converterReader = new ConverterReader();
      converterReader.readConverter(method);

    }
View Full Code Here

    m_HelpText = null;
    // Look for a globalInfo method that returns a string
    // describing the target
    for (int i = 0;i < m_Methods.length; i++) {
      String name = m_Methods[i].getDisplayName();
      Method meth = m_Methods[i].getMethod();
      if (name.equals("globalInfo")) {
  if (meth.getReturnType().equals(String.class)) {
    try {
      Object args[] = { };
      String globalInfo = (String)(meth.invoke(m_Target, args));
            String summary = globalInfo;
            int ci = globalInfo.indexOf('.');
            if (ci != -1) {
              summary = globalInfo.substring(0, ci + 1);
            }
      final String className = targ.getClass().getName();
            m_HelpText = new StringBuffer("NAME\n");
            m_HelpText.append(className).append("\n\n");
            m_HelpText.append("SYNOPSIS\n").append(globalInfo).append("\n\n");
            m_HelpBut = new JButton("More");
      m_HelpBut.setToolTipText("More information about "
                                     + className);
     
      m_HelpBut.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent a) {
                openHelpFrame();
                m_HelpBut.setEnabled(false);
              }
            });

      if (m_Target instanceof CapabilitiesHandler) {
        m_CapabilitiesBut = new JButton("Capabilities");
        m_CapabilitiesBut.setToolTipText("The capabilities of "
      + className);
       
        m_CapabilitiesBut.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent a) {
      openCapabilitiesHelpDialog();
      m_CapabilitiesBut.setEnabled(false);
    }
        });
      }
      else {
        m_CapabilitiesBut = null;
      }

      jt.setColumns(30);
      jt.setFont(new Font("SansSerif", Font.PLAIN,12));
      jt.setEditable(false);
      jt.setLineWrap(true);
      jt.setWrapStyleWord(true);
      jt.setText(summary);
            jt.setBackground(getBackground());
      JPanel jp = new JPanel();
      jp.setBorder(BorderFactory.createCompoundBorder(
       BorderFactory.createTitledBorder("About"),
       BorderFactory.createEmptyBorder(5, 5, 5, 5)
     ));
      jp.setLayout(new BorderLayout());
      jp.add(jt, BorderLayout.CENTER);
            JPanel p2 = new JPanel();
            p2.setLayout(new BorderLayout());
            p2.add(m_HelpBut, BorderLayout.NORTH);
            if (m_CapabilitiesBut != null) {
              JPanel p3 = new JPanel();
              p3.setLayout(new BorderLayout());
              p3.add(m_CapabilitiesBut, BorderLayout.NORTH);
              p2.add(p3, BorderLayout.CENTER);
            }
            jp.add(p2, BorderLayout.EAST);
      GridBagConstraints gbConstraints = new GridBagConstraints();
      //      gbConstraints.anchor = GridBagConstraints.EAST;
      gbConstraints.fill = GridBagConstraints.BOTH;
      //      gbConstraints.gridy = 0;     gbConstraints.gridx = 0;
      gbConstraints.gridwidth = 2;
      gbConstraints.insets = new Insets(0,5,0,5);
      gbLayout.setConstraints(jp, gbConstraints);
      m_aboutPanel = jp;
      scrollablePanel.add(m_aboutPanel);
      componentOffset = 1;
      break;
    } catch (Exception ex) {
     
    }
  }
      }
    }

    m_Editors = new PropertyEditor[m_Properties.length];
    m_Values = new Object[m_Properties.length];
    m_Views = new JComponent[m_Properties.length];
    m_Labels = new JLabel[m_Properties.length];
    m_TipTexts = new String[m_Properties.length];
    boolean firstTip = true;
    for (int i = 0; i < m_Properties.length; i++) {

      // Don't display hidden or expert properties.
      if (m_Properties[i].isHidden() || m_Properties[i].isExpert()) {
  continue;
      }

      String name = m_Properties[i].getDisplayName();
      Class type = m_Properties[i].getPropertyType();
      Method getter = m_Properties[i].getReadMethod();
      Method setter = m_Properties[i].getWriteMethod();

      // Only display read/write properties.
      if (getter == null || setter == null) {
  continue;
      }
 
      JComponent view = null;

      try {
  Object args[] = { };
  Object value = getter.invoke(m_Target, args);
  m_Values[i] = value;

  PropertyEditor editor = null;
  Class pec = m_Properties[i].getPropertyEditorClass();
  if (pec != null) {
    try {
      editor = (PropertyEditor)pec.newInstance();
    } catch (Exception ex) {
      // Drop through.
    }
  }
  if (editor == null) {
    editor = PropertyEditorManager.findEditor(type);
  }
  m_Editors[i] = editor;

  // If we can't edit this component, skip it.
  if (editor == null) {
    // If it's a user-defined property we give a warning.
    String getterClass = m_Properties[i].getReadMethod()
      .getDeclaringClass().getName();
    /*
    if (getterClass.indexOf("java.") != 0) {
      System.err.println("Warning: Can't find public property editor"
             + " for property \"" + name + "\" (class \""
             + type.getName() + "\").  Skipping.");
    }
    */
    continue;
  }
  if (editor instanceof GenericObjectEditor) {
    ((GenericObjectEditor) editor).setClassType(type);
  }
 
  if (editor instanceof EnvironmentHandler) {
    ((EnvironmentHandler)editor).setEnvironment(m_env);
  }

  // Don't try to set null values:
  if (value == null) {
    // If it's a user-defined property we give a warning.
    String getterClass = m_Properties[i].getReadMethod()
      .getDeclaringClass().getName();
    /*
    if (getterClass.indexOf("java.") != 0) {
      System.err.println("Warning: Property \"" + name
             + "\" has null initial value.  Skipping.");
    }
    */
    continue;
  }

  editor.setValue(value);

  // now look for a TipText method for this property
        String tipName = name + "TipText";
  for (int j = 0; j < m_Methods.length; j++) {
    String mname = m_Methods[j].getDisplayName();
    Method meth = m_Methods[j].getMethod();
    if (mname.equals(tipName)) {
      if (meth.getReturnType().equals(String.class)) {
        try {
    String tempTip = (String)(meth.invoke(m_Target, args));
    int ci = tempTip.indexOf('.');
    if (ci < 0) {
      m_TipTexts[i] = tempTip;
    } else {
      m_TipTexts[i] = tempTip.substring(0, ci);
View Full Code Here

      for (int i = 0 ; i < m_Editors.length; i++) {
  if (m_Editors[i] == editor) {
    PropertyDescriptor property = m_Properties[i];
    Object value = editor.getValue();
    m_Values[i] = value;
    Method setter = property.getWriteMethod();
    try {
      Object args[] = { value };
      args[0] = value;
      setter.invoke(m_Target, args);
    } catch (InvocationTargetException ex) {
      if (ex.getTargetException()
    instanceof PropertyVetoException) {
              String message = "WARNING: Vetoed; reason is: "
                               + ex.getTargetException().getMessage();
        System.err.println(message);
             
              Component jf;
              if(evt.getSource() instanceof JPanel)
                  jf = ((JPanel)evt.getSource()).getParent();
              else
                  jf = new JFrame();
              JOptionPane.showMessageDialog(jf, message,
                                            "error",
                                            JOptionPane.WARNING_MESSAGE);
              if(jf instanceof JFrame)
                  ((JFrame)jf).dispose();

            } else {
        System.err.println(ex.getTargetException().getClass().getName()+
         " while updating "+ property.getName() +": "+
         ex.getTargetException().getMessage());
              Component jf;
              if(evt.getSource() instanceof JPanel)
                  jf = ((JPanel)evt.getSource()).getParent();
              else
                  jf = new JFrame();
              JOptionPane.showMessageDialog(jf,
                                            ex.getTargetException().getClass().getName()+
                                            " while updating "+ property.getName()+
                                            ":\n"+
                                            ex.getTargetException().getMessage(),
                                            "error",
                                            JOptionPane.WARNING_MESSAGE);
              if(jf instanceof JFrame)
                  ((JFrame)jf).dispose();

            }
    } catch (Exception ex) {
      System.err.println("Unexpected exception while updating "
      + property.getName());
    }
    if (m_Views[i] != null && m_Views[i] instanceof PropertyPanel) {
      //System.err.println("Trying to repaint the property canvas");
      m_Views[i].repaint();
      revalidate();
    }
    break;
  }
      }
    }

    // Now re-read all the properties and update the editors
    // for any other properties that have changed.
    for (int i = 0; i < m_Properties.length; i++) {
      Object o;
      try {
  Method getter = m_Properties[i].getReadMethod();
  Method setter = m_Properties[i].getWriteMethod();
 
  if (getter == null || setter == null) {
    // ignore set/get only properties
    continue;
  }
View Full Code Here

        System.out.println("Type: " + type + ", property " + propertyName);

        Object convert = new ConvertUtilsBean().convert(someValue, type);

        Method method = this.getClass().getMethod(methodName, new Class[]
        {
          type
        });
        method.invoke(this, new Object[]
        {
          convert
        });

      }
View Full Code Here

    Class ptypes[] = new Class[] { String.class, Boolean.TYPE };
    Object args[] = new Object[] { desc.getArguments(), new Boolean(!desc.isInitialized()) };
   
    Class service = null;
    service = Class.forName(desc.getClassName());
    Method init = service.getMethod("init", ptypes);

    init.invoke(null, args);
    desc.running = true;
    desc.initialized = true;
   
    if (xlogmon.isLoggable(BasicLevel.DEBUG)) {
      xlogmon.log(BasicLevel.DEBUG, getName() + " service started");
View Full Code Here

  public static void stop(ServiceDesc desc) throws Exception {
    // DF: idempotency (could be done in AgentAdmin)
    if (! desc.running) return;
//       throw new Exception("Service already stopped");
    Class service = Class.forName(desc.getClassName());
    Method stop = service.getMethod("stopService", new Class[0]);
    stop.invoke(null, (Object[]) null);
    desc.running = false;

    if (xlogmon.isLoggable(BasicLevel.DEBUG))
      xlogmon.log(BasicLevel.DEBUG, "Service " + desc.scname + " stopped.");
  }
View Full Code Here

   * @see org.hibernate.connection.ConnectionProvider#close()
   */
  public void close() throws HibernateException {
    if(dataSource != null)
    try {
      Method mClose = dataSource.getClass().getMethod("close", null);
      mClose.invoke(dataSource, null);
    } catch (Exception e) {
      throw new HibernateException(e);
    }
    dataSource = null;
  }
View Full Code Here

TOP

Related Classes of java.lang.reflect.Method

Copyright © 2015 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.