@Override protected Object evaluate(Iterator args) { Object[] argArray = new Object[_ci.getParameters().length]; if( _boundValues != null ) { args = Arrays.asList(_boundValues).iterator(); } for (int i = 0; i < argArray.length; i++) { argArray[i] = args.next(); } return _ci.getConstructor().newInstance(argArray); }
@Override protected Object evaluate(Iterator args) { Object[] argArray = new Object[_ci.getParameters().length]; if( _boundValues != null ) { args = Arrays.asList(_boundValues).iterator(); } for (int i = 0; i < argArray.length; i++) { argArray[i] = args.next(); } return _ci.getConstructor().newInstance(argArray); }
public static TestClass createTestClass(IType testType) { IConstructorInfo noArgConstructor = testType.getTypeInfo().getConstructor(); if (noArgConstructor != null) { return (TestClass) noArgConstructor.getConstructor().newInstance(); } else { IConstructorInfo oneArgConstructor = testType.getTypeInfo().getConstructor(JavaTypes.STRING()); if (oneArgConstructor != null) { return (TestClass) oneArgConstructor.getConstructor().newInstance("temp"); } else { throw new IllegalArgumentException("Type " + testType.getName() + " does not have either a no-arg constructor or a one-arg constructor that takes a String"); } } }
@Override public Object getInstance() { ITypeInfo autoinsertTypeInfo = JavaTypes.AUTOINSERT().getTypeInfo(); return autoinsertTypeInfo.getConstructor().getConstructor().newInstance(); }
@SuppressWarnings({"UnusedDeclaration"}) public static void maybeAutoInsert( Object obj, int index, IType typeToAutoCreate ) { List l = (List)obj; if( l.size() == index ) { if( typeToAutoCreate.isAbstract() || typeToAutoCreate.isInterface() ) { throw new IllegalStateException( "Type " + typeToAutoCreate.getName() + " is abstract or an interface and has no default implementation class to use" ); } final IConstructorInfo constructor = typeToAutoCreate.getTypeInfo().getConstructor(); if( constructor == null ) { throw new IllegalStateException( "Type " + typeToAutoCreate.getName() + " has no default constructor" ); } //noinspection unchecked l.add( constructor.getConstructor().newInstance() ); } }
@SuppressWarnings({"UnusedDeclaration"}) public static void maybeAutoInsert( Object obj, int index, IType typeToAutoCreate ) { List l = (List)obj; if( l.size() == index ) { if( typeToAutoCreate.isAbstract() || typeToAutoCreate.isInterface() ) { throw new IllegalStateException( "Type " + typeToAutoCreate.getName() + " is abstract or an interface and has no default implementation class to use" ); } final IConstructorInfo constructor = typeToAutoCreate.getTypeInfo().getConstructor(); if( constructor == null ) { throw new IllegalStateException( "Type " + typeToAutoCreate.getName() + " has no default constructor" ); } //noinspection unchecked l.add( constructor.getConstructor().newInstance() ); } } }
private IAnnotationInfo makeAutocreateAnnotation(Function0 function) { final IType autocreateType = TypeSystem.getByFullName("gw.lang.Autocreate"); List<? extends IConstructorInfo> constructors = autocreateType.getTypeInfo().getConstructors(); for (IConstructorInfo constructor : constructors) { if (constructor.getParameters().length == 1) { final Object val = constructor.getConstructor().newInstance(function); return new AutoCreateAnnotationInfo(autocreateType, val); } } throw new IllegalStateException("Could not find the block constructor for Autocreate"); }
@Override public Object unmarshal( XmlElement componentElement, UnmarshalContext context ) { URI nsURI; try { nsURI = new URI( WsiAdditions.getInstance().getTargetNamespace( _type ) ); } catch ( URISyntaxException e ) { throw GosuExceptionUtil.forceThrow(e); } Object obj = null; if (componentElement != null) { obj = _type.getTypeInfo().getConstructor().getConstructor().newInstance(); for (Map.Entry<String,IPropertyInfo> prop : getProperties(_type).entrySet()) { XmlElement child = componentElement.getChild(new QName(nsURI.toString(), prop.getKey())); if (child != null) { Object childObj = XmlServices.unmarshal(prop.getValue().getFeatureType(), child, context); if (childObj != null) { prop.getValue().getAccessor().setValue(obj, childObj); } } } } return obj; }
XmlTypeInstance typeInstance = (XmlTypeInstance) gosuType.getTypeInfo().getConstructor().getConstructor().newInstance(); element.setTypeInstance( typeInstance );
private static <T extends XmlElement> T parseDocumentAtUri( URI uri, Class<T> clazz, XmlParseOptions options ) { try { if ( "local".equals( uri.getScheme() ) ) { ITypeInfo clientConnectorTypeInfo = TypeSystem.getByFullName("gw.internal.xml.ws.LocalWebservicesClientConnector").getTypeInfo(); IConstructorInfo ctor = clientConnectorTypeInfo.getCallableConstructor(TypeSystem.get(URI.class)); Object conn = ctor.getConstructor().newInstance(uri); ITypeInfo responseTypeInfo = TypeSystem.getByFullName("gw.internal.xml.ws.WebservicesResponse").getTypeInfo(); Object response = clientConnectorTypeInfo.getProperty("Response").getAccessor().getValue(conn); InputStream is = (InputStream) responseTypeInfo.getProperty("InputStream").getAccessor().getValue(response); //noinspection unchecked return (T) clazz.getMethod( "parse", InputStream.class, XmlParseOptions.class ).invoke( null, is, options ); } else { //noinspection unchecked return (T) clazz.getMethod( "parse", URL.class, XmlParseOptions.class ).invoke( null, uri.toURL(), options ); } } catch ( InvocationTargetException itex ) { throw GosuExceptionUtil.forceThrow( itex.getTargetException() ); } catch ( Exception ex ) { throw GosuExceptionUtil.forceThrow( ex ); } }
private void create( String value, String typeName ) { TypeSystem.getByFullName( typeName ).getTypeInfo().getConstructor( JavaTypes.STRING() ).getConstructor().newInstance( value ); }
private TestCase makeTest(final IType type, String method) { try { TestClass test; if (type.isValid()) { ITypeInfo typeInfo = type.getTypeInfo(); IConstructorInfo noArgCons = typeInfo.getConstructor(); if (noArgCons != null) { test = (TestClass) noArgCons.getConstructor().newInstance(); } else { IConstructorInfo oneArgCons = typeInfo.getConstructor(JavaTypes.STRING()); if (oneArgCons != null) { test = (TestClass) oneArgCons.getConstructor().newInstance(method); } else { throw new IllegalStateException("Test type " + type + " does not have either a no-arg constructor or a one-arg constructor taking a String"); } } } else { test = new InvalidTestClass(_type); } test.setExecutionManager( _executionManager ); test.setName(method); test.setGosuTest(_type instanceof IGosuClass); test.initMetadata( method ); return test; } catch (final Exception e) { e.printStackTrace(); return new ExceptionTestClass(type, e.getMessage()); } }
Pair<IType, QName> pair = iter.next(); while ( true ) { node = (XmlElement) pair.getFirst().getTypeInfo().getConstructor().getConstructor().newInstance(); if ( ! iter.hasNext() ) { break; node = (XmlElement) inputInfo.getRequestElementType().getTypeInfo().getConstructor().getConstructor().newInstance();
public static Object newInstance( IType type, Object ctx, Object[] args ) { ITypeInfo typeInfo = type.getTypeInfo(); IConstructorInfo method; IType[] runtimeTypes = ReflectUtil.extractRuntimeTypes( args ); method = typeInfo.getCallableConstructor( runtimeTypes ); args = ReflectUtil.coerceArgsIfNecessary( method.getParameters(), args ); args = maybeAddOuter( type, ctx, args ); return method.getConstructor().newInstance( args ); }
if( constructor != null ) additionalTypeLoader = (ITypeLoader)constructor.getConstructor().newInstance( execEnv, additionalArgs ); if( constructor != null ) additionalTypeLoader = (ITypeLoader)constructor.getConstructor().newInstance( execEnv ); if( constructor != null ) additionalTypeLoader = (ITypeLoader)constructor.getConstructor().newInstance();
if( constructor != null ) additionalTypeLoader = (ITypeLoader)constructor.getConstructor().newInstance( execEnv, additionalArgs ); if( constructor != null ) additionalTypeLoader = (ITypeLoader)constructor.getConstructor().newInstance( execEnv ); if( constructor != null ) additionalTypeLoader = (ITypeLoader)constructor.getConstructor().newInstance();
public static <T> T construct( String typeName, Object... args ) { IType type = TypeSystem.getByFullName( typeName ); ensureTypeIsValid( type ); IType[] runtimeTypes = extractRuntimeTypes( args ); IConstructorInfo constructorInfo = findCallableConstructor( type, runtimeTypes ); if( constructorInfo != null ) { return (T) constructorInfo.getConstructor().newInstance( coerceArgsIfNecessary( constructorInfo.getParameters(), args ) ); } else { throw new IllegalArgumentException( "Unable to find a constructor on " + type.getName() + " with parameters compatible with arg types [" + GosuStringUtil.join( runtimeTypes, "," ) + "]"); } }
public static <T> T construct( String typeName, Object... args ) { IType type = TypeSystem.getByFullName( typeName ); ensureTypeIsValid( type ); IType[] runtimeTypes = extractRuntimeTypes( args ); IConstructorInfo constructorInfo = findCallableConstructor( type, runtimeTypes ); if( constructorInfo != null ) { return (T) constructorInfo.getConstructor().newInstance( coerceArgsIfNecessary( constructorInfo.getParameters(), args ) ); } else { throw new IllegalArgumentException( "Unable to find a constructor on " + type.getName() + " with parameters compatible with arg types [" + GosuStringUtil.join( runtimeTypes, "," ) + "]"); } }
private void wrapParameter( XmlElement node, Pair<WsdlOperationParameterInfo, Boolean> paramInfo, Object arg ) { XmlElement parameterElement = (XmlElement) paramInfo.getFirst().getParameterElementType().getTypeInfo().getConstructor().getConstructor().newInstance(); parameterElement = paramInfo.getFirst().wrap( arg, parameterElement ); node.addChild( parameterElement ); }
@Override public Object getInstance() { ITypeInfo autocreateTypeInfo = GosuTypes.AUTOCREATE().getTypeInfo(); if ( _concreteType != null && JavaTypes.LIST().isAssignableFrom( _concreteType ) ) { for ( IConstructorInfo constructor : autocreateTypeInfo.getConstructors()) { IParameterInfo[] constructorParams = constructor.getParameters(); if (constructorParams.length > 0 && constructorParams[0].getFeatureType() instanceof IBlockType ) { try { IGosuParser parser = GosuParserFactory.createParser( "\\ -> new java.util.ArrayList()" ); IExpression expr = parser.parseExp( new TypelessScriptPartId( "Xml Schema autocreate block" ) ); Object block = expr.evaluate(); return constructor.getConstructor().newInstance(block); } catch (Exception e) { throw new RuntimeException(e); } } } } return autocreateTypeInfo.getConstructor().getConstructor().newInstance(); }