import java.io.File; import javax.xml.bind.JAXBContext; import javax.xml.bind.Marshaller; import javax.xml.bind.Unmarshaller; public class Demo { public static void main(String[] args) throws Exception { JAXBContext jc = JAXBContext.newInstance(CustomerImpl.class); Unmarshaller unmarshaller = jc.createUnmarshaller(); File xml = new File("input.xml"); Customer customer = (Customer) unmarshaller.unmarshal(xml); Address address = customer.getAddress(); System.out.println(address.getStreet()); Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(customer, System.out); } }
Customer custObj = getCustomer(); Address temp = custObj.getAddress(); System.out.println("Address");
private void printCustomer( final Customer c ) { try { System.out.println( "Customer " + c.getSurname() + " " + c.getName() + "living in " + c.getAddress().getCity() + ", " + c.getAddress().getStreet() ); } catch ( NullPointerException ex ) { System.err.println( "Unable to print out customer information.", ex ); }
JAXBContext jc = JAXBContext.newInstance(Customer.class); Binder<Node> binder = jc.createBinder(); Customer customer = (Customer) binder.unmarshal(document); customer.getAddress().setStreet("2 NEW STREET"); binder.updateXML(customer);
for(Customer input : customers) { Display.append(input.getName()); Display.append("\t"); Display.append(input.getAddress()); Display.append("\n"); }
public void insertCustomerListToB(ArrayList<Customer> customerList) { for (Customer customer : customerList) { ContentValues cv = new ContentValues(); cv.put(DB_TABLE.CUSTOMER_CODE, customer.getCode()); cv.put(DB_TABLE.CUSTOMER_NAME, customer.getName()); cv.put(DB_TABLE.CUSTOMER_ADDRESS, customer.getAddress()); dbB.insert(DB_TABLE.CUSTOMER, null, cv); } }
public static void readBoo() { Object element = null; try { JAXBContext jc = JAXBContext.newInstance(XmlBoo.class); Unmarshaller u = jc.createUnmarshaller(); element = u.unmarshal(new File("xml_boo.xml")); } catch (JAXBException e) { e.printStackTrace(); } if (element instanceof XmlBoo) { XmlBoo xmlBoo = (XmlBoo) element; Customer customer = xmlBoo.getCustomer(); System.out.println("INFO | xmlBoo field: [" + xmlBoo.getSomeBooSpecificField() + "]"); System.out.println("INFO | customer name: [" + customer.getName() + "]"); System.out.println("INFO | address street: [" + customer.getAddress().getStreet() + "]"); } }
private void reloadButtonActionPerformed(java.awt.event.ActionEvent evt) { try { ArrayList<Customer> customerList = null; try { try { customerList = CustomerController.getAllCustomer(); } catch (SQLException ex) { Logger.getLogger(veiwCustomerFrame.class.getName()).log(Level.SEVERE, null, ex); } } catch (Exception ex) { Logger.getLogger(ViewCustomerForm.class.getName()).log(Level.SEVERE, null, ex); } DefaultTableModel tableModel = (DefaultTableModel) customerTable.getModel(); tableModel.setRowCount(0); for (Customer customer : customerList) { Object rowData[] = {customer.getId(), customer.getName(), customer.getAddress(), customer.getSalary()}; tableModel.addRow(rowData); } } catch (Exception ex) { Logger.getLogger(ViewCustomerForm.class.getName()).log(Level.SEVERE, null, ex); } }
customer.getAddress().setStreet("2 NEW STREET"); PhoneNumber workPhone = new PhoneNumber(); workPhone.setType("work");
customer.getAddress().setStreet("2 NEW STREET"); PhoneNumber workPhone = new PhoneNumber(); workPhone.setType("work");
if (otherCustomer.getAddress() != null) { return false; } else if (this.address.equals(otherCustomer.getAddress())) { return true; } else {
public List<Customer> getCustomersByName(String name) throws NoSuchCustomerException { if ("None".equals(name)) { NoSuchCustomer noSuchCustomer = new NoSuchCustomer(); noSuchCustomer.setCustomerName(name); throw new NoSuchCustomerException("Did not find any matching customer for name=" + name, noSuchCustomer); } List<Customer> customers = new ArrayList<Customer>(); for (int c = 0; c < 2; c++) { Customer cust = new Customer(); cust.setName(name); cust.getAddress().add("Pine Street 200"); Date bDate = new GregorianCalendar(2009, 01, 01).getTime(); cust.setBirthDate(bDate); cust.setNumOrders(1); cust.setRevenue(1000); cust.setTest(new BigDecimal(1.5)); cust.setType(CustomerType.BUSINESS); customers.add(cust); } return customers; }