Refine search
var c = new Customer(); c instanceof Customer; //Returns true as c is just a customer c instanceof String; //Returns false as c is not a string, it's a customer silly!
void initialize() {} void initData(Customer customer) { customerName.setText(customer.getName());
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_top); Customer cust=new Customer(); cust.setName("abc"); cust.setCity("xyz"); Intent intent=new Intent(abc.this,xyz.class); intent.putExtra("bundle",cust); startActivity(intent); }
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); } }
JAXBContext jaxbContext = JAXBContext.newInstance(Customer.class); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); Customer customer = (Customer) jaxbUnmarshaller.unmarshal(file); System.out.println("Name :" + customer.getName()); System.out.println("Age :" + customer.getAge()); System.out.println("Id :" + customer.getId());
import java.util.*; import javax.xml.bind.*; import org.eclipse.persistence.jaxb.JAXBContextProperties; public class Demo { public static void main(String[] args) throws Exception { Map<String, Object> properties = new HashMap<String, Object>(1); properties.put(JAXBContextProperties.OXM_METADATA_SOURCE, "forum19641824/oxm.xml"); JAXBContext jc = JAXBContext.newInstance(new Class[] {Customer.class}, properties); Customer customer = new Customer(); customer.setFirstname("Tony"); customer.setLastname("Stark"); Marshaller marshaller = jc.createMarshaller(); marshaller.setAdapter(new LastNameAdapter("01.01.1990")); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(customer, System.out); } }
JAXBContext jc = JAXBContext.newInstance(Customer.class); Customer customer = new Customer(); customer.setName("Jane Doe"); Marshaller marshaller = jc.createMarshaller(); DocumentResult dr = new DocumentResult(); marshaller.marshal(customer, dr);
public static void main(String[] args) { try { StringWriter stringWriter = new StringWriter(); Customer c = new Customer(); c.setAge(1); c.setName("name"); JAXBContext jaxbContext = JAXBContext.newInstance(Customer.class); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.marshal(new JAXBElement<Customer>( new QName("", "Customer"), Customer.class, null, c), stringWriter); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); InputStream is = new ByteArrayInputStream(stringWriter.toString().getBytes()); JAXBElement<Customer> customer = (JAXBElement<Customer>) jaxbUnmarshaller.unmarshal(new StreamSource(is),Customer.class); c = customer.getValue(); } catch (JAXBException e) { e.printStackTrace(); } }
Document document = db.parse(xml); JAXBContext jc = JAXBContext.newInstance(Customer.class); Binder<Node> binder = jc.createBinder(); Customer customer = (Customer) binder.unmarshal(document); customer.getAddress().setStreet("2 NEW STREET"); PhoneNumber workPhone = new PhoneNumber(); workPhone.setType("work"); workPhone.setValue("555-WORK"); customer.getPhoneNumbers().add(workPhone); binder.updateXML(customer);
import java.io.File; import javax.xml.XMLConstants; import javax.xml.bind.JAXBContext; import javax.xml.bind.util.JAXBSource; import javax.xml.validation.*; public class Demo { public static void main(String[] args) throws Exception { Customer customer = new Customer(); customer.setName("Jane Doe"); customer.getPhoneNumbers().add(new PhoneNumber()); customer.getPhoneNumbers().add(new PhoneNumber()); customer.getPhoneNumbers().add(new PhoneNumber()); JAXBContext jc = JAXBContext.newInstance(Customer.class); JAXBSource source = new JAXBSource(jc, customer); SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schema = sf.newSchema(new File("customer.xsd")); Validator validator = schema.newValidator(); validator.setErrorHandler(new MyErrorHandler()); validator.validate(source); } }
import java.io.File; import javax.xml.XMLConstants; import javax.xml.bind.JAXBContext; import javax.xml.bind.util.JAXBSource; import javax.xml.validation.Schema; import javax.xml.validation.SchemaFactory; public class Demo { public static void main(String[] args) throws Exception { SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schema = sf.newSchema(new File("customer.xsd")); JAXBContext jc = JAXBContext.newInstance(Customer.class); Customer customer = new Customer(); // populate the customer object JAXBSource source = new JAXBSource(jc, customer); schema.newValidator().validate(source); } }
JAXBContext jc = JAXBContext.newInstance(Customer.class); Unmarshaller unmarshaller = jc.createUnmarshaller(); Customer customer = (Customer) unmarshaller.unmarshal(reader); System.out.println(customer.getName()); for (Element el : customer.getExtras()) { System.out.println(el.getNodeName() + "->" + el.getTextContent());
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() + "]"); } }
Customer customer = new Customer(); //set customer attributes JAXBContext jc = JAXBContext.newInstance(Customer.class); Marshaller marshaller = jc.createMarshaller(); StringWriter stringWriter = new StringWriter(); marshaller.marshal(customer, stringWriter ); log.info(stringWriter.toString());
Customer c1 = new Customer("Robin"); Order o1 = new Order("Phone"); c1.addOrder(o1); JAXBContext jc = JAXBContext.newInstance(Customer.class); Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(c1, System.out);
private Customer cursorToCustomer(Cursor cursor) { Customer customer = new Customer(); customer.setCustomer(cursor.getString(0)); customer.setName(cursor.getString(1)); customer.setAddress1(cursor.getString(2)); customer.setAddress2(cursor.getString(3)); customer.setCity(cursor.getString(4)); customer.setState(cursor.getString(5)); customer.setZipCode(cursor.getString(6)); customer.setSearchValue(cursor.getString(7)); customer.setCarb(cursor.getString(8)); customer.setFiber(cursor.getString(9)); customer.setSugar(cursor.getString(10)); customer.setProtein(cursor.getString(11)); customer.setSodium(cursor.getString(12)); customer.setCalories(cursor.getString(13)); return comment; }
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);
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; }