configcontext.java

来自「RESIN 3.2 最新源码」· Java 代码 · 共 1,406 行 · 第 1/3 页

JAVA
1,406
字号
      }      if (attrStrategy.isProgram()) {	attrStrategy.setValue(bean, qName,			      buildProgram(attrStrategy, childNode));	return;      }      else if (attrStrategy.isNode()) {	attrStrategy.setValue(bean, qName, childNode);	return;      }      ConfigType childType = null;      Object childBean;      if (childNode instanceof Element) {	childBean = createResinType(attrStrategy.getConfigType(),				    (Element) childNode);	if (childBean != null) {	  ConfigType childBeanType = TypeFactory.getType(childBean.getClass());	  // server/02e3	  // childBeanType.init(childBean);	  childBean = childBeanType.replaceObject(childBean);	  	  attrStrategy.setValue(bean, qName, childBean);	  return;	}      }      String text;      if (attrStrategy.isAllowText()	  && (text = getTextValue(childNode)) != null) {	boolean isTrim = isTrim(childNode);	  	if (isEL() && attrStrategy.isEL()	    && (text.indexOf("#{") >= 0 || text.indexOf("${") >= 0)) {	  if (isTrim)	    text = text.trim();	  	  Object elValue = eval(attrStrategy.getConfigType(), text);	  // ioc/2410	  if (elValue != NULL)	    attrStrategy.setValue(bean, qName, elValue);	  else	    attrStrategy.setValue(bean, qName, null);	}	else {	  setText(bean, qName, text, attrStrategy, isTrim);	}	return;      }      else	childBean = attrStrategy.create(bean);      if (childBean != null) {	ConfigType childBeanType = TypeFactory.getType(childBean.getClass());		if (childNode instanceof Element)	  configureNode(childNode, childBean, childBeanType);	else	  configureChildNode(childNode, TEXT, childBean, childBeanType, false);	childBeanType.init(childBean);	Object newBean = attrStrategy.replaceObject(childBean);	if (newBean != childBean)	  childBean = newBean;	else	  childBean = childBeanType.replaceObject(childBean);	attrStrategy.setValue(bean, qName, childBean);      }      else if ((childBean = getElementValue(attrStrategy, childNode)) != null) {	if (childBean != NULL)	  attrStrategy.setValue(bean, qName, childBean);	else	  attrStrategy.setValue(bean, qName, null);      }      else {	ConfigType attrType = attrStrategy.getConfigType();		String textValue;	if (attrType.isNoTrim())	  textValue = textValueNoTrim(childNode);	else	  textValue = textValue(childNode);	if (isEL() && attrType.isEL() && textValue.indexOf("${") >= 0) {	  childType = attrStrategy.getConfigType();	  	  Object value = childType.valueOf(evalObject(textValue));	  	  attrStrategy.setValue(bean, qName, value);	}	else {	  // needed for boolean	  attrStrategy.setText(bean, qName, textValue);	}      }    } catch (LineConfigException e) {      throw e;    } catch (Exception e) {      throw error(e, childNode);    }  }    public Object create(Node childNode, ConfigType type)    throws ConfigException  {    if (childNode instanceof Element) {      Object childBean = createResinType(type, (Element) childNode);      if (childBean != null) {	ConfigType childBeanType = TypeFactory.getType(childBean.getClass());		childBeanType.init(childBean);	return childBeanType.replaceObject(childBean);      }    }    try {      Object childBean;      String text;      if ((text = getTextValue(childNode)) != null) {	boolean isTrim = isTrim(childNode);	  	if (isEL() && type.isEL()	    && (text.indexOf("#{") >= 0 || text.indexOf("${") >= 0)) {	  if (isTrim)	    text = text.trim();	  	  Object elValue = eval(type, text);	  // ioc/2410	  if (elValue != NULL)	    return elValue;	  else	    return null;	}	else {	  return text;	}      }      else	childBean = type.create(null);      if (childBean != null) {	ConfigType childBeanType = TypeFactory.getType(childBean.getClass());		if (childNode instanceof Element)	  configureNode(childNode, childBean, childBeanType);	else	  configureChildNode(childNode, TEXT, childBean, childBeanType, false);	childBeanType.init(childBean);	return childBeanType.replaceObject(childBean);      }      /*      else if ((childBean = getElementValue(attrStrategy, childNode)) != null) {	if (childBean != NULL)	  attrStrategy.setValue(bean, qName, childBean);	else	  attrStrategy.setValue(bean, qName, null);      }      */      else {	String textValue;	if (type.isNoTrim())	  textValue = textValueNoTrim(childNode);	else	  textValue = textValue(childNode);	if (isEL() && type.isEL() && textValue.indexOf("${") >= 0) {	  Object value = type.valueOf(evalObject(textValue));	  	  return value;	}	else	  return type.valueOf(textValue);      }    } catch (LineConfigException e) {      throw e;    } catch (Exception e) {      throw error(e, childNode);    }  }    private void setText(Object bean,		       QName qName,		       String text,		       Attribute attrStrategy,		       boolean isTrim)    throws Exception  {    ConfigType attrType = attrStrategy.getConfigType();	    if (isTrim && ! attrType.isNoTrim())      text = text.trim();    if (isEL() && attrType.isEL() && text.indexOf("${") >= 0) {      ConfigType childType = attrStrategy.getConfigType();	        Object value = childType.valueOf(evalObject(text));	        attrStrategy.setValue(bean, qName, value);    }    else      attrStrategy.setText(bean, qName, text);  }  private boolean isTrim(Node node)  {    if (node instanceof Attr)      return false;    else if (node instanceof Element) {      Element elt = (Element) node;      if (! "".equals(elt.getAttribute("xml:space")))	return false;    }    return true;  }  private ConfigProgram buildProgram(Attribute attr, Node node)  {    return new NodeBuilderChildProgram(node);  }    private void configureChildAttribute(Attr childNode,				       QName qName,				       Object bean,				       ConfigType type)    throws Exception  {    if (qName.getName().startsWith("xmlns")	|| _resinClassSet.contains(qName)) {      return;    }    Attribute attrStrategy;    try {      attrStrategy = type.getAttribute(qName);      if (attrStrategy == null) {	throw error(L.l("'{0}' is an unknown property of '{1}'.",			qName.getName(), type.getTypeName()),		    childNode);      }      if (attrStrategy.isProgram()) {	attrStrategy.setValue(bean, qName,			      buildProgram(attrStrategy, childNode));	return;      }      else if (attrStrategy.isNode()) {	attrStrategy.setValue(bean, qName, childNode);	return;      }      String textValue = childNode.getValue();      attrStrategy.setText(bean, qName, textValue);    } catch (LineConfigException e) {      throw e;    } catch (Exception e) {      throw error(e, childNode);    }  }  Object configureValue(Node node)  {    String value = textValue(node);    if (isEL() && value != null        && value.startsWith("${") && value.endsWith("}")) {      return evalObject(value);    }    else      return value;  }  public void setDependentScope(DependentScope scope)  {    _dependentScope = scope;  }  public DependentScope getDependentScope()  {    if (_dependentScope == null)      _dependentScope = new DependentScope();    return _dependentScope;  }  public ArrayList<Dependency> getDependencyList()  {    return _dependList;  }      ArrayList<Dependency> getDependencyList(Node node)  {    ArrayList<Dependency> dependList = null;    if (node instanceof QElement) {      QElement qelt = (QElement) node;      /* XXX: line #      builder.setLocation(bean, qelt.getBaseURI(),                          qelt.getFilename(), qelt.getLine());      builder.setNode(bean, qelt);      */      QDocument doc = (QDocument) qelt.getOwnerDocument();      if (doc == null)	return null;      else if (doc == _dependDocument)        return _dependList;      _dependDocument = doc;      ArrayList<Path> pathList;      pathList = doc.getDependList();      if (pathList != null) {        dependList = new ArrayList<Dependency>();        for (int i = 0; i < pathList.size(); i++) {          dependList.add(new Depend(pathList.get(i)));        }      }      _dependList = dependList;    }    return dependList;  }  /**   * Create a custom resin:type value.   */  Object createResinType(ConfigType childType, Element node)  {    String typeName = null;    if (node instanceof QAttributedNode) {      Node child = ((QAttributedNode) node).getFirstAttribute();      for (; child != null; child = child.getNextSibling()) {        Attr attr = (Attr) child;        QName qName = ((QNode) attr).getQName();	if (_resinClassSet.contains(qName)) {	  typeName = attr.getValue();	  break;	}      }    }    else {      NamedNodeMap attrList = node.getAttributes();      if (attrList != null) {        int length = attrList.getLength();        for (int i = 0; i < length; i++) {          Attr attr = (Attr) attrList.item(i);          QName qName = ((QNode) attr).getQName();	  if (_resinClassSet.contains(qName)) {	    typeName = attr.getValue();	    break;	  }        }      }    }    if (typeName != null) {      try {	ClassLoader loader = Thread.currentThread().getContextClassLoader();		Class cl = Class.forName(typeName, false, loader);	ConfigType beanConfigType = TypeFactory.getType(BeanConfig.class);	InterfaceConfig cfg = new InterfaceConfig(cl);	cfg.setClass(cl);	for (Node childNode = node.getFirstChild();	     childNode != null;	     childNode = childNode.getNextSibling()) {	  QName qName = ((QAbstractNode) childNode).getQName();        	  if (qName.equals(RESIN_PARAM)	      || qName.equals(RESIN_PARAM_NS)) {	    configureChildNode(childNode, qName, cfg, beanConfigType, true);	  }	}	cfg.init();	Object bean = cfg.replaceObjectNoInit();	configureBean(bean, node);	Config.init(bean);		return bean;      } catch (Exception e) {	throw ConfigException.create(e);      }    }        return null;  }  /**   * Configures a new object given the object's type.   *   * @param type the expected type of the object   * @param node the configuration node   * @return the configured object   * @throws Exception   */  Object configureCreate(Class type, Node node)    throws Exception  {    Object value = type.newInstance();    return configure(value, node);  }  /**   * Returns the variable resolver.   */  public ConfigELContext getELContext()  {    return _elContext;  }  void addValidator(Validator validator)  {    if (_validators == null)      _validators = new ArrayList<ValidatorEntry>();        _validators.add(new ValidatorEntry(validator));  }  static boolean hasChildren(Node node)  {    Node ptr;    if (node instanceof QAttributedNode) {      Node attr = ((QAttributedNode) node).getFirstAttribute();      for (; attr != null; attr = attr.getNextSibling()) {        if (! attr.getNodeName().startsWith("xml"))          return true;      }    }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?