Package nexj.core.meta

Examples of nexj.core.meta.Type


      }

      setSource(m_operand.getSource(), nFlags);
      m_type = Primitive.BOOLEAN;

      Type type = m_operand.getType();

      if (type == null)
      {
         setConstantValue(Boolean.FALSE);
      }
      else if (type.isPrimitive())
      {
         if (type != Primitive.BOOLEAN)
         {
            throw new TypeMismatchException(getSymbol());
         }
View Full Code Here


    * @param value The value.
    * @return The converted value.
    */
   protected Object convert(Attribute attribute, Object value)
   {
      Type type = attribute.getType();

      if (attribute.isCollection())
      {
         if (value != null)
         {
            if (type.isPrimitive())
            {
               List list = (List)value;
               List convertedList = null;

               for (int i = 0, n = list.size(); i < n; ++i)
               {
                  Object original = list.get(i);

                  if (convertedList == null)
                  {
                     Primitive primitive = Primitive.primitiveOf(original);

                     if (type != primitive)
                     {
                        convertedList = new ArrayList(list.size());

                        for (int k = 0; k < i; ++k)
                        {
                           convertedList.add(list.get(k));
                        }

                        convertedList.add(((Primitive)type).getConverter(primitive).invoke(original));
                     }
                  }
                  else
                  {
                     convertedList.add(type.convert(original));
                  }
               }

               return (convertedList != null) ? convertedList : list;
            }

            InstanceList list;

            if (value instanceof InstanceList)
            {
               list = (InstanceList)value;
            }
            else if (value instanceof Collection)
            {
               list = new InstanceArrayList((Collection)value);
            }
            else if (value instanceof Pair)
            {
               Pair pair = (Pair)value;

               list = new InstanceArrayList(Pair.length(pair));

               do
               {
                  list.add(type.convert(pair.getHead()));
                  pair = pair.getNext();
               }
               while (pair != null);

               return list;
            }
            else if (value instanceof Object[])
            {
               list = new InstanceArrayList(Arrays.asList((Object[])value));
            }
            else
            {
               throw new TypeConversionException(type);
            }

            for (int i = 0, n = list.getCount(); i < n; ++i)
            {
               type.convert(list.get(i));
            }

            return list;
         }
      }

      return type.convert(value);
   }
View Full Code Here

            if (m_nState == DIRTY && !isDirty(i))
            {
               continue;
            }

            Type type = attribute.getType();

            if (attribute.isRequired())
            {
               boolean bMissing = (value == null);

               if (!bMissing)
               {
                  if (type.isPrimitive())
                  {
                     bMissing = (type == Primitive.STRING && value.equals(""));
                  }
                  else
                  {
                     bMissing = (attribute.isCollection() && ((InstanceList)value).isEmpty());
                  }
               }

               if (bMissing)
               {
                  e = createValidationException(e);

                  ValidationException x = new ValidationException("err.validation.requiredAttribute",
                     new Object[]{new StringId(attribute.getCaption()), new StringId(m_metaclass.getCaption())});

                  x.setClassName(m_metaclass.getName());
                  x.setOIDHolder(this);
                  e.addException(attribute.getName(), x);
               }
            }

            if (attribute.getMaxLength() > 0)
            {
               int nLength = 0;

               if (value instanceof String)
               {
                  nLength = ((String)value).length();
               }
               else if (value instanceof Binary)
               {
                  nLength = ((Binary)value).getData().length;
               }

               if (nLength > attribute.getMaxLength())
               {
                  e = createValidationException(e);

                  ValidationException x = new ValidationException("err.validation.maxDataLength",
                     new Object[]{Primitive.createInteger(attribute.getMaxLength()),
                        new StringId(attribute.getCaption()), new StringId(m_metaclass.getCaption())});

                  x.setClassName(m_metaclass.getName());
                  x.setOIDHolder(this);
                  e.addException(attribute.getName(), x);
               }
            }

            if (bFull)
            {
               if (attribute.isConstrained() &&
                  attribute.getEnumeration() != type &&
                  value != null && e == null)
               {
                  if (((InstanceList)attribute.getEnumeration().invoke("read",
                     new Object[]{null, (type.isPrimitive()) ?
                        Pair.attribute(Metaclass.ENUMERATION_VALUE).eq(value) :
                        new Pair(Symbol.AT).eq(value), null, Primitive.createInteger(-1),
                        Primitive.ZERO_INTEGER, Boolean.FALSE})).isEmpty())
                  {
                     e = createValidationException(e);

                     ValidationException x = new ValidationException("err.validation.enumerationValue",
                        new Object[]{new StringId(attribute.getEnumeration().getCaption()),
                           new StringId(attribute.getCaption()), new StringId(m_metaclass.getCaption())});

                     x.setClassName(m_metaclass.getName());
                     x.setOIDHolder(this);
                     e.addException(attribute.getName(), x);
                  }
               }

               if (attribute.getValidationFunction() != null && e == null)
               {
                  Object result = m_context.getMachine().invoke(attribute.getValidationFunction(), this, value, null);

                  if (result != null)
                  {
                     ValidationException x = null;

                     if (result instanceof Boolean)
                     {
                        if (!((Boolean)result).booleanValue())
                        {
                           x = new ValidationException("err.validation.valueRange",
                              new Object[]{new StringId(attribute.getCaption()), new StringId(m_metaclass.getCaption())});
                        }
                     }
                     else if (result instanceof String)
                     {
                        x = new ValidationException((String)result);
                     }
                     else if (result instanceof Pair)
                     {
                        x = new ValidationException((String)((Pair)result).getHead(),
                              Pair.toArray(((Pair)result).getNext()));
                     }

                     if (x != null)
                     {
                        x.setClassName(m_metaclass.getName());
                        x.setOIDHolder(this);
                        e = createValidationException(e);
                        e.addException(attribute.getName(), x);
                     }
                  }
               }
            }

            if (type.isPrimitive() && attribute.isPersistent() && adapter != null)
            {
               try
               {
                  adapter.validate(persistenceMapping.getAttributeMapping(attribute), value);
               }
View Full Code Here

   /**
    * @see nexj.core.meta.MetadataObject#validate(nexj.core.meta.ContextMetadata, ExceptionHolder)
    */
   public void validate(ContextMetadata metadata, ExceptionHolder warnings)
   {
      Type attributeType = m_attribute.getType();
     
      if (m_nSysId == SYSID_ID)
      {
         if (attributeType != Primitive.STRING)
         {
View Full Code Here

            {
               bResult = (obj != null) && ((Class)clazz).isAssignableFrom(obj.getClass());
            }
            else if (clazz instanceof Symbol)
            {
               Type type = ((ClassMetaMap)machine.getContext().getContextMetadata()).getClassMeta(((Symbol)clazz).getName());

               bResult = (type != null && obj instanceof Typed && type.isUpcast(((Typed)obj).getType()));
            }
            else
            {
               throw new TypeMismatchException(getSymbol());
            }
View Full Code Here

         nTF |= TF_READABLE | TF_REF;

         for (int i = 0, nCount = metaclass.getInstanceAttributeCount(); i < nCount; ++i)
         {
            Attribute attribute = metaclass.getInstanceAttribute(i);
            Type type = attribute.getType();
            Object value;

            if (type.isPrimitive())
            {
               value = instance.getValue(attribute.getOrdinal());

               if ((nTF & TF_SERIALIZABLE) != 0 &&
                  type == Primitive.ANY &&
View Full Code Here

         {
            Attribute attribute = metaclass.getInstanceAttribute(i);

            if (attribute.isPersistent() && instance.isDirty(attribute.getOrdinal()))
            {
               Type type = attribute.getType();
               Object value;

               if (type.isPrimitive())
               {
                  value = instance.getValue(attribute.getOrdinal());

                  if ((nTF & TF_SERIALIZABLE) != 0 &&
                     type == Primitive.ANY &&
View Full Code Here

      attribute.setReadPrivilege(getPrivilege(attributeElement, "readPrivilege"));
      attribute.setUpdatePrivilege(getPrivilege(attributeElement, "updatePrivilege"));

      final String sURLPrefix = attribute.getURL();
      final String sTypeName = XMLUtil.getReqStringAttr(attributeElement, "type");
      Type type = Primitive.find(sTypeName);

      if (type == null)
      {
         type = m_metadata.defineMetaclass(sTypeName, attribute);
      }
View Full Code Here

    */
   protected Argument loadArgument(Element element, String sName)
   {
      final Argument arg = new Argument(sName);
      final String sType = XMLUtil.getReqStringAttr(element, "type");
      Type type = Primitive.find(sType);

      if (type == null && s_unsupportedIntrinsicSet.contains(sType))
      {
         type = Primitive.ANY;
      }
View Full Code Here

      m_writer.openElement("Attribute");
      m_writer.writeAttribute("name", attribute.getName());
      m_writer.writeAttribute("visibility", (attribute.getVisibility() == Metaclass.PROTECTED) ? "protected" : "public");

      String sTypeName = "";
      Type type = attribute.getType();

      if (type != null)
      {
         sTypeName = type.getName();
      }

      m_writer.writeAttribute("type", sTypeName);

      if (attribute.isRequired())
View Full Code Here

TOP

Related Classes of nexj.core.meta.Type

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.