Package org.jboss.xb.binding

Examples of org.jboss.xb.binding.JBossXBRuntimeException


         else
         {
            PropertyMetaData propertyMetaData = modelGroup.getPropertyMetaData();
            if(propertyMetaData == null)
            {
               throw new JBossXBRuntimeException(
                   "Currently, property binding metadata must be available for a model group to be marshalled!"
               );
            }

            o = getChildren(stack.peek(), propertyMetaData.getName(),
View Full Code Here


      if(mapping.elementName != null)
      {
         ParticleBinding element = schema.getElementParticle(mapping.elementName);
         if(element == null)
         {
            throw new JBossXBRuntimeException("Element " + mapping.elementName + " is not declared in the schema.");
         }

         ParticleBinding ctxParticle = ctx.particle;
         ctx.particle = element;
         marshalled = marshalElementOccurence((ElementBinding) element.getTerm(), root, particle.getMinOccurs() == 0, declareNs);
         ctx.particle = ctxParticle;
      }
      else if(mapping.typeName != null)
      {
         TypeBinding typeDef = schema.getType(mapping.typeName);
         if(typeDef == null)
         {
            throw new JBossXBRuntimeException("Type " +
                mapping.typeName +
                " is not defined in the schema."
            );
         }

         if(wildcard.getQName() == null)
         {
            throw new JBossXBRuntimeException("Expected the wildcard to have a non-null QName.");
         }

         ElementBinding element = new ElementBinding(schema, wildcard.getQName(), typeDef);
         ParticleBinding ctxParticle = ctx.particle;
         ctx.particle = new ParticleBinding(element);
         marshalled = marshalElementOccurence(element, root, particle.getMinOccurs() == 0, declareNs);
         ctx.particle = ctxParticle;
      }
      else
      {
         throw new JBossXBRuntimeException("Class mapping for " +
             mapping.cls +
             " is associated with neither global element name nor global type name."
         );
      }
View Full Code Here

               list = asList(value);
            }
            else
            {
               // todo: qname are also not yet supported
               throw new JBossXBRuntimeException(
                   "Expected value for list type is an array or " + List.class.getName() + " but got: " + value
               );
            }

            marshalled = SimpleTypeBindings.marshalList(itemType.getQName().getLocalPart(), list, null);
         }
         else
         {
            throw new JBossXBRuntimeException("Marshalling of list types with item types not from " +
                Constants.NS_XML_SCHEMA + " is not supported."
            );
         }
      }
      else if(simpleTypeQName != null && Constants.NS_XML_SCHEMA.equals(simpleTypeQName.getNamespaceURI()))
      {
         String typeName = simpleTypeQName.getLocalPart();

         String prefix = null;
         boolean removePrefix = false;
         if(SimpleTypeBindings.XS_QNAME_NAME.equals(typeName) ||
             SimpleTypeBindings.XS_NOTATION_NAME.equals(typeName))
         {
            QName qNameValue = (QName)value;
            if(qNameValue.getNamespaceURI() != null && qNameValue.getNamespaceURI().length() > 0)
            {
               prefix = nsRegistry.getPrefix(qNameValue.getNamespaceURI());
               if(prefix == null)
               {
                  prefix = qNameValue.getPrefix();
                  if(prefix == null || prefix.length() == 0)
                  {
                     prefix = qNameValue.getLocalPart() + "_ns";
                  }
                  nsRegistry.addPrefixMapping(prefix, qNameValue.getNamespaceURI());
                  ctx.declareNamespace(prefix, qNameValue.getNamespaceURI());

                  removePrefix = true;
               }
            }
         }

         marshalled = SimpleTypeBindings.marshal(typeName, value, nsRegistry);

         if(removePrefix)
         {
            nsRegistry.removePrefixMapping(prefix);
         }
      }
      // todo: this is a quick fix for boolean pattern (0|1 or true|false) should be refactored
      else if(simpleType.getLexicalPattern() != null &&
          simpleType.getBaseType() != null &&
          Constants.QNAME_BOOLEAN.equals(simpleType.getBaseType().getQName()))
      {
         String item = (String)simpleType.getLexicalPattern().get(0);
         if(item.indexOf('0') != -1 && item.indexOf('1') != -1)
         {
            marshalled = ((Boolean)value).booleanValue() ? "1" : "0";
         }
         else
         {
            marshalled = ((Boolean)value).booleanValue() ? "true" : "false";
         }
      }
      else
      {
         if(simpleType.getLexicalEnumeration() != null)
         {
            Method getValue;
            try
            {
               getValue = value.getClass().getMethod("value", null);
            }
            catch(NoSuchMethodException e)
            {
               try
               {
                  getValue = value.getClass().getMethod("getValue", null);
               }
               catch(NoSuchMethodException e1)
               {
                  throw new JBossXBRuntimeException("Failed to find neither value() nor getValue() in " +
                      value.getClass() +
                      " which is bound to enumeration type " + simpleTypeQName
                  );
               }
            }

            try
            {
               value = getValue.invoke(value, null);
            }
            catch(Exception e)
            {
               throw new JBossXBRuntimeException(
                   "Failed to invoke getValue() on " + value + " to get the enumeration value", e
               );
            }
         }
View Full Code Here

         return;
      }

      if(!nillable)
      {
         throw new JBossXBRuntimeException("Failed to marshal " +
             elementQName +
             ": Java value is null but the element is not nillable."
         );
      }
View Full Code Here

   public void addParticle(ParticleBinding particle)
   {
      if(!particle.getTerm().isElement())
      {
         throw new JBossXBRuntimeException("Model group all may contain only elements!");
      }

      ElementBinding element = (ElementBinding)particle.getTerm();
      switch(elements.size())
      {
View Full Code Here

         public ParticleBinding getCurrentParticle()
         {
            if(curParticle == null)
            {
               throw new JBossXBRuntimeException("The cursor in all group has not been positioned yet!");
            }
            return curParticle;
         }

         public ElementBinding getElement()
         {
            return (ElementBinding)getCurrentParticle().getTerm();
         }

         public boolean isPositioned()
         {
            return curParticle != null;
         }

         public void endElement(QName qName)
         {
            if(curParticle == null || !getElement().getQName().equals(qName))
            {
               throw new JBossXBRuntimeException("Failed to process endElement for " + qName +
                  " since the current element is " + (curParticle == null ? null : getElement().getQName())
               );
            }
         }
View Full Code Here

   public void setProcessContents(short pc)
   {
      this.pc = pc;
      if(pc != PC_LAX && pc != PC_SKIP && pc != PC_STRICT)
      {
         throw new JBossXBRuntimeException("Unexpected value for process contents: " + pc);
      }
   }
View Full Code Here

      if(unresolvedElementHandler == null)
      {
         if(required)
         {
            throw new JBossXBRuntimeException("Schema could not be resolved for wildcard content element " +
               qName +
               " and particle handler for unresolved wildcard content elements is not initialized."
            );
         }
         else
View Full Code Here

      {
         reader = parser.getXMLReader();
      }
      catch(SAXException e1)
      {
         throw new JBossXBRuntimeException("Failed to get parser's XMLReader", e1);
      }

      delegateHandler = new DelegatingContentHandler();
      reader.setContentHandler(delegateHandler);
      reader.setErrorHandler(MetaDataErrorHandler.INSTANCE);
View Full Code Here

      {
         reader.setProperty(name, value);
      }
      catch(SAXException e)
      {
         throw new JBossXBRuntimeException("Failed to set property on the XML reader", e);
      }
   }
View Full Code Here

TOP

Related Classes of org.jboss.xb.binding.JBossXBRuntimeException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.