List of usage examples for org.dom4j Attribute getValue
String getValue();
From source file:org.codehaus.aspectwerkz.definition.DocumentParser.java
License:Open Source License
/** * Parses the <tt>aspect</tt> elements. * * @param loader the current class loader * @param systemElement the system element * @param definition the definition object * @param packageName the package name * @param globalPointcuts the global pointcuts *//*from w ww.ja v a 2 s . co m*/ private static void parseAspectElements(final ClassLoader loader, final Element systemElement, final SystemDefinition definition, final String packageName, final List globalPointcuts) { for (Iterator it1 = systemElement.elementIterator("aspect"); it1.hasNext();) { String aspectName = null; String className = null; String deploymentModel = null; String containerClassName = null; Element aspect = (Element) it1.next(); for (Iterator it2 = aspect.attributeIterator(); it2.hasNext();) { Attribute attribute = (Attribute) it2.next(); final String name = attribute.getName().trim(); final String value = attribute.getValue().trim(); if (name.equalsIgnoreCase("class")) { className = value; } else if (name.equalsIgnoreCase("deployment-model")) { deploymentModel = value; } else if (name.equalsIgnoreCase("name")) { aspectName = value; } else if (name.equalsIgnoreCase("container")) { containerClassName = value; } } // class is mandatory if (Strings.isNullOrEmpty(className)) { System.err.println("Warning: could not load aspect without 'class=..' attribute"); new Exception().printStackTrace(); continue; } String aspectClassName = packageName + className; if (aspectName == null) { aspectName = aspectClassName; } // create the aspect definition ClassInfo aspectClassInfo; try { aspectClassInfo = AsmClassInfo.getClassInfo(aspectClassName, loader); } catch (Exception e) { System.err.println("Warning: could not load aspect " + aspectClassName + " from " + loader + "due to: " + e.toString()); e.printStackTrace(); continue; } final AspectDefinition aspectDef = new AspectDefinition(aspectName, aspectClassInfo, definition); // add the global pointcuts to the aspect for (Iterator it = globalPointcuts.iterator(); it.hasNext();) { PointcutInfo pointcutInfo = (PointcutInfo) it.next(); DefinitionParserHelper.createAndAddPointcutDefToAspectDef(pointcutInfo.name, pointcutInfo.expression, aspectDef); } parsePointcutElements(aspect, aspectDef); //needed to support undefined named pointcut in Attributes AW-152 // load the different aspect model and let them define their aspects AspectModelManager.defineAspect(aspectClassInfo, aspectDef, loader); // parse the class bytecode annotations AspectAnnotationParser.parse(aspectClassInfo, aspectDef, loader); // XML definition settings always overrides attribute definition settings // AW-357 if (!Strings.isNullOrEmpty(deploymentModel)) { aspectDef.setDeploymentModel(DeploymentModel.getDeploymentModelFor(deploymentModel)); } if (!Strings.isNullOrEmpty(aspectName)) { aspectDef.setName(aspectName); } if (!Strings.isNullOrEmpty(containerClassName)) { aspectDef.setContainerClassName(containerClassName); } // parse the aspect info parseParameterElements(aspect, aspectDef); parsePointcutElements(aspect, aspectDef); //reparse pc for XML override (AW-152) parseAdviceElements(aspect, aspectDef, aspectClassInfo); parseIntroduceElements(aspect, aspectDef, packageName, loader); definition.addAspect(aspectDef); } }
From source file:org.codehaus.aspectwerkz.definition.DocumentParser.java
License:Open Source License
/** * Parses the <tt>mixin</tt> elements. * * @param loader the current class loader * @param systemElement the system element * @param systemDefinition the system definition * @param packageName the package name *//*from w w w .j a va2 s. c om*/ private static void parseMixinElements(final ClassLoader loader, final Element systemElement, final SystemDefinition systemDefinition, final String packageName) { for (Iterator it1 = systemElement.elementIterator("mixin"); it1.hasNext();) { String className = null; String deploymentModelAsString = null; boolean isTransient = false; boolean isTransientSetInXML = false; String factoryClassName = null; String expression = null; Element mixin = (Element) it1.next(); for (Iterator it2 = mixin.attributeIterator(); it2.hasNext();) { Attribute attribute = (Attribute) it2.next(); final String name = attribute.getName().trim(); final String value = attribute.getValue().trim(); if (name.equalsIgnoreCase("class")) { className = value; } else if (name.equalsIgnoreCase("deployment-model") && value != null) { deploymentModelAsString = value; } else if (name.equalsIgnoreCase("transient")) { if (value != null && value.equalsIgnoreCase("true")) { isTransient = true; isTransientSetInXML = true; } } else if (name.equalsIgnoreCase("factory")) { factoryClassName = value; } else if (name.equalsIgnoreCase("bind-to")) { expression = value; } } String mixinClassName = packageName + className; // create the mixin definition ClassInfo mixinClassInfo; try { mixinClassInfo = AsmClassInfo.getClassInfo(mixinClassName, loader); } catch (Exception e) { System.err.println("Warning: could not load mixin " + mixinClassName + " from " + loader + "due to: " + e.toString()); e.printStackTrace(); continue; } final DeploymentModel deploymentModel = (deploymentModelAsString != null) ? DeploymentModel.getDeploymentModelFor(deploymentModelAsString) : DeploymentModel.PER_INSTANCE; final MixinDefinition mixinDefinition = DefinitionParserHelper.createAndAddMixinDefToSystemDef( mixinClassInfo, expression, deploymentModel, isTransient, systemDefinition); // parse the class bytecode annotations MixinAnnotationParser.parse(mixinClassInfo, mixinDefinition); // XML definition settings always overrides attribute definition settings if present if (!Strings.isNullOrEmpty(deploymentModelAsString)) { mixinDefinition.setDeploymentModel(DeploymentModel.getDeploymentModelFor(deploymentModelAsString)); } if (!Strings.isNullOrEmpty(factoryClassName)) { mixinDefinition.setFactoryClassName(factoryClassName); } if (isTransientSetInXML) { mixinDefinition.setTransient(isTransient); } parseParameterElements(mixin, mixinDefinition); } }
From source file:org.codehaus.aspectwerkz.definition.DocumentParser.java
License:Open Source License
/** * Retrieves and returns the package.//from w w w . j a v a 2 s. co m * * @param packageElement the package element * @return the package as a string ending with DOT, or empty string */ private static String getPackage(final Element packageElement) { String packageName = ""; for (Iterator it2 = packageElement.attributeIterator(); it2.hasNext();) { Attribute attribute = (Attribute) it2.next(); if (attribute.getName().trim().equalsIgnoreCase("name")) { packageName = attribute.getValue().trim(); if (packageName.endsWith(".*")) { packageName = packageName.substring(0, packageName.length() - 1); } else if (packageName.endsWith(".")) { ; // skip } else { packageName += "."; } break; } else { continue; } } return packageName; }
From source file:org.codehaus.aspectwerkz.definition.DocumentParser.java
License:Open Source License
/** * Parses the <tt>include</tt> elements. * * @param root the root element/* ww w . j a v a 2 s . c om*/ * @param definition the definition object * @param packageName the package name */ private static void parseIncludePackageElements(final Element root, final SystemDefinition definition, final String packageName) { for (Iterator it1 = root.elementIterator("include"); it1.hasNext();) { String includePackage = ""; Element includeElement = (Element) it1.next(); for (Iterator it2 = includeElement.attributeIterator(); it2.hasNext();) { Attribute attribute = (Attribute) it2.next(); if (attribute.getName().trim().equalsIgnoreCase("package")) { // handle base package if (packageName.endsWith(".*")) { includePackage = packageName.substring(0, packageName.length() - 2); } else if (packageName.endsWith(".")) { includePackage = packageName.substring(0, packageName.length() - 1); } // handle exclude package includePackage = packageName + attribute.getValue().trim(); if (includePackage.endsWith(".*")) { includePackage = includePackage.substring(0, includePackage.length() - 2); } else if (includePackage.endsWith(".")) { includePackage = includePackage.substring(0, includePackage.length() - 1); } break; } else { continue; } } if (includePackage.length() != 0) { definition.addIncludePackage(includePackage); } } }
From source file:org.codehaus.aspectwerkz.definition.DocumentParser.java
License:Open Source License
/** * Parses the <tt>exclude</tt> elements. * * @param root the root element// ww w .jav a 2 s .com * @param definition the definition object * @param packageName the package name */ private static void parseExcludePackageElements(final Element root, final SystemDefinition definition, final String packageName) { for (Iterator it1 = root.elementIterator("exclude"); it1.hasNext();) { String excludePackage = ""; Element excludeElement = (Element) it1.next(); for (Iterator it2 = excludeElement.attributeIterator(); it2.hasNext();) { Attribute attribute = (Attribute) it2.next(); if (attribute.getName().trim().equalsIgnoreCase("package")) { // handle base package if (packageName.endsWith(".*")) { excludePackage = packageName.substring(0, packageName.length() - 2); } else if (packageName.endsWith(".")) { excludePackage = packageName.substring(0, packageName.length() - 1); } // handle exclude package excludePackage = packageName + attribute.getValue().trim(); if (excludePackage.endsWith(".*")) { excludePackage = excludePackage.substring(0, excludePackage.length() - 2); } else if (excludePackage.endsWith(".")) { excludePackage = excludePackage.substring(0, excludePackage.length() - 1); } break; } else { continue; } } if (excludePackage.length() != 0) { definition.addExcludePackage(excludePackage); } } }
From source file:org.codehaus.aspectwerkz.definition.DocumentParser.java
License:Open Source License
/** * Parses the <tt>prepare</tt> elements. * * @param root the root element/*from w ww . ja v a 2 s. co m*/ * @param definition the definition object * @param packageName the base package name */ public static void parsePrepareElements(final Element root, final SystemDefinition definition, final String packageName) { for (Iterator it1 = root.elementIterator("prepare"); it1.hasNext();) { String preparePackage = ""; Element prepareElement = (Element) it1.next(); for (Iterator it2 = prepareElement.attributeIterator(); it2.hasNext();) { Attribute attribute = (Attribute) it2.next(); if (attribute.getName().trim().equals("package")) { // handle base package if (packageName.endsWith(".*")) { preparePackage = packageName.substring(0, packageName.length() - 2); } else if (packageName.endsWith(".")) { preparePackage = packageName.substring(0, packageName.length() - 1); } // handle prepare package preparePackage = packageName + attribute.getValue().trim(); if (preparePackage.endsWith(".*")) { preparePackage = preparePackage.substring(0, preparePackage.length() - 2); } else if (preparePackage.endsWith(".")) { preparePackage = preparePackage.substring(0, preparePackage.length() - 1); } break; } else { continue; } } if (preparePackage.length() != 0) { definition.addPreparePackage(preparePackage); } } }
From source file:org.codehaus.aspectwerkz.definition.DocumentParser.java
License:Open Source License
/** * Retrieves and returns the base package for a system element * * @param system a system element/*from ww w . j a v a 2 s.co m*/ * @return the base package */ private static String getBasePackage(final Element system) { String basePackage = ""; for (Iterator it2 = system.attributeIterator(); it2.hasNext();) { Attribute attribute = (Attribute) it2.next(); if (attribute.getName().trim().equalsIgnoreCase("base-package")) { basePackage = attribute.getValue().trim(); if (basePackage.endsWith(".*")) { basePackage = basePackage.substring(0, basePackage.length() - 1); } else if (basePackage.endsWith(".")) { ; // skip } else { basePackage += "."; } break; } else { continue; } } return basePackage; }
From source file:org.codehaus.aspectwerkz.extension.persistence.PersistenceDefinitionParser.java
License:Open Source License
/** * Parses the <tt>index</tt> elements. * * @param root the root element//from w ww . j a v a 2 s .co m * @param definition the definition object */ private static void parseIndexElements(final Element root, final PersistenceDefinition definition) { for (Iterator it1 = root.elementIterator("index"); it1.hasNext();) { IndexDefinition indexDef = new IndexDefinition(); Element introduction = (Element) it1.next(); for (Iterator it2 = introduction.attributeIterator(); it2.hasNext();) { Attribute attribute = (Attribute) it2.next(); String name = attribute.getName().trim(); String value = attribute.getValue().trim(); if (name.equals("name")) { indexDef.setName(value); continue; } else if (name.equals("type")) { indexDef.setType(value); continue; } } definition.addIndex(indexDef); } }
From source file:org.codehaus.aspectwerkz.extension.persistence.PersistenceDefinitionParser.java
License:Open Source License
/** * Parses the <tt>peristence-manager</tt> elements. * * @param root the root element//from w w w. j a v a 2 s . c om * @param definition the definition object */ private static void parsePersistenceManagerElements(final Element root, final PersistenceDefinition definition) { for (Iterator it1 = root.elementIterator("persistence-manager"); it1.hasNext();) { PersistenceManagerDefinition pmDef = new PersistenceManagerDefinition(); final Element pm = (Element) it1.next(); for (Iterator it2 = pm.attributeIterator(); it2.hasNext();) { Attribute attribute = (Attribute) it2.next(); String name = attribute.getName().trim(); String value = attribute.getValue().trim(); if (name.equals("class")) { pmDef.setClassName(value); } else if (name.equals("active")) { pmDef.setActive(value); } } for (Iterator it2 = pm.elementIterator(); it2.hasNext();) { Element nestedAdviceElement = (Element) it2.next(); if (nestedAdviceElement.getName().trim().equals("index-ref")) { IndexRefDefinition indexDef = new IndexRefDefinition(); indexDef.setName(nestedAdviceElement.attributeValue("name")); pmDef.addIndexRef(indexDef); } else if (nestedAdviceElement.getName().trim().equals("param")) { ParameterDefinition paramDef = new ParameterDefinition(); paramDef.setName(nestedAdviceElement.attributeValue("name")); paramDef.setValue(nestedAdviceElement.getText()); pmDef.addParameter(paramDef); } } definition.addPersistenceManager(pmDef); } }
From source file:org.codehaus.aspectwerkz.extension.persistence.PersistenceDefinitionParser.java
License:Open Source License
/** * Parses the <tt>persistent</tt> elements. * * @param root the root element//from w ww . ja v a2 s . co m * @param definition the definition object */ private static void parsePersistentElements(final Element root, final PersistenceDefinition definition) { for (Iterator it1 = root.elementIterator("persistent"); it1.hasNext();) { final PersistentObjectDefinition persistentDef = new PersistentObjectDefinition(); final Element persistent = (Element) it1.next(); for (Iterator it2 = persistent.attributeIterator(); it2.hasNext();) { Attribute attribute = (Attribute) it2.next(); String name = attribute.getName().trim(); String value = attribute.getValue().trim(); if (name.equals("class")) { persistentDef.setClassName(value); continue; } } for (Iterator it2 = persistent.elementIterator(); it2.hasNext();) { Element nestedAdviceElement = (Element) it2.next(); if (nestedAdviceElement.getName().trim().equals("index-ref")) { IndexRefDefinition indexDef = new IndexRefDefinition(); indexDef.setName(nestedAdviceElement.attributeValue("name")); indexDef.setMethod(nestedAdviceElement.attributeValue("method")); persistentDef.addIndexRef(indexDef); } } definition.addPersistentObject(persistentDef); } }