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();
}
}
}
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();
}
}
}
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);
}
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);
}
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;
}
Aggregations