Class def = getTargetClass(child);
if (def==null) {
return;
}
if (isServerResource(def)) {
Restlet finder = Finder.createFinder(def, Finder.class, hasParametersOrAttributes(child) ? createContext(parentContext,child) : parentContext,parentContext.getLogger());
if (defaultRoute) {
LOG.fine("Mapping default -> "+def.getName());
router.attachDefault(finder);
} else if (router!=null) {
LOG.fine("Mapping "+match+" -> "+def.getName());
router.attach(match,finder);
} else {
filter.setNext(finder);
}
} else {
try {
Restlet restlet = createRestlet(parentContext,def,child);
if (defaultRoute) {
LOG.fine("Mapping default -> "+def.getName());
router.attachDefault(restlet);
} else if (router!=null) {
LOG.fine("Mapping "+match+" -> "+def.getName());
router.attach(match,restlet);
} else {
filter.setNext(restlet);
}
} catch (Exception ex) {
LOG.log(Level.SEVERE,"Cannot instantiate class: "+def.getName(),ex);
}
}
} else if (name.equals(FILTER)) {
String match = child.getAttributeValue("match");
if (match==null && filter==null && !defaultRoute) {
LOG.severe("The filter element does not have the required match attribute.");
return;
}
Class def = getTargetClass(child);
if (def==null) {
return;
}
Filter childFilter = null;
try {
childFilter = createFilter(parentContext,def,child);
} catch (Exception ex) {
LOG.log(Level.SEVERE,"Cannot instantiate filter.",ex);
return;
}
if (defaultRoute) {
router.attachDefault(childFilter);
} else if (router!=null) {
router.attach(match,childFilter);
} else {
filter.setNext(childFilter);
}
Iterator<Element> elements = child.getElementChildren();
while (elements.hasNext()) {
Element nextChild = elements.next();
if (nextChild.getName().equals(NEXT)) {
Iterator<Element> nextChildren = nextChild.getElementChildren();
while (nextChildren.hasNext()) {
attachNext(childFilter,nextChildren.next());
}
}
}
} else if (name.equals(CONTENT)) {
String match = child.getAttributeValue("match");
if (match==null && filter==null && !defaultRoute) {
LOG.severe("The content element does not have the required match attribute.");
return;
}
Restlet restlet = createContent(parentContext,child);
if (defaultRoute) {
router.attachDefault(restlet);
} else if (router!=null) {
router.attach(match,restlet);
} else {
filter.setNext(restlet);
}
} else if (name.equals(REDIRECT)) {
String match = child.getAttributeValue("match");
if (match==null && filter==null && !defaultRoute) {
LOG.severe("The content element does not have the required match attribute.");
return;
}
String to = child.getAttributeValue("to");
if (to==null) {
LOG.severe("The redirect element is missing the required 'to' attribute.");
return;
}
Reference targetRef = new Reference(to);
Restlet restlet = null;
if (targetRef.isAbsolute() && targetRef.getScheme().equals("riap")) {
restlet = new Redirector(parentContext,to,Redirector.MODE_SERVER_INBOUND);
} else {
restlet = new Redirector(parentContext,to,Redirector.MODE_CLIENT_SEE_OTHER);
}