Was a Nubie, now I'm just dangerous...

I found I could use a class for more objects if I could pass methods to be 
called as parameters to my constructor.  A lot of postings, how-to atricles and 
a Sun Tutorial led me to Reflection, aka Class Method.  Sample code, which I 
incorporated, is at 
<http://java.sun.com/docs/books/tutorial/reflect/object/invoke.html>

This example worked (embedded into a class of mine) before I added my cloning 
of statements (each is marked below).  I get a "NoSuchMethodException" catch 
from the statement marked "//me -X".  "getHOUSENAME" is an XMLBeans generated  
method and I've used it earlier in the same class.

Here's the cod segment (full files attached):

public static String append(String firstWord, String secondWord)   //Sun
 {                                                                  //Sun
    String result = null;                                           //Sun
    String result2 = null;                                          //me
    Class c = String.class;                                         //Sun
    Class c2 = house.getClass();                                    //me
    Class[] parameterTypes = new Class[] {String.class};            //Sun
    Method concatMethod;                                            //Sun
    Method houseGetMethod;                                          //me
    Method houseSetMethod;                                          //me
    Object[] arguments = new Object[] {secondWord};                 //Sun
    System.out.println(nameTextCO.getText());                       //me
    String shortName = nameTextCO.getText();                        //me
    Object[] arguments2 = new Object[] {shortName};                 //me
    try {                                                           //Sun
      concatMethod = c.getMethod("concat", parameterTypes);         //Sun
      houseGetMethod = c2.getMethod("getHOUSENAME", null);          //me -X
      result = (String) concatMethod.invoke(firstWord, arguments);  //Sun
      result2 = (String) houseGetMethod.invoke(house[0], null);     //me
      System.out.println(result2);                                  //me
    } catch (NoSuchMethodException e) {                             //Sun
        System.out.println(e);                                      //Sun
    } catch (IllegalAccessException e) {                            //Sun
        System.out.println(e);                                      //Sun
    } catch (InvocationTargetException e) {                         //Sun
        System.out.println(e);                                      //Sun
    }                                                               //Sun
    return result;                                                  //Sun
 }

Any suggestions?

Appreciations,
Gene  

Attachment: InfoColumn.java
Description: Binary data

<?xml version="1.0" encoding="UTF-8"?>
<!--Sanity Check-->
<xs:schema targetNamespace="http://HOUSES"; elementFormDefault="qualified" xmlns:hse="http://HOUSES"; xmlns:xs="http://www.w3.org/2001/XMLSchema";>
	<xs:element name="HOUSES">
		<xs:complexType>
		      <xs:sequence>
        			<xs:element name="HOUSE" type="hse:houseElement" minOccurs="8" maxOccurs="8"/>
			</xs:sequence>
		</xs:complexType>
	</xs:element>
	<xs:complexType name="houseElement">
		<xs:sequence>
			<xs:element name="HOUSE_NAME" type="xs:string"/>
			<xs:element name="SHORT_NAME" type="xs:string"/>
			<xs:element name="RENT" type="xs:integer"/>
			<xs:element name="SEC_DEP" type="xs:integer"/>
			<xs:element name="NEW_DEP" type="xs:integer"/>
			<xs:element name="SAV_BAL" type="xs:integer"/>
			<xs:element name="CHK_BAL" type="xs:integer"/>
		</xs:sequence>
	</xs:complexType>
</xs:schema>

<?xml version="1.0" encoding="UTF-8"?>
<!--edited with XML Spy v4.3 U (http://www.xmlspy.com) by Gene Holmerud-->
<!--HOUSES RecordSet for Java RENTALS Application, ver 0.4-->
<!--Note: Units of SAV_BAL and CHK_BAL are pennies and type xs:integer.-->
<!--All other money quanties are whole dollars and type xs:integer.-->
<HOUSES xmlns="http://HOUSES";>
  <HOUSE>
    <HOUSE_NAME>Common</HOUSE_NAME>
    <SHORT_NAME>CO</SHORT_NAME>
    <RENT>0</RENT>
    <SEC_DEP>0</SEC_DEP>
    <NEW_DEP>0</NEW_DEP>
    <SAV_BAL>2560</SAV_BAL>
    <CHK_BAL>742</CHK_BAL>
  </HOUSE>
  <HOUSE>
    <HOUSE_NAME>Lynwood</HOUSE_NAME>
    <SHORT_NAME>L</SHORT_NAME>
    <RENT>850</RENT>
    <SEC_DEP>1200</SEC_DEP>
    <NEW_DEP>0</NEW_DEP>
    <SAV_BAL>0</SAV_BAL>
    <CHK_BAL>250</CHK_BAL>
  </HOUSE>
  <HOUSE>
    <HOUSE_NAME>Windrose</HOUSE_NAME>
    <SHORT_NAME>W</SHORT_NAME>
    <RENT>850</RENT>
    <SEC_DEP>1200</SEC_DEP>
    <NEW_DEP>0</NEW_DEP>
    <SAV_BAL>20000</SAV_BAL>
    <CHK_BAL>12500</CHK_BAL>
  </HOUSE>
  <HOUSE>
    <HOUSE_NAME>Vogel</HOUSE_NAME>
    <SHORT_NAME>V</SHORT_NAME>
    <RENT>850</RENT>
    <SEC_DEP>1000</SEC_DEP>
    <NEW_DEP>0</NEW_DEP>
    <SAV_BAL>10000</SAV_BAL>
    <CHK_BAL>15000</CHK_BAL>
  </HOUSE>
  <HOUSE>
    <HOUSE_NAME>Future4</HOUSE_NAME>
    <SHORT_NAME>F4</SHORT_NAME>
    <RENT>0</RENT>
    <SEC_DEP>0</SEC_DEP>
    <NEW_DEP>0</NEW_DEP>
    <SAV_BAL>0</SAV_BAL>
    <CHK_BAL>0</CHK_BAL>
  </HOUSE>
  <HOUSE>
    <HOUSE_NAME>Future5</HOUSE_NAME>
    <SHORT_NAME>F5</SHORT_NAME>
    <RENT>0</RENT>
    <SEC_DEP>0</SEC_DEP>
    <NEW_DEP>0</NEW_DEP>
    <SAV_BAL>0</SAV_BAL>
    <CHK_BAL>0</CHK_BAL>
  </HOUSE>
  <HOUSE>
    <HOUSE_NAME>Future6</HOUSE_NAME>
    <SHORT_NAME>F6</SHORT_NAME>
    <RENT>0</RENT>
    <SEC_DEP>0</SEC_DEP>
    <NEW_DEP>0</NEW_DEP>
    <SAV_BAL>0</SAV_BAL>
    <CHK_BAL>0</CHK_BAL>
  </HOUSE>
  <HOUSE>
    <HOUSE_NAME>LT Save</HOUSE_NAME>
    <SHORT_NAME>LS</SHORT_NAME>
    <RENT>0</RENT>
    <SEC_DEP>0</SEC_DEP>
    <NEW_DEP>0</NEW_DEP>
    <SAV_BAL>0</SAV_BAL>
    <CHK_BAL>0</CHK_BAL>
  </HOUSE>
</HOUSES>

Attachment: HouseElement.java
Description: Binary data

Attachment: HouseElementImpl.java
Description: Binary data

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to