/hazelcast-spring/src/main/java/com/hazelcast/spring/AbstractHazelcastBeanDefinitionParser.java

https://bitbucket.org/gabral6_gmailcom/hazelcast · Java · 62 lines · 37 code · 7 blank · 18 comment · 12 complexity · deb3cfe30488e6a375cbecd952cadfe8 MD5 · raw file

  1. /*
  2. * Copyright (c) 2008-2013, Hazelcast, Inc. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.hazelcast.spring;
  17. import com.hazelcast.config.AbstractXmlConfigHelper;
  18. import org.springframework.beans.factory.support.BeanDefinitionBuilder;
  19. import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser;
  20. import org.springframework.beans.factory.xml.ParserContext;
  21. import org.w3c.dom.NamedNodeMap;
  22. import org.w3c.dom.Node;
  23. /**
  24. * @mdogan 4/10/12
  25. */
  26. public abstract class AbstractHazelcastBeanDefinitionParser extends AbstractBeanDefinitionParser {
  27. public abstract class SpringXmlBuilderHelper extends AbstractXmlConfigHelper {
  28. protected void handleCommonBeanAttributes(Node node, BeanDefinitionBuilder builder, ParserContext parserContext) {
  29. final NamedNodeMap attributes = node.getAttributes();
  30. if (attributes != null) {
  31. Node lazyInitAttr = attributes.getNamedItem("lazy-init");
  32. if (lazyInitAttr != null) {
  33. builder.setLazyInit(Boolean.valueOf(getValue(lazyInitAttr)));
  34. } else {
  35. builder.setLazyInit(parserContext.isDefaultLazyInit());
  36. }
  37. if (parserContext.isNested()) {
  38. builder.setScope(parserContext.getContainingBeanDefinition().getScope());
  39. } else {
  40. Node scopeNode = attributes.getNamedItem("scope");
  41. if (scopeNode != null) {
  42. builder.setScope(getValue(scopeNode));
  43. }
  44. }
  45. Node dependsOnNode = attributes.getNamedItem("depends-on");
  46. if (dependsOnNode != null) {
  47. String[] dependsOn = getValue(dependsOnNode).split("[,;]");
  48. for (String dep : dependsOn) {
  49. builder.addDependsOn(dep.trim());
  50. }
  51. }
  52. }
  53. }
  54. }
  55. }