Created
August 13, 2016 21:18
-
-
Save fjunior87/02df3325d80037c957791c39f2a7110f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Component | |
| @Service | |
| public class ContactAdapterFactory implements AdapterFactory{ | |
| @Property(name="adapters") | |
| public static final String[] ADAPTER_CLASSES = { | |
| Contact.class.getName() | |
| }; | |
| @Property(name="adaptables") | |
| public static final String[] ADAPTABLE_CLASSES = { | |
| Resource.class.getName() | |
| }; | |
| @Override | |
| @SuppressWarnings("unchecked") | |
| public <AdapterType> AdapterType getAdapter(Object adaptable, Class<AdapterType> type) { | |
| if(adaptable instanceof Resource && | |
| type.equals(Contact.class)) { | |
| Contact contact = new Contact(); | |
| Resource resource = (Resource)adaptable; | |
| ValueMap valueMap = ResourceUtil.getValueMap((Resource)adaptable); | |
| contact.setName(valueMap.get("name", String.class)); | |
| contact.setEmail(valueMap.get("email", String.class)); | |
| contact.setPhone(valueMap.get("phone", String.class)); | |
| contact.setAddress(valueMap.get("address", String.class)); | |
| Resource contactImage = resource.getChild("contactImage"); | |
| if(contactImage != null) { | |
| contact.setContactImage(contactImage.getPath()); | |
| } | |
| System.out.println(contact); | |
| return (AdapterType)contact; | |
| } else { | |
| return null; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment