protected static void assertCircularInclude(final LaContainer container, final String path, LinkedList<String> paths) { paths.addFirst(container.getPath()); try { if (path.equals(container.getPath())) { throw new CircularIncludeRuntimeException(path, new ArrayList<String>(paths)); } for (int i = 0; i < container.getParentSize(); ++i) { assertCircularInclude(container.getParent(i), path, paths); } } finally { paths.removeFirst(); } }
public void registerDescendant(LaContainer descendant) { assertParameterIsNotNull(descendant, "descendant"); descendants.put(descendant.getPath(), descendant); }
/** * @return */ protected File getRootDir() { final String path = getContainer().getPath(); final String[] names = LdiStringUtil.split(path, "/"); File file = LdiResourceUtil.getResourceAsFile(path); for (int i = 0; i < names.length; ++i) { file = file.getParentFile(); } return file; }
void registerComponentDef(LaContainer container, Method method, LaContainerPreparer preparer) { ComponentDef componentDef = constructComponentDef(method, preparer); if (componentDef.getComponentName() != null) { componentDef = redefine(componentDef, container.getPath()); } container.register(componentDef); }
protected void throwDependencyXmlParseFailureException(LaContainer parent, String path, Throwable cause) { final LdiExceptionMessageBuilder br = new LdiExceptionMessageBuilder(); br.addNotice("Failed to parse the dependency XML."); br.addItem("Dependency XML"); br.addElement(path + (parent != null ? " included by " + parent.getPath() : "")); final String msg = br.buildExceptionMessage(); throw new DiXmlParseFailureException(msg, cause); }
protected void throwJavaScriptExpressionException(Object exp, Map<String, ? extends Object> contextMap, LaContainer container, Exception e) { final LdiExceptionMessageBuilder br = new LdiExceptionMessageBuilder(); br.addNotice("Failed to evaluate the JavaScript expression."); br.addItem("Di XML"); br.addElement(container.getPath()); br.addItem("Expression"); br.addElement(exp); br.addItem("Context Map"); br.addElement(contextMap); final String msg = br.buildExceptionMessage(); throw new IllegalStateException(msg, e); }
protected void throwDiXmlNotFoundException(LaContainer parent, String path) { final LdiExceptionMessageBuilder br = new LdiExceptionMessageBuilder(); br.addNotice("Not found the Di xml by the path."); br.addItem("Specified Path"); br.addElement(path); if (parent != null) { br.addItem("Included By"); br.addElement(parent.getPath()); } final String msg = br.buildExceptionMessage(); throw new DiXmlNotFoundException(msg); }
protected void throwComponentNotFoundException(LaContainer container, Object key) { final LdiExceptionMessageBuilder br = new LdiExceptionMessageBuilder(); br.addNotice("Not found the component by the key."); br.addItem("Component Key"); br.addElement(key); br.addItem("Definition Path"); br.addElement(container.getPath()); final String msg = br.buildExceptionMessage(); throw new ComponentNotFoundException(msg, key); }
protected void throwTooManyRegistrationComponentException() { final LdiExceptionMessageBuilder br = new LdiExceptionMessageBuilder(); br.addNotice("Too many registration components."); br.addItem("Component Key"); br.addElement(key); br.addItem("Registered Components"); for (ComponentDef def : getComponentDefs()) { final String componentName = def.getComponentName(); final String componentType = def.getComponentClass().getName(); Object componentInstance = null; try { componentInstance = def.getComponent(); } catch (RuntimeException ignored) { // nested too many...no way but just in case } final String definedDiXml = def.getContainer().getPath(); br.addElement("componentName: " + componentName); br.addElement(" componentType: " + componentType); if (componentInstance != null) { // just in case br.addElement(" componentInstance: " + componentInstance); br.addElement(" classLoader: " + componentInstance.getClass().getClassLoader()); } br.addElement(" definedDiXml: " + definedDiXml); } final String msg = br.buildExceptionMessage(); throw new TooManyRegistrationComponentException(msg, key, componentDefs); }
protected void throwPropertyValueGetFailureException(ComponentDef componentDef, PropertyDef propertyDef, Object component, RuntimeException cause) { final LdiExceptionMessageBuilder br = new LdiExceptionMessageBuilder(); br.addNotice("Failed to get the value for the property."); if (componentDef != null) { br.addItem("Component Def"); final String componentName = componentDef.getComponentName(); final String typeName = componentDef.getComponentClass().getName(); final String definedPath = componentDef.getContainer().getPath(); br.addElement("name=" + componentName + ", type=" + typeName + ", path=" + definedPath); } br.addItem("Property Owner"); br.addElement(component); br.addItem("Property Definition"); br.addElement(propertyDef); final String msg = br.buildExceptionMessage(); throw new IllegalPropertyDefinitionException(msg, cause); }
protected void throwPropertyComponentGetFailureException(ComponentDef componentDef, Object key, Object component, String propertyName, RuntimeException cause) { final LdiExceptionMessageBuilder br = new LdiExceptionMessageBuilder(); br.addNotice("Failed to get the component for the property by the key."); br.addItem("Component Key"); br.addElement(key); if (componentDef != null) { br.addItem("Component Def"); final String componentName = componentDef.getComponentName(); final String typeName = componentDef.getComponentClass().getName(); final String definedPath = componentDef.getContainer().getPath(); br.addElement("name=" + componentName + ", type=" + typeName + ", path=" + definedPath); } br.addItem("Property Owner"); br.addElement(component); br.addItem("Property Name"); br.addElement(propertyName); final String msg = br.buildExceptionMessage(); throw new IllegalPropertyDefinitionException(msg, cause); }
protected void throwExpressionClassCreateFailureException(String exp, Map<String, ? extends Object> contextMap, LaContainer container, String className, RuntimeException cause) { final LdiExceptionMessageBuilder br = new LdiExceptionMessageBuilder(); br.addNotice("Failed to create the class in the expression."); br.addItem("Di XML"); br.addElement(container.getPath()); br.addItem("Expression"); br.addElement(exp); br.addItem("Context Map"); br.addElement(contextMap); br.addItem("Class Name"); br.addElement(className); final String msg = br.buildExceptionMessage(); throw new ExpressionClassCreateFailureException(msg, cause); }
protected void throwExpressionCannotConvertException(String exp, Map<String, ? extends Object> contextMap, LaContainer container, Class<?> conversionType, Integer index, RuntimeException cause) { final LdiExceptionMessageBuilder br = new LdiExceptionMessageBuilder(); br.addNotice("Failed to convert the value to the type in the expression."); br.addItem("Di XML"); br.addElement(container.getPath()); br.addItem("Expression"); br.addElement(exp); br.addItem("Context Map"); br.addElement(contextMap); br.addItem("Conversion Type"); br.addElement(conversionType); if (index != null) { br.addItem("Array Index"); br.addElement(index); } final String msg = br.buildExceptionMessage(); throw new ExpressionClassCreateFailureException(msg, cause); } }
protected void throwContainerInitFailureException(Throwable cause) { if (cause instanceof ContainerInitFailureException) { // means nested exception throw (ContainerInitFailureException) cause; } final LdiExceptionMessageBuilder br = new LdiExceptionMessageBuilder(); br.addNotice("Failed to initialize the container."); br.addItem("Path"); br.addElement(getPath()); br.addItem("Namespace"); br.addElement(getNamespace()); int parentSize = getParentSize(); if (parentSize > 0) { br.addItem("Included by"); for (int i = 0; i < parentSize; i++) { final LaContainer parent = getParent(i); if (parent != null) { // just in case br.addElement(parent.getPath()); } } } final String msg = br.buildExceptionMessage(); throw new ContainerInitFailureException(msg, cause); }
public LaContainer include(LaContainer parent, String path) { final String realPath = pathResolver.resolvePath(parent.getPath(), path); assertCircularInclude(parent, realPath); enter(realPath); try { final LaContainer root = parent.getRoot(); final LaContainer child; synchronized (root) { if (root.hasDescendant(realPath)) { showReadingLog(parent, path, realPath, true); child = root.getDescendant(realPath); parent.include(child); } else { showReadingLog(parent, path, realPath, false); final String ext = getExtension(realPath); final LaContainerBuilder builder = getBuilder(ext); child = builder.include(parent, realPath); root.registerDescendant(child); if (child.isInitializeOnCreate()) { child.init(); } } } return child; } finally { leave(realPath); } }