Search in sources :

Example 51 with Constructor

use of java.lang.reflect.Constructor in project ACS by ACS-Community.

the class ACSAlarmSystemInterfaceFactory method createSource.

/**
	 * Create a new instance of an alarm system interface.
	 * @param sourceName the source name.
	 * @return the interface instance.
	 * @throws ASIException if the AlarmSystemInterface instance can not be created.
	 */
public static synchronized ACSAlarmSystemInterface createSource(String sourceName) throws ACSASFactoryNotInitedEx, SourceCreationErrorEx {
    if (useACSAlarmSystem == null) {
        Exception e = new IllegalStateException("Factory not initialised");
        throw new AcsJACSASFactoryNotInitedEx(e).toACSASFactoryNotInitedEx();
    }
    if (useACSAlarmSystem) {
        return new ACSAlarmSystemInterfaceProxy(sourceName, logger);
    } else {
        if (source != null) {
            return source;
        }
        try {
            Thread t = Thread.currentThread();
            ClassLoader loader = t.getContextClassLoader();
            Class cl = loader.loadClass("alma.acs.alarmsystem.binding.ACSLaserSource");
            Class[] classes = { String.class, Logger.class };
            Constructor constructor = cl.getConstructor(classes);
            // TODO: take ContainerServicesBase object received in the init method, 
            // and set it on ACSJMSTopicConnectionImpl.containerServices
            // Of course in after the ACS 7.0 release rush, this static field communication 
            // must be replaced with with real calls, or at least the absence of such an object must be detected early.
            source = (ACSAlarmSystemInterface) constructor.newInstance(sourceName, logger);
            return source;
        } catch (Throwable t) {
            System.out.println("ERROR: " + t.getMessage());
            t.printStackTrace();
            throw new AcsJSourceCreationErrorEx(t).toSourceCreationErrorEx();
        }
    }
}
Also used : AcsJACSASFactoryNotInitedEx(alma.acsErrTypeAlarmSourceFactory.wrappers.AcsJACSASFactoryNotInitedEx) Constructor(java.lang.reflect.Constructor) AcsJSourceCreationErrorEx(alma.acsErrTypeAlarmSourceFactory.wrappers.AcsJSourceCreationErrorEx)

Example 52 with Constructor

use of java.lang.reflect.Constructor in project ACS by ACS-Community.

the class ACSAlarmSystemInterfaceFactory method createFaultState.

/** 
	   * Factory method for creating ACSFaultState instances.
	   * @return a new ACSFaultState instance.
	   *
	   */
public static synchronized ACSFaultState createFaultState() throws ACSASFactoryNotInitedEx, FaultStateCreationErrorEx {
    if (useACSAlarmSystem == null) {
        Exception e = new IllegalStateException("Factory not initialised");
        throw new AcsJACSASFactoryNotInitedEx(e).toACSASFactoryNotInitedEx();
    }
    if (useACSAlarmSystem) {
        return new ACSFaultStateImpl();
    } else {
        try {
            Thread t = Thread.currentThread();
            ClassLoader loader = t.getContextClassLoader();
            Class cl = loader.loadClass("alma.acs.alarmsystem.binding.ACSLaserFaultStateImpl");
            Class[] classes = {};
            Constructor constructor = cl.getConstructor(classes);
            return (ACSFaultState) constructor.newInstance();
        } catch (Exception e) {
            throw new AcsJFaultStateCreationErrorEx(e).toFaultStateCreationErrorEx();
        }
    }
}
Also used : AcsJFaultStateCreationErrorEx(alma.acsErrTypeAlarmSourceFactory.wrappers.AcsJFaultStateCreationErrorEx) AcsJACSASFactoryNotInitedEx(alma.acsErrTypeAlarmSourceFactory.wrappers.AcsJACSASFactoryNotInitedEx) Constructor(java.lang.reflect.Constructor)

Example 53 with Constructor

use of java.lang.reflect.Constructor in project ACS by ACS-Community.

the class ACSLogParserVTD method initReflection.

/**
	 * Initialize all the fields and methods with reflection.
	 *  
	 * @throws Exception If fails instantiating fields and methods
	 */
private void initReflection() throws Exception {
    // VTDGen class 
    Class vtdGenClass = Class.forName("com.ximpleware.VTDGen");
    // VTDNav class 
    Class vtdNavClass = Class.forName("com.ximpleware.VTDNav");
    // VTDGEn constructor
    Class[] paramsClasses = new Class[0];
    Constructor constructor = vtdGenClass.getConstructor(paramsClasses);
    Object[] params = new Object[0];
    vtdGen = constructor.newInstance(params);
    // Get VTDGen.clear();
    VTDGen_clear = vtdGenClass.getMethod("clear", new Class[0]);
    // Get VTDGen.setDoc();
    Class[] setDocParmsClasses = new Class[] { byte[].class };
    VTDGen_setDoc = vtdGenClass.getMethod("setDoc", setDocParmsClasses);
    // Get VTDGen.parse();
    Class[] parseParamsClasses = new Class[] { boolean.class };
    VTDGen_parse = vtdGenClass.getMethod("parse", parseParamsClasses);
    // Get VTDGen.getNav();
    VTDGen_getNav = vtdGenClass.getMethod("getNav", new Class[0]);
    // Get VTDNav.ROOT
    Field rootField = vtdNavClass.getField("ROOT");
    NAV_ROOT = rootField.getInt(vtdNavClass);
    // Get VTDNav.FIRST_CHILD
    Field firstChildField = vtdNavClass.getField("FIRST_CHILD");
    NAV_FIRST_CHILD = firstChildField.getInt(vtdNavClass);
    // Get VTDNav.NEXT_SIBLING
    Field nextSiblingField = vtdNavClass.getField("NEXT_SIBLING");
    NAV_NEXT_SIBLING = nextSiblingField.getInt(vtdNavClass);
    // Get VTDNav.toElement(int)
    Class[] toElementsParamsClasses = new Class[] { int.class };
    VTDNav_toElement = vtdNavClass.getMethod("toElement", toElementsParamsClasses);
    // Get VTDNav.matchElement(String)
    Class[] matchElementsParamsClasses = new Class[] { java.lang.String.class };
    VTDNav_matchElement = vtdNavClass.getMethod("matchElement", matchElementsParamsClasses);
    // Get VTDNav.hasAttr(String)
    Class[] hasAttrParamsClasses = new Class[] { java.lang.String.class };
    VTDNav_hasAttr = vtdNavClass.getMethod("hasAttr", hasAttrParamsClasses);
    // Get VTDNav.getAttrCount();
    VTDNav_getAttrCount = vtdNavClass.getMethod("getAttrCount", new Class[0]);
    // Get VTDNav.toString(int)
    Class[] toStringParamsClasses = new Class[] { int.class };
    VTDNav_toString = vtdNavClass.getMethod("toString", toStringParamsClasses);
    // Get VTDNav.getText();
    VTDNav_getText = vtdNavClass.getMethod("getText", new Class[0]);
    // Get VTDNav.getAttrVal(String);
    Class[] getAttrValParamsClasses = new Class[] { java.lang.String.class };
    VTDNav_getAttrVal = vtdNavClass.getMethod("getAttrVal", getAttrValParamsClasses);
    // Get VTDNav.getTokenOffset(int)
    Class[] getTokenOffsetParamsClasses = new Class[] { int.class };
    VTDNav_getTokenOffset = vtdNavClass.getMethod("getTokenOffset", getTokenOffsetParamsClasses);
    // Get VTDNav.getTokenLength(int);
    Class[] getTokenLengthParamsClasses = new Class[] { int.class };
    VTDNav_getTokenLength = vtdNavClass.getMethod("getTokenLength", getTokenLengthParamsClasses);
    // Get VTDNav.getTokenCount();
    VTDNav_getTokenCount = vtdNavClass.getMethod("getTokenCount", new Class[0]);
    // Get VTDNav.toNormalizedString(int)
    Class[] toNormalizedStringParamsClasses = new Class[] { int.class };
    VTDNav_toNormalizedString = vtdNavClass.getMethod("toNormalizedString", toNormalizedStringParamsClasses);
    // Get VTDNav.toElement(int,String)
    Class[] toElement_Str_dStringParamsClasses = new Class[] { int.class, java.lang.String.class };
    VTDNav_toElement_String = vtdNavClass.getMethod("toElement", toElement_Str_dStringParamsClasses);
}
Also used : LogField(com.cosylab.logging.engine.log.LogField) Field(java.lang.reflect.Field) Constructor(java.lang.reflect.Constructor)

Example 54 with Constructor

use of java.lang.reflect.Constructor in project L42 by ElvisResearchGroup.

the class PlgWrapperGenerator method plgComplete1.

public static ClassB plgComplete1(List<Ast.C> cs, Program p, ClassB l) throws UnresolvedOverloading, ClassUnfit, MethodUnfit {
    PluginWithPart pwp = OnLineCode._isPluginWithPart(l.getDoc1());
    if (pwp == null) {
        return l;
    }
    PlgInfo plgInfo = new PlgInfo(l.getDoc1());
    if (!hasPluginUnresponsive(l)) {
        throw new RefactorErrors.ClassUnfit().msg("Class " + Path.outer(0, cs) + " does not contain method #pluginUnresponsive(binaryRepr)");
    }
    Class<?> c = pwp.pointed;
    Method[] jms = c.getMethods();
    Constructor<?>[] jcs = c.getDeclaredConstructors();
    List<Member> msResult = new ArrayList<>(templateWrapper);
    Path pTop = Path.outer(0, cs);
    for (Member m : l.getMs()) {
        if (!(m instanceof MethodWithType)) {
            msResult.add(m);
            continue;
        }
        MethodWithType mwt = (MethodWithType) m;
        if (mwt.get_inner().isPresent()) {
            msResult.add(mwt);
            continue;
        }
        addMwt(p, plgInfo, jms, jcs, msResult, pTop, mwt);
    }
    return l.withMs(msResult);
}
Also used : Path(ast.Ast.Path) Constructor(java.lang.reflect.Constructor) ArrayList(java.util.ArrayList) ClassUnfit(is.L42.connected.withSafeOperators.pluginWrapper.RefactorErrors.ClassUnfit) Method(java.lang.reflect.Method) MethodWithType(ast.ExpCore.ClassB.MethodWithType) PlgInfo(platformSpecific.fakeInternet.PluginWithPart.PlgInfo) PluginWithPart(platformSpecific.fakeInternet.PluginWithPart) Member(ast.ExpCore.ClassB.Member)

Example 55 with Constructor

use of java.lang.reflect.Constructor in project L42 by ElvisResearchGroup.

the class PlgWrapperGenerator method usingConstructor.

private static UsingInfo usingConstructor(PlgInfo plgInfo, Constructor<?>[] jcs, MethodWithType mwt, String name) throws UnresolvedOverloading {
    List<Constructor<?>> jcs0 = new ArrayList<>();
    for (Constructor<?> mi : jcs) {
        if (argLessPData(mi) != mwt.getMs().getNames().size()) {
            continue;
        }
        jcs0.add(mi);
    }
    if (jcs0.size() != 1) {
        throw new RefactorErrors.UnresolvedOverloading().msg("The referred java class " + plgInfo.plgClass.getName() + " does not have exactly one constructor with right number of arguments.\n" + "List of candidate constructors:" + jcs0);
    }
    assert jcs0.size() == 1 : jcs0.size();
    Constructor<?> jc = jcs0.get(0);
    UsingInfo ui = new UsingInfo(plgInfo, jc);
    return ui;
}
Also used : UsingInfo(platformSpecific.fakeInternet.PluginWithPart.UsingInfo) Constructor(java.lang.reflect.Constructor) ArrayList(java.util.ArrayList) UnresolvedOverloading(is.L42.connected.withSafeOperators.pluginWrapper.RefactorErrors.UnresolvedOverloading)

Aggregations

Constructor (java.lang.reflect.Constructor)1314 InvocationTargetException (java.lang.reflect.InvocationTargetException)283 Method (java.lang.reflect.Method)253 IOException (java.io.IOException)128 Field (java.lang.reflect.Field)112 ArrayList (java.util.ArrayList)106 Test (org.junit.Test)92 DOMTestDocumentBuilderFactory (org.w3c.domts.DOMTestDocumentBuilderFactory)74 JUnitTestSuiteAdapter (org.w3c.domts.JUnitTestSuiteAdapter)73 List (java.util.List)61 JAXPDOMTestDocumentBuilderFactory (org.w3c.domts.JAXPDOMTestDocumentBuilderFactory)58 Map (java.util.Map)50 Type (java.lang.reflect.Type)39 Annotation (java.lang.annotation.Annotation)38 HashMap (java.util.HashMap)38 HashSet (java.util.HashSet)31 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)31 ParameterizedType (java.lang.reflect.ParameterizedType)30 File (java.io.File)20 URL (java.net.URL)20