📄 unknownelement.java
字号:
if (children != null) { Iterator it = children.iterator(); for (int i = 0; it.hasNext(); i++) { RuntimeConfigurable childWrapper = parentWrapper.getChild(i); UnknownElement child = (UnknownElement) it.next(); try { if (!handleChild( parentUri, ih, parent, child, childWrapper)) { if (!(parent instanceof TaskContainer)) { ih.throwNotSupported(getProject(), parent, child.getTag()); } else { // a task container - anything could happen - just add the // child to the container TaskContainer container = (TaskContainer) parent; container.addTask(child); } } } catch (UnsupportedElementException ex) { throw new BuildException( parentWrapper.getElementTag() + " doesn't support the nested \"" + ex.getElement() + "\" element.", ex); } } } } /** * @return the component name - uses ProjectHelper#genComponentName() */ protected String getComponentName() { return ProjectHelper.genComponentName(getNamespace(), getTag()); } /** * This is used then the realobject of the UE is a PreSetDefinition. * This is also used when a presetdef is used on a presetdef * The attributes, elements and text are applied to this * UE. * * @param u an UnknownElement containing the attributes, elements and text */ public void applyPreSet(UnknownElement u) { if (presetDefed) { return; } // Do the runtime getWrapper().applyPreSet(u.getWrapper()); if (u.children != null) { List newChildren = new ArrayList(); newChildren.addAll(u.children); if (children != null) { newChildren.addAll(children); } children = newChildren; } presetDefed = true; } /** * Creates a named task or data type. If the real object is a task, * it is configured up to the init() stage. * * @param ue The unknown element to create the real object for. * Must not be <code>null</code>. * @param w Ignored in this implementation. * * @return the task or data type represented by the given unknown element. */ protected Object makeObject(UnknownElement ue, RuntimeConfigurable w) { ComponentHelper helper = ComponentHelper.getComponentHelper( getProject()); String name = ue.getComponentName(); Object o = helper.createComponent(ue, ue.getNamespace(), name); if (o == null) { throw getNotFoundException("task or type", name); } if (o instanceof PreSetDef.PreSetDefinition) { PreSetDef.PreSetDefinition def = (PreSetDef.PreSetDefinition) o; o = def.createObject(ue.getProject()); if (o == null) { throw getNotFoundException( "preset " + name, def.getPreSets().getComponentName()); } ue.applyPreSet(def.getPreSets()); if (o instanceof Task) { Task task = (Task) o; task.setTaskType(ue.getTaskType()); task.setTaskName(ue.getTaskName()); task.init(); } } if (o instanceof UnknownElement) { o = ((UnknownElement) o).makeObject((UnknownElement) o, w); } if (o instanceof Task) { ((Task) o).setOwningTarget(getOwningTarget()); } if (o instanceof ProjectComponent) { ((ProjectComponent) o).setLocation(getLocation()); } return o; } /** * Creates a named task and configures it up to the init() stage. * * @param ue The UnknownElement to create the real task for. * Must not be <code>null</code>. * @param w Ignored. * * @return the task specified by the given unknown element, or * <code>null</code> if the task name is not recognised. */ protected Task makeTask(UnknownElement ue, RuntimeConfigurable w) { Task task = getProject().createTask(ue.getTag()); if (task != null) { task.setLocation(getLocation()); // UnknownElement always has an associated target task.setOwningTarget(getOwningTarget()); task.init(); } return task; } /** * Returns a very verbose exception for when a task/data type cannot * be found. * * @param what The kind of thing being created. For example, when * a task name could not be found, this would be * <code>"task"</code>. Should not be <code>null</code>. * @param name The name of the element which could not be found. * Should not be <code>null</code>. * * @return a detailed description of what might have caused the problem. */ protected BuildException getNotFoundException(String what, String name) { ComponentHelper helper = ComponentHelper.getComponentHelper(getProject()); String msg = helper.diagnoseCreationFailure(name, what); return new BuildException(msg, getLocation()); } /** * Returns the name to use in logging messages. * * @return the name to use in logging messages. */ public String getTaskName() { //return elementName; return realThing == null || !(realThing instanceof Task) ? super.getTaskName() : ((Task) realThing).getTaskName(); } /** * Returns the task instance after it has been created and if it is a task. * * @return a task instance or <code>null</code> if the real object is not * a task. */ public Task getTask() { if (realThing instanceof Task) { return (Task) realThing; } return null; } /** * Return the configured object * * @return the real thing whatever it is * * @since ant 1.6 */ public Object getRealThing() { return realThing; } /** * Set the configured object * @param realThing the configured object * @since ant 1.7 */ public void setRealThing(Object realThing) { this.realThing = realThing; } /** * Try to create a nested element of <code>parent</code> for the * given tag. * * @return whether the creation has been successful */ private boolean handleChild( String parentUri, IntrospectionHelper ih, Object parent, UnknownElement child, RuntimeConfigurable childWrapper) { String childName = ProjectHelper.genComponentName( child.getNamespace(), child.getTag()); if (ih.supportsNestedElement(parentUri, childName)) { IntrospectionHelper.Creator creator = ih.getElementCreator( getProject(), parentUri, parent, childName, child); creator.setPolyType(childWrapper.getPolyType()); Object realChild = creator.create(); if (realChild instanceof PreSetDef.PreSetDefinition) { PreSetDef.PreSetDefinition def = (PreSetDef.PreSetDefinition) realChild; realChild = creator.getRealObject(); child.applyPreSet(def.getPreSets()); } childWrapper.setCreator(creator); childWrapper.setProxy(realChild); if (realChild instanceof Task) { Task childTask = (Task) realChild; childTask.setRuntimeConfigurableWrapper(childWrapper); childTask.setTaskName(childName); childTask.setTaskType(childName); } if (realChild instanceof ProjectComponent) { ((ProjectComponent) realChild).setLocation(child.getLocation()); } childWrapper.maybeConfigure(getProject()); child.handleChildren(realChild, childWrapper); creator.store(); return true; } return false; } /** * like contents equals, but ignores project * @param obj the object to check against * @return true if this unknownelement has the same contents the other */ public boolean similar(Object obj) { if (obj == null) { return false; } if (!getClass().getName().equals(obj.getClass().getName())) { return false; } UnknownElement other = (UnknownElement) obj; // Are the names the same ? if (!equalsString(elementName, other.elementName)) { return false; } if (!namespace.equals(other.namespace)) { return false; } if (!qname.equals(other.qname)) { return false; } // Are attributes the same ? if (!getWrapper().getAttributeMap().equals( other.getWrapper().getAttributeMap())) { return false; } // Is the text the same? // Need to use equals on the string and not // on the stringbuffer as equals on the string buffer // does not compare the contents. if (!getWrapper().getText().toString().equals( other.getWrapper().getText().toString())) { return false; } // Are the sub elements the same ? if (children == null || children.size() == 0) { return other.children == null || other.children.size() == 0; } if (other.children == null) { return false; } if (children.size() != other.children.size()) { return false; } for (int i = 0; i < children.size(); ++i) { UnknownElement child = (UnknownElement) children.get(i); if (!child.similar(other.children.get(i))) { return false; } } return true; } private static boolean equalsString(String a, String b) { return (a == null) ? (b == null) : a.equals(b); } /** * Make a copy of the unknown element and set it in the new project. * @param newProject the project to create the UE in. * @return the copied UE. */ public UnknownElement copy(Project newProject) { UnknownElement ret = new UnknownElement(getTag()); ret.setNamespace(getNamespace()); ret.setProject(newProject); ret.setQName(getQName()); ret.setTaskType(getTaskType()); ret.setTaskName(getTaskName()); ret.setLocation(getLocation()); if (getOwningTarget() == null) { Target t = new Target(); t.setProject(getProject()); ret.setOwningTarget(t); } else { ret.setOwningTarget(getOwningTarget()); } RuntimeConfigurable copyRC = new RuntimeConfigurable( ret, getTaskName()); copyRC.setPolyType(getWrapper().getPolyType()); Map m = getWrapper().getAttributeMap(); for (Iterator i = m.entrySet().iterator(); i.hasNext();) { Map.Entry entry = (Map.Entry) i.next(); copyRC.setAttribute( (String) entry.getKey(), (String) entry.getValue()); } copyRC.addText(getWrapper().getText().toString()); for (Enumeration e = getWrapper().getChildren(); e.hasMoreElements();) { RuntimeConfigurable r = (RuntimeConfigurable) e.nextElement(); UnknownElement ueChild = (UnknownElement) r.getProxy(); UnknownElement copyChild = ueChild.copy(newProject); copyRC.addChild(copyChild.getWrapper()); ret.addChild(copyChild); } return ret; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -