1 19 package org.sample.registry.model.impl; 20 21 import org.sample.registry.model.ReferenceableRegistryComponent; 22 import org.sample.registry.model.RegistryCommon; 23 import org.sample.registry.model.RegistryVisitor; 24 import org.sample.registry.model.Service; 25 26 30 31 public class FindByNameAndTypeVisitor<T extends ReferenceableRegistryComponent> 32 extends RegistryVisitor.Deep { 33 34 private String name; 35 private Class <T> type; 36 private T found; 37 38 public FindByNameAndTypeVisitor() { 39 } 40 41 public T find(RegistryCommon registry, String name, Class <T> type) { 42 if (name == null || type == null) { 43 return null; 44 } 45 46 this.name = name; 47 this.type = type; 48 registry.accept(this); 49 return found; 50 } 51 52 public void visit(Service component) { 53 if (name.equals(component.getName())) { 54 found = type.cast(component); 55 return; 56 } 57 } 58 } 59 60 | Popular Tags |