ih = IntrospectionHelper.getHelper(p, element); } catch (final Throwable t) { if (ih.supportsCharacters()) { v.add("#PCDATA"); v.addAll(Collections.list(ih.getNestedElements())); sb.append(String.format("<!ATTLIST %s%n id ID #IMPLIED", name)); for (final String attrName : Collections.list(ih.getAttributes())) { if ("id".equals(attrName)) { continue; final Class<?> type = ih.getAttributeType(attrName); if (type.equals(Boolean.class) || type.equals(Boolean.TYPE)) { sb.append(BOOLEAN).append(" "); && !TASKS.equals(nestedName) && !TYPES.equals(nestedName)) { printElementDecl(out, p, nestedName, ih.getElementType(nestedName));
/** * Try to set a value on an object using reflection. * Helper method for easier access to IntrospectionHelper.setAttribute(). * @param obj the object on which the attribute should be set * @param name the attributename * @param value the new value */ protected void tryToSetAParameter(Object obj, String name, String value) { Project prj = (getProject() != null) ? getProject() : new Project(); IntrospectionHelper iHelper = IntrospectionHelper.getHelper(prj, obj.getClass()); try { iHelper.setAttribute(prj, obj, name, value); } catch (BuildException e) { // no-op } }
IntrospectionHelper ih = IntrospectionHelper.getHelper(helperImpl.project, parentClass); child = uc; } else { child = ih.createElement(helperImpl.project, parent, elementName);
/** * Stores a configured child element within its parent object. * * @param project Project containing the objects. * May be <code>null</code>. * @param parent Parent object to add child to. * Must not be <code>null</code>. * @param child Child object to store in parent. * Should not be <code>null</code>. * @param tag Name of element which generated the child. * May be <code>null</code>, in which case * the child is not stored. */ public static void storeChild(Project project, Object parent, Object child, String tag) { IntrospectionHelper ih = IntrospectionHelper.getHelper(project, parent.getClass()); ih.storeElement(project, parent, child, tag); }
/** * Adds the content of #PCDATA sections to an element. * * @param project The project containing the target. * Must not be <code>null</code>. * @param target The target object to be configured. * Must not be <code>null</code>. * @param text Text to add to the target. * May be <code>null</code>, in which case this * method call is a no-op. * * @exception BuildException if the target object doesn't accept text */ public static void addText(Project project, Object target, String text) throws BuildException { if (text == null) { return; } if (target instanceof TypeAdapter) { target = ((TypeAdapter) target).getProxy(); } IntrospectionHelper.getHelper(project, target.getClass()).addText(project, target, text); }
/** * Copies the properties into the Ant task. */ public void configure(Object antObject) { IntrospectionHelper ih = IntrospectionHelper.getHelper(antObject.getClass()); // set attributes first for (Iterator itr = attributes.entrySet().iterator(); itr.hasNext();) { Entry att = (Entry)itr.next(); ih.setAttribute(getProject(), antObject, (String)att.getKey(), (String)att.getValue()); } // then nested elements for (Iterator itr = elements.iterator(); itr.hasNext();) { AntElement e = (AntElement) itr.next(); Object child = ih.createElement(getProject(), antObject, e.name); e.configure(child); ih.storeElement(getProject(), antObject, child, e.name); } } }
/** * Returns a helper for the given class, either from the cache * or by creating a new instance. * * @param c The class for which a helper is required. * Must not be <code>null</code>. * * @return a helper for the specified class */ public static synchronized IntrospectionHelper getHelper(final Class<?> c) { return getHelper(null, c); }
IntrospectionHelper ih = IntrospectionHelper.getHelper(getProject(), parentClass); try { if (!childWrapper.isEnabled(child)) { if (ih.supportsNestedElement( parentUri, ProjectHelper.genComponentName( child.getNamespace(), child.getTag()))) { parentUri, ih, parent, child, childWrapper)) { if (!(parent instanceof TaskContainer)) { ih.throwNotSupported(getProject(), parent, child.getTag()); } else {
/** * Sets the named attribute in the given element, which is part of the * given project. * * @param p The project containing the element. This is used when files * need to be resolved. Must not be <code>null</code>. * @param element The element to set the attribute in. Must not be * <code>null</code>. * @param attributeName The name of the attribute to set. Must not be * <code>null</code>. * @param value The value to set the attribute to. This may be interpreted * or converted to the necessary type if the setter method * doesn't just take a string. Must not be <code>null</code>. * * @exception BuildException if the introspected class doesn't support * the given attribute, or if the setting * method fails. */ public void setAttribute(final Project p, final Object element, final String attributeName, final String value) throws BuildException { setAttribute(p, element, attributeName, (Object) value); }
private void addAttributeValueProposals(IntrospectionHelper helper, String attributeName, String prefix, List<ICompletionProposal> proposals) { Enumeration<String> attributes = helper.getAttributes(); while (attributes.hasMoreElements()) { String attribute = attributes.nextElement(); if (attribute.equals(attributeName)) { Class<?> attributeType = helper.getAttributeType(attribute); addAttributeValueProposalsForAttributeType(attributeType, prefix, proposals); break; } } }
@Override public Enumeration<?> getNestedElements() { return _helperInstance.getNestedElements(); }
@Override public Enumeration<?> getAttributes() { return _helperInstance.getAttributes(); }
@Override public Class<?> getElementType(String elementName) { return _helperInstance.getElementType(elementName); }
/** * Send a "build finished" event to the build listeners * for this project. * @param exception an exception indicating a reason for a build * failure. May be <code>null</code>, indicating * a successful build. */ public void fireBuildFinished(final Throwable exception) { final BuildEvent event = new BuildEvent(this); event.setException(exception); for (BuildListener currListener : listeners) { currListener.buildFinished(event); } // Inform IH to clear the cache IntrospectionHelper.clearCache(); }
@Override public Class<?> getAttributeType(String attributeName) { return _helperInstance.getAttributeType(attributeName); }
/** * Copies the properties into the Ant task. */ public void configure(Object antObject) { IntrospectionHelper ih = IntrospectionHelper.getHelper(antObject.getClass()); // set attributes first for (Iterator itr = attributes.entrySet().iterator(); itr.hasNext();) { Entry att = (Entry)itr.next(); ih.setAttribute(getProject(), antObject, (String)att.getKey(), (String)att.getValue()); } // then nested elements for (Iterator itr = elements.iterator(); itr.hasNext();) { AntElement e = (AntElement) itr.next(); Object child = ih.createElement(getProject(), antObject, e.name); e.configure(child); ih.storeElement(getProject(), antObject, child, e.name); } } }
public SingleModuleIntrospection(IModule module, String taskClassName) throws ClassNotFoundException { _taskClass = loadClass(taskClassName); _helperInstance = IntrospectionHelper.getHelper(_taskClass); }
@Override void invoke(Task taskInstance, Object arg, IntrospectionHelper helper) { if (TypeCategory.ENUM == _typeCategory) { arg = EnumeratedAttribute.getInstance(_type, arg.toString().toLowerCase()); } helper.setAttribute(null, taskInstance, _helperKey, arg); }
/** * Returns whether the named element supports nested elements. */ private boolean hasNestedElements(String elementName) { IElement element = getDtd().getElement(elementName); if (element != null) { return !element.isEmpty(); } AntTypeDefinition taskClass = getTaskClass(elementName); if (taskClass != null) { IntrospectionHelper helper = getIntrospectionHelper(taskClass); if (helper != null) { Enumeration<String> nested = helper.getNestedElements(); return nested.hasMoreElements(); } } return false; }
private void addAttributeProposals(IntrospectionHelper helper, String taskName, String prefix, List<ICompletionProposal> proposals) { Enumeration<String> attributes = helper.getAttributes(); while (attributes.hasMoreElements()) { String attribute = attributes.nextElement(); if (prefix.length() == 0 || attribute.toLowerCase().startsWith(prefix)) { String replacementString = attribute + "=\"\""; //$NON-NLS-1$ addAttributeProposal(taskName, prefix, proposals, attribute, replacementString, attribute, false); } } }