/** * Get the root binding definition. This is only allowed after the call to * {@link #writeBindings(String, String, List, ProblemHandler)}. * * @return root binding element */ public BindingElement getRootBinding() { return m_rootHolder.getBinding(); }
/** * Complete the generated bindings. This prepares the generated bindings for writing to the file system, if desired. * * @param name file name for root or singleton binding definition * @return holder for root binding definition */ public BindingHolder finish(String name) { BindingHolder root = m_directory.configureFiles(name, m_targetPackage, Collections.EMPTY_LIST); return root; }
/** * Get the binding definition for a namespace, which must already have been created. This method should only be used * after the {@link #generate(Boolean, List)} method has been called. It delegates to the * {@link org.jibx.binding.model.BindingOrganizer} implementation. * * @param uri URI * @return binding holder */ public BindingHolder getBinding(String uri) { return m_directory.getRequiredBinding(uri); }
public boolean visit(MappingElement mapping) { org.jibx.runtime.QName qname = mapping.getTypeQName(); if (qname != null) { types.put(qname, mapping); } String name = mapping.getName(); if (name != null) { NamespaceElement ns = mapping.getNamespace(); if (ns == null) { qname = new org.jibx.runtime.QName(holder.getElementDefaultNamespace(), name); } else { qname = new org.jibx.runtime.QName(mapping.getNamespace().getUri(), name); } elems.put(qname, mapping); } return false; } };
loop: for (Iterator childiter = binding.topChildIterator(); childiter.hasNext();) { ElementBase child = (ElementBase)childiter.next(); switch (child.type()) { if (((NamespaceElement)child).getPrefix() == null) { return true; if (checkNoNamespace(((org.jibx.binding.model.IncludeElement)child).getBinding())) { return true;
/** * Report problems found in binding. * * @param vctx Validation Context * @param handler Problem Handler */ private static void reportBindingProblems(org.jibx.binding.model.ValidationContext vctx, ProblemHandler handler) { StringBuffer buff = new StringBuffer(); ArrayList problems = vctx.getProblems(); for (int i = 0; i < problems.size(); i++) { org.jibx.binding.model.ValidationProblem prob = (org.jibx.binding.model.ValidationProblem)problems.get(i); buff.setLength(0); buff.append(prob.getSeverity() >= org.jibx.binding.model.ValidationProblem.ERROR_LEVEL ? "Error: " : "Warning: "); buff.append(prob.getDescription()); handler.report(buff.toString()); } }
public boolean visit(IncludeElement node) { try { // force creation of defintions context for containing binding m_context.getFormatDefinitions(); node.prevalidate(m_context); } catch (Throwable t) { m_context.addFatal("Error during validation: " + t.getMessage()); t.printStackTrace(); return false; } return true; } }
/** * Check if a <structure> element represents a type derivation. If the element is empty, has no name or property, * is required, and is a mapping reference, then it can be handled as a type derivation. * * @param struct * @return <code>true</code> if a type derivation, <code>false</code> if not */ private static boolean isTypeDerivation(StructureElement struct) { return struct.children().size() == 0 && !struct.hasName() && !struct.hasProperty() && !struct.isOptional() && (struct.getDeclaredType() != null || struct.getEffectiveMapping() != null); }
/** * Set the name and namespace URI for a concrete <mapping> binding component. This is the same logic as used in * the {@link StructureClassHolder} equivalent. * * @param qname qualified name to be set (<code>null</code> if none) * @param mapping concrete mapping definition * @param holder binding containing the mapping */ private void setName(QName qname, MappingElementBase mapping, BindingHolder holder) { if (qname != null) { String name = qname.getName(); mapping.setName(name); String uri = qname.getUri(); holder.addNamespaceUsage(uri); if (!Utility.safeEquals(uri, holder.getElementDefaultNamespace())) { mapping.setUri(uri); } } }
private static String itemType(MappingElement mappingElement, QName qName) { String localPart = qName.getLocalPart(); for (Iterator<?> childIterator = mappingElement.childIterator(); childIterator.hasNext();) { Object child = childIterator.next(); if (child instanceof ValueElement) { ValueElement valueElement = (ValueElement)child; if (localPart.equals(valueElement.getName())) { return valueElement.getDeclaredType(); } } // TODO /* * else if (child instanceof ) { .. } else if () { .. } */ } return null; }
/** * Create and initialize a <mapping> element. * * @param type * @param cust * @return mapping */ private MappingElement createMapping(String type, ClassCustom cust) { MappingElement mapabs; mapabs = new MappingElement(); mapabs.setClassName(type); mapabs.setCreateType(cust.getCreateType()); mapabs.setFactoryName(cust.getFactoryMethod()); return mapabs; }
/** * Visit mapping element. This just adds the mapping definition, if not already added. * * @param node * @return expansion flag */ public boolean visit(MappingElement node) { // check for nested mapping if (!(m_context.getParentElement() instanceof BindingElement)) { m_context.addWarning("No schema equivalent for nested type definitions - converting to global type"); } // add the definition forceMappingDetail(node); return super.visit(node); }
/** * Add documentation for a particular field or property. * * @param value * @param elem */ private void addItemDocumentation(ValueElement value, AnnotatedBase elem) { IClassItem item = value.getField(); if (item == null) { item = value.getGet(); if (item == null) { item = value.getSet(); } } if (item != null) { setDocumentation(item, elem); } }
/** * Get the binding definition for a namespace, creating a new one if not previously defined. This method should only * be used after the {@link #generate(Boolean, List)} method has been called. It delegates to the * {@link org.jibx.binding.model.BindingOrganizer} implementation. * * @param uri URI * @param dflt namespace is default for elements in binding flag * @return binding holder */ public BindingHolder addBinding(String uri, boolean dflt) { BindingHolder hold = m_directory.getBinding(uri); if (hold == null) { hold = m_directory.addBinding(uri, uri, null, dflt); } return hold; }
/** * Check if a container element of the binding represents complex content. * * @param cont * @return <code>true</code> if complex content, <code>false</code> if not */ private static boolean isComplexContent(ContainerElementBase cont) { ArrayList contents = cont.getContentComponents(); for (int i = 0; i < contents.size(); i++) { Object item = contents.get(i); if (item instanceof IComponent && ((IComponent)item).hasName()) { return true; } else if (item instanceof ContainerElementBase && isComplexContent((ContainerElementBase)item)) { return true; } } return false; }
public String getType(QName qn, boolean element) { MappingElement mappingElement = element ? elements.get(jibxQName(qn)) : types.get(jibxQName(qn)); return (mappingElement == null) ? null : mappingElement.getClassName(); }
/** * Adds a collection of namespace URIs to be referenced at root binding level. * * @param uris URIs */ public void addRootUris(Collection uris) { m_directory.addRootUris(uris); }
/** * Convenience method to create the simple type definition for the type of a component. * * @param comp * @return type definition */ private SimpleTypeElement buildSimpleType(IComponent comp) { return buildSimpleType(comp.getType()); }
public boolean visit(IncludeElement node) { try { // force creation of defintions context for containing binding m_context.getFormatDefinitions(); node.prevalidate(m_context); } catch (Throwable t) { m_context.addFatal("Error during validation: " + t.getMessage()); t.printStackTrace(); return false; } return true; } }
public void onBindViewHolder(BindingHolder holder, int position) { final T item = mItems.get(position); holder.getBinding().setVariable(BR.item, item); holder.getBinding().executePendingBindings(); }