Package com.caucho.quercus.marshal

Examples of com.caucho.quercus.marshal.MarshalFactory


   */
  private ModuleContext(ClassLoader loader)
  {
    _loader = loader;

    _marshalFactory = new MarshalFactory(this);
    _exprFactory = new ExprFactory();

    _stdClassDef = new InterpretedClassDef("stdClass", null, new String[0]);
    _stdClass = new QuercusClass(this, _stdClassDef, null);

View Full Code Here


  {
    int size = getSize();

    T[] array = T[].class.cast(Array.newInstance(elementType, size));

    MarshalFactory factory = env.getModuleContext().getMarshalFactory();
    Marshal elementMarshal = factory.create(elementType);

    int i = 0;

    for (Entry ptr = getHead(); ptr != null; ptr = ptr.getNext()) {
      Array.set(array, i++, elementMarshal.marshal(env,
View Full Code Here

   
    synchronized (this) {
      if (_isInit)
        return;

      MarshalFactory marshalFactory = _moduleContext.getMarshalFactory();
      ExprFactory exprFactory = _moduleContext.getExprFactory();

      try {
        boolean callUsesVariableArgs = false;
        boolean callUsesSymbolTable = false;
        boolean returnNullAsFalse = false;

        for (Annotation ann : _methodAnn) {
          if (VariableArguments.class.isAssignableFrom(ann.annotationType()))
            callUsesVariableArgs = true;

          if (UsesSymbolTable.class.isAssignableFrom(ann.annotationType()))
            callUsesSymbolTable = true;

          if (ReturnNullAsFalse.class.isAssignableFrom(ann.annotationType()))
            returnNullAsFalse = true;
        }

        _isCallUsesVariableArgs = callUsesVariableArgs;
        _isCallUsesSymbolTable = callUsesSymbolTable;

        _hasEnv = _param.length > 0 && _param[0].equals(Env.class);
        int envOffset = _hasEnv ? 1 : 0;

        if (envOffset < _param.length)
          _hasThis = hasThis(_param[envOffset], _paramAnn[envOffset]);
        else
          _hasThis = false;

        if (_hasThis)
          envOffset++;

        boolean hasRestArgs = false;
        boolean isRestReference = false;

        if (_param.length > 0
            && (_param[_param.length - 1].equals(Value[].class)
                || _param[_param.length - 1].equals(Object[].class))) {
          hasRestArgs = true;

          for (Annotation ann : _paramAnn[_param.length - 1]) {
            if (Reference.class.isAssignableFrom(ann.annotationType()))
              isRestReference = true;
          }
        }

        _hasRestArgs = hasRestArgs;
        _isRestReference = isRestReference;

        int argLength = _param.length;

        if (_hasRestArgs)
          argLength -= 1;

        _defaultExprs = new Expr[argLength - envOffset];
        _marshalArgs = new Marshal[argLength - envOffset];

        _maxArgumentLength = argLength - envOffset;
        _minArgumentLength = _maxArgumentLength;

        for (int i = 0; i < argLength - envOffset; i++) {
          boolean isReference = false;
          boolean isPassThru = false;
     
          boolean isNotNull = false;

          for (Annotation ann : _paramAnn[i + envOffset]) {
            if (Optional.class.isAssignableFrom(ann.annotationType())) {
              _minArgumentLength--;

              Optional opt = (Optional) ann;

              if (! opt.value().equals("")) {
                try {
                  Expr expr = QuercusParser.parse(_moduleContext.getQuercus(), opt.value());
                  _defaultExprs[i] = expr;
                } catch (java.io.IOException e) {
                  throw new QuercusRuntimeException(e);
                }
              } else
                _defaultExprs[i] = exprFactory.createDefault();
            } else if (Reference.class.isAssignableFrom(ann.annotationType())) {
              isReference = true;
            } else if (PassThru.class.isAssignableFrom(ann.annotationType())) {
              isPassThru = true;
            } else if (NotNull.class.isAssignableFrom(ann.annotationType())) {
              isNotNull = true;
            }
          }

          Class<?> argType = _param[i + envOffset];

          if (isReference) {
            _marshalArgs[i] = marshalFactory.createReference();

            if (! Value.class.equals(argType)
                && ! Var.class.equals(argType)) {
              throw new QuercusException(L.l("reference must be Value or Var for {0}",
                                             _name));
            }
          }
          else if (isPassThru) {
            _marshalArgs[i] = marshalFactory.createValuePassThru();
       
            if (! Value.class.equals(argType)) {
              throw new QuercusException(L.l("pass thru must be Value for {0}",
                                             _name));
            }
          }
          else
            _marshalArgs[i] = marshalFactory.create(argType, isNotNull);
        }

        _unmarshalReturn = marshalFactory.create(_retType,
                                                 false,
                                                 returnNullAsFalse);
      } finally {
        _isInit = true;
      }
View Full Code Here

  {
    int size = getSize();

    Object array = Array.newInstance(elementType, size);

    MarshalFactory factory = env.getModuleContext().getMarshalFactory();
    Marshal elementMarshal = factory.create(elementType);

    int i = 0;

    for (Map.Entry<Value, Value> entry : entrySet()) {
      Array.set(array, i++, elementMarshal.marshal(env,
View Full Code Here

   */
  private ModuleContext(ClassLoader loader)
  {
    _loader = loader;
   
    _marshalFactory = new MarshalFactory(this);
    _exprFactory = new ExprFactory();
   
    _stdClassDef = new InterpretedClassDef("stdClass", null, new String[0]);
    _stdClass = new QuercusClass(this, _stdClassDef, null);

View Full Code Here

    ArrayValueImpl arrayValueImpl = new ArrayValueImpl();

    // XXX: needs to go into constructor
    Class componentClass = getType().getComponentType();

    MarshalFactory factory = getModuleContext().getMarshalFactory();
    Marshal componentClassMarshal = factory.create(componentClass);

    int length = Array.getLength(obj);
     
    for (int i = 0; i < length; i++) {
      Object component = Array.get(obj, i);
View Full Code Here

      if (Modifier.isStatic(field.getModifiers()))
        continue;
      else if (field.isAnnotationPresent(Hide.class))
        continue;

      MarshalFactory factory = moduleContext.getMarshalFactory();
      Marshal marshal = factory.create(field.getType(), false);
     
      _fieldMap.put(new ConstStringValue(field.getName()),
        new FieldMarshalPair(field, marshal));
    }
View Full Code Here

  {
    int size = getSize();

    Object array = Array.newInstance(elementType, size);

    MarshalFactory factory = env.getModuleContext().getMarshalFactory();
    Marshal elementMarshal = factory.create(elementType);

    int i = 0;

    for (Entry ptr = getHead(); ptr != null; ptr = ptr.getNext()) {
      Array.set(array, i++, elementMarshal.marshal(env,
View Full Code Here

    synchronized (this) {
      if (_isInit)
        return;

      MarshalFactory marshalFactory = _moduleContext.getMarshalFactory();
      ExprFactory exprFactory = _moduleContext.getExprFactory();

      try {
        boolean callUsesVariableArgs = false;
        boolean callUsesSymbolTable = false;
        boolean returnNullAsFalse = false;

        for (Annotation ann : _methodAnn) {
          if (VariableArguments.class.isAssignableFrom(ann.annotationType()))
            callUsesVariableArgs = true;

          if (UsesSymbolTable.class.isAssignableFrom(ann.annotationType()))
            callUsesSymbolTable = true;

          if (ReturnNullAsFalse.class.isAssignableFrom(ann.annotationType()))
            returnNullAsFalse = true;
        }

        _isCallUsesVariableArgs = callUsesVariableArgs;
        _isCallUsesSymbolTable = callUsesSymbolTable;

        _hasEnv = _param.length > 0 && _param[0].equals(Env.class);
        int envOffset = _hasEnv ? 1 : 0;

        if (envOffset < _param.length)
          _hasThis = hasThis(_param[envOffset], _paramAnn[envOffset]);
        else
          _hasThis = false;

        if (_hasThis)
          envOffset++;

        boolean hasRestArgs = false;
        boolean isRestReference = false;

        if (_param.length > 0
            && (_param[_param.length - 1].equals(Value[].class)
                || _param[_param.length - 1].equals(Object[].class))) {
          hasRestArgs = true;

          for (Annotation ann : _paramAnn[_param.length - 1]) {
            if (Reference.class.isAssignableFrom(ann.annotationType()))
              isRestReference = true;
          }
        }

        _hasRestArgs = hasRestArgs;
        _isRestReference = isRestReference;

        int argLength = _param.length;

        if (_hasRestArgs)
          argLength -= 1;

        _defaultExprs = new Expr[argLength - envOffset];
        _marshalArgs = new Marshal[argLength - envOffset];

        _maxArgumentLength = argLength - envOffset;
        _minArgumentLength = _maxArgumentLength;

        for (int i = 0; i < argLength - envOffset; i++) {
          boolean isReference = false;
          boolean isPassThru = false;

          boolean isNotNull = false;
         
          boolean isExpectString = false;
          boolean isExpectNumeric = false;
          boolean isExpectBoolean = false;

          Class<?> argType = _param[i + envOffset];
         
          for (Annotation ann : _paramAnn[i + envOffset]) {
            if (Optional.class.isAssignableFrom(ann.annotationType())) {
              _minArgumentLength--;

              Optional opt = (Optional) ann;

              if (opt.value().equals(Optional.NOT_SET))
                _defaultExprs[i] = exprFactory.createDefault();
              else if (opt.value().equals("")) {
                _defaultExprs[i] = exprFactory.createLiteral(StringValue.EMPTY);
              }
              else {
                _defaultExprs[i] = QuercusParser.parseDefault(exprFactory, opt.value());
              }
            } else if (Reference.class.isAssignableFrom(ann.annotationType())) {
              if (! Value.class.equals(argType)
                  && ! Var.class.equals(argType)) {
                throw new QuercusException(L.l("reference must be Value or Var for {0}",
                                               _name));
              }
             
              isReference = true;
            } else if (PassThru.class.isAssignableFrom(ann.annotationType())) {
              if (! Value.class.equals(argType)) {
                throw new QuercusException(L.l("pass thru must be Value for {0}",
                                               _name));
              }
             
              isPassThru = true;
            } else if (NotNull.class.isAssignableFrom(ann.annotationType())) {
              isNotNull = true;
            } else if (Expect.class.isAssignableFrom(ann.annotationType())) {
              if (! Value.class.equals(argType)) {
                throw new QuercusException(L.l("Expect type must be Value for {0}",
                                               _name));
              }
             
              Expect.Type type = ((Expect) ann).type();
             
              if (type == Expect.Type.STRING) {
                isExpectString = true;
              }
              else if (type == Expect.Type.NUMERIC) {
                isExpectNumeric = true;
              }
              else if (type == Expect.Type.BOOLEAN) {
                isExpectBoolean = true;
              }
            }
          }

          if (isReference) {
            _marshalArgs[i] = marshalFactory.createReference();
          }
          else if (isPassThru) {
            _marshalArgs[i] = marshalFactory.createValuePassThru();
          }
          else if (isExpectString) {
            _marshalArgs[i] = marshalFactory.createExpectString();
          }
          else if (isExpectNumeric) {
            _marshalArgs[i] = marshalFactory.createExpectNumeric();
          }
          else if (isExpectBoolean) {
            _marshalArgs[i] = marshalFactory.createExpectBoolean();
          }
          else {
            _marshalArgs[i] = marshalFactory.create(argType, isNotNull);
          }
        }

        _unmarshalReturn = marshalFactory.create(_retType,
                                                 false,
                                                 returnNullAsFalse);
      } finally {
        _isInit = true;
      }
View Full Code Here

    for (Field field : fields) {
      if (Modifier.isStatic(field.getModifiers()))
        continue;

      MarshalFactory factory = moduleContext.getMarshalFactory();
      Marshal marshal = factory.create(field.getType(), false);
     
      _fieldMap.put(new ConstStringValue(field.getName()),
                    new FieldMarshalPair(field, marshal));
    }
View Full Code Here

TOP

Related Classes of com.caucho.quercus.marshal.MarshalFactory

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.